refactor: return complete tool results inline
This commit is contained in:
@@ -7,7 +7,9 @@ import type { AnalysisClient, ExecutionOptions } from "./AnalysisProvider.js";
|
||||
export const closeAnalysisClient = async (
|
||||
client: AnalysisClient,
|
||||
providerId: string,
|
||||
options: Pick<ExecutionOptions, "progress"> = {},
|
||||
options: Pick<ExecutionOptions, "progress"> & {
|
||||
readonly retainDocument?: boolean;
|
||||
} = {},
|
||||
): Promise<Result<null, AnalysisError>> => {
|
||||
try {
|
||||
if (client.closeWithOutcome !== undefined)
|
||||
|
||||
@@ -102,7 +102,9 @@ export interface AnalysisClient extends AnalysisOperationPort {
|
||||
requestActivitySnapshots?(): readonly ProviderRequestActivitySnapshot[];
|
||||
/** Close with a typed result when the provider can verify cleanup. */
|
||||
closeWithOutcome?(
|
||||
options?: Pick<ExecutionOptions, "progress">,
|
||||
options?: Pick<ExecutionOptions, "progress"> & {
|
||||
readonly retainDocument?: boolean;
|
||||
},
|
||||
): Promise<Result<null, AnalysisError>>;
|
||||
close(): Promise<void>;
|
||||
}
|
||||
@@ -166,8 +168,6 @@ interface CapabilityLimits {
|
||||
export type CapabilityDescriptor = CapabilityAvailability & {
|
||||
readonly provider: ProviderIdentity;
|
||||
readonly operation: Exclude<AnalysisOperation, "health">;
|
||||
readonly inputContractVersion: number;
|
||||
readonly outputContractVersion: number;
|
||||
readonly pagination: "none" | "offset" | "cursor";
|
||||
readonly exhaustive: boolean;
|
||||
readonly effects: CapabilityEffects;
|
||||
|
||||
@@ -365,7 +365,6 @@ const candidate = (
|
||||
? null
|
||||
: createAnalysisProfile(
|
||||
{ id, name: identity.name, version: "1" },
|
||||
1,
|
||||
{ fixture: id },
|
||||
),
|
||||
compatibility: {},
|
||||
@@ -395,8 +394,6 @@ const candidate = (
|
||||
const capability = (provider: ProviderIdentity): CapabilityDescriptor => ({
|
||||
provider,
|
||||
operation: "address_name",
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
|
||||
@@ -54,11 +54,9 @@ describe("analysis snapshot cache partitioning", () => {
|
||||
analysisProfile: ANALYSIS_SNAPSHOT_PROFILE,
|
||||
limitations: [expect.stringContaining("local REA analysis snapshot")],
|
||||
});
|
||||
const changedProfile = createAnalysisProfile(
|
||||
ANALYSIS_SNAPSHOT_PROVIDER,
|
||||
1,
|
||||
{ loader: "configured-override" },
|
||||
);
|
||||
const changedProfile = createAnalysisProfile(ANALYSIS_SNAPSHOT_PROVIDER, {
|
||||
loader: "configured-override",
|
||||
});
|
||||
expect(
|
||||
cache.lookup(ANALYSIS_SNAPSHOT_TARGET, changedProfile, "address_name", {
|
||||
address: "0x1000",
|
||||
@@ -67,7 +65,6 @@ describe("analysis snapshot cache partitioning", () => {
|
||||
).toBeUndefined();
|
||||
const changedProviderProfile = createAnalysisProfile(
|
||||
{ id: "other", name: "Other", version: "1" },
|
||||
1,
|
||||
{ loader: "mach-o-arm64" },
|
||||
);
|
||||
expect(
|
||||
|
||||
@@ -30,11 +30,7 @@ import {
|
||||
const APPLICATION_GRAPH_IDENTITIES = [
|
||||
{
|
||||
operation: "analyze_javascript_application",
|
||||
predicate: "rea.javascript-application-analysis/v1",
|
||||
},
|
||||
{
|
||||
operation: "analyze_javascript_application",
|
||||
predicate: "rea.javascript-application-analysis/v2",
|
||||
predicate: "rea.javascript-application-analysis",
|
||||
},
|
||||
{
|
||||
operation: "reconcile_javascript_runtime",
|
||||
@@ -82,7 +78,6 @@ export const resolveTraceApplicationFeatureRequestValidated = (
|
||||
native_observations: [...input.native_observations, ...native.value],
|
||||
seed: input.seed,
|
||||
direction: input.direction,
|
||||
limits: input.limits,
|
||||
};
|
||||
const parsed = traceApplicationFeatureInputSchema.safeParse(raw);
|
||||
return parsed.success
|
||||
|
||||
@@ -188,7 +188,6 @@ const createExtractionResult = (
|
||||
extracted: readonly ExtractedOccurrence[],
|
||||
): ArtifactExtractionResult => {
|
||||
const extractionSemantic = {
|
||||
schema_version: 1 as const,
|
||||
source_manifest_id: inventory.manifest.manifest_id,
|
||||
selected_occurrence_ids: selected
|
||||
.map(({ occurrence }) => occurrence.occurrence_id)
|
||||
|
||||
@@ -149,7 +149,7 @@ export const createArtifactNode = (input: {
|
||||
readonly contentState: ArtifactNode["content_state"];
|
||||
readonly limitations?: readonly string[];
|
||||
}): ArtifactNode => ({
|
||||
artifact_id: `art_${digestCanonical({ schema_version: 1, sha256: input.sha256 })}`,
|
||||
artifact_id: `art_${digestCanonical({ sha256: input.sha256 })}`,
|
||||
kind: input.kind,
|
||||
format: input.format,
|
||||
sha256: input.sha256,
|
||||
|
||||
@@ -41,6 +41,27 @@ export const inventoryArtifact = async (
|
||||
return paginateArtifactInventory(snapshot, page);
|
||||
};
|
||||
|
||||
/** Inventory one artifact and return every graph collection in one response. */
|
||||
export const inventoryArtifactFully = async (
|
||||
inputPath: string,
|
||||
limits: ArtifactLimits,
|
||||
options: {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly nativeMount?: ArtifactNativeMountPolicy;
|
||||
readonly integrity?: ArtifactIntegrityPolicy;
|
||||
} = {},
|
||||
): Promise<ArtifactInventoryResult> => {
|
||||
const snapshot = await scanArtifactInventory(inputPath, limits, options);
|
||||
return paginateArtifactInventory(snapshot, {
|
||||
nodeOffset: 0,
|
||||
nodeLimit: Math.max(1, snapshot.nodes.length),
|
||||
occurrenceOffset: 0,
|
||||
occurrenceLimit: Math.max(1, snapshot.occurrences.length),
|
||||
edgeOffset: 0,
|
||||
edgeLimit: Math.max(1, snapshot.edges.length),
|
||||
});
|
||||
};
|
||||
|
||||
/** Scan an artifact once and retain the complete immutable graph for projection. */
|
||||
export const scanArtifactInventory = async (
|
||||
inputPath: string,
|
||||
|
||||
@@ -258,9 +258,7 @@ const buildManifest = ({
|
||||
readonly orderedEdges: readonly { edge_id: string }[];
|
||||
}): ArtifactInventoryResult["manifest"] =>
|
||||
artifactInventoryResultSchema.shape.manifest.parse({
|
||||
schema_version: 1,
|
||||
manifest_id: `agm_${digestCanonical({
|
||||
schema_version: 1,
|
||||
root_artifact_id: rootNode.artifact_id,
|
||||
graph_sha256: graphSha256,
|
||||
})}`,
|
||||
|
||||
@@ -1,35 +1,18 @@
|
||||
import { realpath } from "node:fs/promises";
|
||||
|
||||
import type { ArtifactLimits } from "../artifacts/ArtifactReader.js";
|
||||
import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js";
|
||||
import { isPathWithinRoot } from "../domain/localPath.js";
|
||||
import {
|
||||
scanCanonicalArtifactInventory,
|
||||
type ArtifactInventoryOptions,
|
||||
type ArtifactInventorySnapshot,
|
||||
} from "./ArtifactInventory.js";
|
||||
import { canonicalizeConfiguredRoots } from "./ConfiguredRoots.js";
|
||||
|
||||
/** Resolve, authorize, and scan one artifact without a second path resolution. */
|
||||
export const scanAuthorizedArtifactInventory = async (
|
||||
inputPath: string,
|
||||
roots: readonly string[],
|
||||
limits: ArtifactLimits,
|
||||
options: ArtifactInventoryOptions = {},
|
||||
): Promise<ArtifactInventorySnapshot> => {
|
||||
if (roots.length === 0)
|
||||
throw new ArtifactReaderFailure(
|
||||
"path",
|
||||
"Artifact input roots are disabled",
|
||||
);
|
||||
const [path, approved] = await Promise.all([
|
||||
realpath(inputPath),
|
||||
canonicalizeConfiguredRoots(roots),
|
||||
]);
|
||||
if (!approved.some((root) => isPathWithinRoot(root, path)))
|
||||
throw new ArtifactReaderFailure(
|
||||
"path",
|
||||
"Artifact path is outside approved input roots",
|
||||
);
|
||||
const path = await realpath(inputPath);
|
||||
return scanCanonicalArtifactInventory(path, limits, options);
|
||||
};
|
||||
|
||||
@@ -228,7 +228,9 @@ export class BinarySession
|
||||
|
||||
/** Close the active target, if any. */
|
||||
close(
|
||||
options: Pick<ExecutionOptions, "progress"> = {},
|
||||
options: Pick<ExecutionOptions, "progress"> & {
|
||||
readonly retainProviderDocuments?: boolean;
|
||||
} = {},
|
||||
): Promise<Result<null, AnalysisError>> {
|
||||
return this.#serialize(async () => {
|
||||
const previous = this.#active;
|
||||
@@ -240,7 +242,14 @@ export class BinarySession
|
||||
: await closeAnalysisClient(
|
||||
previous.client,
|
||||
previous.route.identity.id,
|
||||
options,
|
||||
{
|
||||
...(options.progress === undefined
|
||||
? {}
|
||||
: { progress: options.progress }),
|
||||
...(options.retainProviderDocuments === true
|
||||
? { retainDocument: true }
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
this.clearSessionRecords();
|
||||
this.#clearRuntimeAvailability();
|
||||
@@ -340,7 +349,6 @@ export class BinarySession
|
||||
"ProviderAdapterError",
|
||||
"HopperProcessError",
|
||||
"HopperStartError",
|
||||
"HopperRemoteError",
|
||||
].includes(result.error._tag)
|
||||
) {
|
||||
const capabilities = this.#active?.route.capabilities;
|
||||
@@ -351,7 +359,7 @@ export class BinarySession
|
||||
changed =
|
||||
this.#markRuntimeUnavailable(
|
||||
descriptor.operation,
|
||||
"Provider became unavailable during this session.",
|
||||
`${result.error._tag}: ${result.error.message}`,
|
||||
) || changed;
|
||||
if (changed) this.#emitAvailabilityChanged();
|
||||
}
|
||||
|
||||
@@ -27,18 +27,6 @@ import type {
|
||||
ProviderIdentity,
|
||||
} from "./AnalysisProvider.js";
|
||||
|
||||
/** Compact identity and summary for one retained immutable Evidence bundle. */
|
||||
export interface EvidenceBundleSnapshot {
|
||||
readonly bundleDigest: string;
|
||||
readonly bundleVersion: 2;
|
||||
readonly bytes: number;
|
||||
readonly records: number;
|
||||
readonly unknowns: number;
|
||||
readonly scope: "session";
|
||||
readonly survivesSession: false;
|
||||
readonly uri: string;
|
||||
}
|
||||
|
||||
/** Target lifecycle used by CLI and MCP without exposing a concrete provider. */
|
||||
export interface BinarySessionPort extends AnalysisOperationPort {
|
||||
open(
|
||||
@@ -51,7 +39,9 @@ export interface BinarySessionPort extends AnalysisOperationPort {
|
||||
},
|
||||
): Promise<Result<BinaryTarget, AnalysisError>>;
|
||||
close(
|
||||
options?: Pick<ExecutionOptions, "progress">,
|
||||
options?: Pick<ExecutionOptions, "progress"> & {
|
||||
readonly retainProviderDocuments?: boolean;
|
||||
},
|
||||
): Promise<Result<null, AnalysisError>>;
|
||||
status(): JsonValue;
|
||||
activeTarget(): BinaryTarget | undefined;
|
||||
@@ -61,9 +51,6 @@ export interface BinarySessionPort extends AnalysisOperationPort {
|
||||
hasEvidence(evidenceId: string): boolean;
|
||||
evidenceById(evidenceId: string): Evidence | undefined;
|
||||
exportEvidenceBundle(): EvidenceBundle;
|
||||
snapshotEvidenceBundle(): Result<EvidenceBundleSnapshot, EvidenceLimitError>;
|
||||
releaseEvidenceBundle(bundleDigest: string): boolean;
|
||||
retainedEvidenceBundle(digest: string): string | undefined;
|
||||
importEvidenceBundle(
|
||||
bundle: unknown,
|
||||
): Result<number, EvidenceIntegrityError | EvidenceLimitError>;
|
||||
|
||||
@@ -3,10 +3,7 @@ import type { AnalysisSnapshot } from "../domain/analysisSnapshot.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import { createEvidence, type Evidence } from "../domain/evidence.js";
|
||||
import type { EvidenceBundle } from "../domain/evidenceBundle.js";
|
||||
import {
|
||||
evidenceBundleForTarget,
|
||||
serializeEvidenceBundle,
|
||||
} from "../domain/evidenceBundle.js";
|
||||
import { evidenceBundleForTarget } from "../domain/evidenceBundle.js";
|
||||
import {
|
||||
EvidenceIntegrityError,
|
||||
EvidenceLimitError,
|
||||
@@ -28,7 +25,6 @@ import type {
|
||||
UpdateUnknownInput,
|
||||
} from "../domain/residualUnknown.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { EvidenceBundleSnapshot } from "./BinarySessionPort.js";
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
AnalysisOperation,
|
||||
@@ -48,15 +44,11 @@ export interface ActiveAnalysisBinding {
|
||||
|
||||
/** Owns session evidence, snapshots, workspaces, and residual unknowns. */
|
||||
export abstract class BinarySessionRecords {
|
||||
static readonly MAX_RETAINED_BUNDLES = 16;
|
||||
static readonly MAX_RETAINED_BUNDLE_BYTES = 64 * 1024 * 1024;
|
||||
readonly #evidence = new EvidenceLedger({
|
||||
maxRecords: 10_000,
|
||||
maxBytes: 64 * 1024 * 1024,
|
||||
});
|
||||
readonly #snapshot = new AnalysisSnapshotCache();
|
||||
readonly #retainedBundles = new Map<string, string>();
|
||||
#retainedBundleBytes = 0;
|
||||
readonly #investigationWorkspaces = new Map<string, InvestigationWorkspace>();
|
||||
readonly #coverageWorkspaces = new Map<
|
||||
string,
|
||||
@@ -94,61 +86,6 @@ export abstract class BinarySessionRecords {
|
||||
return this.#evidence.export();
|
||||
}
|
||||
|
||||
snapshotEvidenceBundle(): Result<EvidenceBundleSnapshot, EvidenceLimitError> {
|
||||
const bundle = this.#evidence.export();
|
||||
const encoded = serializeEvidenceBundle(bundle);
|
||||
const digest = createHash("sha256").update(encoded).digest("hex");
|
||||
const existing = this.#retainedBundles.get(digest);
|
||||
if (existing === undefined) {
|
||||
if (
|
||||
this.#retainedBundles.size >= BinarySessionRecords.MAX_RETAINED_BUNDLES
|
||||
)
|
||||
return err(
|
||||
new EvidenceLimitError(
|
||||
"records",
|
||||
BinarySessionRecords.MAX_RETAINED_BUNDLES,
|
||||
),
|
||||
);
|
||||
const bytes = Buffer.byteLength(encoded);
|
||||
if (
|
||||
this.#retainedBundleBytes + bytes >
|
||||
BinarySessionRecords.MAX_RETAINED_BUNDLE_BYTES
|
||||
)
|
||||
return err(
|
||||
new EvidenceLimitError(
|
||||
"bytes",
|
||||
BinarySessionRecords.MAX_RETAINED_BUNDLE_BYTES,
|
||||
),
|
||||
);
|
||||
this.#retainedBundles.set(digest, encoded);
|
||||
this.#retainedBundleBytes += bytes;
|
||||
}
|
||||
return ok({
|
||||
bundleDigest: digest,
|
||||
bundleVersion: 2,
|
||||
bytes: Buffer.byteLength(existing ?? encoded),
|
||||
records: bundle.records.length,
|
||||
unknowns: bundle.unknowns.length,
|
||||
scope: "session",
|
||||
survivesSession: false,
|
||||
uri: `rea://evidence-bundle/${digest}`,
|
||||
});
|
||||
}
|
||||
|
||||
retainedEvidenceBundle(digest: string): string | undefined {
|
||||
return this.#retainedBundles.get(digest);
|
||||
}
|
||||
|
||||
/** Release one immutable bundle so bounded retention has an explicit recovery path. */
|
||||
releaseEvidenceBundle(bundleDigest: string): boolean {
|
||||
const encoded = this.#retainedBundles.get(bundleDigest);
|
||||
if (encoded === undefined) return false;
|
||||
this.#retainedBundles.delete(bundleDigest);
|
||||
this.#retainedBundleBytes -= Buffer.byteLength(encoded);
|
||||
this.#emitSnapshotChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
importEvidenceBundle(
|
||||
bundle: unknown,
|
||||
): Result<number, EvidenceIntegrityError | EvidenceLimitError> {
|
||||
@@ -263,8 +200,6 @@ export abstract class BinarySessionRecords {
|
||||
this.#evidence.clear();
|
||||
this.#snapshot.clear();
|
||||
this.#snapshotInvalidated = false;
|
||||
this.#retainedBundles.clear();
|
||||
this.#retainedBundleBytes = 0;
|
||||
this.#emitSnapshotChanged();
|
||||
}
|
||||
|
||||
@@ -415,4 +350,3 @@ const sortedWorkspaces = <
|
||||
left.revision - right.revision,
|
||||
)
|
||||
.map((workspace) => structuredClone(workspace));
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
@@ -169,7 +169,6 @@ const processLineageStatus = (
|
||||
: {
|
||||
status: observation.status,
|
||||
observed_at: observation.observedAt,
|
||||
schema_version: observation.lineage.schemaVersion,
|
||||
launcher_pid: observation.lineage.launcherPid,
|
||||
launcher_parent_pid: observation.lineage.launcherParentPid,
|
||||
process_group_id: observation.lineage.processGroupId,
|
||||
@@ -194,8 +193,6 @@ const capabilityStatus = (
|
||||
available: descriptor.available,
|
||||
reason: descriptor.reason,
|
||||
availability_code: descriptor.availabilityCode ?? null,
|
||||
input_contract_version: descriptor.inputContractVersion,
|
||||
output_contract_version: descriptor.outputContractVersion,
|
||||
pagination: descriptor.pagination,
|
||||
exhaustive: descriptor.exhaustive,
|
||||
effects: {
|
||||
|
||||
@@ -63,7 +63,7 @@ type BrowserEvidenceOperation =
|
||||
| "capture_web_screenshot"
|
||||
| "compare_web_screenshots";
|
||||
|
||||
/** Create Evidence v2 for a policy-scoped external browser observation. */
|
||||
/** Create Evidence for a policy-scoped external browser observation. */
|
||||
export const createBrowserEvidence = (
|
||||
operation: BrowserEvidenceOperation,
|
||||
input: BrowserEvidenceInput,
|
||||
@@ -125,8 +125,7 @@ const browserParameters = (
|
||||
cdp_endpoint: input.cdp_endpoint,
|
||||
allowed_origins: input.allowed_origins,
|
||||
};
|
||||
if (!("target_id" in input))
|
||||
return { ...scope, offset: input.offset, limit: input.limit };
|
||||
if (!("target_id" in input)) return scope;
|
||||
if ("screenshot_approved" in input)
|
||||
return {
|
||||
...scope,
|
||||
|
||||
@@ -33,7 +33,7 @@ const browserScenarioParameters = (
|
||||
limits: scenario.limits,
|
||||
});
|
||||
|
||||
/** Create Evidence v2 without retaining resolved scenario secret values. */
|
||||
/** Create Evidence without retaining resolved scenario secret values. */
|
||||
export const createBrowserScenarioEvidence = (
|
||||
scenario: BrowserScenario,
|
||||
capture: BrowserScenarioCapture,
|
||||
|
||||
@@ -15,9 +15,6 @@ export interface CallPathTraceInput {
|
||||
readonly start: string;
|
||||
readonly goal?: string | undefined;
|
||||
readonly direction: "forward" | "backward";
|
||||
readonly max_depth: number;
|
||||
readonly max_nodes: number;
|
||||
readonly max_operations: number;
|
||||
}
|
||||
|
||||
interface TraceState {
|
||||
@@ -38,9 +35,7 @@ interface TraceState {
|
||||
readonly address: string;
|
||||
readonly error: ReturnType<typeof projectAnalysisError>;
|
||||
}>;
|
||||
readonly frontier: Set<string>;
|
||||
readonly residual: Set<string>;
|
||||
operations: number;
|
||||
queueIndex: number;
|
||||
traversalPath: string[];
|
||||
}
|
||||
@@ -59,7 +54,7 @@ interface DiscoveredEdge {
|
||||
readonly discoveryDepth: number;
|
||||
}
|
||||
|
||||
/** Trace one deterministic bounded direct caller/callee path. */
|
||||
/** Trace direct caller/callee relationships until the graph is exhausted or the goal is reached. */
|
||||
export const traceCallPath = async (
|
||||
call: AnalysisCall,
|
||||
input: CallPathTraceInput,
|
||||
@@ -74,17 +69,6 @@ export const traceCallPath = async (
|
||||
if (address === undefined) break;
|
||||
const current = state.visited.get(address);
|
||||
if (current === undefined) continue;
|
||||
if (current.depth >= input.max_depth) {
|
||||
state.frontier.add(address);
|
||||
state.residual.add("Call-path traversal reached the depth limit.");
|
||||
continue;
|
||||
}
|
||||
if (state.operations >= input.max_operations) {
|
||||
recordPendingFrontier(state, input);
|
||||
state.residual.add("Call-path traversal reached the operation budget.");
|
||||
break;
|
||||
}
|
||||
state.operations += 1;
|
||||
const found = await expandAddress(call, {
|
||||
input,
|
||||
state,
|
||||
@@ -102,9 +86,7 @@ const createTraceState = (input: CallPathTraceInput): TraceState => ({
|
||||
queue: [input.start],
|
||||
edges: new Map(),
|
||||
failures: [],
|
||||
frontier: new Set(),
|
||||
residual: new Set(),
|
||||
operations: 0,
|
||||
queueIndex: 0,
|
||||
traversalPath: input.goal === input.start ? [input.start] : [],
|
||||
});
|
||||
@@ -152,12 +134,6 @@ const expandAddress = async (
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (state.visited.size >= input.max_nodes) {
|
||||
if (state.frontier.size < input.max_nodes)
|
||||
state.frontier.add(relatedAddress);
|
||||
state.residual.add("Call-path traversal reached the node limit.");
|
||||
continue;
|
||||
}
|
||||
state.visited.set(relatedAddress, {
|
||||
depth: current.depth + 1,
|
||||
path,
|
||||
@@ -182,10 +158,6 @@ const recordEdge = (
|
||||
input.direction === "forward" ? edge.relatedAddress : edge.address;
|
||||
const edgeKey = `${sourceAddress}\u0000${targetAddress}`;
|
||||
if (state.edges.has(edgeKey)) return;
|
||||
if (state.edges.size >= input.max_nodes) {
|
||||
state.residual.add("Call-path traversal reached the edge limit.");
|
||||
return;
|
||||
}
|
||||
state.edges.set(edgeKey, {
|
||||
source_address: sourceAddress,
|
||||
target_address: targetAddress,
|
||||
@@ -193,14 +165,6 @@ const recordEdge = (
|
||||
});
|
||||
};
|
||||
|
||||
const recordPendingFrontier = (
|
||||
state: TraceState,
|
||||
input: CallPathTraceInput,
|
||||
): void => {
|
||||
for (const pending of state.queue.slice(state.queueIndex - 1))
|
||||
if (state.frontier.size < input.max_nodes) state.frontier.add(pending);
|
||||
};
|
||||
|
||||
const projectTrace = (input: CallPathTraceInput, state: TraceState) => ({
|
||||
start: input.start,
|
||||
goal: input.goal ?? null,
|
||||
@@ -225,19 +189,13 @@ const projectTrace = (input: CallPathTraceInput, state: TraceState) => ({
|
||||
),
|
||||
traversal_path: state.traversalPath,
|
||||
failures: state.failures,
|
||||
frontier: [...state.frontier].sort(compareAddress),
|
||||
limits: {
|
||||
max_depth: input.max_depth,
|
||||
max_nodes: input.max_nodes,
|
||||
max_operations: input.max_operations,
|
||||
traversal: {
|
||||
nodes_visited: state.visited.size,
|
||||
operations_used: state.operations,
|
||||
},
|
||||
truncated: state.residual.size > 0,
|
||||
residual_unknowns: [...state.residual],
|
||||
limitations: [
|
||||
"Direct provider call relationships may omit unresolved indirect calls.",
|
||||
"A not_reached goal is only absent from this bounded traversal, not from the complete program.",
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ describe("capability inventory contract", () => {
|
||||
{
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
},
|
||||
);
|
||||
const unavailable = inventory.find(({ available }) => !available);
|
||||
|
||||
@@ -5,7 +5,6 @@ import { buildCapabilityInventory } from "./CapabilityInventory.js";
|
||||
const enabledPolicy: Parameters<typeof buildCapabilityInventory>[1] = {
|
||||
processCaptureEnabled: true,
|
||||
evidenceFileRoots: 1,
|
||||
investigationInputRoots: 1,
|
||||
browserObservationEnabled: true,
|
||||
browserScenarioEnabled: true,
|
||||
electronObservationEnabled: true,
|
||||
@@ -180,7 +179,6 @@ describe("capability inventory: caller guidance", () => {
|
||||
...enabledPolicy,
|
||||
processCaptureEnabled: false,
|
||||
evidenceFileRoots: 0,
|
||||
investigationInputRoots: 0,
|
||||
browserObservationEnabled: false,
|
||||
electronObservationEnabled: false,
|
||||
v8InspectorObservationEnabled: false,
|
||||
|
||||
@@ -29,7 +29,6 @@ type ProviderDescriptor = ProviderCapability;
|
||||
export type AvailabilityPolicy = {
|
||||
readonly processCaptureEnabled: boolean;
|
||||
readonly evidenceFileRoots: number;
|
||||
readonly investigationInputRoots: number;
|
||||
readonly browserObservationEnabled?: boolean;
|
||||
readonly browserScenarioEnabled?: boolean;
|
||||
readonly electronObservationEnabled?: boolean;
|
||||
@@ -190,16 +189,9 @@ const availabilityFor = (context: AvailabilityContext): Availability => {
|
||||
|
||||
const javascriptApplicationAvailability = ({
|
||||
name,
|
||||
policy,
|
||||
}: AvailabilityContext): Availability | null => {
|
||||
if (name === "analyze_javascript_application")
|
||||
return policy.investigationInputRoots === 0
|
||||
? {
|
||||
reason: "policy_disabled",
|
||||
remediation:
|
||||
"Configure an exact REA_INVESTIGATION_INPUT_ROOTS_JSON root in the MCP registration, then restart the registered MCP server or client.",
|
||||
}
|
||||
: { reason: "available", remediation: null };
|
||||
return { reason: "available", remediation: null };
|
||||
return name === "reconcile_javascript_runtime"
|
||||
? { reason: "available", remediation: null }
|
||||
: null;
|
||||
|
||||
@@ -42,7 +42,6 @@ export type VersionInventoryScanner = typeof scanAuthorizedArtifactInventory;
|
||||
export interface VersionInventoryScanOptions {
|
||||
readonly leftPath: string;
|
||||
readonly rightPath: string;
|
||||
readonly inputRoots: readonly string[];
|
||||
readonly limits: ArtifactLimits;
|
||||
readonly signal?: AbortSignal;
|
||||
readonly integrity: ArtifactIntegrityPolicy;
|
||||
@@ -54,11 +53,11 @@ export const scanVersionInventories = async (
|
||||
scanner: VersionInventoryScanner = scanAuthorizedArtifactInventory,
|
||||
): Promise<VersionSnapshots> => {
|
||||
const [left, right] = await Promise.all([
|
||||
scanner(options.leftPath, options.inputRoots, options.limits, {
|
||||
scanner(options.leftPath, options.limits, {
|
||||
signal: options.signal,
|
||||
integrity: options.integrity,
|
||||
}),
|
||||
scanner(options.rightPath, options.inputRoots, options.limits, {
|
||||
scanner(options.rightPath, options.limits, {
|
||||
signal: options.signal,
|
||||
integrity: options.integrity,
|
||||
}),
|
||||
@@ -69,7 +68,6 @@ export const scanVersionInventories = async (
|
||||
/** Authorize and scan both inputs once under the same bounded traversal policy. */
|
||||
export const scanVersions = async (
|
||||
input: CrossVersionInvestigationInput,
|
||||
inputRoots: readonly string[],
|
||||
signal?: AbortSignal,
|
||||
integrityContinueEnabled = false,
|
||||
): Promise<Result<VersionSnapshots, AnalysisError>> => {
|
||||
@@ -90,7 +88,6 @@ export const scanVersions = async (
|
||||
await scanVersionInventories({
|
||||
leftPath: input.left_path,
|
||||
rightPath: input.right_path,
|
||||
inputRoots,
|
||||
limits,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
integrity,
|
||||
|
||||
@@ -56,12 +56,10 @@ export interface CrossVersionInvestigationOutcome {
|
||||
|
||||
/** Runtime authority and cancellation capabilities for one investigation. */
|
||||
export interface CrossVersionInvestigationExecution {
|
||||
readonly inputRoots: readonly string[];
|
||||
readonly session?: BinarySessionPort;
|
||||
readonly signal?: AbortSignal;
|
||||
readonly progress?: ProgressReporter;
|
||||
readonly integrityContinueEnabled?: boolean;
|
||||
readonly authorizeInputRead?: () => Promise<Result<null, AnalysisError>>;
|
||||
readonly authorizeWorkspaceWrite?: () => Promise<Result<null, AnalysisError>>;
|
||||
}
|
||||
|
||||
@@ -106,10 +104,6 @@ export const runCrossVersionInvestigationValidated = async (
|
||||
execution.session,
|
||||
);
|
||||
}
|
||||
if (execution.authorizeInputRead !== undefined) {
|
||||
const authorized = await execution.authorizeInputRead();
|
||||
if (!authorized.ok) return authorized;
|
||||
}
|
||||
await execution.progress?.report({
|
||||
phase: "scan_versions",
|
||||
completed: 0,
|
||||
@@ -119,7 +113,6 @@ export const runCrossVersionInvestigationValidated = async (
|
||||
|
||||
const snapshots = await scanVersions(
|
||||
input,
|
||||
execution.inputRoots,
|
||||
execution.signal,
|
||||
execution.integrityContinueEnabled,
|
||||
);
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { parseConfig } from "../config.js";
|
||||
import { projectAnalysisError } from "../domain/errors.js";
|
||||
import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||
import {
|
||||
createServerIdentity,
|
||||
createServerIdentitySummary,
|
||||
} from "../serverIdentity.js";
|
||||
import { createServerIdentity } from "../serverIdentity.js";
|
||||
import { silentLogger, type Logger } from "../logger.js";
|
||||
import { createBinarySession } from "./runtime.js";
|
||||
|
||||
@@ -26,82 +23,10 @@ const runSessionStatus = async (
|
||||
}
|
||||
};
|
||||
|
||||
/** List provider identities, selection, and availability without capability bodies. */
|
||||
export const runProviderStatus = async (
|
||||
logger: Logger = silentLogger,
|
||||
detail: "summary" | "full" = "summary",
|
||||
): Promise<JsonValue> => {
|
||||
const fullStatus = await runSessionStatus(logger);
|
||||
if (detail === "full") return fullStatus;
|
||||
const parsedStatus = jsonObjectSchema.safeParse(fullStatus);
|
||||
if (!parsedStatus.success || parsedStatus.data.error !== undefined)
|
||||
return fullStatus;
|
||||
const status = parsedStatus.data;
|
||||
return {
|
||||
open: status.open ?? false,
|
||||
provider: status.provider ?? null,
|
||||
providers: status.providers ?? [],
|
||||
analysis_provider_binding: status.analysis_provider_binding ?? null,
|
||||
analysis_provider_candidates: projectJsonObjectArray(
|
||||
status.analysis_provider_candidates,
|
||||
["provider", "availability", "target_support", "selected"],
|
||||
),
|
||||
server_identity: createServerIdentitySummary({
|
||||
startedAt: new Date().toISOString(),
|
||||
}),
|
||||
};
|
||||
};
|
||||
/** List complete provider identities, capabilities, and availability. */
|
||||
export const runProviderStatus = (logger: Logger = silentLogger) =>
|
||||
runSessionStatus(logger);
|
||||
|
||||
/** List concise operation availability, with explicit full descriptor opt-in. */
|
||||
export const runCapabilityStatus = async (
|
||||
logger: Logger = silentLogger,
|
||||
detail: "summary" | "full" = "summary",
|
||||
): Promise<JsonValue> => {
|
||||
const fullStatus = await runSessionStatus(logger);
|
||||
if (detail === "full") return fullStatus;
|
||||
const parsedStatus = jsonObjectSchema.safeParse(fullStatus);
|
||||
if (!parsedStatus.success || parsedStatus.data.error !== undefined)
|
||||
return fullStatus;
|
||||
const status = parsedStatus.data;
|
||||
const capabilities = projectJsonObjectArray(status.capabilities, [
|
||||
"operation",
|
||||
"available",
|
||||
"reason",
|
||||
]);
|
||||
const available = capabilities.filter(
|
||||
(candidate) =>
|
||||
typeof candidate === "object" &&
|
||||
candidate !== null &&
|
||||
"available" in candidate &&
|
||||
candidate.available === true,
|
||||
).length;
|
||||
return {
|
||||
open: status.open ?? false,
|
||||
summary: {
|
||||
total: capabilities.length,
|
||||
available,
|
||||
unavailable: capabilities.length - available,
|
||||
},
|
||||
capabilities,
|
||||
analysis_provider_binding: status.analysis_provider_binding ?? null,
|
||||
server_identity: createServerIdentitySummary({
|
||||
startedAt: new Date().toISOString(),
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
const projectJsonObjectArray = (
|
||||
value: JsonValue | undefined,
|
||||
keys: readonly string[],
|
||||
): JsonValue[] =>
|
||||
Array.isArray(value)
|
||||
? value.map((candidate) => {
|
||||
const parsed = jsonObjectSchema.safeParse(candidate);
|
||||
if (!parsed.success) return candidate;
|
||||
return Object.fromEntries(
|
||||
keys.flatMap((key) =>
|
||||
parsed.data[key] === undefined ? [] : [[key, parsed.data[key]]],
|
||||
),
|
||||
);
|
||||
})
|
||||
: [];
|
||||
/** List complete operation descriptors and availability. */
|
||||
export const runCapabilityStatus = (logger: Logger = silentLogger) =>
|
||||
runSessionStatus(logger);
|
||||
|
||||
@@ -228,7 +228,7 @@ const collectDoctorIdentity = async (
|
||||
live_server: {
|
||||
state: "unknown",
|
||||
remediation:
|
||||
"Compare rea://server/identity or binary_session from the active client; an on-disk registration cannot prove the running server version.",
|
||||
"Call binary_session in the active client to inspect the running server identity.",
|
||||
},
|
||||
installations: {
|
||||
paths: installationPaths,
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import type { DoctorCheck, DoctorReport } from "./Doctor.js";
|
||||
|
||||
/** Project doctor diagnostics for concise CLI output or explicit full detail. */
|
||||
export const projectDoctorReport = (
|
||||
report: DoctorReport,
|
||||
detail: "summary" | "full",
|
||||
): DoctorReport | ReturnType<typeof doctorSummary> =>
|
||||
detail === "full" ? report : doctorSummary(report);
|
||||
|
||||
const doctorSummary = (report: DoctorReport) => ({
|
||||
healthy: report.healthy,
|
||||
environment_healthy: report.environment_healthy,
|
||||
scope: report.scope,
|
||||
...(report.hopperPath === undefined
|
||||
? {}
|
||||
: { hopper_path: report.hopperPath }),
|
||||
providers: (report.providerInspections ?? []).map((provider) => ({
|
||||
id: provider.id,
|
||||
configured: provider.configured,
|
||||
available: provider.available,
|
||||
provider_version: provider.providerVersion,
|
||||
failed_checks: provider.checks.filter(({ ok }) => !ok).map(checkSummary),
|
||||
})),
|
||||
failed_scope_checks: report.scope_checks
|
||||
.filter(({ ok }) => !ok)
|
||||
.map(checkSummary),
|
||||
informational_drift_count: report.informational_checks.filter(({ ok }) => !ok)
|
||||
.length,
|
||||
identity:
|
||||
report.identity === undefined
|
||||
? null
|
||||
: {
|
||||
cli_package_version: report.identity.cli_package_version,
|
||||
expected_skill_version: report.identity.expected_skill_version,
|
||||
catalog: {
|
||||
counts: report.identity.catalog.counts,
|
||||
digests: report.identity.catalog.digests,
|
||||
},
|
||||
installations: report.identity.installations,
|
||||
skill: report.identity.skill,
|
||||
registrations: report.identity.registrations,
|
||||
},
|
||||
});
|
||||
|
||||
const checkSummary = (
|
||||
check: Pick<DoctorCheck, "name" | "classification" | "detail"> & {
|
||||
readonly remediation?: string | null;
|
||||
},
|
||||
) => ({
|
||||
name: check.name,
|
||||
classification: check.classification,
|
||||
...(check.detail === undefined ? {} : { detail: check.detail }),
|
||||
...(check.remediation === undefined || check.remediation === null
|
||||
? {}
|
||||
: { remediation: check.remediation }),
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { digestJson } from "./JavaScriptReplayPlanning.js";
|
||||
|
||||
/** Create Evidence v2 without retaining arbitrary runtime argument values. */
|
||||
/** Create Evidence without retaining arbitrary runtime argument values. */
|
||||
export const createElectronActiveEvidence = (
|
||||
input: ElectronActiveObservationInput,
|
||||
result: ElectronActiveObservationResult,
|
||||
@@ -34,7 +34,6 @@ const scenarioProjection = (
|
||||
input: ElectronActiveObservationInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
approved: input.approved,
|
||||
schema_version: input.schema_version,
|
||||
executable_path: input.executable_path,
|
||||
application_path: input.application_path,
|
||||
application_root: input.application_root,
|
||||
|
||||
@@ -14,7 +14,7 @@ import type {
|
||||
|
||||
type ElectronOperation = "list_electron_targets" | "inspect_electron_page";
|
||||
|
||||
/** Create Evidence v2 for one root-confined Electron observation. */
|
||||
/** Create Evidence for one Electron observation. */
|
||||
export const createElectronEvidence = (
|
||||
operation: ElectronOperation,
|
||||
input: ListElectronTargetsInput | InspectElectronPageInput,
|
||||
@@ -56,5 +56,5 @@ const parameters = (
|
||||
source_capture_approved: input.source_capture_approved,
|
||||
limits: input.limits,
|
||||
}
|
||||
: { offset: input.offset, limit: input.limit }),
|
||||
: {}),
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import type { AnalysisOperation } from "./AnalysisProvider.js";
|
||||
import { AnalysisOutputError, type AnalysisError } from "../domain/errors.js";
|
||||
import { parseAddressedPage } from "../domain/hopperValues.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type {
|
||||
@@ -16,33 +16,29 @@ type AnalysisCall = (
|
||||
) => Promise<Result<JsonValue, AnalysisError>>;
|
||||
|
||||
type LiteralSearchSource = readonly [
|
||||
"list_strings" | "list_procedures",
|
||||
"search_strings" | "search_procedures",
|
||||
"string" | "procedure",
|
||||
];
|
||||
|
||||
interface ReferenceTraceRequest {
|
||||
readonly matches: readonly TraceMatch[];
|
||||
readonly limit: number;
|
||||
readonly operationBudget: number;
|
||||
readonly signal?: AbortSignal;
|
||||
}
|
||||
|
||||
const FEATURE_SEARCH_SOURCES: readonly LiteralSearchSource[] = [
|
||||
["list_strings", "string"],
|
||||
["list_procedures", "procedure"],
|
||||
["search_strings", "string"],
|
||||
["search_procedures", "procedure"],
|
||||
];
|
||||
const STRING_SEARCH_SOURCES: readonly LiteralSearchSource[] = [
|
||||
["list_strings", "string"],
|
||||
["search_strings", "string"],
|
||||
];
|
||||
|
||||
export interface LiteralTraceInput {
|
||||
readonly query: string;
|
||||
readonly case_sensitive: boolean;
|
||||
readonly limit: number;
|
||||
readonly max_operations: number;
|
||||
}
|
||||
|
||||
/** Trace a bounded feature or string literal through provider xrefs. */
|
||||
/** Trace every matching feature or string literal through provider xrefs. */
|
||||
export const traceLiteralFeature = async (
|
||||
call: AnalysisCall,
|
||||
input: LiteralTraceInput,
|
||||
@@ -53,29 +49,18 @@ export const traceLiteralFeature = async (
|
||||
scope === "feature" ? FEATURE_SEARCH_SOURCES : STRING_SEARCH_SOURCES;
|
||||
const searched = await literalMatches(call, input, sources, signal);
|
||||
if (!searched.ok) return searched;
|
||||
const residual = new Set<string>();
|
||||
const traced = await traceReferences(call, {
|
||||
matches: searched.value.matches,
|
||||
limit: input.limit,
|
||||
operationBudget: input.max_operations - searched.value.operations,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
});
|
||||
if (!traced.ok) return traced;
|
||||
for (const reason of traced.value.residual) residual.add(reason);
|
||||
const operations = searched.value.operations + traced.value.operations;
|
||||
if (operations >= input.max_operations)
|
||||
residual.add("Investigation reached the operation budget.");
|
||||
if (searched.value.matches.length >= input.limit)
|
||||
residual.add("Literal matches reached the configured limit.");
|
||||
return ok({
|
||||
query: input.query,
|
||||
search_mode: "literal",
|
||||
operations_used: operations,
|
||||
operation_budget: input.max_operations,
|
||||
matches: searched.value.matches,
|
||||
references: traced.value.references,
|
||||
truncated: residual.size > 0,
|
||||
residual_unknowns: [...residual],
|
||||
truncated: false,
|
||||
residual_unknowns: [],
|
||||
});
|
||||
};
|
||||
|
||||
@@ -84,53 +69,70 @@ const literalMatches = async (
|
||||
input: LiteralTraceInput,
|
||||
sources: readonly LiteralSearchSource[],
|
||||
signal?: AbortSignal,
|
||||
): Promise<
|
||||
Result<{ matches: TraceMatch[]; operations: number }, AnalysisError>
|
||||
> => {
|
||||
let operations = 0;
|
||||
): Promise<Result<{ matches: TraceMatch[] }, AnalysisError>> => {
|
||||
const matches: TraceMatch[] = [];
|
||||
const needle = input.case_sensitive ? input.query : input.query.toLowerCase();
|
||||
for (const [tool, type] of sources) {
|
||||
let offset = 0;
|
||||
while (operations < input.max_operations && matches.length < input.limit) {
|
||||
operations += 1;
|
||||
const result = await call(tool, { offset, limit: 500 }, signal);
|
||||
const needles = [...new Set(input.query.trim().split(/\s+/u))];
|
||||
const matched = new Set<string>();
|
||||
for (const needle of needles) {
|
||||
for (const [tool, type] of sources) {
|
||||
const result = await call(
|
||||
tool,
|
||||
{
|
||||
pattern: needle,
|
||||
mode: "literal",
|
||||
case_sensitive: input.case_sensitive,
|
||||
},
|
||||
signal,
|
||||
);
|
||||
if (!result.ok) return result;
|
||||
const page = parseAddressedPage(result.value);
|
||||
if (!page.ok) return page;
|
||||
for (const item of page.value.items) {
|
||||
const haystack = input.case_sensitive
|
||||
? item.name
|
||||
: item.name.toLowerCase();
|
||||
if (haystack.includes(needle))
|
||||
matches.push({ type, address: item.address, value: item.name });
|
||||
if (matches.length >= input.limit) break;
|
||||
}
|
||||
if (!page.value.hasMore || page.value.nextOffset === null) break;
|
||||
offset = page.value.nextOffset;
|
||||
const items = z
|
||||
.array(z.object({ address: z.string(), value: z.string() }))
|
||||
.safeParse(result.value);
|
||||
if (!items.success)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
tool,
|
||||
"provider returned an invalid search result",
|
||||
),
|
||||
);
|
||||
addPageMatches({
|
||||
items: items.data.map(({ address, value: name }) => ({
|
||||
address,
|
||||
name,
|
||||
})),
|
||||
type,
|
||||
matches,
|
||||
matched,
|
||||
});
|
||||
}
|
||||
}
|
||||
return ok({ matches, operations });
|
||||
return ok({ matches });
|
||||
};
|
||||
|
||||
const addPageMatches = (input: {
|
||||
readonly items: readonly {
|
||||
readonly address: string;
|
||||
readonly name: string;
|
||||
}[];
|
||||
readonly type: TraceMatch["type"];
|
||||
readonly matches: TraceMatch[];
|
||||
readonly matched: Set<string>;
|
||||
}): void => {
|
||||
const { items, type, matches, matched } = input;
|
||||
for (const item of items) {
|
||||
const key = `${type}\u0000${item.address}`;
|
||||
if (matched.has(key)) continue;
|
||||
matches.push({ type, address: item.address, value: item.name });
|
||||
matched.add(key);
|
||||
}
|
||||
};
|
||||
|
||||
const traceReferences = async (
|
||||
call: AnalysisCall,
|
||||
request: ReferenceTraceRequest,
|
||||
): Promise<
|
||||
Result<
|
||||
{ references: TraceReference[]; operations: number; residual: string[] },
|
||||
AnalysisError
|
||||
>
|
||||
> => {
|
||||
let operations = 0;
|
||||
): Promise<Result<{ references: TraceReference[] }, AnalysisError>> => {
|
||||
const references: TraceReference[] = [];
|
||||
const residual = new Set<string>();
|
||||
for (const match of request.matches) {
|
||||
if (operations >= request.operationBudget) {
|
||||
residual.add("Reference traversal stopped at the operation budget.");
|
||||
break;
|
||||
}
|
||||
operations += 1;
|
||||
const xrefs = await call(
|
||||
"xrefs",
|
||||
{ address: match.address },
|
||||
@@ -152,13 +154,6 @@ const traceReferences = async (
|
||||
"provider returned a non-address value",
|
||||
),
|
||||
);
|
||||
if (operations >= request.operationBudget) {
|
||||
residual.add(
|
||||
"Containing-procedure resolution stopped at the operation budget.",
|
||||
);
|
||||
break;
|
||||
}
|
||||
operations += 1;
|
||||
const resolved = await call(
|
||||
"resolve_containing_procedure",
|
||||
{ address: source },
|
||||
@@ -170,16 +165,7 @@ const traceReferences = async (
|
||||
source_address: source,
|
||||
containing_procedure: resolved.value,
|
||||
});
|
||||
if (references.length >= request.limit) {
|
||||
residual.add("Reference results reached the configured limit.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (references.length >= request.limit) break;
|
||||
}
|
||||
return ok({
|
||||
references,
|
||||
operations,
|
||||
residual: [...residual],
|
||||
});
|
||||
return ok({ references });
|
||||
};
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import type { AnalysisOperation } from "./AnalysisProvider.js";
|
||||
import { AnalysisOutputError, type AnalysisError } from "../domain/errors.js";
|
||||
import { parseAddressedPage } from "../domain/hopperValues.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
|
||||
type PageCall = (
|
||||
name: AnalysisOperation,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
signal?: AbortSignal,
|
||||
) => Promise<Result<JsonValue, AnalysisError>>;
|
||||
|
||||
/** Read all addressed entries while enforcing advancing provider pagination. */
|
||||
export const readAllAddressed = async (input: {
|
||||
readonly call: PageCall;
|
||||
readonly tool: "list_names" | "list_procedures";
|
||||
readonly signal?: AbortSignal;
|
||||
}) => {
|
||||
const entries: Array<{ address: string; name: string }> = [];
|
||||
let offset = 0;
|
||||
while (true) {
|
||||
const result = await input.call(
|
||||
input.tool,
|
||||
{ offset, limit: 500 },
|
||||
input.signal,
|
||||
);
|
||||
if (!result.ok) return result;
|
||||
const page = parseAddressedPage(result.value);
|
||||
if (!page.ok) return page;
|
||||
entries.push(...page.value.items);
|
||||
if (!page.value.hasMore || page.value.nextOffset === null)
|
||||
return ok(entries);
|
||||
if (page.value.nextOffset <= offset)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
input.tool,
|
||||
"provider returned a non-advancing pagination offset",
|
||||
),
|
||||
);
|
||||
offset = page.value.nextOffset;
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { z } from "zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import type {
|
||||
AnalysisOperation,
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
type EnhancedResult,
|
||||
type ValidatedEnhancedCall,
|
||||
} from "./EnhancedToolTypes.js";
|
||||
import { readAllAddressed } from "./EnhancedToolPagination.js";
|
||||
import { traceCallPath } from "./CallPathTracing.js";
|
||||
import { traceLiteralFeature } from "./EnhancedLiteralTracing.js";
|
||||
import { projectNativeApiInspection } from "./NativeApiInspection.js";
|
||||
@@ -128,7 +127,7 @@ export class EnhancedTools {
|
||||
case "find_xrefs_to_name":
|
||||
return this.#findXrefs(call.input.name, signal);
|
||||
case "binary_overview":
|
||||
return this.#binaryOverview(call.input, signal);
|
||||
return this.#binaryOverview(signal);
|
||||
case "analyze_function":
|
||||
return this.#analyzeFunction(call.input, signal);
|
||||
case "inspect_native_api":
|
||||
@@ -208,9 +207,6 @@ export class EnhancedTools {
|
||||
): EnhancedResult {
|
||||
const analysisInput = enhancedInputSchemas.analyze_function.parse({
|
||||
procedure: input.procedure,
|
||||
include_assembly: true,
|
||||
max_pseudocode_chars: input.max_pseudocode_chars,
|
||||
max_instructions: input.max_instructions,
|
||||
});
|
||||
const result = await this.#call("analyze_function", analysisInput, signal);
|
||||
if (!result.ok) return result;
|
||||
@@ -281,7 +277,6 @@ export class EnhancedTools {
|
||||
input: {
|
||||
readonly address: string;
|
||||
readonly direction: "forward" | "backward";
|
||||
readonly depth: number;
|
||||
},
|
||||
signal?: AbortSignal,
|
||||
): EnhancedResult {
|
||||
@@ -297,9 +292,7 @@ export class EnhancedTools {
|
||||
|
||||
while (queueIndex < queue.length) {
|
||||
const current = queue[queueIndex++];
|
||||
if (current === undefined || current.depth >= input.depth) {
|
||||
continue;
|
||||
}
|
||||
if (current === undefined) continue;
|
||||
const level = String(current.depth);
|
||||
graph[level] ??= [];
|
||||
|
||||
@@ -330,12 +323,10 @@ export class EnhancedTools {
|
||||
status: "ok",
|
||||
calls: [...related.value],
|
||||
});
|
||||
if (current.depth + 1 < input.depth) {
|
||||
for (const address of related.value) {
|
||||
if (!discovered.has(address)) {
|
||||
discovered.add(address);
|
||||
queue.push({ address, depth: current.depth + 1 });
|
||||
}
|
||||
for (const address of related.value) {
|
||||
if (!discovered.has(address)) {
|
||||
discovered.add(address);
|
||||
queue.push({ address, depth: current.depth + 1 });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,16 +371,13 @@ export class EnhancedTools {
|
||||
});
|
||||
}
|
||||
|
||||
async #binaryOverview(
|
||||
input: { detail: "concise" | "detailed"; limit: number },
|
||||
signal?: AbortSignal,
|
||||
): EnhancedResult {
|
||||
async #binaryOverview(signal?: AbortSignal): EnhancedResult {
|
||||
const [segmentsResult, documentsResult, proceduresResult, stringsResult] =
|
||||
await Promise.all([
|
||||
this.#call("list_segments", {}, signal),
|
||||
this.#call("list_documents", {}, signal),
|
||||
this.#call("list_procedures", { offset: 0, limit: 1 }, signal),
|
||||
this.#call("list_strings", { offset: 0, limit: 1 }, signal),
|
||||
this.#call("list_procedures", {}, signal),
|
||||
this.#call("list_strings", {}, signal),
|
||||
]);
|
||||
if (!segmentsResult.ok) return segmentsResult;
|
||||
if (!documentsResult.ok) return documentsResult;
|
||||
@@ -407,14 +395,12 @@ export class EnhancedTools {
|
||||
|
||||
return ok({
|
||||
document: documents.value[0] ?? "unknown",
|
||||
detail: input.detail,
|
||||
segments: segments.value
|
||||
.slice(0, input.limit)
|
||||
.map(({ name, start, end }) =>
|
||||
input.detail === "detailed"
|
||||
? { name, start, end, length: addressDistance(start, end) }
|
||||
: { name, start, end },
|
||||
),
|
||||
segments: segments.value.map(({ name, start, end }) => ({
|
||||
name,
|
||||
start,
|
||||
end,
|
||||
length: addressDistance(start, end),
|
||||
})),
|
||||
segment_count: segments.value.length,
|
||||
procedure_count: procedureCount.value,
|
||||
string_count: stringCount.value,
|
||||
@@ -425,12 +411,19 @@ export class EnhancedTools {
|
||||
tool: "list_names" | "list_procedures",
|
||||
signal?: AbortSignal,
|
||||
) {
|
||||
return readAllAddressed({
|
||||
call: (name, arguments_, operationSignal) =>
|
||||
this.#call(name, arguments_, operationSignal),
|
||||
tool,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
});
|
||||
const result = await this.#call(tool, {}, signal);
|
||||
if (!result.ok) return result;
|
||||
const parsed = z
|
||||
.array(z.object({ address: z.string(), value: z.string() }))
|
||||
.safeParse(result.value);
|
||||
return parsed.success
|
||||
? ok(parsed.data.map(({ address, value: name }) => ({ address, name })))
|
||||
: err(
|
||||
new AnalysisOutputError(
|
||||
tool,
|
||||
"provider returned an invalid inventory",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async #call(
|
||||
@@ -438,12 +431,16 @@ export class EnhancedTools {
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<JsonValue, AnalysisError>> {
|
||||
if (signal?.aborted === true) return err(new AnalysisCancelledError(name));
|
||||
if (isAborted(signal)) return err(new AnalysisCancelledError(name));
|
||||
const execution = await this.analysis.execute(
|
||||
name,
|
||||
arguments_,
|
||||
signal === undefined ? {} : { signal },
|
||||
);
|
||||
if (isAborted(signal)) return err(new AnalysisCancelledError(name));
|
||||
return execution.ok ? ok(execution.value.result) : execution;
|
||||
}
|
||||
}
|
||||
|
||||
const isAborted = (signal: AbortSignal | undefined): boolean =>
|
||||
signal?.aborted === true;
|
||||
|
||||
@@ -49,7 +49,7 @@ export const exportEvidenceBundleCommand = async (
|
||||
);
|
||||
};
|
||||
|
||||
/** Compare two validated canonical Evidence v2 bundles without session state. */
|
||||
/** Compare two validated canonical Evidence bundles without session state. */
|
||||
export const compareEvidenceBundlesCommand = async (input: {
|
||||
readonly leftPath: string;
|
||||
readonly rightPath: string;
|
||||
|
||||
@@ -6,10 +6,7 @@ import {
|
||||
} from "../domain/evidenceBundle.js";
|
||||
import { EvidenceFileError, EvidenceIntegrityError } from "../domain/errors.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
LEGACY_PROCESS_CAPTURE_MESSAGE,
|
||||
parseProcessCapture,
|
||||
} from "../domain/processCapture.js";
|
||||
import { parseProcessCapture } from "../domain/processCapture.js";
|
||||
import { readBoundedJson, writeBoundedText } from "./BoundedJsonFiles.js";
|
||||
|
||||
type EvidenceReadFailure = EvidenceFileError | EvidenceIntegrityError;
|
||||
@@ -27,9 +24,7 @@ export const readEvidenceBundle = async (
|
||||
try {
|
||||
const bundle = parseEvidenceBundle(loaded.value);
|
||||
for (const record of bundle.records) {
|
||||
if (record.predicate_type === "rea.process-capture/v3")
|
||||
throw new TypeError(LEGACY_PROCESS_CAPTURE_MESSAGE);
|
||||
if (record.predicate_type === "rea.process-capture/v4")
|
||||
if (record.predicate_type === "rea.process-capture")
|
||||
parseProcessCapture(record.normalized_result);
|
||||
}
|
||||
return ok(bundle);
|
||||
|
||||
@@ -39,7 +39,7 @@ interface InventoryProjectionOptions<
|
||||
readonly protocolError: string;
|
||||
}
|
||||
|
||||
/** Parse one inventory projection and wrap its deterministic result in Evidence v2. */
|
||||
/** Parse one inventory projection and wrap its deterministic result in Evidence. */
|
||||
export const projectInventoryEvidence = <
|
||||
Input extends InventoryProjectionInput,
|
||||
Output extends InventoryProjectionResult,
|
||||
|
||||
@@ -14,7 +14,7 @@ export const REA_WORKFLOW_PROVIDER = {
|
||||
export const workflowAnalysisProfile = (
|
||||
upstream: AnalysisProfileCommitment,
|
||||
): AnalysisProfileCommitment =>
|
||||
createAnalysisProfile(REA_WORKFLOW_PROVIDER, 1, {
|
||||
createAnalysisProfile(REA_WORKFLOW_PROVIDER, {
|
||||
upstream_analysis_profile: upstream,
|
||||
});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { JAVASCRIPT_APPLICATION_PROVIDER } from "./InvestigationProviders.js";
|
||||
|
||||
/** Create Evidence v2 for one deterministic local JavaScript application graph. */
|
||||
/** Create Evidence for one deterministic local JavaScript application graph. */
|
||||
export const createJavaScriptApplicationEvidence = (
|
||||
input: AnalyzeJavaScriptApplicationInput,
|
||||
result: JavaScriptApplicationAnalysisResult,
|
||||
@@ -23,7 +23,7 @@ export const createJavaScriptApplicationEvidence = (
|
||||
},
|
||||
JAVASCRIPT_APPLICATION_PROVIDER,
|
||||
{
|
||||
predicateType: `rea.javascript-application-analysis/v${String(result.schema_version)}`,
|
||||
predicateType: "rea.javascript-application-analysis",
|
||||
operation: "analyze_javascript_application",
|
||||
parameters: parameters(input),
|
||||
result: jsonValueSchema.parse(result),
|
||||
@@ -40,7 +40,5 @@ const parameters = (
|
||||
input: AnalyzeJavaScriptApplicationInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
format: input.format,
|
||||
approved: input.approved,
|
||||
source_map_read_approved: input.source_map_read_approved,
|
||||
limits: input.limits,
|
||||
});
|
||||
|
||||
@@ -33,10 +33,7 @@ export const parseApplicationGraphEvidence = (
|
||||
const evidence = parseEvidence(input);
|
||||
if (
|
||||
evidence.operation === "analyze_javascript_application" &&
|
||||
[
|
||||
"rea.javascript-application-analysis/v1",
|
||||
"rea.javascript-application-analysis/v2",
|
||||
].includes(evidence.predicate_type) &&
|
||||
evidence.predicate_type === "rea.javascript-application-analysis" &&
|
||||
providerMatches(evidence, JAVASCRIPT_APPLICATION_PROVIDER)
|
||||
)
|
||||
return staticApplicationSource(evidence);
|
||||
@@ -70,12 +67,9 @@ const staticApplicationSource = (
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
if (
|
||||
evidence.predicate_type !==
|
||||
`rea.javascript-application-analysis/v${String(result.schema_version)}`
|
||||
)
|
||||
if (evidence.predicate_type !== "rea.javascript-application-analysis")
|
||||
throw new TypeError(
|
||||
"JavaScript application Evidence predicate does not match its result schema version",
|
||||
"JavaScript application Evidence predicate does not match its result shape",
|
||||
);
|
||||
analyzeJavaScriptApplicationInputSchema.parse({
|
||||
input_path: result.input_path,
|
||||
@@ -87,7 +81,7 @@ const staticApplicationSource = (
|
||||
graph: result.graph,
|
||||
kind: "static-application",
|
||||
rootArtifactSha256: result.root_artifact_sha256,
|
||||
semanticGraph: result.schema_version === 2 ? result.semantic_graph : null,
|
||||
semanticGraph: result.semantic_graph,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -6,11 +6,9 @@ import {
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
} from "../domain/javascriptApplicationAnalysis.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisProtocolError,
|
||||
ArtifactOperationError,
|
||||
PermissionRequiredError,
|
||||
type AnalysisError,
|
||||
} from "../domain/errors.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
@@ -19,13 +17,11 @@ import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { ExecutionOptions } from "./AnalysisProvider.js";
|
||||
import { createJavaScriptApplicationEvidence } from "./JavaScriptApplicationEvidence.js";
|
||||
import { reconstructJavaScriptArtifact } from "./JavaScriptArtifactReconstruction.js";
|
||||
import type { PermissionAuthority } from "./PermissionAuthority.js";
|
||||
|
||||
const OPERATION = "analyze_javascript_application" as const;
|
||||
|
||||
/** Authorize and statically analyze one local JavaScript/Electron application. */
|
||||
/** Statically analyze one local JavaScript/Electron application. */
|
||||
export const analyzeJavaScriptApplication = async (
|
||||
authority: PermissionAuthority | undefined,
|
||||
rawInput: unknown,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
@@ -38,65 +34,31 @@ export const analyzeJavaScriptApplication = async (
|
||||
projectInputIssues(parsed.error.issues, rawInput),
|
||||
),
|
||||
);
|
||||
return analyzeJavaScriptApplicationValidated(authority, parsed.data, options);
|
||||
return analyzeJavaScriptApplicationValidated(parsed.data, options);
|
||||
};
|
||||
|
||||
/** Analyze input already parsed by a trusted adapter boundary. */
|
||||
export const analyzeJavaScriptApplicationValidated = async (
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: z.output<typeof analyzeJavaScriptApplicationInputSchema>,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
if (authority === undefined)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"rea-javascript-application",
|
||||
OPERATION,
|
||||
"JavaScript application permission policy is not configured",
|
||||
),
|
||||
);
|
||||
const authorized = await authority.authorize(
|
||||
{
|
||||
capability: "investigation_input",
|
||||
roots: [input.input_path],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
network: "none",
|
||||
mount: false,
|
||||
operation_identity: `${OPERATION}:${input.input_path}`,
|
||||
},
|
||||
"read",
|
||||
);
|
||||
if (!authorized.ok)
|
||||
return err(
|
||||
authorized.error instanceof PermissionRequiredError
|
||||
? authorized.error
|
||||
: new ArtifactOperationError(OPERATION, "path", {
|
||||
logicalPath: input.input_path,
|
||||
declaredSha256: null,
|
||||
calculatedSha256: null,
|
||||
unpacked: false,
|
||||
}),
|
||||
);
|
||||
await options.progress?.report({
|
||||
phase: "analyze_javascript_application",
|
||||
completed: 0,
|
||||
total: 1,
|
||||
message: "Inventorying and parsing approved application artifacts",
|
||||
message: "Inventorying and parsing application artifacts",
|
||||
});
|
||||
try {
|
||||
const reconstructed = await reconstructJavaScriptArtifact(
|
||||
{
|
||||
input_path: input.input_path,
|
||||
format: input.format,
|
||||
source_map_read_approved: input.source_map_read_approved,
|
||||
limits: input.limits,
|
||||
},
|
||||
options.signal,
|
||||
);
|
||||
const { electron_summary: summary, ...application } = reconstructed;
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse({
|
||||
schema_version: 2,
|
||||
...application,
|
||||
summary,
|
||||
limitations: reconstructed.graph.limitations,
|
||||
|
||||
@@ -60,7 +60,6 @@ export const traceApplicationFeatureEvidenceValidated = (
|
||||
nativeEvidence,
|
||||
seed: input.seed,
|
||||
direction: input.direction,
|
||||
limits: input.limits,
|
||||
});
|
||||
return ok(
|
||||
createApplicationFeatureTraceEvidence(
|
||||
@@ -69,7 +68,6 @@ export const traceApplicationFeatureEvidenceValidated = (
|
||||
native_evidence_ids: nativeEvidence.map(({ evidence_id: id }) => id),
|
||||
seed: input.seed,
|
||||
direction: input.direction,
|
||||
limits: input.limits,
|
||||
},
|
||||
result,
|
||||
),
|
||||
|
||||
@@ -100,11 +100,6 @@ const finalizeArtifactAnalysis = (
|
||||
limitations: [
|
||||
"JavaScript and HTML were parsed as inert text; bundle bootstrap code was never executed.",
|
||||
"Static paths and relationships may remain unresolved when expressions are dynamic or obfuscated.",
|
||||
...(input.source_map_read_approved
|
||||
? []
|
||||
: [
|
||||
"Source maps were inventoried but their contents were not read without separate approval.",
|
||||
]),
|
||||
...(truncatedScopes === 0
|
||||
? []
|
||||
: ["One or more static-analysis scopes reached an approved bound."]),
|
||||
@@ -419,16 +414,14 @@ const unavailableSourceMap = (
|
||||
): JavaScriptSourceMapObservation => {
|
||||
if (file.text.included)
|
||||
throw new TypeError("Expected unavailable source-map text");
|
||||
const notApproved = file.text.reason === "not-approved";
|
||||
return {
|
||||
path: file.path,
|
||||
sha256: file.sha256,
|
||||
status: notApproved ? "not-approved" : "invalid",
|
||||
status: "invalid",
|
||||
sources: [],
|
||||
omitted_sources: 0,
|
||||
limitation: notApproved
|
||||
? "Source-map content requires separate approval."
|
||||
: "Source-map text was unavailable within approved limits.",
|
||||
limitation:
|
||||
"Source-map text was unavailable within the selected input limits.",
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export interface JavaScriptHtmlScriptObservation {
|
||||
readonly location: JavaScriptSourceRange;
|
||||
}
|
||||
|
||||
/** One original source declared by an approved local source map. */
|
||||
/** One original source declared by a local source map. */
|
||||
export interface JavaScriptSourceMapOriginal {
|
||||
readonly source: string;
|
||||
readonly content: string | null;
|
||||
@@ -68,7 +68,7 @@ export type JavaScriptSourceMapObservation = JavaScriptStructuredObservation &
|
||||
readonly limitation: string;
|
||||
}
|
||||
| {
|
||||
readonly status: "invalid" | "not-approved";
|
||||
readonly status: "invalid";
|
||||
readonly sources: readonly [];
|
||||
readonly omitted_sources: 0;
|
||||
readonly limitation: string;
|
||||
|
||||
@@ -40,7 +40,6 @@ export interface JavaScriptArtifactFile {
|
||||
readonly included: false;
|
||||
readonly reason:
|
||||
| "not-applicable"
|
||||
| "not-approved"
|
||||
| "file-limit"
|
||||
| "byte-limit"
|
||||
| "invalid-utf8";
|
||||
@@ -63,7 +62,6 @@ export interface JavaScriptArtifactFileSet {
|
||||
readonly text_bytes_read: number;
|
||||
readonly omitted_text_files: number;
|
||||
readonly limit_omitted_text_files: number;
|
||||
readonly policy_filtered_text_files: number;
|
||||
readonly invalid_utf8_files: number;
|
||||
}
|
||||
|
||||
@@ -77,7 +75,7 @@ interface ExpectedFile {
|
||||
|
||||
interface Selection {
|
||||
readonly selected: boolean;
|
||||
readonly reason: "file-limit" | "byte-limit" | "not-approved" | null;
|
||||
readonly reason: "file-limit" | "byte-limit" | null;
|
||||
}
|
||||
|
||||
interface ReadContext {
|
||||
@@ -143,9 +141,6 @@ export const readJavaScriptArtifactFiles = async (
|
||||
limit_omitted_text_files: [...selections.values()].filter(
|
||||
({ reason }) => reason === "file-limit" || reason === "byte-limit",
|
||||
).length,
|
||||
policy_filtered_text_files: [...selections.values()].filter(
|
||||
({ reason }) => reason === "not-approved",
|
||||
).length,
|
||||
invalid_utf8_files: context.invalidUtf8,
|
||||
};
|
||||
};
|
||||
@@ -306,10 +301,6 @@ const selectTextFiles = (
|
||||
});
|
||||
for (const file of ordered) {
|
||||
if (file.kind === "native-addon") continue;
|
||||
if (file.kind === "source-map" && !input.source_map_read_approved) {
|
||||
selected.set(file.path, { selected: false, reason: "not-approved" });
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
fileCount >= input.limits.max_text_files ||
|
||||
file.bytes > input.limits.max_text_file_bytes
|
||||
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
collectElectronIpcRecords,
|
||||
} from "./ElectronBoundaryAnalysis.js";
|
||||
|
||||
/** Project bounded artifact and AST facts into JavaScript Application Graph v1. */
|
||||
/** Project bounded artifact and AST facts into JavaScript Application Graph. */
|
||||
export const buildJavaScriptArtifactGraph = (
|
||||
snapshot: ArtifactInventorySnapshot,
|
||||
fileSet: JavaScriptArtifactFileSet,
|
||||
@@ -75,7 +75,6 @@ export const buildJavaScriptArtifactGraph = (
|
||||
const coverage = graphCoverage(context);
|
||||
return createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
schema_version: 1,
|
||||
root_node_ids:
|
||||
packageRoots.length === 0
|
||||
? [root.node_id]
|
||||
@@ -92,7 +91,7 @@ const graphCoverage = (context: JavaScriptArtifactGraphContext) => {
|
||||
context.fileSet.limit_omitted_text_files +
|
||||
context.accumulator.omittedObservations();
|
||||
const sourceMapPolicyGap = context.analysis.source_maps.some(
|
||||
({ status }) => status === "not-approved",
|
||||
({ status }) => status === "invalid",
|
||||
);
|
||||
const malformedStructuredData =
|
||||
context.analysis.packages.some(({ status }) => status !== "included") ||
|
||||
|
||||
@@ -187,10 +187,7 @@ export const addJavaScriptArtifactFiles = (
|
||||
const sourceMap = context.analysis.source_maps.find(
|
||||
({ path }) => path === file.path,
|
||||
);
|
||||
if (
|
||||
sourceMap !== undefined &&
|
||||
(sourceMap.status === "invalid" || sourceMap.status === "not-approved")
|
||||
)
|
||||
if (sourceMap !== undefined && sourceMap.status === "invalid")
|
||||
addUnavailableStaticParseScope(context, {
|
||||
file,
|
||||
asset: target,
|
||||
|
||||
@@ -39,7 +39,6 @@ export interface JavaScriptArtifactReconstructionResult {
|
||||
readonly text_bytes_read: number;
|
||||
readonly omitted_text_files: number;
|
||||
readonly limit_omitted_text_files: number;
|
||||
readonly policy_filtered_text_files: number;
|
||||
readonly invalid_utf8_files: number;
|
||||
readonly parsed_javascript_files: number;
|
||||
readonly visited_ast_nodes: number;
|
||||
@@ -109,7 +108,6 @@ export const reconstructJavaScriptArtifact = async (
|
||||
text_bytes_read: files.text_bytes_read,
|
||||
omitted_text_files: files.omitted_text_files,
|
||||
limit_omitted_text_files: files.limit_omitted_text_files,
|
||||
policy_filtered_text_files: files.policy_filtered_text_files,
|
||||
invalid_utf8_files: files.invalid_utf8_files,
|
||||
parsed_javascript_files: analysis.files.filter(
|
||||
({ javascript }) => javascript !== null,
|
||||
|
||||
@@ -6,11 +6,10 @@ import {
|
||||
javascriptApplicationAnalysisLimitsSchema,
|
||||
} from "../domain/javascriptApplicationAnalysis.js";
|
||||
|
||||
/** Local ASAR/directory reconstruction request with explicit source-map authority. */
|
||||
/** Local ASAR/directory reconstruction request. */
|
||||
export const javascriptArtifactReconstructionInputSchema = z.strictObject({
|
||||
input_path: z.string().min(1).max(16_384),
|
||||
input_path: z.string().min(1),
|
||||
format: z.enum(["auto", "asar", "directory"]).default("auto"),
|
||||
source_map_read_approved: z.boolean().default(false),
|
||||
limits: javascriptApplicationAnalysisLimitsSchema.default(
|
||||
JAVASCRIPT_APPLICATION_ANALYSIS_DEFAULT_LIMITS,
|
||||
),
|
||||
|
||||
@@ -16,7 +16,7 @@ type RuntimeObservationOperation =
|
||||
| "list_javascript_runtime_targets"
|
||||
| "observe_javascript_runtime";
|
||||
|
||||
/** Create deterministic Evidence v2 for one passive Inspector operation. */
|
||||
/** Create deterministic Evidence for one passive Inspector operation. */
|
||||
export const createJavaScriptRuntimeObservationEvidence = (
|
||||
operation: RuntimeObservationOperation,
|
||||
input: ListJavaScriptRuntimeTargetsInput | ObserveJavaScriptRuntimeInput,
|
||||
@@ -56,5 +56,5 @@ const parameters = (
|
||||
observation_ms: input.observation_ms,
|
||||
limits: input.limits,
|
||||
}
|
||||
: { offset: input.offset, limit: input.limit }),
|
||||
: {}),
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import type {
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER } from "./InvestigationProviders.js";
|
||||
|
||||
/** Create derived Evidence v2 for one exact set of static/runtime inputs. */
|
||||
/** Create derived Evidence for one exact set of static/runtime inputs. */
|
||||
export const createJavaScriptRuntimeReconciliationEvidence = (
|
||||
input: ReconcileJavaScriptRuntimeInput,
|
||||
result: JavaScriptRuntimeReconciliationResult,
|
||||
|
||||
@@ -101,7 +101,6 @@ export const buildJavaScriptSemanticGraph = ({
|
||||
const unknowns = [...state.unknowns.values()];
|
||||
return createJavaScriptSemanticGraph({
|
||||
schema: "JavaScriptSemanticRelationGraph",
|
||||
schema_version: 1,
|
||||
root_artifact_sha256: rootArtifactSha256,
|
||||
application_graph_id: applicationGraph.graph_id,
|
||||
root_node_ids: [...state.roots],
|
||||
|
||||
@@ -32,7 +32,7 @@ export const traceJavaScriptSemanticsEvidenceValidated = (
|
||||
path: ["application"],
|
||||
reason: "invalid_value",
|
||||
expected:
|
||||
"analyze_javascript_application v2 Evidence; reanalyze the artifact with the current REA version",
|
||||
"inline Evidence from analyze_javascript_application with a semantic graph",
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -53,7 +53,6 @@ const createManagedApplicationGraphEvidence = (
|
||||
managed_members_evidence_id: input.managed_members?.evidence_id ?? null,
|
||||
managed_native_boundaries_evidence_id:
|
||||
input.managed_native_boundaries?.evidence_id ?? null,
|
||||
limits: jsonValueSchema.parse(input.limits),
|
||||
},
|
||||
result: jsonValueSchema.parse(
|
||||
managedApplicationGraphResultSchema.parse(result),
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
MANAGED_STATIC_PROVIDER,
|
||||
MANAGED_WORKFLOW_PROVIDER,
|
||||
} from "./InvestigationProviders.js";
|
||||
import { MANAGED_INSPECTION_DEFAULTS } from "../dotnet/ManagedInspectionDefaults.js";
|
||||
|
||||
/** Compare managed members from input parsed by a trusted adapter. */
|
||||
export const compareManagedMembersEvidenceValidated = (
|
||||
@@ -37,7 +38,6 @@ export const compareManagedMembersEvidenceValidated = (
|
||||
const result = compareManagedMembers(
|
||||
{ evidenceId: left.evidenceId, result: left.result },
|
||||
{ evidenceId: right.evidenceId, result: right.result },
|
||||
input.limits,
|
||||
);
|
||||
return ok(createManagedMemberComparisonEvidence(input, result));
|
||||
} catch (cause: unknown) {
|
||||
@@ -49,11 +49,13 @@ export const compareManagedMembersEvidenceValidated = (
|
||||
export const compareManagedMemberPaths = async (input: {
|
||||
readonly leftPath: string;
|
||||
readonly rightPath: string;
|
||||
readonly memberLimits: ManagedMemberPathInspectionLimits;
|
||||
readonly comparisonLimits: CompareManagedMembersInput["limits"];
|
||||
}): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const operation = "compare_managed_members";
|
||||
try {
|
||||
const memberLimits: ManagedMemberPathInspectionLimits = {
|
||||
...MANAGED_INSPECTION_DEFAULTS,
|
||||
maxFileBytes: MANAGED_INSPECTION_DEFAULTS.maxFileBytes,
|
||||
};
|
||||
const [leftTarget, rightTarget] = await Promise.all([
|
||||
parseBinaryTarget(input.leftPath),
|
||||
parseBinaryTarget(input.rightPath),
|
||||
@@ -71,13 +73,13 @@ export const compareManagedMemberPaths = async (input: {
|
||||
stat(rightTarget.value.path),
|
||||
]);
|
||||
if (
|
||||
leftStat.size > input.memberLimits.maxFileBytes ||
|
||||
rightStat.size > input.memberLimits.maxFileBytes
|
||||
leftStat.size > memberLimits.maxFileBytes ||
|
||||
rightStat.size > memberLimits.maxFileBytes
|
||||
)
|
||||
return err(
|
||||
new AnalysisInputError(operation, {
|
||||
cause: new RangeError(
|
||||
`Managed comparison input exceeds max_file_bytes ${String(input.memberLimits.maxFileBytes)}`,
|
||||
`Managed comparison input exceeds max_file_bytes ${String(memberLimits.maxFileBytes)}`,
|
||||
),
|
||||
}),
|
||||
);
|
||||
@@ -88,19 +90,19 @@ export const compareManagedMemberPaths = async (input: {
|
||||
const leftInspection = inspectManagedMembersBytes(
|
||||
leftBytes,
|
||||
leftTarget.value,
|
||||
input.memberLimits,
|
||||
memberLimits,
|
||||
);
|
||||
const rightInspection = inspectManagedMembersBytes(
|
||||
rightBytes,
|
||||
rightTarget.value,
|
||||
input.memberLimits,
|
||||
memberLimits,
|
||||
);
|
||||
const leftEvidence = createEvidence(
|
||||
leftTarget.value,
|
||||
MANAGED_STATIC_PROVIDER,
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: memberLimitParameters(input.memberLimits),
|
||||
parameters: memberLimitParameters(memberLimits),
|
||||
result: jsonValueSchema.parse(leftInspection),
|
||||
rawResult: null,
|
||||
limitations: leftInspection.limitations,
|
||||
@@ -112,7 +114,7 @@ export const compareManagedMemberPaths = async (input: {
|
||||
MANAGED_STATIC_PROVIDER,
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: memberLimitParameters(input.memberLimits),
|
||||
parameters: memberLimitParameters(memberLimits),
|
||||
result: jsonValueSchema.parse(rightInspection),
|
||||
rawResult: null,
|
||||
limitations: rightInspection.limitations,
|
||||
@@ -128,14 +130,12 @@ export const compareManagedMemberPaths = async (input: {
|
||||
evidenceId: rightEvidence.evidence_id,
|
||||
result: rightInspection,
|
||||
},
|
||||
input.comparisonLimits,
|
||||
);
|
||||
return ok(
|
||||
createManagedMemberComparisonEvidence(
|
||||
{
|
||||
left: leftEvidence,
|
||||
right: rightEvidence,
|
||||
limits: input.comparisonLimits,
|
||||
},
|
||||
result,
|
||||
),
|
||||
@@ -152,7 +152,7 @@ export interface ManagedMemberPathInspectionLimits
|
||||
}
|
||||
|
||||
const createManagedMemberComparisonEvidence = (
|
||||
parameters: Pick<CompareManagedMembersInput, "left" | "right" | "limits">,
|
||||
parameters: Pick<CompareManagedMembersInput, "left" | "right">,
|
||||
result: z.infer<typeof managedMemberComparisonResultSchema>,
|
||||
): Evidence =>
|
||||
createEvidence(undefined, MANAGED_WORKFLOW_PROVIDER, {
|
||||
@@ -161,7 +161,6 @@ const createManagedMemberComparisonEvidence = (
|
||||
parameters: {
|
||||
left_evidence_id: parameters.left.evidence_id,
|
||||
right_evidence_id: parameters.right.evidence_id,
|
||||
limits: jsonValueSchema.parse(parameters.limits),
|
||||
},
|
||||
result: jsonValueSchema.parse(result),
|
||||
rawResult: null,
|
||||
@@ -175,17 +174,6 @@ const createManagedMemberComparisonEvidence = (
|
||||
const memberLimitParameters = (
|
||||
limits: ManagedMemberPathInspectionLimits,
|
||||
): Record<string, ReturnType<typeof jsonValueSchema.parse>> => ({
|
||||
type_offset: limits.typeOffset,
|
||||
type_limit: limits.typeLimit,
|
||||
method_offset: limits.methodOffset,
|
||||
method_limit: limits.methodLimit,
|
||||
field_offset: limits.fieldOffset,
|
||||
field_limit: limits.fieldLimit,
|
||||
member_ref_offset: limits.memberRefOffset,
|
||||
member_ref_limit: limits.memberRefLimit,
|
||||
edge_offset: limits.edgeOffset,
|
||||
edge_limit: limits.edgeLimit,
|
||||
instruction_anchor_limit: limits.instructionAnchorLimit,
|
||||
max_file_bytes: limits.maxFileBytes,
|
||||
max_metadata_bytes: limits.maxMetadataBytes,
|
||||
max_table_rows: limits.maxTableRows,
|
||||
|
||||
@@ -52,7 +52,6 @@ const createManagedNativeVerificationEvidence = (
|
||||
native_evidence_ids: jsonValueSchema.parse(
|
||||
input.native_observations.map(({ evidence_id: id }) => id),
|
||||
),
|
||||
limits: jsonValueSchema.parse(input.limits),
|
||||
},
|
||||
result: jsonValueSchema.parse(result),
|
||||
rawResult: null,
|
||||
|
||||
@@ -27,7 +27,6 @@ describe("managed decompiler reconstruction import", () => {
|
||||
const result = importManagedReconstruction(exampleInput());
|
||||
|
||||
expect(result).toMatchObject({
|
||||
schema_version: 1,
|
||||
phase: "reconstruction-import",
|
||||
executed: false,
|
||||
static_observation: {
|
||||
@@ -104,25 +103,22 @@ describe("managed decompiler reconstruction import", () => {
|
||||
const observed = managedMemberInspectionSchema.parse(
|
||||
input.static_members.normalized_result,
|
||||
);
|
||||
const method = observed.methods.items[0];
|
||||
const method = observed.methods[0];
|
||||
if (method === undefined) throw new Error("missing observed method");
|
||||
const partial = {
|
||||
...observed,
|
||||
methods: {
|
||||
...observed.methods,
|
||||
items: [
|
||||
{
|
||||
...method,
|
||||
body: {
|
||||
...method.body,
|
||||
status: "partial" as const,
|
||||
normalized_il_sha256: null,
|
||||
truncated_instructions: 1,
|
||||
issue: "instruction limit reached",
|
||||
},
|
||||
methods: [
|
||||
{
|
||||
...method,
|
||||
body: {
|
||||
...method.body,
|
||||
status: "partial" as const,
|
||||
normalized_il_sha256: null,
|
||||
truncated_instructions: 1,
|
||||
issue: "instruction limit reached",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
coverage: { state: "partial" as const, issues: [] },
|
||||
};
|
||||
const partialEvidence = createEvidence(
|
||||
|
||||
@@ -10,7 +10,6 @@ describe("native API inspection", () => {
|
||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
|
||||
expect(projectNativeApiInspection(dossier)).toMatchObject({
|
||||
schema_version: 1,
|
||||
procedure: { address: "0x401000", name: "fixture_main" },
|
||||
boundary: {
|
||||
available: true,
|
||||
|
||||
@@ -27,7 +27,6 @@ export const projectNativeApiInspection = (
|
||||
? availableResidualUnknowns(boundary)
|
||||
: boundary.residual_unknowns;
|
||||
return nativeApiInspectionResultSchema.parse({
|
||||
schema_version: 1,
|
||||
procedure: {
|
||||
address: dossier.procedure.address,
|
||||
name: dossier.procedure.name,
|
||||
|
||||
@@ -129,7 +129,6 @@ export const executeNodeCharacterization = async (
|
||||
return ok(
|
||||
jsonValueSchema.parse(
|
||||
nodeCharacterizationExecutionOutputSchema.parse({
|
||||
schema_version: 1,
|
||||
phase: "execution",
|
||||
plan: prepared.value.plan,
|
||||
transformation: host.instrumentation.manifest,
|
||||
@@ -148,7 +147,6 @@ const prepareValidated = async (
|
||||
): Promise<
|
||||
Result<
|
||||
{
|
||||
readonly schema_version: 1;
|
||||
readonly phase: "preparation";
|
||||
readonly plan: RuntimeCharacterizationPlan;
|
||||
readonly transformation: NonNullable<
|
||||
@@ -192,7 +190,6 @@ const prepareValidated = async (
|
||||
output.plan,
|
||||
);
|
||||
return ok({
|
||||
schema_version: 1,
|
||||
phase: "preparation",
|
||||
plan,
|
||||
transformation: host.instrumentation.manifest,
|
||||
|
||||
@@ -110,7 +110,6 @@ export type PendingProcessCapture = Omit<
|
||||
export const buildCaptureResult = (
|
||||
options: CaptureResultOptions,
|
||||
): PendingProcessCapture => ({
|
||||
schema_version: 4,
|
||||
manifest: options.manifest,
|
||||
normalization: options.scenario.normalization,
|
||||
frames: options.frames,
|
||||
|
||||
@@ -13,7 +13,6 @@ import { projectInputIssues } from "../domain/inputIssueProjection.js";
|
||||
import { processTraceSpecificationSchema } from "../domain/processTraceComparison.js";
|
||||
import {
|
||||
compareProcessCaptures,
|
||||
LEGACY_PROCESS_CAPTURE_MESSAGE,
|
||||
parseProcessScenario,
|
||||
parseProcessCapture,
|
||||
} from "../domain/processCapture.js";
|
||||
@@ -88,10 +87,7 @@ export const compareProcessEvidenceFiles = async (
|
||||
traceSpecification,
|
||||
});
|
||||
return createEvidence(undefined, PROCESS_PROVIDER, {
|
||||
predicateType:
|
||||
traceSpecification === undefined
|
||||
? "rea.process-comparison/v3"
|
||||
: "rea.process-comparison/v4",
|
||||
predicateType: "rea.process-comparison",
|
||||
operation: "compare_process_captures",
|
||||
parameters: {
|
||||
left_evidence_id: left.id,
|
||||
@@ -123,15 +119,10 @@ const parseCaptureEvidence = (input: unknown) => {
|
||||
}
|
||||
if (
|
||||
evidence.operation !== "capture_process_scenario" ||
|
||||
evidence.predicate_type !== "rea.process-capture/v4" ||
|
||||
evidence.predicate_type !== "rea.process-capture" ||
|
||||
evidence.provider.id !== PROCESS_PROVIDER.id ||
|
||||
evidence.provider.version !== PROCESS_PROVIDER.version
|
||||
) {
|
||||
if (evidence.predicate_type === "rea.process-capture/v3")
|
||||
throw new ProcessCliFailure(
|
||||
"invalid_input",
|
||||
LEGACY_PROCESS_CAPTURE_MESSAGE,
|
||||
);
|
||||
throw new ProcessCliFailure(
|
||||
"invalid_input",
|
||||
"Capture evidence is not from the current process-capture workflow. Create new capture evidence, then try again.",
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
ProcessScenario,
|
||||
} from "../domain/processCapture.js";
|
||||
|
||||
/** Provider identity for controlled Process Capture v4 evidence. */
|
||||
/** Provider identity for controlled process capture evidence. */
|
||||
export const PROCESS_PROVIDER = {
|
||||
id: "rea-process",
|
||||
name: "REA deterministic process harness",
|
||||
@@ -26,13 +26,13 @@ const processEvidenceParameters = (
|
||||
normalization: scenario.normalization,
|
||||
});
|
||||
|
||||
/** Create one canonical observed Process Capture v4 Evidence record. */
|
||||
/** Create one canonical observed process capture Evidence record. */
|
||||
export const createProcessCaptureEvidence = (
|
||||
scenario: ProcessScenario,
|
||||
capture: ProcessCapture,
|
||||
) => {
|
||||
return createEvidence(undefined, PROCESS_PROVIDER, {
|
||||
predicateType: "rea.process-capture/v4",
|
||||
predicateType: "rea.process-capture",
|
||||
operation: "capture_process_scenario",
|
||||
parameters: processEvidenceParameters(scenario),
|
||||
result: jsonValueSchema.parse(capture),
|
||||
|
||||
@@ -2,27 +2,12 @@ import { z } from "zod";
|
||||
|
||||
const addressSchema = z.string().regex(/^0x[0-9a-f]+$/iu);
|
||||
const identitySchema = z.object({ address: addressSchema, name: z.string() });
|
||||
const collectionSchema = z.object({
|
||||
items: z.array(z.unknown()),
|
||||
total: z.number().int().min(0).nullable(),
|
||||
returned: z.number().int().min(0),
|
||||
truncated: z.boolean(),
|
||||
next_offset: z.number().int().min(0).nullable(),
|
||||
});
|
||||
|
||||
/** Extract a real address from the provider's exact procedure page. */
|
||||
/** Extract one real procedure address from the complete inline inventory. */
|
||||
export const firstProcedureAddress = (input: unknown): string => {
|
||||
const page = z
|
||||
.object({
|
||||
items: z.array(z.object({ address: addressSchema })).min(1),
|
||||
offset: z.number().int().min(0),
|
||||
limit: z.number().int().min(1),
|
||||
total: z.number().int().min(1),
|
||||
next_offset: z.number().int().min(0).nullable(),
|
||||
has_more: z.boolean(),
|
||||
})
|
||||
.parse(input);
|
||||
const first = page.items[0];
|
||||
const first = z
|
||||
.array(z.object({ address: addressSchema }))
|
||||
.min(1)
|
||||
.parse(input)[0];
|
||||
if (first === undefined) throw new TypeError("Procedure page was empty");
|
||||
return first.address;
|
||||
};
|
||||
@@ -56,7 +41,7 @@ export const requirePseudocode = (
|
||||
return input;
|
||||
};
|
||||
|
||||
/** Validate an exact bounded Hopper function dossier semantically. */
|
||||
/** Validate a complete Hopper function dossier semantically. */
|
||||
export const requireFunctionDossier = (
|
||||
input: unknown,
|
||||
expectedAddress: string,
|
||||
@@ -70,13 +55,11 @@ export const requireFunctionDossier = (
|
||||
throw new TypeError("analyze_function returned the wrong procedure");
|
||||
if (procedure.name.trim().length === 0)
|
||||
throw new TypeError("analyze_function omitted the procedure name");
|
||||
validatePseudocodeBounds(value.pseudocode);
|
||||
for (const field of COLLECTION_FIELDS)
|
||||
validateCollection(value[field], field);
|
||||
requirePseudocode(value.pseudocode, "analyze_function");
|
||||
for (const field of COLLECTION_FIELDS) list(value, field);
|
||||
for (const field of ["callers", "callees"] as const)
|
||||
z.array(identitySchema).parse(collectionSchema.parse(value[field]).items);
|
||||
validateBlocks(collectionSchema.parse(value.basic_blocks).items);
|
||||
validateInstructionScan(value.instruction_scan);
|
||||
z.array(identitySchema).parse(list(value, field));
|
||||
validateBlocks(list(value, "basic_blocks"));
|
||||
return value;
|
||||
};
|
||||
|
||||
@@ -99,9 +82,7 @@ export const requireFunctionDossierOracle = (
|
||||
): Record<string, unknown> => {
|
||||
const value = requireFunctionDossier(input, oracle.procedure_address);
|
||||
if (oracle.callee_address !== undefined) {
|
||||
const callees = z
|
||||
.array(identitySchema)
|
||||
.parse(collectionSchema.parse(value.callees).items);
|
||||
const callees = z.array(identitySchema).parse(list(value, "callees"));
|
||||
if (!callees.some(({ address }) => address === oracle.callee_address))
|
||||
throw new TypeError(
|
||||
"analyze_function omitted the expected fixture callee",
|
||||
@@ -114,7 +95,7 @@ export const requireFunctionDossierOracle = (
|
||||
target_address: addressSchema,
|
||||
}),
|
||||
)
|
||||
.parse(collectionSchema.parse(value.outgoing_references).items);
|
||||
.parse(list(value, "outgoing_references"));
|
||||
if (
|
||||
!references.some(
|
||||
({ target_address }) => target_address === oracle.callee_address,
|
||||
@@ -126,9 +107,7 @@ export const requireFunctionDossierOracle = (
|
||||
}
|
||||
|
||||
if (oracle.caller_address !== undefined) {
|
||||
const callers = z
|
||||
.array(identitySchema)
|
||||
.parse(collectionSchema.parse(value.callers).items);
|
||||
const callers = z.array(identitySchema).parse(list(value, "callers"));
|
||||
if (!callers.some(({ address }) => address === oracle.caller_address))
|
||||
throw new TypeError(
|
||||
"analyze_function omitted the expected fixture caller",
|
||||
@@ -160,7 +139,7 @@ export const requireFunctionDossierOracle = (
|
||||
text: z.string(),
|
||||
}),
|
||||
)
|
||||
.parse(collectionSchema.parse(value.comments).items);
|
||||
.parse(list(value, "comments"));
|
||||
if (
|
||||
!comments.some(
|
||||
({ address, kind, text }) =>
|
||||
@@ -172,16 +151,13 @@ export const requireFunctionDossierOracle = (
|
||||
throw new TypeError("analyze_function omitted the verifier comment");
|
||||
}
|
||||
|
||||
if (
|
||||
oracle.require_assembly === true &&
|
||||
collectionSchema.parse(value.assembly).items.length === 0
|
||||
)
|
||||
if (oracle.require_assembly === true && list(value, "assembly").length === 0)
|
||||
throw new TypeError("analyze_function omitted fixture assembly");
|
||||
|
||||
if (oracle.require_cfg_successor) {
|
||||
const blocks = z
|
||||
.array(z.object({ successors: z.array(addressSchema) }))
|
||||
.parse(collectionSchema.parse(value.basic_blocks).items);
|
||||
.parse(list(value, "basic_blocks"));
|
||||
if (!blocks.some(({ successors }) => successors.length > 0))
|
||||
throw new TypeError("analyze_function omitted a real CFG successor");
|
||||
}
|
||||
@@ -205,12 +181,10 @@ const requireReferencedValue = (
|
||||
expected: string,
|
||||
normalize: (value: string) => string,
|
||||
): void => {
|
||||
const values = z
|
||||
.array(referencedValueSchema)
|
||||
.parse(collectionSchema.parse(dossier[field]).items);
|
||||
const values = z.array(referencedValueSchema).parse(list(dossier, field));
|
||||
const references = z
|
||||
.array(referenceEdgeSchema)
|
||||
.parse(collectionSchema.parse(dossier.outgoing_references).items);
|
||||
.parse(list(dossier, "outgoing_references"));
|
||||
const found = values.some(
|
||||
({ address, value, source_address: sourceAddress }) =>
|
||||
normalize(value) === expected &&
|
||||
@@ -248,29 +222,8 @@ const COLLECTION_FIELDS = [
|
||||
"basic_blocks",
|
||||
] as const;
|
||||
|
||||
const validatePseudocodeBounds = (input: unknown): void => {
|
||||
const pseudocode = z
|
||||
.object({
|
||||
text: z.string(),
|
||||
returned_chars: z.number().int().min(0),
|
||||
total_chars: z.number().int().min(0),
|
||||
})
|
||||
.parse(input);
|
||||
const text = requirePseudocode(pseudocode.text, "analyze_function");
|
||||
if (
|
||||
pseudocode.returned_chars !== [...text].length ||
|
||||
pseudocode.total_chars < pseudocode.returned_chars
|
||||
)
|
||||
throw new TypeError(
|
||||
"analyze_function returned inconsistent pseudocode bounds",
|
||||
);
|
||||
};
|
||||
|
||||
const validateCollection = (input: unknown, field: string): void => {
|
||||
const collection = collectionSchema.parse(input);
|
||||
if (collection.returned !== collection.items.length)
|
||||
throw new TypeError(`analyze_function returned an invalid ${field} result`);
|
||||
};
|
||||
const list = (value: Record<string, unknown>, field: string): unknown[] =>
|
||||
z.array(z.unknown()).parse(value[field]);
|
||||
|
||||
const validateBlocks = (items: readonly unknown[]): void => {
|
||||
for (const block of items)
|
||||
@@ -278,16 +231,6 @@ const validateBlocks = (items: readonly unknown[]): void => {
|
||||
throw new TypeError("analyze_function omitted CFG successor evidence");
|
||||
};
|
||||
|
||||
const validateInstructionScan = (input: unknown): void => {
|
||||
const scan = z
|
||||
.object({ scanned: z.number().int().min(0), truncated: z.boolean() })
|
||||
.parse(input);
|
||||
if (scan.scanned === 0 && !scan.truncated)
|
||||
throw new TypeError(
|
||||
"analyze_function omitted instruction scan limitations",
|
||||
);
|
||||
};
|
||||
|
||||
const objectValue = (
|
||||
input: unknown,
|
||||
message: string,
|
||||
|
||||
@@ -103,7 +103,7 @@ export const evidenceSupportsOriginalAuthority = (
|
||||
if (authority === "process")
|
||||
return (
|
||||
evidence.operation === "capture_process_scenario" &&
|
||||
evidence.predicate_type === "rea.process-capture/v4"
|
||||
evidence.predicate_type === "rea.process-capture"
|
||||
);
|
||||
return evidence.authority === "external-service";
|
||||
};
|
||||
|
||||
@@ -144,7 +144,7 @@ const deriveProcessCandidate = (
|
||||
): void => {
|
||||
if (
|
||||
evidence.operation !== "capture_process_scenario" ||
|
||||
evidence.predicate_type !== "rea.process-capture/v4"
|
||||
evidence.predicate_type !== "rea.process-capture"
|
||||
)
|
||||
return;
|
||||
try {
|
||||
@@ -344,7 +344,7 @@ const reviewedEvidenceState = (
|
||||
): ReconstructionObligation["authority_references"][number]["state"] => {
|
||||
if (
|
||||
evidence.operation === "capture_process_scenario" &&
|
||||
evidence.predicate_type === "rea.process-capture/v4" &&
|
||||
evidence.predicate_type === "rea.process-capture" &&
|
||||
evidence.confidence === "observed"
|
||||
)
|
||||
return "observed";
|
||||
|
||||
@@ -33,7 +33,7 @@ const proofEvidence = (id: string) =>
|
||||
|
||||
const processEvidence = () =>
|
||||
createEvidence(undefined, PROCESS_PROVIDER, {
|
||||
predicateType: "rea.process-capture/v4",
|
||||
predicateType: "rea.process-capture",
|
||||
operation: "capture_process_scenario",
|
||||
parameters: {},
|
||||
result: jsonValueSchema.parse(
|
||||
@@ -80,8 +80,7 @@ const request = (
|
||||
): ReconstructionObligationLedgerInput => ({
|
||||
evidence_bundle: createEvidenceBundle(records),
|
||||
reviewed_obligations: [],
|
||||
manifest: { schema_version: 1, bindings: [], contradictions: [] },
|
||||
limits: { max_obligations: 100 },
|
||||
manifest: { bindings: [], contradictions: [] },
|
||||
page: { offset: 0, limit: 50 },
|
||||
...overrides,
|
||||
});
|
||||
@@ -121,7 +120,6 @@ describe("reconstruction obligation ledger", () => {
|
||||
const result = build(
|
||||
request([capture, proof], {
|
||||
manifest: {
|
||||
schema_version: 1,
|
||||
bindings: [
|
||||
{
|
||||
obligation_id: obligation.obligation_id,
|
||||
@@ -224,7 +222,7 @@ describe("reconstruction obligation ledger", () => {
|
||||
const result = build(
|
||||
request([evidence], {
|
||||
reviewed_obligations: reviewed,
|
||||
manifest: { schema_version: 1, bindings, contradictions: [] },
|
||||
manifest: { bindings, contradictions: [] },
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -297,7 +295,6 @@ describe("reconstruction obligation ledger fail-closed behavior", () => {
|
||||
request([original, proof], {
|
||||
reviewed_obligations: [reviewed],
|
||||
manifest: {
|
||||
schema_version: 1,
|
||||
bindings: [binding, binding],
|
||||
contradictions: [
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ const proofEvidence = (id: string) =>
|
||||
|
||||
const processEvidence = () =>
|
||||
createEvidence(undefined, PROCESS_PROVIDER, {
|
||||
predicateType: "rea.process-capture/v4",
|
||||
predicateType: "rea.process-capture",
|
||||
operation: "capture_process_scenario",
|
||||
parameters: {},
|
||||
result: jsonValueSchema.parse(
|
||||
@@ -81,8 +81,7 @@ const request = (
|
||||
): ReconstructionObligationLedgerInput => ({
|
||||
evidence_bundle: createEvidenceBundle(records),
|
||||
reviewed_obligations: [],
|
||||
manifest: { schema_version: 1, bindings: [], contradictions: [] },
|
||||
limits: { max_obligations: 100 },
|
||||
manifest: { bindings: [], contradictions: [] },
|
||||
page: { offset: 0, limit: 50 },
|
||||
...overrides,
|
||||
});
|
||||
@@ -233,7 +232,6 @@ describe("reconstruction obligation ledger", () => {
|
||||
const result = build(
|
||||
request([capture, proof], {
|
||||
manifest: {
|
||||
schema_version: 1,
|
||||
bindings: [unitBinding],
|
||||
contradictions: [],
|
||||
},
|
||||
@@ -262,7 +260,6 @@ describe("reconstruction obligation ledger case closure", () => {
|
||||
const result = build(
|
||||
request([capture, proof], {
|
||||
manifest: {
|
||||
schema_version: 1,
|
||||
bindings: [
|
||||
{
|
||||
obligation_id: obligation.obligation_id,
|
||||
@@ -335,7 +332,6 @@ describe("reconstruction obligation ledger case closure", () => {
|
||||
const result = build(
|
||||
request([capture, proof], {
|
||||
manifest: {
|
||||
schema_version: 1,
|
||||
bindings: [
|
||||
{
|
||||
obligation_id: obligation.obligation_id,
|
||||
|
||||
@@ -51,13 +51,11 @@ export const evaluateReconstructionObligationLedger = ({
|
||||
candidates: candidatesInput,
|
||||
bundle: bundleInput,
|
||||
manifest,
|
||||
maxObligations,
|
||||
generationLimitations,
|
||||
}: {
|
||||
readonly candidates: readonly ReconstructionObligationCandidate[];
|
||||
readonly bundle: EvidenceBundle;
|
||||
readonly manifest: ReconstructionObligationManifest;
|
||||
readonly maxObligations: number;
|
||||
readonly generationLimitations: readonly string[];
|
||||
}): ReconstructionObligationLedger => {
|
||||
const bundle = parseEvidenceBundle(bundleInput);
|
||||
@@ -65,8 +63,7 @@ export const evaluateReconstructionObligationLedger = ({
|
||||
left.obligation_id.localeCompare(right.obligation_id),
|
||||
);
|
||||
const orphanManifestIds = findOrphanManifestIds(allCandidates, manifest);
|
||||
const candidates = allCandidates.slice(0, maxObligations);
|
||||
const omittedCount = allCandidates.length - candidates.length;
|
||||
const candidates = allCandidates;
|
||||
const context = createEvaluationContext(candidates, bundle, manifest);
|
||||
const obligations = applyDependencyDiagnostics(
|
||||
candidates.map((candidate) => evaluateObligation(candidate, context)),
|
||||
@@ -97,14 +94,9 @@ export const evaluateReconstructionObligationLedger = ({
|
||||
const limitations = ledgerLimitations(
|
||||
generationLimitations,
|
||||
allCandidates.length,
|
||||
omittedCount,
|
||||
orphanManifestIds,
|
||||
);
|
||||
const coverage = obligationLedgerCoverage(
|
||||
omittedCount,
|
||||
maxObligations,
|
||||
limitations.length > 0,
|
||||
);
|
||||
const coverage = obligationLedgerCoverage(limitations.length > 0);
|
||||
const semantic = {
|
||||
coverage,
|
||||
summary: summarizeObligations(obligations),
|
||||
@@ -115,7 +107,7 @@ export const evaluateReconstructionObligationLedger = ({
|
||||
evidence_links: evidenceLinks,
|
||||
limitations,
|
||||
};
|
||||
const evaluatedStatus = obligationLedgerStatus(obligations, omittedCount);
|
||||
const evaluatedStatus = obligationLedgerStatus(obligations);
|
||||
const status =
|
||||
evaluatedStatus === "failed"
|
||||
? evaluatedStatus
|
||||
@@ -129,7 +121,6 @@ export const evaluateReconstructionObligationLedger = ({
|
||||
});
|
||||
return reconstructionObligationLedgerSchema.parse({
|
||||
schema: "ReconstructionObligationLedger",
|
||||
schema_version: 1,
|
||||
ledger_id: `rol_${digestObligationLedgerValue({
|
||||
schema: "rea.reconstruction-obligation-ledger/v1",
|
||||
evidence_ids: bundle.records.map(({ evidence_id: id }) => id),
|
||||
@@ -181,7 +172,6 @@ const findOrphanManifestIds = (
|
||||
const ledgerLimitations = (
|
||||
generationLimitations: readonly string[],
|
||||
candidateCount: number,
|
||||
omittedCount: number,
|
||||
orphanManifestIds: readonly string[],
|
||||
): string[] =>
|
||||
[
|
||||
@@ -192,11 +182,6 @@ const ledgerLimitations = (
|
||||
"No reconstruction obligations were derived; closure cannot be claimed.",
|
||||
]
|
||||
: []),
|
||||
...(omittedCount > 0
|
||||
? [
|
||||
`${String(omittedCount)} obligation candidates were omitted by max_obligations; closure is unknown.`,
|
||||
]
|
||||
: []),
|
||||
...(orphanManifestIds.length > 0
|
||||
? [
|
||||
`Manifest entries reference unknown obligations: ${orphanManifestIds.join(", ")}.`,
|
||||
|
||||
@@ -11,14 +11,9 @@ import type {
|
||||
type DiagnosticCode = ReconstructionObligation["diagnostics"][number]["code"];
|
||||
|
||||
export const obligationLedgerCoverage = (
|
||||
omittedCount: number,
|
||||
maxObligations: number,
|
||||
incomplete: boolean,
|
||||
): ReconstructionObligationLedger["coverage"] => ({
|
||||
status: incomplete ? "partial" : "complete",
|
||||
truncated: omittedCount > 0,
|
||||
omitted_count: omittedCount,
|
||||
max_obligations: maxObligations,
|
||||
});
|
||||
|
||||
export const summarizeObligations = (
|
||||
@@ -103,7 +98,6 @@ export const obligationLedgerEvidenceLinks = (
|
||||
|
||||
export const obligationLedgerStatus = (
|
||||
obligations: readonly ReconstructionObligation[],
|
||||
omittedCount: number,
|
||||
): ReconstructionObligationLedger["status"] => {
|
||||
if (obligations.length === 0) return "unknown";
|
||||
const requiredOpen = obligations.filter(
|
||||
@@ -117,11 +111,7 @@ export const obligationLedgerStatus = (
|
||||
)
|
||||
)
|
||||
return "failed";
|
||||
if (
|
||||
omittedCount > 0 ||
|
||||
requiredOpen.some(({ status }) => status === "unknown")
|
||||
)
|
||||
return "unknown";
|
||||
if (requiredOpen.some(({ status }) => status === "unknown")) return "unknown";
|
||||
return requiredOpen.length === 0 ? "ready" : "open";
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export const resolveReconstructionObligationLedgerRequest = (
|
||||
: err(new AnalysisInputError(OPERATION, { cause: parsed.error }));
|
||||
};
|
||||
|
||||
/** Build one deterministic ledger page and wrap it in portable Evidence v2. */
|
||||
/** Build one deterministic ledger page and wrap it in portable Evidence. */
|
||||
export const buildReconstructionObligationLedgerEvidenceValidated = (
|
||||
input: ReconstructionObligationLedgerInput,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
@@ -43,7 +43,6 @@ export const buildReconstructionObligationLedgerEvidenceValidated = (
|
||||
candidates: generated.candidates,
|
||||
bundle: input.evidence_bundle,
|
||||
manifest: input.manifest,
|
||||
maxObligations: input.limits.max_obligations,
|
||||
generationLimitations: generated.limitations,
|
||||
});
|
||||
const page = pageLedger(ledger, input.page.offset, input.page.limit);
|
||||
@@ -94,7 +93,6 @@ const createLedgerEvidence = (
|
||||
parameters: jsonObjectSchema.parse({
|
||||
ledger_id: page.ledger_id,
|
||||
closure_digest: page.closure_digest,
|
||||
limits: input.limits,
|
||||
page: input.page,
|
||||
}),
|
||||
result: jsonValueSchema.parse(page),
|
||||
|
||||
@@ -27,7 +27,7 @@ export const resolveReconstructionReadinessRequest = (
|
||||
: err(new AnalysisInputError(OPERATION, { cause: parsed.error }));
|
||||
};
|
||||
|
||||
/** Evaluate and wrap one deterministic readiness report in Evidence v2. */
|
||||
/** Evaluate and wrap one deterministic readiness report in Evidence. */
|
||||
export const evaluateReconstructionReadinessValidated = (
|
||||
input: ReconstructionReadinessInput,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
|
||||
@@ -1,25 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
registrationPermissionEnvironment,
|
||||
runSetup,
|
||||
type SetupProgressEvent,
|
||||
} from "./Setup.js";
|
||||
import { runSetup, type SetupProgressEvent } from "./Setup.js";
|
||||
import { FakeSetupHost, options } from "./Setup.fixture.js";
|
||||
|
||||
describe("setup workflow", () => {
|
||||
it("propagates only the explicit non-secret investigation root policy", () => {
|
||||
expect(
|
||||
registrationPermissionEnvironment({
|
||||
REA_INVESTIGATION_INPUT_ROOTS_JSON: '["/approved/apps"]',
|
||||
AUTHORIZATION: "secret",
|
||||
}),
|
||||
).toEqual({
|
||||
REA_INVESTIGATION_INPUT_ROOTS_JSON: '["/approved/apps"]',
|
||||
});
|
||||
expect(registrationPermissionEnvironment({})).toEqual({});
|
||||
});
|
||||
|
||||
it("returns a complete plan without mutation", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.clients = [{ name: "cursor", configPath: "/cursor.json" }];
|
||||
|
||||
@@ -36,12 +36,8 @@ import {
|
||||
type SetupFailureCode,
|
||||
type SetupHopperInstallResult,
|
||||
} from "./SetupInstallFailure.js";
|
||||
import {
|
||||
providerRegistrationEnvironment,
|
||||
registrationPermissionEnvironment,
|
||||
} from "./SetupRegistrationEnvironment.js";
|
||||
import { providerRegistrationEnvironment } from "./SetupRegistrationEnvironment.js";
|
||||
export type { SetupHopperInstallResult } from "./SetupInstallFailure.js";
|
||||
export { registrationPermissionEnvironment } from "./SetupRegistrationEnvironment.js";
|
||||
|
||||
/** Exact non-secret provider variables propagated into managed registrations. */
|
||||
export type SetupProviderEnvironment = Readonly<Record<string, string>>;
|
||||
@@ -483,7 +479,6 @@ export const systemSetupHost = (
|
||||
const diagnosis = await runDoctor(undefined, doctorHost);
|
||||
return {
|
||||
...providerRegistrationEnvironment(diagnosis.providerInspections ?? []),
|
||||
...registrationPermissionEnvironment(process.env),
|
||||
...(diagnosis.hopperPath === undefined
|
||||
? {}
|
||||
: { HOPPER_LAUNCHER_PATH: diagnosis.hopperPath }),
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
import type { DoctorProviderInspection } from "./Doctor.js";
|
||||
|
||||
/** Select explicit non-secret permission settings safe for managed MCP registrations. */
|
||||
export const registrationPermissionEnvironment = (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
): Readonly<Record<string, string>> => {
|
||||
const investigationRoots = environment.REA_INVESTIGATION_INPUT_ROOTS_JSON;
|
||||
return investigationRoots === undefined
|
||||
? {}
|
||||
: { REA_INVESTIGATION_INPUT_ROOTS_JSON: investigationRoots };
|
||||
};
|
||||
|
||||
/** Select exact non-secret settings published by available providers. */
|
||||
export const providerRegistrationEnvironment = (
|
||||
inspections: readonly DoctorProviderInspection[],
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { runCapabilityStatus, runProviderStatus } from "./DirectAnalysis.js";
|
||||
import { createDoctorHostFixture } from "./Doctor.fixture.js";
|
||||
import { projectDoctorReport } from "./DoctorProjection.js";
|
||||
import { runDoctor } from "./Doctor.js";
|
||||
|
||||
describe("purpose-specific CLI projections", () => {
|
||||
it("keeps provider and capability summaries concise with explicit full detail", async () => {
|
||||
const providers = await runProviderStatus();
|
||||
const capabilities = await runCapabilityStatus();
|
||||
const full = await runCapabilityStatus(undefined, "full");
|
||||
|
||||
expect(providers).toMatchObject({
|
||||
open: false,
|
||||
analysis_provider_candidates: expect.any(Array),
|
||||
server_identity: { catalog: { counts: expect.any(Object) } },
|
||||
});
|
||||
expect(JSON.stringify(providers)).not.toContain('"capabilities"');
|
||||
expect(JSON.stringify(providers)).not.toContain('"tools"');
|
||||
expect(capabilities).toMatchObject({
|
||||
summary: {
|
||||
total: expect.any(Number),
|
||||
available: expect.any(Number),
|
||||
unavailable: expect.any(Number),
|
||||
},
|
||||
capabilities: expect.any(Array),
|
||||
});
|
||||
expect(JSON.stringify(capabilities)).not.toContain('"effects"');
|
||||
expect(JSON.stringify(capabilities)).not.toContain('"limits"');
|
||||
expect(JSON.stringify(full)).toContain('"effects"');
|
||||
expect(JSON.stringify(full)).toContain('"catalog"');
|
||||
});
|
||||
|
||||
it("omits the catalog tool array only from the default doctor projection", async () => {
|
||||
const report = await runDoctor(
|
||||
undefined,
|
||||
createDoctorHostFixture({ validTarget: () => Promise.resolve(true) }),
|
||||
);
|
||||
const summary = projectDoctorReport(report, "summary");
|
||||
const full = projectDoctorReport(report, "full");
|
||||
|
||||
expect(summary).toMatchObject({
|
||||
healthy: true,
|
||||
environment_healthy: true,
|
||||
failed_scope_checks: [],
|
||||
informational_drift_count: 0,
|
||||
});
|
||||
expect(JSON.stringify(summary)).not.toContain('"tools"');
|
||||
expect(JSON.stringify(full)).toContain('"tools"');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user