refactor(vscode): address code review feedback for agent permissions display

- Replace non-null assertion with SolidJS Show callback pattern
- Add 'unknown' color fallback for unrecognized permission actions
- Document wildcard pattern assumption in summary computation
- Move mapAgent helper to module scope for better code organization
This commit is contained in:
Mark IJbema
2026-04-08 13:36:24 +02:00
parent cc257fdd30
commit 359410fad2
2 changed files with 21 additions and 16 deletions
+14 -12
View File
@@ -90,12 +90,26 @@ import {
saveCustomProvider as saveCustomProviderAction,
} from "./provider-actions"
import { fetchOpenAIModels, FetchModelsError } from "./shared/fetch-models"
import type { Agent } from "@kilocode/sdk/v2/client"
type KiloProviderOptions = {
projectDirectory?: string | null
slimEditMetadata?: boolean
}
// Helper to map agent data to the subset of fields sent to the webview
const mapAgent = (a: Agent) => ({
name: a.name,
displayName: a.displayName,
description: a.description,
mode: a.mode,
native: a.native,
hidden: a.hidden,
color: a.color,
deprecated: a.deprecated,
permission: a.permission,
})
export class KiloProvider implements vscode.WebviewViewProvider, TelemetryPropertiesProvider {
public static readonly viewType = "kilo-code.SidebarProvider"
@@ -1623,18 +1637,6 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
const { visible, defaultAgent } = filterVisibleAgents(agents)
const mapAgent = (a: (typeof agents)[number]) => ({
name: a.name,
displayName: a.displayName,
description: a.description,
mode: a.mode,
native: a.native,
hidden: a.hidden,
color: a.color,
deprecated: a.deprecated,
permission: a.permission,
})
const message = {
type: "agentsLoaded",
agents: visible.map(mapAgent),
@@ -232,8 +232,8 @@ const ModeEditView: Component<Props> = (props) => {
</Card>
{/* Calculated permissions (read-only, collapsible) */}
<Show when={agent()?.permission}>
<PermissionRuleset rules={agent()!.permission!} expanded={expanded()} onToggle={() => setExpanded((v) => !v)} />
<Show when={agent()?.permission} keyed>
{(rules) => <PermissionRuleset rules={rules} expanded={expanded()} onToggle={() => setExpanded((v) => !v)} />}
</Show>
<div style={{ display: "flex", "justify-content": "flex-end" }}>
@@ -253,6 +253,7 @@ const ACTION_COLORS: Record<string, { bg: string; fg: string }> = {
allow: { bg: "var(--vscode-terminal-ansiGreen, #3fb950)", fg: "var(--vscode-editor-background, #1e1e1e)" },
ask: { bg: "var(--vscode-editorWarning-foreground, #cca700)", fg: "var(--vscode-editor-background, #1e1e1e)" },
deny: { bg: "var(--vscode-errorForeground, #f85149)", fg: "var(--vscode-editor-background, #fff)" },
unknown: { bg: "var(--vscode-descriptionForeground, #8b949e)", fg: "var(--vscode-editor-background, #1e1e1e)" },
}
interface RulesetProps {
@@ -265,6 +266,8 @@ const PermissionRuleset: Component<RulesetProps> = (props) => {
const language = useLanguage()
// Compute effective action per unique tool by finding the last rule with pattern "*"
// NOTE: This assumes the CLI uses "*" as the wildcard pattern for catch-all rules.
// If the CLI convention changes (e.g. to "**" or another pattern), this will need updating.
const summary = createMemo(() => {
const tools = new Map<string, PermissionRuleItem["action"]>()
for (const rule of props.rules) {
@@ -320,7 +323,7 @@ const PermissionRuleset: Component<RulesetProps> = (props) => {
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "4px" }}>
<For each={summary()}>
{([tool, action]) => {
const colors = ACTION_COLORS[action] ?? ACTION_COLORS.ask
const colors = ACTION_COLORS[action] ?? ACTION_COLORS.unknown
return (
<span
style={{
@@ -376,7 +379,7 @@ const PermissionRuleset: Component<RulesetProps> = (props) => {
<tbody>
<For each={props.rules}>
{(rule, idx) => {
const colors = ACTION_COLORS[rule.action] ?? ACTION_COLORS.ask
const colors = ACTION_COLORS[rule.action] ?? ACTION_COLORS.unknown
return (
<tr
style={{