syntax = "proto3";

package kodex.agents.v1;

import "kodex/providers/v1/provider_hub.proto";
import "kodex/runtime/v1/runtime_manager.proto";

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

// AgentManagerService is the stable v1 inter-service contract for the agent
// orchestration domain. It owns flows, stages, roles, prompt templates, agent
// sessions, agent runs, acceptance state, follow-up intents and human gate refs.
service AgentManagerService {
  // CreateFlow creates a flow in the requested scope.
  rpc CreateFlow(CreateFlowRequest) returns (FlowResponse);
  // UpdateFlow changes safe flow metadata without mutating immutable versions.
  rpc UpdateFlow(UpdateFlowRequest) returns (FlowResponse);
  // CreateFlowVersion creates an immutable flow definition version.
  rpc CreateFlowVersion(CreateFlowVersionRequest) returns (FlowVersionResponse);
  // ActivateFlowVersion activates one version for future sessions and runs.
  rpc ActivateFlowVersion(ActivateFlowVersionRequest) returns (FlowVersionResponse);
  // GetFlow returns authoritative flow state.
  rpc GetFlow(GetFlowRequest) returns (FlowResponse);
  // ListFlows returns flows by scope and status.
  rpc ListFlows(ListFlowsRequest) returns (ListFlowsResponse);
  // CreateRoleProfile creates an agent role profile.
  rpc CreateRoleProfile(CreateRoleProfileRequest) returns (RoleProfileResponse);
  // UpdateRoleProfile changes safe role metadata and policy refs.
  rpc UpdateRoleProfile(UpdateRoleProfileRequest) returns (RoleProfileResponse);
  // GetRoleProfile returns authoritative role state.
  rpc GetRoleProfile(GetRoleProfileRequest) returns (RoleProfileResponse);
  // ListRoleProfiles returns role profiles by scope, kind and status.
  rpc ListRoleProfiles(ListRoleProfilesRequest) returns (ListRoleProfilesResponse);
  // GetPromptTemplate returns prompt template metadata without template body.
  rpc GetPromptTemplate(GetPromptTemplateRequest) returns (PromptTemplateResponse);
  // ListPromptTemplates returns prompt templates by role and kind.
  rpc ListPromptTemplates(ListPromptTemplatesRequest) returns (ListPromptTemplatesResponse);
  // CreatePromptTemplateVersion creates a prompt template version for a role.
  rpc CreatePromptTemplateVersion(CreatePromptTemplateVersionRequest) returns (PromptTemplateVersionResponse);
  // ActivatePromptTemplateVersion activates one prompt version for future runs.
  rpc ActivatePromptTemplateVersion(ActivatePromptTemplateVersionRequest) returns (PromptTemplateVersionResponse);
  // GetPromptTemplateVersion returns one prompt template version.
  rpc GetPromptTemplateVersion(GetPromptTemplateVersionRequest) returns (PromptTemplateVersionResponse);
  // ListPromptTemplateVersions returns prompt versions by role and kind.
  rpc ListPromptTemplateVersions(ListPromptTemplateVersionsRequest) returns (ListPromptTemplateVersionsResponse);
  // StartAgentSession creates or continues an agent session.
  rpc StartAgentSession(StartAgentSessionRequest) returns (AgentSessionResponse);
  // StartAgentRun creates a role run and records immutable context refs.
  rpc StartAgentRun(StartAgentRunRequest) returns (AgentRunResponse);
  // RecordRunState records a generic run lifecycle transition from runtime, MCP or hook ingress.
  rpc RecordRunState(RecordRunStateRequest) returns (AgentRunResponse);
  // ReportAgentRunState records a bounded state report from an agent-runner bound to one runtime job.
  rpc ReportAgentRunState(ReportAgentRunStateRequest) returns (AgentRunResponse);
  // GetAgentRunRuntimeStatus возвращает безопасное состояние runtime для одного run.
  rpc GetAgentRunRuntimeStatus(GetAgentRunRuntimeStatusRequest) returns (AgentRunRuntimeStatusResponse);
  // RecordSessionStateSnapshot records metadata for a Codex session state object.
  rpc RecordSessionStateSnapshot(RecordSessionStateSnapshotRequest) returns (AgentSessionStateSnapshotResponse);
  // RequestAcceptance requests acceptance checks for a session, run and stage.
  rpc RequestAcceptance(RequestAcceptanceRequest) returns (AcceptanceResultResponse);
  // RecordAcceptanceResult records acceptance state after machine or role checks.
  rpc RecordAcceptanceResult(RecordAcceptanceResultRequest) returns (AcceptanceResultResponse);
  // GetAcceptanceResult returns one acceptance result.
  rpc GetAcceptanceResult(GetAcceptanceResultRequest) returns (AcceptanceResultResponse);
  // ListAcceptanceResults returns acceptance results by session, run, stage or status.
  rpc ListAcceptanceResults(ListAcceptanceResultsRequest) returns (ListAcceptanceResultsResponse);
  // CreateFollowUpIntent records an intent for the next provider-native work item.
  rpc CreateFollowUpIntent(CreateFollowUpIntentRequest) returns (FollowUpIntentResponse);
  // DispatchFollowUpIntent sends a requested follow-up intent to provider-hub as a typed provider command.
  rpc DispatchFollowUpIntent(DispatchFollowUpIntentRequest) returns (FollowUpIntentResponse);
  // RecordAgentActivity records one safe timeline entry for a session or run.
  rpc RecordAgentActivity(RecordAgentActivityRequest) returns (AgentActivityResponse);
  // ListAgentActivities returns safe timeline entries by session or run.
  rpc ListAgentActivities(ListAgentActivitiesRequest) returns (ListAgentActivitiesResponse);
  // RequestHumanGate records an owner-decision wait and safe interaction/governance refs.
  rpc RequestHumanGate(RequestHumanGateRequest) returns (HumanGateRequestResponse);
  // RecordHumanGateDecision records a normalized owner decision outcome.
  rpc RecordHumanGateDecision(RecordHumanGateDecisionRequest) returns (HumanGateRequestResponse);
  // GetHumanGateRequest returns one owner-decision wait.
  rpc GetHumanGateRequest(GetHumanGateRequestRequest) returns (HumanGateRequestResponse);
  // ListHumanGateRequests returns owner-decision waits by session, run, stage or state.
  rpc ListHumanGateRequests(ListHumanGateRequestsRequest) returns (ListHumanGateRequestsResponse);
  // GetAgentSession returns authoritative session state.
  rpc GetAgentSession(GetAgentSessionRequest) returns (AgentSessionResponse);
  // ListAgentSessions returns safe session summaries for operator read surfaces.
  rpc ListAgentSessions(ListAgentSessionsRequest) returns (ListAgentSessionsResponse);
  // ListAgentRuns returns agent runs by session, role, status or provider target.
  rpc ListAgentRuns(ListAgentRunsRequest) returns (ListAgentRunsResponse);
  // ListAgentRunSummaries returns safe run summaries for operator read surfaces.
  rpc ListAgentRunSummaries(ListAgentRunSummariesRequest) returns (ListAgentRunSummariesResponse);
  // CreateSelfDeployPlan records a safe pending plan for self-deploy orchestration.
  rpc CreateSelfDeployPlan(CreateSelfDeployPlanRequest) returns (SelfDeployPlanResponse);
  // CreateSelfDeployPlanFromSignal records a pending plan from a safe provider/project signal.
  rpc CreateSelfDeployPlanFromSignal(CreateSelfDeployPlanFromSignalRequest) returns (SelfDeployPlanResponse);
  // GetSelfDeployPlan returns one safe self-deploy plan.
  rpc GetSelfDeployPlan(GetSelfDeployPlanRequest) returns (SelfDeployPlanResponse);
  // ListSelfDeployPlans returns safe self-deploy plans by project, repository, signal or status.
  rpc ListSelfDeployPlans(ListSelfDeployPlansRequest) returns (ListSelfDeployPlansResponse);
}

// CommandMeta is required for every mutating command.
message CommandMeta {
  // command_id is a unique command identifier. Either command_id or idempotency_key is required.
  optional string command_id = 1;
  // idempotency_key is an idempotency key scoped by operation and actor.
  optional string idempotency_key = 2;
  // expected_version is present only for existing aggregate mutations.
  optional int64 expected_version = 3;
  // actor is the authenticated caller.
  Actor actor = 4;
  // reason is a machine or operator reason for audit and domain events.
  string reason = 5;
  // request_id links the command to logs, traces and audit.
  string request_id = 6;
  // request_context carries safe request metadata; no tokens, secrets, email or names.
  RequestContext request_context = 7;
}

// QueryMeta carries safe metadata for authoritative reads.
message QueryMeta {
  // actor is the authenticated caller.
  Actor actor = 1;
  // request_id links the read to logs and traces.
  string request_id = 2;
  // request_context carries safe request metadata.
  RequestContext request_context = 3;
}

// RequestContext is safe request metadata used for audit and diagnostics.
message RequestContext {
  // source identifies caller surface, for example staff-gateway, platform-mcp-server or service.
  string source = 1;
  // trace_id links platform traces.
  optional string trace_id = 2;
  // session_id links a user session when available.
  optional string session_id = 3;
  // client_ip_hash is an optional hashed client address.
  optional string client_ip_hash = 4;
}

// Actor identifies a user, service, agent or external account.
message Actor {
  // type is a subject type such as user, service, agent or external_account.
  string type = 1;
  // id is the subject identifier in its owner domain.
  string id = 2;
}

// PageRequest limits list responses.
message PageRequest {
  // page_size is the maximum item count requested by caller.
  int32 page_size = 1;
  // page_token is an opaque continuation token returned by a previous call.
  optional string page_token = 2;
}

// PageResponse describes list continuation state.
message PageResponse {
  // next_page_token is empty when there are no more items.
  optional string next_page_token = 1;
}

// LocalizedText carries text for one locale.
message LocalizedText {
  // locale is a BCP 47 locale code, for example ru or en-US.
  string locale = 1;
  // text is localized display text.
  string text = 2;
}

// ScopeRef identifies where a flow, role, session or automation applies.
message ScopeRef {
  // type classifies the scope.
  AgentScopeType type = 1;
  // ref is an external scope identifier owned by another domain.
  string ref = 2;
}

// ProviderTargetRef points to provider-native artifacts without copying their state.
message ProviderTargetRef {
  // work_item_ref points to Issue or another provider-native work item projection.
  optional string work_item_ref = 1;
  // pull_request_ref points to PR/MR projection when available.
  optional string pull_request_ref = 2;
  // comment_ref points to a provider comment projection when available.
  optional string comment_ref = 3;
  // review_signal_ref points to a provider review signal when available.
  optional string review_signal_ref = 4;
}

// GovernanceContextRef указывает на факты governance-manager без копирования тела решений.
message GovernanceContextRef {
  // risk_assessment_ref указывает на состояние оценки риска.
  optional string risk_assessment_ref = 1;
  // gate_request_ref указывает на состояние запроса gate.
  optional string gate_request_ref = 2;
  // gate_decision_ref указывает на состояние решения gate.
  optional string gate_decision_ref = 3;
  // release_decision_package_ref указывает на пакет evidence для release decision.
  optional string release_decision_package_ref = 4;
  // release_decision_ref указывает на состояние release decision.
  optional string release_decision_ref = 5;
  // risk_profile_ref указывает на risk policy profile, применённый к факту.
  optional string risk_profile_ref = 6;
  // gate_policy_ref указывает на gate policy, потребовавшую решение владельца.
  optional string gate_policy_ref = 7;
  // release_policy_ref указывает на release policy из project-catalog.
  optional string release_policy_ref = 8;
}

// RuntimeContextRef points to runtime state owned by runtime-manager.
message RuntimeContextRef {
  // slot_ref points to runtime slot state.
  optional string slot_ref = 1;
  // job_ref points to platform job state.
  optional string job_ref = 2;
  // workspace_ref points to workspace materialization state.
  optional string workspace_ref = 3;
  // context_ref is an opaque runtime context reference.
  optional string context_ref = 4;
}

// GuidanceRef fixes one guidance package used in an agent run.
message GuidanceRef {
  // package_installation_ref points to package-hub installation state.
  string package_installation_ref = 1;
  // package_version_ref points to package-hub version state.
  string package_version_ref = 2;
  // manifest_digest identifies the manifest used for the run.
  string manifest_digest = 3;
  // source_ref optionally identifies a materialized source in runtime workspace.
  optional string source_ref = 4;
  // capability_ref is a stable safe ref for realtime hooks and runtime materialization.
  optional string capability_ref = 5;
  // capability_kind classifies the selected capability context, for example guidance.
  optional string capability_kind = 6;
  // package_ref points to package-hub package state.
  optional string package_ref = 7;
  // package_slug is a safe package slug captured for policy/debug displays.
  optional string package_slug = 8;
  // package_version_label is a safe human-readable package version label.
  optional string package_version_label = 9;
  // policy_summary_json carries a bounded safe status summary without manifest payload.
  optional string policy_summary_json = 10;
}

// GuidanceSelectionHint is an untrusted caller hint resolved by agent-manager
// through package-hub before creating immutable GuidanceRef records on a run.
message GuidanceSelectionHint {
  // package_installation_ref optionally narrows selection to an installed guidance package.
  optional string package_installation_ref = 1;
  // package_slug optionally narrows selection by package slug inside the run scope.
  optional string package_slug = 2;
}

// ObjectRef points to object storage without embedding object content.
message ObjectRef {
  // object_uri points to S3-compatible object storage.
  string object_uri = 1;
  // object_digest is a digest used for integrity checks.
  string object_digest = 2;
  // object_size_bytes is optional object size for limits and retention.
  optional int64 object_size_bytes = 3;
}

// AgentScopeType classifies scope ownership.
enum AgentScopeType {
  AGENT_SCOPE_TYPE_UNSPECIFIED = 0;
  AGENT_SCOPE_TYPE_PLATFORM = 1;
  AGENT_SCOPE_TYPE_ORGANIZATION = 2;
  AGENT_SCOPE_TYPE_PROJECT = 3;
  AGENT_SCOPE_TYPE_REPOSITORY = 4;
}

// FlowStatus is the flow lifecycle status.
enum FlowStatus {
  FLOW_STATUS_UNSPECIFIED = 0;
  FLOW_STATUS_DRAFT = 1;
  FLOW_STATUS_ACTIVE = 2;
  FLOW_STATUS_DISABLED = 3;
  FLOW_STATUS_ARCHIVED = 4;
}

// FlowVersionStatus is the immutable flow version lifecycle status.
enum FlowVersionStatus {
  FLOW_VERSION_STATUS_UNSPECIFIED = 0;
  FLOW_VERSION_STATUS_DRAFT = 1;
  FLOW_VERSION_STATUS_ACTIVE = 2;
  FLOW_VERSION_STATUS_SUPERSEDED = 3;
  FLOW_VERSION_STATUS_REJECTED = 4;
}

// StageType classifies stage behavior inside a flow.
enum StageType {
  STAGE_TYPE_UNSPECIFIED = 0;
  STAGE_TYPE_WORK = 1;
  STAGE_TYPE_REVIEW = 2;
  STAGE_TYPE_GATE = 3;
  STAGE_TYPE_RELEASE = 4;
  STAGE_TYPE_OPS = 5;
  STAGE_TYPE_CUSTOM = 6;
}

// RoleKind classifies agent role behavior.
enum RoleKind {
  ROLE_KIND_UNSPECIFIED = 0;
  ROLE_KIND_WORKER = 1;
  ROLE_KIND_REVIEWER = 2;
  ROLE_KIND_GATEKEEPER = 3;
  ROLE_KIND_MANAGER = 4;
  ROLE_KIND_QA = 5;
  ROLE_KIND_OPS = 6;
  ROLE_KIND_CUSTOM = 7;
}

// RoleStatus is the role lifecycle status.
enum RoleStatus {
  ROLE_STATUS_UNSPECIFIED = 0;
  ROLE_STATUS_DRAFT = 1;
  ROLE_STATUS_ACTIVE = 2;
  ROLE_STATUS_DISABLED = 3;
  ROLE_STATUS_ARCHIVED = 4;
}

// PromptKind classifies prompt template purpose.
enum PromptKind {
  PROMPT_KIND_UNSPECIFIED = 0;
  PROMPT_KIND_WORK = 1;
  PROMPT_KIND_REVISE = 2;
  PROMPT_KIND_REVIEW = 3;
  PROMPT_KIND_MANAGER = 4;
  PROMPT_KIND_CUSTOM = 5;
}

// PromptVersionStatus is the prompt template version lifecycle status.
enum PromptVersionStatus {
  PROMPT_VERSION_STATUS_UNSPECIFIED = 0;
  PROMPT_VERSION_STATUS_DRAFT = 1;
  PROMPT_VERSION_STATUS_ACTIVE = 2;
  PROMPT_VERSION_STATUS_SUPERSEDED = 3;
  PROMPT_VERSION_STATUS_REJECTED = 4;
}

// StageRoleBindingKind describes how a role participates in a stage.
enum StageRoleBindingKind {
  STAGE_ROLE_BINDING_KIND_UNSPECIFIED = 0;
  STAGE_ROLE_BINDING_KIND_EXECUTOR = 1;
  STAGE_ROLE_BINDING_KIND_REVIEWER = 2;
  STAGE_ROLE_BINDING_KIND_GATEKEEPER = 3;
  STAGE_ROLE_BINDING_KIND_QA = 4;
  STAGE_ROLE_BINDING_KIND_OBSERVER = 5;
  STAGE_ROLE_BINDING_KIND_CUSTOM = 6;
}

// AgentSessionStatus is the lifecycle status of a logical agent session.
enum AgentSessionStatus {
  AGENT_SESSION_STATUS_UNSPECIFIED = 0;
  AGENT_SESSION_STATUS_OPEN = 1;
  AGENT_SESSION_STATUS_WAITING = 2;
  AGENT_SESSION_STATUS_COMPLETED = 3;
  AGENT_SESSION_STATUS_FAILED = 4;
  AGENT_SESSION_STATUS_CANCELLED = 5;
}

// AgentRunStatus is the lifecycle status of one role run.
enum AgentRunStatus {
  AGENT_RUN_STATUS_UNSPECIFIED = 0;
  AGENT_RUN_STATUS_REQUESTED = 1;
  AGENT_RUN_STATUS_STARTING = 2;
  AGENT_RUN_STATUS_RUNNING = 3;
  AGENT_RUN_STATUS_WAITING = 4;
  AGENT_RUN_STATUS_COMPLETED = 5;
  AGENT_RUN_STATUS_FAILED = 6;
  AGENT_RUN_STATUS_CANCELLED = 7;
}

// AgentRunnerRunState is the bounded status vocabulary accepted from agent-runner.
enum AgentRunnerRunState {
  AGENT_RUNNER_RUN_STATE_UNSPECIFIED = 0;
  AGENT_RUNNER_RUN_STATE_QUEUED = 1;
  AGENT_RUNNER_RUN_STATE_RUNNING = 2;
  AGENT_RUNNER_RUN_STATE_COMPLETED = 3;
  AGENT_RUNNER_RUN_STATE_FAILED = 4;
  AGENT_RUNNER_RUN_STATE_STARTED = 5;
  AGENT_RUNNER_RUN_STATE_CANCELLED = 6;
  AGENT_RUNNER_RUN_STATE_TIMED_OUT = 7;
}

// AgentRunRuntimeObservationState описывает, удалось ли прочитать актуальное состояние runtime.
enum AgentRunRuntimeObservationState {
  AGENT_RUN_RUNTIME_OBSERVATION_STATE_UNSPECIFIED = 0;
  AGENT_RUN_RUNTIME_OBSERVATION_STATE_NOT_CREATED = 1;
  AGENT_RUN_RUNTIME_OBSERVATION_STATE_STORED_REF = 2;
  AGENT_RUN_RUNTIME_OBSERVATION_STATE_LIVE = 3;
  AGENT_RUN_RUNTIME_OBSERVATION_STATE_UNAVAILABLE = 4;
  AGENT_RUN_RUNTIME_OBSERVATION_STATE_CONFLICT = 5;
}

// AgentRuntimeJobStatus отражает безопасный жизненный цикл runtime job для чтения UI/MCP.
enum AgentRuntimeJobStatus {
  AGENT_RUNTIME_JOB_STATUS_UNSPECIFIED = 0;
  AGENT_RUNTIME_JOB_STATUS_PENDING = 1;
  AGENT_RUNTIME_JOB_STATUS_CLAIMED = 2;
  AGENT_RUNTIME_JOB_STATUS_RUNNING = 3;
  AGENT_RUNTIME_JOB_STATUS_SUCCEEDED = 4;
  AGENT_RUNTIME_JOB_STATUS_FAILED = 5;
  AGENT_RUNTIME_JOB_STATUS_CANCELLED = 6;
  AGENT_RUNTIME_JOB_STATUS_TIMED_OUT = 7;
}

// AgentSessionSnapshotKind classifies Codex session state snapshots.
enum AgentSessionSnapshotKind {
  AGENT_SESSION_SNAPSHOT_KIND_UNSPECIFIED = 0;
  AGENT_SESSION_SNAPSHOT_KIND_TURN_CHECKPOINT = 1;
  AGENT_SESSION_SNAPSHOT_KIND_RUN_COMPLETION = 2;
  AGENT_SESSION_SNAPSHOT_KIND_MANUAL_CHECKPOINT = 3;
  AGENT_SESSION_SNAPSHOT_KIND_RECOVERY_CHECKPOINT = 4;
}

// AcceptanceCheckKind classifies acceptance logic.
enum AcceptanceCheckKind {
  ACCEPTANCE_CHECK_KIND_UNSPECIFIED = 0;
  ACCEPTANCE_CHECK_KIND_ARTIFACT = 1;
  ACCEPTANCE_CHECK_KIND_WATERMARK = 2;
  ACCEPTANCE_CHECK_KIND_POLICY = 3;
  ACCEPTANCE_CHECK_KIND_ROLE_RESULT = 4;
  ACCEPTANCE_CHECK_KIND_HUMAN_GATE = 5;
  ACCEPTANCE_CHECK_KIND_FOLLOW_UP = 6;
}

// AcceptanceStatus is the lifecycle status of an acceptance result.
enum AcceptanceStatus {
  ACCEPTANCE_STATUS_UNSPECIFIED = 0;
  ACCEPTANCE_STATUS_PENDING = 1;
  ACCEPTANCE_STATUS_PASSED = 2;
  ACCEPTANCE_STATUS_FAILED = 3;
  ACCEPTANCE_STATUS_WAITING = 4;
  ACCEPTANCE_STATUS_SKIPPED = 5;
}

// FollowUpIntentStatus is the lifecycle status of a follow-up intent.
enum FollowUpIntentStatus {
  FOLLOW_UP_INTENT_STATUS_UNSPECIFIED = 0;
  FOLLOW_UP_INTENT_STATUS_PLANNED = 1;
  FOLLOW_UP_INTENT_STATUS_REQUESTED = 2;
  FOLLOW_UP_INTENT_STATUS_CREATED = 3;
  FOLLOW_UP_INTENT_STATUS_FAILED = 4;
  FOLLOW_UP_INTENT_STATUS_CANCELLED = 5;
  FOLLOW_UP_INTENT_STATUS_UPDATED = 6;
  FOLLOW_UP_INTENT_STATUS_COMMENTED = 7;
  FOLLOW_UP_INTENT_STATUS_REVIEW_SIGNALED = 8;
}

// FollowUpDispatchKind selects the typed provider command for a follow-up intent.
enum FollowUpDispatchKind {
  FOLLOW_UP_DISPATCH_KIND_UNSPECIFIED = 0;
  FOLLOW_UP_DISPATCH_KIND_CREATE_ISSUE = 1;
  FOLLOW_UP_DISPATCH_KIND_UPDATE_ISSUE = 2;
  FOLLOW_UP_DISPATCH_KIND_CREATE_COMMENT = 3;
  FOLLOW_UP_DISPATCH_KIND_UPDATE_COMMENT = 4;
  FOLLOW_UP_DISPATCH_KIND_UPDATE_PULL_REQUEST = 5;
  FOLLOW_UP_DISPATCH_KIND_CREATE_REVIEW_SIGNAL = 6;
}

// AgentActivityKind classifies a safe timeline entry.
enum AgentActivityKind {
  AGENT_ACTIVITY_KIND_UNSPECIFIED = 0;
  AGENT_ACTIVITY_KIND_LIFECYCLE = 1;
  AGENT_ACTIVITY_KIND_TOOL_USE = 2;
  AGENT_ACTIVITY_KIND_TOOL_RESULT = 3;
  AGENT_ACTIVITY_KIND_PERMISSION = 4;
  AGENT_ACTIVITY_KIND_PROVIDER_SIGNAL = 5;
  AGENT_ACTIVITY_KIND_RUNTIME_SIGNAL = 6;
  AGENT_ACTIVITY_KIND_CHECKPOINT = 7;
  AGENT_ACTIVITY_KIND_OTHER = 8;
}

// AgentActivityStatus is the lifecycle status of one timeline entry.
enum AgentActivityStatus {
  AGENT_ACTIVITY_STATUS_UNSPECIFIED = 0;
  AGENT_ACTIVITY_STATUS_PLANNED = 1;
  AGENT_ACTIVITY_STATUS_STARTED = 2;
  AGENT_ACTIVITY_STATUS_SUCCEEDED = 3;
  AGENT_ACTIVITY_STATUS_FAILED = 4;
  AGENT_ACTIVITY_STATUS_DENIED = 5;
  AGENT_ACTIVITY_STATUS_WAITING = 6;
  AGENT_ACTIVITY_STATUS_CANCELLED = 7;
  AGENT_ACTIVITY_STATUS_SKIPPED = 8;
}

// HumanGateStatus is the lifecycle status of a human gate request.
enum HumanGateStatus {
  HUMAN_GATE_STATUS_UNSPECIFIED = 0;
  HUMAN_GATE_STATUS_REQUESTED = 1;
  HUMAN_GATE_STATUS_WAITING = 2;
  HUMAN_GATE_STATUS_RESOLVED = 3;
  HUMAN_GATE_STATUS_FAILED = 4;
  HUMAN_GATE_STATUS_CANCELLED = 5;
}

// HumanGateOutcome is the normalized owner decision used by agent-manager flow state.
enum HumanGateOutcome {
  HUMAN_GATE_OUTCOME_UNSPECIFIED = 0;
  HUMAN_GATE_OUTCOME_NONE = 1;
  HUMAN_GATE_OUTCOME_APPROVE = 2;
  HUMAN_GATE_OUTCOME_REJECT = 3;
  HUMAN_GATE_OUTCOME_REQUEST_CHANGES = 4;
  HUMAN_GATE_OUTCOME_ANSWER = 5;
}

// SelfDeployPlanStatus is the lifecycle status of a self-deploy orchestration plan.
enum SelfDeployPlanStatus {
  SELF_DEPLOY_PLAN_STATUS_UNSPECIFIED = 0;
  SELF_DEPLOY_PLAN_STATUS_PENDING_APPROVAL = 1;
  SELF_DEPLOY_PLAN_STATUS_APPROVED = 2;
  SELF_DEPLOY_PLAN_STATUS_REJECTED = 3;
  SELF_DEPLOY_PLAN_STATUS_CANCELLED = 4;
  SELF_DEPLOY_PLAN_STATUS_FAILED = 5;
}

// SelfDeployRuntimeBuildStatus describes build job dispatch state for an approved self-deploy plan.
enum SelfDeployRuntimeBuildStatus {
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_UNSPECIFIED = 0;
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_NOT_REQUESTED = 1;
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_BLOCKED = 2;
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_REQUESTED = 3;
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_FAILED = 4;
  // PREPARING_CONTEXT means governance approved the plan, but runtime-owned build context refs are not ready yet.
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_PREPARING_CONTEXT = 5;
  SELF_DEPLOY_RUNTIME_BUILD_STATUS_SUCCEEDED = 6;
}

// SelfDeployRuntimeDeployStatus describes deploy job dispatch state for an approved self-deploy plan.
enum SelfDeployRuntimeDeployStatus {
  SELF_DEPLOY_RUNTIME_DEPLOY_STATUS_UNSPECIFIED = 0;
  SELF_DEPLOY_RUNTIME_DEPLOY_STATUS_NOT_REQUESTED = 1;
  SELF_DEPLOY_RUNTIME_DEPLOY_STATUS_BLOCKED = 2;
  SELF_DEPLOY_RUNTIME_DEPLOY_STATUS_REQUESTED = 3;
  SELF_DEPLOY_RUNTIME_DEPLOY_STATUS_FAILED = 4;
  SELF_DEPLOY_RUNTIME_DEPLOY_STATUS_SUCCEEDED = 5;
}

// SelfDeployPathCategory classifies affected paths without storing a raw diff.
enum SelfDeployPathCategory {
  SELF_DEPLOY_PATH_CATEGORY_UNSPECIFIED = 0;
  SELF_DEPLOY_PATH_CATEGORY_SERVICE_SOURCE = 1;
  SELF_DEPLOY_PATH_CATEGORY_SERVICE_CONFIG = 2;
  SELF_DEPLOY_PATH_CATEGORY_DEPLOY_MANIFEST = 3;
  SELF_DEPLOY_PATH_CATEGORY_RUNTIME_CONFIG = 4;
  SELF_DEPLOY_PATH_CATEGORY_DOCUMENTATION = 5;
  SELF_DEPLOY_PATH_CATEGORY_TEST = 6;
  SELF_DEPLOY_PATH_CATEGORY_PLATFORM_POLICY = 7;
  SELF_DEPLOY_PATH_CATEGORY_OTHER = 8;
  SELF_DEPLOY_PATH_CATEGORY_SERVICES_POLICY = 9;
}

// AutomationTriggerKind classifies automation input.
enum AutomationTriggerKind {
  AUTOMATION_TRIGGER_KIND_UNSPECIFIED = 0;
  AUTOMATION_TRIGGER_KIND_SCHEDULE = 1;
  AUTOMATION_TRIGGER_KIND_DOMAIN_EVENT = 2;
  AUTOMATION_TRIGGER_KIND_PROVIDER_SIGNAL = 3;
  AUTOMATION_TRIGGER_KIND_MANUAL = 4;
  AUTOMATION_TRIGGER_KIND_EXTERNAL_CALLBACK = 5;
}

// AutomationStatus is the automation binding lifecycle status.
enum AutomationStatus {
  AUTOMATION_STATUS_UNSPECIFIED = 0;
  AUTOMATION_STATUS_ACTIVE = 1;
  AUTOMATION_STATUS_DISABLED = 2;
  AUTOMATION_STATUS_PAUSED = 3;
}

// Flow is a logical process template in a scope.
message Flow {
  string id = 1;
  ScopeRef scope = 2;
  string slug = 3;
  repeated LocalizedText display_name = 4;
  repeated LocalizedText description = 5;
  optional string icon_object_uri = 6;
  FlowStatus status = 7;
  optional string active_version_id = 8;
  int64 version = 9;
  string created_at = 10;
  string updated_at = 11;
}

// FlowVersion is an immutable flow definition snapshot.
message FlowVersion {
  string id = 1;
  string flow_id = 2;
  int64 version = 3;
  optional string source_ref = 4;
  string definition_digest = 5;
  FlowVersionStatus status = 6;
  repeated Stage stages = 7;
  repeated StageTransition transitions = 8;
  repeated StageRoleBinding stage_role_bindings = 9;
  optional string activated_at = 10;
  string created_at = 11;
}

// Stage is one flow stage.
message Stage {
  string id = 1;
  string flow_version_id = 2;
  string slug = 3;
  StageType stage_type = 4;
  repeated LocalizedText display_name = 5;
  optional string icon_object_uri = 6;
  // required_artifacts_json is bounded policy JSON for expected provider/runtime/package artifacts.
  string required_artifacts_json = 7;
  // acceptance_policy_json is bounded policy JSON for checks, watermarks, gates and transitions.
  string acceptance_policy_json = 8;
  int32 position = 9;
}

// StageTransition is an allowed transition between stages.
message StageTransition {
  string id = 1;
  string flow_version_id = 2;
  optional string from_stage_id = 3;
  string to_stage_id = 4;
  // condition_json is bounded policy JSON for acceptance, gate, branch or manual choices.
  string condition_json = 5;
  optional string follow_up_type = 6;
}

// RoleProfile is an agent role profile.
message RoleProfile {
  string id = 1;
  ScopeRef scope = 2;
  string slug = 3;
  repeated LocalizedText display_name = 4;
  optional string icon_object_uri = 5;
  RoleKind role_kind = 6;
  string runtime_profile = 7;
  repeated string allowed_mcp_tools = 8;
  optional string provider_account_policy_ref = 9;
  RoleStatus status = 10;
  int64 version = 11;
  string created_at = 12;
  string updated_at = 13;
}

// PromptTemplate groups prompt versions for one role and purpose.
message PromptTemplate {
  string id = 1;
  string role_profile_id = 2;
  PromptKind prompt_kind = 3;
  optional string active_version_id = 4;
  int64 version = 5;
  string created_at = 6;
  string updated_at = 7;
}

// PromptTemplateVersion fixes prompt template content and its source.
message PromptTemplateVersion {
  string id = 1;
  string prompt_template_id = 2;
  string role_profile_id = 3;
  PromptKind prompt_kind = 4;
  int64 version = 5;
  optional string source_ref = 6;
  optional ObjectRef template_object = 7;
  string template_digest = 8;
  PromptVersionStatus status = 9;
  string created_at = 10;
  optional string activated_at = 11;
}

// StageRoleBinding links a stage to a role.
message StageRoleBinding {
  string id = 1;
  string stage_id = 2;
  string role_profile_id = 3;
  StageRoleBindingKind binding_kind = 4;
  // launch_policy_json is bounded policy JSON for manual, automatic, parallel and retry launches.
  string launch_policy_json = 5;
  bool required_for_acceptance = 6;
}

// AgentSession is a resumable logical agent context.
message AgentSession {
  string id = 1;
  ScopeRef scope = 2;
  optional string provider_work_item_ref = 3;
  optional string flow_version_id = 4;
  optional string current_stage_id = 5;
  optional string latest_state_snapshot_id = 6;
  AgentSessionStatus status = 7;
  string created_by_actor_ref = 8;
  int64 version = 9;
  string created_at = 10;
  string updated_at = 11;
}

// AgentRun is one role run inside an agent session.
message AgentRun {
  string id = 1;
  string session_id = 2;
  optional string flow_version_id = 3;
  optional string stage_id = 4;
  string role_profile_id = 5;
  int64 role_profile_version = 6;
  string role_profile_digest = 7;
  string prompt_template_version_id = 8;
  string prompt_template_digest = 9;
  RuntimeContextRef runtime_context = 10;
  ProviderTargetRef provider_target = 11;
  repeated GuidanceRef guidance_refs = 12;
  AgentRunStatus status = 13;
  optional string result_summary = 14;
  optional string failure_code = 15;
  int64 version = 16;
  optional string started_at = 17;
  optional string finished_at = 18;
  string created_at = 19;
  string updated_at = 20;
}

// AgentSessionStateSnapshot is metadata for an object-store Codex session state.
message AgentSessionStateSnapshot {
  string id = 1;
  string session_id = 2;
  optional string run_id = 3;
  AgentSessionSnapshotKind snapshot_kind = 4;
  optional int64 turn_index = 5;
  ObjectRef object = 6;
  string captured_at = 7;
  string created_at = 8;
}

// AcceptanceResult records machine, role or human-gate acceptance state.
message AcceptanceResult {
  string id = 1;
  string session_id = 2;
  optional string run_id = 3;
  optional string stage_id = 4;
  AcceptanceCheckKind check_kind = 5;
  AcceptanceStatus status = 6;
  optional string target_ref = 7;
  // details_json is bounded diagnostic JSON without secrets, tokens, email or provider payloads.
  string details_json = 8;
  int64 version = 9;
  string created_at = 10;
  string updated_at = 11;
  GovernanceContextRef governance_context = 12;
}

// FollowUpIntent is an intent to create or update a provider-native work item.
message FollowUpIntent {
  string id = 1;
  string session_id = 2;
  optional string from_stage_id = 3;
  optional string to_stage_id = 4;
  string provider_work_item_type = 5;
  optional string provider_operation_ref = 6;
  FollowUpIntentStatus status = 7;
  optional string instruction_body_digest = 8;
  int64 version = 9;
  string created_at = 10;
  string updated_at = 11;
  // run_id points to the run that produced the follow-up evidence.
  optional string run_id = 12;
  // acceptance_result_id points to the positive machine acceptance result when one exists.
  optional string acceptance_result_id = 13;
  // provider_target contains safe refs to provider-native artifacts.
  ProviderTargetRef provider_target = 14;
  // safe_title is a bounded title for the next provider-native work item.
  optional string safe_title = 15;
  // safe_summary is a bounded summary for the next provider-native work item.
  optional string safe_summary = 16;
  // role_hint is a bounded role hint for the next flow step.
  optional string role_hint = 17;
  // stage_hint is a bounded stage hint for the next flow step.
  optional string stage_hint = 18;
  // idempotency_key is the command idempotency key stored with this intent.
  string idempotency_key = 19;
  GovernanceContextRef governance_context = 20;
}

// AgentActivity is a safe persistent timeline entry owned by agent-manager.
message AgentActivity {
  string id = 1;
  string session_id = 2;
  optional string run_id = 3;
  optional string turn_id = 4;
  optional string tool_use_id = 5;
  AgentActivityKind activity_kind = 6;
  optional string tool_name = 7;
  optional string tool_category = 8;
  AgentActivityStatus status = 9;
  optional string started_at = 10;
  optional string finished_at = 11;
  optional int64 duration_ms = 12;
  optional string safe_summary = 13;
  optional string payload_digest = 14;
  optional string bounded_error = 15;
  // safe_refs_json is bounded JSON object with refs only, never raw payload.
  string safe_refs_json = 16;
  // safe_details_json is bounded JSON object with safe display details only.
  string safe_details_json = 17;
  optional string correlation_id = 18;
  string idempotency_key = 19;
  int64 version = 20;
  string created_at = 21;
  string updated_at = 22;
}

// HumanGateRequest is the authoritative agent-manager wait/result state for an owner decision.
message HumanGateRequest {
  string id = 1;
  string session_id = 2;
  optional string run_id = 3;
  optional string stage_id = 4;
  optional string acceptance_result_id = 5;
  ProviderTargetRef provider_target = 6;
  optional string target_ref = 7;
  string request_kind = 8;
  string reason_code = 9;
  optional string safe_summary = 10;
  optional string interaction_request_ref = 11;
  optional string interaction_response_ref = 12;
  optional string governance_gate_request_ref = 13;
  optional string governance_decision_ref = 14;
  HumanGateStatus status = 15;
  HumanGateOutcome outcome = 16;
  string idempotency_key = 17;
  int64 version = 18;
  string created_at = 19;
  string updated_at = 20;
  optional string resolved_at = 21;
  GovernanceContextRef governance_context = 22;
}

// SelfDeployPlan is a pending safe plan for building or deploying this platform.
message SelfDeployPlan {
  string id = 1;
  ScopeRef scope = 2;
  string project_ref = 3;
  string repository_ref = 4;
  optional string provider_signal_ref = 5;
  string source_ref = 6;
  string merge_commit_sha = 7;
  optional string services_yaml_ref = 8;
  string services_yaml_digest = 9;
  repeated string affected_service_keys = 10;
  repeated SelfDeployPathCategory path_categories = 11;
  repeated kodex.runtime.v1.JobType expected_runtime_job_types = 12;
  GovernanceContextRef governance_context = 13;
  optional string safe_summary = 14;
  string plan_fingerprint = 15;
  string idempotency_key = 16;
  SelfDeployPlanStatus status = 17;
  int64 version = 18;
  string created_at = 19;
  string updated_at = 20;
  repeated SelfDeployRuntimeBuildJobRef runtime_build_jobs = 21;
  SelfDeployRuntimeBuildStatus runtime_build_status = 22;
  optional string runtime_build_plan_fingerprint = 23;
  optional string runtime_build_error_code = 24;
  optional string runtime_build_summary = 25;
  optional string provider_slug = 26;
  optional string repository_full_name = 27;
  optional string provider_repository_id = 28;
  repeated SelfDeployRuntimeBuildContextRef runtime_build_contexts = 29;
  repeated SelfDeployRuntimeDeployJobRef runtime_deploy_jobs = 30;
  SelfDeployRuntimeDeployStatus runtime_deploy_status = 31;
  optional string runtime_deploy_plan_fingerprint = 32;
  optional string runtime_deploy_error_code = 33;
  optional string runtime_deploy_summary = 34;
}

// SelfDeployRuntimeBuildJobRef stores safe runtime-manager refs for one build job.
message SelfDeployRuntimeBuildJobRef {
  string service_key = 1;
  optional string service_ref = 2;
  string runtime_job_ref = 3;
  optional string runtime_job_status = 4;
  optional string build_plan_item_fingerprint = 5;
}

// SelfDeployRuntimeBuildContextRef stores safe runtime-manager refs for one materialized build context.
message SelfDeployRuntimeBuildContextRef {
  string service_key = 1;
  optional string runtime_build_context_ref = 2;
  optional string runtime_build_context_status = 3;
  optional string build_context_ref = 4;
  optional string build_context_digest = 5;
  optional string dockerfile_digest = 6;
  optional string materialization_fingerprint = 7;
  optional string build_plan_item_fingerprint = 8;
  optional string manifest_bundle_digest = 9;
}

// SelfDeployRuntimeDeployJobRef stores safe runtime-manager refs for one deploy job.
message SelfDeployRuntimeDeployJobRef {
  string service_key = 1;
  optional string service_ref = 2;
  string runtime_job_ref = 3;
  optional string runtime_job_status = 4;
  optional string deploy_plan_item_fingerprint = 5;
}

// FlowDefinitionInput is the typed input for immutable flow version creation.
message FlowDefinitionInput {
  repeated StageInput stages = 1;
  repeated StageTransitionInput transitions = 2;
  repeated StageRoleBindingInput stage_role_bindings = 3;
  string definition_digest = 4;
}

message StageInput {
  string slug = 1;
  StageType stage_type = 2;
  repeated LocalizedText display_name = 3;
  optional string icon_object_uri = 4;
  string required_artifacts_json = 5;
  string acceptance_policy_json = 6;
  int32 position = 7;
}

message StageTransitionInput {
  optional string from_stage_slug = 1;
  string to_stage_slug = 2;
  string condition_json = 3;
  optional string follow_up_type = 4;
}

message StageRoleBindingInput {
  string stage_slug = 1;
  string role_profile_id = 2;
  StageRoleBindingKind binding_kind = 3;
  string launch_policy_json = 4;
  bool required_for_acceptance = 5;
}

message CreateFlowRequest {
  CommandMeta meta = 1;
  ScopeRef scope = 2;
  string slug = 3;
  repeated LocalizedText display_name = 4;
  repeated LocalizedText description = 5;
  optional string icon_object_uri = 6;
}

message UpdateFlowRequest {
  CommandMeta meta = 1;
  string flow_id = 2;
  repeated LocalizedText display_name = 3;
  repeated LocalizedText description = 4;
  optional string icon_object_uri = 5;
  optional FlowStatus status = 6;
}

message CreateFlowVersionRequest {
  CommandMeta meta = 1;
  string flow_id = 2;
  optional string source_ref = 3;
  FlowDefinitionInput definition = 4;
}

message ActivateFlowVersionRequest {
  CommandMeta meta = 1;
  string flow_version_id = 2;
}

message GetFlowRequest {
  QueryMeta meta = 1;
  string flow_id = 2;
}

message ListFlowsRequest {
  QueryMeta meta = 1;
  ScopeRef scope = 2;
  optional FlowStatus status = 3;
  PageRequest page = 4;
}

message FlowResponse {
  Flow flow = 1;
  optional FlowVersion active_version = 2;
}

message FlowVersionResponse {
  FlowVersion flow_version = 1;
}

message ListFlowsResponse {
  repeated Flow flows = 1;
  PageResponse page = 2;
}

message CreateRoleProfileRequest {
  CommandMeta meta = 1;
  ScopeRef scope = 2;
  string slug = 3;
  repeated LocalizedText display_name = 4;
  optional string icon_object_uri = 5;
  RoleKind role_kind = 6;
  string runtime_profile = 7;
  repeated string allowed_mcp_tools = 8;
  optional string provider_account_policy_ref = 9;
}

message UpdateRoleProfileRequest {
  CommandMeta meta = 1;
  string role_profile_id = 2;
  repeated LocalizedText display_name = 3;
  optional string icon_object_uri = 4;
  optional RoleKind role_kind = 5;
  optional string runtime_profile = 6;
  repeated string allowed_mcp_tools = 7;
  optional string provider_account_policy_ref = 8;
  optional RoleStatus status = 9;
}

message GetRoleProfileRequest {
  QueryMeta meta = 1;
  string role_profile_id = 2;
}

message ListRoleProfilesRequest {
  QueryMeta meta = 1;
  ScopeRef scope = 2;
  optional RoleKind role_kind = 3;
  optional RoleStatus status = 4;
  PageRequest page = 5;
}

message RoleProfileResponse {
  RoleProfile role_profile = 1;
}

message ListRoleProfilesResponse {
  repeated RoleProfile role_profiles = 1;
  PageResponse page = 2;
}

message GetPromptTemplateRequest {
  QueryMeta meta = 1;
  string prompt_template_id = 2;
}

message ListPromptTemplatesRequest {
  QueryMeta meta = 1;
  string role_profile_id = 2;
  optional PromptKind prompt_kind = 3;
  PageRequest page = 4;
}

message PromptTemplateResponse {
  PromptTemplate prompt_template = 1;
  optional PromptTemplateVersion active_version = 2;
}

message ListPromptTemplatesResponse {
  repeated PromptTemplate prompt_templates = 1;
  PageResponse page = 2;
}

message CreatePromptTemplateVersionRequest {
  CommandMeta meta = 1;
  string role_profile_id = 2;
  PromptKind prompt_kind = 3;
  optional string source_ref = 4;
  optional ObjectRef template_object = 5;
  string template_digest = 6;
}

message ActivatePromptTemplateVersionRequest {
  CommandMeta meta = 1;
  string prompt_template_version_id = 2;
}

message GetPromptTemplateVersionRequest {
  QueryMeta meta = 1;
  string prompt_template_version_id = 2;
}

message ListPromptTemplateVersionsRequest {
  QueryMeta meta = 1;
  string role_profile_id = 2;
  optional PromptKind prompt_kind = 3;
  optional PromptVersionStatus status = 4;
  PageRequest page = 5;
}

message PromptTemplateVersionResponse {
  PromptTemplateVersion prompt_template_version = 1;
}

message ListPromptTemplateVersionsResponse {
  repeated PromptTemplateVersion prompt_template_versions = 1;
  PageResponse page = 2;
}

message StartAgentSessionRequest {
  CommandMeta meta = 1;
  ScopeRef scope = 2;
  optional string provider_work_item_ref = 3;
  optional string flow_version_id = 4;
  optional string current_stage_id = 5;
  string created_by_actor_ref = 6;
}

message StartAgentRunRequest {
  CommandMeta meta = 1;
  string session_id = 2;
  optional string flow_version_id = 3;
  optional string stage_id = 4;
  string role_profile_id = 5;
  string prompt_template_version_id = 6;
  ProviderTargetRef provider_target = 7;
  repeated GuidanceSelectionHint guidance_selection_hints = 8;
}

message RecordRunStateRequest {
  CommandMeta meta = 1;
  string run_id = 2;
  AgentRunStatus status = 3;
  RuntimeContextRef runtime_context = 4;
  ProviderTargetRef provider_target = 5;
  optional string result_summary = 6;
  optional string failure_code = 7;
  optional string started_at = 8;
  optional string finished_at = 9;
  optional string reason_code = 10;
}

message ReportAgentRunStateRequest {
  CommandMeta meta = 1;
  string run_id = 2;
  string session_id = 3;
  string runtime_slot_ref = 4;
  string runtime_job_ref = 5;
  AgentRunnerRunState state = 6;
  optional string safe_summary = 7;
  optional string failure_code = 8;
  optional string diagnostic_digest = 9;
  optional string started_at = 10;
  optional string finished_at = 11;
}

message RecordSessionStateSnapshotRequest {
  CommandMeta meta = 1;
  string session_id = 2;
  optional string run_id = 3;
  AgentSessionSnapshotKind snapshot_kind = 4;
  optional int64 turn_index = 5;
  ObjectRef object = 6;
  string captured_at = 7;
}

message RequestAcceptanceRequest {
  CommandMeta meta = 1;
  string session_id = 2;
  optional string run_id = 3;
  optional string stage_id = 4;
  repeated AcceptanceCheckKind check_kinds = 5;
  optional string target_ref = 6;
  GovernanceContextRef governance_context = 7;
}

message RecordAcceptanceResultRequest {
  CommandMeta meta = 1;
  string acceptance_result_id = 2;
  AcceptanceStatus status = 3;
  optional string target_ref = 4;
  string details_json = 5;
  GovernanceContextRef governance_context = 6;
}

message GetAcceptanceResultRequest {
  QueryMeta meta = 1;
  string acceptance_result_id = 2;
}

message ListAcceptanceResultsRequest {
  QueryMeta meta = 1;
  optional string session_id = 2;
  optional string run_id = 3;
  optional string stage_id = 4;
  optional AcceptanceStatus status = 5;
  PageRequest page = 6;
}

message CreateFollowUpIntentRequest {
  CommandMeta meta = 1;
  string session_id = 2;
  optional string from_stage_id = 3;
  optional string to_stage_id = 4;
  string provider_work_item_type = 5;
  optional string provider_operation_ref = 6;
  optional string instruction_body_digest = 7;
  optional string run_id = 8;
  optional string acceptance_result_id = 9;
  ProviderTargetRef provider_target = 10;
  optional string safe_title = 11;
  optional string safe_summary = 12;
  optional string role_hint = 13;
  optional string stage_hint = 14;
  GovernanceContextRef governance_context = 15;
}

message DispatchFollowUpIntentRequest {
  CommandMeta meta = 1;
  string follow_up_intent_id = 2;
  FollowUpDispatchKind dispatch_kind = 3;
  kodex.providers.v1.ProviderOperationPolicyContext operation_policy_context = 4;
  kodex.providers.v1.ApprovalGateReference approval_gate_ref = 5;
  oneof command {
    FollowUpCreateIssueCommand create_issue = 10;
    FollowUpUpdateIssueCommand update_issue = 11;
    FollowUpCreateCommentCommand create_comment = 12;
    FollowUpUpdateCommentCommand update_comment = 13;
    FollowUpUpdatePullRequestCommand update_pull_request = 14;
    FollowUpCreateReviewSignalCommand create_review_signal = 15;
  }
}

message FollowUpCreateIssueCommand {
  string project_id = 1;
  string repository_id = 2;
  string provider_slug = 3;
  string external_account_id = 4;
  kodex.providers.v1.ProviderTarget repository_target = 5;
  optional string safe_body_hint = 6;
  repeated string labels = 7;
  repeated string assignee_provider_logins = 8;
  optional string milestone = 9;
  optional string watermark_json = 10;
}

message FollowUpUpdateIssueCommand {
  string external_account_id = 1;
  kodex.providers.v1.ProviderTarget target = 2;
  optional string safe_title = 3;
  optional string safe_body_hint = 4;
  kodex.providers.v1.StringListPatch labels = 5;
  kodex.providers.v1.StringListPatch assignee_provider_logins = 6;
  optional string milestone = 7;
  optional string state = 8;
  optional string provider_work_item_type = 9;
  optional string watermark_json = 10;
  optional string expected_provider_version = 11;
}

message FollowUpCreateCommentCommand {
  string external_account_id = 1;
  kodex.providers.v1.ProviderTarget target = 2;
  string safe_body_hint = 3;
}

message FollowUpUpdateCommentCommand {
  string external_account_id = 1;
  kodex.providers.v1.ProviderTarget target = 2;
  string provider_comment_id = 3;
  string safe_body_hint = 4;
  optional string expected_provider_version = 5;
}

message FollowUpUpdatePullRequestCommand {
  string external_account_id = 1;
  kodex.providers.v1.ProviderTarget target = 2;
  optional string safe_title = 3;
  optional string safe_body_hint = 4;
  kodex.providers.v1.StringListPatch labels = 5;
  kodex.providers.v1.StringListPatch assignee_provider_logins = 6;
  optional string milestone = 7;
  optional string state = 8;
  optional string base_branch = 9;
  optional bool maintainer_can_modify = 10;
  optional string watermark_json = 11;
  string expected_provider_version = 12;
}

message FollowUpCreateReviewSignalCommand {
  string external_account_id = 1;
  kodex.providers.v1.ProviderTarget target = 2;
  kodex.providers.v1.ReviewSignalKind kind = 3;
  optional string safe_body_hint = 4;
  repeated kodex.providers.v1.ReviewInlineComment inline_comments = 5;
}

message RecordAgentActivityRequest {
  CommandMeta meta = 1;
  string session_id = 2;
  optional string run_id = 3;
  optional string turn_id = 4;
  optional string tool_use_id = 5;
  AgentActivityKind activity_kind = 6;
  optional string tool_name = 7;
  optional string tool_category = 8;
  AgentActivityStatus status = 9;
  optional string started_at = 10;
  optional string finished_at = 11;
  optional int64 duration_ms = 12;
  optional string safe_summary = 13;
  optional string payload_digest = 14;
  optional string bounded_error = 15;
  string safe_refs_json = 16;
  string safe_details_json = 17;
  optional string correlation_id = 18;
}

message ListAgentActivitiesRequest {
  QueryMeta meta = 1;
  optional string session_id = 2;
  optional string run_id = 3;
  optional AgentActivityKind activity_kind = 4;
  optional AgentActivityStatus status = 5;
  PageRequest page = 6;
}

message RequestHumanGateRequest {
  CommandMeta meta = 1;
  string session_id = 2;
  optional string run_id = 3;
  optional string stage_id = 4;
  optional string acceptance_result_id = 5;
  ProviderTargetRef provider_target = 6;
  optional string target_ref = 7;
  string request_kind = 8;
  string reason_code = 9;
  optional string safe_summary = 10;
  optional string interaction_request_ref = 11;
  optional string governance_gate_request_ref = 12;
  GovernanceContextRef governance_context = 13;
}

message RecordHumanGateDecisionRequest {
  CommandMeta meta = 1;
  string human_gate_request_id = 2;
  HumanGateStatus status = 3;
  HumanGateOutcome outcome = 4;
  optional string safe_summary = 5;
  optional string interaction_request_ref = 6;
  optional string interaction_response_ref = 7;
  optional string governance_gate_request_ref = 8;
  optional string governance_decision_ref = 9;
  GovernanceContextRef governance_context = 10;
}

message GetHumanGateRequestRequest {
  QueryMeta meta = 1;
  string human_gate_request_id = 2;
}

message ListHumanGateRequestsRequest {
  QueryMeta meta = 1;
  optional string session_id = 2;
  optional string run_id = 3;
  optional string stage_id = 4;
  optional HumanGateStatus status = 5;
  optional HumanGateOutcome outcome = 6;
  PageRequest page = 7;
}

message GetAgentSessionRequest {
  QueryMeta meta = 1;
  string session_id = 2;
}

message ListAgentRunsRequest {
  QueryMeta meta = 1;
  optional string session_id = 2;
  optional string role_profile_id = 3;
  optional AgentRunStatus status = 4;
  optional string provider_work_item_ref = 5;
  PageRequest page = 6;
}

message ListAgentSessionsRequest {
  QueryMeta meta = 1;
  optional ScopeRef scope = 2;
  optional AgentSessionStatus status = 3;
  optional string provider_work_item_ref = 4;
  optional string created_by_actor_ref = 5;
  optional string created_after = 6;
  optional string created_before = 7;
  PageRequest page = 8;
}

message ListAgentRunSummariesRequest {
  QueryMeta meta = 1;
  optional ScopeRef scope = 2;
  optional string session_id = 3;
  optional string role_profile_id = 4;
  optional AgentRunStatus status = 5;
  optional string provider_work_item_ref = 6;
  optional string provider_pull_request_ref = 7;
  optional string created_after = 8;
  optional string created_before = 9;
  PageRequest page = 10;
}

message CreateSelfDeployPlanRequest {
  CommandMeta meta = 1;
  ScopeRef scope = 2;
  string project_ref = 3;
  string repository_ref = 4;
  optional string provider_signal_ref = 5;
  string source_ref = 6;
  string merge_commit_sha = 7;
  optional string services_yaml_ref = 8;
  string services_yaml_digest = 9;
  repeated string affected_service_keys = 10;
  repeated SelfDeployPathCategory path_categories = 11;
  repeated kodex.runtime.v1.JobType expected_runtime_job_types = 12;
  GovernanceContextRef governance_context = 13;
  optional string safe_summary = 14;
  optional string provider_slug = 15;
  optional string repository_full_name = 16;
  optional string provider_repository_id = 17;
}

message CreateSelfDeployPlanFromSignalRequest {
  CommandMeta meta = 1;
  ScopeRef scope = 2;
  string project_ref = 3;
  string repository_ref = 4;
  string provider_signal_ref = 5;
  string source_ref = 6;
  string merge_commit_sha = 7;
  optional string services_yaml_ref = 8;
  string services_yaml_digest = 9;
  repeated string affected_service_keys = 10;
  repeated SelfDeployPathCategory path_categories = 11;
  repeated kodex.runtime.v1.JobType expected_runtime_job_types = 12;
  GovernanceContextRef governance_context = 13;
  optional string safe_summary = 14;
  optional string provider_slug = 15;
  optional string repository_full_name = 16;
  optional string provider_repository_id = 17;
}

message GetSelfDeployPlanRequest {
  QueryMeta meta = 1;
  string self_deploy_plan_id = 2;
}

message ListSelfDeployPlansRequest {
  QueryMeta meta = 1;
  optional ScopeRef scope = 2;
  optional string project_ref = 3;
  optional string repository_ref = 4;
  optional string provider_signal_ref = 5;
  optional SelfDeployPlanStatus status = 6;
  PageRequest page = 7;
}

message GetAgentRunRuntimeStatusRequest {
  QueryMeta meta = 1;
  string run_id = 2;
}

message AgentSessionResponse {
  AgentSession session = 1;
  optional AgentSessionStateSnapshot latest_state_snapshot = 2;
}

message AgentRunResponse {
  AgentRun run = 1;
}

message AgentRunRuntimeStatusResponse {
  AgentRun run = 1;
  AgentRunRuntimeStatus runtime_status = 2;
}

message AgentRunRuntimeStatus {
  string run_id = 1;
  AgentRunStatus run_status = 2;
  RuntimeContextRef runtime_context = 3;
  AgentRunRuntimeObservationState observation_state = 4;
  optional string runtime_job_ref = 5;
  AgentRuntimeJobStatus runtime_job_status = 6;
  optional string runtime_job_command_ref = 7;
  optional int64 runtime_job_version = 8;
  optional string runtime_job_created_at = 9;
  optional string runtime_job_started_at = 10;
  optional string runtime_job_finished_at = 11;
  optional string runtime_job_updated_at = 12;
  optional string safe_error_code = 13;
  optional string safe_summary = 14;
  optional string run_started_at = 15;
  optional string run_finished_at = 16;
  string run_updated_at = 17;
  int64 run_version = 18;
  bool human_gate_waiting = 19;
  optional string human_gate_request_ref = 20;
  optional string human_gate_reason_code = 21;
  bool follow_up_waiting = 22;
}

message AgentActivitySummary {
  string activity_id = 1;
  AgentActivityKind activity_kind = 2;
  AgentActivityStatus status = 3;
  optional string tool_name = 4;
  optional string tool_category = 5;
  optional string safe_summary = 6;
  optional string payload_digest = 7;
  optional string bounded_error = 8;
  optional string started_at = 9;
  optional string finished_at = 10;
  string updated_at = 11;
  int64 version = 12;
}

message AgentRunListItem {
  AgentRun run = 1;
  optional string runtime_job_ref = 2;
  AgentRunRuntimeObservationState runtime_observation_state = 3;
  optional string runtime_safe_error_code = 4;
  optional string runtime_safe_summary = 5;
  bool human_gate_waiting = 6;
  optional string human_gate_request_ref = 7;
  optional string human_gate_reason_code = 8;
  bool follow_up_waiting = 9;
  optional AgentActivitySummary latest_activity = 10;
}

message AgentSessionListItem {
  AgentSession session = 1;
  optional string latest_run_id = 2;
  optional AgentRunStatus latest_run_status = 3;
  optional string latest_runtime_job_ref = 4;
  optional string latest_run_safe_summary = 5;
  int32 active_run_count = 6;
  bool human_gate_waiting = 7;
  optional string human_gate_request_ref = 8;
  optional string human_gate_reason_code = 9;
  optional AgentActivitySummary latest_activity = 10;
  bool follow_up_waiting = 11;
  optional string follow_up_ref = 12;
}

message AgentSessionStateSnapshotResponse {
  AgentSessionStateSnapshot snapshot = 1;
  AgentSession session = 2;
}

message AcceptanceResultResponse {
  AcceptanceResult acceptance_result = 1;
}

message ListAcceptanceResultsResponse {
  repeated AcceptanceResult acceptance_results = 1;
  PageResponse page = 2;
}

message FollowUpIntentResponse {
  FollowUpIntent follow_up_intent = 1;
}

message AgentActivityResponse {
  AgentActivity activity = 1;
}

message ListAgentActivitiesResponse {
  repeated AgentActivity activities = 1;
  PageResponse page = 2;
}

message HumanGateRequestResponse {
  HumanGateRequest human_gate_request = 1;
}

message ListHumanGateRequestsResponse {
  repeated HumanGateRequest human_gate_requests = 1;
  PageResponse page = 2;
}

message SelfDeployPlanResponse {
  SelfDeployPlan self_deploy_plan = 1;
}

message ListSelfDeployPlansResponse {
  repeated SelfDeployPlan self_deploy_plans = 1;
  PageResponse page = 2;
}

message ListAgentRunsResponse {
  repeated AgentRun runs = 1;
  PageResponse page = 2;
}

message ListAgentSessionsResponse {
  repeated AgentSessionListItem sessions = 1;
  PageResponse page = 2;
}

message ListAgentRunSummariesResponse {
  repeated AgentRunListItem runs = 1;
  PageResponse page = 2;
}
