mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
253 lines
8.8 KiB
TypeScript
253 lines
8.8 KiB
TypeScript
import { registerPlaywrightTraceCommand } from "./playwrightTraceCommand.js";
|
|
import { registerApiContractCommand } from "./apiContractCommand.js";
|
|
import { registerEvtxArchiveCommand } from "./evtxArchiveCommand.js";
|
|
import { registerNtfsJournalCommand } from "./ntfsJournalCommand.js";
|
|
import type { CliInstance } from "./types.js";
|
|
|
|
import { cliCommandFor } from "../contracts/cliCommandNames.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import type { JsonValue } from "../domain/jsonValue.js";
|
|
import type { Logger } from "pino";
|
|
import { APPLICATION_TOOL_CONTRACTS } from "../contracts/applicationToolContracts.js";
|
|
import { contractNamed } from "./contractCliDescription.js";
|
|
import { registerContractDocumentCommand } from "./contractDocumentCommand.js";
|
|
import type { EvidenceLookup } from "../application/EvidenceInputResolver.js";
|
|
import type { Evidence } from "../domain/evidence.js";
|
|
import type { Result } from "../domain/result.js";
|
|
import {
|
|
evidenceBundleOption,
|
|
runEvidenceInputCommand,
|
|
} from "./evidenceInputCommand.js";
|
|
|
|
/** Application workflows whose CLI input is one Evidence-carrying JSON document. */
|
|
type EvidenceWorkflowOperation =
|
|
| "trace_application_feature"
|
|
| "trace_javascript_semantics"
|
|
| "compare_application_versions"
|
|
| "compare_javascript_export_shapes"
|
|
| "project_android_application_graph"
|
|
| "project_apple_application_graph"
|
|
| "project_harmony_application_graph";
|
|
|
|
const workflowJsonDescription = "Inline workflow JSON or JSON file path";
|
|
|
|
/** Register CLI equivalents of provider-neutral application graph workflows. */
|
|
export const registerApplicationCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>> = process.env,
|
|
): void => {
|
|
registerPlaywrightTraceCommand(cli, logger, environment);
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("trace_application_feature"),
|
|
operation: "trace_application_feature",
|
|
omit: {
|
|
view: "A one-shot command retains no session Evidence for a selected view; save the complete trace and query it with inspect-analysis-view",
|
|
},
|
|
description:
|
|
"Trace a typed seed through authenticated application Evidence JSON",
|
|
loadWorkflow: async () =>
|
|
(
|
|
await import("../application/javascript/JavaScriptApplicationWorkflowService.js")
|
|
).traceApplicationFeatureEvidence,
|
|
});
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("trace_javascript_semantics"),
|
|
operation: "trace_javascript_semantics",
|
|
description:
|
|
"Trace bounded static semantic relations through authenticated application Evidence",
|
|
loadWorkflow: async () =>
|
|
(
|
|
await import("../application/javascript/JavaScriptSemanticTraceService.js")
|
|
).traceJavaScriptSemanticsEvidence,
|
|
});
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("compare_application_versions"),
|
|
operation: "compare_application_versions",
|
|
description:
|
|
"Compare two authenticated JavaScript Application Graph versions",
|
|
loadWorkflow: async () =>
|
|
(
|
|
await import("../application/javascript/JavaScriptApplicationWorkflowService.js")
|
|
).compareApplicationVersionsEvidence,
|
|
});
|
|
registerApiContractCommand(cli, logger);
|
|
registerEvtxArchiveCommand(cli, logger);
|
|
registerNtfsJournalCommand(cli, logger);
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("compare_javascript_export_shapes"),
|
|
operation: "compare_javascript_export_shapes",
|
|
description:
|
|
"Compare exact static JavaScript export return shapes without execution",
|
|
loadWorkflow: async () =>
|
|
(
|
|
await import("../application/javascript/JavaScriptApplicationWorkflowService.js")
|
|
).compareJavaScriptExportShapesEvidence,
|
|
});
|
|
registerObligationLedgerCommand(cli, logger);
|
|
registerCoverageCommand(cli, logger);
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("project_android_application_graph"),
|
|
operation: "project_android_application_graph",
|
|
description:
|
|
"Project authenticated APK inventory Evidence into an Android application graph",
|
|
loadWorkflow: async () =>
|
|
(await import("../application/InventoryProjectionEvidence.js"))
|
|
.projectAndroidApplicationEvidence,
|
|
});
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("project_apple_application_graph"),
|
|
operation: "project_apple_application_graph",
|
|
description:
|
|
"Project authenticated IPA or macOS app inventory Evidence into an Apple application graph",
|
|
loadWorkflow: async () =>
|
|
(await import("../application/InventoryProjectionEvidence.js"))
|
|
.projectAppleApplicationEvidence,
|
|
});
|
|
registerEvidenceJsonCommand({
|
|
cli,
|
|
logger,
|
|
name: cliCommandFor("project_harmony_application_graph"),
|
|
operation: "project_harmony_application_graph",
|
|
description:
|
|
"Project authenticated HarmonyOS HAP, HSP, or App Pack inventory Evidence into an application graph",
|
|
loadWorkflow: async () =>
|
|
(await import("../application/InventoryProjectionEvidence.js"))
|
|
.projectHarmonyApplicationEvidence,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Inline reconstruction workflows. Each owner authenticates its embedded
|
|
* Evidence bundle itself, so the handler passes the decoded document on.
|
|
*/
|
|
const registerReconstructionDocumentCommand = <
|
|
Operation extends
|
|
| "build_reconstruction_obligation_ledger"
|
|
| "evaluate_reconstruction_coverage",
|
|
>(
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
operation: Operation,
|
|
command: string,
|
|
description: string,
|
|
workflow: (
|
|
input: unknown,
|
|
) => Promise<
|
|
| { readonly ok: true; readonly value: JsonValue }
|
|
| { readonly ok: false; readonly error: AnalysisError }
|
|
>,
|
|
): void =>
|
|
registerContractDocumentCommand(
|
|
cli,
|
|
logger,
|
|
contractNamed(APPLICATION_TOOL_CONTRACTS, operation),
|
|
{ command, description, document: workflowJsonDescription },
|
|
async (input) => {
|
|
const result = await workflow(input);
|
|
return result.ok
|
|
? result.value
|
|
: {
|
|
error: "Application workflow failed",
|
|
...projectAnalysisError(result.error, "invocation"),
|
|
};
|
|
},
|
|
);
|
|
|
|
const registerObligationLedgerCommand = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
): void =>
|
|
registerReconstructionDocumentCommand(
|
|
cli,
|
|
logger,
|
|
"build_reconstruction_obligation_ledger",
|
|
cliCommandFor("build_reconstruction_obligation_ledger"),
|
|
"Generate a deterministic Evidence-backed reconstruction obligation ledger page",
|
|
async (input) => {
|
|
const { buildReconstructionObligationLedgerEvidence } =
|
|
await import("../application/ReconstructionObligationLedgerService.js");
|
|
return buildReconstructionObligationLedgerEvidence(input);
|
|
},
|
|
);
|
|
|
|
const registerCoverageCommand = (cli: CliInstance, logger: Logger): void =>
|
|
registerReconstructionDocumentCommand(
|
|
cli,
|
|
logger,
|
|
"evaluate_reconstruction_coverage",
|
|
cliCommandFor("evaluate_reconstruction_coverage"),
|
|
"Evaluate inline fail-closed reconstruction coverage",
|
|
async (input) => {
|
|
const { evaluateReconstructionCoverage } =
|
|
await import("../application/ReconstructionCoverageService.js");
|
|
return evaluateReconstructionCoverage(input);
|
|
},
|
|
);
|
|
|
|
/** Evidence consumers share one explicit portable source and cancellation lifetime. */
|
|
const registerEvidenceJsonCommand = ({
|
|
cli,
|
|
logger,
|
|
name,
|
|
operation,
|
|
description,
|
|
omit,
|
|
loadWorkflow,
|
|
}: {
|
|
readonly cli: CliInstance;
|
|
readonly logger: Logger;
|
|
readonly name: string;
|
|
readonly operation: EvidenceWorkflowOperation;
|
|
readonly description: string;
|
|
readonly omit?: Readonly<Record<string, string>>;
|
|
readonly loadWorkflow: () => Promise<
|
|
(
|
|
input: unknown,
|
|
lookup: EvidenceLookup | undefined,
|
|
options: { readonly signal: AbortSignal },
|
|
) => Result<{ readonly evidence: Evidence }, AnalysisError>
|
|
>;
|
|
}): void =>
|
|
registerContractDocumentCommand(
|
|
cli,
|
|
logger,
|
|
contractNamed(APPLICATION_TOOL_CONTRACTS, operation),
|
|
{
|
|
command: name,
|
|
description,
|
|
document: workflowJsonDescription,
|
|
...(omit === undefined ? {} : { omit }),
|
|
cliOptions: { evidenceBundle: evidenceBundleOption },
|
|
},
|
|
async (input, { signal, frame, cliOptions }) => {
|
|
const result = await runEvidenceInputCommand(
|
|
input,
|
|
{ operation, signal, frame, cliOptions },
|
|
async (lookup) => {
|
|
const workflow = await loadWorkflow();
|
|
const selected = workflow(input, lookup, { signal });
|
|
return selected.ok
|
|
? { ok: true, value: selected.value.evidence }
|
|
: selected;
|
|
},
|
|
);
|
|
return result.ok
|
|
? result.value
|
|
: { error: "Application workflow failed", ...result.error };
|
|
},
|
|
);
|