mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 22:04:46 +00:00
feat(coding-agent): type ToolCallEvent.input per tool (#1147)
This commit is contained in:
commit
ce607fc343
13 changed files with 219 additions and 19 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Added typed `ToolCallEvent.input` per tool with `isToolCallEventType()` type guard for narrowing built-in tool events ([#1147](https://github.com/badlogic/pi-mono/pull/1147) by [@giuseppeg](https://github.com/giuseppeg))
|
||||||
- Exported `discoverAndLoadExtensions` from package to enable extension testing without a local repo clone ([#1148](https://github.com/badlogic/pi-mono/issues/1148))
|
- Exported `discoverAndLoadExtensions` from package to enable extension testing without a local repo clone ([#1148](https://github.com/badlogic/pi-mono/issues/1148))
|
||||||
- Added Extension UI Protocol documentation to RPC docs covering all request/response types for extension dialogs and notifications ([#1144](https://github.com/badlogic/pi-mono/pull/1144) by [@aliou](https://github.com/aliou))
|
- Added Extension UI Protocol documentation to RPC docs covering all request/response types for extension dialogs and notifications ([#1144](https://github.com/badlogic/pi-mono/pull/1144) by [@aliou](https://github.com/aliou))
|
||||||
- Added `rpc-demo.ts` example extension exercising all RPC-supported extension UI methods ([#1144](https://github.com/badlogic/pi-mono/pull/1144) by [@aliou](https://github.com/aliou))
|
- Added `rpc-demo.ts` example extension exercising all RPC-supported extension UI methods ([#1144](https://github.com/badlogic/pi-mono/pull/1144) by [@aliou](https://github.com/aliou))
|
||||||
|
|
|
||||||
|
|
@ -473,16 +473,49 @@ Use this to update UI elements (status bars, footers) or perform model-specific
|
||||||
|
|
||||||
#### tool_call
|
#### tool_call
|
||||||
|
|
||||||
Fired before tool executes. **Can block.**
|
Fired before tool executes. **Can block.** Use `isToolCallEventType` to narrow and get typed inputs.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
import { isToolCallEventType } from "@mariozechner/pi-coding-agent";
|
||||||
|
|
||||||
pi.on("tool_call", async (event, ctx) => {
|
pi.on("tool_call", async (event, ctx) => {
|
||||||
// event.toolName - "bash", "read", "write", "edit", etc.
|
// event.toolName - "bash", "read", "write", "edit", etc.
|
||||||
// event.toolCallId
|
// event.toolCallId
|
||||||
// event.input - tool parameters
|
// event.input - tool parameters
|
||||||
|
|
||||||
if (shouldBlock(event)) {
|
// Built-in tools: no type params needed
|
||||||
return { block: true, reason: "Not allowed" };
|
if (isToolCallEventType("bash", event)) {
|
||||||
|
// event.input is { command: string; timeout?: number }
|
||||||
|
if (event.input.command.includes("rm -rf")) {
|
||||||
|
return { block: true, reason: "Dangerous command" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isToolCallEventType("read", event)) {
|
||||||
|
// event.input is { path: string; offset?: number; limit?: number }
|
||||||
|
console.log(`Reading: ${event.input.path}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Typing custom tool input
|
||||||
|
|
||||||
|
Custom tools should export their input type:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// my-extension.ts
|
||||||
|
export type MyToolInput = Static<typeof myToolSchema>;
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `isToolCallEventType` with explicit type parameters:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { isToolCallEventType } from "@mariozechner/pi-coding-agent";
|
||||||
|
import type { MyToolInput } from "my-extension";
|
||||||
|
|
||||||
|
pi.on("tool_call", (event) => {
|
||||||
|
if (isToolCallEventType<"my_tool", MyToolInput>("my_tool", event)) {
|
||||||
|
event.input.action; // typed
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ export type {
|
||||||
// App keybindings (for custom editors)
|
// App keybindings (for custom editors)
|
||||||
AppAction,
|
AppAction,
|
||||||
AppendEntryHandler,
|
AppendEntryHandler,
|
||||||
|
// Events - Tool (ToolCallEvent types)
|
||||||
|
BashToolCallEvent,
|
||||||
BashToolResultEvent,
|
BashToolResultEvent,
|
||||||
BeforeAgentStartEvent,
|
BeforeAgentStartEvent,
|
||||||
BeforeAgentStartEventResult,
|
BeforeAgentStartEventResult,
|
||||||
|
|
@ -35,7 +37,9 @@ export type {
|
||||||
// Event Results
|
// Event Results
|
||||||
ContextEventResult,
|
ContextEventResult,
|
||||||
ContextUsage,
|
ContextUsage,
|
||||||
|
CustomToolCallEvent,
|
||||||
CustomToolResultEvent,
|
CustomToolResultEvent,
|
||||||
|
EditToolCallEvent,
|
||||||
EditToolResultEvent,
|
EditToolResultEvent,
|
||||||
ExecOptions,
|
ExecOptions,
|
||||||
ExecResult,
|
ExecResult,
|
||||||
|
|
@ -59,10 +63,12 @@ export type {
|
||||||
ExtensionUIContext,
|
ExtensionUIContext,
|
||||||
ExtensionUIDialogOptions,
|
ExtensionUIDialogOptions,
|
||||||
ExtensionWidgetOptions,
|
ExtensionWidgetOptions,
|
||||||
|
FindToolCallEvent,
|
||||||
FindToolResultEvent,
|
FindToolResultEvent,
|
||||||
GetActiveToolsHandler,
|
GetActiveToolsHandler,
|
||||||
GetAllToolsHandler,
|
GetAllToolsHandler,
|
||||||
GetThinkingLevelHandler,
|
GetThinkingLevelHandler,
|
||||||
|
GrepToolCallEvent,
|
||||||
GrepToolResultEvent,
|
GrepToolResultEvent,
|
||||||
// Events - Input
|
// Events - Input
|
||||||
InputEvent,
|
InputEvent,
|
||||||
|
|
@ -70,6 +76,7 @@ export type {
|
||||||
InputSource,
|
InputSource,
|
||||||
KeybindingsManager,
|
KeybindingsManager,
|
||||||
LoadExtensionsResult,
|
LoadExtensionsResult,
|
||||||
|
LsToolCallEvent,
|
||||||
LsToolResultEvent,
|
LsToolResultEvent,
|
||||||
// Message Rendering
|
// Message Rendering
|
||||||
MessageRenderer,
|
MessageRenderer,
|
||||||
|
|
@ -79,6 +86,7 @@ export type {
|
||||||
// Provider Registration
|
// Provider Registration
|
||||||
ProviderConfig,
|
ProviderConfig,
|
||||||
ProviderModelConfig,
|
ProviderModelConfig,
|
||||||
|
ReadToolCallEvent,
|
||||||
ReadToolResultEvent,
|
ReadToolResultEvent,
|
||||||
// Commands
|
// Commands
|
||||||
RegisteredCommand,
|
RegisteredCommand,
|
||||||
|
|
@ -124,6 +132,7 @@ export type {
|
||||||
UserBashEvent,
|
UserBashEvent,
|
||||||
UserBashEventResult,
|
UserBashEventResult,
|
||||||
WidgetPlacement,
|
WidgetPlacement,
|
||||||
|
WriteToolCallEvent,
|
||||||
WriteToolResultEvent,
|
WriteToolResultEvent,
|
||||||
} from "./types.js";
|
} from "./types.js";
|
||||||
// Type guards
|
// Type guards
|
||||||
|
|
@ -134,6 +143,7 @@ export {
|
||||||
isGrepToolResult,
|
isGrepToolResult,
|
||||||
isLsToolResult,
|
isLsToolResult,
|
||||||
isReadToolResult,
|
isReadToolResult,
|
||||||
|
isToolCallEventType,
|
||||||
isWriteToolResult,
|
isWriteToolResult,
|
||||||
} from "./types.js";
|
} from "./types.js";
|
||||||
export {
|
export {
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,17 @@ import type { BashOperations } from "../tools/bash.js";
|
||||||
import type { EditToolDetails } from "../tools/edit.js";
|
import type { EditToolDetails } from "../tools/edit.js";
|
||||||
import type {
|
import type {
|
||||||
BashToolDetails,
|
BashToolDetails,
|
||||||
|
BashToolInput,
|
||||||
|
EditToolInput,
|
||||||
FindToolDetails,
|
FindToolDetails,
|
||||||
|
FindToolInput,
|
||||||
GrepToolDetails,
|
GrepToolDetails,
|
||||||
|
GrepToolInput,
|
||||||
LsToolDetails,
|
LsToolDetails,
|
||||||
|
LsToolInput,
|
||||||
ReadToolDetails,
|
ReadToolDetails,
|
||||||
|
ReadToolInput,
|
||||||
|
WriteToolInput,
|
||||||
} from "../tools/index.js";
|
} from "../tools/index.js";
|
||||||
|
|
||||||
export type { ExecOptions, ExecResult } from "../exec.js";
|
export type { ExecOptions, ExecResult } from "../exec.js";
|
||||||
|
|
@ -547,14 +554,62 @@ export type InputEventResult =
|
||||||
// Tool Events
|
// Tool Events
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
/** Fired before a tool executes. Can block. */
|
interface ToolCallEventBase {
|
||||||
export interface ToolCallEvent {
|
|
||||||
type: "tool_call";
|
type: "tool_call";
|
||||||
toolName: string;
|
|
||||||
toolCallId: string;
|
toolCallId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BashToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "bash";
|
||||||
|
input: BashToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReadToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "read";
|
||||||
|
input: ReadToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EditToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "edit";
|
||||||
|
input: EditToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WriteToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "write";
|
||||||
|
input: WriteToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GrepToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "grep";
|
||||||
|
input: GrepToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FindToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "find";
|
||||||
|
input: FindToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LsToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: "ls";
|
||||||
|
input: LsToolInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CustomToolCallEvent extends ToolCallEventBase {
|
||||||
|
toolName: string;
|
||||||
input: Record<string, unknown>;
|
input: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fired before a tool executes. Can block. */
|
||||||
|
export type ToolCallEvent =
|
||||||
|
| BashToolCallEvent
|
||||||
|
| ReadToolCallEvent
|
||||||
|
| EditToolCallEvent
|
||||||
|
| WriteToolCallEvent
|
||||||
|
| GrepToolCallEvent
|
||||||
|
| FindToolCallEvent
|
||||||
|
| LsToolCallEvent
|
||||||
|
| CustomToolCallEvent;
|
||||||
|
|
||||||
interface ToolResultEventBase {
|
interface ToolResultEventBase {
|
||||||
type: "tool_result";
|
type: "tool_result";
|
||||||
toolCallId: string;
|
toolCallId: string;
|
||||||
|
|
@ -614,7 +669,7 @@ export type ToolResultEvent =
|
||||||
| LsToolResultEvent
|
| LsToolResultEvent
|
||||||
| CustomToolResultEvent;
|
| CustomToolResultEvent;
|
||||||
|
|
||||||
// Type guards
|
// Type guards for ToolResultEvent
|
||||||
export function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {
|
export function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {
|
||||||
return e.toolName === "bash";
|
return e.toolName === "bash";
|
||||||
}
|
}
|
||||||
|
|
@ -637,6 +692,41 @@ export function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent {
|
||||||
return e.toolName === "ls";
|
return e.toolName === "ls";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type guard for narrowing ToolCallEvent by tool name.
|
||||||
|
*
|
||||||
|
* Built-in tools narrow automatically (no type params needed):
|
||||||
|
* ```ts
|
||||||
|
* if (isToolCallEventType("bash", event)) {
|
||||||
|
* event.input.command; // string
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Custom tools require explicit type parameters:
|
||||||
|
* ```ts
|
||||||
|
* if (isToolCallEventType<"my_tool", MyToolInput>("my_tool", event)) {
|
||||||
|
* event.input.action; // typed
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Note: Direct narrowing via `event.toolName === "bash"` doesn't work because
|
||||||
|
* CustomToolCallEvent.toolName is `string` which overlaps with all literals.
|
||||||
|
*/
|
||||||
|
export function isToolCallEventType(toolName: "bash", event: ToolCallEvent): event is BashToolCallEvent;
|
||||||
|
export function isToolCallEventType(toolName: "read", event: ToolCallEvent): event is ReadToolCallEvent;
|
||||||
|
export function isToolCallEventType(toolName: "edit", event: ToolCallEvent): event is EditToolCallEvent;
|
||||||
|
export function isToolCallEventType(toolName: "write", event: ToolCallEvent): event is WriteToolCallEvent;
|
||||||
|
export function isToolCallEventType(toolName: "grep", event: ToolCallEvent): event is GrepToolCallEvent;
|
||||||
|
export function isToolCallEventType(toolName: "find", event: ToolCallEvent): event is FindToolCallEvent;
|
||||||
|
export function isToolCallEventType(toolName: "ls", event: ToolCallEvent): event is LsToolCallEvent;
|
||||||
|
export function isToolCallEventType<TName extends string, TInput extends Record<string, unknown>>(
|
||||||
|
toolName: TName,
|
||||||
|
event: ToolCallEvent,
|
||||||
|
): event is ToolCallEvent & { toolName: TName; input: TInput };
|
||||||
|
export function isToolCallEventType(toolName: string, event: ToolCallEvent): boolean {
|
||||||
|
return event.toolName === toolName;
|
||||||
|
}
|
||||||
|
|
||||||
/** Union of all event types */
|
/** Union of all event types */
|
||||||
export type ExtensionEvent =
|
export type ExtensionEvent =
|
||||||
| ResourcesDiscoverEvent
|
| ResourcesDiscoverEvent
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { createWriteStream, existsSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import { getShellConfig, getShellEnv, killProcessTree } from "../../utils/shell.js";
|
import { getShellConfig, getShellEnv, killProcessTree } from "../../utils/shell.js";
|
||||||
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from "./truncate.js";
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateTail } from "./truncate.js";
|
||||||
|
|
@ -21,6 +21,8 @@ const bashSchema = Type.Object({
|
||||||
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type BashToolInput = Static<typeof bashSchema>;
|
||||||
|
|
||||||
export interface BashToolDetails {
|
export interface BashToolDetails {
|
||||||
truncation?: TruncationResult;
|
truncation?: TruncationResult;
|
||||||
fullOutputPath?: string;
|
fullOutputPath?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { constants } from "fs";
|
import { constants } from "fs";
|
||||||
import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
|
import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
|
||||||
import {
|
import {
|
||||||
|
|
@ -19,6 +19,8 @@ const editSchema = Type.Object({
|
||||||
newText: Type.String({ description: "New text to replace the old text with" }),
|
newText: Type.String({ description: "New text to replace the old text with" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type EditToolInput = Static<typeof editSchema>;
|
||||||
|
|
||||||
export interface EditToolDetails {
|
export interface EditToolDetails {
|
||||||
/** Unified diff of the changes made */
|
/** Unified diff of the changes made */
|
||||||
diff: string;
|
diff: string;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { spawnSync } from "child_process";
|
import { spawnSync } from "child_process";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { globSync } from "glob";
|
import { globSync } from "glob";
|
||||||
|
|
@ -16,6 +16,8 @@ const findSchema = Type.Object({
|
||||||
limit: Type.Optional(Type.Number({ description: "Maximum number of results (default: 1000)" })),
|
limit: Type.Optional(Type.Number({ description: "Maximum number of results (default: 1000)" })),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type FindToolInput = Static<typeof findSchema>;
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 1000;
|
const DEFAULT_LIMIT = 1000;
|
||||||
|
|
||||||
export interface FindToolDetails {
|
export interface FindToolDetails {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { createInterface } from "node:readline";
|
import { createInterface } from "node:readline";
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import { readFileSync, statSync } from "fs";
|
import { readFileSync, statSync } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
@ -29,6 +29,8 @@ const grepSchema = Type.Object({
|
||||||
limit: Type.Optional(Type.Number({ description: "Maximum number of matches to return (default: 100)" })),
|
limit: Type.Optional(Type.Number({ description: "Maximum number of matches to return (default: 100)" })),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type GrepToolInput = Static<typeof grepSchema>;
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 100;
|
const DEFAULT_LIMIT = 100;
|
||||||
|
|
||||||
export interface GrepToolDetails {
|
export interface GrepToolDetails {
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,48 @@
|
||||||
export {
|
export {
|
||||||
type BashOperations,
|
type BashOperations,
|
||||||
type BashToolDetails,
|
type BashToolDetails,
|
||||||
|
type BashToolInput,
|
||||||
type BashToolOptions,
|
type BashToolOptions,
|
||||||
bashTool,
|
bashTool,
|
||||||
createBashTool,
|
createBashTool,
|
||||||
} from "./bash.js";
|
} from "./bash.js";
|
||||||
export { createEditTool, type EditOperations, type EditToolDetails, type EditToolOptions, editTool } from "./edit.js";
|
export {
|
||||||
export { createFindTool, type FindOperations, type FindToolDetails, type FindToolOptions, findTool } from "./find.js";
|
createEditTool,
|
||||||
export { createGrepTool, type GrepOperations, type GrepToolDetails, type GrepToolOptions, grepTool } from "./grep.js";
|
type EditOperations,
|
||||||
export { createLsTool, type LsOperations, type LsToolDetails, type LsToolOptions, lsTool } from "./ls.js";
|
type EditToolDetails,
|
||||||
|
type EditToolInput,
|
||||||
|
type EditToolOptions,
|
||||||
|
editTool,
|
||||||
|
} from "./edit.js";
|
||||||
|
export {
|
||||||
|
createFindTool,
|
||||||
|
type FindOperations,
|
||||||
|
type FindToolDetails,
|
||||||
|
type FindToolInput,
|
||||||
|
type FindToolOptions,
|
||||||
|
findTool,
|
||||||
|
} from "./find.js";
|
||||||
|
export {
|
||||||
|
createGrepTool,
|
||||||
|
type GrepOperations,
|
||||||
|
type GrepToolDetails,
|
||||||
|
type GrepToolInput,
|
||||||
|
type GrepToolOptions,
|
||||||
|
grepTool,
|
||||||
|
} from "./grep.js";
|
||||||
|
export {
|
||||||
|
createLsTool,
|
||||||
|
type LsOperations,
|
||||||
|
type LsToolDetails,
|
||||||
|
type LsToolInput,
|
||||||
|
type LsToolOptions,
|
||||||
|
lsTool,
|
||||||
|
} from "./ls.js";
|
||||||
export {
|
export {
|
||||||
createReadTool,
|
createReadTool,
|
||||||
type ReadOperations,
|
type ReadOperations,
|
||||||
type ReadToolDetails,
|
type ReadToolDetails,
|
||||||
|
type ReadToolInput,
|
||||||
type ReadToolOptions,
|
type ReadToolOptions,
|
||||||
readTool,
|
readTool,
|
||||||
} from "./read.js";
|
} from "./read.js";
|
||||||
|
|
@ -26,7 +56,13 @@ export {
|
||||||
truncateLine,
|
truncateLine,
|
||||||
truncateTail,
|
truncateTail,
|
||||||
} from "./truncate.js";
|
} from "./truncate.js";
|
||||||
export { createWriteTool, type WriteOperations, type WriteToolOptions, writeTool } from "./write.js";
|
export {
|
||||||
|
createWriteTool,
|
||||||
|
type WriteOperations,
|
||||||
|
type WriteToolInput,
|
||||||
|
type WriteToolOptions,
|
||||||
|
writeTool,
|
||||||
|
} from "./write.js";
|
||||||
|
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { type BashToolOptions, bashTool, createBashTool } from "./bash.js";
|
import { type BashToolOptions, bashTool, createBashTool } from "./bash.js";
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { existsSync, readdirSync, statSync } from "fs";
|
import { existsSync, readdirSync, statSync } from "fs";
|
||||||
import nodePath from "path";
|
import nodePath from "path";
|
||||||
import { resolveToCwd } from "./path-utils.js";
|
import { resolveToCwd } from "./path-utils.js";
|
||||||
|
|
@ -10,6 +10,8 @@ const lsSchema = Type.Object({
|
||||||
limit: Type.Optional(Type.Number({ description: "Maximum number of entries to return (default: 500)" })),
|
limit: Type.Optional(Type.Number({ description: "Maximum number of entries to return (default: 500)" })),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type LsToolInput = Static<typeof lsSchema>;
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 500;
|
const DEFAULT_LIMIT = 500;
|
||||||
|
|
||||||
export interface LsToolDetails {
|
export interface LsToolDetails {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import type { ImageContent, TextContent } from "@mariozechner/pi-ai";
|
import type { ImageContent, TextContent } from "@mariozechner/pi-ai";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { constants } from "fs";
|
import { constants } from "fs";
|
||||||
import { access as fsAccess, readFile as fsReadFile } from "fs/promises";
|
import { access as fsAccess, readFile as fsReadFile } from "fs/promises";
|
||||||
import { formatDimensionNote, resizeImage } from "../../utils/image-resize.js";
|
import { formatDimensionNote, resizeImage } from "../../utils/image-resize.js";
|
||||||
|
|
@ -14,6 +14,8 @@ const readSchema = Type.Object({
|
||||||
limit: Type.Optional(Type.Number({ description: "Maximum number of lines to read" })),
|
limit: Type.Optional(Type.Number({ description: "Maximum number of lines to read" })),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type ReadToolInput = Static<typeof readSchema>;
|
||||||
|
|
||||||
export interface ReadToolDetails {
|
export interface ReadToolDetails {
|
||||||
truncation?: TruncationResult;
|
truncation?: TruncationResult;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { type Static, Type } from "@sinclair/typebox";
|
||||||
import { mkdir as fsMkdir, writeFile as fsWriteFile } from "fs/promises";
|
import { mkdir as fsMkdir, writeFile as fsWriteFile } from "fs/promises";
|
||||||
import { dirname } from "path";
|
import { dirname } from "path";
|
||||||
import { resolveToCwd } from "./path-utils.js";
|
import { resolveToCwd } from "./path-utils.js";
|
||||||
|
|
@ -9,6 +9,8 @@ const writeSchema = Type.Object({
|
||||||
content: Type.String({ description: "Content to write to the file" }),
|
content: Type.String({ description: "Content to write to the file" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type WriteToolInput = Static<typeof writeSchema>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pluggable operations for the write tool.
|
* Pluggable operations for the write tool.
|
||||||
* Override these to delegate file writing to remote systems (e.g., SSH).
|
* Override these to delegate file writing to remote systems (e.g., SSH).
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,13 @@ export type {
|
||||||
AgentToolResult,
|
AgentToolResult,
|
||||||
AgentToolUpdateCallback,
|
AgentToolUpdateCallback,
|
||||||
AppAction,
|
AppAction,
|
||||||
|
BashToolCallEvent,
|
||||||
BeforeAgentStartEvent,
|
BeforeAgentStartEvent,
|
||||||
CompactOptions,
|
CompactOptions,
|
||||||
ContextEvent,
|
ContextEvent,
|
||||||
ContextUsage,
|
ContextUsage,
|
||||||
|
CustomToolCallEvent,
|
||||||
|
EditToolCallEvent,
|
||||||
ExecOptions,
|
ExecOptions,
|
||||||
ExecResult,
|
ExecResult,
|
||||||
Extension,
|
Extension,
|
||||||
|
|
@ -69,15 +72,19 @@ export type {
|
||||||
ExtensionUIContext,
|
ExtensionUIContext,
|
||||||
ExtensionUIDialogOptions,
|
ExtensionUIDialogOptions,
|
||||||
ExtensionWidgetOptions,
|
ExtensionWidgetOptions,
|
||||||
|
FindToolCallEvent,
|
||||||
|
GrepToolCallEvent,
|
||||||
InputEvent,
|
InputEvent,
|
||||||
InputEventResult,
|
InputEventResult,
|
||||||
InputSource,
|
InputSource,
|
||||||
KeybindingsManager,
|
KeybindingsManager,
|
||||||
LoadExtensionsResult,
|
LoadExtensionsResult,
|
||||||
|
LsToolCallEvent,
|
||||||
MessageRenderer,
|
MessageRenderer,
|
||||||
MessageRenderOptions,
|
MessageRenderOptions,
|
||||||
ProviderConfig,
|
ProviderConfig,
|
||||||
ProviderModelConfig,
|
ProviderModelConfig,
|
||||||
|
ReadToolCallEvent,
|
||||||
RegisteredCommand,
|
RegisteredCommand,
|
||||||
RegisteredTool,
|
RegisteredTool,
|
||||||
SessionBeforeCompactEvent,
|
SessionBeforeCompactEvent,
|
||||||
|
|
@ -100,6 +107,7 @@ export type {
|
||||||
UserBashEvent,
|
UserBashEvent,
|
||||||
UserBashEventResult,
|
UserBashEventResult,
|
||||||
WidgetPlacement,
|
WidgetPlacement,
|
||||||
|
WriteToolCallEvent,
|
||||||
} from "./core/extensions/index.js";
|
} from "./core/extensions/index.js";
|
||||||
export {
|
export {
|
||||||
createExtensionRuntime,
|
createExtensionRuntime,
|
||||||
|
|
@ -111,6 +119,7 @@ export {
|
||||||
isGrepToolResult,
|
isGrepToolResult,
|
||||||
isLsToolResult,
|
isLsToolResult,
|
||||||
isReadToolResult,
|
isReadToolResult,
|
||||||
|
isToolCallEventType,
|
||||||
isWriteToolResult,
|
isWriteToolResult,
|
||||||
wrapRegisteredTool,
|
wrapRegisteredTool,
|
||||||
wrapRegisteredTools,
|
wrapRegisteredTools,
|
||||||
|
|
@ -196,6 +205,7 @@ export {
|
||||||
export {
|
export {
|
||||||
type BashOperations,
|
type BashOperations,
|
||||||
type BashToolDetails,
|
type BashToolDetails,
|
||||||
|
type BashToolInput,
|
||||||
type BashToolOptions,
|
type BashToolOptions,
|
||||||
bashTool,
|
bashTool,
|
||||||
codingTools,
|
codingTools,
|
||||||
|
|
@ -203,23 +213,28 @@ export {
|
||||||
DEFAULT_MAX_LINES,
|
DEFAULT_MAX_LINES,
|
||||||
type EditOperations,
|
type EditOperations,
|
||||||
type EditToolDetails,
|
type EditToolDetails,
|
||||||
|
type EditToolInput,
|
||||||
type EditToolOptions,
|
type EditToolOptions,
|
||||||
editTool,
|
editTool,
|
||||||
type FindOperations,
|
type FindOperations,
|
||||||
type FindToolDetails,
|
type FindToolDetails,
|
||||||
|
type FindToolInput,
|
||||||
type FindToolOptions,
|
type FindToolOptions,
|
||||||
findTool,
|
findTool,
|
||||||
formatSize,
|
formatSize,
|
||||||
type GrepOperations,
|
type GrepOperations,
|
||||||
type GrepToolDetails,
|
type GrepToolDetails,
|
||||||
|
type GrepToolInput,
|
||||||
type GrepToolOptions,
|
type GrepToolOptions,
|
||||||
grepTool,
|
grepTool,
|
||||||
type LsOperations,
|
type LsOperations,
|
||||||
type LsToolDetails,
|
type LsToolDetails,
|
||||||
|
type LsToolInput,
|
||||||
type LsToolOptions,
|
type LsToolOptions,
|
||||||
lsTool,
|
lsTool,
|
||||||
type ReadOperations,
|
type ReadOperations,
|
||||||
type ReadToolDetails,
|
type ReadToolDetails,
|
||||||
|
type ReadToolInput,
|
||||||
type ReadToolOptions,
|
type ReadToolOptions,
|
||||||
readTool,
|
readTool,
|
||||||
type ToolsOptions,
|
type ToolsOptions,
|
||||||
|
|
@ -229,6 +244,7 @@ export {
|
||||||
truncateLine,
|
truncateLine,
|
||||||
truncateTail,
|
truncateTail,
|
||||||
type WriteOperations,
|
type WriteOperations,
|
||||||
|
type WriteToolInput,
|
||||||
type WriteToolOptions,
|
type WriteToolOptions,
|
||||||
writeTool,
|
writeTool,
|
||||||
} from "./core/tools/index.js";
|
} from "./core/tools/index.js";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue