Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/uv/src/pi-ext-shell-tool.ts

Raw
// Generated by scripts/codegen.ts. DO NOT EDIT.
// ============================================================================
// THIS FILE IS GENERATED. DO NOT EDIT IT DIRECTLY.
// Instead, edit scripts/codegen/templates/pi-ext-shell-tool.ts.
// Then run: mise run //:codegen
// ============================================================================
import type {
	ExtensionAPI,
	ToolCallEvent,
} from "@earendil-works/pi-coding-agent";

/**
 * Type guard for shell-tool `tool_call` events (bash, powershell, nu).
 * All shell tools share one input schema: { command: string, timeout? }.
 * Classify by that schema shape via `pi.getAllTools()` so command interception
 * applies to whichever shell tool is active and degrades to a no-op when no
 * shell tool is present. Pi has no shell-tool discriminant, so shape is the only
 * name-agnostic, isolation-safe signal available.
 */
export function isShellToolCall(
	event: ToolCallEvent,
	pi: ExtensionAPI,
): event is ToolCallEvent & { input: { command: string } } {
	if (typeof (event.input as { command?: unknown }).command !== "string")
		return false;
	const info = pi.getAllTools().find((tool) => tool.name === event.toolName);
	const properties = (
		info?.parameters as { properties?: { command?: { type?: unknown } } }
	)?.properties;
	return properties?.command?.type === "string";
}