Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/server/routes/instance/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export const SessionRoutes = lazy(() =>
description: "Successfully retrieved diff",
content: {
"application/json": {
schema: resolver(Snapshot.FileDiff.array()),
schema: resolver(Snapshot.FileDiff.zod.array()),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export const User = Base.extend({
.object({
title: z.string().optional(),
body: z.string().optional(),
diffs: Snapshot.FileDiff.array(),
diffs: Snapshot.FileDiff.zod.array(),
})
.optional(),
agent: z.string(),
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const Info = z
additions: z.number(),
deletions: z.number(),
files: z.number(),
diffs: Snapshot.FileDiff.array().optional(),
diffs: Snapshot.FileDiff.zod.array().optional(),
})
.optional(),
share: z
Expand Down Expand Up @@ -239,7 +239,7 @@ export const Event = {
"session.diff",
z.object({
sessionID: SessionID.zod,
diff: Snapshot.FileDiff.array(),
diff: Snapshot.FileDiff.zod.array(),
}),
),
Error: BusEvent.define(
Expand Down
38 changes: 19 additions & 19 deletions packages/opencode/src/snapshot/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cause, Duration, Effect, Layer, Schedule, Semaphore, Context, Stream } from "effect"
import { Cause, Duration, Effect, Layer, Schedule, Schema, Semaphore, Context, Stream } from "effect"
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
import { formatPatch, structuredPatch } from "diff"
import path from "path"
Expand All @@ -10,25 +10,25 @@ import { Hash } from "@opencode-ai/shared/util/hash"
import { Config } from "../config"
import { Global } from "../global"
import { Log } from "../util"

export const Patch = z.object({
hash: z.string(),
files: z.string().array(),
import { withStatics } from "@/util/schema"
import { zod } from "@/util/effect-zod"

export const Patch = Schema.Struct({
hash: Schema.String,
files: Schema.mutable(Schema.Array(Schema.String)),
}).pipe(withStatics((s) => ({ zod: zod(s) })))
export type Patch = typeof Patch.Type

export const FileDiff = Schema.Struct({
file: Schema.String,
patch: Schema.String,
additions: Schema.Number,
deletions: Schema.Number,
status: Schema.optional(Schema.Literals(["added", "deleted", "modified"])),
})
export type Patch = z.infer<typeof Patch>

export const FileDiff = z
.object({
file: z.string(),
patch: z.string(),
additions: z.number(),
deletions: z.number(),
status: z.enum(["added", "deleted", "modified"]).optional(),
})
.meta({
ref: "SnapshotFileDiff",
})
export type FileDiff = z.infer<typeof FileDiff>
.annotate({ identifier: "SnapshotFileDiff" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
export type FileDiff = typeof FileDiff.Type

const log = Log.create({ service: "snapshot" })
const prune = "7.days"
Expand Down
14 changes: 8 additions & 6 deletions packages/opencode/src/tool/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,17 @@ export const EditTool = Tool.define(
}).pipe(Effect.orDie),
)

let additions = 0
let deletions = 0
for (const change of diffLines(contentOld, contentNew)) {
if (change.added) additions += change.count || 0
if (change.removed) deletions += change.count || 0
}
const filediff: Snapshot.FileDiff = {
file: filePath,
patch: diff,
additions: 0,
deletions: 0,
}
for (const change of diffLines(contentOld, contentNew)) {
if (change.added) filediff.additions += change.count || 0
if (change.removed) filediff.deletions += change.count || 0
additions,
deletions,
}

yield* ctx.metadata({
Expand Down
Loading