migrate Snapshot schemas to Effect Schema (#23747)

This commit is contained in:
Kit Langton
2026-04-21 17:37:27 -04:00
committed by GitHub
parent b1c3095edd
commit 0bcf734a67
5 changed files with 30 additions and 28 deletions
@@ -471,7 +471,7 @@ export const SessionRoutes = lazy(() =>
description: "Successfully retrieved diff", description: "Successfully retrieved diff",
content: { content: {
"application/json": { "application/json": {
schema: resolver(Snapshot.FileDiff.array()), schema: resolver(Snapshot.FileDiff.zod.array()),
}, },
}, },
}, },
+1 -1
View File
@@ -366,7 +366,7 @@ export const User = Base.extend({
.object({ .object({
title: z.string().optional(), title: z.string().optional(),
body: z.string().optional(), body: z.string().optional(),
diffs: Snapshot.FileDiff.array(), diffs: Snapshot.FileDiff.zod.array(),
}) })
.optional(), .optional(),
agent: z.string(), agent: z.string(),
+2 -2
View File
@@ -127,7 +127,7 @@ export const Info = z
additions: z.number(), additions: z.number(),
deletions: z.number(), deletions: z.number(),
files: z.number(), files: z.number(),
diffs: Snapshot.FileDiff.array().optional(), diffs: Snapshot.FileDiff.zod.array().optional(),
}) })
.optional(), .optional(),
share: z share: z
@@ -239,7 +239,7 @@ export const Event = {
"session.diff", "session.diff",
z.object({ z.object({
sessionID: SessionID.zod, sessionID: SessionID.zod,
diff: Snapshot.FileDiff.array(), diff: Snapshot.FileDiff.zod.array(),
}), }),
), ),
Error: BusEvent.define( Error: BusEvent.define(
+17 -17
View File
@@ -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 { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
import { formatPatch, structuredPatch } from "diff" import { formatPatch, structuredPatch } from "diff"
import path from "path" import path from "path"
@@ -10,25 +10,25 @@ import { Hash } from "@opencode-ai/shared/util/hash"
import { Config } from "../config" import { Config } from "../config"
import { Global } from "../global" import { Global } from "../global"
import { Log } from "../util" import { Log } from "../util"
import { withStatics } from "@/util/schema"
import { zod } from "@/util/effect-zod"
export const Patch = z.object({ export const Patch = Schema.Struct({
hash: z.string(), hash: Schema.String,
files: z.string().array(), files: Schema.mutable(Schema.Array(Schema.String)),
}) }).pipe(withStatics((s) => ({ zod: zod(s) })))
export type Patch = z.infer<typeof Patch> export type Patch = typeof Patch.Type
export const FileDiff = z export const FileDiff = Schema.Struct({
.object({ file: Schema.String,
file: z.string(), patch: Schema.String,
patch: z.string(), additions: Schema.Number,
additions: z.number(), deletions: Schema.Number,
deletions: z.number(), status: Schema.optional(Schema.Literals(["added", "deleted", "modified"])),
status: z.enum(["added", "deleted", "modified"]).optional(),
}) })
.meta({ .annotate({ identifier: "SnapshotFileDiff" })
ref: "SnapshotFileDiff", .pipe(withStatics((s) => ({ zod: zod(s) })))
}) export type FileDiff = typeof FileDiff.Type
export type FileDiff = z.infer<typeof FileDiff>
const log = Log.create({ service: "snapshot" }) const log = Log.create({ service: "snapshot" })
const prune = "7.days" const prune = "7.days"
+8 -6
View File
@@ -153,15 +153,17 @@ export const EditTool = Tool.define(
}).pipe(Effect.orDie), }).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 = { const filediff: Snapshot.FileDiff = {
file: filePath, file: filePath,
patch: diff, patch: diff,
additions: 0, additions,
deletions: 0, deletions,
}
for (const change of diffLines(contentOld, contentNew)) {
if (change.added) filediff.additions += change.count || 0
if (change.removed) filediff.deletions += change.count || 0
} }
yield* ctx.metadata({ yield* ctx.metadata({