feat: streamline agent integration and MCP routing
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import type { ToolContract } from "./toolContracts.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
import { evidenceResultOf } from "./toolOutputSchemas.js";
|
||||
@@ -11,6 +13,8 @@ import {
|
||||
analyzeJavaScriptApplicationInputSchema,
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
} from "../domain/javascriptApplicationAnalysis.js";
|
||||
import { JAVASCRIPT_APPLICATION_NODE_KINDS } from "../domain/javascriptApplicationGraphSchemas.js";
|
||||
import { applicationCoverageSchema } from "../domain/javascriptApplicationEvidenceSchemas.js";
|
||||
import {
|
||||
javascriptRuntimeReconciliationResultSchema,
|
||||
reconcileJavaScriptRuntimeInputSchema,
|
||||
@@ -19,8 +23,62 @@ import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "./javascriptRuntimeRe
|
||||
|
||||
const listOutputSchema = evidenceResultOf(electronTargetListSchema);
|
||||
const inspectionOutputSchema = evidenceResultOf(electronPageInspectionSchema);
|
||||
/** MCP-only response selection; analysis identity does not depend on projection. */
|
||||
export const analyzeJavaScriptApplicationToolInputSchema =
|
||||
analyzeJavaScriptApplicationInputSchema.extend({
|
||||
detail: z
|
||||
.enum(["summary", "full"])
|
||||
.default("summary")
|
||||
.describe(
|
||||
"summary returns bounded findings and paged graph resource URIs; full returns the complete graph only when explicitly required",
|
||||
),
|
||||
});
|
||||
|
||||
/** Bounded default projection for agent-facing JavaScript application analysis. */
|
||||
export const javascriptApplicationAnalysisSummarySchema =
|
||||
javascriptApplicationAnalysisResultSchema.omit({ graph: true }).extend({
|
||||
unknowns: z.array(z.string().min(1).max(4_096)).max(1_000),
|
||||
graph: z.strictObject({
|
||||
graph_id: z.string().regex(/^jag_[a-f0-9]{64}$/u),
|
||||
node_count: z.number().int().min(0),
|
||||
edge_count: z.number().int().min(0),
|
||||
roots: z.strictObject({
|
||||
items: z.array(z.string().regex(/^jag_node_[a-f0-9]{64}$/u)),
|
||||
total: z.number().int().min(0),
|
||||
truncated: z.boolean(),
|
||||
}),
|
||||
node_kinds: z.array(
|
||||
z.strictObject({
|
||||
kind: z.enum(JAVASCRIPT_APPLICATION_NODE_KINDS),
|
||||
count: z.number().int().min(1),
|
||||
}),
|
||||
),
|
||||
top_findings: z.array(
|
||||
z.strictObject({
|
||||
node_id: z.string().regex(/^jag_node_[a-f0-9]{64}$/u),
|
||||
kind: z.enum(JAVASCRIPT_APPLICATION_NODE_KINDS),
|
||||
label: z.string().nullable(),
|
||||
authority: z.string(),
|
||||
state: z.string(),
|
||||
confidence: z.string(),
|
||||
location: z.json(),
|
||||
}),
|
||||
),
|
||||
coverage: applicationCoverageSchema,
|
||||
limitations: z.array(z.string()),
|
||||
pages: z.strictObject({
|
||||
nodes: z.string().startsWith("rea://evidence/"),
|
||||
edges: z.string().startsWith("rea://evidence/"),
|
||||
page_limit: z.number().int().min(1).max(500),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
const applicationOutputSchema = evidenceResultOf(
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
z.union([
|
||||
javascriptApplicationAnalysisSummarySchema,
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
]),
|
||||
);
|
||||
const reconciliationOutputSchema = evidenceResultOf(
|
||||
javascriptRuntimeReconciliationResultSchema,
|
||||
@@ -88,9 +146,9 @@ export const ELECTRON_TOOL_CONTRACTS = [
|
||||
name: "analyze_javascript_application",
|
||||
...toolContractMetadata("analyze_javascript_application"),
|
||||
description:
|
||||
"Statically reconstruct one approved local ASAR or extracted JavaScript application as Evidence v2 and JavaScript Application Graph v1. Maps BrowserWindow preferences, preload and contextBridge APIs, literal and dynamic IPC, handler locations, sender-validation observations, utility processes, and requested native addon bindings without executing JavaScript; source-map contents require separate approval.",
|
||||
"Statically reconstruct one approved local ASAR or extracted JavaScript application without executing it. The default summary returns architecture/security counts, top evidence-backed findings, unknowns, and paged graph resource URIs; request detail=full only when the complete graph must be returned immediately. Identical inputs are deterministic, so do not repeat the call or reread full Evidence without a specific missing detail.",
|
||||
kind: "electron-provider",
|
||||
inputSchema: analyzeJavaScriptApplicationInputSchema,
|
||||
inputSchema: analyzeJavaScriptApplicationToolInputSchema,
|
||||
outputSchema: applicationOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
@@ -100,6 +158,7 @@ export const ELECTRON_TOOL_CONTRACTS = [
|
||||
format: "auto",
|
||||
approved: true,
|
||||
source_map_read_approved: false,
|
||||
detail: "summary",
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -6,6 +6,13 @@ import { toolContractMetadata } from "./toolEffects.js";
|
||||
|
||||
/** Exact caller boundary for execution-free PE/CLI triage and identity. */
|
||||
export const managedArtifactInputSchema = z.object({
|
||||
path: z
|
||||
.string()
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe(
|
||||
"Managed PE/CLI path to open before inspection; omit only when a managed target is already active",
|
||||
),
|
||||
reference_offset: z.number().int().min(0).default(0),
|
||||
reference_limit: z.number().int().min(1).max(500).default(100),
|
||||
resource_offset: z.number().int().min(0).default(0),
|
||||
@@ -122,14 +129,14 @@ export const MANAGED_TOOL_CONTRACTS = [
|
||||
name: "inspect_managed_artifact",
|
||||
...toolContractMetadata("inspect_managed_artifact"),
|
||||
description:
|
||||
"Classify the active PE/CLI artifact and inventory exact assembly/module identity, target framework evidence, references, resources, and custom attributes without loading or executing target code. Returns bounded pages and explicit partial or malformed coverage.",
|
||||
"Open and classify an explicit managed PE/CLI path, or inspect the active managed target, then inventory exact assembly/module identity, target framework evidence, references, resources, and custom attributes without loading or executing target code. Returns bounded pages and explicit partial or malformed coverage.",
|
||||
kind: "managed-provider",
|
||||
inputSchema: managedArtifactInputSchema,
|
||||
outputSchema,
|
||||
examples: [
|
||||
{
|
||||
title: "Example inspect managed artifact request",
|
||||
input: {},
|
||||
input: { path: "/tmp/Example.dll" },
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { z } from "zod";
|
||||
|
||||
/** Caller observations and projection controls for binary_session. */
|
||||
export const binarySessionInputSchema = z.object({
|
||||
detail: z
|
||||
.enum(["summary", "capabilities", "full"])
|
||||
.default("summary")
|
||||
.describe(
|
||||
"summary returns routing state; capabilities returns one filtered tool-availability page; full returns complete diagnostics only when required",
|
||||
),
|
||||
capability_family: z
|
||||
.enum([
|
||||
"official-proxy",
|
||||
"enhanced",
|
||||
"native-provider",
|
||||
"artifact-provider",
|
||||
"managed-provider",
|
||||
"browser-provider",
|
||||
"electron-provider",
|
||||
"application",
|
||||
"session",
|
||||
])
|
||||
.optional()
|
||||
.describe("Optional tool family for detail=capabilities"),
|
||||
cursor: z
|
||||
.number()
|
||||
.int()
|
||||
.min(0)
|
||||
.default(0)
|
||||
.describe("Zero-based capability cursor for detail=capabilities"),
|
||||
limit: z.number().int().min(1).max(100).default(25),
|
||||
expected_package_version: z.string().min(1).optional(),
|
||||
expected_catalog_digest: z
|
||||
.string()
|
||||
.regex(/^[a-f0-9]{64}$/u)
|
||||
.optional(),
|
||||
expected_server_path: z.string().min(1).optional(),
|
||||
});
|
||||
@@ -34,6 +34,9 @@ import {
|
||||
} from "./sessionLifecycleInputs.js";
|
||||
import type { ToolContract, ToolExample } from "./toolContractTypes.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
import { binarySessionInputSchema } from "./sessionStatusContract.js";
|
||||
|
||||
export { binarySessionInputSchema } from "./sessionStatusContract.js";
|
||||
|
||||
export type { ToolContract, ToolExample } from "./toolContractTypes.js";
|
||||
|
||||
@@ -366,16 +369,6 @@ export const ENHANCED_TOOL_CONTRACTS = [
|
||||
),
|
||||
] as const satisfies readonly ToolContract[];
|
||||
|
||||
/** Caller observations used to compare a live server with expected identity. */
|
||||
export const binarySessionInputSchema = z.object({
|
||||
expected_package_version: z.string().min(1).optional(),
|
||||
expected_catalog_digest: z
|
||||
.string()
|
||||
.regex(/^[a-f0-9]{64}$/u)
|
||||
.optional(),
|
||||
expected_server_path: z.string().min(1).optional(),
|
||||
});
|
||||
|
||||
/** Session-owned Evidence bundle export options. */
|
||||
export const exportEvidenceBundleInputSchema = z.strictObject({
|
||||
path: z.string().min(1).optional(),
|
||||
@@ -426,7 +419,7 @@ export const SESSION_TOOL_CONTRACTS = [
|
||||
),
|
||||
session(
|
||||
"binary_session",
|
||||
"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.",
|
||||
"Report compact target, provider, and alignment state without starting analysis. The default summary is the routing check agents should use; detail=capabilities returns one family-filtered availability page, while detail=full is reserved for complete provider diagnostics.",
|
||||
binarySessionInputSchema,
|
||||
),
|
||||
session(
|
||||
|
||||
@@ -52,6 +52,8 @@ import {
|
||||
searchPageOutput,
|
||||
segmentOutput,
|
||||
sessionProvider,
|
||||
providerIdentity,
|
||||
toolAvailability,
|
||||
symbolDiscoveryOutput,
|
||||
targetFormatSchema,
|
||||
targetKindSchema,
|
||||
@@ -275,15 +277,57 @@ export const sessionOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
|
||||
),
|
||||
binary_session: lifecycleResultOf(
|
||||
z.union([
|
||||
sessionProvider.extend({ open: z.literal(false) }),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(["x86", "x86_64", "arm", "arm64"]).nullable(),
|
||||
z.object({
|
||||
view: z.literal("summary"),
|
||||
open: z.boolean(),
|
||||
provider: providerIdentity,
|
||||
active_provider: providerIdentity.nullable(),
|
||||
target: z
|
||||
.object({
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(["x86", "x86_64", "arm", "arm64"]).nullable(),
|
||||
})
|
||||
.nullable(),
|
||||
alignment: z.object({
|
||||
state: z.enum(["aligned", "mcp_server_restart_required", "unknown"]),
|
||||
reasons: z.array(z.string()),
|
||||
remediation: z.string().nullable(),
|
||||
}),
|
||||
recommended_actions: z.array(z.string()),
|
||||
}),
|
||||
z.object({
|
||||
view: z.literal("capabilities"),
|
||||
open: z.boolean(),
|
||||
provider: providerIdentity,
|
||||
active_provider: providerIdentity.nullable(),
|
||||
capability_family: z.string().nullable(),
|
||||
capabilities: z.object({
|
||||
items: z.array(toolAvailability),
|
||||
cursor: z.number().int().min(0),
|
||||
limit: z.number().int().min(1),
|
||||
total: z.number().int().min(0),
|
||||
next_cursor: z.number().int().min(0).nullable(),
|
||||
has_more: z.boolean(),
|
||||
}),
|
||||
}),
|
||||
z.union([
|
||||
sessionProvider.extend({
|
||||
view: z.literal("full"),
|
||||
open: z.literal(false),
|
||||
}),
|
||||
sessionProvider.extend({
|
||||
view: z.literal("full"),
|
||||
open: z.literal(true),
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(["x86", "x86_64", "arm", "arm64"]).nullable(),
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
export_evidence_bundle: lifecycleResultOf(
|
||||
|
||||
@@ -85,7 +85,7 @@ const providerCapability = z.object({
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
const providerIdentity = z.object({
|
||||
export const providerIdentity = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
version: z.string().nullable(),
|
||||
@@ -139,6 +139,38 @@ const providerTargetSupport = z.discriminatedUnion("status", [
|
||||
}),
|
||||
]);
|
||||
|
||||
export const toolAvailability = z.object({
|
||||
name: z.string(),
|
||||
surface: z.string(),
|
||||
available: z.boolean(),
|
||||
reason: z.enum([
|
||||
"available",
|
||||
"target_required",
|
||||
"provider_missing",
|
||||
"provider_unavailable",
|
||||
"target_unsupported",
|
||||
"unsupported_host",
|
||||
"policy_disabled",
|
||||
]),
|
||||
remediation: z.string().nullable(),
|
||||
effects: z.strictObject({
|
||||
mutatesTarget: z.boolean(),
|
||||
mutatesSession: z.boolean(),
|
||||
writesFilesystem: z.boolean(),
|
||||
launchesProcess: z.boolean(),
|
||||
accessesNetwork: z.boolean(),
|
||||
changesUiState: z.boolean(),
|
||||
mayDiscardData: z.boolean(),
|
||||
idempotent: z.boolean(),
|
||||
}),
|
||||
annotations: z.object({
|
||||
read_only: z.boolean(),
|
||||
destructive: z.boolean(),
|
||||
idempotent: z.boolean(),
|
||||
open_world: z.boolean(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const sessionProvider = z.object({
|
||||
provider: providerIdentity,
|
||||
providers: z.array(providerIdentity),
|
||||
@@ -163,39 +195,7 @@ export const sessionProvider = z.object({
|
||||
capabilities: z.array(providerCapability),
|
||||
}),
|
||||
),
|
||||
tool_availability: z.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
surface: z.string(),
|
||||
available: z.boolean(),
|
||||
reason: z.enum([
|
||||
"available",
|
||||
"target_required",
|
||||
"provider_missing",
|
||||
"provider_unavailable",
|
||||
"target_unsupported",
|
||||
"unsupported_host",
|
||||
"policy_disabled",
|
||||
]),
|
||||
remediation: z.string().nullable(),
|
||||
effects: z.strictObject({
|
||||
mutatesTarget: z.boolean(),
|
||||
mutatesSession: z.boolean(),
|
||||
writesFilesystem: z.boolean(),
|
||||
launchesProcess: z.boolean(),
|
||||
accessesNetwork: z.boolean(),
|
||||
changesUiState: z.boolean(),
|
||||
mayDiscardData: z.boolean(),
|
||||
idempotent: z.boolean(),
|
||||
}),
|
||||
annotations: z.object({
|
||||
read_only: z.boolean(),
|
||||
destructive: z.boolean(),
|
||||
idempotent: z.boolean(),
|
||||
open_world: z.boolean(),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
tool_availability: z.array(toolAvailability),
|
||||
client_features: z.object({
|
||||
elicitation_form: z.boolean(),
|
||||
elicitation_url: z.boolean(),
|
||||
|
||||
Reference in New Issue
Block a user