Bundle report templates and integrate validation and rendering

This commit is contained in:
gitea committed 2026-10-12 11:38:19 +08:00
1 parent c4df5ad325
commit f726c22445
19 files changed
+588 -77

No files matched your search

+38 -6
View File
@@ -1,11 +1,35 @@
import type { CorpConfig } from "../../core/config/types.js";
import type { createSealClient } from "../../core/http/factory.js";
import { runCapability } from "../helpers.js";
import { numberOption, stringOption } from "../parser.js";
import { runCapabilityResult } from "../helpers.js";
import { booleanOption, numberOption, stringOption } from "../parser.js";
import { outputOptions, printJson } from "../printer.js";
import { CliError, usageError } from "../../core/errors.js";
import { renderReportFile, saveReportMarkdown, validateReportFile } from "../../domains/seal/reports/files.js";
import type { MonthlyReportResult } from "../../domains/seal/reports/monthly.js";
import { loadReviews, reviewFilePath, writeReview } from "../../domains/seal/reports/review-store.js";
import type { ParsedArgs } from "../types.js";
/** Tenant-free commands: dispatch these before resolving enterprise configuration or authentication. */
export async function handleLocalReportCommand(action: "validate" | "render", args: ParsedArgs) {
const file = args.command[2] ?? stringOption(args.options.file);
if (!file) throw usageError(`Usage: seal-use report ${action} <报告文件.md>${action === "render" ? " --out <产物路径词干>" : ""}`);
const python = stringOption(args.options.python);
if (action === "validate") {
const result = await validateReportFile(file, { python });
printJson(result, outputOptions(args.options));
if (!result.valid) throw new CliError("报告校验未通过,请按 issues 修正后重试。", 1);
return;
}
const out = stringOption(args.options.out) ?? stringOption(args.options.o);
if (!out) throw usageError("Usage: seal-use report render <报告文件.md> --out <产物路径词干>");
const result = await renderReportFile(file, {
out, python, format: stringOption(args.options.format), width: numberOption(args.options.width),
chrome: stringOption(args.options.chrome), overwrite: booleanOption(args.options.overwrite)
});
printJson(result, outputOptions(args.options));
if (!result.validation.valid) throw new CliError("报告校验未通过,未生成渲染产物。请按 validation.issues 修正后重试。", 1);
}
/** `seal-use report monthly` — 月度 AI 审核准确率报告(Markdown 填充)。 */
export async function handleReportCommand(
action: string | undefined,
@@ -18,7 +42,7 @@ export async function handleReportCommand(
if (!month) {
throw new Error("Usage: seal-use report monthly --month <YYYY-MM> [--template <file>] [--report-id <RPT-...>] [--corp <corpId>]");
}
await runCapability(
const result = await runCapabilityResult(
"sealReportMonthlyGet",
client,
corp,
@@ -27,9 +51,17 @@ export async function handleReportCommand(
templatePath: stringOption(args.options.template),
reportId: stringOption(args.options["report-id"]) ?? stringOption(args.options.reportId),
maxRuns: numberOption(args.options["max-runs"]) ?? numberOption(args.options.maxRuns)
},
outputOptions(args.options)
);
}
) as MonthlyReportResult;
const out = stringOption(args.options.out) ?? stringOption(args.options.o);
if (out) {
const saved = saveReportMarkdown(result.content, result.templatePath, out, booleanOption(args.options.overwrite));
const quotedFile = `'${saved.file.replace(/'/g, "'\\''")}'`;
printJson({ ...result, content: undefined, ...saved, next: {
validate: `seal-use report validate ${quotedFile}`,
render: `seal-use report render ${quotedFile} --out build/report`
} }, outputOptions(args.options));
} else printJson(result, outputOptions(args.options));
return;
}