diff --git a/webui/src/lib/csv.spec.ts b/webui/src/lib/csv.spec.ts index b30e558..b66e979 100644 --- a/webui/src/lib/csv.spec.ts +++ b/webui/src/lib/csv.spec.ts @@ -84,3 +84,13 @@ describe('toCsv: formula injection (P4)', () => { expect(toCsv(['note'], [['cost=5']])).toBe('note\r\ncost=5\r\n') }) }) + +describe('toCsv numbers', () => { + it.each([ + [-5, '-5'], + [-0.25, '-0.25'], + [12, '12'], + ])('writes the number %s unguarded', (n, want) => { + expect(toCsv(['v'], [[n]])).toBe(`v\r\n${want}\r\n`) + }) +}) diff --git a/webui/src/lib/csv.ts b/webui/src/lib/csv.ts index 6ec9981..83c4083 100644 --- a/webui/src/lib/csv.ts +++ b/webui/src/lib/csv.ts @@ -41,7 +41,7 @@ const CSV_FORMULA_LEAD_CHARS = /^[=+\-@\t\r]/ */ function csvField(value: unknown): string { let s = value === null || value === undefined ? '' : String(value) - if (CSV_FORMULA_LEAD_CHARS.test(s)) s = `'${s}` + if (typeof value !== 'number' && CSV_FORMULA_LEAD_CHARS.test(s)) s = `'${s}` if (!CSV_SPECIAL_CHARS.test(s)) return s return `"${s.replace(/"/g, '""')}"` } diff --git a/webui/src/lib/format.spec.ts b/webui/src/lib/format.spec.ts index d57b224..1dbf769 100644 --- a/webui/src/lib/format.spec.ts +++ b/webui/src/lib/format.spec.ts @@ -72,6 +72,9 @@ describe('formatContextWindow', () => { // when they happen to be exact multiples of 1024 (128000 = 125 × // 1024) — decimal-K/M. { tokens: 128_000, want: '128k' }, // review regression: was "125k" + { tokens: 1_500, want: '1.5k' }, + { tokens: 9_950, want: '10k' }, + { tokens: 1_500_000, want: '1.5M' }, { tokens: 1_000_000, want: '1M' }, // review regression: was "977k" { tokens: 2_000_000, want: '2M' }, // review regression: was "1953k" // Plain digits under 1024, either path. diff --git a/webui/src/lib/format.ts b/webui/src/lib/format.ts index 57366f9..fb39eee 100644 --- a/webui/src/lib/format.ts +++ b/webui/src/lib/format.ts @@ -194,8 +194,13 @@ export function formatContextWindow(tokens: number): string { } // 999_500+ would round to "1000k"; the M branch renders it as "1M". - if (tokens < 999_500) return `${Math.round(tokens / 1_000)}k` - return `${Math.round(tokens / 1_000_000)}M` + if (tokens < 999_500) return `${roundScaled(tokens / 1_000)}k` + return `${roundScaled(tokens / 1_000_000)}M` +} + +/** roundScaled keeps one decimal below 10 ("1.5") so 1500 does not read as 2k, and rounds to whole units from 10 up. */ +function roundScaled(value: number): string { + return value < 10 ? String(Math.round(value * 10) / 10) : String(Math.round(value)) } /** formatUsdPerMTok renders a USD-per-million-tokens float as "$0.19" (2 decimals) — the shared building block for both the visible cost chip and ModelChip's hover detail. */ diff --git a/webui/src/lib/yaml-emit.spec.ts b/webui/src/lib/yaml-emit.spec.ts index 7ec0658..02e3a76 100644 --- a/webui/src/lib/yaml-emit.spec.ts +++ b/webui/src/lib/yaml-emit.spec.ts @@ -285,3 +285,14 @@ describe('toYamlValue', () => { expect(toYamlValue(weird)).toBe(String(weird)) }) }) + +describe('emitYamlScalar non-finite numbers', () => { + it.each([ + [Number.NaN, '.nan'], + [Infinity, '.inf'], + [-Infinity, '-.inf'], + [-3.5, '-3.5'], + ])('%s -> %s', (n, want) => { + expect(emitYamlScalar(n)).toBe(want) + }) +}) diff --git a/webui/src/lib/yaml-emit.ts b/webui/src/lib/yaml-emit.ts index c439bd7..8eb1229 100644 --- a/webui/src/lib/yaml-emit.ts +++ b/webui/src/lib/yaml-emit.ts @@ -148,10 +148,19 @@ export function emitYamlKey(key: string): string { return yamlKeyNeedsQuoting(key) ? escapeYamlUnsafeControls(JSON.stringify(key)) : key } +/** yamlNumber spells non-finite values with their YAML 1.2 float forms; String(NaN) is a plain string in YAML. */ +function yamlNumber(n: number): string { + if (Number.isNaN(n)) return '.nan' + if (n === Infinity) return '.inf' + if (n === -Infinity) return '-.inf' + return String(n) +} + /** emitYamlScalar renders one leaf value in "key: " position OR a flow list/map element — quoted (JSON-style) whenever needsQuoting says the plain form is unsafe, plain otherwise. Booleans/numbers/null render via their own JS literal, never through the string quoting path (a real `true`/`false`/`null`/number is safe unquoted by construction — only a STRING value can accidentally spell one of those). */ export function emitYamlScalar(value: YamlPrimitive): string { if (value === null) return 'null' - if (typeof value === 'boolean' || typeof value === 'number') return String(value) + if (typeof value === 'number') return yamlNumber(value) + if (typeof value === 'boolean') return String(value) return needsQuoting(value) ? escapeYamlUnsafeControls(JSON.stringify(value)) : value }