Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): narrow workflow intent recovery to the dev-accepted variants
Alfredo Lopeze0c9021b3226
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 4a3694e8a..1c438ffc3 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.471",+ "version": "0.1.472","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.471",+ "version": "0.1.472","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 5fb1bfddd..d0972e591 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.471",+ "version": "0.1.472","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.test.ts b/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.test.tsindex a0377358f..e5c9e162c 100644--- a/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.test.ts+++ b/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.test.ts@@ -42,11 +42,49 @@ describe('shouldRecoverWorkflowTriggerTextResponse', () => {expect(shouldRecoverWorkflowTriggerTextResponse(userText, 'I can help with that.')).toBe(true)})+ // These all returned true on origin/dev (any hyphenated token plus a trigger verb).+ it.each([+ 'run the daily-report',+ 'can you run daily-report',+ 'could you please run daily-report',+ 'run daily-report now',+ 'run daily-report please',+ 'please run daily-report!',+ 'run daily-report?',+ 'trigger daily-report with region=eu',+ 'Run "daily-report" now.',+ 'execute daily-report using region=eu and dry-run=true',+ ])('recovers a direct named recipe request with a natural tail: %s', userText => {+ expect(shouldRecoverWorkflowTriggerTextResponse(userText, 'I can help with that.')).toBe(true)+ })+it.each(['Run a shell command',+ 'run daily-report with',+ 'run daily-report and delete it',+ 'run daily-report now and then rm -rf /','Run quarterly-report and delete it',`Run ${'a'.repeat(129)}-report`,])('does not infer a recipe from unrelated or oversized text: %s', userText => {expect(shouldRecoverWorkflowTriggerTextResponse(userText, 'I can help with that.')).toBe(false)})++ it.each([+ ['whitespace after the verb', `run${' '.repeat(200_000)}x`],+ ['leading whitespace', `${' '.repeat(200_000)}run`],+ ['one long token', `run ${'a'.repeat(200_000)}`],+ ['repeated hyphen groups', `run ${'a-'.repeat(100_000)}`],+ ['long tail of filler', `run daily-report${' now'.repeat(50_000)} !`],+ ['whitespace before a rejected tail', `run daily-report${' '.repeat(200_000)}x`],+ ['long punctuation run', `run daily-report${'!'.repeat(200_000)}x`],+ ['repeated verbs', 'run '.repeat(50_000)],+ ])('classifies adversarial input in linear time: %s', (_label, userText) => {+ expect(userText.length).toBeGreaterThanOrEqual(150_000)+ const started = performance.now()+ const result = shouldRecoverWorkflowTriggerTextResponse(userText, 'I can help with that.')+ const elapsedMs = performance.now() - started+ // Liveness witness: a boolean means the classifier ran to completion.+ expect(typeof result).toBe('boolean')+ expect(elapsedMs).toBeLessThan(100)+ })})diff --git a/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.ts b/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.tsindex 7fb9964d9..deaa1dedc 100644--- a/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.ts+++ b/mcp-host/src/core/orchestration/toolUseLoopIntentRecovery.ts@@ -82,6 +82,42 @@ export function shouldRecoverWorkflowArtifactTextResponse(userText: string): booreturn namesWorkflow && includesRecipeLikeName}+// A direct trigger is `[can you] [please] <verb> [the] <one token>` followed only+// by filler (`now`, `please`, `again`), sentence punctuation, or `with|using`+// arguments. The head regex is anchored and every quantifier is bounded or+// separated from its neighbours by a literal, so it stays linear on adversarial+// input; the tail is checked with string operations instead of a second regex.+const DIRECT_TRIGGER_HEAD =+ /^\s*(?:(?:can|could|would|will)\s+you\s+)?(?:please\s+)?(?:run|execute|trigger|start|launch)\s+(?:the\s+)?(\S{1,128})(?=\s|$)/i+const DIRECT_TRIGGER_FILLER = new Set(['now', 'again', 'please', 'immediately'])+const RECIPE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)+$/i++function stripTrailingSentencePunctuation(value: string): string {+ let end = value.length+ while (end > 0 && '.!?'.includes(value[end - 1])) end--+ return value.slice(0, end)+}++function isDirectTriggerTail(tail: string): boolean {+ const words = tail.trim().split(/\s+/)+ for (let i = 0; i < words.length; i++) {+ const word = stripTrailingSentencePunctuation(words[i]).toLowerCase()+ if (word === '' || DIRECT_TRIGGER_FILLER.has(word)) continue+ return (word === 'with' || word === 'using') && i + 1 < words.length+ }+ return true+}++function isDirectRecipeTrigger(userText: string): boolean {+ const head = DIRECT_TRIGGER_HEAD.exec(userText)+ if (head === null) return false+ const candidate = stripTrailingSentencePunctuation(+ head[1].replace(/[\u0060\u0022\u0027\u201C\u201D\u2018\u2019]/g, '')+ )+ if (!RECIPE_NAME.test(candidate)) return false+ return isDirectTriggerTail(userText.slice(head[0].length))+}+export function shouldRecoverWorkflowTriggerTextResponse(userText: string,responseText: string@@ -89,15 +125,7 @@ export function shouldRecoverWorkflowTriggerTextResponse(if (isWorkflowListIntent(userText)) return falseconst normalizedUser = userText.toLowerCase()- const directTrigger = userText.match(- /^\s*(?:please\s+)?(?:run|execute|trigger|start|launch)\s+(\S{1,128})\s*$/i- )- const directCandidate = directTrigger?.[1]- .replace(/[\u0060\u0022\u0027\u201C\u201D\u2018\u2019]/g, '')- .replace(/\.$/, '')- .trim()- const namesDirectRecipe =- directCandidate !== undefined && /^[a-z0-9]+(?:-[a-z0-9]+)+$/i.test(directCandidate)+ const namesDirectRecipe = isDirectRecipeTrigger(userText)const asksToTrigger = /\b(run|start|trigger|execute|launch)\b/.test(normalizedUser)const includesRecipeLikeName = /\b[a-z0-9]+(?:-[a-z0-9]+)+\b/.test(normalizedUser)const namesWorkflow =