Open
Conversation
* distinguish between preference activation (isActive) and actual AI enablement, i.e. isActive and additional conditions (canRun) * include workspace trust in the canRun state and emit change events for it Contributed on behalf of STMicroelectronics
* keep AI commands visible when enabled in preferences but disable execution when workspace is untrusted * switch chat input, tree widget, and toolbar enablement to react to canRun/onDidChangeCanRun * re-register inline completions and code action providers on canRun changes instead of preference activation alone * ensure toolbar items re-evaluate isEnabled on trust changes via additional onDidChangeCanRun listener Contributed on behalf of STMicroelectronics
* add a workspace restriction contribution and restricted-mode welcome message for AI features * disable workspace prompt template loading when the workspace is not trusted Contributed on behalf of STMicroelectronics
7eec620 to
25b71ef
Compare
* replace non-data image URLs in chat markdown with a blocked placeholder when workspace trust is missing * apply the same trust-based image blocking to question prompts and tool call markdown output * extract shared useBlockExternalImages hook for workspace trust state Contributed on behalf of STMicroelectronics
26f451b to
0d34073
Compare
* add AIPreferenceService, a trust-aware PreferenceService wrapper that hides workspace- and folder-scoped AI preference values when the workspace is untrusted * add shared bindXyzPreferences helpers in @theia/ai-core so AI preference proxies can be wired through AIPreferenceService without per-package rebind/child-container boilerplate Contributed on behalf of STMicroelectronics
3510441 to
8b7678c
Compare
95100fe to
ba40a9d
Compare
* introduce a small helper in @theia/ai-core/lib/browser that reads preferences via PreferenceService.inspect and drops workspace/folder values when the workspace is untrusted * use TrustAwarePreferenceReader where AI settings must ignore workspace-scoped values in untrusted workspaces Contributed on behalf of STMicroelectronics
ba40a9d to
9813f8a
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What it does
Hooks workspace trust into AI features so that all AI functionality is disabled in Restricted Mode, fixes #16892.
AIActivationService.isActivereflects theenableAIpreference and controls UI visibility, views, menus, toolbar items, context key. This PR keepsisActiveunchanged and adds a newcanRunproperty that reflectsisActive && workspaceTrusted. All functional checks, commandisEnabled, chat input enablement, inline completion guards, code action guards, now usecanRuninstead ofisActive, while visibility checks stay onisActive.This results in three states:
Commit 1-3 address this.
<img>elements with external URLs, for example from AI generated markdown like, are replaced with a[External image blocked]placeholder. Images usingdata:URIs, for example user attached images or tool call results, are always allowed. In trusted workspaces, external images render normally.The fourth commit addresses image loading.
TrustAwarePreferenceReaderhelper. When the workspace is untrusted,getdrops workspace and folder values and falls back to the user or default value. Writes continue through the normalPreferenceService.The preferences covered in this PR are tool confirmation,
ai-features.chat.toolConfirmation, language model aliases,ai-features.modelSettings.languageModelAliases, and agent settings,ai-features.agentSettings. Other AI preferences only affect UX and continue to usePreferenceServiceunchanged. Additionally, workspace prompt templates,.prompts/*.prompttemplateand configured template directories, files, and extensions, are unloaded in Restricted Mode and reloaded when trust is granted.The last commit addresses preferences and prompt templates.
How to test
Enable
enableAIandsecurity.workspace.trust.enabled, then open a folder and deny trust. Verify that AI views remain visible but functionality is disabled, chat shows an "AI Features are Restricted" message with a "Manage Workspace Trust" button, chat input is disabled, AI commands are greyed out, inline completions and code actions do not trigger, and workspace prompt templates are not loaded. Granting trust should re enable everything immediately, revoking trust should disable it again.To test external image blocking in isolation, without the
canRungate disabling AI chat entirely, you can temporarily changepackages/ai-ide/src/browser/ai-ide-activation-service.tsline 68:To test the trust aware preference wrapper in isolation, apply the same temporary change so AI chat stays functional, then set a workspace scoped override in
.theia/settings.json, for example"ai-features.chat.toolConfirmation": { "*": "always_allow" }.With the workspace untrusted, the effective value seen by AI should still come from user or default, so confirmation prompts should still appear. Granting trust should make the workspace override take effect without a reload, revoking trust should hide it again.
Follow ups
An earlier iteration of this PR tried to introduce a generic
AIPreferenceServicewrapper aroundPreferenceServiceas a facade and rewired all AI packages to inject it.However there were multiple smaller issues, like with proxies or initialization order, that made me revert this.
For now this PR has only targeted fixes.
As a follow up, it might be worth investigating to add trust aware reads into the core
PreferenceServiceitself, so the behavior is available framework wide and AI code can stop using a dedicated helper.Breaking changes
Attribution
Contributed on behalf of STMicroelectronics
Review checklist
nlsservice (for details, please see the Internationalization/Localization section in the Coding Guidelines)Reminder for reviewers