Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/maple-agent/app/locales/de/app.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,9 @@ chat-question-label = Frage von Maple
chat-permission-label = Diese Aktion erlauben?
chat-permission-allow = Einmal erlauben
chat-permission-deny = Ablehnen
chat-permission-note-placeholder = Oder sag Maple, was es stattdessen tun soll…
# $mode is the name of the task's permission mode, for example Auto.
chat-permission-mode-hint = Im Modus „{ $mode }“ fragt Maple vor Aktionen wie dieser
chat-permission-reason-secrets = Dies liest Geheimnisse oder Zugangsdaten.
chat-permission-reason-secrets-leaving = Dies könnte Geheimnisse von diesem Computer nach außen senden.
chat-permission-reason-sends-out = Dies sendet oder veröffentlicht etwas außerhalb dieses Computers.
Expand Down
3 changes: 3 additions & 0 deletions apps/maple-agent/app/locales/en/app.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,9 @@ chat-question-label = Question from Maple
chat-permission-label = Allow this action?
chat-permission-allow = Allow once
chat-permission-deny = Deny
chat-permission-note-placeholder = Or tell Maple what to do instead…
# $mode is the name of the task's permission mode, for example Auto.
chat-permission-mode-hint = { $mode } asks before actions like this
chat-permission-reason-secrets = This reads secrets or credentials.
chat-permission-reason-secrets-leaving = This could send secrets off this computer.
chat-permission-reason-sends-out = This sends or publishes something outside this computer.
Expand Down
3 changes: 3 additions & 0 deletions apps/maple-agent/app/locales/es/app.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,9 @@ chat-question-label = Pregunta de Maple
chat-permission-label = ¿Permitir esta acción?
chat-permission-allow = Permitir una vez
chat-permission-deny = Rechazar
chat-permission-note-placeholder = O dile a Maple qué hacer en su lugar…
# $mode is the name of the task's permission mode, for example Auto.
chat-permission-mode-hint = El modo { $mode } pregunta antes de acciones como esta
chat-permission-reason-secrets = Esto lee secretos o credenciales.
chat-permission-reason-secrets-leaving = Esto podría enviar secretos fuera de esta computadora.
chat-permission-reason-sends-out = Esto envía o publica algo fuera de esta computadora.
Expand Down
3 changes: 3 additions & 0 deletions apps/maple-agent/app/locales/ko/app.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,9 @@ chat-question-label = Maple의 질문
chat-permission-label = 이 동작을 허용할까요?
chat-permission-allow = 한 번 허용
chat-permission-deny = 거부
chat-permission-note-placeholder = 또는 Maple에게 대신 할 일을 알려주세요…
# $mode is the name of the task's permission mode, for example Auto.
chat-permission-mode-hint = '{ $mode }' 모드는 이런 동작을 하기 전에 물어봐요
chat-permission-reason-secrets = 비밀 정보 또는 자격 증명을 읽어요.
chat-permission-reason-secrets-leaving = 비밀 정보를 이 컴퓨터 밖으로 보낼 수 있어요.
chat-permission-reason-sends-out = 이 컴퓨터 밖으로 무언가를 보내거나 게시해요.
Expand Down
17 changes: 16 additions & 1 deletion apps/maple-agent/app/src/ui/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ struct TranscriptCtx<'a> {
/// For a step: whether the thread's rail runs on to the steps drawn
/// right above and below it.
rail: step::Rail,
/// For a tool call the user was asked to allow: where that stands.
asked: Option<step::Asked>,
}

/// Text-to-speech progress for one message.
Expand Down Expand Up @@ -856,6 +858,9 @@ pub struct ChatScreen {
/// How long finished turns worked, by lead item id. Only turns this
/// window timed have one.
turn_worked: HashMap<String, std::time::Duration>,
/// What the user said to the permission requests answered in this
/// view, by the id of the tool call each was about: allowed, or not.
step_permissions: HashMap<String, bool>,
/// Clocks of the runs this window saw start, by session id.
run_clocks: HashMap<String, turn::TimedRun>,
/// A repaint for a running turn's time is on its way.
Expand Down Expand Up @@ -1700,6 +1705,7 @@ impl ChatScreen {
turns: turn::Turns::default(),
toggled_chunks: HashSet::new(),
turn_worked: HashMap::new(),
step_permissions: HashMap::new(),
run_clocks: HashMap::new(),
run_tick_pending: std::cell::Cell::new(false),
question_selected: HashMap::new(),
Expand Down Expand Up @@ -3782,6 +3788,7 @@ impl ChatScreen {
self.toggled_tools.clear();
self.toggled_chunks.clear();
self.turn_worked.clear();
self.step_permissions.clear();
if let Some(composer) = self.composer.clone() {
composer.update(cx, |input, cx| input.reset_vim_context(cx));
}
Expand Down Expand Up @@ -5815,8 +5822,14 @@ impl ChatScreen {
let chat = cx.entity().downgrade();
let question_chat = chat.clone();
let application_vim_enabled = self.application_vim_enabled;
// On a permission request the field is the other way to answer.
let placeholder = if self.current_permission().is_some() {
"chat-permission-note-placeholder"
} else {
"chat-answer-placeholder"
};
let input = cx.new(move |cx| {
TextInput::localized("chat-answer-placeholder", cx)
TextInput::localized(placeholder, cx)
.application_vim(application_vim_enabled)
.on_application_escape(move |window, cx| {
if let Some(chat) = question_chat.upgrade() {
Expand Down Expand Up @@ -5911,6 +5924,7 @@ impl ChatScreen {
if answer.trim().is_empty() {
return;
}
self.settle_permission(&question);
let request_id = question.request_id.clone();
let callback_request_id = request_id.clone();
let backend = self.backend.clone();
Expand Down Expand Up @@ -7638,6 +7652,7 @@ impl Render for ChatScreen {
input,
&self.question_selected,
&key_labels,
self.permission_mode,
&self.messages,
cx,
),
Expand Down
2 changes: 2 additions & 0 deletions apps/maple-agent/app/src/ui/chat/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ impl ChatScreen {
.retain(|id| self.timeline_index.contains_key(id));
self.turn_worked
.retain(|id, _| self.timeline_index.contains_key(id));
self.step_permissions
.retain(|id, _| self.timeline_index.contains_key(id));
self.markdown_cache.clear();
self.derived.clear();
self.messages = Default::default();
Expand Down
43 changes: 34 additions & 9 deletions apps/maple-agent/app/src/ui/chat/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ const NODE_CENTRE: Pixels = px(16.);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum StepState {
Running,
/// The call waits for the user to allow it.
Waiting,
Done,
Failed,
Stopped,
/// The user said no to the call.
Denied,
}

impl StepState {
Expand All @@ -38,23 +42,38 @@ impl StepState {
/// Colour of the step's title.
pub(super) fn ink(self) -> u32 {
match self {
Self::Done | Self::Failed => theme::text_primary(),
Self::Running | Self::Stopped => theme::text_muted(),
Self::Done | Self::Failed | Self::Waiting => theme::text_primary(),
Self::Running | Self::Stopped | Self::Denied => theme::text_muted(),
}
}
}

/// What the user was asked about a tool call, and said.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Asked {
/// The request is on screen.
Waiting,
Allowed,
Denied,
}

/// Whether the rail runs on from a step's node to the step drawn right
/// above it, and to the one right below.
pub(super) type Rail = (bool, bool);

/// The icon on a tool call's node, by what the tool does.
pub(super) fn tool_icon(item: &AgentTimelineItem) -> &'static str {
let name = item
.label
.as_ref()
.filter(|label| label.kind == "tool")
.and_then(|label| label.name.as_deref());
icon_for_tool(
item.label
.as_ref()
.filter(|label| label.kind == "tool")
.and_then(|label| label.name.as_deref()),
)
}

/// The icon for a tool by its name; a tool the app does not know gets the
/// plain one.
pub(super) fn icon_for_tool(name: Option<&str>) -> &'static str {
match name {
Some("bash" | "powershell" | "shell") => "terminal",
Some("read" | "read_file") => "file-text",
Expand Down Expand Up @@ -90,7 +109,9 @@ pub(super) fn step(
let glyph = match state {
StepState::Done => theme::text_secondary(),
StepState::Failed => theme::status_error(),
StepState::Running | StepState::Stopped => theme::text_muted(),
// Coral means the step waits on the user.
StepState::Waiting => theme::accent_ink(),
StepState::Running | StepState::Stopped | StepState::Denied => theme::text_muted(),
};
let segment = || div().absolute().left(px(10.)).w(px(1.)).bg(line);
div()
Expand Down Expand Up @@ -120,7 +141,11 @@ pub(super) fn step(
.rounded_full()
.bg(gpui::rgb(theme::bg_app()))
.border_1()
.border_color(line)
.border_color(if state == StepState::Waiting {
gpui::rgb(glyph)
} else {
line
})
.flex()
.items_center()
.justify_center()
Expand Down
57 changes: 57 additions & 0 deletions apps/maple-agent/app/src/ui/chat/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,63 @@ mod state_tests {
});
}

/// A permission request is about the call still running, and that
/// call keeps what the user answered.
#[gpui::test]
fn test_a_call_keeps_what_the_user_said_to_its_permission_request(cx: &mut TestAppContext) {
cx.executor().allow_parking();
let screen = screen(cx);
screen.update(cx, |this, cx| {
this.selected_session = Some("s1".to_string());
let call = |id: &str, status: &str, command: &str| AgentTimelineItem {
status: Some(status.to_string()),
label: Some(maple_agent::agent::AgentTimelineLabel {
kind: "tool".to_string(),
name: Some("bash".to_string()),
detail: Some(command.to_string()),
}),
input: Some(serde_json::json!({ "command": command })),
..item(id, "tool", None)
};
// One reply made these calls. All are on screen as running
// before any is asked about.
this.replace_timeline(vec![
user_item("u1", "Push it"),
call("read", "completed", "cat notes.txt"),
call("push", "running", "git push"),
call("list", "running", "ls"),
]);
assert_eq!(this.waiting_step(), None, "nothing waits before a request");

this.handle_service_event(permission_event("p1"), cx);
assert_eq!(
this.waiting_step(),
Some(2),
"the request is about the call that would do what it says, not the newest"
);
this.toggle_question_option(0, 0, cx);
assert_eq!(this.step_permissions.get("push"), Some(&true));

// The same command again is the next call's; it is refused,
// and the earlier answer stays.
this.apply_incoming_item("s1", call("again", "running", "git push"), cx);
this.handle_service_event(permission_event("p2"), cx);
assert_eq!(this.waiting_step(), Some(4));
this.toggle_question_option(0, 1, cx);
assert_eq!(this.step_permissions.get("again"), Some(&false));
assert_eq!(this.step_permissions.get("push"), Some(&true));

// Two calls the request could mean: neither is marked, and
// neither keeps the answer.
this.apply_incoming_item("s1", call("third", "running", "git push"), cx);
this.apply_incoming_item("s1", call("fourth", "running", "git push"), cx);
this.handle_service_event(permission_event("p3"), cx);
assert_eq!(this.waiting_step(), None);
this.toggle_question_option(0, 0, cx);
assert_eq!(this.step_permissions.len(), 2);
});
}

/// A permission card and its notification are worded in the interface's
/// language, and the answer stays the runtime's label in any language.
#[gpui::test]
Expand Down
Loading
Loading