@kilncraft/plugin-sdk 0.0.0-stage → 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 CHANGED
@@ -1,3 +1,192 @@
1
- # Temporary Holding Version
1
+ # @kilncraft/plugin-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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)
@@ -0,0 +1,6 @@
1
+ import { Plugin } from '@kilncraft/shared';
2
+ export { Plugin, PluginCommand, PluginContext, PluginHooks, PluginModule } from '@kilncraft/shared';
3
+
4
+ declare function definePlugin(plugin: Plugin): Plugin;
5
+
6
+ export { definePlugin };
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ // src/index.ts
2
+ function definePlugin(plugin) {
3
+ if (typeof plugin.id !== "string" || plugin.id.length === 0) {
4
+ throw new Error("Plugin id must be a non-empty string");
5
+ }
6
+ return plugin;
7
+ }
8
+
9
+ export { definePlugin };
10
+ //# sourceMappingURL=index.js.map
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAUO,SAAS,aAAa,MAAA,EAAwB;AACnD,EAAA,IAAI,OAAO,MAAA,CAAO,EAAA,KAAO,YAAY,MAAA,CAAO,EAAA,CAAG,WAAW,CAAA,EAAG;AAC3D,IAAA,MAAM,IAAI,MAAM,sCAAsC,CAAA;AAAA,EACxD;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import type {\n Plugin,\n PluginCommand,\n PluginContext,\n PluginHooks,\n PluginModule,\n} from \"@kilncraft/shared\";\n\nexport type { Plugin, PluginCommand, PluginContext, PluginHooks, PluginModule };\n\nexport function definePlugin(plugin: Plugin): Plugin {\n if (typeof plugin.id !== \"string\" || plugin.id.length === 0) {\n throw new Error(\"Plugin id must be a non-empty string\");\n }\n return plugin;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@kilncraft/plugin-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "vitest run",
21
+ "clean": "rm -rf dist .turbo coverage"
22
+ },
23
+ "dependencies": {
24
+ "@kilncraft/shared": "workspace:*"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "26.6.6",
28
+ "@vitest/coverage-v8": "5.1.0",
29
+ "tsup": "9.0.0",
30
+ "typescript": "5.9.3",
31
+ "vitest": "5.1.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
36
+ }