refactor(core): replace unused runtime input schemas with types in filesystem and permission (#57961)

This commit is contained in:
Aiden Cline
2026-10-21 20:06:18 -05:00
committed by GitHub
Unverified
parent b6c0327e18
commit 9496ff842c
6 changed files with 51 additions and 74 deletions
+10 -13
View File
@@ -10,17 +10,15 @@ import { FileSystemSearch } from "./filesystem/search.js"
import { Entry, FileSystem, FindInput, Write } from "@opencode/schema/filesystem"
export { Entry, Match, Submatch } from "@opencode/schema/filesystem"
export const ReadInput = Schema.Struct({
path: RelativePath,
})
export type ReadInput = typeof ReadInput.Type
export interface ReadInput {
readonly path: RelativePath
}
export const WriteInput = Schema.Struct({
export interface WriteInput {
/** Absolute, or relative to the location directory. */
path: Schema.String,
data: Schema.Uint8Array,
})
export type WriteInput = typeof WriteInput.Type
readonly path: string
readonly data: Uint8Array
}
export class NotFoundError extends Schema.TaggedError<NotFoundError>()("FileSystem.NotFoundError", {
path: RelativePath,
@@ -59,10 +57,9 @@ export const Content = Schema.Struct({
}).annotate({ identifier: "FileSystem.Content" })
export type Content = typeof Content.Type
export const ListInput = Schema.Struct({
path: Schema.String.pipe(Schema.optional),
})
export type ListInput = typeof ListInput.Type
export interface ListInput {
readonly path?: string
}
export { FindInput, Write }
+6 -7
View File
@@ -2,7 +2,7 @@ export * as FileSystemSearch from "./search.js"
import { makeLocationNode } from "@opencode/util/effect/app-node"
import path from "path"
import { Clock, Context, Deferred, Duration, Effect, Layer, Schema, Scope } from "effect"
import { Clock, Context, Deferred, Duration, Effect, Layer, Scope } from "effect"
import { Fff } from "#fff"
import fuzzysort from "fuzzysort"
import { FileSystem } from "@opencode/schema/filesystem"
@@ -15,10 +15,9 @@ export interface Interface {
readonly find: (input: FileSystem.FindInput) => Effect.Effect<FileSystem.Entry[]>
}
export const Options = Schema.Struct({
fff: Schema.optional(Schema.Boolean),
})
export type Options = typeof Options.Type
export interface Options {
readonly fff?: boolean
}
export class Service extends Context.Service<Service, Interface>()("@opencode/FileSystem/Search") {}
@@ -50,7 +49,7 @@ function search(index: ReturnType<typeof emptyIndex>, input: FileSystem.FindInpu
})
}
export const ripgrepLayer = Layer.effect(
const ripgrepLayer = Layer.effect(
Service,
Effect.gen(function* () {
const location = yield* Location.Service
@@ -181,7 +180,7 @@ export const fffLayer = Layer.effect(
}),
)
export const layer = (options?: Options) =>
const layer = (options?: Options) =>
Layer.unwrap(
Effect.gen(function* () {
const location = yield* Location.Service
+7 -10
View File
@@ -3,17 +3,15 @@ export * as Watcher from "./watcher.js"
// @ts-ignore
import { createWrapper } from "@parcel/watcher/wrapper.js"
import type ParcelWatcher from "@parcel/watcher"
import { FileSystem } from "@opencode/schema/filesystem"
import { makeGlobalNode } from "@opencode/util/effect/app-node"
import { FSUtil } from "@opencode/util/fs-util"
import { Cause, Context, Effect, Layer, PubSub, RcMap, Schema, Stream } from "effect"
import { Cause, Context, Effect, Layer, PubSub, RcMap, Stream } from "effect"
import { lazy } from "../util/lazy.js"
import { watch } from "node:fs"
import path from "path"
import loadBinding from "./watcher-binding.js"
const SUBSCRIBE_TIMEOUT_MS = 10_000
export const Event = { Updated: FileSystem.Event.Changed }
const watcher = lazy((): typeof ParcelWatcher | undefined => {
try {
@@ -37,7 +35,7 @@ export type WatchInput =
| { readonly path: string; readonly type: "entries"; readonly names: readonly string[] }
| { readonly path: string; readonly type: "directory"; readonly ignore?: readonly string[] }
export type Subscription = {
type Subscription = {
readonly unsubscribe: () => Promise<void>
/** Backend name for logging, e.g. "node" or "fs-events". */
readonly backend?: string
@@ -65,14 +63,13 @@ export interface Interface {
readonly subscribe: (input: WatchInput, onReady?: Effect.Effect<void>) => Effect.Effect<Stream.Stream<Update>>
}
export const Options = Schema.Struct({
enabled: Schema.optional(Schema.Boolean),
})
export type Options = typeof Options.Type
export interface Options {
readonly enabled?: boolean
}
export class Service extends Context.Service<Service, Interface>()("@opencode/Watcher") {}
export interface TestInterface extends Interface {
interface TestInterface extends Interface {
/** Delivers one update to every active watch whose target covers `update.path`. */
readonly emit: (update: Update) => Effect.Effect<void>
/** Returns every subscribe call observed so far, in order. */
@@ -226,7 +223,7 @@ export const nativeLayer = Layer.succeed(
}),
)
export const nativeNode = makeGlobalNode({ service: Native, layer: nativeLayer, deps: [] })
const nativeNode = makeGlobalNode({ service: Native, layer: nativeLayer, deps: [] })
export function configured(options?: Options) {
return makeGlobalNode({ service: Service, layer: layer(options), deps: [nativeNode] })
+13 -26
View File
@@ -24,40 +24,27 @@ export type ID = typeof ID.Type
export const Source = Permission.Source
export type Source = typeof Source.Type
const RequestFields = {
sessionID: Permission.Request.fields.sessionID,
action: Permission.Request.fields.action,
resources: Permission.Request.fields.resources,
save: Permission.Request.fields.save,
metadata: Permission.Request.fields.metadata,
source: Permission.Request.fields.source,
}
export const Request = Permission.Request
export type Request = typeof Request.Type
export const Reply = Permission.Reply
export type Reply = typeof Reply.Type
export const AssertInput = Schema.Struct({
id: ID.pipe(Schema.optional),
...RequestFields,
agent: Agent.ID.pipe(Schema.optional),
}).annotate({ identifier: "Permission.AssertInput" })
export type AssertInput = typeof AssertInput.Type
export interface AssertInput extends Omit<Request, "id" | "message"> {
readonly id?: ID
readonly agent?: Agent.ID
}
export const ReplyInput = Schema.Struct({
requestID: ID,
reply: Reply,
message: Schema.String.pipe(Schema.optional),
}).annotate({ identifier: "Permission.ReplyInput" })
export type ReplyInput = typeof ReplyInput.Type
export interface ReplyInput {
readonly requestID: ID
readonly reply: Reply
readonly message?: string
}
export const AskResult = Schema.Struct({
id: ID,
effect: Permission.Effect,
}).annotate({ identifier: "Permission.AskResult" })
export type AskResult = typeof AskResult.Type
export interface AskResult {
readonly id: ID
readonly effect: Permission.Effect
}
export { Event } from "@opencode/schema/permission"
+14 -17
View File
@@ -4,7 +4,7 @@ import { eq } from "drizzle-orm"
import { Cause, Context, DateTime, Effect, Layer, Schema } from "effect"
import { isSqlError } from "effect/sql/SqlError"
import type { EffectDrizzleQueryError } from "drizzle-orm/effect-core/errors"
import { Project } from "@opencode/schema/project"
import type { Project } from "@opencode/schema/project"
import { Database } from "../database/database.js"
import { makeGlobalNode } from "@opencode/util/effect/app-node"
import { PermissionTable } from "./sql.js"
@@ -16,24 +16,21 @@ export type ID = typeof ID.Type
export const Info = PermissionSaved.Info
export type Info = typeof Info.Type
export const ListInput = Schema.Struct({
projectID: Project.ID.pipe(Schema.optional),
}).annotate({ identifier: "PermissionSaved.ListInput" })
export type ListInput = typeof ListInput.Type
export interface ListInput {
readonly projectID?: Project.ID
}
export const AddInput = Schema.Struct({
projectID: Project.ID,
action: Schema.String,
resources: Schema.Array(Schema.String),
}).annotate({ identifier: "PermissionSaved.AddInput" })
export type AddInput = typeof AddInput.Type
export interface AddInput {
readonly projectID: Project.ID
readonly action: string
readonly resources: readonly string[]
}
export const UpdateInput = Schema.Struct({
id: ID,
action: Schema.String.pipe(Schema.optional),
resource: Schema.String.pipe(Schema.optional),
}).annotate({ identifier: "PermissionSaved.UpdateInput" })
export type UpdateInput = typeof UpdateInput.Type
export interface UpdateInput {
readonly id: ID
readonly action?: string
readonly resource?: string
}
export class NotFoundError extends Schema.TaggedError<NotFoundError>()("PermissionSaved.NotFoundError", {
id: ID,
+1 -1
View File
@@ -2,7 +2,7 @@ import { sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core"
import type { Project } from "@opencode/schema/project"
import { Timestamps } from "../database/schema.sql.js"
import { ProjectTable } from "../project/sql.js"
import type { PermissionSaved } from "./saved.js"
import type { PermissionSaved } from "@opencode/schema/permission-saved"
export const PermissionTable = sqliteTable(
"permission",