GeezerVison is showing github.com — Permission rework (#6319) · burka/opencode@351ddee
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test.yml +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,11 +2,9 @@ name: test | 2 | 2 |
| 3 | 3 | on: | 4 | 4 | push: | 5 | | - branches-ignore: | 6 | | - - production | | 5 | + branches: | | 6 | + - dev | 7 | 7 | pull_request: | 8 | | - branches-ignore: | 9 | | - - production | 10 | 8 | workflow_dispatch: | 11 | 9 | jobs: | 12 | 10 | test: | |
Collapse file Copy file name to clipboardExpand all lines: .opencode/agent/git-committer.md -10Lines changed: 0 additions & 10 deletions Collapse file Copy file name to clipboardExpand all lines: .opencode/opencode.jsonc +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | "options": {}, | 11 | 11 | }, | 12 | 12 | }, | 13 | | - "mcp": {}, | | 13 | + "permission": "ask", | | 14 | + "mcp": { | | 15 | + "context7": { | | 16 | + "type": "remote", | | 17 | + "url": "https://mcp.context7.com/mcp", | | 18 | + }, | | 19 | + }, | 14 | 20 | "tools": { | 15 | 21 | "github-triage": false, | 16 | 22 | }, | |
Collapse file Copy file name to clipboard +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | [install] | 2 | 2 | exact = true | | 3 | + | | 4 | +[test] | | 5 | +root = "./do-not-run-tests-from-root" | | 6 | + |
Collapse file Copy file name to clipboardExpand all lines: flake.lock +3-3Lines changed: 3 additions & 3 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 10 | 10 | "typecheck": "bun turbo typecheck", | 11 | 11 | "prepare": "husky", | 12 | 12 | "random": "echo 'Random script'", | 13 | | - "hello": "echo 'Hello World!'" | | 13 | + "hello": "echo 'Hello World!'", | | 14 | + "test": "echo 'do not run tests from root' && exit 1" | 14 | 15 | }, | 15 | 16 | "workspaces": { | 16 | 17 | "packages": [ | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/context/global-sync.tsx +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ import { | 15 | 15 | type McpStatus, | 16 | 16 | type LspStatus, | 17 | 17 | type VcsInfo, | 18 | | - type Permission, | | 18 | + type PermissionRequest, | 19 | 19 | createOpencodeClient, | 20 | 20 | } from "@opencode-ai/sdk/v2/client" | 21 | 21 | import { createStore, produce, reconcile } from "solid-js/store" | @@ -46,7 +46,7 @@ type State = { | 46 | 46 | [sessionID: string]: Todo[] | 47 | 47 | } | 48 | 48 | permission: { | 49 | | - [sessionID: string]: Permission[] | | 49 | + [sessionID: string]: PermissionRequest[] | 50 | 50 | } | 51 | 51 | mcp: { | 52 | 52 | [name: string]: McpStatus | @@ -168,7 +168,7 @@ function createGlobalSync() { | 168 | 168 | vcs: () => sdk.vcs.get().then((x) => setStore("vcs", x.data)), | 169 | 169 | permission: () => | 170 | 170 | sdk.permission.list().then((x) => { | 171 | | - const grouped: Record<string, Permission[]> = {} | | 171 | + const grouped: Record<string, PermissionRequest[]> = {} | 172 | 172 | for (const perm of x.data ?? []) { | 173 | 173 | if (!perm?.id || !perm.sessionID) continue | 174 | 174 | const existing = grouped[perm.sessionID] | @@ -349,7 +349,7 @@ function createGlobalSync() { | 349 | 349 | setStore("vcs", { branch: event.properties.branch }) | 350 | 350 | break | 351 | 351 | } | 352 | | - case "permission.updated": { | | 352 | + case "permission.asked": { | 353 | 353 | const sessionID = event.properties.sessionID | 354 | 354 | const permissions = store.permission[sessionID] | 355 | 355 | if (!permissions) { | @@ -375,7 +375,7 @@ function createGlobalSync() { | 375 | 375 | case "permission.replied": { | 376 | 376 | const permissions = store.permission[event.properties.sessionID] | 377 | 377 | if (!permissions) break | 378 | | - const result = Binary.search(permissions, event.properties.permissionID, (p) => p.id) | | 378 | + const result = Binary.search(permissions, event.properties.requestID, (p) => p.id) | 379 | 379 | if (!result.found) break | 380 | 380 | setStore( | 381 | 381 | "permission", | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/context/permission.tsx +6-8Lines changed: 6 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { createMemo, onCleanup } from "solid-js" | 2 | 2 | import { createStore } from "solid-js/store" | 3 | 3 | import { createSimpleContext } from "@opencode-ai/ui/context" | 4 | | -import type { Permission } from "@opencode-ai/sdk/v2/client" | | 4 | +import type { PermissionRequest } from "@opencode-ai/sdk/v2/client" | 5 | 5 | import { persisted } from "@/utils/persist" | 6 | 6 | import { useGlobalSDK } from "@/context/global-sdk" | 7 | 7 | import { useGlobalSync } from "./global-sync" | @@ -14,10 +14,8 @@ type PermissionRespondFn = (input: { | 14 | 14 | directory?: string | 15 | 15 | }) => void | 16 | 16 |
| 17 | | -const AUTO_ACCEPT_TYPES = new Set(["edit", "write"]) | 18 | | - | 19 | | -function shouldAutoAccept(perm: Permission) { | 20 | | - return AUTO_ACCEPT_TYPES.has(perm.type) | | 17 | +function shouldAutoAccept(perm: PermissionRequest) { | | 18 | + return perm.permission === "edit" | 21 | 19 | } | 22 | 20 |
| 23 | 21 | export const { use: usePermission, provider: PermissionProvider } = createSimpleContext({ | @@ -48,7 +46,7 @@ export const { use: usePermission, provider: PermissionProvider } = createSimple | 48 | 46 | }) | 49 | 47 | } | 50 | 48 |
| 51 | | - function respondOnce(permission: Permission, directory?: string) { | | 49 | + function respondOnce(permission: PermissionRequest, directory?: string) { | 52 | 50 | if (responded.has(permission.id)) return | 53 | 51 | responded.add(permission.id) | 54 | 52 | respond({ | @@ -65,7 +63,7 @@ export const { use: usePermission, provider: PermissionProvider } = createSimple | 65 | 63 |
| 66 | 64 | const unsubscribe = globalSDK.event.listen((e) => { | 67 | 65 | const event = e.details | 68 | | - if (event?.type !== "permission.updated") return | | 66 | + if (event?.type !== "permission.asked") return | 69 | 67 |
| 70 | 68 | const perm = event.properties | 71 | 69 | if (!isAutoAccepting(perm.sessionID)) return | @@ -98,7 +96,7 @@ export const { use: usePermission, provider: PermissionProvider } = createSimple | 98 | 96 | return { | 99 | 97 | ready, | 100 | 98 | respond, | 101 | | - autoResponds(permission: Permission) { | | 99 | + autoResponds(permission: PermissionRequest) { | 102 | 100 | return isAutoAccepting(permission.sessionID) && shouldAutoAccept(permission) | 103 | 101 | }, | 104 | 102 | isAutoAccepting, | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/pages/layout.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -175,7 +175,7 @@ export default function Layout(props: ParentProps) { | 175 | 175 | const permissionAlertCooldownMs = 5000 | 176 | 176 |
| 177 | 177 | const unsub = globalSDK.event.listen((e) => { | 178 | | - if (e.details?.type !== "permission.updated") return | | 178 | + if (e.details?.type !== "permission.asked") return | 179 | 179 | const directory = e.name | 180 | 180 | const perm = e.details.properties | 181 | 181 | if (permission.autoResponds(perm)) return | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/acp/agent.ts +14-17Lines changed: 14 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,19 +71,19 @@ export namespace ACP { | 71 | 71 | this.config.sdk.event.subscribe({ directory }).then(async (events) => { | 72 | 72 | for await (const event of events.stream) { | 73 | 73 | switch (event.type) { | 74 | | - case "permission.updated": | | 74 | + case "permission.asked": | 75 | 75 | try { | 76 | 76 | const permission = event.properties | 77 | 77 | const res = await this.connection | 78 | 78 | .requestPermission({ | 79 | 79 | sessionId, | 80 | 80 | toolCall: { | 81 | | - toolCallId: permission.callID ?? permission.id, | | 81 | + toolCallId: permission.tool?.callID ?? permission.id, | 82 | 82 | status: "pending", | 83 | | - title: permission.title, | | 83 | + title: permission.permission, | 84 | 84 | rawInput: permission.metadata, | 85 | | - kind: toToolKind(permission.type), | 86 | | - locations: toLocations(permission.type, permission.metadata), | | 85 | + kind: toToolKind(permission.permission), | | 86 | + locations: toLocations(permission.permission, permission.metadata), | 87 | 87 | }, | 88 | 88 | options, | 89 | 89 | }) | @@ -93,28 +93,25 @@ export namespace ACP { | 93 | 93 | permissionID: permission.id, | 94 | 94 | sessionID: permission.sessionID, | 95 | 95 | }) | 96 | | - await this.config.sdk.permission.respond({ | 97 | | - sessionID: permission.sessionID, | 98 | | - permissionID: permission.id, | 99 | | - response: "reject", | | 96 | + await this.config.sdk.permission.reply({ | | 97 | + requestID: permission.id, | | 98 | + reply: "reject", | 100 | 99 | directory, | 101 | 100 | }) | 102 | 101 | return | 103 | 102 | }) | 104 | 103 | if (!res) return | 105 | 104 | if (res.outcome.outcome !== "selected") { | 106 | | - await this.config.sdk.permission.respond({ | 107 | | - sessionID: permission.sessionID, | 108 | | - permissionID: permission.id, | 109 | | - response: "reject", | | 105 | + await this.config.sdk.permission.reply({ | | 106 | + requestID: permission.id, | | 107 | + reply: "reject", | 110 | 108 | directory, | 111 | 109 | }) | 112 | 110 | return | 113 | 111 | } | 114 | | - await this.config.sdk.permission.respond({ | 115 | | - sessionID: permission.sessionID, | 116 | | - permissionID: permission.id, | 117 | | - response: res.outcome.optionId as "once" | "always" | "reject", | | 112 | + await this.config.sdk.permission.reply({ | | 113 | + requestID: permission.id, | | 114 | + reply: res.outcome.optionId as "once" | "always" | "reject", | 118 | 115 | directory, | 119 | 116 | }) | 120 | 117 | } catch (err) { | |
|