feat: overhaul AI settings, fix Catty Agent streaming and tool execution

AI Settings:
- Remove External Agents section, add dedicated Codex/Claude Code sections
  with auto-detection and manual path override
- Add OpenRouter model list auto-fetch with searchable dropdown
- Remove standalone Default Model section, integrate into provider cards
- Provider toggle now acts as mutual-exclusive active selector
- Add cross-window state sync via storage events
- Add ErrorBoundary around AI tab for graceful error handling

Catty Agent fixes:
- Fix streaming: use .chat() instead of default Responses API, use
  getReader() pattern instead of for-await, handle text-delta/text chunk
  types correctly per SDK v6
- Fix API key: decrypt encrypted key before passing to SDK
- Fix terminal_execute: use PTY stream (visible in terminal) with MCP
  markers instead of invisible SSH exec channel
- Fix multi-turn: only pass user/assistant text history, skip tool
  messages to avoid SDK schema validation errors
- Fix tool result display: create new assistant message after tool
  results so follow-up text renders correctly

Other:
- Add netcatty:ai:resolve-cli IPC handler for CLI path validation
- Remove Gemini from agent discovery (only Codex + Claude Code)
- Fix lint errors across ChatInput, TerminalLayer, SettingsAITab
- Strip MCP markers from tool execution stdout

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
bincxzandClaude Opus 4.6 committed 2026-03-15 03:53:39 +08:00
1 parent 3136100514
commit f53bc05cb3
9 files changed
+864 -387

No files matched your search

+40 -1
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { localStorageAdapter } from '../../infrastructure/persistence/localStorageAdapter';
import {
STORAGE_KEY_AI_PROVIDERS,
@@ -131,6 +131,45 @@ export function useAIState() {
localStorageAdapter.writeNumber(STORAGE_KEY_AI_MAX_ITERATIONS, value);
}, []);
// ── Cross-window sync via storage events ──
// When the settings window updates localStorage, the main window picks up changes.
useEffect(() => {
const handleStorage = (e: StorageEvent) => {
switch (e.key) {
case STORAGE_KEY_AI_PROVIDERS:
setProvidersRaw(localStorageAdapter.read<ProviderConfig[]>(STORAGE_KEY_AI_PROVIDERS) ?? []);
break;
case STORAGE_KEY_AI_ACTIVE_PROVIDER:
setActiveProviderIdRaw(localStorageAdapter.readString(STORAGE_KEY_AI_ACTIVE_PROVIDER) ?? '');
break;
case STORAGE_KEY_AI_ACTIVE_MODEL:
setActiveModelIdRaw(localStorageAdapter.readString(STORAGE_KEY_AI_ACTIVE_MODEL) ?? '');
break;
case STORAGE_KEY_AI_PERMISSION_MODE: {
const mode = localStorageAdapter.readString(STORAGE_KEY_AI_PERMISSION_MODE);
if (mode === 'observer' || mode === 'confirm' || mode === 'autonomous') {
setGlobalPermissionModeRaw(mode);
}
break;
}
case STORAGE_KEY_AI_EXTERNAL_AGENTS:
setExternalAgentsRaw(localStorageAdapter.read<ExternalAgentConfig[]>(STORAGE_KEY_AI_EXTERNAL_AGENTS) ?? []);
break;
case STORAGE_KEY_AI_DEFAULT_AGENT:
setDefaultAgentIdRaw(localStorageAdapter.readString(STORAGE_KEY_AI_DEFAULT_AGENT) ?? 'catty');
break;
case STORAGE_KEY_AI_COMMAND_TIMEOUT:
setCommandTimeoutRaw(localStorageAdapter.readNumber(STORAGE_KEY_AI_COMMAND_TIMEOUT) ?? 60);
break;
case STORAGE_KEY_AI_MAX_ITERATIONS:
setMaxIterationsRaw(localStorageAdapter.readNumber(STORAGE_KEY_AI_MAX_ITERATIONS) ?? 20);
break;
}
};
window.addEventListener('storage', handleStorage);
return () => window.removeEventListener('storage', handleStorage);
}, []);
// ── Session CRUD ──
const persistSessions = useCallback((next: AISession[]) => {
localStorageAdapter.write(STORAGE_KEY_AI_SESSIONS, next);