refactor!: enforce canonical evidence and provider boundaries

Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
morluto
2026-10-09 20:18:52 +08:00
parent 2a7746998d
commit 63bf91405c
514 changed files with 9296 additions and 5825 deletions
+33 -13
View File
@@ -1,8 +1,8 @@
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
import {
NATIVE_MACOS_PROVIDER_IDENTITY as IDENTITY,
nativeMacOSCapabilities,
} from "./NativeMacOSProviderMetadata.js";
export { NATIVE_MACOS_PROVIDER_IDENTITY } from "./NativeMacOSProviderMetadata.js";
import { inspectAppleDispatchMetadata } from "./AppleDispatchMetadata.js";
import { observeNativeUi } from "./NativeUiObservation.js";
import { LldbCallTracer, type NativeCallTracer } from "./LldbCallTracer.js";
@@ -25,6 +25,8 @@ import {
type NativeToolName,
} from "../contracts/native/nativeToolContracts.js";
import type { BinaryTarget } from "../domain/binaryTarget.js";
import { toolContract } from "../contracts/toolContracts.js";
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
import type { EvidenceLocation } from "../domain/evidence.js";
import {
AnalysisCancelledError,
@@ -79,12 +81,17 @@ import {
/** Read-only semantic provider composed from Xcode command-line utilities. */
export class NativeMacOSProvider implements AnalysisProvider {
readonly #capabilities: readonly CapabilityDescriptor[];
readonly #environment: NodeJS.ProcessEnv;
constructor(
private readonly runner: NativeCommandRunner = new XcrunCommandRunner(),
environment: Readonly<NodeJS.ProcessEnv>,
private readonly runner: NativeCommandRunner = new XcrunCommandRunner(
environment,
),
platform: NodeJS.Platform = process.platform,
private readonly tracer: NativeCallTracer = new LldbCallTracer(),
private readonly tracer: NativeCallTracer = new LldbCallTracer(environment),
) {
this.#environment = snapshotEnvironment(environment, platform);
this.#capabilities = nativeMacOSCapabilities(platform);
}
@@ -97,7 +104,12 @@ export class NativeMacOSProvider implements AnalysisProvider {
}
createClient(target: BinaryTarget): AnalysisClient {
return new NativeMacOSClient(target, this.runner, this.tracer);
return new NativeMacOSClient(
target,
this.runner,
this.tracer,
this.#environment,
);
}
}
@@ -106,6 +118,7 @@ class NativeMacOSClient implements AnalysisClient {
private readonly target: BinaryTarget,
private readonly runner: NativeCommandRunner,
private readonly tracer: NativeCallTracer,
private readonly environment: Readonly<NodeJS.ProcessEnv>,
) {}
async execute(
@@ -118,6 +131,18 @@ class NativeMacOSClient implements AnalysisClient {
if (operation === "health")
return ok(createAnalysisExecution(null, IDENTITY));
if (operation === "inspect_native_dispatch_metadata") {
const input = toolContract(operation).inputSchema.safeParse(parameters);
if (!input.success)
return err(
analysisInputErrorFromIssues(
operation,
input.error.issues,
parameters,
{
cause: input.error,
},
),
);
if (this.target.kind !== "executable" || this.target.format !== "mach-o")
return err(
new AnalysisCapabilityUnavailableError(
@@ -127,15 +152,9 @@ class NativeMacOSClient implements AnalysisClient {
),
);
try {
const maxRecords = z
.number()
.int()
.min(1)
.max(20000)
.parse(parameters.max_records ?? 5000);
const result = await inspectAppleDispatchMetadata(
this.target,
maxRecords,
input.data.max_records,
options?.signal,
);
return ok(
@@ -191,6 +210,7 @@ class NativeMacOSClient implements AnalysisClient {
operation === "capture_native_ui_scenario"
) {
const result = await observeNativeUi(this.target, operation, parameters, {
environment: this.environment,
signal: options?.signal,
});
return result.ok
@@ -225,8 +245,8 @@ class NativeMacOSClient implements AnalysisClient {
}
}
close(): Promise<void> {
return Promise.resolve();
close(): Promise<Result<null, AnalysisError>> {
return Promise.resolve(ok(null));
}
#dispatch(