using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Unity.Pipeline.Editor.Commands.PackageManager
{
///
/// One package in a list/search/add result — a JSON-friendly projection of
/// UnityEditor.PackageManager.PackageInfo (CLI-203).
///
[Serializable]
public class PackageSummary
{
[JsonProperty("name")] public string Name { get; set; }
[JsonProperty("version")] public string Version { get; set; }
[JsonProperty("displayName")] public string DisplayName { get; set; }
/// Resolved source: Registry, Embedded, Local, Git, BuiltIn, LocalTarball, Unknown.
[JsonProperty("source")] public string Source { get; set; }
[JsonProperty("resolvedPath")] public string ResolvedPath { get; set; }
/// True when the package is a direct manifest dependency (vs. a transitive one).
[JsonProperty("isDirectDependency")] public bool IsDirectDependency { get; set; }
/// True when the package is currently installed/resolved in the project (vs. only
/// available in the registry). Always true for an installed-scope listing.
[JsonProperty("isInstalled")] public bool IsInstalled { get; set; }
}
///
/// Synchronous result of package_list (CLI-203). The command returns the full result in one
/// call for every scope — installed reads the resolved set inline; available/all
/// run a registry query and block until it completes — so listing never uses the trigger-then-poll
/// path that the mutating commands do.
///
[Serializable]
public class PackageListResponse
{
[JsonProperty("success")] public bool Success { get; set; }
/// The scope that was listed: installed | available | all.
[JsonProperty("scope")] public string Scope { get; set; }
[JsonProperty("count")] public int Count { get; set; }
/// The packages in the requested scope.
[JsonProperty("packages")] public List Packages { get; set; }
/// Manifest dependencies (name → version).
[JsonProperty("manifest")] public Dictionary Manifest { get; set; }
[JsonProperty("message")] public string Message { get; set; }
}
///
/// Synchronous result of package_search (CLI-203). Like package_list, the registry
/// query is awaited inside the command, so the matches are returned in one call. Each entry carries
/// so callers can tell which results are already installed.
///
[Serializable]
public class PackageSearchResponse
{
[JsonProperty("success")] public bool Success { get; set; }
/// The search query (empty when listing all available packages).
[JsonProperty("query")] public string Query { get; set; }
[JsonProperty("count")] public int Count { get; set; }
/// The matching packages available in the registry.
[JsonProperty("packages")] public List Packages { get; set; }
[JsonProperty("message")] public string Message { get; set; }
}
///
/// Persisted status of the last async mutating operation (add / remove / resolve), written to a Temp
/// status file that survives the domain reload an add/remove/resolve triggers (CLI-203). Read back
/// verbatim by package_status so a caller can poll an async op — or validate one whose
/// synchronous reply was lost to the reload.
///
[Serializable]
public class PackageStatus
{
/// idle | in_progress | completed | failed.
[JsonProperty("status")] public string Status { get; set; }
/// add | remove | resolve.
[JsonProperty("operation")] public string Operation { get; set; }
/// The operation's subject (identifier/name), when applicable.
[JsonProperty("argument")] public string Argument { get; set; }
[JsonProperty("success")] public bool Success { get; set; }
[JsonProperty("error")] public string Error { get; set; }
[JsonProperty("message")] public string Message { get; set; }
/// The operation triggers a recompile/domain reload; poll recompile_status.
[JsonProperty("requiresRecompile")] public bool RequiresRecompile { get; set; }
/// The added package (add only); null for remove/resolve.
[JsonProperty("package")] public PackageSummary Package { get; set; }
/// Manifest dependencies (name → version) after the operation.
[JsonProperty("manifest")] public Dictionary Manifest { get; set; }
[JsonProperty("startedAt")] public string StartedAt { get; set; }
[JsonProperty("completedAt")] public string CompletedAt { get; set; }
}
///
/// Result of a mutating package command — package_add / package_remove /
/// package_resolve (CLI-203). These are dual-mode: by default the call returns
/// in_progress immediately (poll package_status); with wait=true it blocks and
/// this carries the final completed/failed outcome. It reports the confirm/dry_run
/// gate via / . A successful add/remove
/// leaves a recompile/domain reload in flight () — poll
/// recompile_status to wait for the editor to be ready.
///
[Serializable]
public class PackageMutationResponse
{
[JsonProperty("success")] public bool Success { get; set; }
/// add | remove | resolve.
[JsonProperty("operation")] public string Operation { get; set; }
/// The operation's subject (identifier/name), when applicable.
[JsonProperty("argument")] public string Argument { get; set; }
/// in_progress | completed | dry_run | rejected | failed | busy.
[JsonProperty("status")] public string Status { get; set; }
/// True only when the operation actually mutated the project.
[JsonProperty("applied")] public bool Applied { get; set; }
[JsonProperty("dryRun")] public bool DryRun { get; set; }
/// Human-readable description of the intended/performed change.
[JsonProperty("plan")] public string Plan { get; set; }
/// The operation leaves a recompile/domain reload in flight; poll recompile_status.
[JsonProperty("requiresRecompile")] public bool RequiresRecompile { get; set; }
/// The added package (add only); null for remove/resolve.
[JsonProperty("package")] public PackageSummary Package { get; set; }
/// Manifest dependencies (name → version) after the operation.
[JsonProperty("manifest")] public Dictionary Manifest { get; set; }
[JsonProperty("message")] public string Message { get; set; }
public static PackageMutationResponse InProgress(string operation, string argument, string plan) =>
new PackageMutationResponse
{
Success = true,
Operation = operation,
Argument = argument,
Status = "in_progress",
Applied = true,
Plan = plan,
Message = $"{operation} started. Poll package_status until status is 'completed' or 'failed'."
};
public static PackageMutationResponse Busy(string operation) =>
new PackageMutationResponse
{
Success = false,
Operation = operation,
Status = "busy",
Message = "Another package operation is in progress. Poll package_status, then retry."
};
public static PackageMutationResponse DryRunPreview(string operation, string argument, string plan, string message) =>
new PackageMutationResponse
{
Success = true,
Operation = operation,
Argument = argument,
Status = "dry_run",
DryRun = true,
Plan = plan,
Message = message
};
public static PackageMutationResponse Rejected(string operation, string argument, string message) =>
new PackageMutationResponse
{
Success = false,
Operation = operation,
Argument = argument,
Status = "rejected",
Message = message
};
public static PackageMutationResponse Failed(string operation, string argument, string message) =>
new PackageMutationResponse
{
Success = false,
Operation = operation,
Argument = argument,
Status = "failed",
Message = message
};
}
}