use schemars::JsonSchema;
use serde::Serialize;
use heddle_cli_render::cli::render::RepositoryContextInfo;
use super::operator::OperatorCommandOutput;
use verbs::{ActionTemplate, AvailableGitRef, RepositoryVerificationState, ThreadSummary};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, JsonSchema)]
#[schemars(rename = "FsKitReadinessSchema")]
pub struct FskitReadinessReport {
pub state: &'static str,
pub backend: &'static str,
pub action: &'static str,
#[serde(skip_serializing_if = "Option::is_none")]
pub settings_url: Option<&'static str>,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadListSchema")]
pub struct ThreadListOutput {
pub output_kind: &'static str,
pub repository_capability: String,
pub repository_label: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub repository_context: Option<RepositoryContextInfo>,
pub storage_model: String,
pub hosted_enabled: bool,
pub threads: Vec<ThreadSummary>,
pub available_git_refs: Vec<AvailableGitRef>,
pub current: Option<String>,
#[serde(rename = "verification")]
pub trust: RepositoryVerificationState,
#[serde(serialize_with = "serialize_empty_action_as_null")]
#[schemars(with = "Option<String>")]
pub recommended_action: String,
pub recommended_action_template: Option<ActionTemplate>,
pub recovery_commands: Vec<String>,
pub recovery_action_templates: Vec<ActionTemplate>,
#[serde(skip)]
#[schemars(skip)]
pub import_guidance: Option<ThreadListImportGuidanceOutput>,
}
#[derive(Serialize, JsonSchema)]
pub struct ThreadListImportGuidanceOutput {
pub current_branch: String,
pub missing_branch_count: usize,
pub missing_branches: Vec<String>,
pub recommended_command: String,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadShowSchema")]
pub struct ThreadShowOutput {
pub output_kind: &'static str,
pub repository_label: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub repository_context: Option<RepositoryContextInfo>,
#[serde(flatten)]
pub summary: ThreadSummary,
#[serde(serialize_with = "serialize_empty_action_as_null")]
#[schemars(with = "Option<String>")]
pub next_action: String,
pub next_action_template: Option<ActionTemplate>,
pub recommended_action_template: Option<ActionTemplate>,
#[serde(rename = "verification")]
pub trust: RepositoryVerificationState,
pub recovery_commands: Vec<String>,
}
fn serialize_empty_action_as_null<S>(
action: &String,
serializer: S,
) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
if action.is_empty() {
serializer.serialize_none()
} else {
serializer.serialize_some(action)
}
}
#[derive(Serialize, JsonSchema)]
pub struct ThreadOpOutput {
pub output_kind: &'static str,
pub status: &'static str,
pub action: &'static str,
pub name: String,
pub message: String,
pub next_action: Option<String>,
pub next_action_template: Option<ActionTemplate>,
pub recommended_action: Option<String>,
pub recommended_action_template: Option<ActionTemplate>,
pub thread: Option<ThreadSummary>,
pub path: Option<String>,
pub execution_path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub fskit_readiness: Option<FskitReadinessReport>,
#[allow(dead_code)]
#[serde(skip_serializing)]
#[schemars(skip)]
pub trust: Option<RepositoryVerificationState>,
}
#[derive(Serialize, JsonSchema)]
pub struct ThreadCurrentOutput {
pub thread: String,
}
#[derive(Clone, Serialize, JsonSchema)]
pub struct ThreadCaptureOutput {
pub state_id: String,
pub created_at: String,
pub intent: Option<String>,
pub confidence: Option<f32>,
pub agent: Option<String>,
pub message: String,
pub summary: Option<ThreadCaptureSummary>,
}
#[derive(Clone, Serialize, JsonSchema)]
pub struct ThreadCaptureSummary {
pub added: usize,
pub modified: usize,
pub deleted: usize,
pub total: usize,
}
#[derive(Serialize, JsonSchema)]
pub struct ThreadRecordOutput {
#[serde(flatten)]
pub operator: OperatorCommandOutput,
pub thread: repo::Thread,
pub changed_path_count: usize,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadCleanupSchema")]
pub struct ThreadCleanupOutput {
#[serde(flatten)]
pub operator: OperatorCommandOutput,
pub dry_run: bool,
pub merged: Vec<DroppedThread>,
pub auto: Vec<DroppedThread>,
pub abandoned: Vec<DroppedThread>,
pub reclaimed_bytes: u64,
pub would_reclaim_bytes: u64,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub skipped: Vec<SkippedThread>,
}
#[derive(Clone, Serialize, JsonSchema)]
#[schemars(rename = "ThreadDroppedSchema")]
pub struct DroppedThread {
pub thread: String,
pub id: String,
pub reason: &'static str,
pub age_seconds: i64,
pub bytes: u64,
pub execution_path: Option<String>,
}
#[derive(Clone, Serialize, JsonSchema)]
#[schemars(rename = "ThreadCleanupSkippedSchema")]
pub struct SkippedThread {
pub thread: String,
pub id: String,
pub reason: &'static str,
pub note: String,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadResolveSchema")]
pub struct ThreadResolveOutput {
#[serde(flatten)]
pub operator: OperatorCommandOutput,
pub thread: String,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadAbsorbSchema")]
pub struct ThreadAbsorbOutput {
pub thread: String,
pub into: String,
pub preview_only: bool,
pub conflicts: Vec<String>,
pub merge_state: Option<String>,
pub message: String,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadApprovalSchema")]
pub struct ApprovalOutput {
pub id: String,
pub repo_path: String,
pub source_thread: String,
pub target_thread: String,
pub source_state: String,
pub approver_user_id: String,
pub note: String,
pub approved_at: u64,
pub expires_at: u64,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadMergeRequirementSchema")]
pub struct UnmetOutput {
pub policy_id: String,
pub kind: String,
pub group_id: String,
pub reason: String,
pub needed: u32,
pub have: u32,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadMergeEligibilitySchema")]
pub struct EligibilityOutput {
pub allowed: bool,
pub unmet: Vec<UnmetOutput>,
pub valid_approvals: Vec<ApprovalOutput>,
}
#[derive(Serialize, JsonSchema)]
#[schemars(rename = "ThreadRevokeApprovalSchema")]
pub struct ApprovalRevokeOutput {
pub output_kind: &'static str,
pub id: String,
pub deleted: bool,
}