audit-e2w 0.0.0-stage → 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/cordis.patch.yml +3 -0
  4. package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
  5. package/dsh_plugins/audit-e2w/lib/index.js +114 -0
  6. package/dsh_plugins/audit-e2w/lib/skill.js +41 -0
  7. package/excel_word/README.md +380 -0
  8. package/excel_word/qoder_engine.py +438 -0
  9. package/excel_word/requirements.txt +4 -0
  10. package/excel_word/wesync/__init__.py +19 -0
  11. package/excel_word/wesync/__main__.py +6 -0
  12. package/excel_word/wesync/align.py +154 -0
  13. package/excel_word/wesync/api.py +840 -0
  14. package/excel_word/wesync/backup_history.py +65 -0
  15. package/excel_word/wesync/changelog.py +58 -0
  16. package/excel_word/wesync/cli.py +173 -0
  17. package/excel_word/wesync/commands/__init__.py +8 -0
  18. package/excel_word/wesync/commands/blank_cmd.py +250 -0
  19. package/excel_word/wesync/commands/bookmark_cmd.py +115 -0
  20. package/excel_word/wesync/commands/clear_cmd.py +48 -0
  21. package/excel_word/wesync/commands/export_cmd.py +220 -0
  22. package/excel_word/wesync/commands/marks_cmd.py +152 -0
  23. package/excel_word/wesync/commands/placeholders_cmd.py +87 -0
  24. package/excel_word/wesync/commands/writeback_cmd.py +513 -0
  25. package/excel_word/wesync/config.py +96 -0
  26. package/excel_word/wesync/console.py +78 -0
  27. package/excel_word/wesync/docx_blank.py +156 -0
  28. package/excel_word/wesync/docx_bookmarks.py +287 -0
  29. package/excel_word/wesync/docx_columns.py +257 -0
  30. package/excel_word/wesync/docx_edit.py +77 -0
  31. package/excel_word/wesync/docx_grid.py +212 -0
  32. package/excel_word/wesync/docx_marks.py +291 -0
  33. package/excel_word/wesync/docx_meta.py +157 -0
  34. package/excel_word/wesync/docx_newtable.py +220 -0
  35. package/excel_word/wesync/docx_placeholders.py +161 -0
  36. package/excel_word/wesync/docx_rows.py +67 -0
  37. package/excel_word/wesync/errors.py +5 -0
  38. package/excel_word/wesync/excel_blocks.py +543 -0
  39. package/excel_word/wesync/excel_export.py +136 -0
  40. package/excel_word/wesync/excel_marks.py +193 -0
  41. package/excel_word/wesync/excel_totals.py +53 -0
  42. package/excel_word/wesync/fsops.py +214 -0
  43. package/excel_word/wesync/gui/__init__.py +34 -0
  44. package/excel_word/wesync/gui/__main__.py +6 -0
  45. package/excel_word/wesync/gui/app.py +399 -0
  46. package/excel_word/wesync/gui/manual.py +68 -0
  47. package/excel_word/wesync/gui/pages/__init__.py +31 -0
  48. package/excel_word/wesync/gui/pages/_page.py +89 -0
  49. package/excel_word/wesync/gui/pages/batch_page.py +423 -0
  50. package/excel_word/wesync/gui/pages/blank_page.py +465 -0
  51. package/excel_word/wesync/gui/pages/bookmark_page.py +37 -0
  52. package/excel_word/wesync/gui/pages/export_page.py +88 -0
  53. package/excel_word/wesync/gui/pages/format_page.py +429 -0
  54. package/excel_word/wesync/gui/pages/help_page.py +92 -0
  55. package/excel_word/wesync/gui/pages/history_page.py +145 -0
  56. package/excel_word/wesync/gui/pages/marks_page.py +178 -0
  57. package/excel_word/wesync/gui/pages/writeback_page.py +452 -0
  58. package/excel_word/wesync/gui/resources.py +22 -0
  59. package/excel_word/wesync/gui/runner.py +74 -0
  60. package/excel_word/wesync/gui/store.py +34 -0
  61. package/excel_word/wesync/gui/theme.py +100 -0
  62. package/excel_word/wesync/gui/widgets/__init__.py +8 -0
  63. package/excel_word/wesync/gui/widgets/cards.py +20 -0
  64. package/excel_word/wesync/gui/widgets/filebar.py +58 -0
  65. package/excel_word/wesync/gui/widgets/logpane.py +110 -0
  66. package/excel_word/wesync/gui/widgets/nav.py +39 -0
  67. package/excel_word/wesync/report_format.py +1577 -0
  68. package/excel_word/wesync/sort_rules.py +244 -0
  69. package/excel_word/wesync/valuefmt.py +462 -0
  70. package/package.json +49 -4
  71. package/qoder_plugins/audit-toolbox/README.md +156 -0
  72. package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
@@ -0,0 +1,265 @@
1
+ import path from "node:path"
2
+
3
+ export const emptySchema = { type: "object", properties: {}, additionalProperties: false }
4
+
5
+ export const queryOperations = ["blank-scan", "deleted-list", "blank-batch-scan", "diff", "table-list", "sort-list", "template-scan", "backup-list", "format-scan", "format-heading-candidates"]
6
+ export const runOperations = ["export", "writeback", "bookmark", "rejudge", "clear-bookmarks", "marks", "marks-sync", "placeholders", "placeholders-sync", "blank-delete", "restore-tables", "blank-batch-delete", "diff-export", "append-table", "sort-set", "sort-clear", "batch-writeback", "template-batch", "fill-placeholders", "backup-restore", "format-apply"]
7
+ export const pathProperties = {
8
+ docx: { type: "string", description: "Word 文件绝对路径(.docx/.docm)" },
9
+ excel: { type: "string", description: "Excel 工作簿绝对路径(.xlsx/.xlsm);留空使用默认同名工作簿" },
10
+ paths: { type: "array", items: { type: "string" }, maxItems: 200, description: "批量处理的绝对路径清单" },
11
+ templates: { type: "array", items: { type: "string" }, maxItems: 200, description: "Word 模板绝对路径清单" },
12
+ items: {
13
+ type: "array",
14
+ maxItems: 200,
15
+ description: "批量任务清单;模板生成使用 excel/template,批量删表使用 docx/pick/keepCaptionFor/reversible/excel",
16
+ items: { type: "object" },
17
+ },
18
+ outDir: { type: "string", description: "输出目录绝对路径" },
19
+ backupPath: { type: "string", description: "历史备份文件绝对路径" },
20
+ target: { type: "string", description: "恢复目标文件绝对路径" },
21
+ template: { type: "string", description: "格式样板 Word 绝对路径;与 profileName 二选一" },
22
+ profileName: { type: "string", description: "已保存的纯格式方案名称;与 template 二选一" },
23
+ output: { type: "string", description: "格式调整结果的新 Word 文件绝对路径,不得覆盖原报告" },
24
+ }
25
+ export const formatProperties = {
26
+ template: pathProperties.template,
27
+ profileName: pathProperties.profileName,
28
+ output: pathProperties.output,
29
+ scope: {
30
+ type: "object",
31
+ description: "七项调整范围;提供时必须完整包含七项且至少开启一项",
32
+ properties: Object.fromEntries(["cover", "headings", "statement", "body", "table_text", "table_emphasis", "table_borders"].map(key => [key, { type: "boolean" }])),
33
+ required: ["cover", "headings", "statement", "body", "table_text", "table_emphasis", "table_borders"],
34
+ additionalProperties: false,
35
+ },
36
+ headingBatchId: { type: "string", description: "format-heading-candidates 返回的当前候选批次编号" },
37
+ headingLevels: {
38
+ type: "object",
39
+ maxProperties: 300,
40
+ description: "用户确认的候选编号到 1~4 级标题映射;未确认的候选不要列入",
41
+ additionalProperties: { type: "integer", minimum: 1, maximum: 4 },
42
+ },
43
+ roleBatchId: { type: "string", description: "format-heading-candidates 返回的当前角色/边界批次编号" },
44
+ roleOverrides: {
45
+ type: "object",
46
+ maxProperties: 300,
47
+ description: "用户确认的疑难段落编号到 body/table_title 映射;只放已确认项",
48
+ additionalProperties: { type: "string", enum: ["body", "table_title"] },
49
+ },
50
+ regionStartId: { type: "string", description: "用户确认的附注起始边界候选编号;必须与 roleBatchId 同时提供" },
51
+ }
52
+ export const runProperties = {
53
+ ...pathProperties,
54
+ dryRun: { type: "boolean", description: "仅预演,不写文件;Agent 处理写盘任务时应先传 true,用户确认后传 false" },
55
+ force: { type: "boolean", description: "跳过文件占用检查;仅在用户明确同意时使用" },
56
+ backup: { type: "boolean", description: "覆盖前备份到 _backup;Agent 处理写盘任务时建议保持 true" },
57
+ noBackup: { type: "boolean", description: "兼容旧参数:覆盖前不备份" },
58
+ withExcelLinks: { type: "boolean", description: "Excel 中写入定位 Word 链接" },
59
+ totalsFormula: { type: "boolean", description: "合计行写 SUM 公式" },
60
+ contents: {
61
+ type: "object",
62
+ properties: {
63
+ tables: { type: "boolean" },
64
+ marks: { type: "boolean" },
65
+ placeholders: { type: "boolean" },
66
+ keepHighlight: { type: "boolean" },
67
+ },
68
+ additionalProperties: false,
69
+ },
70
+ keepHighlight: { type: "boolean", description: "同步标注后保留高亮" },
71
+ deleteEmptyRows: { type: "boolean", description: "删除 B 列标记为✕的行" },
72
+ changelog: { type: "boolean", description: "导出差量改动清单" },
73
+ pick: { type: "string", description: "候选/恢复编号,逗号分隔或 all" },
74
+ keepCaption: { type: "boolean", description: "只删表格并保留标题" },
75
+ keepCaptionFor: { type: "string", description: "保留标题的候选编号" },
76
+ reversible: { type: "boolean", description: "可逆删除并保留 Excel 表块" },
77
+ name: { type: "string", description: "新表名称" },
78
+ nrows: { type: "integer", minimum: 1, maximum: 200 },
79
+ ncols: { type: "integer", minimum: 1, maximum: 30 },
80
+ after: { type: "string", description: "在指定表块后插入" },
81
+ code: { type: "string", description: "表块编号" },
82
+ column: { type: "string", description: "排序依据的列名" },
83
+ descending: { type: "boolean", description: "降序;false 为升序" },
84
+ confirmed: { type: "boolean", description: "format-apply 正式写盘前必须为 true,表示用户已确认预演范围、标题级别、疑难角色和边界" },
85
+ }
86
+ export const operationSpecs = {
87
+ "blank-scan": { title: "扫描空白表", tool: "audit_query", required: ["docx"], optional: ["docx"], defaults: {}, dryRun: false, writes: false, example: { operation: "blank-scan", docx: "D:\\审计项目\\报告.docx" } },
88
+ "deleted-list": { title: "查看可恢复表格", tool: "audit_query", required: ["docx"], optional: ["docx", "excel"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: false, example: { operation: "deleted-list", docx: "D:\\审计项目\\报告.docx", excel: "D:\\审计项目\\报告_表格数据.xlsx" } },
89
+ "blank-batch-scan": { title: "批量扫描空白表", tool: "audit_query", required: ["paths"], optional: ["paths"], defaults: {}, dryRun: false, writes: false, example: { operation: "blank-batch-scan", paths: ["D:\\审计项目\\报告一.docx", "D:\\审计项目\\报告二.docx"] } },
90
+ diff: { title: "差异比对", tool: "audit_query", required: ["docx"], optional: ["docx", "excel"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: false, example: { operation: "diff", docx: "D:\\审计项目\\报告.docx", excel: "D:\\审计项目\\报告_表格数据.xlsx" } },
91
+ "table-list": { title: "查看工作簿表块", tool: "audit_query", required: ["docx"], optional: ["docx", "excel"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: false, example: { operation: "table-list", docx: "D:\\审计项目\\报告.docx", excel: "D:\\审计项目\\报告_表格数据.xlsx" } },
92
+ "sort-list": { title: "查看排序设置", tool: "audit_query", required: ["docx"], optional: ["docx", "excel"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: false, example: { operation: "sort-list", docx: "D:\\审计项目\\报告.docx", excel: "D:\\审计项目\\报告_表格数据.xlsx" } },
93
+ "template-scan": { title: "检查模板字段", tool: "audit_query", required: ["docx"], optional: ["docx"], defaults: {}, dryRun: false, writes: false, example: { operation: "template-scan", docx: "D:\\审计项目\\模板.docx" } },
94
+ "backup-list": { title: "查看历史备份", tool: "audit_query", required: ["docx"], optional: ["docx", "excel"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: false, example: { operation: "backup-list", docx: "D:\\审计项目\\报告.docx", excel: "D:\\审计项目\\报告_表格数据.xlsx" } },
95
+ "format-scan": { title: "格式调整预演", tool: "audit_query", required: ["docx"], optional: ["docx", "template", "profileName", "scope", "headingBatchId", "headingLevels", "roleBatchId", "roleOverrides", "regionStartId"], defaults: {}, dryRun: false, writes: false, agentOnly: true, example: { operation: "format-scan", docx: "D:\\审计项目\\报告.docx", template: "D:\\审计项目\\样板.docx" } },
96
+ "format-heading-candidates": { title: "筛选候选标题与疑难角色", tool: "audit_query", required: ["docx"], optional: ["docx"], defaults: {}, dryRun: false, writes: false, agentOnly: true, example: { operation: "format-heading-candidates", docx: "D:\\审计项目\\报告.docx" } },
97
+ export: { title: "创建 Excel", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force", "backup", "noBackup", "withExcelLinks", "totalsFormula"], defaults: { excel: "同名_表格数据.xlsx", withExcelLinks: true, totalsFormula: true, backup: true, force: false }, dryRun: true, writes: true, example: { operation: "export", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
98
+ writeback: { title: "同步到 Word", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force", "backup", "noBackup", "contents", "deleteEmptyRows", "changelog"], defaults: { excel: "同名_表格数据.xlsx", contents: { tables: true, marks: false, placeholders: false }, backup: true, force: false }, dryRun: true, writes: true, example: { operation: "writeback", docx: "D:\\审计项目\\报告.docx", excel: "D:\\审计项目\\报告_表格数据.xlsx", contents: { tables: true }, dryRun: true } },
99
+ bookmark: { title: "重建或迁移书签", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force", "withExcelLinks"], defaults: { excel: "同名_表格数据.xlsx", withExcelLinks: true, force: false }, dryRun: true, writes: true, example: { operation: "bookmark", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
100
+ rejudge: { title: "重新判定标记", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force", "backup", "noBackup"], defaults: { excel: "同名_表格数据.xlsx", backup: true, force: false }, dryRun: true, writes: true, example: { operation: "rejudge", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
101
+ "clear-bookmarks": { title: "清理 Word 书签", tool: "audit_run", required: ["docx"], optional: ["docx", "dryRun", "force"], defaults: { force: false }, dryRun: true, writes: true, example: { operation: "clear-bookmarks", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
102
+ marks: { title: "导出或刷新标注", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force"], defaults: { excel: "同名_表格数据.xlsx", force: false }, dryRun: true, writes: true, example: { operation: "marks", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
103
+ "marks-sync": { title: "同步标注到 Word", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force", "keepHighlight"], defaults: { excel: "同名_表格数据.xlsx", keepHighlight: false, force: false }, dryRun: true, writes: true, example: { operation: "marks-sync", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
104
+ placeholders: { title: "补齐占位符工作表", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force"], defaults: { excel: "同名_表格数据.xlsx", force: false }, dryRun: true, writes: true, example: { operation: "placeholders", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
105
+ "placeholders-sync": { title: "同步占位符到 Word", tool: "audit_run", required: ["docx"], optional: ["docx", "excel", "dryRun", "force"], defaults: { excel: "同名_表格数据.xlsx", force: false }, dryRun: true, writes: true, example: { operation: "placeholders-sync", docx: "D:\\审计项目\\报告.docx", dryRun: true } },
106
+ "blank-delete": { title: "删除空白表格", tool: "audit_run", required: ["docx", "pick"], optional: ["docx", "excel", "dryRun", "force", "pick", "keepCaption", "keepCaptionFor", "reversible"], defaults: { reversible: true, keepCaption: false, force: false }, dryRun: true, writes: true, example: { operation: "blank-delete", docx: "D:\\审计项目\\报告.docx", pick: "1", dryRun: true } },
107
+ "restore-tables": { title: "恢复已删表格", tool: "audit_run", required: ["docx", "pick"], optional: ["docx", "excel", "dryRun", "force", "pick"], defaults: { excel: "同名_表格数据.xlsx", force: false }, dryRun: true, writes: true, example: { operation: "restore-tables", docx: "D:\\审计项目\\报告.docx", pick: "1", dryRun: true } },
108
+ "blank-batch-delete": { title: "批量删除空白表", tool: "audit_run", required: ["items"], optional: ["items", "dryRun", "force"], defaults: { force: false }, dryRun: true, writes: true, example: { operation: "blank-batch-delete", items: [{ docx: "D:\\审计项目\\报告.docx", pick: "1", reversible: true }], dryRun: true } },
109
+ "diff-export": { title: "导出差异清单", tool: "audit_run", required: ["docx"], optional: ["docx", "excel"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: true, example: { operation: "diff-export", docx: "D:\\审计项目\\报告.docx" } },
110
+ "append-table": { title: "追加新表块", tool: "audit_run", required: ["docx", "name", "nrows", "ncols"], optional: ["docx", "excel", "name", "nrows", "ncols", "after"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: true, example: { operation: "append-table", docx: "D:\\审计项目\\报告.docx", name: "审计发现问题汇总", nrows: 3, ncols: 3 } },
111
+ "sort-set": { title: "设置表格排序", tool: "audit_run", required: ["docx", "code", "column"], optional: ["docx", "excel", "code", "column", "descending"], defaults: { excel: "同名_表格数据.xlsx", descending: true }, dryRun: false, writes: true, example: { operation: "sort-set", docx: "D:\\审计项目\\报告.docx", code: "T02", column: "金额", descending: true } },
112
+ "sort-clear": { title: "清除表格排序", tool: "audit_run", required: ["docx", "code"], optional: ["docx", "excel", "code"], defaults: { excel: "同名_表格数据.xlsx" }, dryRun: false, writes: true, example: { operation: "sort-clear", docx: "D:\\审计项目\\报告.docx", code: "T02" } },
113
+ "batch-writeback": { title: "多报告批量同步", tool: "audit_run", required: ["paths"], optional: ["paths", "dryRun", "force", "backup", "noBackup", "contents", "keepHighlight"], defaults: { contents: { tables: true, marks: false, placeholders: false }, keepHighlight: true, backup: true, force: false }, dryRun: true, writes: true, example: { operation: "batch-writeback", paths: ["D:\\审计项目\\报告一.docx"], contents: { tables: true }, dryRun: true } },
114
+ "template-batch": { title: "模板批量生成", tool: "audit_run", required: ["templates", "items", "outDir"], optional: ["templates", "items", "outDir", "dryRun", "contents", "keepHighlight"], defaults: { contents: { tables: true, marks: false, placeholders: true }, keepHighlight: true }, dryRun: true, writes: true, example: { operation: "template-batch", templates: ["D:\\审计项目\\模板.docx"], items: [{ excel: "D:\\审计项目\\底稿.xlsx", template: 1 }], outDir: "D:\\审计项目\\输出", dryRun: true } },
115
+ "fill-placeholders": { title: "生成正文信息填写表", tool: "audit_run", required: ["docx", "paths"], optional: ["docx", "paths"], defaults: {}, dryRun: false, writes: true, example: { operation: "fill-placeholders", docx: "D:\\审计项目\\模板.docx", paths: ["D:\\审计项目\\底稿.xlsx"] } },
116
+ "backup-restore": { title: "恢复历史备份", tool: "audit_run", required: ["backupPath", "target"], optional: ["backupPath", "target"], defaults: {}, dryRun: false, writes: true, example: { operation: "backup-restore", backupPath: "D:\\审计项目\\_backup\\报告.bak.docx", target: "D:\\审计项目\\报告.docx" } },
117
+ "format-apply": { title: "应用报告格式", tool: "audit_run", required: ["docx"], optional: ["docx", "template", "profileName", "output", "scope", "headingBatchId", "headingLevels", "roleBatchId", "roleOverrides", "regionStartId", "dryRun", "confirmed"], defaults: {}, dryRun: true, writes: true, agentOnly: true, example: { operation: "format-apply", docx: "D:\\审计项目\\报告.docx", template: "D:\\审计项目\\样板.docx", output: "D:\\审计项目\\报告_调整格式.docx", dryRun: true } },
118
+ }
119
+
120
+ const isObject = value => Boolean(value) && typeof value === "object" && !Array.isArray(value)
121
+
122
+ function validatePath(value, label, suffixes = []) {
123
+ if (typeof value !== "string" || !value.trim()) throw new Error(`${label}必须使用绝对路径`)
124
+ if (/[\u0000-\u001f]/.test(value)) throw new Error(`${label}含有控制字符`)
125
+ if (!path.isAbsolute(value)) throw new Error(`${label}必须使用绝对路径`)
126
+ if (suffixes.length && !suffixes.some(suffix => value.toLowerCase().endsWith(suffix))) {
127
+ throw new Error(`${label}只支持 ${suffixes.join("/")} 文件`)
128
+ }
129
+ return value
130
+ }
131
+
132
+ export function validateRunArgs(args, allowedOperations) {
133
+ if (!isObject(args)) throw new Error("参数必须是对象")
134
+ if (!allowedOperations.includes(args.operation)) throw new Error("不支持的操作")
135
+ const spec = operationSpecs[args.operation]
136
+ if (!spec) throw new Error("该操作缺少能力定义")
137
+ if (args.dryRun !== undefined && !spec.dryRun) throw new Error(`${spec.title}不支持预演,请先用相关只读查询检查。`)
138
+ if (args.operation === "format-apply" && args.dryRun !== true && args.confirmed !== true) throw new Error("正式应用格式前必须取得用户确认,并传 confirmed=true。")
139
+ const allowedKeys = new Set(["operation", ...spec.required, ...spec.optional])
140
+ for (const key of Object.keys(args)) {
141
+ if (!allowedKeys.has(key)) throw new Error(`${spec.title}不支持参数:${key}`)
142
+ }
143
+ const labels = { docx: "Word 文件", excel: "Excel 工作簿", paths: "文件清单", templates: "模板清单", items: "任务清单", outDir: "输出目录", pick: "候选编号", name: "新表名称", nrows: "行数", ncols: "列数", code: "表块编号", column: "排序列名", backupPath: "历史备份文件", target: "恢复目标文件", template: "样板 Word", output: "输出 Word" }
144
+ for (const key of spec.required) {
145
+ const value = args[key]
146
+ if (value === undefined || value === null || value === "" || (Array.isArray(value) && value.length === 0)) {
147
+ throw new Error(`${spec.title}缺少${labels[key] || key}。`)
148
+ }
149
+ }
150
+ const request = { operation: args.operation }
151
+ if (args.docx !== undefined && args.docx !== "") request.docx = validatePath(args.docx, "Word 文件", [".docx", ".docm"])
152
+ if (args.excel !== undefined && args.excel !== "") request.excel = validatePath(args.excel, "Excel 工作簿", [".xlsx", ".xlsm"])
153
+ for (const key of ["template", "output"]) {
154
+ if (args[key] !== undefined && args[key] !== "") request[key] = validatePath(args[key], labels[key], [".docx", ".docm"])
155
+ }
156
+ if (args.operation.startsWith("format-")) {
157
+ if (request.template && args.profileName) throw new Error("样板报告与已存格式方案只能二选一。")
158
+ if (args.profileName !== undefined) {
159
+ if (typeof args.profileName !== "string" || !args.profileName.trim()) throw new Error("profileName 必须是非空文本。")
160
+ request.profileName = args.profileName.trim()
161
+ }
162
+ if (args.scope !== undefined) {
163
+ const keys = ["cover", "headings", "statement", "body", "table_text", "table_emphasis", "table_borders"]
164
+ if (!isObject(args.scope) || Object.keys(args.scope).length !== keys.length || keys.some(key => typeof args.scope[key] !== "boolean")) throw new Error("scope 必须完整包含七项布尔值。")
165
+ if (!keys.some(key => args.scope[key])) throw new Error("scope 至少开启一项。")
166
+ request.scope = Object.fromEntries(keys.map(key => [key, args.scope[key]]))
167
+ }
168
+ if ((args.headingBatchId === undefined) !== (args.headingLevels === undefined)) throw new Error("headingBatchId 与 headingLevels 必须同时提供。")
169
+ if (args.headingBatchId !== undefined) {
170
+ if (typeof args.headingBatchId !== "string" || !args.headingBatchId) throw new Error("headingBatchId 必须是非空文本。")
171
+ if (!isObject(args.headingLevels) || Object.keys(args.headingLevels).length > 300 || Object.entries(args.headingLevels).some(([key, value]) => !key || !Number.isInteger(value) || value < 1 || value > 4)) throw new Error("headingLevels 必须是最多 300 项、级别为 1~4 整数的映射。")
172
+ if (args.scope && !args.scope.headings) throw new Error("应用候选标题级别时必须勾选 headings。")
173
+ request.headingBatchId = args.headingBatchId
174
+ request.headingLevels = args.headingLevels
175
+ }
176
+ if ((args.roleBatchId === undefined) !== (args.roleOverrides === undefined) && args.regionStartId === undefined) throw new Error("roleBatchId 与 roleOverrides 必须同时提供。")
177
+ if (args.roleBatchId !== undefined) {
178
+ if (typeof args.roleBatchId !== "string" || !args.roleBatchId) throw new Error("roleBatchId 必须是非空文本。")
179
+ if (args.headingBatchId !== undefined && args.headingBatchId !== args.roleBatchId) throw new Error("标题与角色候选必须使用同一批次编号。")
180
+ if (args.roleOverrides !== undefined && (!isObject(args.roleOverrides) || Object.keys(args.roleOverrides).length > 300 || Object.entries(args.roleOverrides).some(([key, value]) => !key || !["body", "table_title"].includes(value)))) throw new Error("roleOverrides 必须是最多 300 项的 body/table_title 映射。")
181
+ if (args.roleOverrides !== undefined && args.scope && !args.scope.statement) throw new Error("应用表格标题角色时必须勾选 statement。")
182
+ request.roleBatchId = args.roleBatchId
183
+ if (args.roleOverrides !== undefined) request.roleOverrides = args.roleOverrides
184
+ }
185
+ if (args.regionStartId !== undefined) {
186
+ if (typeof args.regionStartId !== "string" || !args.regionStartId) throw new Error("regionStartId 必须是非空文本。")
187
+ if (args.roleBatchId === undefined) throw new Error("应用附注边界时必须同时提供 roleBatchId。")
188
+ request.regionStartId = args.regionStartId
189
+ }
190
+ }
191
+ for (const key of ["paths", "templates"]) {
192
+ if (args[key] === undefined) continue
193
+ if (!Array.isArray(args[key]) || args[key].length > 200) throw new Error(`${key} 必须是路径数组,且最多 200 项`)
194
+ const suffixes = key === "templates" || args.operation !== "fill-placeholders" ? [".docx", ".docm"] : [".xlsx", ".xlsm"]
195
+ request[key] = args[key].map((value, index) => validatePath(value, `${key}[${index}]`, suffixes))
196
+ }
197
+ if (args.items !== undefined) {
198
+ if (!Array.isArray(args.items) || args.items.length > 200 || args.items.some(item => !isObject(item))) {
199
+ throw new Error("items 必须是对象数组,且最多 200 项")
200
+ }
201
+ if (args.operation === "template-batch") {
202
+ request.items = args.items.map((item, index) => {
203
+ const allowed = new Set(["excel", "template"])
204
+ for (const key of Object.keys(item)) if (!allowed.has(key)) throw new Error(`items[${index}] 不支持参数:${key}`)
205
+ if (!Number.isInteger(item.template) || item.template < 1 || item.template > request.templates.length) throw new Error(`items[${index}].template 必须是 1~${request.templates.length} 的模板编号`)
206
+ return { excel: validatePath(item.excel, `items[${index}].excel`, [".xlsx", ".xlsm"]), template: item.template }
207
+ })
208
+ } else if (args.operation === "blank-batch-delete") {
209
+ request.items = args.items.map((item, index) => {
210
+ const allowed = new Set(["docx", "pick", "keepCaptionFor", "reversible", "excel"])
211
+ for (const key of Object.keys(item)) if (!allowed.has(key)) throw new Error(`items[${index}] 不支持参数:${key}`)
212
+ if (typeof item.pick !== "string" || !item.pick.trim()) throw new Error(`items[${index}].pick 必须填写候选编号`)
213
+ if (item.reversible !== undefined && typeof item.reversible !== "boolean") throw new Error(`items[${index}].reversible 必须是布尔值`)
214
+ const value = { docx: validatePath(item.docx, `items[${index}].docx`, [".docx", ".docm"]), pick: item.pick.trim() }
215
+ if (item.keepCaptionFor !== undefined) {
216
+ if (typeof item.keepCaptionFor !== "string") throw new Error(`items[${index}].keepCaptionFor 必须是文本`)
217
+ value.keepCaptionFor = item.keepCaptionFor
218
+ }
219
+ if (item.reversible !== undefined) value.reversible = item.reversible
220
+ if (item.excel !== undefined && item.excel !== "") value.excel = validatePath(item.excel, `items[${index}].excel`, [".xlsx", ".xlsm"])
221
+ return value
222
+ })
223
+ } else {
224
+ request.items = args.items
225
+ }
226
+ }
227
+ if (args.outDir !== undefined) request.outDir = validatePath(args.outDir, "输出目录")
228
+ if (args.backupPath !== undefined) request.backupPath = validatePath(args.backupPath, "备份文件", [".docx", ".docm", ".xlsx", ".xlsm"])
229
+ if (args.target !== undefined) request.target = validatePath(args.target, "目标文件", [".docx", ".docm", ".xlsx", ".xlsm"])
230
+ if (request.backupPath && request.target && path.extname(request.backupPath).toLowerCase() !== path.extname(request.target).toLowerCase()) {
231
+ throw new Error("备份文件与目标文件的扩展名必须一致。")
232
+ }
233
+ for (const key of ["dryRun", "force", "backup", "noBackup", "withExcelLinks", "totalsFormula", "keepHighlight", "deleteEmptyRows", "changelog", "keepCaption", "reversible", "descending", "confirmed"]) {
234
+ if (args[key] !== undefined) {
235
+ if (typeof args[key] !== "boolean") throw new Error(`${key} 必须是布尔值`)
236
+ request[key] = args[key]
237
+ }
238
+ }
239
+ for (const key of ["pick", "keepCaptionFor", "name", "after", "code", "column"]) {
240
+ if (args[key] !== undefined) {
241
+ if (typeof args[key] !== "string") throw new Error(`${key} 必须是文本`)
242
+ request[key] = args[key]
243
+ }
244
+ }
245
+ for (const key of ["nrows", "ncols"]) {
246
+ if (args[key] !== undefined) {
247
+ if (!Number.isInteger(args[key])) throw new Error(`${key} 必须是整数`)
248
+ const maximum = key === "nrows" ? 200 : 30
249
+ if (args[key] < 1 || args[key] > maximum) throw new Error(`${key} 必须在 1~${maximum} 之间`)
250
+ request[key] = args[key]
251
+ }
252
+ }
253
+ if (args.contents !== undefined) {
254
+ if (!isObject(args.contents)) throw new Error("同步内容格式不正确")
255
+ request.contents = {}
256
+ for (const key of ["tables", "marks", "placeholders", "keepHighlight"]) {
257
+ if (args.contents[key] !== undefined) {
258
+ if (typeof args.contents[key] !== "boolean") throw new Error(`contents.${key} 必须是布尔值`)
259
+ request.contents[key] = args.contents[key]
260
+ }
261
+ }
262
+ if (!["tables", "marks", "placeholders"].some(key => request.contents[key] === true)) throw new Error("同步内容至少勾选一项。")
263
+ }
264
+ return request
265
+ }