---
name: create-scripture
description: "将佛学经典蒸馏成 AI Skill。导入书籍原文与注疏，生成义理体系 + 说法角色，支持持续追加与诠释校正。 | Distill Buddhist scriptures into AI Skills. Import texts & commentaries, generate doctrine system + teaching persona, with continuous evolution."
argument-hint: "[scripture-name-or-slug]"
version: "1.0.0"
user-invocable: true
allowed-tools: Read, Write, Edit, Bash
---

> **Language / 语言**: This skill supports both English and Chinese. Detect the user's language from their first message and respond in the same language throughout.
>
> 本 Skill 支持中英文。根据用户第一条消息的语言，全程使用同一语言回复。

# 佛经.skill 创建器

## 触发条件

当用户说以下任意内容时启动：
- `/create-scripture`
- "帮我创建一个佛经 skill"
- "我想蒸馏一部经典"
- "新建经典"
- "给我做一个 XX 的 skill"

当用户对已有经典 Skill 说以下内容时，进入进化模式：
- "我有新书" / "追加一本"
- "这个解释不对" / "应该按 XX 的说法"
- `/update-scripture {slug}`

当用户说 `/list-scriptures` 时列出所有已生成的经典。

---

## 工具使用规则

本 Skill 运行在 Claude Code 环境，使用以下工具：

| 任务 | 使用工具 |
|------|---------| 
| 读取 PDF 书籍 | `Read` 工具（原生支持 PDF） |
| 读取图片/扫描版 | `Read` 工具（原生支持图片） |
| 读取 MD/TXT 文件 | `Read` 工具 |
| 读取 EPUB 电子书 | `Bash` → `python3 ${CLAUDE_SKILL_DIR}/tools/epub_parser.py` |
| 写入/更新 Skill 文件 | `Write` / `Edit` 工具 |
| 版本管理 | `Bash` → `python3 ${CLAUDE_SKILL_DIR}/tools/version_manager.py` |
| 列出已有 Skill | `Bash` → `python3 ${CLAUDE_SKILL_DIR}/tools/skill_writer.py --action list` |

**基础目录**：Skill 文件写入 `./scriptures/{slug}/`（相对于本项目目录）。

---

## 主流程：创建新经典 Skill

### Step 1：基础信息录入（3 个问题）

参考 `${CLAUDE_SKILL_DIR}/prompts/intake.md` 的问题序列，只问 3 个问题：

1. **经典名称**（必填）
   - 示例：`金刚经`、`心经`、`六祖坛经`
2. **经典定位**（一句话：传承、类型、核心关注）
   - 示例：`大乘般若部 般若空性 鸠摩罗什译`
3. **角色定位**（你期望 AI 以什么身份说法？特点？）
   - 示例：`禅宗风格 直指人心 结合现代生活 不说教`

除名称外均可跳过。收集完后汇总确认再进入下一步。

### Step 2：原材料导入

询问用户提供原材料，展示方式供选择：

```
原材料怎么提供？

  [A] 上传书籍文件
      PDF / EPUB / TXT / Markdown
      支持一次导入多本，如原典 + 多家注疏

  [B] 直接粘贴内容
      把经文或注解文字复制进来

  [C] 提供书籍目录结构
      先告诉我有哪些书和章节，我来指导分段蒸馏

可以混用，也可以跳过（凭基础信息生成最小 Skill）。
```

#### 长文本分段策略

佛经书籍通常较长（数万至数十万字），需分段蒸馏：

1. 用户提供**目录结构**后，规划蒸馏顺序
2. 按逻辑单元分段读取（如按品/章/节）
3. 每段读取后提取增量知识，合并到对应模块
4. 保持全局一致性——每次合并后检查是否与已有义理冲突

**优先级**：
- 经文原典 > 权威注疏 > 通俗解读 > 学术论文
- 同一段落有多家解释时，标注各家观点，不做取舍

---

### Step 3：分析原材料

将收集到的所有原材料和用户填写的基础信息汇总，按以下两条线分析：

**线路 A（义理体系 / Doctrine）**：
- 参考 `${CLAUDE_SKILL_DIR}/prompts/doctrine_analyzer.md` 中的提取维度
- 提取：核心义理、重要概念、修行法门、经典名句、论证结构
- 根据经典类型重点提取（般若部/净土/禅宗/唯识不同侧重）

**线路 B（说法角色 / Teaching Persona）**：
- 参考 `${CLAUDE_SKILL_DIR}/prompts/persona_analyzer.md` 中的提取维度
- 从原材料中提取：说法风格、譬喻方式、应机方式、语言特征
- 结合用户指定的角色定位

### Step 4：生成并预览

参考 `${CLAUDE_SKILL_DIR}/prompts/doctrine_builder.md` 生成义理体系内容。
参考 `${CLAUDE_SKILL_DIR}/prompts/persona_builder.md` 生成说法角色内容。

向用户展示摘要，询问：
```
义理体系摘要：
  - 核心思想：{xxx}
  - 重要概念：{xxx}
  - 修行指导：{xxx}
  ...

说法角色摘要：
  - 说法风格：{xxx}
  - 譬喻方式：{xxx}
  - 应机特点：{xxx}
  ...

确认生成？还是需要调整？
```

### Step 5：写入文件

用户确认后，执行以下写入操作：

**1. 创建目录结构**（用 Bash）：
```bash
mkdir -p scriptures/{slug}/versions
mkdir -p scriptures/{slug}/sources
```

**2. 写入 doctrine.md**（用 Write 工具）：
路径：`scriptures/{slug}/doctrine.md`

**3. 写入 persona.md**（用 Write 工具）：
路径：`scriptures/{slug}/persona.md`

**4. 写入 meta.json**（用 Write 工具）：
路径：`scriptures/{slug}/meta.json`
内容：
```json
{
  "name": "{name}",
  "slug": "{slug}",
  "created_at": "{ISO时间}",
  "updated_at": "{ISO时间}",
  "version": "v1",
  "scripture_info": {
    "tradition": "{传承}",
    "category": "{类别}",
    "translator": "{译者}",
    "original_language": "{原语言}"
  },
  "teaching_style": {
    "persona": "{角色定位}",
    "tags": [...]
  },
  "sources": [...已蒸馏书籍列表],
  "corrections_count": 0
}
```

**5. 生成完整 SKILL.md**（用 Write 工具）：
路径：`scriptures/{slug}/SKILL.md`

SKILL.md 结构：
```markdown
---
name: scripture-{slug}
description: {name}，{tradition} {category}
user-invocable: true
---

# {name}

{tradition} · {category} · {translator}

---

## PART A：义理体系

{doctrine.md 全部内容}

---

## PART B：说法角色

{persona.md 全部内容}

---

## 运行规则

1. 先由 PART B 判断：以什么方式回应这个问题？
2. 再由 PART A 执行：基于义理体系组织回答内容
3. 输出时始终保持 PART B 的说法风格
4. 引用经文时标注出处（品名/章节）
5. 多家注疏有不同解释时，呈现主要观点并说明差异
6. PART B Layer 0 的规则优先级最高，任何情况下不得违背
```

告知用户：
```
✅ 经典 Skill 已创建！

文件位置：scriptures/{slug}/
触发词：/{slug}（完整版）
        /{slug}-doctrine（仅义理问答）
        /{slug}-persona（仅说法角色）

可以继续追加书籍：发送「追加一本」或上传新文件。
如果觉得某个解释不对，直接说「这个解释应该按 XX 的说法」。
```

---

## 进化模式：追加书籍

用户提供新书籍时：

1. 按 Step 2 的方式读取新内容
2. 用 `Read` 读取现有 `scriptures/{slug}/doctrine.md` 和 `persona.md`
3. 参考 `${CLAUDE_SKILL_DIR}/prompts/merger.md` 分析增量内容
4. 存档当前版本（用 Bash）：
   ```bash
   python3 ${CLAUDE_SKILL_DIR}/tools/version_manager.py --action backup --slug {slug} --base-dir ./scriptures
   ```
5. 用 `Edit` 工具追加增量内容到对应文件
6. 重新生成 `SKILL.md`（合并最新 doctrine.md + persona.md）
7. 更新 `meta.json` 的 version、updated_at 和 sources

---

## 进化模式：诠释校正

用户表达"这个解释不对"/"应该按 XX 的说法"时：

1. 参考 `${CLAUDE_SKILL_DIR}/prompts/correction_handler.md` 识别校正内容
2. 判断属于 Doctrine（义理/概念）还是 Persona（说法风格）
3. 生成 correction 记录
4. 用 `Edit` 工具追加到对应文件的 `## Correction 记录` 节
5. 重新生成 `SKILL.md`

---

## 管理命令

`/list-scriptures`：
```bash
python3 ${CLAUDE_SKILL_DIR}/tools/skill_writer.py --action list --base-dir ./scriptures
```

`/scripture-rollback {slug} {version}`：
```bash
python3 ${CLAUDE_SKILL_DIR}/tools/version_manager.py --action rollback --slug {slug} --version {version} --base-dir ./scriptures
```

`/delete-scripture {slug}`：
确认后执行：
```bash
rm -rf scriptures/{slug}
```

---

# English Version

# Scripture.skill Creator

## Trigger Conditions

Activate when the user says any of the following:
- `/create-scripture`
- "Help me create a scripture skill"
- "I want to distill a classic text"
- "New scripture"
- "Make a skill for XX"

Enter evolution mode when the user says:
- "I have a new book" / "append"
- "This interpretation is wrong" / "It should follow XX's interpretation"
- `/update-scripture {slug}`

List all generated scriptures when the user says `/list-scriptures`.

---

## Tool Usage Rules

This Skill runs in the Claude Code environment with the following tools:

| Task | Tool |
|------|------|
| Read PDF books | `Read` tool (native PDF support) |
| Read image/scanned pages | `Read` tool (native image support) |
| Read MD/TXT files | `Read` tool |
| Read EPUB e-books | `Bash` → `python3 ${CLAUDE_SKILL_DIR}/tools/epub_parser.py` |
| Write/update Skill files | `Write` / `Edit` tool |
| Version management | `Bash` → `python3 ${CLAUDE_SKILL_DIR}/tools/version_manager.py` |
| List existing Skills | `Bash` → `python3 ${CLAUDE_SKILL_DIR}/tools/skill_writer.py --action list` |

**Base directory**: Skill files are written to `./scriptures/{slug}/` (relative to the project directory).

---

## Main Flow: Create a New Scripture Skill

### Step 1: Basic Info Collection (3 questions)

Refer to `${CLAUDE_SKILL_DIR}/prompts/intake.md` for the question sequence. Only ask 3 questions:

1. **Scripture name** (required)
   - Example: `Diamond Sutra`, `Heart Sutra`, `Platform Sutra`
2. **Scripture context** (one sentence: tradition, category, core focus)
   - Example: `Mahayana Prajnaparamita, Sunyata teachings, Kumarajiva translation`
3. **Teaching persona** (what role should the AI assume? What style?)
   - Example: `Zen style, direct pointing, modern life application, non-preachy`

Everything except the name can be skipped. Summarize and confirm before moving to the next step.

### Step 2: Source Material Import

Ask the user how they'd like to provide materials:

```
How would you like to provide source materials?

  [A] Upload book files
      PDF / EPUB / TXT / Markdown
      Multiple books at once (e.g., original text + commentaries)

  [B] Paste text directly
      Copy-paste scripture or commentary text

  [C] Provide book table of contents
      Tell me what books and chapters you have, I'll guide segmented distillation

Can mix and match, or skip entirely (generate minimal Skill from basic info).
```

#### Long Text Segmentation Strategy

Buddhist texts can be very long (tens to hundreds of thousands of characters). Segmented distillation:

1. User provides **table of contents** → plan distillation order
2. Read in logical units (by chapter/section/品)
3. Extract incremental knowledge after each segment, merge into corresponding modules
4. Maintain global consistency — check for doctrinal conflicts after each merge

**Priority**:
- Original scripture text > Authoritative commentaries > Popular interpretations > Academic papers
- When multiple interpretations exist for the same passage, note all perspectives without choosing sides

---

### Step 3: Analyze Source Material

Combine all collected materials with user-provided basic info, analyze along two tracks:

**Track A (Doctrine System)**:
- Refer to `${CLAUDE_SKILL_DIR}/prompts/doctrine_analyzer.md`
- Extract: core doctrines, key concepts, practice methods, famous passages, argument structures
- Focus extraction based on scripture type (Prajnaparamita/Pure Land/Chan/Yogacara)

**Track B (Teaching Persona)**:
- Refer to `${CLAUDE_SKILL_DIR}/prompts/persona_analyzer.md`
- Extract: teaching style, metaphor patterns, responsive teaching methods, language characteristics
- Combine with user-specified persona

### Step 4: Generate and Preview

Refer to `${CLAUDE_SKILL_DIR}/prompts/doctrine_builder.md` for doctrine content.
Refer to `${CLAUDE_SKILL_DIR}/prompts/persona_builder.md` for teaching persona.

Show summary to user and ask for confirmation.

### Step 5: Write Files

After user confirmation, write all files following the same structure as the Chinese version above.

---

## Evolution Mode: Append Books

When user provides new books:

1. Read new content as in Step 2
2. `Read` existing `scriptures/{slug}/doctrine.md` and `persona.md`
3. Refer to `${CLAUDE_SKILL_DIR}/prompts/merger.md` for incremental analysis
4. Backup current version
5. `Edit` to append incremental content
6. Regenerate `SKILL.md`
7. Update `meta.json`

---

## Evolution Mode: Interpretation Correction

When user says "this interpretation is wrong" / "should follow XX's interpretation":

1. Refer to `${CLAUDE_SKILL_DIR}/prompts/correction_handler.md`
2. Determine if it affects Doctrine or Persona
3. Generate correction record
4. Append to corresponding file's `## Correction 记录` section
5. Regenerate `SKILL.md`

---

## Management Commands

`/list-scriptures`:
```bash
python3 ${CLAUDE_SKILL_DIR}/tools/skill_writer.py --action list --base-dir ./scriptures
```

`/scripture-rollback {slug} {version}`:
```bash
python3 ${CLAUDE_SKILL_DIR}/tools/version_manager.py --action rollback --slug {slug} --version {version} --base-dir ./scriptures
```

`/delete-scripture {slug}`:
After confirmation:
```bash
rm -rf scriptures/{slug}
```
