feat: complete REA remediation program

This commit is contained in:
N0zoM1z0
2026-07-22 22:09:12 +09:00
committed by N0zoM1z0
parent 737940c90c
commit d25e98c3f9
460 changed files with 13985 additions and 1877 deletions
+42 -11
View File
@@ -1,11 +1,11 @@
import { applicationVersionComparisonResultSchema } from "../domain/javascriptApplicationVersionComparisonSchemas.js";
import { applicationFeatureTraceResultSchema } from "../domain/javascriptFeatureTraceSchemas.js";
import { javaScriptExportShapeComparisonResultSchema } from "../domain/javascriptExportShapeComparisonSchemas.js";
import {
applicationVersionComparisonResultSchema,
compareApplicationVersionsInputSchema,
} from "../domain/javascriptApplicationVersionComparisonSchemas.js";
import {
applicationFeatureTraceResultSchema,
traceApplicationFeatureInputSchema,
} from "../domain/javascriptFeatureTraceSchemas.js";
compareApplicationVersionsRequestSchema,
compareJavaScriptExportShapesRequestSchema,
traceApplicationFeatureRequestSchema,
} from "./applicationWorkflowInputContracts.js";
import {
controlledReplayInputSchema,
controlledReplayOutputSchema,
@@ -28,6 +28,7 @@ import { toolContractMetadata } from "./toolEffects.js";
import { evidenceResultOf } from "./toolOutputSchemas.js";
import {
JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
JAVASCRIPT_EXPORT_SHAPE_COMPARISON_EXAMPLE,
JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
} from "./javascriptApplicationWorkflowExamples.js";
@@ -35,6 +36,9 @@ const traceOutputSchema = evidenceResultOf(applicationFeatureTraceResultSchema);
const comparisonOutputSchema = evidenceResultOf(
applicationVersionComparisonResultSchema,
);
const exportShapeComparisonOutputSchema = evidenceResultOf(
javaScriptExportShapeComparisonResultSchema,
);
const HASH = "0".repeat(64);
const NODE_PREPARATION_EXAMPLE = jsonObjectSchema.parse({
preparation_approved: true,
@@ -105,9 +109,9 @@ export const APPLICATION_TOOL_CONTRACTS = [
name: "trace_application_feature",
...toolContractMetadata("trace_application_feature"),
description:
"Trace a typed literal seed through an authenticated JavaScript Application Graph with explicit direction, depth, node, edge, and path bounds. Original static, native, passive-runtime, inferred, and unknown authorities remain distinct; native addon handoffs never open a provider or execute the application.",
"Trace a typed literal seed through an authenticated JavaScript Application Graph supplied as full Evidence or an Evidence ID returned earlier in this session. Explicit direction, depth, node, edge, and path bounds apply. Original static, native, passive-runtime, inferred, and unknown authorities remain distinct; native addon handoffs never open a provider or execute the application.",
kind: "application",
inputSchema: traceApplicationFeatureInputSchema,
inputSchema: traceApplicationFeatureRequestSchema,
outputSchema: traceOutputSchema,
examples: [
{
@@ -120,9 +124,9 @@ export const APPLICATION_TOOL_CONTRACTS = [
name: "compare_application_versions",
...toolContractMetadata("compare_application_versions"),
description:
"Compare two authenticated JavaScript Application Graph versions using unique-only exact digest, module source digest, source-map identity, structural fingerprint, and non-module semantic-key tiers. Reports added, removed, changed, ambiguous, and unknown entities plus a bounded changed_from graph without fuzzy or module-ordinal pairing.",
"Compare two authenticated JavaScript Application Graph versions supplied as full Evidence or Evidence IDs returned earlier in this session. Uses unique-only exact digest, module source digest, source-map identity, structural fingerprint, and non-module semantic-key tiers. Reports added, removed, changed, ambiguous, and unknown entities plus a bounded changed_from graph without fuzzy or module-ordinal pairing.",
kind: "application",
inputSchema: compareApplicationVersionsInputSchema,
inputSchema: compareApplicationVersionsRequestSchema,
outputSchema: comparisonOutputSchema,
examples: [
{
@@ -131,6 +135,21 @@ export const APPLICATION_TOOL_CONTRACTS = [
},
],
},
{
name: "compare_javascript_export_shapes",
...toolContractMetadata("compare_javascript_export_shapes"),
description:
"Compare bounded static return shapes for one exact module/export selector on each authenticated JavaScript Application Graph, supplied as full Evidence or session Evidence IDs. Variants pair only by reciprocal unique literal discriminants; dynamic values, incomplete properties, and ambiguous variants remain unknown. Reports JSON Pointer changes and recommends controlled replay separately without executing JavaScript.",
kind: "application",
inputSchema: compareJavaScriptExportShapesRequestSchema,
outputSchema: exportShapeComparisonOutputSchema,
examples: [
{
title: "Compare one exact parser export without execution",
input: JAVASCRIPT_EXPORT_SHAPE_COMPARISON_EXAMPLE,
},
],
},
{
name: "run_controlled_replay",
...toolContractMetadata("run_controlled_replay"),
@@ -257,3 +276,15 @@ export const APPLICATION_TOOL_CONTRACTS = [
],
},
] as const satisfies readonly ToolContract[];
/** Resolve one named application contract without relying on array position. */
export const applicationToolContract = (
name: (typeof APPLICATION_TOOL_CONTRACTS)[number]["name"],
): (typeof APPLICATION_TOOL_CONTRACTS)[number] => {
const contract = APPLICATION_TOOL_CONTRACTS.find(
({ name: candidate }) => candidate === name,
);
if (contract === undefined)
throw new Error(`Missing application tool contract: ${name}`);
return contract;
};
@@ -0,0 +1,130 @@
import { z } from "zod";
import { evidenceSchema } from "../domain/evidence.js";
import { compareApplicationVersionsInputSchema } from "../domain/javascriptApplicationVersionComparisonSchemas.js";
import { compareJavaScriptExportShapesInputSchema } from "../domain/javascriptExportShapeComparisonSchemas.js";
import { traceApplicationFeatureInputSchema } from "../domain/javascriptFeatureTraceSchemas.js";
const evidenceIdSchema = z
.string()
.regex(/^ev_[a-f0-9]{64}$/u)
.describe("Evidence ID returned earlier in this session");
const requireExactlyOne = (
context: z.RefinementCtx,
fields: readonly [string, unknown, string, unknown],
): void => {
const [leftName, left, rightName, right] = fields;
if ((left === undefined) !== (right === undefined)) return;
context.addIssue({
code: "custom",
path: [left === undefined ? leftName : rightName],
message: `Supply exactly one of ${leftName} or ${rightName}`,
});
};
/** MCP/CLI trace request accepting full Evidence or a ledger reference. */
export const traceApplicationFeatureRequestSchema = z
.strictObject({
application: evidenceSchema.optional(),
application_evidence_id: evidenceIdSchema.optional(),
native_observations:
traceApplicationFeatureInputSchema.shape.native_observations,
native_observation_evidence_ids: z
.array(evidenceIdSchema)
.max(64)
.default([]),
seed: traceApplicationFeatureInputSchema.shape.seed,
direction: traceApplicationFeatureInputSchema.shape.direction,
limits: traceApplicationFeatureInputSchema.shape.limits,
})
.superRefine((input, context) => {
requireExactlyOne(context, [
"application",
input.application,
"application_evidence_id",
input.application_evidence_id,
]);
});
/** MCP/CLI comparison request accepting full Evidence or ledger references. */
export const compareApplicationVersionsRequestSchema = z
.strictObject({
left: evidenceSchema.optional(),
left_evidence_id: evidenceIdSchema.optional(),
right: evidenceSchema.optional(),
right_evidence_id: evidenceIdSchema.optional(),
left_native_observations:
compareApplicationVersionsInputSchema.shape.left_native_observations,
left_native_observation_evidence_ids: z
.array(evidenceIdSchema)
.max(64)
.default([]),
right_native_observations:
compareApplicationVersionsInputSchema.shape.right_native_observations,
right_native_observation_evidence_ids: z
.array(evidenceIdSchema)
.max(64)
.default([]),
limits: compareApplicationVersionsInputSchema.shape.limits,
unknown_registry_approved:
compareApplicationVersionsInputSchema.shape.unknown_registry_approved,
})
.superRefine((input, context) => {
requireExactlyOne(context, [
"left",
input.left,
"left_evidence_id",
input.left_evidence_id,
]);
requireExactlyOne(context, [
"right",
input.right,
"right_evidence_id",
input.right_evidence_id,
]);
});
/** MCP/CLI export-shape request accepting full Evidence or ledger references. */
export const compareJavaScriptExportShapesRequestSchema = z
.strictObject({
left: evidenceSchema.optional(),
left_evidence_id: evidenceIdSchema.optional(),
right: evidenceSchema.optional(),
right_evidence_id: evidenceIdSchema.optional(),
left_module_path:
compareJavaScriptExportShapesInputSchema.shape.left_module_path,
left_export_name:
compareJavaScriptExportShapesInputSchema.shape.left_export_name,
right_module_path:
compareJavaScriptExportShapesInputSchema.shape.right_module_path,
right_export_name:
compareJavaScriptExportShapesInputSchema.shape.right_export_name,
limits: compareJavaScriptExportShapesInputSchema.shape.limits,
unknown_registry_approved:
compareJavaScriptExportShapesInputSchema.shape.unknown_registry_approved,
})
.superRefine((input, context) => {
requireExactlyOne(context, [
"left",
input.left,
"left_evidence_id",
input.left_evidence_id,
]);
requireExactlyOne(context, [
"right",
input.right,
"right_evidence_id",
input.right_evidence_id,
]);
});
export type TraceApplicationFeatureRequest = z.output<
typeof traceApplicationFeatureRequestSchema
>;
export type CompareApplicationVersionsRequest = z.output<
typeof compareApplicationVersionsRequestSchema
>;
export type CompareJavaScriptExportShapesRequest = z.output<
typeof compareJavaScriptExportShapesRequestSchema
>;
@@ -44,21 +44,47 @@ const reconciliationEvidence = createEvidence(
evidenceLinks: reconciliation.evidence_links,
},
);
const EXAMPLE_EVIDENCE_ID = `ev_${"0".repeat(64)}`;
const SECOND_EXAMPLE_EVIDENCE_ID = `ev_${"1".repeat(64)}`;
const TRACE_SEED = {
kind: "module" as const,
value: "renderer.js",
match: "exact" as const,
case_sensitive: false,
};
/** Valid public trace request without proprietary artifacts. */
/** Natural trace request using the Evidence ID returned by its producer. */
export const JAVASCRIPT_FEATURE_TRACE_EXAMPLE = {
application: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
seed: {
kind: "module" as const,
value: "renderer.js",
match: "exact" as const,
case_sensitive: false,
},
application_evidence_id: EXAMPLE_EVIDENCE_ID,
seed: TRACE_SEED,
direction: "both" as const,
};
/** Valid static/runtime graph pair demonstrating comparison authority. */
/** Natural version comparison using two producer-returned Evidence IDs. */
export const JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE = {
left_evidence_id: EXAMPLE_EVIDENCE_ID,
right_evidence_id: SECOND_EXAMPLE_EVIDENCE_ID,
};
/** Exact static return-shape comparison using producer-returned Evidence IDs. */
export const JAVASCRIPT_EXPORT_SHAPE_COMPARISON_EXAMPLE = {
left_evidence_id: EXAMPLE_EVIDENCE_ID,
right_evidence_id: SECOND_EXAMPLE_EVIDENCE_ID,
left_module_path: "parser.mjs",
left_export_name: "default",
right_module_path: "parser.mjs",
right_export_name: "default",
};
/** Full-Evidence compatibility fixture used by pure domain and adapter tests. */
export const JAVASCRIPT_FEATURE_TRACE_FULL_EVIDENCE_EXAMPLE = {
application: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
seed: TRACE_SEED,
direction: "both" as const,
};
/** Full-Evidence compatibility comparison fixture. */
export const JAVASCRIPT_VERSION_COMPARISON_FULL_EVIDENCE_EXAMPLE = {
left: JAVASCRIPT_APPLICATION_EVIDENCE_EXAMPLE,
right: reconciliationEvidence,
};
+1
View File
@@ -116,6 +116,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
reconcile_javascript_runtime: evidence,
trace_application_feature: evidence,
compare_application_versions: evidence,
compare_javascript_export_shapes: evidence,
run_controlled_replay: effects({
mutatesSession: true,
writesFilesystem: true,