pi-layers0.1.3
Directory layers for pi: an umbrella folder's skills, prompts, instructions, path-scoped rules and MCP servers reach every session inside it, including git submodules and linked worktrees that live elsewhere
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-layers
Share skills, prompt templates, instructions, rules, and MCP servers across folders in pi.
A folder with .pi/layer.json is a layer for sessions in that folder and its descendants, including Git submodules and linked worktrees that belong there.
Each search checks the starting folder and its ancestors: inside your home folder it stops at home (included); outside home it goes to the drive or filesystem root.
On Windows, the home boundary ignores case, including the drive letter, and treats \ and / alike.
Install
pi install npm:pi-layers
To try it without installing, run pi -e npm:pi-layers.
Define a layer
Create .pi/layer.json in the folder you want to share resources from.
All fields are optional.
| Field | Default | Meaning |
|---|---|---|
name |
Folder name | Layer name; 1–64 ASCII letters, digits, dots, underscores, or hyphens. |
skills |
[] |
List of skill folders. |
prompts |
[] |
List of prompt template folders. |
rules |
[".agents/rules"] |
List of rule folders. |
context |
["AGENTS.md"] |
List of instruction files to add if pi has not already loaded them. |
mcpServers |
{} |
Server definitions keyed by name, as in mcp.json; null also means none. |
$schema |
None | Optional metadata; not validated. |
{
"name": "shared",
"skills": ["skills"],
"prompts": ["prompts"],
"mcpServers": { "tools": { "command": "node", "args": ["./tools/server.mjs"] } }
}
Use paths relative to the layer root in skills, prompts, rules, and context.
Invalid JSON, wrong field types, and paths that leave the layer root reject the whole file.
The check is the same on every system: \ counts as a separator, and /x, C:x and .. paths are refused.
Unknown top-level fields are ignored with a warning.
Among trusted layers, the inner layer wins for same-name skills, prompts, and MCP servers.
Skills from pi's own user or project folders take precedence over layer skills, and a same-name server in mcp.json takes precedence over a layer's server.
A command-based MCP server runs from its layer root unless it sets cwd; a relative cwd is resolved from that root.
Trust a layer
Add trusted paths to ~/.pi/agent/pi-layers.json, or to $PI_CODING_AGENT_DIR/pi-layers.json if you set that variable.
{ "trusted": ["~/work/shared"] }
A layer contributes nothing unless its folder or the location it represents in the main checkout is at or below a listed path.
Use absolute paths or ~/ paths, then run /reload.
Trust only folders whose instructions and MCP commands you want pi to use.
Write rules
Put Markdown files in a rule folder.
Without paths, a rule goes into the system prompt.
With paths, its globs are relative to the layer root and also match where a file belongs in the main checkout.
The first successful matching read, edit, or write adds the rule text to the tool result.
Compaction and /tree navigation let it attach again.
---
paths:
- "src/**/*.ts"
---
Use the existing error type for service failures.
A checkout's own .agents/rules can load without a layer.json and follows pi's project trust.
If the checkout root is itself an untrusted layer, those rules do not load through pi-layers.
Inspect with /layers
Run /layers to see which layers were found, whether they are trusted, what they contribute, any configuration warnings, and the trust file in use.
When a trusted layer lists a skills, prompts, rules or context path that does not exist, such as an uninitialized submodule, pi-layers warns once per startup or /reload and shows the path as missing in /layers and in the resolved event; defaults the layer did not list are not checked.
Extension API
inLayer(name, cwd?) checks for a trusted layer and defaults to the process's working directory.
resolveLayers(cwd, { home }) lists layers outermost first without checking trust; omit the options to use the user's home folder.
logicalPath(path) returns the location a path represents in its main checkout, or its physical path if it has no separate location.
import { inLayer, logicalPath, resolveLayers } from "pi-layers";
const trusted = inLayer("shared", ctx.cwd);
const { layers } = resolveLayers(ctx.cwd);
const location = logicalPath(ctx.cwd);
pi.events.emit("pi-layers:query", { reply: (resolution) => console.log(resolution) });
The helpers work without the extension running.
The running extension emits pi-layers:resolved on session start or when it resolves a new working folder.
Use pi-layers:query with reply for the current view, or without it to receive pi-layers:resolved again; early queries are served when the first resolution is ready.
MIT (LICENSE); the rule loader and checkout resolver were adapted from MIT-licensed code.