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
27 changes: 27 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# C++ formatting for bolt-cppml, checked by the Lint Code Base workflow
# (clang-format) together with CPPLINT.cfg (cpplint).
#
# Google style, which is what cpplint verifies, with the indentation and line
# length this code base already uses.
BasedOnStyle: Google
Language: Cpp
Standard: c++17

# Four-space indentation; access specifiers sit one space in, as cpplint expects.
IndentWidth: 4
AccessModifierOffset: -3
Comment on lines +11 to +13

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Formatter enforces the wrong indentation

IndentWidth enforces four-space indentation instead of the two spaces required by the Code Style Guidelines. Contributors cannot follow both the formatter and the documented rule.

Learn more

The repository's Code Style Guidelines require two-space indentation. The new formatter instead establishes four spaces as the repository-wide formatting policy, so running it preserves or creates violations of that requirement.

Example: Formatting a function body indents its statements by four spaces, while the contributor guideline requires two.

Recommended fix: Set IndentWidth to 2, adjust AccessModifierOffset to preserve the intended access-specifier placement, and reformat the affected files. If changing the repository policy is intended, explicitly reconcile the contributor guideline with that policy.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 4

# Keep in step with "linelength" in CPPLINT.cfg.
ColumnLimit: 120

# "Type* name", never derived from the surrounding code.
DerivePointerAlignment: false
PointerAlignment: Left

# Only short functions defined inside a class stay on one line.
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
22 changes: 22 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cpplint configuration for bolt-cppml, used by the Lint Code Base workflow.
# The matching formatter settings are in .clang-format.
set noparent

# Keep in step with ColumnLimit in .clang-format.
linelength=120

# Header guards are derived from the path below include/, for example
# include/bolt/bolt.hpp -> BOLT_BOLT_HPP_.
root=include

# The code is C++17 and uses the standard threading and time headers
# (<mutex>, <thread>, <chrono>, <system_error>, ...). cpplint's build/c++11
# check rejects those headers outright, so it cannot be satisfied.
filter=-build/c++11

# Source files carry no per-file copyright line; the licence is in LICENSE.
filter=-legal/copyright

# Non-const reference parameters are allowed. The Google style guide dropped
# this rule in 2020 and current cpplint releases no longer check it.
filter=-runtime/references
97 changes: 55 additions & 42 deletions bolt_terminal_ai.cpp
Original file line number Diff line number Diff line change
@@ -1,107 +1,119 @@
#include "include/bolt/ai/enhanced_ai_manager.hpp"
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>

#include "include/bolt/ai/enhanced_ai_manager.hpp"
#ifdef _WIN32
#include <io.h> // For _isatty / _fileno
#include <io.h> // For _isatty / _fileno
#define isatty _isatty
#define fileno _fileno
#else
#include <unistd.h> // For isatty
#endif

class BoltTerminalAI {
private:
private:
std::unique_ptr<bolt::ai::EnhancedAIManager> ai_manager_;
std::string session_id_;
public:

public:
BoltTerminalAI() {
ai_manager_ = std::make_unique<bolt::ai::EnhancedAIManager>();
session_id_ = "terminal_session";
ai_manager_->create_session(session_id_);
}

void show_status() {
std::cout << "\n📊 AI Status:\n";
std::cout << " Current Provider: " << ai_manager_->get_current_provider() << "\n";
std::cout << " Ready: " << (ai_manager_->is_ready() ? "✅" : "❌") << "\n";
std::cout << " Direct Model: " << (ai_manager_->has_direct_model() ? "✅ " + ai_manager_->get_model_info() : "❌ Using fallback") << "\n";

std::cout << " Direct Model: "
<< (ai_manager_->has_direct_model() ? "✅ " + ai_manager_->get_model_info() : "❌ Using fallback")
<< "\n";

auto stats = ai_manager_->get_statistics();
std::cout << " Total Requests: " << stats.total_requests << "\n";
std::cout << " Successful: " << stats.successful_requests << "\n";
std::cout << " Failed: " << stats.failed_requests << "\n\n";
}

void chat_loop() {
std::cout << "🤖 Bolt AI Terminal Chat\n";
std::cout << "========================\n\n";

show_status();

// Check if input is from a pipe or terminal
bool is_piped = !isatty(fileno(stdin));

if (!is_piped) {
std::cout << "Commands:\n";
std::cout << " /status - Show AI status\n";
std::cout << " /history - Show chat history\n";
std::cout << " /clear - Clear chat history\n";
std::cout << " /load - Try to load a GGUF model\n";
std::cout << " /quit - Exit the application\n\n";

std::cout << "💬 Start chatting (type your message and press Enter):\n\n";
}

std::string input;
while (std::getline(std::cin, input)) {
if (input.empty()) {
if (is_piped) break; // Exit on empty line when piped
if (is_piped)
break; // Exit on empty line when piped
continue;
}

if (!is_piped) {
std::cout << "You: " << input << "\n";
}

// Handle commands
if (input == "/quit" || input == "/exit") {
std::cout << "\n👋 Goodbye!\n";
break;
}

if (input == "/status") {
show_status();
if (!is_piped) continue;
else break;
if (!is_piped)
continue;
else
break;
}

if (input == "/history") {
show_history();
if (!is_piped) continue;
else break;
if (!is_piped)
continue;
else
break;
}

if (input == "/clear") {
ai_manager_->clear_session_history(session_id_);
std::cout << "🗑️ Chat history cleared.\n\n";
if (!is_piped) continue;
else break;
if (!is_piped)
continue;
else
break;
}

if (input == "/load") {
try_load_model();
if (!is_piped) continue;
else break;
if (!is_piped)
continue;
else
break;
}

// Send to AI
std::cout << "AI: ";
auto response = ai_manager_->chat(input, session_id_);

if (response.success) {
std::cout << response.response << "\n";
if (response.inference_time_ms > 0) {
Expand All @@ -114,32 +126,32 @@ class BoltTerminalAI {
} else {
std::cout << "❌ Error: " << response.error << "\n";
}

std::cout << "\n";

// For piped input, process one question and exit
if (is_piped) {
break;
}
}
}
private:

private:
void show_history() {
auto history = ai_manager_->get_session_history(session_id_);
if (history.empty()) {
std::cout << "📝 No chat history yet.\n\n";
return;
}

std::cout << "\n📜 Chat History:\n";
std::cout << "================\n";
for (const auto& entry : history) {
std::cout << entry << "\n";
}
std::cout << "\n";
}

void try_load_model() {
std::cout << "🔍 Attempting to auto-detect GGUF models...\n";
if (ai_manager_->auto_detect_models()) {
Expand All @@ -148,7 +160,8 @@ class BoltTerminalAI {
} else {
std::cout << "❌ No GGUF models found. You can:\n";
std::cout << " 1. Download a small model:\n";
std::cout << " wget -P ./models/ https://huggingface.co/microsoft/DialoGPT-small/resolve/main/model.gguf\n";
std::cout
<< " wget -P ./models/ https://huggingface.co/microsoft/DialoGPT-small/resolve/main/model.gguf\n";
std::cout << " 2. Or continue using intelligent fallback responses\n\n";
}
}
Expand All @@ -162,6 +175,6 @@ int main() {
std::cerr << "❌ Error: " << e.what() << std::endl;
return 1;
}

return 0;
}
Loading
Loading