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
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,148 @@
1
- # Temporary Holding Version
1
+ # Audit_E2W
2
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.
3
+ 让 Agent 按你的指令处理本机 Word / Excel 审计文档:从 Word 提取表格、标注和正文占位符,在 Excel 中修改,再同步回 Word;也支持空白表格处理、差异检查、排序、批量报告和备份恢复。
4
+
5
+ 当前版本:**1.11.2**。仅支持 **Windows 10/11 64 位**,不支持 macOS。
6
+
7
+ ## 能做什么
8
+
9
+ - **Word → Excel**:导出表格;只要表格、链接标注、正文占位符任意一种存在就导出,并创建三个工作表。
10
+ - **Excel → Word**:同步单元格、行列结构、标注、正文占位符及数值显示格式;同步前可检查差异。
11
+ - **表格维护**:重建书签、重新判定表块、追加表格、设置或清除排序。
12
+ - **空白表格**:扫描、删除、查看已删除表块、恢复;支持批量处理。
13
+ - **批量办公**:批量同步、单模板批量生成报告、批量填写占位符。
14
+ - **安全回退**:修改前备份,可查看备份历史并恢复;预演不写文件,危险操作需确认。
15
+
16
+ ## 三种使用方式
17
+
18
+ | 方式 | 适用场景 | 需要什么 |
19
+ | --- | --- | --- |
20
+ | Windows 图形界面 | 直接手工操作 | Python 源码环境,或已构建的 Windows 程序 |
21
+ | Qoder 插件 | 在 Qoder 中用自然语言指挥 Agent,并提供操作界面 | Qoder Desktop、Windows 版引擎 |
22
+ | DSH 完整插件 | 在 DSH 中用自然语言指挥 Agent | DSH、Node.js 24.11+、pnpm 10+、Python 3.12+ |
23
+ | WorkBuddy / DSH Skill | 只安装工作流说明,由 Agent 调用本机执行脚本 | 对应 Agent、Windows 版引擎 |
24
+
25
+ ### 1. 源码运行
26
+
27
+ 在项目根目录安装依赖并启动图形界面:
28
+
29
+ ```powershell
30
+ uv sync
31
+ .\.venv\Scripts\pythonw.exe .\审计工具箱.pyw
32
+ ```
33
+
34
+ 没有 uv 时,也可使用 Python 3.12+:
35
+
36
+ ```powershell
37
+ python -m venv .venv
38
+ .\.venv\Scripts\python.exe -m pip install -r requirements.txt
39
+ .\.venv\Scripts\pythonw.exe .\审计工具箱.pyw
40
+ ```
41
+
42
+ 命令行示例(在 `excel_word` 目录执行):
43
+
44
+ ```powershell
45
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py export .\报告.docx --dry-run
46
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py export .\报告.docx
47
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py writeback .\报告.docx --dry-run
48
+ ..\.venv\Scripts\python.exe .\word_excel_sync.py writeback .\报告.docx
49
+ ```
50
+
51
+ ### 2. Qoder 插件
52
+
53
+ 源码目录为 `qoder_plugins/audit-toolbox`。构建脚本会把 Windows 引擎、MCP Server、界面和 Skill 打入插件 ZIP:
54
+
55
+ ```powershell
56
+ .\.venv\Scripts\python.exe .\packaging\build_qoder_plugin.py
57
+ ```
58
+
59
+ 构建前需要 PyInstaller;产物位于 `dist/qoder_plugins`。Qoder 插件包使用 Qoder 内置 Node.js 运行 MCP Server。
60
+
61
+ ### 3. DSH 完整插件
62
+
63
+ 仓库根目录是可安装的 DSH npm bundle,入口声明在 `cordis.patch.yml`,提供四个工具:
64
+
65
+ - `audit_capabilities`:查看 31 个操作及参数。
66
+ - `audit_engine_status`:检查本机引擎和版本。
67
+ - `audit_query`:只读扫描与差异检查。
68
+ - `audit_run`:执行操作;非预演写操作必须经 DSH 用户审批。
69
+
70
+ 安装包优先使用 `AUDIT_TOOLBOX_ENGINE` 指定的 Windows 引擎,其次使用包内 `engine/审计工具箱引擎.exe`,最后使用 Python 源码引擎。公开 npm/GitHub 包**不附带 Windows exe**,因此源码方式需要先安装 Python 依赖:
71
+
72
+ ```powershell
73
+ py -3.12 -m venv .venv
74
+ .\.venv\Scripts\python.exe -m pip install python-docx==1.2.0 openpyxl==3.1.5 lxml==6.1.1
75
+ ```
76
+
77
+ 可通过 `AUDIT_TOOLBOX_PYTHON` 指定解释器的绝对路径。插件与引擎版本不一致时会拒绝执行,不会静默降级。
78
+
79
+ 安装到 DSH profile(Windows):
80
+
81
+ ```powershell
82
+ npm install -g pnpm@10
83
+ py -3.12 -m venv .venv
84
+ .\.venv\Scripts\python.exe -m pip install python-docx==1.2.0 openpyxl==3.1.5 lxml==6.1.1
85
+ $env:AUDIT_TOOLBOX_PYTHON = (Resolve-Path .\.venv\Scripts\python.exe).Path
86
+
87
+ dsh plugin --profile desktop add github:xymlg/Audit_E2W
88
+ dsh --profile desktop --dump-config
89
+ dsh --profile desktop
90
+ ```
91
+
92
+ `desktop` 可替换为实际 profile 名;`--dump-config` 应显示 `audit-e2w` 配置层。GitHub 安装的是纯 JavaScript 发布入口,不需要构建脚本授权。生产环境建议把安装地址锁定到具体提交,例如 `github:xymlg/Audit_E2W#<commit-sha>`。
93
+
94
+ 开发和打包检查:
95
+
96
+ ```powershell
97
+ npm run check
98
+ npm test
99
+ npm pack --dry-run
100
+ ```
101
+
102
+ ### 4. 通用 Agent Skill
103
+
104
+ `agent_skills/audit-word-excel-workbuddy` 是 WorkBuddy 专用工作流 Skill,只走本地脚本通道;`agent_skills/audit-word-excel` 是 DSH 等 Agent 的通用工作流 Skill。两者都不包含 Windows 引擎二进制,必须配合本机执行脚本或已安装的 Windows 程序使用。
105
+
106
+ ```powershell
107
+ .\.venv\Scripts\python.exe .\packaging\build_agent_skills.py --check-only
108
+ .\.venv\Scripts\python.exe .\packaging\build_agent_skills.py --build-zips
109
+ ```
110
+
111
+ ## 推荐工作流程
112
+
113
+ 1. 让 Agent 先检查引擎状态和文件路径。
114
+ 2. 先预演、扫描或比对差异,不直接写盘。
115
+ 3. 说明将修改或生成哪些文件。
116
+ 4. 获得确认后执行;写操作通过宿主审批或由用户明确授权。
117
+ 5. 核对结果、警告和部分失败项;必要时从备份恢复。
118
+
119
+ 示例:
120
+
121
+ > 先检查引擎状态,然后对 `D:\工作\报告.docx` 执行导出预演,告诉我会生成哪些工作表和文件,不要写盘。
122
+
123
+ > 对 `D:\工作\报告.docx` 和 `D:\工作\报告_表格数据.xlsx` 做差异检查,列出变化,等我确认后再同步。
124
+
125
+ ## 安全与数据边界
126
+
127
+ - 所有文件操作在本机执行,不上传报告内容。
128
+ - 插件不注册 HTTP 服务,不提供远程文件访问接口。
129
+ - Agent 工具要求 Windows 绝对路径,并限制文件扩展名。
130
+ - 写操作、取消、版本校验和 JSONL 引擎通信均有自动化测试。
131
+ - 请优先使用副本;修改前备份不能替代独立归档。
132
+ - 本项目不包含客户报告、账号、密钥或二进制构建产物。
133
+
134
+ ## 开发
135
+
136
+ ```powershell
137
+ uv sync
138
+ .\.venv\Scripts\python.exe -m pytest excel_word/tests -q
139
+ npm --prefix qoder_plugins/audit-toolbox run check
140
+ npm --prefix qoder_plugins/audit-toolbox run smoke
141
+ npm test
142
+ ```
143
+
144
+ Python 测试会在项目内 `.tmp` 下创建并自动清理测试文档。目录结构和扩展约定见 `功能规划与文件布局.md`;详细接口见 `excel_word/README.md`。
145
+
146
+ ## 许可证
147
+
148
+ [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,114 @@
1
+ import { emptySchema, 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
+ }
19
+
20
+ export function createTools({ runtime = new AuditRuntime(), approval } = {}) {
21
+ const capabilities = {
22
+ name: "audit_capabilities",
23
+ description: "只读获取 Audit_E2W 全部操作、必填参数、默认值、预演支持和调用示例。选择操作或补参数前使用。",
24
+ parameters: emptySchema,
25
+ output,
26
+ execute: async () => ({
27
+ version: manifest.version,
28
+ operations: Object.entries(operationSpecs).map(([operation, spec]) => ({ operation, ...spec })),
29
+ }),
30
+ }
31
+ const status = {
32
+ name: "audit_engine_status",
33
+ description: "检查本地 Audit_E2W 引擎是否可用、版本是否一致。只读,不修改文件。",
34
+ parameters: emptySchema,
35
+ output,
36
+ execute: async () => runtime.status(),
37
+ }
38
+ const query = {
39
+ name: "audit_query",
40
+ description: "只读扫描 Word/Excel,不修改文件。支持空白表、可恢复表、差异、表块、排序、模板字段和备份历史。返回完整日志和结构化数据。",
41
+ parameters: {
42
+ type: "object",
43
+ properties: queryProperties,
44
+ required: ["operation"],
45
+ additionalProperties: false,
46
+ },
47
+ output,
48
+ execute: async (args, exec) => {
49
+ const request = validateRunArgs(args, queryOperations)
50
+ const outcome = await runtime.run(request, exec.signal)
51
+ return { operation: request.operation, dryRun: false, ...outcome }
52
+ },
53
+ }
54
+ const run = {
55
+ name: "audit_run",
56
+ description: "执行 Word/Excel 审计操作。先用 audit_capabilities 核对参数;写盘前先预演或差异检查,说明影响文件并取得用户确认。dryRun=true 不写文件;dryRun=false 的写操作必须通过 DSH 审批。常见映射:export=创建Excel,writeback=同步Word,template-batch=单模板报告,batch-writeback=批量同步。",
57
+ parameters: {
58
+ type: "object",
59
+ properties: {
60
+ operation: { type: "string", enum: runOperations, description: "执行操作名;先用 audit_capabilities 查看必填参数和示例" },
61
+ ...runProperties,
62
+ },
63
+ required: ["operation"],
64
+ additionalProperties: false,
65
+ },
66
+ output,
67
+ execute: async (args, exec) => {
68
+ const request = validateRunArgs(args, runOperations)
69
+ const spec = operationSpecs[request.operation]
70
+ if (spec.writes && request.dryRun !== true) {
71
+ if (!exec.agent || !approval?.request) throw new Error("写操作需要 DSH 用户审批服务;当前请求已拒绝。")
72
+ const decision = await approval.request({
73
+ agent: exec.agent,
74
+ toolName: "audit_run",
75
+ callId: exec.callId,
76
+ reason: `Audit_E2W 将执行“${spec.title}”,可能修改或生成本地 Word/Excel 文件。请核对工具参数中的文件路径。`,
77
+ signal: exec.signal,
78
+ })
79
+ if (decision !== "allowed-once") throw new Error(`用户未批准写操作(${decision})。`)
80
+ }
81
+ const outcome = await runtime.run(request, exec.signal)
82
+ return { operation: request.operation, dryRun: request.dryRun === true, ...outcome }
83
+ },
84
+ }
85
+ return { capabilities, status, query, run }
86
+ }
87
+
88
+ function registerSkill(ctx) {
89
+ const fiber = ctx.inject(["skills"], skillCtx => {
90
+ skillCtx.effect(() => skillCtx.skills.register({
91
+ name: skillName,
92
+ description: skillDescription,
93
+ whenToUse: skillWhenToUse,
94
+ content: skillContent,
95
+ source: "bundled",
96
+ }), "dsh-audit-e2w:skill")
97
+ })
98
+ return () => { void fiber.dispose() }
99
+ }
100
+
101
+ export function apply(ctx) {
102
+ const runtime = new AuditRuntime()
103
+ const tools = createTools({ runtime, approval: ctx.approval })
104
+ const disposers = []
105
+ for (const tool of Object.values(tools)) {
106
+ disposers.push(ctx.effect(() => ctx.tools.register(tool), `dsh-audit-e2w:${tool.name}`))
107
+ }
108
+ disposers.push(registerSkill(ctx))
109
+ ctx.logger.info("Audit_E2W tools mounted; local engine status is checked on demand.")
110
+ return async () => {
111
+ for (const dispose of disposers.reverse()) await dispose()
112
+ runtime.dispose()
113
+ }
114
+ }
@@ -0,0 +1,41 @@
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\` 调用。写操作会触发 DSH 审批,审批未通过不得绕过。
13
+ 4. 读取返回的日志、结果和文件路径,向用户核验实际结果;不要仅凭工具调用成功就宣称业务结果正确。
14
+ 5. 批量任务逐份汇报成功、失败和跳过;顶层成功不代表每份文件都成功。
15
+
16
+ ## 常见映射
17
+
18
+ - Word 导出 Excel:\`export\`
19
+ - Excel 同步回 Word:\`writeback\`
20
+ - Word 与 Excel 差异:\`diff\`
21
+ - 标注导出/同步:\`marks\` / \`marks-sync\`
22
+ - 占位符工作表补齐/同步:\`placeholders\` / \`placeholders-sync\`
23
+ - 单模板报告:\`template-batch\`
24
+ - 多报告同步:\`batch-writeback\`
25
+ - 空白表扫描/删除:\`blank-scan\` / \`blank-delete\`
26
+ - 备份查看/恢复:\`backup-list\` / \`backup-restore\`
27
+ - 格式调整预演:\`format-scan\`
28
+ - 候选标题、表题角色与附注边界:\`format-heading-candidates\`
29
+ - 应用报告格式:\`format-apply\`
30
+
31
+ ## 报告格式
32
+
33
+ 1. 用户要用样板调整格式时,把 \`docx\` 和样板 \`template\` 传给 \`format-scan\`;\`template\` 与已存 \`profileName\` 二选一。未指定范围时默认七项全选;自定义 \`scope\` 必须完整包含 \`cover\`、\`headings\`、\`statement\`、\`body\`、\`table_text\`、\`table_emphasis\`、\`table_borders\`,不能全关。
34
+ 2. 需要识别未标注的一至四级标题、区分表题与表格前引导正文、核对附注边界时,调用 \`format-heading-candidates\`。只使用返回的 \`candidates\`、\`role_candidates\`、\`boundary_candidates\` 和有限上下文,不得读取或上传整篇报告、表格单元格、页眉页脚或批注来补充判断。\`truncated=true\` 时说明候选已达上限,不能声称覆盖全部疑难项。
35
+ 3. 根据候选原文和有限格式线索给出标题级别、角色和边界建议;标题级别只能是 1~4,角色只能是 \`body\` 或 \`table_title\`。逐项展示置信度,不确定的列为待确认,只在用户确认后保存 \`headingLevels\`、\`roleOverrides\`、\`regionStartId\`。
36
+ 4. 将原样确认的 \`headingBatchId\`、\`headingLevels\` 和相同的 \`docx\`/样板/范围传给 \`format-scan\`。角色或边界使用同一个批次作为 \`roleBatchId\`;标题与角色同时确认时两个批次编号必须一致。核对预演数量、\`assigned_headings\`、\`assigned_roles\` 和 \`region_start\`;报告或候选变化导致旧批次被拒绝时,重新扫描并重新确认。
37
+ 5. 预演后取得用户执行确认,调用 \`format-apply\`:\`dryRun=true\` 只预演;正式执行用 \`dryRun=false\`、\`confirmed=true\`,并指定新的 \`output\` 路径。绝不覆盖原报告。
38
+ 6. 候选级别和角色只应用直接排版,边界只改变本次格式处理范围;不写标题样式、不改大纲级别、不更新目录。完成后核对输出为新文件、原报告未改、确认数量一致,并按返回的 \`visual_review\` 提醒用户在 Word 中复核封面、标题、正文、表题、宽表格和分页。结构核验通过不等于目视排版通过。
39
+
40
+ 不得覆盖模板或源 Excel;不得擅自设置 \`force: true\` 或关闭备份。遇到版本不一致、文件占用、警告或部分失败,应停止并报告,不要静默降级。
41
+ `