Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): read accounting negatives in XLSX and note dates kept as text
marcoteba709e9ac1136
diff --git a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.tsindex cb41a2f8a..0447e878e 100644--- a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts@@ -389,6 +389,23 @@ describe('signs, identifiers and text left as sent', () => {expect(ws.getCell('E4').value).toBe('+1-800-555-0100')})+ it('reads accounting parentheses as a sign on a quantity, and notes refused dates', async () => {+ const { ws, result } = await oneSheet([+ ['Account', 'Q1', 'Q2', 'Note', 'Booked on'],+ ['A', 1200, '($300)', '(1)', '2026-02-27'],+ ['B', '(500)', '(1,200.50)', '(2)', '2026-02-29'],+ ['C', 700, 1200, '(3)', '1899-12-31'],+ ])+ expect(ws.getCell('B3').value).toBe(-500)+ expect(ws.getCell('C2').value).toBe(-300)+ expect(ws.getCell('C3').value).toBe(-1200.5)+ expect(ws.getCell('D2').value).toBe('(1)')+ expect(ws.getCell('E3').value).toBe('2026-02-29')+ expect(result.content).toContain(+ "column 'Booked on': 2 dates such as '2026-02-29' were kept as text"+ )+ })+it('writes identifier columns without thousands separators', async () => {const headers = ['Invoice No.',diff --git a/mcp-host/src/workflow/xlsxCells.ts b/mcp-host/src/workflow/xlsxCells.tsindex 8fefbb8a3..7de2adce5 100644--- a/mcp-host/src/workflow/xlsxCells.ts+++ b/mcp-host/src/workflow/xlsxCells.ts@@ -103,6 +103,18 @@ export function currencySuffix(s: string): [string, number] | undefined {type ParsedNumber = { value: number; written: number; percent: boolean; currency?: string }function parseNumberText(text: string): ParsedNumber | 'ambiguous' | undefined {+ // "(500)" is how accounting writes -500. "(1)" also marks a note, so the+ // parentheses are a sign only on a clear quantity, as a leading "+" is below.+ const accounting = /^\((.+)\)$/.exec(text)+ if (accounting && !/^[-+\u2212]/.test(accounting[1].trim())) {+ const inner = parseNumberText(accounting[1].trim())+ if (inner === undefined || inner === 'ambiguous') return inner+ const digits = accounting[1].replace(/\D/g, '').length+ if (!inner.currency && !inner.percent && !/[.,]/.test(accounting[1]) && digits < 3) {+ return undefined+ }+ return { ...inner, value: -inner.value, written: -inner.written }+ }let s = textlet percent = falseif (s.endsWith('%')) {@@ -230,6 +242,15 @@ const LOCALE_NUMBERS = []const LOCALE_DATE = /^(?:\d{1,2}[/.-]\d{1,2}[/.-]\d{2,4}|\d{4}\/\d{1,2}\/\d{1,2})$/+/**+ * Whether text kept as text is an ISO 8601 date this reader refused: one that+ * does not exist, or one before 1 March 1900, which Excel shows a day late.+ */+export function looksLikeRefusedDate(text: string): boolean {+ const s = text.trim()+ return ISO_DATE.test(s) && !parseDateText(s)+}+/*** Whether text kept as text spells a number or a date in a form this reader* does not convert ("1.234,50", "12,5%", "22/09/2026", "1e6"), so the callerdiff --git a/mcp-host/src/workflow/xlsxWorkbook.ts b/mcp-host/src/workflow/xlsxWorkbook.tsindex 851ab15ef..53d3a7c84 100644--- a/mcp-host/src/workflow/xlsxWorkbook.ts+++ b/mcp-host/src/workflow/xlsxWorkbook.ts@@ -16,6 +16,7 @@ import {cellProblem,codeDigits,isQuantityText,+ looksLikeRefusedDate,looksLikeUnreadNumber,readCell,startsLikeFormula,@@ -614,6 +615,20 @@ function writeSheet('; send JSON numbers, or ISO 8601 dates such as 2026-09-22.')}+ const refused = requested.has(c)+ ? []+ : cells.filter(cell => cell.kind === 'text' && looksLikeRefusedDate(cell.text))+ if (refused.length > 0) {+ const sample = refused[0].text.trim()+ warnings.push(+ `${columnName(c)}: ` ++ (refused.length === 1+ ? `'${sample}' was kept as text: it is not a real date, or it is`+ : `${refused.length} dates such as '${sample}' were kept as text: each is not a ` ++ 'real date, or is') ++ ' before 1 March 1900, where Excel dates start.'+ )+ }if (cells.some(cell => cell.shifted)) {warnings.push(`${columnName(c)}: times with a UTC offset were converted to UTC.`)}