Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
18 changes: 12 additions & 6 deletions crates/forge_main/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,16 @@ impl From<&UIState> for Info {

impl From<&Metrics> for Info {
fn from(metrics: &Metrics) -> Self {
let duration = match metrics.duration() {
Some(d) => humantime::format_duration(Duration::from_secs(d.as_secs())).to_string(),
None => "0s".to_string(),
};
let mut info = Info::new().add_title(format!("TASK COMPLETED [in {duration}]"));
let mut info = Info::new();
if let Some(duration) = metrics.duration()
&& duration.as_secs() > 0
{
let duration =
humantime::format_duration(Duration::from_secs(duration.as_secs())).to_string();
info = info.add_title(format!("TASK COMPLETED [in {duration}]"));
} else {
info = info.add_title("TASK COMPLETED".to_string())
}

// Add file changes section inspired by the example format
if metrics.files_changed.is_empty() {
Expand Down Expand Up @@ -410,7 +415,8 @@ impl From<&Conversation> for Info {
info = info.add_key_value("Title", title);
}

info
// Insert metrics information
info.extend(Info::from(&conversation.metrics))
}
}

Expand Down
25 changes: 18 additions & 7 deletions crates/forge_main/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use forge_api::{
ToolName, Workflow,
};
use forge_display::MarkdownFormat;
use forge_domain::{
ChatResponseContent, McpConfig, McpServerConfig, Metrics, Provider, Scope, TitleFormat,
};
use forge_domain::{ChatResponseContent, McpConfig, McpServerConfig, Provider, Scope, TitleFormat};
use forge_fs::ForgeFS;
use forge_spinner::SpinnerManager;
use forge_tracker::ToolCallPayload;
Expand Down Expand Up @@ -698,6 +696,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
match self.state.conversation_id {
Some(ref id) => Ok(*id),
None => {
let mut new_conversation = false;
self.spinner.start(Some("Initializing"))?;

// Select a model if workflow doesn't have one
Expand All @@ -719,10 +718,11 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
conversation
} else {
// Conversation doesn't exist, create a new one with this ID

new_conversation = true;
Conversation::new(conversation_id)
}
} else {
new_conversation = true;
Conversation::generate()
};

Expand All @@ -733,6 +733,17 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
.and_then(|ctx| ctx.usage)
.unwrap_or(self.state.usage.clone());

if new_conversation {
self.writeln_title(
TitleFormat::info("Initialized conversation")
.sub_title(conversation.id.into_string()),
)?;
} else {
self.writeln_title(
TitleFormat::info("Resumed conversation")
.sub_title(conversation.id.into_string()),
)?;
}
Ok(conversation.id)
}
}
Expand Down Expand Up @@ -973,7 +984,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
ChatResponse::TaskComplete => {
if let Some(conversation_id) = self.state.conversation_id.as_ref() {
let conversation = self.api.conversation(conversation_id).await?;
self.on_completion(conversation.unwrap().metrics).await?;
self.on_completion(conversation.unwrap()).await?;
}
}
}
Expand All @@ -993,11 +1004,11 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
Ok(())
}

async fn on_completion(&mut self, metrics: Metrics) -> anyhow::Result<()> {
async fn on_completion(&mut self, conversation: Conversation) -> anyhow::Result<()> {
self.spinner.start(Some("Loading Summary"))?;

let info = Info::default()
.extend(Info::from(&metrics))
.extend(Info::from(&conversation))
.extend(get_usage(&self.state));

// if let Ok(Some(usage)) = self.api.user_usage().await {
Expand Down
21 changes: 13 additions & 8 deletions shell-plugin/forge.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
# Configuration: Change these variables to customize the forge command and special characters
# Using typeset to keep variables local to plugin scope and prevent public exposure
typeset -h _FORGE_BIN="${FORGE_BIN:-forge}"
typeset -h _FORGE_CONVERSATION_PATTERN="#\?"
typeset -h _FORGE_CONVERSATION_PATTERN="\?\?"
Comment thread
tusharmath marked this conversation as resolved.

ZSH_HIGHLIGHT_HIGHLIGHTERS+=(pattern)
# Style the conversation pattern with appropriate highlighting
ZSH_HIGHLIGHT_PATTERNS+=('(#s)\?\? *' 'fg=white,bold')
Comment thread
tusharmath marked this conversation as resolved.


# Store conversation ID in a temporary variable (local to plugin)
typeset -h _FORGE_CONVERSATION_ID=""
Expand All @@ -17,7 +22,7 @@ function _forge_transform_buffer() {
local forge_cmd=""
local input_text=""

# Check if the line starts with the conversation pattern (default: '# ')
# Check if the line starts with the conversation pattern (default: '??')
if [[ "$BUFFER" =~ "^${_FORGE_CONVERSATION_PATTERN}(.*)$" ]]; then
input_text="${match[1]}"

Expand Down Expand Up @@ -88,7 +93,7 @@ function forge-at-completion() {
function forge-insert-pattern() {
# Toggle the conversation pattern at the beginning of the line
# while maintaining cursor position relative to the original text
local pattern="#? "
local pattern="?? "
local original_cursor_pos=$CURSOR

# Check if buffer already starts with the pattern
Expand Down Expand Up @@ -119,14 +124,14 @@ function forge-accept-line() {
echo # Add a newline before execution for better UX
eval "$BUFFER"

# Clear the buffer and reset prompt
BUFFER=""
CURSOR=0
# Set buffer to conversation pattern for continued interaction
BUFFER="?? "
CURSOR=${#BUFFER}
zle reset-prompt
return
fi

# For non-# commands, use normal accept-line
# For non-?? commands, use normal accept-line
zle accept-line
}

Expand All @@ -135,7 +140,7 @@ zle -N forge-insert-pattern
zle -N forge-accept-line
zle -N forge-at-completion

# Bind Enter to our custom accept-line that transforms # commands
# Bind Enter to our custom accept-line that transforms ?? commands
bindkey '^M' forge-accept-line
bindkey '^J' forge-accept-line

Expand Down
Loading