@@ -6,6 +6,7 @@ local state = require('opencode.state')
66local config = require (' opencode.config' )
77local snapshot = require (' opencode.snapshot' )
88local mention = require (' opencode.ui.mention' )
9+ local permission_window = require (' opencode.ui.permission_window' )
910
1011local M = {}
1112
@@ -54,43 +55,6 @@ function M._format_reasoning(output, part)
5455 end
5556end
5657
57- function M ._handle_permission_request (output , part )
58- if part .state and part .state .status == ' error' and part .state .error then
59- if part .state .error :match (' rejected permission' ) then
60- state .current_permission = nil
61- else
62- vim .notify (' Unknown part state error: ' .. part .state .error )
63- end
64- return
65- end
66-
67- M ._format_permission_request (output )
68- end
69-
70- function M ._format_permission_request (output )
71- local keys
72-
73- if require (' opencode.ui.ui' ).is_opencode_focused () then
74- keys = {
75- config .keymap .permission .accept ,
76- config .keymap .permission .accept_all ,
77- config .keymap .permission .deny ,
78- }
79- else
80- keys = {
81- config .get_key_for_function (' editor' , ' permission_accept' ),
82- config .get_key_for_function (' editor' , ' permission_accept_all' ),
83- config .get_key_for_function (' editor' , ' permission_deny' ),
84- }
85- end
86-
87- output :add_empty_line ()
88- output :add_line (' > [!WARNING] Permission required to run this tool.' )
89- output :add_line (' >' )
90- output :add_line ((' > Accept `%s` Always `%s` Deny `%s`' ):format (unpack (keys )))
91- output :add_empty_line ()
92- end
93-
9458--- Calculate statistics for reverted messages and tool calls
9559--- @param messages { info : MessageInfo , parts : OpencodeMessagePart[] } [] All messages in the session
9660--- @param revert_index number Index of the message where revert occurred
@@ -646,10 +610,6 @@ function M._format_tool(output, part)
646610 local metadata = part .state .metadata or {}
647611 local tool_output = part .state .output or ' '
648612
649- if state .current_permission and state .current_permission .messageID == part .messageID then
650- metadata = state .current_permission .metadata or metadata
651- end
652-
653613 if tool == ' bash' then
654614 M ._format_bash_tool (output , input --[[ @as BashToolInput]] , metadata --[[ @as BashToolMetadata]] )
655615 elseif tool == ' read' or tool == ' edit' or tool == ' write' then
@@ -681,25 +641,6 @@ function M._format_tool(output, part)
681641 M ._format_callout (output , ' ERROR' , part .state .input .error )
682642 end
683643
684- if
685- state .current_permission
686- and (
687- (
688- state .current_permission .tool
689- and state .current_permission .tool .callID == part .callID
690- and state .current_permission .tool .messageID == part .messageID
691- )
692- --- @TODO this is for backward compatibility, remove later
693- or (
694- not state .current_permission .tool
695- and state .current_permission .messageID == part .messageID
696- and state .current_permission .callID == part .callID
697- )
698- )
699- then
700- M ._handle_permission_request (output , part )
701- end
702-
703644 local end_line = output :get_line_count ()
704645 if end_line - start_line > 1 then
705646 M ._add_vertical_border (output , start_line , end_line , ' OpencodeToolBorder' , - 1 )
@@ -893,6 +834,12 @@ function M.format_part(part, message, is_last_part)
893834 M ._format_patch (output , part )
894835 content_added = true
895836 end
837+ elseif role == ' system' then
838+ if part .type == ' permissions-display' then
839+ local text = table.concat (permission_window .get_display_lines (), ' \n ' )
840+ output :add_lines (vim .split (vim .trim (text ), ' \n ' ))
841+ content_added = true
842+ end
896843 end
897844
898845 if content_added then
0 commit comments