gongwen-skill 2.6.1 → 2.8.0
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/.dsh/skills/gongwen-skill/SKILL.md +44 -11
- package/.dsh/skills/gongwen-skill.md +44 -11
- package/CHANGELOG.md +22 -0
- package/README.md +42 -6
- package/SKILL.md +44 -11
- package/dsh/index.js +1 -1
- package/engine/core/document/_generator_helpers.py +3 -2
- package/engine/core/document/markdown_converter.py +4 -2
- package/engine/core/document/ooxml_workflow.py +2 -2
- package/engine/core/rules/checker.py +1 -1
- package/engine/inject.py +10 -6
- package/gongwen/__init__.py +1 -1
- package/gongwen/_legacy.py +22 -4
- package/gongwen/cli/doctor_cmds.py +54 -2
- package/gongwen/cli/font_cmds.py +21 -10
- package/gongwen/cli/helpers.py +21 -8
- package/gongwen/cli/netcheck.py +362 -0
- package/gongwen/cli/update_cmds.py +27 -6
- package/gongwen/cli/wizard_cmds.py +420 -0
- package/gongwen/md2docx_render.py +3 -2
- package/package.json +1 -1
- package/prompts/usage-prompts.md +1 -1
- package/pyproject.toml +1 -1
|
@@ -103,6 +103,7 @@ metadata:
|
|
|
103
103
|
```
|
|
104
104
|
- **PyPI 为权威判定渠道**(pip 包核心分发,pip install -U 即从 PyPI 拉取);PyPI 不可达时回退 GitHub tag(备用渠道,git 用户/CI 触发源)
|
|
105
105
|
- GitCode/AtomGit 与 GitHub 同源 tag,仅在 GitHub 不可达时作国内拉取镜像提示(不参与版本判定)
|
|
106
|
+
- GitHub 不可达且触发 DNS 诊断时(系统解析为保留/Fake-IP 段),`check-update --json` 会输出 `dns_diagnosis` 字段(含 `hosts_suggestions`),如实向用户转述排查建议即可
|
|
106
107
|
- 若全部渠道均不可用(无 git/无网络),**必须明确告知用户"版本自检因无法访问远程而跳过"**,不得静默假设本地即最新
|
|
107
108
|
3.5. **本地 git tag 对比**(P6,Agent 执行版本确认时补充):
|
|
108
109
|
- 优先对 skill 安装目录执行 git tag 对比:
|
|
@@ -258,21 +259,23 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
258
259
|
|
|
259
260
|
## 用户交互指引(Agent 必须遵守)
|
|
260
261
|
|
|
262
|
+
> **终端用户也可直接运行 `python -m gongwen wizard`**:交互式向导以菜单方式完成同样的 A/B/C/D 路径选择与逐步确认(详见下文「向导式交互」小节)。Agent 读到本条时,若用户表示「不熟悉命令/不想记参数」,应主动引导其使用向导,而非逐字念命令行参数。
|
|
263
|
+
|
|
261
264
|
### 第一步:确认路径(必须,严禁跳过)
|
|
262
265
|
|
|
263
|
-
|
|
266
|
+
用通俗语言问用户走哪条路,**不允许跳过**。向导模式与对话模式共用同一套路径:
|
|
264
267
|
|
|
265
268
|
> 这个工具支持四种处理方式:
|
|
266
|
-
> -
|
|
267
|
-
> -
|
|
268
|
-
> -
|
|
269
|
-
> -
|
|
269
|
+
> - **A. 格式优化**:不改文字,只修排版(字体/字号/页边距/行距/缩进),按国标标准化
|
|
270
|
+
> - **B. 内容优化**:润色文字表达,生成带标记的对比文档——保持原文档排版样式,修改处红色高亮或删除线、每段附修改说明
|
|
271
|
+
> - **C. 生成模板**:直接生成一份空白公文模板,按国标设好版式
|
|
272
|
+
> - **D. 一键格式修复**(fix-common):快速规范化常见格式问题(段落类型/编号拆分/首句加粗),输出不含 AI 声明段的干净文档
|
|
270
273
|
|
|
271
274
|
若用户说「帮我优化一下」,必须追问是改格式还是改内容。
|
|
272
275
|
|
|
273
276
|
### 第二步:告知输出物
|
|
274
277
|
|
|
275
|
-
|
|
278
|
+
执行前明确说会生成什么文件、包含什么标记。向导模式会在执行前展示将运行的完整命令。
|
|
276
279
|
|
|
277
280
|
### 第三步:执行后验证
|
|
278
281
|
|
|
@@ -280,6 +283,29 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
280
283
|
|
|
281
284
|
---
|
|
282
285
|
|
|
286
|
+
### 向导式交互(`wizard` 命令)
|
|
287
|
+
|
|
288
|
+
当用户**不熟悉命令行**、希望**逐步确认后再执行**,或 Agent 需要**把交互决策委托给工具**时,使用向导:
|
|
289
|
+
|
|
290
|
+
```
|
|
291
|
+
python -m gongwen wizard # 终端交互:菜单选 A/B/C/D → 逐项填参 → 预览确认 → 执行
|
|
292
|
+
python -m gongwen wizard --answers 答案.json # Agent 非交互:跳过提问直接执行
|
|
293
|
+
python -m gongwen wizard --answers 答案.json --dry-run # 只打印将执行的命令,不真正执行
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
- **路径菜单**:A 格式优化(`optimize`)|B 内容优化(`optimize-content`)|C 生成模板(`template`)|D 一键格式修复(`fix-common`)
|
|
297
|
+
- **交互流程**:选择路径 → 收集参数(公文类型支持 序号 / id / 中文名,如 `1`、`notice`、`通知`)→ A/B/D 先预览再 y/n 确认 → 执行;C 无修改风险直接执行
|
|
298
|
+
- **`--answers` JSON 扁平结构**(Agent 场景,顶层带 `path`):
|
|
299
|
+
```json
|
|
300
|
+
{"path": "A", "input": "原文.docx", "doc_type": "notice", "output": "成品.docx", "apply": true}
|
|
301
|
+
```
|
|
302
|
+
- 字段缺失:非交互模式直接报错并列出缺失项(不静默、不进交互菜单)
|
|
303
|
+
- 不写 `apply` 时 A/B/D **仅预览不执行**(安全默认);`apply: true` 跳过确认直接执行
|
|
304
|
+
- 非交互执行机制:`subprocess` 调用 `sys.executable -m gongwen <子命令>`,输出流式透传,Agent 可直接解析子命令原始输出
|
|
305
|
+
- **`--dry-run`**:只打印将执行的命令;A/B 会同时打印「预览」与「执行」两条命令,便于 Agent 预演与调试
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
283
309
|
## 执行标准总则(所有路径共享)
|
|
284
310
|
|
|
285
311
|
### Agent 行为准则
|
|
@@ -295,7 +321,7 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
295
321
|
| "按上级文件要求调整" | 用户有政策依据但未提供 | 追问具体文件名或文号,或用 web 搜索相关政策 |
|
|
296
322
|
| "弄漂亮一点" | 希望格式规范 | 解释 GB/T 9704 标准是唯一合规格式 |
|
|
297
323
|
|
|
298
|
-
**原则**:不确定时 **先确认路径**(A/B/C
|
|
324
|
+
**原则**:不确定时 **先确认路径**(A/B/C/D,向导模式同),再用 **具体示例引导用户选择**,不猜测。
|
|
299
325
|
|
|
300
326
|
#### 2. 充分利用 skill 知识库
|
|
301
327
|
|
|
@@ -846,10 +872,16 @@ python -m gongwen fix-common 文件.docx -o 成品.docx
|
|
|
846
872
|
|
|
847
873
|
---
|
|
848
874
|
|
|
849
|
-
## 附录:全部命令速查(
|
|
875
|
+
## 附录:全部命令速查(25 个,按用途分组)
|
|
850
876
|
|
|
851
877
|
> Agent 遇到用户需求时,先在此表定位对应命令;命令用法不明确时运行 `python -m gongwen <命令> --help` 查看完整参数。
|
|
852
878
|
|
|
879
|
+
### 🧭 向导式交互
|
|
880
|
+
|
|
881
|
+
| 命令 | 用途 | 最小用法 |
|
|
882
|
+
|------|------|---------|
|
|
883
|
+
| `wizard` | 交互式路径引导(A/B/C/D)+ 一键执行;Agent 用 `--answers` 非交互 / `--dry-run` 只打印命令 | `python -m gongwen wizard` |
|
|
884
|
+
|
|
853
885
|
### 🏗️ 生成与模板
|
|
854
886
|
|
|
855
887
|
| 命令 | 用途 | 最小用法 |
|
|
@@ -894,15 +926,16 @@ python -m gongwen fix-common 文件.docx -o 成品.docx
|
|
|
894
926
|
| `table-signs` | 从名单批量生成会议桌签 | `python -m gongwen table-signs 名单.txt -o 桌签.docx` |
|
|
895
927
|
| `review` | 生成公文审稿流转单(五/三角色) | `python -m gongwen review report -o 审稿单.docx` |
|
|
896
928
|
| `handoff` | 跨会话交接(长任务收尾必写) | `python -m gongwen handoff --write` |
|
|
897
|
-
| `check-update` | 版本自检(PyPI pip 包权威 + GitHub
|
|
898
|
-
| `font` |
|
|
929
|
+
| `check-update` | 版本自检(PyPI pip 包权威 + GitHub 备用,自动检测安装形态;GitHub 不可达时 DNS 诊断) | `python -m gongwen check-update` |
|
|
930
|
+
| `font` | 公文标准字体管理(安装/检查/列出;下载失败时自动安全 DNS 直连兜底) | `python -m gongwen font install` |
|
|
899
931
|
|
|
900
932
|
### 🩺 诊断与修复
|
|
901
933
|
|
|
902
934
|
| 命令 | 用途 | 最小用法 |
|
|
903
935
|
|------|------|---------|
|
|
904
|
-
| `doctor` | 全面诊断:检查 Python 版本/依赖/版本一致性/字体/DSH
|
|
936
|
+
| `doctor` | 全面诊断:检查 Python 版本/依赖/版本一致性/字体/DSH 文件/代码风格/网络 DNS 等 | `python -m gongwen doctor` |
|
|
905
937
|
| `doctor --json` | JSON 结构化输出(便于 Agent 解析) | `python -m gongwen doctor --json` |
|
|
938
|
+
| `doctor --offline` | 跳过网络/DNS 诊断(离线模式) | `python -m gongwen doctor --offline` |
|
|
906
939
|
| `repair` | 修复常见问题:安装缺失依赖/字体/同步 SKILL.md 副本 | `python -m gongwen repair` |
|
|
907
940
|
|
|
908
941
|
### ⚙️ 规则管理
|
|
@@ -103,6 +103,7 @@ metadata:
|
|
|
103
103
|
```
|
|
104
104
|
- **PyPI 为权威判定渠道**(pip 包核心分发,pip install -U 即从 PyPI 拉取);PyPI 不可达时回退 GitHub tag(备用渠道,git 用户/CI 触发源)
|
|
105
105
|
- GitCode/AtomGit 与 GitHub 同源 tag,仅在 GitHub 不可达时作国内拉取镜像提示(不参与版本判定)
|
|
106
|
+
- GitHub 不可达且触发 DNS 诊断时(系统解析为保留/Fake-IP 段),`check-update --json` 会输出 `dns_diagnosis` 字段(含 `hosts_suggestions`),如实向用户转述排查建议即可
|
|
106
107
|
- 若全部渠道均不可用(无 git/无网络),**必须明确告知用户"版本自检因无法访问远程而跳过"**,不得静默假设本地即最新
|
|
107
108
|
3.5. **本地 git tag 对比**(P6,Agent 执行版本确认时补充):
|
|
108
109
|
- 优先对 skill 安装目录执行 git tag 对比:
|
|
@@ -258,21 +259,23 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
258
259
|
|
|
259
260
|
## 用户交互指引(Agent 必须遵守)
|
|
260
261
|
|
|
262
|
+
> **终端用户也可直接运行 `python -m gongwen wizard`**:交互式向导以菜单方式完成同样的 A/B/C/D 路径选择与逐步确认(详见下文「向导式交互」小节)。Agent 读到本条时,若用户表示「不熟悉命令/不想记参数」,应主动引导其使用向导,而非逐字念命令行参数。
|
|
263
|
+
|
|
261
264
|
### 第一步:确认路径(必须,严禁跳过)
|
|
262
265
|
|
|
263
|
-
|
|
266
|
+
用通俗语言问用户走哪条路,**不允许跳过**。向导模式与对话模式共用同一套路径:
|
|
264
267
|
|
|
265
268
|
> 这个工具支持四种处理方式:
|
|
266
|
-
> -
|
|
267
|
-
> -
|
|
268
|
-
> -
|
|
269
|
-
> -
|
|
269
|
+
> - **A. 格式优化**:不改文字,只修排版(字体/字号/页边距/行距/缩进),按国标标准化
|
|
270
|
+
> - **B. 内容优化**:润色文字表达,生成带标记的对比文档——保持原文档排版样式,修改处红色高亮或删除线、每段附修改说明
|
|
271
|
+
> - **C. 生成模板**:直接生成一份空白公文模板,按国标设好版式
|
|
272
|
+
> - **D. 一键格式修复**(fix-common):快速规范化常见格式问题(段落类型/编号拆分/首句加粗),输出不含 AI 声明段的干净文档
|
|
270
273
|
|
|
271
274
|
若用户说「帮我优化一下」,必须追问是改格式还是改内容。
|
|
272
275
|
|
|
273
276
|
### 第二步:告知输出物
|
|
274
277
|
|
|
275
|
-
|
|
278
|
+
执行前明确说会生成什么文件、包含什么标记。向导模式会在执行前展示将运行的完整命令。
|
|
276
279
|
|
|
277
280
|
### 第三步:执行后验证
|
|
278
281
|
|
|
@@ -280,6 +283,29 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
280
283
|
|
|
281
284
|
---
|
|
282
285
|
|
|
286
|
+
### 向导式交互(`wizard` 命令)
|
|
287
|
+
|
|
288
|
+
当用户**不熟悉命令行**、希望**逐步确认后再执行**,或 Agent 需要**把交互决策委托给工具**时,使用向导:
|
|
289
|
+
|
|
290
|
+
```
|
|
291
|
+
python -m gongwen wizard # 终端交互:菜单选 A/B/C/D → 逐项填参 → 预览确认 → 执行
|
|
292
|
+
python -m gongwen wizard --answers 答案.json # Agent 非交互:跳过提问直接执行
|
|
293
|
+
python -m gongwen wizard --answers 答案.json --dry-run # 只打印将执行的命令,不真正执行
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
- **路径菜单**:A 格式优化(`optimize`)|B 内容优化(`optimize-content`)|C 生成模板(`template`)|D 一键格式修复(`fix-common`)
|
|
297
|
+
- **交互流程**:选择路径 → 收集参数(公文类型支持 序号 / id / 中文名,如 `1`、`notice`、`通知`)→ A/B/D 先预览再 y/n 确认 → 执行;C 无修改风险直接执行
|
|
298
|
+
- **`--answers` JSON 扁平结构**(Agent 场景,顶层带 `path`):
|
|
299
|
+
```json
|
|
300
|
+
{"path": "A", "input": "原文.docx", "doc_type": "notice", "output": "成品.docx", "apply": true}
|
|
301
|
+
```
|
|
302
|
+
- 字段缺失:非交互模式直接报错并列出缺失项(不静默、不进交互菜单)
|
|
303
|
+
- 不写 `apply` 时 A/B/D **仅预览不执行**(安全默认);`apply: true` 跳过确认直接执行
|
|
304
|
+
- 非交互执行机制:`subprocess` 调用 `sys.executable -m gongwen <子命令>`,输出流式透传,Agent 可直接解析子命令原始输出
|
|
305
|
+
- **`--dry-run`**:只打印将执行的命令;A/B 会同时打印「预览」与「执行」两条命令,便于 Agent 预演与调试
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
283
309
|
## 执行标准总则(所有路径共享)
|
|
284
310
|
|
|
285
311
|
### Agent 行为准则
|
|
@@ -295,7 +321,7 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
295
321
|
| "按上级文件要求调整" | 用户有政策依据但未提供 | 追问具体文件名或文号,或用 web 搜索相关政策 |
|
|
296
322
|
| "弄漂亮一点" | 希望格式规范 | 解释 GB/T 9704 标准是唯一合规格式 |
|
|
297
323
|
|
|
298
|
-
**原则**:不确定时 **先确认路径**(A/B/C
|
|
324
|
+
**原则**:不确定时 **先确认路径**(A/B/C/D,向导模式同),再用 **具体示例引导用户选择**,不猜测。
|
|
299
325
|
|
|
300
326
|
#### 2. 充分利用 skill 知识库
|
|
301
327
|
|
|
@@ -846,10 +872,16 @@ python -m gongwen fix-common 文件.docx -o 成品.docx
|
|
|
846
872
|
|
|
847
873
|
---
|
|
848
874
|
|
|
849
|
-
## 附录:全部命令速查(
|
|
875
|
+
## 附录:全部命令速查(25 个,按用途分组)
|
|
850
876
|
|
|
851
877
|
> Agent 遇到用户需求时,先在此表定位对应命令;命令用法不明确时运行 `python -m gongwen <命令> --help` 查看完整参数。
|
|
852
878
|
|
|
879
|
+
### 🧭 向导式交互
|
|
880
|
+
|
|
881
|
+
| 命令 | 用途 | 最小用法 |
|
|
882
|
+
|------|------|---------|
|
|
883
|
+
| `wizard` | 交互式路径引导(A/B/C/D)+ 一键执行;Agent 用 `--answers` 非交互 / `--dry-run` 只打印命令 | `python -m gongwen wizard` |
|
|
884
|
+
|
|
853
885
|
### 🏗️ 生成与模板
|
|
854
886
|
|
|
855
887
|
| 命令 | 用途 | 最小用法 |
|
|
@@ -894,15 +926,16 @@ python -m gongwen fix-common 文件.docx -o 成品.docx
|
|
|
894
926
|
| `table-signs` | 从名单批量生成会议桌签 | `python -m gongwen table-signs 名单.txt -o 桌签.docx` |
|
|
895
927
|
| `review` | 生成公文审稿流转单(五/三角色) | `python -m gongwen review report -o 审稿单.docx` |
|
|
896
928
|
| `handoff` | 跨会话交接(长任务收尾必写) | `python -m gongwen handoff --write` |
|
|
897
|
-
| `check-update` | 版本自检(PyPI pip 包权威 + GitHub
|
|
898
|
-
| `font` |
|
|
929
|
+
| `check-update` | 版本自检(PyPI pip 包权威 + GitHub 备用,自动检测安装形态;GitHub 不可达时 DNS 诊断) | `python -m gongwen check-update` |
|
|
930
|
+
| `font` | 公文标准字体管理(安装/检查/列出;下载失败时自动安全 DNS 直连兜底) | `python -m gongwen font install` |
|
|
899
931
|
|
|
900
932
|
### 🩺 诊断与修复
|
|
901
933
|
|
|
902
934
|
| 命令 | 用途 | 最小用法 |
|
|
903
935
|
|------|------|---------|
|
|
904
|
-
| `doctor` | 全面诊断:检查 Python 版本/依赖/版本一致性/字体/DSH
|
|
936
|
+
| `doctor` | 全面诊断:检查 Python 版本/依赖/版本一致性/字体/DSH 文件/代码风格/网络 DNS 等 | `python -m gongwen doctor` |
|
|
905
937
|
| `doctor --json` | JSON 结构化输出(便于 Agent 解析) | `python -m gongwen doctor --json` |
|
|
938
|
+
| `doctor --offline` | 跳过网络/DNS 诊断(离线模式) | `python -m gongwen doctor --offline` |
|
|
906
939
|
| `repair` | 修复常见问题:安装缺失依赖/字体/同步 SKILL.md 副本 | `python -m gongwen repair` |
|
|
907
940
|
|
|
908
941
|
### ⚙️ 规则管理
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,28 @@
|
|
|
4
4
|
Licensed under the MIT License. See the LICENSE file for details.
|
|
5
5
|
-->
|
|
6
6
|
|
|
7
|
+
## v2.8.0 (2026-09-03)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **DNS 污染诊断(安全 DNS / DoH)**:`check-update` 在 GitHub 渠道不可达时自动触发 DNS 污染诊断,对比系统解析与安全 DNS(DoH)真实 IP,输出污染判定、对比表与可直接粘贴的 hosts 条目建议
|
|
11
|
+
- **`doctor` 新增「网络/DNS 诊断」检查项**:默认联网检测 GitHub/PyPI 关键域名是否疑似 DNS 污染(系统解析落在 198.18.0.0/15 等保留/Fake-IP 段时判定疑似污染),`--offline` 参数可完全跳过网络查询
|
|
12
|
+
- **新增 `gongwen/cli/netcheck.py` 模块**:DoH 解析(内置阿里 `dns.alidns.com` / 腾讯 `doh.pub` / `1.12.12.12` / Google 备用,多端点自动降级)+ 系统解析对比 + 污染判定 + hosts 建议生成;环境变量 `GONGWEN_DOH` 可覆盖为自定义 DoH 端点
|
|
13
|
+
- **`check-update --json` 输出新增 `dns_diagnosis` 字段**:含 `polluted` / `detail` / `hosts_suggestions` 等,便于 Agent 解析
|
|
14
|
+
- **自动直连兜底(DNS 污染时零操作下载)**:`font install` 下载字体、`check-update`/`helpers` 查询 PyPI 常规请求失败时,自动用 DoH 真实 IP + TLS SNI 直连重试(`netcheck.download_with_doh_fallback` / `_DoHHTTPSConnection`),证书校验仍针对真实域名,安全不降级
|
|
15
|
+
|
|
16
|
+
### Notes
|
|
17
|
+
- 诊断只做建议,不修改 hosts、不改变版本判定逻辑;自动直连仅作为下载/查询失败的兜底路径(YAGNI)
|
|
18
|
+
- DoH 查询经第三方公共 DNS 服务(阿里/腾讯),仅诊断/兜底失败时发起少量查询;可设置 `GONGWEN_DOH` 指向私有端点
|
|
19
|
+
|
|
20
|
+
## v2.7.0 (2026-09-03)
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- **新增 `wizard` 向导式交互命令**:`python -m gongwen wizard` 以 A/B/C/D 路径菜单引导用户(A 格式优化 `optimize` / B 内容优化 `optimize-content` / C 生成模板 `template` / D 一键格式修复 `fix-common`),交互收集参数后一键执行
|
|
24
|
+
- **双模式交互**:终端 input() 交互(公文类型支持序号 / id / 中文名智能匹配)+ `--answers` 扁平 JSON 非交互(Agent 场景,顶层带 `path`,如 `{"path":"A","input":"a.docx","apply":true}`)
|
|
25
|
+
- **安全默认**:A/B/D 修改类路径先预览再 y/n 确认;非交互模式不写 `apply` 时仅预览不执行;`--dry-run` 只打印将执行的命令(A/B 同时打印预览+执行两条)
|
|
26
|
+
- **执行机制**:`subprocess` 调用 `sys.executable -m gongwen <子命令>`,输出流式透传,Agent 可直接解析子命令原始输出
|
|
27
|
+
- **文档同步**:SKILL.md「用户交互指引」升级为向导式三步流程并新增「向导式交互」小节(命令速查 24→25 个);README 能力表与命令行速查补充 wizard 用法
|
|
28
|
+
|
|
7
29
|
## v2.6.1 (2026-09-02)
|
|
8
30
|
|
|
9
31
|
### Changed
|
package/README.md
CHANGED
|
@@ -45,11 +45,12 @@ Licensed under the MIT License. See the LICENSE file for details.
|
|
|
45
45
|
| 🔍 审稿生成 | `review` | 按五角色审稿机制生成审稿意见 |
|
|
46
46
|
| 🧩 完整审校 | `full-review` | 修订+批注联合命令(句子级差异修订 + 分类批注) |
|
|
47
47
|
| 🎨 样式学习 | `style-learn` / `style-list` | 上传标准文档学习 Run/段落/页面三级样式(字体/字号/字间距/行距/缩进/页边距),生成命名模板持久化,后续用 `optimize -t 模板名` 套用 |
|
|
48
|
-
| 🔄 版本自检 | `check-update` | 版本自检(PyPI pip 包权威判定 + GitHub 备用,GitCode/AtomGit
|
|
49
|
-
| 🩺 自我诊断 | `doctor` / `repair` | 全面诊断
|
|
48
|
+
| 🔄 版本自检 | `check-update` | 版本自检(PyPI pip 包权威判定 + GitHub 备用,GitCode/AtomGit 作国内镜像提示;GitHub 不可达时自动做 DNS 污染诊断 + hosts 建议) |
|
|
49
|
+
| 🩺 自我诊断 | `doctor` / `repair` | 全面诊断 23 项(Python/依赖/版本一致性/字体/DSH 文件/DSH 技能 frontmatter/代码风格/网络 DNS),自动修复常见问题;`--offline` 跳过网络检查 |
|
|
50
50
|
| 🕵️ 文档审计 | `audit` | 检查删除线/加粗/AI 声明等痕迹 |
|
|
51
51
|
| 🤝 会话交接 | `handoff` | 跨会话上下文传递(`--list` / `--latest` / Agent 长任务收尾必写) |
|
|
52
52
|
| ⚙️ 规则管理 | `rule-export/import/list` | YAML 规则三层定制(官方/单位/用户) |
|
|
53
|
+
| 🧭 向导式交互 | `wizard` | 交互式路径引导(A/B/C/D)+ 一键执行;Agent 用 `--answers` 非交互 / `--dry-run` 只打印命令 |
|
|
53
54
|
|
|
54
55
|
## 使用示例
|
|
55
56
|
|
|
@@ -259,6 +260,24 @@ python -m gongwen optimize-content 新闻稿.docx --changes changes.json \
|
|
|
259
260
|
--show-confirmed 已确认实体也生成批注
|
|
260
261
|
```
|
|
261
262
|
|
|
263
|
+
### 🧭 向导式交互(wizard)
|
|
264
|
+
|
|
265
|
+
交互式引导选择处理路径并一键执行,适合不熟悉命令行的用户;Agent 可走非交互模式:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
python -m gongwen wizard # 终端交互:菜单选 A/B/C/D → 逐项填参 → 预览确认 → 执行
|
|
269
|
+
python -m gongwen wizard --answers 答案.json # Agent 非交互:跳过提问直接执行
|
|
270
|
+
python -m gongwen wizard --answers 答案.json --dry-run # 只打印将执行的命令
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
`--answers` 扁平 JSON(顶层带 `path`):
|
|
274
|
+
|
|
275
|
+
```json
|
|
276
|
+
{"path": "A", "input": "原文.docx", "doc_type": "notice", "output": "成品.docx", "apply": true}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
路径:A 格式优化(`optimize`)|B 内容优化(`optimize-content`)|C 生成模板(`template`)|D 一键格式修复(`fix-common`)。A/B/D 默认先预览再 y/n 确认;不写 `apply` 时非交互模式仅预览不执行(安全默认)。
|
|
280
|
+
|
|
262
281
|
## 📐 GB/T 9704 标准格式
|
|
263
282
|
|
|
264
283
|
| 元素 | 字体 | 字号 | 对齐 |
|
|
@@ -317,7 +336,7 @@ python -m gongwen rule-list notice
|
|
|
317
336
|
|
|
318
337
|
Agent 加载 skill 后**必须执行版本追新自检**,确保使用最新版本:
|
|
319
338
|
|
|
320
|
-
1. **远程自检**(首选):`python -m gongwen check-update`——以 **PyPI(pip 包发布源)为权威判定渠道**并发查询比对本地(pip install -U 即从 PyPI 拉取);PyPI 不可达时回退 GitHub tag(备用渠道)。全部渠道不可达时明确告知"版本自检跳过"。GitHub 为海外渠道(国内常超时)采用短超时快速降级;GitHub 不可达时自动提示国内代码镜像(GitCode/AtomGit,与 GitHub 同源 tag
|
|
339
|
+
1. **远程自检**(首选):`python -m gongwen check-update`——以 **PyPI(pip 包发布源)为权威判定渠道**并发查询比对本地(pip install -U 即从 PyPI 拉取);PyPI 不可达时回退 GitHub tag(备用渠道)。全部渠道不可达时明确告知"版本自检跳过"。GitHub 为海外渠道(国内常超时)采用短超时快速降级;GitHub 不可达时自动提示国内代码镜像(GitCode/AtomGit,与 GitHub 同源 tag)、GitHub520 hosts 加速方案,并自动做 **DNS 污染诊断**(对比系统解析与安全 DNS/DoH 真实 IP,输出可直接粘贴的 hosts 条目建议)
|
|
321
340
|
2. **本地 git tag 对比**(补充):对 skill 安装目录执行 `git -C "<skill安装目录>" describe --tags --abbrev=0`;若安装目录不在 git 管理下,应告知用户"无法执行版本对比,建议手动检查 GitHub 更新"
|
|
322
341
|
3. **落后则警告**:发现本地版本落后于最新版本时,**必须在执行前警告用户**并提示更新——`check-update` 会按安装形态自动给出精准更新命令(pip 包安装:`pip install --upgrade gongwen-skill`;git/skill 目录安装:`cd <gongwen-skill目录> && git pull && git fetch --tags`),不得静默使用旧版本
|
|
323
342
|
|
|
@@ -337,7 +356,7 @@ DSH 采用 **Cordis 模块化微内核架构**:技能体系基于本地文件
|
|
|
337
356
|
git clone https://github.com/linhut/gongwen-skill.git
|
|
338
357
|
cd gongwen-skill
|
|
339
358
|
pip install -r requirements.txt # 或 pip install gongwen-skill(已上 PyPI)
|
|
340
|
-
python -m gongwen --version # 检验:gongwen-skill v2.
|
|
359
|
+
python -m gongwen --version # 检验:gongwen-skill v2.8.0
|
|
341
360
|
```
|
|
342
361
|
|
|
343
362
|
### 方式一:作为 DSH Skill 注册(基于本地文件系统)
|
|
@@ -393,7 +412,7 @@ pnpm add -w gongwen-skill
|
|
|
393
412
|
"dependencies": {
|
|
394
413
|
"@deepseek-ai/dsh-base": "...",
|
|
395
414
|
"@deepseek-ai/dsh-web-app": "...",
|
|
396
|
-
"gongwen-skill": "^2.
|
|
415
|
+
"gongwen-skill": "^2.8.0"
|
|
397
416
|
},
|
|
398
417
|
"dsh": {
|
|
399
418
|
"profile": {
|
|
@@ -574,7 +593,7 @@ pip install -r requirements.txt
|
|
|
574
593
|
用户:帮我优化这份会议通知的第二章节措辞
|
|
575
594
|
|
|
576
595
|
Agent:📋 合规自检报告
|
|
577
|
-
Skill 版本: v2.
|
|
596
|
+
Skill 版本: v2.8.0(版本自检已确认最新)
|
|
578
597
|
路径判定: B(内容优化)
|
|
579
598
|
依据: 用户指定了已有文档,且要求"优化措辞"
|
|
580
599
|
命令调用: 1. python -m gongwen optimize-content 会议通知.docx --changes changes.json --apply --paragraphs "5-8"
|
|
@@ -610,6 +629,23 @@ Skill 定位为**工具层**,默认不依赖 LLM(确定性工作全自包含
|
|
|
610
629
|
|
|
611
630
|
---
|
|
612
631
|
|
|
632
|
+
## 🌐 GitHub 不可达排查(安全 DNS / DoH)
|
|
633
|
+
|
|
634
|
+
国内网络访问 GitHub 常遇「无法访问 / 超时」问题,常见原因之一是 **DNS 污染**——系统 DNS 返回的不是真实 IP,而是保留/Fake-IP 段(如 198.18.0.0/15、0.0.0.0),连接自然失败或超时。
|
|
635
|
+
|
|
636
|
+
**快速诊断**:运行 python -m gongwen doctor(含网络/DNS 检查项),或 python -m gongwen check-update(GitHub 渠道不可达时自动诊断)。检测到疑似污染时,会输出系统解析 vs 安全 DNS 真实 IP 对比,以及可直接粘贴的 hosts 条目建议。
|
|
637
|
+
|
|
638
|
+
**原理**:安全 DNS(DoH,DNS over HTTPS)通过加密 HTTP 查询 DNS,避免中间设备篡改解析结果,可拿到域名的真实 IP。本工具内置阿里(dns.alidns.com)、腾讯(doh.pub / 1.12.12.12)等国内公共 DoH 端点,多端点自动降级;可通过环境变量 GONGWEN_DOH 覆盖为自定义端点(如自建的 DoH 服务)。
|
|
639
|
+
|
|
640
|
+
**自动兜底(v2.8.0)**:`font install` 下载字体、`check-update` 查 PyPI 时若常规请求失败(疑似 DNS 污染),自动用 DoH 真实 IP + TLS SNI 直连重试——TLS 证书仍按真实域名校验,安全不降级,用户零操作。
|
|
641
|
+
|
|
642
|
+
**处置建议**(按推荐度):
|
|
643
|
+
1. 若使用了代理工具(Clash/V2Ray 等)且系统解析命中 198.18.x Fake-IP,优先检查其 DNS 模式的 fake-ip-filter 是否漏掉 GitHub 域名(比改 hosts 更治本)
|
|
644
|
+
2. 将诊断输出的 hosts 条目写入 C:\Windows\System32\drivers\etc\hosts(需管理员权限),git / 浏览器即可直连真实 IP
|
|
645
|
+
3. 或使用国内镜像仓库克隆/更新(见下方「镜像仓库」)
|
|
646
|
+
|
|
647
|
+
> 诊断 + 自动兜底:本工具不写入 hosts、不修改系统配置;但 `font install` 下载字体、`check-update` 查询 PyPI 遇到 DNS 污染导致的失败时,会**自动用安全 DNS(DoH)真实 IP + TLS SNI 直连重试**(零操作,证书校验不降级)。DoH 查询经第三方公共 DNS 服务,仅在诊断/兜底失败时发起少量查询,隐私敏感者可设置 GONGWEN_DOH 指向自有端点。
|
|
648
|
+
|
|
613
649
|
## 📄 许可证与出处
|
|
614
650
|
|
|
615
651
|
MIT License · **(c) 2026 Jose AI** · https://www.linhut.cn
|
package/SKILL.md
CHANGED
|
@@ -103,6 +103,7 @@ metadata:
|
|
|
103
103
|
```
|
|
104
104
|
- **PyPI 为权威判定渠道**(pip 包核心分发,pip install -U 即从 PyPI 拉取);PyPI 不可达时回退 GitHub tag(备用渠道,git 用户/CI 触发源)
|
|
105
105
|
- GitCode/AtomGit 与 GitHub 同源 tag,仅在 GitHub 不可达时作国内拉取镜像提示(不参与版本判定)
|
|
106
|
+
- GitHub 不可达且触发 DNS 诊断时(系统解析为保留/Fake-IP 段),`check-update --json` 会输出 `dns_diagnosis` 字段(含 `hosts_suggestions`),如实向用户转述排查建议即可
|
|
106
107
|
- 若全部渠道均不可用(无 git/无网络),**必须明确告知用户"版本自检因无法访问远程而跳过"**,不得静默假设本地即最新
|
|
107
108
|
3.5. **本地 git tag 对比**(P6,Agent 执行版本确认时补充):
|
|
108
109
|
- 优先对 skill 安装目录执行 git tag 对比:
|
|
@@ -258,21 +259,23 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
258
259
|
|
|
259
260
|
## 用户交互指引(Agent 必须遵守)
|
|
260
261
|
|
|
262
|
+
> **终端用户也可直接运行 `python -m gongwen wizard`**:交互式向导以菜单方式完成同样的 A/B/C/D 路径选择与逐步确认(详见下文「向导式交互」小节)。Agent 读到本条时,若用户表示「不熟悉命令/不想记参数」,应主动引导其使用向导,而非逐字念命令行参数。
|
|
263
|
+
|
|
261
264
|
### 第一步:确认路径(必须,严禁跳过)
|
|
262
265
|
|
|
263
|
-
|
|
266
|
+
用通俗语言问用户走哪条路,**不允许跳过**。向导模式与对话模式共用同一套路径:
|
|
264
267
|
|
|
265
268
|
> 这个工具支持四种处理方式:
|
|
266
|
-
> -
|
|
267
|
-
> -
|
|
268
|
-
> -
|
|
269
|
-
> -
|
|
269
|
+
> - **A. 格式优化**:不改文字,只修排版(字体/字号/页边距/行距/缩进),按国标标准化
|
|
270
|
+
> - **B. 内容优化**:润色文字表达,生成带标记的对比文档——保持原文档排版样式,修改处红色高亮或删除线、每段附修改说明
|
|
271
|
+
> - **C. 生成模板**:直接生成一份空白公文模板,按国标设好版式
|
|
272
|
+
> - **D. 一键格式修复**(fix-common):快速规范化常见格式问题(段落类型/编号拆分/首句加粗),输出不含 AI 声明段的干净文档
|
|
270
273
|
|
|
271
274
|
若用户说「帮我优化一下」,必须追问是改格式还是改内容。
|
|
272
275
|
|
|
273
276
|
### 第二步:告知输出物
|
|
274
277
|
|
|
275
|
-
|
|
278
|
+
执行前明确说会生成什么文件、包含什么标记。向导模式会在执行前展示将运行的完整命令。
|
|
276
279
|
|
|
277
280
|
### 第三步:执行后验证
|
|
278
281
|
|
|
@@ -280,6 +283,29 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
280
283
|
|
|
281
284
|
---
|
|
282
285
|
|
|
286
|
+
### 向导式交互(`wizard` 命令)
|
|
287
|
+
|
|
288
|
+
当用户**不熟悉命令行**、希望**逐步确认后再执行**,或 Agent 需要**把交互决策委托给工具**时,使用向导:
|
|
289
|
+
|
|
290
|
+
```
|
|
291
|
+
python -m gongwen wizard # 终端交互:菜单选 A/B/C/D → 逐项填参 → 预览确认 → 执行
|
|
292
|
+
python -m gongwen wizard --answers 答案.json # Agent 非交互:跳过提问直接执行
|
|
293
|
+
python -m gongwen wizard --answers 答案.json --dry-run # 只打印将执行的命令,不真正执行
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
- **路径菜单**:A 格式优化(`optimize`)|B 内容优化(`optimize-content`)|C 生成模板(`template`)|D 一键格式修复(`fix-common`)
|
|
297
|
+
- **交互流程**:选择路径 → 收集参数(公文类型支持 序号 / id / 中文名,如 `1`、`notice`、`通知`)→ A/B/D 先预览再 y/n 确认 → 执行;C 无修改风险直接执行
|
|
298
|
+
- **`--answers` JSON 扁平结构**(Agent 场景,顶层带 `path`):
|
|
299
|
+
```json
|
|
300
|
+
{"path": "A", "input": "原文.docx", "doc_type": "notice", "output": "成品.docx", "apply": true}
|
|
301
|
+
```
|
|
302
|
+
- 字段缺失:非交互模式直接报错并列出缺失项(不静默、不进交互菜单)
|
|
303
|
+
- 不写 `apply` 时 A/B/D **仅预览不执行**(安全默认);`apply: true` 跳过确认直接执行
|
|
304
|
+
- 非交互执行机制:`subprocess` 调用 `sys.executable -m gongwen <子命令>`,输出流式透传,Agent 可直接解析子命令原始输出
|
|
305
|
+
- **`--dry-run`**:只打印将执行的命令;A/B 会同时打印「预览」与「执行」两条命令,便于 Agent 预演与调试
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
283
309
|
## 执行标准总则(所有路径共享)
|
|
284
310
|
|
|
285
311
|
### Agent 行为准则
|
|
@@ -295,7 +321,7 @@ python -m gongwen handoff --latest --summary # 最新交接文档(Markdown 摘
|
|
|
295
321
|
| "按上级文件要求调整" | 用户有政策依据但未提供 | 追问具体文件名或文号,或用 web 搜索相关政策 |
|
|
296
322
|
| "弄漂亮一点" | 希望格式规范 | 解释 GB/T 9704 标准是唯一合规格式 |
|
|
297
323
|
|
|
298
|
-
**原则**:不确定时 **先确认路径**(A/B/C
|
|
324
|
+
**原则**:不确定时 **先确认路径**(A/B/C/D,向导模式同),再用 **具体示例引导用户选择**,不猜测。
|
|
299
325
|
|
|
300
326
|
#### 2. 充分利用 skill 知识库
|
|
301
327
|
|
|
@@ -846,10 +872,16 @@ python -m gongwen fix-common 文件.docx -o 成品.docx
|
|
|
846
872
|
|
|
847
873
|
---
|
|
848
874
|
|
|
849
|
-
## 附录:全部命令速查(
|
|
875
|
+
## 附录:全部命令速查(25 个,按用途分组)
|
|
850
876
|
|
|
851
877
|
> Agent 遇到用户需求时,先在此表定位对应命令;命令用法不明确时运行 `python -m gongwen <命令> --help` 查看完整参数。
|
|
852
878
|
|
|
879
|
+
### 🧭 向导式交互
|
|
880
|
+
|
|
881
|
+
| 命令 | 用途 | 最小用法 |
|
|
882
|
+
|------|------|---------|
|
|
883
|
+
| `wizard` | 交互式路径引导(A/B/C/D)+ 一键执行;Agent 用 `--answers` 非交互 / `--dry-run` 只打印命令 | `python -m gongwen wizard` |
|
|
884
|
+
|
|
853
885
|
### 🏗️ 生成与模板
|
|
854
886
|
|
|
855
887
|
| 命令 | 用途 | 最小用法 |
|
|
@@ -894,15 +926,16 @@ python -m gongwen fix-common 文件.docx -o 成品.docx
|
|
|
894
926
|
| `table-signs` | 从名单批量生成会议桌签 | `python -m gongwen table-signs 名单.txt -o 桌签.docx` |
|
|
895
927
|
| `review` | 生成公文审稿流转单(五/三角色) | `python -m gongwen review report -o 审稿单.docx` |
|
|
896
928
|
| `handoff` | 跨会话交接(长任务收尾必写) | `python -m gongwen handoff --write` |
|
|
897
|
-
| `check-update` | 版本自检(PyPI pip 包权威 + GitHub
|
|
898
|
-
| `font` |
|
|
929
|
+
| `check-update` | 版本自检(PyPI pip 包权威 + GitHub 备用,自动检测安装形态;GitHub 不可达时 DNS 诊断) | `python -m gongwen check-update` |
|
|
930
|
+
| `font` | 公文标准字体管理(安装/检查/列出;下载失败时自动安全 DNS 直连兜底) | `python -m gongwen font install` |
|
|
899
931
|
|
|
900
932
|
### 🩺 诊断与修复
|
|
901
933
|
|
|
902
934
|
| 命令 | 用途 | 最小用法 |
|
|
903
935
|
|------|------|---------|
|
|
904
|
-
| `doctor` | 全面诊断:检查 Python 版本/依赖/版本一致性/字体/DSH
|
|
936
|
+
| `doctor` | 全面诊断:检查 Python 版本/依赖/版本一致性/字体/DSH 文件/代码风格/网络 DNS 等 | `python -m gongwen doctor` |
|
|
905
937
|
| `doctor --json` | JSON 结构化输出(便于 Agent 解析) | `python -m gongwen doctor --json` |
|
|
938
|
+
| `doctor --offline` | 跳过网络/DNS 诊断(离线模式) | `python -m gongwen doctor --offline` |
|
|
906
939
|
| `repair` | 修复常见问题:安装缺失依赖/字体/同步 SKILL.md 副本 | `python -m gongwen repair` |
|
|
907
940
|
|
|
908
941
|
### ⚙️ 规则管理
|
package/dsh/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 公文全流程处理工具 - DSH plugin bridge (gongwen-skill, v2.
|
|
1
|
+
// 公文全流程处理工具 - DSH plugin bridge (gongwen-skill, v2.8.0+)
|
|
2
2
|
// (c) 2026 Jose AI (https://www.linhut.cn)
|
|
3
3
|
// https://github.com/linhut/gongwen-skill
|
|
4
4
|
// Licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -529,8 +529,9 @@ def _apply_run_format(run, run_model: Run):
|
|
|
529
529
|
run.font.italic = fmt.italic
|
|
530
530
|
if fmt.underline is not None:
|
|
531
531
|
run.font.underline = fmt.underline
|
|
532
|
-
if fmt.strikethrough is
|
|
533
|
-
|
|
532
|
+
if fmt.strikethrough is not None:
|
|
533
|
+
# True 设置删除线 / False 显式清除已有删除线(避免 strikethrough=False 时旧删除线残留)
|
|
534
|
+
run.font.strike = fmt.strikethrough
|
|
534
535
|
|
|
535
536
|
# === 颜色 ===
|
|
536
537
|
if fmt.color:
|
|
@@ -30,8 +30,8 @@ _MD_UL_RE = re.compile(r'^[-*+]\s+')
|
|
|
30
30
|
# markdown 有序列表前缀:1. 2. 3. 或 1、2、3、
|
|
31
31
|
_MD_OL_RE = re.compile(r'^\d+[.、]\s*')
|
|
32
32
|
|
|
33
|
-
# markdown
|
|
34
|
-
_MD_TABLE_RE = re.compile(r'
|
|
33
|
+
# markdown 表格行(支持单列:| a |;贪婪匹配到行尾,多列 | a | b | 亦能识别)
|
|
34
|
+
_MD_TABLE_RE = re.compile(r'^\|.+\|$')
|
|
35
35
|
|
|
36
36
|
# markdown 表格分隔行:|----|----|
|
|
37
37
|
_MD_TABLE_SEP_RE = re.compile(r'^\|[\s\-:|]+\|$')
|
|
@@ -263,6 +263,8 @@ def convert_markdown(model: DocumentModel) -> int:
|
|
|
263
263
|
ol_match = _MD_OL_RE.match(text)
|
|
264
264
|
if ol_match and not para.is_heading:
|
|
265
265
|
is_list = True
|
|
266
|
+
text = _MD_OL_RE.sub('', text)
|
|
267
|
+
list_indent_pt = 32 # 有序列表同样 2 字符缩进(与无序列表一致)
|
|
266
268
|
|
|
267
269
|
# --- 应用格式修改到 run ---
|
|
268
270
|
|
|
@@ -79,7 +79,7 @@ class OOXMLWorkflow:
|
|
|
79
79
|
return self
|
|
80
80
|
|
|
81
81
|
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
|
|
82
|
-
#
|
|
83
|
-
if self.unpack_dir is not None
|
|
82
|
+
# 修复:无论正常结束或异常均清理临时目录,避免每次异常残留 gongwen_ooxml_* 目录泄漏磁盘
|
|
83
|
+
if self.unpack_dir is not None:
|
|
84
84
|
shutil.rmtree(self.unpack_dir, ignore_errors=True)
|
|
85
85
|
self.unpack_dir = None
|
|
@@ -893,7 +893,7 @@ def _check_header_field(model, rule_id: str, severity: str, name: str,
|
|
|
893
893
|
suggested_fix="仅保留一个主送机关",
|
|
894
894
|
reason="请示一般只写一个主送机关(发现多个主送机关段)",
|
|
895
895
|
))
|
|
896
|
-
elif re.search(r'[、,,
|
|
896
|
+
elif re.search(r'[、,,]{2,}', first.strip().rstrip('::')) and len(first.strip().rstrip('::')) > 5:
|
|
897
897
|
issues.append(CheckIssue(
|
|
898
898
|
rule_id=rule_id, check_type="content", severity=severity,
|
|
899
899
|
name=name, location=f"paragraph:{recips[0].index}",
|
package/engine/inject.py
CHANGED
|
@@ -379,7 +379,7 @@ def inject_footer(output_path: str, footer_config: dict) -> None:
|
|
|
379
379
|
# 页码注入:Word PAGE 域动态页码
|
|
380
380
|
# ---------------------------------------------------------------------------
|
|
381
381
|
|
|
382
|
-
def _add_page_run(para_elem, text: str, font_name: str, size_pt:
|
|
382
|
+
def _add_page_run(para_elem, text: str, font_name: str, size_pt: float) -> None:
|
|
383
383
|
"""添加一个普通文本 run 到段落元素。"""
|
|
384
384
|
from docx.oxml import OxmlElement
|
|
385
385
|
from docx.oxml.ns import qn
|
|
@@ -402,7 +402,7 @@ def _add_page_run(para_elem, text: str, font_name: str, size_pt: int) -> None:
|
|
|
402
402
|
para_elem.append(r)
|
|
403
403
|
|
|
404
404
|
|
|
405
|
-
def _build_page_number_xml(fmt: str, font_name: str, size_pt:
|
|
405
|
+
def _build_page_number_xml(fmt: str, font_name: str, size_pt: float) -> list:
|
|
406
406
|
"""解析页码格式字符串,返回 (类型, 内容, 字体, 字号) 元素列表。"""
|
|
407
407
|
import re
|
|
408
408
|
elements = []
|
|
@@ -621,6 +621,10 @@ def inject_page_number(output_path: str, page_number_config: dict) -> None:
|
|
|
621
621
|
from docx.oxml import OxmlElement
|
|
622
622
|
from docx.oxml.ns import qn
|
|
623
623
|
from docx.shared import Pt
|
|
624
|
+
from engine.core.document.font_utils import (
|
|
625
|
+
PAGE_NUMBER_FONT,
|
|
626
|
+
PAGE_NUMBER_SIZE_PT,
|
|
627
|
+
)
|
|
624
628
|
|
|
625
629
|
enabled = page_number_config.get('enabled')
|
|
626
630
|
if enabled is None:
|
|
@@ -629,8 +633,8 @@ def inject_page_number(output_path: str, page_number_config: dict) -> None:
|
|
|
629
633
|
return
|
|
630
634
|
|
|
631
635
|
fmt = page_number_config.get('format', '- {PAGE} -')
|
|
632
|
-
font_name = page_number_config.get('font',
|
|
633
|
-
size_pt = page_number_config.get('size',
|
|
636
|
+
font_name = page_number_config.get('font', PAGE_NUMBER_FONT)
|
|
637
|
+
size_pt = page_number_config.get('size', PAGE_NUMBER_SIZE_PT)
|
|
634
638
|
align = page_number_config.get('alignment') or page_number_config.get('position', 'center')
|
|
635
639
|
if align == 'right-left':
|
|
636
640
|
align = 'right'
|
|
@@ -671,9 +675,9 @@ def inject_page_number(output_path: str, page_number_config: dict) -> None:
|
|
|
671
675
|
if is_odd_even:
|
|
672
676
|
ind = OxmlElement('w:ind')
|
|
673
677
|
if align == 'right':
|
|
674
|
-
ind.set(qn('w:right'), str(int(
|
|
678
|
+
ind.set(qn('w:right'), str(int(PAGE_NUMBER_SIZE_PT * 20)))
|
|
675
679
|
else:
|
|
676
|
-
ind.set(qn('w:left'), str(int(
|
|
680
|
+
ind.set(qn('w:left'), str(int(PAGE_NUMBER_SIZE_PT * 20)))
|
|
677
681
|
pPr.append(ind)
|
|
678
682
|
try:
|
|
679
683
|
bm = section.bottom_margin
|
package/gongwen/__init__.py
CHANGED