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,160 @@
1
+ """marks / marks-sync 子命令:高亮标记导出到「链接标注」工作表,并把填写内容同步回 Word。"""
2
+
3
+ import docx
4
+ from openpyxl import load_workbook
5
+
6
+ from ..console import log, warn
7
+ from ..docx_marks import (
8
+ apply_mark_change,
9
+ ensure_mark_bookmarks,
10
+ find_marks,
11
+ mark_payload_by_bookmark,
12
+ processed_marks,
13
+ )
14
+ from ..errors import SyncError
15
+ from ..excel_marks import SHEET_MARKS, build_marks_sheet, parse_marks_rows, read_previous_marks
16
+ from ..fsops import check_file_free, load_workbook_for_save, resolve_docx, resolve_xlsx, save_docx_xlsx_transaction
17
+
18
+
19
+ def _mark_label(bookmark: str, fallback: str) -> str:
20
+ return bookmark or fallback
21
+
22
+
23
+ def cmd_marks(args) -> int:
24
+ """刷新工作簿里的「链接标注」工作表(不动表格数据,不改 Word 文字)。"""
25
+ docx_path = resolve_docx(args.docx)
26
+ xlsx_path = resolve_xlsx(docx_path, args.excel)
27
+ if not xlsx_path.exists():
28
+ raise SyncError(
29
+ f"找不到工作簿:{xlsx_path}\n请先执行「导出表格到 Excel」(或界面上的“导出/刷新标注”会自动先导出)。"
30
+ )
31
+ if not args.dry_run:
32
+ check_file_free(docx_path, args.force)
33
+ check_file_free(xlsx_path, args.force)
34
+
35
+ doc = docx.Document(str(docx_path))
36
+ marks = find_marks(doc)
37
+ previous = read_previous_marks(xlsx_path)
38
+ processed = processed_marks(doc, {mark.bookmark for mark in marks if mark.bookmark})
39
+
40
+ log(f"读取 Word:{docx_path.name}")
41
+ log(f"发现高亮标记(待处理):{len(marks)} 处" + (f",已处理:{len(processed)} 处" if processed else ""))
42
+ for mark in marks:
43
+ filled = "已填" if any(row["bookmark"] == mark.bookmark and (row["new"] or row["link"]) for row in previous) else "未填"
44
+ log(f" M{mark.index:02d} {mark.location}({filled}):{mark.text[:40]}")
45
+ known = {m.bookmark for m in marks if m.bookmark} | {item["bookmark"] for item in processed}
46
+ stale = [row for row in previous if row["bookmark"] and row["bookmark"] not in known]
47
+ if stale:
48
+ log(f" (另有 {len(stale)} 处工作簿里记录过的标记在 Word 中已删除,将保留为记录行)")
49
+
50
+ if args.dry_run:
51
+ log("预演模式(--dry-run):以上为将写入「链接标注」工作表的标记,未写入任何文件。")
52
+ return 0
53
+
54
+ created = ensure_mark_bookmarks(doc, marks)
55
+ workbook = load_workbook_for_save(xlsx_path)
56
+ stats = build_marks_sheet(workbook, docx_path.name, marks, previous, processed)
57
+ backups = save_docx_xlsx_transaction(
58
+ docx_path=docx_path if created else None, doc=doc if created else None,
59
+ xlsx_path=xlsx_path, wb=workbook, backup=getattr(args, "backup", True),
60
+ )
61
+ docx_backup = backups.get(docx_path) if created else None
62
+ xlsx_backup = backups.get(xlsx_path)
63
+ if created:
64
+ log(f"[标记] 已为 {created} 处标记插入定位书签并保存 Word(备份:{docx_backup.name if docx_backup else '无'})")
65
+ log(
66
+ f"[标记] 已刷新工作表「{SHEET_MARKS}」:{stats['marks']} 行标记"
67
+ + (f",{stats['processed']} 行已处理" if stats.get("processed") else "")
68
+ + (f",{stats['orphans']} 行已删除记录" if stats["orphans"] else "")
69
+ + (f"(原文件已备份:{xlsx_backup.name})" if xlsx_backup else "")
70
+ )
71
+ return 0
72
+
73
+
74
+ def cmd_marks_sync(args) -> int:
75
+ """把「链接标注」工作表里填写的内容同步回 Word。"""
76
+ docx_path = resolve_docx(args.docx)
77
+ xlsx_path = resolve_xlsx(docx_path, args.excel)
78
+ if not xlsx_path.exists():
79
+ raise SyncError(f"找不到工作簿:{xlsx_path}\n请先执行「导出表格到 Excel」或「导出/刷新标注」。")
80
+ if not args.dry_run:
81
+ check_file_free(docx_path, args.force)
82
+ check_file_free(xlsx_path, args.force)
83
+
84
+ workbook = load_workbook(str(xlsx_path))
85
+ if SHEET_MARKS not in workbook.sheetnames:
86
+ raise SyncError(f"工作簿里没有「{SHEET_MARKS}」工作表,请先在界面上执行“导出/刷新标注”。")
87
+ rows = getattr(args, "rows", None)
88
+ if rows is None:
89
+ cached_workbook = load_workbook(str(xlsx_path), data_only=True)
90
+ rows = parse_marks_rows(
91
+ workbook[SHEET_MARKS], cached_workbook[SHEET_MARKS], zero_mode=getattr(args, "mark_zero", "excel")
92
+ )
93
+ if not rows:
94
+ raise SyncError(f"「{SHEET_MARKS}」工作表里没有数据行,请先执行“导出/刷新标注”。")
95
+
96
+ doc = getattr(args, "_doc", None) or docx.Document(str(docx_path))
97
+ keep_highlight = bool(getattr(args, "keep_highlight", False))
98
+ mark_parts = {mark.bookmark: mark.part for mark in find_marks(doc) if mark.bookmark}
99
+ log(f"读取 Word:{docx_path.name}")
100
+ log(f"读取 Excel:{xlsx_path.name}(工作表:{SHEET_MARKS},{len(rows)} 行)")
101
+ if keep_highlight:
102
+ log("[标记] 本次同步保留高亮(不去色),便于人工复核")
103
+ if args.dry_run:
104
+ log("预演模式(--dry-run):只显示将发生的改动,不写入文件。")
105
+
106
+ changed = 0
107
+ deleted = 0
108
+ pending = 0
109
+ for row in rows:
110
+ label = row["label"]
111
+ bookmark = row["bookmark"]
112
+ if not bookmark:
113
+ deleted += 1
114
+ log(f"[跳过] {label}:该行没有书签,无法定位")
115
+ continue
116
+ payload = mark_payload_by_bookmark(doc, bookmark)
117
+ if payload is None:
118
+ deleted += 1
119
+ log(f"[跳过] {label} {row['original'][:24]}:Word 中该标记已删除")
120
+ continue
121
+ if not row.get("new_filled", bool(row["new"])) and not row["link"]:
122
+ pending += 1
123
+ warn(f"{label} {row['position']}:新内容与链接地址均未填,保留原样未同步。")
124
+ continue
125
+ p_el, children, runs = payload
126
+ part = mark_parts.get(bookmark, doc.part)
127
+ result = apply_mark_change(
128
+ part, p_el, children, runs, row["new"], row["link"], keep_highlight=keep_highlight, doc=doc
129
+ )
130
+ if result == "deleted":
131
+ deleted += 1
132
+ log(f"[跳过] {label}:标记内容在 Word 中已为空")
133
+ elif result == "changed":
134
+ changed += 1
135
+ detail = row["new"] if row["new"] else "(文字不变)"
136
+ extra = f",链接 → {row['link']}" if row["link"] else ""
137
+ log(f"[标记] {label} {row['position']}:{row['original'][:20]} → {detail}{extra}")
138
+
139
+ log(
140
+ f"合计:同步 {changed} 处标记"
141
+ + (f",跳过 {deleted} 处(已删除/无书签)" if deleted else "")
142
+ + (f",待填写 {pending} 处(新内容与链接地址均为空)" if pending else "")
143
+ + "。"
144
+ )
145
+
146
+ if args.dry_run:
147
+ log("预演结束,未写入任何文件。")
148
+ return 0
149
+ if not changed:
150
+ log("标注表与 Word 内容一致,未做任何写入。")
151
+ return 0
152
+ if getattr(args, "_skip_save", False):
153
+ args._marks_changed = True
154
+ return 0
155
+ backups = save_docx_xlsx_transaction(
156
+ docx_path=docx_path, doc=doc, backup=getattr(args, "backup", True),
157
+ )
158
+ backup = backups.get(docx_path)
159
+ log(f"[标记] 已保存 {docx_path.name}" + (f"(原文件已备份:{backup.name})" if backup else ""))
160
+ return 0
@@ -0,0 +1,92 @@
1
+ """placeholders / placeholders-sync 子命令:{字段名} 骨架导出到「正文信息」表、填值写回 Word。"""
2
+
3
+ import docx
4
+
5
+ from ..console import log, warn
6
+ from ..docx_placeholders import (
7
+ VALUES_SHEET,
8
+ apply_placeholders,
9
+ read_placeholder_values,
10
+ scan_placeholders,
11
+ write_placeholder_sheet,
12
+ )
13
+ from ..errors import SyncError
14
+ from ..fsops import check_file_free, resolve_docx, resolve_xlsx, save_docx_xlsx_transaction
15
+
16
+
17
+ def cmd_placeholders(args) -> int:
18
+ """按当前 Word 的 {字段名} 给工作簿「正文信息」表补齐骨架(保留已填值)。"""
19
+ docx_path = resolve_docx(args.docx)
20
+ xlsx_path = resolve_xlsx(docx_path, args.excel)
21
+ if not xlsx_path.exists():
22
+ raise SyncError(
23
+ f"找不到工作簿:{xlsx_path}\n请先执行「导出表格到 Excel」(界面上“导出/刷新占位符”会确认后自动先导出)。"
24
+ )
25
+ if not args.dry_run:
26
+ check_file_free(xlsx_path, args.force)
27
+ doc = getattr(args, "_doc", None) or docx.Document(str(docx_path))
28
+ fields = scan_placeholders(doc)
29
+ log(f"读取 Word:{docx_path.name}")
30
+ if not fields:
31
+ log("Word 中没有 {字段名} 占位符,无需生成「正文信息」表。")
32
+ return 0
33
+ log(f"发现占位符 {len(fields)} 个字段:{'、'.join(fields)}")
34
+ if args.dry_run:
35
+ log("预演模式(--dry-run):以上字段将加入/补齐「正文信息」表,未写入任何文件。")
36
+ return 0
37
+ added = write_placeholder_sheet(xlsx_path, fields, backup=getattr(args, "backup", True))
38
+ log(
39
+ f"[占位符] 「{VALUES_SHEET}」表已就绪({len(fields)} 个字段"
40
+ + (f",本次新增 {len(added)} 个" if added else ",无新增字段")
41
+ + "),已填值保留;请在 B 列填值后执行「同步占位符」。"
42
+ )
43
+ return 0
44
+
45
+
46
+ def cmd_placeholders_sync(args) -> int:
47
+ """把「正文信息」表填好的值写回当前 Word 的占位符;未填字段保留原样并逐条警告。"""
48
+ docx_path = resolve_docx(args.docx)
49
+ xlsx_path = resolve_xlsx(docx_path, args.excel)
50
+ if not xlsx_path.exists():
51
+ raise SyncError(f"找不到工作簿:{xlsx_path}\n请先执行「导出表格到 Excel」或「导出/刷新占位符」。")
52
+ if not args.dry_run:
53
+ check_file_free(docx_path, args.force)
54
+ check_file_free(xlsx_path, args.force)
55
+ values = getattr(args, "values", None)
56
+ if values is None:
57
+ values = read_placeholder_values(xlsx_path, zero_mode=getattr(args, "placeholder_zero", "excel"))
58
+ doc = getattr(args, "_doc", None) or docx.Document(str(docx_path))
59
+ fields = scan_placeholders(doc)
60
+ log(f"读取 Word:{docx_path.name}")
61
+ if not fields:
62
+ log("Word 中没有 {字段名} 占位符,无需同步。")
63
+ return 0
64
+ if not values:
65
+ raise SyncError(
66
+ f"工作簿没有「{VALUES_SHEET}」表或表里没填任何值,请先执行「导出/刷新占位符」并在 B 列填值。"
67
+ )
68
+ result = apply_placeholders(doc, values, dry_run=args.dry_run)
69
+ for field, new in result["replaced"]:
70
+ log(f"[占位符] {{{field}}} → {new}")
71
+ for field in result["missing"]:
72
+ warn(f"占位符 {{{field}}} 在「{VALUES_SHEET}」表未填值,保留原样未同步。")
73
+ log(
74
+ f"合计:替换 {len(result['replaced'])} 处占位符"
75
+ + (f",未填保留原样 {len(result['missing'])} 处" if result["missing"] else "")
76
+ + "。"
77
+ )
78
+ if args.dry_run:
79
+ log("预演结束,未写入任何文件。")
80
+ return 0
81
+ if not result["replaced"]:
82
+ log("没有可替换的占位符,未做任何写入。")
83
+ return 0
84
+ if getattr(args, "_skip_save", False):
85
+ args._placeholder_changed = bool(result["replaced"])
86
+ return 0
87
+ backups = save_docx_xlsx_transaction(
88
+ docx_path=docx_path, doc=doc, backup=getattr(args, "backup", True),
89
+ )
90
+ backup = backups.get(docx_path)
91
+ log(f"[占位符] 已保存 {docx_path.name}" + (f"(原文件已备份:{backup.name})" if backup else ""))
92
+ return 0