mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
refactor(cli): move allow-everything route to kilocode directory
Move the /allow-everything endpoint from the shared permission routes into packages/opencode/src/kilocode/permission/routes.ts to reduce diff with upstream and ease future merges.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { Hono } from "hono"
|
||||
import { describeRoute, resolver, validator } from "hono-openapi"
|
||||
import z from "zod"
|
||||
import { Config } from "@/config/config"
|
||||
import { PermissionNext } from "@/permission/next"
|
||||
import { Session } from "@/session"
|
||||
import { errors } from "../../server/error"
|
||||
import { lazy } from "../../util/lazy"
|
||||
|
||||
export const PermissionKilocodeRoutes = lazy(() =>
|
||||
new Hono().post(
|
||||
"/allow-everything",
|
||||
describeRoute({
|
||||
summary: "Allow everything",
|
||||
description: "Enable or disable allowing all permissions without prompts.",
|
||||
operationId: "permission.allowEverything",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Success",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(z.boolean()),
|
||||
},
|
||||
},
|
||||
},
|
||||
...errors(400, 404),
|
||||
},
|
||||
}),
|
||||
validator(
|
||||
"json",
|
||||
z.object({
|
||||
enable: z.boolean(),
|
||||
requestID: z.string().optional(),
|
||||
sessionID: z.string().optional(),
|
||||
}),
|
||||
),
|
||||
async (c) => {
|
||||
const body = c.req.valid("json")
|
||||
const rules: PermissionNext.Ruleset = [{ permission: "*", pattern: "*", action: "allow" }]
|
||||
|
||||
if (!body.enable) {
|
||||
if (body.sessionID) {
|
||||
const session = await Session.get(body.sessionID)
|
||||
await Session.setPermission({
|
||||
sessionID: body.sessionID,
|
||||
permission: (session.permission ?? []).filter(
|
||||
(rule) => !(rule.permission === "*" && rule.pattern === "*" && rule.action === "allow"),
|
||||
),
|
||||
})
|
||||
await PermissionNext.allowEverything({ enable: false, sessionID: body.sessionID })
|
||||
return c.json(true)
|
||||
}
|
||||
|
||||
await Config.updateGlobal({ permission: { "*": { "*": null } } }, { dispose: false })
|
||||
await PermissionNext.allowEverything({ enable: false })
|
||||
return c.json(true)
|
||||
}
|
||||
|
||||
if (body.sessionID) {
|
||||
const session = await Session.get(body.sessionID)
|
||||
await Session.setPermission({
|
||||
sessionID: body.sessionID,
|
||||
permission: [...(session.permission ?? []), ...rules],
|
||||
})
|
||||
} else {
|
||||
await Config.updateGlobal({ permission: PermissionNext.toConfig(rules) }, { dispose: false })
|
||||
}
|
||||
|
||||
await PermissionNext.allowEverything({
|
||||
enable: true,
|
||||
requestID: body.requestID,
|
||||
sessionID: body.sessionID,
|
||||
})
|
||||
|
||||
return c.json(true)
|
||||
},
|
||||
),
|
||||
)
|
||||
@@ -2,8 +2,6 @@ import { Hono } from "hono"
|
||||
import { describeRoute, validator, resolver } from "hono-openapi"
|
||||
import z from "zod"
|
||||
import { PermissionNext } from "@/permission/next"
|
||||
import { Session } from "@/session" // kilocode_change
|
||||
import { Config } from "@/config/config" // kilocode_change
|
||||
import { errors } from "../error"
|
||||
import { lazy } from "../../util/lazy"
|
||||
|
||||
@@ -95,76 +93,6 @@ export const PermissionRoutes = lazy(() =>
|
||||
},
|
||||
)
|
||||
// kilocode_change end
|
||||
// kilocode_change start
|
||||
.post(
|
||||
"/allow-everything",
|
||||
describeRoute({
|
||||
summary: "Allow everything",
|
||||
description: "Enable or disable allowing all permissions without prompts.",
|
||||
operationId: "permission.allowEverything",
|
||||
responses: {
|
||||
200: {
|
||||
description: "Success",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(z.boolean()),
|
||||
},
|
||||
},
|
||||
},
|
||||
...errors(400, 404),
|
||||
},
|
||||
}),
|
||||
validator(
|
||||
"json",
|
||||
z.object({
|
||||
enable: z.boolean(),
|
||||
requestID: z.string().optional(),
|
||||
sessionID: z.string().optional(),
|
||||
}),
|
||||
),
|
||||
async (c) => {
|
||||
const json = c.req.valid("json")
|
||||
const rules: PermissionNext.Ruleset = [{ permission: "*", pattern: "*", action: "allow" }]
|
||||
|
||||
if (!json.enable) {
|
||||
if (json.sessionID) {
|
||||
const session = await Session.get(json.sessionID)
|
||||
await Session.setPermission({
|
||||
sessionID: json.sessionID,
|
||||
permission: (session.permission ?? []).filter(
|
||||
(rule) => !(rule.permission === "*" && rule.pattern === "*" && rule.action === "allow"),
|
||||
),
|
||||
})
|
||||
await PermissionNext.allowEverything({ enable: false, sessionID: json.sessionID })
|
||||
return c.json(true)
|
||||
}
|
||||
|
||||
await Config.updateGlobal({ permission: { "*": { "*": null } } }, { dispose: false })
|
||||
await PermissionNext.allowEverything({ enable: false })
|
||||
return c.json(true)
|
||||
}
|
||||
|
||||
if (json.sessionID) {
|
||||
const session = await Session.get(json.sessionID)
|
||||
const existing = session.permission ?? []
|
||||
await Session.setPermission({
|
||||
sessionID: json.sessionID,
|
||||
permission: [...existing, ...rules],
|
||||
})
|
||||
} else {
|
||||
await Config.updateGlobal({ permission: PermissionNext.toConfig(rules) }, { dispose: false })
|
||||
}
|
||||
|
||||
await PermissionNext.allowEverything({
|
||||
enable: true,
|
||||
requestID: json.requestID,
|
||||
sessionID: json.sessionID,
|
||||
})
|
||||
|
||||
return c.json(true)
|
||||
},
|
||||
)
|
||||
// kilocode_change end
|
||||
.get(
|
||||
"/",
|
||||
describeRoute({
|
||||
|
||||
@@ -48,6 +48,7 @@ import { errors } from "./error"
|
||||
import { CommitMessageRoutes } from "./routes/commit-message" // kilocode_change
|
||||
import { EnhancePromptRoutes } from "./routes/enhance-prompt" // kilocode_change
|
||||
import { KilocodeRoutes } from "./routes/kilocode" // kilocode_change
|
||||
import { PermissionKilocodeRoutes } from "../kilocode/permission/routes" // kilocode_change
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { QuestionRoutes } from "./routes/question"
|
||||
import { PermissionRoutes } from "./routes/permission"
|
||||
@@ -277,6 +278,7 @@ export namespace Server {
|
||||
.route("/experimental", ExperimentalRoutes())
|
||||
.route("/session", SessionRoutes())
|
||||
.route("/permission", PermissionRoutes())
|
||||
.route("/permission", PermissionKilocodeRoutes()) // kilocode_change
|
||||
.route("/question", QuestionRoutes())
|
||||
.route("/provider", ProviderRoutes())
|
||||
.route("/telemetry", TelemetryRoutes()) // kilocode_change
|
||||
|
||||
Reference in New Issue
Block a user