diff --git a/pkg/app/package.json b/pkg/app/package.json index 2963c70..fa9d532 100644 --- a/pkg/app/package.json +++ b/pkg/app/package.json @@ -1,6 +1,6 @@ { "name": "@hanzo/app", - "version": "0.3.114", + "version": "0.3.115", "description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.", "type": "module", "main": "./dist/index.js", diff --git a/pkg/app/src/Recents.test.ts b/pkg/app/src/Recents.test.ts index 0042dac..98306d2 100644 --- a/pkg/app/src/Recents.test.ts +++ b/pkg/app/src/Recents.test.ts @@ -2,7 +2,7 @@ import { createElement, type ReactNode } from 'react' import { renderToStaticMarkup } from 'react-dom/server' import { afterEach, describe, expect, test, vi } from 'vitest' -const { part, row, convMenu, presses, state, devState, capturedActions } = vi.hoisted(() => { +const { part, row, convMenu, presses, state, devState, capturedActions, marked } = vi.hoisted(() => { type Part = { children?: ReactNode; 'data-slot'?: string; 'aria-label'?: string; 'aria-expanded'?: boolean; active?: boolean } const presses: (() => void)[] = [] const state = { threads: [] as { id: string; title: string; updatedAt: string; pinned?: boolean }[] } @@ -10,15 +10,17 @@ const { part, row, convMenu, presses, state, devState, capturedActions } = vi.ho const capturedActions: { remove?: (t: { id: string; title?: string }) => Promise; rename?: (t: { id: string; title?: string }, next: string) => Promise }[] = [] const part = ({ children, 'data-slot': slot, 'aria-label': label, 'aria-expanded': expanded }: Part) => createElement('div', { 'data-slot': slot, 'aria-label': label, 'aria-expanded': expanded }, children) - const convMenu = ({ children, canShare, customActions }: { children?: ReactNode; canShare?: boolean; customActions?: typeof capturedActions[number] }) => { + const convMenu = ({ children, canShare, noun, customActions }: { children?: ReactNode; canShare?: boolean; noun?: string; customActions?: typeof capturedActions[number] }) => { if (customActions) capturedActions.push(customActions) - return createElement('div', { 'data-slot': 'conv-menu', 'data-share': String(Boolean(canShare)) }, children) + return createElement('div', { 'data-slot': 'conv-menu', 'data-share': String(Boolean(canShare)), 'data-noun': noun }, children) } + // What @hanzo/build's run marks store was asked to keep, by run id. + const marked: Record> = {} const row = ({ children, active, onPress }: Part & { onPress?: () => void }) => { if (onPress) presses.push(onPress) return createElement('div', { 'data-slot': 'row', 'aria-current': active ? 'page' : undefined }, children) } - return { part, row, convMenu, presses, state, devState, capturedActions } + return { part, row, convMenu, presses, state, devState, capturedActions, marked } }) vi.mock('@hanzo/i18n/react', () => ({ useI18n: () => ({ t: (s: string) => s, dir: 'ltr' }) })) @@ -28,6 +30,7 @@ vi.mock('@hanzo/build', () => ({ DOTS: { running: 'running', done: 'done', error: 'error' }, route: () => ({ kind: 'new' }), useSessions: () => ({ value: devState.sessions, loading: false, error: null, reload: () => {} }), + useRunMarks: () => [marked, (id: string, patch: Record) => void (marked[id] = { ...marked[id], ...patch })], })) vi.mock('@hanzo/ui', () => ({ DropdownMenu: ({ items }: { items: { key: string }[] }) => createElement('div', { 'data-slot': 'menu' }, items.map((i) => createElement('span', { key: i.key, 'data-item': i.key }))), @@ -59,6 +62,7 @@ afterEach(() => { state.threads = [] devState.sessions = [] capturedActions.length = 0 + for (const k of Object.keys(marked)) delete marked[k] vi.unstubAllGlobals() vi.doUnmock('@hanzo/studio') }) @@ -80,7 +84,7 @@ describe('Design’s Recents & collapsible Pinned section', () => { // First Build: a row wears its age, and a dot only while it works or when it failed; the settled Logo has none. expect(html.match(/data-dot="[a-z]+"/g)).toEqual(['data-dot="running"', 'data-dot="error"']) // Design conversations now have full ConversationMenu + Select multiple, with Chat-only Share disabled. - expect(html).toContain('data-slot="conv-menu" data-share="false"') + expect(html).toContain('data-slot="conv-menu" data-share="false" data-noun="design"') expect(html).toContain('select-multiple') expect(html).not.toContain('data-item="status-') expect(html).not.toContain('No chats yet.') @@ -96,7 +100,7 @@ describe('Design’s Recents & collapsible Pinned section', () => { const { Recents } = await import('./Recents') const html = renderToStaticMarkup(createElement(Recents, { host: {} as never, mode: 'chat', thread: null, onOpen: () => {}, onNew: () => {} })) expect(html).toContain('data-slot="pinned-group-toggle"') - expect(html).toContain('data-slot="conv-menu" data-share="true"') + expect(html).toContain('data-slot="conv-menu" data-share="true" data-noun="chat"') expect(html.indexOf('Pinned strategy')).toBeLessThan(html.indexOf('Daily notes')) }) @@ -144,4 +148,41 @@ describe('Design’s Recents & collapsible Pinned section', () => { }, ]) }) + + test('a Dev run’s menu calls it a run, and its archive, pin and delete go to the store a run’s own menu writes (@hanzo/build)', async () => { + vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, status: 200 }))) + devState.sessions = [{ id: 'sess_a', title: 'Add a checkout page', status: 'done', createdAt: new Date(now - 60_000).toISOString() }] + const { Recents } = await import('./Recents') + const host = { api: 'https://api.hanzo.ai', org: 'acme', token: () => 'tok', path: '', go: () => {} } as never + const html = renderToStaticMarkup(createElement(Recents, { host, mode: 'dev', thread: null, onOpen: () => {}, onNew: () => {} })) + expect(html).toContain('data-noun="run"') + const act = capturedActions[0] as unknown as { + archive: (t: { id: string; archived?: boolean }) => Promise + pin: (t: { id: string; pinned?: boolean }) => Promise + remove: (t: { id: string }) => Promise + } + await act.archive({ id: 'sess_a', archived: false }) + await act.pin({ id: 'sess_a', pinned: false }) + expect(marked.sess_a).toEqual({ archived: true, pinned: true }) + await act.archive({ id: 'sess_a', archived: true }) + expect(marked.sess_a).toMatchObject({ archived: false }) + await act.remove({ id: 'sess_a' }) + expect(marked.sess_a).toMatchObject({ deleted: true }) + }) + + test('a run archived from its own page is out of the Recents list, and one deleted there too', async () => { + devState.sessions = [ + { id: 'sess_keep', title: 'Fix the footer', status: 'done', createdAt: new Date(now - 60_000).toISOString() }, + { id: 'sess_arch', title: 'Old experiment', status: 'done', createdAt: new Date(now - 120_000).toISOString() }, + { id: 'sess_gone', title: 'Wrong turn', status: 'done', createdAt: new Date(now - 180_000).toISOString() }, + ] + marked.sess_arch = { archived: true } + marked.sess_gone = { deleted: true } + const { Recents } = await import('./Recents') + const host = { api: 'https://api.hanzo.ai', org: 'acme', token: () => 'tok', path: '', go: () => {} } as never + const html = renderToStaticMarkup(createElement(Recents, { host, mode: 'dev', thread: null, onOpen: () => {}, onNew: () => {} })) + expect(html).toContain('Fix the footer') + expect(html).not.toContain('Old experiment') + expect(html).not.toContain('Wrong turn') + }) }) diff --git a/pkg/app/src/Recents.tsx b/pkg/app/src/Recents.tsx index 489151b..2d8b5a9 100644 --- a/pkg/app/src/Recents.tsx +++ b/pkg/app/src/Recents.tsx @@ -14,7 +14,7 @@ import { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'rea import { ScrollView, SizableText, XStack, YStack } from '@hanzo/gui' import { CheckSquare, ChevronDown, ChevronRight, GitPullRequest, ListFilter } from 'lucide-react' import type { Thread } from '@hanzo/ai' -import { DOTS, route, useSessions, type Host } from '@hanzo/build' +import { DOTS, route, useRunMarks, useSessions, type Host } from '@hanzo/build' import * as studio from '@hanzo/studio' import { DropdownMenu, type DropdownMenuProps } from '@hanzo/ui' import { SidebarItem, StatusDot } from '@hanzo/ui/chat' @@ -268,22 +268,10 @@ function Chats({ ) } -type RunMeta = { title?: string; pinned?: boolean; archived?: boolean; deleted?: boolean } - -/** Dev's Recents: the org's coding runs alone. */ +/** Dev's Recents: the org's coding runs alone. What a person did to a run (pinned, archived, deleted, renamed) is @hanzo/build's store, the one a run's own menu writes too. */ function Runs({ host, view, keep, onOpen }: { host: Host; view: View; keep: (v: View) => void; onOpen: (r: Recent) => void }) { const store = useSessions(host) - const [meta, setMeta] = useKept>('hanzo.dev.runs.meta', {}) - const metaRef = useRef(meta) - metaRef.current = meta - const patchMeta = (id: string, patch: Partial) => { - const next = { - ...(metaRef.current ?? {}), - [id]: { ...(metaRef.current?.[id] ?? {}), ...patch }, - } - metaRef.current = next - setMeta(next) - } + const [meta, patchMeta] = useRunMarks() const r = route(host.path) const run = r.kind === 'run' ? r.id : null // A run this list has not seen is one just begun: read the store again, once for it. @@ -617,6 +605,7 @@ function List({ onGone={onNew} customActions={customActions} canShare={mode === 'chat'} + noun={mode === 'dev' ? 'run' : mode === 'design' ? 'design' : 'chat'} hrefOf={hrefOf} primary={primary} > diff --git a/pkg/app/src/Search.test.ts b/pkg/app/src/Search.test.ts index 0b1cd1a..28b1995 100644 --- a/pkg/app/src/Search.test.ts +++ b/pkg/app/src/Search.test.ts @@ -27,6 +27,7 @@ vi.mock('@hanzo/build', async () => { path, // As @hanzo/build's reads it: the host's api, token, org and person, at once. useSessions: (h: { api: string; person: unknown }) => (asked.push(h), h.api, Boolean(h.person), { value: [] }), + useRunMarks: () => [{}, () => {}], nav: (_: unknown, go: Go) => [ { id: 'work', label: 'Work', links: [link(go, 'new', 'New run', ''), link(go, 'projects', 'Projects', path({ kind: 'screen', screen: 'projects' }))] }, { id: 'run', label: 'Run', links: [settings(go, 'machines', 'Machines')] }, diff --git a/pkg/app/src/Sidebar.test.ts b/pkg/app/src/Sidebar.test.ts index 49d1fbb..e001119 100644 --- a/pkg/app/src/Sidebar.test.ts +++ b/pkg/app/src/Sidebar.test.ts @@ -79,6 +79,7 @@ vi.mock('@hanzo/build', () => { Rename: () => null, route, useSessions: () => ({ value: [], loading: false, error: null, reload: () => {} }), + useRunMarks: () => [{}, () => {}], useLanguage: () => ['', () => {}] as const, NEW: 'new', own: () => [group('work', 'Work', ['New run', 'Projects', 'Issues', 'Templates'])], diff --git a/pkg/app/src/thread.tsx b/pkg/app/src/thread.tsx index 2f6281c..369636c 100644 --- a/pkg/app/src/thread.tsx +++ b/pkg/app/src/thread.tsx @@ -216,8 +216,13 @@ const mac = (): boolean => typeof navigator !== 'undefined' && /Mac|iPhone|iPad| type Dialogue = 'rename' | 'delete' | 'share' | 'organize' +/** What a list holds: a conversation, a Dev run or a design. The menu says it in that word wherever it names one. */ +export type Noun = 'chat' | 'run' | 'design' + /** What a row needs of the list's menu. */ interface Menus { + /** What the list holds, for the words on a row's own ⋯. */ + noun: Noun /** This menu's own id: its rows carry it (`data-menu-of`), so the keys find the rows of the list whose menu is open. */ list: string /** The conversation the ⋯ that was just pressed belongs to, and the ⋯. */ @@ -331,8 +336,10 @@ export function ConversationMenu({ canShare = !customActions, hrefOf = href, primary = true, + noun = 'chat', children, }: { + noun?: Noun threads: Map active?: string | null onGone?: () => void @@ -500,7 +507,9 @@ export function ConversationMenu({ if (!allArchived) { const snapshots = succeeded.map((th) => ({ ...th, archived: true })) toast( - snapshots.length === 1 ? t('Archived chat') : t('Archived {n} chats', { n: snapshots.length }), + snapshots.length === 1 + ? noun === 'run' ? t('Archived run') : noun === 'design' ? t('Archived design') : t('Archived chat') + : noun === 'run' ? t('Archived {n} runs', { n: snapshots.length }) : noun === 'design' ? t('Archived {n} designs', { n: snapshots.length }) : t('Archived {n} chats', { n: snapshots.length }), { duration: 5000, action: { @@ -513,12 +522,14 @@ export function ConversationMenu({ ) } else { toast.success( - succeeded.length === 1 ? t('Unarchived chat') : t('Unarchived {n} chats', { n: succeeded.length }), + succeeded.length === 1 + ? noun === 'run' ? t('Unarchived run') : noun === 'design' ? t('Unarchived design') : t('Unarchived chat') + : noun === 'run' ? t('Unarchived {n} runs', { n: succeeded.length }) : noun === 'design' ? t('Unarchived {n} designs', { n: succeeded.length }) : t('Unarchived {n} chats', { n: succeeded.length }), ) } }) }, - [act, t], + [act, t, noun], ) const batchPin = useCallback( @@ -668,6 +679,7 @@ export function ConversationMenu({ const rows = useMemo( () => ({ + noun, list, aim, open: menu ? aimed : null, @@ -687,7 +699,7 @@ export function ConversationMenu({ clearSelect, hrefOf, }), - [list, aim, menu, aimed, renaming, commitRename, cancelRename, selected, selecting, active, selectRange, toggleSelect, clearSelect, hrefOf], + [noun, list, aim, menu, aimed, renaming, commitRename, cancelRename, selected, selecting, active, selectRange, toggleSelect, clearSelect, hrefOf], ) // The menu is named by its conversation: gui would name it by its trigger, the @@ -978,6 +990,7 @@ export function ConversationMenu({ ) : null} void @@ -1398,12 +1414,12 @@ function Rename({ return ( - {t('Rename chat')} + {noun === 'run' ? t('Rename run') : noun === 'design' ? t('Rename design') : t('Rename chat')} void @@ -1463,11 +1481,15 @@ function Delete({ return ( - {t('Delete chat?')} + {noun === 'run' ? t('Delete run?') : noun === 'design' ? t('Delete design?') : t('Delete chat?')} - {t('“{title}” is deleted for good, with every link it was shared by. To keep it out of the list instead, archive it.', { - title: thread ? titleOf(thread, t('Untitled')) : '', - })} + {noun === 'design' + ? t('“{title}” is deleted for good. To keep it out of the list instead, archive it.', { + title: thread ? titleOf(thread, t('Untitled')) : '', + }) + : t('“{title}” is deleted for good, with every link it was shared by. To keep it out of the list instead, archive it.', { + title: thread ? titleOf(thread, t('Untitled')) : '', + })}