Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): keep the plus sign an XLSX number was written with

marcotebc8a83b660a9d
diff --git a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
index c208192db..3a1a8f8e6 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
@@ -404,6 +404,20 @@ describe('signs, identifiers and text left as sent', () => {
expect(ws.getCell('E4').value).toBe('+1-800-555-0100')
})
+ it('keeps showing the plus a number was written with', async () => {
+ const { ws } = await oneSheet([
+ ['Dial prefix', 'Score change', 'Share'],
+ ['+44', '+5', '+12%'],
+ ['+1', '-3', '-3%'],
+ ])
+ expect(ws.getCell('A2').value).toBe(44)
+ expect(ws.getCell('A2').numFmt).toMatch(/^\+/)
+ expect(ws.getCell('B2').value).toBe(5)
+ expect(ws.getCell('B2').numFmt).toMatch(/^\+[^;]*;-/)
+ expect(ws.getCell('B3').numFmt ?? '').not.toMatch(/^\+/)
+ expect(ws.getCell('C2').numFmt).toMatch(/^\+[^;]*%/)
+ })
+
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'],
diff --git a/mcp-host/src/workflow/xlsxCells.ts b/mcp-host/src/workflow/xlsxCells.ts
index 7de2adce5..edc464f82 100644
--- a/mcp-host/src/workflow/xlsxCells.ts
+++ b/mcp-host/src/workflow/xlsxCells.ts
@@ -62,6 +62,8 @@ export interface SheetCell {
written?: number
/** Symbol a currency text carried. */
currency?: string
+ /** Written with a leading "+", which its format keeps showing. */
+ signed?: boolean
/** A time with seconds, shown with them. */
seconds?: boolean
/** A time with a UTC offset, moved to UTC. */
@@ -100,7 +102,13 @@ export function currencySuffix(s: string): [string, number] | undefined {
return undefined
}
-type ParsedNumber = { value: number; written: number; percent: boolean; currency?: string }
+type ParsedNumber = {
+ value: number
+ written: number
+ percent: boolean
+ currency?: string
+ plus?: boolean
+}
function parseNumberText(text: string): ParsedNumber | 'ambiguous' | undefined {
// "(500)" is how accounting writes -500. "(1)" also marks a note, so the
@@ -156,7 +164,7 @@ function parseNumberText(text: string): ParsedNumber | 'ambiguous' | undefined {
const written = Number(plain) || 0
// Shifting the exponent in the text avoids 1.1 / 100 = 0.011000000000000001.
const value = percent ? Number(`${plain}e-2`) || 0 : written
- return { value, written, percent, currency }
+ return { value, written, percent, currency, ...(plus ? { plus } : {}) }
}
const ISO_DATE =
@@ -225,6 +233,7 @@ export function readCell(raw: unknown, convert = true): SheetCell {
text,
written: parsed.written,
currency: parsed.currency,
+ ...(parsed.plus ? { signed: true } : {}),
}
}
diff --git a/mcp-host/src/workflow/xlsxWorkbook.ts b/mcp-host/src/workflow/xlsxWorkbook.ts
index 72895623a..1b97d54bf 100644
--- a/mcp-host/src/workflow/xlsxWorkbook.ts
+++ b/mcp-host/src/workflow/xlsxWorkbook.ts
@@ -370,9 +370,31 @@ function fits(spec: FormatSpec, cell: SheetCell): boolean {
}
/** The value written for `cell` and the format it is shown with. */
+/**
+ * `numFmt` showing a "+" before a positive value, as the cell was written. A
+ * format of one section gets its negative and zero sections too, since Excel
+ * would otherwise print a negative as "-+5".
+ */
+function withPlus(numFmt: string | undefined): string {
+ const format = numFmt ?? 'General'
+ const sections = format.split(';')
+ if (sections.length === 1) return `+${format};-${format};${format}`
+ return [`+${sections[0]}`, ...sections.slice(1)].join(';')
+}
+
function cellOutput(
cell: SheetCell,
plan: ColumnPlan
+): { value: SheetCell['value']; numFmt?: string } {
+ const out = plainCellOutput(cell, plan)
+ return cell.signed && typeof out.value === 'number' && out.value > 0
+ ? { ...out, numFmt: withPlus(out.numFmt) }
+ : out
+}
+
+function plainCellOutput(
+ cell: SheetCell,
+ plan: ColumnPlan
): { value: SheetCell['value']; numFmt?: string } {
const { spec } = plan
const value =