audit-e2w 0.0.0-stage → 1.11.7

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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -3
  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 +122 -0
  6. package/dsh_plugins/audit-e2w/lib/skill.js +42 -0
  7. package/excel_word/README.md +388 -0
  8. package/excel_word/qoder_engine.py +437 -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/ai/__init__.py +52 -0
  13. package/excel_word/wesync/ai/actions.py +369 -0
  14. package/excel_word/wesync/ai/client.py +340 -0
  15. package/excel_word/wesync/ai/config.py +291 -0
  16. package/excel_word/wesync/ai/docs.py +177 -0
  17. package/excel_word/wesync/ai/prompts.py +288 -0
  18. package/excel_word/wesync/ai/tasks/__init__.py +26 -0
  19. package/excel_word/wesync/ai/tasks/actions_task.py +97 -0
  20. package/excel_word/wesync/ai/tasks/combined.py +123 -0
  21. package/excel_word/wesync/ai/tasks/diff_note.py +61 -0
  22. package/excel_word/wesync/ai/tasks/headings.py +119 -0
  23. package/excel_word/wesync/ai/tasks/help_task.py +69 -0
  24. package/excel_word/wesync/ai/tasks/roles.py +128 -0
  25. package/excel_word/wesync/align.py +155 -0
  26. package/excel_word/wesync/api.py +1292 -0
  27. package/excel_word/wesync/backup_history.py +100 -0
  28. package/excel_word/wesync/changelog.py +58 -0
  29. package/excel_word/wesync/cli.py +191 -0
  30. package/excel_word/wesync/commands/__init__.py +8 -0
  31. package/excel_word/wesync/commands/blank_cmd.py +279 -0
  32. package/excel_word/wesync/commands/bookmark_cmd.py +146 -0
  33. package/excel_word/wesync/commands/clear_cmd.py +50 -0
  34. package/excel_word/wesync/commands/export_cmd.py +270 -0
  35. package/excel_word/wesync/commands/incremental_cmd.py +157 -0
  36. package/excel_word/wesync/commands/marks_cmd.py +160 -0
  37. package/excel_word/wesync/commands/placeholders_cmd.py +92 -0
  38. package/excel_word/wesync/commands/writeback_cmd.py +469 -0
  39. package/excel_word/wesync/config.py +97 -0
  40. package/excel_word/wesync/console.py +85 -0
  41. package/excel_word/wesync/docx_blank.py +156 -0
  42. package/excel_word/wesync/docx_bookmarks.py +294 -0
  43. package/excel_word/wesync/docx_columns.py +257 -0
  44. package/excel_word/wesync/docx_edit.py +77 -0
  45. package/excel_word/wesync/docx_grid.py +212 -0
  46. package/excel_word/wesync/docx_marks.py +399 -0
  47. package/excel_word/wesync/docx_meta.py +157 -0
  48. package/excel_word/wesync/docx_newtable.py +220 -0
  49. package/excel_word/wesync/docx_placeholders.py +200 -0
  50. package/excel_word/wesync/docx_rows.py +67 -0
  51. package/excel_word/wesync/errors.py +5 -0
  52. package/excel_word/wesync/excel_blocks.py +502 -0
  53. package/excel_word/wesync/excel_export.py +143 -0
  54. package/excel_word/wesync/excel_marks.py +265 -0
  55. package/excel_word/wesync/excel_totals.py +53 -0
  56. package/excel_word/wesync/fsops.py +219 -0
  57. package/excel_word/wesync/gui/__init__.py +53 -0
  58. package/excel_word/wesync/gui/__main__.py +6 -0
  59. package/excel_word/wesync/gui/app.py +613 -0
  60. package/excel_word/wesync/gui/manual.py +70 -0
  61. package/excel_word/wesync/gui/pages/__init__.py +80 -0
  62. package/excel_word/wesync/gui/pages/_page.py +211 -0
  63. package/excel_word/wesync/gui/pages/ai_page.py +854 -0
  64. package/excel_word/wesync/gui/pages/batch_page.py +456 -0
  65. package/excel_word/wesync/gui/pages/blank_page.py +530 -0
  66. package/excel_word/wesync/gui/pages/bookmark_page.py +97 -0
  67. package/excel_word/wesync/gui/pages/export_page.py +141 -0
  68. package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
  69. package/excel_word/wesync/gui/pages/format_page.py +551 -0
  70. package/excel_word/wesync/gui/pages/help_page.py +158 -0
  71. package/excel_word/wesync/gui/pages/history_page.py +168 -0
  72. package/excel_word/wesync/gui/pages/marks_page.py +211 -0
  73. package/excel_word/wesync/gui/pages/settings_page.py +450 -0
  74. package/excel_word/wesync/gui/pages/writeback_page.py +473 -0
  75. package/excel_word/wesync/gui/resources.py +22 -0
  76. package/excel_word/wesync/gui/runner.py +90 -0
  77. package/excel_word/wesync/gui/store.py +50 -0
  78. package/excel_word/wesync/gui/theme.py +271 -0
  79. package/excel_word/wesync/gui/widgets/__init__.py +8 -0
  80. package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
  81. package/excel_word/wesync/gui/widgets/cards.py +139 -0
  82. package/excel_word/wesync/gui/widgets/chips.py +565 -0
  83. package/excel_word/wesync/gui/widgets/filebar.py +58 -0
  84. package/excel_word/wesync/gui/widgets/logpane.py +126 -0
  85. package/excel_word/wesync/gui/widgets/nav.py +294 -0
  86. package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
  87. package/excel_word/wesync/report_format.py +1585 -0
  88. package/excel_word/wesync/settings.py +35 -0
  89. package/excel_word/wesync/sort_rules.py +293 -0
  90. package/excel_word/wesync/valuefmt.py +485 -0
  91. package/package.json +53 -6
  92. package/packaging//344/275/277/347/224/250/350/257/264/346/230/216.txt +247 -0
  93. package/qoder_plugins/audit-toolbox/README.md +159 -0
  94. package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
@@ -0,0 +1,369 @@
1
+ """AI 可建议/可执行的操作白名单:意图解析与参数校验。
2
+
3
+ 设计红线(比单纯判级更严,因为这里可能触发写盘):
4
+ - 模型只能从 ACTION_SPECS 里已有的操作中选,不在表里的一律拒绝;
5
+ - 模型给的所有参数都要过本地校验:路径必须真实存在、枚举值必须在允许集、
6
+ pick/编号必须来自最近的扫描结果;
7
+ - 写操作默认只到"预演"为止;正式执行必须由用户点确认,模型无权决定;
8
+ - 模型永远不能直接写文件:它只产出 ACTION 结构,执行由本地完成。
9
+
10
+ 本模块纯逻辑、不写盘、不发网络请求,便于单测。
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import re
16
+ from pathlib import Path
17
+
18
+
19
+ # 每个操作的规格:
20
+ # label 界面上怎么称呼
21
+ # writes 是否可能写盘(True 时必须预演 + 用户确认)
22
+ # preview 是否支持预演(不支持写盘的操作无法预演,只能让用户手工点)
23
+ # params 参数名 -> 规格(required 必填;type 校验类型;enum 允许值)
24
+ # page 对应哪个 GUI 页面(建议模式下用来引导用户)
25
+ # tip 给用户的说明
26
+ ACTION_SPECS: dict[str, dict] = {
27
+ "export": {
28
+ "label": "创建 Excel(Word → 工作簿)",
29
+ "writes": True, "preview": True, "page": "ExportPage",
30
+ "params": {
31
+ "docx": {"required": True, "type": "docx"},
32
+ "excel": {"type": "xlsx"},
33
+ "backup": {"type": "bool"},
34
+ },
35
+ "tip": "按当前 Word 重建工作簿;已有同名工作簿会先备份。",
36
+ },
37
+ "incremental-export": {
38
+ "label": "增量导出(只追加新表)",
39
+ "writes": True, "preview": True, "page": "ExportPage",
40
+ "params": {
41
+ "docx": {"required": True, "type": "docx"},
42
+ "excel": {"type": "xlsx"},
43
+ "backup": {"type": "bool"},
44
+ },
45
+ "tip": "只登记 Word 里新增的表格、标注、占位符,既有行不动。",
46
+ },
47
+ "writeback": {
48
+ "label": "同步到 Word",
49
+ "writes": True, "preview": True, "page": "WritebackPage",
50
+ "params": {
51
+ "docx": {"required": True, "type": "docx"},
52
+ "excel": {"type": "xlsx"},
53
+ "backup": {"type": "bool"},
54
+ "deleteEmptyRows": {"type": "bool"},
55
+ "changelog": {"type": "bool"},
56
+ },
57
+ "tip": "把 Excel 的改动写回 Word,保留字体、边框、合并单元格。",
58
+ },
59
+ "rejudge": {
60
+ "label": "重新判定 ✓/✕",
61
+ "writes": True, "preview": True, "page": "ExportPage",
62
+ "params": {
63
+ "docx": {"required": True, "type": "docx"},
64
+ "excel": {"type": "xlsx"},
65
+ "backup": {"type": "bool"},
66
+ },
67
+ "tip": "按工作簿当前内容重判 B 列标记,只改标记不改数据。",
68
+ },
69
+ "bookmark": {
70
+ "label": "重建书签",
71
+ "writes": True, "preview": True, "page": "BookmarkPage",
72
+ "params": {
73
+ "docx": {"required": True, "type": "docx"},
74
+ "excel": {"type": "xlsx"},
75
+ },
76
+ "tip": "重建或迁移表格书签,修复书签对不上的问题。",
77
+ },
78
+ "clear-bookmarks": {
79
+ "label": "清理工具书签",
80
+ "writes": True, "preview": True, "page": "BookmarkPage",
81
+ "params": {"docx": {"required": True, "type": "docx"}},
82
+ "tip": "移除工具写入的书签,交回干净的 Word。",
83
+ },
84
+ "marks": {
85
+ "label": "导出标注",
86
+ "writes": True, "preview": True, "page": "MarksPage",
87
+ "params": {
88
+ "docx": {"required": True, "type": "docx"},
89
+ "excel": {"type": "xlsx"},
90
+ },
91
+ "tip": "把 Word 里的高亮标注导出到工作簿「链接标注」表。",
92
+ },
93
+ "marks-sync": {
94
+ "label": "同步标注到 Word",
95
+ "writes": True, "preview": True, "page": "MarksPage",
96
+ "params": {
97
+ "docx": {"required": True, "type": "docx"},
98
+ "excel": {"type": "xlsx"},
99
+ "keepHighlight": {"type": "bool"},
100
+ },
101
+ "tip": "把「链接标注」表填的内容写回 Word。",
102
+ },
103
+ "placeholders": {
104
+ "label": "补齐正文信息表",
105
+ "writes": True, "preview": True, "page": "MarksPage",
106
+ "params": {
107
+ "docx": {"required": True, "type": "docx"},
108
+ "excel": {"type": "xlsx"},
109
+ },
110
+ "tip": "按模板占位符给工作簿补「正文信息」填写骨架,保留已填值。",
111
+ },
112
+ "placeholders-sync": {
113
+ "label": "同步占位符到 Word",
114
+ "writes": True, "preview": True, "page": "MarksPage",
115
+ "params": {
116
+ "docx": {"required": True, "type": "docx"},
117
+ "excel": {"type": "xlsx"},
118
+ },
119
+ "tip": "把「正文信息」表的值替换 Word 里的 {字段名}。",
120
+ },
121
+ "blank-delete": {
122
+ "label": "删除空白表格",
123
+ "writes": True, "preview": True, "page": "BlankPage",
124
+ "params": {
125
+ "docx": {"required": True, "type": "docx"},
126
+ "excel": {"type": "xlsx"},
127
+ "pick": {"required": True, "type": "pick"},
128
+ "keepCaption": {"type": "bool"},
129
+ "reversible": {"type": "bool"},
130
+ },
131
+ "tip": "删除指定的空白表;可逆删除会在工作簿保留待恢复记录。",
132
+ },
133
+ "restore-tables": {
134
+ "label": "恢复已删除表格",
135
+ "writes": True, "preview": True, "page": "BlankPage",
136
+ "params": {
137
+ "docx": {"required": True, "type": "docx"},
138
+ "excel": {"type": "xlsx"},
139
+ "pick": {"required": True, "type": "pick"},
140
+ },
141
+ "tip": "把之前可逆删除的表恢复回 Word。",
142
+ },
143
+ "diff-export": {
144
+ "label": "导出差异清单",
145
+ "writes": True, "preview": False, "page": "WritebackPage",
146
+ "params": {
147
+ "docx": {"required": True, "type": "docx"},
148
+ "excel": {"type": "xlsx"},
149
+ },
150
+ "tip": "把逐格差异导出成清单工作簿,便于归档。",
151
+ },
152
+ "format-apply": {
153
+ "label": "生成格式调整副本",
154
+ "writes": True, "preview": True, "page": "FormatPage",
155
+ "params": {
156
+ "docx": {"required": True, "type": "docx"},
157
+ "template": {"type": "docx"},
158
+ "profileName": {"type": "str"},
159
+ "output": {"required": True, "type": "docx_new"},
160
+ },
161
+ "tip": "按样板或已存方案生成格式副本,原报告不改。",
162
+ },
163
+ "batch-writeback": {
164
+ "label": "批量同步多份报告",
165
+ "writes": True, "preview": True, "page": "BatchPage",
166
+ "params": {
167
+ "paths": {"required": True, "type": "docx_list"},
168
+ "backup": {"type": "bool"},
169
+ },
170
+ "tip": "多份报告一起把 Excel 改动写回 Word。",
171
+ },
172
+ "template-batch": {
173
+ "label": "模板批量生成报告",
174
+ "writes": True, "preview": True, "page": "BatchPage",
175
+ "params": {
176
+ "templates": {"required": True, "type": "docx_list"},
177
+ "items": {"required": True, "type": "json"},
178
+ "outDir": {"required": True, "type": "dir"},
179
+ },
180
+ "tip": "一套模板配多个工作簿,批量生成报告。",
181
+ },
182
+ "backup-restore": {
183
+ "label": "恢复历史备份",
184
+ "writes": True, "preview": False, "page": "HistoryPage",
185
+ "params": {
186
+ "backupPath": {"required": True, "type": "backup"},
187
+ "target": {"required": True, "type": "docx_or_xlsx"},
188
+ },
189
+ "tip": "把文件回滚到某个备份时间点;恢复前会再备份现状。",
190
+ },
191
+ }
192
+
193
+ # 只读操作:可以随时跑,不需要确认
194
+ READ_ACTIONS: dict[str, dict] = {
195
+ "blank-scan": {"label": "扫描空白表格", "page": "BlankPage", "params": {"docx": {"required": True, "type": "docx"}}},
196
+ "deleted-list": {"label": "查看可恢复表格", "page": "BlankPage", "params": {"docx": {"required": True, "type": "docx"}}},
197
+ "diff": {"label": "查看 Excel 与 Word 差异", "page": "WritebackPage",
198
+ "params": {"docx": {"required": True, "type": "docx"}, "excel": {"type": "xlsx"}}},
199
+ "table-list": {"label": "查看工作簿表块", "page": "WritebackPage",
200
+ "params": {"docx": {"required": True, "type": "docx"}, "excel": {"type": "xlsx"}}},
201
+ "backup-list": {"label": "查看历史备份", "page": "HistoryPage",
202
+ "params": {"docx": {"required": True, "type": "docx"}, "excel": {"type": "xlsx"}}},
203
+ "template-scan": {"label": "检查模板占位符", "page": "BatchPage", "params": {"docx": {"required": True, "type": "docx"}}},
204
+ "format-scan": {"label": "预演格式调整", "page": "FormatPage", "params": {"docx": {"required": True, "type": "docx"}}},
205
+ }
206
+
207
+ # 页面中文名(建议模式用来引导用户去哪一页)
208
+ PAGE_LABELS = {
209
+ "ExportPage": "创建Excel",
210
+ "WritebackPage": "同步Word",
211
+ "MarksPage": "标注与占位",
212
+ "BatchPage": "批量同步",
213
+ "BlankPage": "空白表格",
214
+ "FormatPage": "一键调整格式",
215
+ "BookmarkPage": "书签工具",
216
+ "HistoryPage": "备份与回滚",
217
+ }
218
+
219
+
220
+ class ActionError(Exception):
221
+ """操作建议/校验失败;消息面向用户,可直接展示。"""
222
+
223
+
224
+ def page_label(page: str) -> str:
225
+ return PAGE_LABELS.get(page, page)
226
+
227
+
228
+ def action_label(name: str) -> str:
229
+ spec = ACTION_SPECS.get(name) or READ_ACTIONS.get(name) or {}
230
+ return spec.get("label", name)
231
+
232
+
233
+ def _check_path(value, kind: str, *, must_exist: bool) -> str:
234
+ text = str(value or "").strip()
235
+ if not text:
236
+ raise ActionError("路径为空。")
237
+ path = Path(text)
238
+ if not path.is_absolute():
239
+ raise ActionError(f"需要绝对路径:{text}")
240
+ suffix = path.suffix.lower()
241
+ if kind == "docx" and suffix not in (".docx", ".docm"):
242
+ raise ActionError(f"不是 Word 文件:{path.name}")
243
+ if kind == "docx_new" and suffix not in (".docx", ".docm"):
244
+ raise ActionError(f"输出必须是 .docx/.docm:{path.name}")
245
+ if kind == "xlsx" and suffix not in (".xlsx", ".xlsm"):
246
+ raise ActionError(f"不是 Excel 文件:{path.name}")
247
+ if kind == "backup" and suffix not in (".docx", ".docm", ".xlsx", ".xlsm"):
248
+ raise ActionError(f"备份文件类型不支持:{path.name}")
249
+ if kind == "docx_or_xlsx" and suffix not in (".docx", ".docm", ".xlsx", ".xlsm"):
250
+ raise ActionError(f"目标文件类型不支持:{path.name}")
251
+ if kind == "dir":
252
+ if must_exist and not path.is_dir():
253
+ raise ActionError(f"目录不存在:{path}")
254
+ return str(path)
255
+ # 输出文件允许不存在(是新建目标),其余必须存在
256
+ if kind == "docx_new":
257
+ if path.exists():
258
+ raise ActionError(f"输出文件已存在,不会覆盖:{path.name}")
259
+ if not path.parent.is_dir():
260
+ raise ActionError(f"输出目录不存在:{path.parent}")
261
+ return str(path)
262
+ if must_exist and not path.exists():
263
+ raise ActionError(f"文件不存在:{path}")
264
+ return str(path)
265
+
266
+
267
+ def _check_pick(value, allowed: set[str] | None) -> str:
268
+ """pick 支持 "1,3" 或 "all";给了扫描结果时必须落在候选编号内。"""
269
+ text = str(value or "").strip()
270
+ if not text:
271
+ raise ActionError("缺少要处理的编号。")
272
+ if text.lower() == "all":
273
+ return "all"
274
+ parts = [item.strip() for item in text.split(",") if item.strip()]
275
+ if not parts:
276
+ raise ActionError("缺少要处理的编号。")
277
+ for item in parts:
278
+ if not re.fullmatch(r"\d{1,3}", item):
279
+ raise ActionError(f"编号不合法:{item}(应为数字,多个用逗号分隔,或 all)")
280
+ if allowed is not None:
281
+ unknown = [item for item in parts if item not in allowed]
282
+ if unknown:
283
+ raise ActionError(f"编号不在本次扫描结果里:{', '.join(unknown)}")
284
+ return ",".join(parts)
285
+
286
+
287
+ def validate_action(
288
+ name: str,
289
+ params: dict,
290
+ *,
291
+ allow_read: bool = True,
292
+ allowed_picks: set[str] | None = None,
293
+ strict_exists: bool = True,
294
+ ) -> dict:
295
+ """校验一个操作及其参数;通过则返回规范化后的参数,否则抛 ActionError。"""
296
+ spec = ACTION_SPECS.get(name)
297
+ if spec is None:
298
+ if allow_read and name in READ_ACTIONS:
299
+ spec = {**READ_ACTIONS[name], "writes": False, "preview": False}
300
+ else:
301
+ raise ActionError(f"不支持的操作:{name}(只能从工具已有的操作里选)")
302
+ if not isinstance(params, dict):
303
+ raise ActionError("参数必须是对象。")
304
+
305
+ specs = spec.get("params") or {}
306
+ unknown = [key for key in params if key not in specs]
307
+ if unknown:
308
+ raise ActionError(f"不认识的参数:{', '.join(unknown)}")
309
+ missing = [key for key, rule in specs.items() if rule.get("required") and key not in params]
310
+ if missing:
311
+ raise ActionError(f"缺少必填参数:{', '.join(missing)}")
312
+
313
+ result: dict = {}
314
+ for key, value in params.items():
315
+ rule = specs[key]
316
+ kind = rule.get("type", "str")
317
+ if kind == "bool":
318
+ if not isinstance(value, bool):
319
+ raise ActionError(f"参数 {key} 必须是 true/false")
320
+ result[key] = value
321
+ elif kind in ("docx", "docx_new", "xlsx", "backup", "docx_or_xlsx"):
322
+ result[key] = _check_path(value, kind, must_exist=strict_exists)
323
+ elif kind == "dir":
324
+ result[key] = _check_path(value, "dir", must_exist=strict_exists)
325
+ elif kind == "docx_list":
326
+ if not isinstance(value, list) or not value:
327
+ raise ActionError(f"参数 {key} 必须是非空数组")
328
+ if len(value) > 200:
329
+ raise ActionError("一次最多 200 个文件")
330
+ result[key] = [_check_path(item, "docx", must_exist=strict_exists) for item in value]
331
+ elif kind == "pick":
332
+ result[key] = _check_pick(value, allowed_picks)
333
+ elif kind == "json":
334
+ # 批量清单等结构化参数:模型给的对象/数组原样保留,由下游再校验
335
+ if not isinstance(value, (list, dict)):
336
+ raise ActionError(f"参数 {key} 必须是数组或对象")
337
+ result[key] = value
338
+ else:
339
+ text = str(value or "").strip()
340
+ if not text:
341
+ raise ActionError(f"参数 {key} 不能为空")
342
+ result[key] = text
343
+ return result
344
+
345
+
346
+ def describe(name: str) -> dict:
347
+ """给模型/界面看的操作说明(不含内部字段)。"""
348
+ spec = ACTION_SPECS.get(name) or READ_ACTIONS.get(name)
349
+ if not spec:
350
+ return {}
351
+ params = spec.get("params") or {}
352
+ return {
353
+ "name": name,
354
+ "label": spec.get("label", name),
355
+ "writes": bool(spec.get("writes")),
356
+ "preview": bool(spec.get("preview")),
357
+ "page": page_label(spec.get("page", "")),
358
+ "tip": spec.get("tip", ""),
359
+ "required": [key for key, rule in params.items() if rule.get("required")],
360
+ "optional": [key for key, rule in params.items() if not rule.get("required")],
361
+ }
362
+
363
+
364
+ def catalog(writes_only: bool = False) -> list[dict]:
365
+ """全部可用操作的简要清单,供提示词与界面使用。"""
366
+ items = [describe(name) for name in ACTION_SPECS]
367
+ if not writes_only:
368
+ items += [describe(name) for name in READ_ACTIONS]
369
+ return [item for item in items if item]