Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
53 changes: 47 additions & 6 deletions pkg/app/src/Recents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ 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 }[] }
const devState = { sessions: [] as { id: string; title: string; status: string; createdAt: string }[] }
const capturedActions: { remove?: (t: { id: string; title?: string }) => Promise<boolean>; rename?: (t: { id: string; title?: string }, next: string) => Promise<boolean> }[] = []
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<string, Record<string, unknown>> = {}
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' }) }))
Expand All @@ -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<string, unknown>) => 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 }))),
Expand Down Expand Up @@ -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')
})
Expand All @@ -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.')
Expand All @@ -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'))
})

Expand Down Expand Up @@ -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<boolean>
pin: (t: { id: string; pinned?: boolean }) => Promise<boolean>
remove: (t: { id: string }) => Promise<boolean>
}
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')
})
})
19 changes: 4 additions & 15 deletions pkg/app/src/Recents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<Record<string, RunMeta>>('hanzo.dev.runs.meta', {})
const metaRef = useRef(meta)
metaRef.current = meta
const patchMeta = (id: string, patch: Partial<RunMeta>) => {
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.
Expand Down Expand Up @@ -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}
>
Expand Down
1 change: 1 addition & 0 deletions pkg/app/src/Search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')] },
Expand Down
1 change: 1 addition & 0 deletions pkg/app/src/Sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])],
Expand Down
44 changes: 33 additions & 11 deletions pkg/app/src/thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ⋯. */
Expand Down Expand Up @@ -331,8 +336,10 @@ export function ConversationMenu({
canShare = !customActions,
hrefOf = href,
primary = true,
noun = 'chat',
children,
}: {
noun?: Noun
threads: Map<string, Thread>
active?: string | null
onGone?: () => void
Expand Down Expand Up @@ -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: {
Expand All @@ -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(
Expand Down Expand Up @@ -668,6 +679,7 @@ export function ConversationMenu({

const rows = useMemo<Menus>(
() => ({
noun,
list,
aim,
open: menu ? aimed : null,
Expand All @@ -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
Expand Down Expand Up @@ -978,6 +990,7 @@ export function ConversationMenu({
</YStack>
) : null}
<Rename
noun={noun}
t={subject}
open={dialogue === 'rename'}
onOpenChange={shut}
Expand All @@ -987,6 +1000,7 @@ export function ConversationMenu({
}}
/>
<Delete
noun={noun}
t={subject}
open={dialogue === 'delete'}
onOpenChange={shut}
Expand Down Expand Up @@ -1285,7 +1299,7 @@ export function ThreadRow({
render="button"
// Named for what it is, not for the row: the row's own name is its title,
// and a second button named with that title would answer for it too.
aria-label={t('Chat options')}
aria-label={menus.noun === 'run' ? t('Run options') : menus.noun === 'design' ? t('Design options') : t('Chat options')}
aria-describedby={about}
id={id}
data-slot="thread-options"
Expand Down Expand Up @@ -1368,12 +1382,14 @@ export function ThreadMore({ t: thread }: { t: Thread }) {

/** A conversation's title, written again: one line, never empty. */
function Rename({
noun,
t: thread,
open,
onOpenChange,
onCloseAutoFocus,
save,
}: {
noun: Noun
t: Thread | null
open: boolean
onOpenChange: (open: boolean) => void
Expand All @@ -1398,12 +1414,12 @@ function Rename({
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent maxW={440} width="calc(100vw - 24px)" rounded="$6" gap="$3" onCloseAutoFocus={onCloseAutoFocus}>
<DialogTitle>{t('Rename chat')}</DialogTitle>
<DialogTitle>{noun === 'run' ? t('Rename run') : noun === 'design' ? t('Rename design') : t('Rename chat')}</DialogTitle>
<Input
autoFocus
value={words}
onChangeText={setWords}
aria-label={t('Chat title')}
aria-label={noun === 'run' ? t('Run title') : noun === 'design' ? t('Design title') : t('Chat title')}
borderColor="var(--border-strong)"
focusVisibleStyle={{ outlineWidth: 2, outlineStyle: 'solid', outlineColor: 'var(--ring)' }}
$max-sm={{ minH: 44 }}
Expand Down Expand Up @@ -1447,12 +1463,14 @@ function Rename({

/** Deleting asks first, and says what goes with it: every turn, and every link it was shared by. */
function Delete({
noun,
t: thread,
open,
onOpenChange,
onCloseAutoFocus,
remove,
}: {
noun: Noun
t: Thread | null
open: boolean
onOpenChange: (open: boolean) => void
Expand All @@ -1463,11 +1481,15 @@ function Delete({
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent maxW={440} width="calc(100vw - 24px)" rounded="$6" gap="$3" onCloseAutoFocus={onCloseAutoFocus}>
<DialogTitle>{t('Delete chat?')}</DialogTitle>
<DialogTitle>{noun === 'run' ? t('Delete run?') : noun === 'design' ? t('Delete design?') : t('Delete chat?')}</DialogTitle>
<SizableText size="$2" color="$soft">
{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')) : '',
})}
</SizableText>
<XStack gap="$2" justify="flex-end" flexWrap="wrap">
<Button
Expand Down
Loading