GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(httpapi): bridge catalog read endpoints (#24353) · ildella/opencode@eb02199

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • specs/effect
      • http-api.md
    • src
      • agent
        • agent.ts
      • command
        • index.ts
      • format
        • index.ts
      • permission
        • index.ts
      • server/routes/instance
        • httpapi
          • instance.ts
        • index.ts
      • skill
        • index.ts
    • test/server
      • httpapi-instance.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/specs/effect/http-api.md‎

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 numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Use raw Effect HTTP routes where `HttpApi` does not fit. The goal is deleting Ho
140140
| `file` | `bridged` partial | list/content/status only |
141141
| `mcp` | `bridged` partial | status only |
142142
| `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 |
144144
| experimental JSON routes | `next/later` | console, tool, worktree, resource, global session list |
145145
| `session` | `later/special` | large stateful surface plus streaming |
146146
| `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
151151
## Next PRs
152152

153153
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.
156155

157156
## Checklist
158157

@@ -165,7 +164,7 @@ Use raw Effect HTTP routes where `HttpApi` does not fit. The goal is deleting Ho
165164
- [x] Add bridge-level auth and instance tests.
166165
- [ ] Complete exact Hono route inventory.
167166
- [x] Resolve implemented-but-unmounted route groups.
168-
- [ ] Port remaining JSON routes.
167+
- [x] Port remaining top-level JSON reads.
169168
- [ ] Generate SDK/OpenAPI from Effect routes.
170169
- [ ] Flip ported JSON routes to default-on with fallback.
171170
- [ ] Delete replaced Hono route implementations.
Collapse file

‎packages/opencode/src/agent/agent.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/agent/agent.ts
+29-30Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import z from "zod"
33
import { Provider } from "../provider"
44
import { ModelID, ProviderID } from "../provider/schema"
55
import { generateObject, streamObject, type ModelMessage } from "ai"
6-
import { Instance } from "../project/instance"
76
import { Truncate } from "../tool"
87
import { Auth } from "../auth"
98
import { ProviderTransform } from "../provider"
@@ -19,37 +18,37 @@ import { Global } from "@opencode-ai/core/global"
1918
import path from "path"
2019
import { Plugin } from "@/plugin"
2120
import { Skill } from "../skill"
22-
import { Effect, Context, Layer } from "effect"
21+
import { Effect, Context, Layer, Schema } from "effect"
2322
import { InstanceState } from "@/effect"
2423
import * as Option from "effect/Option"
2524
import * as OtelTracer from "@effect/opentelemetry/Tracer"
25+
import { zod } from "@/util/effect-zod"
26+
import { withStatics, type DeepMutable } from "@/util/schema"
2627

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>>
5352

5453
export interface Interface {
5554
readonly get: (agent: string) => Effect.Effect<Info>
@@ -79,7 +78,7 @@ export const layer = Layer.effect(
7978
const provider = yield* Provider.Service
8079

8180
const state = yield* InstanceState.make<State>(
82-
Effect.fn("Agent.state")(function* (_ctx) {
81+
Effect.fn("Agent.state")(function* (ctx) {
8382
const cfg = yield* config.get()
8483
const skillDirs = yield* skill.dirs()
8584
const whitelistedDirs = [Truncate.GLOB, ...skillDirs.map((dir) => path.join(dir, "*"))]
@@ -136,7 +135,7 @@ export const layer = Layer.effect(
136135
edit: {
137136
"*": "deny",
138137
[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",
140139
},
141140
}),
142141
user,
Collapse file

‎packages/opencode/src/command/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/command/index.ts
+16-17Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { InstanceContext } from "@/project/instance"
55
import { SessionID, MessageID } from "@/session/schema"
66
import { Effect, Layer, Context, Schema } from "effect"
77
import z from "zod"
8+
import { zod, ZodOverride } from "@/util/effect-zod"
9+
import { withStatics } from "@/util/schema"
810
import { Config } from "../config"
911
import { MCP } from "../mcp"
1012
import { Skill } from "../skill"
@@ -27,25 +29,22 @@ export const Event = {
2729
),
2830
}
2931

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) })))
4645

4746
// 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 }
4948

5049
export function hints(template: string) {
5150
const result: string[] = []
Collapse file

‎packages/opencode/src/format/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/format/index.ts
+11-12Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import { Effect, Layer, Context } from "effect"
1+
import { Effect, Layer, Context, Schema } from "effect"
22
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
33
import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
44
import { InstanceState } from "@/effect"
55
import path from "path"
66
import { mergeDeep } from "remeda"
7-
import z from "zod"
87
import { Config } from "../config"
98
import { Log } from "../util"
109
import * as Formatter from "./formatter"
10+
import { zod } from "@/util/effect-zod"
11+
import { withStatics } from "@/util/schema"
1112

1213
const log = Log.create({ service: "format" })
1314

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>
2423

2524
export interface Interface {
2625
readonly init: () => Effect.Effect<void>
Collapse file

‎packages/opencode/src/permission/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/permission/index.ts
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ export const Action = Schema.Literals(["allow", "deny", "ask"])
2222
.pipe(withStatics((s) => ({ zod: zod(s) })))
2323
export type Action = Schema.Schema.Type<typeof Action>
2424

25-
export class Rule extends Schema.Class<Rule>("PermissionRule")({
25+
export const Rule = Schema.Struct({
2626
permission: Schema.String,
2727
pattern: Schema.String,
2828
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>
3233

3334
export const Ruleset = Schema.mutable(Schema.Array(Rule))
3435
.annotate({ identifier: "PermissionRuleset" })
Collapse file

‎packages/opencode/src/server/routes/instance/httpapi/instance.ts‎

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 numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import { Agent } from "@/agent/agent"
2+
import { Command } from "@/command"
3+
import { Format } from "@/format"
14
import { Global } from "@opencode-ai/core/global"
5+
import { LSP } from "@/lsp"
26
import { Vcs } from "@/project"
7+
import { Skill } from "@/skill"
38
import * as InstanceState from "@/effect/instance-state"
49
import { Effect, Layer, Schema } from "effect"
510
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
@@ -21,6 +26,11 @@ export const InstancePaths = {
2126
path: "/path",
2227
vcs: "/vcs",
2328
vcsDiff: "/vcs/diff",
29+
command: "/command",
30+
agent: "/agent",
31+
skill: "/skill",
32+
lsp: "/lsp",
33+
formatter: "/formatter",
2434
} as const
2535

2636
export const InstanceApi = HttpApi.make("instance")
@@ -57,6 +67,51 @@ export const InstanceApi = HttpApi.make("instance")
5767
description: "Retrieve the current git diff for the working tree or against the default branch.",
5868
}),
5969
),
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+
),
60115
)
61116
.annotateMerge(
62117
OpenApi.annotations({
@@ -76,6 +131,11 @@ export const InstanceApi = HttpApi.make("instance")
76131

77132
export const instanceHandlers = Layer.unwrap(
78133
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
79139
const vcs = yield* Vcs.Service
80140

81141
const getPath = Effect.fn("InstanceHttpApi.path")(function* () {
@@ -98,8 +158,43 @@ export const instanceHandlers = Layer.unwrap(
98158
return yield* vcs.diff(ctx.query.mode)
99159
})
100160

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+
101181
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),
103191
)
104192
}),
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+
)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.