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 years that begin a slide's bullets

marcotebf0d23012722a
diff --git a/mcp-host/src/workflow/__tests__/internalTools.pptx.contract.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pptx.contract.test.ts
index 595ceb6da..58667c15b 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.pptx.contract.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.pptx.contract.test.ts
@@ -260,6 +260,48 @@ describe('clerum__generate_pptx — execute() answers malformed input by field',
expect(body.paragraphs).toEqual(['one', 'two'])
})
+ it('keeps the year that begins each bullet, and takes list numbers off', async () => {
+ const bodyOf = async (bullets: string[] | string) => {
+ const result = await generatePptx(
+ { filename: 'n.pptx', slides: [{ layout: 'title-bullets', title: 'Years', bullets }] },
+ outputDir
+ )
+ expect(result.success, result.error).toBe(true)
+ expect(result.content).not.toContain('Notes')
+ return textShapes(slideXml(path.join(outputDir, 'n.pptx'), 1)).find(s =>
+ s.paragraphs.some(p => p.includes('year') || p.includes('Second'))
+ )!.paragraphs
+ }
+ expect(await bodyOf(['2024. A record year', '2025. Another strong year'])).toEqual([
+ '2024. A record year',
+ '2025. Another strong year',
+ ])
+ expect(await bodyOf('1. First\n2) Second')).toEqual(['First', 'Second'])
+ })
+
+ it('takes the numbers off every level of a numbered outline, and says it was flattened', async () => {
+ const outline = [
+ '1. Plan',
+ ' 1. Build',
+ ' 1. Design',
+ ' 2. Code',
+ ' 2. Ship',
+ '2. Grow',
+ ]
+ for (const bullets of [outline.join('\n'), outline]) {
+ const result = await generatePptx(
+ { filename: 'o.pptx', slides: [{ layout: 'title-bullets', title: 'Outline', bullets }] },
+ outputDir
+ )
+ expect(result.success, result.error).toBe(true)
+ expect(result.content).toContain('is a nested bullet')
+ const body = textShapes(slideXml(path.join(outputDir, 'o.pptx'), 1)).find(s =>
+ s.paragraphs.some(p => p.includes('Design'))
+ )!
+ expect(body.paragraphs).toEqual(['Plan', 'Build', 'Design', 'Code', 'Ship', 'Grow'])
+ }
+ })
+
it('reads table rows sent as records in header order', async () => {
const result = await generatePptx(
{
diff --git a/mcp-host/src/workflow/__tests__/pptxInput.test.ts b/mcp-host/src/workflow/__tests__/pptxInput.test.ts
index b49c85849..d5415e7a6 100644
--- a/mcp-host/src/workflow/__tests__/pptxInput.test.ts
+++ b/mcp-host/src/workflow/__tests__/pptxInput.test.ts
@@ -22,8 +22,19 @@ describe('readStringList', () => {
})
it('takes the numbers off a numbered list and keeps its order', () => {
- expect(list('1. First\n2) Second\n10. Tenth')).toEqual(['First', 'Second', 'Tenth'])
+ expect(list('1. First\n2) Second\n3. Third')).toEqual(['First', 'Second', 'Third'])
expect(list(['1. First', '2. Second'])).toEqual(['First', 'Second'])
+ expect(list('1. First\n\n2. Second')).toEqual(['First', 'Second'])
+ expect(list('- Intro\n1. First\n2. Second')).toEqual(['Intro', 'First', 'Second'])
+ })
+
+ it('takes off numbers of two digits and more', () => {
+ const items = Array.from({ length: 12 }, (_, i) => `Item ${i + 1}`)
+ expect(list(items.map((item, i) => `${i + 1}. ${item}`).join('\n'))).toEqual(items)
+ })
+
+ it('takes off a 1 that numbers every item, as Markdown allows', () => {
+ expect(list('1. First\n1. Second\n1. Third')).toEqual(['First', 'Second', 'Third'])
})
it('keeps a number that starts an item when the text is not a list', () => {
@@ -34,6 +45,30 @@ describe('readStringList', () => {
])
})
+ it('keeps numbers that do not count the items from 1: they are part of the text', () => {
+ const ctx = context()
+ const years = ['2024. A record year', '2025. Another strong year']
+ expect(list(years, ctx)).toEqual(years)
+ expect(list(years.join('\n'), ctx)).toEqual(years)
+ expect(list(years.map(year => `- ${year}`).join('\n'), ctx)).toEqual(years)
+ expect(list('- Revenue\n- 2024. A record year', ctx)).toEqual([
+ 'Revenue',
+ '2024. A record year',
+ ])
+ expect(list(['1. Acme', '2. Globex', '5. Initech'], ctx)).toEqual([
+ '1. Acme',
+ '2. Globex',
+ '5. Initech',
+ ])
+ expect(list('4. Fourth\n5. Fifth', ctx)).toEqual(['4. Fourth', '5. Fifth'])
+ expect(list('1. First\n2. Second\n2024. A record year', ctx)).toEqual([
+ '1. First',
+ '2. Second',
+ '2024. A record year',
+ ])
+ expect(ctx.warnings).toEqual([])
+ })
+
it('sets a nested bullet at the first level and says so', () => {
const ctx = context()
expect(list('- Revenue\n - EMEA up 12%\n 1. APAC flat\n- Costs', ctx)).toEqual([
@@ -46,6 +81,160 @@ describe('readStringList', () => {
expect(ctx.warnings[0]).toContain('bullets line 2 is a nested bullet')
})
+ it('numbers each run of nested items on its own', () => {
+ const ctx = context()
+ expect(list('1. Revenue\n 1. EMEA\n 2. APAC\n2. Costs\n 1. Payroll', ctx)).toEqual([
+ 'Revenue',
+ 'EMEA',
+ 'APAC',
+ 'Costs',
+ 'Payroll',
+ ])
+ expect(ctx.warnings).toHaveLength(1)
+ })
+
+ it('keeps the numbers of nested items that do not count from 1', () => {
+ const ctx = context()
+ expect(list('Milestones:\n 2024. Launch\n 2025. Growth', ctx)).toEqual([
+ 'Milestones:',
+ '2024. Launch',
+ '2025. Growth',
+ ])
+ expect(ctx.warnings).toHaveLength(1)
+ expect(ctx.warnings[0]).toContain('bullets line 2 is a nested bullet')
+ expect(list('1. Plan\n - 2024. Launch\n2. Grow')).toEqual(['Plan', '2024. Launch', 'Grow'])
+ })
+
+ it('takes the numbers off an outline numbered at every level', () => {
+ const outline = [
+ '1. Plan',
+ ' 1. Build',
+ ' 1. Design',
+ ' 2. Code',
+ ' 2. Ship',
+ '2. Grow',
+ ]
+ const ctx = context()
+ expect(list(outline.join('\n'), ctx)).toEqual([
+ 'Plan',
+ 'Build',
+ 'Design',
+ 'Code',
+ 'Ship',
+ 'Grow',
+ ])
+ expect(ctx.warnings).toHaveLength(1)
+ expect(ctx.warnings[0]).toContain('bullets line 2 is a nested bullet')
+ expect(list(outline)).toEqual(['Plan', 'Build', 'Design', 'Code', 'Ship', 'Grow'])
+ expect(list('1. A\n 1. B\n 1. C\n 2. D\n 2. E\n2. F')).toEqual([
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ 'F',
+ ])
+ expect(list('1. A\n\t1. B\n\t\t1. C\n\t2. D')).toEqual(['A', 'B', 'C', 'D'])
+ expect(list('1. A\n 1. B\n 2. C\n 1. D\n 3. E')).toEqual(['A', 'B', 'C', 'D', 'E'])
+ expect(list('- A\n 1. B\n 2. C\n 1. D')).toEqual(['A', 'B', 'C', 'D'])
+ })
+
+ it('counts a numbered sublist on its own under each bullet', () => {
+ const steps = [
+ '- Setup',
+ ' - Install:',
+ ' 1. Download',
+ ' 2. Unpack',
+ ' - Configure:',
+ ' 1. Edit config',
+ '- Run',
+ ]
+ expect(list(steps.join('\n'))).toEqual([
+ 'Setup',
+ 'Install:',
+ 'Download',
+ 'Unpack',
+ 'Configure:',
+ 'Edit config',
+ 'Run',
+ ])
+ expect(list('- A\n 1. B\n 1. C\n 2. D\n 2. E\n- F')).toEqual([
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ 'F',
+ ])
+ })
+
+ it('takes off the numbers of a nested count carried on under the next item', () => {
+ expect(list('1. A\n 1. x\n 2. y\n2. B\n 3. z')).toEqual(['A', 'x', 'y', 'B', 'z'])
+ expect(list('Q1\n 1. Hire\n 2. Launch\nQ2\n 3. Expand\n 4. Raise')).toEqual([
+ 'Q1',
+ 'Hire',
+ 'Launch',
+ 'Q2',
+ 'Expand',
+ 'Raise',
+ ])
+ expect(list('Intro\n 1. a\n 2. b\n 3. c')).toEqual(['Intro', 'a', 'b', 'c'])
+ })
+
+ it('takes off a nested number that could count an item, wherever it is set in', () => {
+ expect(list('- A\n 2. B')).toEqual(['A', 'B'])
+ // One line set in a column too far or too short leaves its neighbors alone.
+ const shifted = '1. Plan\n 1. Build\n 1. Design\n 2. Code\n 2. Ship\n2. Grow'
+ expect(list(shifted)).toEqual(['Plan', 'Build', 'Design', 'Code', 'Ship', 'Grow'])
+ const phases = [
+ '1. Plan',
+ ' - Phase A',
+ ' 1. Build',
+ ' 1. Design',
+ ' 2. Ship',
+ ' 1. Review',
+ ' - Phase B',
+ ]
+ expect(list(phases)).toEqual([
+ 'Plan',
+ 'Phase A',
+ 'Build',
+ 'Design',
+ 'Ship',
+ 'Review',
+ 'Phase B',
+ ])
+ const steps = [
+ '1. Plan',
+ ' 1. Build',
+ ' 1. Design',
+ ' 1. Draft',
+ ' 2. Review',
+ ' 2. Code',
+ ' 3. Test',
+ ]
+ expect(list(steps)).toEqual(['Plan', 'Build', 'Design', 'Draft', 'Review', 'Code', 'Test'])
+ })
+
+ it('takes off numbers set to the right, as " 9." over "10."', () => {
+ const items = Array.from({ length: 11 }, (_, i) => `Item ${i + 1}`)
+ const aligned = (indent: string) =>
+ items.map((item, i) => `${indent}${String(i + 1).padStart(2)}. ${item}`).join('\n')
+ expect(list(aligned(''))).toEqual(items)
+ expect(list(`Steps:\n${aligned(' ')}`)).toEqual(['Steps:', ...items])
+ })
+
+ it('keeps the numbers of a sublist that does not count, at any depth', () => {
+ const ctx = context()
+ expect(
+ list('1. Plan\n 1. Build\n 2024. Launch\n 2025. Growth\n2. Grow', ctx)
+ ).toEqual(['Plan', 'Build', '2024. Launch', '2025. Growth', 'Grow'])
+ expect(list('1. A\n 1. x\n 2. y\n2. B\n 2024. z')).toEqual(['A', 'x', 'y', 'B', '2024. z'])
+ expect(list('Steps:\n 9. i\n 2024. j')).toEqual(['Steps:', '9. i', '2024. j'])
+ expect(list('Steps:\n 9. i\n2024. j')).toEqual(['Steps:', '9. i', '2024. j'])
+ expect(ctx.warnings).toHaveLength(1)
+ })
+
it('names the array entry of a nested bullet', () => {
const ctx = context()
list(['Revenue', ' - EMEA up 12%'], ctx)
diff --git a/mcp-host/src/workflow/pptxInput.ts b/mcp-host/src/workflow/pptxInput.ts
index 392f084fe..11d35a20e 100644
--- a/mcp-host/src/workflow/pptxInput.ts
+++ b/mcp-host/src/workflow/pptxInput.ts
@@ -183,11 +183,22 @@ const ORDERED_MARKER = /^\d{1,9}[.)]\s+/
/** A list item set in from the left: a bullet nested under the one above. */
const NESTED_ITEM = /^[ \t]+(?:[-*+•]|\d{1,9}[.)])\s/
+/**
+ * The number of a numbered list marker, when it could count an item of a list
+ * this long: "2024. A record year" in a short list is a year, not a position.
+ */
+function countsItem(text: string, items: number): boolean {
+ const n = /^(\d{1,9})[.)]\s/.exec(text)
+ return !!n && Number(n[1]) <= items
+}
+
/**
* A list of text items. One string is read as one item per line. Slides show
* one level of bullets, so a nested item joins the first level, and the result
- * says so. Numbers are taken off only when every item is a list item: a lone
- * "2024. A record year" keeps its year.
+ * says so. Numbers are taken off the first level only when every item is a
+ * list item and every number could count one of them, and off a nested item
+ * when its number could: a lone "2024. A record year", or two years in a row,
+ * keep their years.
*/
export function readStringList(
value: unknown,
@@ -212,7 +223,12 @@ export function readStringList(
.map((item, i) => ({ text: readText(item, at(i), max, ctx), nested: nested[i] }))
.filter((item): item is { text: string; nested: boolean } => !!item.text)
const marked = (text: string) => LIST_MARKER.test(text) || ORDERED_MARKER.test(text)
- const numbered = items.length > 1 && items.every(item => marked(item.text))
+ const bareOf = (text: string) => text.replace(LIST_MARKER, '')
+ const counts = (text: string) => countsItem(bareOf(text), items.length)
+ const numbered =
+ items.length > 1 &&
+ items.every(item => marked(item.text)) &&
+ items.every(item => item.nested || !ORDERED_MARKER.test(bareOf(item.text)) || counts(item.text))
const first = nested.indexOf(true)
if (first >= 0) {
ctx.warnings.push(
@@ -222,8 +238,8 @@ export function readStringList(
}
return items
.map(({ text, nested }) => {
- const bare = text.replace(LIST_MARKER, '')
- return numbered || nested ? bare.replace(ORDERED_MARKER, '') : bare
+ const bare = bareOf(text)
+ return (nested ? counts(text) : numbered) ? bare.replace(ORDERED_MARKER, '') : bare
})
.filter(Boolean)
}