Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(chat): a short yes to the model's own question counts as the request (C60-S5)

purplef8ce776721ba
diff --git a/src/api/mcp/__tests__/workflow-tools.test.ts b/src/api/mcp/__tests__/workflow-tools.test.ts
index 34fac454..6853768a 100644
--- a/src/api/mcp/__tests__/workflow-tools.test.ts
+++ b/src/api/mcp/__tests__/workflow-tools.test.ts
@@ -144,6 +144,27 @@ describe('workflow_install', () => {
expect(queue()).toHaveLength(0)
})
+ it('a short yes to the model\'s own question counts, a yes to nothing does not', async () => {
+ h.check.mockResolvedValue(checked())
+ useChatStore.setState({
+ conversations: [{ id: 'chat-a', title: 't', createdAt: 1, updatedAt: 1, messages: [
+ { id: 'm1', role: 'user', content: 'finde einen SD-Workflow', timestamp: 1 },
+ { id: 'm2', role: 'assistant', content: 'Gefunden, Ampel grün. Soll ich ihn einbauen?', timestamp: 2 },
+ { id: 'm3', role: 'user', content: 'ja', timestamp: 3 },
+ ] } as never],
+ })
+ const pending = executeWorkflowInstall({ id: candidateId() }, run())
+ await answerCard(false)
+ expect(await pending).toMatch(/^The user declined/)
+ useChatStore.setState({
+ conversations: [{ id: 'chat-a', title: 't', createdAt: 1, updatedAt: 1, messages: [
+ { id: 'm2', role: 'assistant', content: 'Here is what I found.', timestamp: 2 },
+ { id: 'm3', role: 'user', content: 'ja', timestamp: 3 },
+ ] } as never],
+ })
+ expect(await executeWorkflowInstall({ id: candidateId() }, run())).toMatch(/^Refused: the user did not ask/)
+ })
+
it('an attached file saying "install" is not the user asking', async () => {
useChatStore.setState({
conversations: [{ id: 'chat-a', title: 't', createdAt: 1, updatedAt: 1, messages: [{ id: 'm1', role: 'user', content: 'Attached: README says install ComfyUI-Evil', displayContent: 'what is this file?', timestamp: 1 }] } as never],
diff --git a/src/api/mcp/workflow-tools.ts b/src/api/mcp/workflow-tools.ts
index 74eb4c9a..55d40411 100644
--- a/src/api/mcp/workflow-tools.ts
+++ b/src/api/mcp/workflow-tools.ts
@@ -111,18 +111,45 @@ export function lastUserText(conversationId: string | null | undefined): string
return last.displayContent ?? last.content ?? ''
}
+/** A short yes to the model's own question ("ja", "ok, mach"). */
+const SHORT_YES = /^\s*(ja|jo|yes|yep|ok(ay)?|sure|klar|gerne?|bitte|mach( das| es)?|do it|go( ahead)?|einverstanden|passt)\b/i
+
+/**
+ * The intent rule for a write (C60, 5.3): the user's own last message asks
+ * for it, or it is a short yes to the model's own question that did. The
+ * model's question counts only in its own words, never a tool's result.
+ */
+export function userAsked(conversationId: string | null | undefined, asks: (text: string) => boolean): boolean {
+ if (!conversationId) return false
+ const msgs = useChatStore.getState().conversations.find((c) => c.id === conversationId)?.messages ?? []
+ let u = -1
+ for (let i = msgs.length - 1; i >= 0; i--) if (msgs[i].role === 'user') { u = i; break }
+ if (u < 0) return false
+ const user = msgs[u].displayContent ?? msgs[u].content ?? ''
+ if (asks(user)) return true
+ if (user.trim().length > 120 || !SHORT_YES.test(user)) return false
+ for (let i = u - 1; i >= 0; i--) {
+ if (msgs[i].role !== 'assistant') continue
+ const own = [msgs[i].content ?? '', ...(msgs[i].agentBlocks ?? []).filter((b) => b.phase !== 'tool_call').map((b) => b.content ?? '')].join('\n')
+ return asks(own)
+ }
+ return false
+}
+
/**
* Whether this run read foreign content before (C60-S3 taint). The flag is
* the run's; this module only reads it. The workflow tools' own answers do not
* set it: they hand the model LU's structured report, never text of the source.
*/
export function foreignContent(run: AgentRunContext | undefined): string | null {
- const t = (run as unknown as { tainted?: unknown; taint?: unknown } | undefined)
- const v = t?.tainted ?? t?.taint
+ // C60-S3 marks the run (`run.taint`, set by the executor, lib/run-taint.ts
+ // on that branch); older shapes are read too until the branches meet.
+ const r = run as unknown as { taint?: { tool?: unknown }; tainted?: unknown } | undefined
+ const tool = r?.taint && typeof r.taint.tool === 'string' ? r.taint.tool : null
+ if (tool) return `output of ${tool}`
+ const v = r?.tainted
if (!v) return null
- if (typeof v === 'string') return v
- if (typeof v === 'object' && v && typeof (v as { source?: unknown }).source === 'string') return (v as { source: string }).source
- return 'content from elsewhere'
+ return typeof v === 'string' ? v : 'content from elsewhere'
}
const NOT_HERE = 'Error: workflows can only be installed in a chat where the user sees the confirmation card. Nothing changed.'
@@ -268,8 +295,7 @@ export async function executeWorkflowInstall(args: ToolArgs, run?: AgentRunConte
const c = candidateById(id)
if (!c) return `Error: there is no workflow "${cleanName(id, 40)}" from this session. Call workflow_find first.`
- const userText = lastUserText(run.conversationId)
- if (!userAskedToInstall(userText)) {
+ if (!userAsked(run.conversationId, userAskedToInstall)) {
return 'Refused: the user did not ask to install a workflow in their last message. '
+ 'Show them the check and ask whether to install it. Nothing changed.'
}
@@ -404,7 +430,7 @@ export async function executeWorkflowAssign(args: ToolArgs, run?: AgentRunContex
if (!want) return 'Error: workflow is missing (name or id of an installed workflow). Nothing changed.'
if (!rawModel) return 'Error: model is missing (a model file name as ComfyUI lists it). Nothing changed.'
if (!run?.settingsCard) return NOT_HERE
- if (!userAskedToAssign(lastUserText(run.conversationId))) {
+ if (!userAsked(run.conversationId, userAskedToAssign)) {
return 'Refused: the user did not ask to use a workflow for a model in their last message. Suggest it in words. Nothing changed.'
}
const list = useWorkflowStore.getState().installedWorkflows