@ampcode/plugin 0.0.0-20260505003009-gecb28b5 → 0.0.0-20260507002947-gc0f61c8
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 +26 -59
- package/index.d.ts +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,79 +1,46 @@
|
|
|
1
|
-
<!-- This file is
|
|
1
|
+
<!-- This file is the npm package README. The full guide lives at https://ampcode.com/manual#plugins -->
|
|
2
2
|
|
|
3
3
|
# Amp Plugin API
|
|
4
4
|
|
|
5
|
-
Amp plugins are TypeScript files that extend and customize [Amp](https://ampcode.com).
|
|
5
|
+
Amp plugins are TypeScript files that extend and customize [Amp](https://ampcode.com).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Plugins can:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- **Handle events** — `amp.on(...)` for tool calls, tool results, and agent lifecycle events
|
|
10
|
+
- **Add tools** — `amp.registerTool(...)` for custom tools the agent can call
|
|
11
|
+
- **Add commands** — `amp.registerCommand(...)` for command palette actions
|
|
12
|
+
- **Show UI** — `ctx.ui.notify(...)`, `ctx.ui.confirm(...)`, `ctx.ui.input(...)`, and `ctx.ui.select(...)`
|
|
13
|
+
- **Classify with AI** — `amp.ai.ask(...)` for yes/no decisions with confidence and reasoning
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
- **Tools** — `amp.registerTool(...)` for custom tools
|
|
13
|
-
- **Commands** — `amp.registerCommand(...)` to add to Amp's command palette
|
|
14
|
-
- **User input and UI** — `ctx.ui.notify(...)`, `ctx.ui.confirm(...)`
|
|
15
|
-
- **AI & system utilities** — `amp.ai.ask(...)` for yes-no LLM answers
|
|
15
|
+
## Locations
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Amp loads plugins from three locations:
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
- **Project plugins** — `.amp/plugins/*.ts`
|
|
20
|
+
- **System plugins** — `~/.config/amp/plugins/*.ts`
|
|
21
|
+
- **Global plugins** — configured in workspace settings (limited experimental release)
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
- Ensure Amp runs tests before finishing its work
|
|
23
|
-
- Block or require confirmation for commands you deem risky
|
|
24
|
-
- Correct common agent mistakes that AGENTS.md alone can't fix
|
|
25
|
-
|
|
26
|
-
See [Amp Plugin API documentation](https://ampcode.com/manual/plugin-api).
|
|
27
|
-
|
|
28
|
-
## Using Plugins
|
|
29
|
-
|
|
30
|
-
Run the Amp CLI with `PLUGINS=all amp` to use plugins. If the `PLUGINS` env var is not set, plugins are disabled. Plugins can execute arbitrary code, so only enable plugins when running Amp in trusted workspaces.
|
|
31
|
-
|
|
32
|
-
**Limitations:**
|
|
33
|
-
|
|
34
|
-
- The Amp plugin API only works in the Amp CLI, not the Amp editor extension.
|
|
35
|
-
- The Amp plugin API only works when the Amp CLI is installed via the binary install method, not via `npm install`.
|
|
36
|
-
|
|
37
|
-
## Authoring Plugins
|
|
38
|
-
|
|
39
|
-
Use this prompt:
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
Make an Amp plugin to __________. See https://ampcode.com/manual/plugin-api for docs.
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
- Ensure you're running with `PLUGINS=all amp`
|
|
46
|
-
- Use `Ctrl-o` `plugins: reload` to reload all plugins after they're changed.
|
|
47
|
-
- All plugin files must start with `// @i-know-the-amp-plugin-api-is-wip-and-very-experimental-right-now`.
|
|
48
|
-
|
|
49
|
-
## Example Plugin
|
|
50
|
-
|
|
51
|
-
`.amp/plugins/permissions.ts`:
|
|
23
|
+
## Minimal Plugin
|
|
52
24
|
|
|
53
25
|
```ts
|
|
54
|
-
// @i-know-the-amp-plugin-api-is-wip-and-very-experimental-right-now
|
|
55
26
|
import type { PluginAPI } from '@ampcode/plugin'
|
|
56
27
|
|
|
57
28
|
export default function (amp: PluginAPI) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const confirmed = await ctx.ui.confirm({
|
|
61
|
-
title: `Allow ${event.tool}?`,
|
|
62
|
-
message: `The agent wants to execute the "${event.tool}" tool.`,
|
|
63
|
-
confirmButtonText: 'Allow',
|
|
64
|
-
})
|
|
65
|
-
if (!confirmed) {
|
|
66
|
-
ctx.logger.log(`User rejected tool execution: ${event.tool}`)
|
|
67
|
-
return {
|
|
68
|
-
action: 'reject-and-continue',
|
|
69
|
-
message: `User rejected execution of tool ${event.tool}.`,
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return { action: 'allow' }
|
|
29
|
+
amp.on('session.start', async (_event, ctx) => {
|
|
30
|
+
await ctx.ui.notify('Plugin loaded.')
|
|
73
31
|
})
|
|
74
32
|
}
|
|
75
33
|
```
|
|
76
34
|
|
|
35
|
+
After changing a plugin, open the command palette and run `plugins: reload`.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
- Plugin guide and worked examples: <https://ampcode.com/manual#plugins>
|
|
40
|
+
- Full `@ampcode/plugin` type reference and a complete kitchen-sink example: <https://ampcode.com/manual/plugin-api>
|
|
41
|
+
|
|
42
|
+
Plugins execute code, so only use plugins from people and workspaces you trust.
|
|
43
|
+
|
|
77
44
|
## Acknowledgment
|
|
78
45
|
|
|
79
|
-
Amp's plugin API is inspired by [pi's extension API](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/docs/extensions.md), created by
|
|
46
|
+
Amp's plugin API is inspired by [pi's extension API](https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/docs/extensions.md), created by Mario Zechner.
|
package/index.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ declare module '@ampcode/plugin' {
|
|
|
47
47
|
toolCallsInMessages: ToolCallsInMessages
|
|
48
48
|
filesModifiedByToolCall: FilesModifiedByToolCall
|
|
49
49
|
filePathFromURI: FilePathFromURI
|
|
50
|
+
isPluginUINotAvailableError: IsPluginUINotAvailableError
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -727,6 +728,11 @@ declare module '@ampcode/plugin' {
|
|
|
727
728
|
*/
|
|
728
729
|
export type FilePathFromURI = (uri: URI) => string
|
|
729
730
|
|
|
731
|
+
/**
|
|
732
|
+
* Determines whether an instance of Error indicates that no Plugin UI is available.
|
|
733
|
+
*/
|
|
734
|
+
export type IsPluginUINotAvailableError = (error: Error) => boolean
|
|
735
|
+
|
|
730
736
|
/**
|
|
731
737
|
* Options for registering a command.
|
|
732
738
|
*/
|