#!/usr/bin/env node // Backfills verified workflows/screenshots from capture reports, writes the gap // ledger, and refreshes coverage-audit.json. Run after captures and before build. import fs from "node:fs"; import path from "node:path"; import { createHash } from "node:crypto"; import { fileURLToPath } from "node:url"; const here = path.dirname(fileURLToPath(import.meta.url)); const webRoot = path.resolve(here, "../.."); const dataDir = path.join(webRoot, "manual", "data"); const features = JSON.parse(fs.readFileSync(path.join(dataDir, "manual-features.json"), "utf8")); const captureDir = path.join(dataDir, "capture"); const verifiedCommands = { ch01: ["Part_Box"], ch02: ["Part_Box", "Part_Cylinder", "Part_Cut", "Part_CheckGeometry"], ch03: ["Sketcher_NewSketch", "Sketcher_CreateRectangle"], ch04: ["PartDesign_Body", "PartDesign_NewSketch", "PartDesign_Pad"], ch05: ["Assembly_CreateAssembly", "Assembly_InsertLink"], ch06: ["Spreadsheet_CreateSheet"], }; const commandIndex = new Map(features.commands.map(item => [`${item.module}:${item.command}`, item])); const sha256 = file => createHash("sha256").update(fs.readFileSync(file)).digest("hex"); const workflows = []; const screenshots = []; for (const name of fs.readdirSync(captureDir).filter(file => file.endsWith(".json")).sort()) { const report = JSON.parse(fs.readFileSync(path.join(captureDir, name), "utf8")); if (!report.ok) continue; const workflowId = `${report.chapter}-${report.workflow}`; const commands = (verifiedCommands[report.chapter] ?? []).filter(command => features.commands.some(item => item.command === command)); for (const shot of report.shots ?? []) { screenshots.push({ id: shot.id, file: shot.file, chapterId: report.chapter, workflowId, bytes: shot.bytes, sha256: shot.sha256, fullPage: shot.fullPage }); } const screenshotId = report.shots?.[0]?.id ?? null; for (const command of commands) { const item = features.commands.find(entry => entry.command === command && entry.chapterId === report.chapter); if (!item) continue; item.status = "verified"; item.workflowId = workflowId; item.screenshotId = screenshotId; } workflows.push({ id: workflowId, chapterId: report.chapter, title: report.workflow, commands, screenshots: (report.shots ?? []).map(shot => shot.id), status: "verified" }); } features.workflows = workflows; features.screenshots = screenshots; features.stats.workflows = workflows.length; features.stats.screenshots = screenshots.length; features.stats.verified = features.commands.filter(item => item.status === "verified").length; const moduleGaps = [ { id: "b-techdraw-worker", module: "TechDraw", title: "TechDraw 跨 Worker 文档桥", detail: "页面 Worker 未持有目标文档,TechDraw_PageDefault 报 Document does not exist;SVG 回退不是 TechDraw 输出。", desktopRefs: ["freecad-source/src/Mod/TechDraw/App/DrawPage.cpp", "freecad-source/src/Mod/TechDraw/App/DrawViewPart.cpp"], status: "boundary", evidence: "web/tools/manual/evidence/ch11" }, { id: "b-fem-native", module: "Fem", title: "FEM 原生结果对象", detail: "FemMeshObject/FemResultObject 未随包发布,结果停留在 Worker;VTK 显示为 three.js 近似。", desktopRefs: ["freecad-source/src/Mod/Fem/App/FemMeshObject.cpp", "web/docs/current/web-freecad-gaps-fem.md"], status: "boundary", evidence: "web/tools/manual/evidence/ch12" }, { id: "b-cam-opencamlib", module: "CAM", title: "CAM OpenCAMLib 路径", detail: "Adaptive/Surface/Waterline 依赖 OpenCAMLib 与完整 ToolBit/G-code 栈,WASM 包未提供。", desktopRefs: ["freecad-source/src/Mod/CAM/App/AppPath.cpp", "web/docs/current/cam-teaching-gap.md"], status: "boundary", evidence: "web/tools/manual/evidence/ch10" }, { id: "b-gltf-native", module: "Import", title: "glTF 原生导入/导出", detail: "OCCT WASM 构建 USE_RAPIDJSON=OFF,RWGltf 无法读写;当前仅 three.js 查看。", desktopRefs: ["freecad-source/src/Mod/Import/App/ReaderGltf.cpp", "freecad-source/src/Mod/Import/App/WriterGltf.cpp"], status: "boundary", evidence: "web/manual/content/ch07-import-export.md" }, { id: "b-cloud-remote", module: "Cloud", title: "Cloud 远程存储", detail: "Save/Restore 需要远程 S3 凭据与服务;本地 OPFS 不受影响。", desktopRefs: ["web/src/cloud.worker.ts"], status: "boundary", evidence: "web/manual/content/ch13-specialists.md" }, { id: "b-material-sparse", module: "Material", title: "Material 原生库兼容", detail: "Material 原生 API 对稀疏数组/单位处理不完整,部分命令为边界。", desktopRefs: ["freecad-source/src/Mod/Material/App/MaterialManager.cpp"], status: "boundary", evidence: "web/docs/current/freecad-official-case-ledger.json" }, { id: "b-bim-no-creation", module: "BIM", title: "BIM 构件创建命令无面板", detail: "BIM 命令停靠区只有 BIM_Nudge_Up / BIM_Unclone / BIM_Ungroup;Arch_Site / Arch_Wall / BIM_Slab 等创建命令一律无任务面板。实测可用的只有 BIM_Views、BIM_Library、BIM_Setup、BIM_Material 四个非创建类命令。", desktopRefs: ["freecad-source/src/Mod/BIM/ArchWall.py", "freecad-source/src/Mod/BIM/ArchSite.py"], status: "boundary", evidence: "web/manual/assets/ch09/bim-workbench", measuredAt: "2026-11-15" }, { id: "b-mesh-frompartshape", module: "Mesh", title: "Mesh_FromPartShape 无面板", detail: "实体转网格的标准入口 Mesh_FromPartShape 在 Web 端没有任务面板。可用替代是 Mesh_BuildRegularSolid,实测返回 nativeOperationCompleted=true、typeId=Mesh::Cube。", desktopRefs: ["freecad-source/src/Mod/Mesh/App/AppMesh.cpp"], status: "boundary", evidence: "web/manual/assets/ch08/mesh-workbench", measuredAt: "2026-11-15" }, { id: "b-draft-needs-viewport", module: "Draft", title: "Draft 图元需要三维视口取点", detail: "Draft_Rectangle 面板填满数值后仍提示 Pick first corner,图元要求先在三维视口取点;工作台壳层页面没有 canvas,取不了点。Draft_Line / Draft_Wire / Draft_Array 连面板都没有。", desktopRefs: ["freecad-source/src/Mod/Draft/draftobjects/rectangle.py"], status: "boundary", evidence: "web/manual/assets/ch13/specialist-tools", measuredAt: "2026-11-15" }, { id: "b-robot-no-model", module: "Robot", title: "Robot 面板未接可驱动机器人", detail: "Robot_CreateRobot 面板六个分组齐全,但 Joint angles 分组固定显示 Home: Not set — use Set Home;点 Set Home 与点动按钮后文本与数值均不变。", desktopRefs: ["freecad-source/src/Mod/Robot/App/RobotObject.cpp"], status: "boundary", evidence: "web/manual/assets/ch13/specialist-tools", measuredAt: "2026-11-15" }, { id: "b-plot-no-canvas", module: "Plot", title: "Plot 面板不渲染画布", detail: "Plot_Axes 面板五个分组齐全,但点 New figure 与 Add axes 后页面既不新增 svg 也不新增 canvas,在 Download SVG 之前没有可视化反馈。", desktopRefs: ["freecad-source/src/Mod/Plot/plot/Plot.py"], status: "boundary", evidence: "web/manual/assets/ch13/specialist-tools", measuredAt: "2026-11-15" }, ]; const gapLedger = { schema: "freecad-web-manual/gaps/v1", generatedAt: new Date().toISOString(), verified: features.commands.filter(item => item.status === "verified").length, fixNeeded: [], boundaries: moduleGaps, notes: [ "草图编辑器已从右侧属性栏移到主舞台(project-shell 的 .stage-sketch-task)," + "命令按宽度自动排成多列,1440 宽窗口下为 3 列;ch03 截图已按新布局重采。", "项目页 Part 文档切换 PartDesign 需要 ownership handoff;教程改用 partdesign.html。", "Mesh/BIM/TechDraw/FEM 模块页显示 boundary/no-worker,教程按模块页实际任务与边界编写。", "两套页面壳不可互换:project.html 能新建 Document 且工作台下拉给 30 个工作台;" + "workbench.html?module=X 对多数模块绑定固定文档 id workbench-document,既不能新建也不能打开文档。", "字段面板能填写并提交但缺父对象文档的失败属前置未满足,不记为产品回归。", ], }; fs.writeFileSync(path.join(dataDir, "manual-features.json"), `${JSON.stringify(features, null, 2)}\n`); fs.writeFileSync(path.join(dataDir, "gap-ledger.json"), `${JSON.stringify(gapLedger, null, 2)}\n`); const coverage = JSON.parse(fs.readFileSync(path.join(dataDir, "coverage-audit.json"), "utf8")); coverage.verified = features.stats.verified; coverage.workflows = features.stats.workflows; coverage.screenshots = features.stats.screenshots; coverage.byStatus = Object.fromEntries(["verified", "detailed", "overview", "boundary"].map(status => [status, features.commands.filter(item => item.status === status).length])); coverage.ok = coverage.unknownModules.length === 0; fs.writeFileSync(path.join(dataDir, "coverage-audit.json"), `${JSON.stringify(coverage, null, 2)}\n`); const lines = [ "# Web FreeCAD 教案缺口台账", "", `生成时间:${gapLedger.generatedAt}`, "", `已验证命令:${gapLedger.verified};待修:${gapLedger.fixNeeded.length};边界:${gapLedger.boundaries.length}`, "", "| 模块 | 边界 | 原因 | 桌面源码入口 |", "|---|---|---|---|", ...moduleGaps.map(gap => `| ${gap.module} | ${gap.title} | ${gap.detail} | ${gap.desktopRefs.join("
")} |`), "", "## 布局/流程说明", "", ...gapLedger.notes.map(note => `- ${note}`), ]; const docDir = path.join(webRoot, "docs", "current"); fs.mkdirSync(docDir, { recursive: true }); fs.writeFileSync(path.join(docDir, "web-freecad-manual-gaps.md"), `${lines.join("\n")}\n`); console.log(JSON.stringify({ ok: true, verified: features.stats.verified, workflows: workflows.length, screenshots: screenshots.length, boundaries: moduleGaps.length }));