@kilncraft/plugin-sdk 1.0.0 → 1.1.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 +192 -0
- package/package.json +9 -9
- package/LICENSE +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# @kilncraft/plugin-sdk
|
|
2
|
+
|
|
3
|
+
Types and helpers for writing Kilncraft plugins. A plugin can add tools, prompt
|
|
4
|
+
commands, and lifecycle hooks without modifying the core packages.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm i @kilncraft/plugin-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Requires Node.js >= 24.
|
|
13
|
+
|
|
14
|
+
## Define a plugin
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { definePlugin } from "@kilncraft/plugin-sdk";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
|
|
20
|
+
const input = z.object({ path: z.string() });
|
|
21
|
+
|
|
22
|
+
export default definePlugin({
|
|
23
|
+
id: "my-plugin",
|
|
24
|
+
version: "1.0.0",
|
|
25
|
+
|
|
26
|
+
hooks: {
|
|
27
|
+
"session.start": async (context, payload) => {
|
|
28
|
+
context.logger.info({ session: payload.sessionID }, "session started");
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
"message.received": async (_context, payload) => {
|
|
32
|
+
// Return a replacement message, or undefined to keep it.
|
|
33
|
+
return undefined;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
"tool.before": async (_context, payload) => {
|
|
37
|
+
if (payload.call.name === "bash" && /rm\s+-rf/.test(String(payload.call.input))) {
|
|
38
|
+
return "block";
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
"tool.after": async (_context, payload) => {
|
|
44
|
+
if (payload.call.name === "read") {
|
|
45
|
+
return { kind: "text", text: "blocked by plugin" };
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
event: async (context, event) => {
|
|
51
|
+
context.logger.debug({ event: event.type }, "plugin event");
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
tools: [
|
|
56
|
+
{
|
|
57
|
+
id: "my_tool",
|
|
58
|
+
description: "Example tool",
|
|
59
|
+
input,
|
|
60
|
+
readOnly: true,
|
|
61
|
+
parallelizable: true,
|
|
62
|
+
defaultDecision: "allow",
|
|
63
|
+
async execute({ path }, context) {
|
|
64
|
+
return { kind: "text", text: `plugin saw ${path}` };
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
|
|
69
|
+
commands: [
|
|
70
|
+
{
|
|
71
|
+
name: "/my-command",
|
|
72
|
+
description: "Insert a prompt template",
|
|
73
|
+
template: "Review $ARGUMENTS for correctness.",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`definePlugin` validates that `id` is a non-empty string and returns the same
|
|
80
|
+
object. It is a type helper, not a runtime wrapper.
|
|
81
|
+
|
|
82
|
+
## Plugin shape
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
interface Plugin {
|
|
86
|
+
id: string;
|
|
87
|
+
version?: string;
|
|
88
|
+
hooks?: PluginHooks;
|
|
89
|
+
tools?: ToolDefinition<unknown>[];
|
|
90
|
+
commands?: PluginCommand[];
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
A plugin module may be:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
export default plugin;
|
|
98
|
+
// or
|
|
99
|
+
export const plugin = { ... };
|
|
100
|
+
// or
|
|
101
|
+
export { plugin };
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`loadPlugins` (from `@kilncraft/core`) unwraps all three shapes.
|
|
105
|
+
|
|
106
|
+
## Hooks
|
|
107
|
+
|
|
108
|
+
| Hook | Signature | Return |
|
|
109
|
+
| ------------------ | ---------------------------------------- | ------------------------------------------------- |
|
|
110
|
+
| `session.start` | `(context, { sessionID, cwd, model })` | `void` |
|
|
111
|
+
| `message.received` | `(context, { sessionID, message })` | replacement `ChatMessage` or `undefined` |
|
|
112
|
+
| `tool.before` | `(context, { sessionID, call })` | replacement `ToolCall`, `"block"`, or `undefined` |
|
|
113
|
+
| `tool.after` | `(context, { sessionID, call, output })` | replacement `ToolOutput` or `undefined` |
|
|
114
|
+
| `event` | `(context, event)` | `void` |
|
|
115
|
+
|
|
116
|
+
Rules:
|
|
117
|
+
|
|
118
|
+
- Hooks run in plugin order; a later plugin sees the previous plugin's result.
|
|
119
|
+
- A hook that throws is logged and skipped; it does not crash the agent.
|
|
120
|
+
- `tool.before` cannot change a tool call's `id`.
|
|
121
|
+
- `tool.after` can replace output but should preserve the output contract.
|
|
122
|
+
|
|
123
|
+
`PluginContext` contains `cwd`, `dataDir`, and a redacting `logger`.
|
|
124
|
+
|
|
125
|
+
## Tools
|
|
126
|
+
|
|
127
|
+
Plugins add tools through the same `ToolDefinition` contract used by the core
|
|
128
|
+
(`id`, `description`, Zod `input`, `readOnly`, `parallelizable`,
|
|
129
|
+
`defaultDecision`, `execute`). Register them by adding the plugin to config:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"plugins": ["./plugins/my-plugin.ts"]
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Paths are resolved relative to the workspace; package specifiers are imported as
|
|
138
|
+
module URLs.
|
|
139
|
+
|
|
140
|
+
## Commands
|
|
141
|
+
|
|
142
|
+
`PluginCommand` is:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
interface PluginCommand {
|
|
146
|
+
name: string; // e.g. "/review"
|
|
147
|
+
description: string;
|
|
148
|
+
template: string; // prompt template, may include $ARGUMENTS
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
`PluginHost.getCommands()` exposes them. The current TUI/CLI command surface does
|
|
153
|
+
not yet render plugin commands automatically; they are available to embedders and
|
|
154
|
+
future UI work.
|
|
155
|
+
|
|
156
|
+
## Loading and reloading
|
|
157
|
+
|
|
158
|
+
`@kilncraft/core` loads plugins listed in `config.plugins`:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { loadPlugins } from "@kilncraft/core";
|
|
162
|
+
|
|
163
|
+
const host = await loadPlugins(config.plugins, {
|
|
164
|
+
cwd: process.cwd(),
|
|
165
|
+
dataDir: "/tmp/kilncraft-data",
|
|
166
|
+
logger,
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The SDK's `reload()` reloads config and plugins and returns the plugin ids.
|
|
171
|
+
|
|
172
|
+
## Security
|
|
173
|
+
|
|
174
|
+
Plugins are trusted local code. `loadPlugins` imports them with Node's module
|
|
175
|
+
loader, so a plugin can run arbitrary code. Only load plugins from sources you
|
|
176
|
+
control, and review third-party plugins before adding them. Plugin `tools` go
|
|
177
|
+
through the permission engine like built-in tools.
|
|
178
|
+
|
|
179
|
+
## Development
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
pnpm --filter @kilncraft/plugin-sdk build
|
|
183
|
+
pnpm --filter @kilncraft/plugin-sdk test
|
|
184
|
+
pnpm --filter @kilncraft/plugin-sdk typecheck
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Related packages
|
|
188
|
+
|
|
189
|
+
- `@kilncraft/core` — `PluginHost` and `loadPlugins`
|
|
190
|
+
- `@kilncraft/shared` — plugin and tool types
|
|
191
|
+
- `@kilncraft/sdk` — `reload()` for plugin changes
|
|
192
|
+
- [Root README](../../README.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kilncraft/plugin-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,8 +14,14 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"clean": "rm -rf dist .turbo coverage"
|
|
22
|
+
},
|
|
17
23
|
"dependencies": {
|
|
18
|
-
"@kilncraft/shared": "
|
|
24
|
+
"@kilncraft/shared": "workspace:*"
|
|
19
25
|
},
|
|
20
26
|
"devDependencies": {
|
|
21
27
|
"@types/node": "26.6.6",
|
|
@@ -26,11 +32,5 @@
|
|
|
26
32
|
},
|
|
27
33
|
"publishConfig": {
|
|
28
34
|
"access": "public"
|
|
29
|
-
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "tsup",
|
|
32
|
-
"typecheck": "tsc --noEmit",
|
|
33
|
-
"test": "vitest run",
|
|
34
|
-
"clean": "rm -rf dist .turbo coverage"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Kilncraft contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|