feat(coding-agent): add packages array with filtering support

- Add PackageSource type for npm/git sources with optional filtering
- Migrate npm:/git: sources from extensions to packages array
- Add getPackages(), setPackages(), setProjectPackages() methods
- Update package-manager to resolve from packages array
- Support selective loading: extensions, skills, prompts, themes per package
- Update pi list to show packages
- Add migration tests for settings

closes #645
This commit is contained in:
Mario Zechner 2026-01-23 19:51:23 +01:00
parent dd838d0fe0
commit ef1fc3103e
8 changed files with 434 additions and 63 deletions

View file

@ -846,7 +846,11 @@ Global `~/.pi/agent/settings.json` stores persistent preferences:
| `doubleEscapeAction` | Action for double-escape with empty editor: `tree` or `fork` | `tree` |
| `editorPaddingX` | Horizontal padding for input editor (0-3) | `0` |
| `markdown.codeBlockIndent` | Prefix for each rendered code block line | `" "` |
| `extensions` | Extension sources or file paths (npm:, git:, local) | `[]` |
| `packages` | External package sources (npm:, git:) with optional filtering | `[]` |
| `extensions` | Local extension file paths or directories | `[]` |
| `skills` | Local skill file paths or directories | `[]` |
| `prompts` | Local prompt template file paths or directories | `[]` |
| `themes` | Local theme file paths or directories | `[]` |
---
@ -983,19 +987,43 @@ Extensions are TypeScript modules that extend pi's behavior.
**Locations:**
- Global: `~/.pi/agent/extensions/*.ts` or `~/.pi/agent/extensions/*/index.ts`
- Project: `.pi/extensions/*.ts` or `.pi/extensions/*/index.ts`
- Settings: `extensions` array supports file paths and `npm:` or `git:` sources
- Settings: `extensions` array for local paths, `packages` array for npm/git sources
- CLI: `--extension <path>` or `-e <path>` (temporary for this run)
Install and remove extension sources with the CLI:
**Install packages:**
```bash
pi install npm:@foo/bar@1.0.0
pi install git:github.com/user/repo@v1
pi install https://github.com/user/repo # raw URLs work too
pi remove npm:@foo/bar
pi list # show installed packages
pi update # update all non-pinned packages
```
Use `-l` to install into project settings (`.pi/settings.json`).
**Package filtering:** By default, packages load all resources (extensions, skills, prompts, themes). To selectively load only certain resources, use the object form in settings.json:
```json
{
"packages": [
"npm:simple-pkg",
{
"source": "npm:shitty-extensions",
"extensions": ["extensions/oracle.ts", "extensions/memory-mode.ts"],
"skills": ["skills/a-nach-b"],
"themes": [],
"prompts": []
}
]
}
```
- Omit a key to load all of that type
- Use empty array `[]` to load none of that type
- Paths are relative to package root
**Dependencies:** Extensions can have their own dependencies. Place a `package.json` next to the extension (or in a parent directory), run `npm install`, and imports are resolved via [jiti](https://github.com/unjs/jiti). See [examples/extensions/with-deps/](examples/extensions/with-deps/).
#### Custom Tools