Refine report pipeline to support date ranges and recordId reviews
This commit is contained in:
1 parent
64680cd4a0
commit
077ecb050c
11 files changed
+552
-164
No files matched your search
+63
-19
@@ -78,7 +78,7 @@ export async function handleLocalReportCommand(action: "validate" | "render" | "
|
||||
if (!result.validation.valid) throw new CliError("报告校验未通过,未生成渲染产物。请按 validation.issues 修正后重试。", 1);
|
||||
}
|
||||
|
||||
/** `seal-use report monthly` / `data` — 月度 AI 审核报告。 */
|
||||
/** `seal-use report generate` / `data` — AI 审核报告。 */
|
||||
export async function handleReportCommand(
|
||||
action: string | undefined,
|
||||
client: Awaited<ReturnType<typeof createSealClient>>,
|
||||
@@ -86,16 +86,35 @@ export async function handleReportCommand(
|
||||
args: ParsedArgs
|
||||
) {
|
||||
if (action === "data") {
|
||||
const startDate =
|
||||
stringOption(args.options["start-date"]) ??
|
||||
stringOption(args.options.startDate) ??
|
||||
stringOption(args.options.start) ??
|
||||
stringOption(args.options.since);
|
||||
const endDate =
|
||||
stringOption(args.options["end-date"]) ??
|
||||
stringOption(args.options.endDate) ??
|
||||
stringOption(args.options.end) ??
|
||||
stringOption(args.options.until);
|
||||
const month = stringOption(args.options.month);
|
||||
if (!month) {
|
||||
throw new Error("Usage: seal-use report data --month <YYYY-MM> [--max-runs <n>] [--corp <corpId>]");
|
||||
|
||||
if ((!startDate || !endDate) && !month) {
|
||||
throw usageError(
|
||||
"Usage: seal-use report data --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD> [--templates <t1,t2...>] [--max-runs <n>] [--corp <corpId>]"
|
||||
);
|
||||
}
|
||||
|
||||
const templates = stringOption(args.options.templates)?.split(/[,;]+/).map((s) => s.trim()).filter(Boolean);
|
||||
|
||||
const result = await runCapabilityResult(
|
||||
"sealReportDataGet",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
startDate,
|
||||
endDate,
|
||||
month,
|
||||
templates,
|
||||
maxRuns: numberOption(args.options["max-runs"]) ?? numberOption(args.options.maxRuns)
|
||||
}
|
||||
);
|
||||
@@ -103,17 +122,36 @@ export async function handleReportCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "monthly" || action === "month") {
|
||||
if (action === "monthly" || action === "month" || action === "generate") {
|
||||
const startDate =
|
||||
stringOption(args.options["start-date"]) ??
|
||||
stringOption(args.options.startDate) ??
|
||||
stringOption(args.options.start) ??
|
||||
stringOption(args.options.since);
|
||||
const endDate =
|
||||
stringOption(args.options["end-date"]) ??
|
||||
stringOption(args.options.endDate) ??
|
||||
stringOption(args.options.end) ??
|
||||
stringOption(args.options.until);
|
||||
const month = stringOption(args.options.month);
|
||||
if (!month) {
|
||||
throw new Error("Usage: seal-use report monthly --month <YYYY-MM> [--template <file>] [--report-id <RPT-...>] [--corp <corpId>]");
|
||||
|
||||
if ((!startDate || !endDate) && !month) {
|
||||
throw usageError(
|
||||
"Usage: seal-use report generate --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD> [--templates <t1,t2...>] [--template <file>] [--report-id <RPT-...>] [--corp <corpId>]"
|
||||
);
|
||||
}
|
||||
|
||||
const templates = stringOption(args.options.templates)?.split(/[,;]+/).map((s) => s.trim()).filter(Boolean);
|
||||
|
||||
const result = await runCapabilityResult(
|
||||
"sealReportMonthlyGet",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
startDate,
|
||||
endDate,
|
||||
month,
|
||||
templates,
|
||||
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),
|
||||
@@ -141,17 +179,14 @@ export async function handleReportCommand(
|
||||
|
||||
if (action === "review") {
|
||||
const sub = args.command[2]; // set | list
|
||||
const month = stringOption(args.options.month);
|
||||
if (!month) {
|
||||
throw new Error("Usage: seal-use report review <set|list> --month <YYYY-MM> [--sn <SN> --verdict <v>] [--corp <corpId>]");
|
||||
}
|
||||
|
||||
if (sub === "list") {
|
||||
const reviews = loadReviews(corp.id, month);
|
||||
const scope = stringOption(args.options.month) ?? stringOption(args.options.scope);
|
||||
const reviews = loadReviews(corp.id, scope);
|
||||
printJson({
|
||||
corpId: corp.id,
|
||||
month,
|
||||
file: reviewFilePath(corp.id, month),
|
||||
...(scope ? { month: scope } : {}),
|
||||
file: reviewFilePath(corp.id, scope),
|
||||
count: reviews.size,
|
||||
reviews: [...reviews.values()]
|
||||
});
|
||||
@@ -159,14 +194,23 @@ export async function handleReportCommand(
|
||||
}
|
||||
|
||||
if (sub === "set") {
|
||||
const sn = stringOption(args.options.sn) ?? stringOption(args.options["document-sn"]);
|
||||
const recordId =
|
||||
stringOption(args.options["record-id"]) ??
|
||||
stringOption(args.options.recordId) ??
|
||||
stringOption(args.options.id);
|
||||
const sn =
|
||||
stringOption(args.options.sn) ??
|
||||
stringOption(args.options["document-sn"]);
|
||||
const verdict = stringOption(args.options.verdict);
|
||||
if (!sn || !verdict) {
|
||||
throw new Error(
|
||||
"Usage: seal-use report review set --month <YYYY-MM> --sn <SN> --verdict <ai_correct|human_correct|both_correct|both_wrong|undecided> [--note <text>] [--reviewed-by <who>] [--corp <corpId>]"
|
||||
const month = stringOption(args.options.month) ?? stringOption(args.options.scope);
|
||||
|
||||
if ((!recordId && !sn) || !verdict) {
|
||||
throw usageError(
|
||||
"Usage: seal-use report review set [--record-id <ID>] [--sn <SN>] --verdict <ai_correct|human_correct|both_correct|both_wrong|undecided> [--note <text>] [--reviewed-by <who>] [--corp <corpId>]"
|
||||
);
|
||||
}
|
||||
const record = writeReview(corp.id, {
|
||||
recordId,
|
||||
sn,
|
||||
month,
|
||||
verdict,
|
||||
@@ -177,8 +221,8 @@ export async function handleReportCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown report review subcommand: ${sub ?? ""}. Use 'set' or 'list'.`);
|
||||
throw usageError(`Unknown report review subcommand: ${sub ?? ""}. Use 'set' or 'list'.`);
|
||||
}
|
||||
|
||||
throw new Error(`Unknown report command: ${action ?? ""}. Run 'seal-use report --help' for available commands.`);
|
||||
throw usageError(`Unknown report command: ${action ?? ""}. Run 'seal-use help report' for available commands.`);
|
||||
}
|
||||
+20
-18
@@ -654,20 +654,22 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
description: "Tenant-free local command: calculates proportions and outputs high-fidelity SVG chart."
|
||||
},
|
||||
{
|
||||
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> [--out <报告.md>] [--template <file>] [--report-id <RPT-...>] [--max-runs <n>] [--allow-unreviewed] [--corp <corpId>]"],
|
||||
name: "generate",
|
||||
aliases: ["monthly", "month"],
|
||||
summary: "Fill the audit report template with performance, risk, and approval-run data",
|
||||
usage: ["seal-use report generate --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD> [--templates <t1,t2...>] [--out <报告.md>] [--template <file>] [--report-id <RPT-...>] [--max-runs <n>] [--allow-unreviewed] [--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 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: "--start-date <YYYY-MM-DD>", description: "Statistics start date, YYYY-MM-DD (e.g. 2026-08-12)" },
|
||||
{ flag: "--end-date <YYYY-MM-DD>", description: "Statistics end date, YYYY-MM-DD (e.g. 2026-09-18)" },
|
||||
{ flag: "--templates <names>", description: "Comma-separated template whitelist; filters blocks and ledger at source" },
|
||||
{ flag: "--template <file>", description: "Custom template Markdown path; defaults to the Git-managed template embedded in the binary" },
|
||||
{ flag: "--out <file>", description: "Save Markdown plus local images and Excel/CSV ledgers beside the report; stdout stays JSON" },
|
||||
{ flag: "--overwrite", description: "Explicitly permit replacing existing output files" },
|
||||
{ flag: "--report-id <RPT-...>", description: "Custom report id; defaults to RPT-<YYYYMM>-<random>" },
|
||||
{ flag: "--report-id <RPT-...>", description: "Custom report id; defaults to RPT-<dateTag>-<random>" },
|
||||
{ flag: "--max-runs <n>", description: "Cap approval-run detail fetch, default 500 (max 500)" },
|
||||
{ flag: "--allow-unreviewed", description: "Bypass pre-flight adjudication gate to generate draft when unreviewed diverged runs exist" }
|
||||
],
|
||||
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."
|
||||
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). Generates both Markdown report and companion Excel/CSV ledger."
|
||||
},
|
||||
{
|
||||
name: "validate",
|
||||
@@ -704,25 +706,25 @@ export const HELP_REGISTRY: AreaHelp[] = [
|
||||
},
|
||||
{
|
||||
name: "review set",
|
||||
summary: "Record one human adjudication (who was right: AI or human) for a document",
|
||||
usage: ["seal-use report review set --month <YYYY-MM> --sn <SN> --verdict <v> [--note <text>] [--reviewed-by <who>] [--corp <corpId>]"],
|
||||
summary: "Record one human adjudication (who was right: AI or human) for an approval run or document",
|
||||
usage: ["seal-use report review set [--record-id <ID>] [--sn <SN>] --verdict <v> [--note <text>] [--reviewed-by <who>] [--corp <corpId>]"],
|
||||
options: [
|
||||
{ flag: "--month <YYYY-MM>", description: "Statistics month, YYYY-MM (required)" },
|
||||
{ flag: "--sn <SN>", description: "Document SN to adjudicate (required)" },
|
||||
{ flag: "--record-id <ID>", description: "Approval run recordId for exact single-run targeting" },
|
||||
{ flag: "--sn <SN>", description: "Document SN to adjudicate" },
|
||||
{ flag: "--verdict <v>", description: "ai_correct | human_correct | both_correct | both_wrong | undecided (required)" },
|
||||
{ flag: "--note <text>", description: "Optional adjudication note" },
|
||||
{ flag: "--reviewed-by <who>", description: "Optional reviewer name for the audit trail" }
|
||||
],
|
||||
description: "Append-only local JSONL per tenant+month (~/.config/seal-use/state/reviews/). Typically adjudicate diverged blocks (AI != human); report monthly joins these to compute human accuracy. No network: writes only the local store."
|
||||
description: "Append-only local JSONL per tenant (~/.config/seal-use/state/reviews/). Supports exact recordId target or SN. Typically adjudicates diverged blocks or overrides specific agreed runs."
|
||||
},
|
||||
{
|
||||
name: "review list",
|
||||
summary: "List human adjudications recorded for a tenant+month",
|
||||
usage: ["seal-use report review list --month <YYYY-MM> [--corp <corpId>]"],
|
||||
summary: "List human adjudications recorded for a tenant",
|
||||
usage: ["seal-use report review list [--corp <corpId>]"],
|
||||
options: [
|
||||
{ flag: "--month <YYYY-MM>", description: "Statistics month, YYYY-MM (required)" }
|
||||
{ flag: "--corp <corpId>", description: "Target enterprise corpId" }
|
||||
],
|
||||
description: "Reads the local JSONL store and returns all adjudications keyed by SN."
|
||||
description: "Reads the local JSONL store and returns all adjudications."
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user