feat(session): add child_readonly config and restore/lock agent type for child sessions#390
Conversation
2ba416d to
8c89875
Compare
a1d6d30 to
4a1642f
Compare
sudo-tee
left a comment
There was a problem hiding this comment.
Looks good.
Only 1 comment about the mode/model resolving.
| if selected_session and selected_session.parentID then | ||
| state.session.set_active(selected_session) | ||
| local ok, messages = pcall(function() | ||
| return session.get_messages(selected_session):await() | ||
| end) | ||
| local restored = false | ||
| if ok and messages then | ||
| local all_agents = vim.list_extend(config_file.get_opencode_agents():await(), config_file.get_subagents():await()) | ||
| for i = 1, #messages do | ||
| local msg = messages[i] | ||
| if msg and msg.info and msg.info.mode then | ||
| if vim.tbl_contains(all_agents, msg.info.mode) then | ||
| state.model.set_mode(msg.info.mode) | ||
| if msg.info.providerID and msg.info.modelID then | ||
| state.model.set_model(msg.info.providerID .. '/' .. msg.info.modelID) | ||
| end | ||
| restored = true | ||
| break | ||
| end | ||
| end | ||
| end | ||
| end | ||
| if not restored then | ||
| -- Fallback to session.agent, then default_mode | ||
| if selected_session.agent then | ||
| local all_agents = | ||
| vim.list_extend(config_file.get_opencode_agents():await(), config_file.get_subagents():await()) | ||
| if vim.tbl_contains(all_agents, selected_session.agent) then | ||
| state.model.set_mode(selected_session.agent) | ||
| else | ||
| state.model.set_mode(config.default_mode) | ||
| end | ||
| else | ||
| log.notify('Could not infer agent type for child session', vim.log.levels.WARN) | ||
| state.model.set_mode(config.default_mode) | ||
| end | ||
| end | ||
| elseif selected_session and selected_session.agent then | ||
| -- Parent session with agent info: restore directly | ||
| local available_agents = config_file.get_opencode_agents():await() | ||
| if vim.tbl_contains(available_agents, selected_session.agent) then | ||
| state.model.set_mode(selected_session.agent) | ||
| end | ||
| if selected_session.model then | ||
| local model_str = selected_session.model.providerID .. '/' .. selected_session.model.id | ||
| state.model.set_model(model_str) | ||
| end | ||
| else | ||
| agent_model.ensure_current_mode():await() | ||
| end |
There was a problem hiding this comment.
I would split this into multiple little helpers as it's a bit hard to follow, there is a lot of nesting.
|
I think this should wait for #397. This PR still filters restored |
Make sense to me after having a look at #397 |
…for child sessions - Add child_readonly config (default: true) to opt into messaging child sessions - Infer child session agent type from first assistant message on switch (session.agent may be polluted by prior incorrect agent params) - Lock agent type in child sessions, reject user-initiated mode switches - Child sessions scan messages forward (first is reliable), parent sessions scan backward (most recent is current choice) - Include subagents in agent validation list - Send inferred agent type when messaging child sessions to override polluted session.agent on backend
4a1642f to
8d599ff
Compare
child_readonlyconfig (default:true) to opt into messaging child sessionsRelated: #381, #387