Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2e77da4
feat(shell): implement :conversation clone command
dariuszkowalski-com Nov 24, 2025
9dabb6d
Merge branch 'main' into feature/conversation-clone-shell-plugin-clean
dariuszkowalski-com Nov 25, 2025
6465b2f
Merge branch 'main' into feature/conversation-clone-shell-plugin-clean
tusharmath Nov 26, 2025
e140c92
Merge branch 'main' into feature/conversation-clone-shell-plugin-clean
dariuszkowalski-com Nov 26, 2025
9fd5b18
feat(shell-plugin): add :clone command with smart conversation display
dariuszkowalski-com Nov 25, 2025
d34d2d1
refactor(shell-plugin): remove :conversation clone functionality
dariuszkowalski-com Nov 25, 2025
f4e12dc
feat: add :clone command to built-in commands and improve logging
dariuszkowalski-com Nov 26, 2025
02df3a5
feat: restore :clone functionality in shell plugin
dariuszkowalski-com Nov 27, 2025
9e9b1e0
feat: add :clone command to built_in_commands.json
dariuszkowalski-com Nov 27, 2025
dfe1802
test: add missing command fixtures for test_parse_builtin_commands
dariuszkowalski-com Nov 27, 2025
848584a
test: fix fixture paths in test_parse_builtin_commands
dariuszkowalski-com Nov 27, 2025
4331798
fix: restore original command paths and fix test
dariuszkowalski-com Nov 27, 2025
9ade28c
fix: complete restoration of .forge and benchmarks files
dariuszkowalski-com Nov 27, 2025
bc25539
revert: restore .forge/ and benchmarks/ to main branch state
dariuszkowalski-com Nov 27, 2025
a15d8f1
Merge branch 'main' into feature/conversation-clone-shell-plugin-clean
tusharmath Nov 29, 2025
2f27e53
Merge branch 'main' into feature/conversation-clone-shell-plugin-clean
tusharmath Nov 29, 2025
827c103
refactor(shell): simplify clone output logging
tusharmath Nov 29, 2025
2f81094
refactor(shell): unify preview window configuration in clone action
tusharmath Nov 29, 2025
04acedc
style(info): change info display color from cyan to green
tusharmath Nov 29, 2025
f84255f
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 29, 2025
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
4 changes: 4 additions & 0 deletions crates/forge_main/src/built_in_commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,9 @@
{
"command": "agent",
"description": "Select and switch between agents [alias: a]"
},
{
"command": "clone",
"description": "Clone and manage conversation context"
}
]
11 changes: 8 additions & 3 deletions crates/forge_main/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,19 @@ impl fmt::Display for Info {
Section::Items(key, value) => {
if let Some(key) = key {
if let Some(width) = width {
writeln!(f, " {} {}", format!("{key:<width$}:").cyan().bold(), value)?;
writeln!(
f,
" {} {}",
format!("{key:<width$}:").green().bold(),
value
)?;
} else {
// No section width (items without a title)
writeln!(f, " {}: {}", key.cyan().bold(), value)?;
writeln!(f, " {}: {}", key.green().bold(), value)?;
}
} else {
// Show value-only items
writeln!(f, " {} {}", "⦿".cyan(), value)?;
writeln!(f, " {} {}", "⦿".green(), value)?;
}
}
}
Expand Down
225 changes: 225 additions & 0 deletions shell-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Forge ZSH Plugin

A powerful ZSH plugin that provides intelligent command transformation, file tagging, and conversation management for the Forge AI assistant.

## Features

- **Smart Command Transformation**: Convert `:command` syntax into forge executions
- **Agent Selection**: Tab completion for available agents using `:agent_name`
- **File Tagging**: Interactive file selection with `@[filename]` syntax
- **Syntax Highlighting**: Visual feedback for commands and tagged files
- **Conversation Continuity**: Automatic session management across commands
- **Interactive Completion**: Fuzzy finding for files and agents

## Prerequisites

Before using this plugin, ensure you have the following tools installed:

- **fzf** - Command-line fuzzy finder
- **fd** - Fast file finder (alternative to find)
- **forge** - The Forge CLI tool

### Installation of Prerequisites

```bash
# macOS (using Homebrew)
brew install fzf fd

# Ubuntu/Debian
sudo apt install fzf fd-find

# Arch Linux
sudo pacman -S fzf fd
```

## Usage

### Starting a Conversation

Begin any command with `:` followed by your prompt:

```bash
: Get the current time
```

This automatically starts a new conversation with the default Forge agent.

### Using Specific Agents

Specify an agent by name after the colon:

```bash
:sage How does caching work in this system?
:muse Create a deployment strategy for my app
```

**Tab Completion**: Type `:` followed by partial agent name and press `TAB` for interactive selection.

### File Tagging

Tag files in your commands using the `@[filename]` syntax:

```bash
: Review this code @[src/main.rs]
: Explain the configuration in @[config.yaml]
```

**Interactive Selection**: Type `@` and press `TAB` to search and select files interactively using fuzzy finder.

### Conversation Continuity

Commands within the same session maintain context:

```bash
# First command
: My project uses React and TypeScript

# Second command (remembers previous context)
: How can I optimize the build process?
```

The plugin automatically manages conversation IDs to maintain context across related commands.

### Session Management

#### Starting New Sessions

Clear the current conversation context and start fresh:

```bash
:new
# or use the alias
:n
```

This will:

- Clear the current conversation ID
- Show the banner with helpful information
- Reset the session state
- Display a confirmation message with timestamp

#### System Information

View system and project information:

```bash
:info
# or use the alias
:i
```

This displays:

- System information
- Project details
- Current configuration

- Current configuration

#### Cloning Conversations

Create a copy of an existing conversation with interactive selection:

```bash
:clone
```

This will:
- Display an interactive list of all conversations with preview
- Allow you to select a conversation to clone
- Create a new conversation with the same content
- Automatically switch to the cloned conversation
- Show the cloned conversation content and details

You can also clone a specific conversation by providing its ID:

```bash
:clone <conversation_id>
```

This is useful when you want to:
- Create a backup before making significant changes
- Start a new conversation branch from an existing context
- Experiment with different approaches while preserving the original

#### Session Status

The plugin automatically displays session information including:

- Conversation ID when starting new sessions
- Active agent information
- New session confirmations with timestamps

## Syntax Highlighting

The plugin provides visual feedback through syntax highlighting:

- **Tagged Files** (`@[filename]`): Displayed in **green bold**
- **Agent Commands** (`:agent`): Agent names in **yellow bold**
- **Command Text**: Remaining text in **white bold**

## Configuration

Customize the plugin behavior by setting these variables before loading the plugin:

```bash
# Custom forge binary location
export FORGE_BIN="/path/to/custom/forge"
```

### Available Configuration Variables

- `FORGE_BIN`: Path to the forge executable (default: `forge`)
- Internal pattern matching for conversation syntax (`:`)
- New session command keyword: `:new` or `:n`

### .forge Directory

The plugin creates a `.forge` directory in your current working directory (similar to `.git`) for temporary files:

- `FORGE_EDITMSG`: Temporary file used when opening an external editor with `:edit`

## Advanced Features

### Command History

All transformed commands are properly saved to ZSH history, allowing you to:

- Navigate command history with arrow keys
- Search previous forge commands with `Ctrl+R`
- Reuse complex commands with file tags

### Keyboard Shortcuts

- **Tab**: Interactive completion for files (`@`) and agents (`:`)
- **Enter**: Transform and execute `:commands`
- **Ctrl+C**: Interrupt running forge commands

## Examples

### Basic Usage

```bash
: What's the weather like?
:sage Explain the MVC pattern
:planner Help me structure this project
```

### With File Tagging

```bash
: Review this implementation @[src/auth.rs]
: Debug the issue in @[logs/error.log] @[config/app.yml]
```

### Session Flow

```bash
: I'm working on a Rust web API
: What are the best practices for error handling?
: Show me an example with @[src/errors.rs]
:info
:new
: New conversation starts here
```
100 changes: 99 additions & 1 deletion shell-plugin/forge.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typeset -h _FORGE_BIN="${FORGE_BIN:-forge}"
typeset -h _FORGE_CONVERSATION_PATTERN=":"
typeset -h _FORGE_MAX_COMMIT_DIFF="${FORGE_MAX_COMMIT_DIFF:-100000}"
typeset -h _FORGE_DELIMITER='\s\s+'
typeset -h _FORGE_PREVIEW_WINDOW="--preview-window=top:40%:wrap:border-sharp"
typeset -h _FORGE_PREVIEW_WINDOW="--preview-window=top:75%:wrap:border-sharp"

# Detect fd command - Ubuntu/Debian use 'fdfind', others use 'fd'
typeset -h _FORGE_FD_CMD="$(command -v fdfind 2>/dev/null || command -v fd 2>/dev/null || echo 'fd')"
Expand Down Expand Up @@ -702,6 +702,101 @@ function _forge_action_suggest() {
fi
}

# Action handler: Clone conversation
function _forge_action_clone() {
local input_text="$1"
local clone_target="$input_text"

echo

# Handle explicit clone target if provided
if [[ -n "$clone_target" ]]; then
_forge_clone_and_switch "$clone_target"
_forge_reset
return 0
fi

# Get conversations list for fzf selection
local conversations_output
conversations_output=$($_FORGE_BIN conversation list --porcelain 2>/dev/null)

if [[ -z "$conversations_output" ]]; then
_forge_log error "No conversations found"
_forge_reset
return 0
fi

# Get current conversation ID if set
local current_id="$_FORGE_CONVERSATION_ID"

# Create fzf interface similar to :conversation
local prompt_text="Clone Conversation ❯ "
local fzf_args=(
--prompt="$prompt_text"
--delimiter="$_FORGE_DELIMITER"
--with-nth="2,3"
--preview="CLICOLOR_FORCE=1 $_FORGE_BIN conversation info {1}; echo; CLICOLOR_FORCE=1 $_FORGE_BIN conversation show {1}"
$_FORGE_PREVIEW_WINDOW
)

# Position cursor on current conversation if available
if [[ -n "$current_id" ]]; then
local index=$(_forge_find_index "$conversations_output" "$current_id")
fzf_args+=(--bind="start:pos($index)")
fi

local selected_conversation
selected_conversation=$(echo "$conversations_output" | _forge_fzf "${fzf_args[@]}")

if [[ -n "$selected_conversation" ]]; then
# Extract conversation ID
local conversation_id=$(echo "$selected_conversation" | sed -E 's/ .*//' | tr -d '\n')
_forge_clone_and_switch "$conversation_id"
fi

_forge_reset
}

# Helper function to clone and switch to conversation
function _forge_clone_and_switch() {
local clone_target="$1"

# Store original conversation ID to check if we're cloning current conversation
local original_conversation_id="$_FORGE_CONVERSATION_ID"

# Execute clone command
_forge_log info "Cloning conversation \033[1m${clone_target}\033[0m"
local clone_output
clone_output=$($_FORGE_BIN conversation clone "$clone_target" 2>&1)
local clone_exit_code=$?

if [[ $clone_exit_code -eq 0 ]]; then
# Extract new conversation ID from output
local new_id=$(echo "$clone_output" | grep -oE '[a-f0-9-]{36}' | tail -1)

if [[ -n "$new_id" ]]; then
# Set as active conversation
_FORGE_CONVERSATION_ID="$new_id"

_forge_log success "└─ Switched to conversation \033[1m${new_id}\033[0m"

# Show content and info only if cloning a different conversation (not current one)
if [[ "$clone_target" != "$original_conversation_id" ]]; then
echo
_forge_exec conversation show "$new_id"

# Show new conversation info
echo
_forge_exec conversation info "$new_id"
fi
else
_forge_log error "Failed to extract new conversation ID from clone output"
fi
else
_forge_log error "Failed to clone conversation: $clone_output"
fi
}

# Action handler: Login to provider
function _forge_action_login() {
echo
Expand Down Expand Up @@ -882,6 +977,9 @@ function forge-accept-line() {
suggest|s)
_forge_action_suggest "$input_text"
;;
clone)
_forge_action_clone "$input_text"
;;
login)
_forge_action_login
;;
Expand Down
Loading