import * as vscode from "vscode"; import OpenAI from "openai"; import https from "https"; import fs from "fs"; import {translations} from "./translations" import { Agent } from "./types"; import { Utils } from "./utils"; import { ToolsPermissionsMode as ToolsPermissonsMode} from "./constants"; export class Configuration { // extension configs enabled = true; launch_completion = "" launch_chat = "" launch_embeddings = "" launch_tools = "" launch_training_completion = "" launch_training_chat = "" lora_completion = "" lora_chat = "" endpoint = "http=//127.0.0.1:8012"; endpoint_chat = "http=//127.0.0.1:8011"; endpoint_tools = "http=//127.0.0.1:8011"; endpoint_embeddings = "http=//127.0.0.1:8010"; new_completion_model_port = 8012 new_chat_model_port = 8011 new_embeddings_model_port = 8010 new_tools_model_port = 8009 new_completion_model_host = "127.0.0.1" new_chat_model_host = "127.0.0.1" new_embeddings_model_host = "127.0.0.1" new_tools_model_host = "127.0.0.1" auto = true; debounce_ms = 0; api_key = ""; api_key_chat = ""; api_key_tools = ""; api_key_embeddings = "" self_signed_certificate = ""; n_prefix = 256; n_suffix = 64; n_predict = 128; t_max_prompt_ms = 500; t_max_predict_ms = 2500; show_info = true; max_line_suffix = 8; max_cache_keys = 250; ring_n_chunks = 16; ring_chunk_size = 64; ring_scope = 1024; ring_update_ms = 1000; skills_folder = "" hooks_folder = "" scripts_folder = "" language = "en"; health_check_interval_s = 30; health_check_compl_enabled = false; health_check_chat_enabled = false; health_check_embs_enabled = false; health_check_tools_enabled = false; only_one_local_model = false; // experimental - avoid using use_openai_endpoint = false; openai_client: OpenAI | null = null; openai_client_model: string = ""; openai_prompt_template: string = "<|fim_prefix|>{inputPrefix}{prompt}<|fim_suffix|>{inputSuffix}<|fim_middle|>"; rag_enabled = false; rag_chunk_max_chars = 800 rag_max_lines_per_chunk = 40 rag_max_chars_per_chunk_line = 300 rag_max_files = 10000 rag_max_chunks = 50000 rag_max_bm25_filter_chunks = 47 rag_max_embedding_filter_chunks = 5 rag_max_context_files = 3 rag_max_context_file_chars = 10000 rag_ignore_file = "" tool_run_terminal_command_enabled = true; tool_run_terminal_command_timeout = 300; tool_run_terminal_command_max_chars = 5000; tool_create_agent_enabled = true; tool_search_source_enabled = true; tool_read_file_enabled = true; tool_list_directory_enabled = true; tool_regex_search_enabled = true; tool_delete_file_enabled = true; tool_permit_some_terminal_commands = false; tools_permissions_mode = ToolsPermissonsMode.Ask.toString(); tool_permit_file_changes = false tool_permit_file_delete = false tool_get_diff_enabled = false; tool_edit_file_enabled = true; tool_multi_edit_file_enabled = true; tool_ask_user_enabled = true; tool_custom_tool_enabled = false; tool_custom_tool_description = ""; tool_custom_tool_source = "" tool_custom_eval_tool_enabled = false tool_custom_eval_tool_description = "" tool_custom_eval_tool_property_description = "" tool_custom_eval_tool_code = ""; tool_llama_vscode_help_enabled = true; tool_update_todo_list_enabled = true; tool_delegate_task_enabled = true; tool_get_errors_enabled = true; tool_rename_symbol_enabled = true tool_search_tools_enabled = false; tool_web_browser_enabled = false; web_browser_max_chars = 6000; web_browser_max_results = 5; web_browser_timeout_s = 20; web_browser_allow_local_urls = false; tools_max_iterations = 50; auto_memory_enabled = true; max_auto_memory_files = 10; plan_review_frequency = 5; reminder_edit_file_frequency = 5 tools_log_calls = false; chats_max_history = 50; chats_max_tokens = 64000; chats_summarize_old_msgs = false; chats_msgs_keep = 50 lm_max_input_tokens = 0; lm_max_output_tokens = 0; max_parallel_completions = 3 completion_models_list = new Array(); embeddings_models_list = new Array(); tools_models_list = new Array(); chat_models_list = new Array(); envs_list = new Array(); env_start_last_used = false; env_start_last_used_confirm = true; ask_install_llamacpp = true; ask_upgrade_llamacpp_hours = 24; popup_max_chars = 160; ai_api_version = "v1"; ai_model = "google/gemini-2.5-flash" agents_list = new Array(); agent_rules = "" agent_commands = new Array(); tools_custom = new Array(); context_custom:object = {}; // additional configs` // TODO: change to snake_case for consistency axiosRequestConfigCompl = {}; axiosRequestConfigChat = {}; axiosRequestConfigTools = {}; axiosRequestConfigEmbeddings = {}; disabledLanguages: string[] = []; languageSettings:Record = {} telegram_api_token = "" telegram_bot_enabled = false; telegram_bot_users = "" telegram_chunk_size = 250; tools_permission_timeout = 600; send_prompt_from_editor_enabled = false; remove_sent_prompt_from_editor = false; // TODO: change to snake_case for consistency RING_UPDATE_MIN_TIME_LAST_COMPL = 3000; MIN_TIME_BETWEEN_COMPL = 600; MAX_LAST_PICK_LINE_DISTANCE = 32; MAX_QUEUED_CHUNKS = 16; DELAY_BEFORE_COMPL_REQUEST = 150; MAX_EVENTS_IN_LOG = 250; MAX_CHARS_TOOL_RETURN = 5000 config: vscode.WorkspaceConfiguration; private uiLanguages = new Map>([]) private langIndexes = new Map([ [0, "en"], [1, "bg"], [2, "de"], [3, "ru"], [4, "es"], [5, "cn"], [6, "fr"], ]); constructor() { this.config = vscode.workspace.getConfiguration("llama-vscode"); this.initUiLanguages() this.updateConfigs(this.config); this.setLlamaRequestConfig(); this.setOpenAiClient(); } private initUiLanguages(){ let totalLanguages = 0; if (translations.length > 0) totalLanguages = translations[0].length for (let langInd = 0; langInd < totalLanguages; langInd++){ let lang = new Map(translations.map(transl => [transl[0], transl[langInd]])); this.uiLanguages.set(this.langIndexes.get(langInd) ?? "", lang); } } private updateConfigs = (config: vscode.WorkspaceConfiguration) => { // TODO Handle the case of wrong types for the configuration values this.endpoint = Utils.trimTrailingSlash(String(config.get("endpoint"))); this.endpoint_chat = Utils.trimTrailingSlash(String(config.get("endpoint_chat"))); this.endpoint_tools = Utils.trimTrailingSlash(String(config.get("endpoint_tools"))); this.endpoint_embeddings = Utils.trimTrailingSlash(String(config.get("endpoint_embeddings"))); this.new_completion_model_port = Number(config.get("new_completion_model_port")); this.new_chat_model_port = Number(config.get("new_chat_model_port")); this.new_embeddings_model_port = Number(config.get("new_embeddings_model_port")); this.new_tools_model_port = Number(config.get("new_tools_model_port")); this.new_completion_model_host = String(config.get("new_completion_model_host")); this.new_chat_model_host = String(config.get("new_chat_model_host")); this.new_embeddings_model_host = String(config.get("new_embeddings_model_host")); this.new_tools_model_host = String(config.get("new_tools_model_host")); this.launch_completion = String(config.get("launch_completion")); this.launch_chat = String(config.get("launch_chat")); this.launch_embeddings = String(config.get("launch_embeddings")); this.launch_tools = String(config.get("launch_tools")); this.launch_training_completion = String(config.get("launch_training_completion")); this.launch_training_chat = String(config.get("launch_training_chat")); this.ai_model = String(config.get("ai_model")); this.ai_api_version = String(config.get("ai_api_version")); this.lora_completion = String(config.get("lora_completion")); this.lora_chat = String(config.get("lora_chat")); this.use_openai_endpoint = Boolean(config.get("use_openai_endpoint")); this.openai_client_model = String(config.get("openai_client_model")); this.openai_prompt_template = String(config.get("openai_prompt_template")); this.auto = Boolean(config.get("auto")); this.debounce_ms = Number(config.get("debounce_ms")); this.api_key = String(config.get("api_key")); this.api_key_chat = String(config.get("api_key_chat")); this.api_key_tools = String(config.get("api_key_tools")); this.api_key_embeddings = String(config.get("api_key_embeddings")); this.self_signed_certificate = String(config.get("self_signed_certificate")); this.n_prefix = Number(config.get("n_prefix")); this.n_suffix = Number(config.get("n_suffix")); this.n_predict = Number(config.get("n_predict")); this.rag_chunk_max_chars = Number(config.get("rag_chunk_max_chars")); this.rag_ignore_file = String(config.get("rag_ignore_file")); this.t_max_prompt_ms = Number(config.get("t_max_prompt_ms")); this.t_max_predict_ms = Number(config.get("t_max_predict_ms")); this.show_info = Boolean(config.get("show_info")); this.max_line_suffix = Number(config.get("max_line_suffix")); this.max_cache_keys = Number(config.get("max_cache_keys")); this.ring_n_chunks = Number(config.get("ring_n_chunks")); this.ring_chunk_size = Number(config.get("ring_chunk_size")); this.ring_scope = Number(config.get("ring_scope")); this.ring_update_ms = Number(config.get("ring_update_ms")); this.rag_enabled = Boolean(config.get("rag_enabled")); this.rag_max_lines_per_chunk = Number(config.get("rag_max_lines_per_chunk")); this.rag_max_chars_per_chunk_line = Number(config.get("rag_max_chars_per_chunk_line")); this.rag_max_files = Number(config.get("rag_max_files")); this.rag_max_chunks = Number(config.get("rag_max_chunks")); this.rag_max_bm25_filter_chunks = Number(config.get("rag_max_bm25_filter_chunks")); this.rag_max_embedding_filter_chunks = Number(config.get("rag_max_embedding_filter_chunks")); this.rag_max_context_files = Number(config.get("rag_max_context_files")); this.rag_max_context_file_chars = Number(config.get("rag_max_context_file_chars")); this.tool_run_terminal_command_enabled = Boolean(config.get("tool_run_terminal_command_enabled")); this.tool_run_terminal_command_timeout = Number(config.get("tool_run_terminal_command_timeout")); this.tool_run_terminal_command_max_chars = Number(config.get("tool_run_terminal_command_max_chars")); this.tool_create_agent_enabled = Boolean(config.get("tool_create_agent_enabled")); this.tool_search_source_enabled = Boolean(config.get("tool_search_source_enabled")); this.tool_read_file_enabled = Boolean(config.get("tool_read_file_enabled")); this.tool_list_directory_enabled = Boolean(config.get("tool_list_directory_enabled")); this.tool_regex_search_enabled = Boolean(config.get("tool_regex_search_enabled")); this.tool_delete_file_enabled = Boolean(config.get("tool_delete_file_enabled")); this.tool_permit_some_terminal_commands = Boolean(config.get("tool_permit_some_terminal_commands")); this.tools_permissions_mode = String(config.get("tools_permissions_mode")); this.tool_permit_file_changes = Boolean(config.get("tool_permit_file_changes")); this. tool_permit_file_delete = Boolean(config.get("tool_permit_file_delete")); this.tool_get_diff_enabled = Boolean(config.get("tool_get_diff_enabled")); this.tool_edit_file_enabled = Boolean(config.get("tool_edit_file_enabled")); this.tool_multi_edit_file_enabled = Boolean(config.get("tool_multi_edit_file_enabled")); this.tool_ask_user_enabled = Boolean(config.get("tool_ask_user_enabled")); this.tool_custom_tool_enabled = Boolean(config.get("tool_custom_tool_enabled")); this.tool_update_todo_list_enabled = Boolean(config.get("tool_update_todo_list_enabled")); this.tool_delegate_task_enabled = Boolean(config.get("tool_delegate_task_enabled")); this.tool_llama_vscode_help_enabled = Boolean(config.get("tool_llama_vscode_help_enabled")); this.only_one_local_model = Boolean(config.get("only_one_local_model")); this.tool_custom_tool_description = String(config.get("tool_custom_tool_description")); this.tool_custom_tool_source = String(config.get("tool_custom_tool_source")); this.tool_custom_eval_tool_enabled = Boolean(config.get("tool_custom_eval_tool_enabled")); this.tool_custom_eval_tool_property_description = String(config.get("tool_custom_eval_tool_property_description")); this.tool_custom_eval_tool_description = String(config.get("tool_custom_eval_tool_description")); this.tool_custom_eval_tool_code = String(config.get("tool_custom_eval_tool_code")); this.tools_max_iterations = Number(config.get("tools_max_iterations")); this.tool_get_errors_enabled = Boolean(config.get("tool_get_errors_enabled")); this.tool_rename_symbol_enabled = Boolean(config.get("tool_rename_symbol_enabled")); this.tool_search_tools_enabled = Boolean(config.get("tool_search_tools_enabled")); this.tool_web_browser_enabled = Boolean(config.get("tool_web_browser_enabled")); this.web_browser_max_chars = Number(config.get("web_browser_max_chars")); this.web_browser_max_results = Number(config.get("web_browser_max_results")); this.web_browser_timeout_s = Number(config.get("web_browser_timeout_s")); this.web_browser_allow_local_urls = Boolean(config.get("web_browser_allow_local_urls")); this.auto_memory_enabled = Boolean(config.get("auto_memory_enabled")); this.max_auto_memory_files = Number(config.get("max_auto_memory_files")); this.plan_review_frequency = Number(config.get("plan_review_frequency")); this.reminder_edit_file_frequency = Number(config.get("reminder_edit_file_frequency")); this.tools_log_calls = Boolean(config.get("tools_log_calls")); this.chats_max_history = Number(config.get("chats_max_history")); this.chats_max_tokens = Number(config.get("chats_max_tokens")); this.max_parallel_completions = Number(config.get("max_parallel_completions")); this.chats_summarize_old_msgs = Boolean(config.get("chats_summarize_old_msgs")); this.chats_msgs_keep = Number(config.get("chats_msgs_keep")); this.lm_max_input_tokens = Number(config.get("lm_max_input_tokens")); this.lm_max_output_tokens = Number(config.get("lm_max_output_tokens")); this.popup_max_chars = Number(config.get("popup_max_chars")); this.skills_folder = String(config.get("skills_folder")); this.hooks_folder = String(config.get("hooks_folder")); this.scripts_folder = String(config.get("scripts_folder")); this.language = String(config.get("language")); this.disabledLanguages = config.get("disabledLanguages") || []; this.enabled = Boolean(config.get("enabled", true)); this.languageSettings = config.get>('languageSettings') || {}; this.completion_models_list = config.get("completion_models_list")??new Array(); this.chat_models_list = config.get("chat_models_list")??new Array(); this.embeddings_models_list = config.get("embeddings_models_list")??new Array(); this.tools_models_list = config.get("tools_models_list")??new Array(); this.envs_list = config.get("envs_list")??new Array(); this.agents_list = this.normalizeAgents(config.get("agents_list") ?? new Array()); this.agent_rules = String(config.get("agent_rules")); this.agent_commands = config.get("agent_commands")??new Array(); this.env_start_last_used = Boolean(config.get("env_start_last_used", false)); this.tools_custom = config.get("tools_custom")??new Array(); this.context_custom = config.get("context_custom")??{}; this.env_start_last_used_confirm = Boolean(config.get("env_start_last_used_confirm", true)); this.ask_install_llamacpp = Boolean(config.get("ask_install_llamacpp", true)); this.ask_upgrade_llamacpp_hours = Number(config.get("ask_upgrade_llamacpp_hours")); this.health_check_interval_s = Number(config.get("health_check_interval_s")); this.health_check_compl_enabled = Boolean(config.get("health_check_compl_enabled")); this.health_check_chat_enabled = Boolean(config.get("health_check_chat_enabled")); this.health_check_embs_enabled = Boolean(config.get("health_check_embs_enabled")); this.health_check_tools_enabled = Boolean(config.get("health_check_tools_enabled")); this.telegram_api_token = String(config.get("telegram_api_token")); this.telegram_bot_enabled = Boolean(config.get("telegram_bot_enabled")); this.telegram_bot_users = String(config.get("telegram_bot_users")); this.telegram_chunk_size = Number(config.get("telegram_chunk_size")); this.tools_permission_timeout = Number(config.get("tools_permission_timeout")); this.send_prompt_from_editor_enabled = Boolean(config.get("send_prompt_from_editor_enabled")); this.remove_sent_prompt_from_editor = Boolean(config.get("remove_sent_prompt_from_editor")); }; private normalizeAgents(rawAgents: unknown): Agent[] { if (!Array.isArray(rawAgents)) { return []; } return rawAgents.map((rawAgent) => this.normalizeAgent(rawAgent)); } private normalizeAgent(rawAgent: unknown): Agent { const agent = (rawAgent && typeof rawAgent === 'object' ? rawAgent : {}) as Record; const systemInstructionValue = agent.systemInstruction ?? agent.system_instruction ?? []; const subagentEnabledValue = agent.subagentEnabled; let systemInstruction: string[]; if (Array.isArray(systemInstructionValue)) { systemInstruction = systemInstructionValue.map((value) => String(value)); } else if (typeof systemInstructionValue === 'string') { systemInstruction = systemInstructionValue.split(/\r?\n/); } else { systemInstruction = []; } let subagentEnabled: boolean | undefined; if (typeof subagentEnabledValue === 'boolean') { subagentEnabled = subagentEnabledValue; } else if (typeof subagentEnabledValue === 'string') { subagentEnabled = subagentEnabledValue.toLowerCase() === 'true'; } return { ...agent, name: String(agent.name ?? ''), description: agent.description !== undefined ? String(agent.description) : undefined, systemInstruction, subagentEnabled, tools: Array.isArray(agent.tools) ? agent.tools.map((tool) => String(tool)) : undefined, toolsModel: agent.toolsModel && typeof agent.toolsModel === 'object' ? { ...(agent.toolsModel as Record) } : undefined, } as Agent; } getUiText = (uiText: string): string | undefined => { let langTexts = this.uiLanguages.get(this.language); if (langTexts == undefined) langTexts = this.uiLanguages.get("en"); return langTexts?.get(uiText); }; updateOnEvent = (event: vscode.ConfigurationChangeEvent, config: vscode.WorkspaceConfiguration) => { this.updateConfigs(config); if (event.affectsConfiguration("llama-vscode.api_key") || event.affectsConfiguration("llama-vscode.api_key_tools") || event.affectsConfiguration("llama-vscode.api_key_chat") || event.affectsConfiguration("llama-vscode.api_key_embeddings") || event.affectsConfiguration("llama-vscode.self_signed_certificate")) { this.setLlamaRequestConfig(); this.setOpenAiClient(); } }; isAgentReminderSettingChanged = (event: vscode.ConfigurationChangeEvent) => { return event.affectsConfiguration("llama-vscode.reminder_edit_file_frequency") || event.affectsConfiguration("llama-vscode.plan_review_frequency") || event.affectsConfiguration("llama-vscode.tool_update_todo_list_enabled") || event.affectsConfiguration("llama-vscode.tool_edit_file_enabled") } isEnvViewSettingChanged = (event: vscode.ConfigurationChangeEvent) => { return event.affectsConfiguration("llama-vscode.enabled") || event.affectsConfiguration("llama-vscode.rag_enabled") || event.affectsConfiguration("llama-vscode.env_start_last_used") || event.affectsConfiguration("llama-vscode.health_check_compl_enabled") || event.affectsConfiguration("llama-vscode.health_check_chat_enabled") || event.affectsConfiguration("llama-vscode.health_check_embs_enabled") || event.affectsConfiguration("llama-vscode.health_check_tools_enabled"); } isRagConfigChanged = (event: vscode.ConfigurationChangeEvent) => { return event.affectsConfiguration("llama-vscode.rag_chunk_max_chars") || event.affectsConfiguration("llama-vscode.rag_max_lines_per_chunk") || event.affectsConfiguration("llama-vscode.rag_max_files") || event.affectsConfiguration("llama-vscode.rag_max_chars_per_chunk_line") || event.affectsConfiguration("llama-vscode.rag_enabled") || event.affectsConfiguration("llama-vscode.rag_ignore_file") } isCompletionsEnabledConfigChanged = (event: vscode.ConfigurationChangeEvent) => { return event.affectsConfiguration("llama-vscode.enabled") } isTelegramBotConfigChanged = (event: vscode.ConfigurationChangeEvent) => { return event.affectsConfiguration("llama-vscode.telegram_api_token") || event.affectsConfiguration("llama-vscode.telegram_bot_enabled") || event.affectsConfiguration("llama-vscode.telegram_bot_users") || event.affectsConfiguration("llama-vscode.telegram_chunk_size"); } isToolChanged = (event: vscode.ConfigurationChangeEvent) => { return event.affectsConfiguration("llama-vscode.tool_run_terminal_command_enabled") || event.affectsConfiguration("llama-vscode.tool_create_agent_enabled") || event.affectsConfiguration("llama-vscode.tool_search_source_enabled") || event.affectsConfiguration("llama-vscode.tool_list_directory_enabled") || event.affectsConfiguration("llama-vscode.tool_read_file_enabled") || event.affectsConfiguration("llama-vscode.tool_regex_search_enabled") || event.affectsConfiguration("llama-vscode.tool_custom_tool_source") || event.affectsConfiguration("llama-vscode.tool_custom_tool_description") || event.affectsConfiguration("llama-vscode.tool_custom_tool_enabled") || event.affectsConfiguration("llama-vscode.tool_ask_user_enabled") || event.affectsConfiguration("llama-vscode.tool_delete_file_enabled") || event.affectsConfiguration("llama-vscode.tool_edit_file_enabled") || event.affectsConfiguration("llama-vscode.tool_multi_edit_file_enabled") || event.affectsConfiguration("llama-vscode.tool_get_diff_enabled") || event.affectsConfiguration("llama-vscode.tool_llama_vscode_help_enabled") || event.affectsConfiguration("llama-vscode.tool_update_todo_list_enabled") || event.affectsConfiguration("llama-vscode.tool_delegate_task_enabled") || event.affectsConfiguration("llama-vscode.tool_custom_eval_tool_enabled") || event.affectsConfiguration("llama-vscode.tool_custom_eval_tool_description") || event.affectsConfiguration("llama-vscode.tool_custom_eval_tool_property_description") || event.affectsConfiguration("llama-vscode.tool_update_task_enabled") || event.affectsConfiguration("llama-vscode.tool_save_plan_enabled") || event.affectsConfiguration("llama-vscode.tools_custom") || event.affectsConfiguration("llama-vscode.tool_get_errors_enabled") || event.affectsConfiguration("llama-vscode.tool_rename_symbol_enabled") || event.affectsConfiguration("llama-vscode.tool_search_tools_enabled") || event.affectsConfiguration("llama-vscode.tool_web_browser_enabled") } setLlamaRequestConfig = () => { this.axiosRequestConfigCompl = {}; if (this.api_key != undefined && this.api_key.trim() != "") { this.axiosRequestConfigCompl = { headers: { Authorization: `Bearer ${this.api_key.trim()}`, "Content-Type": "application/json", }, }; } if (this.self_signed_certificate != undefined && this.self_signed_certificate.trim() != "") { const httpsAgent = new https.Agent({ ca: fs.readFileSync(this.self_signed_certificate.trim()), }); this.axiosRequestConfigCompl = { ...this.axiosRequestConfigCompl, httpsAgent, }; } this.axiosRequestConfigChat = {}; if (this.api_key_chat != undefined && this.api_key_chat.trim() != "") { this.axiosRequestConfigChat = { headers: { Authorization: `Bearer ${this.api_key_chat.trim()}`, "Content-Type": "application/json", }, }; } this.axiosRequestConfigTools = {}; if (this.api_key_tools != undefined && this.api_key_tools.trim() != "") { this.axiosRequestConfigTools = { headers: { Authorization: `Bearer ${this.api_key_tools.trim()}`, "Content-Type": "application/json", }, }; } this.axiosRequestConfigEmbeddings = {}; if (this.api_key_embeddings != undefined && this.api_key_embeddings.trim() != "") { this.axiosRequestConfigEmbeddings = { headers: { Authorization: `Bearer ${this.api_key_embeddings.trim()}`, "Content-Type": "application/json", }, }; } }; setOpenAiClient = () => { this.openai_client = null; if (this.use_openai_endpoint) { this.openai_client = new OpenAI({ apiKey: this.api_key || "empty", baseURL: this.endpoint, }); } }; isCompletionEnabled = (document?: vscode.TextDocument, language?: string): boolean => { if (!this.enabled) return false; const languageToCheck = language ?? document?.languageId; if (languageToCheck) { return this.languageSettings[languageToCheck] ?? true; } return true; } getEnvStartLastUsedScope = (): vscode.ConfigurationTarget => { const inspected = this.config.inspect("env_start_last_used"); if (inspected?.workspaceValue !== undefined) return vscode.ConfigurationTarget.Workspace; if (inspected?.globalValue !== undefined) return vscode.ConfigurationTarget.Global; return vscode.ConfigurationTarget.Workspace; } updateEnvStartLastUsed = async (value: boolean) => { const inspected = this.config.inspect("env_start_last_used"); const target = inspected?.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace : vscode.ConfigurationTarget.Global; await this.updateConfigValue("env_start_last_used", value, target); } updateEnvStartLastUsedConfirm = async (value: boolean) => { const confirm = this.config.inspect("env_start_last_used_confirm"); const target = this.getEnvStartLastUsedScope() === vscode.ConfigurationTarget.Workspace || confirm?.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace : vscode.ConfigurationTarget.Global; await this.updateConfigValue("env_start_last_used_confirm", value, target); } updateConfigValue = async (settingName: string, value: any, target: vscode.ConfigurationTarget = vscode.ConfigurationTarget.Global) => { await this.config.update(settingName, value, target); } /** * The scope the user actually stores `agent_commands` in. The setting is * window-scoped, so a workspace value shadows the global one on read - * writing at Global while the commands live in the workspace file would be * silently shadowed (the write would look like a no-op). */ getAgentCommandsScope = (): vscode.ConfigurationTarget => { const inspected = this.config.inspect("agent_commands"); if (inspected?.workspaceValue !== undefined) return vscode.ConfigurationTarget.Workspace; return vscode.ConfigurationTarget.Global; } /** * Persists the agent commands list at the scope it is stored in. */ updateAgentCommands = async (value: any[]) => { await this.updateConfigValue("agent_commands", value, this.getAgentCommandsScope()); } }