-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(tool_policy): diagnostics RPC and Developer Options panel #2715
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
Open
MrMrVlad
wants to merge
5
commits into
tinyhumansai:main
Choose a base branch
from
MrMrVlad:feat/2136-tool-policy-diagnostics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01eb678
feat(tool_policy): add diagnostics RPC and Developer Options panel
3c63b46
chore(app): format diagnostics panel files
4dacb92
fix(tool_policy): address PR review — i18n, redaction, test regex
4e7a457
chore: apply pre-push auto-fixes
a739c7d
test(tool_policy): clear denial buffer before registry tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
275 changes: 275 additions & 0 deletions
275
app/src/components/settings/panels/ToolPolicyDiagnosticsPanel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,275 @@ | ||
| import { useEffect, useMemo, useState } from 'react'; | ||
|
|
||
| import { useT } from '../../../lib/i18n/I18nContext'; | ||
| import { callCoreRpc } from '../../../services/coreRpcClient'; | ||
| import SettingsHeader from '../components/SettingsHeader'; | ||
| import { useSettingsNavigation } from '../hooks/useSettingsNavigation'; | ||
|
|
||
| type ToolPolicyDiagnostics = { | ||
| total_tools: number; | ||
| enabled_tools: number; | ||
| mcp_stdio_tools: number; | ||
| json_rpc_tools: number; | ||
| possible_write_surfaces: string[]; | ||
| policy_surfaces: string[]; | ||
| posture: { | ||
| autonomy_level: string; | ||
| workspace_only: boolean; | ||
| max_actions_per_hour: number; | ||
| require_approval_for_medium_risk: boolean; | ||
| block_high_risk_commands: boolean; | ||
| }; | ||
| mcp_allowlists: { | ||
| enabled: boolean; | ||
| server_count: number; | ||
| enabled_server_count: number; | ||
| servers: { | ||
| name: string; | ||
| enabled: boolean; | ||
| allowed_tools_count: number; | ||
| disallowed_tools_count: number; | ||
| has_allowlist: boolean; | ||
| has_denylist: boolean; | ||
| }[]; | ||
| }; | ||
| mcp_write_audit: { enabled: boolean; recent_rows: number | null; last_error: string | null }; | ||
| recent_denials: { | ||
| timestamp_ms: number; | ||
| tool_name: string; | ||
| policy: string; | ||
| action: string; | ||
| reason: string; | ||
| }[]; | ||
| }; | ||
|
|
||
| const ToolPolicyDiagnosticsPanel = () => { | ||
| const { t } = useT(); | ||
| const { navigateBack, breadcrumbs } = useSettingsNavigation(); | ||
|
|
||
| const [status, setStatus] = useState< | ||
| | { kind: 'loading' } | ||
| | { kind: 'ready'; diagnostics: ToolPolicyDiagnostics } | ||
| | { kind: 'error'; message: string } | ||
| >({ kind: 'loading' }); | ||
|
|
||
| useEffect(() => { | ||
| let cancelled = false; | ||
| (async () => { | ||
| try { | ||
| const diagnostics = await callCoreRpc<ToolPolicyDiagnostics>({ | ||
| method: 'tool_registry.diagnostics', | ||
| params: {}, | ||
| timeoutMs: 10_000, | ||
| }); | ||
| if (cancelled) return; | ||
| setStatus({ kind: 'ready', diagnostics }); | ||
| } catch (err) { | ||
| if (cancelled) return; | ||
| setStatus({ kind: 'error', message: err instanceof Error ? err.message : String(err) }); | ||
| } | ||
| })(); | ||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, []); | ||
|
|
||
| const body = useMemo(() => { | ||
| if (status.kind === 'loading') { | ||
| return ( | ||
| <div className="px-4 py-3 text-sm text-sage-700 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.loading')} | ||
| </div> | ||
| ); | ||
| } | ||
| if (status.kind === 'error') { | ||
| return ( | ||
| <div className="px-4 py-3 rounded-lg border border-coral-300 dark:border-coral-500/40 bg-coral-50 dark:bg-coral-500/10"> | ||
| <div className="text-sm font-semibold text-coral-900 dark:text-coral-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.unavailable')} | ||
| </div> | ||
| <div className="text-xs text-coral-800 dark:text-coral-200 mt-1 font-mono break-words"> | ||
| {status.message} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const d = status.diagnostics; | ||
| const recentRows = | ||
| d.mcp_write_audit.recent_rows === null ? '—' : String(d.mcp_write_audit.recent_rows); | ||
|
|
||
| return ( | ||
| <div className="px-4 pt-3 pb-6 flex flex-col gap-3"> | ||
| <div className="px-4 py-3 rounded-lg border border-sage-300 dark:border-sage-500/40 bg-sage-50 dark:bg-sage-500/10"> | ||
| <div className="text-sm font-semibold text-sage-900 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.posture.title')} | ||
| </div> | ||
| <dl className="mt-2 grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs"> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.posture.autonomy')} | ||
| </dt> | ||
| <dd className="font-mono text-sage-900 dark:text-sage-200"> | ||
| {d.posture.autonomy_level} | ||
| </dd> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.posture.workspaceOnly')} | ||
| </dt> | ||
| <dd className="text-sage-900 dark:text-sage-200">{String(d.posture.workspace_only)}</dd> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.posture.maxActionsPerHour')} | ||
| </dt> | ||
| <dd className="font-mono text-sage-900 dark:text-sage-200"> | ||
| {d.posture.max_actions_per_hour} | ||
| </dd> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.posture.approvalMediumRisk')} | ||
| </dt> | ||
| <dd className="text-sage-900 dark:text-sage-200"> | ||
| {String(d.posture.require_approval_for_medium_risk)} | ||
| </dd> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.posture.blockHighRisk')} | ||
| </dt> | ||
| <dd className="text-sage-900 dark:text-sage-200"> | ||
| {String(d.posture.block_high_risk_commands)} | ||
| </dd> | ||
| </dl> | ||
| </div> | ||
|
|
||
| <div className="px-4 py-3 rounded-lg border border-sage-300 dark:border-sage-500/40 bg-white dark:bg-sage-900/20"> | ||
| <div className="text-sm font-semibold text-sage-900 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.inventory.title')} | ||
| </div> | ||
| <dl className="mt-2 grid grid-cols-2 gap-x-6 gap-y-1 text-xs"> | ||
| <div> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.inventory.totalTools')} | ||
| </dt> | ||
| <dd className="font-mono text-sage-900 dark:text-sage-200">{d.total_tools}</dd> | ||
| </div> | ||
| <div> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.inventory.enabledTools')} | ||
| </dt> | ||
| <dd className="font-mono text-sage-900 dark:text-sage-200">{d.enabled_tools}</dd> | ||
| </div> | ||
| <div> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.inventory.mcpStdioTools')} | ||
| </dt> | ||
| <dd className="font-mono text-sage-900 dark:text-sage-200">{d.mcp_stdio_tools}</dd> | ||
| </div> | ||
| <div> | ||
| <dt className="text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.inventory.jsonRpcTools')} | ||
| </dt> | ||
| <dd className="font-mono text-sage-900 dark:text-sage-200">{d.json_rpc_tools}</dd> | ||
| </div> | ||
| </dl> | ||
| </div> | ||
|
|
||
| <div className="px-4 py-3 rounded-lg border border-sage-300 dark:border-sage-500/40 bg-white dark:bg-sage-900/20"> | ||
| <div className="text-sm font-semibold text-sage-900 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.mcpAllowlists.title')} | ||
| </div> | ||
| <div className="mt-1 text-xs text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.mcpAllowlists.summary') | ||
| .replace('{enabled}', String(d.mcp_allowlists.enabled)) | ||
| .replace('{enabledCount}', String(d.mcp_allowlists.enabled_server_count)) | ||
| .replace('{totalCount}', String(d.mcp_allowlists.server_count))} | ||
| </div> | ||
| {d.mcp_allowlists.servers.length > 0 && ( | ||
| <ul className="mt-2 text-xs space-y-1"> | ||
| {d.mcp_allowlists.servers.slice(0, 10).map(s => ( | ||
| <li key={s.name} className="flex items-center justify-between gap-3"> | ||
| <span | ||
| className="font-mono text-sage-900 dark:text-sage-200 truncate" | ||
| title={s.name}> | ||
| {s.name || t('devOptions.toolPolicyDiagnostics.mcpAllowlists.unnamed')} | ||
| </span> | ||
| <span className="text-sage-700 dark:text-sage-300 font-mono"> | ||
| {t('devOptions.toolPolicyDiagnostics.mcpAllowlists.allowDeny') | ||
| .replace('{allowCount}', String(s.allowed_tools_count)) | ||
| .replace('{denyCount}', String(s.disallowed_tools_count))} | ||
| </span> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="px-4 py-3 rounded-lg border border-sage-300 dark:border-sage-500/40 bg-white dark:bg-sage-900/20"> | ||
| <div className="text-sm font-semibold text-sage-900 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.mcpWriteAudit.title')} | ||
| </div> | ||
| <div className="mt-1 text-xs text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.mcpWriteAudit.summary') | ||
| .replace('{enabled}', String(d.mcp_write_audit.enabled)) | ||
| .replace('{recentRows}', recentRows)} | ||
| </div> | ||
| {d.mcp_write_audit.last_error && ( | ||
| <div className="mt-2 text-xs text-coral-700 dark:text-coral-200 font-mono break-words"> | ||
| {d.mcp_write_audit.last_error} | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="px-4 py-3 rounded-lg border border-sage-300 dark:border-sage-500/40 bg-white dark:bg-sage-900/20"> | ||
| <div className="text-sm font-semibold text-sage-900 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.recentBlocked.title')} | ||
| </div> | ||
| {d.recent_denials.length === 0 ? ( | ||
| <div className="mt-1 text-xs text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.recentBlocked.empty')} | ||
| </div> | ||
| ) : ( | ||
| <ul className="mt-2 text-xs space-y-1"> | ||
| {d.recent_denials.slice(0, 10).map(entry => ( | ||
| <li | ||
| key={`${entry.timestamp_ms}:${entry.tool_name}`} | ||
| className="flex flex-col gap-0.5"> | ||
| <div className="flex items-center justify-between gap-3"> | ||
| <span | ||
| className="font-mono text-sage-900 dark:text-sage-200 truncate" | ||
| title={entry.tool_name}> | ||
| {entry.tool_name} | ||
| </span> | ||
| <span className="text-sage-700 dark:text-sage-300 font-mono"> | ||
| {entry.policy}:{entry.action} | ||
| </span> | ||
| </div> | ||
| <div className="text-sage-700 dark:text-sage-300 break-words">{entry.reason}</div> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="px-4 py-3 rounded-lg border border-sage-300 dark:border-sage-500/40 bg-white dark:bg-sage-900/20"> | ||
| <div className="text-sm font-semibold text-sage-900 dark:text-sage-200"> | ||
| {t('devOptions.toolPolicyDiagnostics.redactedSurfaces.title')} | ||
| </div> | ||
| <div className="mt-1 text-xs text-sage-700 dark:text-sage-300"> | ||
| {t('devOptions.toolPolicyDiagnostics.redactedSurfaces.summary') | ||
| .replace('{writeCount}', String(d.possible_write_surfaces.length)) | ||
| .replace('{policyCount}', String(d.policy_surfaces.length))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }, [status, t]); | ||
|
|
||
| return ( | ||
| <div className="z-10 relative"> | ||
| <SettingsHeader | ||
| title={t('devOptions.diagnostics')} | ||
| showBackButton={true} | ||
| onBack={navigateBack} | ||
| breadcrumbs={breadcrumbs} | ||
| /> | ||
| {body} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ToolPolicyDiagnosticsPanel; |
49 changes: 49 additions & 0 deletions
49
app/src/components/settings/panels/__tests__/ToolPolicyDiagnosticsPanel.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
| import { describe, expect, test, vi } from 'vitest'; | ||
|
|
||
| import { renderWithProviders } from '../../../../test/test-utils'; | ||
|
|
||
| const hoisted = vi.hoisted(() => ({ callCoreRpc: vi.fn() })); | ||
|
|
||
| vi.mock('../../../../services/coreRpcClient', () => ({ | ||
| callCoreRpc: (...args: unknown[]) => hoisted.callCoreRpc(...args), | ||
| })); | ||
|
|
||
| vi.mock('../../hooks/useSettingsNavigation', () => ({ | ||
| useSettingsNavigation: () => ({ navigateBack: vi.fn(), breadcrumbs: [] }), | ||
| })); | ||
|
|
||
| describe('ToolPolicyDiagnosticsPanel', () => { | ||
| test('renders diagnostics from core RPC', async () => { | ||
| hoisted.callCoreRpc.mockResolvedValue({ | ||
| total_tools: 10, | ||
| enabled_tools: 10, | ||
| mcp_stdio_tools: 3, | ||
| json_rpc_tools: 7, | ||
| possible_write_surfaces: ['tools.composio_execute'], | ||
| policy_surfaces: ['security.policy_info'], | ||
| posture: { | ||
| autonomy_level: 'supervised', | ||
| workspace_only: true, | ||
| max_actions_per_hour: 123, | ||
| require_approval_for_medium_risk: true, | ||
| block_high_risk_commands: true, | ||
| }, | ||
| mcp_allowlists: { enabled: true, server_count: 0, enabled_server_count: 0, servers: [] }, | ||
| mcp_write_audit: { enabled: true, recent_rows: 5, last_error: null }, | ||
| recent_denials: [], | ||
| }); | ||
|
|
||
| const Panel = (await import('../ToolPolicyDiagnosticsPanel')).default; | ||
| renderWithProviders(<Panel />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(/Policy posture/i)).toBeInTheDocument(); | ||
| }); | ||
| expect(screen.getByText('supervised')).toBeInTheDocument(); | ||
| expect(screen.getByText(/Total tools/i)).toBeInTheDocument(); | ||
| expect(screen.getAllByText('10').length).toBeGreaterThan(0); | ||
| expect(screen.getByText(/Recent \(24h\): 5/i)).toBeInTheDocument(); | ||
| expect(hoisted.callCoreRpc).toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 766
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 310
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 60380
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 45495
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 189
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 2583
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 137
🏁 Script executed:
Repository: tinyhumansai/openhuman
Length of output: 381
Propagate the new
devOptions.toolPolicyDiagnostics.*i18n keys into all chunked locale filesThe keys added in
app/src/lib/i18n/en.ts(devOptions.toolPolicyDiagnostics.*) are missing fromapp/src/lib/i18n/chunks/en-*.tsand corresponding non-English chunk files (e.g.,ar-*.ts), which will cause missing UI text for chunked locales. Add these exact keys to the matchingen-N.tschunk and to every non-English locale chunk (ar,bn,de,es,fr,hi,id,it,ko,pt,ru,zh-CN) using the English value as the placeholder if needed.🤖 Prompt for AI Agents