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.

fix(chat): find the longest matching workflow name before splitting on a colon

purple63497cde366a
diff --git a/src/hooks/__tests__/workflow-trigger-echtes-gate-und-stop.test.ts b/src/hooks/__tests__/workflow-trigger-echtes-gate-und-stop.test.ts
index 623cb554..44529fb1 100644
--- a/src/hooks/__tests__/workflow-trigger-echtes-gate-und-stop.test.ts
+++ b/src/hooks/__tests__/workflow-trigger-echtes-gate-und-stop.test.ts
@@ -204,3 +204,86 @@ describe('klein 1: "run workflow <name>: <input>" beantwortet den ersten user_in
expect(lastAssistant.content).toMatch(/Saved to memory: quantum computing/)
})
})
+
+describe('Nachtrag 1, bau/review-wfgate.md Runde 3: ein Ablaufname MIT Doppelpunkt', () => {
+ /** Zwei Ablaeufe, deren Namen sich nur durch den Doppelpunkt-Teil
+ * unterscheiden: "Deploy" (fragt nach der Umgebung) und "Deploy: staging"
+ * (fuehrt direkt ein blockiertes Werkzeug aus). Vor dem Fix waere
+ * "run workflow Deploy: staging" am ERSTEN Doppelpunkt gesplittet worden,
+ * haette Name "Deploy" und Eingabe "staging" ergeben und damit den
+ * falschen (oder bei einem echten Doppelpunkt-Namen: GAR keinen) Ablauf
+ * getroffen. */
+ function deployWorkflow() {
+ return {
+ id: 'guard-wf-deploy',
+ name: 'Deploy',
+ description: '',
+ icon: 'Zap',
+ steps: [{ id: 's1', type: 'user_input' as const, label: 'Ask', userInputPrompt: 'Which environment?' }],
+ variables: {},
+ isBuiltIn: false,
+ createdAt: 0,
+ updatedAt: 0,
+ }
+ }
+ function deployStagingWorkflow() {
+ return {
+ id: 'guard-wf-deploy-staging',
+ name: 'Deploy: staging',
+ description: '',
+ icon: 'Zap',
+ steps: [{ id: 's1', type: 'tool' as const, label: 'run it', toolName: 'shell_execute', toolArgs: { command: 'echo hi' } }],
+ variables: {},
+ isBuiltIn: false,
+ createdAt: 0,
+ updatedAt: 0,
+ }
+ }
+
+ it('"run workflow Deploy: staging" trifft den Ablauf "Deploy: staging", nicht "Deploy" mit Eingabe "staging"', async () => {
+ useAgentWorkflowStore.setState((s) => ({ workflows: [...s.workflows, deployWorkflow(), deployStagingWorkflow()] }))
+ usePermissionStore.getState().setGlobalPermission('terminal', 'blocked')
+ const execSpy = vi.spyOn(toolRegistry, 'execute')
+
+ const { result } = renderHook(() => useAgentChat())
+ const convId = seed()
+
+ await act(async () => {
+ await result.current.sendAgentMessage('run workflow Deploy: staging')
+ await tick()
+ })
+
+ // Negativkontrolle: der falsche Treffer waere "Deploy" mit Eingabe
+ // "staging" gewesen, dessen einziger Schritt sofort fertig ist und NIE
+ // nach der Umgebung fragt und NIE ein Werkzeug ausfuehrt.
+ expect(execSpy.mock.calls.map((c) => c[0])).not.toContain('memory_save')
+ const conv = useChatStore.getState().conversations.find((c) => c.id === convId)!
+ const lastAssistant = [...conv.messages].reverse().find((m) => m.role === 'assistant')!
+ expect(lastAssistant.content).not.toMatch(/Which environment\?/)
+ // Positivkontrolle: "Deploy: staging" wurde erkannt und sein blockiertes
+ // Werkzeug lief nie, meldet aber den Ablehnungsfehler statt zu haengen.
+ expect(execSpy.mock.calls.map((c) => c[0])).not.toContain('shell_execute')
+ expect(lastAssistant.content).toMatch(/Workflow error/)
+ })
+
+ it('Negativkontrolle: ohne den passenden Namen "Deploy: staging" im Store faellt der alte Doppelpunkt-Split wieder zum kuerzeren Namen zurueck', async () => {
+ useAgentWorkflowStore.setState((s) => ({ workflows: [...s.workflows, deployWorkflow()] }))
+
+ const { result } = renderHook(() => useAgentChat())
+ const convId = seed()
+
+ await act(async () => {
+ await result.current.sendAgentMessage('run workflow Deploy: staging')
+ await tick()
+ await tick()
+ })
+
+ // Ohne den laengeren Namen im Store greift der Fallback (Split am ersten
+ // Doppelpunkt): Name "Deploy", Eingabe "staging" fuellt den einzigen
+ // user_input-Schritt vor, der Ablauf laeuft durch statt zu fragen.
+ expect(__activeAgentRunConvIdsForTests()).not.toContain(convId)
+ const conv = useChatStore.getState().conversations.find((c) => c.id === convId)!
+ const lastAssistant = [...conv.messages].reverse().find((m) => m.role === 'assistant')!
+ expect(lastAssistant.content).not.toMatch(/Which environment\?/)
+ })
+})
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 7d960c83..8f398bb4 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -315,13 +315,41 @@ export function useAgentChat() {
// R2, bau/review-wfgate.md klein 1: "run workflow <name>: <input>" lets
// the text after the FIRST colon answer the workflow's first
// `user_input` step, the same convention `run_workflow`'s own `input`
- // argument uses (builtin-tools.ts). Optional and non-greedy on the name
- // so a colon-free name still matches unchanged.
- const workflowMatch = userContent.match(/^run\s+workflow\s+([^:]+?)\s*(?::\s*([\s\S]*))?$/i)
- if (workflowMatch) {
- const workflowName = workflowMatch[1].trim()
- const workflowInput = workflowMatch[2]?.trim()
+ // argument uses (builtin-tools.ts).
+ //
+ // Nachtrag 1, Runde 3 (bau/review-wfgate.md): a workflow name is a free
+ // text field (WorkflowBuilder.tsx), so it can itself contain a colon.
+ // Splitting at the FIRST colon unconditionally broke that case
+ // silently: "run workflow Deploy: staging" against a workflow actually
+ // named "Deploy: staging" used to look for name "Deploy" instead, find
+ // nothing, and fall through to an ordinary chat message. Fix: look up
+ // the LONGEST workflow name (from the store, case-insensitive like the
+ // rest of this match) that the text after "run workflow" starts with,
+ // and only take whatever follows it as the ": <input>" answer. Only
+ // when no stored name matches at all does this fall back to the old
+ // split-at-first-colon behaviour (whose result then simply won't be
+ // found below either, same as an unrecognised name always was).
+ const runWorkflowMatch = userContent.match(/^run\s+workflow\s+([\s\S]+)$/i)
+ let workflowName = ''
+ let workflowInput: string | undefined
+ if (runWorkflowMatch) {
+ const rest = runWorkflowMatch[1].trim()
const wfStore = useAgentWorkflowStore.getState()
+ const byLongestName = [...wfStore.workflows].sort((a, b) => b.name.length - a.name.length)
+ const nameMatch = byLongestName.find(w => {
+ if (rest.length < w.name.length) return false
+ if (rest.slice(0, w.name.length).toLowerCase() !== w.name.toLowerCase()) return false
+ const after = rest.slice(w.name.length).trimStart()
+ return after === '' || after.startsWith(':')
+ })
+ if (nameMatch) {
+ workflowName = nameMatch.name
+ workflowInput = rest.slice(nameMatch.name.length).trimStart().replace(/^:\s*/, '').trim() || undefined
+ } else {
+ const fallback = rest.match(/^([^:]+?)\s*(?::\s*([\s\S]*))?$/)
+ workflowName = fallback?.[1]?.trim() ?? rest
+ workflowInput = fallback?.[2]?.trim()
+ }
const workflow = wfStore.workflows.find(
w => w.name.toLowerCase() === workflowName.toLowerCase()
)