migrate Snapshot schemas to Effect Schema (#23747)
This commit is contained in:
@@ -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()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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(),
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -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 = 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>
|
.annotate({ identifier: "SnapshotFileDiff" })
|
||||||
|
.pipe(withStatics((s) => ({ zod: zod(s) })))
|
||||||
export const FileDiff = z
|
export type FileDiff = typeof FileDiff.Type
|
||||||
.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>
|
|
||||||
|
|
||||||
const log = Log.create({ service: "snapshot" })
|
const log = Log.create({ service: "snapshot" })
|
||||||
const prune = "7.days"
|
const prune = "7.days"
|
||||||
|
|||||||
@@ -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({
|
||||||
|
|||||||
Reference in New Issue
Block a user