Skip to content

Commit 0c990b6

Browse files
committed
feat: Permission mode for tool execution
1 parent f0f6734 commit 0c990b6

File tree

10 files changed

+375
-97
lines changed

10 files changed

+375
-97
lines changed

huly-coder.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ model: anthropic/claude-3.5-sonnet
2828
#provider_api_key: sk-xxxxxxxxxxxxxxxxxxxxx
2929
#provider_base_url: http://127.0.0.1:1234/v1
3030

31+
#---------------------------------------
32+
# Permission mode
33+
#---------------------------------------
34+
# Supported permission modes:
35+
# - full_autonomous
36+
# - manual_approval (default)
37+
# - deny_all
38+
permission_mode: manual_approval
39+
3140
#---------------------------------------
3241
# Workspace Configuration
3342
#---------------------------------------

src/agent/event.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Display;
22

33
// Copyright © 2025 Huly Labs. Use of this source code is governed by the MIT license.
4-
use rig::message::Message;
4+
use rig::message::{Message, ToolCall};
55

66
#[derive(Clone, Debug, Default, PartialEq)]
77
pub enum AgentState {
@@ -11,21 +11,30 @@ pub enum AgentState {
1111
Thinking,
1212
WaitingUserPrompt,
1313
Error(String),
14-
Completed(bool),
15-
ToolCall(String, serde_json::Value),
14+
Completed,
15+
ToolCall(ToolCall, bool),
1616
}
1717

1818
impl AgentState {
1919
pub fn is_paused(&self) -> bool {
2020
matches!(
2121
self,
22-
Self::Paused | Self::Completed(true) | Self::Error(_) | Self::WaitingUserPrompt
22+
Self::Paused
23+
| Self::Completed
24+
| Self::Error(_)
25+
| Self::WaitingUserPrompt
26+
| Self::ToolCall(_, true)
2327
)
2428
}
2529

2630
#[inline]
2731
pub fn is_completed(&self) -> bool {
28-
matches!(self, Self::Completed(is_finished) if *is_finished)
32+
matches!(self, Self::Completed)
33+
}
34+
35+
#[inline]
36+
pub fn is_tool_call(&self) -> bool {
37+
matches!(self, Self::ToolCall(_, false))
2938
}
3039
}
3140

@@ -37,8 +46,14 @@ impl Display for AgentState {
3746
Self::Thinking => write!(f, "Thinking"),
3847
Self::WaitingUserPrompt => write!(f, "WaitingUserPrompt"),
3948
Self::Error(_) => write!(f, "Error"),
40-
Self::Completed(is_finished) => write!(f, "Completed({})", is_finished),
41-
Self::ToolCall(name, _) => write!(f, "ToolCall[{}]", name),
49+
Self::Completed => write!(f, "Completed"),
50+
Self::ToolCall(tool_call, need_confirm) => {
51+
write!(
52+
f,
53+
"ToolCall[{}] need_confirm={}",
54+
tool_call.function.name, need_confirm
55+
)
56+
}
4257
}
4358
}
4459
}
@@ -63,12 +78,20 @@ pub enum AgentOutputEvent {
6378
HighlightFile(String, bool),
6479
}
6580

81+
#[derive(Clone, Debug)]
82+
pub enum ConfirmToolResponse {
83+
Approve,
84+
Deny,
85+
AlwaysApprove,
86+
}
87+
6688
/// Controls events that are sent to the agent
6789
#[derive(Clone, Debug)]
6890
pub enum AgentControlEvent {
6991
SendMessage(String),
7092
/// Sends data to stdin of running terminal by idx
7193
TerminalData(usize, Vec<u8>),
94+
ConfirmTool(ConfirmToolResponse),
7295
CancelTask,
7396
NewTask,
7497
}

0 commit comments

Comments
 (0)