diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index c8a57b87d..0c4aba0b4 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- Fixed `pi.getAllTools()` to expose each tool's `promptGuidelines` for extensions that need per-tool guideline attribution ([#4879](https://github.com/earendil-works/pi/issues/4879)). - Fixed follow-up messages queued by `agent_end` extension handlers to drain before the agent becomes idle ([#5115](https://github.com/earendil-works/pi-mono/pull/5115) by [@DanielThomas](https://github.com/DanielThomas)). - Fixed extension input events to report `streamingBehavior` only for prompts actually queued during streaming ([#5107](https://github.com/earendil-works/pi-mono/pull/5107)). - Fixed fenced `diff` code blocks and other highlight.js scopes to keep theme-aware syntax colors after the `cli-highlight` replacement ([#5092](https://github.com/earendil-works/pi/issues/5092)). diff --git a/packages/coding-agent/docs/extensions.md b/packages/coding-agent/docs/extensions.md index 4d243d9a5..db856fc86 100644 --- a/packages/coding-agent/docs/extensions.md +++ b/packages/coding-agent/docs/extensions.md @@ -1493,7 +1493,8 @@ const all = pi.getAllTools(); // [{ // name: "read", // description: "Read file contents...", -// parameters: ..., +// parameters: ..., +// promptGuidelines: ["Use read to examine files instead of cat or sed."], // sourceInfo: { path: "", source: "builtin", scope: "temporary", origin: "top-level" } // }, ...] const names = all.map(t => t.name); @@ -1502,7 +1503,7 @@ const extensionTools = all.filter((t) => t.sourceInfo.source !== "builtin" && t. pi.setActiveTools(["read", "bash"]); // Switch to read-only ``` -`pi.getAllTools()` returns `name`, `description`, `parameters`, and `sourceInfo`. +`pi.getAllTools()` returns `name`, `description`, `parameters`, `promptGuidelines`, and `sourceInfo`. Typical `sourceInfo.source` values: - `builtin` for built-in tools diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts index 59a39ef39..212de19e3 100644 --- a/packages/coding-agent/src/core/agent-session.ts +++ b/packages/coding-agent/src/core/agent-session.ts @@ -759,13 +759,14 @@ export class AgentSession { } /** - * Get all configured tools with name, description, parameter schema, and source metadata. + * Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata. */ getAllTools(): ToolInfo[] { return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({ name: definition.name, description: definition.description, parameters: definition.parameters, + promptGuidelines: definition.promptGuidelines, sourceInfo, })); } diff --git a/packages/coding-agent/src/core/extensions/types.ts b/packages/coding-agent/src/core/extensions/types.ts index f7afcf135..0d5bb7af9 100644 --- a/packages/coding-agent/src/core/extensions/types.ts +++ b/packages/coding-agent/src/core/extensions/types.ts @@ -1213,7 +1213,7 @@ export interface ExtensionAPI { /** Get the list of currently active tool names. */ getActiveTools(): string[]; - /** Get all configured tools with parameter schema and source metadata. */ + /** Get all configured tools with parameter schema, prompt guidelines, and source metadata. */ getAllTools(): ToolInfo[]; /** Set the active tools by name. */ @@ -1424,8 +1424,8 @@ export type GetSessionNameHandler = () => string | undefined; export type GetActiveToolsHandler = () => string[]; -/** Tool info with name, description, parameter schema, and source metadata */ -export type ToolInfo = Pick & { +/** Tool info with name, description, parameter schema, prompt guidelines, and source metadata. */ +export type ToolInfo = Pick & { sourceInfo: SourceInfo; }; diff --git a/packages/coding-agent/test/agent-session-dynamic-tools.test.ts b/packages/coding-agent/test/agent-session-dynamic-tools.test.ts index e58ea22fc..cf64a17f7 100644 --- a/packages/coding-agent/test/agent-session-dynamic-tools.test.ts +++ b/packages/coding-agent/test/agent-session-dynamic-tools.test.ts @@ -72,6 +72,9 @@ describe("AgentSession dynamic tool registration", () => { const readTool = allTools.find((tool) => tool.name === "read"); expect(allTools.map((tool) => tool.name)).toContain("dynamic_tool"); + expect(dynamicTool?.promptGuidelines).toEqual([ + "Use dynamic_tool when the user asks for dynamic behavior tests.", + ]); expect(dynamicTool?.sourceInfo).toMatchObject({ path: "", source: "inline",