mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 02:04:32 +00:00
Improve extension discovery docs with multi-entry package.json example
This commit is contained in:
parent
91cca23d23
commit
f4a3724b7e
2 changed files with 33 additions and 1012 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -8,7 +8,7 @@ Extensions are TypeScript modules that extend pi's behavior. They can subscribe
|
||||||
- **Custom tools** - Register tools the LLM can call via `pi.registerTool()`
|
- **Custom tools** - Register tools the LLM can call via `pi.registerTool()`
|
||||||
- **Event interception** - Block or modify tool calls, inject context, customize compaction
|
- **Event interception** - Block or modify tool calls, inject context, customize compaction
|
||||||
- **User interaction** - Prompt users via `ctx.ui` (select, confirm, input, notify)
|
- **User interaction** - Prompt users via `ctx.ui` (select, confirm, input, notify)
|
||||||
- **Custom UI components** - Full TUI components with keyboard input via `ctx.ui.custom()`
|
- **Custom UI components** - Full TUI components with keyboard input via `ctx.ui.custom()` for complex interactions
|
||||||
- **Custom commands** - Register commands like `/mycommand` via `pi.registerCommand()`
|
- **Custom commands** - Register commands like `/mycommand` via `pi.registerCommand()`
|
||||||
- **Session persistence** - Store state that survives restarts via `pi.appendEntry()`
|
- **Session persistence** - Store state that survives restarts via `pi.appendEntry()`
|
||||||
- **Custom rendering** - Control how tool calls/results and messages appear in TUI
|
- **Custom rendering** - Control how tool calls/results and messages appear in TUI
|
||||||
|
|
@ -97,18 +97,43 @@ Additional paths via `settings.json`:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Subdirectory structure with package.json:**
|
**Discovery rules:**
|
||||||
|
|
||||||
|
1. **Direct files:** `extensions/*.ts` or `*.js` → loaded directly
|
||||||
|
2. **Subdirectory with index:** `extensions/myext/index.ts` → loaded as single extension
|
||||||
|
3. **Subdirectory with package.json:** `extensions/myext/package.json` with `"pi"` field → loads declared paths
|
||||||
|
|
||||||
```
|
```
|
||||||
~/.pi/agent/extensions/
|
~/.pi/agent/extensions/
|
||||||
├── simple.ts # Direct file (auto-discovered)
|
├── simple.ts # Direct file (auto-discovered)
|
||||||
└── complex-extension/
|
├── my-tool/
|
||||||
├── package.json # Optional: { "pi": { "extensions": ["./src/main.ts"] } }
|
│ └── index.ts # Subdirectory with index (auto-discovered)
|
||||||
├── index.ts # Entry point (if no package.json)
|
└── my-extension-pack/
|
||||||
|
├── package.json # Declares multiple extensions
|
||||||
|
├── node_modules/ # Dependencies installed here
|
||||||
└── src/
|
└── src/
|
||||||
└── main.ts # Custom entry (via package.json)
|
├── safety-gates.ts # First extension
|
||||||
|
└── custom-tools.ts # Second extension
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
// my-extension-pack/package.json
|
||||||
|
{
|
||||||
|
"name": "my-extension-pack",
|
||||||
|
"dependencies": {
|
||||||
|
"lodash": "^4.0.0"
|
||||||
|
},
|
||||||
|
"pi": {
|
||||||
|
"extensions": ["./src/safety-gates.ts", "./src/custom-tools.ts"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `package.json` approach enables:
|
||||||
|
- Multiple extensions from one package
|
||||||
|
- Third-party npm dependencies (resolved via jiti)
|
||||||
|
- Nested source structure (no depth limit within the package)
|
||||||
|
|
||||||
## Available Imports
|
## Available Imports
|
||||||
|
|
||||||
| Package | Purpose |
|
| Package | Purpose |
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue