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
18 changes: 18 additions & 0 deletions LLM.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,24 @@ owns:
into the same, so sign-out or checkout never replaces the app with a page.
- **Look**: `gui.config.ts` is `@hanzo/ui/gui-config`'s `monochrome`, hanzo.ai's
config, for every window; `main.tsx` loads hanzo.ai's stylesheets in its order.
- **Both schemes**: `src/app.css` cuts the window's own skin (obsidian floor, one
sidebar surface) for the DARK scheme only, scoped `html:root:not(.t_light):not(.light)`;
light takes the app's own floor and card and a small block of `--desk-*` aliases.
Unscoped, the dark values dressed a system set to light too: the sidebar stayed
black under dark ink and every title in it but the lit one disappeared.
`e2e-tests/appearance.spec.ts` measures each sidebar title against what is painted
behind it (4.5:1) in both schemes. `src/desktop.css` is not imported by this window.
- **Updates**: `src/update.tsx`, in the bar beside Local AI. Once the window is up
(15 s) and every 30 minutes it asks the feed (`plugins.updater`); with a newer
version the bar says "Update available" and nothing else moves. One press
downloads, installs, stops the node and relaunches (Windows' installer restarts
itself). A failed install says so and can be pressed again. The old banner lives
in the retired layout and is not mounted here.
- **Developer mode**: the window's own `/settings` page (`DesktopSettings`) holds
the same switch as the account card, the palette (⌘K), ⌘⇧D and a run's menu:
`@hanzo/build/dev-mode`'s `hanzo.dev_mode`, off for a new person. The app's own
Settings pages are not reachable from this window, so a switch only drawn there
would not be found.

The stack is pinned in `pnpm-workspace.yaml`'s catalog to the versions
hanzo-inc/app pins. Move them together.
Expand Down
76 changes: 76 additions & 0 deletions apps/hanzo-desktop/e2e-tests/appearance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* The window reads in both schemes — measured, not reviewed.
*
* The window's skin (src/app.css) is cut for the dark scheme; left unscoped it
* also dressed a window whose reader's system is light: the sidebar stayed
* black under dark ink, so every title in it but the lit one vanished and a
* non-developer saw a column of nothing. Each label in the sidebar must read
* (WCAG 4.5:1) on whatever it sits on, in light and in dark.
*/
import { expect, type Page, test } from '@playwright/test';

async function enter(page: Page) {
await page.setViewportSize({ width: 1280, height: 900 });
await page.goto('/');
await page.getByRole('button', { name: /Not now|Continue without login/ }).click();
await expect(page.locator('[data-slot="app-column"]')).toBeVisible({ timeout: 30_000 });
}

type Reading = { label: string; ratio: number };

/** Every title in the sidebar, with its contrast against what is painted behind it. */
async function sidebar(page: Page): Promise<Reading[]> {
return page.evaluate(() => {
const parse = (c: string): number[] | null => {
const m = c.match(/rgba?\(([^)]+)\)/);
if (!m) return null;
const [r = 0, g = 0, b = 0, a = 1] = m[1]!.split(/[ ,/]+/).filter(Boolean).map(Number);
return [r, g, b, a];
};
const over = (top: number[], under: number[]) => {
const a = top[3]!;
return [0, 1, 2].map((i) => top[i]! * a + under[i]! * (1 - a)).concat(1);
};
const ground = (el: Element): number[] => {
const chain: number[][] = [];
for (let n: Element | null = el; n; n = n.parentElement) {
const c = parse(getComputedStyle(n).backgroundColor);
if (c && c[3]! > 0) chain.push(c);
if (c && c[3] === 1) break;
}
return chain.reduceRight((under, c) => over(c, under), [255, 255, 255, 1]);
};
const lum = (c: number[]) => {
const [r, g, b] = c.map((v) => {
const s = v! / 255;
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
});
return 0.2126 * r! + 0.7152 * g! + 0.0722 * b!;
};
const out: { label: string; ratio: number }[] = [];
const column = document.querySelector('[data-slot="app-column"]')!;
for (const el of column.querySelectorAll('button, a')) {
const label = (el.textContent ?? '').trim();
if (!label || (el as HTMLElement).offsetParent === null) continue;
const fg = parse(getComputedStyle(el).color);
if (!fg) continue;
const bg = ground(el);
const text = over(fg, bg);
const [hi, lo] = [lum(text), lum(bg)].sort((a, b) => b - a);
out.push({ label, ratio: (hi! + 0.05) / (lo! + 0.05) });
}
return out;
});
}

for (const scheme of ['light', 'dark'] as const) {
test(`every title in the sidebar reads in the ${scheme} scheme`, async ({ page }) => {
await page.emulateMedia({ colorScheme: scheme });
await enter(page);
const read = await sidebar(page);
const names = read.map((r) => r.label);
expect(names, 'the rail names its apps').toEqual(expect.arrayContaining(['Chat', 'Dev', 'Library']));
for (const r of read) expect(r.ratio, `${r.label} on the ${scheme} sidebar`).toBeGreaterThanOrEqual(4.5);
await page.screenshot({ path: `${process.env.SHOT_DIR ?? 'test-results'}/sidebar-${scheme}.png` });
});
}
148 changes: 148 additions & 0 deletions apps/hanzo-desktop/e2e-tests/redesign-site.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/**
* Redesign a site from its address, through the window's own commands (hanzo-inc/app#312, hanzoai/desktop#15).
*
* The main window is hanzo.ai's app, and Dev's New on This computer offers to redesign an address pasted into it: the
* window opens the site and saves a copy for the agent (`local_site_capture`), serves the folder's `redesign/` live
* (`local_preview_start`) and shows it in Chrome (`local_preview_open`), and the agent is the ordinary
* `local_workspace_run_dev`. There is no Tauri runtime in this suite, so the IPC is a stand-in that answers the way
* the Rust commands do and writes every call down; the Rust side is `cargo test local_site`. Signed in with a token
* the app reads from the keychain record, against a stubbed platform.
*/
import { expect, type Page, test } from '@playwright/test';

const b64 = (o: object) => Buffer.from(JSON.stringify(o)).toString('base64url');
const expires = Math.floor(Date.now() / 1000) + 86_400;
const TOKEN = [
b64({ alg: 'none', typ: 'JWT' }),
b64({ sub: 'u1', name: 'James', email: 'james@acme.test', owner: 'acme', exp: expires, orgs: [{ org: 'acme', role: 'member' }], org: 'acme' }),
'x',
].join('.');
const SESSION = JSON.stringify({
hanzo_iam_access_token: TOKEN,
hanzo_iam_refresh_token: 'r',
hanzo_iam_expires_at: String(Date.now() + 86_400_000),
});

type Call = { cmd: string; args: Record<string, unknown> };

/** A signed-in window whose IPC is a stand-in for the desktop's commands. `refuse` is what `local_site_capture` says no with. */
async function signedIn(page: Page, refuse = ''): Promise<Call[]> {
const calls: Call[] = [];
await page.exposeFunction('__ipc', (call: Call) => calls.push(call));
await page.addInitScript(
({ session, refuse }) => {
let callback = 1;
(window as unknown as Record<string, unknown>).__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main', windowLabel: 'main' } },
transformCallback(f: unknown) {
const id = callback++;
(window as unknown as Record<string, unknown>)[`_${id}`] = f;
return id;
},
unregisterCallback() {},
convertFileSrc: (p: string) => p,
async invoke(cmd: string, args: Record<string, unknown>) {
(window as unknown as { __ipc: (c: unknown) => void }).__ipc({ cmd, args });
switch (cmd) {
case 'secure_storage_get':
if (args.key === 'iam-session') return session;
throw 'Key not found';
case 'plugin:event|listen':
return callback++;
case 'local_site_folder':
return { name: args.name, path: `/Users/james/Documents/Hanzo/${args.name}` };
case 'local_site_capture':
if (refuse) throw refuse;
return { title: 'Acme Plumbing', url: args.url, files: ['page.html', 'text.md'], screenshot: false };
case 'local_preview_start':
return { url: 'http://127.0.0.1:9933/', port: 9933 };
case 'local_workspace_run_dev':
return { session_id: 's1', output: 'The page hides its call to action. I rebuilt it around one clear button.', process: '', success: true };
case 'local_workspace_discover':
return [];
default:
return null;
}
},
};
localStorage.setItem('hanzo.local_workspaces', JSON.stringify([{ id: 'w1', name: 'shop', path: '/Users/james/work/shop', addedAt: 1, lastOpenedAt: 5 }]));
},
{ session: SESSION, refuse },
);
await page.route('**/v1/**', (route) => {
const path = new URL(route.request().url()).pathname;
const json = (body: unknown) => route.fulfill({ contentType: 'application/json', body: JSON.stringify(body), headers: { 'access-control-allow-origin': '*' } });
if (path.endsWith('/stream')) return route.fulfill({ contentType: 'text/event-stream', body: ': ok\n\n' });
if (path === '/v1/agent/sessions' || path === '/v1/agents/sessions') return json({ sessions: [] });
if (path === '/v1/agent/targets' || path === '/v1/agents/targets') return json({ targets: [] });
if (path.startsWith('/v1/agents/chat/conversations')) return json({ conversations: [] });
if (path === '/v1/project') return json([]);
return json({});
});
return calls;
}

const sidebar = (calls: Call[]) => calls.map((c) => c.cmd).filter((c) => /^local_(site|preview|workspace_run)/.test(c));

test.describe('Redesign a site in Hanzo Desktop', () => {
test('an address pasted in Dev is offered as a redesign, and one press does all of it through the window’s commands', async ({ page }) => {
const calls = await signedIn(page);
await page.setViewportSize({ width: 1280, height: 860 });
await page.goto('/dev');
const ask = page.getByPlaceholder(/Ask, build/);
await ask.fill('https://www.acme.com/plumbing', { timeout: 60_000 });
const offer = page.locator('[data-slot="redesign-offer"]');
await expect(offer).toContainText('Redesign acme.com?');
await page.screenshot({ path: 'test-results/redesign-offer.png' });

await offer.getByRole('button', { name: 'Redesign this site' }).click();
const card = page.locator('[data-slot="redesign"]');
await expect(card).toContainText('Redesigned acme.com', { timeout: 15_000 });
await expect(card).toContainText('Live preview: http://127.0.0.1:9933/');
await expect(card).toContainText('The page hides its call to action. I rebuilt it around one clear button.');
await page.screenshot({ path: 'test-results/redesign-done.png' });

// The window's commands, in order: a new folder named for the site, the site saved into it, the redesign served and shown, the agent run there.
expect(sidebar(calls)).toEqual(['local_site_folder', 'local_site_capture', 'local_preview_start', 'local_preview_open', 'local_workspace_run_dev']);
const [folder, capture, start, open, run] = ['local_site_folder', 'local_site_capture', 'local_preview_start', 'local_preview_open', 'local_workspace_run_dev'].map(
(cmd) => calls.find((c) => c.cmd === cmd)!,
);
const dir = '/Users/james/Documents/Hanzo/acme-redesign';
expect(folder.args).toEqual({ name: 'acme-redesign' });
expect(capture.args).toEqual({ url: 'https://www.acme.com/plumbing', dir });
expect(start.args).toEqual({ dir });
expect(open.args).toEqual({ url: 'http://127.0.0.1:9933/' });
expect(run.args.workspacePath).toBe(dir);
expect(String(run.args.prompt)).toContain('Redesign the website https://www.acme.com/plumbing (Acme Plumbing).');
expect(String(run.args.prompt)).toContain('- .hanzo/reference/text.md:');
expect(String(run.args.prompt)).toContain('Do not start a server and do not use the network');

// Open in Chrome shows the same address again.
await card.getByRole('button', { name: 'Open in Chrome' }).click();
await expect.poll(() => calls.filter((c) => c.cmd === 'local_preview_open').length).toBe(2);
// The redesign's folder is now the one Auto picks.
await expect(page.getByRole('button', { name: /^Folder: / })).toHaveAccessibleName('Folder: Auto · acme-redesign');
});

test('a site the window will not open is said in plain words, and no agent is run', async ({ page }) => {
const calls = await signedIn(page, 'Hanzo opens sites on the internet, or one running on this computer. That address is on a private network.');
await page.goto('/dev');
await page.getByPlaceholder(/Ask, build/).fill('http://192.168.1.10/', { timeout: 60_000 });
await page.getByPlaceholder(/Ask, build/).press('Enter');
const card = page.locator('[data-slot="redesign"]');
await expect(card).toContainText('Could not redesign 192.168.1.10');
await expect(card).toContainText('That address is on a private network.');
expect(sidebar(calls)).toEqual(['local_site_folder', 'local_site_capture']);
await page.screenshot({ path: 'test-results/redesign-refused.png' });
});

test('an ask that only holds a link is a normal run in the folder', async ({ page }) => {
const calls = await signedIn(page);
await page.goto('/dev');
const ask = page.getByPlaceholder(/Ask, build/);
await ask.fill('What does https://www.acme.com say about pricing?', { timeout: 60_000 });
await expect(page.locator('[data-slot="redesign-offer"]')).toHaveCount(0);
await ask.press('Enter');
await expect.poll(() => sidebar(calls)).toEqual(['local_workspace_run_dev']);
});
});
44 changes: 44 additions & 0 deletions apps/hanzo-desktop/src/__tests__/developer-mode.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Developer mode in the window's own Settings: off for a new person, one switch,
* kept on this device, and the same switch the account card, ⌘K and a run's menu
* hold (@hanzo/build's `hanzo.dev_mode`), so turning it on here shows the process
* in Dev at once.
*/
import { DEV_MODE_KEY } from '@hanzo/build/dev-mode';
import { fireEvent, render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it } from 'vitest';

import { DesktopSettings } from '../desktop-shortcuts';

const page = () =>
render(<DesktopSettings isAuthenticated onSignIn={() => undefined} onBack={() => undefined} />);

describe('Developer mode in Settings', () => {
beforeEach(() => window.localStorage.clear());

it('is off for a new person, and says what it shows', () => {
page();
const mark = screen.getByRole('switch', { name: 'Developer mode' });
expect(mark).toHaveAttribute('aria-checked', 'false');
expect(screen.getByTestId('desktop-dev-mode')).toHaveTextContent(
'Shows the process: the terminal, the commands Hanzo runs and each step. Off, Hanzo shows the result.',
);
});

it('turns on with one press, is kept on this device, and turns off again', () => {
page();
const mark = screen.getByRole('switch', { name: 'Developer mode' });
fireEvent.click(mark);
expect(mark).toHaveAttribute('aria-checked', 'true');
expect(window.localStorage.getItem(DEV_MODE_KEY)).toBe('true');
fireEvent.click(mark);
expect(mark).toHaveAttribute('aria-checked', 'false');
expect(window.localStorage.getItem(DEV_MODE_KEY)).toBe('false');
});

it('opens on what the device kept', () => {
window.localStorage.setItem(DEV_MODE_KEY, 'true');
page();
expect(screen.getByRole('switch', { name: 'Developer mode' })).toHaveAttribute('aria-checked', 'true');
});
});
Loading
Loading