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 .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-08-02 - [Cow Optimization for String Processing]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the ad hoc Jules root directory

This task-specific optimization note introduces .jules/ as a new top-level content category even though it only documents this hooks implementation change and has no lasting product or tooling role. Remove it or place any durable documentation near the owning hooks module so the repository does not accumulate tool-specific scratch directories.

AGENTS.md reference: AGENTS.md:L131-L131

Useful? React with 👍 / 👎.

**Learning:** In Rust CLI applications processing potentially mixed-case arguments, `str::to_lowercase()` always eagerly allocates a `String` heap buffer. If the expected valid inputs are short and typically lowercase (like known agent names), this represents a 100% redundant allocation penalty.
**Action:** Use `std::borrow::Cow` combined with `.chars().any(|c| c.is_uppercase())` to skip allocation entirely for already-lowercase input, and return `Cow::Borrowed` literals when mapping to known values.
2 changes: 1 addition & 1 deletion crates/forktty-ui-gtk/src/socket_cli/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ pub(super) fn single_agent_command(
let Some(agent) = args.first() else {
return Err(CliError::new(format!("{command} requires an agent")));
};
let normalized = normalize_agent_name(agent);
let normalized = normalize_agent_name(agent).into_owned();
let spec = agent_spec(&normalized)
.ok_or_else(|| CliError::new(format!("Unsupported {command} agent: {agent}")))?;
Ok((spec, args[1..].to_vec()))
Expand Down
2 changes: 1 addition & 1 deletion crates/forktty-ui-gtk/src/socket_cli/hooks/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(in crate::socket_cli) fn handle_hook_event(
) -> CliResult<()> {
let agent_name = args
.first()
.map(|value| normalize_agent_name(value))
.map(|value| normalize_agent_name(value).into_owned())
.unwrap_or_default();
let event = args
.get(1)
Expand Down
19 changes: 13 additions & 6 deletions crates/forktty-ui-gtk/src/socket_cli/hooks/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,19 @@ pub(in crate::socket_cli) fn agent_spec(agent: &str) -> Option<&'static AgentSpe
AGENTS.iter().find(|spec| spec.key == agent)
}

pub(in crate::socket_cli) fn normalize_agent_name(agent: &str) -> String {
match agent.to_lowercase().as_str() {
"claude-code" | "claude_code" => "claude".to_string(),
"open-code" | "open_code" => "opencode".to_string(),
"agy" => "antigravity".to_string(),
other => other.to_string(),
pub(in crate::socket_cli) fn normalize_agent_name(agent: &str) -> std::borrow::Cow<'_, str> {
// Optimization: Avoid eager allocation by checking if the string is already lowercase.
let lowercased = if agent.chars().any(|c| c.is_uppercase()) {
std::borrow::Cow::Owned(agent.to_lowercase())
} else {
std::borrow::Cow::Borrowed(agent)
};

match lowercased.as_ref() {
"claude-code" | "claude_code" => std::borrow::Cow::Borrowed("claude"),
"open-code" | "open_code" => std::borrow::Cow::Borrowed("opencode"),
"agy" => std::borrow::Cow::Borrowed("antigravity"),
_ => lowercased,
}
}

Expand Down
Loading