$npx -y skills add pa1nrui1/legal-skills --skill 法律文书模板与导出统一处理法律工作中最终需要输出本地 Word(.docx)的文书、报告、清单、笔录、意见书、函件、合同和正式交付文件。由法律工作总控强制路由调用;业务 Skill 负责正文和法律判断,本 Skill 负责选择格式 profile、接收语义 HTML 或要素式填充数据、导出 DOCX、结构体检和兜底模板。
| 1 | # 法律文书模板与导出 |
| 2 | |
| 3 | 本 Skill 只处理最终 Word 的格式与导出,不替代业务 Skill 的事实梳理、法律分析、文书正文生成、材料读取复查、法规核验和出稿前审查。 |
| 4 | |
| 5 | ## 法律工作总控规则(强制) |
| 6 | |
| 7 | 执行本 Skill 前,必须先遵循: |
| 8 | - skills/legal/法律工作总控/references/practice-profile.md |
| 9 | - skills/legal/法律工作总控/references/source-boundary-protocol.md |
| 10 | |
| 11 | 本 Skill 继承 `practice-profile.md` 的子 Skill 执行质量门;审查报告、来源边界或验证结果缺失时,不得标记为正式交付。 |
| 12 | |
| 13 | ## 强制路由 |
| 14 | |
| 15 | - 凡最终产物是本地 `.docx` 的法律文书、报告、清单、笔录、意见书、函件、合同或正式交付文件,必须调用本 Skill。 |
| 16 | - `法律工作总控` 负责判断是否进入本 Skill;用户直接点名业务 Skill 生成 Word 时,业务 Skill 也必须先通过 `法律文书出稿前审查`,再调用本 Skill。 |
| 17 | - 普通线性文书正式交付接收 `法律文书出稿前审查` 生成的 `draft_checked.html`,并必须附带审查报告。 |
| 18 | - 要素式表单文书正式交付接收经质控通过的 `complaint-data.json`、`fill-plan.json` 和模板克隆质控报告,使用 DOCX 母版克隆填充链路。 |
| 19 | - 审查报告不是 `PASS` 或 `FIXED_PASS` 时,禁止生成正式 `.docx`。 |
| 20 | - 未命中专用 profile 时,使用 `fallback_desktop_word`。 |
| 21 | - 原 Skill 中保留的 `python-docx`、`Node.js docx`、Word 导出示例或旧技术方案只作为迁移评估来源/历史参考;不得作为最终 Word 导出路径执行。 |
| 22 | - 普通线性文书走本 Skill 的语义 HTML -> `html_to_docx.py` -> DOCX 链路。 |
| 23 | - 要素式表单文书走 DOCX 母版 -> `fill_docx_template.py` -> 清洁 DOCX 链路;不得用全局字符串替换驱动正式填充。 |
| 24 | |
| 25 | ## 输入约定 |
| 26 | |
| 27 | 普通线性文书:业务 Skill 应先生成语义 HTML,并经 `法律文书出稿前审查` 生成 `draft_checked.html`。使用 XHTML 兼容写法: |
| 28 | |
| 29 | - `h1`:文书标题。 |
| 30 | - `h2` / `h3`:层级标题。 |
| 31 | - `p.meta`:申请人、当事人、案号、法院、基础信息。 |
| 32 | - `p.body` 或普通 `p`:正文段落。 |
| 33 | - `p.signature`:落款。 |
| 34 | - `table`:真实表格。 |
| 35 | - `section`:附件、事实、理由、请求、证据目录等区块。 |
| 36 | |
| 37 | 要素式表单文书:业务 Skill 应生成结构化字段和填充计划: |
| 38 | |
| 39 | - `complaint-data.json`:当事人、送达、诉请、事实、担保、证据、落款等字段数据,字段应有来源或缺口说明。 |
| 40 | - `fill-plan.json`:每个字段的表格坐标、锚点和填充模式;重复锚点必须用表格坐标定位。 |
| 41 | - `qc-report.json` / `qc-report.md`:模板克隆质控报告,状态必须为 `PASS`。 |
| 42 | |
| 43 | ## Profile |
| 44 | |
| 45 | 内置 profile 位于 `assets/profiles/`: |
| 46 | |
| 47 | - `litigation_standard`:诉讼/刑辩通用文书。 |
| 48 | - `legal_report`:法律服务建议书、检索报告、案件提纲等。 |
| 49 | - `judgment_style`:民事判决书、审理报告等特殊法院文书样式。 |
| 50 | - `entrustment_authorization`:委托合同管理-授权委托书。 |
| 51 | - `entrustment_contract`:委托合同管理-委托代理合同。 |
| 52 | - `entrustment_risk_notice`:委托合同管理-风险义务告知书。 |
| 53 | - `entrustment_statement_record`:委托合同管理-委托人陈述笔录/案件沟通记录。 |
| 54 | - `entrustment_supervision_card`:委托合同管理-服务质量监督卡。 |
| 55 | - `legal_representative_certificate`:委托合同管理-法定代表人身份证明书。 |
| 56 | - `contract_standard`:解除协议、补充协议、终止协议、无专门排版规范的合同正式文本。 |
| 57 | - `litigation_visualization`:诉讼可视化图表嵌入 Word。 |
| 58 | - `fallback_desktop_word`:无专用模板时的兜底桌面 Word。 |
| 59 | |
| 60 | ## 模板匹配与版本门禁 |
| 61 | |
| 62 | 全局模板登记表位于 `assets/legal-template-registry.json`,只做索引和门禁,不迁移各业务 Skill 的正文模板或外部模板文件。正式合同类 Word 如存在内容模板来源,应先生成 `template-selection.json`: |
| 63 | |
| 64 | ```bash |
| 65 | python scripts/select_legal_template.py \ |
| 66 | --source-skill 合同起草 \ |
| 67 | --doc-type 解除委托协议 \ |
| 68 | --business-scene 撤诉解除委托 \ |
| 69 | --user-request "客户撤诉,费用不退,留存抵扣后续法律服务" \ |
| 70 | --source-template-path "模板源文件.docx" \ |
| 71 | --output template-selection.json |
| 72 | ``` |
| 73 | |
| 74 | 选择结果必须写入 `preflight-meta.json`,至少包括 `template_selection_path`、`content_template_id`、`content_template_version`、`content_template_sha256`、`profile_id`、`profile_version` 和 `format_standard`。未命中登记表、模板 sha256 不一致、多候选冲突或 profile 不兼容时,不得进入正式导出。 |
| 75 | |
| 76 | ## 导出命令 |
| 77 | |
| 78 | ```bash |
| 79 | python scripts/html_to_docx.py \ |
| 80 | --input draft_checked.html \ |
| 81 | --output output.docx \ |
| 82 | --profile litigation_standard \ |
| 83 | --preflight-report 出稿前审查报告.md |
| 84 | ``` |
| 85 | |
| 86 | 如未指定或未找到 profile,脚本使用 `fallback_desktop_word`。 |
| 87 | |
| 88 | 要素式表单文书导出: |
| 89 | |
| 90 | ```bash |
| 91 | python scripts/fill_docx_template.py \ |
| 92 | --template 母版.docx \ |
| 93 | --plan fill-plan.json \ |
| 94 | --output output.docx \ |
| 95 | --log fill-execution-log.json |
| 96 | ``` |
| 97 | |
| 98 | 一键质控验证: |
| 99 | |
| 100 | ```bash |
| 101 | python scripts/run_template_clone_qc.py \ |
| 102 | --template-id civil_complaint_private_lending_v1 \ |
| 103 | --fixture private_lending_basic \ |
| 104 | --out /tmp/legal_template_clone_qc |
| 105 | ``` |
| 106 | |
| 107 | 全部登记起诉状母版结构/渲染回归: |
| 108 | |
| 109 | ```bash |
| 110 | python scripts/run_template_clone_qc.py \ |
| 111 | --all \ |
| 112 | --fixture structure_only \ |
| 113 | --out /tmp/legal_template_clone_all_qc |
| 114 | ``` |
| 115 | |
| 116 | 双通道回归验证(同时验证旧 HTML 链路和新模板克隆链路): |
| 117 | |
| 118 | ```bash |
| 119 | python scripts/run_dual_docx_qc.py --out /tmp/legal_dual_docx_qc |
| 120 | ``` |
| 121 | |
| 122 | ## 失败与兜底 |
| 123 | |
| 124 | - 普通线性文书的 `draft_checked.html`、审查报告或 profile 缺失时,停止导出并退回 `法律文书出稿前审查` 或业务 Skill 补齐。 |
| 125 | - 要素式表单文书的模板登记、母版 DOCX、`complaint-data.json`、`fill-plan.json` 或模板克隆质控报告缺失时,停止导出并退回业务 Skill 或模板克隆质控补齐。 |
| 126 | - `html_to_docx.py` 执行失败时,报告本次命令、错误摘要和输入文件路径;不得输出未验证的 `.docx`。 |
| 127 | - 专用 profile 不存在、JSON 解析失败或 manifest 异常时,使用 `fallback_desktop_word` 重新导出,并在交付说明中标注兜底 profile。 |
| 128 | - `health_check.py` 未通过时,不得宣称 Word 已交付;先修复导出问题,修复失败则保留中间文件和错误摘要。 |
| 129 | |
| 130 | ## 验证命令 |
| 131 | |
| 132 | ```bash |
| 133 | python scripts/health_check.py |
| 134 | python scripts/health_check.py --docx output.docx --expect-title "文书标题" |
| 135 | python scripts/health_check.py --docx output.docx --expect-title "解除委托协议" --format-standard contract_standard |
| 136 | python scripts/health_check.py --docx output.docx --expect-clean-clone --template-clone-report qc-report.json |
| 137 | ``` |
| 138 | |
| 139 | 验证至少检查: |
| 140 | |
| 141 | - profile JSON 可解析。 |
| 142 | - manifest 可解析。 |
| 143 | - DOCX 可解包。 |
| 144 | - `word/document.xml` 存在。 |
| 145 | - 标题文本存在。 |
| 146 | - 页边距配置存在。 |
| 147 | - 指定 `--format-standard contract_standard` 时,反查 DOCX XML 中实际字号、字体和行距;合同正式文本正文和 meta 不得小于小四,行距应为 1.5 倍或固定 24-28 磅。 |
| 148 | - 页码字段存在。 |
| 149 | - 表格生成真实 `w:tbl`。 |
| 150 | - 要素式表单文书的模板克隆 manifest 可解析。 |
| 151 | - 清洁模板填充 DOCX 不含 `w:ins`、`w:del`、`trackRevisions` 或 comments。 |
| 152 | - 模板克隆质控报告状态为 `PASS`。 |
| 153 | |
| 154 | 正式交付包审计: |
| 155 | |
| 156 | ```bash |
| 157 | python scripts/audit_formal_delivery.py \ |
| 158 | --bundle-dir 正式交付目录 \ |
| 159 | --docx 正式交付文件.docx |
| 160 | ``` |
| 161 | |
| 162 | 正式 `.docx` 不得仅凭“文件已生成”标记完成。普通 HTML 交付包必须具备 `draft.html`、`preflight-meta.json` |