Token导航 LogoToken导航

Agent Skill · 研究检索

pretext(pretext 搜索)

pretext 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

pretext 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为操作浏览器;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 36,120。

总安装 1,978周安装 80GitHub Stars 12下载 621核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:pretext(pretext 搜索)
来源仓库:https://github.com/asharibali/pretext-skills
仓库路径:skills/pretext
安装命令:
npx skills add https://github.com/asharibali/pretext-skills --skill pretext
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/asharibali/pretext-skills --skill pretext

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

pretext 是纯 JavaScript 文本测量与排版库,无需 DOM 即可计算多行文本布局。它使用 canvas measureText 作为基准,适用于服务端渲染与性能敏感场景。支持 DOM、Canvas、SVG 输出,减少浏览器重排开销,提升渲染效率。

安装来自 GitHub,注意浏览器兼容性,避免在旧版环境中使用高级特性。pretext 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/pretext

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/asharibali/pretext-skills --skill pretext;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要操作浏览器,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

pretext 怎么安装?

在终端执行 npx skills add https://github.com/asharibali/pretext-skills --skill pretext。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

pretext 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

pretext 需要什么权限?

权限级别是操作浏览器。该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

pretext 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

pretext 用的人多吗?

公开数据是累计安装 1,978 次,近一周安装 80 次,下载 621 次,GitHub 12 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

pretext 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
pretext

pretext 搜索 · 本页

1,97812操作浏览器未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Pretext – DOM-Free Text Measurement & Layout

Pretext is a pure-JavaScript/TypeScript library that measures and lays out multiline text without touching the DOM. It uses the browser's own font engine (via canvas measureText) as ground truth, then does all line-breaking and height calculation in pure arithmetic. Supports rendering to DOM, Canvas, SVG, and (eventually) server-side.

Why This Matters

DOM-based text measurement (getBoundingClientRect, offsetHeight) triggers layout reflow — one of the most expensive operations in a browser. Every call forces the engine to recalculate styles and geometry for potentially the entire document. In a virtualized list with 10,000 rows, that means 10,000 reflows just to get row heights.

Pretext replaces that with a two-phase approach: one prepare() call does text analysis, segmentation, glue rules, and canvas measurement (the expensive part, done once), then layout() computes height from cached widths using pure math (the cheap part, called on every resize). This is 300-600x faster than DOM measurement, and it eliminates layout thrashing entirely.

The result is pixel-perfect across browsers (7680/7680 on Chrome, Safari, and Firefox accuracy sweeps), supports all languages including emoji, mixed-bidi, CJK, Thai, Arabic, Khmer, Myanmar, Urdu, and more.

Installation

npm install @chenglou/pretext

Two Paths: Pick the Simpler One

Fast Path (90% of cases — you just need the height)

import { prepare, layout } from '@chenglou/pretext'

const prepared = prepare('AGI 春天到了. بدأت الرحلة 🚀‎', '16px Inter')
const { height, lineCount } = layout(prepared, maxWidth, 20)

This covers virtualized lists, dynamic containers, scroll anchoring — anything where you need to know how tall text will be at a given width. The prepared handle is reusable: on resize, just call layout() again with the new width.

For textarea-like text where spaces, tabs, and \n hard breaks stay visible:

const prepared = prepare(textareaValue, '16px Inter', { whiteSpace: 'pre-wrap' })
const { height } = layout(prepared, textareaWidth, 20)

For CJK/Hangul text that should avoid breaking within words:

const prepared = prepare(text, '16px Inter', { wordBreak: 'keep-all' })

Rich Path (you need the actual lines)

When you need to render text yourself (Canvas, SVG, WebGL) or do variable-width layout (flowing around images), switch to the rich APIs:

import { prepareWithSegments, layoutWithLines, walkLineRanges, layoutNextLine, layoutNextLineRange, materializeLineRange, measureLineStats, measureNaturalWidth } from '@chenglou/pretext'
  • layoutWithLines() — all lines at a fixed width (Canvas/SVG rendering)
  • walkLineRanges() — line ranges without building strings (shrink-wrap, binary search for optimal width, balanced text layout)
  • measureLineStats() — line count and widest line width without any allocations
  • measureNaturalWidth() — widest forced line when width is not the thing causing wraps
  • layoutNextLine() — one line at a time with varying width (text flowing around obstacles), returns full line with text
  • layoutNextLineRange() — same as above but without building the text string; use materializeLineRange() to get the text when needed

Rich-Text Inline Flow (multi-font, chips, mentions)

For rich-text inline flow with mixed fonts, code spans, mentions, chips, and browser-like boundary whitespace collapse:

import { prepareRichInline, walkRichInlineLineRanges, materializeRichInlineLineRange, measureRichInlineStats } from '@chenglou/pretext/rich-inline'

const prepared = prepareRichInline([
  { text: 'Ship ', font: '500 17px Inter' },
  { text: '@maya', font: '700 12px Inter', break: 'never', extraWidth: 22 },
  { text: "'s rich-note", font: '500 17px Inter' },
])

walkRichInlineLineRanges(prepared, 320, range => {
  const line = materializeRichInlineLineRange(prepared, range)
  // each fragment keeps its source item index, text slice, gapBefore, and cursors
})

The rich-inline helper is intentionally narrow:

  • Raw inline text in, including boundary spaces
  • Caller-owned extraWidth for pill chrome (padding + border width)
  • break: 'never' for atomic items like chips and mentions
  • white-space: normal only
  • Not a nested markup tree and not a general CSS inline formatting engine

API Reference

Fast-path APIs

prepare(text: string, font: string, options?: {
  whiteSpace?: 'normal' | 'pre-wrap',
  wordBreak?: 'normal' | 'keep-all'
}): PreparedText

layout(prepared: PreparedText, maxWidth: number, lineHeight: number): {
  height: number,
  lineCount: number
}

Rich-path APIs

prepareWithSegments(text: string, font: string, options?: {
  whiteSpace?: 'normal' | 'pre-wrap',
  wordBreak?: 'normal' | 'keep-all'
}): PreparedTextWithSegments

layoutWithLines(prepared: PreparedTextWithSegments, maxWidth: number, lineHeight: number): {
  height: number, lineCount: number, lines: LayoutLine[]
}

walkLineRanges(prepared: PreparedTextWithSegments, maxWidth: number,
  onLine: (line: LayoutLineRange) => void): number

measureLineStats(prepared: PreparedTextWithSegments, maxWidth: number): {
  lineCount: number, maxLineWidth: number
}

measureNaturalWidth(prepared: PreparedTextWithSegments): number

layoutNextLineRange(prepared: PreparedTextWithSegments, start: LayoutCursor, maxWidth: number): LayoutLineRange | null

layoutNextLine(prepared: PreparedTextWithSegments, start: LayoutCursor, maxWidth: number): LayoutLine | null

materializeLineRange(prepared: PreparedTextWithSegments, line: LayoutLineRange): LayoutLine

Rich-inline APIs (@chenglou/pretext/rich-inline)

prepareRichInline(items: RichInlineItem[]): PreparedRichInline

layoutNextRichInlineLineRange(prepared: PreparedRichInline, maxWidth: number, start?: RichInlineCursor): RichInlineLineRange | null

walkRichInlineLineRanges(prepared: PreparedRichInline, maxWidth: number,
  onLine: (line: RichInlineLineRange) => void): number

materializeRichInlineLineRange(prepared: PreparedRichInline, line: RichInlineLineRange): RichInlineLine

measureRichInlineStats(prepared: PreparedRichInline, maxWidth: number): {
  lineCount: number, maxLineWidth: number
}

Utility APIs

clearCache(): void   // release internal caches used by prepare/prepareWithSegments
setLocale(locale?: string): void  // retarget word segmenter for future prepare() calls; also clears cache

Key Types

type LayoutLine = {
  text: string         // full text of the line
  width: number        // measured pixel width
  start: LayoutCursor  // inclusive start cursor
  end: LayoutCursor    // exclusive end cursor
}

type LayoutLineRange = {
  width: number
  start: LayoutCursor
  end: LayoutCursor
}

type LayoutCursor = {
  segmentIndex: number   // position in prepared segments
  graphemeIndex: number  // grapheme within that segment
}

type RichInlineItem = {
  text: string            // raw text including boundary spaces
  font: string            // canvas font shorthand
  break?: 'normal' | 'never'  // 'never' = atomic (chips, mentions)
  extraWidth?: number     // horizontal chrome width (padding + border)
}

type RichInlineFragment = {
  itemIndex: number       // index into original items array
  text: string
  gapBefore: number       // collapsed boundary gap
  occupiedWidth: number   // text width + extraWidth
  start: LayoutCursor
  end: LayoutCursor
}

type RichInlineLine = {
  fragments: RichInlineFragment[]
  width: number
  end: RichInlineCursor
}

Key Things to Get Right

  • Cache prepared handles. Same text + same font = reuse the handle. Only call prepare() again if the text or font actually changed. On resize, just re-call layout().
  • Match your CSS exactly. The font string must match your CSS font shorthand (size, weight, style, family). The lineHeight must match your CSS line-height. Mismatches produce wrong heights.
  • Use {whiteSpace: 'pre-wrap'} for textareas where spaces, tabs, and newlines should be preserved. Tabs follow default browser-style tab-size: 8 stops.
  • Use {wordBreak: 'keep-all'} for CJK/Hangul when you want to avoid breaking within words.
  • Avoid system-ui on macOS — canvas and DOM can resolve to different fonts (SF Pro Text vs SF Pro Display), breaking accuracy. Use a named font.
  • clearCache() is rarely needed — only when cycling through many different fonts and you want to release memory.
  • setLocale() is optional — by default Pretext uses the current locale. Call it before prepare() if you need a specific Intl.Segmenter locale.

Supported CSS Target

  • white-space: normal (default) and pre-wrap
  • word-break: normal (default) and keep-all
  • overflow-wrap: break-word — narrow widths can break inside words, but only at grapheme boundaries
  • line-break: auto
  • Tabs follow default browser-style tab-size: 8

What Pretext Handles Under the Hood

  • Segmentation: text analysis, normalization, Unicode-aware word/grapheme segmentation via Intl.Segmenter
  • CJK: astral ideographs, compatibility blocks, extension blocks, kinsoku (line-start/end prohibited punctuation)
  • Arabic/RTL: no-space punctuation cluster merging, punctuation-plus-mark clusters, bidi metadata on the rich path
  • Emoji: auto-detected per-font correction for canvas/DOM width discrepancy, ZWJ sequences
  • Soft hyphens: invisible when unbroken, visible trailing - when the break is chosen
  • NBSP/NNBSP/WJ: preserved as visible content, prevents word-boundary wrapping
  • ZWSP: preserved as zero-width break opportunity
  • URL-like runs: modeled as structured breakable units (path + query) to avoid bad mid-path breaks
  • Mixed script: handles mixed-bidi, CJK-leading no-space runs, contextual ASCII quotes, numeric/time-range expressions

Ready-to-Use Examples

See the references/examples/ directory for complete, copy-paste-ready code:

Fast-path (height measurement):

  • basic-height.ts — measure text height for a container, with wordBreak: 'keep-all'
  • pre-wrap-textarea.ts — auto-size a textarea with preserved whitespace and tabs
  • resize-handler.ts — canonical resize pattern: prepare() once, layout() on every resize
  • virtualized-list.ts — variable row heights for virtualized lists with cached handles
  • scroll-anchor.ts — prevent layout shift by predicting height before DOM insertion
  • label-overflow-check.ts — CI/dev-time check that labels fit without wrapping
  • multilingual-layout.ts — locale-aware measurement with setLocale() for CJK, Arabic, Thai

Rich-path (manual line layout):

  • canvas-manual-layout.ts — render wrapped text on a canvas with layoutWithLines
  • svg-text-render.ts — render wrapped text into SVG <tspan> elements
  • flow-around-image.ts — route text around a floated image using layoutNextLineRange
  • two-column-flow.ts — continuous two-column editorial flow with layoutNextLineRange
  • shrink-wrap.ts — find tightest container width with walkLineRanges and measureLineStats
  • balanced-text.ts — binary-search for balanced line widths to avoid orphan lines
  • natural-width.ts — tooltip/popover sizing with measureNaturalWidth
  • bubble-chat.ts — chat bubble shrink-wrap: find tightest width, then render lines

Rich-inline (multi-font):

  • rich-inline.ts — multi-font inline flow with atomic chips and mentions

Deep Reference

  • references/README.md — Full API surface from the library repo: installation, complete type definitions, all function signatures, usage examples, and caveats.
  • references/AGENTS.md — Agent-specific guidance: important source files, implementation notes, practical patterns, gotchas, open questions, and decision heuristics for building with Pretext.
  • references/STATUS.md — Current accuracy dashboard and benchmark snapshot pointers (browser sweep results, corpus canaries).
  • references/RESEARCH.md — Research log: everything tried, measured, and learned — system-ui discovery, word-sum accuracy, Arabic frontier, soft hyphens, emoji correction, CJK/Thai/Khmer/Myanmar/Japanese/Chinese corpus canaries, and rejected approaches.
  • references/DEVELOPMENT.md — Development setup, day-to-day commands, packaging/release checks, browser accuracy and benchmarking commands, corpus tooling, and deep profiling workflow.
  • references/CHANGELOG.md — Version history from 0.0.0 (2026-03-26) through unreleased changes including keep-all support and rich-inline APIs.
  • references/TODO.md — Current priorities: canary maintenance, next engine work, demo direction, and open design questions.
  • references/SECURITY.md — Security policy and private vulnerability reporting via GitHub advisories.

平台分布

Codex

34.98%
按下载量换算217

Claude

29.3%
按下载量换算182

Cursor

21.3%
按下载量换算132

Gemini CLI

10.16%
按下载量换算63

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills