feat(elf): inspect dynamic dependencies and required symbol versions

Add offline ELF dependency, search-path, symbol-version and import inspection with retained Evidence summaries and pages. Bound GNU-hash work and preserve cancellation, stable identity and caller-selected parameters across CLI/MCP.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
Matt Van Hornandgensokyo-dev authored and GitHub committed 2026-11-17 08:19:52 +00:00
1 parent af062e7a2d
commit e9c72dbd1f
100 files changed
+7137 -89

No files matched your search

+17
View File
@@ -16,6 +16,7 @@ import {
createPeImportsService,
createWindowsShortcutService,
createNativeExportsService,
createElfDependenciesService,
} from "../composition/binaryDiagnostics.js";
import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
@@ -295,6 +296,22 @@ export const registerBinaryDiagnosticsCommands = (
},
deliverWithService(createNativeExportsService, "rea-native-exports"),
);
registerContractCommand(
cli,
logger,
contract("inspect_elf_dependencies"),
{
description:
"Inspect ELF needed libraries and required symbol versions without executing the image",
positionals: ["path"],
callerPaths: ["path"],
evidenceDelivery: true,
fields: {
path: { description: "Local ELF32/ELF64 ET_EXEC or ET_DYN image" },
},
},
deliverWithService(createElfDependenciesService, "rea-elf-dependencies"),
);
const layout = createBinaryLayoutService(environment);
registerContractCommand(
cli,
+22 -15
View File
@@ -1111,22 +1111,14 @@ const branchOnlyField = (
/**
* An option that must stay omitted when the caller omits it, because the
* input branch or route the caller selects applies its own default on
* admission. Help and `--schema` still state the default, in the
* description and as JSON Schema `default`.
* admission. Help and `--schema` still state the default through the
* schema metadata.
*/
export const withoutDefault = (schema: z.ZodType): z.ZodType => {
if (!(schema instanceof z.ZodDefault)) return schema;
const value: unknown = schema.parse(undefined);
const omittable = (schema.removeDefault() as z.ZodType).optional();
const shown = typeof value === "string" ? value : JSON.stringify(value);
return omittable.meta({
...schema.meta(),
description:
schema.description === undefined
? `Default: ${shown}`
: `${schema.description} (default: ${shown})`,
default: value,
});
return omittable.meta({ ...schema.meta(), default: value });
};
/**
@@ -1941,12 +1933,15 @@ export const describeContractCommand = <
schema = schema.default(projected.default as never);
if (described !== undefined) schema = schema.describe(described);
}
const description =
const described =
projected?.description ??
schema.description ??
describedThroughWrappers(declared);
if (description !== undefined && description !== schema.description)
schema = schema.describe(description);
if (described !== undefined && described !== schema.description)
schema = schema.describe(described);
if (!delivery && projected?.default === undefined)
schema = withoutDefault(schema);
const description = schema.description ?? described;
const value = core(declared);
const selector = selectorOptions[field];
let selectorOption: ContractCliSelectorOption | undefined;
@@ -2350,7 +2345,19 @@ export const describeContractCommand = <
};
return [{ path: [flag], message, issue }];
});
const result = contractChecks.safeParse(toContractInput(options));
// Checks observe execution defaults, while the command retains the
// caller's raw selections. Resolve only omitted fields: supplied
// options have already passed argv admission, and JSON text is not
// decoded until the command runs.
const checkInput = toContractInput(options);
if (checks.length > 0)
for (const [field, declared] of Object.entries(shape)) {
if (Object.hasOwn(checkInput, field)) continue;
const omitted = declared.safeParse(undefined);
if (omitted.success && omitted.data !== undefined)
checkInput[field] = omitted.data;
}
const result = contractChecks.safeParse(checkInput);
return result.success
? conflicts
: [
+18 -15
View File
@@ -78,17 +78,28 @@ const typeName = (field: z.ZodType): string => {
/** A shown default; empty arrays and a `false` boolean default are not shown. */
const shownDefault = (field: z.ZodType, type: string): unknown => {
const metadata = field.meta();
const value =
field instanceof z.ZodDefault
? (field.def.defaultValue as unknown)
: field instanceof z.ZodOptional
? shownDefault(field.unwrap() as z.ZodType, type)
: undefined;
metadata !== undefined && Object.hasOwn(metadata, "default")
? metadata.default
: field instanceof z.ZodDefault
? (field.def.defaultValue as unknown)
: field instanceof z.ZodOptional
? shownDefault(field.unwrap() as z.ZodType, type)
: undefined;
if (Array.isArray(value) && value.length === 0) return undefined;
if (type === "boolean" && value === false) return undefined;
return value;
};
const fieldDescription = (field: z.ZodType, type = typeName(field)): string => {
const defaultValue = shownDefault(field, type);
const description = field.description ?? "";
return defaultValue === undefined
? description
: `${description} (default: ${String(defaultValue)})`;
};
const optionRows = (
options: z.ZodObject,
alias: Readonly<Record<string, string>> | undefined,
@@ -99,15 +110,7 @@ const optionRows = (
const short = alias?.[key];
const value = type === "boolean" ? "" : ` <${type}>`;
const label = `--${optionFlagName(key)}${short === undefined ? "" : `, -${short}`}${value}`;
const defaultValue = shownDefault(field, type);
const description = field.description ?? "";
return {
label,
description:
defaultValue === undefined
? description
: `${description} (default: ${String(defaultValue)})`,
};
return { label, description: fieldDescription(field, type) };
},
);
@@ -200,7 +203,7 @@ export const formatCommandHelp = (name: string, help: CommandHelp): string => {
(help.args?.shape ?? {}) as Readonly<Record<string, z.ZodType>>,
).map(([key, field]) => ({
label: key,
description: field.description ?? "",
description: fieldDescription(field),
}));
if (args.length > 0) lines.push("", "Arguments:", ...alignedRows(args));
const options =