Files
reverse-engineering-anything/src/contracts/analysisViewToolContracts.ts
T

167 lines
6.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { API_SURFACE_EXAMPLE } from "./analysisViewApiSurfaceExample.js";
import { ENVIRONMENT_MANIFEST_EXAMPLE } from "./analysisViewEnvironmentManifestExample.js";
import { inspectAnalysisViewInputSchema } from "../domain/analysisView/analysisViewRequest.js";
import { analysisViewResultSchema } from "../domain/analysisView/analysisViewResult.js";
import type { ToolContract, ToolExample } from "./toolContractTypes.js";
import { toolContractMetadata, evidenceEffects } from "./toolEffects.js";
import { evidenceResultOf } from "./toolOutputSchemaPrimitives.js";
const RETAINED_EXAMPLE_ID = `ev_${"a".repeat(64)}`;
const retainedViewExample = <
const Title extends string,
const View extends ToolExample["input"],
>(
title: Title,
view: View,
) =>
({
title,
input: {
source: {
kind: "retained-evidence",
evidence_id: RETAINED_EXAMPLE_ID,
},
view,
},
}) as const;
/** Selected views of completed layout, JavaScript, native, inventory, WASM, Mach-O, Interface Builder and web network Evidence. */
export const ANALYSIS_VIEW_TOOL_CONTRACTS = [
{
name: "inspect_analysis_view",
cli: true,
...toolContractMetadata("inspect_analysis_view", evidenceEffects),
kind: "application",
description:
'Read summaries, selected facts, or pages from completed Evidence without rerunning analysis. Use the producing tool’s retained-view handoff for compatible selectors; the examples here are not exhaustive. Copy normalized_result.parent_evidence_id from a summary into source: {kind: "retained-evidence", evidence_id: "<parent_evidence_id>"}. Other sources are {kind: "inline", evidence: <complete Evidence>} or {kind: "evidence-file", path: "<absolute JSON path>", evidence_id?: "<record ID>"}; select an ID for a multi-record bundle. For native pseudocode use {source: {kind: "retained-evidence", evidence_id: "<parent_evidence_id>"}, view: {kind: "native", facet: "pseudocode", offset: 0, limit: 128}}; procedure_pseudo_code parents support this text facet, while other native function facets require analyze_function. Common views: {kind: "summary"} has no facet; {kind: "inventory", collection: "occurrences", logical_paths: ["package.json"], offset: 0, limit: 64} selects artifact paths, path_globs: ["lib/*/*.so"] selects by whole-path glob, artifact_kinds: ["native-addon"] selects recognized kinds, and order_by: {field: "declared_size", direction: "descending"} ranks rows by size before paging; {kind: "capture", detail: "preview", offset: 0, limit: 20} pages saved network records; {kind: "managed-members", collection: "methods", offset: 0, limit: 64} pages managed members. Use the producer’s named kind for other families; compact schemas may omit nested shapes, so do not invent selectors. Text offsets/limits use UTF-16 code units; row pages count the selected retained collection. Preserve parent identity, null/unavailable values, source coverage, limitations and unknowns; exhausting pages does not prove complete discovery, runtime use or absence. Smaller pages can resolve delivery limits without repeating analysis; complete parent Evidence remains available for export.',
inputSchema: inspectAnalysisViewInputSchema,
outputSchema: evidenceResultOf(analysisViewResultSchema),
examples: [
retainedViewExample(
"Page endpoint observations from retained web bundle analysis Evidence",
{
kind: "web-bundle",
collection: "endpoints",
offset: 0,
limit: 32,
},
),
retainedViewExample(
"Page selected native inventory fields without repeating the complete list",
{
kind: "native-inventory",
offset: 0,
limit: 32,
fields: ["value"],
},
),
retainedViewExample(
"Read exact inventory paths from retained inspection Evidence",
{
kind: "inventory",
collection: "occurrences",
logical_paths: ["package.json", "main.js"],
offset: 0,
limit: 32,
},
),
retainedViewExample("Select native addons by recognized artifact kind", {
kind: "inventory",
collection: "occurrences",
artifact_kinds: ["native-addon"],
fields: ["logical_path", "declared_size", "unpacked"],
offset: 0,
limit: 64,
}),
retainedViewExample("Rank the largest files below an archive directory", {
kind: "inventory",
collection: "occurrences",
path_globs: ["lib/**"],
entry_kinds: ["file"],
order_by: { field: "declared_size", direction: "descending" },
fields: ["logical_path", "declared_size"],
offset: 0,
limit: 16,
}),
{
title: "Group requests from retained HAR Evidence",
input: API_SURFACE_EXAMPLE.input,
},
{
title: "Project an environment manifest from retained HAR Evidence",
input: ENVIRONMENT_MANIFEST_EXAMPLE.input,
},
retainedViewExample(
"Summarize retained analysis Evidence, including WASM",
{ kind: "summary" },
),
retainedViewExample(
"Read one ELF section from retained layout Evidence",
{
kind: "item",
collection: "sections",
selector: { name: ".text" },
},
),
retainedViewExample(
"Page native high-pcode operations from retained Evidence",
{
kind: "native",
facet: "value_flow_operations",
offset: 0,
limit: 32,
},
),
retainedViewExample(
"Page module identities from retained application Evidence",
{
kind: "page",
collection: "modules",
offset: 0,
limit: 32,
},
),
retainedViewExample(
"Read selected metadata and native facts by exact retained paths",
{
kind: "javascript-facts",
where: { paths: ["package.json", "build/Release/addon.node"] },
property_keys: [
"name",
"version",
"bytes",
"availability",
"operation",
"analysis_status",
],
include_available_property_keys: true,
offset: 0,
limit: 32,
},
),
retainedViewExample(
"Count distinct IPC channels per operation in one retained source",
{
kind: "javascript-fact-groups",
where: { paths: ["preload.js"], kinds: ["ipc-channel"] },
group_by: ["operation", "channel"],
offset: 0,
limit: 256,
},
),
retainedViewExample(
"Read typed module reference facts from retained application Evidence",
{
kind: "javascript",
collection: "modules",
projection: "references",
where: { path: "main.js", kind: "javascript-module" },
offset: 0,
limit: 64,
},
),
],
},
] as const satisfies readonly ToolContract[];