* fix(build): emit no runtime imports for type-only bindings
Under verbatimModuleSyntax, an import whose specifiers all carry inline
`type` modifiers compiles to `import {} from "..."`, a side-effect import
that still resolves and evaluates the module. 78 compiled modules carried
one, including `import {} from "playwright-core"` in the browser scenario
session, which loaded Playwright's module graph at MCP startup.
Use top-level `import type` for these bindings and enable oxlint's
typescript/no-import-type-side-effects rule so the pattern cannot return.
Refs #1685
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* perf(mcp): load Playwright when a scenario launches, not at startup
The browser scenario and Electron active providers are constructed before
the stdio server serves, and both bound Playwright's launchers at module
load. Resolve `chromium` and `_electron` from playwright-core when a
capture opens instead, as the web module resolver already does.
MCP startup now resolves 1,312 modules (4,902 resolutions) instead of
1,598 (6,076) before reading the first request, and no longer loads
playwright-core. Provider construction, the tool catalog, and capability
inventory are unchanged.
A boundary test spawns the stdio server, initializes, lists tools, and
asserts playwright-core and isomorphic-git were not resolved; the CLI
probe now exercises the real launch path to prove detection.
Closes #1685
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { AnalysisProtocolError } from "../domain/analysisErrorCore.js";
|
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import {
|
|
createEvidence,
|
|
type Evidence,
|
|
type EvidenceProvider,
|
|
type EvidenceSubjectTarget,
|
|
} from "../domain/evidence.js";
|
|
import { jsonValueSchema } from "../domain/jsonValue.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
import { requestInputError, workflowInputError } from "./workflowInputError.js";
|
|
|
|
interface InventoryProjectionInput {
|
|
readonly inventory_evidence: readonly Evidence[];
|
|
readonly limits?: unknown;
|
|
}
|
|
|
|
interface InventoryProjectionResult {
|
|
readonly root_sha256: string;
|
|
readonly source_evidence_ids: readonly string[];
|
|
readonly limitations: readonly string[];
|
|
}
|
|
|
|
interface InventoryProjectionOptions<
|
|
Input extends InventoryProjectionInput,
|
|
Output extends InventoryProjectionResult,
|
|
> {
|
|
readonly rawInput: unknown;
|
|
readonly schema: z.ZodType<Input>;
|
|
readonly project: (input: Input) => Output;
|
|
readonly operation: string;
|
|
readonly predicateType: string;
|
|
readonly provider: EvidenceProvider;
|
|
readonly subjectFormat: (first: Evidence) => EvidenceSubjectTarget["format"];
|
|
readonly protocolError: string;
|
|
}
|
|
|
|
/** Parse one inventory projection and wrap its deterministic result in Evidence. */
|
|
export const projectInventoryEvidence = <
|
|
Input extends InventoryProjectionInput,
|
|
Output extends InventoryProjectionResult,
|
|
>(
|
|
options: InventoryProjectionOptions<Input, Output>,
|
|
): Result<Evidence, AnalysisError> => {
|
|
const parsed = options.schema.safeParse(options.rawInput);
|
|
if (!parsed.success)
|
|
return err(
|
|
requestInputError(options.operation, parsed.error, options.rawInput),
|
|
);
|
|
try {
|
|
const result = options.project(parsed.data);
|
|
const first = parsed.data.inventory_evidence[0];
|
|
return ok(
|
|
createEvidence(
|
|
first?.subject === null || first?.subject === undefined
|
|
? undefined
|
|
: {
|
|
path: first.subject.local_path,
|
|
sha256: result.root_sha256,
|
|
format: options.subjectFormat(first),
|
|
},
|
|
options.provider,
|
|
{
|
|
predicateType: options.predicateType,
|
|
operation: options.operation,
|
|
parameters: {
|
|
inventory_evidence_ids: [...result.source_evidence_ids],
|
|
...("limits" in parsed.data && parsed.data.limits !== undefined
|
|
? { limits: jsonValueSchema.parse(parsed.data.limits) }
|
|
: {}),
|
|
},
|
|
result: jsonValueSchema.parse(result),
|
|
rawResult: null,
|
|
confidence: "inferred",
|
|
authority: "analyst-inference",
|
|
environment: null,
|
|
limitations: result.limitations,
|
|
evidenceLinks: result.source_evidence_ids,
|
|
},
|
|
),
|
|
);
|
|
} catch (cause: unknown) {
|
|
return err(
|
|
cause instanceof TypeError || cause instanceof z.ZodError
|
|
? workflowInputError(options.operation, cause)
|
|
: new AnalysisProtocolError(options.protocolError, { cause }),
|
|
);
|
|
}
|
|
};
|