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.
- package/LICENSE +21 -0
- package/README.md +152 -3
- package/cordis.patch.yml +3 -0
- package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
- package/dsh_plugins/audit-e2w/lib/index.js +122 -0
- package/dsh_plugins/audit-e2w/lib/skill.js +42 -0
- package/excel_word/README.md +388 -0
- package/excel_word/qoder_engine.py +437 -0
- package/excel_word/requirements.txt +4 -0
- package/excel_word/wesync/__init__.py +19 -0
- package/excel_word/wesync/__main__.py +6 -0
- package/excel_word/wesync/ai/__init__.py +52 -0
- package/excel_word/wesync/ai/actions.py +369 -0
- package/excel_word/wesync/ai/client.py +340 -0
- package/excel_word/wesync/ai/config.py +291 -0
- package/excel_word/wesync/ai/docs.py +177 -0
- package/excel_word/wesync/ai/prompts.py +288 -0
- package/excel_word/wesync/ai/tasks/__init__.py +26 -0
- package/excel_word/wesync/ai/tasks/actions_task.py +97 -0
- package/excel_word/wesync/ai/tasks/combined.py +123 -0
- package/excel_word/wesync/ai/tasks/diff_note.py +61 -0
- package/excel_word/wesync/ai/tasks/headings.py +119 -0
- package/excel_word/wesync/ai/tasks/help_task.py +69 -0
- package/excel_word/wesync/ai/tasks/roles.py +128 -0
- package/excel_word/wesync/align.py +155 -0
- package/excel_word/wesync/api.py +1292 -0
- package/excel_word/wesync/backup_history.py +100 -0
- package/excel_word/wesync/changelog.py +58 -0
- package/excel_word/wesync/cli.py +191 -0
- package/excel_word/wesync/commands/__init__.py +8 -0
- package/excel_word/wesync/commands/blank_cmd.py +279 -0
- package/excel_word/wesync/commands/bookmark_cmd.py +146 -0
- package/excel_word/wesync/commands/clear_cmd.py +50 -0
- package/excel_word/wesync/commands/export_cmd.py +270 -0
- package/excel_word/wesync/commands/incremental_cmd.py +157 -0
- package/excel_word/wesync/commands/marks_cmd.py +160 -0
- package/excel_word/wesync/commands/placeholders_cmd.py +92 -0
- package/excel_word/wesync/commands/writeback_cmd.py +469 -0
- package/excel_word/wesync/config.py +97 -0
- package/excel_word/wesync/console.py +85 -0
- package/excel_word/wesync/docx_blank.py +156 -0
- package/excel_word/wesync/docx_bookmarks.py +294 -0
- package/excel_word/wesync/docx_columns.py +257 -0
- package/excel_word/wesync/docx_edit.py +77 -0
- package/excel_word/wesync/docx_grid.py +212 -0
- package/excel_word/wesync/docx_marks.py +399 -0
- package/excel_word/wesync/docx_meta.py +157 -0
- package/excel_word/wesync/docx_newtable.py +220 -0
- package/excel_word/wesync/docx_placeholders.py +200 -0
- package/excel_word/wesync/docx_rows.py +67 -0
- package/excel_word/wesync/errors.py +5 -0
- package/excel_word/wesync/excel_blocks.py +502 -0
- package/excel_word/wesync/excel_export.py +143 -0
- package/excel_word/wesync/excel_marks.py +265 -0
- package/excel_word/wesync/excel_totals.py +53 -0
- package/excel_word/wesync/fsops.py +219 -0
- package/excel_word/wesync/gui/__init__.py +53 -0
- package/excel_word/wesync/gui/__main__.py +6 -0
- package/excel_word/wesync/gui/app.py +613 -0
- package/excel_word/wesync/gui/manual.py +70 -0
- package/excel_word/wesync/gui/pages/__init__.py +80 -0
- package/excel_word/wesync/gui/pages/_page.py +211 -0
- package/excel_word/wesync/gui/pages/ai_page.py +854 -0
- package/excel_word/wesync/gui/pages/batch_page.py +456 -0
- package/excel_word/wesync/gui/pages/blank_page.py +530 -0
- package/excel_word/wesync/gui/pages/bookmark_page.py +97 -0
- package/excel_word/wesync/gui/pages/export_page.py +141 -0
- package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
- package/excel_word/wesync/gui/pages/format_page.py +551 -0
- package/excel_word/wesync/gui/pages/help_page.py +158 -0
- package/excel_word/wesync/gui/pages/history_page.py +168 -0
- package/excel_word/wesync/gui/pages/marks_page.py +211 -0
- package/excel_word/wesync/gui/pages/settings_page.py +450 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +473 -0
- package/excel_word/wesync/gui/resources.py +22 -0
- package/excel_word/wesync/gui/runner.py +90 -0
- package/excel_word/wesync/gui/store.py +50 -0
- package/excel_word/wesync/gui/theme.py +271 -0
- package/excel_word/wesync/gui/widgets/__init__.py +8 -0
- package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
- package/excel_word/wesync/gui/widgets/cards.py +139 -0
- package/excel_word/wesync/gui/widgets/chips.py +565 -0
- package/excel_word/wesync/gui/widgets/filebar.py +58 -0
- package/excel_word/wesync/gui/widgets/logpane.py +126 -0
- package/excel_word/wesync/gui/widgets/nav.py +294 -0
- package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
- package/excel_word/wesync/report_format.py +1585 -0
- package/excel_word/wesync/settings.py +35 -0
- package/excel_word/wesync/sort_rules.py +293 -0
- package/excel_word/wesync/valuefmt.py +485 -0
- package/package.json +53 -6
- package/packaging//344/275/277/347/224/250/350/257/264/346/230/216.txt +247 -0
- package/qoder_plugins/audit-toolbox/README.md +159 -0
- package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
"""Qoder 插件无窗口引擎:从 stdin 读 JSON 请求,向 stdout 输出 JSONL 日志与结果。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import contextlib
|
|
6
|
+
import datetime as dt
|
|
7
|
+
import io
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from wesync import __version__, api
|
|
13
|
+
from wesync.console import reset_log_state, set_log_sink
|
|
14
|
+
from wesync.errors import SyncError
|
|
15
|
+
|
|
16
|
+
QUERY_OPERATIONS = {
|
|
17
|
+
"blank-scan", "deleted-list", "blank-batch-scan", "diff", "table-list",
|
|
18
|
+
"sort-list", "template-scan", "backup-list", "format-scan",
|
|
19
|
+
"format-heading-candidates",
|
|
20
|
+
}
|
|
21
|
+
RUN_OPERATIONS = {
|
|
22
|
+
"export", "writeback", "bookmark", "rejudge", "clear-bookmarks", "marks",
|
|
23
|
+
"marks-sync", "placeholders", "placeholders-sync", "blank-delete",
|
|
24
|
+
"restore-tables", "blank-batch-delete", "diff-export", "incremental-export",
|
|
25
|
+
"sort-set", "sort-clear", "batch-writeback", "template-batch",
|
|
26
|
+
"fill-placeholders", "backup-restore", "format-apply",
|
|
27
|
+
}
|
|
28
|
+
DRY_RUN_OPERATIONS = {
|
|
29
|
+
"export", "writeback", "bookmark", "rejudge", "clear-bookmarks", "marks",
|
|
30
|
+
"marks-sync", "placeholders", "placeholders-sync", "blank-delete",
|
|
31
|
+
"restore-tables", "blank-batch-delete", "batch-writeback", "template-batch", "incremental-export",
|
|
32
|
+
"format-apply",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _emit(request_id: str, kind: str, **payload) -> None:
|
|
37
|
+
message = {"id": request_id, "type": kind, **payload}
|
|
38
|
+
data = (json.dumps(message, ensure_ascii=False) + "\n").encode("utf-8")
|
|
39
|
+
sys.stdout.buffer.write(data)
|
|
40
|
+
sys.stdout.buffer.flush()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _required_path(request: dict, key: str, suffixes: tuple[str, ...]) -> str:
|
|
44
|
+
value = request.get(key)
|
|
45
|
+
if not isinstance(value, str) or not value.strip():
|
|
46
|
+
raise SyncError(f"缺少{key}路径")
|
|
47
|
+
value = value.strip()
|
|
48
|
+
if any(ord(ch) < 32 for ch in value):
|
|
49
|
+
raise SyncError(f"{key}路径含有控制字符")
|
|
50
|
+
path = Path(value).expanduser()
|
|
51
|
+
if not path.is_absolute():
|
|
52
|
+
raise SyncError(f"{key}必须使用绝对路径")
|
|
53
|
+
if suffixes and path.suffix.lower() not in suffixes:
|
|
54
|
+
raise SyncError(f"{key}只支持 {'/'.join(suffixes)} 文件")
|
|
55
|
+
return str(path)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _optional_path(request: dict, key: str, suffixes: tuple[str, ...]) -> str | None:
|
|
59
|
+
value = request.get(key)
|
|
60
|
+
if value in (None, ""):
|
|
61
|
+
return None
|
|
62
|
+
return _required_path(request, key, suffixes)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _path_list(request: dict, key: str, suffixes: tuple[str, ...]) -> list[str]:
|
|
66
|
+
values = request.get(key)
|
|
67
|
+
if not isinstance(values, list) or not values:
|
|
68
|
+
raise SyncError(f"请至少选择一个{key}文件")
|
|
69
|
+
if len(values) > 200:
|
|
70
|
+
raise SyncError(f"{key}一次最多处理 200 个文件")
|
|
71
|
+
result = []
|
|
72
|
+
for value in values:
|
|
73
|
+
if not isinstance(value, str):
|
|
74
|
+
raise SyncError(f"{key}必须是路径数组")
|
|
75
|
+
result.append(_required_path({key: value}, key, suffixes))
|
|
76
|
+
return result
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _text(request: dict, key: str, label: str) -> str:
|
|
80
|
+
value = request.get(key)
|
|
81
|
+
if not isinstance(value, str) or not value.strip():
|
|
82
|
+
raise SyncError(f"请填写{label}")
|
|
83
|
+
return value.strip()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _flag(request: dict, key: str, default: bool = False) -> bool:
|
|
87
|
+
value = request.get(key, default)
|
|
88
|
+
if not isinstance(value, bool):
|
|
89
|
+
raise SyncError(f"{key}必须是布尔值")
|
|
90
|
+
return value
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _integer(request: dict, key: str, label: str, minimum: int, maximum: int) -> int:
|
|
94
|
+
value = request.get(key)
|
|
95
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
96
|
+
raise SyncError(f"{label}必须是整数")
|
|
97
|
+
if not minimum <= value <= maximum:
|
|
98
|
+
raise SyncError(f"{label}必须在 {minimum}~{maximum} 之间")
|
|
99
|
+
return value
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _contents(request: dict, default: tuple[str, ...]) -> tuple[str, ...]:
|
|
103
|
+
raw = request.get("contents") or {}
|
|
104
|
+
if not isinstance(raw, dict):
|
|
105
|
+
raise SyncError("同步内容格式不正确")
|
|
106
|
+
selected = tuple(name for name in ("tables", "marks", "placeholders") if raw.get(name, name in default))
|
|
107
|
+
if not selected:
|
|
108
|
+
raise SyncError("同步内容至少勾选一项")
|
|
109
|
+
return selected
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _jsonable(value):
|
|
113
|
+
if isinstance(value, Path):
|
|
114
|
+
return str(value)
|
|
115
|
+
if isinstance(value, (dt.datetime, dt.date, dt.time)):
|
|
116
|
+
return value.isoformat()
|
|
117
|
+
if isinstance(value, dict):
|
|
118
|
+
return {str(key): _jsonable(item) for key, item in value.items()}
|
|
119
|
+
if isinstance(value, (list, tuple)):
|
|
120
|
+
return [_jsonable(item) for item in value]
|
|
121
|
+
if isinstance(value, set):
|
|
122
|
+
return [_jsonable(item) for item in sorted(value, key=str)]
|
|
123
|
+
if value is None or isinstance(value, (str, int, float, bool)):
|
|
124
|
+
return value
|
|
125
|
+
return str(value)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _blank_candidates(items: list[dict]) -> list[dict]:
|
|
129
|
+
keys = ("no", "index", "code", "kind", "nrows", "ncols", "caption_text")
|
|
130
|
+
return [{key: item.get(key) for key in keys} for item in items]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _template_items(request: dict, template_count: int) -> list[dict]:
|
|
134
|
+
raw = request.get("items")
|
|
135
|
+
if not isinstance(raw, list) or not raw:
|
|
136
|
+
raise SyncError("请至少添加一个 Excel 工作簿")
|
|
137
|
+
if len(raw) > 200:
|
|
138
|
+
raise SyncError("一次最多生成 200 份报告")
|
|
139
|
+
result = []
|
|
140
|
+
for item in raw:
|
|
141
|
+
if not isinstance(item, dict):
|
|
142
|
+
raise SyncError("模板清单格式不正确")
|
|
143
|
+
excel = _required_path(item, "excel", (".xlsx", ".xlsm"))
|
|
144
|
+
template = item.get("template")
|
|
145
|
+
if isinstance(template, bool) or not isinstance(template, int) or not 1 <= template <= template_count:
|
|
146
|
+
raise SyncError("请为每个工作簿选择有效的所属模板")
|
|
147
|
+
result.append({"excel": excel, "template": template})
|
|
148
|
+
return result
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _blank_batch_items(request: dict) -> list[dict]:
|
|
152
|
+
raw = request.get("items")
|
|
153
|
+
if not isinstance(raw, list) or not raw:
|
|
154
|
+
raise SyncError("请先批量扫描并勾选要删除的空白表格")
|
|
155
|
+
if len(raw) > 200:
|
|
156
|
+
raise SyncError("一次最多处理 200 份报告")
|
|
157
|
+
result = []
|
|
158
|
+
for item in raw:
|
|
159
|
+
if not isinstance(item, dict):
|
|
160
|
+
raise SyncError("批量删除清单格式不正确")
|
|
161
|
+
docx = _required_path(item, "docx", (".docx", ".docm"))
|
|
162
|
+
pick = _text(item, "pick", "候选编号")
|
|
163
|
+
keep_for = item.get("keepCaptionFor")
|
|
164
|
+
if keep_for is not None and not isinstance(keep_for, str):
|
|
165
|
+
raise SyncError("保留标题编号必须是文本")
|
|
166
|
+
excel = _optional_path(item, "excel", (".xlsx", ".xlsm"))
|
|
167
|
+
reversible = item.get("reversible", True)
|
|
168
|
+
if not isinstance(reversible, bool):
|
|
169
|
+
raise SyncError("reversible 必须是布尔值")
|
|
170
|
+
result.append({
|
|
171
|
+
"docx": docx,
|
|
172
|
+
"pick": pick,
|
|
173
|
+
"keep_caption_for": keep_for,
|
|
174
|
+
"reversible": reversible,
|
|
175
|
+
"excel": excel,
|
|
176
|
+
})
|
|
177
|
+
return result
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _format_args(request: dict) -> dict:
|
|
181
|
+
profile_name = request.get("profileName")
|
|
182
|
+
if profile_name is not None and (not isinstance(profile_name, str) or not profile_name.strip()):
|
|
183
|
+
raise SyncError("profileName 必须是非空文本")
|
|
184
|
+
levels = request.get("headingLevels")
|
|
185
|
+
if levels is not None:
|
|
186
|
+
if not isinstance(levels, dict) or len(levels) > 300:
|
|
187
|
+
raise SyncError("headingLevels 必须是候选编号到 1~4 级标题的映射,且最多 300 项")
|
|
188
|
+
if any(not isinstance(key, str) or type(value) is not int or not 1 <= value <= 4 for key, value in levels.items()):
|
|
189
|
+
raise SyncError("headingLevels 的级别必须是 1~4 的整数")
|
|
190
|
+
batch_id = request.get("headingBatchId")
|
|
191
|
+
if batch_id is not None and (not isinstance(batch_id, str) or not batch_id):
|
|
192
|
+
raise SyncError("headingBatchId 必须是非空文本")
|
|
193
|
+
role_batch_id = request.get("roleBatchId")
|
|
194
|
+
if role_batch_id is not None and (not isinstance(role_batch_id, str) or not role_batch_id):
|
|
195
|
+
raise SyncError("roleBatchId 必须是非空文本")
|
|
196
|
+
role_overrides = request.get("roleOverrides")
|
|
197
|
+
if role_overrides is not None:
|
|
198
|
+
if not isinstance(role_overrides, dict) or len(role_overrides) > 300:
|
|
199
|
+
raise SyncError("roleOverrides 必须是最多 300 项的疑难角色映射")
|
|
200
|
+
if any(not isinstance(key, str) or value not in ("body", "table_title") for key, value in role_overrides.items()):
|
|
201
|
+
raise SyncError("roleOverrides 的角色只能是 body 或 table_title")
|
|
202
|
+
region_start_id = request.get("regionStartId")
|
|
203
|
+
if region_start_id is not None and (not isinstance(region_start_id, str) or not region_start_id):
|
|
204
|
+
raise SyncError("regionStartId 必须是非空文本")
|
|
205
|
+
return {
|
|
206
|
+
"template": _optional_path(request, "template", (".docx", ".docm")),
|
|
207
|
+
"profile_name": profile_name.strip() if profile_name is not None else None,
|
|
208
|
+
"scope": request.get("scope"),
|
|
209
|
+
"heading_batch_id": batch_id,
|
|
210
|
+
"heading_levels": levels,
|
|
211
|
+
"role_batch_id": role_batch_id,
|
|
212
|
+
"role_overrides": role_overrides,
|
|
213
|
+
"region_start_id": region_start_id,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _dispatch(request: dict):
|
|
218
|
+
operation = request["operation"]
|
|
219
|
+
docx = _optional_path(request, "docx", (".docx", ".docm"))
|
|
220
|
+
excel = _optional_path(request, "excel", (".xlsx", ".xlsm"))
|
|
221
|
+
dry_run = _flag(request, "dryRun")
|
|
222
|
+
force = _flag(request, "force")
|
|
223
|
+
if dry_run and operation not in DRY_RUN_OPERATIONS:
|
|
224
|
+
raise SyncError("该操作不支持预演")
|
|
225
|
+
if operation in RUN_OPERATIONS and not dry_run and not _flag(request, "confirmed"):
|
|
226
|
+
raise SyncError("正式写盘前必须取得用户确认,并传 confirmed=true")
|
|
227
|
+
|
|
228
|
+
if operation in QUERY_OPERATIONS:
|
|
229
|
+
if operation == "blank-scan":
|
|
230
|
+
return _blank_candidates(api.scan_blank_tables(_required_path(request, "docx", (".docx", ".docm"))))
|
|
231
|
+
if operation == "deleted-list":
|
|
232
|
+
return api.list_deleted_blocks(_required_path(request, "docx", (".docx", ".docm")), excel)
|
|
233
|
+
if operation == "blank-batch-scan":
|
|
234
|
+
results = api.scan_blank_batch(_path_list(request, "paths", (".docx", ".docm")))
|
|
235
|
+
for item in results:
|
|
236
|
+
item["candidates"] = _blank_candidates(item.get("candidates", []))
|
|
237
|
+
return results
|
|
238
|
+
if operation == "diff":
|
|
239
|
+
return api.scan_writeback_diff(_required_path(request, "docx", (".docx", ".docm")), excel)
|
|
240
|
+
if operation == "table-list":
|
|
241
|
+
return api.list_table_blocks(_required_path(request, "docx", (".docx", ".docm")), excel)
|
|
242
|
+
if operation == "sort-list":
|
|
243
|
+
return api.list_table_sorts(_required_path(request, "docx", (".docx", ".docm")), excel)
|
|
244
|
+
if operation == "template-scan":
|
|
245
|
+
return api.scan_template_placeholders(_required_path(request, "docx", (".docx", ".docm")))
|
|
246
|
+
if operation == "backup-list":
|
|
247
|
+
return api.scan_backups(_required_path(request, "docx", (".docx", ".docm")), excel)
|
|
248
|
+
if operation == "format-heading-candidates":
|
|
249
|
+
return api.scan_format_heading_candidates(_required_path(request, "docx", (".docx", ".docm")))
|
|
250
|
+
if operation == "format-scan":
|
|
251
|
+
return api.scan_report_format(
|
|
252
|
+
_required_path(request, "docx", (".docx", ".docm")),
|
|
253
|
+
**_format_args(request),
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
if operation == "format-apply":
|
|
257
|
+
return api.run_report_format(
|
|
258
|
+
_required_path(request, "docx", (".docx", ".docm")),
|
|
259
|
+
output=_optional_path(request, "output", (".docx", ".docm")),
|
|
260
|
+
dry_run=dry_run,
|
|
261
|
+
**_format_args(request),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
if operation == "backup-restore":
|
|
265
|
+
backup = _required_path(request, "backupPath", (".docx", ".docm", ".xlsx", ".xlsm"))
|
|
266
|
+
target = _required_path(request, "target", (".docx", ".docm", ".xlsx", ".xlsm"))
|
|
267
|
+
if Path(backup).suffix.lower() != Path(target).suffix.lower():
|
|
268
|
+
raise SyncError("备份文件与目标文件类型必须一致")
|
|
269
|
+
return api.run_restore_backup(backup, target)
|
|
270
|
+
|
|
271
|
+
if operation == "template-batch":
|
|
272
|
+
templates = _path_list(request, "templates", (".docx", ".docm"))
|
|
273
|
+
items = _template_items(request, len(templates))
|
|
274
|
+
out_dir = _required_path(request, "outDir", ())
|
|
275
|
+
return api.run_template_batch(
|
|
276
|
+
templates,
|
|
277
|
+
items,
|
|
278
|
+
out_dir,
|
|
279
|
+
dry_run=dry_run,
|
|
280
|
+
contents=_contents(request, ("tables", "placeholders")),
|
|
281
|
+
keep_highlight=_flag(request, "keepHighlight", True),
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
if operation == "fill-placeholders":
|
|
285
|
+
template = _required_path(request, "docx", (".docx", ".docm"))
|
|
286
|
+
return api.fill_placeholder_sheets(template, _path_list(request, "paths", (".xlsx", ".xlsm")))
|
|
287
|
+
|
|
288
|
+
if operation == "blank-batch-delete":
|
|
289
|
+
return api.run_blank_batch(_blank_batch_items(request), dry_run=dry_run, force=force)
|
|
290
|
+
|
|
291
|
+
if operation == "batch-writeback":
|
|
292
|
+
return api.run_batch_writeback(
|
|
293
|
+
_path_list(request, "paths", (".docx", ".docm")),
|
|
294
|
+
dry_run=dry_run,
|
|
295
|
+
backup=_flag(request, "backup", True),
|
|
296
|
+
force=force,
|
|
297
|
+
contents=_contents(request, ("tables",)),
|
|
298
|
+
keep_highlight=_flag(request, "keepHighlight", True),
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
if docx is None:
|
|
302
|
+
raise SyncError("缺少 docx 路径")
|
|
303
|
+
backup = _flag(request, "backup", not _flag(request, "noBackup"))
|
|
304
|
+
if operation == "export":
|
|
305
|
+
return api.run_export(
|
|
306
|
+
docx, excel, dry_run=dry_run, force=force,
|
|
307
|
+
with_excel_links=_flag(request, "withExcelLinks", True),
|
|
308
|
+
totals_formula=_flag(request, "totalsFormula", True), backup=backup,
|
|
309
|
+
)
|
|
310
|
+
if operation == "writeback":
|
|
311
|
+
contents = request.get("contents") or {"tables": True, "marks": False, "placeholders": False}
|
|
312
|
+
return api.run_sync_content(
|
|
313
|
+
docx, excel,
|
|
314
|
+
tables=_flag(contents, "tables", True),
|
|
315
|
+
marks=_flag(contents, "marks"),
|
|
316
|
+
placeholders=_flag(contents, "placeholders"),
|
|
317
|
+
keep_highlight=_flag(contents, "keepHighlight", True),
|
|
318
|
+
dry_run=dry_run, force=force, backup=backup,
|
|
319
|
+
changelog=_flag(request, "changelog"),
|
|
320
|
+
delete_empty_rows=_flag(request, "deleteEmptyRows"),
|
|
321
|
+
)
|
|
322
|
+
if operation == "bookmark":
|
|
323
|
+
return api.run_bookmark(
|
|
324
|
+
docx, excel, dry_run=dry_run, force=force,
|
|
325
|
+
with_excel_links=_flag(request, "withExcelLinks", True),
|
|
326
|
+
)
|
|
327
|
+
if operation == "rejudge":
|
|
328
|
+
return api.run_rejudge(docx, excel, dry_run=dry_run, force=force, backup=backup)
|
|
329
|
+
if operation == "clear-bookmarks":
|
|
330
|
+
return api.run_clear_bookmarks(docx, dry_run=dry_run, force=force)
|
|
331
|
+
if operation == "marks":
|
|
332
|
+
return api.run_marks(docx, excel, dry_run=dry_run, force=force)
|
|
333
|
+
if operation == "marks-sync":
|
|
334
|
+
return api.run_marks_sync(
|
|
335
|
+
docx, excel, dry_run=dry_run, force=force,
|
|
336
|
+
keep_highlight=_flag(request, "keepHighlight"),
|
|
337
|
+
)
|
|
338
|
+
if operation == "placeholders":
|
|
339
|
+
return api.run_placeholder_export(docx, excel, dry_run=dry_run, force=force)
|
|
340
|
+
if operation == "placeholders-sync":
|
|
341
|
+
return api.run_placeholder_sync(docx, excel, dry_run=dry_run, force=force)
|
|
342
|
+
if operation == "blank-delete":
|
|
343
|
+
return api.run_blank_tables(
|
|
344
|
+
docx, dry_run=dry_run, force=force,
|
|
345
|
+
pick=_text(request, "pick", "候选编号"),
|
|
346
|
+
keep_caption=_flag(request, "keepCaption"),
|
|
347
|
+
keep_caption_for=request.get("keepCaptionFor"),
|
|
348
|
+
reversible=_flag(request, "reversible", True), excel=excel,
|
|
349
|
+
)
|
|
350
|
+
if operation == "restore-tables":
|
|
351
|
+
return api.run_restore_tables(
|
|
352
|
+
docx, excel, pick=_text(request, "pick", "恢复编号"),
|
|
353
|
+
dry_run=dry_run, force=force,
|
|
354
|
+
)
|
|
355
|
+
if operation == "diff-export":
|
|
356
|
+
records = api.scan_writeback_diff(docx, excel)
|
|
357
|
+
return api.export_diff_report(docx, excel, records)
|
|
358
|
+
if operation == "incremental-export":
|
|
359
|
+
return api.run_incremental_export(
|
|
360
|
+
docx, excel, dry_run=dry_run, force=force,
|
|
361
|
+
with_excel_links=_flag(request, "withExcelLinks", True),
|
|
362
|
+
totals_formula=_flag(request, "totalsFormula", True),
|
|
363
|
+
backup=_flag(request, "backup", True),
|
|
364
|
+
)
|
|
365
|
+
if operation == "sort-set":
|
|
366
|
+
return api.set_table_sort(
|
|
367
|
+
docx, excel,
|
|
368
|
+
code=_text(request, "code", "表块编号"),
|
|
369
|
+
column=_text(request, "column", "排序列"),
|
|
370
|
+
descending=_flag(request, "descending", True),
|
|
371
|
+
)
|
|
372
|
+
if operation == "sort-clear":
|
|
373
|
+
return api.clear_table_sort(docx, excel, code=_text(request, "code", "表块编号"))
|
|
374
|
+
raise SyncError(f"不支持的操作:{operation}")
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def _run(request: dict, request_id: str) -> int:
|
|
378
|
+
operation = request.get("operation")
|
|
379
|
+
if operation == "version":
|
|
380
|
+
_emit(request_id, "result", code=0, version=__version__)
|
|
381
|
+
return 0
|
|
382
|
+
if operation not in QUERY_OPERATIONS | RUN_OPERATIONS:
|
|
383
|
+
_emit(request_id, "log", level="error", message=f"不支持的操作:{operation}")
|
|
384
|
+
_emit(request_id, "result", code=2, operation=str(operation or "unknown"), version=__version__)
|
|
385
|
+
return 2
|
|
386
|
+
|
|
387
|
+
stderr = io.StringIO()
|
|
388
|
+
|
|
389
|
+
def sink(message: str) -> None:
|
|
390
|
+
level = "warning" if message.startswith("警告:") else "info"
|
|
391
|
+
_emit(request_id, "log", level=level, message=message)
|
|
392
|
+
|
|
393
|
+
set_log_sink(sink)
|
|
394
|
+
reset_log_state()
|
|
395
|
+
try:
|
|
396
|
+
with contextlib.redirect_stderr(stderr):
|
|
397
|
+
data = _dispatch(request)
|
|
398
|
+
code = 0
|
|
399
|
+
except (SyncError, OSError, ValueError) as exc:
|
|
400
|
+
_emit(request_id, "log", level="error", message=str(exc))
|
|
401
|
+
data = None
|
|
402
|
+
code = 2
|
|
403
|
+
except Exception as exc:
|
|
404
|
+
_emit(request_id, "log", level="error", message=f"引擎异常:{type(exc).__name__}: {exc}")
|
|
405
|
+
data = None
|
|
406
|
+
code = 2
|
|
407
|
+
finally:
|
|
408
|
+
set_log_sink(None)
|
|
409
|
+
reset_log_state()
|
|
410
|
+
|
|
411
|
+
for line in stderr.getvalue().splitlines():
|
|
412
|
+
if line.strip():
|
|
413
|
+
_emit(request_id, "log", level="error", message=line.strip())
|
|
414
|
+
_emit(request_id, "result", code=int(code), operation=operation, version=__version__, data=_jsonable(data))
|
|
415
|
+
return int(code)
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def main() -> int:
|
|
419
|
+
for raw_line in sys.stdin.buffer:
|
|
420
|
+
line = raw_line.decode("utf-8")
|
|
421
|
+
if not line.strip():
|
|
422
|
+
continue
|
|
423
|
+
try:
|
|
424
|
+
request = json.loads(line)
|
|
425
|
+
if not isinstance(request, dict):
|
|
426
|
+
raise ValueError("请求必须是 JSON 对象")
|
|
427
|
+
request_id = str(request.get("id") or "engine")
|
|
428
|
+
except (ValueError, TypeError) as exc:
|
|
429
|
+
_emit("engine", "log", level="error", message=f"请求格式错误:{exc}")
|
|
430
|
+
_emit("engine", "result", code=2, operation="unknown", version=__version__)
|
|
431
|
+
continue
|
|
432
|
+
_run(request, request_id)
|
|
433
|
+
return 0
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
if __name__ == "__main__":
|
|
437
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Word 表格 ⇄ Excel 双向同步工具(结构化包)。
|
|
2
|
+
|
|
3
|
+
模块职责:
|
|
4
|
+
config / errors / console —— 常量、异常、中文日志
|
|
5
|
+
fsops / valuefmt —— 文件操作、数值与公式处理
|
|
6
|
+
docx_* —— Word 侧:网格解析、书签、单元格写入、行列结构
|
|
7
|
+
excel_* —— Excel 侧:导出工作簿、解析表块与元数据
|
|
8
|
+
commands / cli —— 各子命令与命令行入口
|
|
9
|
+
|
|
10
|
+
对外入口:``from wesync import main`` 或 ``python -m wesync.cli <子命令> ...``
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
__version__ = "1.11.7"
|
|
16
|
+
|
|
17
|
+
from .cli import main
|
|
18
|
+
|
|
19
|
+
__all__ = ["main", "__version__"]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""AI 适配层:OpenAI 兼容接口的最小客户端与配置。
|
|
2
|
+
|
|
3
|
+
设计红线(与项目约定一致):
|
|
4
|
+
- 只用标准库 urllib,不新增第三方依赖,不影响打包体积;
|
|
5
|
+
- 默认关闭;未启用时本包不被任何既有代码导入;
|
|
6
|
+
- 只发送本地筛出的候选片段,绝不发送整篇报告、表格单元格或页眉页脚;
|
|
7
|
+
- 只产出"判断结果",写盘仍由 commands/* 完成,AI 不直接改文件;
|
|
8
|
+
- 任何失败(网络、超时、返回格式错)都降级为本地规则,不阻塞主流程。
|
|
9
|
+
|
|
10
|
+
本文件刻意采用惰性导出:仅 `import wesync.ai` 不会拉入 client(urllib)
|
|
11
|
+
或 tasks,保证「AI 关闭」路径只付出读一个 JSON 的代价。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
_LAZY = {
|
|
17
|
+
"AiError": ("client", "AiError"),
|
|
18
|
+
"ChatClient": ("client", "ChatClient"),
|
|
19
|
+
"ChatResult": ("client", "ChatResult"),
|
|
20
|
+
"chat": ("client", "chat"),
|
|
21
|
+
"list_models": ("client", "list_models"),
|
|
22
|
+
"parse_json_block": ("client", "parse_json_block"),
|
|
23
|
+
"AI_CONFIG_NAME": ("config", "AI_CONFIG_NAME"),
|
|
24
|
+
"AiConfigError": ("config", "AiConfigError"),
|
|
25
|
+
"DEFAULT_AI": ("config", "DEFAULT_AI"),
|
|
26
|
+
"PROVIDERS": ("config", "PROVIDERS"),
|
|
27
|
+
"load_ai_config": ("config", "load_ai_config"),
|
|
28
|
+
"mask_key": ("config", "mask_key"),
|
|
29
|
+
"normalize_ai": ("config", "normalize_ai"),
|
|
30
|
+
"resolve_api_key": ("config", "resolve_api_key"),
|
|
31
|
+
"save_ai_config": ("config", "save_ai_config"),
|
|
32
|
+
"save_api_key": ("config", "save_api_key"),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
__all__ = sorted(_LAZY)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def __getattr__(name: str):
|
|
39
|
+
"""按需导入子模块,避免导入包时加载 urllib 与任务代码。"""
|
|
40
|
+
target = _LAZY.get(name)
|
|
41
|
+
if target is None:
|
|
42
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
43
|
+
import importlib
|
|
44
|
+
|
|
45
|
+
module = importlib.import_module(f".{target[0]}", __name__)
|
|
46
|
+
value = getattr(module, target[1])
|
|
47
|
+
globals()[name] = value
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def __dir__():
|
|
52
|
+
return sorted(set(globals()) | set(_LAZY))
|