fix(coding-agent): add createEditTool/createWriteTool to legacy pi shim
The legacy @oh-my-pi/pi-coding-agent shim exported the read/bash/grep/find/ls tool factories but omitted the edit and write ones. pi extensions importing createEditTool or createWriteTool (e.g. gentle-pi) failed Bun's static export check during extension validation, blocking omp install. Added createEditTool/createEditToolDefinition and createWriteTool/ createWriteToolDefinition, mirroring the upstream pi surface and the existing sibling factories. The unsupported operations seam throws a descriptive error like createGrepTool does. Fixes #7094
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `omp install` failing extension validation for pi extensions that import `createEditTool` or `createWriteTool` (e.g. gentle-pi) — the legacy `@oh-my-pi/pi-coding-agent` shim exported the read/bash/grep/find/ls tool factories but omitted the edit and write ones, so a named import threw Bun's static "Export named X not found" error. Added `createEditTool`/`createEditToolDefinition` and `createWriteTool`/`createWriteToolDefinition` to match the upstream pi surface ([#7094](https://github.com/can1357/oh-my-pi/issues/7094)).
|
||||
|
||||
## [17.2.0] - 2026-07-30
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
@@ -140,6 +140,25 @@ export interface LsToolOptions {
|
||||
operations?: LsOperations;
|
||||
}
|
||||
|
||||
export interface EditOperations {
|
||||
readFile: (absolutePath: string) => Promise<Buffer>;
|
||||
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
||||
access: (absolutePath: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface EditToolOptions {
|
||||
operations?: EditOperations;
|
||||
}
|
||||
|
||||
export interface WriteOperations {
|
||||
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
||||
mkdir: (dir: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface WriteToolOptions {
|
||||
operations?: WriteOperations;
|
||||
}
|
||||
|
||||
const legacyBashSchema = Type.Object({
|
||||
command: Type.String({ description: "Bash command to execute" }),
|
||||
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds" })),
|
||||
@@ -636,6 +655,40 @@ export function createLsTool(cwd: string, options?: LsToolOptions): ToolDefiniti
|
||||
return createLsToolDefinition(cwd, options);
|
||||
}
|
||||
|
||||
/** Create the legacy edit tool definition. */
|
||||
export function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition {
|
||||
if (options?.operations) {
|
||||
throw new Error(
|
||||
"Legacy EditToolOptions.operations is not supported: OMP's built-in edit tool writes the local " +
|
||||
"filesystem natively and exposes no pluggable operations seam. Register a custom edit tool via " +
|
||||
"defineTool() instead of passing operations to createEditTool()/createEditToolDefinition().",
|
||||
);
|
||||
}
|
||||
return legacyBuiltinTool(cwd, "edit");
|
||||
}
|
||||
|
||||
/** Create the legacy edit tool. */
|
||||
export function createEditTool(cwd: string, options?: EditToolOptions): ToolDefinition {
|
||||
return createEditToolDefinition(cwd, options);
|
||||
}
|
||||
|
||||
/** Create the legacy write tool definition. */
|
||||
export function createWriteToolDefinition(cwd: string, options?: WriteToolOptions): ToolDefinition {
|
||||
if (options?.operations) {
|
||||
throw new Error(
|
||||
"Legacy WriteToolOptions.operations is not supported: OMP's built-in write tool writes the local " +
|
||||
"filesystem natively and exposes no pluggable operations seam. Register a custom write tool via " +
|
||||
"defineTool() instead of passing operations to createWriteTool()/createWriteToolDefinition().",
|
||||
);
|
||||
}
|
||||
return legacyBuiltinTool(cwd, "write");
|
||||
}
|
||||
|
||||
/** Create the legacy write tool. */
|
||||
export function createWriteTool(cwd: string, options?: WriteToolOptions): ToolDefinition {
|
||||
return createWriteToolDefinition(cwd, options);
|
||||
}
|
||||
|
||||
/** Create legacy read, bash, edit, and write tools. */
|
||||
export function createCodingTools(cwd: string): ToolDefinition[] {
|
||||
return LEGACY_CODING_TOOL_NAMES.map(name => legacyBuiltinTool(cwd, name));
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import * as shim from "@oh-my-pi/pi-coding-agent/extensibility/legacy-pi-coding-agent-shim";
|
||||
|
||||
// Issue #7094: pi extensions import the edit/write tool factories
|
||||
// (`createEditTool`, `createEditToolDefinition`, `createWriteTool`,
|
||||
// `createWriteToolDefinition`) from `@earendil-works/pi-coding-agent`, which
|
||||
// aliases to this shim. The shim exported the other five tool factories
|
||||
// (read/bash/grep/find/ls) but omitted edit and write, so a named import of
|
||||
// either threw Bun's static "Export named X not found" error and any importing
|
||||
// extension (e.g. gentle-pi) failed validation. These pin the factory surface
|
||||
// and the tool definitions they build.
|
||||
describe("legacy shim edit/write tool factories", () => {
|
||||
it("exports the edit/write factories as callable functions", () => {
|
||||
expect(typeof shim.createEditTool).toBe("function");
|
||||
expect(typeof shim.createEditToolDefinition).toBe("function");
|
||||
expect(typeof shim.createWriteTool).toBe("function");
|
||||
expect(typeof shim.createWriteToolDefinition).toBe("function");
|
||||
});
|
||||
|
||||
it("builds edit and write tool definitions bound to the built-in tools", () => {
|
||||
const edit = shim.createEditTool(process.cwd());
|
||||
expect(edit.name).toBe("edit");
|
||||
expect(typeof edit.execute).toBe("function");
|
||||
|
||||
const write = shim.createWriteTool(process.cwd());
|
||||
expect(write.name).toBe("write");
|
||||
expect(typeof write.execute).toBe("function");
|
||||
});
|
||||
|
||||
it("rejects the unsupported operations seam", () => {
|
||||
expect(() => shim.createEditTool(process.cwd(), { operations: {} as never })).toThrow(
|
||||
/operations is not supported/,
|
||||
);
|
||||
expect(() => shim.createWriteTool(process.cwd(), { operations: {} as never })).toThrow(
|
||||
/operations is not supported/,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user