← Catalog

@labratinc/pi-rules

Pi package that loads Cursor-compatible project rules lazily — bodies only when alwaysApply, globs, or @mention say so

Extension

Install

Install with PiG

pig install npm:@labratinc/pi-rules

Install with Pi

pi install npm:@labratinc/pi-rules
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/extension.ts"
  ],
  "minPiVersion": "0.80.0",
  "changelogPath": "./CHANGELOG.md"
}

README

Written by the package's publisher, shown as published in version 1.0.3 (README.md). PiG does not review it.

@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

SourceRole
.cursorrulesLegacy always-on project rules
.cursor/rules/**/*.mdcCursor project rules (recursive)
packages/*/.cursor/rules, apps/*/.cursor/rules, services/*/.cursor/rulesNested package rules

AGENTS.md is not re-injected — Pi already loads it as a context file.

Cursor contract (lazy loading)

ModeFrontmatterPrompt behavior
Always ApplyalwaysApply: trueBody injected every turn
Specific Filesglobs + alwaysApply: falseBody only when an active path matches
Apply Intelligentlydescription onlyIndex row; agent reads when relevant
ManualneitherIndex only until @rule-name or /rules apply
Legacy.cursorrulesTreated 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)

LimitDefaultBehavior
Total Active bodies48 KiBLower-priority actives that do not fit move to Available
Per-rule soft cap16 KiBOversized 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

CommandEffect
/rules or /rules statusList discovered rules, active paths, budget notes
/rules apply <name>Force-inject a rule body on the next turn
/rules reloadRescan 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:

  1. Open npmjs.com/package/@labratinc/pi-rules → Settings → Trusted Publisher.
  2. 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)
  3. 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):

  1. npmjs.com → Access Tokens → Generate New Token (granular).
  2. 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.
  3. GitLab → Settings → CI/CD → Variables:
    • Key: NPM_TOKEN
    • Masked + Protected
  4. After Trusted Publishing succeeds, delete NPM_TOKEN and 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