mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(core): return write confirmations as strings (#63616)
This commit is contained in:
committed by
GitHub
Unverified
parent
e82687adf4
commit
b6ed77e474
@@ -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 })),
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user