diff --git a/LLM.md b/LLM.md index d70039e..f8015bd 100644 --- a/LLM.md +++ b/LLM.md @@ -441,6 +441,20 @@ from the page's origin and `useClient` posts the credential calls there. hanzo.a and hanzo.market (`src/choose.tsx`, `src/menu.tsx`) are the two callers; the bar's own menu (Header.tsx) and the Accounts section keep their markup. +## Dev on Hanzo Desktop: This computer, and a site to redesign + +`dev.tsx` hands @hanzo/build's Dev what only the desktop window has, as `Host.local` and `Host.site`; a browser +page gets neither (`isTauri()` is false), and Dev offers the cloud workspace and the org's machines only. + +- `lib/local-fs.ts` `desktopLocal()`: the folders the window opened, its folder dialog, and a run of the `dev` agent + in one folder (`local_workspace_run_dev`). +- `lib/local-site.ts` `desktopSite()` (hanzo-inc/app issue 312): opening a site from the computer's own connection and + saving a copy of it into a folder for the agent (`local_site_capture`: the page, its words, its stylesheets, a picture + when a paired browser can take one), naming a new folder under Documents/Hanzo (`local_site_folder`), serving the + folder's `redesign/` live with reload on every file change (`local_preview_start`, `local_preview_stop`) and showing + it in Chrome (`local_preview_open`, which opens only a preview the window is serving). What the desktop refuses (a + private-network address, a site that will not answer) comes back in plain words and is shown as it comes. + ## Build and ship The repository is a pnpm workspace of the packages it publishes, each under diff --git a/pkg/app/package.json b/pkg/app/package.json index ae90c08..72f011f 100644 --- a/pkg/app/package.json +++ b/pkg/app/package.json @@ -1,6 +1,6 @@ { "name": "@hanzo/app", - "version": "0.3.112", + "version": "0.3.113", "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", @@ -59,7 +59,7 @@ "peerDependencies": { "@hanzo/ai": ">=0.7.0", "@hanzo/appearance": ">=0.2.15", - "@hanzo/build": ">=0.2.136", + "@hanzo/build": ">=0.2.138", "@hanzo/composer": ">=0.2.0", "@hanzo/design": ">=0.5.39", "@hanzo/event": ">=0.3.63", diff --git a/pkg/app/src/dev.tsx b/pkg/app/src/dev.tsx index c65c975..752567f 100644 --- a/pkg/app/src/dev.tsx +++ b/pkg/app/src/dev.tsx @@ -45,6 +45,7 @@ import { app, place, settings, visit } from './lib/host' import { link } from './lib/tags' import { payUrl, topUp } from './lib/pay' import { desktopLocal } from './lib/local-fs' +import { desktopSite } from './lib/local-site' /** Where the builder links out: every one of them an address of this site. */ const LINKS: Host['links'] = { @@ -102,6 +103,8 @@ export function useDevHost(): Host { const signedIn = Boolean(accessToken || bearer() || u) // Hanzo Desktop's folders, so Dev offers This computer (hanzo-inc/app issues 309 and 310); none in a browser. const local = useMemo(() => desktopLocal(), []) + // The same window opens a site, saves a copy for the agent and serves its redesign live (hanzo-inc/app issue 312). + const site = useMemo(() => desktopSite(), []) return useMemo( () => ({ @@ -155,7 +158,8 @@ export function useDevHost(): Host { signIn: () => enter(), signOut: () => void logout(), ...(local ? { local } : {}), + ...(site ? { site } : {}), }), - [scoped, memberships, look.pref.theme, look.set, signedIn, name, email, avatar, here, router, logout, local], + [scoped, memberships, look.pref.theme, look.set, signedIn, name, email, avatar, here, router, logout, local, site], ) } diff --git a/pkg/app/src/lib/local-site.test.ts b/pkg/app/src/lib/local-site.test.ts new file mode 100644 index 0000000..6bc50a8 --- /dev/null +++ b/pkg/app/src/lib/local-site.test.ts @@ -0,0 +1,64 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' + +import { desktopSite } from './local-site' + +/** A window with Hanzo Desktop's IPC (`invoke`), as the desktop's webview has. */ +function desktop(invoke: (cmd: string, args?: Record) => Promise) { + ;(globalThis as Record).window = { __TAURI_INTERNALS__: { invoke } } +} + +afterEach(() => { + delete (globalThis as Record).window +}) + +describe('Redesigning a site on Hanzo Desktop (hanzo-inc/app issue 312)', () => { + it('is nothing in a browser page, which cannot open a site for the agent', () => { + ;(globalThis as Record).window = {} + expect(desktopSite()).toBeNull() + }) + + it('names the folder, saves the site into it, serves its redesign and shows it, each through the desktop’s own command', async () => { + const invoke = vi.fn(async (cmd: string) => { + switch (cmd) { + case 'local_site_folder': + return { name: 'acme-redesign', path: '/Users/me/Documents/Hanzo/acme-redesign' } + case 'local_site_capture': + return { title: 'Acme', url: 'https://acme.test/', files: ['page.html', 'text.md'], screenshot: false } + case 'local_preview_start': + return { url: 'http://127.0.0.1:9933/', port: 9933 } + default: + return null + } + }) + desktop(invoke) + const site = desktopSite()! + await expect(site.folder('acme-redesign')).resolves.toEqual({ name: 'acme-redesign', path: '/Users/me/Documents/Hanzo/acme-redesign' }) + await expect(site.capture('https://acme.test', '/Users/me/Documents/Hanzo/acme-redesign')).resolves.toEqual({ + title: 'Acme', + url: 'https://acme.test/', + files: ['page.html', 'text.md'], + screenshot: false, + }) + await expect(site.preview('/Users/me/Documents/Hanzo/acme-redesign')).resolves.toEqual({ url: 'http://127.0.0.1:9933/' }) + await site.show('http://127.0.0.1:9933/') + await site.stop('/Users/me/Documents/Hanzo/acme-redesign') + expect(invoke.mock.calls).toEqual([ + ['local_site_folder', { name: 'acme-redesign' }], + ['local_site_capture', { url: 'https://acme.test', dir: '/Users/me/Documents/Hanzo/acme-redesign' }], + ['local_preview_start', { dir: '/Users/me/Documents/Hanzo/acme-redesign' }], + ['local_preview_open', { url: 'http://127.0.0.1:9933/' }], + ['local_preview_stop', { dir: '/Users/me/Documents/Hanzo/acme-redesign' }], + ]) + }) + + it('says what the desktop refused in its own words, whether it rejects with text or an Error', async () => { + desktop(async () => { + throw 'The site took too long to answer.' + }) + await expect(desktopSite()!.capture('https://slow.test', '/x')).rejects.toThrow('The site took too long to answer.') + desktop(async () => { + throw new Error('That preview is not running any more.') + }) + await expect(desktopSite()!.show('http://127.0.0.1:1/')).rejects.toThrow('That preview is not running any more.') + }) +}) diff --git a/pkg/app/src/lib/local-site.ts b/pkg/app/src/lib/local-site.ts new file mode 100644 index 0000000..c2dee26 --- /dev/null +++ b/pkg/app/src/lib/local-site.ts @@ -0,0 +1,71 @@ +/** + * Redesigning a site on Hanzo Desktop (hanzo-inc/app issue 312, hanzoai/desktop issue 15). + * + * `desktopSite()` is @hanzo/build's `Site` (`Host.site`) over the desktop's own commands: the window opens the + * site from the computer's connection and saves a copy into a folder (`local_site_capture`), serves the folder's + * `redesign/` live on this computer (`local_preview_start`) and shows it in Chrome (`local_preview_open`). A browser + * page has no such commands, so it gets none and Dev offers nothing of it. The agent runs through `desktopLocal()`. + * + * What the desktop refuses it says in plain words (an address on a private network, a site that will not answer), and + * those words are what a person reads: they are passed up as the error's own message. + */ +import type { Site } from '@hanzo/build' + +import { isTauri } from './local-fs' + +/** Invoke a desktop command; a refusal is its plain words, as an Error. */ +async function command(name: string, args?: Record): Promise { + const win = window as unknown as { __TAURI_INTERNALS__?: { invoke: (cmd: string, args?: Record) => Promise } } + const invoke = win.__TAURI_INTERNALS__?.invoke + if (!invoke) throw new Error('Hanzo Desktop is not running.') + try { + return await invoke(name, args) + } catch (e) { + throw e instanceof Error ? e : new Error(typeof e === 'string' ? e : 'Hanzo Desktop could not do that.') + } +} + +/** What `local_site_folder` answers: the folder's name and path. */ +interface SiteFolder { + name: string + path: string +} + +/** What `local_site_capture` answers. */ +interface SiteSaved { + title: string + url: string + files: string[] + screenshot: boolean +} + +/** What `local_preview_start` answers. */ +interface Live { + url: string + port: number +} + +/** Hanzo Desktop's way of redesigning a site, or null outside its window. */ +export function desktopSite(): Site | null { + if (!isTauri()) return null + return { + folder: async (name) => { + const made = await command('local_site_folder', { name }) + return { path: made.path, name: made.name } + }, + capture: async (url, folder) => { + const saved = await command('local_site_capture', { url, dir: folder }) + return { title: saved.title, url: saved.url, files: saved.files, screenshot: saved.screenshot } + }, + preview: async (folder) => { + const live = await command('local_preview_start', { dir: folder }) + return { url: live.url } + }, + stop: async (folder) => { + await command('local_preview_stop', { dir: folder }) + }, + show: async (url) => { + await command('local_preview_open', { url }) + }, + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e85f3a0..1f28168 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,8 +13,8 @@ catalogs: specifier: 0.2.15 version: 0.2.15 '@hanzo/build': - specifier: 0.2.136 - version: 0.2.136 + specifier: 0.2.138 + version: 0.2.138 '@hanzo/composer': specifier: 0.2.0 version: 0.2.0 @@ -137,7 +137,7 @@ importers: version: 0.2.15(react@19.2.8) '@hanzo/build': specifier: 'catalog:' - version: 0.2.136(4ad4e3c852ede235ac12cd2c3e40a847) + version: 0.2.138(4ad4e3c852ede235ac12cd2c3e40a847) '@hanzo/composer': specifier: 'catalog:' version: 0.2.0(@hanzo/gui@8.3.5(react-dom@19.2.8(react@19.2.8))(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8))(react@19.2.8) @@ -161,7 +161,7 @@ importers: version: 1.0.26(react@19.2.8) '@hanzo/studio': specifier: 'catalog:' - version: 0.1.12(55f61c60f0ef9e74a1ba4544998ebcaa) + version: 0.1.12(1daf1b408a857e5e5d54be1fe6d5c97d) '@hanzo/tabs': specifier: 'catalog:' version: https://codeload.github.com/hanzo-inc/tabs/tar.gz/26a30cbc5fac232e5b11d5d77939f9573ca0c8d8(@hanzo/gui@8.3.5(react-dom@19.2.8(react@19.2.8))(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8))(@hanzo/ui@8.33.6(patch_hash=55c0ec6cbb062072f0fb16726890e144dc6564d5e5a7e9ce62c5fb86faa38649)(c331da2469a6af62a53d9754cbbbaf69))(lucide-react@1.42.0(react@19.2.8))(react-dom@19.2.8(react@19.2.8))(react@19.2.8) @@ -654,8 +654,8 @@ packages: react: optional: true - '@hanzo/build@0.2.136': - resolution: {integrity: sha512-H/pDSB2P22JN/dVQb4EprV6ZO6RIacD0I70ETuIUED4jiFB94CKAmLnj1/3OsSqKesCZ69mTvsqOI9Blb9J5gw==} + '@hanzo/build@0.2.138': + resolution: {integrity: sha512-M8kebr/45XKfTh9tFdTzUme6890McNh4T4trapl4DQp/9fc/G6xcFQTH50m8aFojhBeJ4jqeME/DbnX10WNKbw==} engines: {node: '>=22.18'} peerDependencies: '@hanzo/composer': '>=0.2.0' @@ -3884,7 +3884,7 @@ snapshots: optionalDependencies: react: 19.2.8 - '@hanzo/build@0.2.136(4ad4e3c852ede235ac12cd2c3e40a847)': + '@hanzo/build@0.2.138(4ad4e3c852ede235ac12cd2c3e40a847)': dependencies: '@hanzo/composer': 0.2.0(@hanzo/gui@8.3.5(react-dom@19.2.8(react@19.2.8))(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8))(react@19.2.8) '@hanzo/gui': 8.3.5(react-dom@19.2.8(react@19.2.8))(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8) @@ -4037,9 +4037,9 @@ snapshots: '@hanzogui/lucide-icons-2': 8.3.5(react-dom@19.2.8(react@19.2.8))(react-native-svg@15.15.5(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8))(react@19.2.8) react: 19.2.8 - '@hanzo/studio@0.1.12(55f61c60f0ef9e74a1ba4544998ebcaa)': + '@hanzo/studio@0.1.12(1daf1b408a857e5e5d54be1fe6d5c97d)': dependencies: - '@hanzo/build': 0.2.136(4ad4e3c852ede235ac12cd2c3e40a847) + '@hanzo/build': 0.2.138(4ad4e3c852ede235ac12cd2c3e40a847) '@hanzo/composer': 0.2.0(@hanzo/gui@8.3.5(react-dom@19.2.8(react@19.2.8))(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8))(react@19.2.8) '@hanzo/gui': 8.3.5(react-dom@19.2.8(react@19.2.8))(react-native@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.87.1(@babel/core@7.29.7(supports-color@8.1.1))(supports-color@8.1.1))(@types/react@19.2.18)(react@19.2.8)(supports-color@8.1.1))(react@19.2.8) '@hanzo/i18n': 0.5.5(react@19.2.8) diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 9d54b15..328dd6a 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -33,7 +33,7 @@ minimumReleaseAge: 0 catalog: '@hanzo/ai': 0.7.0 '@hanzo/appearance': 0.2.15 - '@hanzo/build': 0.2.136 + '@hanzo/build': 0.2.138 '@hanzo/composer': 0.2.0 '@hanzo/design': 0.5.39 '@hanzo/event': 0.3.67