Created greet tool outputting 'hi'.
BuildAdded custom red rendering for tool output.
EditConfirmed tool output displays in red.
Verifyi want to create a simple custom tool in an extension called greet.ts in .pi/extensions. the tool should just output "hi"
The user wants to create a custom tool in an extension. I should first read the extensions documentation to understand how to create extensions with custom tools.
I have the documentation. Let me create a simple extension with a custom tool called "greet" that outputs "hi". Based on the examples and documentation, I need to:
.pi/extensions/greet.tsExtensionAPIpi.registerTool()The simplest version would have:
Done. I created a simple extension with a custom tool that outputs "hi". The extension:
ExtensionAPIThe user can test it by running pi from this directory since it's in the project-local .pi/extensions/ folder, or by using pi -e .pi/extensions/greet.ts.
Created .pi/extensions/greet.ts with a simple greet tool that returns "hi".
The extension will be auto-discovered when you run pi from this directory. Alternatively, test it with:
pi -e .pi/extensions/greet.tswell use the tool now
The user wants me to use the greet tool that was just created. I have access to it as a tool.
hiThe greet tool worked and returned "hi" as expected.
Done! The tool returned "hi" as expected.
add simple custom rendering for the tool result, make the output red
The user wants me to add custom rendering for the tool result to make the output red. Based on the documentation, I need to add a renderResult function to the tool definition that uses the theme to style the text red.
Looking at the docs:
renderResult(result, options, theme) - renders the tool resultText from @mariozechner/pi-tuitheme.fg("error", text) since error is typically redLet me update the extension.
I've added a renderResult function that uses theme.fg("error", "hi") to render the output in red (error color is typically red). Let me use the tool again to show it working.
hiThe tool worked. The rendering should now show "hi" in red in the TUI. The function result here just shows the text content, but in the actual TUI display it would be rendered in red using the theme's error color.
Done. Added renderResult that uses theme.fg("error", "hi") to render the output in red. The tool result should now display in red in the TUI.
use the greet tool again
The user wants me to use the greet tool again to see the red rendering.
hiThe tool was called. In the TUI, the "hi" should now be rendered in red due to the custom renderResult function.
Done. You should see "hi" rendered in red now.
pi -e .pi/extensions/greet.ts