mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
refactor(core): simplify persistence runtime code (#43954)
This commit is contained in:
committed by
GitHub
Unverified
parent
6c3c4bc50f
commit
b3d6063329
@@ -51,7 +51,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/Cr
|
||||
const layer = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const { db } = yield* Database.Service
|
||||
const db = (yield* Database.Service).db
|
||||
const decode = Schema.decodeUnknownSync(Value)
|
||||
const stored = (row: typeof CredentialTable.$inferSelect) => {
|
||||
if (!row.integration_id) return
|
||||
|
||||
@@ -481,7 +481,7 @@ export function transformSession(input: TransformInput): TransformResult {
|
||||
|
||||
export function status(): Effect.Effect<Status, never, Database.Service> {
|
||||
return Effect.gen(function* () {
|
||||
const { db } = yield* Database.Service
|
||||
const db = (yield* Database.Service).db
|
||||
if (!(yield* hasLegacySessions(db))) return { status: "completed" as const }
|
||||
const state = yield* readState(db)
|
||||
if (runtimeState.status === "running") return runtimeState
|
||||
@@ -523,7 +523,7 @@ function updateProgress(progress: Progress) {
|
||||
export function run(options: Options = {}): Effect.Effect<RunResult, never, Database.Service | Global.Service> {
|
||||
return lock.withPermit(
|
||||
Effect.gen(function* () {
|
||||
const { db } = yield* Database.Service
|
||||
const db = (yield* Database.Service).db
|
||||
const global = yield* Global.Service
|
||||
const state = yield* readState(db)
|
||||
if (state?.phase === "completed") return { status: "completed" as const }
|
||||
|
||||
@@ -23,13 +23,13 @@ const environmentValue = (environment: Environment, name: string) =>
|
||||
const bypassesProxy = (url: URL, value: string | undefined) => {
|
||||
if (!value) return false
|
||||
const port = url.port || (url.protocol === "wss:" ? "443" : "80")
|
||||
const hostname = url.hostname.toLowerCase()
|
||||
return value.split(/[\s,]+/).some((entry) => {
|
||||
if (!entry) return false
|
||||
if (entry === "*") return true
|
||||
const match = entry.match(/^(.+?):(\d+)$/)
|
||||
if (match?.[2] && match[2] !== port) return false
|
||||
const host = (match?.[1] ?? entry).toLowerCase().replace(/^\*/, "")
|
||||
const hostname = url.hostname.toLowerCase()
|
||||
return host.startsWith(".") ? hostname.endsWith(host) : hostname === host
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/KV
|
||||
const layer = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const { db } = yield* Database.Service
|
||||
const db = (yield* Database.Service).db
|
||||
return Service.of({
|
||||
get: Effect.fn("KV.get")(function* (key) {
|
||||
return (yield* db
|
||||
|
||||
@@ -177,7 +177,7 @@ const layer = Layer.effect(
|
||||
return false
|
||||
})
|
||||
|
||||
function denied(input: AssertInput, rules: Permission.Ruleset) {
|
||||
function denied(input: Pick<Request, "action" | "resources">, rules: Permission.Ruleset) {
|
||||
return input.resources.some((resource) => evaluate(input.action, resource, rules).effect === "deny")
|
||||
}
|
||||
|
||||
@@ -301,12 +301,11 @@ const layer = Layer.effect(
|
||||
|
||||
const rememberedRules = yield* savedRules()
|
||||
for (const [id, item] of pending) {
|
||||
const input = { ...item.request }
|
||||
const rules = yield* configured(item.request.sessionID, item.agent).pipe(
|
||||
Effect.catchTag("Session.NotFoundError", () => Effect.succeed(undefined)),
|
||||
)
|
||||
if (!rules) continue
|
||||
if (denied(input, rules)) continue
|
||||
if (denied(item.request, rules)) continue
|
||||
const effective = [...rules, ...rememberedRules]
|
||||
if (
|
||||
!item.request.resources.every(
|
||||
|
||||
@@ -37,7 +37,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/Pe
|
||||
const layer = Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const { db } = yield* Database.Service
|
||||
const db = (yield* Database.Service).db
|
||||
|
||||
const list = Effect.fnUntraced(function* (input?: ListInput) {
|
||||
const rows = yield* db
|
||||
|
||||
@@ -185,7 +185,7 @@ const layer = Layer.effect(
|
||||
return `${host.toLowerCase()}/${pathname}`
|
||||
}
|
||||
|
||||
const root = Effect.fnUntraced(function* (repo: Git.Repository) {
|
||||
const rootCommit = Effect.fnUntraced(function* (repo: Git.Repository) {
|
||||
const root = (yield* git.history.rootCommits(repo))[0]
|
||||
return root ? ID.make(root) : undefined
|
||||
})
|
||||
@@ -235,7 +235,7 @@ const layer = Layer.effect(
|
||||
const repo = yield* git.repo.discover(input)
|
||||
if (repo) {
|
||||
const previous = yield* cached(repo.commonDirectory)
|
||||
const id = (yield* remote(repo)) ?? previous ?? (yield* root(repo))
|
||||
const id = (yield* remote(repo)) ?? previous ?? (yield* rootCommit(repo))
|
||||
const canonical =
|
||||
repo.gitDirectory === repo.commonDirectory
|
||||
? repo.worktree
|
||||
|
||||
Reference in New Issue
Block a user