updateSessionOptionsForMode applies the per-mode safe-defaults patch via session.options.update after create/resume succeeds. In empty mode the four overridable feature flags default to safe values; caller values win. installedPlugins=[] is unconditional in empty mode.
(ctx context.Context, session *Session, base optBackInFields)
| 211 | // four overridable feature flags default to safe values; caller values win. |
| 212 | // installedPlugins=[] is unconditional in empty mode. |
| 213 | func (c *Client) updateSessionOptionsForMode(ctx context.Context, session *Session, base optBackInFields) error { |
| 214 | patch := &rpc.SessionUpdateOptionsParams{} |
| 215 | hasAny := false |
| 216 | if c.options.Mode == ModeEmpty { |
| 217 | if base.SkipCustomInstructions != nil { |
| 218 | patch.SkipCustomInstructions = base.SkipCustomInstructions |
| 219 | } else { |
| 220 | t := true |
| 221 | patch.SkipCustomInstructions = &t |
| 222 | } |
| 223 | if base.CustomAgentsLocalOnly != nil { |
| 224 | patch.CustomAgentsLocalOnly = base.CustomAgentsLocalOnly |
| 225 | } else { |
| 226 | t := true |
| 227 | patch.CustomAgentsLocalOnly = &t |
| 228 | } |
| 229 | if base.CoauthorEnabled != nil { |
| 230 | patch.CoauthorEnabled = base.CoauthorEnabled |
| 231 | } else { |
| 232 | f := false |
| 233 | patch.CoauthorEnabled = &f |
| 234 | } |
| 235 | if base.ManageScheduleEnabled != nil { |
| 236 | patch.ManageScheduleEnabled = base.ManageScheduleEnabled |
| 237 | } else { |
| 238 | f := false |
| 239 | patch.ManageScheduleEnabled = &f |
| 240 | } |
| 241 | patch.InstalledPlugins = []rpc.SessionInstalledPlugin{} |
| 242 | hasAny = true |
| 243 | } else { |
| 244 | if base.SkipCustomInstructions != nil { |
| 245 | patch.SkipCustomInstructions = base.SkipCustomInstructions |
| 246 | hasAny = true |
| 247 | } |
| 248 | if base.CustomAgentsLocalOnly != nil { |
| 249 | patch.CustomAgentsLocalOnly = base.CustomAgentsLocalOnly |
| 250 | hasAny = true |
| 251 | } |
| 252 | if base.CoauthorEnabled != nil { |
| 253 | patch.CoauthorEnabled = base.CoauthorEnabled |
| 254 | hasAny = true |
| 255 | } |
| 256 | if base.ManageScheduleEnabled != nil { |
| 257 | patch.ManageScheduleEnabled = base.ManageScheduleEnabled |
| 258 | hasAny = true |
| 259 | } |
| 260 | } |
| 261 | if !hasAny { |
| 262 | return nil |
| 263 | } |
| 264 | if _, err := session.RPC.Options.Update(ctx, patch); err != nil { |
| 265 | // The runtime session exists but the post-create options patch |
| 266 | // failed — best-effort disconnect so we don't leak it (in empty |
| 267 | // mode it would otherwise keep running with permissive defaults). |
| 268 | _ = session.Disconnect() |
| 269 | c.sessionsMux.Lock() |
| 270 | delete(c.sessions, session.SessionID) |
no test coverage detected