Repository navigation
feat: explain tool auto-approval #12494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
4250ad9
073df16
c1530a9
e389860
e72068d
59782ae
85dbf44
ff02a97
69960b1
75862be
207fecc
7f37d01
b36b24e
0eb9fac
d4da7dd
6edf6ca
9c16457
c3a38ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": minor | ||
| --- | ||
|
|
||
| Show why a tool call was auto-approved. Expanding a tool call now explains whether it ran automatically or after your approval, and which rule allowed it — from your agent, the project config, your global config, or auto-approve (YOLO) mode. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { createContext, useContext, Show, type Accessor, type ParentProps } from "solid-js" | ||
|
|
||
| /** | ||
| * Explains why a tool call was auto-approved, inside the expanded tool row. | ||
| * | ||
| * The backend records this on the tool part's `state.metadata.approval`. The display strings are | ||
| * resolved by the caller (which owns the localized `t`) and carried on the context, so this stays | ||
| * free of any i18n key coupling. | ||
| */ | ||
| export type ToolApproval = { | ||
| source: "agent" | "global" | "project" | "yolo" | "session" | "manual" | "default" | ||
| agent?: string | ||
| rule?: { permission: string; pattern: string; action: string } | ||
| } | ||
|
|
||
| /** Pre-resolved, localized text plus the raw approval, supplied by the caller. */ | ||
| export type ToolApprovalDisplay = { | ||
| approval: ToolApproval | ||
| decision: string | ||
| source?: string | ||
| rule?: string | ||
| } | ||
|
|
||
| const SOURCE_KEYS = ["agent", "global", "project", "yolo", "session", "manual", "default"] as const | ||
|
|
||
| const Context = createContext<Accessor<ToolApprovalDisplay | undefined>>(() => undefined) | ||
|
|
||
| /** Provide the resolved approval to the tool row below. */ | ||
| export function ToolApprovalProvider(props: ParentProps<{ value: Accessor<ToolApprovalDisplay | undefined> }>) { | ||
| return <Context.Provider value={props.value}>{props.children}</Context.Provider> | ||
| } | ||
|
|
||
| export function useToolApproval() { | ||
| return useContext(Context) | ||
| } | ||
|
|
||
| /** Read the raw approval payload off a tool part's metadata, if present. */ | ||
| export function toolApprovalFrom(metadata: Record<string, unknown> | undefined): ToolApproval | undefined { | ||
| const value = metadata?.approval | ||
| if (!value || typeof value !== "object") return undefined | ||
| const approval = value as ToolApproval | ||
| return SOURCE_KEYS.includes(approval.source) ? approval : undefined | ||
| } | ||
|
|
||
| type Translate = (key: string, params?: Record<string, string | number | boolean>) => string | ||
|
|
||
| /** Resolve an approval read off metadata into localized display text via the caller's `t`. */ | ||
| export function resolveToolApproval( | ||
| metadata: Record<string, unknown> | undefined, | ||
| t: Translate, | ||
| ): ToolApprovalDisplay | undefined { | ||
| const approval = toolApprovalFrom(metadata) | ||
| if (!approval) return undefined | ||
| const sourceText = () => { | ||
| if (approval.source === "agent") | ||
| return approval.agent | ||
| ? t("ui.approval.source.agent", { agent: approval.agent }) | ||
| : t("ui.approval.source.agent.default") | ||
| if (approval.source === "manual") return undefined | ||
| return t(`ui.approval.source.${approval.source}`) | ||
| } | ||
| return { | ||
| approval, | ||
| decision: approval.source === "manual" ? t("ui.approval.manual") : t("ui.approval.auto"), | ||
| source: sourceText(), | ||
| rule: approval.rule | ||
| ? t("ui.approval.rule", { permission: approval.rule.permission, pattern: approval.rule.pattern }) | ||
| : undefined, | ||
| } | ||
| } | ||
|
|
||
| /** The single "why was this allowed" line shown inside a tool row's expanded body. */ | ||
| export function ToolApprovalLine(props: { display: ToolApprovalDisplay }) { | ||
| const manual = () => props.display.approval.source === "manual" | ||
| return ( | ||
| <div data-slot="tool-approval-line" data-source={props.display.approval.source}> | ||
| <span data-slot="tool-approval-decision">{props.display.decision}</span> | ||
| <Show when={!manual()}> | ||
| <Show when={props.display.source}> | ||
| {(text) => <span data-slot="tool-approval-source">{text()}</span>} | ||
| </Show> | ||
| <Show when={props.display.rule}>{(text) => <span data-slot="tool-approval-rule">{text()}</span>}</Show> | ||
| </Show> | ||
| </div> | ||
| ) | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.