@codeplane-ai/plugin 30.0.1 → 31.0.1
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/dist/example.d.ts +5 -0
- package/dist/example.js +22 -0
- package/dist/index.d.ts +42 -0
- package/package.json +1 -1
package/dist/example.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { Plugin } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Example plugin demonstrating the tool lifecycle hooks a plugin can use to
|
|
4
|
+
* extend Codeplane: registering tools, gating which tools the model sees,
|
|
5
|
+
* and observing/repairing tool failures.
|
|
6
|
+
*/
|
|
2
7
|
export declare const ExamplePlugin: Plugin;
|
package/dist/example.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { tool } from "./tool.js";
|
|
2
|
+
/**
|
|
3
|
+
* Example plugin demonstrating the tool lifecycle hooks a plugin can use to
|
|
4
|
+
* extend Codeplane: registering tools, gating which tools the model sees,
|
|
5
|
+
* and observing/repairing tool failures.
|
|
6
|
+
*/
|
|
2
7
|
export const ExamplePlugin = async (_ctx) => {
|
|
3
8
|
return {
|
|
9
|
+
// Register a custom tool the model can call.
|
|
4
10
|
tool: {
|
|
5
11
|
mytool: tool({
|
|
6
12
|
description: "This is a custom tool",
|
|
@@ -12,5 +18,21 @@ export const ExamplePlugin = async (_ctx) => {
|
|
|
12
18
|
},
|
|
13
19
|
}),
|
|
14
20
|
},
|
|
21
|
+
// Gate which tools are exposed to the model. Here we enforce a read-only
|
|
22
|
+
// mode for a "reviewer" agent by hiding mutating tools.
|
|
23
|
+
"tool.list": async (input, output) => {
|
|
24
|
+
if (input.agent === "reviewer") {
|
|
25
|
+
const blocked = new Set(["write", "edit", "bash", "apply_patch"]);
|
|
26
|
+
output.tools = output.tools.filter((id) => !blocked.has(id));
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
// Observe tool failures and rewrite the message the model sees so it can
|
|
30
|
+
// recover instead of giving up.
|
|
31
|
+
"tool.execute.error": async (input, output) => {
|
|
32
|
+
console.error(`[example] tool ${input.tool} failed: ${output.error}`);
|
|
33
|
+
if (input.tool === "webfetch") {
|
|
34
|
+
output.output += "\n\nHint: the network may be offline — try `read` on a local file instead.";
|
|
35
|
+
}
|
|
36
|
+
},
|
|
15
37
|
};
|
|
16
38
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -251,6 +251,33 @@ export interface Hooks {
|
|
|
251
251
|
output: string;
|
|
252
252
|
metadata: any;
|
|
253
253
|
}) => Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Called when a tool fails to execute. Fires for native tools, MCP tools,
|
|
256
|
+
* and the task/subagent tool, completing the tool lifecycle alongside
|
|
257
|
+
* `tool.execute.before` and `tool.execute.after`.
|
|
258
|
+
*
|
|
259
|
+
* Use it to observe failures (telemetry, metrics, retries) and to rewrite
|
|
260
|
+
* the text the model sees so it can recover gracefully instead of giving up.
|
|
261
|
+
*
|
|
262
|
+
* - `error`: the original error message (informational)
|
|
263
|
+
* - `output`: the failure text shown to the model. Mutate to customize.
|
|
264
|
+
* - `title`/`metadata`: tool-call title and metadata where available; mutate
|
|
265
|
+
* to enrich the recorded tool call.
|
|
266
|
+
*
|
|
267
|
+
* Note: some tools (e.g. certain MCP tools) still produce output on failure,
|
|
268
|
+
* in which case `tool.execute.after` also fires after this hook.
|
|
269
|
+
*/
|
|
270
|
+
"tool.execute.error"?: (input: {
|
|
271
|
+
tool: string;
|
|
272
|
+
sessionID: string;
|
|
273
|
+
callID: string;
|
|
274
|
+
args: any;
|
|
275
|
+
}, output: {
|
|
276
|
+
error: string;
|
|
277
|
+
output: string;
|
|
278
|
+
title?: string;
|
|
279
|
+
metadata?: Record<string, any>;
|
|
280
|
+
}) => Promise<void>;
|
|
254
281
|
"experimental.chat.messages.transform"?: (input: {}, output: {
|
|
255
282
|
messages: {
|
|
256
283
|
info: Message;
|
|
@@ -309,4 +336,19 @@ export interface Hooks {
|
|
|
309
336
|
description: string;
|
|
310
337
|
parameters: any;
|
|
311
338
|
}) => Promise<void>;
|
|
339
|
+
/**
|
|
340
|
+
* Called once per turn when the set of tools exposed to the model is
|
|
341
|
+
* assembled, after agent/session permission filtering. Lets plugins gate
|
|
342
|
+
* which tools the model can see and call — e.g. enforce a read-only mode,
|
|
343
|
+
* disable network tools, or restrict tools for a specific agent.
|
|
344
|
+
*
|
|
345
|
+
* - `agent`: the active agent name
|
|
346
|
+
* - `tools`: the available tool IDs. Mutate the array to add or remove
|
|
347
|
+
* entries; removed tools are hidden from the model for this turn.
|
|
348
|
+
*/
|
|
349
|
+
"tool.list"?: (input: {
|
|
350
|
+
agent: string;
|
|
351
|
+
}, output: {
|
|
352
|
+
tools: string[];
|
|
353
|
+
}) => Promise<void>;
|
|
312
354
|
}
|