@amaster.ai/pi-attachments

中文文档
0.1.37发布于 2026/11/09Apache-2.0TypeScriptES Module近 30 天下载 4110

Pi extension for attachment processing — classifies, parses, and renders file attachments into LLM-visible prompt context

原始使用文档
文档目录6 节
  1. Recognized mentions
  2. Skill resolution
  3. Output assembly
  4. Configuration
  5. Limits
  6. Failure diagnostics

@amaster.ai/pi-attachments

pi-attachments preview

Pi extension that intercepts user input, resolves @-references to local resources, and injects their content into the prompt before the model sees it.

Hooks the input event of @earendil-works/pi-coding-agent. When a recognized mention appears in the user message, the original mention is stripped and replaced with structured context (skill block, attachment listing, or <system-reminder>). Image attachments are passed through as multimodal ImageContent.

Recognized mentions

SyntaxResolves to
@path/to/file.tsFile contents (text/doc) or base64 image
@"/path with spaces/file.pdf"Same as above, supports whitespace in paths
@path/to/file.ts#L10-20Line range syntax preserved in the reference (range applied downstream)
@path/to/dirDirectory listing (files + subdirs, ignores .git/node_modules/build outputs)
@skill:<name>Loads SKILL.md for a registered skill

@http(s)://... is not treated as a file reference. Unknown namespaces (e.g. @app:erp-prod) are left alone — neither resolved as a skill nor as a file.

Skill resolution

@skill:<name> searches in this order, first hit wins:

  1. <cwd>/.pi/skills/<name>/SKILL.md — project-level skill
  2. <agentDir>/skills/<name>/SKILL.md — user-level skill (resolved via @amaster.ai/pi-shared's resolveAgentDir(), override with PI_AGENT_HOME)

The order matches loadSkillsFromAllLocations in the pi-coding-agent SDK so a project skill overrides a user-installed one. Frontmatter is stripped; the body is wrapped in <skill name="..." location="...">…</skill> and prepended to the user message.

Output assembly

When at least one mention resolves, the input is rewritten as three optional segments in this order:

<skill name="..." location="...">…</skill>   ← skill blocks (if any)

<original user text with mentions stripped>

<system-reminder>
## file.ts: /abs/path/file.ts
```text
…contents…
```

Pure-text inputs with no resolvable mentions are left untouched (handler returns undefined).

Configuration

Env varDefaultMeaning
PI_ATTACHMENT_MAX_TEXT_CHARS128000Shared text budget per input across file/directory blocks
PI_AGENT_HOME(from pi-shared)Override for user-level skill search root

Limits

Text files are read as bounded UTF-8 prefixes instead of loading the full file. File and directory blocks share PI_ATTACHMENT_MAX_TEXT_CHARS (default 128,000); later contents are omitted when the budget is exhausted, with their references retained. Invalid or non-positive environment values use the default. renderAttachmentContext(attachments, options) callers share the same budget through options.maxTextChars; a zero budget emits references and omission notes only.

Image attachments share a 20 MiB raw-byte budget per input, including drag uploads and file mentions. Images outside the vision budget retain source paths with a visible resize/crop hint; drag uploads are persisted incrementally within a separate 128 MiB storage budget per input. Uploads beyond that storage budget require a file reference or smaller image. Accepted vision images and Markdown references retain matching order.

  • Directory listing: capped at 200 entries per directory; remainder is summarized as [Listing truncated: showing 200 of N entries].
  • Ignored directory entries: .git, node_modules, .DS_Store, .next, .turbo, dist, build, .cache.
  • Mention ordering: skills are matched before files, so the resolved mentions[] array groups by kind rather than preserving textual order. Downstream consumers must not rely on textual order.

Failure diagnostics

Missing or unreadable referenced files are included as explicit per-attachment failure notices. Other readable attachments remain available, and the model is told which sources were not inspected.

版本与发布记录

@amaster.ai/pi-attachments 共发布 132 个版本,首次发布于 2026/05/16;过去 12 个月发布了 132 个版本。

版本发布日期距今
0.1.37latest2026/11/09今天
0.1.2-beta.91beta2026/11/072 天前
0.1.2-beta.902026/11/062 天前
0.1.2-beta.892026/11/053 天前
0.1.2-beta.882026/11/054 天前
0.1.362026/11/054 天前

关于 @amaster.ai/pi-attachments 的常见问题

@amaster.ai/pi-attachments 是什么?

Pi extension for attachment processing — classifies, parses, and renders file attachments into LLM-visible prompt context

如何安装 @amaster.ai/pi-attachments?

在项目目录运行 npm install @amaster.ai/pi-attachments,或使用 pnpm add / yarn add / bun add。

@amaster.ai/pi-attachments 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amaster.ai/pi-attachments 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@amaster.ai/pi-attachments 可以商用吗?

@amaster.ai/pi-attachments 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@amaster.ai/pi-attachments 的下载量有多少?

根据 npm 官方下载统计,@amaster.ai/pi-attachments 在 2026/10/06 – 2026/11/04 这 30 天内被下载 4,110 次,日均约 137 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amaster.ai/pi-attachments 还在维护吗?

最新版本 0.1.37 发布于 2026/11/09(今天);至今共发布 132 个版本,其中过去 12 个月发布了 132 个;首次发布于 2026/05/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。