fix(native): distinguish batch selectors from resolved entries

This commit is contained in:
N0zoM1z0
2026-10-09 19:09:30 +08:00
parent 6cc817e8bd
commit bfaa5a6c2c
9 changed files with 281 additions and 13 deletions
+44 -2
View File
@@ -254,20 +254,33 @@ export class EnhancedTools {
): EnhancedResult {
const items = await Promise.all(
addresses.map(async (address) => {
const resolved = await resolveProcedureAddress(
this.#call.bind(this),
address,
signal,
);
const procedure = resolved.ok
? await this.#batchProcedureIdentity(resolved.value, signal)
: {
status: "unknown" as const,
error: projectAnalysisError(resolved.error),
};
const result = await this.#call(
"procedure_pseudo_code",
{ procedure: address },
{ procedure: resolved.ok ? resolved.value : address },
signal,
);
if (!result.ok)
return {
address,
procedure,
status: "error" as const,
error: projectAnalysisError(result.error),
};
if (typeof result.value !== "string" || result.value.length === 0)
return {
address,
procedure,
status: "error" as const,
error: projectAnalysisError(
new AnalysisOutputError(
@@ -276,7 +289,12 @@ export class EnhancedTools {
),
),
};
return { address, status: "ok" as const, pseudocode: result.value };
return {
address,
procedure,
status: "ok" as const,
pseudocode: result.value,
};
}),
);
const succeeded = items.filter(({ status }) => status === "ok").length;
@@ -288,6 +306,30 @@ export class EnhancedTools {
});
}
async #batchProcedureIdentity(address: string, signal?: AbortSignal) {
const observed = await this.#call("address_name", { address }, signal);
const named =
observed.ok &&
(typeof observed.value === "string" || observed.value === null);
return {
status: "resolved" as const,
address,
name: named ? observed.value : null,
...(named
? {}
: {
name_error: projectAnalysisError(
observed.ok
? new AnalysisOutputError(
"address_name",
"provider returned an invalid entry label",
)
: observed.error,
),
}),
};
}
async #callGraph(
input: {
readonly address: string;
+3 -1
View File
@@ -18,7 +18,9 @@ export const workflowAnalysisProfile = (
): AnalysisProfileCommitment =>
createAnalysisProfile(REA_WORKFLOW_PROVIDER, {
upstream_analysis_profile: upstream,
...(operation === "binary_overview" ? { workflow_revision: 2 } : {}),
...(operation === "binary_overview" || operation === "batch_decompile"
? { workflow_revision: 2 }
: {}),
});
/** Provider identity for deterministic artifact inventories. */
+33 -1
View File
@@ -10,7 +10,11 @@ import {
committedProviderSchema,
} from "../domain/analysisProfile.js";
import type { BinaryTarget } from "../domain/binaryTarget.js";
import { createEvidence, type Evidence } from "../domain/evidence.js";
import {
createEvidence,
type Evidence,
type EvidenceLocation,
} from "../domain/evidence.js";
import type { JsonValue } from "../domain/jsonValue.js";
import type { UnknownRegistryPort } from "./investigation/InvestigationRecordPort.js";
import { UnknownRegistryError } from "../domain/unknownRegistryError.js";
@@ -37,8 +41,36 @@ export const createWorkflowEvidence = (input: {
}),
confidence: "derived",
limitations: ["Derived by an REA composed workflow."],
...(input.operation === "batch_decompile"
? { locations: batchProcedureLocations(input.result) }
: {}),
});
const batchProcedureLocations = (result: JsonValue): EvidenceLocation[] => {
if (
result === null ||
typeof result !== "object" ||
Array.isArray(result) ||
!Array.isArray(result.items)
)
return [];
const addresses = new Set<string>();
for (const item of result.items) {
if (item === null || typeof item !== "object" || Array.isArray(item))
continue;
const procedure = item.procedure;
if (
procedure !== null &&
typeof procedure === "object" &&
!Array.isArray(procedure) &&
procedure.status === "resolved" &&
typeof procedure.address === "string"
)
addresses.add(procedure.address);
}
return [...addresses].map((address) => ({ kind: "address", address }));
};
/** Convert workflow Evidence into its exact replay binding, when it has a profile. */
export const workflowSnapshotRecord = (
evidence: Evidence,
+1 -1
View File
@@ -44,7 +44,7 @@ export const ENHANCED_TOOL_CONTRACTS = [
),
enhanced(
"batch_decompile",
"Decompile each explicit procedure symbol or address concurrently. Returns ordered per-item success or error results and aggregate counts.",
"Decompile each explicit procedure symbol or address concurrently. Preserves each input selector in address and reports the observed canonical entry and entry label in procedure; identity or label failures remain explicit without discarding usable pseudocode. Returns ordered per-item success or error results and aggregate counts.",
enhancedInputSchemas.batch_decompile,
),
enhanced(
+25 -2
View File
@@ -245,6 +245,23 @@ const callPathTraceOutput = resultOf(
}),
);
/** Identity facts attached to one requested batch selector. */
const batchProcedureIdentity = z.discriminatedUnion("status", [
z.object({
status: z.literal("resolved"),
address: z.string().min(1).describe("Observed canonical procedure entry."),
name: z
.string()
.nullable()
.describe("Provider's entry label, or null when unavailable."),
name_error: analysisErrorProjectionSchema.optional(),
}),
z.object({
status: z.literal("unknown"),
error: analysisErrorProjectionSchema,
}),
]);
/** Exact structured-content schemas for composed analysis workflows. */
export const enhancedOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
inspect_native_dispatch_metadata: resultOf(
@@ -259,12 +276,18 @@ export const enhancedOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
items: z.array(
z.discriminatedUnion("status", [
z.object({
address: z.string(),
address: z
.string()
.describe("Original caller-selected symbol or address."),
procedure: batchProcedureIdentity,
status: z.literal("ok"),
pseudocode: z.string().min(1),
}),
z.object({
address: z.string(),
address: z
.string()
.describe("Original caller-selected symbol or address."),
procedure: batchProcedureIdentity,
status: z.literal("error"),
error: analysisErrorProjectionSchema,
}),