syntax = "proto3";

package kodex.controlplane.v1;

option go_package = "github.com/codex-k8s/kodex/proto/gen/go/kodex/controlplane/v1;controlplanev1";

import "google/protobuf/empty.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

message Principal {
  string user_id = 1;
  string email = 2;
  string github_login = 3;
  bool is_platform_admin = 4;
  bool is_platform_owner = 5;
}

message IngestGitHubWebhookRequest {
  string correlation_id = 1;
  string event_type = 2;
  string delivery_id = 3;
  google.protobuf.Timestamp received_at = 4;
  bytes payload_json = 5;
}

message IngestGitHubWebhookResponse {
  string correlation_id = 1;
  string run_id = 2;
  string status = 3;
  bool duplicate = 4;
}

message ResolveStaffByEmailRequest {
  string email = 1;
  optional string github_login = 2;
}

message ResolveStaffByEmailResponse {
  Principal principal = 1;
}

message AuthorizeOAuthUserRequest {
  string email = 1;
  int64 github_user_id = 2;
  string github_login = 3;
}

message AuthorizeOAuthUserResponse {
  Principal principal = 1;
}

message Project {
  string id = 1;
  string slug = 2;
  string name = 3;
  string role = 4;
}

message ListProjectsRequest {
  Principal principal = 1;
  int32 limit = 2;
}

message ListProjectsResponse {
  repeated Project items = 1;
}

message UpsertProjectRequest {
  Principal principal = 1;
  string slug = 2;
  string name = 3;
}

message GetProjectRequest {
  Principal principal = 1;
  string project_id = 2;
}

message DeleteProjectRequest {
  Principal principal = 1;
  string project_id = 2;
}

message Run {
  string id = 1;
  string correlation_id = 2;
  optional string project_id = 3;
  optional string project_slug = 4;
  optional string project_name = 5;
  string status = 6;
  google.protobuf.Timestamp created_at = 7;
  google.protobuf.Timestamp started_at = 8;
  google.protobuf.Timestamp finished_at = 9;
  optional int32 issue_number = 10;
  optional string issue_url = 11;
  optional int32 pr_number = 12;
  optional string pr_url = 13;
  optional string trigger_kind = 14;
  optional string trigger_label = 15;
  optional string job_name = 16;
  optional string job_namespace = 17;
  optional string namespace = 18;
  bool job_exists = 19;
  bool namespace_exists = 20;
  optional string wait_state = 21;
  optional string wait_reason = 22;
  optional string agent_key = 23;
  google.protobuf.Timestamp wait_since = 24;
  google.protobuf.Timestamp last_heartbeat_at = 25;
  RunWaitProjection wait_projection = 26;
}

message RunWaitProjection {
  string wait_state = 1;
  string wait_reason = 2;
  GitHubRateLimitWaitItem dominant_wait = 3;
  repeated GitHubRateLimitWaitItem related_waits = 4;
  string comment_mirror_state = 5;
}

message GitHubRateLimitWaitItem {
  string wait_id = 1;
  string contour_kind = 2;
  string limit_kind = 3;
  string operation_class = 4;
  string state = 5;
  string confidence = 6;
  google.protobuf.Timestamp entered_at = 7;
  google.protobuf.Timestamp resume_not_before = 8;
  int32 attempts_used = 9;
  int32 max_attempts = 10;
  GitHubRateLimitRecoveryHint recovery_hint = 11;
  GitHubRateLimitManualAction manual_action = 12;
}

message GitHubRateLimitRecoveryHint {
  string hint_kind = 1;
  google.protobuf.Timestamp resume_not_before = 2;
  string source_headers = 3;
  string details_markdown = 4;
}

message GitHubRateLimitManualAction {
  string kind = 1;
  string summary = 2;
  string details_markdown = 3;
  google.protobuf.Timestamp suggested_not_before = 4;
}

message ApprovalRequest {
  int64 id = 1;
  string correlation_id = 2;
  optional string run_id = 3;
  optional string project_id = 4;
  optional string project_slug = 5;
  optional string project_name = 6;
  google.protobuf.Int32Value issue_number = 7;
  google.protobuf.Int32Value pr_number = 8;
  optional string trigger_label = 9;
  string tool_name = 10;
  string action = 11;
  string approval_mode = 12;
  string requested_by = 13;
  google.protobuf.Timestamp created_at = 14;
}

message ListPendingApprovalsRequest {
  Principal principal = 1;
  int32 limit = 2;
}

message ListPendingApprovalsResponse {
  repeated ApprovalRequest items = 1;
}

message ResolveApprovalDecisionRequest {
  Principal principal = 1;
  int64 approval_request_id = 2;
  string decision = 3;
  optional string reason = 4;
}

message ResolveApprovalDecisionResponse {
  int64 id = 1;
  string correlation_id = 2;
  optional string run_id = 3;
  string tool_name = 4;
  string action = 5;
  string approval_state = 6;
}

message ListRunsRequest {
  Principal principal = 1;
  int32 page = 2;
  int32 page_size = 3;
}

message ListRunsResponse {
  repeated Run items = 1;
  int32 total_count = 2;
  int32 page = 3;
  int32 page_size = 4;
}

message ListRunJobsRequest {
  Principal principal = 1;
  int32 limit = 2;
  optional string trigger_kind = 3;
  optional string status = 4;
  optional string agent_key = 5;
}

message ListRunJobsResponse {
  repeated Run items = 1;
}

message ListRunWaitsRequest {
  Principal principal = 1;
  int32 limit = 2;
  optional string trigger_kind = 3;
  optional string status = 4;
  optional string agent_key = 5;
  optional string wait_state = 6;
}

message ListRunWaitsResponse {
  repeated Run items = 1;
}

message GetRunRequest {
  Principal principal = 1;
  string run_id = 2;
}

message GetRunLogsRequest {
  Principal principal = 1;
  string run_id = 2;
  int32 tail_lines = 3;
}

message CancelRunRequest {
  Principal principal = 1;
  string run_id = 2;
  optional string reason = 3;
}

message RunActionResponse {
  string run_id = 1;
  string action = 2;
  string previous_status = 3;
  string current_status = 4;
  bool already_terminal = 5;
  bool runtime_deploy_cancel_requested = 6;
  bool job_stopped = 7;
  int32 canceled_github_waits = 8;
  optional string comment_url = 9;
}

message RunLogs {
  string run_id = 1;
  string status = 2;
  google.protobuf.Timestamp updated_at = 3;
  string snapshot_json = 4;
  repeated string tail_lines = 5;
}

message FlowEvent {
  string correlation_id = 1;
  string event_type = 2;
  google.protobuf.Timestamp created_at = 3;
  string payload_json = 4;
}

message ListRunEventsRequest {
  Principal principal = 1;
  string run_id = 2;
  int32 limit = 3;
}

message ListRunEventsResponse {
  repeated FlowEvent items = 1;
}

message SystemSetting {
  string key = 1;
  string section = 2;
  string value_kind = 3;
  string reload_semantics = 4;
  string visibility = 5;
  bool boolean_value = 6;
  bool default_boolean_value = 7;
  string source = 8;
  int64 version = 9;
  google.protobuf.Timestamp updated_at = 10;
  optional string updated_by_user_id = 11;
  optional string updated_by_email = 12;
}

message ListSystemSettingsRequest {
  Principal principal = 1;
}

message ListSystemSettingsResponse {
  repeated SystemSetting items = 1;
}

message GetSystemSettingRequest {
  Principal principal = 1;
  string setting_key = 2;
}

message UpdateSystemSettingBooleanRequest {
  Principal principal = 1;
  string setting_key = 2;
  bool boolean_value = 3;
}

message ResetSystemSettingRequest {
  Principal principal = 1;
  string setting_key = 2;
}

message LearningFeedback {
  int64 id = 1;
  string run_id = 2;
  optional string repository_id = 3;
  optional int32 pr_number = 4;
  optional string file_path = 5;
  optional int32 line = 6;
  string kind = 7;
  string explanation = 8;
  google.protobuf.Timestamp created_at = 9;
}

message ListRunLearningFeedbackRequest {
  Principal principal = 1;
  string run_id = 2;
  int32 limit = 3;
}

message ListRunLearningFeedbackResponse {
  repeated LearningFeedback items = 1;
}

message User {
  string id = 1;
  string email = 2;
  optional int64 github_user_id = 3;
  optional string github_login = 4;
  bool is_platform_admin = 5;
  bool is_platform_owner = 6;
}

message ListUsersRequest {
  Principal principal = 1;
  int32 limit = 2;
}

message ListUsersResponse {
  repeated User items = 1;
}

message CreateUserRequest {
  Principal principal = 1;
  string email = 2;
  bool is_platform_admin = 3;
}

message DeleteUserRequest {
  Principal principal = 1;
  string user_id = 2;
}

message ProjectMember {
  string project_id = 1;
  string user_id = 2;
  string email = 3;
  string role = 4;
  google.protobuf.BoolValue learning_mode_override = 5;
}

message ListProjectMembersRequest {
  Principal principal = 1;
  string project_id = 2;
  int32 limit = 3;
}

message ListProjectMembersResponse {
  repeated ProjectMember items = 1;
}

message UpsertProjectMemberRequest {
  Principal principal = 1;
  string project_id = 2;
  optional string user_id = 3;
  optional string email = 4;
  string role = 5;
}

message DeleteProjectMemberRequest {
  Principal principal = 1;
  string project_id = 2;
  string user_id = 3;
}

message SetProjectMemberLearningModeOverrideRequest {
  Principal principal = 1;
  string project_id = 2;
  string user_id = 3;
  google.protobuf.BoolValue enabled = 4;
}

message RepositoryBinding {
  string id = 1;
  string project_id = 2;
  string provider = 3;
  int64 external_id = 4;
  string owner = 5;
  string name = 6;
  string services_yaml_path = 7;
  optional string bot_username = 8;
  optional string bot_email = 9;
  optional string preflight_updated_at = 10;
  string alias = 11;
  string role = 12;
  string default_ref = 13;
  optional string docs_root_path = 14;
}

message ListProjectRepositoriesRequest {
  Principal principal = 1;
  string project_id = 2;
  int32 limit = 3;
}

message ListProjectRepositoriesResponse {
  repeated RepositoryBinding items = 1;
}

message UpsertProjectRepositoryRequest {
  Principal principal = 1;
  string project_id = 2;
  string provider = 3;
  string owner = 4;
  string name = 5;
  string token = 6;
  string services_yaml_path = 7;
  string alias = 8;
  string role = 9;
  string default_ref = 10;
  optional string docs_root_path = 11;
}

message DeleteProjectRepositoryRequest {
  Principal principal = 1;
  string project_id = 2;
  string repository_id = 3;
}

message UpsertRepositoryBotParamsRequest {
  Principal principal = 1;
  string project_id = 2;
  string repository_id = 3;
  optional string bot_token = 4;
  optional string bot_username = 5;
  optional string bot_email = 6;
}

message RunRepositoryPreflightRequest {
  Principal principal = 1;
  string project_id = 2;
  string repository_id = 3;
}

message PreflightCheckResult {
  string name = 1;
  string status = 2;
  optional string details = 3;
}

message RunRepositoryPreflightResponse {
  string repository_id = 1;
  string status = 2;
  repeated PreflightCheckResult checks = 3;
  string report_json = 4;
  google.protobuf.Timestamp finished_at = 5;
}

message ProjectGitHubTokens {
  string project_id = 1;
  bool has_platform_token = 2;
  bool has_bot_token = 3;
  optional string bot_username = 4;
  optional string bot_email = 5;
}

message GetProjectGitHubTokensRequest {
  Principal principal = 1;
  string project_id = 2;
}

message UpsertProjectGitHubTokensRequest {
  Principal principal = 1;
  string project_id = 2;
  optional string platform_token = 3;
  optional string bot_token = 4;
  optional string bot_username = 5;
  optional string bot_email = 6;
}

message NextStepActionRequest {
  Principal principal = 1;
  string repository_full_name = 2;
  optional int32 issue_number = 3;
  optional int32 pull_request_number = 4;
  string action_kind = 5;
  string target_label = 6;
}

message NextStepActionResponse {
  string repository_full_name = 1;
  string thread_kind = 2;
  int32 thread_number = 3;
  optional string thread_url = 4;
  repeated string removed_labels = 5;
  repeated string added_labels = 6;
  repeated string final_labels = 7;
}

message ConfigEntry {
  string id = 1;
  string scope = 2;
  string kind = 3;
  optional string project_id = 4;
  optional string repository_id = 5;
  string key = 6;
  optional string value = 7;
  repeated string sync_targets = 8;
  string mutability = 9;
  bool is_dangerous = 10;
  optional string updated_at = 11;
}

message ListConfigEntriesRequest {
  Principal principal = 1;
  string scope = 2;
  optional string project_id = 3;
  optional string repository_id = 4;
  int32 limit = 5;
}

message ListConfigEntriesResponse {
  repeated ConfigEntry items = 1;
}

message UpsertConfigEntryRequest {
  Principal principal = 1;
  string scope = 2;
  string kind = 3;
  optional string project_id = 4;
  optional string repository_id = 5;
  string key = 6;
  optional string value_plain = 7;
  optional string value_secret = 8;
  repeated string sync_targets = 9;
  string mutability = 10;
  bool is_dangerous = 11;
  bool dangerous_confirmed = 12;
}

message DeleteConfigEntryRequest {
  Principal principal = 1;
  string config_entry_id = 2;
}

message DocsetGroup {
  string id = 1;
  string title = 2;
  string description = 3;
  bool default_selected = 4;
}

message ListDocsetGroupsRequest {
  Principal principal = 1;
  string docset_ref = 2;
  string locale = 3;
}

message ListDocsetGroupsResponse {
  repeated DocsetGroup groups = 1;
}

message ImportDocsetRequest {
  Principal principal = 1;
  string project_id = 2;
  string repository_id = 3;
  string docset_ref = 4;
  string locale = 5;
  repeated string group_ids = 6;
}

message ImportDocsetResponse {
  string repository_full_name = 1;
  int32 pr_number = 2;
  string pr_url = 3;
  string branch = 4;
  int32 files_total = 5;
}

message SyncDocsetRequest {
  Principal principal = 1;
  string project_id = 2;
  string repository_id = 3;
  string docset_ref = 4;
}

message SyncDocsetResponse {
  string repository_full_name = 1;
  int32 pr_number = 2;
  string pr_url = 3;
  string branch = 4;
  int32 files_updated = 5;
  int32 files_drift = 6;
}

message IssueRunMCPTokenRequest {
  string run_id = 1;
  string namespace = 2;
  string runtime_mode = 3;
  int32 ttl_seconds = 4;
}

message IssueRunMCPTokenResponse {
  string token = 1;
  google.protobuf.Timestamp expires_at = 2;
}

message PrepareRunEnvironmentRequest {
  string run_id = 1;
  string runtime_mode = 2;
  string namespace = 3;
  string target_env = 4;
  int32 slot_no = 5;
  string repository_full_name = 6;
  string services_yaml_path = 7;
  string build_ref = 8;
  bool deploy_only = 9;
}

message PrepareRunEnvironmentResponse {
  bool ok = 1;
  string run_id = 2;
  string namespace = 3;
  string target_env = 4;
}

message EvaluateRuntimeReuseRequest {
  string run_id = 1;
  string project_id = 2;
  int64 issue_number = 3;
  string agent_key = 4;
  string runtime_mode = 5;
  string namespace = 6;
  string target_env = 7;
  int32 slot_no = 8;
  string repository_full_name = 9;
  string services_yaml_path = 10;
  string build_ref = 11;
  bool deploy_only = 12;
}

message EvaluateRuntimeReuseResponse {
  bool reusable = 1;
  string namespace = 2;
  string target_env = 3;
  string effective_build_ref = 4;
  string fingerprint_hash = 5;
  string reason = 6;
}

message ClaimNextInteractionDispatchRequest {
  int32 pending_attempt_timeout_seconds = 1;
}

message ClaimNextInteractionDispatchResponse {
  bool found = 1;
  string correlation_id = 2;
  string interaction_id = 3;
  string run_id = 4;
  string interaction_kind = 5;
  string recipient_provider = 6;
  string recipient_ref = 7;
  google.protobuf.Timestamp response_deadline_at = 8;
  int64 attempt_id = 9;
  int32 attempt_no = 10;
  string delivery_id = 11;
  string adapter_kind = 12;
  bytes request_envelope_json = 13;
}

message CompleteInteractionDispatchRequest {
  string interaction_id = 1;
  string delivery_id = 2;
  string adapter_kind = 3;
  string status = 4;
  bytes request_envelope_json = 5;
  bytes ack_payload_json = 6;
  optional string adapter_delivery_id = 7;
  bool retryable = 8;
  optional string last_error_code = 9;
  google.protobuf.Timestamp next_retry_at = 10;
  google.protobuf.Timestamp finished_at = 11;
  bytes provider_message_ref_json = 12;
  optional string edit_capability = 13;
  google.protobuf.Timestamp callback_token_expires_at = 14;
}

message CompleteInteractionDispatchResponse {
  string interaction_id = 1;
  string interaction_state = 2;
  bool resume_required = 3;
  string run_id = 4;
  string resume_correlation_id = 5;
}

message ExpireNextInteractionRequest {}

message ExpireNextInteractionResponse {
  bool found = 1;
  string interaction_id = 2;
  string interaction_state = 3;
  bool resume_required = 4;
  string run_id = 5;
  string resume_correlation_id = 6;
}

message ProcessNextGitHubRateLimitWaitRequest {
  string worker_id = 1;
}

message ProcessNextGitHubRateLimitWaitResponse {
  bool found = 1;
  string wait_id = 2;
  string run_id = 3;
  string state = 4;
  string resolution_kind = 5;
  int32 attempt_no = 6;
  string manual_action_kind = 7;
  google.protobuf.Timestamp resume_not_before = 8;
  string requeued_correlation_id = 9;
}

message GitHubRateLimitHeaders {
  optional int32 rate_limit_limit = 1;
  optional int32 rate_limit_remaining = 2;
  optional int32 rate_limit_used = 3;
  google.protobuf.Timestamp rate_limit_reset_at = 4;
  optional string rate_limit_resource = 5;
  optional int32 retry_after_seconds = 6;
  optional string github_request_id = 7;
  optional string documentation_url = 8;
}

message ReportGitHubRateLimitSignalRequest {
  string run_id = 1;
  string signal_id = 2;
  string correlation_id = 3;
  string contour_kind = 4;
  string signal_origin = 5;
  string operation_class = 6;
  int32 provider_status_code = 7;
  google.protobuf.Timestamp occurred_at = 8;
  optional string request_fingerprint = 9;
  optional string stderr_excerpt = 10;
  optional string message_excerpt = 11;
  GitHubRateLimitHeaders github_headers = 12;
  optional int64 session_snapshot_version = 13;
}

message ReportGitHubRateLimitSignalResponse {
  string wait_id = 1;
  string wait_state = 2;
  string wait_reason = 3;
  string next_step_kind = 4;
  string runner_action = 5;
  google.protobuf.Timestamp resume_not_before = 6;
}

message ChangeGovernanceScopeHint {
  string context_key = 1;
  string surface_kind = 2;
}

message ChangeGovernanceVerificationTarget {
  string target_kind = 1;
  string target_ref = 2;
}

message ChangeGovernanceWaveDraft {
  string wave_key = 1;
  int32 publish_order = 2;
  string dominant_intent = 3;
  string bounded_scope_kind = 4;
  string summary = 5;
  repeated ChangeGovernanceVerificationTarget verification_targets = 6;
}

message ChangeGovernanceArtifactLinkSeed {
  string artifact_kind = 1;
  string artifact_ref = 2;
  string relation_kind = 3;
  string display_label = 4;
}

message ReportChangeGovernanceDraftSignalRequest {
  string run_id = 1;
  string signal_id = 2;
  string correlation_id = 3;
  string project_id = 4;
  string repository_full_name = 5;
  int32 issue_number = 6;
  google.protobuf.Int32Value pr_number = 7;
  string branch_name = 8;
  string draft_ref = 9;
  string draft_kind = 10;
  repeated ChangeGovernanceScopeHint change_scope_hints = 11;
  repeated string candidate_risk_drivers = 12;
  optional string draft_checksum = 13;
  google.protobuf.Timestamp occurred_at = 14;
}

message ReportChangeGovernanceDraftSignalResponse {
  string package_id = 1;
  string draft_state = 2;
  string next_step_kind = 3;
}

message PublishChangeGovernanceWaveMapRequest {
  string run_id = 1;
  string package_id = 2;
  string wave_map_id = 3;
  string correlation_id = 4;
  repeated ChangeGovernanceWaveDraft waves = 5;
  google.protobuf.Timestamp published_at = 6;
}

message PublishChangeGovernanceWaveMapResponse {
  string package_id = 1;
  string publication_state = 2;
  int64 projection_version = 3;
}

message UpsertChangeGovernanceEvidenceSignalRequest {
  string run_id = 1;
  string package_id = 2;
  string signal_id = 3;
  string correlation_id = 4;
  string scope_kind = 5;
  string scope_ref = 6;
  string block_kind = 7;
  repeated ChangeGovernanceArtifactLinkSeed artifact_links = 8;
  string verification_state_hint = 9;
  bool required_by_tier = 10;
  google.protobuf.Timestamp occurred_at = 11;
}

message UpsertChangeGovernanceEvidenceSignalResponse {
  string package_id = 1;
  string evidence_completeness_state = 2;
  string verification_minimum_state = 3;
  int64 projection_version = 4;
}

message MissionControlWarmupProject {
  string project_id = 1;
  string project_name = 2;
  string repository_full_name = 3;
}

message ListMissionControlWarmupProjectsRequest {
  int32 limit = 1;
}

message ListMissionControlWarmupProjectsResponse {
  repeated MissionControlWarmupProject items = 1;
}

message RunMissionControlWarmupRequest {
  string project_id = 1;
  string requested_by = 2;
  string correlation_id = 3;
  bool force_rebuild = 4;
}

message RunMissionControlWarmupResponse {
  string project_id = 1;
  int64 entity_count = 2;
  int64 relation_count = 3;
  int64 timeline_entry_count = 4;
  int64 command_count = 5;
  int64 max_projection_version = 6;
  int32 backfilled_entities = 7;
  int32 backfilled_relations = 8;
  int32 backfilled_timelines = 9;
  int64 run_entity_count = 10;
  int64 legacy_agent_count = 11;
  int64 continuity_gap_count = 12;
  int64 open_continuity_gap_count = 13;
  int64 blocking_gap_count = 14;
  int64 missing_pull_request_gap_count = 15;
  int64 missing_follow_up_issue_gap_count = 16;
  int64 watermark_count = 17;
  bool ready_for_reconcile = 18;
  string reconcile_gating_reason = 19;
  bool ready_for_transport = 20;
  string transport_gating_reason = 21;
  string provider_freshness_status = 22;
  string provider_coverage_status = 23;
  string graph_projection_status = 24;
  string launch_policy_status = 25;
}

message MissionControlEntityRef {
  string entity_kind = 1;
  string entity_public_id = 2;
}

message MissionControlProviderReference {
  string provider = 1;
  string external_id = 2;
  string url = 3;
}

message MissionControlPrimaryActor {
  string actor_type = 1;
  string actor_id = 2;
  string display_name = 3;
}

message MissionControlEntityCard {
  string entity_kind = 1;
  string entity_public_id = 2;
  string title = 3;
  string state = 4;
  string sync_status = 5;
  MissionControlProviderReference provider_reference = 6;
  MissionControlPrimaryActor primary_actor = 7;
  int32 relation_count = 8;
  google.protobuf.Timestamp last_timeline_at = 9;
  repeated string badges = 10;
  int64 projection_version = 11;
}

message MissionControlRelation {
  string relation_kind = 1;
  string source_kind = 2;
  string source_entity_kind = 3;
  string source_entity_public_id = 4;
  string target_entity_kind = 5;
  string target_entity_public_id = 6;
  string direction = 7;
}

message MissionControlTimelineEntry {
  string entry_id = 1;
  string entity_kind = 2;
  string entity_public_id = 3;
  string source_kind = 4;
  string source_ref = 5;
  google.protobuf.Timestamp occurred_at = 6;
  string summary = 7;
  optional string body_markdown = 8;
  optional string command_id = 9;
  optional string provider_url = 10;
  bool is_read_only = 11;
}

message MissionControlAllowedAction {
  string action_kind = 1;
  string presentation = 2;
  bool allowed_when_degraded = 3;
  string approval_requirement = 4;
  optional string blocked_reason = 5;
}

message MissionControlProviderDeepLink {
  string action_kind = 1;
  string url = 2;
  string reason = 3;
}

message MissionControlWorkItemDetailsPayload {
  string repository_full_name = 1;
  int64 issue_number = 2;
  optional string issue_url = 3;
  optional string last_run_id = 4;
  optional string last_status = 5;
  optional string trigger_kind = 6;
  optional string work_item_type = 7;
  optional string stage_label = 8;
  repeated string labels = 9;
  optional string owner = 10;
  repeated string assignees = 11;
  google.protobuf.Timestamp last_provider_sync_at = 12;
}

message MissionControlDiscussionDetailsPayload {
  optional string discussion_kind = 1;
  optional string status = 2;
  optional string author = 3;
  int32 participant_count = 4;
  optional string latest_comment_excerpt = 5;
  optional string formalization_target = 6;
}

message MissionControlPullRequestDetailsPayload {
  string repository_full_name = 1;
  int64 pull_request_number = 2;
  optional string pull_request_url = 3;
  optional string last_run_id = 4;
  optional string last_status = 5;
  optional string branch_head = 6;
  optional string branch_base = 7;
  optional string merge_state = 8;
  optional string review_decision = 9;
  optional string checks_summary = 10;
  repeated string linked_issue_refs = 11;
}

message MissionControlAgentDetailsPayload {
  string agent_key = 1;
  optional string run_status = 2;
  optional string runtime_mode = 3;
  optional string waiting_reason = 4;
  optional string active_run_id = 5;
  google.protobuf.Timestamp last_heartbeat_at = 6;
  optional string last_run_repository = 7;
}

message MissionControlEntityDetails {
  MissionControlEntityCard entity = 1;
  repeated MissionControlRelation relations = 2;
  repeated MissionControlTimelineEntry timeline_preview = 3;
  repeated MissionControlAllowedAction allowed_actions = 4;
  repeated MissionControlProviderDeepLink provider_deep_links = 5;
  oneof detail_payload {
    MissionControlWorkItemDetailsPayload work_item = 6;
    MissionControlDiscussionDetailsPayload discussion = 7;
    MissionControlPullRequestDetailsPayload pull_request = 8;
    MissionControlAgentDetailsPayload agent = 9;
  }
}

message MissionControlSnapshotSummary {
  int32 total_entities = 1;
  int32 working_count = 2;
  int32 waiting_count = 3;
  int32 blocked_count = 4;
  int32 review_count = 5;
  int32 recent_critical_updates_count = 6;
}

message MissionControlDashboardSnapshot {
  string snapshot_id = 1;
  string view_mode = 2;
  string freshness_status = 3;
  google.protobuf.Timestamp generated_at = 4;
  google.protobuf.Timestamp stale_after = 5;
  MissionControlSnapshotSummary summary = 6;
  repeated MissionControlEntityCard entities = 7;
  repeated MissionControlRelation relations = 8;
  optional string next_page_cursor = 9;
}

message GetMissionControlSnapshotRequest {
  Principal principal = 1;
  optional string view_mode = 2;
  optional string active_filter = 3;
  optional string search = 4;
  optional string cursor = 5;
  int32 limit = 6;
}

message GetMissionControlSnapshotResponse {
  MissionControlDashboardSnapshot snapshot = 1;
}

message GetMissionControlEntityRequest {
  Principal principal = 1;
  string entity_kind = 2;
  string entity_public_id = 3;
  int32 timeline_limit = 4;
}

message ListMissionControlTimelineRequest {
  Principal principal = 1;
  string entity_kind = 2;
  string entity_public_id = 3;
  optional string cursor = 4;
  int32 limit = 5;
}

message ListMissionControlTimelineResponse {
  repeated MissionControlTimelineEntry items = 1;
  optional string next_cursor = 2;
}

message MissionControlNodeRef {
  string node_kind = 1;
  string node_public_id = 2;
}

message MissionControlWorkspaceFilters {
  string open_scope = 1;
  string assignment_scope = 2;
  string state_preset = 3;
  optional string search = 4;
}

message MissionControlWorkspaceSummary {
  int32 root_count = 1;
  int32 node_count = 2;
  int32 blocking_gap_count = 3;
  int32 warning_gap_count = 4;
  int32 recent_closed_context_count = 5;
  int32 working_count = 6;
  int32 waiting_count = 7;
  int32 blocked_count = 8;
  int32 review_count = 9;
  int32 recent_critical_updates_count = 10;
}

message MissionControlWorkspaceWatermark {
  string watermark_kind = 1;
  string status = 2;
  string summary = 3;
  google.protobuf.Timestamp observed_at = 4;
  google.protobuf.Timestamp window_started_at = 5;
  google.protobuf.Timestamp window_ended_at = 6;
}

message MissionControlRootGroup {
  string root_node_kind = 1;
  string root_node_public_id = 2;
  string root_title = 3;
  repeated MissionControlNodeRef node_refs = 4;
  bool has_blocking_gap = 5;
  google.protobuf.Timestamp latest_activity_at = 6;
}

message MissionControlNode {
  string node_kind = 1;
  string node_public_id = 2;
  string title = 3;
  string visibility_tier = 4;
  string active_state = 5;
  string continuity_status = 6;
  string coverage_class = 7;
  MissionControlProviderReference provider_reference = 8;
  string root_node_public_id = 9;
  int32 column_index = 10;
  google.protobuf.Timestamp last_activity_at = 11;
  bool has_blocking_gap = 12;
  repeated string badges = 13;
  int64 projection_version = 14;
}

message MissionControlEdge {
  string edge_kind = 1;
  string source_node_kind = 2;
  string source_node_public_id = 3;
  string target_node_kind = 4;
  string target_node_public_id = 5;
  string visibility_tier = 6;
  string source_of_truth = 7;
  bool is_primary_path = 8;
}

message MissionControlWorkspaceSnapshot {
  string snapshot_id = 1;
  string view_mode = 2;
  google.protobuf.Timestamp generated_at = 3;
  MissionControlWorkspaceFilters effective_filters = 4;
  MissionControlWorkspaceSummary summary = 5;
  repeated MissionControlWorkspaceWatermark workspace_watermarks = 6;
  repeated MissionControlRootGroup root_groups = 7;
  repeated MissionControlNode nodes = 8;
  repeated MissionControlEdge edges = 9;
  optional string next_root_cursor = 10;
}

message GetMissionControlWorkspaceRequest {
  Principal principal = 1;
  optional string view_mode = 2;
  optional string state_preset = 3;
  optional string search = 4;
  optional string cursor = 5;
  int32 root_limit = 6;
}

message GetMissionControlWorkspaceResponse {
  MissionControlWorkspaceSnapshot snapshot = 1;
}

message MissionControlContinuityGap {
  int64 gap_id = 1;
  string gap_kind = 2;
  string severity = 3;
  string status = 4;
  string subject_node_kind = 5;
  string subject_node_public_id = 6;
  optional string expected_node_kind = 7;
  optional string expected_stage_label = 8;
  google.protobuf.Timestamp detected_at = 9;
  google.protobuf.Timestamp resolved_at = 10;
  optional string resolution_hint = 11;
}

message MissionControlStageNextStepTemplate {
  string thread_kind = 1;
  int32 thread_number = 2;
  string target_label = 3;
  repeated string removed_labels = 4;
  optional string display_variant = 5;
  string approval_requirement = 6;
  repeated int64 expected_gap_ids = 7;
}

message MissionControlLaunchSurface {
  string action_kind = 1;
  string presentation = 2;
  string approval_requirement = 3;
  optional string blocked_reason = 4;
  MissionControlStageNextStepTemplate command_template = 5;
}

message MissionControlDiscussionNodeDetails {
  string discussion_kind = 1;
  string status = 2;
  string author = 3;
  int32 participant_count = 4;
  string latest_comment_excerpt = 5;
  repeated MissionControlNodeRef formalization_target_refs = 6;
}

message MissionControlWorkItemNodeDetails {
  string repository_full_name = 1;
  int64 issue_number = 2;
  string stage_label = 3;
  repeated string labels = 4;
  repeated string assignees = 5;
  repeated MissionControlNodeRef linked_run_refs = 6;
  repeated MissionControlNodeRef linked_follow_up_refs = 7;
  google.protobuf.Timestamp last_provider_sync_at = 8;
}

message MissionControlRunNodeDetails {
  string run_id = 1;
  string agent_key = 2;
  string run_status = 3;
  string runtime_mode = 4;
  string trigger_label = 5;
  string build_ref = 6;
  string candidate_namespace = 7;
  google.protobuf.Timestamp started_at = 8;
  google.protobuf.Timestamp finished_at = 9;
  repeated MissionControlNodeRef linked_pull_request_refs = 10;
  repeated MissionControlNodeRef produced_issue_refs = 11;
}

message MissionControlPullRequestNodeDetails {
  string repository_full_name = 1;
  int64 pull_request_number = 2;
  string branch_head = 3;
  string branch_base = 4;
  string merge_state = 5;
  string review_decision = 6;
  string checks_summary = 7;
  repeated MissionControlNodeRef linked_issue_refs = 8;
  MissionControlNodeRef linked_run_ref = 9;
}

message MissionControlActivityEntry {
  string entry_id = 1;
  string node_kind = 2;
  string node_public_id = 3;
  string source_kind = 4;
  string source_ref = 5;
  google.protobuf.Timestamp occurred_at = 6;
  string summary = 7;
  optional string body_markdown = 8;
  optional string provider_url = 9;
  bool is_read_only = 10;
}

message MissionControlNodeDetails {
  MissionControlNode node = 1;
  repeated MissionControlNode adjacent_nodes = 2;
  repeated MissionControlEdge adjacent_edges = 3;
  repeated MissionControlContinuityGap continuity_gaps = 4;
  repeated MissionControlWorkspaceWatermark node_watermarks = 5;
  repeated MissionControlActivityEntry activity_preview = 6;
  repeated MissionControlLaunchSurface launch_surfaces = 7;
  repeated MissionControlProviderDeepLink provider_deep_links = 8;
  oneof detail_payload {
    MissionControlDiscussionNodeDetails discussion = 9;
    MissionControlWorkItemNodeDetails work_item = 10;
    MissionControlRunNodeDetails run = 11;
    MissionControlPullRequestNodeDetails pull_request = 12;
  }
}

message GetMissionControlNodeRequest {
  Principal principal = 1;
  string node_kind = 2;
  string node_public_id = 3;
}

message ListMissionControlNodeActivityRequest {
  Principal principal = 1;
  string node_kind = 2;
  string node_public_id = 3;
  optional string cursor = 4;
  int32 limit = 5;
}

message ListMissionControlNodeActivityResponse {
  repeated MissionControlActivityEntry items = 1;
  optional string next_cursor = 2;
}

message PreviewMissionControlLaunchRequest {
  Principal principal = 1;
  string node_kind = 2;
  string node_public_id = 3;
  string thread_kind = 4;
  int32 thread_number = 5;
  string target_label = 6;
  repeated string removed_labels = 7;
  int64 expected_projection_version = 8;
}

message MissionControlLaunchPreviewLabelDiff {
  repeated string removed_labels = 1;
  repeated string added_labels = 2;
  repeated string final_labels = 3;
}

message MissionControlLaunchPreviewContinuityEffect {
  repeated int64 resolved_gap_ids = 1;
  repeated int64 remaining_gap_ids = 2;
  repeated MissionControlNodeRef resulting_node_refs = 3;
  repeated string provider_redirects = 4;
}

message MissionControlLaunchPreview {
  string preview_id = 1;
  string approval_requirement = 2;
  MissionControlLaunchPreviewLabelDiff label_diff = 3;
  MissionControlLaunchPreviewContinuityEffect continuity_effect = 4;
  optional string blocking_reason = 5;
}

message MissionControlStageNextStepPayload {
  string thread_kind = 1;
  int32 thread_number = 2;
  string target_label = 3;
  repeated string removed_labels = 4;
  optional string display_variant = 5;
  optional string approval_requirement = 6;
}

message MissionControlPendingCommand {
  string project_id = 1;
  string command_id = 2;
  string command_kind = 3;
  string effective_command_kind = 4;
  string status = 5;
  string correlation_id = 6;
  string business_intent_key = 7;
  string repository_full_name = 8;
  optional string retry_target_command_id = 9;
  MissionControlStageNextStepPayload stage_next_step = 10;
  google.protobuf.Timestamp requested_at = 11;
  google.protobuf.Timestamp updated_at = 12;
}

message ClaimMissionControlPendingCommandsRequest {
  int32 limit = 1;
  string worker_id = 2;
  google.protobuf.Duration lease_ttl = 3;
}

message ClaimMissionControlPendingCommandsResponse {
  repeated MissionControlPendingCommand items = 1;
}

message MissionControlCommandState {
  string project_id = 1;
  string command_id = 2;
  string command_kind = 3;
  string status = 4;
  string failure_reason = 5;
  string correlation_id = 6;
  repeated string provider_delivery_ids = 7;
  optional string status_message = 8;
  google.protobuf.Timestamp updated_at = 9;
  google.protobuf.Timestamp reconciled_at = 10;
  string business_intent_key = 11;
  repeated MissionControlEntityRef entity_refs = 12;
  MissionControlCommandApproval approval = 13;
  optional string blocking_reason = 14;
}

message MissionControlCommandApproval {
  string approval_state = 1;
  optional string approval_request_id = 2;
  google.protobuf.Timestamp requested_at = 3;
  google.protobuf.Timestamp decided_at = 4;
  optional string approver_actor_id = 5;
}

message MissionControlDiscussionCreatePayload {
  string title = 1;
  optional string body_markdown = 2;
  optional string parent_entity_kind = 3;
  optional string parent_entity_public_id = 4;
}

message MissionControlWorkItemCreatePayload {
  string title = 1;
  optional string body_markdown = 2;
  repeated string initial_labels = 3;
  repeated MissionControlEntityRef related_entity_refs = 4;
}

message MissionControlDiscussionFormalizePayload {
  string source_entity_kind = 1;
  string source_entity_public_id = 2;
  string formalized_kind = 3;
  string title = 4;
  optional string body_markdown = 5;
}

message MissionControlRetrySyncPayload {
  string command_id = 1;
  optional string retry_reason = 2;
  optional string expected_status = 3;
}

message SubmitMissionControlCommandRequest {
  Principal principal = 1;
  string project_id = 2;
  string command_kind = 3;
  optional string target_entity_kind = 4;
  optional string target_entity_public_id = 5;
  string business_intent_key = 6;
  int64 expected_projection_version = 7;
  string correlation_id = 8;
  google.protobuf.Timestamp requested_at = 9;
  oneof payload {
    MissionControlDiscussionCreatePayload discussion_create = 10;
    MissionControlWorkItemCreatePayload work_item_create = 11;
    MissionControlDiscussionFormalizePayload discussion_formalize = 12;
    MissionControlStageNextStepPayload stage_next_step = 13;
    MissionControlRetrySyncPayload retry_sync = 14;
  }
}

message GetMissionControlCommandRequest {
  Principal principal = 1;
  string command_id = 2;
}

message QueueMissionControlCommandRequest {
  string project_id = 1;
  string command_id = 2;
  optional string status_message = 3;
  google.protobuf.Timestamp updated_at = 4;
}

message MarkMissionControlCommandPendingSyncRequest {
  string project_id = 1;
  string command_id = 2;
  repeated string provider_delivery_ids = 3;
  optional string status_message = 4;
  google.protobuf.Timestamp updated_at = 5;
}

message MarkMissionControlCommandReconciledRequest {
  string project_id = 1;
  string command_id = 2;
  repeated string provider_delivery_ids = 3;
  optional string status_message = 4;
  google.protobuf.Timestamp updated_at = 5;
  google.protobuf.Timestamp reconciled_at = 6;
}

message MarkMissionControlCommandFailedRequest {
  string project_id = 1;
  string command_id = 2;
  string failure_reason = 3;
  repeated string provider_delivery_ids = 4;
  optional string status_message = 5;
  google.protobuf.Timestamp updated_at = 6;
}

message SubmitInteractionCallbackRequest {
  string interaction_id = 1;
  optional string delivery_id = 2;
  string adapter_event_id = 3;
  string callback_kind = 4;
  google.protobuf.Timestamp occurred_at = 5;
  optional string callback_handle = 6;
  optional string free_text = 7;
  optional string responder_ref = 8;
  bytes provider_message_ref_json = 9;
  optional string provider_update_id = 10;
  optional string provider_callback_query_id = 11;
  optional string delivery_status = 12;
  optional string transport_error_code = 13;
  bool transport_retryable = 14;
  bytes raw_payload_json = 15;
}

message SubmitInteractionCallbackResponse {
  bool accepted = 1;
  string classification = 2;
  string interaction_state = 3;
  bool resume_required = 4;
  string continuation_action = 5;
  int64 effective_response_id = 6;
}

message RuntimeDeployTaskLog {
  string stage = 1;
  string level = 2;
  string message = 3;
  google.protobuf.Timestamp created_at = 4;
}

message RuntimeDeployTask {
  string run_id = 1;
  string runtime_mode = 2;
  string namespace = 3;
  string target_env = 4;
  int32 slot_no = 5;
  string repository_full_name = 6;
  string services_yaml_path = 7;
  string build_ref = 8;
  bool deploy_only = 9;
  string status = 10;
  optional string lease_owner = 11;
  google.protobuf.Timestamp lease_until = 12;
  int32 attempts = 13;
  optional string last_error = 14;
  optional string result_namespace = 15;
  optional string result_target_env = 16;
  google.protobuf.Timestamp cancel_requested_at = 17;
  optional string cancel_requested_by = 18;
  optional string cancel_reason = 19;
  google.protobuf.Timestamp stop_requested_at = 20;
  optional string stop_requested_by = 21;
  optional string stop_reason = 22;
  optional string terminal_status_source = 23;
  int64 terminal_event_seq = 24;
  google.protobuf.Timestamp created_at = 25;
  google.protobuf.Timestamp updated_at = 26;
  google.protobuf.Timestamp started_at = 27;
  google.protobuf.Timestamp finished_at = 28;
  repeated RuntimeDeployTaskLog logs = 29;
}

message ListRuntimeDeployTasksRequest {
  Principal principal = 1;
  int32 page = 2;
  int32 page_size = 3;
  optional string status = 4;
  optional string target_env = 5;
}

message ListRuntimeDeployTasksResponse {
  repeated RuntimeDeployTask items = 1;
  int32 total_count = 2;
  int32 page = 3;
  int32 page_size = 4;
}

message GetRuntimeDeployTaskRequest {
  Principal principal = 1;
  string run_id = 2;
}

message CancelRuntimeDeployTaskRequest {
  Principal principal = 1;
  string run_id = 2;
  optional string reason = 3;
}

message StopRuntimeDeployTaskRequest {
  Principal principal = 1;
  string run_id = 2;
  optional string reason = 3;
  // force must be true because stop is a destructive operator action.
  bool force = 4;
}

message RuntimeDeployTaskActionResponse {
  string run_id = 1;
  string action = 2;
  string previous_status = 3;
  string current_status = 4;
  bool already_terminal = 5;
}

message RuntimeError {
  string id = 1;
  string source = 2;
  string level = 3;
  string message = 4;
  string details_json = 5;
  optional string stack_trace = 6;
  optional string correlation_id = 7;
  optional string run_id = 8;
  optional string project_id = 9;
  optional string namespace = 10;
  optional string job_name = 11;
  google.protobuf.Timestamp viewed_at = 12;
  optional string viewed_by = 13;
  google.protobuf.Timestamp created_at = 14;
}

message ListRuntimeErrorsRequest {
  Principal principal = 1;
  int32 limit = 2;
  optional string state = 3;
  optional string level = 4;
  optional string source = 5;
  optional string run_id = 6;
  optional string correlation_id = 7;
}

message ListRuntimeErrorsResponse {
  repeated RuntimeError items = 1;
}

message MarkRuntimeErrorViewedRequest {
  Principal principal = 1;
  string runtime_error_id = 2;
}

message RegistryImageTag {
  string tag = 1;
  string digest = 2;
  google.protobuf.Timestamp created_at = 3;
  int64 config_size_bytes = 4;
}

message RegistryImageRepository {
  string repository = 1;
  int32 tag_count = 2;
  repeated RegistryImageTag tags = 3;
}

message ListRegistryImagesRequest {
  Principal principal = 1;
  int32 limit_repositories = 2;
  int32 limit_tags = 3;
  optional string repository = 4;
}

message ListRegistryImagesResponse {
  repeated RegistryImageRepository items = 1;
}

message DeleteRegistryImageTagRequest {
  Principal principal = 1;
  string repository = 2;
  string tag = 3;
}

message RegistryImageDeleteResult {
  string repository = 1;
  string tag = 2;
  string digest = 3;
  bool deleted = 4;
}

message CleanupRegistryImagesRequest {
  Principal principal = 1;
  optional string repository_prefix = 2;
  int32 limit_repositories = 3;
  int32 keep_tags = 4;
  bool dry_run = 5;
}

message CleanupRegistryImagesResponse {
  int32 repositories_scanned = 1;
  int32 tags_deleted = 2;
  int32 tags_skipped = 3;
  repeated RegistryImageDeleteResult deleted = 4;
  repeated RegistryImageDeleteResult skipped = 5;
}

message UpsertAgentSessionRequest {
  string run_id = 1;
  string correlation_id = 2;
  optional string project_id = 3;
  string repository_full_name = 4;
  string agent_key = 5;
  google.protobuf.Int32Value issue_number = 6;
  string branch_name = 7;
  google.protobuf.Int32Value pr_number = 8;
  optional string pr_url = 9;
  optional string trigger_kind = 10;
  optional string template_kind = 11;
  optional string template_source = 12;
  optional string template_locale = 13;
  optional string model = 14;
  optional string reasoning_effort = 15;
  optional string status = 16;
  optional string session_id = 17;
  optional bytes session_json = 18;
  optional string codex_cli_session_path = 19;
  optional bytes codex_cli_session_json = 20;
  google.protobuf.Timestamp started_at = 21;
  google.protobuf.Timestamp finished_at = 22;
  int64 snapshot_version = 23;
  optional string snapshot_checksum = 24;
}

message UpsertAgentSessionResponse {
  bool ok = 1;
  string run_id = 2;
  int64 snapshot_version = 3;
  optional string snapshot_checksum = 4;
}

message AgentSessionSnapshot {
  string run_id = 1;
  string correlation_id = 2;
  optional string project_id = 3;
  string repository_full_name = 4;
  string agent_key = 5;
  google.protobuf.Int32Value issue_number = 6;
  string branch_name = 7;
  google.protobuf.Int32Value pr_number = 8;
  optional string pr_url = 9;
  optional string trigger_kind = 10;
  optional string template_kind = 11;
  optional string template_source = 12;
  optional string template_locale = 13;
  optional string model = 14;
  optional string reasoning_effort = 15;
  optional string status = 16;
  optional string session_id = 17;
  optional bytes session_json = 18;
  optional string codex_cli_session_path = 19;
  optional bytes codex_cli_session_json = 20;
  google.protobuf.Timestamp started_at = 21;
  google.protobuf.Timestamp finished_at = 22;
  google.protobuf.Timestamp created_at = 23;
  google.protobuf.Timestamp updated_at = 24;
  int64 snapshot_version = 25;
  optional string snapshot_checksum = 26;
  google.protobuf.Timestamp snapshot_updated_at = 27;
}

message GetLatestAgentSessionRequest {
  string repository_full_name = 1;
  string branch_name = 2;
  string agent_key = 3;
}

message GetLatestAgentSessionResponse {
  bool found = 1;
  AgentSessionSnapshot session = 2;
}

message GetRunInteractionResumePayloadRequest {}

message GetRunInteractionResumePayloadResponse {
  bool found = 1;
  bytes payload_json = 2;
}

message GetRunGitHubRateLimitResumePayloadRequest {}

message GetRunGitHubRateLimitResumePayloadResponse {
  bool found = 1;
  bytes payload_json = 2;
}

message LookupRunPullRequestRequest {
  optional string project_id = 1;
  string repository_full_name = 2;
  google.protobuf.Int32Value pr_number = 3;
  optional string head_branch = 4;
}

message LookupRunPullRequestResponse {
  bool found = 1;
  int32 pr_number = 2;
  string pr_url = 3;
  optional string pr_state = 4;
  optional string head_branch = 5;
  optional string base_branch = 6;
}

message InsertRunFlowEventRequest {
  string run_id = 1;
  string event_type = 2;
  bytes payload_json = 3;
}

message InsertRunFlowEventResponse {
  bool ok = 1;
  string event_type = 2;
}

message UpsertRunStatusCommentRequest {
  string run_id = 1;
  string phase = 2;
  optional string job_name = 3;
  optional string job_namespace = 4;
  optional string runtime_mode = 5;
  optional string namespace = 6;
  optional string trigger_kind = 7;
  optional string prompt_locale = 8;
  optional string run_status = 9;
  bool deleted = 10;
  bool already_deleted = 11;
  optional string model = 12;
  optional string reasoning_effort = 13;
  optional string codex_auth_verification_url = 14;
  optional string codex_auth_user_code = 15;
}

message UpsertRunStatusCommentResponse {
  bool ok = 1;
  string run_id = 2;
  int64 comment_id = 3;
  optional string comment_url = 4;
}

message GetCodexAuthRequest {}

message GetCodexAuthResponse {
  bool found = 1;
  bytes auth_json = 2;
}

message UpsertCodexAuthRequest {
  bytes auth_json = 1;
}

message UpsertCodexAuthResponse {
  bool ok = 1;
}

message DeleteRunNamespaceRequest {
  Principal principal = 1;
  string run_id = 2;
}

message DeleteRunNamespaceResponse {
  bool ok = 1;
  string run_id = 2;
  string namespace = 3;
  bool deleted = 4;
  bool already_deleted = 5;
  optional string comment_url = 6;
}

service ControlPlaneService {
  rpc IngestGitHubWebhook(IngestGitHubWebhookRequest) returns (IngestGitHubWebhookResponse);

  // Used by api-gateway staff auth when oauth2-proxy injects identity headers.
  rpc ResolveStaffByEmail(ResolveStaffByEmailRequest) returns (ResolveStaffByEmailResponse);

  // Used by api-gateway OAuth callback to enforce allowlist and persist GitHub identity.
  rpc AuthorizeOAuthUser(AuthorizeOAuthUserRequest) returns (AuthorizeOAuthUserResponse);

  rpc ListProjects(ListProjectsRequest) returns (ListProjectsResponse);
  rpc UpsertProject(UpsertProjectRequest) returns (Project);
  rpc GetProject(GetProjectRequest) returns (Project);
  rpc DeleteProject(DeleteProjectRequest) returns (google.protobuf.Empty);

  rpc ListRuns(ListRunsRequest) returns (ListRunsResponse);
  rpc ListRunWaits(ListRunWaitsRequest) returns (ListRunWaitsResponse);
  rpc GetRun(GetRunRequest) returns (Run);
  rpc CancelRun(CancelRunRequest) returns (RunActionResponse);
  rpc GetRunLogs(GetRunLogsRequest) returns (RunLogs);
  rpc ListPendingApprovals(ListPendingApprovalsRequest) returns (ListPendingApprovalsResponse);
  rpc ResolveApprovalDecision(ResolveApprovalDecisionRequest) returns (ResolveApprovalDecisionResponse);
  rpc ListRunEvents(ListRunEventsRequest) returns (ListRunEventsResponse);
  rpc ListRunLearningFeedback(ListRunLearningFeedbackRequest) returns (ListRunLearningFeedbackResponse);
  rpc ListSystemSettings(ListSystemSettingsRequest) returns (ListSystemSettingsResponse);
  rpc GetSystemSetting(GetSystemSettingRequest) returns (SystemSetting);
  rpc UpdateSystemSettingBoolean(UpdateSystemSettingBooleanRequest) returns (SystemSetting);
  rpc ResetSystemSetting(ResetSystemSettingRequest) returns (SystemSetting);

  rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
  rpc CreateUser(CreateUserRequest) returns (User);
  rpc DeleteUser(DeleteUserRequest) returns (google.protobuf.Empty);

  rpc ListProjectMembers(ListProjectMembersRequest) returns (ListProjectMembersResponse);
  rpc UpsertProjectMember(UpsertProjectMemberRequest) returns (google.protobuf.Empty);
  rpc DeleteProjectMember(DeleteProjectMemberRequest) returns (google.protobuf.Empty);
  rpc SetProjectMemberLearningModeOverride(SetProjectMemberLearningModeOverrideRequest) returns (google.protobuf.Empty);

  rpc ListProjectRepositories(ListProjectRepositoriesRequest) returns (ListProjectRepositoriesResponse);
  rpc UpsertProjectRepository(UpsertProjectRepositoryRequest) returns (RepositoryBinding);
  rpc DeleteProjectRepository(DeleteProjectRepositoryRequest) returns (google.protobuf.Empty);
  rpc UpsertRepositoryBotParams(UpsertRepositoryBotParamsRequest) returns (google.protobuf.Empty);
  rpc RunRepositoryPreflight(RunRepositoryPreflightRequest) returns (RunRepositoryPreflightResponse);

  rpc GetProjectGitHubTokens(GetProjectGitHubTokensRequest) returns (ProjectGitHubTokens);
  rpc UpsertProjectGitHubTokens(UpsertProjectGitHubTokensRequest) returns (google.protobuf.Empty);
  rpc PreviewNextStepAction(NextStepActionRequest) returns (NextStepActionResponse);
  rpc ExecuteNextStepAction(NextStepActionRequest) returns (NextStepActionResponse);

  rpc ListDocsetGroups(ListDocsetGroupsRequest) returns (ListDocsetGroupsResponse);
  rpc ImportDocset(ImportDocsetRequest) returns (ImportDocsetResponse);
  rpc SyncDocset(SyncDocsetRequest) returns (SyncDocsetResponse);
  rpc IssueRunMCPToken(IssueRunMCPTokenRequest) returns (IssueRunMCPTokenResponse);
  rpc PrepareRunEnvironment(PrepareRunEnvironmentRequest) returns (PrepareRunEnvironmentResponse);
  rpc EvaluateRuntimeReuse(EvaluateRuntimeReuseRequest) returns (EvaluateRuntimeReuseResponse);
  rpc ClaimNextInteractionDispatch(ClaimNextInteractionDispatchRequest) returns (ClaimNextInteractionDispatchResponse);
  rpc CompleteInteractionDispatch(CompleteInteractionDispatchRequest) returns (CompleteInteractionDispatchResponse);
  rpc ExpireNextInteraction(ExpireNextInteractionRequest) returns (ExpireNextInteractionResponse);
  rpc ProcessNextGitHubRateLimitWait(ProcessNextGitHubRateLimitWaitRequest) returns (ProcessNextGitHubRateLimitWaitResponse);
  rpc ReportGitHubRateLimitSignal(ReportGitHubRateLimitSignalRequest) returns (ReportGitHubRateLimitSignalResponse);
  rpc ReportChangeGovernanceDraftSignal(ReportChangeGovernanceDraftSignalRequest) returns (ReportChangeGovernanceDraftSignalResponse);
  rpc PublishChangeGovernanceWaveMap(PublishChangeGovernanceWaveMapRequest) returns (PublishChangeGovernanceWaveMapResponse);
  rpc UpsertChangeGovernanceEvidenceSignal(UpsertChangeGovernanceEvidenceSignalRequest) returns (UpsertChangeGovernanceEvidenceSignalResponse);
  rpc GetMissionControlWorkspace(GetMissionControlWorkspaceRequest) returns (GetMissionControlWorkspaceResponse);
  rpc GetMissionControlNode(GetMissionControlNodeRequest) returns (MissionControlNodeDetails);
  rpc ListMissionControlNodeActivity(ListMissionControlNodeActivityRequest) returns (ListMissionControlNodeActivityResponse);
  rpc PreviewMissionControlLaunch(PreviewMissionControlLaunchRequest) returns (MissionControlLaunchPreview);
  rpc GetMissionControlSnapshot(GetMissionControlSnapshotRequest) returns (GetMissionControlSnapshotResponse);
  rpc GetMissionControlEntity(GetMissionControlEntityRequest) returns (MissionControlEntityDetails);
  rpc ListMissionControlTimeline(ListMissionControlTimelineRequest) returns (ListMissionControlTimelineResponse);
  rpc ListMissionControlWarmupProjects(ListMissionControlWarmupProjectsRequest) returns (ListMissionControlWarmupProjectsResponse);
  rpc RunMissionControlWarmup(RunMissionControlWarmupRequest) returns (RunMissionControlWarmupResponse);
  rpc SubmitMissionControlCommand(SubmitMissionControlCommandRequest) returns (MissionControlCommandState);
  rpc GetMissionControlCommand(GetMissionControlCommandRequest) returns (MissionControlCommandState);
  rpc ClaimMissionControlPendingCommands(ClaimMissionControlPendingCommandsRequest) returns (ClaimMissionControlPendingCommandsResponse);
  rpc QueueMissionControlCommand(QueueMissionControlCommandRequest) returns (MissionControlCommandState);
  rpc MarkMissionControlCommandPendingSync(MarkMissionControlCommandPendingSyncRequest) returns (MissionControlCommandState);
  rpc MarkMissionControlCommandReconciled(MarkMissionControlCommandReconciledRequest) returns (MissionControlCommandState);
  rpc MarkMissionControlCommandFailed(MarkMissionControlCommandFailedRequest) returns (MissionControlCommandState);
  rpc SubmitInteractionCallback(SubmitInteractionCallbackRequest) returns (SubmitInteractionCallbackResponse);
  rpc SubmitAdapterInteractionCallback(SubmitInteractionCallbackRequest) returns (SubmitInteractionCallbackResponse);
  rpc ListRuntimeDeployTasks(ListRuntimeDeployTasksRequest) returns (ListRuntimeDeployTasksResponse);
  rpc GetRuntimeDeployTask(GetRuntimeDeployTaskRequest) returns (RuntimeDeployTask);
  rpc CancelRuntimeDeployTask(CancelRuntimeDeployTaskRequest) returns (RuntimeDeployTaskActionResponse);
  rpc StopRuntimeDeployTask(StopRuntimeDeployTaskRequest) returns (RuntimeDeployTaskActionResponse);
  rpc ListRuntimeErrors(ListRuntimeErrorsRequest) returns (ListRuntimeErrorsResponse);
  rpc MarkRuntimeErrorViewed(MarkRuntimeErrorViewedRequest) returns (RuntimeError);

  // Used by agent-runner for run-bound session persistence and event callbacks.
  rpc UpsertAgentSession(UpsertAgentSessionRequest) returns (UpsertAgentSessionResponse);
  rpc GetLatestAgentSession(GetLatestAgentSessionRequest) returns (GetLatestAgentSessionResponse);
  rpc GetRunInteractionResumePayload(GetRunInteractionResumePayloadRequest) returns (GetRunInteractionResumePayloadResponse);
  rpc GetRunGitHubRateLimitResumePayload(GetRunGitHubRateLimitResumePayloadRequest) returns (GetRunGitHubRateLimitResumePayloadResponse);
  rpc LookupRunPullRequest(LookupRunPullRequestRequest) returns (LookupRunPullRequestResponse);
  rpc InsertRunFlowEvent(InsertRunFlowEventRequest) returns (InsertRunFlowEventResponse);
  rpc UpsertRunStatusComment(UpsertRunStatusCommentRequest) returns (UpsertRunStatusCommentResponse);
  rpc GetCodexAuth(GetCodexAuthRequest) returns (GetCodexAuthResponse);
  rpc UpsertCodexAuth(UpsertCodexAuthRequest) returns (UpsertCodexAuthResponse);
  rpc DeleteRunNamespace(DeleteRunNamespaceRequest) returns (DeleteRunNamespaceResponse);
}
