fix(coding-agent): built-in tools work like extension tools
Export readToolDefinition / createReadToolDefinition and the equivalent built-in ToolDefinition APIs from @mariozechner/pi-coding-agent.
This commit is contained in:
@@ -42,7 +42,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return originalRead.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("read "));
|
||||
text += theme.fg("accent", args.path);
|
||||
if (args.offset || args.limit) {
|
||||
@@ -54,7 +54,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded, isPartial }, theme) {
|
||||
renderResult(result, { expanded, isPartial }, theme, _context) {
|
||||
if (isPartial) return new Text(theme.fg("warning", "Reading..."), 0, 0);
|
||||
|
||||
const details = result.details as ReadToolDetails | undefined;
|
||||
@@ -101,7 +101,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return originalBash.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("$ "));
|
||||
const cmd = args.command.length > 80 ? `${args.command.slice(0, 77)}...` : args.command;
|
||||
text += theme.fg("accent", cmd);
|
||||
@@ -111,7 +111,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded, isPartial }, theme) {
|
||||
renderResult(result, { expanded, isPartial }, theme, _context) {
|
||||
if (isPartial) return new Text(theme.fg("warning", "Running..."), 0, 0);
|
||||
|
||||
const details = result.details as BashToolDetails | undefined;
|
||||
@@ -160,13 +160,13 @@ export default function (pi: ExtensionAPI) {
|
||||
return originalEdit.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("edit "));
|
||||
text += theme.fg("accent", args.path);
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded, isPartial }, theme) {
|
||||
renderResult(result, { expanded, isPartial }, theme, _context) {
|
||||
if (isPartial) return new Text(theme.fg("warning", "Editing..."), 0, 0);
|
||||
|
||||
const details = result.details as EditToolDetails | undefined;
|
||||
@@ -224,7 +224,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return originalWrite.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("write "));
|
||||
text += theme.fg("accent", args.path);
|
||||
const lineCount = args.content.split("\n").length;
|
||||
@@ -232,7 +232,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { isPartial }, theme) {
|
||||
renderResult(result, { isPartial }, theme, _context) {
|
||||
if (isPartial) return new Text(theme.fg("warning", "Writing..."), 0, 0);
|
||||
|
||||
const content = result.content[0];
|
||||
|
||||
@@ -80,7 +80,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.read.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const path = shortenPath(args.path || "");
|
||||
let pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
||||
|
||||
@@ -94,7 +94,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(`${theme.fg("toolTitle", theme.bold("read"))} ${pathDisplay}`, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
// Minimal mode: show nothing in collapsed state
|
||||
if (!expanded) {
|
||||
return new Text("", 0, 0);
|
||||
@@ -127,7 +127,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.bash.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const command = args.command || "...";
|
||||
const timeout = args.timeout as number | undefined;
|
||||
const timeoutSuffix = timeout ? theme.fg("muted", ` (timeout ${timeout}s)`) : "";
|
||||
@@ -135,7 +135,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(theme.fg("toolTitle", theme.bold(`$ ${command}`)) + timeoutSuffix, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
// Minimal mode: show nothing in collapsed state
|
||||
if (!expanded) {
|
||||
return new Text("", 0, 0);
|
||||
@@ -176,7 +176,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.write.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const path = shortenPath(args.path || "");
|
||||
const pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
||||
const lineCount = args.content ? args.content.split("\n").length : 0;
|
||||
@@ -185,7 +185,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(`${theme.fg("toolTitle", theme.bold("write"))} ${pathDisplay}${lineInfo}`, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
// Minimal mode: show nothing (file was written)
|
||||
if (!expanded) {
|
||||
return new Text("", 0, 0);
|
||||
@@ -218,14 +218,14 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.edit.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const path = shortenPath(args.path || "");
|
||||
const pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
||||
|
||||
return new Text(`${theme.fg("toolTitle", theme.bold("edit"))} ${pathDisplay}`, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
// Minimal mode: show nothing in collapsed state
|
||||
if (!expanded) {
|
||||
return new Text("", 0, 0);
|
||||
@@ -263,7 +263,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.find.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const pattern = args.pattern || "";
|
||||
const path = shortenPath(args.path || ".");
|
||||
const limit = args.limit;
|
||||
@@ -277,7 +277,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
if (!expanded) {
|
||||
// Minimal: just show count
|
||||
const textContent = result.content.find((c) => c.type === "text");
|
||||
@@ -321,7 +321,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.grep.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const pattern = args.pattern || "";
|
||||
const path = shortenPath(args.path || ".");
|
||||
const glob = args.glob;
|
||||
@@ -339,7 +339,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
if (!expanded) {
|
||||
// Minimal: just show match count
|
||||
const textContent = result.content.find((c) => c.type === "text");
|
||||
@@ -383,7 +383,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return tools.ls.execute(toolCallId, params, signal, onUpdate);
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const path = shortenPath(args.path || ".");
|
||||
const limit = args.limit;
|
||||
|
||||
@@ -395,7 +395,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
if (!expanded) {
|
||||
// Minimal: just show entry count
|
||||
const textContent = result.content.find((c) => c.type === "text");
|
||||
|
||||
@@ -227,7 +227,7 @@ export default function question(pi: ExtensionAPI) {
|
||||
};
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("question ")) + theme.fg("muted", args.question);
|
||||
const opts = Array.isArray(args.options) ? args.options : [];
|
||||
if (opts.length) {
|
||||
@@ -238,7 +238,7 @@ export default function question(pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, _options, theme) {
|
||||
renderResult(result, _options, theme, _context) {
|
||||
const details = result.details as QuestionDetails | undefined;
|
||||
if (!details) {
|
||||
const text = result.content[0];
|
||||
|
||||
@@ -393,7 +393,7 @@ export default function questionnaire(pi: ExtensionAPI) {
|
||||
};
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const qs = (args.questions as Question[]) || [];
|
||||
const count = qs.length;
|
||||
const labels = qs.map((q) => q.label || q.id).join(", ");
|
||||
@@ -405,7 +405,7 @@ export default function questionnaire(pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, _options, theme) {
|
||||
renderResult(result, _options, theme, _context) {
|
||||
const details = result.details as QuestionnaireResult | undefined;
|
||||
if (!details) {
|
||||
const text = result.content[0];
|
||||
|
||||
@@ -668,7 +668,7 @@ export default function (pi: ExtensionAPI) {
|
||||
};
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
const scope: AgentScope = args.agentScope ?? "user";
|
||||
if (args.chain && args.chain.length > 0) {
|
||||
let text =
|
||||
@@ -712,7 +712,7 @@ export default function (pi: ExtensionAPI) {
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
const details = result.details as SubagentDetails | undefined;
|
||||
if (!details || details.results.length === 0) {
|
||||
const text = result.content[0];
|
||||
|
||||
@@ -220,14 +220,14 @@ export default function (pi: ExtensionAPI) {
|
||||
}
|
||||
},
|
||||
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("todo ")) + theme.fg("muted", args.action);
|
||||
if (args.text) text += ` ${theme.fg("dim", `"${args.text}"`)}`;
|
||||
if (args.id !== undefined) text += ` ${theme.fg("accent", `#${args.id}`)}`;
|
||||
return new Text(text, 0, 0);
|
||||
},
|
||||
|
||||
renderResult(result, { expanded }, theme) {
|
||||
renderResult(result, { expanded }, theme, _context) {
|
||||
const details = result.details as TodoDetails | undefined;
|
||||
if (!details) {
|
||||
const text = result.content[0];
|
||||
|
||||
@@ -135,7 +135,7 @@ export default function (pi: ExtensionAPI) {
|
||||
},
|
||||
|
||||
// Custom rendering of the tool call (shown before/during execution)
|
||||
renderCall(args, theme) {
|
||||
renderCall(args, theme, _context) {
|
||||
let text = theme.fg("toolTitle", theme.bold("rg "));
|
||||
text += theme.fg("accent", `"${args.pattern}"`);
|
||||
if (args.path) {
|
||||
@@ -148,7 +148,7 @@ export default function (pi: ExtensionAPI) {
|
||||
},
|
||||
|
||||
// Custom rendering of the tool result
|
||||
renderResult(result, { expanded, isPartial }, theme) {
|
||||
renderResult(result, { expanded, isPartial }, theme, _context) {
|
||||
const details = result.details as RgDetails | undefined;
|
||||
|
||||
// Handle streaming/partial results
|
||||
|
||||
Reference in New Issue
Block a user