feat(session): add explicit provider registry and target binding

Introduce deterministic deep-provider discovery and immutable per-target routing while retaining disjoint artifact and native capability families.

Expose provider selection consistently through MCP, CLI, environment configuration, session status, prompt completion, typed diagnostics, and generated documentation. Preserve exact provider/profile provenance without request racing or transparent fallback.

Cover overlapping providers, ambiguity, rejection details, cancellation, restoration, package installation, and real Hopper target switching.
This commit is contained in:
N0zoM1z0
2026-07-15 22:13:48 +09:00
committed by N0zoM1z0
parent bd3cf964d6
commit 941d7101dd
174 changed files with 5370 additions and 648 deletions
+107 -3
View File
@@ -122,15 +122,96 @@ export class AnalysisTimeoutError extends AnalysisError {
}
}
/** No configured provider can satisfy a requested operation. */
/** Stable failure classes for target-bound deep-provider selection. */
export type ProviderSelectionFailureReason =
| "unknown_provider"
| "provider_unavailable"
| "target_unsupported"
| "ambiguous"
| "invalid_options";
/** One actionable candidate rejection retained in caller diagnostics. */
export interface ProviderSelectionRejection {
readonly providerId: string;
readonly code: string;
readonly reason: string;
readonly diagnostics: Readonly<Record<string, JsonValue>>;
}
/** Complete typed context for one failed deep-provider selection. */
export interface ProviderSelectionErrorOptions {
readonly operation?: string;
readonly reason: ProviderSelectionFailureReason;
readonly requestedProviderId: string;
readonly candidateIds: readonly string[];
readonly rejections?: readonly ProviderSelectionRejection[];
}
/** No configured provider can satisfy a requested operation or target binding. */
export class ProviderSelectionError extends AnalysisError {
readonly _tag = "ProviderSelectionError";
readonly operation: string;
readonly reason: ProviderSelectionFailureReason;
readonly requestedProviderId: string;
readonly candidateIds: readonly string[];
readonly rejections: readonly ProviderSelectionRejection[];
override readonly userMessage: string;
constructor(readonly operation: string) {
super(`No configured provider can execute ${operation}`);
constructor(input: string | ProviderSelectionErrorOptions) {
const legacy = typeof input === "string";
const options: ProviderSelectionErrorOptions = legacy
? {
operation: input,
reason: "provider_unavailable",
requestedProviderId: "auto",
candidateIds: [],
}
: input;
const operation = options.operation ?? "open_binary";
super(
legacy
? `No configured provider can execute ${operation}`
: providerSelectionDiagnostic(options),
);
this.operation = operation;
this.reason = options.reason;
this.requestedProviderId = options.requestedProviderId;
this.candidateIds = [...options.candidateIds];
this.rejections = [...(options.rejections ?? [])].map((rejection) => ({
...rejection,
diagnostics: structuredClone(rejection.diagnostics),
}));
this.userMessage = providerSelectionUserMessage(options);
}
}
const providerSelectionDiagnostic = (
options: ProviderSelectionErrorOptions,
): string => {
const candidates =
options.candidateIds.length === 0
? "none"
: options.candidateIds.join(", ");
return `Analysis provider selection failed (${options.reason}) for ${options.requestedProviderId}; candidates: ${candidates}`;
};
const providerSelectionUserMessage = (
options: ProviderSelectionErrorOptions,
): string => {
switch (options.reason) {
case "ambiguous":
return "Multiple analysis providers support this target. Choose one with provider_id, --provider, or REA_ANALYSIS_PROVIDER.";
case "unknown_provider":
return `The requested analysis provider is unknown. Choose one of: ${options.candidateIds.join(", ") || "no configured providers"}.`;
case "provider_unavailable":
return "The selected analysis provider is unavailable. Review the reported local diagnostics or run `rea doctor`, then retry.";
case "target_unsupported":
return "The selected analysis provider does not support this target. Choose another provider or open a supported extracted binary.";
case "invalid_options":
return "The analysis provider selection or open options are invalid. Correct them and try again.";
}
};
/** A provider adapter failed outside its more precise typed variants. */
export class ProviderAdapterError extends AnalysisError {
readonly _tag = "ProviderAdapterError";
@@ -459,6 +540,11 @@ export const projectAnalysisError = (
const errorCode = (error: AnalysisError): AnalysisErrorProjection["code"] => {
if (error instanceof PermissionRequiredError) return "permission_required";
if (
error instanceof ProviderSelectionError &&
error.reason === "provider_unavailable"
)
return "provider_unavailable";
if (error instanceof BrowserObservationError) {
if (error.reason === "payload_limit") return "truncated";
if (
@@ -602,6 +688,19 @@ const errorDetails = (
return { operation: error.operation, reason: error.reason };
if (error instanceof AnalysisCapabilityUnavailableError)
return { provider_id: error.providerId, operation: error.operation };
if (error instanceof ProviderSelectionError)
return {
operation: error.operation,
selection_reason: error.reason,
requested_provider_id: error.requestedProviderId,
candidate_ids: [...error.candidateIds],
rejections: error.rejections.map((rejection) => ({
provider_id: rejection.providerId,
code: rejection.code,
reason: rejection.reason,
diagnostics: rejection.diagnostics,
})),
};
if (error instanceof ProviderAdapterError)
return { provider_id: error.providerId, operation: error.operation };
if (error instanceof BrowserObservationError)
@@ -670,6 +769,11 @@ const errorCategory = (
error: AnalysisError,
): AnalysisErrorProjection["category"] => {
if (error instanceof PermissionRequiredError) return "permission_required";
if (
error instanceof ProviderSelectionError &&
error.reason === "provider_unavailable"
)
return "unavailable";
if (error._tag === "ProcessCaptureError")
return error.userCategory ?? "execution_failure";
if (error instanceof BrowserObservationError) {