perf(javascript): query selected source-to-bundle facts (#6128)
Select completed source-to-bundle mappings and candidates through the shared view owner, preserve reference-file provenance, and retain full Evidence. Reuse bounded JSON reading, heap admission, and cancellation before session writes. Verified public Redux Toolkit source/map facts with an independent oracle, equivalent CLI/MCP workflows, focused negative controls, and complete CI/review. Historical paired SDK context estimates fall about 64%; timing/resource tradeoffs and final verification receipts are recorded without a general speedup or actual model-token claim. Fixes #6112.
This commit is contained in:
1 parent
a0214e0e0e
commit
0583fc69be
29 files changed
+3527
-129
No files matched your search
@@ -1012,6 +1012,7 @@ const registerObservationTools = ({
|
||||
options.optionalProviderLoadFailures?.javascriptRuntimeObservation,
|
||||
});
|
||||
registerApplicationTools(server, {
|
||||
artifactResources,
|
||||
evidenceById,
|
||||
logger,
|
||||
recordEvidence,
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import { resolveSourceToBundleReference } from "../../application/javascript/SourceToBundleReference.js";
|
||||
import {
|
||||
requireAnalysisViewRetention,
|
||||
inspectAnalysisViewValidated,
|
||||
} from "../../application/analysisView/AnalysisViewService.js";
|
||||
import type { EvidenceMcpServer } from "../EvidenceMcpServer.js";
|
||||
import { runAdmittedToolOperation } from "../admittedToolOperation.js";
|
||||
import { resolveApplicationEvidenceRequest } from "../../application/EvidenceInputResolver.js";
|
||||
@@ -8,7 +16,7 @@ import { applicationToolContract } from "../../contracts/applicationToolContract
|
||||
import { sourceToBundleComparisonResultSchema } from "../../domain/javascript/sourceToBundleComparisonSchemas.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { recordResult } from "./helpers.js";
|
||||
import { recordApplicationResult } from "./helpers.js";
|
||||
import type { ApplicationToolRegistration } from "./types.js";
|
||||
|
||||
const contract = applicationToolContract("compare_source_to_bundle");
|
||||
@@ -28,13 +36,31 @@ export const registerCompareSourceToBundleTool = (
|
||||
contract.name,
|
||||
context.mcpReq.signal,
|
||||
async () => {
|
||||
if (input.view !== undefined) {
|
||||
const retention = requireAnalysisViewRetention(
|
||||
contract.name,
|
||||
options,
|
||||
);
|
||||
if (!retention.ok)
|
||||
return server.delivery.toCallToolResult(retention, contract);
|
||||
}
|
||||
const resolved = resolveApplicationEvidenceRequest(
|
||||
input,
|
||||
options.evidenceById,
|
||||
);
|
||||
if (!resolved.ok)
|
||||
return server.delivery.toCallToolResult(resolved, contract);
|
||||
const parsed = resolved.value;
|
||||
const reference = await resolveSourceToBundleReference(
|
||||
resolved.value.reference,
|
||||
context.mcpReq.signal,
|
||||
options.artifactResources,
|
||||
);
|
||||
if (!reference.ok)
|
||||
return server.delivery.toCallToolResult(reference, contract);
|
||||
const parsed = {
|
||||
...reference.value,
|
||||
application: resolved.value.application,
|
||||
};
|
||||
const result = await logToolExecution(
|
||||
options.logger,
|
||||
contract.name,
|
||||
@@ -43,23 +69,59 @@ export const registerCompareSourceToBundleTool = (
|
||||
);
|
||||
if (!result.ok)
|
||||
return server.delivery.toCallToolResult(result, contract);
|
||||
const parent = result.value;
|
||||
const comparison = sourceToBundleComparisonResultSchema.parse(
|
||||
parent.normalized_result,
|
||||
);
|
||||
// Stage the projection against the owned parent before committing any session facts.
|
||||
const selected =
|
||||
input.view === undefined
|
||||
? ok(parent)
|
||||
: inspectAnalysisViewValidated(
|
||||
{
|
||||
source: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: parent.evidence_id,
|
||||
},
|
||||
view: input.view,
|
||||
},
|
||||
(id) =>
|
||||
id === parent.evidence_id
|
||||
? parent
|
||||
: options.evidenceById?.(id),
|
||||
);
|
||||
await setImmediate();
|
||||
if (context.mcpReq.signal.aborted)
|
||||
return server.delivery.toErrorToolResult(
|
||||
new AnalysisCancelledError(contract.name, {
|
||||
cause: context.mcpReq.signal.reason,
|
||||
}),
|
||||
contract.returnsTargetContent,
|
||||
);
|
||||
if (!selected.ok)
|
||||
return server.delivery.toCallToolResult(selected, contract);
|
||||
const recorded = recordSessionEvidenceSources(
|
||||
options.recordEvidence,
|
||||
[parsed.application],
|
||||
);
|
||||
if (!recorded.ok)
|
||||
return server.delivery.toCallToolResult(recorded, contract);
|
||||
const comparison = sourceToBundleComparisonResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
);
|
||||
return recordResult(
|
||||
{ ...options, delivery: server.delivery },
|
||||
contract,
|
||||
result.value,
|
||||
const saved = recordApplicationResult(
|
||||
options,
|
||||
parent,
|
||||
comparison.summary.unknown > 0
|
||||
? "source-to-bundle-comparison"
|
||||
: undefined,
|
||||
);
|
||||
if (saved !== undefined && !saved.ok)
|
||||
return server.delivery.toCallToolResult(saved, contract);
|
||||
return server.delivery.toEvidenceToolResult(
|
||||
selected.value,
|
||||
contract,
|
||||
input.view === undefined
|
||||
? saved
|
||||
: options.recordEvidence?.(selected.value),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -14,16 +14,26 @@ export const recordResult = (
|
||||
| "javascript-export-shape"
|
||||
| "source-to-bundle-comparison",
|
||||
) => {
|
||||
const recorded =
|
||||
unknownKind === undefined
|
||||
? options.recordEvidence?.(evidence)
|
||||
: options.recordEvidenceWithUnknown?.(
|
||||
evidence,
|
||||
unknownRegistration(evidence, unknownKind),
|
||||
);
|
||||
const recorded = recordApplicationResult(options, evidence, unknownKind);
|
||||
return options.delivery.toEvidenceToolResult(evidence, contract, recorded);
|
||||
};
|
||||
|
||||
/** Record the complete parent before choosing a delivery projection. */
|
||||
export const recordApplicationResult = (
|
||||
options: ApplicationToolRegistration,
|
||||
evidence: Evidence,
|
||||
unknownKind?:
|
||||
| "application-version-comparison"
|
||||
| "javascript-export-shape"
|
||||
| "source-to-bundle-comparison",
|
||||
) =>
|
||||
unknownKind === undefined
|
||||
? options.recordEvidence?.(evidence)
|
||||
: options.recordEvidenceWithUnknown?.(
|
||||
evidence,
|
||||
unknownRegistration(evidence, unknownKind),
|
||||
);
|
||||
|
||||
const unknownRegistration = (
|
||||
evidence: Evidence,
|
||||
kind:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ArtifactResourceScope } from "../../artifacts/ArtifactResourceScope.js";
|
||||
import type {
|
||||
EvidenceWriter,
|
||||
EvidenceReader,
|
||||
@@ -8,6 +9,7 @@ import type { WithAdmittedAnalysis } from "../analysisAdmission.js";
|
||||
|
||||
/** Shared services for registering JavaScript application graph workflows. */
|
||||
export interface ApplicationToolRegistration {
|
||||
readonly artifactResources?: ArtifactResourceScope;
|
||||
readonly withAdmittedAnalysis?: WithAdmittedAnalysis;
|
||||
readonly logger: Logger;
|
||||
readonly evidenceById: EvidenceReader["evidenceById"] | undefined;
|
||||
|
||||
Reference in new issue
Block a user