From ab12b0a96d90d549c2703777ee272bf3bfcef1b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 7 Apr 2026 10:22:15 +0000 Subject: [PATCH 1/2] fix: remove dead per-turn fetches from system prompt builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every message send was fetching vault structure, available workspaces, prompt summaries, and tool agent info — then passing all four to SystemPromptBuilder.build() where none of them were ever read. This removes the fetch calls, the two helper methods (getAvailablePromptSummaries, getToolAgentInfo), their supporting interfaces (AgentToolLike, AgentLike, AppWithPlugins), and the dead fields from SystemPromptOptions. The types (PromptSummary, ToolAgentInfo, VaultStructure, WorkspaceSummary) and the WorkspaceIntegrationService methods are kept since WorkflowRunService still uses them. https://claude.ai/code/session_01XbMN35zn6yxTpYWbNzh57h --- src/ui/chat/services/ModelAgentManager.ts | 106 +------------------- src/ui/chat/services/SystemPromptBuilder.ts | 6 -- 2 files changed, 2 insertions(+), 110 deletions(-) diff --git a/src/ui/chat/services/ModelAgentManager.ts b/src/ui/chat/services/ModelAgentManager.ts index 088509974..db460d355 100644 --- a/src/ui/chat/services/ModelAgentManager.ts +++ b/src/ui/chat/services/ModelAgentManager.ts @@ -6,7 +6,7 @@ import { ModelOption, PromptOption } from '../types/SelectionTypes'; import { WorkspaceContext } from '../../../database/types/workspace/WorkspaceTypes'; import { MessageEnhancement } from '../components/suggesters/base/SuggesterInterfaces'; -import { SystemPromptBuilder, PromptSummary, ToolAgentInfo, ContextStatusInfo } from './SystemPromptBuilder'; +import { SystemPromptBuilder, ContextStatusInfo } from './SystemPromptBuilder'; import { ContextNotesManager } from './ContextNotesManager'; import { ModelSelectionUtility } from '../utils/ModelSelectionUtility'; import { PromptConfigurationUtility } from '../utils/PromptConfigurationUtility'; @@ -86,25 +86,6 @@ interface ConversationServiceLike { updateConversationMetadata(conversationId: string, metadata: Record): Promise; } -interface AgentToolLike { - slug?: string; - name?: string; -} - -interface AgentLike { - description?: string; - getTools?: () => AgentToolLike[]; -} - -/** - * App type with plugin registry access - */ -type AppWithPlugins = { - plugins?: { - plugins?: Record; - }; -} & Omit; - /** * Plugin interface with settings structure */ @@ -125,11 +106,6 @@ interface PluginWithSettings { serviceManager?: { getServiceIfReady?: (name: string) => unknown; }; - connector?: { - agentRegistry?: { - getAllAgents: () => Map; - }; - }; } export interface ModelAgentManagerEvents { @@ -1035,12 +1011,6 @@ export class ModelAgentManager { private async buildSystemPromptWithWorkspace(): Promise { const sessionId = await this.getCurrentSessionId(); - // Fetch dynamic context (always fresh) - const vaultStructure = this.workspaceIntegration.getVaultStructure(); - const availableWorkspaces = await this.workspaceIntegration.listAvailableWorkspaces(); - const availablePrompts = await this.getAvailablePromptSummaries(); - const toolAgents = this.getToolAgentInfo(); - // Skip tools section for Nexus/WebLLM - it's pre-trained on the toolset const isNexusModel = this.selectedModel?.providerId === 'webllm'; @@ -1064,12 +1034,7 @@ export class ModelAgentManager { messageEnhancement: this.messageEnhancement, customPrompt: this.currentSystemPrompt, workspaceContext: this.workspaceContext, - loadedWorkspaceData: this.loadedWorkspaceData, // Full comprehensive workspace data - // Dynamic context (always loaded fresh) - vaultStructure, - availableWorkspaces, - availablePrompts, - toolAgents, + loadedWorkspaceData: this.loadedWorkspaceData, // Nexus models are pre-trained on the toolset - skip tools section skipToolsSection: isNexusModel, // Context status for token-limited models @@ -1118,73 +1083,6 @@ export class ModelAgentManager { return this.hasCompactionFrontier(); } - /** - * Get available prompts as summaries for system prompt - * Note: These are user-created prompts, displayed in system prompt for LLM awareness - */ - private async getAvailablePromptSummaries(): Promise { - const prompts = await this.getAvailablePrompts(); - return prompts.map(prompt => ({ - id: prompt.id, - name: prompt.name, - description: prompt.description || 'Custom prompt' - })); - } - - /** - * Get tool agents info from agent registry for system prompt - * Returns agent names, descriptions, and their available tools - */ - private getToolAgentInfo(): ToolAgentInfo[] { - try { - // Access plugin from app - const appWithPlugins = this.app as unknown as AppWithPlugins; - const plugin = appWithPlugins.plugins?.plugins?.['claudesidian-mcp'] as unknown as PluginWithSettings | undefined; - if (!plugin) { - return []; - } - - // Try agentRegistrationService first (works on both desktop and mobile) - const agentService = plugin.serviceManager?.getServiceIfReady?.('agentRegistrationService'); - if (agentService) { - const typedAgentService = agentService as { getAllAgents: () => Map | Array<{ name: string } & AgentLike> }; - const agents = typedAgentService.getAllAgents(); - const agentMap = agents instanceof Map ? agents : new Map(agents.map((a) => [a.name, a])); - - return Array.from(agentMap.entries()).map(([name, agent]) => { - const agentTools = agent.getTools?.() || []; - return { - name, - description: agent.description || '', - tools: agentTools.map(t => t.slug || t.name || 'unknown') - }; - }); - } - - // Fallback to connector's agentRegistry (desktop only) - const connector = plugin.connector; - if (connector?.agentRegistry) { - const agents = connector.agentRegistry.getAllAgents(); - const result: ToolAgentInfo[] = []; - - for (const [name, agent] of agents) { - const agentTools = agent.getTools?.() || []; - result.push({ - name, - description: agent.description || '', - tools: agentTools.map(t => t.slug || t.name || 'unknown') - }); - } - - return result; - } - - return []; - } catch { - return []; - } - } - /** * Get current session ID from conversation */ diff --git a/src/ui/chat/services/SystemPromptBuilder.ts b/src/ui/chat/services/SystemPromptBuilder.ts index 87998e1bd..8e086e2a9 100644 --- a/src/ui/chat/services/SystemPromptBuilder.ts +++ b/src/ui/chat/services/SystemPromptBuilder.ts @@ -82,12 +82,6 @@ export interface SystemPromptOptions { workspaceContext?: WorkspaceContext | null; // Full comprehensive workspace data from LoadWorkspaceTool (when workspace selected in settings) loadedWorkspaceData?: LoadedWorkspaceData | null; - // Dynamic context (always loaded fresh) - vaultStructure?: VaultStructure | null; - availableWorkspaces?: WorkspaceSummary[]; - availablePrompts?: PromptSummary[]; - // Tool agents with their tools (dynamically loaded from agent registry) - toolAgents?: ToolAgentInfo[]; // Skip the tools section for models that are pre-trained on the toolset (e.g., Nexus) skipToolsSection?: boolean; // Context status for token-limited models (enables context awareness) From 7b63377f6ca00f60ddb98ee0134a76e18425c1a5 Mon Sep 17 00:00:00 2001 From: ProfSynapse Date: Tue, 7 Apr 2026 07:40:40 -0400 Subject: [PATCH 2/2] fix: remove context guard that blocked workspace selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `if (workspace?.context)` guard in ChatSettingsModal silently skipped setWorkspaceContext() for any workspace without a populated contextJson column — which is most user-created workspaces. The context parameter was dead weight: setWorkspaceContext() loads everything it needs from workspaceId via loadWorkspace(). Remove the guard, the unnecessary getWorkspace() fetch, and the dead context parameter from setWorkspaceContext(). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/ui/chat/components/ChatSettingsModal.ts | 5 +---- src/ui/chat/services/ModelAgentManager.ts | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ui/chat/components/ChatSettingsModal.ts b/src/ui/chat/components/ChatSettingsModal.ts index ecea7adfa..fad47a813 100644 --- a/src/ui/chat/components/ChatSettingsModal.ts +++ b/src/ui/chat/components/ChatSettingsModal.ts @@ -179,10 +179,7 @@ export class ChatSettingsModal extends Modal { // Update workspace if (settings.workspaceId) { - const workspace = await this.workspaceService.getWorkspace(settings.workspaceId); - if (workspace?.context) { - await this.modelAgentManager.setWorkspaceContext(settings.workspaceId, workspace.context); - } + await this.modelAgentManager.setWorkspaceContext(settings.workspaceId); } else { await this.modelAgentManager.clearWorkspaceContext(); } diff --git a/src/ui/chat/services/ModelAgentManager.ts b/src/ui/chat/services/ModelAgentManager.ts index db460d355..7e7470ad4 100644 --- a/src/ui/chat/services/ModelAgentManager.ts +++ b/src/ui/chat/services/ModelAgentManager.ts @@ -623,9 +623,8 @@ export class ModelAgentManager { * When a workspace is selected in chat settings, load the same rich data * as the #workspace suggester (file structure, sessions, states, etc.) */ - async setWorkspaceContext(workspaceId: string, context: WorkspaceContext): Promise { + async setWorkspaceContext(workspaceId: string): Promise { this.selectedWorkspaceId = workspaceId; - this.workspaceContext = context; // Keep basic context for backward compatibility // Load full comprehensive workspace data (same as #workspace suggester) try {