From cfcf754314f18325bbe7abca9a488e06f6cb17bf Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:58:31 -0500 Subject: [PATCH] refactor(core): drop redundant decoding and branding in config, agent, and skill (#57953) --- packages/core/src/agent.ts | 9 +++---- packages/core/src/config/plugin/agent.ts | 10 +++----- packages/core/src/config/plugin/command.ts | 10 +++----- packages/core/src/skill.ts | 7 +++--- packages/core/src/v1/config/migrate.ts | 29 ++++++++++------------ 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/packages/core/src/agent.ts b/packages/core/src/agent.ts index cd5429319e7..d574e7528b0 100644 --- a/packages/core/src/agent.ts +++ b/packages/core/src/agent.ts @@ -40,7 +40,7 @@ export type Editor = { export interface Interface extends State.Transformable { readonly get: (id: ID) => Effect.Effect readonly resolve: (id?: ID | string) => Effect.Effect - readonly select: (id?: ID | string) => Effect.Effect + readonly select: (id?: ID) => Effect.Effect readonly list: () => Effect.Effect } @@ -77,7 +77,7 @@ const layer = Layer.effect( const data = state.get() const configured = data.default ? selectable(data.agents.get(data.default)) : undefined if (configured) return configured - const build = selectable(data.agents.get(ID.make("build"))) + const build = selectable(data.agents.get(defaultID)) if (build) return build for (const agent of data.agents.values()) { const fallback = selectable(agent) @@ -96,10 +96,7 @@ const layer = Layer.effect( return selectedDefault() }), select: Effect.fn("Agent.select")(function* (id) { - if (id !== undefined) { - const selected = ID.make(id) - return { id: selected, info: state.get().agents.get(selected) } - } + if (id !== undefined) return { id, info: state.get().agents.get(id) } const info = selectedDefault() return { id: info?.id ?? defaultID, info } }), diff --git a/packages/core/src/config/plugin/agent.ts b/packages/core/src/config/plugin/agent.ts index 1d3949d015e..57abeef1f58 100644 --- a/packages/core/src/config/plugin/agent.ts +++ b/packages/core/src/config/plugin/agent.ts @@ -26,7 +26,6 @@ const legacySources = [ const sourceDirectories = ["agent", "agents", "mode", "modes"] as const const decodeAgent = Schema.decodeUnknownOption(ConfigAgent.Info) const decodeLegacyAgent = Schema.decodeUnknownOption(ConfigAgentV1.Info) -const decodeConfig = Schema.decodeUnknownOption(Info) type PathAction = FileAccess.ExternalDirectoryAuthorization["action"] | typeof ReadTool.name | typeof EditTool.name const pathActions = ["external_directory", "read", "edit"] as const satisfies readonly PathAction[] const agentKeys = new Set(["variant", ...Object.keys(ConfigAgent.Info.fields)]) @@ -202,11 +201,8 @@ function decode(file: { directory: string; filepath: string; primary: boolean }, ) : Option.getOrUndefined(decodeAgent({ ...data, system: body }, { errors: "all" })) if (!agent) return - const info = Option.getOrUndefined( - decodeConfig({ - agents: { [name]: file.primary ? { ...agent, mode: "primary" } : agent }, - }), - ) - if (!info) return + const info = Info.make({ + agents: { [name]: file.primary ? ConfigAgent.Info.make({ ...agent, mode: "primary" }) : agent }, + }) return new Document({ type: "document", path: AbsolutePath.make(file.filepath), info }) } diff --git a/packages/core/src/config/plugin/command.ts b/packages/core/src/config/plugin/command.ts index a029fb8adef..5dc6c140acf 100644 --- a/packages/core/src/config/plugin/command.ts +++ b/packages/core/src/config/plugin/command.ts @@ -3,8 +3,6 @@ export * as ConfigCommandPlugin from "./command.js" import { define } from "@opencode/plugin/effect/plugin" import { Info, type Entry } from "@opencode/schema/config" import { ConfigCommand } from "@opencode/schema/config/command" -import { Model } from "@opencode/schema/model" -import { Provider } from "@opencode/schema/provider" import { AppProcess } from "@opencode/util/process" import path from "path" import { Effect, Option, PubSub, Schema, Stream } from "effect" @@ -84,11 +82,9 @@ export const Plugin = define({ command.model === undefined ? commandAgent?.model : { - id: Model.ID.make(command.model.model), - providerID: Provider.ID.make(command.model.providerID), - ...(command.model.variant === undefined - ? {} - : { variant: Model.VariantID.make(command.model.variant) }), + id: command.model.model, + providerID: command.model.providerID, + ...(command.model.variant === undefined ? {} : { variant: command.model.variant }), } const text = yield* evaluateTemplate(command.template, input.prompt.text, { location, diff --git a/packages/core/src/skill.ts b/packages/core/src/skill.ts index 51cf0bc170a..8f7909e0e2e 100644 --- a/packages/core/src/skill.ts +++ b/packages/core/src/skill.ts @@ -104,13 +104,14 @@ const layer = Layer.effect( list: () => Array.from(editor.skills.values()), get: (id) => editor.skills.get(ID.make(id)), add: (skill) => { - editor.skills.set(skill.id, { ...skill } as Types.DeepMutable) + editor.skills.set(skill.id, { ...skill }) }, update: (id, update) => { - const current = editor.skills.get(ID.make(id)) + const key = ID.make(id) + const current = editor.skills.get(key) if (!current) return update(current) - current.id = ID.make(id) + current.id = key }, remove: (id) => { editor.skills.delete(ID.make(id)) diff --git a/packages/core/src/v1/config/migrate.ts b/packages/core/src/v1/config/migrate.ts index 569a0061d8e..2e59eb62667 100644 --- a/packages/core/src/v1/config/migrate.ts +++ b/packages/core/src/v1/config/migrate.ts @@ -13,7 +13,6 @@ import { Model } from "../../model.js" const decodeOptions = { errors: "all", onExcessProperty: "ignore" } as const const decodeAgent = Schema.decodeUnknownSync(Schema.fromJsonString(ConfigAgent.Info), decodeOptions) -const encodeAgent = Schema.encodeSync(ConfigAgent.Info) function permissions(info?: ConfigPermissionV1.Info) { const rules = (info ?? []).flatMap(([key, rule]) => { @@ -38,21 +37,19 @@ export function migrateAgent(info: ConfigAgentV1.Info) { ...(info.temperature === undefined ? {} : { temperature: info.temperature }), ...(info.top_p === undefined ? {} : { top_p: info.top_p }), } - return encodeAgent( - decodeAgent( - JSON.stringify({ - model: modelSelection(info.model, info.variant), - request: Object.keys(body).length ? { body } : undefined, - system: info.prompt, - description: info.description, - mode: info.mode, - hidden: info.hidden, - color: info.color === undefined ? undefined : info.color.startsWith("#") ? info.color : "#aaaaaa", - steps: info.steps, - disabled: info.disable, - permissions: permissions(info.permission), - }), - ), + return decodeAgent( + JSON.stringify({ + model: modelSelection(info.model, info.variant), + request: Object.keys(body).length ? { body } : undefined, + system: info.prompt, + description: info.description, + mode: info.mode, + hidden: info.hidden, + color: info.color === undefined ? undefined : info.color.startsWith("#") ? info.color : "#aaaaaa", + steps: info.steps, + disabled: info.disable, + permissions: permissions(info.permission), + }), ) }