GeezerVison is showing github.com — feat(httpapi): bridge catalog read endpoints (#24353) · ildella/opencode@eb02199
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/opencode/specs/effect/http-api.md +3-4Lines changed: 3 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -140,7 +140,7 @@ Use raw Effect HTTP routes where `HttpApi` does not fit. The goal is deleting Ho | 140 | 140 | | `file` | `bridged` partial | list/content/status only | | 141 | 141 | | `mcp` | `bridged` partial | status only | | 142 | 142 | | `workspace` | `bridged` | list, get, enter | | 143 | | -| top-level instance reads | `bridged` partial | path and vcs reads; command, agent, skill, lsp, formatter next | | | 143 | +| top-level instance reads | `bridged` | path, vcs, command, agent, skill, lsp, formatter | | 144 | 144 | | experimental JSON routes | `next/later` | console, tool, worktree, resource, global session list | | 145 | 145 | | `session` | `later/special` | large stateful surface plus streaming | | 146 | 146 | | `sync` | `later` | process/control side effects | | @@ -151,8 +151,7 @@ Use raw Effect HTTP routes where `HttpApi` does not fit. The goal is deleting Ho | 151 | 151 | ## Next PRs | 152 | 152 |
| 153 | 153 | 1. Produce a generated route inventory from Hono registrations and update `Current Route Status` with exact paths. | 154 | | -2. Continue porting top-level JSON reads. | 155 | | -3. Start the Effect OpenAPI/SDK generation path for already-bridged routes. | | 154 | +2. Start the Effect OpenAPI/SDK generation path for already-bridged routes. | 156 | 155 |
| 157 | 156 | ## Checklist | 158 | 157 |
| @@ -165,7 +164,7 @@ Use raw Effect HTTP routes where `HttpApi` does not fit. The goal is deleting Ho | 165 | 164 | - [x] Add bridge-level auth and instance tests. | 166 | 165 | - [ ] Complete exact Hono route inventory. | 167 | 166 | - [x] Resolve implemented-but-unmounted route groups. | 168 | | -- [ ] Port remaining JSON routes. | | 167 | +- [x] Port remaining top-level JSON reads. | 169 | 168 | - [ ] Generate SDK/OpenAPI from Effect routes. | 170 | 169 | - [ ] Flip ported JSON routes to default-on with fallback. | 171 | 170 | - [ ] Delete replaced Hono route implementations. | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/agent/agent.ts +29-30Lines changed: 29 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,6 @@ import z from "zod" | 3 | 3 | import { Provider } from "../provider" | 4 | 4 | import { ModelID, ProviderID } from "../provider/schema" | 5 | 5 | import { generateObject, streamObject, type ModelMessage } from "ai" | 6 | | -import { Instance } from "../project/instance" | 7 | 6 | import { Truncate } from "../tool" | 8 | 7 | import { Auth } from "../auth" | 9 | 8 | import { ProviderTransform } from "../provider" | @@ -19,37 +18,37 @@ import { Global } from "@opencode-ai/core/global" | 19 | 18 | import path from "path" | 20 | 19 | import { Plugin } from "@/plugin" | 21 | 20 | import { Skill } from "../skill" | 22 | | -import { Effect, Context, Layer } from "effect" | | 21 | +import { Effect, Context, Layer, Schema } from "effect" | 23 | 22 | import { InstanceState } from "@/effect" | 24 | 23 | import * as Option from "effect/Option" | 25 | 24 | import * as OtelTracer from "@effect/opentelemetry/Tracer" | | 25 | +import { zod } from "@/util/effect-zod" | | 26 | +import { withStatics, type DeepMutable } from "@/util/schema" | 26 | 27 |
| 27 | | -export const Info = z | 28 | | - .object({ | 29 | | - name: z.string(), | 30 | | - description: z.string().optional(), | 31 | | - mode: z.enum(["subagent", "primary", "all"]), | 32 | | - native: z.boolean().optional(), | 33 | | - hidden: z.boolean().optional(), | 34 | | - topP: z.number().optional(), | 35 | | - temperature: z.number().optional(), | 36 | | - color: z.string().optional(), | 37 | | - permission: Permission.Ruleset.zod, | 38 | | - model: z | 39 | | - .object({ | 40 | | - modelID: ModelID.zod, | 41 | | - providerID: ProviderID.zod, | 42 | | - }) | 43 | | - .optional(), | 44 | | - variant: z.string().optional(), | 45 | | - prompt: z.string().optional(), | 46 | | - options: z.record(z.string(), z.any()), | 47 | | - steps: z.number().int().positive().optional(), | 48 | | - }) | 49 | | - .meta({ | 50 | | - ref: "Agent", | 51 | | - }) | 52 | | -export type Info = z.infer<typeof Info> | | 28 | +export const Info = Schema.Struct({ | | 29 | + name: Schema.String, | | 30 | + description: Schema.optional(Schema.String), | | 31 | + mode: Schema.Literals(["subagent", "primary", "all"]), | | 32 | + native: Schema.optional(Schema.Boolean), | | 33 | + hidden: Schema.optional(Schema.Boolean), | | 34 | + topP: Schema.optional(Schema.Number), | | 35 | + temperature: Schema.optional(Schema.Number), | | 36 | + color: Schema.optional(Schema.String), | | 37 | + permission: Permission.Ruleset, | | 38 | + model: Schema.optional( | | 39 | + Schema.Struct({ | | 40 | + modelID: ModelID, | | 41 | + providerID: ProviderID, | | 42 | + }), | | 43 | + ), | | 44 | + variant: Schema.optional(Schema.String), | | 45 | + prompt: Schema.optional(Schema.String), | | 46 | + options: Schema.Record(Schema.String, Schema.Unknown), | | 47 | + steps: Schema.optional(Schema.Number), | | 48 | +}) | | 49 | + .annotate({ identifier: "Agent" }) | | 50 | + .pipe(withStatics((s) => ({ zod: zod(s) }))) | | 51 | +export type Info = DeepMutable<Schema.Schema.Type<typeof Info>> | 53 | 52 |
| 54 | 53 | export interface Interface { | 55 | 54 | readonly get: (agent: string) => Effect.Effect<Info> | @@ -79,7 +78,7 @@ export const layer = Layer.effect( | 79 | 78 | const provider = yield* Provider.Service | 80 | 79 |
| 81 | 80 | const state = yield* InstanceState.make<State>( | 82 | | - Effect.fn("Agent.state")(function* (_ctx) { | | 81 | + Effect.fn("Agent.state")(function* (ctx) { | 83 | 82 | const cfg = yield* config.get() | 84 | 83 | const skillDirs = yield* skill.dirs() | 85 | 84 | const whitelistedDirs = [Truncate.GLOB, ...skillDirs.map((dir) => path.join(dir, "*"))] | @@ -136,7 +135,7 @@ export const layer = Layer.effect( | 136 | 135 | edit: { | 137 | 136 | "*": "deny", | 138 | 137 | [path.join(".opencode", "plans", "*.md")]: "allow", | 139 | | - [path.relative(Instance.worktree, path.join(Global.Path.data, path.join("plans", "*.md")))]: "allow", | | 138 | + [path.relative(ctx.worktree, path.join(Global.Path.data, path.join("plans", "*.md")))]: "allow", | 140 | 139 | }, | 141 | 140 | }), | 142 | 141 | user, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/command/index.ts +16-17Lines changed: 16 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,8 @@ import type { InstanceContext } from "@/project/instance" | 5 | 5 | import { SessionID, MessageID } from "@/session/schema" | 6 | 6 | import { Effect, Layer, Context, Schema } from "effect" | 7 | 7 | import z from "zod" | | 8 | +import { zod, ZodOverride } from "@/util/effect-zod" | | 9 | +import { withStatics } from "@/util/schema" | 8 | 10 | import { Config } from "../config" | 9 | 11 | import { MCP } from "../mcp" | 10 | 12 | import { Skill } from "../skill" | @@ -27,25 +29,22 @@ export const Event = { | 27 | 29 | ), | 28 | 30 | } | 29 | 31 |
| 30 | | -export const Info = z | 31 | | - .object({ | 32 | | - name: z.string(), | 33 | | - description: z.string().optional(), | 34 | | - agent: z.string().optional(), | 35 | | - model: z.string().optional(), | 36 | | - source: z.enum(["command", "mcp", "skill"]).optional(), | 37 | | - // workaround for zod not supporting async functions natively so we use getters | 38 | | - // https://zod.dev/v4/changelog?id=zfunction | 39 | | - template: z.promise(z.string()).or(z.string()), | 40 | | - subtask: z.boolean().optional(), | 41 | | - hints: z.array(z.string()), | 42 | | - }) | 43 | | - .meta({ | 44 | | - ref: "Command", | 45 | | - }) | | 32 | +export const Info = Schema.Struct({ | | 33 | + name: Schema.String, | | 34 | + description: Schema.optional(Schema.String), | | 35 | + agent: Schema.optional(Schema.String), | | 36 | + model: Schema.optional(Schema.String), | | 37 | + source: Schema.optional(Schema.Literals(["command", "mcp", "skill"])), | | 38 | + // Some command templates are lazy promises from MCP prompt resolution. | | 39 | + template: Schema.Unknown.annotate({ [ZodOverride]: z.promise(z.string()).or(z.string()) }), | | 40 | + subtask: Schema.optional(Schema.Boolean), | | 41 | + hints: Schema.Array(Schema.String), | | 42 | +}) | | 43 | + .annotate({ identifier: "Command" }) | | 44 | + .pipe(withStatics((s) => ({ zod: zod(s) }))) | 46 | 45 |
| 47 | 46 | // for some reason zod is inferring `string` for z.promise(z.string()).or(z.string()) so we have to manually override it | 48 | | -export type Info = Omit<z.infer<typeof Info>, "template"> & { template: Promise<string> | string } | | 47 | +export type Info = Omit<Schema.Schema.Type<typeof Info>, "template"> & { template: Promise<string> | string } | 49 | 48 |
| 50 | 49 | export function hints(template: string) { | 51 | 50 | const result: string[] = [] | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/format/index.ts +11-12Lines changed: 11 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { Effect, Layer, Context } from "effect" | | 1 | +import { Effect, Layer, Context, Schema } from "effect" | 2 | 2 | import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process" | 3 | 3 | import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner" | 4 | 4 | import { InstanceState } from "@/effect" | 5 | 5 | import path from "path" | 6 | 6 | import { mergeDeep } from "remeda" | 7 | | -import z from "zod" | 8 | 7 | import { Config } from "../config" | 9 | 8 | import { Log } from "../util" | 10 | 9 | import * as Formatter from "./formatter" | | 10 | +import { zod } from "@/util/effect-zod" | | 11 | +import { withStatics } from "@/util/schema" | 11 | 12 |
| 12 | 13 | const log = Log.create({ service: "format" }) | 13 | 14 |
| 14 | | -export const Status = z | 15 | | - .object({ | 16 | | - name: z.string(), | 17 | | - extensions: z.string().array(), | 18 | | - enabled: z.boolean(), | 19 | | - }) | 20 | | - .meta({ | 21 | | - ref: "FormatterStatus", | 22 | | - }) | 23 | | -export type Status = z.infer<typeof Status> | | 15 | +export const Status = Schema.Struct({ | | 16 | + name: Schema.String, | | 17 | + extensions: Schema.Array(Schema.String), | | 18 | + enabled: Schema.Boolean, | | 19 | +}) | | 20 | + .annotate({ identifier: "FormatterStatus" }) | | 21 | + .pipe(withStatics((s) => ({ zod: zod(s) }))) | | 22 | +export type Status = Schema.Schema.Type<typeof Status> | 24 | 23 |
| 25 | 24 | export interface Interface { | 26 | 25 | readonly init: () => Effect.Effect<void> | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/permission/index.ts +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,13 +22,14 @@ export const Action = Schema.Literals(["allow", "deny", "ask"]) | 22 | 22 | .pipe(withStatics((s) => ({ zod: zod(s) }))) | 23 | 23 | export type Action = Schema.Schema.Type<typeof Action> | 24 | 24 |
| 25 | | -export class Rule extends Schema.Class<Rule>("PermissionRule")({ | | 25 | +export const Rule = Schema.Struct({ | 26 | 26 | permission: Schema.String, | 27 | 27 | pattern: Schema.String, | 28 | 28 | action: Action, | 29 | | -}) { | 30 | | - static readonly zod = zod(this) | 31 | | -} | | 29 | +}) | | 30 | + .annotate({ identifier: "PermissionRule" }) | | 31 | + .pipe(withStatics((s) => ({ zod: zod(s) }))) | | 32 | +export type Rule = Schema.Schema.Type<typeof Rule> | 32 | 33 |
| 33 | 34 | export const Ruleset = Schema.mutable(Schema.Array(Rule)) | 34 | 35 | .annotate({ identifier: "PermissionRuleset" }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/instance/httpapi/instance.ts +97-2Lines changed: 97 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { Agent } from "@/agent/agent" | | 2 | +import { Command } from "@/command" | | 3 | +import { Format } from "@/format" | 1 | 4 | import { Global } from "@opencode-ai/core/global" | | 5 | +import { LSP } from "@/lsp" | 2 | 6 | import { Vcs } from "@/project" | | 7 | +import { Skill } from "@/skill" | 3 | 8 | import * as InstanceState from "@/effect/instance-state" | 4 | 9 | import { Effect, Layer, Schema } from "effect" | 5 | 10 | import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" | @@ -21,6 +26,11 @@ export const InstancePaths = { | 21 | 26 | path: "/path", | 22 | 27 | vcs: "/vcs", | 23 | 28 | vcsDiff: "/vcs/diff", | | 29 | + command: "/command", | | 30 | + agent: "/agent", | | 31 | + skill: "/skill", | | 32 | + lsp: "/lsp", | | 33 | + formatter: "/formatter", | 24 | 34 | } as const | 25 | 35 |
| 26 | 36 | export const InstanceApi = HttpApi.make("instance") | @@ -57,6 +67,51 @@ export const InstanceApi = HttpApi.make("instance") | 57 | 67 | description: "Retrieve the current git diff for the working tree or against the default branch.", | 58 | 68 | }), | 59 | 69 | ), | | 70 | + HttpApiEndpoint.get("command", InstancePaths.command, { | | 71 | + success: Schema.Array(Command.Info), | | 72 | + }).annotateMerge( | | 73 | + OpenApi.annotations({ | | 74 | + identifier: "command.list", | | 75 | + summary: "List commands", | | 76 | + description: "Get a list of all available commands in the OpenCode system.", | | 77 | + }), | | 78 | + ), | | 79 | + HttpApiEndpoint.get("agent", InstancePaths.agent, { | | 80 | + success: Schema.Array(Agent.Info), | | 81 | + }).annotateMerge( | | 82 | + OpenApi.annotations({ | | 83 | + identifier: "app.agents", | | 84 | + summary: "List agents", | | 85 | + description: "Get a list of all available AI agents in the OpenCode system.", | | 86 | + }), | | 87 | + ), | | 88 | + HttpApiEndpoint.get("skill", InstancePaths.skill, { | | 89 | + success: Schema.Array(Skill.Info), | | 90 | + }).annotateMerge( | | 91 | + OpenApi.annotations({ | | 92 | + identifier: "app.skills", | | 93 | + summary: "List skills", | | 94 | + description: "Get a list of all available skills in the OpenCode system.", | | 95 | + }), | | 96 | + ), | | 97 | + HttpApiEndpoint.get("lsp", InstancePaths.lsp, { | | 98 | + success: Schema.Array(LSP.Status), | | 99 | + }).annotateMerge( | | 100 | + OpenApi.annotations({ | | 101 | + identifier: "lsp.status", | | 102 | + summary: "Get LSP status", | | 103 | + description: "Get LSP server status", | | 104 | + }), | | 105 | + ), | | 106 | + HttpApiEndpoint.get("formatter", InstancePaths.formatter, { | | 107 | + success: Schema.Array(Format.Status), | | 108 | + }).annotateMerge( | | 109 | + OpenApi.annotations({ | | 110 | + identifier: "formatter.status", | | 111 | + summary: "Get formatter status", | | 112 | + description: "Get formatter status", | | 113 | + }), | | 114 | + ), | 60 | 115 | ) | 61 | 116 | .annotateMerge( | 62 | 117 | OpenApi.annotations({ | @@ -76,6 +131,11 @@ export const InstanceApi = HttpApi.make("instance") | 76 | 131 |
| 77 | 132 | export const instanceHandlers = Layer.unwrap( | 78 | 133 | Effect.gen(function* () { | | 134 | + const agent = yield* Agent.Service | | 135 | + const command = yield* Command.Service | | 136 | + const format = yield* Format.Service | | 137 | + const lsp = yield* LSP.Service | | 138 | + const skill = yield* Skill.Service | 79 | 139 | const vcs = yield* Vcs.Service | 80 | 140 |
| 81 | 141 | const getPath = Effect.fn("InstanceHttpApi.path")(function* () { | @@ -98,8 +158,43 @@ export const instanceHandlers = Layer.unwrap( | 98 | 158 | return yield* vcs.diff(ctx.query.mode) | 99 | 159 | }) | 100 | 160 |
| | 161 | + const getCommand = Effect.fn("InstanceHttpApi.command")(function* () { | | 162 | + return yield* command.list() | | 163 | + }) | | 164 | + | | 165 | + const getAgent = Effect.fn("InstanceHttpApi.agent")(function* () { | | 166 | + return yield* agent.list() | | 167 | + }) | | 168 | + | | 169 | + const getSkill = Effect.fn("InstanceHttpApi.skill")(function* () { | | 170 | + return yield* skill.all() | | 171 | + }) | | 172 | + | | 173 | + const getLsp = Effect.fn("InstanceHttpApi.lsp")(function* () { | | 174 | + return yield* lsp.status() | | 175 | + }) | | 176 | + | | 177 | + const getFormatter = Effect.fn("InstanceHttpApi.formatter")(function* () { | | 178 | + return yield* format.status() | | 179 | + }) | | 180 | + | 101 | 181 | return HttpApiBuilder.group(InstanceApi, "instance", (handlers) => | 102 | | - handlers.handle("path", getPath).handle("vcs", getVcs).handle("vcsDiff", getVcsDiff), | | 182 | + handlers | | 183 | + .handle("path", getPath) | | 184 | + .handle("vcs", getVcs) | | 185 | + .handle("vcsDiff", getVcsDiff) | | 186 | + .handle("command", getCommand) | | 187 | + .handle("agent", getAgent) | | 188 | + .handle("skill", getSkill) | | 189 | + .handle("lsp", getLsp) | | 190 | + .handle("formatter", getFormatter), | 103 | 191 | ) | 104 | 192 | }), | 105 | | -).pipe(Layer.provide(Vcs.defaultLayer)) | | 193 | +).pipe( | | 194 | + Layer.provide(Agent.defaultLayer), | | 195 | + Layer.provide(Command.defaultLayer), | | 196 | + Layer.provide(Format.defaultLayer), | | 197 | + Layer.provide(LSP.defaultLayer), | | 198 | + Layer.provide(Skill.defaultLayer), | | 199 | + Layer.provide(Vcs.defaultLayer), | | 200 | +) |
|