4545 SetSessionModeResponse ,
4646 ResourceContentBlock ,
4747 SessionCapabilities ,
48- SessionConfigOptionSelect ,
49- SessionConfigSelectOption ,
5048 SessionForkCapabilities ,
5149 SessionListCapabilities ,
50+ SessionMode ,
51+ SessionModeState ,
5252 SessionModelState ,
5353 SessionResumeCapabilities ,
5454 SessionInfo ,
@@ -499,6 +499,17 @@ class HermesACPAgent(acp.Agent):
499499
500500 _EDIT_APPROVAL_POLICY_CONFIG_ID = "edit_approval_policy"
501501 _EDIT_APPROVAL_POLICY_DEFAULT = "ask"
502+ _MODE_DEFAULT = "default"
503+ _MODE_ACCEPT_EDITS = "accept_edits"
504+ _MODE_DONT_ASK = "dont_ask"
505+ _MODE_TO_EDIT_APPROVAL_POLICY = {
506+ _MODE_DEFAULT : "ask" ,
507+ _MODE_ACCEPT_EDITS : "workspace_session" ,
508+ _MODE_DONT_ASK : "session" ,
509+ }
510+ _EDIT_APPROVAL_POLICY_TO_MODE = {
511+ value : key for key , value in _MODE_TO_EDIT_APPROVAL_POLICY .items ()
512+ }
502513
503514 def __init__ (self , session_manager : SessionManager | None = None ):
504515 super ().__init__ ()
@@ -513,47 +524,43 @@ def on_connect(self, conn: acp.Client) -> None:
513524 logger .info ("ACP client connected" )
514525
515526
516- def _session_config_options (self , state : SessionState ) -> list [Any ]:
517- values = getattr (state , "config_options" , None )
518- if not isinstance (values , dict ):
519- values = {}
520- current = str (values .get (self ._EDIT_APPROVAL_POLICY_CONFIG_ID ) or self ._EDIT_APPROVAL_POLICY_DEFAULT )
521- allowed = {"ask" , "workspace_session" , "session" }
522- if current not in allowed :
523- current = self ._EDIT_APPROVAL_POLICY_DEFAULT
524- return [
525- SessionConfigOptionSelect (
526- id = self ._EDIT_APPROVAL_POLICY_CONFIG_ID ,
527- name = "Edit approvals" ,
528- description = "Control ACP edit approvals for this session." ,
529- category = "permissions" ,
530- type = "select" ,
531- current_value = current ,
532- options = [
533- SessionConfigSelectOption (
534- value = "ask" ,
535- name = "Ask before edits" ,
536- description = "Require approval for every file edit." ,
537- ),
538- SessionConfigSelectOption (
539- value = "workspace_session" ,
540- name = "Auto-allow workspace edits" ,
541- description = "Allow workspace and /tmp edits for this session; still asks for sensitive paths." ,
542- ),
543- SessionConfigSelectOption (
544- value = "session" ,
545- name = "Auto-allow all edits this session" ,
546- description = "Allow file edits for this session except sensitive paths." ,
547- ),
548- ],
549- )
550- ]
527+ def _session_modes (self , state : SessionState ) -> SessionModeState :
528+ """Return ACP session modes while preserving Zed's separate model picker.
529+
530+ Zed renders ``config_options`` in the prominent selector slot where the
531+ model picker was visible. Claude/Codex expose policy-like controls as ACP
532+ modes, which coexist with the model picker, so Hermes maps edit approval
533+ policy onto modes instead of advertising config options.
534+ """
535+
536+ current = str (getattr (state , "mode" , "" ) or self ._MODE_DEFAULT )
537+ if current not in self ._MODE_TO_EDIT_APPROVAL_POLICY :
538+ current = self ._MODE_DEFAULT
539+ return SessionModeState (
540+ current_mode_id = current ,
541+ available_modes = [
542+ SessionMode (
543+ id = self ._MODE_DEFAULT ,
544+ name = "Default" ,
545+ description = "Ask before edits." ,
546+ ),
547+ SessionMode (
548+ id = self ._MODE_ACCEPT_EDITS ,
549+ name = "Accept Edits" ,
550+ description = "Auto-allow workspace and /tmp edits; still asks for sensitive paths." ,
551+ ),
552+ SessionMode (
553+ id = self ._MODE_DONT_ASK ,
554+ name = "Don't Ask" ,
555+ description = "Auto-allow file edits for this session except sensitive paths." ,
556+ ),
557+ ],
558+ )
551559
552560 def _edit_approval_policy_for_state (self , state : SessionState ) -> tuple [str , str | None ]:
553- values = getattr (state , "config_options" , None )
554- if not isinstance (values , dict ):
555- values = {}
556- return str (values .get (self ._EDIT_APPROVAL_POLICY_CONFIG_ID ) or self ._EDIT_APPROVAL_POLICY_DEFAULT ), state .cwd
561+ mode = str (getattr (state , "mode" , "" ) or self ._MODE_DEFAULT )
562+ policy = self ._MODE_TO_EDIT_APPROVAL_POLICY .get (mode , self ._EDIT_APPROVAL_POLICY_DEFAULT )
563+ return policy , state .cwd
557564
558565 @staticmethod
559566 def _encode_model_choice (provider : str | None , model : str | None ) -> str :
@@ -1040,7 +1047,7 @@ async def new_session(
10401047 return NewSessionResponse (
10411048 session_id = state .session_id ,
10421049 models = self ._build_model_state (state ),
1043- config_options = self ._session_config_options (state ),
1050+ modes = self ._session_modes (state ),
10441051 )
10451052
10461053 async def load_session (
@@ -1084,7 +1091,7 @@ async def load_session(
10841091 self ._schedule_usage_update (state )
10851092 return LoadSessionResponse (
10861093 models = self ._build_model_state (state ),
1087- config_options = self ._session_config_options (state ),
1094+ modes = self ._session_modes (state ),
10881095 )
10891096
10901097 async def resume_session (
@@ -1116,7 +1123,7 @@ async def resume_session(
11161123 self ._schedule_usage_update (state )
11171124 return ResumeSessionResponse (
11181125 models = self ._build_model_state (state ),
1119- config_options = self ._session_config_options (state ),
1126+ modes = self ._session_modes (state ),
11201127 )
11211128
11221129 async def cancel (self , session_id : str , ** kwargs : Any ) -> None :
@@ -1150,7 +1157,7 @@ async def fork_session(
11501157 return ForkSessionResponse (
11511158 session_id = new_id ,
11521159 models = self ._build_model_state (state ) if state is not None else None ,
1153- config_options = self ._session_config_options (state ) if state is not None else None ,
1160+ modes = self ._session_modes (state ) if state is not None else None ,
11541161 )
11551162
11561163 async def list_sessions (
@@ -1307,7 +1314,14 @@ async def prompt(
13071314 streamed_message = False
13081315
13091316 if conn :
1310- tool_progress_cb = make_tool_progress_cb (conn , session_id , loop , tool_call_ids , tool_call_meta )
1317+ tool_progress_cb = make_tool_progress_cb (
1318+ conn ,
1319+ session_id ,
1320+ loop ,
1321+ tool_call_ids ,
1322+ tool_call_meta ,
1323+ edit_approval_policy_getter = lambda : self ._edit_approval_policy_for_state (state ),
1324+ )
13111325 reasoning_cb = make_thinking_cb (conn , session_id , loop )
13121326 step_cb = make_step_cb (conn , session_id , loop , tool_call_ids , tool_call_meta )
13131327 message_cb = make_message_cb (conn , session_id , loop )
@@ -1849,9 +1863,12 @@ async def set_session_mode(
18491863 if state is None :
18501864 logger .warning ("Session %s: mode switch requested for missing session" , session_id )
18511865 return None
1852- setattr (state , "mode" , mode_id )
1866+ normalized_mode = str (mode_id or "" ).strip ()
1867+ if normalized_mode not in self ._MODE_TO_EDIT_APPROVAL_POLICY :
1868+ normalized_mode = self ._MODE_DEFAULT
1869+ setattr (state , "mode" , normalized_mode )
18531870 self .session_manager .save_session (session_id )
1854- logger .info ("Session %s: mode switched to %s" , session_id , mode_id )
1871+ logger .info ("Session %s: mode switched to %s" , session_id , normalized_mode )
18551872 return SetSessionModeResponse ()
18561873
18571874 async def set_config_option (
@@ -1863,11 +1880,15 @@ async def set_config_option(
18631880 logger .warning ("Session %s: config update requested for missing session" , session_id )
18641881 return None
18651882
1866- options = getattr (state , "config_options" , None )
1867- if not isinstance (options , dict ):
1868- options = {}
1869- options [str (config_id )] = value
1870- setattr (state , "config_options" , options )
1883+ if str (config_id ) == self ._EDIT_APPROVAL_POLICY_CONFIG_ID :
1884+ mode = self ._EDIT_APPROVAL_POLICY_TO_MODE .get (str (value ), self ._MODE_DEFAULT )
1885+ setattr (state , "mode" , mode )
1886+ else :
1887+ options = getattr (state , "config_options" , None )
1888+ if not isinstance (options , dict ):
1889+ options = {}
1890+ options [str (config_id )] = value
1891+ setattr (state , "config_options" , options )
18711892 self .session_manager .save_session (session_id )
18721893 logger .info ("Session %s: config option %s updated" , session_id , config_id )
1873- return SetSessionConfigOptionResponse (config_options = self . _session_config_options ( state ) )
1894+ return SetSessionConfigOptionResponse (config_options = [] )
0 commit comments