From c66db1ba119df5c906acd5142e61ff18190c0b85 Mon Sep 17 00:00:00 2001 From: Zach Kelling Date: Fri, 20 Nov 2026 19:20:36 -0800 Subject: [PATCH 1/2] @hanzo/build 0.2.135: skills for a person's work, recommended and added in one click (hanzo-inc/app#462) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Customize › Skills opens with the work the account already holds (Settings › Account), the catalogue skills that suit it, and one Add for the lot with each skill deselectable. The first-run card (Roles first) asks once and is kept per account. Claude-Session: https://claude.ai/code/session_015XYKLn69gF4x75RWePpDBV --- package.json | 2 +- src/api/pref.ts | 4 + src/customize/roles.tsx | 193 +++++++++++++++++++++++++++++++++++++++ src/customize/skills.tsx | 2 + src/index.ts | 2 + src/roles.test.ts | 45 +++++++++ src/roles.ts | 52 +++++++++++ src/settings/account.tsx | 16 +--- 8 files changed, 300 insertions(+), 16 deletions(-) create mode 100644 src/customize/roles.tsx create mode 100644 src/roles.test.ts create mode 100644 src/roles.ts diff --git a/package.json b/package.json index ad55489..abef5cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hanzo/build", - "version": "0.2.134", + "version": "0.2.135", "type": "module", "license": "Apache-2.0 OR MIT", "description": "Hanzo Build — say what you want, watch it built, deployed and running. The builder as a component, mounted by the Hanzo app at hanzo.ai.", diff --git a/src/api/pref.ts b/src/api/pref.ts index bc6cd4b..6a3d033 100644 --- a/src/api/pref.ts +++ b/src/api/pref.ts @@ -44,6 +44,8 @@ export interface Prefs { callName?: string /** What best describes their work. */ work?: string + /** Whether the recommended skills for their work were taken up or put off (customize/roles.tsx); unset until asked. */ + roles?: 'done' | 'skipped' /** What every coding run is told about how they like to work. */ instructions?: string code?: Code @@ -61,6 +63,7 @@ const THEMES: readonly Theme[] = ['system', 'light', 'dark'] const TEXTS: readonly Text[] = ['small', 'medium', 'large'] const MOTIONS: readonly Motion[] = ['system', 'reduced'] const MODES = ['build', 'plan'] as const +const ROLES = ['done', 'skipped'] as const const obj = (v: unknown): Record => (v && typeof v === 'object' && !Array.isArray(v) ? (v as Record) : {}) const text = (v: unknown): string | undefined => (typeof v === 'string' && v.trim() ? v : undefined) @@ -113,6 +116,7 @@ export function prefs(raw: unknown): Prefs { language: text(p.language), callName: text(p.callName), work: text(p.work), + roles: one(p.roles, ROLES), instructions: text(p.instructions), code: code(p.code), side: side(p.side), diff --git a/src/customize/roles.tsx b/src/customize/roles.tsx new file mode 100644 index 0000000..6336121 --- /dev/null +++ b/src/customize/roles.tsx @@ -0,0 +1,193 @@ +/** + * Skills for a person's work: pick what you do, see the skills that suit it, + * add them all in one click or leave some out first. + * + * It stands in two places. In Customize › Skills it is always there, for anyone + * who wants it. As the first run's card (`first`) it asks once, only a person + * who has not said what they work on and has not put it off, and goes away when + * they add the skills or say not now: the work is kept on the account + * (`Prefs.work`, the one Settings › Account holds) and so is the answer + * (`Prefs.roles`), so it follows them to every device and never returns. + * + * Adding a skill switches it on for the org (`toggle`), which is an org admin's + * to do; a member reads what is recommended and is told who adds it. + * + * Its words are the reader's language (@hanzo/i18n `t`); a skill's name and + * description are the catalogue's, drawn as given. + */ +import { SizableText, XStack, YStack } from '@hanzo/gui' +import { useI18n } from '@hanzo/i18n/react' +import { Check } from '@hanzogui/lucide-icons-2' +import { Button } from '@hanzo/ui' +import { useEffect, useMemo, useState } from 'react' + +import { active, brand, tool } from '../api/skills.ts' +import { toggle, type Tool } from '../api/tools.ts' +import { useHost, useTarget } from '../host.tsx' +import { usePrefs } from '../prefs.tsx' +import { recommend, WORK } from '../roles.ts' +import { useLoad } from './load.ts' +import { say } from './say.ts' +import { FilterPills, Part } from './ui.tsx' + +interface Notice { + text: string + error?: boolean +} + +export function Roles({ first = false }: { first?: boolean }) { + const { t } = useI18n() + const host = useHost() + const target = useTarget() + const state = usePrefs(false) + const signed = Boolean(host.person) + const may = signed && host.admin + const kept = state?.prefs.work ?? '' + const [work, setWork] = useState(kept) + const shelf = useLoad(signed ? () => brand(target) : null, null, [target.api, signed]) + const on = useLoad(signed ? () => active(target) : null, [] as Tool[], [target, signed]) + const [left, setLeft] = useState>(new Set()) + const [busy, setBusy] = useState(false) + const [notice, setNotice] = useState(null) + // The card stays up with its word once the skills are added, and goes on the next visit. + const [said, setSaid] = useState(false) + + // The account's work arrives after the first frame; take it up unless the person has already chosen another. + useEffect(() => { + if (kept) setWork((now) => now || kept) + }, [kept]) + useEffect(() => setLeft(new Set()), [work]) + + const lit = useMemo(() => new Set(on.value.map((x) => x.name)), [on.value]) + const suited = useMemo(() => recommend(work, shelf.value), [work, shelf.value]) + const fresh = suited.filter((e) => !lit.has(tool(e.name))) + const taken = fresh.filter((e) => !left.has(e.name)) + + // The first run's card: only a signed-in admin who has said nothing about their work and not put this off. + if (!signed || !state) return null + if (first && !said && (!may || kept || state.prefs.roles || shelf.error)) return null + + const choose = (id: string) => { + setWork(id) + setNotice(null) + } + + const add = async () => { + setBusy(true) + setNotice(null) + try { + await toggle(target, taken.map((e) => tool(e.name))) + await state.save({ work, roles: 'done' }) + on.reload() + setSaid(true) + setNotice({ text: t('{n} skills are on', { n: taken.length }) }) + } catch (e) { + setNotice({ text: say(e, t), error: true }) + } finally { + setBusy(false) + } + } + + const later = async () => { + try { + await state.save({ roles: 'skipped' }) + } catch (e) { + setNotice({ text: say(e, t), error: true }) + } + } + + // Put off, the card is gone; added, it is gone from the next visit. + if (first && state.prefs.roles === 'skipped') return null + + return ( + + + ({ id: w.id, label: t(w.label) }))} onChange={choose} maxVisibleDesktop={11} mobileLimit={5} /> + {work && !suited.length ? ( + + {t('Nothing is recommended for this yet. Browse the skills to add any you like.')} + + ) : null} + {suited.length ? ( + + {suited.map((e) => { + const isOn = lit.has(tool(e.name)) + const picked = !isOn && !left.has(e.name) + return ( + { + if (isOn || !may) return + setLeft((s) => { + const next = new Set(s) + if (next.has(e.name)) next.delete(e.name) + else next.add(e.name) + return next + }) + }} + items="flex-start" + gap="$2.5" + p="$2.5" + rounded="$3" + borderWidth={1} + borderColor={picked ? 'var(--border-strong)' : '$borderColor'} + bg={picked ? '$panel' : 'transparent'} + cursor={isOn || !may ? 'default' : 'pointer'} + $max-sm={{ minH: 44 }} + > + + {isOn || picked ? : null} + + + + {e.name} + + + {e.description} + + + {isOn ? ( + + {t('Added')} + + ) : null} + + ) + })} + + ) : null} + {suited.length && !may ? ( + + {t('An org admin adds skills. Ask them to add these.')} + + ) : null} + {notice ? ( + + {notice.text} + + ) : null} + + {suited.length ? ( + + ) : null} + {first ? ( + + ) : null} + + + + ) +} diff --git a/src/customize/skills.tsx b/src/customize/skills.tsx index 9577628..7b6fac9 100644 --- a/src/customize/skills.tsx +++ b/src/customize/skills.tsx @@ -21,6 +21,7 @@ import { active, authored, brand, document, nameOf, remove, tool, write, type Ca import { toggle, type Tool } from '../api/tools.ts' import { useHost, useTarget } from '../host.tsx' import { useLoad } from './load.ts' +import { Roles } from './roles.tsx' import { say } from './say.ts' import { Add, Confirm, day, Empty, Failed, Field, FilterPills, Grid, Mark, matches, MenuTrigger, Part, Sheet, Soft, Tile, TilesSkeleton, type Pane, useCount, Visitor } from './ui.tsx' @@ -172,6 +173,7 @@ export function Skills({ view, q, adding, onAdding, onView, onCount }: Pane) { return ( + {signed && !q.trim() ? : null} {shelf.error && !shelf.value ? ( diff --git a/src/index.ts b/src/index.ts index 02c8aba..2143622 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,6 +46,8 @@ export type { Done, Folder, Local } from './local.ts' export type { Session, Status } from './api/sessions.ts' export { talks } from './api/talk.ts' export { detect, type Detected } from './api/skills.ts' +export { Roles } from './customize/roles.tsx' +export { recommend, WORK } from './roles.ts' export type { Read } from './data.ts' export { href, parse, path, PLACES, route, SESSION, SLUG, type Route, type Screen } from './route.ts' diff --git a/src/roles.test.ts b/src/roles.test.ts new file mode 100644 index 0000000..c8c9318 --- /dev/null +++ b/src/roles.test.ts @@ -0,0 +1,45 @@ +import { describe, expect, it } from 'vitest' + +import type { Catalogue } from './api/skills.ts' +import { MOST, RECOMMENDED, recommend, WORK } from './roles.ts' + +const every = (names: readonly string[]): Catalogue => ({ + skills: names.map((name) => ({ name, description: `What ${name} does`, product: name.split('_')[0]! })), + products: [], +}) + +describe('the skills a work recommends', () => { + it('names a list for every work the account offers, and none for "something else"', () => { + for (const w of WORK) expect(w.id in RECOMMENDED, w.id).toBe(w.id !== 'other') + expect(Object.keys(RECOMMENDED).every((id) => WORK.some((w) => w.id === id))).toBe(true) + }) + + it('keeps each list within what one click can sensibly add, and free of repeats', () => { + for (const [id, names] of Object.entries(RECOMMENDED)) { + expect(names.length, id).toBeLessThanOrEqual(MOST) + expect(new Set(names).size, id).toBe(names.length) + } + }) + + it('offers the catalogue entries of the work, in the order the list gives them', () => { + const all = every(Object.values(RECOMMENDED).flat()) + expect(recommend('marketing', all).map((e) => e.name)).toEqual([...RECOMMENDED.marketing!]) + expect(recommend('marketing', all)[0]).toMatchObject({ description: 'What marketing_summary does', product: 'marketing' }) + }) + + it('leaves out a skill the catalogue no longer serves, rather than offering what cannot be added', () => { + const all = every(RECOMMENDED.education!.filter((n) => n !== 'knowledge_graph')) + const names = recommend('education', all).map((e) => e.name) + expect(names).not.toContain('knowledge_graph') + expect(names).toEqual(RECOMMENDED.education!.filter((n) => n !== 'knowledge_graph')) + }) + + it('offers nothing for no work, an unknown one, "something else", or before the catalogue is read', () => { + const all = every(Object.values(RECOMMENDED).flat()) + expect(recommend(undefined, all)).toEqual([]) + expect(recommend('', all)).toEqual([]) + expect(recommend('astronaut', all)).toEqual([]) + expect(recommend('other', all)).toEqual([]) + expect(recommend('marketing', null)).toEqual([]) + }) +}) diff --git a/src/roles.ts b/src/roles.ts new file mode 100644 index 0000000..687b7de --- /dev/null +++ b/src/roles.ts @@ -0,0 +1,52 @@ +/** + * What a person's work recommends: the skills of Hanzo's catalogue that suit it, + * so a new person starts with the ones that matter to them switched on rather + * than a list of hundreds. + * + * The work is the account's own (Settings › Account, `Prefs.work`), one list for + * both. Each work names the catalogue skills that read the part of the business + * it lives in; `recommend` keeps the ones the catalogue serves today, in the + * order given, so a skill the platform renames is left out and never offered. + */ +import { phrase } from '@hanzo/i18n' + +import type { Catalogue, Entry } from './api/skills.ts' + +/** What a person may say they work on, each label English and marked (`phrase`), drawn through `t`. */ +export const WORK = [ + { id: 'director', label: phrase('Director or executive') }, + { id: 'engineering', label: phrase('Software engineering') }, + { id: 'data', label: phrase('Data science') }, + { id: 'design', label: phrase('Design') }, + { id: 'product', label: phrase('Product management') }, + { id: 'research', label: phrase('Research') }, + { id: 'writing', label: phrase('Writing') }, + { id: 'education', label: phrase('Education') }, + { id: 'operations', label: phrase('Operations') }, + { id: 'marketing', label: phrase('Marketing and sales') }, + { id: 'other', label: phrase('Something else') }, +] + +/** The most skills one work recommends: a set small enough to read before it is added. */ +export const MOST = 8 + +/** The catalogue skills each work is recommended, best first. 'other' has none: it is a way to skip. */ +export const RECOMMENDED: Record = { + director: ['books_metrics', 'books_pnl', 'books_position', 'captable_summary', 'dataroom_documents', 'guide_suggest', 'team_members', 'billing_usage'], + engineering: ['git_repos', 'git_runs', 'code_ask', 'code_search', 'deploy_applications', 'ci_runs', 'project_deployments', 'sandbox_sandbox'], + data: ['dataset_dataset', 'dataset_lineage', 'eval_runs', 'eval_scores', 'knowledge_graph', 'metrics_query', 'experiment_experiment', 'research_runs'], + design: ['studio_documents', 'studio_templates', 'studio_brands', 'studio_flows', 'studio_runs', 'content_board', 'videos_content', 'library_library'], + product: ['project_project', 'task_board', 'task_issues', 'experiment_experiment', 'flag_defs', 'form_forms', 'guide_strategies', 'research_studies'], + research: ['research_papers', 'research_studies', 'research_evidence', 'research_experiments', 'research_compare', 'benchmark_compare', 'knowledge_files', 'websearch_search'], + writing: ['content_board', 'content_channels', 'content_lifecycle', 'translate_memory', 'library_library', 'team_docs', 'seo_rates', 'websearch_search'], + education: ['knowledge_files', 'knowledge_graph', 'library_library', 'meet_session', 'form_forms', 'content_board', 'translate_memory', 'team_docs'], + operations: ['task_board', 'team_members', 'books_inbox', 'tax_filings', 'compliance_status', 'billing_invoices', 'treasury_accounts', 'team_inbox'], + marketing: ['marketing_summary', 'marketing_campaigns', 'marketing_audiences', 'marketing_broadcasts', 'marketing_sequences', 'campaign_metrics', 'social_posts', 'ad_summary'], +} + +/** The catalogue's skills that `work` recommends, in the order the list gives them, at most `MOST`. */ +export function recommend(work: string | undefined, catalogue: Catalogue | null): Entry[] { + if (!work || !catalogue) return [] + const served = new Map(catalogue.skills.map((e) => [e.name, e])) + return (RECOMMENDED[work] ?? []).flatMap((name) => served.get(name) ?? []).slice(0, MOST) +} diff --git a/src/settings/account.tsx b/src/settings/account.tsx index 8b0acf3..52db415 100644 --- a/src/settings/account.tsx +++ b/src/settings/account.tsx @@ -10,7 +10,6 @@ * an organization's id are drawn as given. */ import { SizableText, XStack, YStack } from '@hanzo/gui' -import { phrase } from '@hanzo/i18n' import { useI18n } from '@hanzo/i18n/react' import { Check, Copy, LogOut } from '@hanzogui/lucide-icons-2' import { Button, Input, Textarea } from '@hanzo/ui' @@ -23,22 +22,9 @@ import { PHOTO, photo, rename } from '../api/profile.ts' import { copy } from '../clipboard.ts' import { useHost, useTarget } from '../host.tsx' import { usePrefs } from '../prefs.tsx' +import { WORK } from '../roles.ts' import { Card, Field, Group, Heading, Note, Row, Soft } from './ui.tsx' -/** What a person may say they work on, each label English and marked (`phrase`), drawn through `t`. */ -export const WORK = [ - { id: 'engineering', label: phrase('Software engineering') }, - { id: 'data', label: phrase('Data science') }, - { id: 'design', label: phrase('Design') }, - { id: 'product', label: phrase('Product management') }, - { id: 'research', label: phrase('Research') }, - { id: 'writing', label: phrase('Writing') }, - { id: 'education', label: phrase('Education') }, - { id: 'operations', label: phrase('Operations') }, - { id: 'marketing', label: phrase('Marketing and sales') }, - { id: 'other', label: phrase('Something else') }, -] - /** Long enough for real guidance, short enough to sit in the settings document beside everything else. */ const INSTRUCTIONS = 3000 From ec7f74570fc87d9585f62c0cf69b81aaf45996f4 Mon Sep 17 00:00:00 2001 From: Zach Kelling Date: Fri, 20 Nov 2026 19:21:06 -0800 Subject: [PATCH 2/2] build: the first-run card draws only where the builder's host and settings are mounted Claude-Session: https://claude.ai/code/session_015XYKLn69gF4x75RWePpDBV --- src/customize/roles.tsx | 14 ++++++++++---- src/host.tsx | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/customize/roles.tsx b/src/customize/roles.tsx index 6336121..ef4b429 100644 --- a/src/customize/roles.tsx +++ b/src/customize/roles.tsx @@ -23,8 +23,8 @@ import { useEffect, useMemo, useState } from 'react' import { active, brand, tool } from '../api/skills.ts' import { toggle, type Tool } from '../api/tools.ts' -import { useHost, useTarget } from '../host.tsx' -import { usePrefs } from '../prefs.tsx' +import { useHost, useHosted, useTarget } from '../host.tsx' +import { usePrefs, type PrefState } from '../prefs.tsx' import { recommend, WORK } from '../roles.ts' import { useLoad } from './load.ts' import { say } from './say.ts' @@ -35,11 +35,17 @@ interface Notice { error?: boolean } +/** Drawn only where the builder's host and settings are mounted, so a chat drawn without them draws nothing. */ export function Roles({ first = false }: { first?: boolean }) { + const hosted = useHosted() + const state = usePrefs(false) + return hosted && state ? : null +} + +function Suggest({ first, state }: { first: boolean; state: PrefState }) { const { t } = useI18n() const host = useHost() const target = useTarget() - const state = usePrefs(false) const signed = Boolean(host.person) const may = signed && host.admin const kept = state?.prefs.work ?? '' @@ -64,7 +70,7 @@ export function Roles({ first = false }: { first?: boolean }) { const taken = fresh.filter((e) => !left.has(e.name)) // The first run's card: only a signed-in admin who has said nothing about their work and not put this off. - if (!signed || !state) return null + if (!signed) return null if (first && !said && (!may || kept || state.prefs.roles || shelf.error)) return null const choose = (id: string) => { diff --git a/src/host.tsx b/src/host.tsx index 36d0b12..c22cab4 100644 --- a/src/host.tsx +++ b/src/host.tsx @@ -137,6 +137,11 @@ export function useHost(): Host { return h } +/** The host, or null where none is mounted: a surface that may be drawn without one (the first run's card in Chat). */ +export function useHosted(): Host | null { + return useContext(Context) +} + /** The host's way of showing a page, where one is mounted and has one. The side panel is drawn without a host too (hanzo.team's rooms). */ export function useBrowse(): Browse | null { return useContext(Context)?.browse ?? null