Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(databases): add database listing and creation to Drive (#7410)
Wolf Mermelstein699543824a49
diff --git a/apps/web/src/features/command/CommandMenu.tsx b/apps/web/src/features/command/CommandMenu.tsxindex 2ed5ce8d71..da50b8b35b 100644--- a/apps/web/src/features/command/CommandMenu.tsx+++ b/apps/web/src/features/command/CommandMenu.tsx@@ -27,6 +27,7 @@ import { type EntityData, isGithubPrEntity } from '@entity';import { EntitySelectionBadge } from '@entity/components/EntitySelectionBadge';import Macro from '@icon/macro-logo.svg';import ArrowLeft from '@phosphor/arrow-left.svg';+import { useDatabaseDiscoverySync } from '@queries/storage/databases';import {Badge,CommandMenuEmptyState,@@ -166,6 +167,8 @@ export function CommandMenuInner(props: {const query = debouncedDependent(CommandState.query, 60);+ useDatabaseDiscoverySync(() => !props.items && CommandState.isOpen());+const defaultCommandItems = props.items? undefined: useCommandItems(query, categoryFilter, {diff --git a/apps/web/src/features/command/useCommandItems.test.ts b/apps/web/src/features/command/useCommandItems.test.tsindex 1ca383c923..d0b4a11c36 100644--- a/apps/web/src/features/command/useCommandItems.test.ts+++ b/apps/web/src/features/command/useCommandItems.test.ts@@ -1,6 +1,8 @@import type {+ Bucket,QuickAccessItem,QuickAccessList,+ QuickAccessListOptions,} from '@core/context/quickAccess/types';import type { CommandWithInfo } from '@core/hotkey/getCommands';import { createRoot, createSignal } from 'solid-js';@@ -10,6 +12,7 @@ import { useCommandItems } from './useCommandItems';const mocks = vi.hoisted(() => ({list: undefined as QuickAccessList | undefined,+ requestedBuckets: [] as Bucket[],entityMode: (): boolean => false,scope: (): CommandWithInfo[] => [],}));@@ -33,7 +36,8 @@ vi.mock('@app/constants/hotkeys', () => ({vi.mock('@core/context/quickAccess', () => ({exclude: () => ['note', 'channel'],useQuickAccess: () => ({- useList: () => {+ useList: (options: QuickAccessListOptions) => {+ mocks.requestedBuckets = [...options.buckets];if (!mocks.list) throw new Error('Missing test list');return mocks.list;},@@ -165,3 +169,32 @@ describe('command menu entity loading', () => {expect(result.isLoadingEntities()).toBe(false);});});++describe('command menu database categories', () => {+ it('keeps databases discoverable in All and Documents without view history', () => {+ const { result, setItems, setLoading, setCategory } = setup();+ const database: QuickAccessItem = {+ id: 'book-organizer',+ kind: 'entity',+ bucket: 'database',+ searchText: 'Book Organizer',+ sortTimestamp: 1,+ timestamps: { createdAt: '2026-09-01T00:00:00Z' },+ data: {+ type: 'database',+ id: 'book-organizer',+ name: 'Book Organizer',+ ownerId: 'owner',+ grant: 'owner',+ createdAt: '2026-09-01T00:00:00Z',+ },+ };+ setItems([database]);+ setLoading(false);+ for (const category of ['all', 'documents'] as const) {+ setCategory(category);+ expect(result.items()).toContain(database);+ expect(mocks.requestedBuckets).toContain('database');+ }+ });+});diff --git a/apps/web/src/features/drive-view/context/drive-source.ts b/apps/web/src/features/drive-view/context/drive-source.tsindex cd2b8eed89..460a0e465c 100644--- a/apps/web/src/features/drive-view/context/drive-source.ts+++ b/apps/web/src/features/drive-view/context/drive-source.ts@@ -10,6 +10,8 @@ export type DriveListItem = SoupEntityRow<EntityData>;/** Query results consumed by Drive's list controller and renderer. */export type DriveListSource = ListDataSource<DriveListItem> & {hasData: Accessor<boolean>;+ /** Independent catalog failures must not block file pagination. */+ databaseError: Accessor<unknown>;featuredIds: Accessor<readonly string[]>;deferInteractions: Accessor<boolean>;};diff --git a/apps/web/src/features/drive-view/drive-create-menu.tsx b/apps/web/src/features/drive-view/drive-create-menu.tsxindex 46e364dba1..ab4149d063 100644--- a/apps/web/src/features/drive-view/drive-create-menu.tsx+++ b/apps/web/src/features/drive-view/drive-create-menu.tsx@@ -22,9 +22,17 @@ export function DriveCreateMenu() {const options = () =>CREATABLE_BLOCKS.filter((block) =>- ['md', 'snippet', 'spreadsheet', 'canvas', 'code', 'project'].includes(- block.blockName- ) && isEnabled(block.blockName)+ [+ 'md',+ 'snippet',+ 'spreadsheet',+ 'canvas',+ 'code',+ 'project',+ 'database',+ ].includes(block.blockName) &&+ isEnabled(block.blockName) &&+ (block.blockName !== 'database' || !state.projectId()));return (diff --git a/apps/web/src/features/drive-view/drive-view.tsx b/apps/web/src/features/drive-view/drive-view.tsxindex e394f9c43a..e178209f88 100644--- a/apps/web/src/features/drive-view/drive-view.tsx+++ b/apps/web/src/features/drive-view/drive-view.tsx@@ -6,16 +6,25 @@ import {useSoupListNavigationHotkeys,} from '@app/features/soup';import { ViewTour } from '@app/features/tours/ViewTour';+import { useFeatureFlag } from '@app/lib/analytics/posthog';import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import {useSplitPanelOrThrow,withSplitPanelOwner,} from '@components/app/split-layout/layoutUtils';import { toast } from '@core/component/Toast/Toast';+import { enableDatabases } from '@core/constant/featureFlags';import { useUserId } from '@core/context/user';import { ListEntityMetadataQueryProvider } from '@entity';import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';-import { createEffect, on, onCleanup, onMount, Suspense } from 'solid-js';+import {+ createEffect,+ createMemo,+ on,+ onCleanup,+ onMount,+ Suspense,+} from 'solid-js';import { DriveProvider } from './context/drive-context';import { driveLocationLabel } from './core/location-label';import {@@ -32,7 +41,10 @@ import {createDriveViewState,type DriveRouteState,} from './primitives/drive-route-state';-import { createDriveState } from './primitives/drive-state';+import {+ availableDriveState,+ createDriveState,+} from './primitives/drive-state';import { createDriveDataSource } from './queries/drive-data-source';import { createDriveSidebarSource } from './queries/drive-sidebar-source';import { documentsTour } from './tour';@@ -45,19 +57,24 @@ function DriveComposition(props: { route: DriveRouteState }) {const panel = useSplitPanelOrThrow();const navigation = useDriveDetailNavigation();const userId = useUserId();+ const databasesFlag = useFeatureFlag(enableDatabases);const notificationSource = useGlobalNotificationSource();const tagSets = useTagSets();const tagSetsReady = useTagSetsReady();const view = createDriveViewState(props.route, () => list.reset());+ const viewState = createMemo(() =>+ availableDriveState(view.value(), databasesFlag().enabled)+ );const searchText = useMobileSearchText(() => view.value().search,panel.handle.isActive);- const selection = () => ({ ...view.value(), search: searchText() });+ const selection = () => ({ ...viewState(), search: searchText() });const sidebar = createDriveSidebarSource();const source = withSplitPanelOwner(listOwnedSlotName('data-source'), () =>createDriveDataSource({selection,+ databasesEnabled: () => databasesFlag().enabled,userId,tagSets,tagSetsReady,@@ -84,7 +101,7 @@ function DriveComposition(props: { route: DriveRouteState }) {}));const state = createDriveState({- state: view.value,+ state: viewState,setState: view.setValue,folders: sidebar.folders,list,diff --git a/apps/web/src/features/drive-view/filters/drive-facets.ts b/apps/web/src/features/drive-view/filters/drive-facets.tsindex a6fe1eb7d4..42981b4f64 100644--- a/apps/web/src/features/drive-view/filters/drive-facets.ts+++ b/apps/web/src/features/drive-view/filters/drive-facets.ts@@ -3,6 +3,7 @@ import {type Facet,type FacetClause,type FacetOption,+ NIL_UUID,TAG_FACET_ID,type TagFacetContext,tagFacetOption,@@ -32,6 +33,7 @@ export type DriveFacetEntity = EntityWithProperties<EntityData>;type DriveFacetOption = FacetOption<DriveFacetEntity, DriveFacetContext>;type DocumentTypeOptionId =+ | 'database'| 'doc-markdown'| 'doc-canvas'| 'doc-spreadsheet'@@ -59,6 +61,11 @@ const namedDocumentSubtype = clause.or();const TYPE_OPTIONS: DriveFacetOption[] = [+ typeOption(+ 'database',+ clause.eq('id', NIL_UUID),+ (entity) => entity.type === 'database'+ ),typeOption('doc-markdown',clause.and(clause.eq('fileType', 'md'), clause.not(namedDocumentSubtype)),diff --git a/apps/web/src/features/drive-view/filters/use-drive-filters.tsx b/apps/web/src/features/drive-view/filters/use-drive-filters.tsxindex 17013cba7d..cd60d71dac 100644--- a/apps/web/src/features/drive-view/filters/use-drive-filters.tsx+++ b/apps/web/src/features/drive-view/filters/use-drive-filters.tsx@@ -1,6 +1,8 @@import type { ListFilterGroup } from '@app/components/view-shell';+import { useFeatureFlag } from '@app/lib/analytics/posthog';import { EntityIcon } from '@core/component/EntityIcon';import { UserIcon } from '@core/component/UserIcon';+import { enableDatabases } from '@core/constant/featureFlags';import { useTagFilterGroup } from '@property/tags/use-tag-filter-group';import { useContacts } from '@queries/contacts/contacts';import { createMemo } from 'solid-js';@@ -9,6 +11,7 @@ import { useDriveView } from '../context/drive-context';export type DriveFilterGroupId = 'type' | 'created-by' | 'tags' | 'scope';const typeOptions = [+ { id: 'database', label: 'Database', type: 'database' },{ id: 'doc-markdown', label: 'Markdown', type: 'md' },{ id: 'doc-canvas', label: 'Canvas', type: 'canvas' },{ id: 'doc-spreadsheet', label: 'Spreadsheet', type: 'spreadsheet' },@@ -29,6 +32,7 @@ export function useDriveFilters() {const userId = actions.userId;const contacts = useContacts();+ const databasesFlag = useFeatureFlag(enableDatabases);const tagGroup = useTagFilterGroup();@@ -83,12 +87,16 @@ export function useDriveFilters() {groups.push({id: 'type',label: 'Type',- options: typeOptions.map((option) => ({- id: option.id,- label: option.label,-- icon: () => <EntityIcon targetType={option.type} size="xs" />,- })),+ options: typeOptions+ .filter(+ (option) => option.id !== 'database' || databasesFlag().enabled+ )+ .map((option) => ({+ id: option.id,+ label: option.label,++ icon: () => <EntityIcon targetType={option.type} size="xs" />,+ })),});if (showCreators()) {diff --git a/apps/web/src/features/drive-view/primitives/drive-state.ts b/apps/web/src/features/drive-view/primitives/drive-state.tsindex 69f1412523..c2ead17661 100644--- a/apps/web/src/features/drive-view/primitives/drive-state.ts+++ b/apps/web/src/features/drive-view/primitives/drive-state.ts@@ -11,6 +11,22 @@ import type {} from '../core/types';import type { DriveListState } from './drive-list';+/** Mask disabled database filters without changing persisted route intent. */+export function availableDriveState(+ state: DriveState,+ databasesEnabled: boolean+): DriveState {+ if (databasesEnabled || !state.facets.type?.includes('database'))+ return state;+ return {+ ...state,+ facets: {+ ...state.facets,+ type: state.facets.type.filter((id) => id !== 'database'),+ },+ };+}+/** Shared navigation and controls. Display derivations stay with their consumers. */export function createDriveState(options: {state: Accessor<DriveState>;diff --git a/apps/web/src/features/drive-view/queries/drive-data-source.test.ts b/apps/web/src/features/drive-view/queries/drive-data-source.test.tsnew file mode 100644index 0000000000..ea69451149--- /dev/null+++ b/apps/web/src/features/drive-view/queries/drive-data-source.test.ts@@ -0,0 +1,154 @@+import type { ListedDatabase } from '@service-storage/generated/schemas/listedDatabase';+import { createRoot, createSignal } from 'solid-js';+import { afterEach, describe, expect, it, vi } from 'vitest';+import type { DriveSelection } from '../context/drive-source';++const mocks = vi.hoisted(() => ({+ database: {+ isSuccess: true,+ isPending: false,+ isFetching: false,+ error: null as unknown,+ data: [] as ListedDatabase[],+ refetch: vi.fn(async () => {}),+ },+ soup: {+ isPending: false,+ isSuccess: true,+ isLoading: false,+ isFetching: false,+ isPlaceholderData: false,+ isFetchingNextPage: false,+ hasNextPage: false,+ error: null as unknown,+ data: { entities: [] },+ refresh: vi.fn(async () => {}),+ fetchNextPage: vi.fn(async () => {}),+ },+}));+vi.mock('@queries/storage/databases', () => ({+ useDatabasesQuery: () => mocks.database,+}));+vi.mock('@queries/soup/items', () => ({+ useSoupAstItemsQuery: () => mocks.soup,+}));+vi.mock('@queries/soup/transform-utils', () => ({+ isDisplayableSoupItem: () => true,+ mapApiSoupItemToEntity: vi.fn(),+}));+vi.mock('@app/features/soup/entity-notifications', () => ({+ withEntityNotifications: (entity: unknown) => entity,+}));+vi.mock('@app/features/soup/search', () => ({+ useOptionalSearchContext: () => undefined,+ createSearchState: ({ text }: { text: () => string }) => ({+ isSearching: () => !!text(),+ data: () => [],+ isLocalSearchSettling: () => false,+ isFetching: () => false,+ featuredIds: () => [],+ error: () => undefined,+ hasNextPage: () => false,+ isFetchingNextPage: () => false,+ refresh: async () => {},+ fetchNextPage: async () => {},+ }),+}));++import { createDriveDataSource } from './drive-data-source';++let dispose: (() => void) | undefined;+afterEach(() => {+ dispose?.();+ vi.clearAllMocks();+});+function setup() {+ mocks.database.data = [+ {+ database: {+ id: 'db',+ name: 'Book Organizer',+ owner_id: 'me',+ created_at: '2026-09-01T00:00:00Z',+ trashed_at: null,+ },+ grant: 'owner',+ tables: [],+ },+ ];+ mocks.database.error = null;+ mocks.database.isSuccess = true;+ mocks.soup.hasNextPage = false;+ mocks.soup.error = null;+ mocks.soup.isSuccess = true;+ return createRoot((cleanup) => {+ dispose = cleanup;+ const [enabled, setEnabled] = createSignal(true);+ const [selection, setSelection] = createSignal<DriveSelection>({+ location: { kind: 'tab', tab: 'owned' },+ scope: 'default',+ sort: 'updated_at',+ search: '',+ facets: {},+ });+ const source = createDriveDataSource({+ selection,+ databasesEnabled: enabled,+ userId: () => 'me',+ tagSets: () => [],+ tagSetsReady: () => true,+ // Notification enrichment is replaced above; this capability is unused.+ notificationSource: {} as never,+ });+ return { source, setSelection, selection, setEnabled };+ });+}+describe('Drive database source integration', () => {+ it('merges databases with files, searches names and applies type facets', () => {+ const { source, setSelection, selection } = setup();+ expect(source.items().map((row) => row.entity.name)).toEqual([+ 'Book Organizer',+ ]);+ setSelection({+ ...selection(),+ search: 'organizer',+ facets: { type: ['database'] },+ });+ expect(source.items()).toHaveLength(1);+ setSelection({ ...selection(), facets: { type: ['doc-markdown'] } });+ expect(source.items()).toHaveLength(0);+ });+ it('removes cached databases immediately when the flag turns off', () => {+ const { source, setEnabled } = setup();+ expect(source.items()).toHaveLength(1);+ setEnabled(false);+ expect(source.items()).toHaveLength(0);+ });+ it('refreshes both transports to recover database failures', async () => {+ const { source } = setup();+ await source.refresh();+ expect(mocks.database.refetch).toHaveBeenCalledOnce();+ expect(mocks.soup.refresh).toHaveBeenCalledOnce();+ });+ it('retains cached database rows after a failed refetch without blocking file pagination', async () => {+ const { source, setSelection, selection } = setup();+ expect(source.items()).toHaveLength(1);+ mocks.database.error = new Error('catalog unavailable');+ mocks.database.isSuccess = false;+ mocks.soup.hasNextPage = true;+ setSelection({ ...selection() });+ expect(source.items()).toHaveLength(1);+ expect(source.databaseError()).toBe(mocks.database.error);+ expect(source.error()).toBeUndefined();+ expect(source.isFetching()).toBe(false);+ await source.loadMore();+ expect(mocks.soup.fetchNextPage).toHaveBeenCalledOnce();+ });+ it('keeps database rows visible when the file transport fails', () => {+ const { source } = setup();+ mocks.soup.error = new Error('files unavailable');+ mocks.soup.isSuccess = false;+ expect(source.hasData()).toBe(true);+ expect(source.error()).toBe(mocks.soup.error);+ });+});diff --git a/apps/web/src/features/drive-view/queries/drive-data-source.ts b/apps/web/src/features/drive-view/queries/drive-data-source.tsindex bc893d1b43..e026f1b94f 100644--- a/apps/web/src/features/drive-view/queries/drive-data-source.ts+++ b/apps/web/src/features/drive-view/queries/drive-data-source.ts@@ -18,10 +18,12 @@ import {isDisplayableSoupItem,mapApiSoupItemToEntity,} from '@queries/soup/transform-utils';+import { useDatabasesQuery } from '@queries/storage/databases';import type { TagSetResponse } from '@service-properties/generated/schemas/tagSetResponse';import { type Accessor, createMemo } from 'solid-js';import type { DriveListSource, DriveSelection } from '../context/drive-source';import { DRIVE_FACETS } from '../filters/drive-facets';+import { selectDriveDatabases } from './drive-databases';import { buildDriveQuery } from './drive-query';import {driveEntityMatchesLocation,@@ -32,6 +34,7 @@ import { buildDriveSearchRequest } from './drive-search';/** Query, local/service search and row assembly owned by Drive. */export function createDriveDataSource(options: {selection: Accessor<DriveSelection>;+ databasesEnabled: Accessor<boolean>;userId: Accessor<string | undefined>;tagSets: Accessor<readonly TagSetResponse[]>;tagSetsReady: Accessor<boolean>;@@ -40,6 +43,20 @@ export function createDriveDataSource(options: {const { selection, userId, notificationSource } = options;const searchContext = useOptionalSearchContext();+ const databasesQuery = useDatabasesQuery();+ const includesDatabases = () => {+ const current = selection();+ return (+ options.databasesEnabled() &&+ current.location.kind === 'tab' &&+ current.location.tab !== 'recent' &&+ current.scope !== 'attachments'+ );+ };+ const databaseEntities = () =>+ includesDatabases() && !databasesQuery.isPending+ ? selectDriveDatabases(databasesQuery.data ?? [], selection(), userId())+ : [];const facetContext = createMemo(() =>createTagFacetContext(options.tagSets())@@ -94,7 +111,7 @@ export function createDriveDataSource(options: {);// Cold REST data suspends; keep the shell and its controls available.- const queryData = () => (query.isLoading ? undefined : query.data);+ const queryData = () => (query.isPending ? undefined : query.data);const matchesFacets = (entity: EntityData) =>testFacets(selection().facets, DRIVE_FACETS, entity, facetContext());@@ -154,7 +171,10 @@ export function createDriveDataSource(options: {const entities = createMemo(() => {if (!facetsReady()) return [];- const matching = rawEntities().filter((entity) => {+ const matching = [+ ...rawEntities().filter((entity) => entity.type !== 'database'),+ ...databaseEntities(),+ ].filter((entity) => {const matchesLocation = driveEntityMatchesLocation(entity,selection(),@@ -174,21 +194,19 @@ export function createDriveDataSource(options: {const items = createSoupRowStore(() => buildFlatSoupRows(entities()));- const isFetching = () => {- if (search.isSearching())- return search.isFetching() || search.isLocalSearchSettling();-- return query.isFetching;- };+ const isFetching = () =>+ search.isSearching()+ ? search.isFetching() || search.isLocalSearchSettling()+ : query.isFetching;const hasMore = () =>search.isSearching() ? search.hasNextPage() : query.hasNextPage;- const error = () => {- if (search.isSearching()) return search.error();+ const error = () =>+ search.isSearching() ? search.error() : (query.error ?? undefined);- return query.error ?? undefined;- };+ const databaseError = () =>+ includesDatabases() ? (databasesQuery.error ?? undefined) : undefined;return {items,@@ -196,20 +214,32 @@ export function createDriveDataSource(options: {isLoading: () => {if (items().length > 0) return false;if (!facetsReady()) return true;- if (search.isSearching()) return isFetching();-- return query.isLoading || query.isFetching;+ if (search.isSearching())+ return (+ isFetching() || (includesDatabases() && databasesQuery.isPending)+ );++ return (+ query.isLoading ||+ query.isFetching ||+ (includesDatabases() && databasesQuery.isPending)+ );},isFetching,error,+ databaseError,hasData: () => {if (search.isSearching())return items().length > 0 || (!isFetching() && !error());- return queryData() !== undefined && !query.isPlaceholderData;+ return (+ items().length > 0 ||+ (queryData() !== undefined && !query.isPlaceholderData) ||+ (includesDatabases() && databasesQuery.isSuccess)+ );},hasMore,@@ -232,8 +262,10 @@ export function createDriveDataSource(options: {},refresh: async () => {- if (search.isSearching()) await search.refresh();- else await query.refresh();+ await Promise.all([+ search.isSearching() ? search.refresh() : query.refresh(),+ includesDatabases() ? databasesQuery.refetch() : Promise.resolve(),+ ]);},featuredIds: search.featuredIds,diff --git a/apps/web/src/features/drive-view/queries/drive-databases.test.ts b/apps/web/src/features/drive-view/queries/drive-databases.test.tsnew file mode 100644index 0000000000..a9452f3a76--- /dev/null+++ b/apps/web/src/features/drive-view/queries/drive-databases.test.ts@@ -0,0 +1,131 @@+import type { ListedDatabase } from '@service-storage/generated/schemas/listedDatabase';+import { describe, expect, it } from 'vitest';+import type { DriveSelection } from '../context/drive-source';+import { availableDriveState } from '../primitives/drive-state';+import { selectDriveDatabases } from './drive-databases';+import {+ driveEntityMatchesLocation,+ orderDriveEntities,+} from './drive-results';++const selection: DriveSelection = {+ location: { kind: 'tab', tab: 'owned' },+ scope: 'default',+ sort: 'updated_at',+ search: '',+ facets: {},+};+const listed: ListedDatabase[] = [+ {+ database: {+ id: 'mine',+ name: 'Product roadmap',+ owner_id: 'me',+ created_at: '2026-09-01T00:00:00Z',+ trashed_at: null,+ },+ grant: 'owner',+ tables: [],+ },+ {+ database: {+ id: 'shared',+ name: 'Customer roadmap',+ owner_id: 'other',+ created_at: '2026-09-02T00:00:00Z',+ trashed_at: null,+ },+ grant: 'view',+ tables: [],+ },+ {+ database: {+ id: 'trash',+ name: 'Archived',+ owner_id: 'me',+ created_at: '2026-09-03T00:00:00Z',+ trashed_at: '2026-09-04T00:00:00Z',+ },+ grant: 'owner',+ tables: [],+ },+];++describe('Drive database listing', () => {+ it('separates owned and shared databases and excludes trash', () => {+ expect(+ selectDriveDatabases(listed, selection, 'me').map((entity) => entity.id)+ ).toEqual(['mine']);+ expect(+ selectDriveDatabases(+ listed,+ { ...selection, location: { kind: 'tab', tab: 'shared' } },+ 'me'+ ).map((entity) => entity.id)+ ).toEqual(['shared']);+ expect(+ selectDriveDatabases(listed, { ...selection, scope: 'all' }, 'me').map(+ (entity) => entity.id+ )+ ).toEqual(['mine', 'shared']);+ });+ it('searches names without depending on the document search service', () => {+ expect(+ selectDriveDatabases(+ listed,+ { ...selection, search: ' PRODUCT ' },+ 'me'+ ).map((entity) => entity.id)+ ).toEqual(['mine']);+ expect(+ selectDriveDatabases(listed, { ...selection, search: 'customer' }, 'me')+ ).toEqual([]);+ });+ it('does not claim folder membership, attachment status or view history', () => {+ for (const selected of [+ {+ ...selection,+ location: { kind: 'folder', id: 'folder' },+ } satisfies DriveSelection,+ {+ ...selection,+ location: { kind: 'tab', tab: 'recent' },+ } satisfies DriveSelection,+ { ...selection, scope: 'attachments' } satisfies DriveSelection,+ ]) {+ expect(selectDriveDatabases(listed, selected, 'me')).toEqual([]);+ }+ expect(selectDriveDatabases(listed, selection, undefined)).toEqual([]);+ });+ it('preserves scope through the normalized list filter and sorts the available timestamp', () => {+ const selected = { ...selection, scope: 'all' } satisfies DriveSelection;+ const entities = selectDriveDatabases(listed, selected, 'me');+ expect(+ entities.every((entity) =>+ driveEntityMatchesLocation(entity, selected, 'me')+ )+ ).toBe(true);+ expect(+ orderDriveEntities(entities, selected, []).map((entity) => entity.id)+ ).toEqual(['shared', 'mine']);+ });+});++describe('disabled database filters', () => {+ it('masks a persisted Database choice while keeping other types and route intent', () => {+ const state = {+ ...selection,+ facets: { type: ['database', 'doc-markdown'], tags: ['urgent'] },+ expandedFolderIds: [],+ favoritesOpen: false,+ rootOpen: true,+ tagsOpen: false,+ };+ expect(availableDriveState(state, false).facets).toEqual({+ type: ['doc-markdown'],+ tags: ['urgent'],+ });+ expect(availableDriveState(state, true)).toBe(state);+ expect(state.facets.type).toEqual(['database', 'doc-markdown']);+ });+});diff --git a/apps/web/src/features/drive-view/queries/drive-databases.ts b/apps/web/src/features/drive-view/queries/drive-databases.tsnew file mode 100644index 0000000000..b931ed1f82--- /dev/null+++ b/apps/web/src/features/drive-view/queries/drive-databases.ts@@ -0,0 +1,39 @@+import type { DatabaseEntity } from '@entity';+import type { ListedDatabase } from '@service-storage/generated/schemas/listedDatabase';+import type { DriveSelection } from '../context/drive-source';++/** Databases have no folder membership or view history; list them in file tabs. */+export function selectDriveDatabases(+ listed: readonly ListedDatabase[],+ selection: DriveSelection,+ userId: string | undefined+): DatabaseEntity[] {+ const { location, scope } = selection;+ if (!userId || location.kind !== 'tab' || location.tab === 'recent')+ return [];+ if (scope === 'attachments') return [];++ const search = selection.search.trim().toLocaleLowerCase();+ return listed.flatMap(({ database, grant }) => {+ if (database.trashed_at) return [];+ if (location.tab === 'shared' && database.owner_id === userId) return [];+ if (+ location.tab === 'owned' &&+ scope === 'default' &&+ database.owner_id !== userId+ )+ return [];+ if (search && !database.name.toLocaleLowerCase().includes(search))+ return [];+ return [+ {+ type: 'database',+ id: database.id,+ name: database.name,+ ownerId: database.owner_id,+ createdAt: database.created_at,+ grant,+ },+ ];+ });+}diff --git a/apps/web/src/features/drive-view/queries/drive-results.ts b/apps/web/src/features/drive-view/queries/drive-results.tsindex 7f1219574b..90fe71c12b 100644--- a/apps/web/src/features/drive-view/queries/drive-results.ts+++ b/apps/web/src/features/drive-view/queries/drive-results.ts@@ -57,6 +57,17 @@ export function driveEntityMatchesLocation();}+ if (entity.type === 'database') {+ if (+ !userId ||+ location.tab === 'recent' ||+ selection.scope === 'attachments'+ )+ return false;+ if (location.tab === 'shared') return entity.ownerId !== userId;+ return selection.scope === 'all' || entity.ownerId === userId;+ }+if (entity.type !== 'document') return false;return documentMatchesTab(entity, location.tab, selection.scope, userId);@@ -74,6 +85,7 @@ export function orderDriveEntities(return [...entities];const timestamp = (entity: EntityData) => {+ if (entity.type === 'database') return entity.createdAt;if (sort === 'created_at') return entity.sortTs ?? entity.createdAt;if (sort === 'viewed_at') return entity.sortTs ?? entity.viewedAt;diff --git a/apps/web/src/features/drive-view/views/drive-list.tsx b/apps/web/src/features/drive-view/views/drive-list.tsxindex 66ae1f479a..6ab2bd484e 100644--- a/apps/web/src/features/drive-view/views/drive-list.tsx+++ b/apps/web/src/features/drive-view/views/drive-list.tsx@@ -65,6 +65,7 @@ export function DriveList() {const timestamp = (entity: EntityData) => {const { location, sort } = state.value();+ if (entity.type === 'database') return entity.createdAt;if (location.kind === 'tab' && location.tab === 'recent')return entity.touchedAt;@@ -263,6 +264,17 @@ export function DriveList() {tabIndex={0}class="@container/u-list relative flex size-full min-h-0 min-w-0 flex-col overflow-hidden outline-none">+ <Show when={source.databaseError()}>+ <div+ role="alert"+ class="flex shrink-0 items-center gap-2 border-b border-edge-muted p-3 text-xs text-ink-muted"+ >+ Databases couldn’t be loaded.+ <Button variant="outline" onClick={() => void refresh()}>+ Try again+ </Button>+ </div>+ </Show><ListLayoutProvider ref={grid}><Switch><Match when={!forceEmptyState() && showError()}>@@ -299,6 +311,14 @@ export function DriveList() {class="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 text-sm text-ink-muted"><span>{emptyMessage()}</span>+ <Show when={source.error()}>+ <Button+ variant="outline"+ onClick={() => void refresh()}+ >+ Try again+ </Button>+ </Show><Show when={hasFilters()}><Button variant="outline" onClick={state.clearFilters}>Clear filtersdiff --git a/apps/web/src/features/next-soup/actions/make-copy-action.ts b/apps/web/src/features/next-soup/actions/make-copy-action.tsindex 9ec6d2dafe..2f67fb74f6 100644--- a/apps/web/src/features/next-soup/actions/make-copy-action.ts+++ b/apps/web/src/features/next-soup/actions/make-copy-action.ts@@ -8,6 +8,7 @@ export const makeCopyAction = () => {const canExecute = (entity: EntityData): boolean => {return (+ entity.type !== 'database' &&entity.type !== 'agent_session' &&entity.type !== 'channel' &&entity.type !== 'email' &&diff --git a/apps/web/src/features/next-soup/actions/make-delete-action.ts b/apps/web/src/features/next-soup/actions/make-delete-action.tsindex cdcd6fea2b..7bf6799f62 100644--- a/apps/web/src/features/next-soup/actions/make-delete-action.ts+++ b/apps/web/src/features/next-soup/actions/make-delete-action.ts@@ -149,7 +149,11 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {};const canExecute = (entity: EntityData): boolean => {- if (entity.type === 'channel_message' || entity.type === 'channel_thread') {+ if (+ entity.type === 'database' ||+ entity.type === 'channel_message' ||+ entity.type === 'channel_thread'+ ) {return false;}if (entity.type === 'email') {diff --git a/apps/web/src/features/next-soup/actions/make-move-to-project-action.ts b/apps/web/src/features/next-soup/actions/make-move-to-project-action.tsindex 7befb2f08e..1437ef9dfe 100644--- a/apps/web/src/features/next-soup/actions/make-move-to-project-action.ts+++ b/apps/web/src/features/next-soup/actions/make-move-to-project-action.ts@@ -7,6 +7,7 @@ import type { EntityActionListState } from './entity-action-context';export const makeMoveToProjectAction = () => {const canExecute = (entity: EntityData): boolean => {return (+ entity.type !== 'database' &&entity.type !== 'agent_session' &&entity.type !== 'channel' &&entity.type !== 'channel_message' &&diff --git a/apps/web/src/features/next-soup/actions/make-rename-action.test.ts b/apps/web/src/features/next-soup/actions/make-rename-action.test.tsindex dffd00e912..0c12db00cc 100644--- a/apps/web/src/features/next-soup/actions/make-rename-action.test.ts+++ b/apps/web/src/features/next-soup/actions/make-rename-action.test.ts@@ -33,6 +33,10 @@ const channel = (const { canExecute } = makeRenameAction({ userId: () => ME });describe('makeRenameAction.canExecute', () => {+ it('leaves database renaming to the native database block', () => {+ expect(canExecute(entity('database', { grant: 'owner' }))).toBe(false);+ });+it('allows the owner of a private channel to rename it', () => {expect(canExecute(channel({ channelType: 'private', ownerId: ME }))).toBe(truediff --git a/apps/web/src/features/next-soup/actions/make-rename-action.ts b/apps/web/src/features/next-soup/actions/make-rename-action.tsindex 2979da5b92..5c9aed8693 100644--- a/apps/web/src/features/next-soup/actions/make-rename-action.ts+++ b/apps/web/src/features/next-soup/actions/make-rename-action.ts@@ -13,7 +13,7 @@ export const makeRenameAction = (options: MakeRenameOptions) => {const canExecute = (entity: EntityData): boolean => {if (entity.type === 'agent_session' && entity.isArchived) return false;- if (entity.type === 'email') return false;+ if (entity.type === 'email' || entity.type === 'database') return false;if (entity.type === 'channel_message' || entity.type === 'channel_thread') {return false;}diff --git a/apps/web/src/lib/core/context/quickAccess/QuickAccessSource.test.ts b/apps/web/src/lib/core/context/quickAccess/QuickAccessSource.test.tsindex 8d927e9d37..520095a49d 100644--- a/apps/web/src/lib/core/context/quickAccess/QuickAccessSource.test.ts+++ b/apps/web/src/lib/core/context/quickAccess/QuickAccessSource.test.ts@@ -16,6 +16,7 @@ import { INITIAL_CACHE_REVISION } from '@graphql-cache/index';import type { HydrationSearchChanges } from '@graphql-cache/protocol';import type { CachedGraphqlChannel } from '@queries/channel/graphql';import type { HistoryItem } from '@queries/history/types';+import type { ListedDatabase } from '@service-storage/generated/schemas/listedDatabase';import { render } from '@solidjs/testing-library';import {QueryClient,@@ -57,6 +58,7 @@ const mocks = vi.hoisted(() => ({companies: [] as CrmCompanyEntity[],crmContacts: [] as CrmContactEntity[],initiatives: [] as InitiativeEntity[],+ databases: [] as ListedDatabase[],crmEnabled: (): boolean => true,cacheEnabled: true,queries: {} as Partial<@@ -170,7 +172,7 @@ vi.mock('@queries/storage/instructions-md', () => ({useInstructionsMdIdQuery: () => ({ data: undefined }),}));vi.mock('@queries/storage/databases', () => ({- useDatabasesQuery: () => ({ data: [], isSuccess: true }),+ useDatabasesQuery: () => ({ data: mocks.databases, isSuccess: true }),}));vi.mock('@service-storage/util/filename', () => ({formatDocumentName: (name: string) => name,@@ -223,6 +225,7 @@ beforeEach(() => {mocks.companies = [];mocks.crmContacts = [];mocks.initiatives = [];+ mocks.databases = [];mocks.crmEnabled = () => true;mocks.cacheEnabled = true;mocks.queries = {};@@ -1299,3 +1302,33 @@ describe('CRM contacts', () => {expect(list.items()).toEqual([]);});});++describe('database command discovery', () => {+ it('merges Book Organizer into command search without any Soup history or cache hits', async () => {+ mocks.databases = [+ {+ database: {+ id: 'book-organizer',+ name: 'Book Organizer',+ owner_id: 'me',+ created_at: '2026-09-01T00:00:00Z',+ trashed_at: null,+ },+ grant: 'owner',+ tables: [],+ },+ ];+ const list = setup((source) =>+ source.useList({+ buckets: ['note', 'document', 'database'],+ searchTerm: () => 'Book Organizer',+ })+ );+ await vi.waitFor(() => expect(list.items()).toHaveLength(1));+ expect(list.items()[0]).toMatchObject({+ bucket: 'database',+ data: { type: 'database', name: 'Book Organizer' },+ });+ expect(mocks.history).toEqual([]);+ });+});diff --git a/apps/web/src/lib/queries/storage/database-discovery.test.ts b/apps/web/src/lib/queries/storage/database-discovery.test.tsnew file mode 100644index 0000000000..c45aa1cc01--- /dev/null+++ b/apps/web/src/lib/queries/storage/database-discovery.test.ts@@ -0,0 +1,56 @@+import { createRoot, createSignal } from 'solid-js';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { useDatabaseDiscoverySync } from './databases';+import { databasesKeys } from './keys';++const mocks = vi.hoisted(() => ({+ flag: (): boolean => true,+ invalidate: vi.fn(async () => {}),+}));+vi.mock('@app/lib/analytics', () => ({ analytics: {} }));+vi.mock('@app/lib/analytics/posthog', () => ({+ useFeatureFlag: () => () => ({ enabled: mocks.flag() }),+}));+vi.mock('@service-storage/client', () => ({ storageServiceClient: {} }));+vi.mock('@queries/client', () => ({+ queryClient: { invalidateQueries: mocks.invalidate },+}));++let dispose: (() => void) | undefined;+afterEach(() => {+ dispose?.();+ vi.clearAllMocks();+});+function setup() {+ return createRoot((cleanup) => {+ dispose = cleanup;+ const [active, setActive] = createSignal(false);+ const [enabled, setEnabled] = createSignal(true);+ mocks.flag = enabled;+ useDatabaseDiscoverySync(active);+ return { setActive, setEnabled };+ });+}++describe('database command discovery refresh', () => {+ it('refreshes the shared catalog on each opening, covering AI creation between openings', () => {+ const { setActive } = setup();+ expect(mocks.invalidate).not.toHaveBeenCalled();+ setActive(true);+ expect(mocks.invalidate).toHaveBeenCalledExactlyOnceWith({+ queryKey: databasesKeys.list.queryKey,+ });+ setActive(false);+ expect(mocks.invalidate).toHaveBeenCalledTimes(1);+ setActive(true);+ expect(mocks.invalidate).toHaveBeenCalledTimes(2);+ });+ it('does not refresh when databases are disabled and responds when the flag becomes available', () => {+ const { setActive, setEnabled } = setup();+ setEnabled(false);+ setActive(true);+ expect(mocks.invalidate).not.toHaveBeenCalled();+ setEnabled(true);+ expect(mocks.invalidate).toHaveBeenCalledOnce();+ });+});diff --git a/apps/web/src/lib/queries/storage/databases.ts b/apps/web/src/lib/queries/storage/databases.tsindex 417b153c84..a8f229140b 100644--- a/apps/web/src/lib/queries/storage/databases.ts+++ b/apps/web/src/lib/queries/storage/databases.ts@@ -17,7 +17,7 @@ import type { OpResult } from '@service-storage/generated/schemas/opResult';import type { UndoOutcome } from '@service-storage/generated/schemas/undoOutcome';import { useQueries, useQuery } from '@tanstack/solid-query';import { ResultAsync } from 'neverthrow';-import type { Accessor } from 'solid-js';+import { type Accessor, createEffect, on } from 'solid-js';import { match, P } from 'ts-pattern';import { queryClient } from '../client';import { databasesKeys } from './keys';@@ -39,6 +39,22 @@ export function useDatabasesQuery() {}));}+/** Re-read discovery when its surface opens, including databases created by AI or other clients. */+export function useDatabaseDiscoverySync(isActive: Accessor<boolean>) {+ const flag = useFeatureFlag(enableDatabases);+ createEffect(+ on(+ () => isActive() && flag().enabled,+ (active) => {+ if (!active) return;+ void queryClient.invalidateQueries({+ queryKey: databasesKeys.list.queryKey,+ });+ }+ )+ );+}+/** One database's schema; spread it and override what a read needs differently. */export function databaseDetailQueryOptions(id: string) {return {diff --git a/docs/AGENT_GUIDE/databases.md b/docs/AGENT_GUIDE/databases.mdindex 3bf4b20712..af96039431 100644--- a/docs/AGENT_GUIDE/databases.md+++ b/docs/AGENT_GUIDE/databases.md@@ -3,6 +3,10 @@Choose **Create → Database** to create a database and its first table with a Namecolumn. **C → L** opens a new database with its title selected and ready to type.Enter saves the title and focuses A1, ready to type without another click.+Opening **Ctrl-K** refreshes database discovery so a database created by AI or+another client appears without reloading. **All** and **Documents** categories+match its name, including databases with no view history.+Creating from Home immediately shows the table tabs, **New table**, **Databaseactions**, and **AI**; no reload is needed to use them.Databases open atdiff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex 90904942ef..6a00934f23 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -957,6 +957,19 @@ viewer identity is available, document inserts into Shared are rejected.Files opens **Drive** using the same shell as Tasks, on desktop and touchdevices alike.+With `enable-databases` enabled, **My Files** includes owned databases and+**Shared with me** includes databases shared by other owners. **All files**+also includes accessible databases owned by others. **Search Drive** matches+database names and **Filter → Type → Database** narrows the list. **New →+Database** creates and opens a database from file tabs or the folder overview;+it is absent inside a folder because databases have no folder membership yet.+Database rows open their database block, including Enter and Open in new split.+Use the database block's own actions to rename, share or trash it. The list+omits unsupported duplicate, delete and move-to-folder actions for databases.+Databases have no view history and do not appear in **Recent**, folder contents,+or **Email attachments**. Creation time orders them when the selected sort has+no corresponding database timestamp.+On touch devices (phones and tablets), the Drive header is a scrollable pillstrip — **Recent**, **My Files**, **Shared with me**, and **Folders** — with aleading filter-drawer button, like Tasks. Touch opens on **Recent** (the first