Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: redesign the Data Manager as a disk-usage treemap with a selection panel

[._.]/ Adam Eivy416580487e56
diff --git a/client/src/components/dataManager/DataSelectionPanel.jsx b/client/src/components/dataManager/DataSelectionPanel.jsx
new file mode 100644
index 0000000000..c4eca40451
--- /dev/null
+++ b/client/src/components/dataManager/DataSelectionPanel.jsx
@@ -0,0 +1,131 @@
+import ProgressBar from '../ui/ProgressBar';
+import { formatBytes, formatCount, formatPercent } from '../../utils/formatters';
+import { DATA_KINDS, dataKindOf } from './dataKinds';
+
+const WORTH_A_LOOK_LIMIT = 6;
+
+function Stat({ label, children }) {
+ return (
+ <div className="min-w-0">
+ <div className="text-[10px] uppercase tracking-wider text-gray-500">{label}</div>
+ <div className="truncate text-sm text-white">{children}</div>
+ </div>
+ );
+}
+
+function SectionTitle({ children, aside }) {
+ return (
+ <div className="flex items-baseline justify-between mb-2">
+ <h2 className="text-[11px] uppercase tracking-wider text-gray-500 font-medium">{children}</h2>
+ {aside}
+ </div>
+ );
+}
+
+// Big-number readout for the current selection (or the whole data/ tree when
+// nothing is selected), a ranked shortlist of what can actually be reclaimed,
+// and how much room the volume has left — the disktree side panel, mapped onto
+// PortOS's category model.
+export default function DataSelectionPanel({ overview, totalFiles, selected, detail, onSelect, onShowActions }) {
+ const total = overview?.totalSize || 0;
+ const categories = overview?.categories || [];
+ const kind = selected ? DATA_KINDS[dataKindOf(selected)] : null;
+ const size = selected ? selected.size : total;
+ const fileCount = selected ? selected.fileCount : totalFiles;
+ const swatch = kind?.swatch ?? 'bg-port-accent';
+ const [value, unit] = formatBytes(size).split(' ');
+ const share = total > 0 ? (size / total) * 100 : 0;
+ const itemCount = selected && detail?.key === selected.key ? detail.items.length : null;
+
+ // Only whole-category purges belong here: an item-scoped category holds the
+ // only copy of its files, so it is never "worth a look" as bulk reclaim.
+ const reclaimable = categories
+ .filter((c) => dataKindOf(c) === 'reclaimable' && c.size > 0)
+ .sort((a, b) => b.size - a.size);
+ const reclaimableTotal = reclaimable.reduce((sum, c) => sum + c.size, 0);
+ const shortlist = reclaimable.slice(0, WORTH_A_LOOK_LIMIT);
+ const shortlistMax = shortlist[0]?.size || 1;
+
+ const disk = overview?.disk;
+
+ return (
+ <aside className="bg-port-card border border-port-border rounded-xl p-4 space-y-5" aria-label="Selection details">
+ <section>
+ <SectionTitle>Selection</SectionTitle>
+ <div className="flex items-center gap-2">
+ <span className={`w-1 h-6 rounded-full ${swatch}`} />
+ <span className="truncate text-lg text-white">{selected ? selected.label : `${overview?.dataDir || 'data'}/`}</span>
+ </div>
+ <div className="mt-0.5 truncate text-xs font-mono text-gray-500">{selected?.path || 'everything PortOS stores'}</div>
+ <div className="mt-3 flex items-baseline gap-1.5">
+ <span className="text-4xl font-light text-white tabular-nums">{value}</span>
+ <span className="text-sm text-gray-500">{unit}</span>
+ </div>
+ <ProgressBar percent={share} tone={kind?.tone ?? 'accent'} track="border" label="Share of data/" className="mt-2" />
+ <div className="mt-3 grid grid-cols-2 gap-x-4 gap-y-3">
+ <Stat label="Of data/">{formatPercent(share, { decimals: share < 10 ? 1 : 0 })}</Stat>
+ <Stat label="Files">{formatCount(fileCount, { fallback: '0' })}</Stat>
+ <Stat label="Kind">{kind ? kind.label : `${formatCount(categories.length)} categories`}</Stat>
+ <Stat label="Entries">{itemCount == null ? '—' : formatCount(itemCount)}</Stat>
+ </div>
+ {kind && <p className="mt-3 text-xs text-gray-500">{kind.hint}</p>}
+ {selected && (
+ <button
+ type="button"
+ onClick={onShowActions}
+ className="mt-3 text-xs text-port-accent hover:underline"
+ >
+ Show actions and contents
+ </button>
+ )}
+ </section>
+
+ <section className="border-t border-port-border pt-4">
+ <SectionTitle aside={<span className="text-xs font-mono text-port-warning">{formatBytes(reclaimableTotal)}</span>}>
+ Worth a look
+ </SectionTitle>
+ {shortlist.length === 0 ? (
+ <p className="text-xs text-gray-500">Nothing reproducible to reclaim right now.</p>
+ ) : (
+ <ul className="space-y-1">
+ {shortlist.map((c) => (
+ <li key={c.key}>
+ <button
+ type="button"
+ onClick={() => onSelect(c.key)}
+ className={`w-full rounded-md border-l-2 border-port-warning/70 px-2 py-1.5 text-left transition-colors hover:bg-port-bg/60 ${selected?.key === c.key ? 'bg-port-bg/60' : ''}`}
+ >
+ <span className="flex items-baseline justify-between gap-2">
+ <span className="truncate text-sm text-gray-200">{c.label}</span>
+ <span className="shrink-0 text-xs font-mono text-white">{formatBytes(c.size)}</span>
+ </span>
+ <span className="mt-1 block h-1 w-full rounded-full bg-port-border/50 overflow-hidden">
+ <span className="block h-full rounded-full bg-port-warning/80" style={{ width: `${Math.max(2, (c.size / shortlistMax) * 100)}%` }} />
+ </span>
+ </button>
+ </li>
+ ))}
+ </ul>
+ )}
+ </section>
+
+ {disk && (
+ <section className="border-t border-port-border pt-4">
+ <SectionTitle>Disk</SectionTitle>
+ <div className="flex items-baseline gap-1.5">
+ <span className="text-2xl font-light text-white tabular-nums">{formatBytes(disk.free)}</span>
+ <span className="text-sm text-gray-500">free</span>
+ </div>
+ <div className="mt-2 h-1.5 w-full rounded-full bg-port-border/60 overflow-hidden flex">
+ <div className="h-full bg-port-accent" style={{ width: `${Math.min(100, (total / disk.total) * 100)}%` }} title={`PortOS data ${formatBytes(total)}`} />
+ <div className="h-full bg-gray-500/70" style={{ width: `${Math.max(0, Math.min(100, ((disk.used - total) / disk.total) * 100))}%` }} />
+ </div>
+ <div className="mt-1.5 flex justify-between text-xs text-gray-500">
+ <span>{formatBytes(disk.used)} used</span>
+ <span>{formatBytes(disk.total)} total</span>
+ </div>
+ </section>
+ )}
+ </aside>
+ );
+}
diff --git a/client/src/components/dataManager/DataTreemap.jsx b/client/src/components/dataManager/DataTreemap.jsx
new file mode 100644
index 0000000000..ad6872fb40
--- /dev/null
+++ b/client/src/components/dataManager/DataTreemap.jsx
@@ -0,0 +1,102 @@
+import { useMemo } from 'react';
+import useContainerWidth from '../../hooks/useContainerWidth';
+import { squarifyTreemap } from '../../lib/squarifyTreemap';
+import { formatBytes } from '../../utils/formatters';
+import { DATA_KINDS, HATCH_STYLE, dataKindOf } from './dataKinds';
+
+// Before the first ResizeObserver callback (and under happy-dom, which never
+// fires one) lay out against a typical desktop width so the map still renders.
+const FALLBACK_WIDTH = 960;
+const HEADER_H = 22;
+const GAP = 3;
+// A category can hold thousands of entries; past this many the extra tiles are
+// sub-pixel slivers, so only the largest get laid out and rendered.
+const MAX_NESTED = 60;
+
+const mapHeight = (width) => Math.round(Math.min(560, Math.max(260, width * 0.5)));
+
+// The selected category's own entries, packed into its tile below the header —
+// one level of drill-down, the way disktree nests a directory's children.
+function NestedItems({ items, width, height }) {
+ const rects = useMemo(
+ () => squarifyTreemap(
+ [...items].sort((a, b) => b.size - a.size).slice(0, MAX_NESTED),
+ width,
+ height,
+ (i) => i.size,
+ ),
+ [items, width, height],
+ );
+ return rects.map(({ item, x, y, w, h }) => {
+ const showName = w > 56 && h > 18;
+ const showSize = showName && h > 34;
+ return (
+ <span
+ key={item.name}
+ className="absolute block overflow-hidden rounded-sm border border-black/20 bg-black/15 px-1.5 py-0.5"
+ style={{ left: x + 1, top: y + 1, width: Math.max(0, w - 2), height: Math.max(0, h - 2) }}
+ title={`${item.name} — ${formatBytes(item.size)}`}
+ >
+ {showName && <span className="block truncate text-[11px] leading-4 text-gray-200">{item.name}</span>}
+ {showSize && <span className="block truncate text-[10px] leading-3 text-gray-400 font-mono">{formatBytes(item.size)}</span>}
+ </span>
+ );
+ });
+}
+
+export default function DataTreemap({ categories, selectedKey, detail, onSelect }) {
+ const [ref, measured] = useContainerWidth();
+ const width = measured || FALLBACK_WIDTH;
+ const height = mapHeight(width);
+
+ const tiles = useMemo(
+ () => squarifyTreemap(categories || [], width, height, (c) => c.size),
+ [categories, width, height],
+ );
+
+ if (!tiles.length) {
+ return (
+ <div ref={ref} className="flex items-center justify-center h-40 rounded-lg border border-port-border text-sm text-gray-500">
+ Nothing stored in data/ yet
+ </div>
+ );
+ }
+
+ return (
+ <div ref={ref} className="relative w-full rounded-lg bg-port-bg" style={{ height }}>
+ {tiles.map(({ item: cat, x, y, w, h }) => {
+ const kind = DATA_KINDS[dataKindOf(cat)];
+ const selected = cat.key === selectedKey;
+ const tileW = Math.max(0, w - GAP);
+ const tileH = Math.max(0, h - GAP);
+ const showHeader = tileW > 44 && tileH > 20;
+ const showSize = tileW > 110;
+ const items = selected && detail?.key === cat.key ? detail.items : null;
+ const bodyH = tileH - HEADER_H - 4;
+ return (
+ <button
+ key={cat.key}
+ type="button"
+ onClick={() => onSelect(cat.key)}
+ title={`${cat.label} — ${formatBytes(cat.size)} · ${kind.label}`}
+ aria-pressed={selected}
+ className={`absolute flex flex-col justify-start overflow-hidden rounded-md border-t-2 text-left transition-colors ${kind.tile} ${kind.edge} ${selected ? 'ring-2 ring-white/70 z-10' : ''}`}
+ style={{ left: x, top: y, width: tileW, height: tileH, ...(kind.hatch ? HATCH_STYLE : null) }}
+ >
+ {showHeader && (
+ <span className="flex w-full shrink-0 items-baseline justify-between gap-2 px-2 bg-black/20" style={{ height: HEADER_H, lineHeight: `${HEADER_H}px` }}>
+ <span className="truncate text-xs font-medium text-white">{cat.label}</span>
+ {showSize && <span className="shrink-0 text-[11px] font-mono text-gray-400">{formatBytes(cat.size)}</span>}
+ </span>
+ )}
+ {items?.length > 0 && showHeader && bodyH > 24 && (
+ <span className="absolute left-1 right-1 bottom-1" style={{ top: HEADER_H + 2 }}>
+ <NestedItems items={items} width={tileW - 8} height={bodyH} />
+ </span>
+ )}
+ </button>
+ );
+ })}
+ </div>
+ );
+}
diff --git a/client/src/components/dataManager/dataKinds.js b/client/src/components/dataManager/dataKinds.js
new file mode 100644
index 0000000000..98184b87fe
--- /dev/null
+++ b/client/src/components/dataManager/dataKinds.js
@@ -0,0 +1,64 @@
+// What a Data Manager category means for cleanup, derived from the server's
+// archivable/deletable/purgeScope/classified flags. One kind per category so
+// the treemap, its legend, and the selection panel color a directory the same
+// way everywhere. Older servers omit `purgeScope`/`classified`; only an
+// explicit `purgeScope: 'items'` / `classified: false` changes the kind.
+
+// Diagonal stripes over a reclaimable tile — the "safe to delete" tell, so it
+// still reads when the tile is too small for a label.
+export const HATCH_STYLE = {
+ backgroundImage: 'repeating-linear-gradient(135deg, rgb(255 255 255 / 0.07) 0 2px, transparent 2px 7px)',
+};
+
+export const DATA_KINDS = {
+ reclaimable: {
+ label: 'Reclaimable',
+ hint: 'Reproducible — safe to purge',
+ tile: 'bg-port-warning/15 hover:bg-port-warning/25',
+ edge: 'border-port-warning/70',
+ swatch: 'bg-port-warning',
+ tone: 'warning',
+ hatch: true,
+ },
+ userFiles: {
+ label: 'Your files',
+ hint: 'Only copy — delete entries one at a time',
+ tile: 'bg-port-accent-2/15 hover:bg-port-accent-2/25',
+ edge: 'border-port-accent-2/70',
+ swatch: 'bg-port-accent-2',
+ tone: 'accent2',
+ },
+ archivable: {
+ label: 'Archivable',
+ hint: 'Can be tarred into data/backup',
+ tile: 'bg-port-accent/15 hover:bg-port-accent/25',
+ edge: 'border-port-accent/70',
+ swatch: 'bg-port-accent',
+ tone: 'accent',
+ },
+ protected: {
+ label: 'Protected',
+ hint: 'PortOS state — never purged here',
+ tile: 'bg-port-success/15 hover:bg-port-success/25',
+ edge: 'border-port-success/70',
+ swatch: 'bg-port-success',
+ tone: 'success',
+ },
+ unclassified: {
+ label: 'Unclassified',
+ hint: 'Unknown directory — actions withheld',
+ tile: 'bg-gray-500/15 hover:bg-gray-500/25',
+ edge: 'border-gray-500/70',
+ swatch: 'bg-gray-500',
+ tone: 'muted',
+ },
+};
+
+export const DATA_KIND_ORDER = ['reclaimable', 'userFiles', 'archivable', 'protected', 'unclassified'];
+
+export function dataKindOf(cat) {
+ if (cat?.classified === false) return 'unclassified';
+ if (cat?.deletable) return cat.purgeScope === 'items' ? 'userFiles' : 'reclaimable';
+ if (cat?.archivable) return 'archivable';
+ return 'protected';
+}
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index 00b17bf634..a9fa1b7382 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -44,6 +44,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `cleanPlatePrompt.js` | Clean-plate prompt builder for setting canon entries (Cluster A — A4). |
| `personaTraitBlend.js` | Re-export of `server/lib/personaTraitBlend.js`. Digital-twin persona trait-blending (M34 P7) — `describeTraitAdjustments` / `renderTraitBlendDirective` / `BIG_FIVE_LEAN` for the Personas UI preview. |
| `seasonStructure.js` | Re-export of `server/lib/seasonStructure.js`. |
+| `squarifyTreemap.js` | `squarifyTreemap(items, width, height, getValue?)` — squarified treemap layout; returns `{ item, x, y, w, h }` tiles whose areas are proportional to each item's value. Drives the Data Manager disk-usage map. |
| `sheetPointers.js` | Mirror of the character-sheet pointer helpers from `server/lib/storyBible.js`. `LEGACY_SHEET_VARIANT_ID` + `readSheetPointer` / `listSheetPointers` / `applySheetPointer` for traversing both the legacy `referenceSheetImageRef` field and the `referenceSheets` map. |
| `shotContinuity.js` | The storyboards / episode-video stages' INLINE pre-render continuity warnings (#1468). `findAxisReversals` / `findShotTypeMonotony` are re-exported from `server/lib/editorial/shotContinuity.js`, the same detectors the authoritative `visual.shot-continuity` check runs; `sceneShotWarnings(scene, opts)` is the client-only composer (the server emits findings in a different shape). Pure/DOM-free. |
| `shotGrammar.js` | Storyboard shot-grammar display labels. `SHOT_TYPES` / `SCREEN_DIRECTIONS` are re-exported from `server/lib/shotGrammar.js`, so a hand-set value in the editor always passes `storyboardShotSchema`; `SHOT_TYPE_LABELS` / `SCREEN_DIRECTION_LABELS` are the client-only selects (#1468). |
diff --git a/client/src/lib/index.js b/client/src/lib/index.js
index af98645a05..e468a2b0ac 100644
--- a/client/src/lib/index.js
+++ b/client/src/lib/index.js
@@ -237,3 +237,4 @@ export * from './eidoverseFrame.js';
export * from './songBookDraft.js';
export * from './layoutRoutes.js';
export * from './navPresentation.js';
+export * from './squarifyTreemap.js';
diff --git a/client/src/lib/squarifyTreemap.js b/client/src/lib/squarifyTreemap.js
new file mode 100644
index 0000000000..ab076be28c
--- /dev/null
+++ b/client/src/lib/squarifyTreemap.js
@@ -0,0 +1,85 @@
+// Squarified treemap layout (Bruls, Huizing & van Wijk). Packs weighted items
+// into a width×height rectangle so each tile's area is proportional to its
+// value while keeping tiles as close to square as possible — the layout disk
+// usage views (disktree, WinDirStat) use so a big directory reads as big.
+//
+// Pure: returns `{ item, x, y, w, h }` in the same units as width/height, in
+// descending-value order. Zero/negative/non-finite values are dropped (they
+// would occupy no area and poison the worst-ratio math).
+
+const worstRatio = (row, side) => {
+ let min = Infinity;
+ let max = 0;
+ let sum = 0;
+ for (const r of row) {
+ sum += r.area;
+ if (r.area < min) min = r.area;
+ if (r.area > max) max = r.area;
+ }
+ if (!sum || !side) return Infinity;
+ const s2 = side * side;
+ const sum2 = sum * sum;
+ return Math.max((s2 * max) / sum2, sum2 / (s2 * min));
+};
+
+export function squarifyTreemap(items, width, height, getValue = (i) => i.value) {
+ const rects = [];
+ if (!(width > 0) || !(height > 0) || !Array.isArray(items)) return rects;
+
+ const weighted = items
+ .map((item) => ({ item, value: Number(getValue(item)) }))
+ .filter((e) => Number.isFinite(e.value) && e.value > 0)
+ .sort((a, b) => b.value - a.value);
+ const total = weighted.reduce((s, e) => s + e.value, 0);
+ if (!total) return rects;
+
+ const scale = (width * height) / total;
+ const queue = weighted.map((e) => ({ item: e.item, area: e.value * scale }));
+ let x = 0;
+ let y = 0;
+ let w = width;
+ let h = height;
+
+ const layoutRow = (row) => {
+ const rowArea = row.reduce((s, r) => s + r.area, 0);
+ if (w >= h) {
+ // Lay the row out as a column along the left edge.
+ const colW = rowArea / h;
+ let cy = y;
+ for (const r of row) {
+ const rh = r.area / colW;
+ rects.push({ item: r.item, x, y: cy, w: colW, h: rh });
+ cy += rh;
+ }
+ x += colW;
+ w -= colW;
+ } else {
+ // Lay the row out along the top edge.
+ const rowH = rowArea / w;
+ let cx = x;
+ for (const r of row) {
+ const rw = r.area / rowH;
+ rects.push({ item: r.item, x: cx, y, w: rw, h: rowH });
+ cx += rw;
+ }
+ y += rowH;
+ h -= rowH;
+ }
+ };
+
+ let row = [];
+ let i = 0;
+ while (i < queue.length) {
+ const side = Math.min(w, h);
+ const candidate = [...row, queue[i]];
+ if (!row.length || worstRatio(candidate, side) <= worstRatio(row, side)) {
+ row = candidate;
+ i += 1;
+ } else {
+ layoutRow(row);
+ row = [];
+ }
+ }
+ if (row.length) layoutRow(row);
+ return rects;
+}
diff --git a/client/src/lib/squarifyTreemap.test.js b/client/src/lib/squarifyTreemap.test.js
new file mode 100644
index 0000000000..ddd6cecb0f
--- /dev/null
+++ b/client/src/lib/squarifyTreemap.test.js
@@ -0,0 +1,38 @@
+import { describe, it, expect } from 'vitest';
+import { squarifyTreemap } from './squarifyTreemap';
+
+const area = (r) => r.w * r.h;
+
+describe('squarifyTreemap', () => {
+ it.each([
+ [[6, 6, 4, 3, 2, 2, 1], 600, 400],
+ [[100, 1, 1, 1], 300, 900],
+ [[5], 200, 100],
+ [[1, 1, 1, 1, 1, 1, 1, 1, 1], 90, 90],
+ ])('tiles %j into %ix%i with proportional areas and no overflow', (values, width, height) => {
+ const rects = squarifyTreemap(values.map((value) => ({ value })), width, height);
+ const total = values.reduce((s, v) => s + v, 0);
+ expect(rects).toHaveLength(values.length);
+ for (const r of rects) {
+ expect(area(r)).toBeCloseTo((r.item.value / total) * width * height, 6);
+ expect(r.x).toBeGreaterThanOrEqual(-1e-9);
+ expect(r.y).toBeGreaterThanOrEqual(-1e-9);
+ expect(r.x + r.w).toBeLessThanOrEqual(width + 1e-6);
+ expect(r.y + r.h).toBeLessThanOrEqual(height + 1e-6);
+ }
+ expect(rects.reduce((s, r) => s + area(r), 0)).toBeCloseTo(width * height, 6);
+ });
+
+ it('keeps equal items close to square instead of slicing strips', () => {
+ const rects = squarifyTreemap(Array.from({ length: 16 }, () => ({ value: 1 })), 400, 400);
+ for (const r of rects) expect(Math.max(r.w / r.h, r.h / r.w)).toBeLessThan(2);
+ });
+
+ it('drops zero, negative, and non-numeric values and handles empty input', () => {
+ const rects = squarifyTreemap([{ value: 0 }, { value: -3 }, { value: 'x' }, { value: 2 }], 100, 50);
+ expect(rects).toHaveLength(1);
+ expect(rects[0]).toMatchObject({ x: 0, y: 0, w: 100, h: 50 });
+ expect(squarifyTreemap([], 100, 50)).toEqual([]);
+ expect(squarifyTreemap([{ value: 1 }], 0, 50)).toEqual([]);
+ });
+});
diff --git a/client/src/pages/DataManager.jsx b/client/src/pages/DataManager.jsx
index 9c016c6e7f..afd445f78c 100644
--- a/client/src/pages/DataManager.jsx
+++ b/client/src/pages/DataManager.jsx
@@ -12,6 +12,9 @@ import { useSocketSubscription } from '../hooks/useSocketSubscription';
import useMounted from '../hooks/useMounted';
import InlineConfirmRow from '../components/ui/InlineConfirmRow';
import ConfirmButtonPair from '../components/ui/ConfirmButtonPair';
+import DataTreemap from '../components/dataManager/DataTreemap';
+import DataSelectionPanel from '../components/dataManager/DataSelectionPanel';
+import { DATA_KINDS, DATA_KIND_ORDER, HATCH_STYLE, dataKindOf } from '../components/dataManager/dataKinds';
// Plural labels for tombstone record kinds — shared between the in-page
// TombstoneGcSection toast and `scripts/gc-tombstones-now.js` (the CLI
@@ -110,13 +113,15 @@ function TombstoneGcSection() {
: 'Prune tombstones acked by every subscribed peer (skips the 24h grace).';
return (
- <div className="bg-port-card border border-port-border rounded-xl p-4 flex items-center justify-between gap-3">
- <div className="flex items-center gap-2 text-sm text-gray-300">
- <Trash2 size={14} className="text-gray-500" />
- <span className="text-gray-400 uppercase tracking-wider text-xs font-medium">Tombstone GC</span>
- <span className="text-gray-500 text-xs">
+ <div className="bg-port-card border border-port-border rounded-xl p-4 space-y-3">
+ <div>
+ <div className="flex items-center gap-2">
+ <Trash2 size={14} className="text-gray-500" />
+ <h2 className="text-gray-400 uppercase tracking-wider text-[11px] font-medium">Tombstone GC</h2>
+ </div>
+ <p className="mt-1 text-gray-500 text-xs">
Run on demand instead of waiting for the 24h orchestrator sweep.
- </span>
+ </p>
</div>
<button
onClick={runSweep}
@@ -131,9 +136,8 @@ function TombstoneGcSection() {
);
}
-function SizeBar({ size, maxSize }) {
+function SizeBar({ size, maxSize, color }) {
const pct = maxSize > 0 ? Math.max(1, (size / maxSize) * 100) : 0;
- const color = pct > 60 ? 'bg-port-warning' : pct > 30 ? 'bg-port-accent' : 'bg-port-success';
return (
<div className="w-full h-1.5 bg-port-border/50 rounded-full overflow-hidden">
<div className={`h-full ${color} rounded-full transition-all`} style={{ width: `${Math.min(pct, 100)}%` }} />
@@ -146,7 +150,9 @@ function CategoryRow({ cat, maxSize, onExpand, expanded, detail, onArchive, onPu
// no Archive/Purge flags. Say why the buttons are missing in outcome terms so
// the row reads as a deliberate safety stance, not a broken row (#3285).
// Older servers omit `classified`; treat only an explicit false as unknown.
- const unclassified = cat.classified === false;
+ const kindKey = dataKindOf(cat);
+ const kind = DATA_KINDS[kindKey];
+ const unclassified = kindKey === 'unclassified';
// `purgeScope: 'items'` categories hold the only copy of each file, so the
// whole-directory Purge button is replaced by a per-row delete in the detail
// table (#3327). Older servers omit `purgeScope` entirely — treat that as the
@@ -165,7 +171,7 @@ function CategoryRow({ cat, maxSize, onExpand, expanded, detail, onArchive, onPu
|| 'A job is using this directory right now — purge once it finishes.';
const { isConfirming, requestDelete, cancelDelete, confirmDelete } = useConfirmDelete();
return (
- <div className="border border-port-border rounded-lg overflow-hidden">
+ <div id={`data-category-${cat.key}`} className={`border rounded-lg overflow-hidden scroll-mt-4 ${expanded ? 'border-port-accent/60' : 'border-port-border'}`}>
<button
onClick={() => onExpand(cat.key)}
className="w-full flex items-center gap-3 p-3 hover:bg-port-card/50 transition-colors text-left"
@@ -173,11 +179,12 @@ function CategoryRow({ cat, maxSize, onExpand, expanded, detail, onArchive, onPu
{expanded ? <ChevronDown size={14} className="text-gray-500 shrink-0" /> : <ChevronRight size={14} className="text-gray-500 shrink-0" />}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
+ <span className={`w-2 h-2 rounded-sm shrink-0 ${kind.swatch}`} title={kind.label} />
<span className="text-sm font-medium text-white">{cat.label}</span>
<span className={`text-xs ${unclassified ? 'text-port-warning' : 'text-gray-500'}`}>{cat.description}</span>
</div>
<div className="mt-1">
- <SizeBar size={cat.size} maxSize={maxSize} />
+ <SizeBar size={cat.size} maxSize={maxSize} color={kind.swatch} />
</div>
</div>
<div className="text-right shrink-0 ml-2">
@@ -429,6 +436,17 @@ export default function DataManager() {
await loadDetail(key);
};
+ // The shortlist and panel select without toggling — re-picking the open
+ // category keeps it open rather than collapsing it like a row click does.
+ const selectCategory = (key) => {
+ if (expandedCatRef.current !== key) handleExpand(key);
+ };
+
+ const showSelectedActions = () => {
+ document.getElementById(`data-category-${expandedCatRef.current}`)
+ ?.scrollIntoView({ behavior: 'smooth', block: 'start' });
+ };
+
const refreshAfterAction = async (key) => {
fetchOverview();
if (expandedCatRef.current === key) await loadDetail(key);
@@ -488,7 +506,11 @@ export default function DataManager() {
);
}
- const maxSize = overview?.categories?.[0]?.size || 1;
+ const categories = overview?.categories || [];
+ const maxSize = categories[0]?.size || 1;
+ const totalFiles = categories.reduce((sum, c) => sum + (c.fileCount || 0), 0);
+ const presentKinds = DATA_KIND_ORDER.filter((k) => categories.some((c) => dataKindOf(c) === k));
+ const selectedCat = categories.find((c) => c.key === expandedCat) || null;
// `/data` is an `isFullWidthRoute` (Layout.jsx), so `<main>` is a bare
// `relative overflow-hidden` and this shell owns the only scroll region.
@@ -506,7 +528,7 @@ export default function DataManager() {
</div>
</div>
<div className="flex items-center gap-4">
- <div className="text-right">
+ <div className="hidden sm:block text-right">
<div className="text-lg font-mono font-bold text-white">{formatBytes(overview?.totalSize || 0)}</div>
<div className="text-xs text-gray-500">total in <code className="text-gray-400">{overview?.dataDir}/</code></div>
</div>
@@ -522,61 +544,77 @@ export default function DataManager() {
{/* Content */}
<div className="flex-1 min-h-0 overflow-auto p-4">
- {/* Summary cards */}
- <div className="grid grid-cols-2 sm:grid-cols-4 gap-3 mb-4">
- <div className="bg-port-card rounded-lg p-3 border border-port-border">
- <div className="text-xs text-gray-500 mb-1">Categories</div>
- <div className="text-lg font-bold text-white">{overview?.categories?.length || 0}</div>
- </div>
- <div className="bg-port-card rounded-lg p-3 border border-port-border">
- <div className="text-xs text-gray-500 mb-1">Total Size</div>
- <div className="text-lg font-bold text-white">{formatBytes(overview?.totalSize || 0)}</div>
- </div>
- <div className="bg-port-card rounded-lg p-3 border border-port-border">
- <div className="text-xs text-gray-500 mb-1">Largest</div>
- <div className="text-lg font-bold text-white">{overview?.categories?.[0]?.label || '—'}</div>
- <div className="text-xs text-gray-500">{formatBytes(overview?.categories?.[0]?.size || 0)}</div>
- </div>
- <div className="bg-port-card rounded-lg p-3 border border-port-border">
- <div className="text-xs text-gray-500 mb-1">Backups</div>
- <div className="text-lg font-bold text-white">{backups.length}</div>
- </div>
- </div>
+ <div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_20rem] items-start">
+ <div className="min-w-0 space-y-3">
+ {/* Totals + kind legend */}
+ <div className="flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs">
+ <span className="text-gray-300">
+ <span className="font-mono text-white">{formatBytes(overview?.totalSize || 0)}</span>
+ {' · '}{formatCount(totalFiles, { fallback: '0' })} files
+ {' · '}{formatCount(categories.length, { fallback: '0' })} categories
+ {' · '}{formatCount(backups.length, { fallback: '0' })} backups
+ </span>
+ <span className="flex flex-wrap items-center gap-x-3 gap-y-1 sm:ml-auto">
+ {presentKinds.map((k) => (
+ <span key={k} className="flex items-center gap-1.5 text-gray-400" title={DATA_KINDS[k].hint}>
+ <span className={`w-2.5 h-2.5 rounded-sm ${DATA_KINDS[k].swatch}`} style={DATA_KINDS[k].hatch ? HATCH_STYLE : undefined} />
+ {DATA_KINDS[k].label}
+ </span>
+ ))}
+ </span>
+ </div>
- {/* Tombstone GC */}
- <div className="mb-4">
- <TombstoneGcSection />
- </div>
+ {/* Disk-usage map — click a tile to select it and nest its entries */}
+ <DataTreemap
+ categories={categories}
+ selectedKey={expandedCat}
+ detail={detail}
+ onSelect={handleExpand}
+ />
+
+ {/* Category list — the action surface for the selection */}
+ <div className="space-y-2">
+ {categories.map(cat => (
+ <CategoryRow
+ key={cat.key}
+ cat={cat}
+ maxSize={maxSize}
+ expanded={expandedCat === cat.key}
+ detail={expandedCat === cat.key ? detail : null}
+ onExpand={handleExpand}
+ onArchive={handleArchive}
+ onPurge={setConfirmPurge}
+ onConfirmPurge={executePurge}
+ onCancelPurge={() => setConfirmPurge(null)}
+ onDeleteItem={handleDeleteItem}
+ deletingItem={expandedCat === cat.key ? deletingItem : null}
+ confirmingPurge={confirmPurge === cat.key}
+ archiving={archiving === cat.key}
+ purging={purging === cat.key}
+ />
+ ))}
+ </div>
- {/* Category list */}
- <div className="space-y-2">
- {overview?.categories?.map(cat => (
- <CategoryRow
- key={cat.key}
- cat={cat}
- maxSize={maxSize}
- expanded={expandedCat === cat.key}
- detail={expandedCat === cat.key ? detail : null}
- onExpand={handleExpand}
- onArchive={handleArchive}
- onPurge={setConfirmPurge}
- onConfirmPurge={executePurge}
- onCancelPurge={() => setConfirmPurge(null)}
- onDeleteItem={handleDeleteItem}
- deletingItem={expandedCat === cat.key ? deletingItem : null}
- confirmingPurge={confirmPurge === cat.key}
- archiving={archiving === cat.key}
- purging={purging === cat.key}
+ {/* Backups section */}
+ <BackupsSection
+ backups={backups}
+ loading={loading}
+ onDelete={handleDeleteBackup}
/>
- ))}
- </div>
+ </div>
- {/* Backups section */}
- <BackupsSection
- backups={backups}
- loading={loading}
- onDelete={handleDeleteBackup}
- />
+ <div className="min-w-0 space-y-4 lg:sticky lg:top-0">
+ <DataSelectionPanel
+ overview={overview}
+ totalFiles={totalFiles}
+ selected={selectedCat}
+ detail={detail}
+ onSelect={selectCategory}
+ onShowActions={showSelectedActions}
+ />
+ <TombstoneGcSection />
+ </div>
+ </div>
</div>
</div>
);
diff --git a/client/src/pages/DataManager.test.jsx b/client/src/pages/DataManager.test.jsx
index 09ff9b436e..8ca3162f4d 100644
--- a/client/src/pages/DataManager.test.jsx
+++ b/client/src/pages/DataManager.test.jsx
@@ -164,7 +164,7 @@ describe('DataManager per-item purge (#3327)', () => {
it('keeps the category-wide Purge button for category-scoped and legacy rows', async () => {
render(<DataManager />);
- await waitFor(() => expect(screen.getByText('Messages')).toBeInTheDocument());
+ await waitFor(() => expect(screen.getAllByText('Messages').length).toBeGreaterThan(0));
expandRow('Messages');
await waitFor(() => expect(screen.getByRole('button', { name: /Purge/ })).toBeInTheDocument());
@@ -209,7 +209,7 @@ describe('DataManager busy categories (#3342)', () => {
it('keeps the Purge button for an idle category in the same list', async () => {
render(<DataManager />);
- await waitFor(() => expect(screen.getByText('Messages')).toBeInTheDocument());
+ await waitFor(() => expect(screen.getAllByText('Messages').length).toBeGreaterThan(0));
expandRow('Messages');
await waitFor(() => expect(screen.getByRole('button', { name: /Purge/ })).toBeInTheDocument());
@@ -268,7 +268,7 @@ describe('DataManager busy categories (#3342)', () => {
purgeDataCategory.mockImplementation(() => new Promise((res) => { resolvePurge = res; }));
render(<DataManager />);
- await waitFor(() => expect(screen.getByText('Messages')).toBeInTheDocument());
+ await waitFor(() => expect(screen.getAllByText('Messages').length).toBeGreaterThan(0));
expandRow('Messages');
await waitFor(() => expect(screen.getByRole('button', { name: /Purge/ })).toBeInTheDocument());
@@ -377,3 +377,47 @@ describe('DataManager category detail loading state (#4147)', () => {
expect(panel.className).toContain('max-h-64');
});
});
+
+// The disk-usage map and its side panel (disktree-style redesign): a tile
+// selects its category, nests that category's entries, and the "worth a look"
+// shortlist offers only whole-category reclaim — never an item-scoped category
+// whose files are the only copy.
+describe('DataManager treemap + selection panel', () => {
+ beforeEach(() => {
+ getDataOverview.mockReset().mockResolvedValue({
+ ...scopedOverview,
+ disk: { total: 10 * 1024 ** 3, used: 6 * 1024 ** 3, free: 4 * 1024 ** 3 },
+ });
+ getDataCategory.mockReset().mockImplementation((key) => Promise.resolve({
+ key,
+ items: key === 'messages' ? [{ name: 'inbox-archive', type: 'directory', size: 900, fileCount: 4 }] : [],
+ }));
+ });
+
+ it('selects a category from its tile and nests its entries in the map', async () => {
+ render(<DataManager />);
+ const tile = await screen.findByRole('button', { name: /^Messages/, pressed: false });
+ fireEvent.click(tile);
+
+ await waitFor(() => expect(screen.getByRole('button', { name: /^Messages/, pressed: true })).toBeInTheDocument());
+ // Entry name shows in the nested tile and in the expanded row's table.
+ await waitFor(() => expect(screen.getAllByText('inbox-archive').length).toBe(2));
+ const panel = screen.getByRole('complementary', { name: 'Selection details' });
+ expect(panel).toHaveTextContent('data/messages');
+ expect(panel).toHaveTextContent('Reclaimable');
+ });
+
+ it('shortlists only whole-category reclaim and shows disk headroom', async () => {
+ render(<DataManager />);
+ const panel = await screen.findByRole('complementary', { name: 'Selection details' });
+ await waitFor(() => expect(panel).toHaveTextContent('Worth a look'));
+
+ const shortlist = panel.querySelector('ul');
+ expect(shortlist).toHaveTextContent('Messages');
+ expect(shortlist).toHaveTextContent('Legacy');
+ expect(shortlist).not.toHaveTextContent('Images');
+ expect(panel).toHaveTextContent('4 GB');
+ expect(panel).toHaveTextContent('6 GB used');
+ expect(panel).toHaveTextContent('10 GB total');
+ });
+});
diff --git a/server/services/dataManager.js b/server/services/dataManager.js
index 53cd8fb630..ea615cddb5 100644
--- a/server/services/dataManager.js
+++ b/server/services/dataManager.js
@@ -1,8 +1,9 @@
-import { readdir, stat, lstat } from 'fs/promises';
+import { readdir, stat, lstat, statfs } from 'fs/promises';
import { join, relative, resolve, isAbsolute } from 'path';
import { existsSync } from 'fs';
import { execFile } from '../lib/childProcess.js';
import { promisify } from 'util';
+import { parseFilesystemStats } from '../lib/fileCore.js';
import { PATHS, ensureDir, isTopLevelEntryName, rmGuarded, writeFileGuarded } from '../lib/fileUtils.js';
import { ServerError } from '../lib/errorHandler.js';
import {
@@ -259,6 +260,10 @@ async function getDirSizeAndCount(dirPath, { strict = false } = {}) {
}
export async function getDataOverview({ strict = false } = {}) {
+ // Capacity of the volume holding data/ so the page can show how much room is
+ // left, not just what PortOS occupies. Null when the platform can't say.
+ // Independent of the scans below, so it runs alongside them.
+ const diskPromise = statfs(DATA_DIR).then(parseFilesystemStats).catch(() => null);
const entries = await readdir(DATA_DIR, { withFileTypes: true }).catch((err) => {
if (strict) throw err;
return [];
@@ -286,9 +291,12 @@ export async function getDataOverview({ strict = false } = {}) {
categories.sort((a, b) => b.size - a.size);
+ const disk = await diskPromise;
+
return {
totalSize: totalResult.size,
categories,
+ disk,
dataDir: 'data'
};
}
diff --git a/server/services/dataManager.strict.test.js b/server/services/dataManager.strict.test.js
index 4e470f4cd3..0e9ea56ff4 100644
--- a/server/services/dataManager.strict.test.js
+++ b/server/services/dataManager.strict.test.js
@@ -61,6 +61,10 @@ describe('dataManager strict overview', () => {
size: 0,
fileCount: 0,
});
+ // The Data Manager's disk panel reads the volume capacity off the overview.
+ expect(overview.disk.total).toBeGreaterThan(0);
+ expect(overview.disk.free).toBeGreaterThanOrEqual(0);
+ expect(overview.disk.free).toBeLessThanOrEqual(overview.disk.total);
});
it('rejects the same failed category scan for fail-closed report callers', async () => {