Organize reports domain into cohesive submodules

This commit is contained in:
gitea committed 2026-10-12 22:14:25 +08:00
1 parent b3c8e93f0b
commit 87b691bd4e
28 files changed
+92 -70

No files matched your search

+10 -3
View File
@@ -4,9 +4,16 @@ 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 { exportReportPackage, 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 {
exportReportPackage,
renderReportFile,
saveReportMarkdown,
validateReportFile,
loadReviews,
reviewFilePath,
writeReview,
type MonthlyReportResult
} from "../../domains/seal/reports/index.js";
import type { ParsedArgs } from "../types.js";
/** Tenant-free commands: dispatch these before resolving enterprise configuration or authentication. */
+1 -1
View File
@@ -1,6 +1,6 @@
import { z } from "zod";
import type { KyInstance } from "ky";
import { buildMonthlyReport } from "../reports/monthly.js";
import { buildMonthlyReport } from "../reports/index.js";
import type { CapabilityContext } from "./helpers.js";
export const reportCapabilities = [
+35 -35
View File
@@ -4,40 +4,40 @@
---
## 模块分层与文件清单
## 模块分层与目录结构
### 1. 图表生成子模块 (`charts/`)
数据驱动的现代图表生成引擎,100% 纯 TypeScript 计算,支持输出内嵌 SVG 与通过 Headless Chrome 导出 4x 超高分屏/印刷级 PNG:
- [`charts/venn.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/charts/venn.ts):AI 与人工审核准确率对比维恩图(`<clipPath>` 透镜独立着色、严格水平中轴对称、AI 字符微调)。
- [`charts/duration-histogram.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/charts/duration-histogram.ts):多模板单据审核耗时分布对比(自动分箱 Binning、7 系列马卡龙色堆叠直方图、总体平均耗时虚线标注)。
- [`charts/index.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/charts/index.ts):图表模块统一出口。
所有相关文件严格按职责收拢在对应的子目录中,根目录仅保留统一导出入口与本说明文档:
### 2. 模板与静态资源 (`templates/`)
- [`templates/monthly.md`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/templates/monthly.md):标准月度报告 Markdown 模板。
- [`templates/report.css`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/templates/report.css):报告排版与 A4 打印样式表。
- [`templates/assets/`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/templates/assets/):内置图表矢量资产(随二进制静态嵌入)。
- [`templates/examples/`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/templates/examples/):真实企业脱敏报告实例文档。
- [`resources.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/resources.ts):Bun 编译期静态资源嵌入定义。
### 3. 取数与组装流水线 (`collect.ts` / `describe.ts` / `monthly.ts` / `render.ts`)
- [`describe.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/describe.ts):解析 Markdown 章节标题并推断数据需求(数据与排版皮彻底解耦)。
- [`collect.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/collect.ts):根据需求通过 Seal API 抓取单据指标,合并人工复核记录。
- [`render.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/render.ts):将收集到的真实业务数据填入 Markdown 模板。
- [`monthly.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/monthly.ts):月度报告构建顶层调度函数 (`buildMonthlyReport`)。
### 4. 人工审核复核存储 (`review-store.ts`)
- [`review-store.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/review-store.ts):管理本地人工复核判定记录(`~/.config/seal-use/reviews/<corpId>/<month>.jsonl`),计算真实人工准确率基线。
### 5. 文档校验与质检门禁 (`validate.ts`)
- [`validate.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/validate.ts):全方位离线质量校验(信息表完整性、章节序号、表格表头加粗排查、数字统计勾稽、公式算术自洽、图片链接有效性)。
### 6. 文件系统与导出收拢 (`files.ts`)
- [`files.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/files.ts):
- `saveReportMarkdown`:导出 Markdown 并将本地配图拷贝至伴生专属目录 `<报告名>.md.assets/`。
- `renderReportFile`:调度 HTML/PNG/PDF 渲染。
- `exportReportPackage`:**整包收纳导出器**,在目标目录(如 `~/Downloads/赢家时尚-202608/`)下单层整齐打包全部交付物(MD、.md.assets、HTML、PDF),杜绝目录污染。
### 7. 渲染与排版底层 (`html.ts` / `browser.ts` / `png.ts`)
- [`html.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/html.ts):Markdown 转 HTML,将所有本地图片(PNG/SVG)与 KaTeX 字体无损转为 Base64 Data URI,编译为 100% 独立的单文件网页。
- [`browser.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/browser.ts):跨平台自动发现 Chromium/Chrome/Edge 内核,驱动 `--headless` 截图超采样与 A4 打印。
- [`png.ts`](file:///Users/yingqing/Code/seal-use/src/domains/seal/reports/png.ts):超长报告的多分带分块拼接,避免单次超大画布内存溢出。
```
src/domains/seal/reports/
├── charts/ # 图表生成子模块(100% 纯 TS 数据驱动矢量计算)
│ ├── venn.ts # 图 1:AI 与人工审核准确率对比维恩图
│ ├── duration-histogram.ts # 图 2:多模板单据审核耗时分布对比堆叠直方图
│ └── index.ts # 图表模块出口
├── pipeline/ # 取数、推断与组装流水线
│ ├── describe.ts # 解析 Markdown 标题并反推各章节数据需求
│ ├── collect.ts # 通过 Seal API 抓取单据指标,合并人工复核记录
│ ├── render.ts # 模板占位填充与章节内容排版
│ ├── monthly.ts # 月度报告顶层调度器 (buildMonthlyReport)
│ ├── review-store.ts # 人工复核判定本地存储(JSONL 租户分片)
│ └── index.ts # 流水线出口
├── render/ # 渲染与排版引擎底层
│ ├── html.ts # Markdown 转自包含 HTML(资源内嵌 Data URI)
│ ├── browser.ts # 跨平台 Headless Chrome 驱动(PDF 打印与长图截取)
│ ├── png.ts # 多分带分块拼接与超大图流式生成
│ └── index.ts # 渲染引擎出口
├── validate/ # 离线质量校验与勾稽门禁
│ ├── validate.ts # 信息表完整性、章节序号、表格格式、公式算术核验
│ └── index.ts # 校验门禁出口
├── export/ # 文件系统整包导出与资产收拢
│ ├── files.ts # 报告整包打包器 (exportReportPackage) 及文件保存
│ └── index.ts # 导出器出口
├── templates/ # 模板与静态资源
│ ├── monthly.md # 标准月度报告 Markdown 模板
│ ├── report.css # 报告排版与 A4 打印样式表
│ ├── resources.ts # Bun 编译期静态资源嵌入定义
│ ├── assets/ # 内置图表矢量资产
│ └── examples/ # 真实脱敏报告示例
├── index.ts # 报告域对外统一门面出口 (Barrel)
└── README.md # 架构与开发指南
```
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { renderDurationHistogramPng, renderDurationHistogramSvg, DEFAULT_EEKA_DURATION_SERIES } from "./duration-histogram.js";
import { pngDimensions } from "../png.js";
import { pngDimensions } from "../render/png.js";
import { writeFileSync, unlinkSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
@@ -1,4 +1,4 @@
import { renderHtmlToImageBuffer } from "../browser.js";
import { renderHtmlToImageBuffer } from "../render/browser.js";
export interface HistogramSeries {
name: string;
+1 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { renderVennAccuracyPng, renderVennAccuracySvg } from "./venn.js";
import { pngDimensions } from "../png.js";
import { pngDimensions } from "../render/png.js";
import { writeFileSync, unlinkSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
+1 -1
View File
@@ -1,4 +1,4 @@
import { renderHtmlToImageBuffer } from "../browser.js";
import { renderHtmlToImageBuffer } from "../render/browser.js";
export interface VennAccuracyOptions {
aiAccuracy: number;
@@ -3,10 +3,10 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
import { tmpdir } from "node:os";
import { join } from "node:path";
import { PNG } from "pngjs";
import { runCli } from "../../../cli/runner.js";
import { buildMonthlyReport } from "./monthly.js";
import { runCli } from "../../../../cli/runner.js";
import { buildMonthlyReport } from "../pipeline/index.js";
import { renderReportFile, saveReportMarkdown, validateReportFile } from "./files.js";
import { BUILTIN_MONTHLY_TEMPLATE, BUILTIN_TEMPLATE_PATH } from "./resources.js";
import { BUILTIN_MONTHLY_TEMPLATE, BUILTIN_TEMPLATE_PATH } from "../templates/resources.js";
const dirs: string[] = [];
const originalCwd = process.cwd();
@@ -1,13 +1,12 @@
import { constants, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os"
import { basename, dirname, extname, join, resolve } from "node:path"
import { CliError, usageError, validationError } from "../../../core/errors.js"
import { BUILTIN_TEMPLATE_PATH, REPORT_ASSETS } from "./resources.js"
import { validateReportDocument, type ReportValidation } from "./validate.js"
import { buildReportHtml } from "./html.js"
import { findReportChrome, renderBrowserArtifacts, renderHtmlToImageBuffer } from "./browser.js"
import { CliError, usageError, validationError } from "../../../../core/errors.js"
import { BUILTIN_TEMPLATE_PATH, REPORT_ASSETS } from "../templates/resources.js"
import { validateReportDocument, type ReportValidation } from "../validate/index.js"
import { buildReportHtml, findReportChrome, renderBrowserArtifacts, renderHtmlToImageBuffer } from "../render/index.js"
export type { ReportValidation } from "./validate.js"
export type { ReportValidation } from "../validate/index.js"
export type ReportRenderOptions = {
out: string;
format?: string;
+1
View File
@@ -0,0 +1 @@
export * from "./files.js";
+6
View File
@@ -0,0 +1,6 @@
export * from "./charts/index.js";
export * from "./pipeline/index.js";
export * from "./render/index.js";
export * from "./validate/index.js";
export * from "./export/index.js";
export * from "./templates/resources.js";
@@ -1,7 +1,7 @@
import type { KyInstance } from "ky";
import * as api from "../api.js";
import { formatBeijingIso } from "../../../core/config/timestamps.js";
import type { ApprovalRun } from "../types.js";
import * as api from "../../api.js";
import { formatBeijingIso } from "../../../../core/config/timestamps.js";
import type { ApprovalRun } from "../../types.js";
import type { ReportDemand } from "./describe.js";
import { loadReviews, type ReviewRecord } from "./review-store.js";
@@ -0,0 +1,5 @@
export * from "./describe.js";
export * from "./collect.js";
export * from "./render.js";
export * from "./monthly.js";
export * from "./review-store.js";
@@ -2,8 +2,8 @@ import type { KyInstance } from "ky";
import { existsSync, readFileSync } from "node:fs";
import { randomBytes } from "node:crypto";
import { resolve } from "node:path";
import { validationError } from "../../../core/errors.js";
import { BUILTIN_MONTHLY_TEMPLATE, BUILTIN_TEMPLATE_PATH } from "./resources.js";
import { validationError } from "../../../../core/errors.js";
import { BUILTIN_MONTHLY_TEMPLATE, BUILTIN_TEMPLATE_PATH } from "../templates/resources.js";
import { describeTemplate } from "./describe.js";
import { collectReportData, type ReportData } from "./collect.js";
import { renderMonthlyReport, type RenderOptions } from "./render.js";
@@ -1,4 +1,4 @@
import { formatBeijingIso } from "../../../core/config/timestamps.js";
import { formatBeijingIso } from "../../../../core/config/timestamps.js";
import type { ReportData, ReportBlock } from "./collect.js";
import type { SectionPlan } from "./describe.js";
@@ -7,7 +7,7 @@ import { collectReportData, type ReportData } from "./collect.js";
import { renderMonthlyReport } from "./render.js";
import { loadReviews, writeReview, reviewFilePath } from "./review-store.js";
const TEMPLATE = join(import.meta.dirname, "templates", "monthly.md");
const TEMPLATE = join(import.meta.dirname, "..", "templates", "monthly.md");
function sampleData(overrides: Partial<ReportData> = {}): ReportData {
return {
@@ -1,6 +1,6 @@
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { validationError } from "../../../core/errors.js";
import { validationError } from "../../../../core/errors.js";
/**
* 人工裁决的本地持久化(JSONL,按 租户 × 月份 分片)。
@@ -43,7 +43,7 @@ const VERDICTS: ReadonlySet<string> = new Set([
"undecided"
]);
import { SEAL_STATE_DIR } from "../../../core/paths.js";
import { SEAL_STATE_DIR } from "../../../../core/paths.js";
const REVIEWS_DIR_ENV = "SEAL_USE_REVIEWS_DIR";
@@ -3,7 +3,7 @@ import { accessSync, constants, existsSync, mkdirSync, mkdtempSync, readdirSync,
import { homedir, tmpdir } from "node:os"
import { dirname, join } from "node:path"
import { pathToFileURL } from "node:url"
import { CliError, validationError } from "../../../core/errors.js"
import { CliError, validationError } from "../../../../core/errors.js"
import { pngDimensions, stitchPngBands, type PngBand } from "./png.js"
export const PNG_BAND_HEIGHT = 14_000
@@ -3,8 +3,8 @@ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writ
import { homedir } from "node:os"
import { basename, dirname, extname, join, resolve } from "node:path"
import { Marked, type TokenizerExtension, type Tokens } from "marked"
import { CliError } from "../../../core/errors.js"
import { REPORT_CSS } from "./resources.js"
import { CliError } from "../../../../core/errors.js"
import { REPORT_CSS } from "../templates/resources.js"
const katexBase = "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/"
const mimeTypes: Record<string, string> = {
+3
View File
@@ -0,0 +1,3 @@
export * from "./browser.js";
export * from "./html.js";
export * from "./png.js";
@@ -1,6 +1,6 @@
import { closeSync, openSync, readFileSync, readSync, writeFileSync } from "node:fs"
import { PNG } from "pngjs"
import { CliError } from "../../../core/errors.js"
import { CliError } from "../../../../core/errors.js"
export type PngBand = { file: string; height: number }
@@ -1,8 +1,8 @@
import monthly from "./templates/monthly.md" with { type: "text" };
import css from "./templates/report.css" with { type: "text" };
import accuracy from "./templates/assets/图1-准确率对比.svg" with { type: "text" };
import benefits from "./templates/assets/图2-综合效益.svg" with { type: "text" };
import screenshot from "./templates/assets/图3-示例截图.svg" with { type: "text" };
import monthly from "./monthly.md" with { type: "text" };
import css from "./report.css" with { type: "text" };
import accuracy from "./assets/图1-准确率对比.svg" with { type: "text" };
import benefits from "./assets/图2-综合效益.svg" with { type: "text" };
import screenshot from "./assets/图3-示例截图.svg" with { type: "text" };
// Git owns the source files; Bun embeds these imports in both developer and release binaries.
// Loading the built-in template never depends on cwd, a checkout, or skill installation.
@@ -0,0 +1 @@
export * from "./validate.js";