agentleFS
pecigonzalopecigonzalo/agent-skills/skills/workflow-pi-extension/SKILL.md

workflow-pi-extension

Skill0 starsChanged 4 months agoMITView on GitHub

Use this skill when creating, modifying, reviewing, debugging, or packaging Pi extensions, including custom tools, commands, event hooks, TUI components, model providers, extension packages, inter-extension communication, and reload behavior, even if the user only refers to a Pi tool or command. Routes to the bundled Pi docs and examples rather than restating the API.

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. About 0 are common, 9 are distinctive, and 14 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Golden Rule: Read the bundled Pi docs before implementing.

    line 13
  2. Very specific:

    Read docs/tui.md for custom UI, widgets, overlays, renderers, footers, or editor components.

    line 26
  3. Very specific:

    Read docs/packages.md for package manifests, dependencies, distribution, or install and update behavior.

    line 27
  4. Very specific:

    Read docs/custom-provider.md for model providers, OAuth, or custom streaming.

    line 28
  5. Very specific:

    Read docs/keybindings.md for shortcuts or editor key handling.

    line 29
  6. Distinctive:

    Prefer an official example over an invented pattern.

    line 32
  7. Distinctive:

    Prefer composable, reusable extensions over one-off monoliths.

    line 38
  8. Very specific:

    Prefer an extension directory with package.json over a loose .ts file once the extension has dependencies, helpers, tests, reusable …

    line 39
  9. Distinctive:

    Keep extension dependencies self-contained in the extension package.

    line 40
  10. Very specific:

    Prefer optional integration through pi.events, and direct imports only for hard dependencies.

    line 42
  11. Distinctive:

    Keep event payloads JSON-serializable unless there is a specific reason not to.

    line 45
  12. Very specific:

    Add "keywords": ["pi-package"] only when publishing or distributing.

    line 85
  13. Distinctive:

    Read the matching Pi docs and the closest official example.

    line 92
  14. Distinctive:

    Check whether an existing extension can be reused or extended instead.

    line 93
  15. Very specific:

    If the extension should persist, place it under ~/.pi/agent/extensions/ or .pi/extensions/.

    line 97
  16. Very specific:

    Verify /reload works from that auto-discovered location.

    line 98
  17. Distinctive:

    Do not hardcode credentials or log secrets.

    line 104
  18. Very specific:

    Avoid shell interpolation.

    line 106
  19. Very specific:

    Check ctx.hasUI before requiring interactive UI, so the extension still works headless.

    line 107
  20. Distinctive:

    Use abort signals for long-running work where available.

    line 108
  21. Very specific:

    Use StringEnum from @earendil-works/pi-ai for tool string enums.

    line 110
  22. Very specific:

    Use withFileMutationQueue() for file-mutating tools so concurrent writes serialize.

    line 112
  23. Very specific:

    Treat ctx.reload() as terminal: await ctx.reload().

    line 115

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Pi Extension Workflow

Provides: A routing map to the authoritative Pi docs, architecture preferences for composable extensions, a package layout, and a safety checklist.

Quick Reference

Golden Rule: Read the bundled Pi docs before implementing; do not invent API shapes

Flow: Identify type → Read docs and closest example → Check for reuse → Design contracts → Implement → Test with pi -e → Verify /reload

One owner per shared capability. Notifications, status widgets, path protection, configuration, and persistence should each live in exactly one extension.


Required References

This skill deliberately does not duplicate the Pi API. Read the relevant docs from the installed Pi package:

  • Always read docs/extensions.md.
  • Read docs/tui.md for custom UI, widgets, overlays, renderers, footers, or editor components.
  • Read docs/packages.md for package manifests, dependencies, distribution, or install and update behavior.
  • Read docs/custom-provider.md for model providers, OAuth, or custom streaming.
  • Read docs/keybindings.md for shortcuts or editor key handling.
  • Inspect the closest file under examples/extensions/.

Prefer an official example over an invented pattern. The extension API surface changes between Pi versions, so a remembered signature is less reliable than the installed docs.


Design Preferences

  • Prefer composable, reusable extensions over one-off monoliths.
  • Prefer an extension directory with package.json over a loose .ts file once the extension has dependencies, helpers, tests, reusable contracts, or is expected to persist.
  • Keep extension dependencies self-contained in the extension package. Do not add extension-specific dependencies to the global Pi package unless there is no alternative.
  • Factor shared behavior into reusable modules or explicit pi.events contracts.
  • Prefer optional integration through pi.events, and direct imports only for hard dependencies. Events let an extension work when its counterpart is absent; an import does not.
  • Namespace shared event names, for example notifications:show.
  • Export constants and TypeScript types for shared event payloads so consumers do not hardcode strings.
  • Keep event payloads JSON-serializable unless there is a specific reason not to.

Preferred Layout

For anything beyond a tiny experiment:

my-extension/
├── package.json
├── index.ts
├── src/
│   ├── events.ts
│   ├── state.ts
│   └── tools.ts
└── test/
    └── smoke.test.ts

Minimal local package.json:

{
  "name": "my-pi-extension",
  "private": true,
  "type": "module",
  "dependencies": {},
  "peerDependencies": {
    "@earendil-works/pi-ai": "*",
    "@earendil-works/pi-coding-agent": "*",
    "@earendil-works/pi-tui": "*",
    "typebox": "*"
  },
  "pi": {
    "extensions": ["./index.ts"]
  }
}

Add "keywords": ["pi-package"] only when publishing or distributing.


Workflow

  1. Identify the extension type: tool, command, event hook, shared service, UI, provider, or package.
  2. Read the matching Pi docs and the closest official example.
  3. Check whether an existing extension can be reused or extended instead.
  4. Design shared capabilities as modules or documented pi.events contracts.
  5. Implement using Pi's documented APIs and TypeScript types.
  6. Test with pi -e ./path.
  7. If the extension should persist, place it under ~/.pi/agent/extensions/ or .pi/extensions/.
  8. Verify /reload works from that auto-discovered location.

Safety Checklist

  • Do not hardcode credentials or log secrets.
  • Validate paths and user input.
  • Avoid shell interpolation. Use pi.exec(command, args) so arguments are passed without a shell.
  • Check ctx.hasUI before requiring interactive UI, so the extension still works headless.
  • Use abort signals for long-running work where available.
  • Bound custom tool output. Unbounded output floods the agent's context.
  • Use StringEnum from @earendil-works/pi-ai for tool string enums.
  • Throw from a tool's execute() to signal failure; do not return an error string.
  • Use withFileMutationQueue() for file-mutating tools so concurrent writes serialize.
  • Restore state on session_start.
  • Clean up watchers, intervals, sockets, and child processes on session_shutdown.
  • Treat ctx.reload() as terminal: await ctx.reload(); return;.

Checklist

Before finishing:

  • The relevant Pi docs were read for this extension type
  • The closest official example was inspected
  • Existing extensions were checked for reuse opportunities
  • Shared behavior is a reusable module or a documented event contract
  • Shared event names are namespaced, with exported types for payloads
  • Dependencies are local to the extension package
  • The extension loads with pi -e
  • /reload works from an auto-discovered location
  • Watchers, intervals, and child processes are cleaned up on shutdown

See also

  • Load standards-typescript when writing the extension implementation.
  • Load standards-testing for the extension's test coverage.
  • Load standards-security when the extension handles credentials, paths, or user input.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.