mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
refactor(cli): project view-delivery inspectors from their contracts (#10600)
* refactor(cli): project view-delivery inspectors from their contracts * refactor(cli): project APK signature, desktop application and EVM inspectors from contracts (#10603)
This commit is contained in:
1 parent
254bb21857
commit
fa53f7070a
15 files changed
+622
-605
No files matched your search
+42
-92
@@ -1,102 +1,52 @@
|
||||
import { parseCliJsonOption } from "./cliJsonOption.js";
|
||||
import { inspectModelArtifactInputSchema } from "../domain/model/modelArtifactQuery.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { z } from "incur";
|
||||
import type { Logger } from "pino";
|
||||
import type { CliInstance } from "./types.js";
|
||||
import { localPathStringSchema } from "../domain/localPath.js";
|
||||
import { absoluteCallerPath } from "../filesystem/callerPath.js";
|
||||
import { createModelArtifactService } from "../composition/model.js";
|
||||
|
||||
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import { withCommandCancellation } from "./commandCancellation.js";
|
||||
import { createModelArtifactService } from "../composition/model.js";
|
||||
import { INSPECT_MODEL_ARTIFACT_CONTRACT } from "../contracts/model/modelToolContracts.js";
|
||||
import {
|
||||
analysisEvidenceDeliveryOptions,
|
||||
deliverCliAnalysisEvidence,
|
||||
} from "./analysisEvidenceDelivery.js";
|
||||
deliverWithService,
|
||||
registerContractCommand,
|
||||
} from "./contractCommand.js";
|
||||
import type { CliInstance } from "./types.js";
|
||||
|
||||
/** One-shot summaries export the same complete observations used by MCP retained pages. */
|
||||
export const registerModelCommands = (
|
||||
cli: CliInstance,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
cli.command(CLI_COMMANDS.inspectModelArtifact, {
|
||||
description:
|
||||
"Inspect GGUF or safetensors headers without loading model weights",
|
||||
args: z.object({
|
||||
path: localPathStringSchema.describe(
|
||||
"Local model file, detected by content",
|
||||
),
|
||||
}),
|
||||
options: z.object({
|
||||
...analysisEvidenceDeliveryOptions,
|
||||
view: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
"JSON model page selection; requires --detail summary and --evidence_output",
|
||||
),
|
||||
hash: z
|
||||
.enum(["header", "full"])
|
||||
.default("header")
|
||||
.describe(
|
||||
"header reads declarations only; full additionally streams all bytes for SHA-256",
|
||||
),
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
withCommandCancellation((signal) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectModelArtifact, async () => {
|
||||
const decoded = parseCliJsonOption(
|
||||
"inspect_model_artifact",
|
||||
"view",
|
||||
options.view,
|
||||
"view must be a JSON model page selection",
|
||||
);
|
||||
if (!decoded.ok) return projectAnalysisError(decoded.error);
|
||||
const view = decoded.value;
|
||||
const selected = inspectModelArtifactInputSchema.safeParse({
|
||||
path: absoluteCallerPath(args.path),
|
||||
hash: options.hash,
|
||||
detail: options.detail,
|
||||
...(view === undefined ? {} : { view }),
|
||||
});
|
||||
if (!selected.success)
|
||||
return projectAnalysisError(
|
||||
analysisInputErrorFromIssues(
|
||||
"inspect_model_artifact",
|
||||
selected.error.issues,
|
||||
{ view },
|
||||
),
|
||||
);
|
||||
const service = createModelArtifactService();
|
||||
return deliverCliAnalysisEvidence({
|
||||
callerInputPath: args.path,
|
||||
run: () =>
|
||||
service.inspect(
|
||||
{
|
||||
path: selected.data.path,
|
||||
hash: selected.data.hash,
|
||||
detail: "complete",
|
||||
},
|
||||
{ signal },
|
||||
),
|
||||
service,
|
||||
providerId: "model-artifact",
|
||||
operation: "inspect_model_artifact",
|
||||
signal,
|
||||
detail: options.detail,
|
||||
evidenceOutput: options.evidence_output,
|
||||
...(selected.data.view === undefined
|
||||
? {}
|
||||
: {
|
||||
view: {
|
||||
kind: "model-artifact" as const,
|
||||
...selected.data.view,
|
||||
},
|
||||
}),
|
||||
});
|
||||
}),
|
||||
),
|
||||
});
|
||||
const deliver = deliverWithService(
|
||||
createModelArtifactService,
|
||||
"model-artifact",
|
||||
);
|
||||
registerContractCommand(
|
||||
cli,
|
||||
logger,
|
||||
INSPECT_MODEL_ARTIFACT_CONTRACT,
|
||||
{
|
||||
command: CLI_COMMANDS.inspectModelArtifact,
|
||||
description:
|
||||
"Inspect GGUF or safetensors headers without loading model weights",
|
||||
positionals: ["path"],
|
||||
callerPaths: ["path"],
|
||||
evidenceDelivery: true,
|
||||
viewDelivery: {
|
||||
invalidJson: "view must be a JSON model page selection",
|
||||
kind: "model-artifact",
|
||||
},
|
||||
fields: {
|
||||
path: { description: "Local model file, detected by content" },
|
||||
hash: {
|
||||
description:
|
||||
"header reads declarations only; full additionally streams all bytes for SHA-256",
|
||||
},
|
||||
view: {
|
||||
description:
|
||||
"JSON model page selection; requires --detail summary and --evidence_output",
|
||||
},
|
||||
},
|
||||
},
|
||||
// The CLI delivers the summary itself, so the service returns complete
|
||||
// Evidence; the contract's own default would retain a summary instead.
|
||||
(input, context) => deliver({ ...input, detail: "complete" }, context),
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user