From 338e5bd450c5d7d04de2f189b51bcfeb1fb96290 Mon Sep 17 00:00:00 2001 From: James <279246542+jamessburnss1313-dev@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:13:34 +0000 Subject: [PATCH 01/19] Add Developer mode and plain device names (Local - Device, Auto (Cloud)) --- package.json | 5 ++ src/api/devices.test.ts | 28 ++++++ src/api/machines.ts | 30 ++++++- src/api/places.ts | 32 +++++-- src/dev-mode.test.ts | 53 ++++++++++++ src/dev-mode.ts | 135 +++++++++++++++++++++++++++++ src/environment.tsx | 14 +-- src/settings/machines.tsx | 177 +++++++++++++++++++++++++++----------- 8 files changed, 407 insertions(+), 67 deletions(-) create mode 100644 src/api/devices.test.ts create mode 100644 src/dev-mode.test.ts create mode 100644 src/dev-mode.ts diff --git a/package.json b/package.json index cee2051..4238aa4 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,11 @@ "import": "./lib/mind.js", "default": "./lib/mind.js" }, + "./dev-mode": { + "types": "./lib/dev-mode.d.ts", + "import": "./lib/dev-mode.js", + "default": "./lib/dev-mode.js" + }, "./package.json": "./package.json" }, "files": [ diff --git a/src/api/devices.test.ts b/src/api/devices.test.ts new file mode 100644 index 0000000..0fa152d --- /dev/null +++ b/src/api/devices.test.ts @@ -0,0 +1,28 @@ +import { describe, expect, it } from 'vitest' + +import { displayMachine, machine } from './machines.ts' +import { displayPlace, SANDBOX } from './places.ts' + +describe('device names a person reads', () => { + it('names a laptop Local - Device in Simple mode and keeps its hardware as the detail', () => { + const m = machine({ + id: 'tgt_1', + label: 'MacBook-Pro.local', + kind: 'laptop', + host: 'MacBook-Pro.local', + status: 'online', + metricsAt: '2026-10-04T06:00:00Z', + spec: { os: 'darwin', arch: 'arm64', cpus: 16, memory: 64 * 1024 * 1024 * 1024, gpus: [{ model: 'Apple M2' }] }, + }) + expect(displayMachine(m, { devMode: false })).toEqual({ title: 'Local - Device', detail: 'Apple M2 · 64 GB · MacBook-Pro.local' }) + expect(displayMachine(m, { devMode: true }).title).toBe('MacBook-Pro.local') + }) + + it('names the cloud workspace Auto (Cloud), or Cloud for a developer', () => { + expect(displayPlace(SANDBOX, { devMode: false })).toEqual({ + title: 'Auto (Cloud)', + detail: 'Runs automatically in your Hanzo cloud workspace', + }) + expect(displayPlace(SANDBOX, { devMode: true }).title).toBe('Cloud') + }) +}) diff --git a/src/api/machines.ts b/src/api/machines.ts index a7ab5a7..ba5c098 100644 --- a/src/api/machines.ts +++ b/src/api/machines.ts @@ -15,6 +15,7 @@ */ import { phrase } from '@hanzo/i18n' +import { formatDeviceLabel } from '../dev-mode.ts' import { call, Refusal, seg, type Target } from './call.ts' export const KINDS = ['laptop', 'gpu', 'cloud', 'cluster', 'machine'] as const @@ -119,17 +120,38 @@ export function formatRelative(isoDate?: string): string { export function specSummary(m: Machine): string { if (m.spec) { const parts: string[] = [] - if (m.spec.cpus) parts.push(`${m.spec.cpus} vCPU`) - if (m.spec.memory) parts.push(formatBytes(m.spec.memory)) if (m.spec.gpus && m.spec.gpus.length > 0) { - const g = m.spec.gpus[0] - parts.push(`${m.spec.gpus.length}× ${g.model || g.vendor || 'GPU'}${g.memory ? ` (${formatBytes(g.memory)})` : ''}`) + const g = m.spec.gpus[0]! + const gpuLabel = g.model || g.vendor || 'GPU' + parts.push(m.spec.gpus.length > 1 ? `${m.spec.gpus.length}× ${gpuLabel}` : gpuLabel) + } else if (m.spec.cpus) { + parts.push(`${m.spec.cpus} vCPU`) } + if (m.spec.memory) parts.push(formatBytes(m.spec.memory)) if (parts.length > 0) return parts.join(' · ') } return m.capacity || '' } +function hardwareSummary(m: Machine): string { + const hw = specSummary(m) + const host = m.host && m.host !== hw ? m.host : '' + return [hw, host].filter(Boolean).join(' · ') +} + +export function displayMachine( + m: Machine, + opts?: { devMode?: boolean }, +): { title: string; detail?: string } { + return formatDeviceLabel(m.label, { + kind: m.kind, + os: m.spec?.os, + hardware: hardwareSummary(m), + host: m.host, + devMode: opts?.devMode, + }) +} + export function machine(raw: unknown): Machine { const o = (raw && typeof raw === 'object' ? raw : {}) as Record const specObj = obj(o.spec) diff --git a/src/api/places.ts b/src/api/places.ts index dc9e0da..23b39e6 100644 --- a/src/api/places.ts +++ b/src/api/places.ts @@ -1,36 +1,54 @@ /** - * Where a run can run: the platform's sandbox, or one of the org's machines. + * Where a run can run: the platform's cloud workspace, or one of the org's machines. * * GET /v1/agent/targets → {targets: [...]}, newest first (machines.ts) * - * The sandbox is not a row the platform lists — it is what a run gets when it + * The cloud workspace is not a row the platform lists — it is what a run gets when it * names no target — so it is the first place here and carries no id. A machine * can take a run only while it is online. */ import { phrase } from '@hanzo/i18n' +import { formatDeviceLabel } from '../dev-mode.ts' import type { Target } from './call.ts' import { machines, state } from './machines.ts' export interface Place { - /** `tgt_…`, or '' for the sandbox. */ + /** `tgt_…`, or '' for the cloud workspace. */ id: string label: string - /** laptop | gpu | cloud | … as the platform names it; 'sandbox' for the sandbox. */ + /** laptop | gpu | cloud | … as the platform names it; 'sandbox' for the cloud workspace. */ kind: string - /** online | offline | draining | not seen yet, as machines.ts `state` reads it; the sandbox is always online. */ + /** online | offline | draining | not seen yet, as machines.ts `state` reads it; the cloud workspace is always online. */ status: string /** "10 vCPU / 122G / 1× GB10", when the machine reported one. */ capacity: string } -/** The sandbox, named in English and marked (`phrase`): a screen draws its label through `t`. */ -export const SANDBOX: Place = { id: '', label: phrase('Hanzo sandbox'), kind: 'sandbox', status: 'online', capacity: '' } +/** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */ +export const SANDBOX: Place = { id: '', label: phrase('Cloud workspace'), kind: 'sandbox', status: 'online', capacity: '' } export async function places(t: Target): Promise { const list = await machines(t) return [SANDBOX, ...list.map((m) => ({ id: m.id, label: m.label, kind: m.kind, status: state(m), capacity: m.capacity }))] } +export function displayPlace( + p: Place, + opts?: { devMode?: boolean; cloudTitle?: string }, +): { title: string; detail?: string } { + if (!p.id) { + return { + title: opts?.devMode ? 'Cloud' : (opts?.cloudTitle ?? 'Auto (Cloud)'), + detail: 'Runs automatically in your Hanzo cloud workspace', + } + } + return formatDeviceLabel(p.label, { + kind: p.kind, + hardware: p.capacity, + devMode: opts?.devMode, + }) +} + /** Whether a run sent here now would be taken. */ export const ready = (p: Place): boolean => p.status === 'online' diff --git a/src/dev-mode.test.ts b/src/dev-mode.test.ts new file mode 100644 index 0000000..70a7285 --- /dev/null +++ b/src/dev-mode.test.ts @@ -0,0 +1,53 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' + +import { DEV_MODE_EVENT, DEV_MODE_KEY, formatDeviceLabel, getDevMode, setDevMode } from './dev-mode.ts' + +afterEach(() => vi.unstubAllGlobals()) + +describe('Developer mode and friendly device labels', () => { + it('syncs hanzo.dev_mode via localStorage and hanzo:dev-mode event', () => { + const store = new Map() + const events: string[] = [] + const target = new EventTarget() + vi.stubGlobal('window', { + localStorage: { + getItem: (k: string) => store.get(k) ?? null, + setItem: (k: string, v: string) => void store.set(k, v), + }, + addEventListener: target.addEventListener.bind(target), + removeEventListener: target.removeEventListener.bind(target), + dispatchEvent: (e: Event) => { + events.push(e.type) + return target.dispatchEvent(e) + }, + }) + expect(getDevMode()).toBe(false) + setDevMode(true) + expect(store.get(DEV_MODE_KEY)).toBe('true') + expect(events).toContain(DEV_MODE_EVENT) + expect(getDevMode()).toBe(true) + }) + + it('formats technical machine strings into neutral Local - Device labels in Simple Mode and preserves hardware detail', () => { + expect(formatDeviceLabel('MacBook-Pro.local · 16 vCPU / 64G', { devMode: false })).toEqual({ + title: 'Local - Device', + detail: 'MacBook-Pro.local · 16 vCPU / 64G', + }) + expect(formatDeviceLabel('MacBook GPU M2', { devMode: false })).toEqual({ + title: 'Local - Device', + detail: 'MacBook GPU M2', + }) + expect(formatDeviceLabel('workstation.local (shell-1)', { devMode: false })).toEqual({ + title: 'Local - Device', + detail: 'workstation.local (shell-1)', + }) + expect(formatDeviceLabel('cloud-1 · shell-1', { devMode: false })).toEqual({ + title: 'Cloud workspace', + detail: 'cloud-1 · shell-1', + }) + expect(formatDeviceLabel('Hanzo sandbox', { devMode: false })).toEqual({ + title: 'Cloud workspace', + detail: 'Managed Hanzo cloud workspace', + }) + }) +}) diff --git a/src/dev-mode.ts b/src/dev-mode.ts new file mode 100644 index 0000000..7e35b75 --- /dev/null +++ b/src/dev-mode.ts @@ -0,0 +1,135 @@ +import { useCallback, useSyncExternalStore } from 'react' + +export const DEV_MODE_KEY = 'hanzo.dev_mode' +export const DEV_MODE_EVENT = 'hanzo:dev-mode' + +export function getDevMode(): boolean { + if (typeof window === 'undefined') return false + try { + return window.localStorage.getItem(DEV_MODE_KEY) === 'true' + } catch { + return false + } +} + +export function setDevMode(next: boolean): void { + if (typeof window === 'undefined') return + try { + window.localStorage.setItem(DEV_MODE_KEY, next ? 'true' : 'false') + } catch { + /* ignore storage errors */ + } + window.dispatchEvent(new CustomEvent(DEV_MODE_EVENT, { detail: { enabled: next } })) +} + +function subscribeDevMode(onChange: () => void): () => void { + if (typeof window === 'undefined') return () => {} + const handler = () => onChange() + const onStorage = (e: StorageEvent) => { + if (e.key === DEV_MODE_KEY) onChange() + } + window.addEventListener(DEV_MODE_EVENT, handler) + window.addEventListener('storage', onStorage) + return () => { + window.removeEventListener(DEV_MODE_EVENT, handler) + window.removeEventListener('storage', onStorage) + } +} + +export function useDevMode(): [boolean, (next: boolean) => void] { + const enabled = useSyncExternalStore(subscribeDevMode, getDevMode, () => false) + const update = useCallback((next: boolean) => setDevMode(next), []) + return [enabled, update] +} + +export interface DeviceLabelOptions { + kind?: string | null + os?: string | null + hardware?: string | null + host?: string | null + cloudTitle?: string + devMode?: boolean +} + +function mergeDetail(...parts: (string | null | undefined)[]): string | undefined { + const seen = new Set() + const out: string[] = [] + for (const p of parts) { + const clean = (p ?? '').trim() + if (!clean) continue + for (const seg of clean.split(/\s*·\s*/)) { + const s = seg.trim() + if (!s) continue + const key = s.toLowerCase() + if (!seen.has(key)) { + seen.add(key) + out.push(s) + } + } + } + return out.length ? out.join(' · ') : undefined +} + +export function formatDeviceLabel( + raw: string | null | undefined, + opts: DeviceLabelOptions = {}, +): { title: string; detail?: string } { + const cleanRaw = (raw ?? '').trim() + const cloudFallback = opts.cloudTitle ?? 'Cloud workspace' + if (!cleanRaw) { + return { title: opts.devMode ? 'Cloud' : cloudFallback } + } + if (opts.devMode) { + return { + title: cleanRaw, + detail: mergeDetail(opts.hardware, opts.host && opts.host !== cleanRaw ? opts.host : undefined), + } + } + + const lower = cleanRaw.toLowerCase() + + if ( + lower === 'hanzo sandbox' || + lower === 'sandbox' || + lower === 'cloud' || + lower === 'cloud workspace' || + /^cloud(-\d+)?(\b|\s|·)/.test(lower) + ) { + return { + title: cloudFallback, + detail: + lower === 'cloud' || lower === 'cloud workspace' || lower === 'hanzo sandbox' || lower === 'sandbox' + ? 'Managed Hanzo cloud workspace' + : cleanRaw, + } + } + + const basePart = cleanRaw + .split(/\s*·\s*/)[0]! + .replace(/\s*\((?:shell|desk|tmux|tty)[^)]*\)\s*$/i, '') + .replace(/\.(local|lan|home|internal)$/i, '') + .replace(/-\d+$/, '') + .trim() + + const combinedHint = `${cleanRaw} ${opts.host ?? ''} ${opts.hardware ?? ''}` + + if ( + /macbook|\bmbp\b|\bmba\b|\b(imac|mac-studio|mac-mini|mac|laptop|desktop|workstation|localhost|local)\b/i.test(combinedHint) || + opts.os === 'darwin' || + opts.kind === 'laptop' || + opts.kind === 'desktop' || + /^tgt_[a-z0-9]+$/i.test(basePart) + ) { + const title = 'Local - Device' + const detail = mergeDetail(opts.hardware, opts.host, cleanRaw !== title ? cleanRaw : undefined) + return { title, detail } + } + + const humanized = basePart + .replace(/[-_]+/g, ' ') + .trim() + + const title = humanized ? `Local - ${humanized}` : 'Local - Device' + const detail = mergeDetail(opts.hardware, opts.host, cleanRaw !== title ? cleanRaw : undefined) + return { title, detail } +} diff --git a/src/environment.tsx b/src/environment.tsx index 03f7db6..cb9eeb4 100644 --- a/src/environment.tsx +++ b/src/environment.tsx @@ -48,16 +48,16 @@ export function Environment({ repo, busy }: { repo: string; busy: boolean }) { }, [shown]) if (!signed) { - return {t('Sign in to see this codebase’s environment.')} + return {t('Sign in to view project environment settings.')} } if (!repo) { - return {t('This run has no codebase, so it has no environment.')} + return {t('This session uses an automatic workspace — no custom setup needed.')} } if (env.error) { return {t('{repo}’s environment could not be read right now.', { repo })} } if (!shown) { - return {t('Reading the environment…')} + return {t('Loading environment…')} } const changed = install !== shown.install || startCmd !== shown.start || shown.proposal !== null @@ -345,20 +345,20 @@ export function SetupDialog({ {homes.loading && !list.length ? ( - {t('Reading the repositories…')} + {t('Loading projects…')} ) : homes.error && !list.length ? ( - {t('The repository list could not be read right now.')} + {t('The project list could not be loaded right now.')} ) : shown.length === 0 ? ( - {list.length ? t('Nothing matches.') : t('This organization has no repositories on the forge yet.')} + {list.length ? t('Nothing matches.') : t('No projects linked yet — start a prompt to create one automatically, or link a GitHub repository.')} ) : ( shown.map((h) => { diff --git a/src/settings/machines.tsx b/src/settings/machines.tsx index 0cabaa5..1d687ab 100644 --- a/src/settings/machines.tsx +++ b/src/settings/machines.tsx @@ -18,6 +18,7 @@ import { Cloud, Cpu, HardDrive, + Info, Laptop, MoreHorizontal, Plus, @@ -25,7 +26,7 @@ import { Terminal, Zap, } from '@hanzogui/lucide-icons-2' -import { Button, Dialog, DialogContent, DialogTitle, DropdownMenu, Input } from '@hanzo/ui' +import { Button, Dialog, DialogContent, DialogTitle, DropdownMenu, Input, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@hanzo/ui' import { CopyButton } from '@hanzo/ui/product' import { useEffect, useState } from 'react' @@ -33,6 +34,7 @@ import { told } from '../api/call.ts' import { add, change, + displayMachine, formatBytes, formatPercent, formatRelative, @@ -46,11 +48,10 @@ import { } from '../api/machines.ts' import { Confirm, Rename } from '../ask.tsx' import { useRead } from '../data.ts' +import { useDevMode } from '../dev-mode.ts' import { useHost, useTarget } from '../host.tsx' import { Card, Field, Group, Heading, Note, Once, Row, Soft } from './ui.tsx' -const mono = { fontFamily: 'var(--f-mono, ui-monospace, monospace)' } - /** What `hanzo link` needs, in the order it is typed on the machine. */ const LINK = ['hanzo login', 'hanzo link'].join('\n') @@ -136,7 +137,7 @@ function StatusBadge({ m }: { m: Machine }) { return ( - + {text} @@ -148,6 +149,7 @@ export function Machines() { const host = useHost() const target = useTarget() const signed = Boolean(host.person) + const [devMode] = useDevMode() const list = useRead(signed ? () => machines(target) : null, UNREAD, [target, signed]) const [adding, setAdding] = useState(false) const [renaming, setRenaming] = useState(null) @@ -155,6 +157,7 @@ export function Machines() { const [keying, setKeying] = useState(null) const [minted, setMinted] = useState<{ machine: Machine; key: string } | null>(null) const [expandedId, setExpandedId] = useState(null) + const [collapsedDevIds, setCollapsedDevIds] = useState>({}) const [showAdvancedLink, setShowAdvancedLink] = useState(false) const [note, setNote] = useState('') @@ -170,7 +173,7 @@ export function Machines() { return ( - {t('Sign in to see your organization’s machines.')} + {t('Sign in to see your linked computers.')} ) } @@ -178,8 +181,9 @@ export function Machines() { const drain = async (m: Machine, status: 'online' | 'draining') => { setNote('') try { + const display = displayMachine(m, { devMode }) await change(target, m.id, { status }) - setNote(status === 'draining' ? t('{name} takes no new runs', { name: m.label }) : t('{name} takes runs again', { name: m.label })) + setNote(status === 'draining' ? t('{name} takes no new runs', { name: display.title }) : t('{name} takes runs again', { name: display.title })) list.reload() } catch (e) { setNote(told(e, t)) @@ -188,9 +192,16 @@ export function Machines() { return ( - + - + {LINK} @@ -205,18 +216,18 @@ export function Machines() { - {t('Supported: macOS, Linux, Windows, NVIDIA CUDA GPUs, Cloud VMs')} + {devMode ? t('Supported: macOS, Linux, Windows, NVIDIA CUDA GPUs, Cloud VMs') : t('Works on macOS, Windows, and Linux')} {showAdvancedLink ? ( - + {t('1. Background daemon (system service)')} @@ -231,7 +242,7 @@ export function Machines() { - + {t('2. Install CLI from shell')} @@ -247,26 +258,26 @@ export function Machines() { {list.value === UNREAD ? ( - {list.error ? told(list.error, t) : t('Reading machines…')} + {list.error ? told(list.error, t) : t('Loading devices…')} ) : list.value.length === 0 ? ( - {t('No machine is linked yet.')} + {t('No computer is linked yet.')} - - {t('Connect your first computer or GPU server')} + + {t('Connect your computer')} - {t('Execute code, runs, and local models directly on your hardware with full privacy and zero cloud fees.')} + {t('Run tasks directly on your own computer in your Hanzo folder.')} - + 1. @@ -274,7 +285,7 @@ export function Machines() { - + 2. @@ -282,7 +293,7 @@ export function Machines() { - + 3. @@ -301,8 +312,21 @@ export function Machines() { ) : ( {list.value.map((m, i) => { - const isExpanded = expandedId === m.id - const hasTelemetry = Boolean(m.metrics || m.spec) + const display = displayMachine(m, { devMode }) + const showDetails = devMode ? !collapsedDevIds[m.id] : expandedId === m.id + const toggleDetails = () => { + if (devMode) { + setCollapsedDevIds((prev) => ({ ...prev, [m.id]: !prev[m.id] })) + } else { + setExpandedId(expandedId === m.id ? null : m.id) + } + } + const calmDetail = [ + said(state(m), t), + m.running ? t('{n} active', { n: m.running }) : m.sessions ? t('{n} runs', { n: m.sessions }) : '', + ] + .filter(Boolean) + .join(' · ') return ( 0 ? 1 : 0} borderColor="$borderColor"> } - title={m.label} - detail={about(m, t)} + title={display.title} + detail={devMode ? about(m, t) : calmDetail} trailing={ + {!devMode && display.detail ? ( + + + + + + + + + + {display.detail} + + + + + ) : null} - {m.serving ? ( + {m.serving && devMode ? ( {t('Serving')} @@ -333,21 +389,32 @@ export function Machines() { ) : null} - + {!devMode ? ( + + ) : ( + + )} + } items={[ - { key: 'details', label: isExpanded ? t('Hide details') : t('Show details'), onSelect: () => setExpandedId(isExpanded ? null : m.id) }, + { key: 'details', label: showDetails ? t('Hide advanced details') : t('Advanced details'), onSelect: toggleDetails }, { key: 'rename', label: t('Rename'), onSelect: () => setRenaming(m) }, - m.status === 'draining' - ? { key: 'online', label: t('Take runs again'), onSelect: () => void drain(m, 'online') } - : { key: 'drain', label: t('Drain'), description: t('Finish what it has, take nothing new'), onSelect: () => void drain(m, 'draining') }, - { key: 'key', label: t('Claim key'), onSelect: () => setKeying(m) }, - { type: 'separator' }, + ...(devMode || showDetails + ? [ + m.status === 'draining' + ? { key: 'online', label: t('Take runs again'), onSelect: () => void drain(m, 'online') } + : { key: 'drain', label: t('Drain'), description: t('Finish what it has, take nothing new'), onSelect: () => void drain(m, 'draining') }, + { key: 'key', label: t('Claim key'), onSelect: () => setKeying(m) }, + ] + : []), + { type: 'separator' as const }, { key: 'remove', label: t('Remove'), destructive: true, onSelect: () => setRemoving(m) }, ]} /> @@ -355,8 +422,8 @@ export function Machines() { } /> - {/* Telemetry and specs panel */} - {isExpanded || hasTelemetry ? ( + {/* Advanced details: hardware specs, live telemetry, keys & CLI flags (collapsed unless opened or Developer mode is ON) */} + {showDetails ? ( {/* Specs bar */} {m.spec ? ( @@ -404,7 +471,7 @@ export function Machines() { {t('CPU Utilization')} - + {formatPercent(m.metrics.cpuUtil)} {m.metrics.cpuTemp ? `· ${m.metrics.cpuTemp}°C` : ''} @@ -413,7 +480,7 @@ export function Machines() { {t('Load (1m, 5m, 15m)')} - + {m.metrics.load1}, {m.metrics.load5 ?? 0}, {m.metrics.load15 ?? 0} @@ -424,7 +491,7 @@ export function Machines() { {t('Memory')} - + {m.spec?.memory ? `${formatBytes(m.metrics.memUsed)} / ${formatBytes(m.spec.memory)}` : t('{size} used', { size: formatBytes(m.metrics.memUsed) })} @@ -435,7 +502,7 @@ export function Machines() { {t('GPU')} - + {formatPercent(m.metrics.gpuUtil)} {m.metrics.gpuTemp ? `· ${m.metrics.gpuTemp}°C` : ''} {m.metrics.gpuPower ? `· ${m.metrics.gpuPower}W` : ''} @@ -446,7 +513,7 @@ export function Machines() { {t('Serving Model')} - + {m.metrics.model} {m.metrics.decode ? `(${m.metrics.decode} tok/s)` : ''} @@ -454,27 +521,39 @@ export function Machines() { ) : null} - {/* Quick Commands & Details */} + {/* Quick Commands & Advanced Actions */} - - + + {t('ID: {id}', { id: m.id })} + {m.host ? ( + + {m.host} + + ) : null} {m.seen ? ( {t('Last heartbeat: {when}', { when: formatRelative(m.seen) })} ) : null} - - - {t('Run directly on this machine:')} - + + + hanzo run --target {m.id} - + @@ -547,7 +626,7 @@ export function Machines() { - + {t('Start background worker with this key:')} From 3dbdde7f818ab5f45e5290dc339058d6bb933a4d Mon Sep 17 00:00:00 2001 From: James <279246542+jamessburnss1313-dev@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:13:34 +0000 Subject: [PATCH 02/19] Dev effort: Fast (low) is a valid saved choice --- src/mind.test.tsx | 24 +++++++++++++----------- src/mind.ts | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/mind.test.tsx b/src/mind.test.tsx index 29084ae..365edec 100644 --- a/src/mind.test.tsx +++ b/src/mind.test.tsx @@ -63,11 +63,11 @@ describe('the kept choice', () => { it('reads an effort it does not know, a blank model and a broken entry as the defaults', () => { browser({ 'hanzo.mind': JSON.stringify({ model: ' ', effort: 'extreme' }) }) expect(kept()).toEqual(FIRST) - // Low and Medium were offered once; a choice kept from then opens on Auto, which a run sends as medium. - for (const effort of ['low', 'medium']) { - browser({ 'hanzo.mind': JSON.stringify({ model: 'zen6', effort }) }) - expect(kept()).toEqual({ model: 'zen6', effort: 'auto' }) - } + // Low is Dev's Fast effort, so a saved 'low' is kept; Medium was offered once and opens on Auto, which a run sends as medium. + browser({ 'hanzo.mind': JSON.stringify({ model: 'zen6', effort: 'low' }) }) + expect(kept()).toEqual({ model: 'zen6', effort: 'low' }) + browser({ 'hanzo.mind': JSON.stringify({ model: 'zen6', effort: 'medium' }) }) + expect(kept()).toEqual({ model: 'zen6', effort: 'auto' }) browser({ 'hanzo.mind': '{not json' }) expect(kept()).toEqual(FIRST) }) @@ -75,10 +75,12 @@ describe('the kept choice', () => { it('keeps only an effort it offers, whoever asks', () => { const { items } = browser() keep({ model: 'zen6', effort: 'max' }) - keep({ effort: 'low' as never }) + keep({ effort: 'medium' as never }) expect(JSON.parse(items.get('hanzo.mind')!)).toEqual({ model: 'zen6', effort: 'auto' }) + keep({ effort: 'low' }) + expect(JSON.parse(items.get('hanzo.mind')!)).toEqual({ model: 'zen6', effort: 'low' }) keep({ model: 'zen6-flash' }) - expect(kept()).toEqual({ model: 'zen6-flash', effort: 'auto' }) + expect(kept()).toEqual({ model: 'zen6-flash', effort: 'low' }) }) it('holds a choice for the page where the browser refuses to store it', () => { @@ -95,12 +97,12 @@ describe('the kept choice', () => { expect(kept()).toEqual({ model: 'zen6', effort: 'auto' }) }) - it('offers Auto, High and Max, in that order, and nothing else', () => { - expect(EFFORTS.map((e) => e.label)).toEqual(['Auto', 'High', 'Max']) + it('offers Auto, Fast, High and Max, in that order, and nothing else', () => { + expect(EFFORTS.map((e) => e.label)).toEqual(['Auto', 'Fast', 'High', 'Max']) }) - it('names to a coding run only an effort it takes: medium for Auto, high for the rest', () => { - expect(EFFORTS.map((e) => level(e.id))).toEqual(['medium', 'high', 'high']) + it('names to a coding run only an effort it takes: medium for Auto, low for Fast, high for the rest', () => { + expect(EFFORTS.map((e) => level(e.id))).toEqual(['medium', 'low', 'high', 'high']) }) }) diff --git a/src/mind.ts b/src/mind.ts index 71d41c0..de1e742 100644 --- a/src/mind.ts +++ b/src/mind.ts @@ -20,6 +20,7 @@ * an effort the person saved to their account once (apps/coding start.go) and * no screen shows any more. */ +import { phrase } from '@hanzo/i18n' import type { Modes } from '@hanzo/ui/chat' import { EFFORTS as EVERY } from '@hanzo/ui/chat/pure' import { parseModels, thirdParty } from '@hanzo/ui/models/catalog' @@ -30,13 +31,32 @@ import { Refusal, type Target } from './api/call.ts' import { ENSO, models as read, type Model } from './api/models.ts' import { usePick } from './pick.ts' -export type Effort = 'auto' | 'high' | 'max' +export type Effort = 'auto' | 'low' | 'high' | 'max' -/** The efforts a Dev run offers, in order: the composer's own list (Chat offers every one), less Low and Medium. Marked English, drawn through `t`. */ -export const EFFORTS = EVERY.filter((e): e is (typeof EVERY)[number] & { id: Effort } => ['auto', 'high', 'max'].includes(e.id)) +const EFFORT_LABELS: Partial> = { + low: phrase('Fast'), +} + +const EFFORT_NOTES: Record = { + auto: phrase('Matches thinking depth to the complexity of each prompt.'), + low: phrase('Fastest edits and replies for straightforward coding tasks.'), + high: phrase('Spends extra time reasoning through multi-step tasks and code.'), + max: phrase('Deepest reasoning and verification for complex architecture.'), +} + +/** The efforts a Dev run offers, in order: Auto (medium), Fast (low), High, and Max. Marked English, drawn through `t`. */ +export const EFFORTS = (['auto', 'low', 'high', 'max'] as const).map((id) => { + const base = EVERY.find((e) => e.id === id) + return { + id, + label: EFFORT_LABELS[id] ?? base?.label ?? id, + note: EFFORT_NOTES[id] ?? base?.note ?? '', + } +}) -/** The effort a coding run names (apps/coding takes low, medium or high): medium for Auto, high for the rest. */ -export const level = (effort: Effort): 'medium' | 'high' => (effort === 'auto' ? 'medium' : 'high') +/** The effort a coding run names (apps/coding takes low, medium or high): low for Fast, medium for Auto, high for High/Max. */ +export const level = (effort: Effort): 'low' | 'medium' | 'high' => + effort === 'low' ? 'low' : effort === 'auto' ? 'medium' : 'high' /** What a person chose: the model (Enso routes) and the effort. */ export interface Choice { @@ -304,6 +324,10 @@ export interface Mind { balance?: string /** The way to the top-up, given the model that was chosen if one was. */ topUp?: (id?: string) => void + /** Whether third-party provider models (Anthropic, OpenAI, Google, etc.) are included in `models`. */ + allowThirdParty?: boolean + /** How many third-party models are currently hidden because `allowThirdParty` is off. */ + hiddenThirdPartyCount?: number } /** The prepaid balance in cents that can pay for another maker's models, for a signed-in target, read once; null until it is, and where the API does not say. */ @@ -372,6 +396,7 @@ export function useMind(t: Target, plan?: string | null, topUp?: (id?: string) = const may = (id: string): boolean => sendable(free, models, cents, id) const model = may(picked) ? picked : ENSO const listed = allowThirdParty ? models : models.filter((m) => !thirdParty(m) || m.id === model) + const hiddenThirdPartyCount = allowThirdParty ? 0 : models.filter((m) => thirdParty(m) && m.id !== model).length // A top-up returns to this address with the model it was for: pick it once the balance can pay. const [back] = useState(returned) useEffect(() => { @@ -389,6 +414,8 @@ export function useMind(t: Target, plan?: string | null, topUp?: (id?: string) = error, note, free, + allowThirdParty, + hiddenThirdPartyCount, pick: (id) => { if (may(id)) pick(id) }, From a48ac8729baf2f20645f16ea2516ddd2bb18f6cc Mon Sep 17 00:00:00 2001 From: James <279246542+jamessburnss1313-dev@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:13:34 +0000 Subject: [PATCH 03/19] Chat to Dev handoff in one module, with a test --- src/handoff.test.ts | 23 +++++++++++++++++++++++ src/handoff.ts | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/handoff.test.ts create mode 100644 src/handoff.ts diff --git a/src/handoff.test.ts b/src/handoff.test.ts new file mode 100644 index 0000000..688db6b --- /dev/null +++ b/src/handoff.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from 'vitest' + +import { DEV_HANDOFF, takeHandoff } from './handoff.ts' + +const store = (value?: string) => { + const items = new Map(value === undefined ? [] : [[DEV_HANDOFF, value]]) + return { items, getItem: (k: string) => items.get(k) ?? null, removeItem: (k: string) => void items.delete(k) } +} + +describe('the Chat to Dev handoff', () => { + it('turns a prompt and code into one draft, and is read once', () => { + const s = store(JSON.stringify({ prompt: ' Fix this ', code: 'let a = 1', language: 'ts' })) + expect(takeHandoff(s)).toBe('Fix this\n\n```ts\nlet a = 1\n```') + expect(s.items.has(DEV_HANDOFF)).toBe(false) + expect(takeHandoff(s)).toBe('') + }) + + it('reads a prompt alone, and nothing from a broken or empty handoff', () => { + expect(takeHandoff(store(JSON.stringify({ prompt: 'Hello' })))).toBe('Hello') + expect(takeHandoff(store('{not json'))).toBe('') + expect(takeHandoff(store())).toBe('') + }) +}) diff --git a/src/handoff.ts b/src/handoff.ts new file mode 100644 index 0000000..ed26da6 --- /dev/null +++ b/src/handoff.ts @@ -0,0 +1,21 @@ +/** + * What Chat's "Open in Dev" leaves in this tab's session storage for the New + * page to pick up: a prompt, and optionally some code to run it on. One key, one + * reader, so Chat and Dev cannot drift apart. + */ +export const DEV_HANDOFF = 'hanzo.handoff.dev' + +/** The draft the handoff makes, or '' for none; the handoff is consumed either way. */ +export function takeHandoff(store: Pick): string { + try { + const raw = store.getItem(DEV_HANDOFF) + if (!raw) return '' + store.removeItem(DEV_HANDOFF) + const h = JSON.parse(raw) as { prompt?: unknown; code?: unknown; language?: unknown } + const text = (v: unknown) => (typeof v === 'string' ? v.trim() : '') + const code = text(h.code) + return [text(h.prompt), code && `\`\`\`${text(h.language)}\n${code}\n\`\`\``].filter(Boolean).join('\n\n') + } catch { + return '' + } +} From 5e05372b5a10398b1b63956e00afde7795144335 Mon Sep 17 00:00:00 2001 From: James <279246542+jamessburnss1313-dev@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:13:34 +0000 Subject: [PATCH 04/19] Copy to clipboard in one place; a refused clipboard throws nothing --- src/clipboard.test.ts | 21 ++ src/clipboard.ts | 9 + src/panel.test.ts | 25 +++ src/panel.tsx | 374 ++++++++++++++++++++++----------- src/settings/account.tsx | 3 +- src/settings/notifications.tsx | 3 +- 6 files changed, 310 insertions(+), 125 deletions(-) create mode 100644 src/clipboard.test.ts create mode 100644 src/clipboard.ts create mode 100644 src/panel.test.ts diff --git a/src/clipboard.test.ts b/src/clipboard.test.ts new file mode 100644 index 0000000..457c43c --- /dev/null +++ b/src/clipboard.test.ts @@ -0,0 +1,21 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' + +import { copy } from './clipboard.ts' + +afterEach(() => vi.unstubAllGlobals()) + +describe('copying to the clipboard', () => { + it('says it copied', async () => { + const wrote: string[] = [] + vi.stubGlobal('navigator', { clipboard: { writeText: async (t: string) => void wrote.push(t) } }) + await expect(copy('abc')).resolves.toBe(true) + expect(wrote).toEqual(['abc']) + }) + + it('says it did not, with nothing thrown, when the browser refuses or has no clipboard', async () => { + vi.stubGlobal('navigator', { clipboard: { writeText: () => Promise.reject(new Error('denied')) } }) + await expect(copy('abc')).resolves.toBe(false) + vi.stubGlobal('navigator', {}) + await expect(copy('abc')).resolves.toBe(false) + }) +}) diff --git a/src/clipboard.ts b/src/clipboard.ts new file mode 100644 index 0000000..9d549c7 --- /dev/null +++ b/src/clipboard.ts @@ -0,0 +1,9 @@ +/** Copy text; true once it is on the clipboard, false where the browser has none or refuses it (nothing is thrown). */ +export const copy = async (text: string): Promise => { + try { + await navigator.clipboard.writeText(text) + return true + } catch { + return false + } +} diff --git a/src/panel.test.ts b/src/panel.test.ts new file mode 100644 index 0000000..7186141 --- /dev/null +++ b/src/panel.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it, vi } from 'vitest' + +vi.mock('@hanzo/gui', () => ({})) +vi.mock('@hanzo/ui', () => ({})) +vi.mock('@hanzogui/lucide-icons-2', () => ({})) +vi.mock('./host.tsx', () => ({})) + +const { screenshot } = await import('./panel.tsx') + +const page = { id: 't1', url: 'https://hanzo.ai', title: 'Hanzo' } + +describe('the page menu', () => { + it('hands a capture to its host as a PNG file', async () => { + const files: File[] = [] + await screenshot({ capture: async () => new Blob(['x'], { type: 'image/png' }) } as never, page, (f) => void files.push(f)) + expect(files).toHaveLength(1) + expect(files[0]!.type).toBe('image/png') + }) + + it('drops a capture the host browser cancels, with nothing thrown', async () => { + const files: File[] = [] + await expect(screenshot({ capture: async () => Promise.reject(new Error('cancelled')) } as never, page, (f) => void files.push(f))).resolves.toBeUndefined() + expect(files).toEqual([]) + }) +}) diff --git a/src/panel.tsx b/src/panel.tsx index 8e78c29..d36f4c0 100644 --- a/src/panel.tsx +++ b/src/panel.tsx @@ -40,10 +40,12 @@ import { DropdownMenuSubTrigger, DropdownMenuTrigger, } from '@hanzo/ui' -import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react' +import { Fragment, useEffect, useMemo, useRef, useState, type ReactNode } from 'react' import { createPortal } from 'react-dom' -import { useBrowse, useBrowser, type Browser } from './host.tsx' +import { RING } from './pane.ts' +import { copy } from './clipboard.ts' +import { useBrowse, useBrowser, type Browser, type Shown } from './host.tsx' import { useSide } from './side.tsx' import { destination, PAGE, type Deck, type Tab } from './tabs.ts' @@ -93,11 +95,12 @@ const quiet = (on = false, disabled = false) => justify: 'center', shrink: 0, rounded: 8, + borderWidth: 0, cursor: disabled ? 'default' : 'pointer', opacity: disabled ? 0.35 : 1, bg: on ? '$hover' : 'transparent', hoverStyle: disabled ? undefined : ({ bg: '$hover' } as const), - focusVisibleStyle: { outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }, + focusVisibleStyle: RING, }) as const /** @@ -111,16 +114,17 @@ export function PanelToggle({ open, onToggle }: { open: boolean; onToggle: () => if (open) return null return ( } data-slot="side-toggle" aria-label={t('Show tabs')} aria-expanded={false} aria-keyshortcuts={SHORTCUTS} {...({ title: t('Show tabs ({keys})', { keys: KEYS }) } as object)} - onPress={onToggle} + onClick={onToggle} width={32} height={32} + $touchable={{ minW: 44, minH: 44 }} + $max-sm={{ minW: 44, minH: 44 }} {...quiet()} > @@ -184,7 +188,10 @@ function Mark({ icon, title }: { icon?: string; title: string }) { return ( {icon && !broken ? ( - setBroken(true)} /> + setBroken(true)} />} + $platform-web={{ objectFit: 'contain' }} + /> ) : ( {(title.trim()[0] ?? '·').toUpperCase()} @@ -199,38 +206,39 @@ function Suggested({ suggested, onGo }: { suggested: readonly Suggestion[]; onGo const { t } = useI18n() return ( - + {t('Suggested')} {suggested.length ? ( {suggested.map((s) => ( - onGo(s.url)} - width={120} - shrink={0} - items="center" - gap="$2" - py="$2.5" - px="$1.5" - rounded={12} - cursor="pointer" - hoverStyle={{ bg: '$hover' }} - focusVisibleStyle={{ outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }} - > - - - {s.title} - + + } + aria-label={s.title} + onClick={() => onGo(s.url)} + width={120} + items="center" + gap="$2" + py="$2.5" + px="$1.5" + rounded={12} + borderWidth={0} + bg="transparent" + cursor="pointer" + hoverStyle={{ bg: '$hover' }} + focusVisibleStyle={RING} + > + + + {s.title} + + ))} ) : ( - + {t('No suggestions.')} )} @@ -244,25 +252,28 @@ function Elsewhere({ tab }: { tab: Tab }) { return ( - + {tab.title || tab.url} popOut(tab)} + render={