Compare commits

..

37 Commits

Author SHA1 Message Date
Petr Mironychev
9a2ba08538 chore: Upgrade plugin to 0.9.11 2026-03-13 00:56:25 +01:00
Petr Mironychev
37084bec59 feat: Improve execute terminal command tool 2026-03-13 00:34:20 +01:00
Petr Mironychev
6910037e97 feat: Update models configuration 2026-03-12 23:58:06 +01:00
Petr Mironychev
a72cdd85a4 feat: Add support QtC 19
remove support QtC 17
2026-03-12 23:31:35 +01:00
lebedeviv1988
31b4e73af5 fix: Qt Creator 19 API breaking changes (#328)
* Inherits `QodeAssist::Settings::AgentRolesWidget` from `Core::IOptionsPageWidget`

* Adds `QodeAssist::Settings::showSettings` function and use it instead `Core::ICore::showOptionsDialog`

---------

Co-authored-by: Ivan Lebedev <ilebedev@flightpath3d.com>
2026-03-05 16:00:51 +01:00
lebedeviv1988
088887c802 fix: enables the send message shortcut only for active chat (#322)
fix: Disables sending message shortcut instead of filtering in `Shortcut::activated` signal handler

Co-authored-by: Ivan Lebedev <ilebedev@flightpath3d.com>
2026-03-05 12:01:14 +01:00
lebedeviv1988
b7a9787cc3 refactor: Refactors AgentRoleDialog's modes handling (#325)
* fix: Fixes `undefined-bool-conversion` compilation warning.

* refactor: Replaces `AgentRoleDialog::m_editMode` with `AgentRoleDialog::m_action`

---------

Co-authored-by: Ivan Lebedev <ilebedev@flightpath3d.com>
2026-03-05 10:48:01 +01:00
Petr Mironychev
e2e13f0f38 refactor: Improve http client (#319) 2026-02-25 15:13:05 +01:00
Petr Mironychev
49ae335d7d chore: Update plugin to 0.9.10 2026-02-25 12:33:14 +01:00
Petr Mironychev
2ba58a403f refactor: UI for opening content from chat (#318)
* refactor: Changed options to opening images from chat
* refactor: Add customizable tooltip
2026-02-25 07:49:37 +01:00
Petr Mironychev
3de1619bf0 feat: Add file search to chat (#317) 2026-02-22 13:53:44 +01:00
Petr Mironychev
ec45067336 chore: Upgrade plugin to 0.9.9 version 2026-01-27 22:41:57 +01:00
Petr Mironychev
52fb65c5b1 feat: Add support QtCreator 18.0.2 2026-01-27 22:41:20 +01:00
Petr Mironychev
478f369ad2 feat: Add codestral and mistral quick setup 2026-01-27 22:41:02 +01:00
Petr Mironychev
762c965377 fix: Add preconditions for windows chat 2026-01-27 22:35:02 +01:00
Petr Mironychev
d2b93310e2 chore: Update plugin to 0.9.8 2026-01-20 20:00:49 +01:00
Petr Mironychev
f3b1e7f411 Add quick setup screenshot 2026-01-20 19:57:44 +01:00
Petr Mironychev
a55c6ccfdb feat: Add predefined templates 2026-01-20 19:54:16 +01:00
Petr Mironychev
b32433c336 refactor: Change quick refactor ui layout 2026-01-20 18:08:49 +01:00
Petr Mironychev
6f11260cd1 refactor: Change UI for fix behavior 2026-01-19 23:52:44 +01:00
Petr Mironychev
ddd6aba091 fix: Remove close chat action from editor context menu 2026-01-19 23:17:31 +01:00
Dinesh Bala
e3f464c54e fix: Create _content folder only when there is an attachment (#297) 2025-12-16 13:19:10 +01:00
Petr Mironychev
e86e58337a Update QodeAssist version range for Qt Creator 16.0.2 2025-12-15 01:00:00 +01:00
Petr Mironychev
dbd47387be chore: Update plugin to 0.9.7 2025-12-15 00:47:50 +01:00
Petr Mironychev
50e1276ab2 feat: Add support QtC 18.0.1 (#296)
* feat: Add support QtC 18.0.1
* feat: Remove support QtC 16.0.2
2025-12-14 02:53:58 +01:00
Petr Mironychev
50c948ccfe chore: Update plugin to 0.9.6 version 2025-12-08 11:10:20 +01:00
Petr Mironychev
949dad4fd2 feat: Update built in roles and docs 2025-12-08 11:09:21 +01:00
Petr Mironychev
01fd7dad6f chore: Upgrade plugin to 0.9.5 version 2025-12-08 10:25:38 +01:00
Petr Mironychev
fd408ba415 fix: Change compressing icon place 2025-12-08 10:24:27 +01:00
Petr Mironychev
14e7ea2ec3 feat: Add separator to chat top bar 2025-12-08 10:18:12 +01:00
Petr Mironychev
9f050aec67 feat: Add summarize chat (#289) 2025-12-05 11:08:23 +01:00
Petr Mironychev
9e118ddfaf fix: Add pause between call tools 2025-12-04 21:05:13 +01:00
Petr Mironychev
157498b770 revert: Remove compact mode for chat blocks 2025-12-04 20:51:14 +01:00
Petr Mironychev
5c8a8f305d Fix chat scrolling (#288)
* fix: Change chat scrolling behavior
* feat: Add compact mode for chat blocks
2025-12-04 20:00:53 +01:00
Petr Mironychev
fc33bb60d0 feat: Add agent roles (#287)
* feat: Add agent roles
* doc: Add agent roles to docs
2025-12-04 19:41:30 +01:00
Petr Mironychev
498eb4d932 feat: Add todo tool (#286) 2025-12-03 21:28:59 +01:00
Petr Mironychev
fb941cea99 doc: Update docs for using OpenAI GPT-5.1 and codex 2025-12-01 16:08:21 +01:00
82 changed files with 5109 additions and 1280 deletions

View File

@@ -46,16 +46,12 @@ jobs:
}
qt_config:
- {
qt_version: "6.8.3",
qt_creator_version: "16.0.2"
qt_version: "6.10.1",
qt_creator_version: "18.0.2"
}
- {
qt_version: "6.9.2",
qt_creator_version: "17.0.2"
}
- {
qt_version: "6.10.0",
qt_creator_version: "18.0.0"
qt_version: "6.10.2",
qt_creator_version: "19.0.0"
}
steps:

View File

@@ -142,7 +142,6 @@ add_qtc_plugin(QodeAssist
QuickRefactorHandler.hpp QuickRefactorHandler.cpp
tools/ToolsFactory.hpp tools/ToolsFactory.cpp
tools/ReadVisibleFilesTool.hpp tools/ReadVisibleFilesTool.cpp
tools/ToolHandler.hpp tools/ToolHandler.cpp
tools/ListProjectFilesTool.hpp tools/ListProjectFilesTool.cpp
tools/ToolsManager.hpp tools/ToolsManager.cpp
@@ -154,6 +153,7 @@ add_qtc_plugin(QodeAssist
tools/ProjectSearchTool.hpp tools/ProjectSearchTool.cpp
tools/FindAndReadFileTool.hpp tools/FindAndReadFileTool.cpp
tools/FileSearchUtils.hpp tools/FileSearchUtils.cpp
tools/TodoTool.hpp tools/TodoTool.cpp
providers/ClaudeMessage.hpp providers/ClaudeMessage.cpp
providers/OpenAIMessage.hpp providers/OpenAIMessage.cpp
providers/OllamaMessage.hpp providers/OllamaMessage.cpp

View File

@@ -20,8 +20,9 @@ qt_add_qml_module(QodeAssistChatView
qml/controls/AttachedFilesPlace.qml
qml/controls/BottomBar.qml
qml/controls/FileMentionPopup.qml
qml/controls/FileEditsActionBar.qml
qml/controls/RulesViewer.qml
qml/controls/ContextViewer.qml
qml/controls/Toast.qml
qml/controls/TopBar.qml
qml/controls/SplitDropZone.qml
@@ -43,6 +44,7 @@ qt_add_qml_module(QodeAssistChatView
icons/chat-icon.svg
icons/chat-pause-icon.svg
icons/rules-icon.svg
icons/context-icon.svg
icons/open-in-editor.svg
icons/apply-changes-button.svg
icons/undo-changes-button.svg
@@ -52,6 +54,7 @@ qt_add_qml_module(QodeAssistChatView
icons/tools-icon-on.svg
icons/tools-icon-off.svg
icons/settings-icon.svg
icons/compress-icon.svg
SOURCES
ChatWidget.hpp ChatWidget.cpp
@@ -65,6 +68,8 @@ qt_add_qml_module(QodeAssistChatView
ChatData.hpp
FileItem.hpp FileItem.cpp
ChatFileManager.hpp ChatFileManager.cpp
ChatCompressor.hpp ChatCompressor.cpp
FileMentionItem.hpp FileMentionItem.cpp
)
target_link_libraries(QodeAssistChatView

310
ChatView/ChatCompressor.cpp Normal file
View File

@@ -0,0 +1,310 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ChatCompressor.hpp"
#include "ChatModel.hpp"
#include "GeneralSettings.hpp"
#include "PromptTemplateManager.hpp"
#include "ProvidersManager.hpp"
#include "logger/Logger.hpp"
#include <QDateTime>
#include <QFile>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QUuid>
namespace QodeAssist::Chat {
ChatCompressor::ChatCompressor(QObject *parent)
: QObject(parent)
{}
void ChatCompressor::startCompression(const QString &chatFilePath, ChatModel *chatModel)
{
if (m_isCompressing) {
emit compressionFailed(tr("Compression already in progress"));
return;
}
if (chatFilePath.isEmpty()) {
emit compressionFailed(tr("No chat file to compress"));
return;
}
if (!chatModel || chatModel->rowCount() == 0) {
emit compressionFailed(tr("Chat is empty, nothing to compress"));
return;
}
auto providerName = Settings::generalSettings().caProvider();
m_provider = LLMCore::ProvidersManager::instance().getProviderByName(providerName);
if (!m_provider) {
emit compressionFailed(tr("No provider available"));
return;
}
auto templateName = Settings::generalSettings().caTemplate();
auto promptTemplate = LLMCore::PromptTemplateManager::instance().getChatTemplateByName(
templateName);
if (!promptTemplate) {
emit compressionFailed(tr("No template available"));
return;
}
m_isCompressing = true;
m_chatModel = chatModel;
m_originalChatPath = chatFilePath;
m_accumulatedSummary.clear();
m_currentRequestId = QUuid::createUuid().toString(QUuid::WithoutBraces);
emit compressionStarted();
connectProviderSignals();
QUrl requestUrl;
QJsonObject payload;
if (m_provider->providerID() == LLMCore::ProviderID::GoogleAI) {
requestUrl = QUrl(QString("%1/models/%2:streamGenerateContent?alt=sse")
.arg(Settings::generalSettings().caUrl(),
Settings::generalSettings().caModel()));
} else {
requestUrl = QUrl(QString("%1%2").arg(Settings::generalSettings().caUrl(),
m_provider->chatEndpoint()));
payload["model"] = Settings::generalSettings().caModel();
payload["stream"] = true;
}
buildRequestPayload(payload, promptTemplate);
LOG_MESSAGE(QString("Starting compression request: %1").arg(m_currentRequestId));
m_provider->sendRequest(m_currentRequestId, requestUrl, payload);
}
bool ChatCompressor::isCompressing() const
{
return m_isCompressing;
}
void ChatCompressor::cancelCompression()
{
if (!m_isCompressing)
return;
LOG_MESSAGE("Cancelling compression request");
if (m_provider && !m_currentRequestId.isEmpty())
m_provider->cancelRequest(m_currentRequestId);
cleanupState();
emit compressionFailed(tr("Compression cancelled"));
}
void ChatCompressor::onPartialResponseReceived(const QString &requestId, const QString &partialText)
{
if (!m_isCompressing || requestId != m_currentRequestId)
return;
m_accumulatedSummary += partialText;
}
void ChatCompressor::onFullResponseReceived(const QString &requestId, const QString &fullText)
{
Q_UNUSED(fullText)
if (!m_isCompressing || requestId != m_currentRequestId)
return;
LOG_MESSAGE(
QString("Received summary, length: %1 characters").arg(m_accumulatedSummary.length()));
QString compressedPath = createCompressedChatPath(m_originalChatPath);
if (!createCompressedChatFile(m_originalChatPath, compressedPath, m_accumulatedSummary)) {
handleCompressionError(tr("Failed to save compressed chat"));
return;
}
LOG_MESSAGE(QString("Compression completed: %1").arg(compressedPath));
cleanupState();
emit compressionCompleted(compressedPath);
}
void ChatCompressor::onRequestFailed(const QString &requestId, const QString &error)
{
if (!m_isCompressing || requestId != m_currentRequestId)
return;
LOG_MESSAGE(QString("Compression request failed: %1").arg(error));
handleCompressionError(tr("Compression failed: %1").arg(error));
}
void ChatCompressor::handleCompressionError(const QString &error)
{
cleanupState();
emit compressionFailed(error);
}
QString ChatCompressor::createCompressedChatPath(const QString &originalPath) const
{
QFileInfo fileInfo(originalPath);
QString hash = QString::number(QDateTime::currentMSecsSinceEpoch() % 100000, 16);
return QString("%1/%2_%3.%4")
.arg(fileInfo.absolutePath(), fileInfo.completeBaseName(), hash, fileInfo.suffix());
}
QString ChatCompressor::buildCompressionPrompt() const
{
return QStringLiteral(
"Please create a comprehensive summary of our entire conversation above. "
"The summary should:\n"
"1. Preserve all important context, decisions, and key information\n"
"2. Maintain technical details, code snippets, file references, and specific examples\n"
"3. Keep the chronological flow of the discussion\n"
"4. Be significantly shorter than the original (aim for 30-40% of original length)\n"
"5. Be written in clear, structured format\n"
"6. Use markdown formatting for better readability\n\n"
"Create the summary now:");
}
void ChatCompressor::buildRequestPayload(
QJsonObject &payload, LLMCore::PromptTemplate *promptTemplate)
{
LLMCore::ContextData context;
context.systemPrompt = QStringLiteral(
"You are a helpful assistant that creates concise summaries of conversations. "
"Your summaries preserve key information, technical details, and the flow of discussion.");
QVector<LLMCore::Message> messages;
for (const auto &msg : m_chatModel->getChatHistory()) {
if (msg.role == ChatModel::ChatRole::Tool
|| msg.role == ChatModel::ChatRole::FileEdit
|| msg.role == ChatModel::ChatRole::Thinking)
continue;
LLMCore::Message apiMessage;
apiMessage.role = (msg.role == ChatModel::ChatRole::User) ? "user" : "assistant";
apiMessage.content = msg.content;
messages.append(apiMessage);
}
LLMCore::Message compressionRequest;
compressionRequest.role = "user";
compressionRequest.content = buildCompressionPrompt();
messages.append(compressionRequest);
context.history = messages;
m_provider->prepareRequest(
payload, promptTemplate, context, LLMCore::RequestType::Chat, false, false);
}
bool ChatCompressor::createCompressedChatFile(
const QString &sourcePath, const QString &destPath, const QString &summary)
{
QFile sourceFile(sourcePath);
if (!sourceFile.open(QIODevice::ReadOnly)) {
LOG_MESSAGE(QString("Failed to open source chat file: %1").arg(sourcePath));
return false;
}
QJsonParseError parseError;
QJsonDocument doc = QJsonDocument::fromJson(sourceFile.readAll(), &parseError);
sourceFile.close();
if (doc.isNull() || !doc.isObject()) {
LOG_MESSAGE(QString("Invalid JSON in chat file: %1 (Error: %2)")
.arg(sourcePath, parseError.errorString()));
return false;
}
QJsonObject root = doc.object();
QJsonObject summaryMessage;
summaryMessage["role"] = "assistant";
summaryMessage["content"] = QString("# Chat Summary\n\n%1").arg(summary);
summaryMessage["id"] = QUuid::createUuid().toString(QUuid::WithoutBraces);
summaryMessage["isRedacted"] = false;
summaryMessage["attachments"] = QJsonArray();
summaryMessage["images"] = QJsonArray();
root["messages"] = QJsonArray{summaryMessage};
if (QFile::exists(destPath))
QFile::remove(destPath);
QFile destFile(destPath);
if (!destFile.open(QIODevice::WriteOnly)) {
LOG_MESSAGE(QString("Failed to create compressed chat file: %1").arg(destPath));
return false;
}
destFile.write(QJsonDocument(root).toJson(QJsonDocument::Indented));
return true;
}
void ChatCompressor::connectProviderSignals()
{
m_connections.append(connect(
m_provider,
&LLMCore::Provider::partialResponseReceived,
this,
&ChatCompressor::onPartialResponseReceived,
Qt::UniqueConnection));
m_connections.append(connect(
m_provider,
&LLMCore::Provider::fullResponseReceived,
this,
&ChatCompressor::onFullResponseReceived,
Qt::UniqueConnection));
m_connections.append(connect(
m_provider,
&LLMCore::Provider::requestFailed,
this,
&ChatCompressor::onRequestFailed,
Qt::UniqueConnection));
}
void ChatCompressor::disconnectAllSignals()
{
for (const auto &connection : std::as_const(m_connections))
disconnect(connection);
m_connections.clear();
}
void ChatCompressor::cleanupState()
{
disconnectAllSignals();
m_isCompressing = false;
m_currentRequestId.clear();
m_originalChatPath.clear();
m_accumulatedSummary.clear();
m_chatModel = nullptr;
m_provider = nullptr;
}
} // namespace QodeAssist::Chat

View File

@@ -0,0 +1,79 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QJsonObject>
#include <QList>
#include <QObject>
#include <QString>
namespace QodeAssist::LLMCore {
class Provider;
class PromptTemplate;
} // namespace QodeAssist::LLMCore
namespace QodeAssist::Chat {
class ChatModel;
class ChatCompressor : public QObject
{
Q_OBJECT
public:
explicit ChatCompressor(QObject *parent = nullptr);
void startCompression(const QString &chatFilePath, ChatModel *chatModel);
bool isCompressing() const;
void cancelCompression();
signals:
void compressionStarted();
void compressionCompleted(const QString &compressedChatPath);
void compressionFailed(const QString &error);
private slots:
void onPartialResponseReceived(const QString &requestId, const QString &partialText);
void onFullResponseReceived(const QString &requestId, const QString &fullText);
void onRequestFailed(const QString &requestId, const QString &error);
private:
QString createCompressedChatPath(const QString &originalPath) const;
QString buildCompressionPrompt() const;
bool createCompressedChatFile(
const QString &sourcePath, const QString &destPath, const QString &summary);
void connectProviderSignals();
void disconnectAllSignals();
void cleanupState();
void handleCompressionError(const QString &error);
void buildRequestPayload(QJsonObject &payload, LLMCore::PromptTemplate *promptTemplate);
bool m_isCompressing = false;
QString m_currentRequestId;
QString m_originalChatPath;
QString m_accumulatedSummary;
LLMCore::Provider *m_provider = nullptr;
ChatModel *m_chatModel = nullptr;
QList<QMetaObject::Connection> m_connections;
};
} // namespace QodeAssist::Chat

View File

@@ -117,8 +117,10 @@ QVariant ChatModel::data(const QModelIndex &index, int role) const
QString contentFolder = QDir(dirPath).filePath(baseName + "_content");
QString fullPath = QDir(contentFolder).filePath(image.storedPath);
imageMap["imageUrl"] = QUrl::fromLocalFile(fullPath).toString();
imageMap["filePath"] = fullPath;
} else {
imageMap["imageUrl"] = QString();
imageMap["filePath"] = QString();
}
imagesList.append(imageMap);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
* Copyright (C) 2024-2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -21,9 +21,12 @@
#include <QClipboard>
#include <QDesktopServices>
#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QTextStream>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
@@ -34,7 +37,9 @@
#include <utils/theme/theme.h>
#include <utils/utilsicons.h>
#include "AgentRole.hpp"
#include "ChatAssistantSettings.hpp"
#include "ChatCompressor.hpp"
#include "ChatSerializer.hpp"
#include "ConfigurationManager.hpp"
#include "GeneralSettings.hpp"
@@ -57,6 +62,7 @@ ChatRootView::ChatRootView(QQuickItem *parent)
, m_clientInterface(new ClientInterface(m_chatModel, &m_promptProvider, this))
, m_fileManager(new ChatFileManager(this))
, m_isRequestInProgress(false)
, m_chatCompressor(new ChatCompressor(this))
{
m_isSyncOpenFiles = Settings::chatAssistantSettings().linkOpenFiles();
connect(
@@ -117,6 +123,11 @@ ChatRootView::ChatRootView(QQuickItem *parent)
&Utils::BaseAspect::changed,
this,
&ChatRootView::updateInputTokensCount);
connect(
&Settings::chatAssistantSettings().systemPrompt,
&Utils::BaseAspect::changed,
this,
&ChatRootView::baseSystemPromptChanged);
auto editors = Core::EditorManager::instance();
@@ -209,6 +220,7 @@ ChatRootView::ChatRootView(QQuickItem *parent)
updateInputTokensCount();
refreshRules();
loadAvailableConfigurations();
loadAvailableAgentRoles();
connect(
ProjectExplorer::ProjectManager::instance(),
@@ -216,6 +228,18 @@ ChatRootView::ChatRootView(QQuickItem *parent)
this,
&ChatRootView::refreshRules);
connect(
ProjectExplorer::ProjectManager::instance(),
&ProjectExplorer::ProjectManager::projectAdded,
this,
&ChatRootView::openFilesChanged);
connect(
ProjectExplorer::ProjectManager::instance(),
&ProjectExplorer::ProjectManager::projectRemoved,
this,
&ChatRootView::openFilesChanged);
connect(
&Settings::chatAssistantSettings().enableChatTools,
&Utils::BaseAspect::changed,
@@ -238,6 +262,27 @@ ChatRootView::ChatRootView(QQuickItem *parent)
m_lastErrorMessage = error;
emit lastErrorMessageChanged();
});
// ChatCompressor signals
connect(m_chatCompressor, &ChatCompressor::compressionStarted, this, [this]() {
emit isCompressingChanged();
});
connect(m_chatCompressor, &ChatCompressor::compressionCompleted, this, [this](const QString &compressedChatPath) {
emit isCompressingChanged();
m_lastInfoMessage = tr("Chat compressed successfully!");
emit lastInfoMessageChanged();
emit compressionCompleted(compressedChatPath);
loadHistory(compressedChatPath);
});
connect(m_chatCompressor, &ChatCompressor::compressionFailed, this, [this](const QString &error) {
emit isCompressingChanged();
m_lastErrorMessage = error;
emit lastErrorMessageChanged();
emit compressionFailed(error);
});
}
ChatModel *ChatRootView::chatModel() const
@@ -311,6 +356,12 @@ void ChatRootView::clearLinkedFiles()
emit linkedFilesChanged();
}
void ChatRootView::clearMessages()
{
m_clientInterface->clearMessages();
clearLinkedFiles();
}
QString ChatRootView::getChatsHistoryDir() const
{
QString path;
@@ -699,7 +750,14 @@ void ChatRootView::openRulesFolder()
void ChatRootView::openSettings()
{
Core::ICore::showOptionsDialog(Constants::QODE_ASSIST_CHAT_ASSISTANT_SETTINGS_PAGE_ID);
Settings::showSettings(Constants::QODE_ASSIST_CHAT_ASSISTANT_SETTINGS_PAGE_ID);
}
void ChatRootView::openFileInEditor(const QString &filePath)
{
if (filePath.isEmpty())
return;
Core::EditorManager::openEditor(Utils::FilePath::fromString(filePath));
}
void ChatRootView::updateInputTokensCount()
@@ -752,6 +810,8 @@ void ChatRootView::onEditorAboutToClose(Core::IEditor *editor)
if (editor) {
m_currentEditors.removeOne(editor);
}
emit openFilesChanged();
}
void ChatRootView::onAppendLinkFileFromEditor(Core::IEditor *editor)
@@ -769,6 +829,7 @@ void ChatRootView::onEditorCreated(Core::IEditor *editor, const Utils::FilePath
{
if (editor && editor->document()) {
m_currentEditors.append(editor);
emit openFilesChanged();
}
}
@@ -1360,4 +1421,130 @@ QString ChatRootView::currentConfiguration() const
return m_currentConfiguration;
}
void ChatRootView::loadAvailableAgentRoles()
{
const QList<Settings::AgentRole> roles = Settings::AgentRolesManager::loadAllRoles();
m_availableAgentRoles.clear();
m_availableAgentRoles.append(Settings::AgentRolesManager::getNoRole().name);
for (const auto &role : roles)
m_availableAgentRoles.append(role.name);
const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId();
m_currentAgentRole = Settings::AgentRolesManager::getNoRole().name;
if (!lastRoleId.isEmpty()) {
for (const auto &role : roles) {
if (role.id == lastRoleId) {
m_currentAgentRole = role.name;
break;
}
}
}
emit availableAgentRolesChanged();
emit currentAgentRoleChanged();
}
void ChatRootView::applyAgentRole(const QString &roleName)
{
auto &settings = Settings::chatAssistantSettings();
if (roleName == Settings::AgentRolesManager::getNoRole().name) {
settings.lastUsedRoleId.setValue("");
settings.writeSettings();
m_currentAgentRole = roleName;
emit currentAgentRoleChanged();
return;
}
const QList<Settings::AgentRole> roles = Settings::AgentRolesManager::loadAllRoles();
for (const auto &role : roles) {
if (role.name == roleName) {
settings.lastUsedRoleId.setValue(role.id);
settings.writeSettings();
m_currentAgentRole = role.name;
emit currentAgentRoleChanged();
break;
}
}
}
QStringList ChatRootView::availableAgentRoles() const
{
return m_availableAgentRoles;
}
QString ChatRootView::currentAgentRole() const
{
return m_currentAgentRole;
}
QString ChatRootView::baseSystemPrompt() const
{
return Settings::chatAssistantSettings().systemPrompt();
}
QString ChatRootView::currentAgentRoleDescription() const
{
const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId();
if (lastRoleId.isEmpty())
return Settings::AgentRolesManager::getNoRole().description;
const Settings::AgentRole role = Settings::AgentRolesManager::loadRole(lastRoleId);
if (role.id.isEmpty())
return Settings::AgentRolesManager::getNoRole().description;
return role.description;
}
QString ChatRootView::currentAgentRoleSystemPrompt() const
{
const QString lastRoleId = Settings::chatAssistantSettings().lastUsedRoleId();
if (lastRoleId.isEmpty())
return QString();
const Settings::AgentRole role = Settings::AgentRolesManager::loadRole(lastRoleId);
if (role.id.isEmpty())
return QString();
return role.systemPrompt;
}
void ChatRootView::openAgentRolesSettings()
{
Settings::showSettings(Utils::Id("QodeAssist.AgentRoles"));
}
void ChatRootView::compressCurrentChat()
{
if (m_chatCompressor->isCompressing()) {
m_lastErrorMessage = tr("Compression is already in progress");
emit lastErrorMessageChanged();
return;
}
if (m_recentFilePath.isEmpty()) {
m_lastErrorMessage = tr("No chat file to compress. Please save the chat first.");
emit lastErrorMessageChanged();
return;
}
autosave();
m_chatCompressor->startCompression(m_recentFilePath, m_chatModel);
}
void ChatRootView::cancelCompression()
{
m_chatCompressor->cancelCompression();
}
bool ChatRootView::isCompressing() const
{
return m_chatCompressor->isCompressing();
}
} // namespace QodeAssist::Chat

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
* Copyright (C) 2024-2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -20,15 +20,18 @@
#pragma once
#include <QQuickItem>
#include <QVariantList>
#include "ChatFileManager.hpp"
#include "ChatModel.hpp"
#include "ClientInterface.hpp"
#include "ChatFileManager.hpp"
#include "llmcore/PromptProviderChat.hpp"
#include <coreplugin/editormanager/editormanager.h>
namespace QodeAssist::Chat {
class ChatCompressor;
class ChatRootView : public QQuickItem
{
Q_OBJECT
@@ -59,6 +62,12 @@ class ChatRootView : public QQuickItem
Q_PROPERTY(bool isThinkingSupport READ isThinkingSupport NOTIFY isThinkingSupportChanged FINAL)
Q_PROPERTY(QStringList availableConfigurations READ availableConfigurations NOTIFY availableConfigurationsChanged FINAL)
Q_PROPERTY(QString currentConfiguration READ currentConfiguration NOTIFY currentConfigurationChanged FINAL)
Q_PROPERTY(QStringList availableAgentRoles READ availableAgentRoles NOTIFY availableAgentRolesChanged FINAL)
Q_PROPERTY(QString currentAgentRole READ currentAgentRole NOTIFY currentAgentRoleChanged FINAL)
Q_PROPERTY(QString baseSystemPrompt READ baseSystemPrompt NOTIFY baseSystemPromptChanged FINAL)
Q_PROPERTY(QString currentAgentRoleDescription READ currentAgentRoleDescription NOTIFY currentAgentRoleChanged FINAL)
Q_PROPERTY(QString currentAgentRoleSystemPrompt READ currentAgentRoleSystemPrompt NOTIFY currentAgentRoleChanged FINAL)
Q_PROPERTY(bool isCompressing READ isCompressing NOTIFY isCompressingChanged FINAL)
QML_ELEMENT
@@ -96,6 +105,8 @@ public:
Q_INVOKABLE void openRulesFolder();
Q_INVOKABLE void openSettings();
Q_INVOKABLE void openFileInEditor(const QString &filePath);
Q_INVOKABLE void updateInputTokensCount();
int inputTokensCount() const;
@@ -146,6 +157,18 @@ public:
QStringList availableConfigurations() const;
QString currentConfiguration() const;
Q_INVOKABLE void compressCurrentChat();
Q_INVOKABLE void cancelCompression();
Q_INVOKABLE void loadAvailableAgentRoles();
Q_INVOKABLE void applyAgentRole(const QString &roleId);
Q_INVOKABLE void openAgentRolesSettings();
QStringList availableAgentRoles() const;
QString currentAgentRole() const;
QString baseSystemPrompt() const;
QString currentAgentRoleDescription() const;
QString currentAgentRoleSystemPrompt() const;
int currentMessageTotalEdits() const;
int currentMessageAppliedEdits() const;
int currentMessagePendingEdits() const;
@@ -155,12 +178,15 @@ public:
bool isThinkingSupport() const;
bool isCompressing() const;
public slots:
void sendMessage(const QString &message);
void copyToClipboard(const QString &text);
void cancelRequest();
void clearAttachmentFiles();
void clearLinkedFiles();
void clearMessages();
signals:
void chatModelChanged();
@@ -191,6 +217,16 @@ signals:
void availableConfigurationsChanged();
void currentConfigurationChanged();
void availableAgentRolesChanged();
void currentAgentRoleChanged();
void baseSystemPromptChanged();
void isCompressingChanged();
void compressionCompleted(const QString &compressedChatPath);
void compressionFailed(const QString &error);
void openFilesChanged();
private:
void updateFileEditStatus(const QString &editId, const QString &status);
QString getChatsHistoryDir() const;
@@ -223,6 +259,11 @@ private:
QStringList m_availableConfigurations;
QString m_currentConfiguration;
QStringList m_availableAgentRoles;
QString m_currentAgentRole;
ChatCompressor *m_chatCompressor;
};
} // namespace QodeAssist::Chat

View File

@@ -38,14 +38,6 @@ SerializationResult ChatSerializer::saveToFile(const ChatModel *model, const QSt
return {false, "Failed to create directory structure"};
}
QString contentFolder = getChatContentFolder(filePath);
QDir dir;
if (!dir.exists(contentFolder)) {
if (!dir.mkpath(contentFolder)) {
LOG_MESSAGE(QString("Warning: Failed to create content folder: %1").arg(contentFolder));
}
}
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
return {false, QString("Failed to open file for writing: %1").arg(filePath)};
@@ -88,7 +80,8 @@ SerializationResult ChatSerializer::loadFromFile(ChatModel *model, const QString
return {true, QString()};
}
QJsonObject ChatSerializer::serializeMessage(const ChatModel::Message &message, const QString &chatFilePath)
QJsonObject ChatSerializer::serializeMessage(
const ChatModel::Message &message, const QString &chatFilePath)
{
QJsonObject messageObj;
messageObj["role"] = static_cast<int>(message.role);
@@ -129,7 +122,8 @@ QJsonObject ChatSerializer::serializeMessage(const ChatModel::Message &message,
return messageObj;
}
ChatModel::Message ChatSerializer::deserializeMessage(const QJsonObject &json, const QString &chatFilePath)
ChatModel::Message ChatSerializer::deserializeMessage(
const QJsonObject &json, const QString &chatFilePath)
{
ChatModel::Message message;
message.role = static_cast<ChatModel::ChatRole>(json["role"].toInt());
@@ -178,7 +172,8 @@ QJsonObject ChatSerializer::serializeChat(const ChatModel *model, const QString
return root;
}
bool ChatSerializer::deserializeChat(ChatModel *model, const QJsonObject &json, const QString &chatFilePath)
bool ChatSerializer::deserializeChat(
ChatModel *model, const QJsonObject &json, const QString &chatFilePath)
{
QJsonArray messagesArray = json["messages"].toArray();
QVector<ChatModel::Message> messages;
@@ -193,7 +188,14 @@ bool ChatSerializer::deserializeChat(ChatModel *model, const QJsonObject &json,
model->setLoadingFromHistory(true);
for (const auto &message : messages) {
model->addMessage(message.content, message.role, message.id, message.attachments, message.images, message.isRedacted, message.signature);
model->addMessage(
message.content,
message.role,
message.id,
message.attachments,
message.images,
message.isRedacted,
message.signature);
LOG_MESSAGE(QString("Loaded message with %1 image(s), isRedacted=%2, signature length=%3")
.arg(message.images.size())
.arg(message.isRedacted)
@@ -219,7 +221,9 @@ bool ChatSerializer::validateVersion(const QString &version)
}
if (version == "0.1") {
LOG_MESSAGE("Loading chat from old format 0.1 - images folder structure has changed from _images to _content");
LOG_MESSAGE(
"Loading chat from old format 0.1 - images folder structure has changed from _images "
"to _content");
return true;
}
@@ -234,10 +238,11 @@ QString ChatSerializer::getChatContentFolder(const QString &chatFilePath)
return QDir(dirPath).filePath(baseName + "_content");
}
bool ChatSerializer::saveContentToStorage(const QString &chatFilePath,
const QString &fileName,
const QString &base64Data,
QString &storedPath)
bool ChatSerializer::saveContentToStorage(
const QString &chatFilePath,
const QString &fileName,
const QString &base64Data,
QString &storedPath)
{
QString contentFolder = getChatContentFolder(chatFilePath);
QDir dir;
@@ -252,9 +257,9 @@ bool ChatSerializer::saveContentToStorage(const QString &chatFilePath,
QString extension = originalFileInfo.suffix();
QString baseName = originalFileInfo.completeBaseName();
QString uniqueName = QString("%1_%2.%3")
.arg(baseName)
.arg(QUuid::createUuid().toString(QUuid::WithoutBraces).left(8))
.arg(extension);
.arg(baseName)
.arg(QUuid::createUuid().toString(QUuid::WithoutBraces).left(8))
.arg(extension);
QString fullPath = QDir(contentFolder).filePath(uniqueName);

View File

@@ -160,6 +160,13 @@ void ClientInterface::sendMessage(
if (chatAssistantSettings.useSystemPrompt()) {
QString systemPrompt = chatAssistantSettings.systemPrompt();
const QString lastRoleId = chatAssistantSettings.lastUsedRoleId();
if (!lastRoleId.isEmpty()) {
const Settings::AgentRole role = Settings::AgentRolesManager::loadRole(lastRoleId);
if (!role.id.isEmpty())
systemPrompt = systemPrompt + "\n\n" + role.systemPrompt;
}
auto project = LLMCore::RulesLoader::getActiveProject();
if (project) {
@@ -318,12 +325,23 @@ void ClientInterface::sendMessage(
Qt::UniqueConnection);
provider->sendRequest(requestId, config.url, config.providerRequest);
if (provider->supportsTools() && provider->toolsManager()) {
provider->toolsManager()->setCurrentSessionId(m_chatFilePath);
}
}
void ClientInterface::clearMessages()
{
const auto providerName = Settings::generalSettings().caProvider();
auto *provider = LLMCore::ProvidersManager::instance().getProviderByName(providerName);
if (provider && !m_chatFilePath.isEmpty() && provider->supportsTools()
&& provider->toolsManager()) {
provider->toolsManager()->clearTodoSession(m_chatFilePath);
}
m_chatModel->clear();
LOG_MESSAGE("Chat history cleared");
}
void ClientInterface::cancelRequest()
@@ -596,6 +614,15 @@ QVector<LLMCore::ImageAttachment> ClientInterface::loadImagesFromStorage(
void ClientInterface::setChatFilePath(const QString &filePath)
{
if (!m_chatFilePath.isEmpty() && m_chatFilePath != filePath) {
const auto providerName = Settings::generalSettings().caProvider();
auto *provider = LLMCore::ProvidersManager::instance().getProviderByName(providerName);
if (provider && provider->supportsTools() && provider->toolsManager()) {
provider->toolsManager()->clearTodoSession(m_chatFilePath);
}
}
m_chatFilePath = filePath;
m_chatModel->setChatFilePath(filePath);
}

View File

@@ -0,0 +1,442 @@
/*
* Copyright (C) 2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "FileMentionItem.hpp"
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
#include <coreplugin/editormanager/documentmodel.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectmanager.h>
namespace QodeAssist::Chat {
FileMentionItem::FileMentionItem(QQuickItem *parent)
: QQuickItem(parent)
{}
QVariantList FileMentionItem::searchResults() const
{
return m_searchResults;
}
int FileMentionItem::currentIndex() const
{
return m_currentIndex;
}
void FileMentionItem::setCurrentIndex(int index)
{
if (m_currentIndex == index)
return;
m_currentIndex = index;
emit currentIndexChanged();
}
void FileMentionItem::updateSearch(const QString &query)
{
m_lastQuery = query;
QVariantList openFiles = getOpenFiles(query);
QVariantList projectResults = searchProjectFiles(query);
QSet<QString> openPaths;
for (const QVariant &item : std::as_const(openFiles)) {
const QVariantMap map = item.toMap();
openPaths.insert(map.value("absolutePath").toString());
}
QVariantList combined = openFiles;
for (const QVariant &item : std::as_const(projectResults)) {
const QVariantMap map = item.toMap();
if (!map.value("isProject").toBool()
&& openPaths.contains(map.value("absolutePath").toString()))
continue;
combined.append(item);
}
m_searchResults = combined;
m_currentIndex = 0;
emit searchResultsChanged();
emit currentIndexChanged();
}
void FileMentionItem::refreshSearch()
{
if (!m_lastQuery.isNull())
updateSearch(m_lastQuery);
}
void FileMentionItem::moveUp()
{
if (m_currentIndex > 0) {
m_currentIndex--;
emit currentIndexChanged();
}
}
void FileMentionItem::moveDown()
{
if (m_currentIndex < m_searchResults.size() - 1) {
m_currentIndex++;
emit currentIndexChanged();
}
}
void FileMentionItem::selectCurrent()
{
if (m_currentIndex < 0 || m_currentIndex >= m_searchResults.size())
return;
const QVariantMap item = m_searchResults[m_currentIndex].toMap();
if (item.value("isProject").toBool()) {
emit projectSelected(item.value("projectName").toString());
} else {
emit fileSelected(
item.value("absolutePath").toString(),
item.value("relativePath").toString(),
item.value("projectName").toString());
}
}
void FileMentionItem::dismiss()
{
m_searchResults.clear();
m_currentIndex = 0;
emit searchResultsChanged();
emit currentIndexChanged();
emit dismissed();
}
QVariantMap FileMentionItem::applyCurrentSelection(
const QString &text, int cursorPosition, bool useTools)
{
if (m_currentIndex < 0 || m_currentIndex >= m_searchResults.size()) {
dismiss();
return {};
}
const QString textBefore = text.left(cursorPosition);
const int atIndex = textBefore.lastIndexOf('@');
if (atIndex < 0) {
dismiss();
return {};
}
const QVariantMap item = m_searchResults[m_currentIndex].toMap();
QString replacement;
if (item.value("isProject").toBool()) {
replacement = QStringLiteral("@") + item.value("projectName").toString() + ":";
} else {
const QString currentQuery = textBefore.mid(atIndex + 1);
const QVariantMap result = handleFileSelection(
item.value("absolutePath").toString(),
item.value("relativePath").toString(),
item.value("projectName").toString(),
currentQuery,
useTools);
if (result.value("mode").toString() == "mention")
replacement = result.value("mentionText").toString();
}
const QString newText = text.left(atIndex) + replacement + text.mid(cursorPosition);
const int newCursorPosition = atIndex + replacement.length();
dismiss();
return {{"text", newText}, {"cursorPosition", newCursorPosition}};
}
QVariantMap FileMentionItem::handleFileSelection(
const QString &absolutePath,
const QString &relativePath,
const QString &projectName,
const QString &currentQuery,
bool useTools)
{
QVariantMap result;
const QString fileName = relativePath.section('/', -1);
QString mentionKey = fileName;
const int colonIdx = currentQuery.indexOf(':');
if (colonIdx > 0) {
const QString projPrefix = currentQuery.left(colonIdx);
if (projPrefix.compare(projectName, Qt::CaseInsensitive) == 0)
mentionKey = projPrefix + ":" + fileName;
}
if (useTools) {
registerMention(mentionKey, absolutePath);
result["mode"] = QStringLiteral("mention");
result["mentionText"] = "@" + mentionKey + " ";
} else {
emit fileAttachRequested({absolutePath});
result["mode"] = QStringLiteral("attach");
}
return result;
}
void FileMentionItem::registerMention(const QString &mentionKey, const QString &absolutePath)
{
m_atMentionMap[mentionKey] = absolutePath;
}
void FileMentionItem::clearMentions()
{
m_atMentionMap.clear();
}
QString FileMentionItem::expandMentions(const QString &text)
{
QString result = text;
for (auto it = m_atMentionMap.constBegin(); it != m_atMentionMap.constEnd(); ++it) {
const QString &mentionKey = it.key();
const QString &absPath = it.value();
const QString displayName = mentionKey.section(':', -1);
const QString escaped = QRegularExpression::escape(mentionKey);
// @key:N-M -> hyperlink + inline code block
const QRegularExpression rangeRe("@" + escaped + ":(\\d+)-(\\d+)(?=\\s|$)");
QRegularExpressionMatchIterator matchIt = rangeRe.globalMatch(result);
QList<QRegularExpressionMatch> matches;
while (matchIt.hasNext())
matches.append(matchIt.next());
for (int i = matches.size() - 1; i >= 0; --i) {
const auto &m = matches[i];
const int startLine = m.captured(1).toInt();
const int endLine = m.captured(2).toInt();
const QString ext = fileExtension(absPath);
const QString snippet = readFileLines(absPath, startLine, endLine);
const QString replacement
= QString("[@%1:%2-%3](file://%4)\n```%5\n%6```")
.arg(displayName)
.arg(startLine)
.arg(endLine)
.arg(absPath, ext, snippet);
result.replace(m.capturedStart(), m.capturedLength(), replacement);
}
// @key -> hyperlink only
const QRegularExpression simpleRe("@" + escaped + "(?=\\s|$)");
result.replace(simpleRe, QString("[@%1](file://%2)").arg(displayName, absPath));
}
return result;
}
QVariantList FileMentionItem::searchProjectFiles(const QString &query)
{
QVariantList results;
struct FileResult
{
QString absolutePath;
QString relativePath;
QString projectName;
int priority;
};
const auto allProjects = ProjectExplorer::ProjectManager::projects();
QString projectFilter;
QString fileQuery = query;
const int colonIdx = query.indexOf(':');
if (colonIdx > 0) {
const QString prefix = query.left(colonIdx);
for (auto project : allProjects) {
if (project && project->displayName().compare(prefix, Qt::CaseInsensitive) == 0) {
projectFilter = project->displayName();
fileQuery = query.mid(colonIdx + 1);
break;
}
}
}
if (projectFilter.isEmpty() && colonIdx < 0) {
const QString lowerQ = query.toLower();
for (auto project : allProjects) {
if (!project)
continue;
const QString name = project->displayName();
if (query.isEmpty() || name.toLower().startsWith(lowerQ)) {
QVariantMap item;
item["absolutePath"] = QString();
item["relativePath"] = name;
item["projectName"] = name;
item["isProject"] = true;
results.append(item);
}
}
}
QList<FileResult> candidates;
const QString lowerFileQuery = fileQuery.toLower();
const bool emptyFileQuery = fileQuery.isEmpty();
for (auto project : allProjects) {
if (!project)
continue;
if (!projectFilter.isEmpty() && project->displayName() != projectFilter)
continue;
const auto projectFiles = project->files(ProjectExplorer::Project::SourceFiles);
const QString projectDir = project->projectDirectory().path();
const QString projectName = project->displayName();
for (const auto &filePath : projectFiles) {
const QString absolutePath = filePath.path();
const QFileInfo fileInfo(absolutePath);
const QString fileName = fileInfo.fileName();
const QString relativePath = QDir(projectDir).relativeFilePath(absolutePath);
const QString lowerFileName = fileName.toLower();
const QString lowerRelativePath = relativePath.toLower();
int priority = -1;
if (emptyFileQuery) {
priority = 3;
} else if (lowerFileName == lowerFileQuery) {
priority = 0;
} else if (lowerFileName.startsWith(lowerFileQuery)) {
priority = 1;
} else if (lowerFileName.contains(lowerFileQuery)) {
priority = 2;
} else if (lowerRelativePath.contains(lowerFileQuery)) {
priority = 3;
}
if (priority >= 0)
candidates.append({absolutePath, relativePath, projectName, priority});
}
}
std::sort(candidates.begin(), candidates.end(), [](const FileResult &a, const FileResult &b) {
if (a.priority != b.priority)
return a.priority < b.priority;
return a.relativePath < b.relativePath;
});
const int maxFiles = qMax(0, 10 - results.size());
const int count = qMin(candidates.size(), maxFiles);
for (int i = 0; i < count; i++) {
QVariantMap item;
item["absolutePath"] = candidates[i].absolutePath;
item["relativePath"] = candidates[i].relativePath;
item["projectName"] = candidates[i].projectName;
item["isProject"] = false;
results.append(item);
}
return results;
}
QVariantList FileMentionItem::getOpenFiles(const QString &query)
{
QVariantList results;
const QString lowerQuery = query.toLower();
const bool emptyQuery = query.isEmpty();
QSet<QString> addedPaths;
auto tryAddDocument = [&](Core::IDocument *document) {
if (!document)
return;
const QString absolutePath = document->filePath().toFSPathString();
if (absolutePath.isEmpty() || addedPaths.contains(absolutePath))
return;
const QFileInfo fileInfo(absolutePath);
const QString fileName = fileInfo.fileName();
if (fileName.isEmpty())
return;
QString relativePath = absolutePath;
QString projectName;
auto project = ProjectExplorer::ProjectManager::projectForFile(document->filePath());
if (project) {
projectName = project->displayName();
relativePath = QDir(project->projectDirectory().path()).relativeFilePath(absolutePath);
}
if (!emptyQuery) {
const QString lowerFileName = fileName.toLower();
const QString lowerRelativePath = relativePath.toLower();
if (!lowerFileName.contains(lowerQuery) && !lowerRelativePath.contains(lowerQuery))
return;
}
addedPaths.insert(absolutePath);
QVariantMap item;
item["absolutePath"] = absolutePath;
item["relativePath"] = relativePath;
item["projectName"] = projectName;
item["isProject"] = false;
item["isOpen"] = true;
results.append(item);
};
if (auto current = Core::EditorManager::currentEditor())
tryAddDocument(current->document());
for (auto editor : Core::EditorManager::visibleEditors())
if (editor)
tryAddDocument(editor->document());
for (auto document : Core::DocumentModel::openedDocuments())
tryAddDocument(document);
return results;
}
QString FileMentionItem::readFileLines(const QString &filePath, int startLine, int endLine)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return {};
QTextStream stream(&file);
QString result;
int lineNum = 1;
while (!stream.atEnd()) {
const QString line = stream.readLine();
if (lineNum >= startLine)
result += line + '\n';
if (lineNum >= endLine)
break;
++lineNum;
}
return result;
}
QString FileMentionItem::fileExtension(const QString &filePath)
{
const int dot = filePath.lastIndexOf('.');
return dot >= 0 ? filePath.mid(dot + 1) : QString();
}
} // namespace QodeAssist::Chat

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QHash>
#include <QQuickItem>
#include <QRegularExpression>
#include <QVariantList>
namespace QodeAssist::Chat {
class FileMentionItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QVariantList searchResults READ searchResults NOTIFY searchResultsChanged FINAL)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL)
QML_ELEMENT
public:
explicit FileMentionItem(QQuickItem *parent = nullptr);
QVariantList searchResults() const;
int currentIndex() const;
void setCurrentIndex(int index);
Q_INVOKABLE void updateSearch(const QString &query);
Q_INVOKABLE void refreshSearch();
Q_INVOKABLE void moveUp();
Q_INVOKABLE void moveDown();
Q_INVOKABLE void selectCurrent();
Q_INVOKABLE void dismiss();
Q_INVOKABLE QVariantMap handleFileSelection(
const QString &absolutePath,
const QString &relativePath,
const QString &projectName,
const QString &currentQuery,
bool useTools);
Q_INVOKABLE QVariantMap applyCurrentSelection(
const QString &text, int cursorPosition, bool useTools);
Q_INVOKABLE void registerMention(const QString &mentionKey, const QString &absolutePath);
Q_INVOKABLE void clearMentions();
Q_INVOKABLE QString expandMentions(const QString &text);
signals:
void searchResultsChanged();
void currentIndexChanged();
void fileSelected(const QString &absolutePath,
const QString &relativePath,
const QString &projectName);
void projectSelected(const QString &projectName);
void dismissed();
void fileAttachRequested(const QStringList &filePaths);
private:
QVariantList searchProjectFiles(const QString &query);
QVariantList getOpenFiles(const QString &query);
QString readFileLines(const QString &filePath, int startLine, int endLine);
static QString fileExtension(const QString &filePath);
QVariantList m_searchResults;
int m_currentIndex = 0;
QString m_lastQuery;
QHash<QString, QString> m_atMentionMap;
};
} // namespace QodeAssist::Chat

View File

@@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<!-- Archive/compress icon: downward arrows pointing to center with horizontal lines -->
<line x1="12" y1="3" x2="12" y2="10" />
<polyline points="9 7 12 10 15 7" />
<line x1="12" y1="21" x2="12" y2="14" />
<polyline points="9 17 12 14 15 17" />
<line x1="4" y1="12" x2="20" y2="12" stroke-width="3" />
</svg>

After

Width:  |  Height:  |  Size: 487 B

View File

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path d="M3 5h18v2H3V5zm0 6h18v2H3v-2zm0 6h12v2H3v-2z"/>
<circle cx="19" cy="17" r="3" fill="none" stroke="currentColor" stroke-width="2"/>
</svg>

After

Width:  |  Height:  |  Size: 233 B

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
* Copyright (C) 2024-2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -26,6 +26,7 @@ import UIControls
import Qt.labs.platform as Platform
import "./chatparts"
import "./controls"
ChatRootView {
id: root
@@ -87,9 +88,12 @@ ChatRootView {
Layout.preferredWidth: parent.width
Layout.preferredHeight: childrenRect.height + 10
isCompressing: root.isCompressing
saveButton.onClicked: root.showSaveDialog()
loadButton.onClicked: root.showLoadDialog()
clearButton.onClicked: root.clearChat()
compressButton.onClicked: compressConfirmDialog.open()
cancelCompressButton.onClicked: root.cancelCompression()
tokensBadge {
text: qsTr("%1/%2").arg(root.inputTokensCount).arg(root.chatModel.tokensThreshold)
}
@@ -97,8 +101,7 @@ ChatRootView {
text: qsTr("Сhat name: %1").arg(root.chatFileName.length > 0 ? root.chatFileName : "Unsaved")
}
openChatHistory.onClicked: root.openChatHistoryFolder()
rulesButton.onClicked: rulesViewer.open()
activeRulesCount: root.activeRulesCount
contextButton.onClicked: contextViewer.open()
pinButton {
visible: typeof _chatview !== 'undefined'
checked: typeof _chatview !== 'undefined' ? _chatview.isPin : false
@@ -131,12 +134,24 @@ ChatRootView {
root.loadAvailableConfigurations()
}
}
roleSelector {
model: root.availableAgentRoles
displayText: root.currentAgentRole
onActivated: function(index) {
root.applyAgentRole(root.availableAgentRoles[index])
}
popup.onAboutToShow: {
root.loadAvailableAgentRoles()
}
}
}
ListView {
id: chatListView
signal hideServiceComponents(int itemIndex)
property bool userScrolledUp: false
Layout.fillWidth: true
Layout.fillHeight: true
@@ -147,6 +162,18 @@ ChatRootView {
boundsBehavior: Flickable.StopAtBounds
cacheBuffer: 2000
onMovingChanged: {
if (moving) {
userScrolledUp = !atYEnd
}
}
onAtYEndChanged: {
if (atYEnd) {
userScrolledUp = false
}
}
delegate: Loader {
id: componentLoader
@@ -167,11 +194,6 @@ ChatRootView {
}
}
onLoaded: {
if (componentLoader.sourceComponent == chatItemComponent) {
chatListView.hideServiceComponents(index)
}
}
}
header: Item {
@@ -183,12 +205,53 @@ ChatRootView {
id: scroll
}
Rectangle {
id: scrollToBottomButton
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
bottomMargin: 10
}
width: 36
height: 36
radius: 18
color: palette.button
border.color: palette.mid
border.width: 1
visible: chatListView.userScrolledUp
opacity: 0.9
z: 100
Text {
anchors.centerIn: parent
text: "▼"
font.pixelSize: 14
color: palette.buttonText
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
chatListView.userScrolledUp = false
root.scrollToBottom()
}
}
Behavior on visible {
enabled: false
}
}
onCountChanged: {
root.scrollToBottom()
if (!userScrolledUp) {
root.scrollToBottom()
}
}
onContentHeightChanged: {
if (atYEnd) {
if (!userScrolledUp && atYEnd) {
root.scrollToBottom()
}
}
@@ -217,6 +280,10 @@ ChatRootView {
messageInput.cursorPosition = model.content.length
root.chatModel.resetModelTo(idx)
}
onOpenFileRequested: function(filePath) {
root.openFileInEditor(filePath)
}
}
}
@@ -224,19 +291,8 @@ ChatRootView {
id: toolMessageComponent
ToolBlock {
id: toolsItem
width: parent.width
toolContent: model.content
Connections {
target: chatListView
function onHideServiceComponents(itemIndex) {
if (index !== itemIndex) {
toolsItem.headerOpacity = 0.5
}
}
}
}
}
@@ -269,8 +325,6 @@ ChatRootView {
id: thinkingMessageComponent
ThinkingBlock {
id: thinking
width: parent.width
thinkingContent: {
let content = model.content
@@ -281,15 +335,6 @@ ChatRootView {
return content
}
isRedacted: model.isRedacted !== undefined ? model.isRedacted : false
Connections {
target: chatListView
function onHideServiceComponents(itemIndex) {
if (index !== itemIndex) {
thinking.headerOpacity = 0.5
}
}
}
}
}
}
@@ -327,7 +372,38 @@ ChatRootView {
}
}
onTextChanged: root.calculateMessageTokensCount(messageInput.text)
onTextChanged: {
root.calculateMessageTokensCount(messageInput.text)
var cursorPos = messageInput.cursorPosition
var textBefore = messageInput.text.substring(0, cursorPos)
var atIndex = textBefore.lastIndexOf('@')
if (atIndex >= 0) {
var query = textBefore.substring(atIndex + 1)
if (query.indexOf(' ') === -1 && query.indexOf('\n') === -1) {
fileMentionPopup.updateSearch(query)
return
}
}
fileMentionPopup.dismiss()
}
Keys.onPressed: function(event) {
if (fileMentionPopup.visible) {
if (event.key === Qt.Key_Down) {
fileMentionPopup.moveDown()
event.accepted = true
} else if (event.key === Qt.Key_Up) {
fileMentionPopup.moveUp()
event.accepted = true
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
root.applyMentionSelection()
event.accepted = true
} else if (event.key === Qt.Key_Escape) {
fileMentionPopup.dismiss()
event.accepted = true
}
}
}
MouseArea {
anchors.fill: parent
@@ -438,15 +514,12 @@ ChatRootView {
sequences: ["Ctrl+Return", "Ctrl+Enter"]
context: Qt.WindowShortcut
onActivated: {
if (messageInput.activeFocus && !Qt.inputMethod.visible) {
root.sendChatMessage()
}
}
enabled: messageInput.activeFocus && !Qt.inputMethod.visible && !fileMentionPopup.visible
onActivated: root.sendChatMessage()
}
function clearChat() {
root.chatModel.clear()
root.clearMessages()
root.clearAttachmentFiles()
root.updateInputTokensCount()
}
@@ -455,12 +528,38 @@ ChatRootView {
Qt.callLater(chatListView.positionViewAtEnd)
}
function applyMentionSelection() {
var result = fileMentionPopup.applyCurrentSelection(
messageInput.text, messageInput.cursorPosition, root.useTools)
if (result.text !== undefined) {
messageInput.text = result.text
messageInput.cursorPosition = result.cursorPosition
}
}
function sendChatMessage() {
root.sendMessage(messageInput.text)
root.sendMessage(fileMentionPopup.expandMentions(messageInput.text))
messageInput.text = ""
fileMentionPopup.clearMentions()
scrollToBottom()
}
Dialog {
id: compressConfirmDialog
anchors.centerIn: parent
title: qsTr("Compress Chat")
modal: true
standardButtons: Dialog.Yes | Dialog.No
Label {
text: qsTr("Create a summarized copy of this chat?\n\nThe summary will be generated by LLM and saved as a new chat file.")
wrapMode: Text.WordWrap
}
onAccepted: root.compressCurrentChat()
}
Toast {
id: errorToast
z: 1000
@@ -479,19 +578,28 @@ ChatRootView {
toastTextColor: "#FFFFFF"
}
RulesViewer {
id: rulesViewer
ContextViewer {
id: contextViewer
width: parent.width * 0.8
height: parent.height * 0.8
width: Math.min(parent.width * 0.85, 800)
height: Math.min(parent.height * 0.85, 700)
x: (parent.width - width) / 2
y: (parent.height - height) / 2
baseSystemPrompt: root.baseSystemPrompt
currentAgentRole: root.currentAgentRole
currentAgentRoleDescription: root.currentAgentRoleDescription
currentAgentRoleSystemPrompt: root.currentAgentRoleSystemPrompt
activeRules: root.activeRules
ruleContentAreaText: root.getRuleContent(rulesViewer.rulesCurrentIndex)
activeRulesCount: root.activeRulesCount
onRefreshRules: root.refreshRules()
onOpenSettings: root.openSettings()
onOpenAgentRolesSettings: root.openAgentRolesSettings()
onOpenRulesFolder: root.openRulesFolder()
onRefreshRules: root.refreshRules()
onRuleSelected: function(index) {
contextViewer.selectedRuleContent = root.getRuleContent(index)
}
}
Connections {
@@ -506,6 +614,26 @@ ChatRootView {
infoToast.show(root.lastInfoMessage)
}
}
function onOpenFilesChanged() {
if (fileMentionPopup.visible)
Qt.callLater(fileMentionPopup.refreshSearch)
}
}
FileMentionPopup {
id: fileMentionPopup
z: 999
width: Math.min(480, root.width - 20)
x: Math.max(5, Math.min(view.x + 5, root.width - width - 5))
y: view.y - height - 4
onSelectionRequested: root.applyMentionSelection()
onFileAttachRequested: function(filePaths) {
root.addFilesToAttachList(filePaths)
}
}
Component.onCompleted: {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
* Copyright (C) 2024-2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -51,6 +51,7 @@ Rectangle {
property int messageIndex: -1
signal resetChatToMessage(int index)
signal openFileRequested(string filePath)
height: msgColumn.implicitHeight + 10
radius: 8
@@ -180,9 +181,12 @@ Rectangle {
onClicked: function() {
root.resetChatToMessage(root.messageIndex)
}
ToolTip.visible: hovered
ToolTip.text: qsTr("Reset chat to this message and edit")
ToolTip.delay: 500
QoAToolTip {
visible: stopButtonId.hovered
text: qsTr("Reset chat to this message and edit")
delay: 500
}
}
component TextComponent : TextBlock {
@@ -204,6 +208,15 @@ Rectangle {
}
}
onLinkActivated: function(link) {
if (link.startsWith("file://")) {
var filePath = link.replace(/^file:\/\//, "")
root.openFileRequested(filePath)
} else {
Qt.openUrlExternally(link)
}
}
ChatUtils {
id: utils
}
@@ -257,33 +270,21 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
acceptedButtons: Qt.LeftButton
cursorShape: Qt.PointingHandCursor
onClicked: (mouse) => {
if (mouse.button === Qt.LeftButton) {
if (mouse.modifiers & Qt.ShiftModifier) {
fileItem.openFileInExternalEditor()
} else {
fileItem.openFileInEditor()
} else if (mouse.button === Qt.RightButton) {
attachmentContextMenu.popup()
}
}
ToolTip.visible: containsMouse
ToolTip.text: qsTr("Left click: Open in Qt Creator\nRight click: More options")
ToolTip.delay: 500
}
Menu {
id: attachmentContextMenu
MenuItem {
text: qsTr("Open in Qt Creator")
onTriggered: fileItem.openFileInEditor()
}
MenuItem {
text: qsTr("Open in System Editor")
onTriggered: fileItem.openFileInExternalEditor()
QoAToolTip {
visible: attachFileMouseArea.containsMouse
text: qsTr("Click: Open in Qt Creator\nShift+Click: Open in System Editor")
delay: 500
}
}
}
@@ -305,7 +306,7 @@ Rectangle {
FileItem {
id: imageFileItem
filePath: itemData.imageUrl ? itemData.imageUrl.toString().replace("file://", "") : ""
filePath: itemData.filePath || ""
}
ColumnLayout {
@@ -361,33 +362,21 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
acceptedButtons: Qt.LeftButton
cursorShape: Qt.PointingHandCursor
onClicked: (mouse) => {
if (mouse.button === Qt.LeftButton) {
if (mouse.modifiers & Qt.ShiftModifier) {
imageFileItem.openFileInExternalEditor()
} else {
imageFileItem.openFileInEditor()
} else if (mouse.button === Qt.RightButton) {
imageContextMenu.popup()
}
}
ToolTip.visible: containsMouse
ToolTip.text: qsTr("Left click: Open in System\nRight click: More options")
ToolTip.delay: 500
}
Menu {
id: imageContextMenu
MenuItem {
text: qsTr("Open in Qt Creator")
onTriggered: imageFileItem.openFileInEditor()
}
MenuItem {
text: qsTr("Open in System Viewer")
onTriggered: imageFileItem.openFileInExternalEditor()
QoAToolTip {
visible: imageMouseArea.containsMouse
text: qsTr("Click: Open in Qt Creator\nShift+Click: Open in System Editor")
delay: 500
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
* Copyright (C) 2024-2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -29,8 +29,6 @@ TextEdit {
selectionColor: palette.highlight
color: palette.text
onLinkActivated: (link) => Qt.openUrlExternally(link)
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
* Copyright (C) 2024-2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -21,6 +21,7 @@ import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import ChatView
import UIControls
Flow {
id: root
@@ -78,9 +79,11 @@ Flow {
}
}
ToolTip.visible: containsMouse
ToolTip.delay: 500
ToolTip.text: "Click: Open in Qt Creator\nShift+Click: Open in external editor\nCtrl+Click / Middle Click: Remove"
QoAToolTip {
visible: mouse.containsMouse
delay: 500
text: "Click: Open in Qt Creator\nShift+Click: Open in external editor\nCtrl+Click / Middle Click: Remove"
}
}
Menu {

View File

@@ -0,0 +1,558 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Basic as QQC
import UIControls
import ChatView
Popup {
id: root
property string baseSystemPrompt
property string currentAgentRole
property string currentAgentRoleDescription
property string currentAgentRoleSystemPrompt
property var activeRules
property int activeRulesCount
property string selectedRuleContent
signal openSettings()
signal openAgentRolesSettings()
signal openRulesFolder()
signal refreshRules()
signal ruleSelected(int index)
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
background: Rectangle {
color: palette.window
border.color: palette.mid
border.width: 1
radius: 4
}
ChatUtils {
id: utils
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 8
RowLayout {
Layout.fillWidth: true
spacing: 10
Text {
text: qsTr("Chat Context")
font.pixelSize: 16
font.bold: true
color: palette.text
Layout.fillWidth: true
}
QoAButton {
text: qsTr("Refresh")
onClicked: root.refreshRules()
}
QoAButton {
text: qsTr("Close")
onClicked: root.close()
}
}
Rectangle {
Layout.fillWidth: true
height: 1
color: palette.mid
}
Flickable {
id: mainFlickable
Layout.fillWidth: true
Layout.fillHeight: true
contentHeight: sectionsColumn.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
ColumnLayout {
id: sectionsColumn
width: mainFlickable.width
spacing: 8
CollapsibleSection {
id: systemPromptSection
Layout.fillWidth: true
title: qsTr("Base System Prompt")
badge: root.baseSystemPrompt.length > 0 ? qsTr("Active") : qsTr("Empty")
badgeColor: root.baseSystemPrompt.length > 0 ? Qt.rgba(0.2, 0.6, 0.3, 1.0) : palette.mid
sectionContent: ColumnLayout {
spacing: 5
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: Math.min(Math.max(systemPromptText.implicitHeight + 16, 50), 200)
color: palette.base
border.color: palette.mid
border.width: 1
radius: 2
Flickable {
id: systemPromptFlickable
anchors.fill: parent
anchors.margins: 8
contentHeight: systemPromptText.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
TextEdit {
id: systemPromptText
width: systemPromptFlickable.width
text: root.baseSystemPrompt.length > 0 ? root.baseSystemPrompt : qsTr("No system prompt configured")
readOnly: true
selectByMouse: true
wrapMode: Text.WordWrap
color: root.baseSystemPrompt.length > 0 ? palette.text : palette.mid
font.family: "monospace"
font.pixelSize: 11
}
QQC.ScrollBar.vertical: QQC.ScrollBar {
policy: systemPromptFlickable.contentHeight > systemPromptFlickable.height ? QQC.ScrollBar.AsNeeded : QQC.ScrollBar.AlwaysOff
}
}
}
RowLayout {
Layout.fillWidth: true
Item { Layout.fillWidth: true }
QoAButton {
text: qsTr("Copy")
enabled: root.baseSystemPrompt.length > 0
onClicked: utils.copyToClipboard(root.baseSystemPrompt)
}
QoAButton {
text: qsTr("Edit in Settings")
onClicked: {
root.openSettings()
root.close()
}
}
}
}
}
CollapsibleSection {
id: agentRoleSection
Layout.fillWidth: true
title: qsTr("Agent Role")
badge: root.currentAgentRole
badgeColor: root.currentAgentRoleSystemPrompt.length > 0 ? Qt.rgba(0.3, 0.4, 0.7, 1.0) : palette.mid
sectionContent: ColumnLayout {
spacing: 8
Text {
text: root.currentAgentRoleDescription
font.pixelSize: 11
font.italic: true
color: palette.mid
wrapMode: Text.WordWrap
Layout.fillWidth: true
visible: root.currentAgentRoleDescription.length > 0
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: Math.min(Math.max(agentPromptText.implicitHeight + 16, 50), 200)
color: palette.base
border.color: palette.mid
border.width: 1
radius: 2
visible: root.currentAgentRoleSystemPrompt.length > 0
Flickable {
id: agentPromptFlickable
anchors.fill: parent
anchors.margins: 8
contentHeight: agentPromptText.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
TextEdit {
id: agentPromptText
width: agentPromptFlickable.width
text: root.currentAgentRoleSystemPrompt
readOnly: true
selectByMouse: true
wrapMode: Text.WordWrap
color: palette.text
font.family: "monospace"
font.pixelSize: 11
}
QQC.ScrollBar.vertical: QQC.ScrollBar {
policy: agentPromptFlickable.contentHeight > agentPromptFlickable.height ? QQC.ScrollBar.AsNeeded : QQC.ScrollBar.AlwaysOff
}
}
}
Text {
text: qsTr("No role selected. Using base system prompt only.")
font.pixelSize: 11
color: palette.mid
wrapMode: Text.WordWrap
Layout.fillWidth: true
visible: root.currentAgentRoleSystemPrompt.length === 0
}
RowLayout {
Layout.fillWidth: true
Item { Layout.fillWidth: true }
QoAButton {
text: qsTr("Copy")
enabled: root.currentAgentRoleSystemPrompt.length > 0
onClicked: utils.copyToClipboard(root.currentAgentRoleSystemPrompt)
}
QoAButton {
text: qsTr("Manage Roles")
onClicked: {
root.openAgentRolesSettings()
root.close()
}
}
}
}
}
CollapsibleSection {
id: projectRulesSection
Layout.fillWidth: true
title: qsTr("Project Rules")
badge: root.activeRulesCount > 0 ? qsTr("%1 active").arg(root.activeRulesCount) : qsTr("None")
badgeColor: root.activeRulesCount > 0 ? Qt.rgba(0.6, 0.5, 0.2, 1.0) : palette.mid
sectionContent: ColumnLayout {
spacing: 8
SplitView {
Layout.fillWidth: true
Layout.preferredHeight: 220
orientation: Qt.Horizontal
visible: root.activeRulesCount > 0
Rectangle {
SplitView.minimumWidth: 120
SplitView.preferredWidth: 180
color: palette.base
border.color: palette.mid
border.width: 1
radius: 2
ColumnLayout {
anchors.fill: parent
anchors.margins: 5
spacing: 5
Text {
text: qsTr("Rules (%1)").arg(rulesList.count)
font.pixelSize: 11
font.bold: true
color: palette.text
Layout.fillWidth: true
}
ListView {
id: rulesList
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
model: root.activeRules
currentIndex: 0
boundsBehavior: Flickable.StopAtBounds
delegate: ItemDelegate {
required property var modelData
required property int index
width: ListView.view.width
height: ruleItemContent.implicitHeight + 8
highlighted: ListView.isCurrentItem
background: Rectangle {
color: {
if (parent.highlighted)
return palette.highlight
if (parent.hovered)
return Qt.tint(palette.base, Qt.rgba(0, 0, 0, 0.05))
return "transparent"
}
radius: 2
}
contentItem: ColumnLayout {
id: ruleItemContent
spacing: 2
Text {
text: modelData.fileName
font.pixelSize: 10
color: parent.parent.highlighted ? palette.highlightedText : palette.text
elide: Text.ElideMiddle
Layout.fillWidth: true
}
Text {
text: modelData.category
font.pixelSize: 9
color: parent.parent.highlighted ? palette.highlightedText : palette.mid
Layout.fillWidth: true
}
}
onClicked: {
rulesList.currentIndex = index
root.ruleSelected(index)
}
}
QQC.ScrollBar.vertical: QQC.ScrollBar {
policy: rulesList.contentHeight > rulesList.height ? QQC.ScrollBar.AsNeeded : QQC.ScrollBar.AlwaysOff
}
}
}
}
Rectangle {
SplitView.fillWidth: true
SplitView.minimumWidth: 200
color: palette.base
border.color: palette.mid
border.width: 1
radius: 2
ColumnLayout {
anchors.fill: parent
anchors.margins: 5
spacing: 5
RowLayout {
Layout.fillWidth: true
spacing: 5
Text {
text: qsTr("Content")
font.pixelSize: 11
font.bold: true
color: palette.text
Layout.fillWidth: true
}
QoAButton {
text: qsTr("Copy")
enabled: root.selectedRuleContent.length > 0
onClicked: utils.copyToClipboard(root.selectedRuleContent)
}
}
Flickable {
id: ruleContentFlickable
Layout.fillWidth: true
Layout.fillHeight: true
contentHeight: ruleContentArea.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
TextEdit {
id: ruleContentArea
width: ruleContentFlickable.width
text: root.selectedRuleContent
readOnly: true
selectByMouse: true
wrapMode: Text.WordWrap
selectionColor: palette.highlight
color: palette.text
font.family: "monospace"
font.pixelSize: 11
}
QQC.ScrollBar.vertical: QQC.ScrollBar {
policy: ruleContentFlickable.contentHeight > ruleContentFlickable.height ? QQC.ScrollBar.AsNeeded : QQC.ScrollBar.AlwaysOff
}
}
}
}
}
Text {
text: qsTr("No project rules found.\nCreate .md files in .qodeassist/rules/common/ or .qodeassist/rules/chat/")
font.pixelSize: 11
color: palette.mid
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
visible: root.activeRulesCount === 0
}
RowLayout {
Layout.fillWidth: true
Item { Layout.fillWidth: true }
QoAButton {
text: qsTr("Open Rules Folder")
onClicked: root.openRulesFolder()
}
}
}
}
}
QQC.ScrollBar.vertical: QQC.ScrollBar {
policy: mainFlickable.contentHeight > mainFlickable.height ? QQC.ScrollBar.AsNeeded : QQC.ScrollBar.AlwaysOff
}
}
Rectangle {
Layout.fillWidth: true
height: 1
color: palette.mid
}
Text {
text: qsTr("Final prompt: Base System Prompt + Agent Role + Project Info + Project Rules + Linked Files")
font.pixelSize: 9
color: palette.mid
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
component CollapsibleSection: ColumnLayout {
id: sectionRoot
property string title
property string badge
property color badgeColor: palette.mid
property Component sectionContent: null
property bool expanded: false
spacing: 0
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 32
color: sectionMouseArea.containsMouse ? Qt.tint(palette.button, Qt.rgba(0, 0, 0, 0.05)) : palette.button
border.color: palette.mid
border.width: 1
radius: 2
MouseArea {
id: sectionMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: sectionRoot.expanded = !sectionRoot.expanded
}
RowLayout {
anchors.fill: parent
anchors.leftMargin: 8
anchors.rightMargin: 8
spacing: 8
Text {
text: sectionRoot.expanded ? "▼" : "▶"
font.pixelSize: 10
color: palette.text
}
Text {
text: sectionRoot.title
font.pixelSize: 12
font.bold: true
color: palette.text
Layout.fillWidth: true
}
Rectangle {
implicitWidth: badgeText.implicitWidth + 12
implicitHeight: 18
color: sectionRoot.badgeColor
radius: 3
Text {
id: badgeText
anchors.centerIn: parent
text: sectionRoot.badge
font.pixelSize: 10
color: "#FFFFFF"
}
}
}
}
Loader {
id: contentLoader
Layout.fillWidth: true
Layout.leftMargin: 12
Layout.topMargin: 8
Layout.bottomMargin: 4
sourceComponent: sectionRoot.sectionContent
visible: sectionRoot.expanded
active: sectionRoot.expanded
}
}
onOpened: {
if (root.activeRulesCount > 0) {
root.ruleSelected(0)
}
}
}

View File

@@ -0,0 +1,167 @@
/*
* Copyright (C) 2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
FileMentionItem {
id: root
signal selectionRequested()
visible: searchResults.length > 0
height: Math.min(searchResults.length * 36, 36 * 6) + 2
onCurrentIndexChanged: {
listView.positionViewAtIndex(root.currentIndex, ListView.Contain)
}
Rectangle {
id: background
anchors.fill: parent
color: palette.window
border.color: palette.mid
border.width: 1
radius: 4
}
ListView {
id: listView
anchors.fill: parent
anchors.margins: 1
model: root.searchResults
currentIndex: root.currentIndex
clip: true
ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AsNeeded
}
delegate: Rectangle {
id: delegateItem
required property int index
required property var modelData
readonly property bool isProject: modelData.isProject === true
readonly property bool isOpen: modelData.isOpen === true
readonly property string fileName: {
if (isProject)
return modelData.projectName
const parts = modelData.relativePath.split('/')
return parts[parts.length - 1]
}
width: listView.width
height: 36
color: index === root.currentIndex
? palette.highlight
: (hoverArea.containsMouse
? Qt.rgba(palette.highlight.r, palette.highlight.g, palette.highlight.b, 0.25)
: "transparent")
RowLayout {
anchors.fill: parent
anchors.leftMargin: 10
anchors.rightMargin: 10
spacing: 8
Item {
Layout.preferredWidth: 18
Layout.preferredHeight: 18
Rectangle {
anchors.fill: parent
radius: 3
visible: delegateItem.isProject || delegateItem.isOpen
color: {
if (delegateItem.index === root.currentIndex)
return Qt.rgba(palette.highlightedText.r,
palette.highlightedText.g,
palette.highlightedText.b, 0.2)
if (delegateItem.isProject)
return Qt.rgba(palette.highlight.r,
palette.highlight.g,
palette.highlight.b, 0.3)
return Qt.rgba(0.2, 0.7, 0.4, 0.3)
}
Text {
anchors.centerIn: parent
text: delegateItem.isProject ? "P" : "O"
font.bold: true
font.pixelSize: 10
color: {
if (delegateItem.index === root.currentIndex)
return palette.highlightedText
if (delegateItem.isProject)
return palette.highlight
return Qt.rgba(0.1, 0.6, 0.3, 1.0)
}
}
}
}
Text {
Layout.preferredWidth: 160
text: delegateItem.fileName
color: delegateItem.index === root.currentIndex
? palette.highlightedText
: (delegateItem.isProject ? palette.highlight : palette.text)
font.bold: true
font.italic: delegateItem.isProject
elide: Text.ElideRight
}
Text {
Layout.fillWidth: true
text: delegateItem.isProject
? "→"
: (delegateItem.modelData.projectName + " / " + delegateItem.modelData.relativePath)
color: delegateItem.index === root.currentIndex
? (delegateItem.isProject
? palette.highlightedText
: Qt.rgba(palette.highlightedText.r,
palette.highlightedText.g,
palette.highlightedText.b, 0.7))
: palette.mid
font.pixelSize: delegateItem.isProject ? 12 : 11
elide: Text.ElideLeft
horizontalAlignment: delegateItem.isProject ? Text.AlignLeft : Text.AlignRight
}
}
MouseArea {
id: hoverArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
root.currentIndex = delegateItem.index
root.selectionRequested()
}
onEntered: root.currentIndex = delegateItem.index
}
}
}
}

View File

@@ -1,251 +0,0 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Basic as QQC
import UIControls
import ChatView
Popup {
id: root
property var activeRules
property alias rulesCurrentIndex: rulesList.currentIndex
property alias ruleContentAreaText: ruleContentArea.text
signal refreshRules()
signal openRulesFolder()
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
background: Rectangle {
color: palette.window
border.color: palette.mid
border.width: 1
radius: 4
}
ChatUtils {
id: utils
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
RowLayout {
Layout.fillWidth: true
spacing: 10
Text {
text: qsTr("Active Project Rules")
font.pixelSize: 16
font.bold: true
color: palette.text
Layout.fillWidth: true
}
QoAButton {
text: qsTr("Open Folder")
onClicked: root.openRulesFolder()
}
QoAButton {
text: qsTr("Refresh")
onClicked: root.refreshRules()
}
QoAButton {
text: qsTr("Close")
onClicked: root.close()
}
}
Rectangle {
Layout.fillWidth: true
height: 1
color: palette.mid
}
SplitView {
Layout.fillWidth: true
Layout.fillHeight: true
orientation: Qt.Horizontal
Rectangle {
SplitView.minimumWidth: 200
SplitView.preferredWidth: parent.width * 0.3
color: palette.base
border.color: palette.mid
border.width: 1
radius: 2
ColumnLayout {
anchors.fill: parent
anchors.margins: 5
spacing: 5
Text {
text: qsTr("Rules Files (%1)").arg(rulesList.count)
font.pixelSize: 12
font.bold: true
color: palette.text
Layout.fillWidth: true
}
ListView {
id: rulesList
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
model: root.activeRules
currentIndex: 0
delegate: ItemDelegate {
required property var modelData
required property int index
width: ListView.view.width
highlighted: ListView.isCurrentItem
background: Rectangle {
color: {
if (parent.highlighted) {
return palette.highlight
} else if (parent.hovered) {
return Qt.tint(palette.base, Qt.rgba(0, 0, 0, 0.05))
}
return "transparent"
}
radius: 2
}
contentItem: ColumnLayout {
spacing: 2
Text {
text: modelData.fileName
font.pixelSize: 11
color: parent.parent.highlighted ? palette.highlightedText : palette.text
elide: Text.ElideMiddle
Layout.fillWidth: true
}
Text {
text: qsTr("Category: %1").arg(modelData.category)
font.pixelSize: 9
color: parent.parent.highlighted ? palette.highlightedText : palette.mid
Layout.fillWidth: true
}
}
onClicked: {
rulesList.currentIndex = index
}
}
ScrollBar.vertical: QQC.ScrollBar {
id: scroll
}
}
Text {
visible: rulesList.count === 0
text: qsTr("No rules found.\nCreate .md files in:\n.qodeassist/rules/common/\n.qodeassist/rules/chat/")
font.pixelSize: 10
color: palette.mid
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
}
}
}
Rectangle {
SplitView.fillWidth: true
color: palette.base
border.color: palette.mid
border.width: 1
radius: 2
ColumnLayout {
anchors.fill: parent
anchors.margins: 5
spacing: 5
RowLayout {
Layout.fillWidth: true
spacing: 5
Text {
text: qsTr("Content")
font.pixelSize: 12
font.bold: true
color: palette.text
Layout.fillWidth: true
}
QoAButton {
text: qsTr("Copy")
enabled: ruleContentArea.text.length > 0
onClicked: utils.copyToClipboard(ruleContentArea.text)
}
}
ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
TextEdit {
id: ruleContentArea
readOnly: true
selectByMouse: true
wrapMode: Text.WordWrap
selectionColor: palette.highlight
color: palette.text
font.family: "monospace"
font.pixelSize: 11
}
}
}
}
}
Text {
text: qsTr("Rules are loaded from .qodeassist/rules/ directory in your project.\n" +
"Common rules apply to all contexts, chat rules apply only to chat assistant.")
font.pixelSize: 9
color: palette.mid
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
}

View File

@@ -29,16 +29,20 @@ Rectangle {
property alias saveButton: saveButtonId
property alias loadButton: loadButtonId
property alias clearButton: clearButtonId
property alias compressButton: compressButtonId
property alias cancelCompressButton: cancelCompressButtonId
property alias tokensBadge: tokensBadgeId
property alias recentPath: recentPathId
property alias openChatHistory: openChatHistoryId
property alias pinButton: pinButtonId
property alias rulesButton: rulesButtonId
property alias contextButton: contextButtonId
property alias toolsButton: toolsButtonId
property alias thinkingMode: thinkingModeId
property alias settingsButton: settingsButtonId
property alias activeRulesCount: activeRulesCountId.text
property alias configSelector: configSelectorId
property alias roleSelector: roleSelector
property bool isCompressing: false
color: palette.window.hslLightness > 0.5 ?
Qt.darker(palette.window, 1.1) :
@@ -87,9 +91,26 @@ Rectangle {
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: qsTr("Switch AI configuration")
ToolTip.text: qsTr("Switch saved AI configuration")
}
QoAComboBox {
id: roleSelector
implicitHeight: 25
model: []
currentIndex: 0
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: qsTr("Switch agent role (different system prompts)")
}
}
Row {
spacing: 10
QoAButton {
id: toolsButtonId
@@ -157,8 +178,13 @@ Rectangle {
ToolTip.delay: 250
ToolTip.text: qsTr("Open Chat Assistant Settings")
}
QoASeparator {
anchors.verticalCenter: parent.verticalCenter
}
}
Item {
height: firstRow.height
width: recentPathId.width
@@ -217,19 +243,6 @@ Rectangle {
ToolTip.text: qsTr("Load chat from *.json file")
}
QoAButton {
id: clearButtonId
icon {
source: "qrc:/qt/qml/ChatView/icons/clean-icon-dark.svg"
height: 15
width: 8
}
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: qsTr("Clean chat")
}
QoAButton {
id: openChatHistoryId
@@ -243,36 +256,70 @@ Rectangle {
ToolTip.text: qsTr("Show in system")
}
QoASeparator {}
QoAButton {
id: rulesButtonId
id: compressButtonId
visible: !root.isCompressing
icon {
source: "qrc:/qt/qml/ChatView/icons/rules-icon.svg"
source: "qrc:/qt/qml/ChatView/icons/compress-icon.svg"
height: 15
width: 15
}
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: qsTr("Compress chat (create summarized copy using LLM)")
}
Row {
id: compressingRow
visible: root.isCompressing
spacing: 6
BusyIndicator {
id: compressBusyIndicator
anchors.verticalCenter: parent.verticalCenter
running: root.isCompressing
width: 16
height: 16
}
Text {
text: qsTr("Compressing...")
height: parent.height
color: palette.text
font.pixelSize: 12
verticalAlignment: Text.AlignVCenter
}
QoAButton {
id: cancelCompressButtonId
text: qsTr("Cancel")
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: qsTr("Cancel compression")
}
}
QoAButton {
id: contextButtonId
icon {
source: "qrc:/qt/qml/ChatView/icons/context-icon.svg"
color: palette.window.hslLightness > 0.5 ? "#000000" : "#FFFFFF"
height: 15
width: 15
}
text: " "
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: root.activeRulesCount > 0
? qsTr("View active project rules (%1)").arg(root.activeRulesCount)
: qsTr("View active project rules (no rules found)")
Text {
id: activeRulesCountId
anchors {
bottom: parent.bottom
bottomMargin: 2
right: parent.right
rightMargin: 4
}
color: palette.text
font.pixelSize: 10
font.bold: true
}
ToolTip.text: qsTr("View chat context (system prompt, role, rules)")
}
Badge {
@@ -282,6 +329,21 @@ Rectangle {
ToolTip.delay: 250
ToolTip.text: qsTr("Current amount tokens in chat and LLM limit threshold")
}
QoASeparator {}
QoAButton {
id: clearButtonId
icon {
source: "qrc:/qt/qml/ChatView/icons/clean-icon-dark.svg"
height: 15
width: 8
}
ToolTip.visible: hovered
ToolTip.delay: 250
ToolTip.text: qsTr("Clean chat")
}
}
}
}

View File

@@ -170,28 +170,26 @@ void ConfigurationManager::selectModel()
: isQuickRefactor ? m_generalSettings.qrUrl.volatileValue()
: m_generalSettings.caUrl.volatileValue();
auto &targetSettings = isCodeCompletion ? m_generalSettings.ccModel
: isPreset1 ? m_generalSettings.ccPreset1Model
: isQuickRefactor ? m_generalSettings.qrModel
: m_generalSettings.caModel;
auto *targetSettings = &(isCodeCompletion ? m_generalSettings.ccModel
: isPreset1 ? m_generalSettings.ccPreset1Model
: isQuickRefactor ? m_generalSettings.qrModel
: m_generalSettings.caModel);
if (auto provider = m_providersManager.getProviderByName(providerName)) {
if (!provider->supportsModelListing()) {
m_generalSettings.showModelsNotSupportedDialog(targetSettings);
m_generalSettings.showModelsNotSupportedDialog(*targetSettings);
return;
}
const auto modelList = provider->getInstalledModels(providerUrl);
if (modelList.isEmpty()) {
m_generalSettings.showModelsNotFoundDialog(targetSettings);
return;
}
QTimer::singleShot(0, &m_generalSettings, [this, modelList, &targetSettings]() {
m_generalSettings.showSelectionDialog(
modelList, targetSettings, Tr::tr("Select LLM Model"), Tr::tr("Models:"));
});
provider->getInstalledModels(providerUrl)
.then(this, [this, targetSettings](const QList<QString> &modelList) {
if (modelList.isEmpty()) {
m_generalSettings.showModelsNotFoundDialog(*targetSettings);
return;
}
m_generalSettings.showSelectionDialog(
modelList, *targetSettings, Tr::tr("Select LLM Model"), Tr::tr("Models:"));
});
}
}

View File

@@ -1,7 +1,7 @@
{
"Id" : "qodeassist",
"Name" : "QodeAssist",
"Version" : "0.9.4",
"Version" : "0.9.11",
"CompatVersion" : "${IDE_VERSION}",
"Vendor" : "Petr Mironychev",
"VendorId" : "petrmironychev",

View File

@@ -125,21 +125,59 @@ For more information, visit the [QodeAssistUpdater repository](https://github.co
## Configuration
QodeAssist supports multiple LLM providers. Choose your preferred provider and follow the configuration guide:
### Quick Setup (Recommended for Beginners)
### Supported Providers
The Quick Setup feature provides one-click configuration for popular cloud AI models. Get started in 3 easy steps:
<details>
<summary>Quick setup: (click to expand)</summary>
<img width="600" alt="Quick Setup" src="https://github.com/user-attachments/assets/20df9155-9095-420c-8387-908bd931bcfa">
</details>
1. **Open QodeAssist Settings**
2. **Select a Preset** - Choose from the Quick Setup dropdown:
- **Anthropic Claude** (Sonnet 4.5, Haiku 4.5, Opus 4.5)
- **OpenAI** (gpt-5.2-codex)
- **Mistral AI** (Codestral 2501)
- **Google AI** (Gemini 2.5 Flash)
3. **Configure API Key** - Click "Configure API Key" button and enter your API key in Provider Settings
All settings (provider, model, template, URL) are configured automatically. Just add your API key and you're ready to go!
### Manual Provider Configuration
For advanced users or local models, choose your preferred provider and follow the detailed configuration guide:
- **[Ollama](docs/ollama-configuration.md)** - Local LLM provider
- **[llama.cpp](docs/llamacpp-configuration.md)** - Local LLM server
- **[Anthropic Claude](docs/claude-configuration.md)** - Сloud provider
- **[OpenAI](docs/openai-configuration.md)** - Сloud provider
- **[Mistral AI](docs/mistral-configuration.md)** - Сloud provider
- **[Google AI](docs/google-ai-configuration.md)** - Сloud provider
- **[Anthropic Claude](docs/claude-configuration.md)** - Cloud provider (manual setup)
- **[OpenAI](docs/openai-configuration.md)** - Cloud provider (includes Responses API support)
- **[Mistral AI](docs/mistral-configuration.md)** - Cloud provider
- **[Google AI](docs/google-ai-configuration.md)** - Cloud provider
- **LM Studio** - Local LLM provider
- **OpenAI-compatible** - Custom providers (OpenRouter, etc.)
### Recommended Models for Best Experience
For optimal coding assistance, we recommend using these top-tier models:
**Best for Code Completion & Refactoring:**
- **Claude 4.5 Haiku or Sonnet** (Anthropic)
- **GPT-5.1-codex or codex-mini** (OpenAI Responses API)
- **Codestral** (Mistral)
**Best for Chat Assistant:**
- **Claude 4.5 Sonnet** (Anthropic) - Outstanding reasoning and natural conversation flow
- **GPT-5.1-codex** (OpenAI Responses API) - Latest model with advanced capabilities
- **Gemini 2.5 or 3.0** (Google AI) - Latest models from Google
- **Mistral large** (Mistral) - Fast and capable
**Local models:**
- **Qwen3-coder** (Qwen) - Best local models
### Additional Configuration
- **[Agent Roles](docs/agent-roles.md)** - Create AI personas with specialized system prompts
- **[Chat Summarization](docs/chat-summarization.md)** - Compress conversations to save context tokens
- **[Project Rules](docs/project-rules.md)** - Customize AI behavior for your project
- **[Ignoring Files](docs/ignoring-files.md)** - Exclude files from context using `.qodeassistignore`
@@ -176,6 +214,8 @@ Configure in: `Tools → Options → QodeAssist → Code Completion → General
- Multiple chat panels: side panel, bottom panel, and popup window
- Chat history with auto-save and restore
- Token usage monitoring
- **[Agent Roles](docs/agent-roles.md)** - Switch between AI personas (Developer, Reviewer, custom roles)
- **[Chat Summarization](docs/chat-summarization.md)** - Compress long conversations into AI-generated summaries
- **[File Context](docs/file-context.md)** - Attach or link files for better context
- Automatic syncing with open editor files (optional)
- Extended thinking mode (Claude, other providers in plan) - Enable deeper reasoning for complex tasks
@@ -260,22 +300,24 @@ QodeAssist uses a flexible prompt composition system that adapts to different co
│ CHAT ASSISTANT │
├─────────────────────────────────────────────────────────────────────────────┤
│ 1. System Prompt (from Chat Assistant Settings) │
│ 2. Project Rules:
│ 2. Agent Role (optional, from role selector):
│ └─ Role-specific system prompt (Developer, Reviewer, custom) │
│ 3. Project Rules: │
│ ├─ .qodeassist/rules/common/*.md │
│ └─ .qodeassist/rules/chat/*.md │
3. File Context (optional): │
4. File Context (optional): │
│ ├─ Attached files (manual) │
│ ├─ Linked files (persistent) │
│ └─ Open editor files (if auto-sync enabled) │
4. Tool Definitions (if enabled): │
5. Tool Definitions (if enabled): │
│ ├─ ReadProjectFileByName │
│ ├─ ListProjectFiles │
│ ├─ SearchInProject │
│ └─ GetIssuesList │
5. Conversation History │
6. User Message │
6. Conversation History │
7. User Message │
│ │
│ Final Prompt: [System: SystemPrompt + Rules + Tools]
│ Final Prompt: [System: SystemPrompt + AgentRole + Rules + Tools] │
│ [History: Previous messages] │
│ [User: FileContext + UserMessage] │
└─────────────────────────────────────────────────────────────────────────────┘
@@ -321,6 +363,7 @@ QodeAssist uses a flexible prompt composition system that adapts to different co
- **Project Rules** are automatically loaded from `.qodeassist/rules/` directory structure
- **System Prompts** are configured independently for each feature in Settings
- **Agent Roles** add role-specific prompts on top of the base system prompt (Chat only)
- **FIM vs Non-FIM models** for code completion use different System Prompts:
- FIM models: Direct completion prompt
- Non-FIM models: Prompt includes response formatting instructions
@@ -328,14 +371,14 @@ QodeAssist uses a flexible prompt composition system that adapts to different co
- **Custom Instructions** provide reusable templates that can be augmented with specific details
- **Tool Calling** is available for Chat and Quick Refactor when enabled
See [Project Rules Documentation](docs/project-rules.md) and [Quick Refactoring Guide](docs/quick-refactoring.md) for more details.
See [Project Rules Documentation](docs/project-rules.md), [Agent Roles Guide](docs/agent-roles.md), and [Quick Refactoring Guide](docs/quick-refactoring.md) for more details.
## QtCreator Version Compatibility
| Qt Creator Version | QodeAssist Version |
|-------------------|-------------------|
| 17.0.0+ | 0.6.0 - 0.x.x |
| 16.0.2 | 0.5.13 - 0.x.x |
| 16.0.2 | 0.5.13 - 0.9.6 |
| 16.0.1 | 0.5.7 - 0.5.13 |
| 16.0.0 | 0.5.2 - 0.5.6 |
| 15.0.1 | 0.4.8 - 0.5.1 |

View File

@@ -13,6 +13,8 @@ qt_add_qml_module(QodeAssistUIControls
qml/QoATextSlider.qml
qml/QoAComboBox.qml
qml/FadeListItemAnimation.qml
qml/QoASeparator.qml
qml/QoAToolTip.qml
RESOURCES
icons/dropdown-arrow-light.svg

View File

@@ -24,9 +24,26 @@ import QtQuick.Controls.Basic as Basic
Basic.ComboBox {
id: control
property real popupContentWidth: 100
implicitWidth: Math.min(contentItem.implicitWidth + 8, 300)
implicitHeight: 30
function updatePopupWidth() {
var maxWidth = 100;
if (model) {
for (var i = 0; i < model.length; i++) {
textMetrics.text = model[i];
maxWidth = Math.max(maxWidth, textMetrics.width + 40);
}
}
popupContentWidth = Math.min(maxWidth, 350);
}
onModelChanged: updatePopupWidth()
Component.onCompleted: updatePopupWidth()
clip: true
indicator: Image {
id: dropdownIcon
@@ -94,7 +111,7 @@ Basic.ComboBox {
popup: Popup {
y: control.height + 2
width: control.width
width: Math.max(control.width, control.popupContentWidth)
implicitHeight: Math.min(contentItem.implicitHeight, 300)
padding: 4
@@ -128,7 +145,7 @@ Basic.ComboBox {
}
delegate: ItemDelegate {
width: control.width - 8
width: control.popup.width - 8
height: 32
contentItem: Text {
@@ -157,5 +174,10 @@ Basic.ComboBox {
}
}
}
TextMetrics {
id: textMetrics
font.pixelSize: 12
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
Rectangle {
id: root
height: 15
width: 1
color: palette.mid
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2026 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick
import QtQuick.Controls
ToolTip {
id: root
padding: 8
contentItem: Text {
text: root.text
font: root.font
color: palette.toolTipText
wrapMode: Text.Wrap
}
background: Item {
implicitWidth: bg.implicitWidth
implicitHeight: bg.implicitHeight
Rectangle {
anchors.fill: bg
anchors.margins: -2
color: Qt.rgba(palette.shadow.r, palette.shadow.g, palette.shadow.b, 0.12)
radius: 8
z: -2
}
Rectangle {
anchors.fill: bg
anchors.margins: -1
color: Qt.rgba(palette.shadow.r, palette.shadow.g, palette.shadow.b, 0.08)
radius: 7
z: -1
}
Rectangle {
id: bg
anchors.fill: parent
color: palette.toolTipBase
border.color: Qt.darker(palette.toolTipBase, 1.2)
border.width: 1
radius: 6
}
}
enter: Transition {
NumberAnimation {
property: "opacity"
from: 0.0
to: 1.0
duration: 150
easing.type: Easing.OutQuad
}
}
exit: Transition {
NumberAnimation {
property: "opacity"
from: 1.0
to: 0.0
duration: 100
easing.type: Easing.InQuad
}
}
}

174
docs/agent-roles.md Normal file
View File

@@ -0,0 +1,174 @@
# Agent Roles
Agent Roles allow you to define different AI personas with specialized system prompts for various tasks. Switch between roles instantly in the chat interface to adapt the AI's behavior to your current needs.
## Overview
Agent Roles are reusable system prompt configurations that modify how the AI assistant responds. Instead of manually changing system prompts, you can create roles like "Developer", "Code Reviewer", or "Documentation Writer" and switch between them with a single click.
**Key Features:**
- **Quick Switching**: Change roles from the chat toolbar dropdown
- **Custom Prompts**: Each role has its own specialized system prompt
- **Built-in Roles**: Pre-configured Developer and Code Reviewer roles
- **Persistent**: Roles are saved locally and loaded on startup
- **Extensible**: Create unlimited custom roles for different tasks
## Default Roles
QodeAssist comes with three built-in roles:
### Developer
Experienced Qt/C++ developer with a structured workflow: analyze the problem, propose a solution, wait for approval, then implement. Best for implementation tasks where you want thoughtful, minimal code changes.
### Code Reviewer
Expert C++/QML code reviewer specializing in C++20 and Qt6. Checks for bugs, memory leaks, thread safety, Qt patterns, and production readiness. Provides direct, specific feedback with code examples.
### Researcher
Research-oriented developer who investigates problems and explores solutions. Analyzes problems, presents multiple approaches with trade-offs, and recommends the best option. Does not write implementation code — focuses on helping you make informed decisions.
## Using Agent Roles
### Switching Roles in Chat
1. Open the Chat Assistant (side panel, bottom panel, or popup window)
2. Locate the **Role selector** dropdown in the top toolbar (next to the configuration selector)
3. Select a role from the dropdown
4. The AI will now use the selected role's system prompt
**Note**: Selecting "No Role" uses only the base system prompt without role specialization.
### Viewing Active Role
Click the **Context** button (📋) in the chat toolbar to view:
- Base system prompt
- Current agent role and its system prompt
- Active project rules
## Managing Agent Roles
### Opening the Role Manager
Navigate to: `Qt Creator → Preferences → QodeAssist → Chat Assistant`
Scroll down to the **Agent Roles** section where you can manage all your roles.
### Creating a New Role
1. Click **Add...** button
2. Fill in the role details:
- **Name**: Display name shown in the dropdown (e.g., "Documentation Writer")
- **ID**: Unique identifier for the role file (e.g., "doc_writer")
- **Description**: Brief explanation of the role's purpose
- **System Prompt**: The specialized instructions for this role
3. Click **OK** to save
### Editing a Role
1. Select a role from the list
2. Click **Edit...** or double-click the role
3. Modify the fields as needed
4. Click **OK** to save changes
**Note**: Built-in roles cannot be edited directly. Duplicate them to create a modifiable copy.
### Duplicating a Role
1. Select a role to duplicate
2. Click **Duplicate...**
3. Modify the copy as needed
4. Click **OK** to save as a new role
### Deleting a Role
1. Select a custom role (built-in roles cannot be deleted)
2. Click **Delete**
3. Confirm deletion
## Creating Effective Roles
### System Prompt Tips
- **Be specific**: Clearly define the role's expertise and focus areas
- **Set expectations**: Describe the desired response format and style
- **Include guidelines**: Add specific rules or constraints for responses
- **Use structured prompts**: Break down complex roles into bullet points
## Storage Location
Agent roles are stored as JSON files in:
```
~/.config/QtProject/qtcreator/qodeassist/agent_roles/
```
**On different platforms:**
- **Linux**: `~/.config/QtProject/qtcreator/qodeassist/agent_roles/`
- **macOS**: `~/Library/Application Support/QtProject/Qt Creator/qodeassist/agent_roles/`
- **Windows**: `%APPDATA%\QtProject\qtcreator\qodeassist\agent_roles\`
### File Format
Each role is stored as a JSON file named `{id}.json`:
```json
{
"id": "doc_writer",
"name": "Documentation Writer",
"description": "Technical documentation and code comments",
"systemPrompt": "You are a technical documentation specialist...",
"isBuiltin": false
}
```
### Manual Editing
You can:
- Edit JSON files directly in any text editor
- Copy role files between machines
- Share roles with team members
- Version control your roles
- Click **Open Roles Folder...** to quickly access the directory
## How Roles Work
When a role is selected, the final system prompt is composed as:
```
┌─────────────────────────────────────────────────┐
│ Final System Prompt = Base Prompt + Role Prompt │
├─────────────────────────────────────────────────┤
│ 1. Base System Prompt (from Chat Settings) │
│ 2. Agent Role System Prompt │
│ 3. Project Rules (common/ + chat/) │
│ 4. Linked Files Context │
└─────────────────────────────────────────────────┘
```
This allows roles to augment rather than replace your base configuration.
## Best Practices
1. **Keep roles focused**: Each role should have a clear, specific purpose
2. **Use descriptive names**: Make it easy to identify roles at a glance
3. **Test your prompts**: Verify roles produce the expected behavior
4. **Iterate and improve**: Refine prompts based on AI responses
5. **Share with team**: Export and share useful roles with colleagues
## Troubleshooting
### Role Not Appearing in Dropdown
- Restart Qt Creator after adding roles manually
- Check JSON file format validity
- Verify file is in the correct directory
### Role Behavior Not as Expected
- Review the system prompt for clarity
- Check if base system prompt conflicts with role prompt
- Try a more specific or detailed prompt
## Related Documentation
- [Project Rules](project-rules.md) - Project-specific AI behavior customization
- [Chat Assistant Features](../README.md#chat-assistant) - Overview of chat functionality
- [File Context](file-context.md) - Attaching files to chat context

115
docs/chat-summarization.md Normal file
View File

@@ -0,0 +1,115 @@
# Chat Summarization
Chat Summarization allows you to compress long conversations into concise AI-generated summaries. This helps save context tokens and makes it easier to continue work on complex topics without losing important information.
## Overview
When conversations grow long, they consume more context tokens with each message. Chat Summarization uses your configured Chat Assistant provider to create an intelligent summary that preserves:
- Key decisions and conclusions
- Technical details and code references
- Important context for continuing the conversation
**Key Features:**
- **One-click compression**: Summarize directly from the chat toolbar
- **Preserves original**: Creates a new chat file, keeping the original intact
- **Smart summaries**: AI extracts the most relevant information
- **Markdown formatted**: Summaries are well-structured and readable
## Using Chat Summarization
### Compressing a Chat
1. Open any chat with conversation history
2. Click the **Compress** button (📦) in the chat top bar
3. Wait for the AI to generate the summary
4. A new chat opens with the compressed summary
### What Gets Preserved
The summarization process:
- Maintains chronological flow of the discussion
- Keeps technical details, code snippets, and file references
- Preserves key decisions and conclusions
- Aims for 30-40% of the original conversation length
### What Gets Filtered
The following message types are excluded from summarization:
- Tool call results (file reads, searches)
- File edit blocks
- Thinking/reasoning blocks
## How It Works
```
┌─────────────────────────────────────────────────────────────┐
│ CHAT SUMMARIZATION │
├─────────────────────────────────────────────────────────────┤
│ 1. Original chat messages are collected │
│ 2. Tool/thinking messages are filtered out │
│ 3. AI generates a structured summary │
│ 4. New chat file is created with summary as first message │
│ 5. Original chat remains unchanged │
└─────────────────────────────────────────────────────────────┘
```
### File Naming
Compressed chats are saved with a unique suffix:
```
original_chat.json → original_chat_a1b2c.json
```
Both files appear in your chat history, allowing you to switch between the full conversation and the summary.
## Best Practices
1. **Summarize at natural breakpoints**: Compress after completing a major task or topic
2. **Review the summary**: Ensure important details were captured before continuing
3. **Keep originals**: Don't delete original chats until you've verified the summary is sufficient
4. **Use for long sessions**: Most beneficial for conversations with 20+ messages
## When to Use
**Good candidates for summarization:**
- Long debugging sessions with resolved issues
- Feature implementation discussions with final decisions
- Research conversations where conclusions were reached
- Any chat approaching context limits
**Consider keeping full history for:**
- Ongoing work that may need exact message references
- Conversations with important code snippets you'll copy
- Discussions where the reasoning process matters
## Configuration
Chat Summarization uses your current Chat Assistant settings:
- **Provider**: Same as Chat Assistant (Settings → QodeAssist → General)
- **Model**: Same as Chat Assistant
- **Template**: Same as Chat Assistant
No additional configuration is required.
## Troubleshooting
### Compression Button Not Visible
- Ensure you have an active chat with messages
- Check that the chat top bar is visible
### Compression Fails
- Verify your Chat Assistant provider is configured correctly
- Check network connectivity
- Ensure the model supports chat completions
### Summary Missing Details
- The AI aims for 30-40% compression; some details may be condensed
- For critical information, keep the original chat
- Consider summarizing smaller conversation segments
## Related Documentation
- [Agent Roles](agent-roles.md) - Switch between AI personas
- [File Context](file-context.md) - Attach files to chat
- [Project Rules](project-rules.md) - Customize AI behavior

View File

@@ -1,11 +1,15 @@
# Configure for OpenAI
QodeAssist supports both OpenAI's standard Chat Completions API and the new Responses API, giving you access to the latest GPT models including GPT-5.1 and GPT-5.1-codex.
## Standard OpenAI Configuration
1. Open Qt Creator settings and navigate to the QodeAssist section
2. Go to Provider Settings tab and configure OpenAI api key
3. Return to General tab and configure:
- Set "OpenAI" as the provider for code completion or/and chat assistant
- Set the OpenAI URL (https://api.openai.com)
- Select your preferred model (e.g., gpt-4o)
- Select your preferred model (e.g., gpt-4o, gpt-5.1, gpt-5.1-codex)
- Choose the OpenAI template for code completion or/and chat
<details>
@@ -14,3 +18,15 @@
<img width="829" alt="OpenAI Settings" src="https://github.com/user-attachments/assets/4716f790-6159-44d0-a8f4-565ccb6eb713" />
</details>
## OpenAI Responses API Configuration
The Responses API is OpenAI's newer endpoint that provides enhanced capabilities and improved performance. It supports the latest GPT-5.1 models.
1. Open Qt Creator settings and navigate to the QodeAssist section
2. Go to Provider Settings tab and configure OpenAI api key
3. Return to General tab and configure:
- Set "OpenAI Responses" as the provider for code completion or/and chat assistant
- Set the OpenAI URL (https://api.openai.com)
- Select your preferred model (e.g., gpt-5.1, gpt-5.1-codex)
- Choose the OpenAI Responses template for code completion or/and chat

View File

@@ -21,7 +21,6 @@
#include <QJsonDocument>
#include <QMutexLocker>
#include <QUuid>
#include <Logger.hpp>
@@ -30,9 +29,7 @@ namespace QodeAssist::LLMCore {
HttpClient::HttpClient(QObject *parent)
: QObject(parent)
, m_manager(new QNetworkAccessManager(this))
{
connect(this, &HttpClient::sendRequest, this, &HttpClient::onSendRequest);
}
{}
HttpClient::~HttpClient()
{
@@ -44,156 +41,96 @@ HttpClient::~HttpClient()
m_activeRequests.clear();
}
void HttpClient::onSendRequest(const HttpRequest &request)
QFuture<QByteArray> HttpClient::get(const QNetworkRequest &request)
{
QJsonDocument doc(request.payload);
LOG_MESSAGE(QString("HttpClient: data: %1").arg(doc.toJson(QJsonDocument::Indented)));
LOG_MESSAGE(QString("HttpClient: GET %1").arg(request.url().toString()));
QNetworkReply *reply
= m_manager->post(request.networkRequest, doc.toJson(QJsonDocument::Compact));
addActiveRequest(reply, request.requestId);
auto promise = std::make_shared<QPromise<QByteArray>>();
promise->start();
QNetworkReply *reply = m_manager->get(request);
setupNonStreamingReply(reply, promise);
return promise->future();
}
QFuture<QByteArray> HttpClient::post(const QNetworkRequest &request, const QJsonObject &payload)
{
QJsonDocument doc(payload);
LOG_MESSAGE(QString("HttpClient: POST %1, data: %2")
.arg(request.url().toString(), doc.toJson(QJsonDocument::Indented)));
auto promise = std::make_shared<QPromise<QByteArray>>();
promise->start();
QNetworkReply *reply = m_manager->post(request, doc.toJson(QJsonDocument::Compact));
setupNonStreamingReply(reply, promise);
return promise->future();
}
QFuture<QByteArray> HttpClient::del(const QNetworkRequest &request,
std::optional<QJsonObject> payload)
{
auto promise = std::make_shared<QPromise<QByteArray>>();
promise->start();
QNetworkReply *reply;
if (payload) {
QJsonDocument doc(*payload);
LOG_MESSAGE(QString("HttpClient: DELETE %1, data: %2")
.arg(request.url().toString(), doc.toJson(QJsonDocument::Indented)));
reply = m_manager->sendCustomRequest(request, "DELETE", doc.toJson(QJsonDocument::Compact));
} else {
LOG_MESSAGE(QString("HttpClient: DELETE %1").arg(request.url().toString()));
reply = m_manager->deleteResource(request);
}
setupNonStreamingReply(reply, promise);
return promise->future();
}
void HttpClient::setupNonStreamingReply(QNetworkReply *reply,
std::shared_ptr<QPromise<QByteArray>> promise)
{
connect(reply, &QNetworkReply::finished, this, [this, reply, promise]() {
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QByteArray responseBody = reply->readAll();
QNetworkReply::NetworkError networkError = reply->error();
QString networkErrorString = reply->errorString();
reply->disconnect();
reply->deleteLater();
LOG_MESSAGE(
QString("HttpClient: Non-streaming request - HTTP Status: %1").arg(statusCode));
bool hasError = (networkError != QNetworkReply::NoError) || (statusCode >= 400);
if (hasError) {
QString errorMsg = parseErrorFromResponse(statusCode, responseBody, networkErrorString);
LOG_MESSAGE(QString("HttpClient: Non-streaming request - Error: %1").arg(errorMsg));
promise->setException(
std::make_exception_ptr(std::runtime_error(errorMsg.toStdString())));
} else {
promise->addResult(responseBody);
}
promise->finish();
});
}
void HttpClient::postStreaming(const QString &requestId, const QNetworkRequest &request,
const QJsonObject &payload)
{
QJsonDocument doc(payload);
LOG_MESSAGE(QString("HttpClient: POST streaming %1, data: %2")
.arg(request.url().toString(), doc.toJson(QJsonDocument::Indented)));
QNetworkReply *reply = m_manager->post(request, doc.toJson(QJsonDocument::Compact));
addActiveRequest(reply, requestId);
connect(reply, &QNetworkReply::readyRead, this, &HttpClient::onReadyRead);
connect(reply, &QNetworkReply::finished, this, &HttpClient::onFinished);
}
void HttpClient::onReadyRead()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (!reply || reply->isFinished())
return;
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode >= 400) {
return;
}
QString requestId;
{
QMutexLocker locker(&m_mutex);
bool found = false;
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
if (it.value() == reply) {
requestId = it.key();
found = true;
break;
}
}
if (!found)
return;
}
if (requestId.isEmpty())
return;
QByteArray data = reply->readAll();
if (!data.isEmpty()) {
emit dataReceived(requestId, data);
}
}
void HttpClient::onFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (!reply)
return;
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QByteArray responseBody = reply->readAll();
QNetworkReply::NetworkError networkError = reply->error();
QString networkErrorString = reply->errorString();
reply->disconnect();
QString requestId;
bool hasError = false;
QString errorMsg;
{
QMutexLocker locker(&m_mutex);
bool found = false;
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
if (it.value() == reply) {
requestId = it.key();
m_activeRequests.erase(it);
found = true;
break;
}
}
if (!found) {
reply->deleteLater();
return;
}
hasError = (networkError != QNetworkReply::NoError) || (statusCode >= 400);
if (hasError) {
errorMsg = parseErrorFromResponse(statusCode, responseBody, networkErrorString);
}
LOG_MESSAGE(QString("HttpClient: Request %1 - HTTP Status: %2").arg(requestId).arg(statusCode));
if (!responseBody.isEmpty()) {
LOG_MESSAGE(QString("HttpClient: Request %1 - Response body (%2 bytes): %3")
.arg(requestId)
.arg(responseBody.size())
.arg(QString::fromUtf8(responseBody)));
}
if (hasError) {
LOG_MESSAGE(QString("HttpClient: Request %1 - Error: %2").arg(requestId, errorMsg));
}
}
reply->deleteLater();
if (!requestId.isEmpty()) {
emit requestFinished(requestId, !hasError, errorMsg);
}
}
QString HttpClient::addActiveRequest(QNetworkReply *reply, const QString &requestId)
{
QMutexLocker locker(&m_mutex);
m_activeRequests[requestId] = reply;
LOG_MESSAGE(QString("HttpClient: Added active request: %1").arg(requestId));
return requestId;
}
QString HttpClient::parseErrorFromResponse(
int statusCode, const QByteArray &responseBody, const QString &networkErrorString)
{
QString errorMsg;
if (!responseBody.isEmpty()) {
QJsonDocument errorDoc = QJsonDocument::fromJson(responseBody);
if (!errorDoc.isNull() && errorDoc.isObject()) {
QJsonObject errorObj = errorDoc.object();
if (errorObj.contains("error")) {
QJsonObject error = errorObj["error"].toObject();
QString message = error["message"].toString();
QString type = error["type"].toString();
QString code = error["code"].toString();
errorMsg = QString("HTTP %1: %2").arg(statusCode).arg(message);
if (!type.isEmpty())
errorMsg += QString(" (type: %1)").arg(type);
if (!code.isEmpty())
errorMsg += QString(" (code: %1)").arg(code);
} else {
errorMsg = QString("HTTP %1: %2").arg(statusCode).arg(QString::fromUtf8(responseBody));
}
} else {
errorMsg = QString("HTTP %1: %2").arg(statusCode).arg(QString::fromUtf8(responseBody));
}
} else {
errorMsg = QString("HTTP %1: %2").arg(statusCode).arg(networkErrorString);
}
return errorMsg;
connect(reply, &QNetworkReply::finished, this, &HttpClient::onStreamingFinished);
}
void HttpClient::cancelRequest(const QString &requestId)
@@ -212,4 +149,128 @@ void HttpClient::cancelRequest(const QString &requestId)
}
}
void HttpClient::onReadyRead()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (!reply || reply->isFinished())
return;
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode >= 400)
return;
QString requestId = findRequestId(reply);
if (requestId.isEmpty())
return;
QByteArray data = reply->readAll();
if (!data.isEmpty()) {
emit dataReceived(requestId, data);
}
}
void HttpClient::onStreamingFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (!reply)
return;
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QByteArray responseBody = reply->readAll();
QNetworkReply::NetworkError networkError = reply->error();
QString networkErrorString = reply->errorString();
reply->disconnect();
QString requestId;
std::optional<QString> error;
{
QMutexLocker locker(&m_mutex);
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
if (it.value() == reply) {
requestId = it.key();
m_activeRequests.erase(it);
break;
}
}
if (requestId.isEmpty()) {
reply->deleteLater();
return;
}
bool hasError = (networkError != QNetworkReply::NoError) || (statusCode >= 400);
if (hasError) {
error = parseErrorFromResponse(statusCode, responseBody, networkErrorString);
}
LOG_MESSAGE(
QString("HttpClient: Request %1 - HTTP Status: %2").arg(requestId).arg(statusCode));
if (!responseBody.isEmpty()) {
LOG_MESSAGE(QString("HttpClient: Request %1 - Response body (%2 bytes): %3")
.arg(requestId)
.arg(responseBody.size())
.arg(QString::fromUtf8(responseBody)));
}
if (error) {
LOG_MESSAGE(QString("HttpClient: Request %1 - Error: %2").arg(requestId, *error));
}
}
reply->deleteLater();
if (!requestId.isEmpty()) {
emit requestFinished(requestId, error);
}
}
QString HttpClient::findRequestId(QNetworkReply *reply)
{
QMutexLocker locker(&m_mutex);
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
if (it.value() == reply)
return it.key();
}
return {};
}
void HttpClient::addActiveRequest(QNetworkReply *reply, const QString &requestId)
{
QMutexLocker locker(&m_mutex);
m_activeRequests[requestId] = reply;
LOG_MESSAGE(QString("HttpClient: Added active request: %1").arg(requestId));
}
QString HttpClient::parseErrorFromResponse(
int statusCode, const QByteArray &responseBody, const QString &networkErrorString)
{
if (!responseBody.isEmpty()) {
QJsonDocument errorDoc = QJsonDocument::fromJson(responseBody);
if (!errorDoc.isNull() && errorDoc.isObject()) {
QJsonObject errorObj = errorDoc.object();
if (errorObj.contains("error")) {
QJsonObject error = errorObj["error"].toObject();
QString message = error["message"].toString();
QString type = error["type"].toString();
QString code = error["code"].toString();
QString errorMsg = QString("HTTP %1: %2").arg(statusCode).arg(message);
if (!type.isEmpty())
errorMsg += QString(" (type: %1)").arg(type);
if (!code.isEmpty())
errorMsg += QString(" (code: %1)").arg(code);
return errorMsg;
}
return QString("HTTP %1: %2")
.arg(statusCode)
.arg(QString::fromUtf8(responseBody));
}
return QString("HTTP %1: %2").arg(statusCode).arg(QString::fromUtf8(responseBody));
}
return QString("HTTP %1: %2").arg(statusCode).arg(networkErrorString);
}
} // namespace QodeAssist::LLMCore

View File

@@ -19,24 +19,19 @@
#pragma once
#include <optional>
#include <QFuture>
#include <QHash>
#include <QJsonObject>
#include <QMap>
#include <QMutex>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QObject>
#include <QUrl>
#include <QPromise>
namespace QodeAssist::LLMCore {
struct HttpRequest
{
QNetworkRequest networkRequest;
QString requestId;
QJsonObject payload;
};
class HttpClient : public QObject
{
Q_OBJECT
@@ -45,21 +40,33 @@ public:
HttpClient(QObject *parent = nullptr);
~HttpClient();
// Non-streaming — return QFuture with full response
QFuture<QByteArray> get(const QNetworkRequest &request);
QFuture<QByteArray> post(const QNetworkRequest &request, const QJsonObject &payload);
QFuture<QByteArray> del(const QNetworkRequest &request,
std::optional<QJsonObject> payload = std::nullopt);
// Streaming — signal-based with requestId
void postStreaming(const QString &requestId, const QNetworkRequest &request,
const QJsonObject &payload);
void cancelRequest(const QString &requestId);
signals:
void sendRequest(const QodeAssist::LLMCore::HttpRequest &request);
void dataReceived(const QString &requestId, const QByteArray &data);
void requestFinished(const QString &requestId, bool success, const QString &error);
void requestFinished(const QString &requestId, std::optional<QString> error);
private slots:
void onSendRequest(const QodeAssist::LLMCore::HttpRequest &request);
void onReadyRead();
void onFinished();
void onStreamingFinished();
private:
QString addActiveRequest(QNetworkReply *reply, const QString &requestId);
QString parseErrorFromResponse(int statusCode, const QByteArray &responseBody, const QString &networkErrorString);
void setupNonStreamingReply(QNetworkReply *reply, std::shared_ptr<QPromise<QByteArray>> promise);
QString findRequestId(QNetworkReply *reply);
void addActiveRequest(QNetworkReply *reply, const QString &requestId);
QString parseErrorFromResponse(int statusCode, const QByteArray &responseBody,
const QString &networkErrorString);
QNetworkAccessManager *m_manager;
QHash<QString, QNetworkReply *> m_activeRequests;

51
llmcore/IToolsManager.hpp Normal file
View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QHash>
#include <QJsonArray>
#include <QJsonObject>
#include <QString>
#include "BaseTool.hpp"
namespace QodeAssist::LLMCore {
class IToolsManager
{
public:
virtual ~IToolsManager() = default;
virtual void executeToolCall(
const QString &requestId,
const QString &toolId,
const QString &toolName,
const QJsonObject &input) = 0;
virtual QJsonArray getToolsDefinitions(
ToolSchemaFormat format,
RunToolsFilter filter = RunToolsFilter::ALL) const = 0;
virtual void cleanupRequest(const QString &requestId) = 0;
virtual void setCurrentSessionId(const QString &sessionId) = 0;
virtual void clearTodoSession(const QString &sessionId) = 0;
};
} // namespace QodeAssist::LLMCore

View File

@@ -19,6 +19,9 @@
#pragma once
#include <optional>
#include <QFuture>
#include <utils/environment.h>
#include <QNetworkRequest>
#include <QObject>
@@ -27,6 +30,7 @@
#include "ContextData.hpp"
#include "DataBuffers.hpp"
#include "HttpClient.hpp"
#include "IToolsManager.hpp"
#include "PromptTemplate.hpp"
#include "RequestType.hpp"
@@ -56,7 +60,7 @@ public:
bool isToolsEnabled,
bool isThinkingEnabled)
= 0;
virtual QList<QString> getInstalledModels(const QString &url) = 0;
virtual QFuture<QList<QString>> getInstalledModels(const QString &url) = 0;
virtual QList<QString> validateRequest(const QJsonObject &request, TemplateType type) = 0;
virtual QString apiKey() const = 0;
virtual void prepareNetworkRequest(QNetworkRequest &networkRequest) const = 0;
@@ -71,6 +75,8 @@ public:
virtual void cancelRequest(const RequestID &requestId);
virtual IToolsManager *toolsManager() const { return nullptr; }
HttpClient *httpClient() const;
public slots:
@@ -78,7 +84,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
= 0;
virtual void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
= 0;
signals:

View File

@@ -19,11 +19,9 @@
#include "ClaudeProvider.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
#include <QUrlQuery>
#include "llmcore/ValidationUtils.hpp"
@@ -142,11 +140,8 @@ void ClaudeProvider::prepareRequest(
}
}
QList<QString> ClaudeProvider::getInstalledModels(const QString &baseUrl)
QFuture<QList<QString>> ClaudeProvider::getInstalledModels(const QString &baseUrl)
{
QList<QString> models;
QNetworkAccessManager manager;
QUrl url(baseUrl + "/v1/models");
QUrlQuery query;
query.addQueryItem("limit", "1000");
@@ -160,32 +155,24 @@ QList<QString> ClaudeProvider::getInstalledModels(const QString &baseUrl)
request.setRawHeader("x-api-key", apiKey().toUtf8());
}
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
QByteArray responseData = reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
QJsonObject jsonObject = jsonResponse.object();
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
if (jsonObject.contains("data")) {
QJsonArray modelArray = jsonObject["data"].toArray();
for (const QJsonValue &value : modelArray) {
QJsonObject modelObject = value.toObject();
if (modelObject.contains("id")) {
QString modelId = modelObject["id"].toString();
models.append(modelId);
models.append(modelObject["id"].toString());
}
}
}
} else {
LOG_MESSAGE(QString("Error fetching Claude models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching Claude models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> ClaudeProvider::validateRequest(const QJsonObject &request, LLMCore::TemplateType type)
@@ -240,12 +227,9 @@ void ClaudeProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(QString("ClaudeProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool ClaudeProvider::supportsTools() const
@@ -268,6 +252,11 @@ void ClaudeProvider::cancelRequest(const LLMCore::RequestID &requestId)
cleanupRequest(requestId);
}
LLMCore::IToolsManager *ClaudeProvider::toolsManager() const
{
return m_toolsManager;
}
void ClaudeProvider::onDataReceived(
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
{
@@ -284,11 +273,11 @@ void ClaudeProvider::onDataReceived(
}
void ClaudeProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("ClaudeProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("ClaudeProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}
@@ -531,6 +520,7 @@ void ClaudeProvider::handleMessageComplete(const QString &requestId)
for (auto toolContent : toolUseContent) {
auto toolStringName = m_toolsManager->toolsFactory()->getStringName(toolContent->name());
emit toolExecutionStarted(requestId, toolContent->id(), toolStringName);
m_toolsManager->executeToolCall(
requestId, toolContent->id(), toolContent->name(), toolContent->input());
}

View File

@@ -44,7 +44,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -58,13 +58,14 @@ public:
bool supportImage() const override;
void cancelRequest(const LLMCore::RequestID &requestId) override;
LLMCore::IToolsManager *toolsManager() const override;
public slots:
void onDataReceived(
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -19,11 +19,9 @@
#include "GoogleAIProvider.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
#include <QtCore/qurlquery.h>
#include "llmcore/ValidationUtils.hpp"
@@ -156,29 +154,17 @@ void GoogleAIProvider::prepareRequest(
}
}
QList<QString> GoogleAIProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> GoogleAIProvider::getInstalledModels(const QString &url)
{
QList<QString> models;
QNetworkAccessManager manager;
QNetworkRequest request(QString("%1/models?key=%2").arg(url, apiKey()));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
QByteArray responseData = reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
QJsonObject jsonObject = jsonResponse.object();
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
if (jsonObject.contains("models")) {
QJsonArray modelArray = jsonObject["models"].toArray();
models.clear();
for (const QJsonValue &value : modelArray) {
QJsonObject modelObject = value.toObject();
if (modelObject.contains("name")) {
@@ -190,12 +176,11 @@ QList<QString> GoogleAIProvider::getInstalledModels(const QString &url)
}
}
}
} else {
LOG_MESSAGE(QString("Error fetching Google AI models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching Google AI models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> GoogleAIProvider::validateRequest(
@@ -254,13 +239,10 @@ void GoogleAIProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(
QString("GoogleAIProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool GoogleAIProvider::supportsTools() const
@@ -327,11 +309,11 @@ void GoogleAIProvider::onDataReceived(
}
void GoogleAIProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("GoogleAIProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("GoogleAIProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -62,8 +62,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -27,11 +27,9 @@
#include "settings/GeneralSettings.hpp"
#include "settings/ProviderSettings.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
namespace QodeAssist::Providers {
@@ -71,35 +69,24 @@ bool LMStudioProvider::supportsModelListing() const
return true;
}
QList<QString> LMStudioProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> LMStudioProvider::getInstalledModels(const QString &url)
{
QList<QString> models;
QNetworkAccessManager manager;
QNetworkRequest request(QString("%1%2").arg(url, "/v1/models"));
QNetworkReply *reply = manager.get(request);
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
QJsonArray modelArray = jsonObject["data"].toArray();
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
QByteArray responseData = reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
QJsonObject jsonObject = jsonResponse.object();
QJsonArray modelArray = jsonObject["data"].toArray();
for (const QJsonValue &value : modelArray) {
QJsonObject modelObject = value.toObject();
QString modelId = modelObject["id"].toString();
models.append(modelId);
for (const QJsonValue &value : modelArray) {
QJsonObject modelObject = value.toObject();
models.append(modelObject["id"].toString());
}
} else {
LOG_MESSAGE(QString("Error fetching LMStudio models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching LMStudio models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> LMStudioProvider::validateRequest(
@@ -149,13 +136,10 @@ void LMStudioProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(
QString("LMStudioProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool LMStudioProvider::supportsTools() const
@@ -195,11 +179,11 @@ void LMStudioProvider::onDataReceived(
}
void LMStudioProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("LMStudioProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("LMStudioProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -61,8 +61,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -26,11 +26,9 @@
#include "settings/QuickRefactorSettings.hpp"
#include "settings/GeneralSettings.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
namespace QodeAssist::Providers {
@@ -121,9 +119,9 @@ void LlamaCppProvider::prepareRequest(
}
}
QList<QString> LlamaCppProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> LlamaCppProvider::getInstalledModels(const QString &)
{
return {};
return QtFuture::makeReadyFuture(QList<QString>{});
}
QList<QString> LlamaCppProvider::validateRequest(
@@ -192,13 +190,10 @@ void LlamaCppProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(
QString("LlamaCppProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool LlamaCppProvider::supportsTools() const
@@ -250,11 +245,11 @@ void LlamaCppProvider::onDataReceived(
}
void LlamaCppProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("LlamaCppProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("LlamaCppProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -61,8 +61,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -27,11 +27,9 @@
#include "settings/GeneralSettings.hpp"
#include "settings/ProviderSettings.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
namespace QodeAssist::Providers {
@@ -71,43 +69,32 @@ bool MistralAIProvider::supportsModelListing() const
return true;
}
QList<QString> MistralAIProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> MistralAIProvider::getInstalledModels(const QString &url)
{
QList<QString> models;
QNetworkAccessManager manager;
QNetworkRequest request(QString("%1/v1/models").arg(url));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
if (!apiKey().isEmpty()) {
request.setRawHeader("Authorization", QString("Bearer %1").arg(apiKey()).toUtf8());
}
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
QByteArray responseData = reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
QJsonObject jsonObject = jsonResponse.object();
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
if (jsonObject.contains("data") && jsonObject["object"].toString() == "list") {
QJsonArray modelArray = jsonObject["data"].toArray();
for (const QJsonValue &value : modelArray) {
QJsonObject modelObject = value.toObject();
if (modelObject.contains("id")) {
QString modelId = modelObject["id"].toString();
models.append(modelId);
models.append(modelObject["id"].toString());
}
}
}
} else {
LOG_MESSAGE(QString("Error fetching Mistral AI models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching Mistral AI models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> MistralAIProvider::validateRequest(
@@ -170,13 +157,10 @@ void MistralAIProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(
QString("MistralAIProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool MistralAIProvider::supportsTools() const
@@ -216,11 +200,11 @@ void MistralAIProvider::onDataReceived(
}
void MistralAIProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("MistralAIProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("MistralAIProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -61,8 +61,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -22,8 +22,6 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
#include <QtCore/qeventloop.h>
#include "llmcore/ValidationUtils.hpp"
#include "logger/Logger.hpp"
@@ -147,35 +145,25 @@ void OllamaProvider::prepareRequest(
}
}
QList<QString> OllamaProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> OllamaProvider::getInstalledModels(const QString &url)
{
QList<QString> models;
QNetworkAccessManager manager;
QNetworkRequest request(QString("%1%2").arg(url, "/api/tags"));
prepareNetworkRequest(request);
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
QByteArray responseData = reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
QJsonObject jsonObject = jsonResponse.object();
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
QJsonArray modelArray = jsonObject["models"].toArray();
for (const QJsonValue &value : modelArray) {
QJsonObject modelObject = value.toObject();
QString modelName = modelObject["name"].toString();
models.append(modelName);
models.append(modelObject["name"].toString());
}
} else {
LOG_MESSAGE(QString("Error fetching models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> OllamaProvider::validateRequest(const QJsonObject &request, LLMCore::TemplateType type)
@@ -248,12 +236,9 @@ void OllamaProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(QString("OllamaProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool OllamaProvider::supportsTools() const
@@ -312,11 +297,11 @@ void OllamaProvider::onDataReceived(
}
void OllamaProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("OllamaProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("OllamaProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -44,7 +44,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -63,8 +63,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -122,9 +122,9 @@ void OpenAICompatProvider::prepareRequest(
}
}
QList<QString> OpenAICompatProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> OpenAICompatProvider::getInstalledModels(const QString &)
{
return QStringList();
return QtFuture::makeReadyFuture(QList<QString>{});
}
QList<QString> OpenAICompatProvider::validateRequest(
@@ -178,13 +178,10 @@ void OpenAICompatProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(
QString("OpenAICompatProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool OpenAICompatProvider::supportsTools() const
@@ -224,11 +221,11 @@ void OpenAICompatProvider::onDataReceived(
}
void OpenAICompatProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("OpenAICompatProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("OpenAICompatProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -61,8 +61,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -27,11 +27,9 @@
#include "settings/GeneralSettings.hpp"
#include "settings/ProviderSettings.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
namespace QodeAssist::Providers {
@@ -141,26 +139,17 @@ void OpenAIProvider::prepareRequest(
}
}
QList<QString> OpenAIProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> OpenAIProvider::getInstalledModels(const QString &url)
{
QList<QString> models;
QNetworkAccessManager manager;
QNetworkRequest request(QString("%1/v1/models").arg(url));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
if (!apiKey().isEmpty()) {
request.setRawHeader("Authorization", QString("Bearer %1").arg(apiKey()).toUtf8());
}
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
QByteArray responseData = reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
QJsonObject jsonObject = jsonResponse.object();
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
if (jsonObject.contains("data")) {
QJsonArray modelArray = jsonObject["data"].toArray();
@@ -176,12 +165,11 @@ QList<QString> OpenAIProvider::getInstalledModels(const QString &url)
}
}
}
} else {
LOG_MESSAGE(QString("Error fetching OpenAI models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching OpenAI models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> OpenAIProvider::validateRequest(const QJsonObject &request, LLMCore::TemplateType type)
@@ -235,12 +223,9 @@ void OpenAIProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
LOG_MESSAGE(QString("OpenAIProvider: Sending request %1 to %2").arg(requestId, url.toString()));
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool OpenAIProvider::supportsTools() const
@@ -280,11 +265,11 @@ void OpenAIProvider::onDataReceived(
}
void OpenAIProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("OpenAIProvider request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("OpenAIProvider request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -61,8 +61,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -28,11 +28,9 @@
#include "settings/ProviderSettings.hpp"
#include "settings/QuickRefactorSettings.hpp"
#include <QEventLoop>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
namespace QodeAssist::Providers {
@@ -158,26 +156,17 @@ void OpenAIResponsesProvider::prepareRequest(
request["stream"] = true;
}
QList<QString> OpenAIResponsesProvider::getInstalledModels(const QString &url)
QFuture<QList<QString>> OpenAIResponsesProvider::getInstalledModels(const QString &url)
{
QList<QString> models;
QNetworkAccessManager manager;
QNetworkRequest request(QString("%1/v1/models").arg(url));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
if (!apiKey().isEmpty()) {
request.setRawHeader("Authorization", QString("Bearer %1").arg(apiKey()).toUtf8());
}
QNetworkReply *reply = manager.get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
if (reply->error() == QNetworkReply::NoError) {
const QByteArray responseData = reply->readAll();
const QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData);
const QJsonObject jsonObject = jsonResponse.object();
return httpClient()->get(request).then([](const QByteArray &data) {
QList<QString> models;
const QJsonObject jsonObject = QJsonDocument::fromJson(data).object();
if (jsonObject.contains("data")) {
const QJsonArray modelArray = jsonObject["data"].toArray();
@@ -200,12 +189,11 @@ QList<QString> OpenAIResponsesProvider::getInstalledModels(const QString &url)
}
}
}
} else {
LOG_MESSAGE(QString("Error fetching OpenAI models: %1").arg(reply->errorString()));
}
reply->deleteLater();
return models;
return models;
}).onFailed([](const std::exception &e) {
LOG_MESSAGE(QString("Error fetching OpenAI models: %1").arg(e.what()));
return QList<QString>{};
});
}
QList<QString> OpenAIResponsesProvider::validateRequest(
@@ -280,10 +268,7 @@ void OpenAIResponsesProvider::sendRequest(
QNetworkRequest networkRequest(url);
prepareNetworkRequest(networkRequest);
LLMCore::HttpRequest
request{.networkRequest = networkRequest, .requestId = requestId, .payload = payload};
emit httpClient()->sendRequest(request);
httpClient()->postStreaming(requestId, networkRequest, payload);
}
bool OpenAIResponsesProvider::supportsTools() const
@@ -344,11 +329,11 @@ void OpenAIResponsesProvider::onDataReceived(
}
void OpenAIResponsesProvider::onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId, bool success, const QString &error)
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
{
if (!success) {
LOG_MESSAGE(QString("OpenAIResponses request %1 failed: %2").arg(requestId, error));
emit requestFailed(requestId, error);
if (error) {
LOG_MESSAGE(QString("OpenAIResponses request %1 failed: %2").arg(requestId, *error));
emit requestFailed(requestId, *error);
cleanupRequest(requestId);
return;
}

View File

@@ -43,7 +43,7 @@ public:
LLMCore::RequestType type,
bool isToolsEnabled,
bool isThinkingEnabled) override;
QList<QString> getInstalledModels(const QString &url) override;
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
QString apiKey() const override;
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
@@ -62,8 +62,7 @@ public slots:
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
void onRequestFinished(
const QodeAssist::LLMCore::RequestID &requestId,
bool success,
const QString &error) override;
std::optional<QString> error) override;
private slots:
void onToolExecutionComplete(

View File

@@ -236,7 +236,7 @@ public:
closeChatViewAction.setText(Tr::tr("Close QodeAssist Chat"));
closeChatViewAction.setIcon(QCODEASSIST_CHAT_ICON.icon());
closeChatViewAction.addOnTriggered(this, [this] {
if (m_chatView->isVisible()) {
if (m_chatView && m_chatView->isActive() && m_chatView->isVisible()) {
m_chatView->close();
}
});
@@ -250,8 +250,6 @@ public:
editorContextMenu->addAction(requestAction.command(), Core::Constants::G_DEFAULT_THREE);
editorContextMenu->addAction(showChatViewAction.command(),
Core::Constants::G_DEFAULT_THREE);
editorContextMenu->addAction(closeChatViewAction.command(),
Core::Constants::G_DEFAULT_THREE);
}
Chat::ChatFileManager::cleanupGlobalIntermediateStorage();

226
settings/AgentRole.cpp Normal file
View File

@@ -0,0 +1,226 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "AgentRole.hpp"
#include <coreplugin/icore.h>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
namespace QodeAssist::Settings {
QString AgentRolesManager::getConfigurationDirectory()
{
QString path = QString("%1/qodeassist/agent_roles")
.arg(Core::ICore::userResourcePath().toFSPathString());
QDir().mkpath(path);
return path;
}
QList<AgentRole> AgentRolesManager::loadAllRoles()
{
QList<AgentRole> roles;
QString configDir = getConfigurationDirectory();
QDir dir(configDir);
ensureDefaultRoles();
const QStringList jsonFiles = dir.entryList({"*.json"}, QDir::Files);
for (const QString &fileName : jsonFiles) {
AgentRole role = loadRoleFromFile(dir.absoluteFilePath(fileName));
if (!role.id.isEmpty()) {
roles.append(role);
}
}
return roles;
}
AgentRole AgentRolesManager::loadRole(const QString &roleId)
{
if (roleId.isEmpty())
return {};
QString filePath = QDir(getConfigurationDirectory()).absoluteFilePath(roleId + ".json");
if (!QFile::exists(filePath))
return {};
return loadRoleFromFile(filePath);
}
AgentRole AgentRolesManager::loadRoleFromFile(const QString &filePath)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly))
return {};
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
if (doc.isNull() || !doc.isObject())
return {};
return AgentRole::fromJson(doc.object());
}
bool AgentRolesManager::saveRole(const AgentRole &role)
{
if (role.id.isEmpty())
return false;
QString filePath = QDir(getConfigurationDirectory()).absoluteFilePath(role.id + ".json");
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly))
return false;
QJsonDocument doc(role.toJson());
file.write(doc.toJson(QJsonDocument::Indented));
return true;
}
bool AgentRolesManager::deleteRole(const QString &roleId)
{
if (roleId.isEmpty())
return false;
QString filePath = QDir(getConfigurationDirectory()).absoluteFilePath(roleId + ".json");
return QFile::remove(filePath);
}
bool AgentRolesManager::roleExists(const QString &roleId)
{
if (roleId.isEmpty())
return false;
QString filePath = QDir(getConfigurationDirectory()).absoluteFilePath(roleId + ".json");
return QFile::exists(filePath);
}
void AgentRolesManager::ensureDefaultRoles()
{
QDir dir(getConfigurationDirectory());
if (!dir.exists("developer.json"))
saveRole(getDefaultDeveloperRole());
if (!dir.exists("reviewer.json"))
saveRole(getDefaultReviewerRole());
if (!dir.exists("researcher.json"))
saveRole(getDefaultResearcherRole());
}
AgentRole AgentRolesManager::getDefaultDeveloperRole()
{
return AgentRole{
"developer",
"Developer",
"Experienced Qt/C++ developer for implementation tasks",
"You are an experienced Qt/C++ developer working on a Qt Creator plugin.\n\n"
"Your workflow:\n"
"1. **Analyze** - understand the problem and what needs to be done\n"
"2. **Propose solution** - explain your approach in 2-3 sentences\n"
"3. **Wait for approval** - don't write code until the solution is confirmed\n"
"4. **Implement** - write clean, minimal code that solves the task\n\n"
"When analyzing:\n"
"- Ask clarifying questions if requirements are unclear\n"
"- Check existing code for similar patterns\n"
"- Consider edge cases and potential issues\n\n"
"When proposing:\n"
"- Explain what you'll change and why\n"
"- Mention files you'll modify\n"
"- Note any architectural implications\n\n"
"When implementing:\n"
"- Use C++20, Qt6, follow existing codebase style\n"
"- Write only what's needed (MVP approach)\n"
"- Include file paths and necessary changes\n"
"- Handle errors properly\n"
"- Make sure it compiles\n\n"
"Keep it practical:\n"
"- Short explanations, let code speak\n"
"- No over-engineering or unnecessary refactoring\n"
"- No TODOs, debug code, or unfinished work\n"
"- Point out non-obvious things\n\n"
"You're a pragmatic team member who thinks before coding.",
true};
}
AgentRole AgentRolesManager::getDefaultReviewerRole()
{
return AgentRole{
"reviewer",
"Code Reviewer",
"Expert C++/QML code reviewer for quality assurance",
"You are an expert C++/QML code reviewer specializing in C++20 and Qt6.\n\n"
"What you check:\n"
"- Bugs, memory leaks, undefined behavior\n"
"- C++20 compliance and Qt6 patterns\n"
"- RAII, move semantics, smart pointers\n"
"- Qt parent-child ownership and signal/slot correctness\n"
"- Thread safety and Qt concurrent usage\n"
"- const-correctness and Qt container usage\n"
"- Performance bottlenecks\n"
"- Production readiness: error handling, no debug leftovers\n\n"
"What you do:\n"
"- Point out problems with clear explanations\n"
"- Suggest specific fixes with code examples\n"
"- Remove unnecessary comments, keep essential docs only\n"
"- Flag anything that's not production-ready\n"
"- Recommend optimizations when you spot them\n\n"
"Focus on: correctness, performance, maintainability, Qt idioms.\n\n"
"Be direct and specific. Show, don't just tell.",
true};
}
AgentRole AgentRolesManager::getDefaultResearcherRole()
{
return AgentRole{
"researcher",
"Researcher",
"Research-oriented developer for exploring solutions",
"You are a research-oriented Qt/C++ developer who investigates problems and explores "
"solutions.\n\n"
"Your job is to think, not to code:\n"
"- Deep dive into the problem before suggesting anything\n"
"- Research Qt docs, patterns, and best practices\n"
"- Find multiple ways to solve it\n"
"- Compare trade-offs: performance, complexity, maintainability\n"
"- Look for relevant Qt APIs and modules\n"
"- Think about architectural consequences\n\n"
"How you work:\n"
"1. **Problem Analysis** - what exactly needs solving\n"
"2. **Research Findings** - what you learned about this problem space\n"
"3. **Solution Options** - present 2-3 approaches with honest pros/cons\n"
"4. **Recommendation** - which one fits best and why\n"
"5. **Next Steps** - what to consider before implementing\n\n"
"What you provide:\n"
"- Clear comparison of different approaches\n"
"- Code snippets as examples (not ready-to-use patches)\n"
"- Links to docs, examples, similar implementations\n"
"- Questions to clarify requirements\n"
"- Warning about potential problems\n\n"
"You DO NOT write implementation code. You explore options and let the developer choose.\n\n"
"Think like a consultant: research thoroughly, present clearly, stay objective.",
true};
}
} // namespace QodeAssist::Settings

82
settings/AgentRole.hpp Normal file
View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QJsonObject>
#include <QList>
#include <QString>
namespace QodeAssist::Settings {
struct AgentRole
{
QString id;
QString name;
QString description;
QString systemPrompt;
bool isBuiltin = false;
QJsonObject toJson() const
{
return QJsonObject{
{"id", id},
{"name", name},
{"description", description},
{"systemPrompt", systemPrompt},
{"isBuiltin", isBuiltin}};
}
static AgentRole fromJson(const QJsonObject &json)
{
return AgentRole{
json["id"].toString(),
json["name"].toString(),
json["description"].toString(),
json["systemPrompt"].toString(),
json["isBuiltin"].toBool(false)};
}
bool operator==(const AgentRole &other) const { return id == other.id; }
};
class AgentRolesManager
{
public:
static QString getConfigurationDirectory();
static QList<AgentRole> loadAllRoles();
static AgentRole loadRole(const QString &roleId);
static AgentRole loadRoleFromFile(const QString &filePath);
static bool saveRole(const AgentRole &role);
static bool deleteRole(const QString &roleId);
static bool roleExists(const QString &roleId);
static void ensureDefaultRoles();
static AgentRole getNoRole()
{
return AgentRole{"", "No Role", "Use base system prompt without role specialization", "", false};
}
private:
static AgentRole getDefaultDeveloperRole();
static AgentRole getDefaultReviewerRole();
static AgentRole getDefaultResearcherRole();
};
} // namespace QodeAssist::Settings

View File

@@ -0,0 +1,125 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "AgentRoleDialog.hpp"
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
namespace QodeAssist::Settings {
AgentRoleDialog::AgentRoleDialog(Action action, QWidget *parent)
: QDialog{parent}
, m_action{action}
{
auto getTitle = [](Action action) {
switch(action)
{
case Action::Add:
return tr("Add Agent Role");
case Action::Duplicate:
return tr("Duplicate Agent Role");
case Action::Edit:
return tr("Edit Agent Role");
}
};
setWindowTitle(getTitle(action));
setupUI();
}
void AgentRoleDialog::setupUI()
{
auto *mainLayout = new QVBoxLayout(this);
auto *formLayout = new QFormLayout();
m_nameEdit = new QLineEdit(this);
m_nameEdit->setPlaceholderText(tr("e.g., Developer, Code Reviewer"));
formLayout->addRow(tr("Name:"), m_nameEdit);
m_idEdit = new QLineEdit(this);
m_idEdit->setPlaceholderText(tr("e.g., developer, code_reviewer"));
formLayout->addRow(tr("ID:"), m_idEdit);
m_descriptionEdit = new QTextEdit(this);
m_descriptionEdit->setPlaceholderText(tr("Brief description of this role..."));
m_descriptionEdit->setMaximumHeight(80);
formLayout->addRow(tr("Description:"), m_descriptionEdit);
mainLayout->addLayout(formLayout);
auto *promptLabel = new QLabel(tr("System Prompt:"), this);
mainLayout->addWidget(promptLabel);
m_systemPromptEdit = new QTextEdit(this);
m_systemPromptEdit->setPlaceholderText(
tr("You are an expert in...\n\nYour role is to:\n- Task 1\n- Task 2\n- Task 3"));
mainLayout->addWidget(m_systemPromptEdit);
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mainLayout->addWidget(m_buttonBox);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &AgentRoleDialog::accept);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &AgentRoleDialog::reject);
connect(m_nameEdit, &QLineEdit::textChanged, this, &AgentRoleDialog::validateInput);
connect(m_idEdit, &QLineEdit::textChanged, this, &AgentRoleDialog::validateInput);
connect(m_systemPromptEdit, &QTextEdit::textChanged, this, &AgentRoleDialog::validateInput);
if (m_action == Action::Edit) {
m_idEdit->setEnabled(false);
m_idEdit->setToolTip(tr("ID cannot be changed for existing roles"));
}
setMinimumSize(600, 500);
validateInput();
}
void AgentRoleDialog::validateInput()
{
bool valid = !m_nameEdit->text().trimmed().isEmpty()
&& !m_idEdit->text().trimmed().isEmpty()
&& !m_systemPromptEdit->toPlainText().trimmed().isEmpty();
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
AgentRole AgentRoleDialog::getRole() const
{
return AgentRole{
m_idEdit->text().trimmed(),
m_nameEdit->text().trimmed(),
m_descriptionEdit->toPlainText().trimmed(),
m_systemPromptEdit->toPlainText().trimmed(),
false};
}
void AgentRoleDialog::setRole(const AgentRole &role)
{
m_idEdit->setText(role.id);
m_nameEdit->setText(role.name);
m_descriptionEdit->setPlainText(role.description);
m_systemPromptEdit->setPlainText(role.systemPrompt);
}
} // namespace QodeAssist::Settings

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QDialog>
#include "AgentRole.hpp"
class QLineEdit;
class QTextEdit;
class QDialogButtonBox;
namespace QodeAssist::Settings {
class AgentRoleDialog : public QDialog
{
Q_OBJECT
public:
enum class Action {
Add,
Duplicate,
Edit,
};
explicit AgentRoleDialog(Action action, QWidget *parent = nullptr);
explicit AgentRoleDialog(const AgentRole &role, Action action, QWidget *parent = nullptr)
: AgentRoleDialog{action, parent}
{
setRole(role);
}
AgentRole getRole() const;
void setRole(const AgentRole &role);
private:
void setupUI();
void validateInput();
QLineEdit *m_nameEdit = nullptr;
QLineEdit *m_idEdit = nullptr;
QTextEdit *m_descriptionEdit = nullptr;
QTextEdit *m_systemPromptEdit = nullptr;
QDialogButtonBox *m_buttonBox = nullptr;
Action m_action;
};
} // namespace QodeAssist::Settings

View File

@@ -0,0 +1,257 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "AgentRolesWidget.hpp"
#include "AgentRole.hpp"
#include "AgentRoleDialog.hpp"
#include "SettingsTr.hpp"
#include <QDesktopServices>
#include <QHBoxLayout>
#include <QLabel>
#include <QListWidget>
#include <QMessageBox>
#include <QPushButton>
#include <QUrl>
#include <QVBoxLayout>
namespace QodeAssist::Settings {
void AgentRolesWidget::setupUI()
{
auto *mainLayout = new QVBoxLayout(this);
auto *headerLayout = new QHBoxLayout();
auto *infoLabel = new QLabel(
Tr::tr("Agent roles define different system prompts for specific tasks."), this);
infoLabel->setWordWrap(true);
headerLayout->addWidget(infoLabel, 1);
auto *openFolderButton = new QPushButton(Tr::tr("Open Roles Folder..."), this);
connect(openFolderButton, &QPushButton::clicked, this, &AgentRolesWidget::onOpenRolesFolder);
headerLayout->addWidget(openFolderButton);
mainLayout->addLayout(headerLayout);
auto *contentLayout = new QHBoxLayout();
m_rolesList = new QListWidget(this);
m_rolesList->setSelectionMode(QAbstractItemView::SingleSelection);
connect(m_rolesList, &QListWidget::itemSelectionChanged, this, &AgentRolesWidget::updateButtons);
connect(m_rolesList, &QListWidget::itemDoubleClicked, this, &AgentRolesWidget::onEditRole);
contentLayout->addWidget(m_rolesList, 1);
auto *buttonsLayout = new QVBoxLayout();
m_addButton = new QPushButton(Tr::tr("Add..."), this);
connect(m_addButton, &QPushButton::clicked, this, &AgentRolesWidget::onAddRole);
buttonsLayout->addWidget(m_addButton);
m_editButton = new QPushButton(Tr::tr("Edit..."), this);
connect(m_editButton, &QPushButton::clicked, this, &AgentRolesWidget::onEditRole);
buttonsLayout->addWidget(m_editButton);
m_duplicateButton = new QPushButton(Tr::tr("Duplicate..."), this);
connect(m_duplicateButton, &QPushButton::clicked, this, &AgentRolesWidget::onDuplicateRole);
buttonsLayout->addWidget(m_duplicateButton);
m_deleteButton = new QPushButton(Tr::tr("Delete"), this);
connect(m_deleteButton, &QPushButton::clicked, this, &AgentRolesWidget::onDeleteRole);
buttonsLayout->addWidget(m_deleteButton);
buttonsLayout->addStretch();
contentLayout->addLayout(buttonsLayout);
mainLayout->addLayout(contentLayout);
updateButtons();
}
void AgentRolesWidget::loadRoles()
{
m_rolesList->clear();
const QList<AgentRole> roles = AgentRolesManager::loadAllRoles();
for (const AgentRole &role : roles) {
auto *item = new QListWidgetItem(role.name, m_rolesList);
item->setData(Qt::UserRole, role.id);
QString tooltip = role.description;
if (role.isBuiltin) {
tooltip += "\n\n" + Tr::tr("(Built-in role)");
item->setForeground(Qt::darkGray);
}
item->setToolTip(tooltip);
}
}
void AgentRolesWidget::updateButtons()
{
QListWidgetItem *selectedItem = m_rolesList->currentItem();
bool hasSelection = selectedItem != nullptr;
bool isBuiltin = false;
if (hasSelection) {
QString roleId = selectedItem->data(Qt::UserRole).toString();
AgentRole role = AgentRolesManager::loadRole(roleId);
isBuiltin = role.isBuiltin;
}
m_editButton->setEnabled(hasSelection);
m_duplicateButton->setEnabled(hasSelection);
m_deleteButton->setEnabled(hasSelection && !isBuiltin);
}
void AgentRolesWidget::onAddRole()
{
AgentRoleDialog dialog{AgentRoleDialog::Action::Add, this};
if (dialog.exec() != QDialog::Accepted)
return;
AgentRole newRole = dialog.getRole();
if (AgentRolesManager::roleExists(newRole.id)) {
QMessageBox::warning(
this,
Tr::tr("Role Already Exists"),
Tr::tr("A role with ID '%1' already exists. Please use a different ID.")
.arg(newRole.id));
return;
}
if (AgentRolesManager::saveRole(newRole)) {
loadRoles();
} else {
QMessageBox::critical(
this, Tr::tr("Error"), Tr::tr("Failed to save role '%1'.").arg(newRole.name));
}
}
void AgentRolesWidget::onEditRole()
{
QListWidgetItem *selectedItem = m_rolesList->currentItem();
if (!selectedItem)
return;
QString roleId = selectedItem->data(Qt::UserRole).toString();
AgentRole role = AgentRolesManager::loadRole(roleId);
if (role.isBuiltin) {
QMessageBox::information(
this,
Tr::tr("Cannot Edit Built-in Role"),
Tr::tr(
"Built-in roles cannot be edited. You can duplicate this role and modify the copy."));
return;
}
AgentRoleDialog dialog{role, AgentRoleDialog::Action::Edit, this};
if (dialog.exec() != QDialog::Accepted)
return;
AgentRole updatedRole = dialog.getRole();
if (AgentRolesManager::saveRole(updatedRole)) {
loadRoles();
} else {
QMessageBox::critical(
this, Tr::tr("Error"), Tr::tr("Failed to update role '%1'.").arg(updatedRole.name));
}
}
void AgentRolesWidget::onDuplicateRole()
{
QListWidgetItem *selectedItem = m_rolesList->currentItem();
if (!selectedItem)
return;
QString roleId = selectedItem->data(Qt::UserRole).toString();
AgentRole role = AgentRolesManager::loadRole(roleId);
role.name += " (Copy)";
role.id += "_copy";
role.isBuiltin = false;
int counter = 1;
QString baseId = role.id;
while (AgentRolesManager::roleExists(role.id)) {
role.id = baseId + QString::number(counter++);
}
AgentRoleDialog dialog{role, AgentRoleDialog::Action::Duplicate, this};
if (dialog.exec() != QDialog::Accepted)
return;
AgentRole newRole = dialog.getRole();
if (AgentRolesManager::roleExists(newRole.id)) {
QMessageBox::warning(
this,
Tr::tr("Role Already Exists"),
Tr::tr("A role with ID '%1' already exists. Please use a different ID.")
.arg(newRole.id));
return;
}
if (AgentRolesManager::saveRole(newRole)) {
loadRoles();
} else {
QMessageBox::critical(this, Tr::tr("Error"), Tr::tr("Failed to duplicate role."));
}
}
void AgentRolesWidget::onDeleteRole()
{
QListWidgetItem *selectedItem = m_rolesList->currentItem();
if (!selectedItem)
return;
QString roleId = selectedItem->data(Qt::UserRole).toString();
AgentRole role = AgentRolesManager::loadRole(roleId);
if (role.isBuiltin) {
QMessageBox::information(
this, Tr::tr("Cannot Delete Built-in Role"), Tr::tr("Built-in roles cannot be deleted."));
return;
}
QMessageBox::StandardButton reply = QMessageBox::question(
this,
Tr::tr("Delete Role"),
Tr::tr("Are you sure you want to delete the role '%1'?").arg(role.name),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
if (AgentRolesManager::deleteRole(roleId)) {
loadRoles();
} else {
QMessageBox::critical(
this, Tr::tr("Error"), Tr::tr("Failed to delete role '%1'.").arg(role.name));
}
}
}
void AgentRolesWidget::onOpenRolesFolder()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(AgentRolesManager::getConfigurationDirectory()));
}
} // namespace QodeAssist::Settings

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
class QListWidget;
class QPushButton;
namespace QodeAssist::Settings {
class AgentRolesWidget : public Core::IOptionsPageWidget
{
Q_OBJECT
public:
explicit AgentRolesWidget()
{
setupUI();
loadRoles();
}
private:
void setupUI();
void loadRoles();
void updateButtons();
void onAddRole();
void onEditRole();
void onDuplicateRole();
void onDeleteRole();
void onOpenRolesFolder();
QListWidget *m_rolesList = nullptr;
QPushButton *m_addButton = nullptr;
QPushButton *m_editButton = nullptr;
QPushButton *m_duplicateButton = nullptr;
QPushButton *m_deleteButton = nullptr;
};
} // namespace QodeAssist::Settings

View File

@@ -16,11 +16,15 @@ add_library(QodeAssistSettings STATIC
ProviderSettings.hpp ProviderSettings.cpp
PluginUpdater.hpp PluginUpdater.cpp
UpdateDialog.hpp UpdateDialog.cpp
AgentRole.hpp AgentRole.cpp
AgentRoleDialog.hpp AgentRoleDialog.cpp
AgentRolesWidget.hpp AgentRolesWidget.cpp
)
target_link_libraries(QodeAssistSettings
PUBLIC
Qt::Core
Qt::Widgets
Qt::Network
QtCreator::Core
QtCreator::Utils

View File

@@ -29,6 +29,7 @@
#include "SettingsConstants.hpp"
#include "SettingsTr.hpp"
#include "SettingsUtils.hpp"
#include "AgentRolesWidget.hpp"
namespace QodeAssist::Settings {
@@ -262,6 +263,9 @@ ChatAssistantSettings::ChatAssistantSettings()
chatRenderer.setDefaultValue("rhi");
#endif
lastUsedRoleId.setSettingsKey(Constants::CA_LAST_USED_ROLE);
lastUsedRoleId.setDefaultValue("");
resetToDefaults.m_buttonText = TrConstants::RESET_TO_DEFAULTS;
readSettings();
@@ -405,4 +409,18 @@ public:
const ChatAssistantSettingsPage chatAssistantSettingsPage;
class AgentRolesSettingsPage : public Core::IOptionsPage
{
public:
AgentRolesSettingsPage()
{
setId("QodeAssist.AgentRoles");
setDisplayName(Tr::tr("Agent Roles"));
setCategory(Constants::QODE_ASSIST_GENERAL_OPTIONS_CATEGORY);
setWidgetCreator([]() { return new AgentRolesWidget(); });
}
};
const AgentRolesSettingsPage agentRolesSettingsPage;
} // namespace QodeAssist::Settings

View File

@@ -21,6 +21,7 @@
#include <utils/aspects.h>
#include "AgentRole.hpp"
#include "ButtonAspect.hpp"
namespace QodeAssist::Settings {
@@ -82,6 +83,8 @@ public:
Utils::SelectionAspect chatRenderer{this};
Utils::StringAspect lastUsedRoleId{this};
private:
void setupConnections();
void resetSettingsToDefaults();

View File

@@ -43,6 +43,106 @@ ConfigurationManager &ConfigurationManager::instance()
return instance;
}
QVector<AIConfiguration> ConfigurationManager::getPredefinedConfigurations(
ConfigurationType type)
{
QVector<AIConfiguration> presets;
AIConfiguration claudeOpus;
claudeOpus.id = "preset_claude_opus";
claudeOpus.name = "Claude Opus 4.6";
claudeOpus.provider = "Claude";
claudeOpus.model = "claude-opus-4-6";
claudeOpus.url = "https://api.anthropic.com";
claudeOpus.endpointMode = "Auto";
claudeOpus.customEndpoint = "";
claudeOpus.templateName = "Claude";
claudeOpus.type = type;
claudeOpus.isPredefined = true;
AIConfiguration claudeSonnet;
claudeSonnet.id = "preset_claude_sonnet";
claudeSonnet.name = "Claude Sonnet 4.6";
claudeSonnet.provider = "Claude";
claudeSonnet.model = "claude-sonnet-4-6";
claudeSonnet.url = "https://api.anthropic.com";
claudeSonnet.endpointMode = "Auto";
claudeSonnet.customEndpoint = "";
claudeSonnet.templateName = "Claude";
claudeSonnet.type = type;
claudeSonnet.isPredefined = true;
AIConfiguration claudeHaiku;
claudeHaiku.id = "preset_claude_haiku";
claudeHaiku.name = "Claude Haiku 4.5";
claudeHaiku.provider = "Claude";
claudeHaiku.model = "claude-haiku-4-5-20251001";
claudeHaiku.url = "https://api.anthropic.com";
claudeHaiku.endpointMode = "Auto";
claudeHaiku.customEndpoint = "";
claudeHaiku.templateName = "Claude";
claudeHaiku.type = type;
claudeHaiku.isPredefined = true;
AIConfiguration codestral;
codestral.id = "preset_codestral";
codestral.name = "Codestral";
codestral.provider = "Codestral";
codestral.model = "codestral-latest";
codestral.url = "https://codestral.mistral.ai";
codestral.endpointMode = "Auto";
codestral.customEndpoint = "";
codestral.templateName = type == ConfigurationType::CodeCompletion ? "Mistral AI FIM" : "Mistral AI Chat";
codestral.type = type;
codestral.isPredefined = true;
AIConfiguration mistral;
mistral.id = "preset_mistral";
mistral.name = "Mistral";
mistral.provider = "Mistral AI";
mistral.model = type == ConfigurationType::CodeCompletion ? "mistral-medium-latest" : "mistral-large-latest";
mistral.url = "https://api.mistral.ai";
mistral.endpointMode = "Auto";
mistral.customEndpoint = "";
mistral.templateName = type == ConfigurationType::CodeCompletion ? "Mistral AI FIM" : "Mistral AI Chat";
mistral.type = type;
mistral.isPredefined = true;
AIConfiguration geminiFlash;
geminiFlash.id = "preset_gemini_flash";
geminiFlash.name = "Gemini 2.5 Flash";
geminiFlash.provider = "Google AI";
geminiFlash.model = "gemini-2.5-flash";
geminiFlash.url = "https://generativelanguage.googleapis.com/v1beta";
geminiFlash.endpointMode = "Auto";
geminiFlash.customEndpoint = "";
geminiFlash.templateName = "Google AI";
geminiFlash.type = type;
geminiFlash.isPredefined = true;
AIConfiguration gpt;
gpt.id = "preset_gpt";
gpt.name = "gpt-5.4";
gpt.provider = "OpenAI Responses";
gpt.model = "gpt-5.4";
gpt.url = "https://api.openai.com";
gpt.endpointMode = "Auto";
gpt.customEndpoint = "";
gpt.templateName = "OpenAI Responses";
gpt.type = type;
gpt.isPredefined = true;
presets.append(claudeSonnet);
presets.append(claudeHaiku);
presets.append(claudeOpus);
presets.append(gpt);
presets.append(codestral);
presets.append(mistral);
presets.append(geminiFlash);
return presets;
}
QString ConfigurationManager::configurationTypeToString(ConfigurationType type) const
{
switch (type) {
@@ -94,6 +194,9 @@ bool ConfigurationManager::loadConfigurations(ConfigurationType type)
configs->clear();
QVector<AIConfiguration> predefinedConfigs = getPredefinedConfigurations(type);
configs->append(predefinedConfigs);
if (!ensureDirectoryExists(type)) {
LOG_MESSAGE("Failed to create configuration directory");
return false;
@@ -131,6 +234,7 @@ bool ConfigurationManager::loadConfigurations(ConfigurationType type)
config.customEndpoint = obj["customEndpoint"].toString();
config.type = type;
config.formatVersion = obj.value("formatVersion").toInt(1);
config.isPredefined = false;
if (config.id.isEmpty() || config.name.isEmpty()) {
LOG_MESSAGE(QString("Invalid configuration data in file: %1").arg(fileInfo.fileName()));
@@ -185,6 +289,12 @@ bool ConfigurationManager::saveConfiguration(const AIConfiguration &config)
bool ConfigurationManager::deleteConfiguration(const QString &id, ConfigurationType type)
{
AIConfiguration config = getConfigurationById(id, type);
if (config.isPredefined) {
LOG_MESSAGE(QString("Cannot delete predefined configuration: %1").arg(id));
return false;
}
QDir dir(getConfigurationDirectory(type));
QStringList filters;
filters << QString("*_%1.json").arg(id);

View File

@@ -41,6 +41,7 @@ struct AIConfiguration
QString customEndpoint;
ConfigurationType type;
int formatVersion = CONFIGURATION_FORMAT_VERSION;
bool isPredefined = false;
};
class ConfigurationManager : public QObject
@@ -59,6 +60,8 @@ public:
QString getConfigurationDirectory(ConfigurationType type) const;
static QVector<AIConfiguration> getPredefinedConfigurations(ConfigurationType type);
signals:
void configurationsChanged(ConfigurationType type);

View File

@@ -23,6 +23,7 @@
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <utils/utilsicons.h>
#include <QComboBox>
#include <QDesktopServices>
#include <QDir>
#include <QInputDialog>
@@ -89,6 +90,27 @@ GeneralSettings::GeneralSettings()
resetToDefaults.m_buttonText = TrConstants::RESET_TO_DEFAULTS;
checkUpdate.m_buttonText = TrConstants::CHECK_UPDATE;
ccPresetConfig.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
ccPresetConfig.setLabelText(Tr::tr("Quick Setup"));
loadPresetConfigurations(ccPresetConfig, ConfigurationType::CodeCompletion);
ccConfigureApiKey.m_buttonText = Tr::tr("Configure API Key");
ccConfigureApiKey.m_tooltip = Tr::tr("Open Provider Settings to configure API keys");
caPresetConfig.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
caPresetConfig.setLabelText(Tr::tr("Quick Setup"));
loadPresetConfigurations(caPresetConfig, ConfigurationType::Chat);
caConfigureApiKey.m_buttonText = Tr::tr("Configure API Key");
caConfigureApiKey.m_tooltip = Tr::tr("Open Provider Settings to configure API keys");
qrPresetConfig.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
qrPresetConfig.setLabelText(Tr::tr("Quick Setup"));
loadPresetConfigurations(qrPresetConfig, ConfigurationType::QuickRefactor);
qrConfigureApiKey.m_buttonText = Tr::tr("Configure API Key");
qrConfigureApiKey.m_tooltip = Tr::tr("Open Provider Settings to configure API keys");
initStringAspect(ccProvider, Constants::CC_PROVIDER, TrConstants::PROVIDER, "Ollama");
ccProvider.setReadOnly(true);
ccSelectProvider.m_buttonText = TrConstants::SELECT;
@@ -127,6 +149,7 @@ GeneralSettings::GeneralSettings()
ccSaveConfig.m_buttonText = TrConstants::SAVE_CONFIG;
ccLoadConfig.m_buttonText = TrConstants::LOAD_CONFIG;
ccLoadConfig.m_tooltip = Tr::tr("Load configuration (includes predefined cloud models)");
ccOpenConfigFolder.m_buttonText = TrConstants::OPEN_CONFIG_FOLDER;
ccOpenConfigFolder.m_icon = Utils::Icons::OPENFILE.icon();
ccOpenConfigFolder.m_isCompact = true;
@@ -218,6 +241,7 @@ GeneralSettings::GeneralSettings()
caSaveConfig.m_buttonText = TrConstants::SAVE_CONFIG;
caLoadConfig.m_buttonText = TrConstants::LOAD_CONFIG;
caLoadConfig.m_tooltip = Tr::tr("Load configuration (includes predefined cloud models)");
caOpenConfigFolder.m_buttonText = TrConstants::OPEN_CONFIG_FOLDER;
caOpenConfigFolder.m_icon = Utils::Icons::OPENFILE.icon();
caOpenConfigFolder.m_isCompact = true;
@@ -262,6 +286,7 @@ GeneralSettings::GeneralSettings()
qrSaveConfig.m_buttonText = TrConstants::SAVE_CONFIG;
qrLoadConfig.m_buttonText = TrConstants::LOAD_CONFIG;
qrLoadConfig.m_tooltip = Tr::tr("Load configuration (includes predefined cloud models)");
qrOpenConfigFolder.m_buttonText = TrConstants::OPEN_CONFIG_FOLDER;
qrOpenConfigFolder.m_icon = Utils::Icons::OPENFILE.icon();
qrOpenConfigFolder.m_isCompact = true;
@@ -325,17 +350,24 @@ GeneralSettings::GeneralSettings()
title(TrConstants::CODE_COMPLETION),
Column{
Row{ccSaveConfig, ccLoadConfig, ccOpenConfigFolder, Stretch{1}},
Row{ccPresetConfig, ccConfigureApiKey, Stretch{1}},
ccGrid,
Row{specifyPreset1, preset1Language, Stretch{1}},
ccPreset1Grid}};
auto caGroup = Group{
title(TrConstants::CHAT_ASSISTANT),
Column{Row{caSaveConfig, caLoadConfig, caOpenConfigFolder, Stretch{1}}, caGrid}};
Column{
Row{caSaveConfig, caLoadConfig, caOpenConfigFolder, Stretch{1}},
Row{caPresetConfig, caConfigureApiKey, Stretch{1}},
caGrid}};
auto qrGroup = Group{
title(TrConstants::QUICK_REFACTOR),
Column{Row{qrSaveConfig, qrLoadConfig, qrOpenConfigFolder, Stretch{1}}, qrGrid}};
Column{
Row{qrSaveConfig, qrLoadConfig, qrOpenConfigFolder, Stretch{1}},
Row{qrPresetConfig, qrConfigureApiKey, Stretch{1}},
qrGrid}};
auto rootLayout = Column{
Row{enableQodeAssist, Stretch{1}, Row{checkUpdate, resetToDefaults}},
@@ -420,7 +452,7 @@ void GeneralSettings::showModelsNotFoundDialog(Utils::StringAspect &aspect)
connect(configureApiKeyBtn, &QPushButton::clicked, &dialog, [&dialog]() {
dialog.close();
Core::ICore::showOptionsDialog(Constants::QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID);
Settings::showSettings(Constants::QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID);
});
dialog.buttonLayout()->addWidget(selectProviderBtn);
@@ -571,6 +603,33 @@ void GeneralSettings::setupConnections()
QodeAssist::UpdateDialog::checkForUpdatesAndShow(Core::ICore::dialogParent());
});
connect(&ccPresetConfig, &Utils::SelectionAspect::volatileValueChanged, this, [this]() {
applyPresetConfiguration(ccPresetConfig.volatileValue(), ConfigurationType::CodeCompletion);
ccPresetConfig.setValue(0);
});
connect(&ccConfigureApiKey, &ButtonAspect::clicked, this, []() {
Settings::showSettings(Constants::QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID);
});
connect(&caPresetConfig, &Utils::SelectionAspect::volatileValueChanged, this, [this]() {
applyPresetConfiguration(caPresetConfig.volatileValue(), ConfigurationType::Chat);
caPresetConfig.setValue(0);
});
connect(&caConfigureApiKey, &ButtonAspect::clicked, this, []() {
Settings::showSettings(Constants::QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID);
});
connect(&qrPresetConfig, &Utils::SelectionAspect::volatileValueChanged, this, [this]() {
applyPresetConfiguration(qrPresetConfig.volatileValue(), ConfigurationType::QuickRefactor);
qrPresetConfig.setValue(0);
});
connect(&qrConfigureApiKey, &ButtonAspect::clicked, this, []() {
Settings::showSettings(Constants::QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID);
});
connect(&specifyPreset1, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
updatePreset1Visiblity(specifyPreset1.volatileValue());
});
@@ -776,11 +835,33 @@ void GeneralSettings::onLoadConfiguration(const QString &prefix)
SettingsDialog dialog(TrConstants::LOAD_CONFIGURATION);
dialog.addLabel(TrConstants::SELECT_CONFIGURATION);
int predefinedCount = 0;
for (const AIConfiguration &config : configs) {
if (config.isPredefined) {
predefinedCount++;
}
}
if (predefinedCount > 0) {
auto *hintLabel = dialog.addLabel(
Tr::tr("[Preset] configurations are predefined cloud models ready to use."));
QFont hintFont = hintLabel->font();
hintFont.setItalic(true);
hintFont.setPointSize(hintFont.pointSize() - 1);
hintLabel->setFont(hintFont);
hintLabel->setStyleSheet("color: gray;");
}
dialog.addSpacing();
QStringList configNames;
for (const AIConfiguration &config : configs) {
configNames.append(config.name);
QString displayName = config.name;
if (config.isPredefined) {
displayName = QString("[Preset] %1").arg(config.name);
}
configNames.append(displayName);
}
auto configList = dialog.addComboBox(configNames, QString());
@@ -790,9 +871,31 @@ void GeneralSettings::onLoadConfiguration(const QString &prefix)
auto *okButton = new QPushButton(TrConstants::OK);
auto *cancelButton = new QPushButton(TrConstants::CANCEL);
auto updateDeleteButtonState = [&]() {
int currentIndex = configList->currentIndex();
if (currentIndex >= 0 && currentIndex < configs.size()) {
deleteButton->setEnabled(!configs[currentIndex].isPredefined);
}
};
connect(configList,
QOverload<int>::of(&QComboBox::currentIndexChanged),
updateDeleteButtonState);
updateDeleteButtonState();
connect(deleteButton, &QPushButton::clicked, &dialog, [&]() {
int currentIndex = configList->currentIndex();
if (currentIndex >= 0 && currentIndex < configs.size()) {
const AIConfiguration &configToDelete = configs[currentIndex];
if (configToDelete.isPredefined) {
QMessageBox::information(
&dialog,
TrConstants::DELETE_CONFIGURATION,
Tr::tr("Predefined configurations cannot be deleted."));
return;
}
QMessageBox::StandardButton reply = QMessageBox::question(
&dialog,
TrConstants::DELETE_CONFIGURATION,
@@ -800,7 +903,6 @@ void GeneralSettings::onLoadConfiguration(const QString &prefix)
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
const AIConfiguration &configToDelete = configs[currentIndex];
if (manager.deleteConfiguration(configToDelete.id, type)) {
dialog.accept();
onLoadConfiguration(prefix);
@@ -860,6 +962,73 @@ void GeneralSettings::onLoadConfiguration(const QString &prefix)
dialog.exec();
}
void GeneralSettings::loadPresetConfigurations(Utils::SelectionAspect &aspect,
ConfigurationType type)
{
QVector<AIConfiguration> presets = ConfigurationManager::getPredefinedConfigurations(type);
if (type == ConfigurationType::CodeCompletion) {
m_ccPresets = presets;
} else if (type == ConfigurationType::Chat) {
m_caPresets = presets;
} else if (type == ConfigurationType::QuickRefactor) {
m_qrPresets = presets;
}
aspect.addOption(Tr::tr("-- Select Preset --"));
for (const AIConfiguration &config : presets) {
aspect.addOption(config.name);
}
aspect.setDefaultValue(0);
}
void GeneralSettings::applyPresetConfiguration(int index, ConfigurationType type)
{
if (index <= 0) {
return;
}
QVector<AIConfiguration> *presets = nullptr;
if (type == ConfigurationType::CodeCompletion) {
presets = &m_ccPresets;
} else if (type == ConfigurationType::Chat) {
presets = &m_caPresets;
} else if (type == ConfigurationType::QuickRefactor) {
presets = &m_qrPresets;
}
if (!presets || index - 1 >= presets->size()) {
return;
}
const AIConfiguration &config = presets->at(index - 1);
if (type == ConfigurationType::CodeCompletion) {
ccProvider.setValue(config.provider);
ccModel.setValue(config.model);
ccTemplate.setValue(config.templateName);
ccUrl.setValue(config.url);
ccEndpointMode.setValue(ccEndpointMode.indexForDisplay(config.endpointMode));
ccCustomEndpoint.setValue(config.customEndpoint);
} else if (type == ConfigurationType::Chat) {
caProvider.setValue(config.provider);
caModel.setValue(config.model);
caTemplate.setValue(config.templateName);
caUrl.setValue(config.url);
caEndpointMode.setValue(caEndpointMode.indexForDisplay(config.endpointMode));
caCustomEndpoint.setValue(config.customEndpoint);
} else if (type == ConfigurationType::QuickRefactor) {
qrProvider.setValue(config.provider);
qrModel.setValue(config.model);
qrTemplate.setValue(config.templateName);
qrUrl.setValue(config.url);
qrEndpointMode.setValue(qrEndpointMode.indexForDisplay(config.endpointMode));
qrCustomEndpoint.setValue(config.customEndpoint);
}
writeSettings();
}
class GeneralSettingsPage : public Core::IOptionsPage
{
public:
@@ -877,5 +1046,29 @@ public:
};
const GeneralSettingsPage generalSettingsPage;
/*!
\sa {Core::ICore::showOptionsDialog()}, {Core::ICore::showSettings()}
\note This function was added to fix Qt Creator API broken changes in v19.0.0-beta2 version
*/
void showSettings(const Utils::Id page)
{
#if QODEASSIST_QT_CREATOR_VERSION >= QT_VERSION_CHECK(18, 0, 83)
Core::ICore::showSettings(page);
#else
Core::ICore::showOptionsDialog(page);
#endif
}
/*!
\sa {Core::ICore::showOptionsDialog()}, {Core::ICore::showSettings()}
\note This function was added to fix Qt Creator API broken changes in v19.0.0-beta2 version
*/
void showSettings(const Utils::Id page, Utils::Id item)
{
#if QODEASSIST_QT_CREATOR_VERSION >= QT_VERSION_CHECK(18, 0, 83)
Core::ICore::showSettings(page, item);
#else
Core::ICore::showOptionsDialog(page, item);
#endif
}
} // namespace QodeAssist::Settings

View File

@@ -23,6 +23,7 @@
#include <QPointer>
#include "ButtonAspect.hpp"
#include "ConfigurationManager.hpp"
namespace Utils {
class DetailsWidget;
@@ -46,6 +47,9 @@ public:
ButtonAspect resetToDefaults{this};
// code completion setttings
Utils::SelectionAspect ccPresetConfig{this};
ButtonAspect ccConfigureApiKey{this};
Utils::StringAspect ccProvider{this};
ButtonAspect ccSelectProvider{this};
@@ -91,6 +95,9 @@ public:
ButtonAspect ccPreset1SelectTemplate{this};
// chat assistant settings
Utils::SelectionAspect caPresetConfig{this};
ButtonAspect caConfigureApiKey{this};
Utils::StringAspect caProvider{this};
ButtonAspect caSelectProvider{this};
@@ -116,6 +123,9 @@ public:
ButtonAspect caOpenConfigFolder{this};
// quick refactor settings
Utils::SelectionAspect qrPresetConfig{this};
ButtonAspect qrConfigureApiKey{this};
Utils::StringAspect qrProvider{this};
ButtonAspect qrSelectProvider{this};
@@ -163,11 +173,21 @@ public:
void onSaveConfiguration(const QString &prefix);
void onLoadConfiguration(const QString &prefix);
void loadPresetConfigurations(Utils::SelectionAspect &aspect, ConfigurationType type);
void applyPresetConfiguration(int index, ConfigurationType type);
private:
void setupConnections();
void resetPageToDefaults();
QVector<AIConfiguration> m_ccPresets;
QVector<AIConfiguration> m_caPresets;
QVector<AIConfiguration> m_qrPresets;
};
GeneralSettings &generalSettings();
void showSettings(const Utils::Id page);
void showSettings(const Utils::Id page, Utils::Id item);
} // namespace QodeAssist::Settings

View File

@@ -111,10 +111,12 @@ const char CA_ALLOW_ACCESS_OUTSIDE_PROJECT[] = "QodeAssist.caAllowAccessOutsideP
const char CA_ENABLE_EDIT_FILE_TOOL[] = "QodeAssist.caEnableEditFileTool";
const char CA_ENABLE_BUILD_PROJECT_TOOL[] = "QodeAssist.caEnableBuildProjectTool";
const char CA_ENABLE_TERMINAL_COMMAND_TOOL[] = "QodeAssist.caEnableTerminalCommandTool";
const char CA_ENABLE_TODO_TOOL[] = "QodeAssist.caEnableTodoTool";
const char CA_ALLOWED_TERMINAL_COMMANDS[] = "QodeAssist.caAllowedTerminalCommands";
const char CA_ALLOWED_TERMINAL_COMMANDS_LINUX[] = "QodeAssist.caAllowedTerminalCommandsLinux";
const char CA_ALLOWED_TERMINAL_COMMANDS_MACOS[] = "QodeAssist.caAllowedTerminalCommandsMacOS";
const char CA_ALLOWED_TERMINAL_COMMANDS_WINDOWS[] = "QodeAssist.caAllowedTerminalCommandsWindows";
const char CA_TERMINAL_COMMAND_TIMEOUT[] = "QodeAssist.caTerminalCommandTimeout";
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
@@ -208,6 +210,8 @@ const char CA_CODE_FONT_SIZE[] = "QodeAssist.caCodeFontSize";
const char CA_TEXT_FORMAT[] = "QodeAssist.caTextFormat";
const char CA_CHAT_RENDERER[] = "QodeAssist.caChatRenderer";
const char CA_LAST_USED_ROLE[] = "QodeAssist.caLastUsedRole";
// quick refactor preset prompt settings
const char QR_TEMPERATURE[] = "QodeAssist.qrTemperature";
const char QR_MAX_TOKENS[] = "QodeAssist.qrMaxTokens";

View File

@@ -97,6 +97,13 @@ ToolsSettings::ToolsSettings()
"unexpected behavior."));
enableTerminalCommandTool.setDefaultValue(false);
enableTodoTool.setSettingsKey(Constants::CA_ENABLE_TODO_TOOL);
enableTodoTool.setLabelText(Tr::tr("Enable Todo Tool"));
enableTodoTool.setToolTip(
Tr::tr("Enable the todo_tool that helps AI track and organize multi-step tasks. "
"Useful for complex refactoring, debugging, and feature implementation workflows."));
enableTodoTool.setDefaultValue(true);
allowedTerminalCommandsLinux.setSettingsKey(Constants::CA_ALLOWED_TERMINAL_COMMANDS_LINUX);
allowedTerminalCommandsLinux.setLabelText(Tr::tr("Allowed Commands (Linux)"));
allowedTerminalCommandsLinux.setToolTip(
@@ -121,6 +128,14 @@ ToolsSettings::ToolsSettings()
allowedTerminalCommandsWindows.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
allowedTerminalCommandsWindows.setDefaultValue("git, dir, type, findstr, where");
terminalCommandTimeout.setSettingsKey(Constants::CA_TERMINAL_COMMAND_TIMEOUT);
terminalCommandTimeout.setLabelText(Tr::tr("Command Timeout (seconds)"));
terminalCommandTimeout.setToolTip(
Tr::tr("Maximum time in seconds to wait for a terminal command to complete. "
"Increase for long-running commands like builds."));
terminalCommandTimeout.setRange(5, 3600);
terminalCommandTimeout.setDefaultValue(30);
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
readSettings();
@@ -158,7 +173,9 @@ ToolsSettings::ToolsSettings()
enableEditFileTool,
enableBuildProjectTool,
enableTerminalCommandTool,
enableTodoTool,
currentOsCommands,
terminalCommandTimeout,
autoApplyFileEdits}},
Stretch{1}};
});
@@ -191,9 +208,11 @@ void ToolsSettings::resetSettingsToDefaults()
resetAspect(enableEditFileTool);
resetAspect(enableBuildProjectTool);
resetAspect(enableTerminalCommandTool);
resetAspect(enableTodoTool);
resetAspect(allowedTerminalCommandsLinux);
resetAspect(allowedTerminalCommandsMacOS);
resetAspect(allowedTerminalCommandsWindows);
resetAspect(terminalCommandTimeout);
writeSettings();
}
}

View File

@@ -41,9 +41,11 @@ public:
Utils::BoolAspect enableEditFileTool{this};
Utils::BoolAspect enableBuildProjectTool{this};
Utils::BoolAspect enableTerminalCommandTool{this};
Utils::BoolAspect enableTodoTool{this};
Utils::StringAspect allowedTerminalCommandsLinux{this};
Utils::StringAspect allowedTerminalCommandsMacOS{this};
Utils::StringAspect allowedTerminalCommandsWindows{this};
Utils::IntegerAspect terminalCommandTimeout{this};
Utils::BoolAspect autoApplyFileEdits{this};
private:

View File

@@ -80,7 +80,10 @@ public:
return true;
}
QList<QString> getInstalledModels(const QString &url) override { return {}; }
QFuture<QList<QString>> getInstalledModels(const QString &) override
{
return QtFuture::makeReadyFuture(QList<QString>{});
}
QStringList validateRequest(
const QJsonObject &request, LLMCore::TemplateType templateType) override

View File

@@ -32,6 +32,8 @@
#include <QSharedPointer>
#include <QTimer>
#include <atomic>
namespace QodeAssist::Tools {
ExecuteTerminalCommandTool::ExecuteTerminalCommandTool(QObject *parent)
@@ -188,54 +190,66 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
QFuture<QString> future = promise->future();
promise->start();
auto resolved = std::make_shared<std::atomic<bool>>(false);
QProcess *process = new QProcess();
process->setWorkingDirectory(workingDir);
process->setProcessChannelMode(QProcess::MergedChannels);
process->setReadChannel(QProcess::StandardOutput);
const int timeoutMs = commandTimeoutMs();
QTimer *timeoutTimer = new QTimer();
timeoutTimer->setSingleShot(true);
timeoutTimer->setInterval(COMMAND_TIMEOUT_MS);
timeoutTimer->setInterval(timeoutMs);
auto outputSize = QSharedPointer<qint64>::create(0);
QObject::connect(timeoutTimer, &QTimer::timeout, [process, promise, resolved, command, args, timeoutTimer, timeoutMs]() {
if (*resolved)
return;
*resolved = true;
QObject::connect(timeoutTimer, &QTimer::timeout, [process, promise, command, args, timeoutTimer]() {
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Command '%1 %2' timed out after %3ms")
.arg(command)
.arg(args)
.arg(COMMAND_TIMEOUT_MS));
.arg(timeoutMs));
process->terminate();
QTimer::singleShot(1000, process, [process]() {
if (process->state() == QProcess::Running) {
if (process->state() != QProcess::NotRunning) {
LOG_MESSAGE("ExecuteTerminalCommandTool: Forcefully killing process after timeout");
process->kill();
}
process->deleteLater();
});
promise->addResult(QString("Error: Command '%1 %2' timed out after %3 seconds. "
"The process has been terminated.")
.arg(command)
.arg(args.isEmpty() ? "" : args)
.arg(COMMAND_TIMEOUT_MS / 1000));
.arg(timeoutMs / 1000));
promise->finish();
process->deleteLater();
timeoutTimer->deleteLater();
});
QObject::connect(
process,
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[this, process, promise, command, args, timeoutTimer, outputSize](
[this, process, promise, resolved, command, args, timeoutTimer](
int exitCode, QProcess::ExitStatus exitStatus) {
if (*resolved) {
process->deleteLater();
return;
}
*resolved = true;
timeoutTimer->stop();
timeoutTimer->deleteLater();
const QByteArray rawOutput = process->readAll();
*outputSize += rawOutput.size();
const QString output = sanitizeOutput(QString::fromUtf8(rawOutput), *outputSize);
const qint64 outputSize = rawOutput.size();
const QString output = sanitizeOutput(QString::fromUtf8(rawOutput), outputSize);
const QString fullCommand = args.isEmpty() ? command : QString("%1 %2").arg(command).arg(args);
@@ -244,7 +258,7 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Command '%1' completed "
"successfully (output size: %2 bytes)")
.arg(fullCommand)
.arg(*outputSize));
.arg(outputSize));
promise->addResult(
QString("Command '%1' executed successfully.\n\nOutput:\n%2")
.arg(fullCommand)
@@ -254,7 +268,7 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
"exit code %2 (output size: %3 bytes)")
.arg(fullCommand)
.arg(exitCode)
.arg(*outputSize));
.arg(outputSize));
promise->addResult(
QString("Command '%1' failed with exit code %2.\n\nOutput:\n%3")
.arg(fullCommand)
@@ -265,7 +279,7 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Command '%1' crashed or was "
"terminated (output size: %2 bytes)")
.arg(fullCommand)
.arg(*outputSize));
.arg(outputSize));
const QString error = process->errorString();
promise->addResult(
QString("Command '%1' crashed or was terminated.\n\nError: %2\n\nOutput:\n%3")
@@ -278,11 +292,13 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
process->deleteLater();
});
QObject::connect(process, &QProcess::errorOccurred, [process, promise, command, args, timeoutTimer](
QObject::connect(process, &QProcess::errorOccurred, [process, promise, resolved, command, args, timeoutTimer](
QProcess::ProcessError error) {
if (promise->future().isFinished()) {
if (*resolved) {
process->deleteLater();
return;
}
*resolved = true;
timeoutTimer->stop();
timeoutTimer->deleteLater();
@@ -324,9 +340,9 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
process->deleteLater();
});
QString fullCommand = command;
QStringList argsList;
if (!args.isEmpty()) {
fullCommand += " " + args;
argsList = QProcess::splitCommand(args);
}
#ifdef Q_OS_WIN
@@ -342,47 +358,22 @@ QFuture<QString> ExecuteTerminalCommandTool::executeAsync(const QJsonObject &inp
if (isBuiltin) {
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Executing Windows builtin command '%1' via cmd.exe")
.arg(command));
process->start("cmd.exe", QStringList() << "/c" << fullCommand);
QStringList cmdArgs;
cmdArgs << "/c" << command;
cmdArgs.append(argsList);
process->start("cmd.exe", cmdArgs);
} else {
#endif
QStringList splitCommand = QProcess::splitCommand(fullCommand);
if (splitCommand.isEmpty()) {
LOG_MESSAGE("ExecuteTerminalCommandTool: Failed to parse command");
promise->addResult(QString("Error: Failed to parse command '%1'").arg(fullCommand));
promise->finish();
process->deleteLater();
timeoutTimer->deleteLater();
return future;
}
const QString program = splitCommand.takeFirst();
process->start(program, splitCommand);
#ifdef Q_OS_WIN
process->start(command, argsList);
}
#else
process->start(command, argsList);
#endif
if (!process->waitForStarted(PROCESS_START_TIMEOUT_MS)) {
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Failed to start command '%1' within %2ms")
.arg(fullCommand)
.arg(PROCESS_START_TIMEOUT_MS));
const QString errorString = process->errorString();
promise->addResult(QString("Error: Failed to start command '%1': %2\n\n"
"Possible reasons:\n"
"- Command not found in PATH\n"
"- Insufficient permissions\n"
"- Invalid command syntax")
.arg(fullCommand)
.arg(errorString));
promise->finish();
process->deleteLater();
timeoutTimer->deleteLater();
return future;
}
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Process started successfully (PID: %1)")
.arg(process->processId()));
timeoutTimer->start();
LOG_MESSAGE(QString("ExecuteTerminalCommandTool: Process start requested for '%1'")
.arg(command));
return future;
}
@@ -414,19 +405,27 @@ bool ExecuteTerminalCommandTool::areArgumentsSafe(const QString &args) const
return true;
}
// Check for null bytes
if (args.contains(QChar('\0'))) {
LOG_MESSAGE("ExecuteTerminalCommandTool: Null byte found in args");
return false;
}
static const QStringList dangerousPatterns = {
";", // Command separator
"&&", // AND operator
"||", // OR operator
"&", // Command separator / background execution
"|", // Pipe operator
">", // Output redirection
">>", // Append redirection
"<", // Input redirection
"`", // Command substitution
"$(", // Command substitution
"$()", // Command substitution
"\\n", // Newline (could start new command)
"\\r" // Carriage return
"${", // Variable expansion
"\n", // Newline (could start new command)
"\r", // Carriage return
#ifdef Q_OS_WIN
"^", // Escape character in cmd.exe (can bypass other checks)
"%", // Environment variable expansion on Windows
#endif
};
for (const QString &pattern : dangerousPatterns) {
@@ -456,9 +455,6 @@ QString ExecuteTerminalCommandTool::sanitizeOutput(const QString &output, qint64
QStringList ExecuteTerminalCommandTool::getAllowedCommands() const
{
static QString cachedCommandsStr;
static QStringList cachedCommands;
QString commandsStr;
#ifdef Q_OS_LINUX
@@ -471,28 +467,27 @@ QStringList ExecuteTerminalCommandTool::getAllowedCommands() const
commandsStr = Settings::toolsSettings().allowedTerminalCommandsLinux().trimmed(); // fallback
#endif
if (commandsStr == cachedCommandsStr && !cachedCommands.isEmpty()) {
return cachedCommands;
}
cachedCommandsStr = commandsStr;
cachedCommands.clear();
if (commandsStr.isEmpty()) {
return QStringList();
}
QStringList result;
const QStringList rawCommands = commandsStr.split(',', Qt::SkipEmptyParts);
cachedCommands.reserve(rawCommands.size());
result.reserve(rawCommands.size());
for (const QString &cmd : rawCommands) {
const QString trimmed = cmd.trimmed();
if (!trimmed.isEmpty()) {
cachedCommands.append(trimmed);
result.append(trimmed);
}
}
return cachedCommands;
return result;
}
int ExecuteTerminalCommandTool::commandTimeoutMs() const
{
return Settings::toolsSettings().terminalCommandTimeout() * 1000;
}
QString ExecuteTerminalCommandTool::getCommandDescription() const
@@ -518,7 +513,7 @@ QString ExecuteTerminalCommandTool::getCommandDescription() const
"Commands have a %2 second timeout. "
"Returns the command output (stdout and stderr) or an error message if the command fails.%3")
.arg(allowedList)
.arg(COMMAND_TIMEOUT_MS / 1000)
.arg(commandTimeoutMs() / 1000)
.arg(osInfo);
}

View File

@@ -46,12 +46,12 @@ private:
QString getCommandDescription() const;
QString sanitizeOutput(const QString &output, qint64 maxSize) const;
int commandTimeoutMs() const;
// Constants for production safety
static constexpr int COMMAND_TIMEOUT_MS = 30000; // 30 seconds
static constexpr qint64 MAX_OUTPUT_SIZE = 10 * 1024 * 1024; // 10 MB
static constexpr int MAX_COMMAND_LENGTH = 1024;
static constexpr int MAX_ARGS_LENGTH = 4096;
static constexpr int PROCESS_START_TIMEOUT_MS = 3000;
};
} // namespace QodeAssist::Tools

View File

@@ -1,132 +0,0 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ReadVisibleFilesTool.hpp"
#include "ToolExceptions.hpp"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <logger/Logger.hpp>
#include <projectexplorer/projectmanager.h>
#include <QJsonArray>
#include <QJsonObject>
#include <QtConcurrent>
namespace QodeAssist::Tools {
ReadVisibleFilesTool::ReadVisibleFilesTool(QObject *parent)
: BaseTool(parent)
, m_ignoreManager(new Context::IgnoreManager(this))
{}
QString ReadVisibleFilesTool::name() const
{
return "read_visible_files";
}
QString ReadVisibleFilesTool::stringName() const
{
return {"Reading currently opened and visible files in IDE editors"};
}
QString ReadVisibleFilesTool::description() const
{
return "Read content from all currently visible editor tabs, including unsaved changes. "
"Returns file paths and content. No parameters required.";
}
QJsonObject ReadVisibleFilesTool::getDefinition(LLMCore::ToolSchemaFormat format) const
{
QJsonObject definition;
definition["type"] = "object";
definition["properties"] = QJsonObject();
definition["required"] = QJsonArray();
switch (format) {
case LLMCore::ToolSchemaFormat::OpenAI:
return customizeForOpenAI(definition);
case LLMCore::ToolSchemaFormat::Claude:
return customizeForClaude(definition);
case LLMCore::ToolSchemaFormat::Ollama:
return customizeForOllama(definition);
case LLMCore::ToolSchemaFormat::Google:
return customizeForGoogle(definition);
}
return definition;
}
LLMCore::ToolPermissions ReadVisibleFilesTool::requiredPermissions() const
{
return LLMCore::ToolPermission::FileSystemRead;
}
QFuture<QString> ReadVisibleFilesTool::executeAsync(const QJsonObject &input)
{
Q_UNUSED(input)
return QtConcurrent::run([this]() -> QString {
auto editors = Core::EditorManager::visibleEditors();
if (editors.isEmpty()) {
QString error = "Error: No visible files in the editor";
throw ToolRuntimeError(error);
}
QStringList results;
for (auto editor : editors) {
if (!editor || !editor->document()) {
continue;
}
QString filePath = editor->document()->filePath().toFSPathString();
auto project = ProjectExplorer::ProjectManager::projectForFile(
editor->document()->filePath());
if (project && m_ignoreManager->shouldIgnore(filePath, project)) {
LOG_MESSAGE(
QString("Ignoring visible file due to .qodeassistignore: %1").arg(filePath));
continue;
}
QByteArray contentBytes = editor->document()->contents();
QString fileContent = QString::fromUtf8(contentBytes);
QString fileResult;
if (fileContent.isEmpty()) {
fileResult
= QString("File: %1\n\nThe file is empty or could not be read").arg(filePath);
} else {
fileResult = QString("File: %1\n\nContent:\n%2").arg(filePath, fileContent);
}
results.append(fileResult);
}
if (results.isEmpty()) {
QString error = "Error: All visible files are excluded by .qodeassistignore";
throw ToolRuntimeError(error);
}
return results.join("\n\n" + QString(80, '=') + "\n\n");
});
}
} // namespace QodeAssist::Tools

360
tools/TodoTool.cpp Normal file
View File

@@ -0,0 +1,360 @@
/*
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "TodoTool.hpp"
#include "ToolExceptions.hpp"
#include <QJsonArray>
#include <QJsonObject>
#include <QMutexLocker>
#include <QtConcurrent>
namespace QodeAssist::Tools {
TodoTool::TodoTool(QObject *parent)
: BaseTool(parent)
{}
QString TodoTool::name() const
{
return "todo_tool";
}
QString TodoTool::stringName() const
{
return "Managing TODO list for task tracking";
}
QString TodoTool::description() const
{
return "Track and organize multi-step tasks during complex operations that require multiple "
"sequential steps. "
"**Use when planning 3+ step workflows.** "
"Operations: 'add' - provide array of task descriptions to create full plan at once, "
"'complete' - provide array of task IDs to mark finished steps, 'list' - review "
"progress. "
"Helpful for: large refactorings, feature implementations, debugging workflows. "
"The list persists throughout the conversation.";
}
QJsonObject TodoTool::getDefinition(LLMCore::ToolSchemaFormat format) const
{
QJsonObject definition;
definition["type"] = "object";
QJsonObject properties;
QJsonObject operationProp;
operationProp["type"] = "string";
operationProp["description"] = "Operation: 'add' (create tasks), 'complete' (mark tasks as "
"done), 'list' (show all tasks)";
QJsonArray operationEnum;
operationEnum.append("add");
operationEnum.append("complete");
operationEnum.append("list");
operationProp["enum"] = operationEnum;
properties["operation"] = operationProp;
QJsonObject tasksProp;
tasksProp["type"] = "array";
QJsonObject tasksItems;
tasksItems["type"] = "string";
tasksProp["items"] = tasksItems;
tasksProp["description"]
= "Array of task descriptions to create (required for 'add' operation). "
"Create all subtasks at once, e.g.: ['Step 1: ...', 'Step 2: ...', 'Step 3: ...']";
properties["tasks"] = tasksProp;
QJsonObject todoIdsProp;
todoIdsProp["type"] = "array";
QJsonObject todoIdsItems;
todoIdsItems["type"] = "integer";
todoIdsProp["items"] = todoIdsItems;
todoIdsProp["description"]
= "Array of todo item IDs to mark as completed (required for 'complete' operation). "
"Example: [1, 2, 5] to complete tasks #1, #2, and #5";
properties["todo_ids"] = todoIdsProp;
definition["properties"] = properties;
QJsonArray required;
required.append("operation");
definition["required"] = required;
switch (format) {
case LLMCore::ToolSchemaFormat::OpenAI:
return customizeForOpenAI(definition);
case LLMCore::ToolSchemaFormat::Claude:
return customizeForClaude(definition);
case LLMCore::ToolSchemaFormat::Ollama:
return customizeForOllama(definition);
case LLMCore::ToolSchemaFormat::Google:
return customizeForGoogle(definition);
}
return definition;
}
LLMCore::ToolPermissions TodoTool::requiredPermissions() const
{
return LLMCore::ToolPermission::None;
}
QFuture<QString> TodoTool::executeAsync(const QJsonObject &input)
{
return QtConcurrent::run([this, input]() -> QString {
QString sessionId = input.value("session_id").toString();
if (sessionId.isEmpty()) {
sessionId = "current";
}
const QString operation = input.value("operation").toString();
if (operation == "add") {
if (!input.contains("tasks") || !input.value("tasks").isArray()) {
throw ToolRuntimeError(
tr("Error: 'tasks' parameter (array) is required for 'add' operation. "
"Example: {\"operation\": \"add\", \"tasks\": [\"Task 1\", \"Task 2\"]}"));
}
const QJsonArray tasksArray = input.value("tasks").toArray();
if (tasksArray.isEmpty()) {
throw ToolRuntimeError(
tr("Error: 'tasks' array cannot be empty. Provide at least one task."));
}
QStringList tasks;
for (const QJsonValue &taskValue : tasksArray) {
QString task = taskValue.toString().trimmed();
if (!task.isEmpty()) {
tasks.append(task);
}
}
if (tasks.isEmpty()) {
throw ToolRuntimeError(
tr("Error: All tasks in 'tasks' array are empty strings."));
}
return addTodos(sessionId, tasks);
} else if (operation == "complete") {
if (!input.contains("todo_ids") || !input.value("todo_ids").isArray()) {
throw ToolRuntimeError(
tr("Error: 'todo_ids' parameter (array) is required for 'complete' operation. "
"Example: {\"operation\": \"complete\", \"todo_ids\": [1, 2, 3]}"));
}
const QJsonArray idsArray = input.value("todo_ids").toArray();
if (idsArray.isEmpty()) {
throw ToolRuntimeError(
tr("Error: 'todo_ids' array cannot be empty. Provide at least one ID."));
}
QList<int> ids;
for (const QJsonValue &idValue : idsArray) {
int id = idValue.toInt(-1);
if (id > 0) {
ids.append(id);
}
}
if (ids.isEmpty()) {
throw ToolRuntimeError(
tr("Error: All IDs in 'todo_ids' array are invalid. IDs must be positive "
"integers."));
}
return completeTodos(sessionId, ids);
} else if (operation == "list") {
return listTodos(sessionId);
} else {
throw ToolRuntimeError(
tr("Error: Unknown operation '%1'. Valid operations: 'add', 'complete', 'list'")
.arg(operation));
}
});
}
void TodoTool::clearSession(const QString &sessionId)
{
QMutexLocker locker(&m_mutex);
m_sessionTodos.remove(sessionId);
m_sessionNextId.remove(sessionId);
}
QString TodoTool::addTodos(const QString &sessionId, const QStringList &tasks)
{
QMutexLocker locker(&m_mutex);
if (!m_sessionTodos.contains(sessionId)) {
m_sessionTodos[sessionId] = QHash<int, TodoItem>();
m_sessionNextId[sessionId] = 1;
}
for (const QString &task : tasks) {
const int newId = m_sessionNextId[sessionId]++;
m_sessionTodos[sessionId][newId] = {newId, task, false};
}
const QString summary = (tasks.size() == 1) ? tr("✓ Added 1 new task")
: tr("✓ Added %1 new tasks").arg(tasks.size());
return QString("%1\n\n%2").arg(summary, listTodosLocked(sessionId));
}
QString TodoTool::completeTodos(const QString &sessionId, const QList<int> &todoIds)
{
QMutexLocker locker(&m_mutex);
if (!m_sessionTodos.contains(sessionId)) {
throw ToolRuntimeError(tr("Error: No todos found in this session"));
}
auto &todos = m_sessionTodos[sessionId];
int completedCount = 0;
int alreadyCompletedCount = 0;
QStringList notFound;
for (const int todoId : todoIds) {
if (!todos.contains(todoId)) {
notFound.append(QString("#%1").arg(todoId));
continue;
}
TodoItem &item = todos[todoId];
if (item.completed) {
alreadyCompletedCount++;
} else {
item.completed = true;
completedCount++;
}
}
QStringList messages;
if (completedCount > 0) {
messages.append((completedCount == 1) ? tr("✓ Marked 1 task as completed")
: tr("✓ Marked %1 tasks as completed")
.arg(completedCount));
}
if (alreadyCompletedCount > 0) {
messages.append(tr("⚠ %1 already completed").arg(alreadyCompletedCount));
}
if (!notFound.isEmpty()) {
messages.append(tr("❌ Not found: %1").arg(notFound.join(", ")));
}
const QString summary = messages.join(", ");
return QString("%1\n\n%2").arg(summary, listRemainingTodosLocked(sessionId));
}
QString TodoTool::listTodos(const QString &sessionId) const
{
QMutexLocker locker(&m_mutex);
return listTodosLocked(sessionId);
}
QString TodoTool::listTodosLocked(const QString &sessionId) const
{
const auto it = m_sessionTodos.constFind(sessionId);
if (it == m_sessionTodos.constEnd() || it->isEmpty()) {
return tr("📋 TODO List: (empty)");
}
const auto &todos = *it;
QList<int> ids = todos.keys();
std::sort(ids.begin(), ids.end());
QStringList lines;
lines.reserve(ids.size() + 4);
lines.append(tr("📋 TODO List:"));
lines.append("");
int completedCount = 0;
for (const int id : ids) {
const TodoItem &item = todos[id];
const QString checkbox = item.completed ? "[x]" : "[ ]";
const QString strikethrough = item.completed ? QString("~~") : QString("");
lines.append(QString("%1 **#%2** %3%4%5")
.arg(checkbox)
.arg(id)
.arg(strikethrough, item.task, strikethrough));
if (item.completed) {
completedCount++;
}
}
lines.append("");
const int totalCount = ids.size();
const int percentage = totalCount > 0 ? (completedCount * 100) / totalCount : 0;
lines.append(
tr("Progress: %1/%2 completed (%3%)").arg(completedCount).arg(totalCount).arg(percentage));
return lines.join("\n");
}
QString TodoTool::listRemainingTodosLocked(const QString &sessionId) const
{
const auto it = m_sessionTodos.constFind(sessionId);
if (it == m_sessionTodos.constEnd() || it->isEmpty()) {
return tr("📋 All tasks completed! 🎉");
}
const auto &todos = *it;
QList<int> ids = todos.keys();
std::sort(ids.begin(), ids.end());
int completedCount = 0;
QStringList remainingLines;
for (const int id : ids) {
const TodoItem &item = todos[id];
if (item.completed) {
completedCount++;
} else {
remainingLines.append(QString("[ ] **#%1** %2").arg(id).arg(item.task));
}
}
if (remainingLines.isEmpty()) {
return tr("📋 All tasks completed! 🎉");
}
QStringList lines;
lines.reserve(remainingLines.size() + 4);
lines.append(tr("📋 Remaining tasks:"));
lines.append("");
lines.append(remainingLines);
lines.append("");
const int totalCount = ids.size();
const int percentage = totalCount > 0 ? (completedCount * 100) / totalCount : 0;
lines.append(
tr("Progress: %1/%2 completed (%3%)").arg(completedCount).arg(totalCount).arg(percentage));
return lines.join("\n");
}
} // namespace QodeAssist::Tools

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2025 Petr Mironychev
* Copyright (C) 2024-2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
@@ -19,16 +19,27 @@
#pragma once
#include <context/IgnoreManager.hpp>
#include <llmcore/BaseTool.hpp>
#include <QHash>
#include <QMutex>
#include <QString>
namespace QodeAssist::Tools {
class ReadVisibleFilesTool : public LLMCore::BaseTool
struct TodoItem
{
int id;
QString task;
bool completed;
};
class TodoTool : public LLMCore::BaseTool
{
Q_OBJECT
public:
explicit ReadVisibleFilesTool(QObject *parent = nullptr);
explicit TodoTool(QObject *parent = nullptr);
QString name() const override;
QString stringName() const override;
@@ -38,8 +49,18 @@ public:
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;
void clearSession(const QString &sessionId);
private:
Context::IgnoreManager *m_ignoreManager;
QString addTodos(const QString &sessionId, const QStringList &tasks);
QString completeTodos(const QString &sessionId, const QList<int> &todoIds);
QString listTodos(const QString &sessionId) const;
QString listTodosLocked(const QString &sessionId) const;
QString listRemainingTodosLocked(const QString &sessionId) const;
mutable QMutex m_mutex;
QHash<QString, QHash<int, TodoItem>> m_sessionTodos;
QHash<QString, int> m_sessionNextId;
};
} // namespace QodeAssist::Tools

View File

@@ -33,7 +33,7 @@
#include "GetIssuesListTool.hpp"
#include "ListProjectFilesTool.hpp"
#include "ProjectSearchTool.hpp"
#include "ReadVisibleFilesTool.hpp"
#include "TodoTool.hpp"
namespace QodeAssist::Tools {
@@ -45,7 +45,6 @@ ToolsFactory::ToolsFactory(QObject *parent)
void ToolsFactory::registerTools()
{
registerTool(new ReadVisibleFilesTool(this));
registerTool(new ListProjectFilesTool(this));
registerTool(new GetIssuesListTool(this));
registerTool(new CreateNewFileTool(this));
@@ -54,6 +53,7 @@ void ToolsFactory::registerTools()
registerTool(new ExecuteTerminalCommandTool(this));
registerTool(new ProjectSearchTool(this));
registerTool(new FindAndReadFileTool(this));
registerTool(new TodoTool(this));
LOG_MESSAGE(QString("Registered %1 tools").arg(m_tools.size()));
}
@@ -107,6 +107,10 @@ QJsonArray ToolsFactory::getToolsDefinitions(
continue;
}
if (it.value()->name() == "todo_tool" && !settings.enableTodoTool()) {
continue;
}
const auto requiredPerms = it.value()->requiredPermissions();
if (filter != LLMCore::RunToolsFilter::ALL) {

View File

@@ -18,7 +18,13 @@
*/
#include "ToolsManager.hpp"
#include "TodoTool.hpp"
#include "logger/Logger.hpp"
#include <QTimer>
namespace {
constexpr int kToolExecutionDelayMs = 300;
}
namespace QodeAssist::Tools {
@@ -75,6 +81,10 @@ void ToolsManager::executeToolCall(
QJsonObject modifiedInput = input;
modifiedInput["_request_id"] = requestId;
if (!m_currentSessionId.isEmpty()) {
modifiedInput["session_id"] = m_currentSessionId;
}
PendingTool pendingTool{toolId, toolName, modifiedInput, "", false};
queue.queue.append(pendingTool);
@@ -140,27 +150,21 @@ QJsonArray ToolsManager::getToolsDefinitions(
void ToolsManager::cleanupRequest(const QString &requestId)
{
if (m_toolQueues.contains(requestId)) {
LOG_MESSAGE(QString("ToolsManager: Canceling pending tools for request %1").arg(requestId));
m_toolHandler->cleanupRequest(requestId);
m_toolQueues.remove(requestId);
}
LOG_MESSAGE(QString("ToolsManager: Cleaned up request %1").arg(requestId));
}
void ToolsManager::onToolFinished(
const QString &requestId, const QString &toolId, const QString &result, bool success)
{
if (!m_toolQueues.contains(requestId)) {
LOG_MESSAGE(QString("ToolsManager: Tool result for unknown request %1").arg(requestId));
return;
}
auto &queue = m_toolQueues[requestId];
if (!queue.completed.contains(toolId)) {
LOG_MESSAGE(QString("ToolsManager: Tool result for unknown tool %1 in request %2")
.arg(toolId, requestId));
return;
}
@@ -173,7 +177,13 @@ void ToolsManager::onToolFinished(
.arg(success ? QString("completed") : QString("failed"))
.arg(requestId));
executeNextTool(requestId);
if (kToolExecutionDelayMs > 0 && !queue.queue.isEmpty()) {
QTimer::singleShot(kToolExecutionDelayMs, this, [this, requestId]() {
executeNextTool(requestId);
});
} else {
executeNextTool(requestId);
}
}
ToolsFactory *ToolsManager::toolsFactory() const
@@ -197,4 +207,17 @@ QHash<QString, QString> ToolsManager::getToolResults(const QString &requestId) c
return results;
}
void ToolsManager::clearTodoSession(const QString &sessionId)
{
auto *todoTool = qobject_cast<TodoTool *>(m_toolsFactory->getToolByName("todo_tool"));
if (todoTool) {
todoTool->clearSession(sessionId);
}
}
void ToolsManager::setCurrentSessionId(const QString &sessionId)
{
m_currentSessionId = sessionId;
}
} // namespace QodeAssist::Tools

View File

@@ -27,6 +27,7 @@
#include "ToolHandler.hpp"
#include "ToolsFactory.hpp"
#include <llmcore/BaseTool.hpp>
#include <llmcore/IToolsManager.hpp>
namespace QodeAssist::Tools {
@@ -46,7 +47,7 @@ struct ToolQueue
bool isExecuting = false;
};
class ToolsManager : public QObject
class ToolsManager : public QObject, public LLMCore::IToolsManager
{
Q_OBJECT
@@ -57,12 +58,15 @@ public:
const QString &requestId,
const QString &toolId,
const QString &toolName,
const QJsonObject &input);
const QJsonObject &input) override;
QJsonArray getToolsDefinitions(
LLMCore::ToolSchemaFormat format,
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL) const;
void cleanupRequest(const QString &requestId);
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL) const override;
void cleanupRequest(const QString &requestId) override;
void setCurrentSessionId(const QString &sessionId) override;
void clearTodoSession(const QString &sessionId) override;
ToolsFactory *toolsFactory() const;
@@ -77,6 +81,7 @@ private:
ToolsFactory *m_toolsFactory;
ToolHandler *m_toolHandler;
QHash<QString, ToolQueue> m_toolQueues;
QString m_currentSessionId;
void executeNextTool(const QString &requestId);
QHash<QString, QString> getToolResults(const QString &requestId) const;

View File

@@ -34,6 +34,7 @@
#include <QDialogButtonBox>
#include <QDir>
#include <QFontMetrics>
#include <QFrame>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
@@ -100,11 +101,17 @@ QuickRefactorDialog::QuickRefactorDialog(QWidget *parent, const QString &lastIns
setWindowTitle(Tr::tr("Quick Refactor"));
setupUi();
if (!m_lastInstructions.isEmpty()) {
m_instructionEdit->setPlainText(m_lastInstructions);
m_instructionEdit->selectAll();
}
QTimer::singleShot(0, this, &QuickRefactorDialog::updateDialogSize);
m_textEdit->installEventFilter(this);
m_instructionEdit->installEventFilter(this);
m_commandsComboBox->installEventFilter(this);
updateDialogSize();
m_commandsComboBox->setFocus();
m_instructionEdit->setFocus();
}
void QuickRefactorDialog::setupUi()
@@ -173,17 +180,25 @@ void QuickRefactorDialog::setupUi()
mainLayout->addLayout(actionsLayout);
QHBoxLayout *instructionsLayout = new QHBoxLayout();
instructionsLayout->setSpacing(4);
QLabel *instructionLabel = new QLabel(Tr::tr("Your Current Instruction:"), this);
mainLayout->addWidget(instructionLabel);
QLabel *instructionsLabel = new QLabel(Tr::tr("Custom Instructions:"), this);
instructionsLayout->addWidget(instructionsLabel);
m_instructionEdit = new QPlainTextEdit(this);
m_instructionEdit->setMinimumHeight(80);
m_instructionEdit->setPlaceholderText(Tr::tr("Type or edit your instruction..."));
mainLayout->addWidget(m_instructionEdit);
QHBoxLayout *savedInstructionsLayout = new QHBoxLayout();
savedInstructionsLayout->setSpacing(4);
QLabel *savedLabel = new QLabel(Tr::tr("Or Load saved:"), this);
savedInstructionsLayout->addWidget(savedLabel);
m_commandsComboBox = new QComboBox(this);
m_commandsComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_commandsComboBox->setEditable(true);
m_commandsComboBox->setInsertPolicy(QComboBox::NoInsert);
m_commandsComboBox->lineEdit()->setPlaceholderText("Search or select instruction...");
m_commandsComboBox->lineEdit()->setPlaceholderText(Tr::tr("Search saved instructions..."));
QCompleter *completer = new QCompleter(this);
completer->setCompletionMode(QCompleter::PopupCompletion);
@@ -191,38 +206,39 @@ void QuickRefactorDialog::setupUi()
completer->setFilterMode(Qt::MatchContains);
m_commandsComboBox->setCompleter(completer);
instructionsLayout->addWidget(m_commandsComboBox);
savedInstructionsLayout->addWidget(m_commandsComboBox);
m_addCommandButton = new QToolButton(this);
m_addCommandButton->setText("+");
m_addCommandButton->setToolTip(Tr::tr("Add Custom Instruction"));
instructionsLayout->addWidget(m_addCommandButton);
m_addCommandButton->setFocusPolicy(Qt::NoFocus);
savedInstructionsLayout->addWidget(m_addCommandButton);
m_editCommandButton = new QToolButton(this);
m_editCommandButton->setText("");
m_editCommandButton->setToolTip(Tr::tr("Edit Custom Instruction"));
instructionsLayout->addWidget(m_editCommandButton);
m_editCommandButton->setFocusPolicy(Qt::NoFocus);
savedInstructionsLayout->addWidget(m_editCommandButton);
m_deleteCommandButton = new QToolButton(this);
m_deleteCommandButton->setText("");
m_deleteCommandButton->setToolTip(Tr::tr("Delete Custom Instruction"));
instructionsLayout->addWidget(m_deleteCommandButton);
m_deleteCommandButton->setFocusPolicy(Qt::NoFocus);
savedInstructionsLayout->addWidget(m_deleteCommandButton);
m_openFolderButton = new QToolButton(this);
m_openFolderButton->setText("📁");
m_openFolderButton->setToolTip(Tr::tr("Open Instructions Folder"));
instructionsLayout->addWidget(m_openFolderButton);
m_openFolderButton->setFocusPolicy(Qt::NoFocus);
savedInstructionsLayout->addWidget(m_openFolderButton);
mainLayout->addLayout(instructionsLayout);
mainLayout->addLayout(savedInstructionsLayout);
m_instructionsLabel = new QLabel(Tr::tr("Additional instructions (optional):"), this);
mainLayout->addWidget(m_instructionsLabel);
m_textEdit = new QPlainTextEdit(this);
m_textEdit->setMinimumHeight(100);
m_textEdit->setPlaceholderText(Tr::tr("Add extra details or modifications to the selected instruction..."));
connect(m_textEdit, &QPlainTextEdit::textChanged, this, &QuickRefactorDialog::updateDialogSize);
connect(
m_instructionEdit,
&QPlainTextEdit::textChanged,
this,
&QuickRefactorDialog::updateDialogSize);
connect(
m_commandsComboBox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
@@ -242,8 +258,6 @@ void QuickRefactorDialog::setupUi()
this,
&QuickRefactorDialog::onOpenInstructionsFolder);
mainLayout->addWidget(m_textEdit);
loadCustomCommands();
loadAvailableConfigurations();
@@ -255,12 +269,23 @@ void QuickRefactorDialog::setupUi()
QDialogButtonBox *buttonBox
= new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QuickRefactorDialog::validateAndAccept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
mainLayout->addWidget(buttonBox);
setTabOrder(m_commandsComboBox, m_textEdit);
setTabOrder(m_textEdit, buttonBox);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
QPushButton *cancelButton = buttonBox->button(QDialogButtonBox::Cancel);
if (okButton) {
okButton->installEventFilter(this);
}
if (cancelButton) {
cancelButton->installEventFilter(this);
}
setTabOrder(m_instructionEdit, m_commandsComboBox);
setTabOrder(m_commandsComboBox, okButton);
setTabOrder(okButton, cancelButton);
}
void QuickRefactorDialog::createActionButtons()
@@ -295,27 +320,12 @@ void QuickRefactorDialog::createActionButtons()
QString QuickRefactorDialog::instructions() const
{
QString result;
CustomInstruction instruction = findCurrentInstruction();
if (!instruction.id.isEmpty()) {
result = instruction.body;
}
QString additionalText = m_textEdit->toPlainText().trimmed();
if (!additionalText.isEmpty()) {
if (!result.isEmpty()) {
result += "\n\n";
}
result += additionalText;
}
return result;
return m_instructionEdit->toPlainText().trimmed();
}
void QuickRefactorDialog::setInstructions(const QString &instructions)
{
m_textEdit->setPlainText(instructions);
m_instructionEdit->setPlainText(instructions);
}
QuickRefactorDialog::Action QuickRefactorDialog::selectedAction() const
@@ -323,17 +333,33 @@ QuickRefactorDialog::Action QuickRefactorDialog::selectedAction() const
return m_selectedAction;
}
void QuickRefactorDialog::keyPressEvent(QKeyEvent *event)
{
QDialog::keyPressEvent(event);
}
bool QuickRefactorDialog::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_textEdit && event->type() == QEvent::KeyPress) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
if (keyEvent->modifiers() & Qt::ShiftModifier) {
return false;
}
accept();
return true;
if (watched == m_instructionEdit) {
if (keyEvent->key() == Qt::Key_Tab) {
m_commandsComboBox->setFocus();
return true;
}
}
if (watched == m_commandsComboBox || watched == m_commandsComboBox->lineEdit()) {
if (keyEvent->key() == Qt::Key_Tab) {
QPushButton *okButton = findChild<QPushButton *>();
if (okButton && okButton->text() == "OK") {
okButton->setFocus();
} else {
focusNextChild();
}
return true;
}
}
}
return QDialog::eventFilter(watched, event);
@@ -343,8 +369,7 @@ void QuickRefactorDialog::useLastInstructions()
{
if (!m_lastInstructions.isEmpty()) {
m_commandsComboBox->setCurrentIndex(0);
m_commandsComboBox->clearEditText(); // Clear search text
m_textEdit->setPlainText(m_lastInstructions);
m_instructionEdit->setPlainText(m_lastInstructions);
m_selectedAction = Action::RepeatLast;
}
accept();
@@ -353,10 +378,10 @@ void QuickRefactorDialog::useLastInstructions()
void QuickRefactorDialog::useImproveCodeTemplate()
{
m_commandsComboBox->setCurrentIndex(0);
m_commandsComboBox->clearEditText(); // Clear search text
m_textEdit->setPlainText(Tr::tr(
"Improve the selected code by enhancing readability, efficiency, and maintainability. "
"Follow best practices for C++/Qt and fix any potential issues."));
m_instructionEdit->setPlainText(
Tr::tr(
"Improve the selected code by enhancing readability, efficiency, and maintainability. "
"Follow best practices for C++/Qt and fix any potential issues."));
m_selectedAction = Action::ImproveCode;
accept();
}
@@ -364,36 +389,29 @@ void QuickRefactorDialog::useImproveCodeTemplate()
void QuickRefactorDialog::useAlternativeSolutionTemplate()
{
m_commandsComboBox->setCurrentIndex(0);
m_commandsComboBox->clearEditText(); // Clear search text
m_textEdit->setPlainText(
Tr::tr("Suggest an alternative implementation approach for the selected code. "
"Provide a different solution that might be cleaner, more efficient, "
"or uses different Qt/C++ patterns or idioms."));
m_instructionEdit->setPlainText(
Tr::tr(
"Suggest an alternative implementation approach for the selected code. "
"Provide a different solution that might be cleaner, more efficient, "
"or uses different Qt/C++ patterns or idioms."));
m_selectedAction = Action::AlternativeSolution;
accept();
}
void QuickRefactorDialog::updateDialogSize()
{
QString text = m_textEdit->toPlainText();
QString text = m_instructionEdit->toPlainText();
QFontMetrics fm(m_textEdit->font());
QFontMetrics fm(m_instructionEdit->font());
QStringList lines = text.split('\n');
int lineCount = lines.size();
int lineCount = qMax(lines.size(), 3);
if (lineCount <= 1) {
int singleLineHeight = fm.height() + 10;
m_textEdit->setMinimumHeight(singleLineHeight);
m_textEdit->setMaximumHeight(singleLineHeight);
} else {
m_textEdit->setMaximumHeight(QWIDGETSIZE_MAX);
m_instructionEdit->setMaximumHeight(QWIDGETSIZE_MAX);
int lineHeight = fm.height() + 2;
int textEditHeight = qMin(qMax(lineCount, 2) * lineHeight, 20 * lineHeight);
m_textEdit->setMinimumHeight(textEditHeight);
}
int lineHeight = fm.height() + 2;
int textEditHeight = qMin(qMax(lineCount, 3) * lineHeight, 15 * lineHeight);
m_instructionEdit->setMinimumHeight(textEditHeight);
int maxWidth = 500;
for (const QString &line : lines) {
@@ -405,14 +423,7 @@ void QuickRefactorDialog::updateDialogSize()
QRect screenGeometry = screen->availableGeometry();
int newWidth = qMin(maxWidth + 40, screenGeometry.width() * 3 / 4);
int newHeight;
if (lineCount <= 1) {
newHeight = 150;
} else {
newHeight = m_textEdit->minimumHeight() + 150;
}
newHeight = qMin(newHeight, screenGeometry.height() * 3 / 4);
int newHeight = qMin(m_instructionEdit->minimumHeight() + 200, screenGeometry.height() * 3 / 4);
resize(newWidth, newHeight);
}
@@ -420,22 +431,16 @@ void QuickRefactorDialog::updateDialogSize()
void QuickRefactorDialog::loadCustomCommands()
{
m_commandsComboBox->clear();
m_commandsComboBox->addItem("", QString()); // Empty item for no selection
m_commandsComboBox->addItem("", QString());
auto &manager = CustomInstructionsManager::instance();
const QVector<CustomInstruction> &instructions = manager.instructions();
QStringList instructionNames;
int defaultInstructionIndex = -1;
for (int i = 0; i < instructions.size(); ++i) {
const CustomInstruction &instruction = instructions[i];
for (const CustomInstruction &instruction : instructions) {
m_commandsComboBox->addItem(instruction.name, instruction.id);
instructionNames.append(instruction.name);
if (instruction.isDefault) {
defaultInstructionIndex = i + 1;
}
}
if (m_commandsComboBox->completer()) {
@@ -443,10 +448,6 @@ void QuickRefactorDialog::loadCustomCommands()
m_commandsComboBox->completer()->setModel(model);
}
if (defaultInstructionIndex > 0) {
m_commandsComboBox->setCurrentIndex(defaultInstructionIndex);
}
bool hasInstructions = !instructions.isEmpty();
m_editCommandButton->setEnabled(hasInstructions);
m_deleteCommandButton->setEnabled(hasInstructions);
@@ -481,7 +482,14 @@ CustomInstruction QuickRefactorDialog::findCurrentInstruction() const
void QuickRefactorDialog::onCommandSelected(int index)
{
Q_UNUSED(index);
if (index <= 0) {
return;
}
CustomInstruction instruction = findCurrentInstruction();
if (!instruction.id.isEmpty()) {
m_instructionEdit->setPlainText(instruction.body);
}
}
void QuickRefactorDialog::onAddCustomCommand()
@@ -493,10 +501,7 @@ void QuickRefactorDialog::onAddCustomCommand()
if (manager.saveInstruction(instruction)) {
loadCustomCommands();
m_commandsComboBox->setCurrentText(instruction.name);
m_textEdit->clear();
} else {
QMessageBox::warning(
this,
@@ -512,7 +517,9 @@ void QuickRefactorDialog::onEditCustomCommand()
if (instruction.id.isEmpty()) {
QMessageBox::information(
this, Tr::tr("No Instruction Selected"), Tr::tr("Please select an instruction to edit."));
this,
Tr::tr("No Instruction Selected"),
Tr::tr("Please select an instruction to edit."));
return;
}
@@ -524,7 +531,6 @@ void QuickRefactorDialog::onEditCustomCommand()
if (manager.saveInstruction(updatedInstruction)) {
loadCustomCommands();
m_commandsComboBox->setCurrentText(updatedInstruction.name);
m_textEdit->clear();
} else {
QMessageBox::warning(
this,
@@ -540,7 +546,9 @@ void QuickRefactorDialog::onDeleteCustomCommand()
if (instruction.id.isEmpty()) {
QMessageBox::information(
this, Tr::tr("No Instruction Selected"), Tr::tr("Please select an instruction to delete."));
this,
Tr::tr("No Instruction Selected"),
Tr::tr("Please select an instruction to delete."));
return;
}
@@ -581,7 +589,7 @@ void QuickRefactorDialog::onOpenInstructionsFolder()
void QuickRefactorDialog::onOpenSettings()
{
Core::ICore::showOptionsDialog(Constants::QODE_ASSIST_QUICK_REFACTOR_SETTINGS_PAGE_ID);
Settings::showSettings(Constants::QODE_ASSIST_QUICK_REFACTOR_SETTINGS_PAGE_ID);
}
QString QuickRefactorDialog::selectedConfiguration() const
@@ -594,8 +602,8 @@ void QuickRefactorDialog::loadAvailableConfigurations()
auto &manager = Settings::ConfigurationManager::instance();
manager.loadConfigurations(Settings::ConfigurationType::QuickRefactor);
QVector<Settings::AIConfiguration> configs
= manager.configurations(Settings::ConfigurationType::QuickRefactor);
QVector<Settings::AIConfiguration> configs = manager.configurations(
Settings::ConfigurationType::QuickRefactor);
m_configComboBox->clear();
m_configComboBox->addItem(Tr::tr("Current"), QString());
@@ -640,4 +648,20 @@ void QuickRefactorDialog::onConfigurationChanged(int index)
}
}
void QuickRefactorDialog::validateAndAccept()
{
QString instruction = m_instructionEdit->toPlainText().trimmed();
if (instruction.isEmpty()) {
QMessageBox::warning(
this,
Tr::tr("No Instruction"),
Tr::tr("Please type an instruction or select a saved one."));
m_instructionEdit->setFocus();
return;
}
accept();
}
} // namespace QodeAssist

View File

@@ -27,6 +27,8 @@ class QPlainTextEdit;
class QToolButton;
class QLabel;
class QComboBox;
class QLineEdit;
class QFrame;
namespace QodeAssist {
@@ -49,6 +51,7 @@ public:
QString selectedConfiguration() const;
bool eventFilter(QObject *watched, QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private slots:
void useLastInstructions();
@@ -64,13 +67,14 @@ private slots:
void loadCustomCommands();
void loadAvailableConfigurations();
void onConfigurationChanged(int index);
void validateAndAccept();
private:
void setupUi();
void createActionButtons();
CustomInstruction findCurrentInstruction() const;
QPlainTextEdit *m_textEdit;
QPlainTextEdit *m_instructionEdit;
QToolButton *m_repeatButton;
QToolButton *m_improveButton;
QToolButton *m_alternativeButton;
@@ -83,7 +87,6 @@ private:
QToolButton *m_thinkingButton;
QComboBox *m_commandsComboBox;
QComboBox *m_configComboBox;
QLabel *m_instructionsLabel;
Action m_selectedAction = Action::Custom;
QString m_lastInstructions;