Skip to content

Commit f3142cb

Browse files
authored
Merge branch 'anomalyco:dev' into dev
2 parents 27974cd + fb4bab8 commit f3142cb

32 files changed

Lines changed: 513 additions & 327 deletions

packages/opencode/specs/openapi-translation-cleanup.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ Verification:
105105

106106
Concrete first targets:
107107

108-
- `sessionID`
109-
- `messageID`
110-
- `partID`
111-
- `permissionID`
112-
- `ptyID`
108+
- `[x]` `sessionID`
109+
- `[x]` `messageID`
110+
- `[x]` `partID`
111+
- `[x]` `permissionID`
112+
- `[x]` `ptyID`
113113

114-
Leave ambiguous route-local `id` overrides for workspace routes until they are renamed or explicitly typed in endpoint params.
114+
- `[x]` Remove ambiguous workspace `id` path overrides once the endpoint source schema emits the `wrk` pattern.
115115

116116
Verification:
117117

packages/opencode/src/control-plane/schema.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
const workspaceIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("workspace") }).pipe(
8-
Schema.brand("WorkspaceID"),
9-
)
7+
const workspaceIdSchema = Schema.String.check(Schema.isStartsWith("wrk")).pipe(Schema.brand("WorkspaceID"))
108

119
export type WorkspaceID = typeof workspaceIdSchema.Type
1210

packages/opencode/src/id/id.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import z from "zod"
21
import { randomBytes } from "crypto"
32

43
const prefixes = {
@@ -7,19 +6,12 @@ const prefixes = {
76
message: "msg",
87
permission: "per",
98
question: "que",
10-
user: "usr",
119
part: "prt",
1210
pty: "pty",
1311
tool: "tool",
1412
workspace: "wrk",
15-
entry: "ent",
16-
account: "act",
1713
} as const
1814

19-
export function schema(prefix: keyof typeof prefixes) {
20-
return z.string().startsWith(prefixes[prefix])
21-
}
22-
2315
const LENGTH = 26
2416

2517
// State for monotonic ID generation

packages/opencode/src/permission/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { Newtype } from "@opencode-ai/core/schema"
66

77
export class PermissionID extends Newtype<PermissionID>()(
88
"PermissionID",
9-
Schema.String.check(Schema.isStartsWith("per")).annotate({ [ZodOverride]: Identifier.schema("permission") }),
9+
Schema.String.check(Schema.isStartsWith("per")),
1010
) {
1111
static ascending(id?: string): PermissionID {
1212
return this.make(Identifier.ascending("permission", id))

packages/opencode/src/pty/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
const ptyIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("pty") }).pipe(Schema.brand("PtyID"))
7+
const ptyIdSchema = Schema.String.check(Schema.isStartsWith("pty")).pipe(Schema.brand("PtyID"))
88

99
export type PtyID = typeof ptyIdSchema.Type
1010

packages/opencode/src/question/schema.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { Newtype } from "@opencode-ai/core/schema"
66

7-
export class QuestionID extends Newtype<QuestionID>()(
8-
"QuestionID",
9-
Schema.String.check(Schema.isStartsWith("que")).annotate({ [ZodOverride]: Identifier.schema("question") }),
10-
) {
7+
export class QuestionID extends Newtype<QuestionID>()("QuestionID", Schema.String.check(Schema.isStartsWith("que"))) {
118
static ascending(id?: string): QuestionID {
129
return this.make(Identifier.ascending("question", id))
1310
}

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ const QueryParameterSchemas: Record<string, OpenApiSchema> = {
6969
"GET /api/session/{sessionID}/message limit": { type: "number" },
7070
}
7171

72-
const PathParameterSchemas: Record<string, OpenApiSchema> = {
73-
sessionID: { type: "string", pattern: "^ses.*" },
74-
messageID: { type: "string", pattern: "^msg.*" },
75-
partID: { type: "string", pattern: "^prt.*" },
76-
permissionID: { type: "string", pattern: "^per.*" },
77-
ptyID: { type: "string", pattern: "^pty.*" },
78-
}
79-
8072
const LegacyComponentDescriptions: Record<string, string> = {
8173
LogLevel: "Log level",
8274
ServerConfig: "Server configuration for opencode serve and web commands",
@@ -486,7 +478,7 @@ function flattenOptions(options: OpenApiSchema[] | undefined): OpenApiSchema[] |
486478
function normalizeParameter(param: OpenApiParameter, route: string) {
487479
if (!param.schema || typeof param.schema !== "object") return
488480
if (param.in === "path") {
489-
param.schema = pathParameterSchema(route, param.name) ?? stripOptionalNull(param.schema)
481+
param.schema = stripOptionalNull(param.schema)
490482
return
491483
}
492484
if (param.in === "query") {
@@ -505,15 +497,6 @@ function normalizeParameter(param: OpenApiParameter, route: string) {
505497
param.schema = stripOptionalNull(param.schema)
506498
}
507499

508-
function pathParameterSchema(route: string, name: string) {
509-
if (name in PathParameterSchemas) return PathParameterSchemas[name]
510-
if (name === "id" && route.startsWith("DELETE /experimental/workspace/")) return { type: "string", pattern: "^wrk.*" }
511-
if (name === "id" && route.startsWith("POST /experimental/workspace/")) return { type: "string", pattern: "^wrk.*" }
512-
if (name === "requestID" && route.startsWith("POST /permission/")) return { type: "string", pattern: "^per.*" }
513-
if (name === "requestID" && route.startsWith("POST /question/")) return { type: "string", pattern: "^que.*" }
514-
return undefined
515-
}
516-
517500
export const PublicApi = OpenCodeHttpApi.annotateMerge(
518501
OpenApi.annotations({
519502
title: "opencode",

packages/opencode/src/session/schema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
export const SessionID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("session") }).pipe(
7+
export const SessionID = Schema.String.check(Schema.isStartsWith("ses")).pipe(
88
Schema.brand("SessionID"),
99
withStatics((s) => ({
1010
descending: (id?: string) => s.make(Identifier.descending("session", id)),
@@ -14,7 +14,7 @@ export const SessionID = Schema.String.annotate({ [ZodOverride]: Identifier.sche
1414

1515
export type SessionID = Schema.Schema.Type<typeof SessionID>
1616

17-
export const MessageID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("message") }).pipe(
17+
export const MessageID = Schema.String.check(Schema.isStartsWith("msg")).pipe(
1818
Schema.brand("MessageID"),
1919
withStatics((s) => ({
2020
ascending: (id?: string) => s.make(Identifier.ascending("message", id)),
@@ -24,7 +24,7 @@ export const MessageID = Schema.String.annotate({ [ZodOverride]: Identifier.sche
2424

2525
export type MessageID = Schema.Schema.Type<typeof MessageID>
2626

27-
export const PartID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("part") }).pipe(
27+
export const PartID = Schema.String.check(Schema.isStartsWith("prt")).pipe(
2828
Schema.brand("PartID"),
2929
withStatics((s) => ({
3030
ascending: (id?: string) => s.make(Identifier.ascending("part", id)),

packages/opencode/src/sync/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
export const EventID = Schema.String.annotate({ [ZodOverride]: Identifier.schema("event") }).pipe(
7+
export const EventID = Schema.String.check(Schema.isStartsWith("evt")).pipe(
88
Schema.brand("EventID"),
99
withStatics((s) => ({
1010
ascending: (id?: string) => s.make(Identifier.ascending("event", id)),

packages/opencode/src/tool/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Schema } from "effect"
22

33
import { Identifier } from "@/id/id"
4-
import { zod, ZodOverride } from "@opencode-ai/core/effect-zod"
4+
import { zod } from "@opencode-ai/core/effect-zod"
55
import { withStatics } from "@opencode-ai/core/schema"
66

7-
const toolIdSchema = Schema.String.annotate({ [ZodOverride]: Identifier.schema("tool") }).pipe(Schema.brand("ToolID"))
7+
const toolIdSchema = Schema.String.check(Schema.isStartsWith("tool")).pipe(Schema.brand("ToolID"))
88

99
export type ToolID = typeof toolIdSchema.Type
1010

0 commit comments

Comments
 (0)