Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(board): export the statistics as CSV

rubenluetke10-beep44f989268600
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index f9c5c53321..4046a68592 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -899,6 +899,11 @@
"streak": "{0} Tage Bestserie"
}
},
+ "export": {
+ "button": "CSV exportieren",
+ "button_tooltip": "Diese Statistiken als CSV-Datei herunterladen",
+ "empty": "Noch nichts zu exportieren."
+ },
"hero": {
"you_spoke": "Du gesagt",
"you_spoke_sub": "Wörter an {name} gesprochen",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 00af73b64e..b821774af6 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -899,6 +899,11 @@
"streak": "{0}-day best streak"
}
},
+ "export": {
+ "button": "Export CSV",
+ "button_tooltip": "Download these statistics as a CSV file",
+ "empty": "Nothing to export yet."
+ },
"hero": {
"you_spoke": "You said",
"you_spoke_sub": "words spoken to {name}",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index b2fde17091..127a320e32 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -899,6 +899,11 @@
"streak": "Mejor racha · {0} días"
}
},
+ "export": {
+ "button": "Exportar CSV",
+ "button_tooltip": "Descargar estas estadísticas como archivo CSV",
+ "empty": "Todavía no hay nada que exportar."
+ },
"hero": {
"you_spoke": "Tú dijiste",
"you_spoke_sub": "palabras dichas a {name}",
diff --git a/jarvis/ui/web/frontend/src/lib/boardCsv.test.ts b/jarvis/ui/web/frontend/src/lib/boardCsv.test.ts
new file mode 100644
index 0000000000..0f24619b09
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/boardCsv.test.ts
@@ -0,0 +1,199 @@
+import { describe, expect, it } from "vitest";
+import {
+ CSV_HEADER,
+ boardCsv,
+ boardCsvFilename,
+ boardCsvRows,
+ csvField,
+} from "./boardCsv";
+import type {
+ BoardCategories,
+ BoardHeatmap,
+ BoardSummary,
+} from "@/hooks/useBoard";
+
+const summary: BoardSummary = {
+ window_days: 30,
+ totals: {
+ tasks_completed: 12,
+ tasks_failed: 1,
+ voice_commands: 40,
+ hours_saved: 2.5,
+ activity_events: 90,
+ conversation_hours: 3.25,
+ user_words: 1200,
+ jarvis_words: 3400,
+ session_count: 8,
+ active_days: 5,
+ first_day: "2026-01-04",
+ },
+ window: {
+ tasks_completed: 3,
+ tasks_failed: 0,
+ voice_commands: 10,
+ hours_saved: 0.5,
+ activity_events: 20,
+ conversation_hours: 1.5,
+ user_words: 300,
+ jarvis_words: 800,
+ session_count: 2,
+ voice_first_try_rate: null,
+ unique_tools: 4,
+ },
+ streak_days: 3,
+ longest_streak: 9,
+};
+
+const heatmap: BoardHeatmap = {
+ start: "2026-08-21",
+ end: "2026-08-22",
+ days: 2,
+ cells: [
+ {
+ date: "2026-08-21",
+ tasks_completed: 1,
+ tasks_failed: 0,
+ activity_events: 5,
+ conversation_hours: 0.5,
+ user_words: 100,
+ jarvis_words: 200,
+ },
+ ],
+};
+
+const categories: BoardCategories = {
+ window_days: 30,
+ total: 3,
+ categories: [
+ { category: "music", count: 2 },
+ { category: 'weather, "local"', count: 1 },
+ ],
+};
+
+/** Minimal RFC 4180 reader, so the quoting assertions test what a reader sees. */
+function parseCsvLine(line: string): string[] {
+ const fields: string[] = [];
+ let field = "";
+ let inQuotes = false;
+ for (let i = 0; i < line.length; i++) {
+ const ch = line[i];
+ if (inQuotes) {
+ if (ch === '"') {
+ if (line[i + 1] === '"') {
+ field += '"';
+ i++;
+ } else inQuotes = false;
+ } else field += ch;
+ } else if (ch === '"') inQuotes = true;
+ else if (ch === ",") {
+ fields.push(field);
+ field = "";
+ } else field += ch;
+ }
+ fields.push(field);
+ return fields;
+}
+
+describe("csvField", () => {
+ it("leaves a plain value alone", () => {
+ expect(csvField("music")).toBe("music");
+ expect(csvField(42)).toBe("42");
+ });
+
+ it("quotes a field containing a comma", () => {
+ expect(csvField("weather, local")).toBe('"weather, local"');
+ });
+
+ it("doubles inner quotes", () => {
+ expect(csvField('say "hi"')).toBe('"say ""hi"""');
+ });
+
+ it("quotes newlines and edge whitespace so a reader cannot silently trim", () => {
+ expect(csvField("a\nb")).toBe('"a\nb"');
+ expect(csvField(" padded ")).toBe('" padded "');
+ });
+
+ it("writes null and undefined as an empty field, never the string 'null'", () => {
+ expect(csvField(null)).toBe("");
+ expect(csvField(undefined)).toBe("");
+ });
+});
+
+describe("boardCsvRows", () => {
+ it("returns nothing when the view holds nothing", () => {
+ expect(boardCsvRows({})).toEqual([]);
+ });
+
+ it("omits a section the view has not loaded instead of writing zeros", () => {
+ const rows = boardCsvRows({ summary });
+ expect(rows.some((r) => r[0] === "daily")).toBe(false);
+ expect(rows.some((r) => r[0] === "categories")).toBe(false);
+ });
+
+ it("puts first_day in the date column, not the value column", () => {
+ const row = boardCsvRows({ summary }).find((r) => r[2] === "first_day");
+ expect(row).toEqual(["totals", "2026-01-04", "first_day", ""]);
+ });
+
+ it("writes a null rate as empty, so it cannot be read as zero", () => {
+ const row = boardCsvRows({ summary }).find(
+ (r) => r[0] === "window" && r[2] === "voice_first_try_rate",
+ );
+ expect(row?.[3]).toBe("");
+ });
+
+ it("emits one row per metric per day, keyed by the ISO date", () => {
+ const rows = boardCsvRows({ heatmap }).filter((r) => r[0] === "daily");
+ expect(rows).toHaveLength(6);
+ expect(rows.every((r) => r[1] === "2026-08-21")).toBe(true);
+ });
+
+ it("keeps the streak values that live outside totals", () => {
+ const rows = boardCsvRows({ summary });
+ expect(rows).toContainEqual(["totals", "", "streak_days", 3]);
+ expect(rows).toContainEqual(["totals", "", "longest_streak", 9]);
+ });
+});
+
+describe("boardCsv", () => {
+ it("starts with the fixed header after the BOM", () => {
+ const text = boardCsv({ summary });
+ expect(text.charCodeAt(0)).toBe(0xfeff);
+ expect(text.slice(1).split("\r\n")[0]).toBe(CSV_HEADER.join(","));
+ });
+
+ it("quotes a category name containing a comma so columns do not shift", () => {
+ const line = boardCsv({ categories })
+ .split("\r\n")
+ .find((l) => l.includes("weather"));
+ expect(line).toBe('categories,,"weather, ""local""",1');
+ // And a reader still sees exactly four fields, with the comma inside one.
+ expect(parseCsvLine(line!)).toEqual([
+ "categories",
+ "",
+ 'weather, "local"',
+ "1",
+ ]);
+ });
+
+ it("uses CRLF and ends with a terminating newline", () => {
+ const text = boardCsv({ summary });
+ expect(text.endsWith("\r\n")).toBe(true);
+ expect(text.includes("\r\n")).toBe(true);
+ });
+
+ it("carries every loaded section in one document", () => {
+ const text = boardCsv({ summary, heatmap, categories });
+ for (const section of ["totals", "window", "daily", "categories"]) {
+ expect(text).toContain(`\r\n${section},`);
+ }
+ });
+});
+
+describe("boardCsvFilename", () => {
+ it("names the file with an ISO date so files sort chronologically", () => {
+ expect(boardCsvFilename(new Date("2026-08-22T18:04:00Z"))).toBe(
+ "jarvis-board-2026-08-22.csv",
+ );
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/lib/boardCsv.ts b/jarvis/ui/web/frontend/src/lib/boardCsv.ts
new file mode 100644
index 0000000000..f8533b7581
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/lib/boardCsv.ts
@@ -0,0 +1,131 @@
+/**
+ * Serialize the Board's aggregates as CSV.
+ *
+ * The Board holds three shapes at once — lifetime/window totals, a day-by-day
+ * series, and a category breakdown. Flattening them into one wide table would
+ * need a column per metric per shape and leave most cells empty, so this emits
+ * TIDY (long) rows instead: one observation per line, four fixed columns.
+ *
+ * section,date,metric,value
+ * totals,,user_words,124503
+ * daily,2026-08-22,user_words,1204
+ * categories,,music,42
+ *
+ * That is the shape pandas pivots in one call and Excel filters natively, and
+ * adding a fourth aggregate later costs a `section` value, not a schema change.
+ *
+ * Dates are ISO 8601 (`YYYY-MM-DD`), never the localized display format —
+ * `08/22/2026` and `22.08.2026` sort as text and are read differently on every
+ * machine that opens the file. The backend already speaks ISO here, so the
+ * values pass through untouched.
+ */
+import type {
+ BoardCategories,
+ BoardHeatmap,
+ BoardSummary,
+} from "@/hooks/useBoard";
+
+/** The fixed header. Exported so a test pins it rather than restating it. */
+export const CSV_HEADER = ["section", "date", "metric", "value"] as const;
+
+/**
+ * Quote one field per RFC 4180.
+ *
+ * A field is quoted when it contains a comma, a quote, a newline, or edge
+ * whitespace that a reader would otherwise silently trim; inner quotes double.
+ * Category names are free text and reach this function, so this is the
+ * difference between a usable file and one that shifts every column after the
+ * first category with a comma in it.
+ */
+export function csvField(value: string | number | null | undefined): string {
+ if (value === null || value === undefined) return "";
+ const text = String(value);
+ const needsQuotes =
+ text.includes(",") ||
+ text.includes('"') ||
+ text.includes("\n") ||
+ text.includes("\r") ||
+ text !== text.trim();
+ if (!needsQuotes) return text;
+ return `"${text.replace(/"/g, '""')}"`;
+}
+
+export interface BoardCsvInput {
+ summary?: BoardSummary;
+ heatmap?: BoardHeatmap;
+ categories?: BoardCategories;
+}
+
+type Row = [string, string, string, string | number];
+
+/**
+ * Build the rows for whatever the view actually holds.
+ *
+ * Sections the view has not loaded are omitted rather than written as zeros —
+ * an empty `daily` section says "not loaded", a run of zeros would claim "no
+ * activity", and those are different facts.
+ */
+export function boardCsvRows(input: BoardCsvInput): Row[] {
+ const rows: Row[] = [];
+
+ if (input.summary) {
+ const { totals, window, streak_days, longest_streak, window_days } =
+ input.summary;
+ for (const [metric, value] of Object.entries(totals)) {
+ // first_day is a date, not a measurement — it belongs in the date column.
+ if (metric === "first_day") {
+ if (value) rows.push(["totals", String(value), "first_day", ""]);
+ continue;
+ }
+ rows.push(["totals", "", metric, value as number]);
+ }
+ rows.push(["totals", "", "streak_days", streak_days]);
+ rows.push(["totals", "", "longest_streak", longest_streak]);
+
+ rows.push(["window", "", "window_days", window_days]);
+ for (const [metric, value] of Object.entries(window)) {
+ // A null rate means "not enough data to compute", which an empty cell
+ // carries correctly and a 0 would not.
+ rows.push(["window", "", metric, value === null ? "" : (value as number)]);
+ }
+ }
+
+ if (input.heatmap) {
+ for (const cell of input.heatmap.cells) {
+ const { date, ...metrics } = cell;
+ for (const [metric, value] of Object.entries(metrics)) {
+ rows.push(["daily", date, metric, value as number]);
+ }
+ }
+ }
+
+ if (input.categories) {
+ for (const entry of input.categories.categories) {
+ rows.push(["categories", "", entry.category, entry.count]);
+ }
+ }
+
+ return rows;
+}
+
+/**
+ * Render the full document.
+ *
+ * CRLF line endings are what RFC 4180 specifies and what Excel expects; every
+ * other reader accepts them. The leading BOM is there so a double-clicked file
+ * opens with correct umlauts in Excel — pandas strips it, so the file stays
+ * usable in both places.
+ */
+export function boardCsv(input: BoardCsvInput): string {
+ const lines = [
+ CSV_HEADER.join(","),
+ ...boardCsvRows(input).map((row) => row.map(csvField).join(",")),
+ ];
+ return "" + lines.join("\r\n") + "\r\n";
+}
+
+/** `jarvis-board-2026-08-22.csv` — ISO in the name too, so files sort by date. */
+export function boardCsvFilename(now: Date = new Date()): string {
+ const iso = now.toISOString().slice(0, 10);
+ return `jarvis-board-${iso}.csv`;
+}
diff --git a/jarvis/ui/web/frontend/src/views/BoardView.tsx b/jarvis/ui/web/frontend/src/views/BoardView.tsx
index 27733694d0..40cdc04e27 100644
--- a/jarvis/ui/web/frontend/src/views/BoardView.tsx
+++ b/jarvis/ui/web/frontend/src/views/BoardView.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { Flame, Loader2, RefreshCw, Share2, Sparkles } from "lucide-react";
+import { Download, Flame, Loader2, RefreshCw, Share2, Sparkles } from "lucide-react";
import { ViewHeader } from "@/views/ChatsView";
import { BoardCard } from "@/components/board/BoardCard";
import { ShareDialog } from "@/components/board/ShareDialog";
@@ -16,6 +16,7 @@ import {
useBoardRefresh,
useBoardSummary,
} from "@/hooks/useBoard";
+import { boardCsv, boardCsvFilename } from "@/lib/boardCsv";
import { cn } from "@/lib/utils";
import { useT } from "@/i18n";
@@ -27,6 +28,26 @@ export function BoardView() {
const refresh = useBoardRefresh();
const [shareOpen, setShareOpen] = useState(false);
+ // Export exactly what the view is holding — a section that has not loaded is
+ // left out of the file rather than written as zeros, because "not loaded" and
+ // "no activity" are different facts.
+ const canExport = Boolean(summary.data || heatmap.data || categories.data);
+
+ function handleExportCsv() {
+ const text = boardCsv({
+ summary: summary.data,
+ heatmap: heatmap.data,
+ categories: categories.data,
+ });
+ const blob = new Blob([text], { type: "text/csv;charset=utf-8" });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = boardCsvFilename();
+ a.click();
+ URL.revokeObjectURL(url);
+ }
+
const s = summary.data;
const userWords = s?.totals.user_words ?? 0;
const jarvisWords = s?.totals.jarvis_words ?? 0;
@@ -92,6 +113,25 @@ export function BoardView() {
<Share2 className="h-3.5 w-3.5" />
{t("board_view.share.button")}
</button>
+ <button
+ type="button"
+ onClick={handleExportCsv}
+ disabled={!canExport}
+ className={cn(
+ "inline-flex items-center gap-2 rounded-lg border border-sheen/[0.08] bg-sheen/[0.03] px-3 py-1.5 text-xs font-medium transition-colors",
+ "hover:border-primary/40 hover:bg-primary/[0.06]",
+ !canExport && "opacity-50",
+ )}
+ title={
+ canExport
+ ? t("board_view.export.button_tooltip")
+ : t("board_view.export.empty")
+ }
+ data-testid="board-export-csv-button"
+ >
+ <Download className="h-3.5 w-3.5" />
+ {t("board_view.export.button")}
+ </button>
<button
type="button"
onClick={() => refresh.mutate()}