@aliou/pi-dev-kit 0.6.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +11 -10
- package/src/commands/index.ts +5 -1
- package/src/commands/update.ts +139 -91
- package/src/skills/pi-extension/SKILL.md +108 -137
- package/src/skills/pi-extension/references/additional-apis.md +252 -208
- package/src/skills/pi-extension/references/commands.md +113 -33
- package/src/skills/pi-extension/references/components.md +267 -102
- package/src/skills/pi-extension/references/hooks.md +229 -156
- package/src/skills/pi-extension/references/messages.md +94 -106
- package/src/skills/pi-extension/references/modes.md +80 -90
- package/src/skills/pi-extension/references/providers.md +255 -96
- package/src/skills/pi-extension/references/publish.md +76 -62
- package/src/skills/pi-extension/references/state.md +80 -33
- package/src/skills/pi-extension/references/structure.md +126 -269
- package/src/skills/pi-extension/references/testing.md +1 -1
- package/src/skills/pi-extension/references/tools.md +198 -823
- package/src/tools/changelog-tool.ts +15 -3
- package/src/tools/docs-tool.ts +3 -3
- package/src/tools/index.ts +5 -1
- package/src/tools/package-manager-tool.ts +8 -4
- package/src/tools/utils.ts +33 -23
- package/src/tools/version-tool.ts +8 -4
- package/src/index.ts +0 -8
|
@@ -1,163 +1,134 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: pi-extension
|
|
3
|
-
description: Create, update, and publish Pi extensions. Use when working on
|
|
3
|
+
description: Create, update, and publish Pi extensions. Use when working on Pi extension packages, custom tools, commands, providers, hooks, TUI components, skills, prompts, or themes.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Pi Extension Development
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use this skill to build and maintain Pi packages. Read the reference file for the area you are changing before editing.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Package Namespace
|
|
11
11
|
|
|
12
|
-
Pi
|
|
12
|
+
Pi core packages are moving from `@mariozechner/*` to `@earendil-works/*`.
|
|
13
13
|
|
|
14
|
-
- `@
|
|
15
|
-
- `@mariozechner
|
|
16
|
-
-
|
|
17
|
-
|
|
14
|
+
- Prefer `@earendil-works/*` for new or migrated code once the target package exists on npm.
|
|
15
|
+
- Keep legacy `@mariozechner/*` imports when the target version is not published under the new namespace yet.
|
|
16
|
+
- Do not mix namespaces inside one package unless you are deliberately supporting a staged migration.
|
|
17
|
+
|
|
18
|
+
Core packages provided by Pi at runtime:
|
|
19
|
+
|
|
20
|
+
- `@earendil-works/pi-coding-agent` — extension API, types, tools, utilities.
|
|
21
|
+
- `@earendil-works/pi-tui` — TUI components.
|
|
22
|
+
- `@earendil-works/pi-ai` — AI utilities such as `StringEnum`.
|
|
23
|
+
- `typebox` — TypeBox 1.x schemas. Do not use `@sinclair/typebox` in new code.
|
|
24
|
+
|
|
25
|
+
## Standard Imports
|
|
18
26
|
|
|
19
27
|
```typescript
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} from "@
|
|
32
|
-
|
|
33
|
-
// Rendering utilities
|
|
34
|
-
import { getMarkdownTheme, keyHint, truncateHead, formatSize } from "@mariozechner/pi-coding-agent";
|
|
35
|
-
|
|
36
|
-
// TUI components
|
|
37
|
-
import { Container, Markdown, Text } from "@mariozechner/pi-tui";
|
|
28
|
+
import { ToolBody, ToolCallHeader, ToolFooter } from "@aliou/pi-utils-ui";
|
|
29
|
+
import type { AgentToolResult, ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
|
|
30
|
+
import {
|
|
31
|
+
defineTool,
|
|
32
|
+
formatSize,
|
|
33
|
+
getMarkdownTheme,
|
|
34
|
+
keyHint,
|
|
35
|
+
truncateHead,
|
|
36
|
+
withFileMutationQueue,
|
|
37
|
+
} from "@earendil-works/pi-coding-agent";
|
|
38
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
39
|
+
import { Container, Markdown, Text } from "@earendil-works/pi-tui";
|
|
40
|
+
import { type Static, Type } from "typebox";
|
|
38
41
|
```
|
|
39
42
|
|
|
43
|
+
If using the legacy namespace, replace `@earendil-works/*` with the matching `@mariozechner/*` package.
|
|
44
|
+
|
|
40
45
|
## Workflow
|
|
41
46
|
|
|
42
|
-
### Creating a
|
|
43
|
-
|
|
44
|
-
1. Read `references/structure.md` for
|
|
45
|
-
2.
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
3.
|
|
51
|
-
4.
|
|
52
|
-
5.
|
|
53
|
-
6.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
2. Read the relevant reference file for the area you are modifying.
|
|
63
|
-
3. Check `references/modes.md` if adding any UI interaction.
|
|
64
|
-
4. Run type checking after changes.
|
|
47
|
+
### Creating a new extension
|
|
48
|
+
|
|
49
|
+
1. Read `references/structure.md` for layout, package metadata, config, and entry-point rules.
|
|
50
|
+
2. Choose feature entry points and read their references:
|
|
51
|
+
- Tools: `src/tools/index.ts`; read `references/tools.md`.
|
|
52
|
+
- Commands: `src/commands/index.ts`; read `references/commands.md`.
|
|
53
|
+
- Hooks/events: `src/hooks/index.ts`; read `references/hooks.md`.
|
|
54
|
+
- Providers: `src/providers/index.ts`; read `references/providers.md`.
|
|
55
|
+
3. For TUI work, read `references/components.md` and Pi `docs/tui.md`.
|
|
56
|
+
4. For mode-sensitive UI, read `references/modes.md`.
|
|
57
|
+
5. For persistent state or custom messages, read `references/state.md` and `references/messages.md`.
|
|
58
|
+
6. For publishing, read `references/publish.md` and `references/documentation.md`.
|
|
59
|
+
|
|
60
|
+
### Modifying an existing extension
|
|
61
|
+
|
|
62
|
+
1. Read `package.json` to find Pi entry points.
|
|
63
|
+
2. Read the entry point and the relevant reference file.
|
|
64
|
+
3. Check the current Pi docs/changelog if changing Pi APIs.
|
|
65
|
+
4. Update code and docs together.
|
|
66
|
+
5. Run typecheck and lint when available.
|
|
65
67
|
|
|
66
68
|
## Reference Files
|
|
67
69
|
|
|
68
70
|
| File | Content |
|
|
69
71
|
|---|---|
|
|
70
|
-
| `references/structure.md` |
|
|
71
|
-
| `references/tools.md` |
|
|
72
|
-
| `references/
|
|
73
|
-
| `references/
|
|
74
|
-
| `references/components.md` | TUI
|
|
75
|
-
| `references/providers.md` |
|
|
76
|
-
| `references/modes.md` |
|
|
77
|
-
| `references/messages.md` | sendMessage
|
|
78
|
-
| `references/state.md` |
|
|
79
|
-
| `references/additional-apis.md` | Shortcuts, flags, exec,
|
|
80
|
-
| `references/publish.md` | npm publishing, changesets
|
|
81
|
-
| `references/testing.md` | Local
|
|
82
|
-
| `references/documentation.md` | README
|
|
72
|
+
| `references/structure.md` | Package layout, package.json, tsconfig, config, entry points, API-key pattern. |
|
|
73
|
+
| `references/tools.md` | `defineTool`, schemas, execute signature, prompt metadata, rendering, truncation, concurrency. |
|
|
74
|
+
| `references/commands.md` | Slash commands, argument completion, session methods, rich UI fallback. |
|
|
75
|
+
| `references/hooks.md` | Event lifecycle, blocking/cancelling, input transforms, system prompt hooks, bash hooks. |
|
|
76
|
+
| `references/components.md` | Pi TUI component interface, built-ins, custom UI, overlays, key handling. |
|
|
77
|
+
| `references/providers.md` | `pi.registerProvider(name, config)`, OAuth, streaming, model metadata. |
|
|
78
|
+
| `references/modes.md` | Interactive/RPC/JSON/Print behavior and fallback patterns. |
|
|
79
|
+
| `references/messages.md` | `sendMessage`, `registerMessageRenderer`, notification choices. |
|
|
80
|
+
| `references/state.md` | Reconstructible state via tool result `details`, `appendEntry` usage. |
|
|
81
|
+
| `references/additional-apis.md` | Shortcuts, flags, exec, session control, reload, UI customization. |
|
|
82
|
+
| `references/publish.md` | npm publishing, changesets, GitHub Actions, pre-publish checklist. |
|
|
83
|
+
| `references/testing.md` | Local testing, type checking, hook tests, core-unit testing. |
|
|
84
|
+
| `references/documentation.md` | README and changelog guidance. |
|
|
83
85
|
|
|
84
86
|
## Reference Extensions
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
- `pi-
|
|
90
|
-
- `pi-
|
|
91
|
-
- `pi-processes` (`/Users/alioudiallo/code/src/pi.dev/pi-processes/`): Multi-action tool with `promptSnippet`/`promptGuidelines` plus system prompt guidance hook for complex multi-tool orchestration, core `ProcessManager` class with unit tests, `ToolBody` with `showCollapsed` fields, conditional footers.
|
|
92
|
-
- `pi-linear` (`/Users/alioudiallo/code/src/pi.dev/pi-linear/`): Multi-action tool with action modules, auth wizard using `Wizard` from `@aliou/pi-utils-settings`, settings command with `registerSettingsCommand`, config migrations, `ToolBody`/`ToolFooter` rendering, system prompt guidance for cross-tool orchestration.
|
|
93
|
-
- `pi-obsidian` (`/Users/alioudiallo/code/src/pi.dev/pi-obsidian/`): Tools wrapping a CLI. Has a separate `obsidian-vault-core` package for domain logic. Uses `pi.exec()` for shell commands, `ToolCallHeader`/`ToolFooter` rendering, throws errors.
|
|
88
|
+
- `pi-linkup` (`/Users/alioudiallo/code/src/pi.dev/pi-linkup/`): API tools, prompt metadata, output truncation, API-key gating.
|
|
89
|
+
- `pi-synthetic` (`/Users/alioudiallo/code/src/pi.dev/pi-synthetic/`): Provider + tools, command UI, API-key gating.
|
|
90
|
+
- `pi-processes` (`/Users/alioudiallo/code/src/pi.dev/pi-processes/`): Multi-action process tool, prompt metadata plus orchestration guidance, unit-tested core manager.
|
|
91
|
+
- `pi-linear` (`/Users/alioudiallo/code/src/pi.dev/pi-linear/`): Multi-action tool, settings UI, auth wizard, config migrations.
|
|
92
|
+
- `pi-obsidian` (`/Users/alioudiallo/code/src/pi.dev/pi-obsidian/`): CLI wrapper with separate core package and `pi.exec()` usage.
|
|
94
93
|
|
|
95
94
|
## Critical Rules
|
|
96
95
|
|
|
97
|
-
1.
|
|
98
|
-
2.
|
|
99
|
-
3.
|
|
100
|
-
4.
|
|
101
|
-
5.
|
|
102
|
-
6.
|
|
103
|
-
7.
|
|
104
|
-
8.
|
|
105
|
-
9.
|
|
106
|
-
10.
|
|
107
|
-
11.
|
|
108
|
-
12.
|
|
109
|
-
13.
|
|
110
|
-
14.
|
|
111
|
-
15.
|
|
112
|
-
16.
|
|
113
|
-
17.
|
|
114
|
-
18.
|
|
115
|
-
19.
|
|
116
|
-
20.
|
|
117
|
-
21.
|
|
118
|
-
22.
|
|
119
|
-
23.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- [ ]
|
|
126
|
-
- [ ]
|
|
127
|
-
- [ ]
|
|
128
|
-
- [ ]
|
|
129
|
-
- [ ]
|
|
130
|
-
- [ ]
|
|
131
|
-
- [ ]
|
|
132
|
-
- [ ]
|
|
133
|
-
- [ ] `
|
|
134
|
-
- [ ]
|
|
135
|
-
- [ ]
|
|
136
|
-
- [ ] `renderResult` detects errors by checking for missing expected fields in `details` (framework sets `details: {}` on throw).
|
|
137
|
-
- [ ] `renderResult` uses `ToolBody` with `showCollapsed` fields.
|
|
138
|
-
- [ ] `renderResult` uses `ToolFooter` conditionally (omits when empty).
|
|
139
|
-
- [ ] Every tool has `label` field.
|
|
140
|
-
- [ ] Tools have `promptSnippet` and/or `promptGuidelines` when appropriate, and `promptGuidelines` bullets name the exact tool instead of saying `this tool`.
|
|
141
|
-
- [ ] Large output tools use `truncateHead()` + temp file pattern.
|
|
142
|
-
- [ ] Domain logic is extracted to testable core modules.
|
|
143
|
-
- [ ] File-mutating custom tools use `withFileMutationQueue()` for the full read-modify-write window.
|
|
144
|
-
- [ ] Path-taking custom tools normalize a leading `@` before resolving paths.
|
|
145
|
-
- [ ] Tool overrides re-declare `promptSnippet`/`promptGuidelines` if they need inherited prompt behavior.
|
|
146
|
-
- [ ] `ctx.ui.custom()` calls have RPC fallback, and interactive close/cancel paths do not rely on `done(undefined)` when fallback detection uses `result === undefined`.
|
|
147
|
-
- [ ] `tool_call` hooks check `ctx.hasUI` before dialog methods.
|
|
148
|
-
- [ ] Fire-and-forget methods (notify, setStatus, etc.) are used without hasUI guards.
|
|
149
|
-
- [ ] If using custom message renderers: collapsed view is scannable, expanded view adds depth, and renderer has plain-text fallback when `details` is missing.
|
|
150
|
-
- [ ] `signal` is forwarded to all async operations (fetch, `pi.exec`, API clients). No unused `_signal`.
|
|
151
|
-
- [ ] Missing API keys produce a notification, not a crash.
|
|
152
|
-
- [ ] If in a monorepo: package doesn't depend on private workspace packages (run `pnpm run check:public-deps` if available).
|
|
153
|
-
- [ ] `pnpm typecheck` passes.
|
|
154
|
-
- [ ] No `child_process` imports -- uses `pi.exec()` for shell commands.
|
|
155
|
-
- [ ] No `homedir()` calls for pi paths -- uses SDK helpers (`getAgentDir()`, etc.).
|
|
156
|
-
- [ ] README documents tools, commands, env vars.
|
|
157
|
-
- [ ] `@mariozechner/pi-tui` (and any other Pi-provided package) is in `peerDependencies` with `optional: true` if imported at runtime, not just `devDependencies`.
|
|
158
|
-
- [ ] `prepare` script is `"[ -d .git ] && husky || true"`, not bare `"husky"`.
|
|
159
|
-
- [ ] `config.ts` uses `ConfigLoader<Raw, Resolved>` with TypeScript interfaces, not TypeBox schemas.
|
|
160
|
-
- [ ] If deviating from the standard feature entry pattern (load-config → check-enabled → register), the reason is documented in `AGENTS.md`.
|
|
161
|
-
- [ ] Settings use `registerSettingsCommand` from `@aliou/pi-utils-settings` when the extension has user-configurable settings.
|
|
162
|
-
- [ ] New code imports TypeBox from `typebox`, not `@sinclair/typebox`.
|
|
163
|
-
- [ ] Any session replacement code uses `withSession` for post-switch work and does not reuse stale session-bound objects.
|
|
96
|
+
1. Use one Pi extension entry point per feature directory; avoid root `src/index.ts` fan-out registrars in new code.
|
|
97
|
+
2. Use `defineTool({...})` for standalone tool definitions. Do not pass explicit generic args; let params infer from `parameters`.
|
|
98
|
+
3. Define `type MyToolParams = Static<typeof parameters>` for helper/action APIs, but prefer inference inside `defineTool` callbacks.
|
|
99
|
+
4. Tool execute signature is `(toolCallId, params, signal, onUpdate, ctx)`. Signal comes before `onUpdate`.
|
|
100
|
+
5. Always call `onUpdate?.(...)` with optional chaining.
|
|
101
|
+
6. Every tool needs `label`. Add `promptSnippet` when the tool should appear in Available tools.
|
|
102
|
+
7. Every `promptGuidelines` bullet must name the exact tool. Do not say `this tool`.
|
|
103
|
+
8. Use `StringEnum` from `pi-ai` for model-facing string enums. Do not use `Type.Union([Type.Literal(...)])` for enums.
|
|
104
|
+
9. Handle `renderResult` partial state first with a stable tool-scoped message.
|
|
105
|
+
10. Detect tool errors by missing expected `details` fields or `context.isError`; thrown tools receive `details: {}`.
|
|
106
|
+
11. Use `ToolCallHeader`, `ToolBody`, and conditional `ToolFooter` for tool rendering.
|
|
107
|
+
12. Use existing TUI components before creating custom components.
|
|
108
|
+
13. `ctx.ui.custom()` needs RPC/print fallback. Interactive close paths must not rely on `done(undefined)`.
|
|
109
|
+
14. Dialog methods that gate behavior need `ctx.hasUI` checks; fire-and-forget UI methods do not.
|
|
110
|
+
15. Forward abort signals to `fetch`, `pi.exec`, SDK clients, and long-running work.
|
|
111
|
+
16. Use `pi.exec()` for normal shell commands. Do not use Node `child_process` unless a documented long-lived streaming process requires it.
|
|
112
|
+
17. File-mutating tools must normalize leading `@` paths and use `withFileMutationQueue()` for the full read-modify-write window.
|
|
113
|
+
18. Large output tools must truncate output, report truncation, and save full output to a temp file.
|
|
114
|
+
19. Store branch-aware tool state in tool result `details` and reconstruct from `ctx.sessionManager.getBranch()`.
|
|
115
|
+
20. After `ctx.newSession()`, `ctx.fork()`, or `ctx.switchSession()`, do post-switch work only in `withSession`.
|
|
116
|
+
21. Treat `await ctx.reload(); return;` as terminal in a command handler.
|
|
117
|
+
22. Provider dynamic model discovery belongs in an async extension factory, not `session_start`.
|
|
118
|
+
23. Use SDK helpers for Pi paths instead of `homedir()` when helpers exist.
|
|
119
|
+
24. No `.js` extensions in TypeScript imports.
|
|
120
|
+
25. Pi core packages you import belong in optional `peerDependencies` with `"*"`, and exact target versions in `devDependencies`.
|
|
121
|
+
|
|
122
|
+
## Completion Checklist
|
|
123
|
+
|
|
124
|
+
- [ ] `package.json` lists the right Pi entry points and package resources.
|
|
125
|
+
- [ ] Imported Pi core packages are optional peers and exact dev deps.
|
|
126
|
+
- [ ] Tools use `defineTool`, labels, prompt metadata where appropriate, correct execute order, optional `onUpdate`, and signal forwarding.
|
|
127
|
+
- [ ] `promptGuidelines` bullets name the exact tool.
|
|
128
|
+
- [ ] Tool renderers return components, handle partial/error states, and use compact collapsed views.
|
|
129
|
+
- [ ] Custom UI has RPC/print fallback and explicit sentinels.
|
|
130
|
+
- [ ] Providers use current provider/model fields (`name`, `authHeader`, `thinkingLevelMap`, OAuth where needed).
|
|
131
|
+
- [ ] State is reconstructible across reload/fork/compaction.
|
|
132
|
+
- [ ] No `child_process`, no `homedir()` for Pi paths, no `.js` import suffixes, no `@sinclair/typebox`.
|
|
133
|
+
- [ ] README documents setup, tools, commands, providers, env vars, and limitations.
|
|
134
|
+
- [ ] Typecheck and lint pass.
|