Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,16 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session",
payload: typeof RevertPayload.Type
}) {
yield* requireSession(ctx.params.sessionID)
return yield* revertSvc.revert({ sessionID: ctx.params.sessionID, ...ctx.payload })
return yield* revertSvc
.revert({ sessionID: ctx.params.sessionID, ...ctx.payload })
.pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
})

const unrevert = Effect.fn("SessionHttpApi.unrevert")(function* (ctx: { params: { sessionID: SessionID } }) {
yield* requireSession(ctx.params.sessionID)
return yield* revertSvc.unrevert({ sessionID: ctx.params.sessionID })
return yield* revertSvc
.unrevert({ sessionID: ctx.params.sessionID })
.pipe(Effect.mapError(() => new HttpApiError.BadRequest({})))
})

const permissionRespond = Effect.fn("SessionHttpApi.permissionRespond")(function* (ctx: {
Expand Down
4 changes: 3 additions & 1 deletion packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ export const layer: Layer.Layer<
})
yield* session.updateMessage(ctx.assistantMessage)
if (ctx.snapshot) {
const patch = yield* snapshot.patch(ctx.snapshot)
const patch = completedSnapshot
? yield* snapshot.patch(ctx.snapshot, completedSnapshot)
: yield* snapshot.patch(ctx.snapshot)
if (patch.files.length) {
yield* session.updatePart({
id: PartID.ascending(),
Expand Down
12 changes: 7 additions & 5 deletions packages/opencode/src/session/revert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const RevertInput = Schema.Struct({
export type RevertInput = Schema.Schema.Type<typeof RevertInput>

export interface Interface {
readonly revert: (input: RevertInput) => Effect.Effect<Session.Info>
readonly unrevert: (input: { sessionID: SessionID }) => Effect.Effect<Session.Info>
readonly revert: (input: RevertInput) => Effect.Effect<Session.Info, Snapshot.Error>
readonly unrevert: (input: { sessionID: SessionID }) => Effect.Effect<Session.Info, Snapshot.Error>
readonly cleanup: (session: Session.Info) => Effect.Effect<void>
}

Expand Down Expand Up @@ -71,9 +71,11 @@ export const layer = Layer.effect(
if (!rev) return session

rev.snapshot = session.revert?.snapshot ?? (yield* snap.track())
if (session.revert?.snapshot) yield* snap.restore(session.revert.snapshot)
yield* snap.revert(patches)
if (rev.snapshot) rev.diff = yield* snap.diff(rev.snapshot)
if (!rev.snapshot) {
return yield* new Snapshot.Error({ operation: "revert", message: "failed to capture the current workspace" })
}
yield* snap.revert(patches, session.revert?.snapshot)
rev.diff = yield* snap.diff(rev.snapshot)
const range = all.filter((msg) => msg.info.id >= rev.messageID)
const diffs = yield* summary.computeDiff({ messages: range })
yield* storage.write(["session_diff", input.sessionID], diffs).pipe(Effect.ignore)
Expand Down
Loading
Loading