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;
}
+26 -3
View File
@@ -611,21 +611,44 @@ export const HELP_REGISTRY: AreaHelp[] = [
{
area: "report",
title: "Monthly audit accuracy reports",
description: "Generate the monthly AI audit accuracy report (Markdown) from a mutable template plus live tenant data.",
description: "Generate monthly audit reports, validate local Markdown, and export HTML/PNG/PDF.",
commands: [
{
name: "monthly",
aliases: ["month"],
summary: "Fill the monthly report template with performance, risk, and approval-run data",
usage: ["seal-use report monthly --month <YYYY-MM> [--template <file>] [--report-id <RPT-...>] [--max-runs <n>] [--corp <corpId>]"],
usage: ["seal-use report monthly --month <YYYY-MM> [--out <报告.md>] [--template <file>] [--report-id <RPT-...>] [--max-runs <n>] [--corp <corpId>]"],
options: [
{ flag: "--month <YYYY-MM>", description: "Statistics month, e.g. 2026-08 (required)" },
{ flag: "--template <file>", description: "Custom template Markdown path; defaults to report-templates/monthly.md" },
{ flag: "--template <file>", description: "Custom template Markdown path; defaults to the Git-managed template embedded in the binary, independent of cwd" },
{ flag: "--out <file>", description: "Save Markdown plus local images beside the report; stdout stays JSON (without the content field)" },
{ flag: "--overwrite", description: "Explicitly permit replacing existing output files" },
{ flag: "--report-id <RPT-...>", description: "Custom report id; defaults to RPT-<YYYYMM>-<random>" },
{ flag: "--max-runs <n>", description: "Cap approval-run detail fetch, default 500 (max 500)" }
],
description: "The template is the mutable skin: section headings, tables, and order may change and data demands are inferred from headings (src/domains/seal/reports/describe.ts). Fields with no upstream metric (human accuracy, mismatch categories) keep template sample values and are marked with a warning note instead of fabricated numbers."
},
{
name: "validate",
summary: "Check a local report's structure, images, totals, and formulas",
usage: ["seal-use report validate <报告.md> [--python <executable>]"],
options: [{ flag: "--python <executable>", description: "Python 3 executable; defaults to python3 on PATH" }],
description: "Local only: no --corp, credentials, or Seal requests. Returns JSON issues; exit 1 if validation fails."
},
{
name: "render",
summary: "Validate and export HTML, full-length PNG, and A4 PDF from local Markdown",
usage: ["seal-use report render <报告.md> --out <build/报告> [--format <all|html|png|pdf>]"],
options: [
{ flag: "--out <stem>", description: "Output filename stem; extensions are appended" },
{ flag: "--format <format>", description: "all (default), html, png, or pdf; PNG/PDF also produce HTML" },
{ flag: "--width <px>", description: "PNG viewport width, default 1200 (320–5000)" },
{ flag: "--python <executable>", description: "Python 3 executable; defaults to python3 on PATH" },
{ flag: "--chrome <executable>", description: "Chrome/Chromium executable; otherwise auto-detected" },
{ flag: "--overwrite", description: "Explicitly permit replacing existing output files after successful rendering" }
],
description: "No enterprise login. Validation failure produces JSON issues and no artifacts. Requires Python 3; PNG/PDF also need Chrome/Chromium, PNG needs Pillow. First use of math fetches and caches KaTeX resources. Markdown parsing is bundled, with no runtime npm/npx dependency."
},
{
name: "review set",
summary: "Record one human adjudication (who was right: AI or human) for a document",
+6 -6
View File
@@ -42,7 +42,7 @@ export const BOOLEAN_FLAGS = new Set([
export const VALUE_FLAGS = new Set([
"access-token", "accessToken", "app-key", "app-security", "appKey", "appSecurity",
"base-url", "batch", "batch-id", "batchId", "business-codes", "businessCodes",
"channel", "code", "concurrency", "content", "content-file", "content-hints", "content-type", "contentFile",
"channel", "chrome", "code", "concurrency", "content", "content-file", "content-hints", "content-type", "contentFile",
"contentType", "context-chars", "contextLines", "corp", "corp-id", "corpId", "corporation-id", "corporationId", "date",
"dedupe-by", "dedupeBy", "default", "departmentId", "dept", "desc",
"description", "description-file", "descriptionFile", "dir", "doc-id-prefix", "doc-id-suffix",
@@ -61,7 +61,7 @@ export const VALUE_FLAGS = new Set([
"out-dir", "outDir", "outgoing-result-webhook", "outgoingResultWebhook", "output", "output-file",
"outputFile", "p", "package-id", "package-ids", "packageId", "packageIds",
"path", "phone", "policyId", "poll-interval", "pollInterval", "port",
"prod", "prod-corp", "prodCorp", "purpose", "q", "query",
"prod", "prod-corp", "prodCorp", "purpose", "python", "q", "query",
"record-id", "record-ids", "recordId", "recordIds", "reject-node", "rejectNode", "rejection-num", "rejectionNum",
"reviewed-by", "reviewedBy",
"report-id",
@@ -81,7 +81,7 @@ export const VALUE_FLAGS = new Set([
"trace-id", "trace-limit",
"type", "until", "url", "userId", "version-name", "versionName",
"verdict",
"webhook", "workflow-type-id", "workflowTypeId"
"webhook", "width", "workflow-type-id", "workflowTypeId"
]);
// Registered flags. Unknown flags are rejected.
@@ -89,7 +89,7 @@ export const KNOWN_FLAGS = new Set([
"V", "access-token", "accessToken", "add", "all", "app-key",
"app-security", "appKey", "appSecurity", "as-hose", "attachments", "auto",
"auto-login", "autoLogin", "base-url", "batch", "batch-id", "batchId",
"bg-save", "business-codes", "businessCodes", "channel", "changelog", "check", "check-only",
"bg-save", "business-codes", "businessCodes", "channel", "changelog", "check", "check-only", "chrome",
"code", "completed-only", "completedOnly", "concurrency", "confirm", "content",
"content-file", "content-hints", "content-type", "contentFile", "contentType", "context-chars", "contextLines", "corp",
"corp-id", "corpId", "corporation-id", "corporationId", "count", "date", "dedupe-by", "dedupeBy",
@@ -115,7 +115,7 @@ export const KNOWN_FLAGS = new Set([
"outgoing-result-webhook", "outgoingResultWebhook", "output", "output-file", "outputFile", "overwrite",
"p", "package-id", "package-ids", "packageId", "packageIds", "path",
"phone", "plain", "policyId", "poll-interval", "pollInterval", "port",
"prod", "prod-corp", "prodCorp", "publish", "purpose", "q",
"prod", "prod-corp", "prodCorp", "publish", "purpose", "python", "q",
"query", "quiet", "r", "recode", "record-id", "record-ids",
"recordId", "recordIds", "refresh", "refresh-if-missing", "reject-node", "rejectNode", "rejection-num", "rejectionNum", "repo",
"report-id",
@@ -138,7 +138,7 @@ export const KNOWN_FLAGS = new Set([
"to", "to-downloads", "toDownloads", "token", "tokenId", "trace-id", "trace-limit", "type",
"until", "url", "userId", "v", "version", "version-name",
"verdict",
"versionName", "wait", "webhook", "with-expense-extraction", "withExpenseExtraction", "with-flow", "workflow-type-id", "workflowTypeId",
"versionName", "wait", "webhook", "width", "with-expense-extraction", "withExpenseExtraction", "with-flow", "workflow-type-id", "workflowTypeId",
"workspace", "yes"
]);
+1 -1
View File
@@ -78,7 +78,7 @@ const READ_ONLY_COMMANDS: Record<string, string[]> = {
// `analyze` is deliberately absent: it POSTs and starts an analysis server-side, so it is a
// mutation despite reading like a query. See SEAL_MUTATING_CAPABILITIES.
analytics: ["insight", "risks", "performance", "export"],
report: ["monthly", "review list"],
report: ["monthly", "validate", "render", "review list"],
source: ["config"],
skill: ["dump", "status"],
doctor: ["", "guide", "paths", "tenant", "auth"],
+5
View File
@@ -224,6 +224,11 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
return;
}
if (area === "report" && (action === "validate" || action === "render")) {
await (await import("./commands/report.js")).handleLocalReportCommand(action, args);
return;
}
// Langfuse trace inspection needs no tenant: it authenticates with the
// compile-time injected read-only key pair, so it dispatches before corp
// selection (like probe/doctor) and never touches a Seal client.