Add report ledger workflow, refine terminology and codify skill discipline
This commit is contained in:
1 parent
077ecb050c
commit
c6bd113fff
21 files changed
+1393
-377
No files matched your search
+116
-9
@@ -16,12 +16,29 @@ import {
|
||||
loadReviews,
|
||||
reviewFilePath,
|
||||
writeReview,
|
||||
type MonthlyReportResult
|
||||
type MonthlyReportResult,
|
||||
buildReportLedgerCsv,
|
||||
buildReportLedgerXlsx,
|
||||
loadReportDataFromLedger,
|
||||
collectReportData,
|
||||
type ReportData
|
||||
} from "../../domains/seal/reports/index.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" | "export" | "template" | "chart", args: ParsedArgs) {
|
||||
export async function handleLocalReportCommand(action: string | undefined, args: ParsedArgs) {
|
||||
if (Boolean(args.options.ledger) || action === "review") {
|
||||
const corpId = stringOption(args.options.corp) ?? stringOption(args.options.corpId) ?? "local-ledger";
|
||||
const corp = {
|
||||
corpId,
|
||||
id: corpId,
|
||||
name: corpId,
|
||||
corpName: corpId,
|
||||
source: { source: "seal", sealUrl: "" }
|
||||
} as unknown as CorpConfig;
|
||||
await handleReportCommand(action, {} as any, corp, args);
|
||||
return;
|
||||
}
|
||||
if (action === "template") {
|
||||
const out = stringOption(args.options.out) ?? stringOption(args.options.o);
|
||||
if (out) {
|
||||
@@ -78,14 +95,83 @@ export async function handleLocalReportCommand(action: "validate" | "render" | "
|
||||
if (!result.validation.valid) throw new CliError("报告校验未通过,未生成渲染产物。请按 validation.issues 修正后重试。", 1);
|
||||
}
|
||||
|
||||
/** `seal-use report generate` / `data` — AI 审核报告。 */
|
||||
/** `seal-use report generate` / `ledger` / `data` — AI 审核报告。 */
|
||||
export async function handleReportCommand(
|
||||
action: string | undefined,
|
||||
client: Awaited<ReturnType<typeof createSealClient>>,
|
||||
corp: CorpConfig,
|
||||
args: ParsedArgs
|
||||
) {
|
||||
if (action === "ledger") {
|
||||
const ledgerPath = stringOption(args.options.ledger);
|
||||
const out = stringOption(args.options.out) ?? stringOption(args.options.o);
|
||||
const format = (stringOption(args.options.format) ?? (out?.endsWith(".csv") ? "csv" : "xlsx")).toLowerCase();
|
||||
|
||||
let data: ReportData;
|
||||
if (ledgerPath) {
|
||||
data = await loadReportDataFromLedger(ledgerPath, { corp: { id: corp.id, name: corp.name } });
|
||||
} else {
|
||||
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 ((!startDate || !endDate) && !month) {
|
||||
throw usageError(
|
||||
"Usage: seal-use report ledger --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD> [--templates <t1,t2...>] [--max-runs <n>] [--out <file.xlsx|csv>] [--corp <corpId>]"
|
||||
);
|
||||
}
|
||||
|
||||
const templates = stringOption(args.options.templates)?.split(/[,;]+/).map((s) => s.trim()).filter(Boolean);
|
||||
data = await collectReportData(client, new Set(["blocks", "templateGroups", "performance"]), {
|
||||
startDate,
|
||||
endDate,
|
||||
month,
|
||||
corp: { id: corp.id, name: corp.name },
|
||||
templates,
|
||||
maxRuns: numberOption(args.options["max-runs"]) ?? numberOption(args.options.maxRuns)
|
||||
});
|
||||
}
|
||||
|
||||
const outFile = out ?? `台账-${corp.id}-${(data.period.label ?? data.period.start).replace(/[^0-9A-Za-z_-]/g, "_")}.${format === "csv" ? "csv" : "xlsx"}`;
|
||||
const targetPath = resolve(outFile);
|
||||
if (format === "csv") {
|
||||
const csvContent = buildReportLedgerCsv(data);
|
||||
writeFileSync(targetPath, csvContent, "utf8");
|
||||
} else {
|
||||
const xlsxBuffer = await buildReportLedgerXlsx(data);
|
||||
writeFileSync(targetPath, xlsxBuffer);
|
||||
}
|
||||
|
||||
const divergedCount = data.blocks.filter((b) => b.agreement === "diverged").length;
|
||||
const unreviewedDiverged = data.blocks.filter((b) => b.agreement === "diverged" && !b.verdict).length;
|
||||
|
||||
printJson({
|
||||
file: targetPath,
|
||||
format: format === "csv" ? "csv" : "xlsx",
|
||||
corpId: corp.id,
|
||||
period: data.period,
|
||||
totalBlocks: data.blocks.length,
|
||||
templates: [...new Set(data.blocks.map((b) => b.template))],
|
||||
divergedCount,
|
||||
unreviewedDiverged,
|
||||
next: {
|
||||
reviewTip: "可在 Excel 中直接编辑'复核定性裁决'列(填写:AI判断正确 / 人工判断错误,或人工判断正确 / AI判定误判),也可直接剔除不需要的模板行",
|
||||
generate: `seal-use report generate --ledger '${targetPath}' --corp ${corp.id} --out reports/报告.md`
|
||||
}
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "data") {
|
||||
const ledgerPath = stringOption(args.options.ledger);
|
||||
const startDate =
|
||||
stringOption(args.options["start-date"]) ??
|
||||
stringOption(args.options.startDate) ??
|
||||
@@ -98,9 +184,9 @@ export async function handleReportCommand(
|
||||
stringOption(args.options.until);
|
||||
const month = stringOption(args.options.month);
|
||||
|
||||
if ((!startDate || !endDate) && !month) {
|
||||
if (!ledgerPath && (!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>]"
|
||||
"Usage: seal-use report data (--ledger <台账.xlsx> | --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD>) [--templates <t1,t2...>] [--max-runs <n>] [--corp <corpId>]"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -115,6 +201,7 @@ export async function handleReportCommand(
|
||||
endDate,
|
||||
month,
|
||||
templates,
|
||||
ledgerPath,
|
||||
maxRuns: numberOption(args.options["max-runs"]) ?? numberOption(args.options.maxRuns)
|
||||
}
|
||||
);
|
||||
@@ -123,6 +210,7 @@ export async function handleReportCommand(
|
||||
}
|
||||
|
||||
if (action === "monthly" || action === "month" || action === "generate") {
|
||||
const ledgerPath = stringOption(args.options.ledger);
|
||||
const startDate =
|
||||
stringOption(args.options["start-date"]) ??
|
||||
stringOption(args.options.startDate) ??
|
||||
@@ -135,9 +223,9 @@ export async function handleReportCommand(
|
||||
stringOption(args.options.until);
|
||||
const month = stringOption(args.options.month);
|
||||
|
||||
if ((!startDate || !endDate) && !month) {
|
||||
if (!ledgerPath && (!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>]"
|
||||
"Usage: seal-use report generate (--ledger <台账.xlsx> | --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD>) [--templates <t1,t2...>] [--template <file>] [--report-id <RPT-...>] [--corp <corpId>]"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,6 +240,7 @@ export async function handleReportCommand(
|
||||
endDate,
|
||||
month,
|
||||
templates,
|
||||
ledgerPath,
|
||||
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),
|
||||
@@ -178,7 +267,7 @@ export async function handleReportCommand(
|
||||
}
|
||||
|
||||
if (action === "review") {
|
||||
const sub = args.command[2]; // set | list
|
||||
const sub = args.command[2]; // set | list | import
|
||||
|
||||
if (sub === "list") {
|
||||
const scope = stringOption(args.options.month) ?? stringOption(args.options.scope);
|
||||
@@ -193,6 +282,24 @@ export async function handleReportCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
if (sub === "import") {
|
||||
const file = args.command[3] ?? stringOption(args.options.file) ?? stringOption(args.options.ledger);
|
||||
if (!file) throw usageError("Usage: seal-use report review import <台账.xlsx|csv> --corp <corpId>");
|
||||
const ledgerData = await loadReportDataFromLedger(file, { corp: { id: corp.id, name: corp.name } });
|
||||
let imported = 0;
|
||||
for (const rev of ledgerData.reviews.values()) {
|
||||
writeReview(corp.id, rev);
|
||||
imported++;
|
||||
}
|
||||
printJson({
|
||||
corpId: corp.id,
|
||||
file: resolve(file),
|
||||
importedCount: imported,
|
||||
totalBlocks: ledgerData.blocks.length
|
||||
}, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
if (sub === "set") {
|
||||
const recordId =
|
||||
stringOption(args.options["record-id"]) ??
|
||||
@@ -221,7 +328,7 @@ export async function handleReportCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
throw usageError(`Unknown report review subcommand: ${sub ?? ""}. Use 'set' or 'list'.`);
|
||||
throw usageError(`Unknown report review subcommand: ${sub ?? ""}. Use 'set', 'list', or 'import'.`);
|
||||
}
|
||||
|
||||
throw usageError(`Unknown report command: ${action ?? ""}. Run 'seal-use help report' for available commands.`);
|
||||
|
||||
Reference in new issue
Block a user