---
name: paragraph-reorder-yashu
description: 主题聚类重排文章段落顺序，将语义相近的段落归组消除话题跳跃。激活条件：用户消息须包含以下关键词之一:`调整段落顺序`、`段落重排`、`重排文章段落`、`段落顺序不合适`。
metadata:
  author: "牙叔教程"
  updated: "2026-07-14 14:10:00"
  version: "1.0.0"
title: paragraph-reorder-yashu
canonical_url: https://skilld.dev/gh/steelan9199/wechat-publisher/paragraph-reorder-yashu
last_updated: 2026-10-07T07:20:50.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install steelan9199/wechat-publisher/paragraph-reorder-yashu`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/paragraph-reorder-yashu`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/steelan9199/wechat-publisher/paragraph-reorder-yashu) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/paragraph-reorder-yashu`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/paragraph-reorder-yashu --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/paragraph-reorder-yashu --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 段落顺序重排

## 功能概述

本技能通过主题聚类策略重排文章段落顺序。AI 语义分析每个段落的核心主题，将语义相近的段落归组放在一起，消除"话题跳跃"现象，使文章读起来更连贯。调整后直接覆盖原文件，同时生成备份。

**适用场景**：信息密度高、段落较多、话题分散的长文（观点类、技术类、资讯类文章）。

**不适用场景**：叙事类（按时间线展开）、流程类（按步骤展开）等段落顺序有内在逻辑约束的文章。

## 环境说明

- 本技能无脚本依赖，由 AI 自身语义理解能力驱动，无需安装任何依赖。
- 运行命令时统一使用 **PowerShell 5** 语法。
- `$SKILL_DIR` 指代本技能所在目录，即 `SKILL.md` 文件所在的文件夹。
- 本技能操作用户指定的 Markdown 文件（读取、备份、覆盖写入）。

## 执行步骤

| 步骤 | 执行动作 | 具体操作 |
|------|---------|---------|
| 1 | 获取文件路径 | 从用户消息中提取文章文件路径。若用户未指定路径，询问用户提供文章文件路径。 |
| 2 | 读取文章 | 运行 `Read` 工具读取用户指定的 Markdown 文件全文。 |
| 3 | 段落切分 | 将文章内容按空行（双换行）切分为段落块。代码块（```...```）即使内部含空行也视为单个段落单元。为每个段落记录原始位置索引（从 1 开始）。详细切分规则见【段落切分规则】。 |
| 4 | 段落数量检查 | 统计段落数量。若 ≤3 段 -> 输出"文章段落数量过少（N 段），无需调整"并结束执行。 |
| 5 | 语义分析与主题聚类 | AI 逐段分析核心主题，将主题相关/相近的段落归入同一聚类组。聚类组内保持原始相对顺序（稳定排序）。聚类组之间按该组首个段落原始出现顺序排列，最小化对原文结构的扰动。详细策略见【聚类排序策略】。 |
| 6 | 顺序评估 | 比较新顺序与原始顺序。若完全一致 -> 输出"当前段落顺序已合理，无需调整"并结束执行。若不一致 -> 继续下一步。 |
| 7 | 展示对照表 | 输出段落映射对照表，格式见【输出格式】。此步骤仅为信息展示，不暂停等待用户确认。 |
| 8 | 创建备份 | 运行 `Copy-Item "{原文件路径}" "{原文件目录}\{原文件名去扩展}_backup_{yyyyMMdd_HHmmss}.{扩展名}"` 创建备份文件。 |
| 9 | 写入重排结果 | 使用 `Write` 工具将重排后的完整内容写入原文件路径。禁止使用 `Set-Content`、`Out-File` 等 PowerShell 写入命令，避免 BOM 编码问题。重排内容 = 按新顺序拼接段落，段落之间用双换行（空行）分隔。 |
| 10 | 输出结果摘要 | 输出备份文件路径、已更新原文件路径、调整段落数量，格式见【输出格式】。 |

### 段落切分规则

段落切分是重排的基础，切分错误会导致文章结构损坏。遵循以下规则：

| 场景 | 处理方式 | 原因 |
|------|---------|------|
| 普通文本块 | 按空行分隔，每个连续非空行块为一个段落 | Markdown 标准段落定义 |
| 代码块（```...```） | 整体视为一个段落单元，不因内部空行拆分 | 代码块内部空行是代码结构的一部分，拆分会破坏代码完整性 |
| 标题行（#、## 等） | AI 语义判断：若标题与紧随其后的段落构成同一主题单元，则合并为一个段落；否则标题独立为一段 | 标题通常是其后续内容的概括，拆开可能导致标题与内容分离 |
| 列表块（-、1. 等） | 连续的列表项（无空行分隔）视为一个段落单元 | 列表项之间无空行时属于同一逻辑块，拆分会破坏列表结构 |

### 聚类排序策略

聚类排序是本技能的核心，遵循以下原则：

1. **主题识别**：AI 为每个段落提炼一个 2-5 字的主题标签（如"性能优化""背景介绍""方案对比"）。
2. **聚类归组**：将主题相同或语义相关的段落归入同一组。例如"性能优化"和"加载速度"归为一组。
3. **组内稳定排序**：同一聚类组内，段落保持原始相对顺序不变，不额外翻转。
4. **组间排序**：聚类组之间，按该组中最早出现的段落的原始位置排序。这样能最大限度保留原文的整体走向。
5. **最小扰动原则**：如果两种排列方案的主题连贯度相近，选择对原文改动最小的方案。

## 输出格式

### 段落映射对照表（步骤 7 输出）

```
| 原位置 | 新位置 | 主题标签 | 段落预览（前 20 字） |
|--------|--------|---------|---------------------|
| 1      | 1      | 引言     | 本文将介绍...         |
| 5      | 2      | 引言     | 在实际应用中...       |
| 2      | 3      | 性能     | 性能优化是...         |
| 4      | 4      | 性能     | 通过缓存机制...       |
| 3      | 5      | 总结     | 综上所述...           |
```

### 结果摘要（步骤 10 输出）

```
## 重排完成

- 备份文件：{备份文件路径}
- 已更新：{原文件路径}
- 调整段落数：{N} 段（共 {M} 段中有 {N} 段位置发生变化）
```

## 错误处理

| 错误场景 | 错误表现 | 处理方式 |
|---------|---------|---------|
| 文件不存在 | `Read` 报错文件不存在 | 检查路径是否正确，提示用户确认文件路径 |
| 文件为空 | 读取后内容为空 | 输出"文件内容为空，无需调整"并结束执行 |
| 无段落结构 | 整篇文章只有一个段落块（无空行分隔） | 输出"文章只有一个段落，无需调整"并结束执行 |
| 写入失败 | `Write` 返回错误 | 检查文件是否被其他程序占用，提示用户关闭后重试 |
| 备份失败 | `Copy-Item` 报错 | 检查磁盘空间和路径权限，提示用户处理后重试 |
