fix: hide duplicated bash permission pattern
Removes permission patterns already shown as the rendered bash command Keeps distinct patterns visible in the permission card Adds tests for the pattern filtering behavior
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import { getVisiblePermissionPatterns } from './permissionCardPatterns';
|
||||
|
||||
describe('getVisiblePermissionPatterns', () => {
|
||||
test('omits a pattern already rendered as the bash command', () => {
|
||||
const command = 'bunx eslint "src/components/session/SessionSidebar.tsx"';
|
||||
|
||||
expect(getVisiblePermissionPatterns([command], command)).toEqual([]);
|
||||
});
|
||||
|
||||
test('preserves distinct permission patterns', () => {
|
||||
const command = 'bunx eslint "src/components/session/SessionSidebar.tsx"';
|
||||
|
||||
expect(getVisiblePermissionPatterns(['bunx eslint *', command], command)).toEqual(['bunx eslint *']);
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay';
|
||||
import { Icon } from "@/components/icon/Icon";
|
||||
import { DiffPreview, WritePreview } from './DiffPreview';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { getVisiblePermissionPatterns } from './permissionCardPatterns';
|
||||
|
||||
const PERMISSION_BASH_CUSTOM_STYLE: React.CSSProperties = {
|
||||
margin: 0,
|
||||
@@ -123,6 +124,7 @@ export const PermissionCard: React.FC<PermissionCardProps> = ({
|
||||
|
||||
const toolName = permission.permission || 'unknown';
|
||||
const tool = toolName.toLowerCase();
|
||||
const isBashTool = tool === 'bash' || tool === 'shell' || tool === 'shell_command';
|
||||
|
||||
const getMeta = (key: string, fallback: string = ''): string => {
|
||||
const val = permission.metadata[key];
|
||||
@@ -137,11 +139,14 @@ export const PermissionCard: React.FC<PermissionCardProps> = ({
|
||||
return Boolean(val);
|
||||
};
|
||||
const displayToolName = getToolDisplayName(toolName);
|
||||
const bashCommand = isBashTool
|
||||
? getMeta('command') || getMeta('cmd') || getMeta('script')
|
||||
: '';
|
||||
const visiblePatterns = getVisiblePermissionPatterns(permission.patterns, bashCommand);
|
||||
|
||||
const renderToolContent = () => {
|
||||
|
||||
if (tool === 'bash' || tool === 'shell' || tool === 'shell_command') {
|
||||
const command = getMeta('command') || getMeta('cmd') || getMeta('script');
|
||||
if (isBashTool) {
|
||||
const description = getMeta('description');
|
||||
const workingDir = getMeta('cwd') || getMeta('working_directory') || getMeta('directory') || getMeta('path');
|
||||
const timeout = getMetaNum('timeout');
|
||||
@@ -162,11 +167,11 @@ export const PermissionCard: React.FC<PermissionCardProps> = ({
|
||||
</div>
|
||||
)}
|
||||
{}
|
||||
{command && (
|
||||
{bashCommand && (
|
||||
<div>
|
||||
<WorkerHighlightedCode
|
||||
language="bash"
|
||||
code={command}
|
||||
code={bashCommand}
|
||||
style={PERMISSION_BASH_CUSTOM_STYLE}
|
||||
codeStyle={PERMISSION_BASH_CODE_TAG_PROPS.style}
|
||||
wrap
|
||||
@@ -333,11 +338,11 @@ export const PermissionCard: React.FC<PermissionCardProps> = ({
|
||||
|
||||
{}
|
||||
<div className="px-2 py-2">
|
||||
{permission.patterns.length > 0 && (
|
||||
{visiblePatterns.length > 0 && (
|
||||
<div className="mb-2">
|
||||
<div className="typography-meta text-muted-foreground mb-1">{t('chat.permissionCard.patterns')}</div>
|
||||
<code className="typography-meta px-2 py-1 bg-muted/30 rounded block break-all">
|
||||
{permission.patterns.join(", ")}
|
||||
{visiblePatterns.join(", ")}
|
||||
</code>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export const getVisiblePermissionPatterns = (patterns: string[], renderedCommand: string): string[] => {
|
||||
if (!renderedCommand) return patterns;
|
||||
return patterns.filter((pattern) => pattern !== renderedCommand);
|
||||
};
|
||||
Reference in New Issue
Block a user