fix(analysis): bind overview document identity to the active target (#1094)
* fix(analysis): bind overview document identity to the active target * fix(analysis): refresh legacy overview snapshot results
This commit is contained in:
@@ -3,13 +3,10 @@ import type {
|
||||
AnalysisOperation,
|
||||
AnalysisOperationPort,
|
||||
} from "./AnalysisProvider.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisOutputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
|
||||
import { type AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { parseDocuments } from "../domain/hopperValues.js";
|
||||
import { resolveAnalysisDocument } from "./AnalysisDocument.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
|
||||
type Facet =
|
||||
@@ -88,7 +85,11 @@ export const inspectAddressContext = async (
|
||||
input: { readonly address: string; readonly document?: string | undefined },
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<JsonValue, AnalysisError>> => {
|
||||
const document = await resolveDocument(analysis, input.document, signal);
|
||||
const document = await resolveAnalysisDocument(
|
||||
analysis,
|
||||
input.document,
|
||||
signal,
|
||||
);
|
||||
if (!document.ok) return document;
|
||||
const args = parameters(document.value, input.address);
|
||||
const operations = [
|
||||
@@ -132,62 +133,6 @@ export const inspectAddressContext = async (
|
||||
});
|
||||
};
|
||||
|
||||
const resolveDocument = async (
|
||||
analysis: AnalysisOperationPort,
|
||||
document: string | undefined,
|
||||
signal: AbortSignal | undefined,
|
||||
): Promise<Result<string, AnalysisError>> => {
|
||||
if (document !== undefined) return ok(document);
|
||||
const current = await analysis.execute(
|
||||
"current_document",
|
||||
{},
|
||||
executionOptions(signal),
|
||||
);
|
||||
if (!current.ok) {
|
||||
if (!(current.error instanceof AnalysisCapabilityUnavailableError))
|
||||
return current;
|
||||
const listed = await analysis.execute(
|
||||
"list_documents",
|
||||
{},
|
||||
executionOptions(signal),
|
||||
);
|
||||
if (!listed.ok) return listed;
|
||||
const parsed = parseDocuments(listed.value.result);
|
||||
if (!parsed.ok)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"list_documents",
|
||||
"expected one document identity when resolving a headless provider",
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
);
|
||||
if (parsed.value.length !== 1)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"list_documents",
|
||||
`expected exactly one document identity for a provider without current-document selection, received ${parsed.value.length}`,
|
||||
),
|
||||
);
|
||||
const [documentName] = parsed.value;
|
||||
if (documentName === undefined)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"list_documents",
|
||||
"provider returned no document identity",
|
||||
),
|
||||
);
|
||||
return ok(documentName);
|
||||
}
|
||||
return typeof current.value.result === "string"
|
||||
? ok(current.value.result)
|
||||
: err(
|
||||
new AnalysisOutputError(
|
||||
"current_document",
|
||||
"expected a document identity string",
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const facet = (
|
||||
result: Result<AnalysisExecution, AnalysisError> | undefined,
|
||||
operation: AnalysisOperation,
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { AnalysisOperationPort } from "./AnalysisProvider.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisOutputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { parseDocuments } from "../domain/hopperValues.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
|
||||
const executionOptions = (signal: AbortSignal | undefined) =>
|
||||
signal === undefined ? undefined : { signal };
|
||||
|
||||
/** Resolve an explicit or provider-selected document without guessing among candidates. */
|
||||
export const resolveAnalysisDocument = async (
|
||||
analysis: AnalysisOperationPort,
|
||||
document: string | undefined,
|
||||
signal: AbortSignal | undefined,
|
||||
): Promise<Result<string, AnalysisError>> => {
|
||||
if (document !== undefined) return ok(document);
|
||||
if (signal?.aborted === true)
|
||||
return err(new AnalysisCancelledError("current_document"));
|
||||
const current = await analysis.execute(
|
||||
"current_document",
|
||||
{},
|
||||
executionOptions(signal),
|
||||
);
|
||||
if (!current.ok) {
|
||||
if (!(current.error instanceof AnalysisCapabilityUnavailableError))
|
||||
return current;
|
||||
const listed = await analysis.execute(
|
||||
"list_documents",
|
||||
{},
|
||||
executionOptions(signal),
|
||||
);
|
||||
if (!listed.ok) return listed;
|
||||
const parsed = parseDocuments(listed.value.result);
|
||||
if (!parsed.ok)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"list_documents",
|
||||
"expected one document identity when resolving a headless provider",
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
);
|
||||
if (parsed.value.length !== 1)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"list_documents",
|
||||
`expected exactly one document identity for a provider without current-document selection, received ${parsed.value.length}`,
|
||||
),
|
||||
);
|
||||
const [documentName] = parsed.value;
|
||||
if (documentName === undefined || documentName.length === 0)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
"list_documents",
|
||||
"provider returned no document identity",
|
||||
),
|
||||
);
|
||||
return ok(documentName);
|
||||
}
|
||||
return typeof current.value.result === "string" &&
|
||||
current.value.result.length > 0
|
||||
? ok(current.value.result)
|
||||
: err(
|
||||
new AnalysisOutputError(
|
||||
"current_document",
|
||||
"expected a nonempty document identity string",
|
||||
),
|
||||
);
|
||||
};
|
||||
@@ -455,7 +455,8 @@ const analysisProfileForRoute = (
|
||||
): AnalysisProfileCommitment | undefined => {
|
||||
const profile = route.profile;
|
||||
if (profile === null || profile === undefined) return undefined;
|
||||
if (isWorkflowEvidenceTool(tool)) return workflowAnalysisProfile(profile);
|
||||
if (isWorkflowEvidenceTool(tool))
|
||||
return workflowAnalysisProfile(profile, tool);
|
||||
const provider = providerIdentityForRoute(route, tool);
|
||||
return provider.id === profile.provider.id ? profile : undefined;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,6 @@ import { type AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
addressDistance,
|
||||
functionDossierSchema,
|
||||
parseDocuments,
|
||||
parseFunctionDossier,
|
||||
parseListCount,
|
||||
parseRelatedAddresses,
|
||||
@@ -37,6 +36,7 @@ import {
|
||||
type EnhancedResult,
|
||||
type ValidatedEnhancedCall,
|
||||
} from "./EnhancedToolTypes.js";
|
||||
import { resolveAnalysisDocument } from "./AnalysisDocument.js";
|
||||
import { traceCallPath } from "./CallPathTracing.js";
|
||||
import { traceLiteralFeature } from "./EnhancedLiteralTracing.js";
|
||||
import { projectNativeApiInspection } from "./native/NativeApiInspection.js";
|
||||
@@ -388,29 +388,32 @@ export class EnhancedTools {
|
||||
}
|
||||
|
||||
async #binaryOverview(signal?: AbortSignal): EnhancedResult {
|
||||
const [segmentsResult, documentsResult, proceduresResult, stringsResult] =
|
||||
await Promise.all([
|
||||
const document = await resolveAnalysisDocument(
|
||||
this.analysis,
|
||||
undefined,
|
||||
signal,
|
||||
);
|
||||
if (!document.ok) return document;
|
||||
const [segmentsResult, proceduresResult, stringsResult] = await Promise.all(
|
||||
[
|
||||
this.#call("list_segments", {}, signal),
|
||||
this.#call("list_documents", {}, signal),
|
||||
this.#call("list_procedures", {}, signal),
|
||||
this.#call("list_strings", {}, signal),
|
||||
]);
|
||||
],
|
||||
);
|
||||
if (!segmentsResult.ok) return segmentsResult;
|
||||
if (!documentsResult.ok) return documentsResult;
|
||||
if (!proceduresResult.ok) return proceduresResult;
|
||||
if (!stringsResult.ok) return stringsResult;
|
||||
|
||||
const segments = parseSegments(segmentsResult.value);
|
||||
if (!segments.ok) return segments;
|
||||
const documents = parseDocuments(documentsResult.value);
|
||||
if (!documents.ok) return documents;
|
||||
const procedureCount = parseListCount(proceduresResult.value, "procedures");
|
||||
if (!procedureCount.ok) return procedureCount;
|
||||
const stringCount = parseListCount(stringsResult.value, "strings");
|
||||
if (!stringCount.ok) return stringCount;
|
||||
|
||||
return ok({
|
||||
document: documents.value[0] ?? "unknown",
|
||||
document: document.value,
|
||||
segments: segments.value.map(({ name, start, end }) => ({
|
||||
name,
|
||||
start,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { AnalysisOperation } from "./AnalysisProvider.js";
|
||||
import {
|
||||
createAnalysisProfile,
|
||||
type AnalysisProfileCommitment,
|
||||
@@ -10,12 +11,14 @@ export const REA_WORKFLOW_PROVIDER = {
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Commit a workflow result to the exact upstream deep-analysis profile. */
|
||||
/** Commit a workflow result to its upstream profile and applicable semantic revision. */
|
||||
export const workflowAnalysisProfile = (
|
||||
upstream: AnalysisProfileCommitment,
|
||||
operation?: AnalysisOperation,
|
||||
): AnalysisProfileCommitment =>
|
||||
createAnalysisProfile(REA_WORKFLOW_PROVIDER, {
|
||||
upstream_analysis_profile: upstream,
|
||||
...(operation === "binary_overview" ? { workflow_revision: 2 } : {}),
|
||||
});
|
||||
|
||||
/** Provider identity for deterministic artifact inventories. */
|
||||
|
||||
@@ -29,7 +29,12 @@ export const createWorkflowEvidence = (input: {
|
||||
result: input.result,
|
||||
...(input.upstreamProfile === undefined
|
||||
? {}
|
||||
: { analysisProfile: workflowAnalysisProfile(input.upstreamProfile) }),
|
||||
: {
|
||||
analysisProfile: workflowAnalysisProfile(
|
||||
input.upstreamProfile,
|
||||
input.operation,
|
||||
),
|
||||
}),
|
||||
confidence: "derived",
|
||||
limitations: ["Derived by an REA composed workflow."],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user