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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xymlg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Audit_E2W
2
+
3
+ 让 Agent 按你的指令处理本机 Word / Excel 审计文档:从 Word 提取表格、标注和正文占位符,在 Excel 中修改,再同步回 Word;也支持空白表格处理、差异检查、排序、批量报告和备份恢复。
4
+
5
+ 当前版本:**1.11.7**。仅支持 **Windows 10/11 64 位**,不支持 macOS。
6
+
7
+ ## 能做什么
8
+
9
+ - **Word → Excel**:导出表格;只要表格、链接标注、正文占位符任意一种存在就导出,并创建三个工作表。
10
+ - **Excel → Word**:同步单元格、行列结构、标注、正文占位符及数值显示格式;同步前可检查差异。
11
+ - **表格维护**:重建书签、重新判定表块、增量导出、设置或清除排序。
12
+ - **空白表格**:扫描、删除、查看已删除表块、恢复;支持批量处理。
13
+ - **批量办公**:批量同步、单模板批量生成报告、批量填写占位符。
14
+ - **安全回退**:修改前备份,可查看备份历史并恢复;预演不写文件,危险操作需确认。
15
+ - **AI 助手(可选,默认关闭)**:可接入任意 OpenAI 兼容接口(云端或本机 Ollama / LM Studio / Magpie)。提供四项能力:① 判标题级别与疑难段落角色,一键填入「一键调整格式」;② 把差异清单写成中文复核说明;③ **AI 对话助手**——用自然语言描述任务,AI 翻译成工具操作,写操作先预演、你确认后才执行;④ **使用说明问答**——依据内置说明书回答"怎么用"。模型名可从「获取模型列表」实时拉取,避免预设过期。**不启用时所有功能与原来完全一致**:不加载 AI 模块、不联网、不写新文件;AI 只产出建议或经白名单校验的操作,写盘仍由原命令完成。
16
+
17
+ ## 三种使用方式
18
+
19
+ | 方式 | 适用场景 | 需要什么 |
20
+ | --- | --- | --- |
21
+ | Windows 图形界面 | 直接手工操作 | Python 源码环境,或已构建的 Windows 程序 |
22
+ | Qoder 插件 | 在 Qoder 中用自然语言指挥 Agent,并提供操作界面 | Qoder Desktop、Windows 版引擎 |
23
+ | DSH 完整插件 | 在 DSH 中用自然语言指挥 Agent | DSH、Node.js 24.11+、pnpm 10+、Python 3.12+ |
24
+ | WorkBuddy / DSH Skill | 只安装工作流说明,由 Agent 调用本机执行脚本 | 对应 Agent、Windows 版引擎 |
25
+
26
+ ### 1. 源码运行
27
+
28
+ 在项目根目录安装依赖并启动图形界面:
29
+
30
+ ```powershell
31
+ uv sync
32
+ .\.venv\Scripts\pythonw.exe .\审计工具箱.pyw
33
+ ```
34
+
35
+ 没有 uv 时,也可使用 Python 3.12+:
36
+
37
+ ```powershell
38
+ python -m venv .venv
39
+ .\.venv\Scripts\python.exe -m pip install -r requirements.txt
40
+ .\.venv\Scripts\pythonw.exe .\审计工具箱.pyw
41
+ ```
42
+
43
+ 命令行示例(在 `excel_word` 目录执行):
44
+
45
+ ```powershell
46
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py export .\报告.docx --dry-run
47
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py export .\报告.docx
48
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py writeback .\报告.docx --dry-run
49
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py writeback .\报告.docx
50
+ ```
51
+
52
+ ### 2. Qoder 插件
53
+
54
+ 源码目录为 `qoder_plugins/audit-toolbox`。构建脚本会把 Windows 引擎、MCP Server、界面和 Skill 打入插件 ZIP:
55
+
56
+ ```powershell
57
+ .\.venv\Scripts\python.exe .\packaging\build_qoder_plugin.py --check-only
58
+ .\.venv\Scripts\python.exe .\packaging\build_qoder_plugin.py
59
+ ```
60
+
61
+ 构建前需要 PyInstaller;产物位于 `dist/qoder_plugins`。Qoder 插件包使用 Qoder 内置 Node.js 运行 MCP Server。构建脚本按 `packaging/build_qoder_plugin.py` 的明确清单复制插件源文件,拒绝链接/junction、客户 Office 文档、锁文件和缓存,并在生成 ZIP 后复核同一清单;`--check-only` 只读核对版本、源树、安装脚本白名单及已有便携版目录,发现版本不一致会直接报错,不修改文件。
62
+
63
+ ### 3. DSH 完整插件
64
+
65
+ 仓库根目录是可安装的 DSH npm bundle,入口声明在 `cordis.patch.yml`,提供四个工具:
66
+
67
+ - `audit_capabilities`:查看 31 个操作及参数。
68
+ - `audit_engine_status`:检查本机引擎和版本。
69
+ - `audit_query`:只读扫描与差异检查。
70
+ - `audit_run`:执行操作;非预演写操作必须经 DSH 用户审批。
71
+
72
+ 安装包优先使用 `AUDIT_TOOLBOX_ENGINE` 指定的 Windows 引擎,其次使用包内 `engine/审计工具箱引擎.exe`,最后使用 Python 源码引擎。公开 npm/GitHub 包**不附带 Windows exe**,因此源码方式需要先安装 Python 依赖:
73
+
74
+ ```powershell
75
+ py -3.12 -m venv .venv
76
+ .\.venv\Scripts\python.exe -m pip install python-docx==1.2.0 openpyxl==3.1.5 lxml==6.1.1
77
+ ```
78
+
79
+ 可通过 `AUDIT_TOOLBOX_PYTHON` 指定解释器的绝对路径。插件与引擎版本不一致时会拒绝执行,不会静默降级。
80
+
81
+ 安装到 DSH profile(Windows):
82
+
83
+ ```powershell
84
+ npm install -g pnpm@10
85
+ py -3.12 -m venv .venv
86
+ .\.venv\Scripts\python.exe -m pip install python-docx==1.2.0 openpyxl==3.1.5 lxml==6.1.1
87
+ $env:AUDIT_TOOLBOX_PYTHON = (Resolve-Path .\.venv\Scripts\python.exe).Path
88
+
89
+ dsh plugin --profile desktop add github:xymlg/Audit_E2W
90
+ dsh --profile desktop --dump-config
91
+ dsh --profile desktop
92
+ ```
93
+
94
+ `desktop` 可替换为实际 profile 名;`--dump-config` 应显示 `audit-e2w` 配置层。GitHub 安装的是纯 JavaScript 发布入口,不需要构建脚本授权。生产环境建议把安装地址锁定到具体提交,例如 `github:xymlg/Audit_E2W#<commit-sha>`。
95
+
96
+ 开发和打包检查:
97
+
98
+ ```powershell
99
+ npm run check
100
+ npm test
101
+ npm pack --dry-run
102
+ ```
103
+
104
+ ### 4. 通用 Agent Skill
105
+
106
+ `agent_skills/audit-word-excel-workbuddy` 是 WorkBuddy 专用工作流 Skill,只走本地脚本通道;`agent_skills/audit-word-excel` 是 DSH 等 Agent 的通用工作流 Skill。两者都不包含 Windows 引擎二进制,必须配合本机执行脚本或已安装的 Windows 程序使用。
107
+
108
+ ```powershell
109
+ .\.venv\Scripts\python.exe .\packaging\build_agent_skills.py --check-only
110
+ .\.venv\Scripts\python.exe .\packaging\build_agent_skills.py --build-zips
111
+ ```
112
+
113
+ ## 推荐工作流程
114
+
115
+ 1. 让 Agent 先检查引擎状态和文件路径。
116
+ 2. 先预演、扫描或比对差异,不直接写盘。
117
+ 3. 说明将修改或生成哪些文件。
118
+ 4. 获得确认后执行;写操作通过宿主审批或由用户明确授权。
119
+ 5. 核对结果、警告和部分失败项;必要时从备份恢复。
120
+
121
+ 示例:
122
+
123
+ > 先检查引擎状态,然后对 `D:\工作\报告.docx` 执行导出预演,告诉我会生成哪些工作表和文件,不要写盘。
124
+
125
+ > 对 `D:\工作\报告.docx` 和 `D:\工作\报告_表格数据.xlsx` 做差异检查,列出变化,等我确认后再同步。
126
+
127
+ ## 安全与数据边界
128
+
129
+ - 所有文件操作在本机执行,不上传报告内容。
130
+ - 插件不注册 HTTP 服务,不提供远程文件访问接口。
131
+ - Agent 工具要求 Windows 绝对路径,并限制文件扩展名。
132
+ - 写操作、取消、版本校验和 JSONL 引擎通信均有自动化测试。
133
+ - 请优先使用副本;修改前备份不能替代独立归档。
134
+ - 本项目不包含客户报告、账号、密钥或二进制构建产物。
135
+ - **AI 助手默认关闭**。启用后也只发送本地筛出的候选片段(候选标题、表格前段落、附注边界,及前后各最多 200 字),不发送整篇报告、表格单元格或页眉页脚;接口地址填本机服务时数据不出机器。密钥经 Windows 数据保护接口加密后存于项目内 `.wesync_ai.json`(不入版本控制),明文不落盘。任何 AI 失败都退回原有本地规则,不影响导出与同步。
136
+ - **AI 不能直接改文件**。自然语言指令只能翻译成工具已有的操作(17 个写操作 + 7 个只读操作的白名单),参数经本地校验(路径必须存在、枚举值必须在允许集、编号必须来自最近扫描结果);写操作一律先预演、由你确认后才执行,且默认写前备份。AI 编造的操作或参数会被拒绝。
137
+
138
+ ## 开发
139
+
140
+ ```powershell
141
+ uv sync
142
+ .\.venv\Scripts\python.exe -m pytest excel_word/tests -q
143
+ npm --prefix qoder_plugins/audit-toolbox run check
144
+ npm --prefix qoder_plugins/audit-toolbox run smoke
145
+ npm test
146
+ ```
147
+
148
+ Python 测试会在项目内 `.tmp` 下创建并自动清理测试文档。目录结构和扩展约定见 `功能规划与文件布局.md`;详细接口见 `excel_word/README.md`。
149
+
150
+ ## 许可证
151
+
152
+ [MIT](LICENSE)。
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: audit-e2w
3
+ name: audit-e2w
@@ -0,0 +1,174 @@
1
+ import { spawn } from "node:child_process"
2
+ import { existsSync } from "node:fs"
3
+ import path from "node:path"
4
+ import { fileURLToPath } from "node:url"
5
+ import manifest from "../../../package.json" with { type: "json" }
6
+
7
+ export const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..")
8
+ const maxLogs = 2000
9
+
10
+ function parseLines(buffer, onLine) {
11
+ let end
12
+ while ((end = buffer.indexOf("\n")) !== -1) {
13
+ const line = buffer.slice(0, end).trim()
14
+ buffer = buffer.slice(end + 1)
15
+ if (!line) continue
16
+ try {
17
+ const event = JSON.parse(line)
18
+ if (event && typeof event === "object" && !Array.isArray(event)) onLine(event)
19
+ else onLine({ type: "log", level: "error", message: "引擎返回了无法解析的数据。" })
20
+ } catch {
21
+ onLine({ type: "log", level: "error", message: `引擎返回了无法解析的数据:${line.slice(0, 200)}` })
22
+ }
23
+ }
24
+ return buffer
25
+ }
26
+
27
+ export function runEngineProcess(command, args, request, { signal, cwd, timeoutMs = 600000, children } = {}) {
28
+ return new Promise((resolve, reject) => {
29
+ if (signal?.aborted) {
30
+ reject(new Error("任务已取消。"))
31
+ return
32
+ }
33
+ const child = spawn(command, args, {
34
+ cwd,
35
+ windowsHide: true,
36
+ shell: false,
37
+ stdio: ["pipe", "pipe", "pipe"],
38
+ env: { ...process.env, PYTHONUTF8: "1", PYTHONDONTWRITEBYTECODE: "1" },
39
+ })
40
+ children?.add(child)
41
+ const logs = []
42
+ let result = null
43
+ let stderr = ""
44
+ let buffer = ""
45
+ let settled = false
46
+ const addLog = (level, message) => {
47
+ logs.push({ level, message: String(message).slice(0, 4000) })
48
+ if (logs.length > maxLogs) logs.splice(0, logs.length - maxLogs)
49
+ }
50
+ const finish = (error, value) => {
51
+ if (settled) return
52
+ settled = true
53
+ children?.delete(child)
54
+ clearTimeout(timer)
55
+ signal?.removeEventListener("abort", abort)
56
+ if (error) reject(error)
57
+ else resolve(value)
58
+ }
59
+ const abort = () => {
60
+ child.kill()
61
+ finish(new Error("任务已取消。"))
62
+ }
63
+ signal?.addEventListener("abort", abort, { once: true })
64
+ const timer = setTimeout(() => {
65
+ child.kill()
66
+ finish(new Error("本地引擎执行超时(10 分钟)。"))
67
+ }, timeoutMs)
68
+ child.stdout.setEncoding("utf8")
69
+ child.stderr.setEncoding("utf8")
70
+ child.stdout.on("data", chunk => {
71
+ buffer = parseLines(buffer + chunk, event => {
72
+ if (event.type === "log") addLog(event.level || "info", event.message || "")
73
+ if (event.type === "result") result = event
74
+ })
75
+ })
76
+ child.stderr.on("data", chunk => {
77
+ stderr = `${stderr}${chunk}`.slice(-16000)
78
+ addLog("error", chunk.trim())
79
+ })
80
+ child.on("error", error => finish(error))
81
+ child.on("close", code => {
82
+ if (buffer.trim()) {
83
+ try {
84
+ const event = JSON.parse(buffer)
85
+ if (event.type === "log") addLog(event.level || "info", event.message || "")
86
+ if (event.type === "result") result = event
87
+ } catch {
88
+ addLog("error", "引擎结束时留下了不完整的响应。")
89
+ }
90
+ }
91
+ if (settled) return
92
+ if (!result) {
93
+ finish(new Error(`引擎提前退出(退出码 ${code})${stderr.trim() ? `:${stderr.trim().slice(-1000)}` : ""}`))
94
+ return
95
+ }
96
+ if (result.code !== 0 || code !== 0) {
97
+ const message = result.message || [...logs].reverse().find(item => item.level === "error")?.message || `引擎执行失败(退出码 ${code})。`
98
+ finish(new Error(message))
99
+ return
100
+ }
101
+ finish(null, { result, logs })
102
+ })
103
+ child.stdin.on("error", () => {})
104
+ child.stdin.end(`${JSON.stringify(request)}\n`, "utf8")
105
+ })
106
+ }
107
+
108
+ function configuredExecutable(value, suffixes, label) {
109
+ if (!value) return null
110
+ if (!path.isAbsolute(value) || /[\u0000-\u001f]/.test(value)) throw new Error(`${label} 必须是绝对路径。`)
111
+ if (!suffixes.some(suffix => value.toLowerCase().endsWith(suffix))) throw new Error(`${label} 文件类型不正确。`)
112
+ if (!existsSync(value)) throw new Error(`${label} 不存在:${value}`)
113
+ return value
114
+ }
115
+
116
+ export function resolveRuntime() {
117
+ if (process.platform !== "win32") throw new Error("Audit_E2W 当前只支持 Windows。")
118
+ const engine = configuredExecutable(process.env.AUDIT_TOOLBOX_ENGINE, [".exe"], "AUDIT_TOOLBOX_ENGINE")
119
+ if (engine) return { kind: "exe", command: engine, args: [], cwd: path.dirname(engine) }
120
+ const bundled = path.join(packageRoot, "engine", "审计工具箱引擎.exe")
121
+ if (existsSync(bundled)) return { kind: "exe", command: bundled, args: [], cwd: path.dirname(bundled) }
122
+ const source = path.join(packageRoot, "excel_word", "qoder_engine.py")
123
+ if (!existsSync(source)) throw new Error("插件包缺少本地引擎源码。请重新安装 Audit_E2W。")
124
+ const python = configuredExecutable(process.env.AUDIT_TOOLBOX_PYTHON, [".exe"], "AUDIT_TOOLBOX_PYTHON")
125
+ || path.join(packageRoot, ".venv", "Scripts", "python.exe")
126
+ if (existsSync(python)) return { kind: "python", command: python, args: ["-B", source], cwd: path.dirname(source) }
127
+ return { kind: "python", command: "python", args: ["-B", source], cwd: path.dirname(source) }
128
+ }
129
+
130
+ export class AuditRuntime {
131
+ constructor(resolver = resolveRuntime) {
132
+ this.resolver = resolver
133
+ this.children = new Set()
134
+ this.cache = null
135
+ }
136
+
137
+ async status() {
138
+ if (this.cache && Date.now() - this.cache.at < 5000) return this.cache.value
139
+ let value
140
+ try {
141
+ const runtime = this.resolver()
142
+ const outcome = await runEngineProcess(runtime.command, runtime.args, { id: "version", operation: "version" }, {
143
+ cwd: runtime.cwd,
144
+ timeoutMs: 15000,
145
+ })
146
+ const version = outcome.result.version
147
+ value = {
148
+ available: true,
149
+ runtime: runtime.kind,
150
+ path: runtime.command,
151
+ version,
152
+ versionMatched: version === manifest.version,
153
+ message: version === manifest.version ? "引擎已就绪,版本一致。" : `插件 ${manifest.version} 与引擎 ${version} 版本不一致,请同步更新。`,
154
+ }
155
+ } catch (error) {
156
+ value = { available: false, runtime: null, path: null, version: null, versionMatched: false, message: error.message }
157
+ }
158
+ this.cache = { at: Date.now(), value }
159
+ return value
160
+ }
161
+
162
+ async run(request, signal) {
163
+ const status = await this.status()
164
+ if (!status.available) throw new Error(`${status.message}\n\n请安装 Audit_E2W Windows 版,或配置 AUDIT_TOOLBOX_ENGINE / AUDIT_TOOLBOX_PYTHON,并安装 requirements.txt 中的 Python 依赖。`)
165
+ if (!status.versionMatched) throw new Error(status.message)
166
+ const runtime = this.resolver()
167
+ return runEngineProcess(runtime.command, runtime.args, request, { cwd: runtime.cwd, signal, children: this.children })
168
+ }
169
+
170
+ dispose() {
171
+ for (const child of this.children) child.kill()
172
+ this.children.clear()
173
+ }
174
+ }
@@ -0,0 +1,122 @@
1
+ import { emptySchema, formatProperties, operationSpecs, pathProperties, queryOperations, runOperations, runProperties, validateRunArgs } from "../../../qoder_plugins/audit-toolbox/catalog.mjs"
2
+ import manifest from "../../../package.json" with { type: "json" }
3
+ import { AuditRuntime } from "./engine.mjs"
4
+ import { skillContent, skillDescription, skillName, skillWhenToUse } from "./skill.js"
5
+
6
+ export const name = "dsh-audit-e2w"
7
+ export const inject = ["tools", "approval"]
8
+
9
+ const output = {
10
+ schema: { type: "object", additionalProperties: true },
11
+ render: (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 2) }],
12
+ }
13
+ const queryProperties = {
14
+ operation: { type: "string", enum: queryOperations, description: "只读操作名;先用 audit_capabilities 查看必填参数和示例" },
15
+ docx: pathProperties.docx,
16
+ excel: pathProperties.excel,
17
+ paths: pathProperties.paths,
18
+ template: formatProperties.template,
19
+ profileName: formatProperties.profileName,
20
+ scope: formatProperties.scope,
21
+ headingBatchId: formatProperties.headingBatchId,
22
+ headingLevels: formatProperties.headingLevels,
23
+ roleBatchId: formatProperties.roleBatchId,
24
+ roleOverrides: formatProperties.roleOverrides,
25
+ regionStartId: formatProperties.regionStartId,
26
+ }
27
+
28
+ export function createTools({ runtime = new AuditRuntime(), approval } = {}) {
29
+ const capabilities = {
30
+ name: "audit_capabilities",
31
+ description: "只读获取 Audit_E2W 全部操作、必填参数、默认值、预演支持和调用示例。选择操作或补参数前使用。",
32
+ parameters: emptySchema,
33
+ output,
34
+ execute: async () => ({
35
+ version: manifest.version,
36
+ operations: Object.entries(operationSpecs).map(([operation, spec]) => ({ operation, ...spec })),
37
+ }),
38
+ }
39
+ const status = {
40
+ name: "audit_engine_status",
41
+ description: "检查本地 Audit_E2W 引擎是否可用、版本是否一致。只读,不修改文件。",
42
+ parameters: emptySchema,
43
+ output,
44
+ execute: async () => runtime.status(),
45
+ }
46
+ const query = {
47
+ name: "audit_query",
48
+ description: "只读扫描 Word/Excel,不修改文件。支持空白表、可恢复表、差异、表块、排序、模板字段和备份历史。返回完整日志和结构化数据。",
49
+ parameters: {
50
+ type: "object",
51
+ properties: queryProperties,
52
+ required: ["operation"],
53
+ additionalProperties: false,
54
+ },
55
+ output,
56
+ execute: async (args, exec) => {
57
+ const request = validateRunArgs(args, queryOperations)
58
+ const outcome = await runtime.run(request, exec.signal)
59
+ return { operation: request.operation, dryRun: false, ...outcome }
60
+ },
61
+ }
62
+ const run = {
63
+ name: "audit_run",
64
+ description: "执行 Word/Excel 审计操作。先用 audit_capabilities 核对参数;写盘前先预演或差异检查,说明影响文件并取得用户确认。dryRun=true 不写文件;dryRun=false 的写操作必须通过 DSH 审批。常见映射:export=创建Excel,writeback=同步Word,template-batch=单模板报告,batch-writeback=批量同步。",
65
+ parameters: {
66
+ type: "object",
67
+ properties: {
68
+ operation: { type: "string", enum: runOperations, description: "执行操作名;先用 audit_capabilities 查看必填参数和示例" },
69
+ ...runProperties,
70
+ },
71
+ required: ["operation"],
72
+ additionalProperties: false,
73
+ },
74
+ output,
75
+ execute: async (args, exec) => {
76
+ const request = validateRunArgs(args, runOperations)
77
+ const spec = operationSpecs[request.operation]
78
+ if (spec.writes && request.dryRun !== true) {
79
+ if (!exec.agent || !approval?.request) throw new Error("写操作需要 DSH 用户审批服务;当前请求已拒绝。")
80
+ const decision = await approval.request({
81
+ agent: exec.agent,
82
+ toolName: "audit_run",
83
+ callId: exec.callId,
84
+ reason: `Audit_E2W 将执行“${spec.title}”,可能修改或生成本地 Word/Excel 文件。请核对工具参数中的文件路径。`,
85
+ signal: exec.signal,
86
+ })
87
+ if (decision !== "allowed-once") throw new Error(`用户未批准写操作(${decision})。`)
88
+ }
89
+ const outcome = await runtime.run(request, exec.signal)
90
+ return { operation: request.operation, dryRun: request.dryRun === true, ...outcome }
91
+ },
92
+ }
93
+ return { capabilities, status, query, run }
94
+ }
95
+
96
+ function registerSkill(ctx) {
97
+ const fiber = ctx.inject(["skills"], skillCtx => {
98
+ skillCtx.effect(() => skillCtx.skills.register({
99
+ name: skillName,
100
+ description: skillDescription,
101
+ whenToUse: skillWhenToUse,
102
+ content: skillContent,
103
+ source: "bundled",
104
+ }), "dsh-audit-e2w:skill")
105
+ })
106
+ return () => { void fiber.dispose() }
107
+ }
108
+
109
+ export function apply(ctx) {
110
+ const runtime = new AuditRuntime()
111
+ const tools = createTools({ runtime, approval: ctx.approval })
112
+ const disposers = []
113
+ for (const tool of Object.values(tools)) {
114
+ disposers.push(ctx.effect(() => ctx.tools.register(tool), `dsh-audit-e2w:${tool.name}`))
115
+ }
116
+ disposers.push(registerSkill(ctx))
117
+ ctx.logger.info("Audit_E2W tools mounted; local engine status is checked on demand.")
118
+ return async () => {
119
+ for (const dispose of disposers.reverse()) await dispose()
120
+ runtime.dispose()
121
+ }
122
+ }
@@ -0,0 +1,42 @@
1
+ export const skillName = "audit-word-excel"
2
+ export const skillDescription = "通过 DSH Agent 在本机完成 Word 与 Excel 审计办公任务:创建 Excel、同步回 Word、标注、占位符、模板批量报告、空白表维护、报告格式调整、差异检查和备份回滚。"
3
+ export const skillWhenToUse = "用户要求处理本地 Word/Excel 审计文件、导出表格、同步数据、生成报告、调整报告格式或检查文档差异时使用。"
4
+ export const skillContent = `# Audit_E2W 本地审计工作流
5
+
6
+ 先调用 \`audit_capabilities\` 查看全部 31 个操作、必填参数和示例,再调用 \`audit_engine_status\` 确认引擎就绪且版本一致。所有文件路径必须是 Windows 绝对路径。
7
+
8
+ ## 安全顺序
9
+
10
+ 1. 用 \`audit_query\` 扫描、比对或列出候选,确认文件和影响范围。
11
+ 2. 对支持预演的操作先调用 \`audit_run\` 且 \`dryRun: true\`,展示目标文件、改动数量、警告和跳过项。
12
+ 3. 向用户说明将修改或生成的文件;得到明确确认后,再以 \`dryRun: false\`、\`confirmed: true\` 调用。写操作会触发 DSH 审批,审批未通过不得绕过。
13
+ 4. 读取返回的日志、结果和文件路径,向用户核验实际结果;不要仅凭工具调用成功就宣称业务结果正确。
14
+ 5. 批量任务逐份汇报成功、失败和跳过;顶层成功不代表每份文件都成功。
15
+
16
+ ## 常见映射
17
+
18
+ - Word 导出 Excel:\`export\`
19
+ - Word 新增内容后只追加新表 XT、标注 XM 和正文信息:\`incremental-export\`(不是全量重置,旧行位置不变)
20
+ - Excel 同步回 Word:\`writeback\`
21
+ - Word 与 Excel 差异:\`diff\`
22
+ - 标注导出/同步:\`marks\` / \`marks-sync\`
23
+ - 占位符工作表补齐/同步:\`placeholders\` / \`placeholders-sync\`
24
+ - 单模板报告:\`template-batch\`
25
+ - 多报告同步:\`batch-writeback\`
26
+ - 空白表扫描/删除:\`blank-scan\` / \`blank-delete\`
27
+ - 备份查看/恢复:\`backup-list\` / \`backup-restore\`
28
+ - 格式调整预演:\`format-scan\`
29
+ - 候选标题、表题角色与附注边界:\`format-heading-candidates\`
30
+ - 应用报告格式:\`format-apply\`
31
+
32
+ ## 报告格式
33
+
34
+ 1. 用户要用样板调整格式时,把 \`docx\` 和样板 \`template\` 传给 \`format-scan\`;\`template\` 与已存 \`profileName\` 二选一。未指定范围时默认七项全选;自定义 \`scope\` 必须完整包含 \`cover\`、\`headings\`、\`statement\`、\`body\`、\`table_text\`、\`table_emphasis\`、\`table_borders\`,不能全关。
35
+ 2. 需要识别未标注的一至四级标题、区分表题与表格前引导正文、核对附注边界时,调用 \`format-heading-candidates\`。只使用返回的 \`candidates\`、\`role_candidates\`、\`boundary_candidates\` 和有限上下文,不得读取或上传整篇报告、表格单元格、页眉页脚或批注来补充判断。\`truncated=true\` 时说明候选已达上限,不能声称覆盖全部疑难项。
36
+ 3. 根据候选原文和有限格式线索给出标题级别、角色和边界建议;标题级别只能是 1~4,角色只能是 \`body\` 或 \`table_title\`。逐项展示置信度,不确定的列为待确认,只在用户确认后保存 \`headingLevels\`、\`roleOverrides\`、\`regionStartId\`。
37
+ 4. 将原样确认的 \`headingBatchId\`、\`headingLevels\` 和相同的 \`docx\`/样板/范围传给 \`format-scan\`。角色或边界使用同一个批次作为 \`roleBatchId\`;标题与角色同时确认时两个批次编号必须一致。核对预演数量、\`assigned_headings\`、\`assigned_roles\` 和 \`region_start\`;报告或候选变化导致旧批次被拒绝时,重新扫描并重新确认。
38
+ 5. 预演后取得用户执行确认,调用 \`format-apply\`:\`dryRun=true\` 只预演;正式执行用 \`dryRun=false\`、\`confirmed=true\`,并指定新的 \`output\` 路径。绝不覆盖原报告。
39
+ 6. 候选级别和角色只应用直接排版,边界只改变本次格式处理范围;不写标题样式、不改大纲级别、不更新目录。完成后核对输出为新文件、原报告未改、确认数量一致,并按返回的 \`visual_review\` 提醒用户在 Word 中复核封面、标题、正文、表题、宽表格和分页。结构核验通过不等于目视排版通过。
40
+
41
+ 不得覆盖模板或源 Excel;不得擅自设置 \`force: true\` 或关闭备份。遇到版本不一致、文件占用、警告或部分失败,应停止并报告,不要静默降级。引擎默认最长运行 10 分钟,超时后先排查文件占用或缩小批量,不重复启动同一写操作。
42
+ `