fix!: repair boundary contracts across CLI and MCP (#597)
* fix(comparisons)!: preserve unknowns across partial observations Share absence and digest semantics, keep unobserved managed bodies unknown, and match unique managed type/name/signatures before structural fallback. BREAKING CHANGE: Managed comparison metadata adds exact-signature matching and its count, and name_matching now reports exact-signature-fallback. * fix(javascript): preserve projected result binding semantics Share syntax-aware property reads and assigned-result resolution. Retain destructuring paths and downgrade downstream whole-result relationships instead of resolving nested or wrapped calls as aliases. * fix(native)!: admit complete parser values and preserve typed failures Decode Mach headers by named columns, validate complete slice keys and lipo alignment, and preserve codesign runtime flags and tagged parser errors. Rename the Ghidra test dossier fixture and connect fake-backed suites to real verification lanes. BREAKING CHANGE: Native load-command results no longer contain the unused, always-null file_offset field. * fix(process): preserve host identity and actionable boundary failures Thread selected platform and environment through process and Doctor seams, stamp observed producer identity in Evidence, and retain PTY, filesystem, lease and lazy-provider failure causes. Drain cancelled lazy loads and omit exited descendants from verified lineage. * fix(browser): preserve cleanup and document-transition evidence Make V8 and Playwright teardown cancellation-aware, expose primary failures alongside incomplete cleanup, share frame-tree and navigation rules, and clear stale WebMCP registrations without pruning unrelated child frames. * fix(adapters): align managed targets and typed CLI outcomes Inspect managed PE/CLI targets independently of native provider selection, reuse successful managed selections, and keep evidence bound to the actual inspected target. Classify canonical CLI error envelopes and exhaustive setup/update/uninstall outcomes, audit registered CLI coverage, and assert platform-specific runtime results. * docs: refresh boundary contracts and shipped roadmap behavior
This commit is contained in:
@@ -7,6 +7,10 @@ import {
|
||||
type ObjcSwiftMetadata,
|
||||
} from "../domain/objcSwiftMetadata.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
EvidenceIntegrityError,
|
||||
} from "../domain/errors.js";
|
||||
import { decodeSwiftClassVtables } from "./AppleSwiftVtables.js";
|
||||
import { createObjcProtocolReader } from "./AppleObjcProtocols.js";
|
||||
|
||||
@@ -624,11 +628,12 @@ export const inspectAppleDispatchMetadata = async (
|
||||
throw new RangeError(
|
||||
"Apple metadata target must be a regular file no larger than 64 MiB",
|
||||
);
|
||||
if (signal?.aborted) throw new Error("cancelled");
|
||||
if (signal?.aborted)
|
||||
throw new AnalysisCancelledError("inspect_native_dispatch_metadata");
|
||||
const bytes = await handle.readFile({ signal });
|
||||
const digest = createHash("sha256").update(bytes).digest("hex");
|
||||
if (digest !== target.sha256)
|
||||
throw new Error(
|
||||
throw new EvidenceIntegrityError(
|
||||
"Apple metadata target digest changed after session binding",
|
||||
);
|
||||
return nativeDispatchMetadataResultSchema.parse({
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisOutputError,
|
||||
ProviderAdapterError,
|
||||
type AnalysisError,
|
||||
AnalysisError,
|
||||
} from "../domain/errors.js";
|
||||
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||
import {
|
||||
@@ -162,6 +162,7 @@ class NativeMacOSClient implements AnalysisClient {
|
||||
}),
|
||||
);
|
||||
} catch (cause) {
|
||||
if (cause instanceof AnalysisError) return err(cause);
|
||||
return err(
|
||||
options?.signal?.aborted
|
||||
? new AnalysisCancelledError(operation)
|
||||
|
||||
@@ -58,5 +58,7 @@ const splitAlgorithms = (value: string | undefined): string[] =>
|
||||
|
||||
const parseRuntime = (value: string | undefined): boolean | null => {
|
||||
if (value === undefined) return null;
|
||||
return /\bruntime\b/u.test(value);
|
||||
const flags = /(?:^|\s)flags=[^(]*\(([^)]*)\)/u.exec(value)?.[1];
|
||||
if (flags === undefined) return null;
|
||||
return flags.split(",").some((flag) => flag.trim() === "runtime");
|
||||
};
|
||||
|
||||
@@ -65,7 +65,16 @@ const integer = (value: string | undefined): number | null => {
|
||||
|
||||
const alignment = (value: string | undefined): number | null => {
|
||||
if (value === undefined) return null;
|
||||
const exponent = /2\^(\d+)/u.exec(value)?.[1];
|
||||
if (exponent !== undefined) return 2 ** Number.parseInt(exponent, 10);
|
||||
const exponent = /^2\^(\d+)(?: \((\d+)\))?$/u.exec(value);
|
||||
const powerText = exponent?.[1];
|
||||
if (powerText !== undefined) {
|
||||
const power = Number.parseInt(powerText, 10);
|
||||
if (power > 52) return null;
|
||||
const alignment = 2 ** power;
|
||||
const reported = exponent?.[2];
|
||||
return reported === undefined || integer(reported) === alignment
|
||||
? alignment
|
||||
: null;
|
||||
}
|
||||
return integer(value);
|
||||
};
|
||||
|
||||
+37
-13
@@ -23,7 +23,6 @@ interface ParsedLoadCommands {
|
||||
readonly commands: Array<{
|
||||
index: number;
|
||||
kind: string;
|
||||
file_offset: number | null;
|
||||
fields: Record<string, string | number | null>;
|
||||
}>;
|
||||
readonly segments: ParsedSegment[];
|
||||
@@ -57,12 +56,12 @@ const normalizeLineEndings = (output: string): string =>
|
||||
/** Parse stable fields from `otool -l`, preserving unknown command fields. */
|
||||
export const parseOtoolLoadCommands = (raw: string) => {
|
||||
const output = normalizeLineEndings(raw);
|
||||
const headerTokens = parseHeaderTokens(output);
|
||||
const state = createLoadCommandState(headerTokens);
|
||||
const header = parseHeader(output);
|
||||
const state = createLoadCommandState(header?.flags);
|
||||
for (const block of output.split(/(?=Load command \d+)/u))
|
||||
parseLoadCommand(block, state);
|
||||
return {
|
||||
fileType: headerTokens?.[4] ?? null,
|
||||
fileType: header?.fileType ?? null,
|
||||
flags: [...state.flags].sort(),
|
||||
uuid: state.uuid,
|
||||
commands: state.commands,
|
||||
@@ -73,15 +72,41 @@ export const parseOtoolLoadCommands = (raw: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
const parseHeaderTokens = (output: string): string[] | undefined =>
|
||||
output
|
||||
.split(/\r?\n/u)
|
||||
.map((line) => line.trim())
|
||||
.find((line) => /^0x[a-fA-F0-9]+\s/u.test(line))
|
||||
?.split(/\s+/u);
|
||||
const parseHeader = (
|
||||
output: string,
|
||||
): { fileType: string | null; flags: string[] } | undefined => {
|
||||
const lines = output.split(/\r?\n/u).map((line) => line.trim());
|
||||
const columnsLine = lines.findIndex((line) => /(?:^|\s)magic\s/u.test(line));
|
||||
if (columnsLine < 0) return undefined;
|
||||
const columns = lines[columnsLine]?.split(/\s+/u);
|
||||
const dataLine = lines.slice(columnsLine + 1).find((line) => line.length > 0);
|
||||
const values = dataLine?.split(/\s+/u);
|
||||
if (columns === undefined || values === undefined) return undefined;
|
||||
const fileTypeIndex = columns.indexOf("filetype");
|
||||
const flagsIndex = columns.indexOf("flags");
|
||||
const complete = values.length >= columns.length;
|
||||
const fileTypeValueIndex =
|
||||
flagsIndex >= 0 && fileTypeIndex > flagsIndex
|
||||
? values.length - (columns.length - fileTypeIndex)
|
||||
: fileTypeIndex;
|
||||
const flagsEnd =
|
||||
flagsIndex >= 0 ? values.length - (columns.length - flagsIndex - 1) : 0;
|
||||
return {
|
||||
fileType:
|
||||
complete && fileTypeValueIndex >= 0 && fileTypeValueIndex < values.length
|
||||
? (values[fileTypeValueIndex] ?? null)
|
||||
: null,
|
||||
flags:
|
||||
!complete || flagsIndex < 0 || flagsIndex >= flagsEnd
|
||||
? []
|
||||
: values
|
||||
.slice(flagsIndex, flagsEnd)
|
||||
.filter((value) => value.length > 0),
|
||||
};
|
||||
};
|
||||
|
||||
const createLoadCommandState = (
|
||||
headerTokens: readonly string[] | undefined,
|
||||
headerFlags: readonly string[] | undefined,
|
||||
): ParsedLoadCommands => ({
|
||||
commands: [],
|
||||
segments: [],
|
||||
@@ -89,7 +114,7 @@ const createLoadCommandState = (
|
||||
entrypoints: [],
|
||||
builds: [],
|
||||
uuid: null,
|
||||
flags: new Set(headerTokens?.slice(7) ?? []),
|
||||
flags: new Set(headerFlags ?? []),
|
||||
});
|
||||
|
||||
const parseLoadCommand = (block: string, state: ParsedLoadCommands): void => {
|
||||
@@ -101,7 +126,6 @@ const parseLoadCommand = (block: string, state: ParsedLoadCommands): void => {
|
||||
state.commands.push({
|
||||
index: Number.parseInt(indexText, 10),
|
||||
kind,
|
||||
file_offset: null,
|
||||
fields,
|
||||
});
|
||||
collectUuid(kind, fields, state);
|
||||
|
||||
Reference in New Issue
Block a user