From b6ed77e4742b56a52130b16d33a7a4947379529a Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Thu, 12 Nov 2026 17:47:37 -0600 Subject: [PATCH] fix(core): return write confirmations as strings (#63616) --- packages/core/src/tool/plugin/write.ts | 24 +++++------------------ packages/core/test/tool-write.test.ts | 27 +++++++++++--------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/packages/core/src/tool/plugin/write.ts b/packages/core/src/tool/plugin/write.ts index 7d04595b603..a28603b66ab 100644 --- a/packages/core/src/tool/plugin/write.ts +++ b/packages/core/src/tool/plugin/write.ts @@ -21,17 +21,9 @@ export const Input = Schema.Struct({ content: Schema.String.annotate({ description: "Content to write to the file" }), }) -export const Output = Schema.Struct({ - operation: Schema.Literal("write"), - target: Schema.String, - resource: Schema.String, - existed: Schema.Boolean, -}) +export const Output = Schema.String export type Output = typeof Output.Type -export const toModelContent = (output: Output) => - `${output.existed ? "Wrote" : "Created"} file successfully: ${output.resource}` - /** Deferred write UX integrations remain visible at the model-facing seam. */ // TODO: Publish watcher/file-edit events after watcher integration exists. // TODO: Add snapshots / undo after design exists. @@ -52,16 +44,10 @@ export const Plugin = { input: Input, output: Output, execute: (input, context) => - Effect.gen(function* () { - const written = yield* fileWrite.write(input, context) - return { - operation: written.operation, - target: written.target, - resource: written.resource, - existed: written.existed, - } - }).pipe( - Effect.map((output) => ({ output, content: toModelContent(output) })), + fileWrite.write(input, context).pipe( + Effect.map((written) => ({ + output: `${written.existed ? "Wrote" : "Created"} file successfully: ${written.resource}`, + })), Effect.mapError((error) => new ToolFailure({ message: `Unable to write ${input.path}`, error })), ), }), diff --git a/packages/core/test/tool-write.test.ts b/packages/core/test/tool-write.test.ts index 279c26c74de..0b6c489cfc9 100644 --- a/packages/core/test/tool-write.test.ts +++ b/packages/core/test/tool-write.test.ts @@ -115,16 +115,14 @@ describe("WriteTool", () => { const fixture = makeWriteFixture() return withTool(tmp.path, fixture, (registry) => Effect.gen(function* () { - expect((yield* toolDefinitions(registry)).map((tool) => tool.name)).toEqual(["write", "execute"]) + expect(yield* toolDefinitions(registry)).toMatchObject([ + { name: "write", outputSchema: { type: "string" } }, + { name: "execute" }, + ]) const settled = yield* executeTool(registry, call({ path: "src/new.txt", content: "created" })) expect(settled).toEqual({ status: "completed", - output: { - operation: "write", - target: path.join(yield* Effect.promise(() => fs.realpath(tmp.path)), "src", "new.txt"), - resource: "src/new.txt", - existed: false, - }, + output: "Created file successfully: src/new.txt", content: [{ type: "text", text: "Created file successfully: src/new.txt" }], }) expect(yield* Effect.promise(() => fs.readFile(path.join(tmp.path, "src", "new.txt"), "utf8"))).toBe( @@ -183,10 +181,11 @@ describe("WriteTool", () => { ), Effect.andThen((settled) => Effect.gen(function* () { - expect(settled.status).toBe("completed") - if (settled.status !== "completed") return - expect(settled.content).toEqual([{ type: "text", text: "Wrote file successfully: existing.txt" }]) - expect(settled.output).toMatchObject({ resource: "existing.txt", existed: true }) + expect(settled).toEqual({ + status: "completed", + output: "Wrote file successfully: existing.txt", + content: [{ type: "text", text: "Wrote file successfully: existing.txt" }], + }) expect(fixture.assertions[0]?.metadata).toMatchObject({ files: [ { @@ -315,11 +314,7 @@ describe("WriteTool", () => { }) expect(settled).toMatchObject({ status: "completed", - output: { - target: absoluteTarget, - resource: absoluteTarget.replaceAll("\\", "/"), - existed: false, - }, + output: `Created file successfully: ${absoluteTarget.replaceAll("\\", "/")}`, }) expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("external") expect(fixture.writes).toEqual([absoluteTarget])