Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
17b0dd0
feat: add in-app AI Chat panel (issue #209, Phase 8)
fernandotonon Apr 6, 2026
ba7f0b4
fix(ai-chat): tool calls execute correctly; show model name in header
fernandotonon Apr 6, 2026
0227717
fix(ai-chat): stop material bleeding; selectable text; context trunca…
fernandotonon Apr 6, 2026
54c3216
fix(ai-chat): fix blank chat area after TextEdit migration
fernandotonon Apr 6, 2026
a455421
fix(ai-chat): fix blank bubbles with explicit TextEdit layout
fernandotonon Apr 6, 2026
01b8453
fix(ai-chat): overlay pattern for selectable text — no more blank bub…
fernandotonon Apr 6, 2026
f5e7f5b
fix(ai-chat): revert bubble layout to original anchoring; add TextEdi…
fernandotonon Apr 6, 2026
6b6f201
fix(ai-chat): remove invalid background:null from QtQuick TextEdit
fernandotonon Apr 6, 2026
44e75d9
fix(ai-chat): stop post-tool loop and context overflow
fernandotonon Apr 6, 2026
31c978b
fix(ai-chat): stop button works between tool calls; fix tool tag parsing
fernandotonon Apr 6, 2026
ead6af5
fix(ai-chat): strip chat-template tokens and hallucinated user turns
fernandotonon Apr 6, 2026
dbf6f67
fix(ai-chat): replace fragile tag regex with JSON object scanner
fernandotonon Apr 6, 2026
781cd8c
fix(ai-chat): handle [Tool: X]\nArguments:{} format; fix result format
fernandotonon Apr 6, 2026
882a7d0
feat(ai-chat): agentic error recovery — retry after tool failures
fernandotonon Apr 6, 2026
8facd38
Improve AI chat agentic behavior and multi-step tool execution
fernandotonon Apr 7, 2026
382a9e2
Fix multi-step AI tool chain: correct material params, KV-cache ordering
fernandotonon Apr 7, 2026
765e28f
Trim verbose tool results in history to conserve context window
fernandotonon Apr 7, 2026
e315679
Pin original user message in sliding history window
fernandotonon Apr 7, 2026
9548858
Cap AI chat output to 400 tokens; fix box=cube rule in system prompt
fernandotonon Apr 7, 2026
558e7e2
Fix AI chat focus and copy/paste issues
fernandotonon Apr 7, 2026
fd8bb45
Improve AI chat agentic behavior and fix model artifacts
fernandotonon Apr 7, 2026
3412ebd
Switch AI chat to structured JSON response format with retry
fernandotonon Apr 7, 2026
12c9b79
Fix phantom box creation and improve axis/remaining enforcement
fernandotonon Apr 7, 2026
ba0d639
Add list_files and read_file MCP tools; fix Z-axis direction
fernandotonon Apr 7, 2026
f2b0ffd
Add search_files tool, filter AI tool list, fix coordinates and recen…
fernandotonon Apr 7, 2026
eea89fb
Add camera MCP tools, search_files, task separation rule
fernandotonon Apr 7, 2026
0aaca04
Fix chat focus on app reactivation; clean up LLM model list
fernandotonon Apr 7, 2026
37d9aef
v2.21.0: Add delete_entity tool, clean up debug prints, update docs a…
fernandotonon Apr 7, 2026
9185a7e
Address PR review: QPointer, input height cap, remove dead code
fernandotonon Apr 7, 2026
eab8d06
Merge branch 'master' into feat/ai-chat-panel
fernandotonon Apr 7, 2026
4ace39a
Fix CI: add AIChatManager to tests/CMakeLists.txt sources
fernandotonon Apr 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.24.0)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0048 NEW) # manages project version

project(QtMeshEditor VERSION 2.20.2 LANGUAGES C CXX)
project(QtMeshEditor VERSION 2.21.0 LANGUAGES C CXX)
message(STATUS "Building QtMeshEditor version ${PROJECT_VERSION}")

set(QTMESHEDITOR_VERSION_STRING "\"${PROJECT_VERSION}\"")
Expand Down
10 changes: 8 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,16 @@ <h3 class="feature-title">Scene Save &amp; Load</h3>
<p class="feature-desc">Save your entire scene &mdash; multiple meshes with positions, rotations, scales, materials, skeletons, and animations &mdash; to a single glTF file. Reopen later to pick up where you left off.</p>
</div>

<div class="feature-card">
<div class="feature-icon">💬</div>
<h3 class="feature-title">AI Chat Assistant</h3>
<p class="feature-desc">Built-in AI chat panel powered by local LLMs. Ask it to create objects, apply materials, move meshes, load files, and control the camera using natural language. Runs entirely on-device.</p>
</div>

<div class="feature-card">
<div class="feature-icon">🔌</div>
<h3 class="feature-title">MCP Server (AI Agents)</h3>
<p class="feature-desc">Built-in Model Context Protocol server lets AI agents like Claude or Cursor control the editor. 29 tools for materials, meshes, scenes, transforms, and animations via HTTP API.</p>
<p class="feature-desc">Built-in Model Context Protocol server lets AI agents like Claude or Cursor control the editor. 40 tools for materials, meshes, scenes, transforms, camera, file browsing, and animations via HTTP API.</p>
</div>
</div>
</section>
Expand Down Expand Up @@ -853,7 +859,7 @@ <h3>Configure Your AI Agent</h3>
</div>

<div class="install-step">
<h3>29 Tools Available</h3>
<h3>40 Tools Available</h3>
<div class="code-wrapper">
<div class="code-block">
# Save and load entire scenes (meshes, transforms, animations)
Expand Down
311 changes: 311 additions & 0 deletions qml/AIChatPanel.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import AIChatPanel 1.0
import PropertiesPanel 1.0

Rectangle {
id: root
color: PropertiesPanelController.panelColor

// Forward focus to the input field whenever the panel gains active focus
// (e.g. when the user clicks anywhere in the dock after returning from
// another app window).
onActiveFocusChanged: {
if (activeFocus)
Qt.callLater(() => inputField.forceActiveFocus())
}

// ---- Header bar ----
Rectangle {
id: header
anchors { top: parent.top; left: parent.left; right: parent.right }
height: 36
color: PropertiesPanelController.headerColor

RowLayout {
anchors { fill: parent; leftMargin: 8; rightMargin: 8 }
spacing: 6

Text {
text: "AI Chat"
color: PropertiesPanelController.textColor
font.pixelSize: 13; font.bold: true
Layout.fillWidth: true
}

// Model status dot
Rectangle {
width: 8; height: 8; radius: 4
color: AIChatManager.modelAvailable ? "#44dd44" : "#dd4444"
}

Text {
text: AIChatManager.modelAvailable
? AIChatManager.currentModelName
: "No model"
color: PropertiesPanelController.textColor
font.pixelSize: 10
elide: Text.ElideMiddle
Layout.maximumWidth: 160
}

// Clear button
Rectangle {
width: 22; height: 22; radius: 3
color: clearArea.containsMouse
? Qt.lighter(PropertiesPanelController.panelColor, 1.5)
: "transparent"

Text { anchors.centerIn: parent; text: "✕"; color: PropertiesPanelController.textColor; font.pixelSize: 11 }
MouseArea {
id: clearArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: AIChatManager.clearHistory()
}
}
}
}

// ---- Single selectable conversation area ----
Flickable {
id: msgFlick
anchors {
top: header.bottom; left: parent.left; right: parent.right
bottom: thinkingRow.top; bottomMargin: 0
}
clip: true
contentWidth: width
contentHeight: msgEdit.implicitHeight + 16

function scrollToBottom() {
contentY = Math.max(0, contentHeight - height)
}

TextEdit {
id: msgEdit
anchors { left: parent.left; right: parent.right; top: parent.top; margins: 8 }
readOnly: true
selectByMouse: true
textFormat: Text.RichText
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
color: PropertiesPanelController.textColor
font.pixelSize: 12
selectionColor: Qt.rgba(0.3, 0.5, 0.8, 0.5)
selectedTextColor: PropertiesPanelController.textColor
text: root.buildHtml()

// Intercept Ctrl/Cmd+C to copy plain text instead of RichText HTML.
Keys.onPressed: (event) => {
if ((event.key === Qt.Key_C) &&
(event.modifiers & Qt.ControlModifier)) {
if (selectedText.length > 0) {
Qt.application.clipboard.text = selectedText
event.accepted = true
}
}
}

// When the user finishes selecting (mouse released with no selection),
// return focus to the input field. Use onActiveFocusChanged instead of
// onSelectedTextChanged to avoid stealing focus mid-drag.
onActiveFocusChanged: {
if (!activeFocus && selectedText.length === 0)
Qt.callLater(() => inputField.forceActiveFocus())
}
}

onContentHeightChanged: Qt.callLater(scrollToBottom)

Connections {
target: AIChatManager
function onMessagesChanged() { Qt.callLater(msgFlick.scrollToBottom) }
function onStreamingTextChanged(){ Qt.callLater(msgFlick.scrollToBottom) }
}
}

// ---- Thinking dots (no tokens yet) ----
Row {
id: thinkingRow
anchors { bottom: inputRow.top; left: parent.left; leftMargin: 12; bottomMargin: 6 }
height: visible ? 14 : 0
spacing: 4
visible: AIChatManager.isGenerating

Comment on lines +129 to +136

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Hide the thinking dots once streaming starts.

This row is labeled "no tokens yet", but visible only checks isGenerating, so the dots stay on-screen during the whole streamed reply.

🐛 Proposed fix
-        visible: AIChatManager.isGenerating
+        visible: AIChatManager.isGenerating && AIChatManager.streamingText.length === 0
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// ---- Thinking dots (no tokens yet) ----
Row {
id: thinkingRow
anchors { bottom: inputRow.top; left: parent.left; leftMargin: 12; bottomMargin: 6 }
height: visible ? 14 : 0
spacing: 4
visible: AIChatManager.isGenerating
// ---- Thinking dots (no tokens yet) ----
Row {
id: thinkingRow
anchors { bottom: inputRow.top; left: parent.left; leftMargin: 12; bottomMargin: 6 }
height: visible ? 14 : 0
spacing: 4
visible: AIChatManager.isGenerating && AIChatManager.streamingText.length === 0
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@qml/AIChatPanel.qml` around lines 129 - 136, The thinkingRow's visible
binding currently uses only AIChatManager.isGenerating so the "no tokens yet"
dots remain during streaming; change its visible expression to hide once
streaming begins (e.g., visible: AIChatManager.isGenerating &&
!AIChatManager.isStreaming or use the appropriate flag like
AIChatManager.hasNoTokens) so thinkingRow (id: thinkingRow) only shows before
streaming starts.

Repeater {
model: 3
Rectangle {
width: 6; height: 6; radius: 3
color: PropertiesPanelController.accentColor
opacity: 0.3
SequentialAnimation on opacity {
loops: Animation.Infinite
NumberAnimation { to: 1.0; duration: 400 }
NumberAnimation { to: 0.3; duration: 400 }
PauseAnimation { duration: index * 150 }
}
}
}
}

// ---- Input row ----
Rectangle {
id: inputRow
anchors { bottom: parent.bottom; left: parent.left; right: parent.right }
height: Math.max(40, Math.min(inputField.implicitHeight, 80) + 16)
color: PropertiesPanelController.headerColor
border.color: PropertiesPanelController.borderColor
border.width: 1

TextArea {
id: inputField
anchors { left: parent.left; right: sendBtn.left;
verticalCenter: parent.verticalCenter;
leftMargin: 8; rightMargin: 6 }
height: Math.min(implicitHeight, 80)
placeholderText: AIChatManager.modelAvailable
? "Ask AI to do something…"
: "Load an AI model first (AI → AI Model Settings)"
color: PropertiesPanelController.textColor
background: null
font.pixelSize: 12
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
enabled: AIChatManager.modelAvailable && !AIChatManager.isGenerating
focus: true

Keys.onReturnPressed: (event) => {
if (event.modifiers & Qt.ShiftModifier) {
event.accepted = false // shift+enter → newline
} else {
event.accepted = true
doSend()
}
}
}

Rectangle {
id: sendBtn
anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 8 }
width: 32; height: 32; radius: 4
color: sendBtnArea.containsMouse
? PropertiesPanelController.accentColor
: PropertiesPanelController.buttonColor
enabled: AIChatManager.modelAvailable

Text {
anchors.centerIn: parent
text: AIChatManager.isGenerating ? "■" : "▶"
color: PropertiesPanelController.textColor
font.pixelSize: 13
}

MouseArea {
id: sendBtnArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (AIChatManager.isGenerating)
AIChatManager.stopGeneration()
else
doSend()
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

// ---- Empty state hint ----
Column {
anchors.centerIn: parent
anchors.verticalCenterOffset: -30
spacing: 8
visible: AIChatManager.messages.length === 0 && !AIChatManager.isGenerating

Text {
anchors.horizontalCenter: parent.horizontalCenter
text: "✦"
color: PropertiesPanelController.accentColor
font.pixelSize: 28
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: "Ask me to control the editor"
color: PropertiesPanelController.textColor
font.pixelSize: 13; opacity: 0.7
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: "\"make the selected mesh twice as large\""
color: PropertiesPanelController.textColor
font.pixelSize: 11; opacity: 0.45; font.italic: true
}
}

// ---- Helpers ----

function doSend() {
var txt = inputField.text.trim()
if (txt.length > 0) {
AIChatManager.sendMessage(txt)
inputField.text = ""
}
}

function escHtml(t) {
return t.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\n/g, "<br>")
}

function buildHtml() {
var html = ""
var msgs = AIChatManager.messages
for (var i = 0; i < msgs.length; ++i) {
var msg = msgs[i]
var isTool = msg.isTool
var role = msg.role
var roleColor, roleLabel
if (isTool) { roleColor = "#88cc88"; roleLabel = "⚙ tool" }
else if (role === "user"){ roleColor = "#88aacc"; roleLabel = "you" }
else { roleColor = "#aaaaaa"; roleLabel = "assistant" }

// Assistant messages may be structured JSON — render appropriately.
var displayText = msg.text
if (role === "assistant" && !isTool) {
var trimmed = msg.text.trim()
if (trimmed.startsWith("{")) {
try {
var obj = JSON.parse(trimmed)
if (obj && obj.command)
displayText = "[calling " + obj.command + "]"
else if (obj && obj.response)
displayText = obj.response // final done message
else if (obj && obj.name)
displayText = "[calling " + obj.name + "]" // legacy fallback
} catch(e) {}
}
}

if (i > 0) html += "<br>"
if (role === "user") {
html += '<p align="right"><font color="#88aacc"><small><b>you</b></small></font><br>'
html += escHtml(displayText) + '</p>'
} else {
html += '<font color="' + roleColor + '"><small><b>' + roleLabel + '</b></small></font><br>'
html += escHtml(displayText) + "<br>"
}
}

// In-progress streaming text
if (AIChatManager.streamingText.length > 0) {
if (msgs.length > 0) html += "<br>"
html += '<font color="#aaaaaa"><small><b>assistant</b></small></font><br>'
html += escHtml(AIChatManager.streamingText)
}

return html
}
}
Loading
Loading