chore: generate
This commit is contained in:
@@ -96,8 +96,8 @@ export const layer = Layer.effect(
|
|||||||
if (patch) {
|
if (patch) {
|
||||||
const repository = yield* git.repo.discover(directory)
|
const repository = yield* git.repo.discover(directory)
|
||||||
if (!repository) return yield* new ApplyChangesError({ message: "Destination is not a Git repository" })
|
if (!repository) return yield* new ApplyChangesError({ message: "Destination is not a Git repository" })
|
||||||
yield* git
|
yield* git.change
|
||||||
.change.apply({ repository, path: directory, changes: patch })
|
.apply({ repository, path: directory, changes: patch })
|
||||||
.pipe(Effect.mapError((error) => new ApplyChangesError({ message: error.message })))
|
.pipe(Effect.mapError((error) => new ApplyChangesError({ message: error.message })))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+68
-67
@@ -244,7 +244,10 @@ export const layer = Layer.effect(
|
|||||||
directory: AbsolutePath,
|
directory: AbsolutePath,
|
||||||
args: string[],
|
args: string[],
|
||||||
) {
|
) {
|
||||||
const result = yield* execute(directory, proc)(args).pipe(
|
const result = yield* execute(
|
||||||
|
directory,
|
||||||
|
proc,
|
||||||
|
)(args).pipe(
|
||||||
Effect.mapError((cause) => new OperationError({ operation, directory, message: cause.message, cause })),
|
Effect.mapError((cause) => new OperationError({ operation, directory, message: cause.message, cause })),
|
||||||
)
|
)
|
||||||
if (result.exitCode === 0) return
|
if (result.exitCode === 0) return
|
||||||
@@ -306,10 +309,7 @@ export const layer = Layer.effect(
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
const reset = Effect.fn("Git.sync.resetHard")(function* (
|
const reset = Effect.fn("Git.sync.resetHard")(function* (repository: Repository, revision: string) {
|
||||||
repository: Repository,
|
|
||||||
revision: string,
|
|
||||||
) {
|
|
||||||
yield* operation("reset", repository.worktree, ["reset", "--hard", revision])
|
yield* operation("reset", repository.worktree, ["reset", "--hard", revision])
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -404,10 +404,12 @@ export const layer = Layer.effect(
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
yield* fs.writeFileString(
|
yield* fs
|
||||||
|
.writeFileString(
|
||||||
path.join(input.gitDirectory, "objects", "info", "alternates"),
|
path.join(input.gitDirectory, "objects", "info", "alternates"),
|
||||||
path.join(input.seed.commonDirectory, "objects") + "\n",
|
path.join(input.seed.commonDirectory, "objects") + "\n",
|
||||||
).pipe(
|
)
|
||||||
|
.pipe(
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
(cause) =>
|
(cause) =>
|
||||||
new OperationError({
|
new OperationError({
|
||||||
@@ -445,14 +447,9 @@ export const layer = Layer.effect(
|
|||||||
if (!candidates.length) return { skipped: [] }
|
if (!candidates.length) return { skipped: [] }
|
||||||
const ignored = input.ignores
|
const ignored = input.ignores
|
||||||
? new Set(
|
? new Set(
|
||||||
(
|
(yield* repositoryOperation("refresh", input.ignores, ["check-ignore", "--no-index", "--stdin", "-z"], {
|
||||||
yield* repositoryOperation(
|
stdin: candidates.join("\0") + "\0",
|
||||||
"refresh",
|
}).pipe(Effect.catch(() => Effect.succeed({ text: "", stderr: "" })))).text
|
||||||
input.ignores,
|
|
||||||
["check-ignore", "--no-index", "--stdin", "-z"],
|
|
||||||
{ stdin: candidates.join("\0") + "\0" },
|
|
||||||
).pipe(Effect.catch(() => Effect.succeed({ text: "", stderr: "" })))
|
|
||||||
).text
|
|
||||||
.split("\0")
|
.split("\0")
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
)
|
)
|
||||||
@@ -460,8 +457,7 @@ export const layer = Layer.effect(
|
|||||||
const allowed = candidates.filter((item) => !ignored.has(item))
|
const allowed = candidates.filter((item) => !ignored.has(item))
|
||||||
const maximum = input.maximumUntrackedFileBytes
|
const maximum = input.maximumUntrackedFileBytes
|
||||||
const skipped = maximum
|
const skipped = maximum
|
||||||
? (
|
? (yield* Effect.forEach(
|
||||||
yield* Effect.forEach(
|
|
||||||
untracked.filter((item) => allowed.includes(item)),
|
untracked.filter((item) => allowed.includes(item)),
|
||||||
(item) =>
|
(item) =>
|
||||||
fs.stat(path.join(input.repository.worktree, item)).pipe(
|
fs.stat(path.join(input.repository.worktree, item)).pipe(
|
||||||
@@ -471,8 +467,7 @@ export const layer = Layer.effect(
|
|||||||
Effect.catch(() => Effect.succeed(undefined)),
|
Effect.catch(() => Effect.succeed(undefined)),
|
||||||
),
|
),
|
||||||
{ concurrency: 8 },
|
{ concurrency: 8 },
|
||||||
)
|
)).filter((item): item is RelativePath => item !== undefined)
|
||||||
).filter((item): item is RelativePath => item !== undefined)
|
|
||||||
: []
|
: []
|
||||||
const stage = allowed.filter((item) => !skipped.includes(RelativePath.make(item)))
|
const stage = allowed.filter((item) => !skipped.includes(RelativePath.make(item)))
|
||||||
const remove = [...ignored, ...skipped]
|
const remove = [...ignored, ...skipped]
|
||||||
@@ -500,11 +495,10 @@ export const layer = Layer.effect(
|
|||||||
if (!input.paths.length) return new Set<RelativePath>()
|
if (!input.paths.length) return new Set<RelativePath>()
|
||||||
const result = yield* proc
|
const result = yield* proc
|
||||||
.run(
|
.run(
|
||||||
ChildProcess.make(
|
ChildProcess.make("git", repositoryArgs(input.repository, ["check-ignore", "--no-index", "--stdin", "-z"]), {
|
||||||
"git",
|
cwd: input.repository.worktree,
|
||||||
repositoryArgs(input.repository, ["check-ignore", "--no-index", "--stdin", "-z"]),
|
extendEnv: true,
|
||||||
{ cwd: input.repository.worktree, extendEnv: true },
|
}),
|
||||||
),
|
|
||||||
{ stdin: input.paths.join("\0") + "\0" },
|
{ stdin: input.paths.join("\0") + "\0" },
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -537,7 +531,8 @@ export const layer = Layer.effect(
|
|||||||
return TreeID.make((yield* repositoryOperation("write_tree", repository, ["write-tree"])).text.trim())
|
return TreeID.make((yield* repositoryOperation("write_tree", repository, ["write-tree"])).text.trim())
|
||||||
})
|
})
|
||||||
|
|
||||||
const captureTree = Effect.fn("Git.tree.capture")((input: {
|
const captureTree = Effect.fn("Git.tree.capture")(
|
||||||
|
(input: {
|
||||||
repository: Repository
|
repository: Repository
|
||||||
scopes: readonly RelativePath[]
|
scopes: readonly RelativePath[]
|
||||||
ignores?: Repository
|
ignores?: Repository
|
||||||
@@ -546,11 +541,7 @@ export const layer = Layer.effect(
|
|||||||
locked(
|
locked(
|
||||||
input.repository,
|
input.repository,
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
yield* Effect.forEach(
|
yield* Effect.forEach(input.scopes, (scope) => refresh({ ...input, scope }), { discard: true })
|
||||||
input.scopes,
|
|
||||||
(scope) => refresh({ ...input, scope }),
|
|
||||||
{ discard: true },
|
|
||||||
)
|
|
||||||
return yield* writeTree(input.repository)
|
return yield* writeTree(input.repository)
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -561,8 +552,14 @@ export const layer = Layer.effect(
|
|||||||
from: TreeID
|
from: TreeID
|
||||||
to: TreeID
|
to: TreeID
|
||||||
}) {
|
}) {
|
||||||
return (yield* repositoryOperation("list_files", input.repository, ["diff", "--name-only", "-z", input.from, input.to]))
|
return (yield* repositoryOperation("list_files", input.repository, [
|
||||||
.text.split("\0")
|
"diff",
|
||||||
|
"--name-only",
|
||||||
|
"-z",
|
||||||
|
input.from,
|
||||||
|
input.to,
|
||||||
|
])).text
|
||||||
|
.split("\0")
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((file) => RelativePath.make(file))
|
.map((file) => RelativePath.make(file))
|
||||||
})
|
})
|
||||||
@@ -577,8 +574,7 @@ export const layer = Layer.effect(
|
|||||||
const paths = input.paths ?? (yield* treeFiles(input))
|
const paths = input.paths ?? (yield* treeFiles(input))
|
||||||
return yield* Effect.forEach(paths, (file) =>
|
return yield* Effect.forEach(paths, (file) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const statusText = (
|
const statusText = (yield* repositoryOperation("diff", input.repository, [
|
||||||
yield* repositoryOperation("diff", input.repository, [
|
|
||||||
"diff",
|
"diff",
|
||||||
"--name-status",
|
"--name-status",
|
||||||
"--no-renames",
|
"--no-renames",
|
||||||
@@ -586,11 +582,9 @@ export const layer = Layer.effect(
|
|||||||
input.to,
|
input.to,
|
||||||
"--",
|
"--",
|
||||||
file,
|
file,
|
||||||
])
|
])).text.trim()
|
||||||
).text.trim()
|
|
||||||
const status = statusText.startsWith("A") ? "added" : statusText.startsWith("D") ? "deleted" : "modified"
|
const status = statusText.startsWith("A") ? "added" : statusText.startsWith("D") ? "deleted" : "modified"
|
||||||
const stats = (
|
const stats = (yield* repositoryOperation("diff", input.repository, [
|
||||||
yield* repositoryOperation("diff", input.repository, [
|
|
||||||
"diff",
|
"diff",
|
||||||
"--numstat",
|
"--numstat",
|
||||||
"--no-renames",
|
"--no-renames",
|
||||||
@@ -598,13 +592,11 @@ export const layer = Layer.effect(
|
|||||||
input.to,
|
input.to,
|
||||||
"--",
|
"--",
|
||||||
file,
|
file,
|
||||||
])
|
])).text.split("\t")
|
||||||
).text.split("\t")
|
|
||||||
const binary = stats[0] === "-" || stats[1] === "-"
|
const binary = stats[0] === "-" || stats[1] === "-"
|
||||||
const patch = binary
|
const patch = binary
|
||||||
? ""
|
? ""
|
||||||
: (
|
: (yield* repositoryOperation("diff", input.repository, [
|
||||||
yield* repositoryOperation("diff", input.repository, [
|
|
||||||
"diff",
|
"diff",
|
||||||
`--unified=${input.context ?? 3}`,
|
`--unified=${input.context ?? 3}`,
|
||||||
"--no-renames",
|
"--no-renames",
|
||||||
@@ -612,8 +604,7 @@ export const layer = Layer.effect(
|
|||||||
input.to,
|
input.to,
|
||||||
"--",
|
"--",
|
||||||
file,
|
file,
|
||||||
])
|
])).text
|
||||||
).text
|
|
||||||
return {
|
return {
|
||||||
path: file,
|
path: file,
|
||||||
status,
|
status,
|
||||||
@@ -626,12 +617,17 @@ export const layer = Layer.effect(
|
|||||||
})
|
})
|
||||||
|
|
||||||
const entry = Effect.fnUntraced(function* (repository: Repository, tree: TreeID, file: RelativePath) {
|
const entry = Effect.fnUntraced(function* (repository: Repository, tree: TreeID, file: RelativePath) {
|
||||||
const text = (
|
const text = (yield* repositoryOperation("restore", repository, [
|
||||||
yield* repositoryOperation("restore", repository, ["ls-tree", "-z", tree, "--", file])
|
"ls-tree",
|
||||||
).text.replace(/\0$/, "")
|
"-z",
|
||||||
|
tree,
|
||||||
|
"--",
|
||||||
|
file,
|
||||||
|
])).text.replace(/\0$/, "")
|
||||||
if (!text) return
|
if (!text) return
|
||||||
const match = text.match(/^(\d+)\s+\w+\s+([0-9a-f]+)\t/)
|
const match = text.match(/^(\d+)\s+\w+\s+([0-9a-f]+)\t/)
|
||||||
if (!match) return yield* new OperationError({
|
if (!match)
|
||||||
|
return yield* new OperationError({
|
||||||
operation: "restore",
|
operation: "restore",
|
||||||
directory: repository.worktree,
|
directory: repository.worktree,
|
||||||
message: `Invalid tree entry for ${file}`,
|
message: `Invalid tree entry for ${file}`,
|
||||||
@@ -639,7 +635,8 @@ export const layer = Layer.effect(
|
|||||||
return { mode: match[1], object: match[2] }
|
return { mode: match[1], object: match[2] }
|
||||||
})
|
})
|
||||||
|
|
||||||
const preview = Effect.fn("Git.tree.preview")((input: {
|
const preview = Effect.fn("Git.tree.preview")(
|
||||||
|
(input: {
|
||||||
repository: Repository
|
repository: Repository
|
||||||
current: TreeID
|
current: TreeID
|
||||||
files: ReadonlyMap<RelativePath, TreeID>
|
files: ReadonlyMap<RelativePath, TreeID>
|
||||||
@@ -690,10 +687,8 @@ export const layer = Layer.effect(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const restore = Effect.fn("Git.tree.restore")((input: {
|
const restore = Effect.fn("Git.tree.restore")(
|
||||||
repository: Repository
|
(input: { repository: Repository; files: ReadonlyMap<RelativePath, TreeID> }) =>
|
||||||
files: ReadonlyMap<RelativePath, TreeID>
|
|
||||||
}) =>
|
|
||||||
locked(
|
locked(
|
||||||
input.repository,
|
input.repository,
|
||||||
Effect.forEach(
|
Effect.forEach(
|
||||||
@@ -704,9 +699,7 @@ export const layer = Layer.effect(
|
|||||||
yield* repositoryOperation("restore", input.repository, ["checkout", tree, "--", file])
|
yield* repositoryOperation("restore", input.repository, ["checkout", tree, "--", file])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
yield* fs
|
yield* fs.remove(path.join(input.repository.worktree, file), { recursive: true, force: true }).pipe(
|
||||||
.remove(path.join(input.repository.worktree, file), { recursive: true, force: true })
|
|
||||||
.pipe(
|
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
(cause) =>
|
(cause) =>
|
||||||
new OperationError({
|
new OperationError({
|
||||||
@@ -733,10 +726,7 @@ export const layer = Layer.effect(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const capture = Effect.fn("Git.change.capture")(function* (input: {
|
const capture = Effect.fn("Git.change.capture")(function* (input: { repository: Repository; path: AbsolutePath }) {
|
||||||
repository: Repository
|
|
||||||
path: AbsolutePath
|
|
||||||
}) {
|
|
||||||
const scope = path.relative(input.repository.worktree, input.path).replaceAll("\\", "/") || "."
|
const scope = path.relative(input.repository.worktree, input.path).replaceAll("\\", "/") || "."
|
||||||
const tracked = yield* execute(
|
const tracked = yield* execute(
|
||||||
input.repository.worktree,
|
input.repository.worktree,
|
||||||
@@ -811,8 +801,7 @@ export const layer = Layer.effect(
|
|||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
(cause) =>
|
(cause) => new PatchError({ operation: "apply", directory: input.path, message: cause.message, cause }),
|
||||||
new PatchError({ operation: "apply", directory: input.path, message: cause.message, cause }),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if (result.exitCode === 0) return
|
if (result.exitCode === 0) return
|
||||||
@@ -831,9 +820,10 @@ export const layer = Layer.effect(
|
|||||||
untracked: "preserve" | "remove"
|
untracked: "preserve" | "remove"
|
||||||
}) {
|
}) {
|
||||||
const scope = path.relative(input.repository.worktree, input.path).replaceAll("\\", "/") || "."
|
const scope = path.relative(input.repository.worktree, input.path).replaceAll("\\", "/") || "."
|
||||||
const restore = yield* execute(input.repository.worktree, proc)(
|
const restore = yield* execute(
|
||||||
input.index === "reset" ? ["checkout", "HEAD", "--", scope] : ["checkout", "--", scope],
|
input.repository.worktree,
|
||||||
).pipe(
|
proc,
|
||||||
|
)(input.index === "reset" ? ["checkout", "HEAD", "--", scope] : ["checkout", "--", scope]).pipe(
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
(cause) => new PatchError({ operation: "reset", directory: input.path, message: cause.message, cause }),
|
(cause) => new PatchError({ operation: "reset", directory: input.path, message: cause.message, cause }),
|
||||||
),
|
),
|
||||||
@@ -846,7 +836,10 @@ export const layer = Layer.effect(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (input.untracked === "preserve") return
|
if (input.untracked === "preserve") return
|
||||||
const clean = yield* execute(input.repository.worktree, proc)(["clean", "-fd", "--", scope]).pipe(
|
const clean = yield* execute(
|
||||||
|
input.repository.worktree,
|
||||||
|
proc,
|
||||||
|
)(["clean", "-fd", "--", scope]).pipe(
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
(cause) => new PatchError({ operation: "reset", directory: input.path, message: cause.message, cause }),
|
(cause) => new PatchError({ operation: "reset", directory: input.path, message: cause.message, cause }),
|
||||||
),
|
),
|
||||||
@@ -937,7 +930,15 @@ export const layer = Layer.effect(
|
|||||||
change: { capture, apply, discard },
|
change: { capture, apply, discard },
|
||||||
worktree: { create: worktreeCreate, remove: worktreeRemove, list: worktreeList },
|
worktree: { create: worktreeCreate, remove: worktreeRemove, list: worktreeList },
|
||||||
index: { refresh, ignored },
|
index: { refresh, ignored },
|
||||||
tree: { capture: captureTree, write: writeTree, files: treeFiles, diff: treeDiff, preview, restore, checkout: checkoutTree },
|
tree: {
|
||||||
|
capture: captureTree,
|
||||||
|
write: writeTree,
|
||||||
|
files: treeFiles,
|
||||||
|
diff: treeDiff,
|
||||||
|
preview,
|
||||||
|
restore,
|
||||||
|
checkout: checkoutTree,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -169,7 +169,8 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Git.Service | E
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (status === "refreshed") {
|
if (status === "refreshed") {
|
||||||
if (!existing) return yield* new FetchFailedError({ repository, message: "Repository is unavailable" })
|
if (!existing)
|
||||||
|
return yield* new FetchFailedError({ repository, message: "Repository is unavailable" })
|
||||||
yield* git.sync
|
yield* git.sync
|
||||||
.fetchRemotes(existing)
|
.fetchRemotes(existing)
|
||||||
.pipe(Effect.mapError((error) => new FetchFailedError({ repository, message: error.message })))
|
.pipe(Effect.mapError((error) => new FetchFailedError({ repository, message: error.message })))
|
||||||
|
|||||||
@@ -172,7 +172,8 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/v2
|
|||||||
|
|
||||||
export const layer = Layer.unwrap(
|
export const layer = Layer.unwrap(
|
||||||
Effect.promise(() => import("./location-layer")).pipe(
|
Effect.promise(() => import("./location-layer")).pipe(
|
||||||
Effect.map(({ LocationServiceMap }) => Layer.effect(
|
Effect.map(({ LocationServiceMap }) =>
|
||||||
|
Layer.effect(
|
||||||
Service,
|
Service,
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const database = yield* Database.Service
|
const database = yield* Database.Service
|
||||||
@@ -302,7 +303,10 @@ export const layer = Layer.unwrap(
|
|||||||
.select({ seq: SessionMessageTable.seq })
|
.select({ seq: SessionMessageTable.seq })
|
||||||
.from(SessionMessageTable)
|
.from(SessionMessageTable)
|
||||||
.where(
|
.where(
|
||||||
and(eq(SessionMessageTable.session_id, input.sessionID), eq(SessionMessageTable.id, input.cursor.id)),
|
and(
|
||||||
|
eq(SessionMessageTable.session_id, input.sessionID),
|
||||||
|
eq(SessionMessageTable.id, input.cursor.id),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.get()
|
.get()
|
||||||
.pipe(Effect.orDie)
|
.pipe(Effect.orDie)
|
||||||
@@ -436,7 +440,9 @@ export const layer = Layer.unwrap(
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const defaultLayer = layer.pipe(
|
export const defaultLayer = layer.pipe(
|
||||||
Layer.provide(Layer.unwrap(Effect.promise(() => import("./location-layer")).pipe(Effect.map((m) => m.LocationServiceMap.layer)))),
|
Layer.provide(
|
||||||
|
Layer.unwrap(Effect.promise(() => import("./location-layer")).pipe(Effect.map((m) => m.LocationServiceMap.layer))),
|
||||||
|
),
|
||||||
Layer.provide(SessionExecution.noopLayer),
|
Layer.provide(SessionExecution.noopLayer),
|
||||||
Layer.provide(SessionStore.defaultLayer),
|
Layer.provide(SessionStore.defaultLayer),
|
||||||
Layer.provide(SessionProjector.defaultLayer),
|
Layer.provide(SessionProjector.defaultLayer),
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ export function fromRow(row: typeof SessionTable.$inferSelect): SessionSchema.In
|
|||||||
workspaceID: row.workspace_id ? WorkspaceV2.ID.make(row.workspace_id) : undefined,
|
workspaceID: row.workspace_id ? WorkspaceV2.ID.make(row.workspace_id) : undefined,
|
||||||
}),
|
}),
|
||||||
subpath: row.path ? RelativePath.make(row.path) : undefined,
|
subpath: row.path ? RelativePath.make(row.path) : undefined,
|
||||||
revert: row.revert
|
revert: row.revert ? { ...row.revert, messageID: SessionMessageID.ID.make(row.revert.messageID) } : undefined,
|
||||||
? { ...row.revert, messageID: SessionMessageID.ID.make(row.revert.messageID) }
|
|
||||||
: undefined,
|
|
||||||
time: {
|
time: {
|
||||||
created: DateTime.makeUnsafe(row.time_created),
|
created: DateTime.makeUnsafe(row.time_created),
|
||||||
updated: DateTime.makeUnsafe(row.time_updated),
|
updated: DateTime.makeUnsafe(row.time_updated),
|
||||||
|
|||||||
@@ -418,13 +418,38 @@ export const layer = Layer.effectDiscard(
|
|||||||
const boundary = yield* db
|
const boundary = yield* db
|
||||||
.select({ seq: SessionMessageTable.seq })
|
.select({ seq: SessionMessageTable.seq })
|
||||||
.from(SessionMessageTable)
|
.from(SessionMessageTable)
|
||||||
.where(and(eq(SessionMessageTable.session_id, event.data.sessionID), eq(SessionMessageTable.id, event.data.messageID)))
|
.where(
|
||||||
|
and(
|
||||||
|
eq(SessionMessageTable.session_id, event.data.sessionID),
|
||||||
|
eq(SessionMessageTable.id, event.data.messageID),
|
||||||
|
),
|
||||||
|
)
|
||||||
.get()
|
.get()
|
||||||
.pipe(Effect.orDie)
|
.pipe(Effect.orDie)
|
||||||
if (!boundary) return yield* Effect.die(`Revert boundary message not found: ${event.data.messageID}`)
|
if (!boundary) return yield* Effect.die(`Revert boundary message not found: ${event.data.messageID}`)
|
||||||
yield* db.delete(SessionMessageTable).where(and(eq(SessionMessageTable.session_id, event.data.sessionID), gt(SessionMessageTable.seq, boundary.seq))).run().pipe(Effect.orDie)
|
yield* db
|
||||||
yield* db.delete(SessionInputTable).where(and(eq(SessionInputTable.session_id, event.data.sessionID), or(gt(SessionInputTable.admitted_seq, boundary.seq), gt(SessionInputTable.promoted_seq, boundary.seq)))).run().pipe(Effect.orDie)
|
.delete(SessionMessageTable)
|
||||||
yield* db.update(SessionTable).set({ revert: null, time_updated: DateTime.toEpochMillis(event.data.timestamp) }).where(eq(SessionTable.id, event.data.sessionID)).run().pipe(Effect.orDie)
|
.where(
|
||||||
|
and(eq(SessionMessageTable.session_id, event.data.sessionID), gt(SessionMessageTable.seq, boundary.seq)),
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
.pipe(Effect.orDie)
|
||||||
|
yield* db
|
||||||
|
.delete(SessionInputTable)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(SessionInputTable.session_id, event.data.sessionID),
|
||||||
|
or(gt(SessionInputTable.admitted_seq, boundary.seq), gt(SessionInputTable.promoted_seq, boundary.seq)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run()
|
||||||
|
.pipe(Effect.orDie)
|
||||||
|
yield* db
|
||||||
|
.update(SessionTable)
|
||||||
|
.set({ revert: null, time_updated: DateTime.toEpochMillis(event.data.timestamp) })
|
||||||
|
.where(eq(SessionTable.id, event.data.sessionID))
|
||||||
|
.run()
|
||||||
|
.pipe(Effect.orDie)
|
||||||
yield* SessionContextEpoch.reset(db, event.data.sessionID)
|
yield* SessionContextEpoch.reset(db, event.data.sessionID)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export const stage = Effect.fn("SessionRevert.stage")(function* (input: {
|
|||||||
const events = yield* EventV2.Service
|
const events = yield* EventV2.Service
|
||||||
const original = input.session.revert?.snapshot
|
const original = input.session.revert?.snapshot
|
||||||
? Snapshot.ID.make(input.session.revert.snapshot)
|
? Snapshot.ID.make(input.session.revert.snapshot)
|
||||||
: (yield* snapshot.capture())
|
: yield* snapshot.capture()
|
||||||
const next = yield* plan({ sessionID: input.session.id, messageID: input.messageID })
|
const next = yield* plan({ sessionID: input.session.id, messageID: input.messageID })
|
||||||
const restore = new Map<RelativePath, Snapshot.ID>()
|
const restore = new Map<RelativePath, Snapshot.ID>()
|
||||||
if (original) {
|
if (original) {
|
||||||
@@ -81,7 +81,10 @@ export const stage = Effect.fn("SessionRevert.stage")(function* (input: {
|
|||||||
const revert = {
|
const revert = {
|
||||||
messageID: input.messageID,
|
messageID: input.messageID,
|
||||||
snapshot: original,
|
snapshot: original,
|
||||||
diff: files.map((file) => file.patch).join("").trim(),
|
diff: files
|
||||||
|
.map((file) => file.patch)
|
||||||
|
.join("")
|
||||||
|
.trim(),
|
||||||
files,
|
files,
|
||||||
} satisfies SessionSchema.Info["revert"]
|
} satisfies SessionSchema.Info["revert"]
|
||||||
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
||||||
|
|||||||
@@ -309,10 +309,14 @@ export const layer = Layer.effect(
|
|||||||
const stepSettlement = publisher.stepSettlement()
|
const stepSettlement = publisher.stepSettlement()
|
||||||
if (stepSettlement && !publisher.hasProviderError()) {
|
if (stepSettlement && !publisher.hasProviderError()) {
|
||||||
const endSnapshot = yield* snapshots.capture()
|
const endSnapshot = yield* snapshots.capture()
|
||||||
const files = startSnapshot && endSnapshot
|
const files =
|
||||||
? yield* snapshots.files({ from: startSnapshot, to: endSnapshot }).pipe(Effect.catch(() => Effect.succeed(undefined)))
|
startSnapshot && endSnapshot
|
||||||
|
? yield* snapshots
|
||||||
|
.files({ from: startSnapshot, to: endSnapshot })
|
||||||
|
.pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||||
: undefined
|
: undefined
|
||||||
yield* withPublication(events.publish(SessionEvent.Step.Ended, {
|
yield* withPublication(
|
||||||
|
events.publish(SessionEvent.Step.Ended, {
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
timestamp: yield* DateTime.now,
|
timestamp: yield* DateTime.now,
|
||||||
assistantMessageID: yield* publisher.startAssistant(),
|
assistantMessageID: yield* publisher.startAssistant(),
|
||||||
@@ -321,7 +325,8 @@ export const layer = Layer.effect(
|
|||||||
tokens: stepSettlement.tokens,
|
tokens: stepSettlement.tokens,
|
||||||
snapshot: endSnapshot,
|
snapshot: endSnapshot,
|
||||||
files,
|
files,
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (publisher.hasProviderError())
|
if (publisher.hasProviderError())
|
||||||
yield* withPublication(publisher.failUnsettledTools("Tool execution interrupted"))
|
yield* withPublication(publisher.failUnsettledTools("Tool execution interrupted"))
|
||||||
|
|||||||
@@ -111,11 +111,13 @@ export const layer = Layer.effect(
|
|||||||
gitDirectory,
|
gitDirectory,
|
||||||
commonDirectory: gitDirectory,
|
commonDirectory: gitDirectory,
|
||||||
})
|
})
|
||||||
return yield* git.repo.create({
|
return yield* git.repo
|
||||||
|
.create({
|
||||||
worktree,
|
worktree,
|
||||||
gitDirectory,
|
gitDirectory,
|
||||||
seed: source,
|
seed: source,
|
||||||
}).pipe(Effect.mapError((cause) => failure("capture", cause)))
|
})
|
||||||
|
.pipe(Effect.mapError((cause) => failure("capture", cause)))
|
||||||
})
|
})
|
||||||
|
|
||||||
const enabled = Effect.fnUntraced(function* () {
|
const enabled = Effect.fnUntraced(function* () {
|
||||||
@@ -136,9 +138,7 @@ export const layer = Layer.effect(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
Effect.catch((cause) =>
|
Effect.catch((cause) => Effect.logWarning("failed to capture snapshot", { cause }).pipe(Effect.as(undefined))),
|
||||||
Effect.logWarning("failed to capture snapshot", { cause }).pipe(Effect.as(undefined)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -189,12 +189,14 @@ export const layer = Layer.effect(
|
|||||||
if (!(yield* enabled())) return yield* new Error({ operation: "preview", message: "Snapshots are disabled" })
|
if (!(yield* enabled())) return yield* new Error({ operation: "preview", message: "Snapshots are disabled" })
|
||||||
const repo = yield* repository().pipe(Effect.mapError((cause) => failure("preview", cause)))
|
const repo = yield* repository().pipe(Effect.mapError((cause) => failure("preview", cause)))
|
||||||
const files = yield* plan("preview", input)
|
const files = yield* plan("preview", input)
|
||||||
const current = yield* git.tree.capture({
|
const current = yield* git.tree
|
||||||
|
.capture({
|
||||||
repository: repo,
|
repository: repo,
|
||||||
scopes: Array.from(files.keys()),
|
scopes: Array.from(files.keys()),
|
||||||
ignores: source,
|
ignores: source,
|
||||||
maximumUntrackedFileBytes: 2 * 1024 * 1024,
|
maximumUntrackedFileBytes: 2 * 1024 * 1024,
|
||||||
}).pipe(Effect.mapError((cause) => failure("preview", cause)))
|
})
|
||||||
|
.pipe(Effect.mapError((cause) => failure("preview", cause)))
|
||||||
return yield* git.tree
|
return yield* git.tree
|
||||||
.preview({
|
.preview({
|
||||||
repository: repo,
|
repository: repo,
|
||||||
|
|||||||
@@ -46,18 +46,52 @@ describe("SessionProjector", () => {
|
|||||||
it.effect("projects staged, cleared, and committed reverts", () =>
|
it.effect("projects staged, cleared, and committed reverts", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const db = (yield* Database.Service).db
|
const db = (yield* Database.Service).db
|
||||||
yield* db.insert(ProjectTable).values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] }).run()
|
yield* db
|
||||||
yield* db.insert(SessionTable).values({ id: sessionID, project_id: Project.ID.global, slug: "test", directory: "/project", title: "test", version: "test" }).run()
|
.insert(ProjectTable)
|
||||||
|
.values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] })
|
||||||
|
.run()
|
||||||
|
yield* db
|
||||||
|
.insert(SessionTable)
|
||||||
|
.values({
|
||||||
|
id: sessionID,
|
||||||
|
project_id: Project.ID.global,
|
||||||
|
slug: "test",
|
||||||
|
directory: "/project",
|
||||||
|
title: "test",
|
||||||
|
version: "test",
|
||||||
|
})
|
||||||
|
.run()
|
||||||
const boundary = SessionMessage.ID.make("msg_boundary")
|
const boundary = SessionMessage.ID.make("msg_boundary")
|
||||||
yield* db.insert(SessionMessageTable).values([assistantRow(boundary, 1), assistantRow(SessionMessage.ID.make("msg_later"), 2)]).run()
|
yield* db
|
||||||
|
.insert(SessionMessageTable)
|
||||||
|
.values([assistantRow(boundary, 1), assistantRow(SessionMessage.ID.make("msg_later"), 2)])
|
||||||
|
.run()
|
||||||
const events = yield* EventV2.Service
|
const events = yield* EventV2.Service
|
||||||
yield* events.publish(SessionEvent.RevertEvent.Staged, { sessionID, timestamp: DateTime.makeUnsafe(1), revert: { messageID: boundary, snapshot: Snapshot.ID.make("tree"), diff: "patch", files: [] } })
|
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
||||||
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toMatchObject({ messageID: boundary, snapshot: "tree", files: [] })
|
sessionID,
|
||||||
|
timestamp: DateTime.makeUnsafe(1),
|
||||||
|
revert: { messageID: boundary, snapshot: Snapshot.ID.make("tree"), diff: "patch", files: [] },
|
||||||
|
})
|
||||||
|
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toMatchObject({
|
||||||
|
messageID: boundary,
|
||||||
|
snapshot: "tree",
|
||||||
|
files: [],
|
||||||
|
})
|
||||||
yield* events.publish(SessionEvent.RevertEvent.Cleared, { sessionID, timestamp: DateTime.makeUnsafe(2) })
|
yield* events.publish(SessionEvent.RevertEvent.Cleared, { sessionID, timestamp: DateTime.makeUnsafe(2) })
|
||||||
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toBeNull()
|
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toBeNull()
|
||||||
yield* events.publish(SessionEvent.RevertEvent.Staged, { sessionID, timestamp: DateTime.makeUnsafe(3), revert: { messageID: boundary, files: [] } })
|
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
||||||
yield* events.publish(SessionEvent.RevertEvent.Committed, { sessionID, messageID: boundary, timestamp: DateTime.makeUnsafe(4) })
|
sessionID,
|
||||||
expect((yield* db.select({ id: SessionMessageTable.id }).from(SessionMessageTable).all()).map((row) => row.id)).toEqual([boundary])
|
timestamp: DateTime.makeUnsafe(3),
|
||||||
|
revert: { messageID: boundary, files: [] },
|
||||||
|
})
|
||||||
|
yield* events.publish(SessionEvent.RevertEvent.Committed, {
|
||||||
|
sessionID,
|
||||||
|
messageID: boundary,
|
||||||
|
timestamp: DateTime.makeUnsafe(4),
|
||||||
|
})
|
||||||
|
expect(
|
||||||
|
(yield* db.select({ id: SessionMessageTable.id }).from(SessionMessageTable).all()).map((row) => row.id),
|
||||||
|
).toEqual([boundary])
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,12 @@ describe("Snapshot", () => {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
expect(yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(project))))).toBeDefined()
|
expect(
|
||||||
expect(yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(linked))))).toBeDefined()
|
yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(project)))),
|
||||||
|
).toBeDefined()
|
||||||
|
expect(
|
||||||
|
yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(linked)))),
|
||||||
|
).toBeDefined()
|
||||||
}),
|
}),
|
||||||
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
),
|
),
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -58,7 +58,11 @@ export const MessageHandler = HttpApiBuilder.group(Api, "server.message", (handl
|
|||||||
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
||||||
return Effect.logError("failed to decode session message").pipe(
|
return Effect.logError("failed to decode session message").pipe(
|
||||||
Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }),
|
Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }),
|
||||||
Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))),
|
Effect.andThen(
|
||||||
|
Effect.fail(
|
||||||
|
new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -307,7 +307,11 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
|||||||
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
||||||
return Effect.logError("failed to decode session message").pipe(
|
return Effect.logError("failed to decode session message").pipe(
|
||||||
Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }),
|
Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }),
|
||||||
Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))),
|
Effect.andThen(
|
||||||
|
Effect.fail(
|
||||||
|
new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user