-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(modes): prevent missing role definition when selecting default mode #4286
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
Conversation
|
Did this break in #3791? Maybe we should revert that. I'm not sure that only considering promptComponents with roleDefinitions is the right fix. |
The only difference in my change is the use of |
- Previously, `getModeSelection` could pick `promptComponent` as the active mode even if it lacked a `roleDefinition`. - This resulted in an empty `roleDefinition` being returned, overriding potentially valid role definitions from built-in modes. - The logic now only considers `promptComponent` if it provides a `roleDefinition`, ensuring that a proper role definition is always selected if available from custom, prompt, or built-in modes.
|
To clarify how this fix works: when a promptComponent lacks a roleDefinition, it's completely skipped. So if someone has a promptComponent with only customInstructions, those instructions are lost and we use the built-in mode entirely. This is an all-or-nothing approach - either the promptComponent is complete (has roleDefinition) and we use it, or it's incomplete and we skip it. An alternative approach could be to merge them - take the roleDefinition from the built-in mode when missing, but preserve any customInstructions from the promptComponent. Something like: const customMode = findModeBySlug(mode, customModes)
const builtInMode = findModeBySlug(mode, modes)
if (customMode) return customMode
if (promptComponent?.roleDefinition) return promptComponent
if (promptComponent?.customInstructions && builtInMode) {
// Merge: use built-in roleDefinition with prompt's customInstructions
return {
roleDefinition: builtInMode.roleDefinition || "",
customInstructions: promptComponent.customInstructions
}
}
return builtInModeBut the current fix is simpler and solves the immediate issue of empty role definitions for certain modes. |
Thanks @daniel-lxs for clarifying the issue — that was really helpful to me. Sorry I’ve been quite busy with my own projects, so I’ve been aiming to provide the minimal fixes and features that at least won’t break anything on my end. Let me know what you guys decide. I’m happy to switch to your approach or keep mine. |
|
No problem, just moved it to draft to avoid accidental merging until we decide. In what situations would a Maybe we can define a more generic role definition, I think the code mode role definition is quite generic, it could work for Let me know what you think. cc: @mrubens |
|
stale |
Related GitHub Issue
Closes: #4285
Description
getModeSelectioncould pickpromptComponentas the active mode even if it lacked aroleDefinition.roleDefinitionbeing returned, overriding potentially valid role definitions from built-in modes.promptComponentif it provides aroleDefinition, ensuring that a proper role definition is always selected if available from custom, prompt, or built-in modes.Test Procedure
Same as the Issue: #4285
Type of Change
srcor test files.Pre-Submission Checklist
npm run lint).console.log) has been removed.npm test).mainbranch.npm run changesetif this PR includes user-facing changes or dependency updates.Screenshots / Videos
BEFORE FIX

AFTER_FIX

Documentation Updates
Get in Touch
Important
Fixes
getModeSelectioninmodes.tsto ensurepromptComponentis only considered if it has aroleDefinition, preventing empty role definitions from overriding valid ones.getModeSelectioninmodes.tsto only considerpromptComponentif it has aroleDefinition.roleDefinitionfrom overriding valid ones from custom or built-in modes.This description was created by
for 89ffd9bcce14efcce9aabc958126b2d5ffb1d10c. You can customize this summary. It will automatically update as commits are pushed.