@d3ara1n/pi-context-include

中文文档
3.0.0发布于 2026/09/20MITES Module零依赖构建来源已验证近 30 天下载 8046

@path syntax for AGENTS.md — include files by reference with recursive resolution

原始使用文档
文档目录8 节
  1. Features
  2. Installation
  3. Dependencies
  4. Usage
  5. Supported file types
  6. Configuration
  7. Path safety fence
  8. Command

@d3ara1n/pi-context-include

npm version npm downloads license

@path syntax for AGENTS.md — include files by reference.

Requires pi 0.86.0 or newer.

Features

  • Line-start only: @path sits at the start of a line, optionally after a Markdown list marker (-, *, +, or 1.) — prevents false positives from emails/code
  • Fenced block safe: @path lines inside triple-backtick blocks are ignored
  • Relative paths: @CODEGRAPH.md, @./docs/rules.md, @../shared/AGENTS.md
  • Absolute paths: @/absolute/path/to/file.md
  • Home directory: @~/.pi/agent/includes/shared-rules.md
  • Recursive includes: included files can themselves contain @ references
  • Cycle detection: prevents infinite include loops
  • Size guard: 500KB total limit, 10 levels deep (configurable)
  • Path safety fence: includes are confined to allowed roots; out-of-scope paths are blocked by default

Installation

pi install npm:@d3ara1n/pi-context-include

Or add to ~/.pi/agent/settings.json:

{
  "extensions": [
    "/absolute/path/to/pi-extensions/packages/pi-context-include"
  ]
}

Dependencies

None.

Usage

In any AGENTS.md file:

# Project Rules

@./docs/api-conventions.md
@~/.pi/agent/includes/team-conventions.md

On each turn, the extension reads the referenced files and updates its own system-prompt section. Pi can preserve unchanged prompt sections across turns.

Important: @path must be at the start of a line, optionally after a Markdown list marker (-/*/+/1.). It will not be recognized mid-sentence or inside code blocks.

Supported file types

.md only. Structured formats (.json/.yaml/.toml) are intentionally excluded — they typically hold config or credentials, not instructions, and are better read on demand.

Configuration

Optional. Read from ~/.pi/agent/settings.json (global) or {project}/.pi/settings.json (project). A present project contextInclude block replaces the global block; omitted fields then use defaults. maxDepth and maxBytes must be finite, non-negative numbers; invalid values use the defaults. maxBytes is measured as UTF-8 bytes. Optional allowedRoots / deniedRoots configure the path safety fence.

{
  "contextInclude": {
    "maxDepth": 15,
    "maxBytes": 1000000
  }
}

Settings files must be valid JSON (no comments). Settings are loaded on session start — run /reload or restart pi after editing.

Path safety fence

Included files appear in the system prompt as <project_instructions> entries within a <context_include> section, so an accidental @secrets.json or @../sibling/secret.md would leak secrets on every turn. Includes are therefore confined to an allow-set of roots, with a deny-set that always wins:

{
  "contextInclude": {
    "allowedRoots": ["./docs", "~/.pi/agent/includes"],
    "deniedRoots": ["./secrets", "node_modules"]
  }
}
  • allowedRoots — roots that may be included. Relative entries resolve against the project root. (This is separate from @-reference resolution: a @path inside an AGENTS.md still resolves relative to that file, as always.) An explicit allowedRoots fully replaces the defaults below; an empty array [] blocks everything.
  • deniedRoots — roots that may never be included, always evaluated first and taking precedence over allowedRoots.

Default allow-set (used when allowedRoots is omitted, so existing setups keep working):

  • each context file's own directory tree (so in-repo @docs/rules.md works zero-config), and
  • ~/.pi/agent/includes/ — a shared home for cross-repo rules.

Anything else (@/etc/..., @../sibling/..., @~/credentials.json) is blocked by default and reported by /context-include:status as "outside allowed roots".

The fence guards against accidents and misconfiguration, not adversaries — anyone who can edit settings.json controls the policy.

Command

/context-include:status — shows the effective allow/deny roots, resolved includes, and any files that were skipped (missing, empty, over size/depth limits, outside the allowed roots, denied by deniedRoots, duplicates, or unreadable). Run this to diagnose why a referenced file wasn't included.

版本与发布记录

@d3ara1n/pi-context-include 共发布 11 个版本,首次发布于 2026/06/03;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.0latest2026/09/201 个月前
2.0.12026/08/142 个月前
2.0.02026/08/142 个月前
1.3.12026/07/133 个月前
1.3.02026/07/114 个月前
1.2.22026/07/104 个月前

关于 @d3ara1n/pi-context-include 的常见问题

@d3ara1n/pi-context-include 是什么?

@path syntax for AGENTS.md — include files by reference with recursive resolution

如何安装 @d3ara1n/pi-context-include?

在项目目录运行 npm install @d3ara1n/pi-context-include,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@earendil-works/pi-coding-agent(>=0.86.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@d3ara1n/pi-context-include 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/d3ara1n__pi-context-include 是否存在。

@d3ara1n/pi-context-include 支持 ESM 还是 CommonJS?

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

@d3ara1n/pi-context-include 可以商用吗?

@d3ara1n/pi-context-include 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d3ara1n/pi-context-include 的下载量有多少?

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

@d3ara1n/pi-context-include 还在维护吗?

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