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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/forge_main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ open.workspace = true
humantime.workspace = true
num-format.workspace = true
atty = "0.2"
gray_matter.workspace = true
url.workspace = true
rust-embed = { version = "8.5", features = ["interpolate-folder-path"] }
indexmap.workspace = true
Expand Down
82 changes: 0 additions & 82 deletions crates/forge_main/src/built_in_commands.json

This file was deleted.

134 changes: 134 additions & 0 deletions crates/forge_main/src/built_in_commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
use anyhow::{Context, Result};
use rust_embed::RustEmbed;

/// Embedded built-in command markdown files
#[derive(RustEmbed)]
#[folder = "src/built_in_commands/"]
#[include = "*.md"]
struct BuiltInCommands;

/// Simple struct to hold parsed command information
pub struct CommandInfo {
pub name: String,
pub description: String,
pub alias: Option<String>,
}

/// Parse a command from markdown content with YAML frontmatter
fn parse_command_markdown(content: &str) -> Result<CommandInfo> {
use gray_matter::Matter;
use gray_matter::engine::YAML;

#[derive(serde::Deserialize)]
struct FrontMatter {
name: String,
description: String,
#[serde(default)]
alias: Option<String>,
}

let matter = Matter::<YAML>::new();
let result = matter.parse::<FrontMatter>(content)?;

let front_matter = result.data.context("Missing command frontmatter")?;

Ok(CommandInfo {
name: front_matter.name,
description: front_matter.description,
alias: front_matter.alias,
})
}

/// Get all built-in commands
///
/// # Errors
///
/// Returns error if any command file cannot be loaded or parsed
pub fn get_built_in_commands() -> Result<Vec<CommandInfo>> {
let mut commands = Vec::new();

for file in BuiltInCommands::iter() {
let content = BuiltInCommands::get(&file)
.with_context(|| format!("Failed to load built-in command: {}", file))?;

let content_str = std::str::from_utf8(content.data.as_ref())
.with_context(|| format!("Invalid UTF-8 in command file: {}", file))?;

let command = parse_command_markdown(content_str)
.with_context(|| format!("Failed to parse built-in command: {}", file))?;

commands.push(command);
}

Ok(commands)
}

/// Get formatted documentation for a specific built-in command
///
/// # Errors
///
/// Returns error if the command is not found or cannot be parsed
pub fn get_command_doc(name: &str) -> Result<String> {
use gray_matter::Matter;
use gray_matter::engine::YAML;

#[derive(serde::Deserialize)]
struct FrontMatter {
name: String,
description: String,
}

let filename = format!("{}.md", name);

let content = BuiltInCommands::get(&filename)
.with_context(|| format!("Built-in command not found: {}", name))?;

let content_str = std::str::from_utf8(content.data.as_ref())
.with_context(|| format!("Invalid UTF-8 in command file: {}", filename))?;

let matter = Matter::<YAML>::new();
let result = matter.parse::<FrontMatter>(content_str)?;

let front_matter = result.data.context("Missing command frontmatter")?;

Ok(format!(
"# {}\n\n{}\n\n{}",
front_matter.name, front_matter.description, result.content
))
}

#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;

use super::*;

#[test]
fn test_get_built_in_commands() {
let actual = get_built_in_commands().unwrap();

// Should have all 20 built-in commands
assert_eq!(actual.len(), 20);

// Verify a few key commands exist
assert!(actual.iter().any(|c| c.name == "info"));
assert!(actual.iter().any(|c| c.name == "agent"));
assert!(actual.iter().any(|c| c.name == "sync"));
assert!(actual.iter().any(|c| c.name == "commit"));
}

#[test]
fn test_command_has_description() {
let actual = get_built_in_commands().unwrap();

// All commands should have non-empty descriptions
for command in actual {
assert!(!command.name.is_empty(), "Command name should not be empty");
assert!(
!command.description.is_empty(),
"Command {} should have a description",
command.name
);
}
}
}
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: agent
description: Select and switch between agents
alias: a
---

Switch between different AI agents with specialized capabilities and behaviors.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/clone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: clone
description: Clone and manage conversation context
---

Create a copy of the current conversation context to start a new branch of the discussion.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: commit
description: Generate AI commit message and commit changes.
---

Analyze staged changes and generate an appropriate commit message, then commit the changes to the repository.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/compact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: compact
description: Compact the conversation context
---

Compress and optimize the conversation history to reduce token usage while preserving important context.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/conversation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: conversation
description: List all conversations for the active workspace
alias: c
---

Display a list of all conversations in the current workspace with their timestamps and details.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/doctor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: doctor
description: Run environment diagnostics for the shell plugin
---

Diagnose and report issues with the shell plugin installation and configuration.
11 changes: 11 additions & 0 deletions crates/forge_main/src/built_in_commands/dump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: dump
description: Save conversation as JSON or HTML (use /dump html for HTML format)
alias: d
---

Save the current conversation to a file. Supports JSON and HTML formats.

Usage:
- `/dump` - Save as JSON
- `/dump html` - Save as HTML
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/edit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: edit
description: Use an external editor to write a prompt
---

Open your default text editor to compose a longer, multi-line prompt before sending it to the AI.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: env
description: Display environment information
alias: e
---

Shows environment configuration including operating system, shell, paths, and other environment variables.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: info
description: Print session information
alias: i
---

Displays current session information including active provider, model, agent, and workspace details.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/login.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: login
description: Login to a provider
---

Authenticate with an AI provider to enable access to their models and services.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/logout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: logout
description: Logout from a provider
---

Remove authentication credentials for a specific AI provider.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: model
description: Switch the models
alias: m
---

Switch between different AI models available for the current provider.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: new
description: Start new conversation
alias: n
---

Start a new conversation session, clearing the current context and history.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: provider
description: Switch the providers
alias: p
---

Switch between different AI providers (e.g., OpenAI, Anthropic, Google, etc.).
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/retry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: retry
description: Retry the last command
alias: r
---

Re-execute the last command or message sent in the current conversation.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/skill.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: skill
description: List all available skills
---

Show all available skills that can be loaded to extend the AI's capabilities with specialized knowledge and workflows.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/suggest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: suggest
description: Generate shell commands without executing them
alias: s
---

Generate shell command suggestions based on your natural language description without executing them.
6 changes: 6 additions & 0 deletions crates/forge_main/src/built_in_commands/sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: sync
description: Sync the current workspace for codebase search
---

Synchronize and index the current workspace to enable semantic code search and navigation.
7 changes: 7 additions & 0 deletions crates/forge_main/src/built_in_commands/tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: tools
description: List all available tools with their descriptions and schema
alias: t
---

Display all available tools that the AI can use, including their descriptions, parameters, and schemas.
Loading
Loading