@labratinc/pi-rules
Pi package that loads Cursor-compatible project rules lazily — bodies only when alwaysApply, globs, or @mention say so
Package details
Install @labratinc/pi-rules from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@labratinc/pi-rules- Package
@labratinc/pi-rules- Version
1.0.3- Published
- Nov 21, 2026
- Downloads
- 450/mo · 450/wk
- Author
- beettlle
- License
- MIT
- Types
- extension
- Size
- 40.3 KB
- Dependencies
- 1 dependency · 1 peer
Pi manifest JSON
{
"extensions": [
"./src/extension.ts"
],
"minPiVersion": "0.80.0",
"changelogPath": "./CHANGELOG.md"
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@labratinc/pi-rules
A pi package that loads Cursor-compatible project rules into the agent system prompt — lazily, following Cursor’s apply contract so large rule trees do not blow the context window.
Install
pi install npm:@labratinc/pi-rules
Local path (this repo):
pi install /path/to/pi-rules
What it reads
| Source | Role |
|---|---|
.cursorrules |
Legacy always-on project rules |
.cursor/rules/**/*.mdc |
Cursor project rules (recursive) |
packages/*/.cursor/rules, apps/*/.cursor/rules, services/*/.cursor/rules |
Nested package rules |
AGENTS.md is not re-injected — Pi already loads it as a context file.
Cursor contract (lazy loading)
| Mode | Frontmatter | Prompt behavior |
|---|---|---|
| Always Apply | alwaysApply: true |
Body injected every turn |
| Specific Files | globs + alwaysApply: false |
Body only when an active path matches |
| Apply Intelligently | description only |
Index row; agent reads when relevant |
| Manual | neither | Index only until @rule-name or /rules apply |
| Legacy | .cursorrules |
Treated as Always Apply |
Active paths come from paths in the user prompt plus files touched by successful read / edit / write tool calls this session. With no active paths, glob rules stay in the Available index.
Budgets (soft-cap, not silent drops)
| Limit | Default | Behavior |
|---|---|---|
| Total Active bodies | 48 KiB | Lower-priority actives that do not fit move to Available |
| Per-rule soft cap | 16 KiB | Oversized Active bodies keep a head prefix + read note |
Override with env:
export PI_RULES_BUDGET_BYTES=65536 # total Active budget
export PI_RULES_PER_RULE_BYTES=24576 # per-rule soft head-truncate
Prompt shape
<project-rules>
## Active rules
### .cursorrules
...
### .cursor/rules/always-core.mdc
...
## Available rules (load with read when relevant)
- `.cursor/rules/python-standards.mdc` — Python standards [glob: **/*.py]
- `.cursor/rules/git-workflow.mdc` — Git/PR workflow [agent ...]
</project-rules>
Commands
| Command | Effect |
|---|---|
/rules or /rules status |
List discovered rules, active paths, budget notes |
/rules apply <name> |
Force-inject a rule body on the next turn |
/rules reload |
Rescan rule files |
Footer status looks like: rules: 2 active · 18 available.
Example rule
---
description: Python standards
globs: ["**/*.py"]
alwaysApply: false
---
- Prefer async/await
- Use type hints
Works with rule collections such as beettlle/CursorRules: copy .cursor/rules into your project; only always-on rules and currently matching globs consume context.
Development
npm install
npm test
npm run typecheck
Publishing (GitLab CI → npm)
Repo: gitlab.com/beettlle/pi-rules
Package: @labratinc/pi-rules (org labratinc)
npm no longer creates empty packages from the website. The package is created on first successful npm publish. After that, connect GitLab with Trusted Publishing so CI does not need a long-lived token.
Step A — First publish (creates the package)
You are already an owner of the labratinc org. From this repo (logged in as an org member):
npm whoami # should be your npm user
npm org ls labratinc # confirm membership
npm publish --access public # creates @labratinc/pi-rules@1.0.1
Scoped packages default to private; --access public is required on the first publish.
Or use GitLab once with a bootstrap token (see Step B fallback), then switch to Trusted Publishing.
Step B — Connect GitLab (Trusted Publishing — preferred)
After the package exists on npmjs.com:
- Open npmjs.com/package/@labratinc/pi-rules → Settings → Trusted Publisher.
- Choose GitLab CI/CD and set exactly:
- Namespace:
beettlle(GitLab username / top-level namespace) - Project name:
pi-rules - Top-level CI file path:
.gitlab-ci.yml(must include.yml) - Environment name: leave empty unless the CI job sets
environment: - Allowed actions: enable
npm publish(stage-only is not enough for this pipeline)
- Namespace:
- Save. Complete a successful OIDC tag publish within 2 days so the config does not expire.
If CI fails with OIDC token exchange error - package not found, the Trusted Publisher connection was not saved for @labratinc/pi-rules (wrong package page, form blocked by 2FA, or expired before first OIDC publish). Open that package’s Settings again, delete any stale connection, recreate it with the fields above, then re-run the tag pipeline.
This repo’s publish job declares id_tokens.NPM_ID_TOKEN for npm. No NPM_TOKEN is required once Trusted Publishing works.
Gallery: pi.dev/packages/@labratinc/pi-rules indexes automatically from the npm pi-package keyword (no separate pi.dev upload).
Optional bootstrap (until Trusted Publishing is validated):
- npmjs.com → Access Tokens → Generate New Token (granular).
- Permissions: Read and write for packages/scopes → select scope
@labratinc(or the package after it exists). Enable Bypass 2FA if your account requires 2FA for publish. - GitLab → Settings → CI/CD → Variables:
- Key:
NPM_TOKEN - Masked + Protected
- Key:
- After Trusted Publishing succeeds, delete
NPM_TOKENand restrict token publishing on the package settings.
Step C — Release a version
# bump package.json / CHANGELOG, then:
git add -A
git commit -m "Release v1.0.2"
git tag v1.0.2
git push origin main --tags
Tag pipelines run test then npm publish --access public on vX.Y.Z tags.
License
MIT