Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion crates/ironclaw_engine/orchestrator/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def signals_tool_intent(text):
"read the", "write the", "create", "run the", "execute",
"query", "retrieve", "add it", "add the", "add this",
"add that", "update the", "delete", "remove the", "look into",
"stop", "pause", "cancel", "halt", "disable",
]

for prefix in PREFIXES:
Expand Down Expand Up @@ -161,10 +162,33 @@ def signals_execution_intent(text):
"ship it", "deploy it", "deploy that", "deploy this", "deploy the ",
"send it", "send that", "send the ",
"fetch it", "fetch that", "fetch the ",
"stop it", "stop that", "stop this", "stop the ",
"pause it", "pause that", "pause this", "pause the ",
"cancel it", "cancel that", "cancel this", "cancel the ",
"halt it", "halt that", "halt this", "halt the ",
"disable it", "disable that", "disable this", "disable the ",
"please run ", "please execute ", "please fetch ",
"please send ", "please deploy ",
"please stop ", "please pause ", "please cancel ",
"please halt ", "please disable ",
]
return any(phrase in lower for phrase in EXEC_PHRASES)
if any(phrase in lower for phrase in EXEC_PHRASES):
return True

# Bare imperative commands at the start of the message.
# "stop pinging", "stop", "pause", "cancel" are unambiguous commands
# that don't match the "verb + pronoun/article" pattern above.
# Checking startswith avoids false positives like "I can't stop".
# Strip trailing punctuation so "Stop." and "cancel!" still match.
trimmed = lower.strip().rstrip(".,!?;:")
IMPERATIVE_STARTS = ["stop ", "pause ", "cancel ", "halt ", "disable "]
BARE_COMMANDS = ["stop", "pause", "cancel", "halt", "disable"]
if trimmed in BARE_COMMANDS:
return True
if any(trimmed.startswith(s) for s in IMPERATIVE_STARTS):
return True

return False


def format_output(result, max_chars=8000):
Expand Down
108 changes: 108 additions & 0 deletions crates/ironclaw_engine/src/executor/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,114 @@ mod tests {
));
}

// ── Stop / pause / cancel intent (mission lifecycle) ─────────

#[test]
fn signals_tool_intent_stop_pause_cancel() {
assert!(eval_python_bool(
r#"signals_tool_intent("I'll stop the mission now.")"#
));
assert!(eval_python_bool(
r#"signals_tool_intent("Let me pause the ticker.")"#
));
assert!(eval_python_bool(
r#"signals_tool_intent("I'll cancel the monitoring.")"#
));
assert!(eval_python_bool(
r#"signals_tool_intent("I'm going to halt the recurring task.")"#
));
assert!(eval_python_bool(
r#"signals_tool_intent("I will disable the mission.")"#
));
}

#[test]
fn signals_tool_intent_no_false_positive_stop_discussion() {
// "let me explain" is in EXCLUSIONS — blocks the entire text
assert!(!eval_python_bool(
r#"signals_tool_intent("Let me explain how to stop the mission.")"#
));
// Past tense should not trigger
assert!(!eval_python_bool(
r#"signals_tool_intent("I already stopped the mission.")"#
));
}

// ── Execution intent: stop / pause / cancel ────────────────

#[test]
fn signals_execution_intent_stop_pause_cancel() {
assert!(eval_python_bool(r#"signals_execution_intent("stop it")"#));
assert!(eval_python_bool(
r#"signals_execution_intent("pause the mission")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("cancel that")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("please stop the ticker")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("please pause everything")"#
));
}

#[test]
fn signals_execution_intent_bare_stop() {
// Bare imperative commands — the exact user messages from #2808
assert!(eval_python_bool(r#"signals_execution_intent("stop")"#));
assert!(eval_python_bool(
r#"signals_execution_intent("stop pinging")"#
));
assert!(eval_python_bool(r#"signals_execution_intent("pause")"#));
assert!(eval_python_bool(r#"signals_execution_intent("cancel")"#));
assert!(eval_python_bool(r#"signals_execution_intent("halt")"#));
}

#[test]
fn signals_execution_intent_no_false_positive_stop_in_sentence() {
// "stop" mid-sentence should NOT trigger — only at the start
assert!(!eval_python_bool(
r#"signals_execution_intent("I can't stop thinking about it")"#
));
assert!(!eval_python_bool(
r#"signals_execution_intent("how do I stop a mission?")"#
));
}

#[test]
fn signals_execution_intent_halt_disable_phrases() {
// "halt/disable" pronoun+article phrases and "please halt/disable"
assert!(eval_python_bool(r#"signals_execution_intent("halt that")"#));
assert!(eval_python_bool(
r#"signals_execution_intent("halt the mission")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("disable it")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("disable the ticker")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("please halt the mission")"#
));
assert!(eval_python_bool(
r#"signals_execution_intent("please disable the routine")"#
));
// Bare "disable" command
assert!(eval_python_bool(r#"signals_execution_intent("disable")"#));
}

#[test]
fn signals_execution_intent_bare_stop_with_punctuation() {
// Bare commands with trailing punctuation must still match
assert!(eval_python_bool(r#"signals_execution_intent("stop.")"#));
assert!(eval_python_bool(r#"signals_execution_intent("cancel!")"#));
assert!(eval_python_bool(
r#"signals_execution_intent("stop pinging.")"#
));
}

// ── Skill activation: smart-quote / autocorrect resilience ───
//
// Regression for the ceo-setup non-activation report. iOS / macOS / most
Expand Down
4 changes: 0 additions & 4 deletions crates/ironclaw_gateway/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ <h2 data-i18n="restart.title">Restart IronClaw Instance</h2>
<!-- Chat Tab -->
<div class="tab-panel active" id="tab-chat">
<div class="thread-sidebar" id="thread-sidebar">
<div class="assistant-item" id="assistant-thread">
<span class="assistant-label" id="assistant-label" data-i18n="chat.assistant">Assistant</span>
<span class="assistant-meta" id="assistant-meta"></span>
</div>
<div class="threads-section-header">
<span data-i18n="chat.conversations">Conversations</span>
<div class="spacer"></div>
Expand Down
1 change: 0 additions & 1 deletion crates/ironclaw_gateway/static/js/core/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ let currentTab = 'chat';
let currentThreadId = null;
let currentThreadIsReadOnly = false;
const threadChannelHints = new Map();
let assistantThreadId = null;
let hasMore = false;
let oldestTimestamp = null;
let loadingOlder = false;
Expand Down
87 changes: 25 additions & 62 deletions crates/ironclaw_gateway/static/js/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,38 +389,16 @@ function loadThreads() {

apiFetch('/api/chat/threads').then((data) => {
const rememberedThreads = [];
// Pinned assistant thread
if (data.assistant_thread) {
assistantThreadId = data.assistant_thread.id;
rememberedThreads.push({
threadId: data.assistant_thread.id,
meta: {
label: I18n.t('thread.assistant'),
source: 'chat',
},
});
const el = document.getElementById('assistant-thread');
const isActive = currentThreadId === assistantThreadId;
el.className = 'assistant-item' + (isActive ? ' active' : '');
el.querySelectorAll('.thread-processing').forEach((node) => node.remove());
const labelEl = document.getElementById('assistant-label');
if (labelEl) {
labelEl.textContent = I18n.t('thread.assistant');
}
const meta = document.getElementById('assistant-meta');
meta.textContent = relativeTime(data.assistant_thread.updated_at);
if (data.assistant_thread.state === 'Processing' && !isActive) {
const spinner = document.createElement('span');
spinner.className = 'thread-processing';
spinner.innerHTML = '<div class="spinner"></div>';
el.appendChild(spinner);
}
}
const threads = [];
// Render one conversation list. The backend may still expose the legacy
// assistant conversation separately, but the sidebar should treat it like
// any other conversation row instead of pinning it above the list.
if (data.assistant_thread) threads.push(data.assistant_thread);
if (Array.isArray(data.threads)) threads.push(...data.threads);
threads.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime());

// Regular threads
const list = document.getElementById('thread-list');
list.innerHTML = '';
const threads = data.threads || [];
for (const thread of threads) {
rememberedThreads.push({
threadId: thread.id,
Expand Down Expand Up @@ -485,8 +463,7 @@ function loadThreads() {
if (window._pendingThreadRestore) {
var pendingId = window._pendingThreadRestore;
window._pendingThreadRestore = null;
var inSidebar = (pendingId === assistantThreadId) ||
threads.some(function(t) { return t.id === pendingId; });
var inSidebar = threads.some(function(t) { return t.id === pendingId; });
if (!inSidebar && window.DEBUG_CHAT_RESTORE === true) {
console.warn('[chat] thread', pendingId, 'not in sidebar list; loading via history API');
}
Expand All @@ -503,31 +480,35 @@ function loadThreads() {
// when the URL does not carry an explicit thread hash.
if (!currentThreadId) {
const activeThreadId = data.active_thread || null;
if (activeThreadId && activeThreadId === assistantThreadId) {
switchToAssistant();
return;
}
if (activeThreadId && threads.some(t => t.id === activeThreadId)) {
// Skip external-channel threads (e.g. HTTP, Telegram) — they are
// read-only in the web UI, so auto-switching to one would leave the
// chat input disabled. Fall through to the assistant thread instead.
const activeThread = threads.find(t => t.id === activeThreadId);
if (!isReadOnlyChannel(activeThread.channel)) {
if (activeThread && !isReadOnlyChannel(activeThread.channel)) {
switchThread(activeThreadId);
return;
}
}
if (assistantThreadId) {
switchToAssistant();

// Prefer a writable gateway-style thread for first load, but still show
// the newest read-only conversation if that's all the user has.
const fallbackThread = threads.find(t => !isReadOnlyChannel(t.channel)) || threads[0];
if (fallbackThread) {
switchThread(fallbackThread.id);
return;
}

currentThreadIsReadOnly = false;
enableChatInput();
const container = document.getElementById('chat-messages');
if (container) {
container.innerHTML = '';
showWelcomeCard();
}
return;
}

// Enable/disable chat input based on channel type
if (currentThreadId) {
const currentThread = currentThreadId === assistantThreadId
? data.assistant_thread
: threads.find(t => t.id === currentThreadId);
const currentThread = threads.find(t => t.id === currentThreadId);
const hintedChannel = currentThread
? currentThread.channel
: threadChannelHints.get(currentThreadId);
Expand All @@ -552,24 +533,6 @@ function disableChatInputReadOnly() {
if (btn) btn.disabled = true;
}

function switchToAssistant() {
if (!assistantThreadId) return;
finalizeActivityGroup();
currentThreadId = assistantThreadId;
currentThreadIsReadOnly = false;
unreadThreads.delete(assistantThreadId);
hasMore = false;
oldestTimestamp = null;
loadHistory();
loadThreads();
updateHash();
if (window.innerWidth <= 768) {
const sidebar = document.getElementById('thread-sidebar');
sidebar.classList.remove('expanded-mobile');
document.getElementById('thread-toggle-btn').innerHTML = '&raquo;';
}
}

function switchThread(threadId) {
clearSuggestionChips();
finalizeActivityGroup();
Expand Down
2 changes: 1 addition & 1 deletion crates/ironclaw_gateway/static/js/core/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function updateHash() {

switch (currentTab) {
case 'chat':
if (currentThreadId && currentThreadId !== assistantThreadId) {
if (currentThreadId) {
parts.push(currentThreadId);
}
break;
Expand Down
1 change: 0 additions & 1 deletion crates/ironclaw_gateway/static/js/core/ui-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ document.getElementById('restart-confirm-btn').addEventListener('click', () => c
document.getElementById('restart-btn').addEventListener('click', () => triggerRestart());
document.getElementById('thread-new-btn').addEventListener('click', () => createNewThread());
document.getElementById('thread-toggle-btn').addEventListener('click', () => toggleThreadSidebar());
document.getElementById('assistant-thread').addEventListener('click', () => switchToAssistant());
document.getElementById('send-btn').addEventListener('click', () => sendMessage());
document.getElementById('memory-edit-btn').addEventListener('click', () => startMemoryEdit());
document.getElementById('memory-save-btn').addEventListener('click', () => saveMemoryEdit());
Expand Down
6 changes: 5 additions & 1 deletion src/bridge/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5969,6 +5969,11 @@ pub(crate) mod test_support {
}
}

let project_id = threads
.first()
.map(|thread| thread.project_id)
.unwrap_or_default();

let store = Arc::new(ThreadTestStore::new());
for thread in threads {
store.save_thread(&thread).await.expect("seed thread"); // safety: cfg(test) fixture
Expand Down Expand Up @@ -5996,7 +6001,6 @@ pub(crate) mod test_support {
));
let cm = Arc::new(ConversationManager::new(Arc::clone(&tm), store_dyn.clone()));

let project_id = ProjectId::new();
let state = EngineState {
thread_manager: tm,
conversation_manager: cm,
Expand Down
Loading
Loading