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:
@@ -0,0 +1,38 @@
|
||||
import { z } from "zod";
|
||||
|
||||
/** Stable provider identifier accepted at CLI, MCP, and environment boundaries. */
|
||||
export const analysisProviderIdSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(64)
|
||||
.regex(/^[a-z][a-z0-9-]*$/u)
|
||||
.refine((value) => value !== "auto", {
|
||||
message: "auto is reserved for provider selection",
|
||||
});
|
||||
|
||||
/** Explicit provider ID or the deterministic automatic-selection policy. */
|
||||
export const analysisProviderSelectorSchema = z.union([
|
||||
z.literal("auto"),
|
||||
analysisProviderIdSchema,
|
||||
]);
|
||||
|
||||
/** Stable reasons a deep provider cannot participate in target selection. */
|
||||
export const PROVIDER_REJECTION_CODES = [
|
||||
"not_configured",
|
||||
"executable_missing",
|
||||
"runtime_missing",
|
||||
"unsupported_host",
|
||||
"unsupported_version",
|
||||
"target_kind_unsupported",
|
||||
"target_format_unsupported",
|
||||
"architecture_unsupported",
|
||||
"open_options_invalid",
|
||||
"version_unresolved",
|
||||
] as const;
|
||||
|
||||
export type AnalysisProviderSelector = z.infer<
|
||||
typeof analysisProviderSelectorSchema
|
||||
>;
|
||||
|
||||
/** Stable reason a deep provider cannot participate in target selection. */
|
||||
export type ProviderRejectionCode = (typeof PROVIDER_REJECTION_CODES)[number];
|
||||
@@ -1,8 +1,10 @@
|
||||
import { z } from "zod";
|
||||
import { analysisProviderSelectorSchema } from "./providerSelection.js";
|
||||
|
||||
/** Input contract for opening a target with an optional staged snapshot. */
|
||||
export const openBinaryInputSchema = z.object({
|
||||
path: z.string().min(1),
|
||||
provider_id: analysisProviderSelectorSchema.optional(),
|
||||
snapshot_path: z.string().min(1).optional(),
|
||||
});
|
||||
|
||||
|
||||
@@ -405,7 +405,7 @@ export const binarySessionInputSchema = z.object({
|
||||
export const SESSION_TOOL_CONTRACTS = [
|
||||
session(
|
||||
"open_binary",
|
||||
"Open a local executable, application bundle, archive, JavaScript, source map, plist, or analysis database after validation. An optional snapshot v2 is imported atomically and must match the binary identity, concrete provider, and canonical analysis profile exactly; provider resources may still start before an MCP cache replay.",
|
||||
"Open a local executable, application bundle, archive, JavaScript, source map, plist, or analysis database after validation. provider_id selects one deep provider or deterministic auto selection; the binding remains stable until close or an explicit switch, with no failure fallback. An optional snapshot v2 is imported atomically and must match the binary identity, concrete provider, and canonical analysis profile exactly.",
|
||||
openBinaryInputSchema,
|
||||
),
|
||||
session(
|
||||
@@ -415,7 +415,7 @@ export const SESSION_TOOL_CONTRACTS = [
|
||||
),
|
||||
session(
|
||||
"binary_session",
|
||||
"Report provider identity, deterministic capability descriptors, and whether a target is open; open targets include canonical path, format, and kind. Use availability, effects, limits, and limitations before selecting analysis operations.",
|
||||
"Report deterministic deep-provider candidates, host availability, target support, the immutable active binding/profile, capability descriptors, and whether a target is open. Candidate discovery never starts an analysis process; use rejection codes and local diagnostics before choosing provider_id.",
|
||||
binarySessionInputSchema,
|
||||
),
|
||||
session(
|
||||
|
||||
@@ -26,6 +26,11 @@ import { callPathResultSchema } from "../domain/callPath.js";
|
||||
import { staticRuntimeCorrelationResultSchema } from "../domain/staticRuntimeCorrelation.js";
|
||||
import { reconstructionVerificationResultSchema } from "../domain/reconstructionVerification.js";
|
||||
import { analysisErrorProjectionSchema } from "./errorSchemas.js";
|
||||
import { analysisProfileSchema } from "../domain/analysisProfile.js";
|
||||
import {
|
||||
PROVIDER_REJECTION_CODES,
|
||||
type ProviderRejectionCode,
|
||||
} from "./providerSelection.js";
|
||||
|
||||
const resultOf = (schema: z.ZodType) =>
|
||||
evidenceEnvelopeSchema
|
||||
@@ -94,10 +99,72 @@ const providerIdentity = z.object({
|
||||
name: z.string(),
|
||||
version: z.string().nullable(),
|
||||
});
|
||||
const providerRejectionCode: z.ZodType<ProviderRejectionCode> = z.enum(
|
||||
PROVIDER_REJECTION_CODES,
|
||||
);
|
||||
const providerDiagnostics = z.record(z.string(), z.json());
|
||||
const providerAvailability = z.discriminatedUnion("status", [
|
||||
z.object({
|
||||
status: z.literal("available"),
|
||||
code: z.null(),
|
||||
reason: z.null(),
|
||||
diagnostics: providerDiagnostics,
|
||||
}),
|
||||
z.object({
|
||||
status: z.literal("unavailable"),
|
||||
code: providerRejectionCode,
|
||||
reason: z.string().min(1),
|
||||
diagnostics: providerDiagnostics,
|
||||
}),
|
||||
]);
|
||||
const providerTargetSupport = z.discriminatedUnion("status", [
|
||||
z.object({
|
||||
status: z.literal("unknown"),
|
||||
code: z.null(),
|
||||
reason: z.string().min(1),
|
||||
diagnostics: providerDiagnostics,
|
||||
}),
|
||||
z.object({
|
||||
status: z.literal("supported"),
|
||||
code: z.null(),
|
||||
reason: z.null(),
|
||||
diagnostics: providerDiagnostics,
|
||||
}),
|
||||
z.object({
|
||||
status: z.literal("unsupported"),
|
||||
code: z.enum([
|
||||
"target_kind_unsupported",
|
||||
"target_format_unsupported",
|
||||
"architecture_unsupported",
|
||||
]),
|
||||
reason: z.string().min(1),
|
||||
diagnostics: providerDiagnostics,
|
||||
}),
|
||||
]);
|
||||
const sessionProvider = z.object({
|
||||
provider: providerIdentity,
|
||||
providers: z.array(providerIdentity),
|
||||
capabilities: z.array(providerCapability),
|
||||
analysis_provider_binding: z
|
||||
.object({
|
||||
provider: providerIdentity,
|
||||
selection_source: z.enum([
|
||||
"request",
|
||||
"environment",
|
||||
"auto-single-candidate",
|
||||
]),
|
||||
analysis_profile: analysisProfileSchema,
|
||||
})
|
||||
.nullable(),
|
||||
analysis_provider_candidates: z.array(
|
||||
z.object({
|
||||
provider: providerIdentity,
|
||||
availability: providerAvailability,
|
||||
target_support: providerTargetSupport,
|
||||
selected: z.boolean(),
|
||||
capabilities: z.array(providerCapability),
|
||||
}),
|
||||
),
|
||||
tool_availability: z.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user