From 42b62c363117c85486405135835ba56bbfc235c0 Mon Sep 17 00:00:00 2001
From: Qijun
Date: Thu, 1 Oct 2026 22:55:55 -0700
Subject: [PATCH 1/4] feat: show what a project keeps in browser storage
Project info in the project menu lists the open project's IndexedDB
database, the record count of every table, the library size against the
1 GiB limit, and the browser's origin-wide usage and persistence.
---
.../web/src/data/storage-summary.test.ts | 34 +++++++
ui-packages/web/src/data/storage-summary.ts | 49 +++++++++++
.../features/projects/project-info-dialog.tsx | 88 +++++++++++++++++++
.../features/projects/project-switcher.tsx | 14 +++
.../src/features/projects/style.module.scss | 35 ++++++++
5 files changed, 220 insertions(+)
create mode 100644 ui-packages/web/src/data/storage-summary.test.ts
create mode 100644 ui-packages/web/src/data/storage-summary.ts
create mode 100644 ui-packages/web/src/features/projects/project-info-dialog.tsx
diff --git a/ui-packages/web/src/data/storage-summary.test.ts b/ui-packages/web/src/data/storage-summary.test.ts
new file mode 100644
index 0000000..1986726
--- /dev/null
+++ b/ui-packages/web/src/data/storage-summary.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, it } from 'vitest'
+import { emptyConversationDraft } from '../core/conversations'
+import { rootSources } from '../core/files'
+import { saveStoredConversationDraft } from './conversation-store'
+import { importStoredFiles, listStoredFiles } from './file-store'
+import { readStorageSummary } from './storage-summary'
+
+describe('storage summary', () => {
+ it('counts every table of the open project and sums the stored file bytes', async () => {
+ await importStoredFiles(
+ rootSources([new File(['# Notes'], 'Notes.md', { type: 'text/markdown' })]),
+ 'keep',
+ )
+ await saveStoredConversationDraft({
+ id: 'conversation',
+ title: null,
+ draft: emptyConversationDraft(),
+ createdAt: 1,
+ lastActiveAt: 1,
+ })
+ const files = await listStoredFiles()
+
+ const summary = await readStorageSummary()
+
+ expect(Object.fromEntries(summary.stores.map(store => [store.name, store.records]))).toEqual({
+ contents: files.length,
+ conversations: 1,
+ files: files.length,
+ folderExports: 0,
+ messages: 0,
+ })
+ expect(summary.fileBytes).toBe(files.reduce((total, file) => total + file.size, 0))
+ })
+})
diff --git a/ui-packages/web/src/data/storage-summary.ts b/ui-packages/web/src/data/storage-summary.ts
new file mode 100644
index 0000000..8dad588
--- /dev/null
+++ b/ui-packages/web/src/data/storage-summary.ts
@@ -0,0 +1,49 @@
+import { listStoredFiles } from './file-store'
+import { openWorkspaceDatabase } from './workspace-database'
+
+export type StoreSummary = { name: string; records: number }
+
+export type BrowserStorage = { usage: number; quota: number; persisted: boolean }
+
+export type StorageSummary = {
+ databaseName: string
+ stores: readonly StoreSummary[]
+ /** The same sum the library limit checks: every stored file, attachments included. */
+ fileBytes: number
+ browser: BrowserStorage | null
+}
+
+// Origin-wide, so it covers every project in this browser, not just the open one.
+const readBrowserStorage = async (): Promise => {
+ if (!navigator.storage?.estimate || !navigator.storage.persisted) return null
+ try {
+ const [{ usage = 0, quota = 0 }, persisted] = await Promise.all([
+ navigator.storage.estimate(),
+ navigator.storage.persisted(),
+ ])
+ return { usage, quota, persisted }
+ } catch (error) {
+ console.error('Unable to read browser storage usage', error)
+ return null
+ }
+}
+
+export const readStorageSummary = async (): Promise => {
+ const database = await openWorkspaceDatabase()
+ const [stores, files, browser] = await Promise.all([
+ Promise.all(
+ Array.from(database.objectStoreNames, async name => ({
+ name,
+ records: await database.count(name),
+ })),
+ ),
+ listStoredFiles(),
+ readBrowserStorage(),
+ ])
+ return {
+ databaseName: database.name,
+ stores,
+ fileBytes: files.reduce((total, file) => total + file.size, 0),
+ browser,
+ }
+}
diff --git a/ui-packages/web/src/features/projects/project-info-dialog.tsx b/ui-packages/web/src/features/projects/project-info-dialog.tsx
new file mode 100644
index 0000000..d933fac
--- /dev/null
+++ b/ui-packages/web/src/features/projects/project-info-dialog.tsx
@@ -0,0 +1,88 @@
+import { useEffect, useState } from 'react'
+import { ConfirmationDialog as Modal } from '../../components/confirmation-dialog'
+import { formatBytes } from '../../core/files'
+import type { Project } from '../../core/projects'
+import {
+ type BrowserStorage,
+ readStorageSummary,
+ type StorageSummary,
+} from '../../data/storage-summary'
+import styles from './style.module.scss'
+
+const percent = new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 1 })
+// A fresh library is a sliver of the quota; rounding it to 0% would read as nothing stored.
+const share = (ratio: number) => (ratio < 0.001 ? 'under 0.1%' : percent.format(ratio))
+
+const BrowserStorageNote = ({ usage, quota, persisted }: BrowserStorage) => (
+
+ This browser, all projects: {formatBytes(usage)} used
+ {quota > 0 && `, ${share(usage / quota)} of what it allows`}.{' '}
+ {persisted
+ ? 'Storage is persistent.'
+ : 'Storage is not persistent; the browser may clear it under disk pressure.'}
+