syntax = "proto3";

package antigravity.localharness;

enum NullValue {
  NULL_VALUE = 0;
}

message InputConfig {
  optional string storage_directory = 1;
  optional uint32 port = 2;
  optional string bind_address = 3;
}

message InitializeConversationEvent {
  optional HarnessConfig config = 1;
}

message HarnessConfig {
  optional string cascade_id = 1;
  oneof model_config {
    GeminiConfig gemini_config = 2;
    GemmaConfig gemma_config = 3;
  }
  optional SystemInstructions system_instructions = 4;
  repeated Tool tools = 5;
  optional HarnessSideTools harness_side_tools = 6;
  optional uint32 compaction_threshold = 7;
  repeated Workspace workspaces = 8;
  repeated string skills_paths = 9;
  optional string finish_tool_schema_json = 10;
  optional bytes initial_trajectory = 11;
  optional string app_data_dir = 12;
}

message Workspace {
  oneof workspace_type {
    FilesystemWorkspace filesystem_workspace = 1;
  }
}

message FilesystemWorkspace {
  optional string directory = 1;
}

message GeminiConfig {
  optional string api_key = 1;
  optional string base_url = 2;
  optional string model_name = 3;
  optional string thinking_level = 4;
  optional bool enable_url_context = 5;
  optional bool enable_google_search = 6;
}

message GemmaConfig {
  optional string base_url = 1;
  optional string model_name = 2;
}

message SystemInstructions {
  oneof type {
    CustomSystemInstructions custom = 1;
    AppendedSystemInstructions appended = 2;
  }
}

message CustomSystemInstructions {
  message Part {
    oneof part {
      string text = 1;
    }
  }

  repeated Part part = 1;
}

message AppendedSystemInstructions {
  message Section {
    optional string title = 1;
    optional string content = 2;
  }

  optional string custom_identity = 1;
  repeated Section appended_sections = 2;
}

message Tool {
  optional string name = 1;
  optional string description = 2;
  optional string parameters_json_schema = 3;
  optional string response_json_schema = 4;
}

message HarnessSideTools {
  optional FindToolConfig find = 1;
  optional RunCommandToolConfig run_command = 2;
  optional SubagentsConfig subagents = 3;
  optional UserQuestionsConfig user_questions = 4;
  optional FileEditToolConfig file_edit = 5;
  optional ViewFileToolConfig view_file = 6;
  optional WriteToFileToolConfig write_to_file = 7;
  optional GrepSearchToolConfig grep_search = 8;
  optional ListDirToolConfig list_dir = 9;
  optional PermissionsConfig permissions = 10;
  optional GenerateImageToolConfig generate_image = 11;
}

message FindToolConfig {
  optional bool enabled = 1;
}

message RunCommandToolConfig {
  optional bool enabled = 1;
}

message SubagentsConfig {
  optional bool enabled = 1;
}

message UserQuestionsConfig {
  optional bool enabled = 1;
}

message FileEditToolConfig {
  optional bool enabled = 1;
}

message ViewFileToolConfig {
  optional bool enabled = 1;
}

message WriteToFileToolConfig {
  optional bool enabled = 1;
}

message GrepSearchToolConfig {
  optional bool enabled = 1;
}

message ListDirToolConfig {
  optional bool enabled = 1;
}

message GenerateImageToolConfig {
  optional bool enabled = 1;
  optional string model_name = 2;
}

message PermissionsConfig {
  optional bool enforce_workspace_validation = 1;
}

message OutputConfig {
  optional int32 port = 1;
  optional string api_key = 2;
}

message OutputEvent {
  optional int64 seq_num = 1;
  optional int64 timestamp_micros = 2;
  oneof event {
    StepUpdate step_update = 10;
    TrajectoryStateUpdate trajectory_state_update = 11;
    ToolCall tool_call = 12;
  }
  optional UsageMetadata usage_metadata = 20;
}

message StepUpdate {
  enum State {
    STATE_UNSPECIFIED = 0;
    STATE_ACTIVE = 1;
    STATE_DONE = 2;
    STATE_WAITING_FOR_USER = 3;
    STATE_ERROR = 4;
  }

  enum Source {
    SOURCE_UNSPECIFIED = 0;
    SOURCE_SYSTEM = 1;
    SOURCE_USER = 2;
    SOURCE_MODEL = 3;
  }

  enum Target {
    TARGET_UNSPECIFIED = 0;
    TARGET_USER = 1;
    TARGET_MODEL = 2;
    TARGET_ENVIRONMENT = 3;
  }

  optional string cascade_id = 1;
  optional string trajectory_id = 2;
  optional uint32 step_index = 3;
  optional State state = 4;
  optional Source source = 5;
  optional Target target = 6;
  optional string error_message = 7;
  optional string thinking = 8;
  optional string text_delta = 9;
  optional string thinking_delta = 10;
  optional string text = 20;
  optional ActionListDirectory list_directory = 21;
  optional ActionFindFile find_file = 22;
  optional ActionSearchDirectory search_directory = 23;
  optional ActionViewFile view_file = 24;
  optional ActionCreateFile create_file = 25;
  optional ActionEditFile edit_file = 26;
  optional ActionRunCommand run_command = 27;
  optional ActionCompaction compaction = 28;
  optional ActionInvokeSubagent invoke_subagent = 29;
  optional ActionGenerateImage generate_image = 30;
  optional ActionFinish finish = 31;
  optional ActionError error = 32;
  optional string request_text = 50;
  optional ToolConfirmationRequest tool_confirmation_request = 51;
  optional UserQuestionsRequest questions_request = 52;
}

message ActionGenerateImage {
  optional string prompt = 1;
  repeated string image_paths = 2;
  optional string image_name = 3;
}

message ActionFinish {
  optional string output_string = 1;
}

message ActionError {
  optional string error_message = 1;
  optional uint32 http_code = 2;
}

message ActionListDirectory {
  message Result {
    optional string name = 1;
    oneof info {
      bool is_directory = 2;
      uint64 file_size = 3;
    }
  }

  optional string directory_path = 1;
  repeated Result results = 2;
}

message ActionFindFile {
  optional string directory_path = 1;
  optional string query = 2;
  optional string output = 3;
}

message ActionSearchDirectory {
  optional string directory_path = 1;
  optional string query = 2;
  optional int32 num_results = 3;
}

message ActionViewFile {
  optional string file_path = 1;
  optional uint32 start_line = 2;
  optional uint32 end_line = 3;
}

message ActionCreateFile {
  optional string file_path = 1;
  optional string contents = 2;
}

message ActionEditFile {
  message DiffLine {
    enum LineAction {
      LINE_ACTION_UNSPECIFIED = 0;
      LINE_ACTION_INSERT = 1;
      LINE_ACTION_DELETE = 2;
      LINE_ACTION_NONE = 3;
    }

    optional string text = 1;
    optional LineAction action = 2;
  }

  message DiffBlock {
    optional int32 start_line = 1;
    optional int32 end_line = 2;
    repeated DiffLine lines = 3;
  }

  optional string file_path = 1;
  repeated DiffBlock diff_block = 2;
}

message ActionRunCommand {
  optional string command_line = 1;
  optional string working_dir = 2;
  optional int32 exit_code = 4;
  optional string combined_output = 5;
}

message ActionCompaction {
}

message ActionInvokeSubagent {
}

message ToolConfirmationRequest {
}

message UserQuestionsRequest {
  repeated UserQuestion questions = 1;
}

message UserQuestion {
  oneof question_type {
    MultipleChoice multiple_choice = 1;
  }
}

message MultipleChoice {
  optional string question = 1;
  repeated string choices = 2;
  optional bool is_multi_select = 3;
}

message InputEvent {
  oneof event {
    string user_input = 1;
    UserInput complex_user_input = 7;
    ToolConfirmation tool_confirmation = 2;
    ToolResponse tool_response = 3;
    UserQuestionsResponse question_response = 4;
    bool halt_request = 5;
    string automated_trigger = 6;
  }
}

message UserInput {
  message Media {
    optional string mime_type = 1;
    optional string description = 2;
    optional bytes data = 3;
  }

  message Part {
    oneof part {
      string text = 1;
      Media media = 2;
    }
  }

  repeated Part parts = 1;
}

message ToolConfirmation {
  optional string trajectory_id = 1;
  optional uint32 step_index = 2;
  optional bool accepted = 3;
}

message TrajectoryStateUpdate {
  enum State {
    STATE_UNSPECIFIED = 0;
    STATE_RUNNING = 1;
    STATE_IDLE = 2;
  }

  optional string trajectory_id = 2;
  optional State state = 3;
}

message Struct {
  repeated Field fields = 1;
}

message Field {
  optional string name = 1;
  optional Value value = 2;
}

message Value {
  oneof kind {
    NullValue null_value = 1;
    double number_value = 2;
    string string_value = 3;
    bool bool_value = 4;
    Struct struct_value = 5;
    ListValue list_value = 6;
    Media media = 7;
  }
}

message ListValue {
  repeated Value values = 1;
}

message ToolCall {
  optional string id = 1;
  optional string name = 2;
  optional string arguments_json = 3;
  optional Struct arguments = 4;
}

message ToolResponse {
  optional string id = 1;
  optional string response_json = 2;
  repeated Media supplemental_media = 3;
  optional Struct response = 4;
}

message UserQuestionsResponse {
  message QuestionsResponse {
    repeated UserQuestionAnswer answers = 1;
  }

  optional string trajectory_id = 1;
  optional uint32 step_index = 2;
  oneof result {
    bool cancelled = 3;
    QuestionsResponse response = 4;
  }
}

message UserQuestionAnswer {
  oneof answer {
    bool unanswered = 1;
    MultipleChoiceAnswer multiple_choice_answer = 2;
  }
}

message MultipleChoiceAnswer {
  repeated int32 selected_choice_indices = 1;
  optional string freeform_response = 2;
}

message Media {
  optional string mime_type = 1;
  optional string description = 2;
  optional bytes data = 3;
}

message UsageMetadata {
  optional int32 prompt_token_count = 1;
  optional int32 cached_content_token_count = 5;
  optional int32 candidates_token_count = 2;
  optional int32 thoughts_token_count = 4;
  optional int32 total_token_count = 3;
}

