mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-22 03:45:23 +00:00
refactor(permission): drop redundant inner decode in Permission.ask (#28575)
This commit is contained in:
@@ -29,7 +29,11 @@ export type Rule = Schema.Schema.Type<typeof Rule>
|
||||
export const Ruleset = Schema.Array(Rule).annotate({ identifier: "PermissionRuleset" })
|
||||
export type Ruleset = Schema.Schema.Type<typeof Ruleset>
|
||||
|
||||
export class Request extends Schema.Class<Request>("PermissionRequest")({
|
||||
// Pure data; nothing checks class identity. As `Schema.Struct` + type alias,
|
||||
// `Permission.ask` can trust its already-typed input and skip the inner
|
||||
// `decodeUnknownSync` that would otherwise throw uncaught on any structural
|
||||
// mismatch. Same pattern as `Question.Request` in PR #28570.
|
||||
export const Request = Schema.Struct({
|
||||
id: PermissionID,
|
||||
sessionID: SessionID,
|
||||
permission: Schema.String,
|
||||
@@ -42,7 +46,8 @@ export class Request extends Schema.Class<Request>("PermissionRequest")({
|
||||
callID: Schema.String,
|
||||
}),
|
||||
),
|
||||
}) {}
|
||||
}).annotate({ identifier: "PermissionRequest" })
|
||||
export type Request = Schema.Schema.Type<typeof Request>
|
||||
|
||||
export const Reply = Schema.Literals(["once", "always", "reject"])
|
||||
export type Reply = Schema.Schema.Type<typeof Reply>
|
||||
@@ -55,10 +60,11 @@ const reply = {
|
||||
export const ReplyBody = Schema.Struct(reply).annotate({ identifier: "PermissionReplyBody" })
|
||||
export type ReplyBody = Schema.Schema.Type<typeof ReplyBody>
|
||||
|
||||
export class Approval extends Schema.Class<Approval>("PermissionApproval")({
|
||||
export const Approval = Schema.Struct({
|
||||
projectID: ProjectID,
|
||||
patterns: Schema.Array(Schema.String),
|
||||
}) {}
|
||||
}).annotate({ identifier: "PermissionApproval" })
|
||||
export type Approval = Schema.Schema.Type<typeof Approval>
|
||||
|
||||
export const Event = {
|
||||
Asked: BusEvent.define("permission.asked", Request),
|
||||
@@ -178,10 +184,15 @@ export const layer = Layer.effect(
|
||||
if (!needsAsk) return
|
||||
|
||||
const id = request.id ?? PermissionID.ascending()
|
||||
const info = Schema.decodeUnknownSync(Request)({
|
||||
const info: Request = {
|
||||
id,
|
||||
...request,
|
||||
})
|
||||
sessionID: request.sessionID,
|
||||
permission: request.permission,
|
||||
patterns: request.patterns,
|
||||
metadata: request.metadata,
|
||||
always: request.always,
|
||||
tool: request.tool,
|
||||
}
|
||||
log.info("asking", { id, permission: info.permission, patterns: info.patterns })
|
||||
|
||||
const deferred = yield* Deferred.make<void, RejectedError | CorrectedError>()
|
||||
|
||||
Reference in New Issue
Block a user