diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 4ad80077..1c1e9c38 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -9,6 +9,8 @@ ### Added - Added `ctx.reload()` to the extension API for programmatic runtime reload ([#1371](https://github.com/badlogic/pi-mono/issues/1371)) +- `/export` HTML now includes tool input schema (parameter names, types, descriptions) in a collapsible section under each tool ([#1416](https://github.com/badlogic/pi-mono/pull/1416) by [@marchellodev](https://github.com/marchellodev)) +- `pi.getAllTools()` now returns tool parameters in addition to name and description ([#1416](https://github.com/badlogic/pi-mono/pull/1416) by [@marchellodev](https://github.com/marchellodev)) ### Fixed diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts index cdc6abba..5f54b4a9 100644 --- a/packages/coding-agent/src/core/agent-session.ts +++ b/packages/coding-agent/src/core/agent-session.ts @@ -56,6 +56,7 @@ import { type SessionBeforeTreeResult, type ShutdownHandler, type ToolDefinition, + type ToolInfo, type TreePreparation, type TurnEndEvent, type TurnStartEvent, @@ -535,12 +536,13 @@ export class AgentSession { } /** - * Get all configured tools with name and description. + * Get all configured tools with name, description, and parameter schema. */ - getAllTools(): Array<{ name: string; description: string }> { + getAllTools(): ToolInfo[] { return Array.from(this._toolRegistry.values()).map((t) => ({ name: t.name, description: t.description, + parameters: t.parameters, })); } diff --git a/packages/coding-agent/src/core/export-html/index.ts b/packages/coding-agent/src/core/export-html/index.ts index ca826195..a961fd78 100644 --- a/packages/coding-agent/src/core/export-html/index.ts +++ b/packages/coding-agent/src/core/export-html/index.ts @@ -3,6 +3,7 @@ import { existsSync, readFileSync, writeFileSync } from "fs"; import { basename, join } from "path"; import { APP_NAME, getExportTemplateDir } from "../../config.js"; import { getResolvedThemeColors, getThemeExportColors } from "../../modes/interactive/theme/theme.js"; +import type { ToolInfo } from "../extensions/types.js"; import type { SessionEntry } from "../session-manager.js"; import { SessionManager } from "../session-manager.js"; @@ -128,7 +129,7 @@ interface SessionData { entries: ReturnType; leafId: string | null; systemPrompt?: string; - tools?: { name: string; description: string }[]; + tools?: ToolInfo[]; /** Pre-rendered HTML for custom tool calls/results, keyed by tool call ID */ renderedTools?: Record; } @@ -253,7 +254,7 @@ export async function exportSessionToHtml( entries, leafId: sm.getLeafId(), systemPrompt: state?.systemPrompt, - tools: state?.tools?.map((t) => ({ name: t.name, description: t.description })), + tools: state?.tools?.map((t) => ({ name: t.name, description: t.description, parameters: t.parameters })), renderedTools, }; diff --git a/packages/coding-agent/src/core/export-html/template.css b/packages/coding-agent/src/core/export-html/template.css index fbcec72a..6ef5d397 100644 --- a/packages/coding-agent/src/core/export-html/template.css +++ b/packages/coding-agent/src/core/export-html/template.css @@ -663,6 +663,65 @@ color: var(--dim); } + .tool-params-hint { + color: var(--muted); + font-style: italic; + } + + .tool-item:has(.tool-params-hint) { + cursor: pointer; + } + + .tool-params-hint::after { + content: '[click to show parameters]'; + } + + .tool-item.params-expanded .tool-params-hint::after { + content: '[hide parameters]'; + } + + .tool-params-content { + display: none; + margin-top: 4px; + margin-left: 12px; + padding-left: 8px; + border-left: 1px solid var(--dim); + } + + .tool-item.params-expanded .tool-params-content { + display: block; + } + + .tool-param { + margin-bottom: 4px; + font-size: 11px; + } + + .tool-param-name { + font-weight: bold; + color: var(--text); + } + + .tool-param-type { + color: var(--dim); + font-style: italic; + } + + .tool-param-required { + color: var(--warning, #e8a838); + font-size: 10px; + } + + .tool-param-optional { + color: var(--dim); + font-size: 10px; + } + + .tool-param-desc { + color: var(--dim); + margin-left: 8px; + } + /* Hook/custom messages */ .hook-message { background: var(--customMessageBg); diff --git a/packages/coding-agent/src/core/export-html/template.js b/packages/coding-agent/src/core/export-html/template.js index 551e34f5..d97bb04d 100644 --- a/packages/coding-agent/src/core/export-html/template.js +++ b/packages/coding-agent/src/core/export-html/template.js @@ -1331,7 +1331,27 @@ html += `
Available Tools
- ${tools.map(t => `
${escapeHtml(t.name)} - ${escapeHtml(t.description)}
`).join('')} + ${tools.map(t => { + const hasParams = t.parameters && typeof t.parameters === 'object' && t.parameters.properties && Object.keys(t.parameters.properties).length > 0; + if (!hasParams) { + return `
${escapeHtml(t.name)} - ${escapeHtml(t.description)}
`; + } + const params = t.parameters; + const properties = params.properties; + const required = params.required || []; + let paramsHtml = ''; + for (const [name, prop] of Object.entries(properties)) { + const isRequired = required.includes(name); + const typeStr = prop.type || 'any'; + const reqLabel = isRequired ? 'required' : 'optional'; + paramsHtml += `
${escapeHtml(name)} ${escapeHtml(typeStr)} ${reqLabel}`; + if (prop.description) { + paramsHtml += `
${escapeHtml(prop.description)}
`; + } + paramsHtml += `
`; + } + return `
${escapeHtml(t.name)} - ${escapeHtml(t.description)}
${paramsHtml}
`; + }).join('')}
`; } diff --git a/packages/coding-agent/src/core/extensions/types.ts b/packages/coding-agent/src/core/extensions/types.ts index 855dbde0..24e07fb5 100644 --- a/packages/coding-agent/src/core/extensions/types.ts +++ b/packages/coding-agent/src/core/extensions/types.ts @@ -1159,8 +1159,8 @@ export type GetSessionNameHandler = () => string | undefined; export type GetActiveToolsHandler = () => string[]; -/** Tool info with name and description */ -export type ToolInfo = Pick; +/** Tool info with name, description, and parameter schema */ +export type ToolInfo = Pick; export type GetAllToolsHandler = () => ToolInfo[];