Legal Document Restoration logo

Legal Document Restoration

Community
vivy-yi
legal-document-restoration

法律文件脱敏稿还原——将外审后的脱敏稿 docx 按比对文件 .md 中的映射表 runs 级还原为原文,保留批注/修订/格式。 适用情形:用户要求还原脱敏稿/还原审核稿/runs 级还原/收到脱敏稿后还原成原文/外审回来后还原入库。 核心:解析比对文件 mapping 段 → runs 级精确替换(不跨 run 边界)→ 每替换一处重建 runInfo → round-trip 校验。 与 legal-document-redaction 互为反向操作——一个写出去,一个读回来。

Overview

Publishervivy-yi
RepositoryGreater-China-Legal
Skill namelegal-document-restoration
Stars
49
Forks
9
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by vivy-yi on GitHub. Read the source before you install it.

Installation

Install the Legal Document Restoration AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/vivy-yi/Greater-China-Legal/tree/main/plugins/legal-operations/legal-document-restoration
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/vivy-yi/Greater-China-Legal.git /tmp/Greater-China-Legal
mkdir -p .claude/skills
cp -r /tmp/Greater-China-Legal/plugins/legal-operations/legal-document-restoration .claude/skills/legal-document-restoration
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Legal Document Restoration in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Legal Document Restoration on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Legal Document Restoration is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

/legal-document-restoration — 法律文件脱敏稿还原

场景通用原子 skill。本 skill 与 legal-document-redaction 互为反向操作。 输入:脱敏稿(docx)+ 比对文件(.md)+ 比对文件 hash(可选) 输出:还原稿(docx)+ 还原日志 + round-trip 校验报告

一、加载上下文(必读)

调用本 skill 前必须确认:

1. 脱敏稿路径(必填)
2. 比对文件路径(必填)—— 必须包含 mapping 段
3. 输出格式(docx 默认 / md / txt)
4. 是否保留批注 / 修订痕迹(默认保留)
5. round-trip 校验是否启用(默认启用)
6. 适用法域(cn-mainland 默认 / hk / tw / sg / mo / eu)

未指定 → 暂停,要求补充(按 GCL 原子 skill 规范)。


二、还原输入解析

2.1 解析脱敏稿结构

读取脱敏稿 docx → 解析为:
  ├─ 段落树(paragraphs)
  ├─ 每个段落含 N 个 run(runs)
  ├─ 每个 run 含文本(text)+ 格式属性(font, size, color)
  └─ 批注 / 修订 / 表格 / 图片 保留

2.2 解析比对文件

读取比对文件 .md → 提取:
  ├─ ## 批次元数据(批次 UUID / 法域 / 生成时间)
  ├─ ## 映射表(占位符 | 原文 | 实体类型 | 上下文角色)
  └─ 可选 ## 文件 hash(SHA256)—— 用于校验完整性

2.3 完整性校验

若有 hash:
  - 计算脱敏稿当前 hash → 与比对文件声明的 hash 对比
  - 不一致 → 拒绝还原(标 [ERROR] 比对文件与脱敏稿不匹配)
若无 hash:
  - 提示用户确认脱敏稿未被篡改

三、runs 级精确替换(核心)

3.1 替换原则

  • 不跨 run 边界:每个占位符必须完整位于一个 run 内,若跨 run 则失败(标 [WARN])
  • 按出现顺序处理:从文档头到尾逐个 run 处理,避免重复匹配
  • 每替换一处重建 runInfo:替换后立即重建 run 的格式属性(font / size / color / bold 等),避免格式错位
  • 大小写敏感:占位符大小写必须与比对文件 mapping 完全一致

3.2 替换流程

步骤 1:扫描所有 run,构建占位符 → run 位置索引
步骤 2:按位置顺序遍历索引
步骤 3:每个占位符执行:
        a. 检查是否完整在单 run 内(否则 [WARN] 跳过)
        b. 用 mapping 中的原文替换占位符
        c. 重建该 run 的格式属性
        d. 记录替换日志(位置 / 占位符 / 原文 / 上下文)
步骤 4:保存还原稿 docx

3.3 失败处理

失败类型处理
占位符跨 run标 [WARN] 跳过该占位符,记录位置
占位符在 mapping 中找不到标 [WARN] 跳过,记录脱敏稿位置
原文在脱敏稿中已存在标 [WARN] 可能重复占位符,跳过
run 格式属性丢失重建 runInfo,使用前一个 run 的格式兜底

四、格式保留

4.1 必须保留

  • ✅ 字体 / 字号 / 颜色 / 加粗 / 斜体 / 下划线
  • ✅ 段落结构 / 缩进 / 对齐
  • ✅ 表格结构 / 单元格合并 / 边框
  • ✅ 列表(有序 / 无序 / 多级)
  • ✅ 修订痕迹(w:ins / w:del)
  • ✅ 批注(w:commentReference)
  • ✅ 页眉页脚 / 页码

4.2 不应变更

  • ❌ 不修改脱敏稿之外的元数据(作者 / 创建时间)
  • ❌ 不删除批注 / 修订(即使与脱敏内容无关)
  • ❌ 不重新计算页码 / 目录

五、round-trip 校验

核心安全机制:还原后的文件再次脱敏,应得到与原脱敏稿一致的输出。

5.1 校验流程

还原稿 → 调用 legal-document-redaction(相同参数)→ 输出新脱敏稿
对比:新脱敏稿 与 原脱敏稿
  ├─ 一致 → round-trip 通过 ✅
  └─ 不一致 → round-trip 失败 [ERROR]

5.2 失败场景

失败原因排查方向
占位符未完全还原检查 runs 跨边界情况
还原时引入新占位符检查原文是否含触发脱敏的字符
格式破坏导致识别失败检查 runInfo 重建逻辑
比对文件与脱敏稿不匹配检查 hash 校验

5.3 强制约束

  • ❌ round-trip 校验失败时禁止输出还原稿——输出"[ERROR] 还原失败,请人工核对"
  • ❌ 不可跳过 round-trip 直接交付还原稿

六、输出格式

markdown
## [A] 还原元数据
- 原脱敏稿:<文件名>
- 比对文件:<文件名>
- 还原计数:N 处
- round-trip 校验:<通过/失败>
- hash 校验:<通过/失败/未提供>

## [B] 还原后文本
[完整原文,保留原格式]

## [C] 还原日志
- [WARN] 占位符未匹配(位置 / 占位符)
- [WARN] 跨 run 边界(位置 / 占位符)
- [ERROR] hash 不一致 / round-trip 失败
- [SKIP] 批注 / 修订未处理(附说明)

七、与场景的协作

本 skill 是 legal-document-redaction 的反向操作,调用方相同但顺序相反:

上游场景触发时机用途
contract-review外审合同稿收回后还原入库 + 内部留底
litigation-support外审案例分享稿收回后还原入内部案例库
data-compliancePIPL 审查外发样本收回后还原留底
cocounsel-legal外部律师协办稿收回后还原到内部系统
employment-legal监管外发文书收回后还原留底
government-investigation外审调查材料收回后还原归档
law-student / legal-clinic外部批改收回后还原到教学档案

配套 references / 相邻 skill:

  • legal-document-redaction/ — 反向操作(脱敏)
  • legal-document-redaction/references/config.md — 白/黑/自定义类型(脱敏时的配置)
  • shared/matter-workspace/ — 案件工作区(实际路径 plugins/legal-scenes/<本场景>/matters/<slug>/)

八、禁用与边界

  • ❌ 不可逆模式不可还原——映射表已销毁,物理上无法还原
  • ❌ 比对文件被篡改 → 拒绝还原——hash 校验失败的脱敏稿不予还原
  • ❌ 跨案映射表不可复用——每个案号独立比对文件
  • ❌ 禁止还原刑事证据原件——破坏证据完整性,需走原件流程
  • ❌ 禁止跳过 round-trip 校验——失败即拒绝输出
  • ❌ 禁止跨 run 边界强行替换——可能导致 run 错位,宁可标 [WARN] 跳过

九、版本与变更

版本日期变更
1.0.02026-06-24初版:runs 级精确替换 + 格式保留 + round-trip 校验

★ Insight ─────────────────────────────────────

  • runs 级替换是 docx 还原的核心难点:docx 不是纯文本,每个字符在 run 里。直接正则全文替换会破坏 run 边界与格式属性。必须按 run 粒度逐个处理,每替换一处重建 runInfo——这是参考通用开源工具还原逻辑的核心工程要求。
  • round-trip 是安全网:还原后再次脱敏应得到原脱敏稿。看似多余但实际是检测"还原完整性 + 还原过程不引入新触发字符"的关键校验。失败即拒绝输出,宁可人工核对也不冒险。
  • 本 skill 与脱敏 skill 互为镜像:trigger_phrases、§ 七协作链路、§ 八禁用边界都成对设计。修改任一边时记得同步另一边,避免一致性漂移。 ─────────────────────────────────────────────────

Frequently asked questions

What does the Legal Document Restoration AI skill do?

法律文件脱敏稿还原——将外审后的脱敏稿 docx 按比对文件 .md 中的映射表 runs 级还原为原文,保留批注/修订/格式。 适用情形:用户要求还原脱敏稿/还原审核稿/runs 级还原/收到脱敏稿后还原成原文/外审回来后还原入库。 核心:解析比对文件 mapping 段 → runs 级精确替换(不跨 run 边界)→ 每替换一处重建 runInfo → round-trip 校验。 与 legal-document-redaction 互为反向操作——一个写出去,一个读回来。

Why use Legal Document Restoration on TypingMind?

Because you install it once and use it with any model. Legal Document Restoration is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Legal Document Restoration in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/vivy-yi/Greater-China-Legal/tree/main/plugins/legal-operations/legal-document-restoration. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Legal Document Restoration?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Legal Document Restoration?

As many as you like. As long as a model supports skills, you can use Legal Document Restoration with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Legal Document Restoration AI skill free?

It is published on GitHub by vivy-yi. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇