import type { FileStat, SandboxEnv, SandboxOrphanSettlement } from "./sandbox.js"; import type { ApprovalGrant, FabricActor, JsonObject, PackagedSkillDirectory, ResultValidator, ShellResult } from "./types.js"; export interface ToolContext { sandbox: SandboxEnv; /** Stable identity of the logical call, preserved across durable retries. */ toolCallId?: string; /** Cancels provider work when the owning prompt, task, or submission is aborted. */ signal?: AbortSignal; /** Runtime observer for a command that settles after cancellation returned. */ onOrphanSettled?: (settlement: SandboxOrphanSettlement) => void | Promise; /** Present only when this logical tool operation passed an approval gate. */ approval?: ApprovalGrant; /** Authenticated actor requesting the operation, when execution crosses a server boundary. */ actor?: FabricActor; /** Authenticated tenant selected for this operation. */ tenantId?: string; /** Version or revision of the policy evaluated for this operation. */ policyVersion?: string; /** Canonical digest of the tool input, suitable for approval and evidence correlation. */ inputDigest?: string; /** Durable sub-step journal. Present only for tools declared `durable: true`. */ step?: ToolStep; /** Runtime-scoped progress logger. Progress never becomes model context. */ log?: ToolProgressLogger; /** Narrow runtime surface for hook-authored tools. */ harness?: ToolHarness; } export interface ToolStep { /** * Persist the completed JSON value under a deterministic name. Recovery * replays a recorded value instead of invoking `run` again. The callback * remains at-least-once executable across a crash before its record lands. */ do(name: string, run: () => T | Promise): Promise; } export interface ToolProgressLogger { info(message: string, data?: JsonObject): void; warn(message: string, data?: JsonObject): void; error(message: string, data?: JsonObject): void; } export interface ToolHarness { readonly sandbox: SandboxEnv; } export interface ToolCall { tool: string; input: TInput; id?: string; } export interface ToolCallResult { tool: string; input: unknown; output?: TOutput; /** Conditional tool definitions introduced at this result boundary. */ addedToolNames?: string[]; /** End the current agent turn after every call in the batch requests termination. */ terminate?: boolean; error?: string; id?: string; } export type ToolEffect = "read" | "write" | "execute" | "none"; export interface ToolDef { name: string; /** Canonical policy identity when this public name is an alias (for example `save_file` -> `write`). */ policyAlias?: string; description?: string; inputSchema?: unknown; /** Runtime output validator for hook-authored tools. */ outputSchema?: unknown; metadata?: JsonObject & { effect?: ToolEffect; }; /** Re-execute interrupted calls and replay completed `step.do()` records. */ durable?: boolean; execute?(input: TInput, context?: ToolContext): Promise | TOutput; } export type HookToolContext = { data: TInput; toolCallId: string; signal?: AbortSignal; log: ToolProgressLogger; } & (THarness extends true ? { harness: ToolHarness; } : { harness?: never; }) & (TDurable extends true ? { step: ToolStep; } : { step?: never; }); /** Hook-oriented tool declaration supported by `defineTool()` and `useTool()`. */ export interface HookToolDefinition { name: string; description?: string; input?: unknown; output?: unknown; metadata?: JsonObject & { effect?: ToolEffect; }; durable?: TDurable; harness?: THarness; run(context: HookToolContext): Promise | TOutput | { output?: TOutput; terminate?: boolean; }; } /** Internal bridge preserving the V2 hook-tool envelope through portable runtimes. */ export declare function unwrapHookToolRunResult(value: unknown): { output: unknown; terminate: boolean; }; export interface SecretRef { kind: "secret"; name: string; } export type CommandEnvValue = string | SecretRef | undefined; export interface Command { name: string; description?: string; executable?: string; args?: string[]; argsSchema?: unknown; buildArgs?: (input: TInput) => string[]; env?: Record; cwd?: string; metadata?: JsonObject; } export interface CommandToolInput { args?: string[]; cwd?: string; timeout?: number; } export interface CommandToolOptions { resolveSecret?: (ref: SecretRef) => string | undefined | Promise; /** Defaults to fail: command secrets are runtime-only and must not be silently omitted. */ onMissingSecret?: "fail"; } export interface ReadFileInput { path: string; /** 1-indexed line at which to start. */ offset?: number; /** Maximum lines to return before framework output limits. */ limit?: number; } export interface ReadFileBufferInput { path: string; } export interface WriteFileInput { path: string; content: string | Uint8Array; } export interface StatInput { path: string; } export interface ReaddirInput { path: string; } export interface ExistsInput { path: string; } export interface MkdirInput { path: string; recursive?: boolean; } export interface RmInput { path: string; recursive?: boolean; force?: boolean; } export interface EditInput { path: string; oldText: string; newText: string; replaceAll?: boolean; } export interface BashInput { command: string; cwd?: string; env?: Record; timeout?: number; } export interface GrepInput { pattern: string; path?: string; include?: string; ignoreCase?: boolean; literal?: boolean; maxMatches?: number; } export interface GrepMatch { path: string; line: number; text: string; } export interface GlobInput { pattern: string; cwd?: string; maxMatches?: number; } export interface ActivateSkillInput { name: string; } /** Public built-in tool limits; documentation and tests consume these constants. */ export declare const BUILTIN_READ_MAX_LINES = 2000; export declare const BUILTIN_READ_MAX_BYTES: number; export declare const BUILTIN_BASH_MAX_LINES = 2000; export declare const BUILTIN_BASH_MAX_BYTES: number; export declare const BUILTIN_GREP_MAX_MATCHES = 100; export declare const BUILTIN_GREP_MAX_LINE_LENGTH = 500; export declare const BUILTIN_GLOB_MAX_RESULTS = 1000; export declare function secret(name: string): SecretRef; export declare function defineCommand(name: string, options?: Omit, "name">): Command; export declare function defineTool(tool: ToolDef): ToolDef; export declare function defineTool(tool: HookToolDefinition): ToolDef; export type BuiltinTool = ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef | ToolDef; export type BuiltinFileTool = Exclude | ToolDef | ToolDef>; export declare function createCommandTools(commands: Command[], options?: CommandToolOptions): ToolDef[]; export declare function createBuiltinTools(sandbox: SandboxEnv, packagedSkills?: Record): BuiltinTool[]; export declare function createFileTools(sandbox: SandboxEnv, packagedSkills?: Record): BuiltinFileTool[]; export declare function readFileTool(sandbox?: SandboxEnv, packagedSkills?: Record): ToolDef; export declare function readFileBufferTool(sandbox?: SandboxEnv): ToolDef; export declare function writeFileTool(sandbox?: SandboxEnv): ToolDef; export declare function editFileTool(sandbox?: SandboxEnv): ToolDef; export declare function statTool(sandbox?: SandboxEnv): ToolDef; export declare function readdirTool(sandbox?: SandboxEnv): ToolDef; export declare function existsTool(sandbox?: SandboxEnv): ToolDef; export declare function mkdirTool(sandbox?: SandboxEnv): ToolDef; export declare function rmTool(sandbox?: SandboxEnv): ToolDef; export declare function bashTool(sandbox?: SandboxEnv): ToolDef; export declare function grepTool(sandbox?: SandboxEnv): ToolDef; export declare function globTool(sandbox?: SandboxEnv): ToolDef; export declare function createActivateSkillTool(skillNames: string[], activate: (name: string) => Promise): ToolDef; export type ResultOutcome = { type: "pending"; } | { type: "finished"; value: TResult; } | { type: "gave_up"; reason: string; }; export interface ResultToolBundle { tools: ToolDef[]; getOutcome(): ResultOutcome; } /** * Produce the per-call `finish` and `give_up` tool pair for a given ResultValidator. * * - `finish`'s parameters are a generic JSON Schema object because we can't derive * a precise schema from `ResultValidator`. The validator's `safeParse` handles * actual validation. * - First successful `finish` (or `give_up`) call wins. Subsequent calls return * an error tool result rather than throwing, to keep the conversation transcript * natural. */ export declare function createResultTools(validator: ResultValidator): ResultToolBundle; export declare function shellQuote(value: string): string; //# sourceMappingURL=tools.d.ts.map