Apply empty-mode safe defaults (or caller-supplied overrides in copilot-cli mode) via ``session.options.update`` after create/resume. If the patch is rejected, tear the session down so empty-mode callers never end up with a permissive session.
(
self,
session: CopilotSession,
mode: CopilotClientMode,
skip_custom_instructions: bool | None,
custom_agents_local_only: bool | None,
coauthor_enabled: bool | None,
manage_schedule_enabled: bool | None,
)
| 3817 | self._client.start(loop) |
| 3818 | |
| 3819 | async def _apply_post_create_options_patch( |
| 3820 | self, |
| 3821 | session: CopilotSession, |
| 3822 | mode: CopilotClientMode, |
| 3823 | skip_custom_instructions: bool | None, |
| 3824 | custom_agents_local_only: bool | None, |
| 3825 | coauthor_enabled: bool | None, |
| 3826 | manage_schedule_enabled: bool | None, |
| 3827 | ) -> None: |
| 3828 | """Apply empty-mode safe defaults (or caller-supplied overrides in |
| 3829 | copilot-cli mode) via ``session.options.update`` after create/resume. |
| 3830 | |
| 3831 | If the patch is rejected, tear the session down so empty-mode callers |
| 3832 | never end up with a permissive session. |
| 3833 | """ |
| 3834 | from .generated.rpc import SessionInstalledPlugin, SessionUpdateOptionsParams |
| 3835 | |
| 3836 | patch = _post_create_options_patch( |
| 3837 | mode, |
| 3838 | skip_custom_instructions, |
| 3839 | custom_agents_local_only, |
| 3840 | coauthor_enabled, |
| 3841 | manage_schedule_enabled, |
| 3842 | ) |
| 3843 | if patch is None: |
| 3844 | return |
| 3845 | |
| 3846 | params = SessionUpdateOptionsParams() |
| 3847 | if "skipCustomInstructions" in patch: |
| 3848 | params.skip_custom_instructions = patch["skipCustomInstructions"] |
| 3849 | if "customAgentsLocalOnly" in patch: |
| 3850 | params.custom_agents_local_only = patch["customAgentsLocalOnly"] |
| 3851 | if "coauthorEnabled" in patch: |
| 3852 | params.coauthor_enabled = patch["coauthorEnabled"] |
| 3853 | if "manageScheduleEnabled" in patch: |
| 3854 | params.manage_schedule_enabled = patch["manageScheduleEnabled"] |
| 3855 | if "installedPlugins" in patch: |
| 3856 | params.installed_plugins = [ |
| 3857 | SessionInstalledPlugin.from_dict(p) if isinstance(p, dict) else p |
| 3858 | for p in patch["installedPlugins"] |
| 3859 | ] |
| 3860 | |
| 3861 | try: |
| 3862 | await session.rpc.options.update(params) |
| 3863 | except BaseException: |
| 3864 | with self._sessions_lock: |
| 3865 | self._sessions.pop(session.session_id, None) |
| 3866 | try: |
| 3867 | await session.disconnect() |
| 3868 | except BaseException: |
| 3869 | pass |
| 3870 | raise |
| 3871 | |
| 3872 | async def _set_session_fs_provider(self) -> None: |
| 3873 | if not self._session_fs_config or not self._client: |
no test coverage detected