/** * Shared helpers used by every Pi tool wrapper. */ import type { AftProjectTransport, BridgeRequestOptions, ToolCallOptions, ToolCallResult } from "@cortexkit/aft-bridge"; import type { AgentToolResult, ExtensionContext, ToolDefinition } from "@earendil-works/pi-coding-agent"; import { type TSchema, Type } from "typebox"; import type { PiToolPresentation } from "../config.js"; import type { PiHarness } from "../harness.js"; import type { PluginContext } from "../types.js"; type TextContent = { type: "text"; text: string; textSignature?: string; }; type ImageContent = { type: "image"; data: string; mimeType: string; }; type ContentBlock = TextContent | ImageContent; /** * Optional integer field schema for Pi tool parameters. * * Pi validates tool arguments against this schema BEFORE our handler runs, and * some models send stringified integers like "42". A strict `Type.Integer()` * would reject those calls before `coerceOptionalInt()` can normalize them, so * keep the schema permissive at the field level while still documenting the * real integer contract for models and host UIs. */ export declare const optionalInt: (min: number, max: number, description?: string) => Type.TOptional>; export { coerceOptionalInt, formatBridgeErrorMessage, isEmptyParam, LONG_RUNNING_COMMAND_TIMEOUT_MS, prepareCanonicalPathArguments, timeoutForCommand, } from "@cortexkit/aft-bridge"; /** Attach Pi's raw-argument preparation hook to a path-bearing tool. */ export declare function withPathAliasPreparation(tool: ToolDefinition): ToolDefinition; /** * Fold `promptSnippet` and `promptGuidelines` into `description` with a fixed layout: * description, blank line, snippet, guidelines as `- ` lines. */ export declare function foldToolGuidanceIntoDescription(description: string | undefined, snippet: string | undefined, guidelines: readonly string[] | undefined): string | undefined; export type PreparedToolDefinition = ToolDefinition & { loadMode?: "essential" | "discoverable"; }; /** * Funnel helper that applies harness-specific adjustments to a ToolDefinition: * - On OMP: attaches `loadMode: "essential"` when presentation is "top_level", * and folds `promptSnippet` and `promptGuidelines` into `description`. * - On Pi (or unknown): leaves definition fields untouched (Pi renders snippet * and guidelines itself; unknown behaves as pi). */ export declare function prepareToolDefinitionForRegistration(tool: ToolDefinition, harness?: PiHarness, presentation?: PiToolPresentation): PreparedToolDefinition; /** Get the session bridge for the current working directory. */ export declare function bridgeFor(ctx: PluginContext, cwd: string): AftProjectTransport; /** * Resolve Pi's native session ID from the tool execution context so that * `/new`, `/fork`, and `/resume` each scope their own undo/checkpoint * namespace in AFT instead of sharing one extension-wide UUID. * * `sessionManager` is on every `ExtensionContext`; we read it defensively * because Pi's public type surface is still evolving and we don't want a * missing field at runtime to wedge tool execution. */ export declare function resolveSessionId(extCtx: ExtensionContext): string | undefined; /** * Error thrown by callBridge on a `success: false` response. Carries the Rust * error `code` so callers can distinguish soft negatives (e.g. symbol_not_found) * from genuine errors without re-parsing the message. */ export declare class BridgeError extends Error { readonly code: string; readonly response?: Record; constructor(message: string, code: string, response?: Record); } /** * Call a bridge command and throw a BridgeError on failure. * Every tool handler should guard with `if (response.success === false)` * before accessing success-only fields — this helper does it uniformly. * * `extCtx` is used to derive Pi's current session ID per call so Rust * scopes backups/undo per Pi session rather than per extension instance. */ export declare function callBridge(bridge: AftProjectTransport, command: string, params?: Record, extCtx?: ExtensionContext, options?: BridgeRequestOptions): Promise>; /** * Wrapper that calls a tool on the Pi agent. It supplies the session ID and * timeout, forwards warnings, gathers any follow-up data, and returns the raw * response plus the text summary the model will receive. */ export declare function callToolCall(bridge: AftProjectTransport, name: string, rawArgs?: Record, extCtx?: ExtensionContext, options?: ToolCallOptions): Promise; /** * Dispatch one bridge call with a session identity captured by the surrounding * logical tool operation. Multi-stage operations must not resolve Pi's mutable * session manager again after an await, because another active session can * become current between preflight, preview, and apply. */ export declare function callToolCallForSession(bridge: AftProjectTransport, name: string, rawArgs: Record, sessionId: string | undefined, extCtx?: ExtensionContext, options?: ToolCallOptions): Promise; /** * Build a text-only AgentToolResult. * This is the standard result shape for most AFT tools. */ export declare function textResult(text: string, details?: TDetails): AgentToolResult; /** Build an AgentToolResult that can include image content blocks. */ export declare function contentResult(content: ContentBlock[], details?: TDetails): AgentToolResult; /** * Convert a bridge response into a pretty JSON string for the model. * Strips undefined/null fields that just clutter the output. */ export declare function jsonTextResult(response: Record, details?: TDetails): AgentToolResult; /** Strip top-level success field before JSON stringifying. */ export declare function stripSuccess(response: Record): Record; //# sourceMappingURL=_shared.d.ts.map