About text-truncator
text-truncator is a skill for shortening text to a specified limit, for long-text preprocessing, previews, and content editing. It prioritizes semantic or paragraph boundaries and reports the resulting length and cutoff location.
Key features
- 01Truncate at semantic boundaries
- 02Preserve paragraph structure where possible
- 03Enforce the specified length limit
- 04Optionally add a custom truncation marker
- 05Report length and cutoff location
Use cases
- 01Prepare long text for Agent input limits
- 02Create text previews or summary excerpts
- 03Trim generated content to reduce redundancy
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ vangong1999/ screen-creative-skills --skill text-truncatorAfter installing, type/text-truncatorin Claude Code to confirm it loaded.
Bundled filesreferences/examples.mdscripts/text_truncator.py
Details
From the project README文本截断工具
功能
智能截断文本,在保持内容完整性和语义连贯性的前提下,将文本截断至指定长度。
使用场景
- 对超出长度限制的文本进行预处理,使其符合智能体的输入要求。
- 在展示文本预览或生成摘要时,截取关键部分以提高效率和可读性。
- 辅助内容创作,对生成的长文本进行智能裁剪,避免冗余。
核心能力
- 语义优先截断: 优先在自然语义边界(如句号、问号、感叹号)处进行截断,最大限度地保持句子的完整性。
- 段落完整性: 在语义边界不足时,优先考虑在段落末尾或换行符处截断,避免破坏段落结构。
- 精确长度控制: 严格遵守用户指定的最大长度限制,确保输出文本不会超限。
- 截断标记插入(可选): 可以在截断文本的末尾自动添加自定义截断标记(如"..."),以指示内容有删节。
输入要求
- 文本内容: 待截断的原始文本(字符串)。
- 最大长度限制: 文本截断后的最大长度(整数,如字符数或 token 数)。
- 截断标记(可选): 自定义截断标记,如 "..." 或 "[内容已截断]"。
输出格式
【文本截断报告】
- 原始文本长度: [整数] 字/Token
- 截断后长度: [整数] 字/Token
- 截断位置: [位置描述,如 "在第X句末尾"] 或 "未截断"
### 截断后的文本
[截断后的文本内容]
约束条件
- 截断后的文本长度必须严格符合最大长度限制。
- 确保截断后的文本在语义上尽可能连贯和完整。
- 如果文本未达到最大长度,则不进行截断,返回原始文本。
- 输出格式必须结构化,清晰展示截断前后的长度信息和截断后的文本内容。
硬性约束
- 未超过目标长度则不截断
- 优先在段落/章节边界截断,避免句子截断
- 截断后标注已截断及原长/现长
参考资料
Comments
Markdown supported