diff --git a/packages/core/src/filesystem.ts b/packages/core/src/filesystem.ts index bd81f0b160e..ab421a7737a 100644 --- a/packages/core/src/filesystem.ts +++ b/packages/core/src/filesystem.ts @@ -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()("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 } diff --git a/packages/core/src/filesystem/search.ts b/packages/core/src/filesystem/search.ts index 7b32acee3db..22cfb74d98f 100644 --- a/packages/core/src/filesystem/search.ts +++ b/packages/core/src/filesystem/search.ts @@ -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 } -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()("@opencode/FileSystem/Search") {} @@ -50,7 +49,7 @@ function search(index: ReturnType, 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 diff --git a/packages/core/src/filesystem/watcher.ts b/packages/core/src/filesystem/watcher.ts index b5c438661d0..f33413bfb02 100644 --- a/packages/core/src/filesystem/watcher.ts +++ b/packages/core/src/filesystem/watcher.ts @@ -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 /** 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) => Effect.Effect> } -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()("@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 /** 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] }) diff --git a/packages/core/src/permission.ts b/packages/core/src/permission.ts index 1dc798807b6..37d58111af0 100644 --- a/packages/core/src/permission.ts +++ b/packages/core/src/permission.ts @@ -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 { + 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" diff --git a/packages/core/src/permission/saved.ts b/packages/core/src/permission/saved.ts index 78aa4124c84..58cd16bb6c8 100644 --- a/packages/core/src/permission/saved.ts +++ b/packages/core/src/permission/saved.ts @@ -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()("PermissionSaved.NotFoundError", { id: ID, diff --git a/packages/core/src/permission/sql.ts b/packages/core/src/permission/sql.ts index 4283f13411a..a0967603ee2 100644 --- a/packages/core/src/permission/sql.ts +++ b/packages/core/src/permission/sql.ts @@ -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",