Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/opencode/src/cli/cmd/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ScrapCommand } from "./scrap"
import { SkillCommand } from "./skill"
import { SnapshotCommand } from "./snapshot"
import { AgentCommand } from "./agent"
import { PermissionCommand } from "./permission"

export const DebugCommand = cmd({
command: "debug",
Expand All @@ -23,6 +24,7 @@ export const DebugCommand = cmd({
.command(SkillCommand)
.command(SnapshotCommand)
.command(AgentCommand)
.command(PermissionCommand)
.command(PathsCommand)
.command({
command: "wait",
Expand Down
68 changes: 68 additions & 0 deletions packages/opencode/src/cli/cmd/debug/permission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { bootstrap } from "../../bootstrap"
import { cmd } from "../cmd"
import { PermissionNext } from "@/permission/next"
import { Agent } from "@/agent/agent"

export const PermissionCommand = cmd({
command: "permission [agent]",
describe: "show all permissions with sources",
builder: (yargs) =>
yargs.positional("agent", {
describe: "agent name (default: build)",
type: "string",
default: "build",
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
const agent = args.agent as string

console.log(`\n=== Permission Report for Agent: ${agent} ===\n`)

const allPerms = await PermissionNext.all(agent)

// Group by source
const bySource = {
default: [] as PermissionNext.RuleWithSource[],
global: [] as PermissionNext.RuleWithSource[],
project: [] as PermissionNext.RuleWithSource[],
session: [] as PermissionNext.RuleWithSource[],
}

for (const rule of allPerms) {
bySource[rule.source].push(rule)
}

// Print by source
for (const [source, rules] of Object.entries(bySource)) {
if (rules.length === 0) continue

console.log(`\n[${source.toUpperCase()}] - ${rules.length} rules:`)
console.log("─".repeat(60))

// Group by permission type
const byPermission = new Map<string, PermissionNext.RuleWithSource[]>()
for (const rule of rules) {
if (!byPermission.has(rule.permission)) {
byPermission.set(rule.permission, [])
}
byPermission.get(rule.permission)!.push(rule)
}

for (const [permission, perms] of byPermission) {
console.log(`\n ${permission}:`)
for (const perm of perms) {
const icon = perm.action === "allow" ? "✓" : perm.action === "deny" ? "✗" : "?"
const readonly = perm.readonly ? "[readonly]" : "[editable]"
console.log(` ${icon} ${perm.action.padEnd(5)} ${perm.pattern.padEnd(30)} ${readonly}`)
}
}
}

console.log(`\n\nTotal rules: ${allPerms.length}`)
console.log(" Default: ", bySource.default.length)
console.log(" Global: ", bySource.global.length)
console.log(" Project: ", bySource.project.length)
console.log(" Session: ", bySource.session.length)
})
},
})
9 changes: 9 additions & 0 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DialogModel, useConnected } from "@tui/component/dialog-model"
import { DialogMcp } from "@tui/component/dialog-mcp"
import { DialogStatus } from "@tui/component/dialog-status"
import { DialogThemeList } from "@tui/component/dialog-theme-list"
import { DialogPermission } from "@tui/component/dialog-permission"
import { DialogHelp } from "./ui/dialog-help"
import { CommandProvider, useCommandDialog } from "@tui/component/dialog-command"
import { DialogAgent } from "@tui/component/dialog-agent"
Expand Down Expand Up @@ -426,6 +427,14 @@ function App() {
},
category: "System",
},
{
title: "View permissions",
value: "permission.view",
onSelect: () => {
dialog.replace(() => <DialogPermission />)
},
category: "System",
},
{
title: "Switch theme",
value: "theme.switch",
Expand Down
Loading