import type { AgentTelemetryConfig, AgentTool } from "@oh-my-pi/pi-agent-core"; import type { ToolChoice } from "@oh-my-pi/pi-ai"; import type { PromptTemplate } from "../config/prompt-templates"; import type { Settings } from "../config/settings"; import type { Skill } from "../extensibility/skills"; import type { GoalModeState, GoalRuntime } from "../goals"; import type { HindsightSessionState } from "../hindsight/state"; import type { PlanModeState } from "../plan-mode/state"; import { type AgentRegistry } from "../registry/agent-registry"; import type { ArtifactManager } from "../session/artifacts"; import type { ClientBridge } from "../session/client-bridge"; import type { CustomMessage } from "../session/messages"; import type { ToolChoiceQueue } from "../session/tool-choice-queue"; import type { AgentOutputManager } from "../task/output-manager"; import type { DiscoverableTool, DiscoverableToolSearchIndex } from "../tool-discovery/tool-index"; import type { EventBus } from "../utils/event-bus"; import type { WorkspaceTree } from "../workspace-tree"; import { type CheckpointState } from "./checkpoint"; import { type TodoPhase } from "./todo-write"; export * from "../edit"; export * from "../exa"; export type * from "../exa/types"; export * from "../goals"; export * from "../lsp"; export * from "../session/streaming-output"; export * from "../task"; export * from "../web/search"; export * from "./ask"; export * from "./ast-edit"; export * from "./ast-grep"; export * from "./bash"; export * from "./browser"; export * from "./calculator"; export * from "./checkpoint"; export * from "./debug"; export * from "./eval"; export * from "./find"; export * from "./gh"; export * from "./hindsight-recall"; export * from "./hindsight-reflect"; export * from "./hindsight-retain"; export * from "./image-gen"; export * from "./inspect-image"; export * from "./irc"; export * from "./job"; export * from "./read"; export * from "./recipe"; export * from "./render-mermaid"; export * from "./report-tool-issue"; export * from "./resolve"; export * from "./review"; export * from "./search"; export * from "./search-tool-bm25"; export * from "./ssh"; export * from "./todo-write"; export * from "./vim"; export * from "./write"; export * from "./yield"; /** Tool type (AgentTool from pi-ai) */ export type Tool = AgentTool; export type ContextFileEntry = { path: string; content: string; depth?: number; }; export type { DiscoverableMCPTool } from "../mcp/discoverable-tool-metadata"; export type { DiscoverableTool, DiscoverableToolSearchIndex, DiscoverableToolSearchResult, DiscoverableToolSource, } from "../tool-discovery/tool-index"; /** Session context for tool factories */ export interface ToolSession { /** Current working directory */ cwd: string; /** Whether UI is available */ hasUI: boolean; /** Skip Python kernel availability check and warmup */ skipPythonPreflight?: boolean; /** Pre-loaded context files (AGENTS.md, etc) */ contextFiles?: ContextFileEntry[]; /** Pre-loaded workspace tree (forwarded to subagents to skip re-scanning) */ workspaceTree?: WorkspaceTree; /** Pre-loaded skills */ skills?: Skill[]; /** Pre-loaded prompt templates */ promptTemplates?: PromptTemplate[]; /** Whether LSP integrations are enabled */ enableLsp?: boolean; /** Whether an edit-capable tool is available in this session (controls hashline output) */ hasEditTool?: boolean; /** Event bus for tool/extension communication */ eventBus?: EventBus; /** Output schema for structured completion (subagents) */ outputSchema?: unknown; /** Whether to include the yield tool by default */ requireYieldTool?: boolean; /** Task recursion depth (0 = top-level, 1 = first child, etc.) */ taskDepth?: number; /** Get session file */ getSessionFile: () => string | null; /** Get eval kernel owner ID for session-scoped retained-kernel cleanup. */ getEvalKernelOwnerId?: () => string | null; /** Reject new eval (python or js) work once session disposal has started. */ assertEvalExecutionAllowed?: () => void; /** Track tool-owned eval work so session disposal can await/abort it like direct session eval runs. */ trackEvalExecution?(execution: Promise, abortController: AbortController): Promise; /** Get session ID */ getSessionId?: () => string | null; /** Get Hindsight runtime state for this agent session. */ getHindsightSessionState?: () => HindsightSessionState | undefined; /** Agent identity used for IRC routing. Returns the registry id (e.g. "0-Main", "0-AuthLoader"). */ getAgentId?: () => string | null; /** Look up a registered tool by name (used by the eval js backend's tool bridge). */ getToolByName?: (name: string) => AgentTool | undefined; /** Agent registry for IRC routing across live sessions. */ agentRegistry?: AgentRegistry; /** Get artifacts directory for artifact:// URLs */ getArtifactsDir?: () => string | null; /** Get the ArtifactManager backing this session (shared across parent + subagents). */ getArtifactManager?: () => ArtifactManager | null; /** Allocate a new artifact path and ID for session-scoped truncated output. */ allocateOutputArtifact?: (toolType: string) => Promise<{ id?: string; path?: string; }>; /** Get session spawns */ getSessionSpawns: () => string | null; /** Get resolved model string if explicitly set for this session */ getModelString?: () => string | undefined; /** Get the current session model string, regardless of how it was chosen */ getActiveModelString?: () => string | undefined; /** Auth storage for passing to subagents (avoids re-discovery) */ authStorage?: import("../session/auth-storage").AuthStorage; /** Model registry for passing to subagents (avoids re-discovery) */ modelRegistry?: import("../config/model-registry").ModelRegistry; /** Agent output manager for unique agent:// IDs across task invocations */ agentOutputManager?: AgentOutputManager; /** Settings instance for passing to subagents */ settings: Settings; /** Plan mode state (if active) */ getPlanModeState?: () => PlanModeState | undefined; /** Goal mode state (if active or paused) */ getGoalModeState?: () => GoalModeState | undefined; /** Goal runtime for the active agent session. */ getGoalRuntime?: () => GoalRuntime | undefined; /** Bridge to the connected client (e.g. ACP editor host). Tools should route fs/terminal/permission requests through this when available. */ getClientBridge?: () => ClientBridge | undefined; /** Get compact conversation context for subagents (excludes tool results, system prompts) */ getCompactContext?: () => string; /** Get cached todo phases for this session. */ getTodoPhases?: () => TodoPhase[]; /** Replace cached todo phases for this session. */ setTodoPhases?: (phases: TodoPhase[]) => void; /** Whether MCP tool discovery is active for this session. */ isMCPDiscoveryEnabled?: () => boolean; /** Get hidden-but-discoverable MCP tools for search_tool_bm25 prompts and fallbacks. * @deprecated Use getDiscoverableTools with source filter instead. */ getDiscoverableMCPTools?: () => import("../mcp/discoverable-tool-metadata").DiscoverableMCPTool[]; /** Get the cached discoverable MCP search index for search_tool_bm25 execution. * @deprecated Use getDiscoverableToolSearchIndex instead. */ getDiscoverableMCPSearchIndex?: () => import("../tool-discovery/tool-index").DiscoverableMCPSearchIndex; /** Get MCP tools activated by prior search_tool_bm25 calls. */ getSelectedMCPToolNames?: () => string[]; /** Merge MCP tool selections into the active session tool set. */ activateDiscoveredMCPTools?: (toolNames: string[]) => Promise; /** Whether any form of tool discovery is active (tools.discoveryMode !== "off" or mcp.discoveryMode). */ isToolDiscoveryEnabled?: () => boolean; /** Get all hidden-but-discoverable tools for search_tool_bm25 prompts. */ getDiscoverableTools?: (filter?: { source?: import("../tool-discovery/tool-index").DiscoverableToolSource; }) => DiscoverableTool[]; /** Get the cached generic discoverable search index. */ getDiscoverableToolSearchIndex?: () => DiscoverableToolSearchIndex; /** Get tool names activated by prior search_tool_bm25 calls (all sources). */ getSelectedDiscoveredToolNames?: () => string[]; /** Merge tool selections into the active session tool set. */ activateDiscoveredTools?: (toolNames: string[]) => Promise; /** The tool-choice queue used to force forthcoming tool invocations and carry invocation handlers. */ getToolChoiceQueue?(): ToolChoiceQueue; /** Build a model-provider-specific ToolChoice that targets the named tool, or undefined if unsupported. */ buildToolChoice?(toolName: string): ToolChoice | undefined; /** Steer a hidden custom message into the conversation (e.g. a preview reminder). */ steer?(message: { customType: string; content: string; details?: unknown; }): void; /** Peek the currently in-flight tool-choice queue directive's invocation handler. Used by the `resolve` tool to dispatch to the pending action. */ peekQueueInvoker?(): ((input: unknown) => Promise | unknown) | undefined; /** Peek the long-lived "standing" resolve handler registered by a mode (e.g. plan mode). * Consulted by the `resolve` tool as a fallback when no queue invoker is in flight, * letting modes accept `resolve` invocations without forcing the tool choice every turn. */ peekStandingResolveHandler?(): ((input: unknown) => Promise | unknown) | undefined; /** Register or clear the standing resolve handler. Passing `null` clears it. */ setStandingResolveHandler?(handler: ((input: unknown) => Promise | unknown) | null): void; /** Get active checkpoint state if any. */ getCheckpointState?: () => CheckpointState | undefined; /** Set or clear active checkpoint state. */ setCheckpointState?: (state: CheckpointState | null) => void; /** Per-session cache of file contents as last shown to the model by * `read`/`search`. Used by hashline anchor-stale recovery to reconstruct * the version the model authored anchors against when the file changed * out-of-band. Lazily initialized by `getFileReadCache`. */ fileReadCache?: import("../edit/file-read-cache").FileReadCache; /** Per-session log of unresolved git merge conflict regions surfaced by * `read`. Each entry gets a stable id N referenced by `write conflict://N` * to splice the recorded region with replacement content. Lazily initialized * by `getConflictHistory`. */ conflictHistory?: import("./conflict-detect").ConflictHistory; /** Queue a hidden message to be injected at the next agent turn. */ queueDeferredMessage?(message: CustomMessage): void; /** Get the active OpenTelemetry config so subagent dispatch can forward * the parent's tracer/hooks with the subagent's own identity stamped. */ getTelemetry?: () => AgentTelemetryConfig | undefined; } export type ToolFactory = (session: ToolSession) => Tool | null | Promise; export type BuiltinToolLoadMode = "essential" | "discoverable"; /** Default essential tool names when tools.essentialOverride is empty. */ export declare const DEFAULT_ESSENTIAL_TOOL_NAMES: readonly string[]; /** * Resolve the active essential built-in tool names from settings. * Returns `tools.essentialOverride` if non-empty (filtered to known built-ins), * otherwise `DEFAULT_ESSENTIAL_TOOL_NAMES`. */ export declare function computeEssentialBuiltinNames(settings: Settings): string[]; /** * Public callable factory map. External callers may invoke `BUILTIN_TOOLS.read(session)` or * `BUILTIN_TOOLS[name](session)` to construct a tool directly. */ export declare const BUILTIN_TOOLS: Record; export declare const HIDDEN_TOOLS: Record; export type ToolName = keyof typeof BUILTIN_TOOLS; export interface EvalBackendsAllowance { python: boolean; js: boolean; } /** Read per-backend allowance from settings (defaults true). */ export declare function readEvalBackendsAllowance(session: ToolSession): EvalBackendsAllowance; /** * Materialize the active eval backend allowance: PI_PY / PI_JS env flags * override the per-key settings; otherwise settings (defaults true) win. */ export declare function resolveEvalBackends(session: ToolSession): EvalBackendsAllowance; /** * Create tools from BUILTIN_TOOLS registry. */ export declare function createTools(session: ToolSession, toolNames?: string[]): Promise;