@hanzo/build 0.2.127 → 0.2.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import type { Say } from '@hanzo/i18n/react';
2
+ import { type Names } from '../names.ts';
2
3
  import { type Target } from './call.ts';
3
4
  export declare const KINDS: readonly ['laptop', 'gpu', 'cloud', 'cluster', 'machine'];
4
5
  export type Kind = (typeof KINDS)[number];
@@ -69,9 +70,13 @@ export declare function formatBytes(bytes?: number): string;
69
70
  export declare function formatPercent(fraction?: number): string;
70
71
  export declare function formatRelative(isoDate?: string): string;
71
72
  export declare function specSummary(m: Machine): string;
73
+ /** The key a machine's name is kept under (names.ts): its hostname, else its label, else its id. */
74
+ export declare const machineKey: (m: Pick<Machine, 'host' | 'label' | 'id'>) => string;
75
+ /** A machine as a person reads it: the name they gave it (`names`, from `useDeviceNames`), else its own as a person says it. */
72
76
  export declare function displayMachine(m: Machine, opts?: {
73
77
  devMode?: boolean;
74
78
  say?: Say;
79
+ names?: Names;
75
80
  }): {
76
81
  title: string;
77
82
  detail?: string;
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { phrase } from '@hanzo/i18n';
17
17
  import { formatDeviceLabel } from '../dev-mode.js';
18
+ import { deviceKey } from '../names.js';
18
19
  import { call, Refusal, seg } from './call.js';
19
20
  export const KINDS = ['laptop', 'gpu', 'cloud', 'cluster', 'machine'];
20
21
  const str = (v) => (typeof v === 'string' ? v : '');
@@ -72,8 +73,11 @@ function hardwareSummary(m) {
72
73
  const host = m.host && m.host !== hw ? m.host : '';
73
74
  return [hw, host].filter(Boolean).join(' · ');
74
75
  }
76
+ /** The key a machine's name is kept under (names.ts): its hostname, else its label, else its id. */
77
+ export const machineKey = (m) => deviceKey(m.host, m.label, m.id);
78
+ /** A machine as a person reads it: the name they gave it (`names`, from `useDeviceNames`), else its own as a person says it. */
75
79
  export function displayMachine(m, opts) {
76
- return formatDeviceLabel(m.label, { hardware: hardwareSummary(m), host: m.host, devMode: opts?.devMode, say: opts?.say });
80
+ return formatDeviceLabel(m.label, { hardware: hardwareSummary(m), host: m.host, name: opts?.names?.[machineKey(m)], devMode: opts?.devMode, say: opts?.say });
77
81
  }
78
82
  export function machine(raw) {
79
83
  const o = (raw && typeof raw === 'object' ? raw : {});
@@ -1,4 +1,5 @@
1
1
  import type { Say } from '@hanzo/i18n/react';
2
+ import { type Names } from '../names.ts';
2
3
  import type { Target } from './call.ts';
3
4
  export interface Place {
4
5
  /** `tgt_…`, or '' for the cloud workspace. */
@@ -10,13 +11,17 @@ export interface Place {
10
11
  status: string;
11
12
  /** "10 vCPU / 122G / 1× GB10", when the machine reported one. */
12
13
  capacity: string;
14
+ /** The hostname its runs report, or '' (the cloud workspace, or a machine addressed by id only). */
15
+ host?: string;
13
16
  }
14
17
  /** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */
15
18
  export declare const SANDBOX: Place;
16
19
  export declare function places(t: Target): Promise<Place[]>;
20
+ /** A place as a person reads it: the name they gave the machine (`names`, from `useDeviceNames`), else its own as a person says it. */
17
21
  export declare function displayPlace(p: Place, opts?: {
18
22
  devMode?: boolean;
19
23
  say?: Say;
24
+ names?: Names;
20
25
  }): {
21
26
  title: string;
22
27
  detail?: string;
package/lib/api/places.js CHANGED
@@ -9,19 +9,21 @@
9
9
  */
10
10
  import { phrase } from '@hanzo/i18n';
11
11
  import { formatDeviceLabel } from '../dev-mode.js';
12
+ import { deviceKey } from '../names.js';
12
13
  import { english } from '../say.js';
13
14
  import { machines, state } from './machines.js';
14
15
  /** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */
15
16
  export const SANDBOX = { id: '', label: phrase('Hanzo sandbox'), kind: 'sandbox', status: 'online', capacity: '' };
16
17
  export async function places(t) {
17
18
  const list = await machines(t);
18
- return [SANDBOX, ...list.map((m) => ({ id: m.id, label: m.label, kind: m.kind, status: state(m), capacity: m.capacity }))];
19
+ return [SANDBOX, ...list.map((m) => ({ id: m.id, label: m.label, kind: m.kind, status: state(m), capacity: m.capacity, ...(m.host ? { host: m.host } : {}) }))];
19
20
  }
21
+ /** A place as a person reads it: the name they gave the machine (`names`, from `useDeviceNames`), else its own as a person says it. */
20
22
  export function displayPlace(p, opts) {
21
23
  const say = opts?.say ?? english;
22
24
  if (!p.id)
23
25
  return opts?.devMode ? { title: 'Cloud' } : { title: say('Auto (Cloud)'), detail: say('Runs automatically in your Hanzo cloud workspace') };
24
- return formatDeviceLabel(p.label, { hardware: p.capacity, devMode: opts?.devMode, say });
26
+ return formatDeviceLabel(p.label, { hardware: p.capacity, host: p.host, name: opts?.names?.[deviceKey(p.host, p.label, p.id)], devMode: opts?.devMode, say });
25
27
  }
26
28
  /** Whether a run sent here now would be taken. */
27
29
  export const ready = (p) => p.status === 'online';
package/lib/api/pref.d.ts CHANGED
@@ -46,12 +46,20 @@ export interface Prefs {
46
46
  side?: Side;
47
47
  /** The suggestions under the composer: when made, from what, the rows, and those dismissed (suggest.ts). */
48
48
  suggest?: Kept;
49
+ /** What the person calls their devices and shells, by device key (names.ts). */
50
+ deviceNames?: Record<string, string>;
49
51
  }
50
52
  /** A change: a key set to a value, or to null to delete it. */
51
53
  export type Patch = {
52
54
  [K in keyof Prefs]?: Prefs[K] | null;
53
55
  };
54
56
  export declare function code(raw: unknown): Code | undefined;
57
+ /** The longest device or shell name kept, in characters: a menu row's worth. */
58
+ export declare const NAME_MAX = 60;
59
+ /** A name as kept: trimmed, one line, at most `NAME_MAX` characters; '' for none. */
60
+ export declare function tidyName(name: unknown): string;
61
+ /** Device and shell names from a stored value, dropping what is not a name; undefined for none. */
62
+ export declare function deviceNames(raw: unknown): Record<string, string> | undefined;
55
63
  export declare function side(raw: unknown): Side | undefined;
56
64
  /** The builder's keys from a whole preference document. */
57
65
  export declare function prefs(raw: unknown): Prefs;
package/lib/api/pref.js CHANGED
@@ -31,6 +31,22 @@ export function code(raw) {
31
31
  });
32
32
  return Object.keys(out).length ? out : undefined;
33
33
  }
34
+ /** The longest device or shell name kept, in characters: a menu row's worth. */
35
+ export const NAME_MAX = 60;
36
+ /** A name as kept: trimmed, one line, at most `NAME_MAX` characters; '' for none. */
37
+ export function tidyName(name) {
38
+ return typeof name === 'string' ? name.replace(/\s+/g, ' ').trim().slice(0, NAME_MAX) : '';
39
+ }
40
+ /** Device and shell names from a stored value, dropping what is not a name; undefined for none. */
41
+ export function deviceNames(raw) {
42
+ const out = {};
43
+ for (const [k, v] of Object.entries(obj(raw))) {
44
+ const name = tidyName(v);
45
+ if (k && name)
46
+ out[k] = name;
47
+ }
48
+ return Object.keys(out).length ? out : undefined;
49
+ }
34
50
  export function side(raw) {
35
51
  const w = obj(raw).width;
36
52
  return typeof w === 'number' && Number.isFinite(w) && w > 0 ? { width: Math.round(w) } : undefined;
@@ -49,6 +65,7 @@ export function prefs(raw) {
49
65
  code: code(p.code),
50
66
  side: side(p.side),
51
67
  suggest: kept(p.suggest),
68
+ deviceNames: deviceNames(p.deviceNames),
52
69
  });
53
70
  }
54
71
  /** What a document reads as once `patch` is merged into it — the platform's own rule. */
package/lib/dev-mode.d.ts CHANGED
@@ -7,14 +7,18 @@ export declare function useDevMode(): [boolean, (next: boolean) => void];
7
7
  export interface DeviceLabelOptions {
8
8
  hardware?: string | null;
9
9
  host?: string | null;
10
+ /** The name the person gave it (names.ts): it wins, for a developer too. */
11
+ name?: string | null;
10
12
  devMode?: boolean;
11
13
  /** The reader's `t`; English where none is given. */
12
14
  say?: Say;
13
15
  }
14
16
  /**
15
- * A device as a person reads it. A developer sees the name the machine reports.
16
- * Anyone else sees that name tidied (`MacBook-Pro.local` → `MacBook-Pro`) with
17
- * the hardware beneath, and the cloud workspace in plain words.
17
+ * A device as a person reads it. A name the person gave it wins. Otherwise a
18
+ * developer sees the name the machine reports, and anyone else sees it as a
19
+ * person says it (`Alexs-MacBook-Pro.local` → "Alex's MacBook Pro", names.ts
20
+ * `friendly`), with the hardware and the hostname beneath, and the cloud
21
+ * workspace in plain words.
18
22
  */
19
23
  export declare function formatDeviceLabel(raw: string | null | undefined, opts?: DeviceLabelOptions): {
20
24
  title: string;
package/lib/dev-mode.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useCallback, useSyncExternalStore } from 'react';
2
+ import { friendly } from './names.js';
2
3
  import { english } from './say.js';
3
4
  export const DEV_MODE_KEY = 'hanzo.dev_mode';
4
5
  export const DEV_MODE_EVENT = 'hanzo:dev-mode';
@@ -58,13 +59,18 @@ function mergeDetail(...parts) {
58
59
  return out.length ? out.join(' · ') : undefined;
59
60
  }
60
61
  /**
61
- * A device as a person reads it. A developer sees the name the machine reports.
62
- * Anyone else sees that name tidied (`MacBook-Pro.local` → `MacBook-Pro`) with
63
- * the hardware beneath, and the cloud workspace in plain words.
62
+ * A device as a person reads it. A name the person gave it wins. Otherwise a
63
+ * developer sees the name the machine reports, and anyone else sees it as a
64
+ * person says it (`Alexs-MacBook-Pro.local` → "Alex's MacBook Pro", names.ts
65
+ * `friendly`), with the hardware and the hostname beneath, and the cloud
66
+ * workspace in plain words.
64
67
  */
65
68
  export function formatDeviceLabel(raw, opts = {}) {
66
69
  const say = opts.say ?? english;
67
70
  const name = (raw ?? '').trim();
71
+ const own = (opts.name ?? '').trim();
72
+ if (own)
73
+ return { title: own, detail: mergeDetail(opts.hardware, opts.host, name !== own ? name : undefined) };
68
74
  if (opts.devMode)
69
75
  return name ? { title: name, detail: mergeDetail(opts.hardware, opts.host && opts.host !== name ? opts.host : undefined) } : { title: 'Cloud' };
70
76
  const lower = name.toLowerCase();
@@ -74,7 +80,7 @@ export function formatDeviceLabel(raw, opts = {}) {
74
80
  const tidy = name
75
81
  .split(/\s*·\s*/)[0]
76
82
  .replace(/\s*\((?:shell|desk|tmux|tty)[^)]*\)\s*$/i, '')
77
- .replace(/\.(local|lan|home|internal)$/i, '')
78
83
  .trim();
79
- return { title: tidy || name, detail: mergeDetail(opts.hardware, opts.host, name !== tidy ? name : undefined) };
84
+ const title = friendly(tidy) || name;
85
+ return { title, detail: mergeDetail(opts.hardware, opts.host, name !== title ? name : undefined) };
80
86
  }
package/lib/index.d.ts CHANGED
@@ -61,6 +61,9 @@ export { artifacts, blob, lead, renders, Reply, Served, speakable, speaker, type
61
61
  export { frames, Page, Panel, PanelToggle, type Kind, type PageProps, type PanelProps, type Suggestion } from './panel.tsx';
62
62
  export { SideProvider, useSplit, type Split } from './side.tsx';
63
63
  export { PrefsProvider } from './prefs.tsx';
64
+ export { deviceKey, friendly, heldNames, NAMES_KEY, rename, shellKey, useDeviceNames, type Names } from './names.ts';
65
+ export { formatDeviceLabel, type DeviceLabelOptions } from './dev-mode.ts';
66
+ export { Rename } from './ask.tsx';
64
67
  export { kinds, Summary, useKinds, type Entry, type Section } from './summary.tsx';
65
68
  /**
66
69
  * The composer's plugins, the same in Chat and Dev: `usePlugins` answers those
package/lib/index.js CHANGED
@@ -56,6 +56,9 @@ export { artifacts, blob, lead, renders, Reply, Served, speakable, speaker } fro
56
56
  export { frames, Page, Panel, PanelToggle } from './panel.js';
57
57
  export { SideProvider, useSplit } from './side.js';
58
58
  export { PrefsProvider } from './prefs.js';
59
+ export { deviceKey, friendly, heldNames, NAMES_KEY, rename, shellKey, useDeviceNames } from './names.js';
60
+ export { formatDeviceLabel } from './dev-mode.js';
61
+ export { Rename } from './ask.js';
59
62
  export { kinds, Summary, useKinds } from './summary.js';
60
63
  /**
61
64
  * The composer's plugins, the same in Chat and Dev: `usePlugins` answers those
package/lib/landing.js CHANGED
@@ -38,6 +38,7 @@ import { homes as readHomes } from './api/work.js';
38
38
  import { SetupDialog } from './environment.js';
39
39
  import { limits as readLimits } from './api/models.js';
40
40
  import { displayPlace, ready, SANDBOX } from './api/places.js';
41
+ import { useDeviceNames } from './names.js';
41
42
  import { Address } from './ask.js';
42
43
  import { asHub, gone, isForge, isHub, settle } from './choice.js';
43
44
  import { useCached, useKept, usePlaces, useRead } from './data.js';
@@ -138,6 +139,7 @@ export function Landing({ onStarted }) {
138
139
  // eslint-disable-next-line react-hooks/exhaustive-deps
139
140
  }, []);
140
141
  const places = usePlaces(target, signed);
142
+ const names = useDeviceNames(signed ? target : null);
141
143
  // The model and effort Chat shares, and dictation into the ask.
142
144
  const { limits } = useLimits(signed ? (signal) => readLimits(target, signal) : null, target);
143
145
  const mind = useMind(target, limits?.plan, host.topUp);
@@ -389,7 +391,7 @@ export function Landing({ onStarted }) {
389
391
  };
390
392
  // Cloud is the managed workspace, set up by the chosen project's environment; the rest are the org's machines.
391
393
  const placeItems = useMemo(() => (places.value.length ? places.value : [SANDBOX]).map((p) => {
392
- const display = displayPlace(p, { devMode, say: t });
394
+ const display = displayPlace(p, { devMode, say: t, names });
393
395
  return {
394
396
  id: p.id || 'sandbox',
395
397
  label: display.title,
@@ -407,8 +409,8 @@ export function Landing({ onStarted }) {
407
409
  disabled: !ready(p),
408
410
  place: p,
409
411
  };
410
- }), [places.value, devMode, t]);
411
- const activePlaceDisplay = useMemo(() => displayPlace(place, { devMode, say: t }), [place, devMode, t]);
412
+ }), [places.value, devMode, t, names]);
413
+ const activePlaceDisplay = useMemo(() => displayPlace(place, { devMode, say: t, names }), [place, devMode, t, names]);
412
414
  const placeTooltip = place.id
413
415
  ? t('Runs locally in your Hanzo folder')
414
416
  : t('Runs automatically in your Hanzo cloud workspace');
package/lib/names.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { Target } from './api/call.ts';
2
+ import { NAME_MAX, tidyName } from './api/pref.ts';
3
+ export { NAME_MAX, tidyName };
4
+ /** Where this browser keeps its copy of the names. */
5
+ export declare const NAMES_KEY = "hanzo.device.names";
6
+ export type Names = Readonly<Record<string, string>>;
7
+ /** The key a device's name is kept under: the first of its hostname, label and id that says something, without a local-network suffix, lowercased. */
8
+ export declare function deviceKey(...parts: (string | null | undefined)[]): string;
9
+ /** The key a shell's name is kept under: its device's key, then its own name. */
10
+ export declare function shellKey(device: string, shell: string): string;
11
+ /** The names from a stored value, dropping what is not a name. */
12
+ export declare function names(raw: unknown): Record<string, string>;
13
+ /**
14
+ * A hostname as a person says it.
15
+ *
16
+ * Alexs-MacBook-Pro.local → Alex's MacBook Pro (macOS drops the apostrophe from "Alex's MacBook Pro")
17
+ * alexs-mbp-2.local → Alex's MacBook Pro (a "-2" is macOS avoiding a name already on the network)
18
+ * MacBook-Air.local → MacBook Air
19
+ * studio-Mac-mini → Studio Mac mini
20
+ * DESKTOP-4F7K2QX → Windows PC (Windows' own made-up name)
21
+ * spark-dgx.lan → spark-dgx (a name someone chose stays theirs)
22
+ */
23
+ export declare function friendly(host: string): string;
24
+ /** The names as this page holds them now. */
25
+ export declare function heldNames(): Names;
26
+ /** The name a person gave the device or shell under `key`, if any. */
27
+ export declare function nameOf(key: string): string | undefined;
28
+ /**
29
+ * Name the device or shell under `key` (an empty name clears it, back to its own).
30
+ * With a `target`, the names are saved on the account too; that save failing
31
+ * keeps the name in this browser.
32
+ */
33
+ export declare function rename(key: string, name: string, target?: Target | null): Promise<void>;
34
+ /**
35
+ * The names a person gave their devices and shells, kept current: a rename on
36
+ * any surface of this page redraws every one that reads them. With a signed-in
37
+ * `target`, the account's names are read once per page and win over this
38
+ * browser's copy.
39
+ */
40
+ export declare function useDeviceNames(target?: Target | null): Names;
package/lib/names.js ADDED
@@ -0,0 +1,189 @@
1
+ /**
2
+ * What a person calls a device or a shell (hanzo-inc/app issue 311).
3
+ *
4
+ * A machine reports its hostname: `Alexs-MacBook-Pro.local`, and its hardware
5
+ * beside it. A person reads a name: "Alex's MacBook Pro". `friendly` turns the
6
+ * hostname into that name. The hardware, the hostname and the chip stay in the
7
+ * detail (`formatDeviceLabel`).
8
+ *
9
+ * A person can also rename a device or a shell. Their name wins everywhere the
10
+ * device is drawn: Dev's "where to run", Settings → Machines, Tabs and the
11
+ * sidebar. It is kept per person on the account (`/v1/pref`, key
12
+ * `deviceNames`), so it follows them to every surface. It is not kept on the
13
+ * machine's record: `hanzo beat` re-registers the record under its hostname on
14
+ * every heartbeat, which would undo the rename within a minute. A copy is also
15
+ * kept in this browser, so the first frame already has it.
16
+ *
17
+ * A name is kept under the device's key (`deviceKey`). That key is the same
18
+ * string whichever surface draws the device: its hostname without the
19
+ * local-network suffix, lowercased, else its label, else its id. Tabs keys a
20
+ * machine by `host || label || id` too. A shell is kept under
21
+ * `<device key>/<shell name>` (`shellKey`).
22
+ */
23
+ import { useEffect, useSyncExternalStore } from 'react';
24
+ import { deviceNames, NAME_MAX, read, save, tidyName } from './api/pref.js';
25
+ export { NAME_MAX, tidyName };
26
+ /** Where this browser keeps its copy of the names. */
27
+ export const NAMES_KEY = 'hanzo.device.names';
28
+ const SUFFIX = /\.(local|lan|home|internal|localdomain)$/i;
29
+ /** The key a device's name is kept under: the first of its hostname, label and id that says something, without a local-network suffix, lowercased. */
30
+ export function deviceKey(...parts) {
31
+ const first = parts.map((p) => (p ?? '').trim()).find(Boolean) ?? '';
32
+ return first.replace(SUFFIX, '').toLowerCase();
33
+ }
34
+ /** The key a shell's name is kept under: its device's key, then its own name. */
35
+ export function shellKey(device, shell) {
36
+ return `${deviceKey(device)}/${shell.trim().toLowerCase()}`;
37
+ }
38
+ /** The names from a stored value, dropping what is not a name. */
39
+ export function names(raw) {
40
+ return deviceNames(raw) ?? {};
41
+ }
42
+ /** Apple's models, as the tail of a hostname spells them and as a person says them. */
43
+ const MODELS = [
44
+ [/^(macbook-?pro|mbp)$/i, 'MacBook Pro'],
45
+ [/^(macbook-?air|mba)$/i, 'MacBook Air'],
46
+ [/^macbook$/i, 'MacBook'],
47
+ [/^imac(-?pro)?$/i, 'iMac'],
48
+ [/^mac-?mini$/i, 'Mac mini'],
49
+ [/^mac-?studio$/i, 'Mac Studio'],
50
+ [/^mac-?pro$/i, 'Mac Pro'],
51
+ ];
52
+ const model = (tail) => MODELS.find(([re]) => re.test(tail))?.[1];
53
+ const capital = (word) => (word ? word.charAt(0).toUpperCase() + word.slice(1) : word);
54
+ /**
55
+ * A hostname as a person says it.
56
+ *
57
+ * Alexs-MacBook-Pro.local → Alex's MacBook Pro (macOS drops the apostrophe from "Alex's MacBook Pro")
58
+ * alexs-mbp-2.local → Alex's MacBook Pro (a "-2" is macOS avoiding a name already on the network)
59
+ * MacBook-Air.local → MacBook Air
60
+ * studio-Mac-mini → Studio Mac mini
61
+ * DESKTOP-4F7K2QX → Windows PC (Windows' own made-up name)
62
+ * spark-dgx.lan → spark-dgx (a name someone chose stays theirs)
63
+ */
64
+ export function friendly(host) {
65
+ const tidy = host.trim().replace(SUFFIX, '');
66
+ if (!tidy)
67
+ return '';
68
+ if (/^desktop-[a-z0-9]{5,}$/i.test(tidy))
69
+ return 'Windows PC';
70
+ if (/^laptop-[a-z0-9]{5,}$/i.test(tidy))
71
+ return 'Windows laptop';
72
+ const words = tidy.replace(/-\d+$/, '').split(/[-_\s]+/).filter(Boolean);
73
+ for (const take of [2, 1]) {
74
+ if (words.length < take)
75
+ continue;
76
+ const name = model(words.slice(-take).join('-'));
77
+ if (!name)
78
+ continue;
79
+ const owner = words.slice(0, -take);
80
+ if (!owner.length)
81
+ return name;
82
+ const last = owner[owner.length - 1];
83
+ // "Alexs" is "Alex's" with the apostrophe macOS could not keep.
84
+ if (last.length > 2 && /s$/i.test(last))
85
+ owner[owner.length - 1] = `${last.slice(0, -1)}'s`;
86
+ return `${owner.map(capital).join(' ')} ${name}`;
87
+ }
88
+ return tidy;
89
+ }
90
+ let kept = {};
91
+ let loaded = false;
92
+ const listeners = new Set();
93
+ function load() {
94
+ if (loaded)
95
+ return;
96
+ loaded = true;
97
+ if (typeof window === 'undefined')
98
+ return;
99
+ try {
100
+ kept = names(JSON.parse(window.localStorage.getItem(NAMES_KEY) ?? '{}'));
101
+ }
102
+ catch {
103
+ kept = {};
104
+ }
105
+ window.addEventListener('storage', (e) => {
106
+ if (e.key !== NAMES_KEY)
107
+ return;
108
+ try {
109
+ set(names(JSON.parse(e.newValue ?? '{}')), false);
110
+ }
111
+ catch {
112
+ /* a bad copy is not a name */
113
+ }
114
+ });
115
+ }
116
+ function set(next, store = true) {
117
+ kept = next;
118
+ if (store && typeof window !== 'undefined') {
119
+ try {
120
+ window.localStorage.setItem(NAMES_KEY, JSON.stringify(next));
121
+ }
122
+ catch {
123
+ /* kept for this page only */
124
+ }
125
+ }
126
+ for (const l of listeners)
127
+ l();
128
+ }
129
+ /** The names as this page holds them now. */
130
+ export function heldNames() {
131
+ load();
132
+ return kept;
133
+ }
134
+ /** The name a person gave the device or shell under `key`, if any. */
135
+ export function nameOf(key) {
136
+ return heldNames()[key];
137
+ }
138
+ /**
139
+ * Name the device or shell under `key` (an empty name clears it, back to its own).
140
+ * With a `target`, the names are saved on the account too; that save failing
141
+ * keeps the name in this browser.
142
+ */
143
+ export async function rename(key, name, target) {
144
+ if (!key)
145
+ return;
146
+ const next = { ...heldNames() };
147
+ const clean = tidyName(name);
148
+ if (clean)
149
+ next[key] = clean;
150
+ else
151
+ delete next[key];
152
+ set(next);
153
+ if (target?.token())
154
+ await save(target, { deviceNames: Object.keys(next).length ? next : null });
155
+ }
156
+ /** The account documents read this page, per credential: the names are adopted once from each. */
157
+ const adopted = new Set();
158
+ function subscribe(onChange) {
159
+ listeners.add(onChange);
160
+ return () => listeners.delete(onChange);
161
+ }
162
+ const EMPTY = {};
163
+ /**
164
+ * The names a person gave their devices and shells, kept current: a rename on
165
+ * any surface of this page redraws every one that reads them. With a signed-in
166
+ * `target`, the account's names are read once per page and win over this
167
+ * browser's copy.
168
+ */
169
+ export function useDeviceNames(target) {
170
+ const held = useSyncExternalStore(subscribe, heldNames, () => EMPTY);
171
+ const token = target?.token() ?? null;
172
+ useEffect(() => {
173
+ if (!target || !token)
174
+ return;
175
+ const key = `${target.api} ${target.org ?? ''} ${token}`;
176
+ if (adopted.has(key))
177
+ return;
178
+ adopted.add(key);
179
+ read(target)
180
+ .then((p) => {
181
+ if (p.deviceNames)
182
+ set({ ...p.deviceNames });
183
+ })
184
+ .catch(() => adopted.delete(key));
185
+ // The target's identity is its api, org and bearer.
186
+ // eslint-disable-next-line react-hooks/exhaustive-deps
187
+ }, [target?.api, target?.org, token]);
188
+ return held;
189
+ }
@@ -17,11 +17,12 @@ import { Button, Dialog, DialogContent, DialogTitle, DropdownMenu, Input, Toolti
17
17
  import { CopyButton } from '@hanzo/ui/product';
18
18
  import { useEffect, useState } from 'react';
19
19
  import { told } from '../api/call.js';
20
- import { add, change, displayMachine, formatBytes, formatPercent, formatRelative, key, KINDS, machines, remove, state, } from '../api/machines.js';
20
+ import { add, change, displayMachine, formatBytes, formatPercent, formatRelative, key, KINDS, machineKey, machines, remove, state, } from '../api/machines.js';
21
21
  import { Confirm, Rename } from '../ask.js';
22
22
  import { useRead } from '../data.js';
23
23
  import { useDevMode } from '../dev-mode.js';
24
24
  import { useHost, useTarget } from '../host.js';
25
+ import { rename, useDeviceNames } from '../names.js';
25
26
  import { Card, Field, Group, Heading, Note, Once, Row, Soft } from './ui.js';
26
27
  /** What `hanzo link` needs, in the order it is typed on the machine. */
27
28
  const LINK = ['hanzo login', 'hanzo link'].join('\n');
@@ -95,6 +96,7 @@ export function Machines() {
95
96
  const host = useHost();
96
97
  const target = useTarget();
97
98
  const signed = Boolean(host.person);
99
+ const names = useDeviceNames(signed ? target : null);
98
100
  const [devMode] = useDevMode();
99
101
  const list = useRead(signed ? () => machines(target) : null, UNREAD, [target, signed]);
100
102
  const [adding, setAdding] = useState(false);
@@ -120,7 +122,7 @@ export function Machines() {
120
122
  const drain = async (m, status) => {
121
123
  setNote('');
122
124
  try {
123
- const display = displayMachine(m, { devMode, say: t });
125
+ const display = displayMachine(m, { devMode, say: t, names });
124
126
  await change(target, m.id, { status });
125
127
  setNote(status === 'draining' ? t('{name} takes no new runs', { name: display.title }) : t('{name} takes runs again', { name: display.title }));
126
128
  list.reload();
@@ -132,7 +134,7 @@ export function Machines() {
132
134
  return (_jsxs(YStack, { gap: "$6", children: [_jsx(Heading, { title: t('Machines'), detail: devMode
133
135
  ? t('Your organization’s own computers. A run sent to one runs there instead of in the cloud workspace.')
134
136
  : t('Connect your computer to run tasks locally in your Hanzo folder.') }), _jsxs(Group, { title: t('Link a machine'), detail: t('Run these on your computer. It stays connected while {command} runs.', { command: 'hanzo link' }), children: [_jsxs(XStack, { items: "flex-start", gap: "$2", px: "$3", py: "$2.5", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", bg: "$raised", children: [_jsx(SizableText, { flex: 1, minW: 0, size: "$2", color: "$ink", "aria-label": t('Link commands'), 'data-i18n-ltr': '', fontFamily: "$mono", "$platform-web": { whiteSpace: 'pre-wrap' }, children: LINK }), _jsx(CopyButton, { value: LINK, label: t('Copy the commands') })] }), _jsxs(XStack, { items: "center", justify: "space-between", flexWrap: "wrap", gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { size: "sm", variant: "ghost", onPress: () => setAdding(true), children: [_jsx(Plus, { size: 14 }), " ", t('Register one by hand')] }), _jsxs(Button, { size: "sm", variant: "ghost", onPress: () => setShowAdvancedLink(!showAdvancedLink), children: [showAdvancedLink ? _jsx(ChevronUp, { size: 14 }) : _jsx(ChevronDown, { size: 14 }), showAdvancedLink ? t('Hide options') : t('Advanced options')] })] }), _jsx(SizableText, { size: "$1", color: "$soft", children: devMode ? t('Supported: macOS, Linux, Windows, NVIDIA CUDA GPUs, Cloud VMs') : t('Works on macOS, Windows, and Linux') })] }), showAdvancedLink ? (_jsxs(YStack, { gap: "$2.5", p: "$3", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", bg: "$raised", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { size: "$2", color: "$ink", fontWeight: "600", children: t('1. Background daemon (system service)') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Run worker continuously in the background without keeping a terminal open:') }), _jsxs(XStack, { items: "center", justify: "space-between", px: "$2.5", py: "$1.5", rounded: "$2", bg: "$raised", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(SizableText, { size: "$1", color: "$ink", 'data-i18n-ltr': '', fontFamily: "$mono", children: "hanzo code --serve" }), _jsx(CopyButton, { value: "hanzo code --serve", label: t('Copy daemon command') })] })] }), _jsxs(YStack, { gap: "$1", pt: "$1", children: [_jsx(SizableText, { size: "$2", color: "$ink", fontWeight: "600", children: t('2. Install CLI from shell') }), _jsxs(XStack, { items: "center", justify: "space-between", px: "$2.5", py: "$1.5", rounded: "$2", bg: "$raised", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(SizableText, { size: "$1", color: "$ink", 'data-i18n-ltr': '', fontFamily: "$mono", children: "curl -fsSL https://hanzo.sh | sh" }), _jsx(CopyButton, { value: "curl -fsSL https://hanzo.sh | sh", label: t('Copy install command') })] })] })] })) : null] }), _jsxs(Group, { title: t('Linked'), children: [list.value === UNREAD ? (_jsx(Soft, { children: list.error ? told(list.error, t) : t('Loading devices…') })) : list.value.length === 0 ? (_jsxs(YStack, { gap: "$3", children: [_jsx(Soft, { children: t('No computer is linked yet.') }), _jsx(Card, { children: _jsxs(YStack, { p: "$4", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$2.5", children: [_jsx(Server, { size: 20 }), _jsxs(YStack, { gap: "$0.5", children: [_jsx(SizableText, { size: "$3", color: "$ink", fontWeight: "600", children: t('Connect your computer') }), _jsx(SizableText, { size: "$2", color: "$soft", children: t('Run tasks directly on your own computer in your Hanzo folder.') })] })] }), _jsxs(YStack, { gap: "$2", pt: "$1", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", width: 20, children: "1." }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Install Hanzo CLI: {command}', { command: _jsx(SizableText, { size: "$2", color: "$ink", fontFamily: "$mono", 'data-i18n-ltr': '', children: "curl -fsSL https://hanzo.sh | sh" }) }) })] }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", width: 20, children: "2." }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Sign in with your account: {command}', { command: _jsx(SizableText, { size: "$2", color: "$ink", fontFamily: "$mono", 'data-i18n-ltr': '', children: "hanzo login" }) }) })] }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { size: "$1", color: "$soft", fontFamily: "$mono", width: 20, children: "3." }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Link the machine: {command}', { command: _jsx(SizableText, { size: "$2", color: "$ink", fontFamily: "$mono", 'data-i18n-ltr': '', children: "hanzo link" }) }) })] })] }), _jsx(XStack, { pt: "$1", children: _jsxs(Button, { size: "sm", variant: "outline", onPress: () => setAdding(true), children: [_jsx(Plus, { size: 14 }), " ", t('Register one by hand')] }) })] }) })] })) : (_jsx(Card, { children: list.value.map((m, i) => {
135
- const display = displayMachine(m, { devMode, say: t });
137
+ const display = displayMachine(m, { devMode, say: t, names });
136
138
  const showDetails = devMode ? !collapsedDevIds[m.id] : expandedId === m.id;
137
139
  const toggleDetails = () => {
138
140
  if (devMode) {
@@ -165,20 +167,22 @@ export function Machines() {
165
167
  }) })), list.error && list.value !== UNREAD ? _jsx(Soft, { children: told(list.error, t) }) : null] }), _jsx(Note, { children: note }), _jsx(Adding, { open: adding, onOpenChange: setAdding, onAdded: (m) => {
166
168
  setNote(t('{name} is registered', { name: m.label }));
167
169
  list.reload();
168
- } }), _jsx(Rename, { open: renaming !== null, onOpenChange: (o) => !o && setRenaming(null), title: t('Rename machine'), name: renaming?.label ?? '',
169
- // Each dialog acts only while it is open, which is while its machine is chosen.
170
+ } }), _jsx(Rename, { open: renaming !== null, onOpenChange: (o) => !o && setRenaming(null), title: t('Rename machine'), name: renaming ? displayMachine(renaming, { devMode, say: t, names }).title : '',
171
+ // Each dialog acts only while it is open, which is while its machine is chosen. The name is the person's, kept on
172
+ // their account (names.ts): the machine's own record is renamed back to its hostname by its next heartbeat.
170
173
  run: async (label) => {
171
- await change(target, renaming.id, { label });
174
+ // Typed back to the name it has by default, it keeps no name of the person's.
175
+ const own = displayMachine(renaming, { devMode, say: t }).title;
176
+ await rename(machineKey(renaming), label === own ? '' : label, target);
172
177
  setNote(t('Renamed to {name}', { name: label }));
173
- list.reload();
174
- } }), _jsx(Confirm, { open: removing !== null, onOpenChange: (o) => !o && setRemoving(null), title: removing ? t('Remove {name}?', { name: removing.label }) : t('Remove this machine?'), says: t('Runs can no longer be sent to it, and its claim key stops working. Linking it again registers it anew.'), act: t('Remove'), run: async () => {
178
+ } }), _jsx(Confirm, { open: removing !== null, onOpenChange: (o) => !o && setRemoving(null), title: removing ? t('Remove {name}?', { name: displayMachine(removing, { devMode, say: t, names }).title }) : t('Remove this machine?'), says: t('Runs can no longer be sent to it, and its claim key stops working. Linking it again registers it anew.'), act: t('Remove'), run: async () => {
175
179
  await remove(target, removing.id);
176
- setNote(t('{name} is removed', { name: removing.label }));
180
+ setNote(t('{name} is removed', { name: displayMachine(removing, { devMode, say: t, names }).title }));
177
181
  list.reload();
178
- } }), _jsx(Confirm, { open: keying !== null, onOpenChange: (o) => !o && setKeying(null), title: keying ? t('Mint a claim key for {name}?', { name: keying.label }) : t('Mint a claim key for this machine?'), says: t('A key it had before stops working, so a runner using it stops getting runs until it has the new one. The new key is shown once.'), act: t('Mint key'), run: async () => {
182
+ } }), _jsx(Confirm, { open: keying !== null, onOpenChange: (o) => !o && setKeying(null), title: keying ? t('Mint a claim key for {name}?', { name: displayMachine(keying, { devMode, say: t, names }).title }) : t('Mint a claim key for this machine?'), says: t('A key it had before stops working, so a runner using it stops getting runs until it has the new one. The new key is shown once.'), act: t('Mint key'), run: async () => {
179
183
  const k = await key(target, keying.id);
180
184
  setMinted({ machine: keying, key: k });
181
- } }), _jsx(Dialog, { open: minted !== null, onOpenChange: (o) => !o && setMinted(null), children: _jsxs(DialogContent, { maxW: 480, showCloseButton: false, children: [_jsx(DialogTitle, { children: t('Claim key for {name}', { name: minted?.machine.label ?? '' }) }), minted ? (_jsxs(YStack, { gap: "$3", children: [_jsx(Once, { value: minted.key, label: t('Claim key'), copy: t('Copy claim key'), children: _jsx(SizableText, { size: "$1", color: "$soft", children: t('A runner on this machine sends it as {header} when it claims the runs sent here, at {route}.', {
185
+ } }), _jsx(Dialog, { open: minted !== null, onOpenChange: (o) => !o && setMinted(null), children: _jsxs(DialogContent, { maxW: 480, showCloseButton: false, children: [_jsx(DialogTitle, { children: t('Claim key for {name}', { name: minted ? displayMachine(minted.machine, { devMode, say: t, names }).title : '' }) }), minted ? (_jsxs(YStack, { gap: "$3", children: [_jsx(Once, { value: minted.key, label: t('Claim key'), copy: t('Copy claim key'), children: _jsx(SizableText, { size: "$1", color: "$soft", children: t('A runner on this machine sends it as {header} when it claims the runs sent here, at {route}.', {
182
186
  header: 'X-Target-Key',
183
187
  route: `POST /v1/agent/targets/${minted.machine.id}/claim`,
184
188
  }) }) }), _jsxs(YStack, { gap: "$1", p: "$2.5", rounded: "$2", bg: "$raised", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(SizableText, { size: "$1", color: "$ink", fontWeight: "600", children: t('Start background worker with this key:') }), _jsxs(XStack, { items: "center", justify: "space-between", px: "$2", py: "$1", rounded: "$2", bg: "$raised", children: [_jsxs(SizableText, { size: "$1", color: "$ink", 'data-i18n-ltr': '', fontFamily: "$mono", children: ["export HANZO_TARGET_KEY=\"", minted.key, "\""] }), _jsx(CopyButton, { value: `export HANZO_TARGET_KEY="${minted.key}"\nhanzo code --serve --target ${minted.machine.id}`, label: t('Copy key command') })] })] })] })) : null, _jsx(XStack, { justify: "flex-end", pt: "$2", children: _jsx(Button, { size: "sm", onPress: () => setMinted(null), children: t('Done') }) })] }) })] }));
package/lib/suggest.d.ts CHANGED
@@ -209,6 +209,12 @@ export declare const shown: (k: Kept | null | undefined) => Suggestion[];
209
209
  * person's activity and signup do not. The one copy here that is authored, so
210
210
  * its words are marked (`phrase`) and drawn in the reader's language, the
211
211
  * prompt too: it is sent as their message and shown as theirs.
212
+ *
213
+ * Dev's starter asks before it builds. A press names no project, no audience
214
+ * and no content, and a model handed "build a landing site for my project"
215
+ * with none of that invents all three: it built a Hanzo AI showcase nobody
216
+ * asked for (hanzo-inc/app#442). So the press starts the conversation about
217
+ * the page, and the build follows the answers.
212
218
  */
213
219
  export declare const STARTERS: readonly Suggestion[];
214
220
  /** Whether a row is a starter: authored, so drawn through `t`; every other row is the person's own words. */
package/lib/suggest.js CHANGED
@@ -396,10 +396,16 @@ export const shown = (k) => (k ? k.rows.filter((r) => !k.dismissed.includes(r.id
396
396
  * person's activity and signup do not. The one copy here that is authored, so
397
397
  * its words are marked (`phrase`) and drawn in the reader's language, the
398
398
  * prompt too: it is sent as their message and shown as theirs.
399
+ *
400
+ * Dev's starter asks before it builds. A press names no project, no audience
401
+ * and no content, and a model handed "build a landing site for my project"
402
+ * with none of that invents all three: it built a Hanzo AI showcase nobody
403
+ * asked for (hanzo-inc/app#442). So the press starts the conversation about
404
+ * the page, and the build follows the answers.
399
405
  */
400
406
  export const STARTERS = [
401
407
  { id: 'start:chat', icon: 'chat', title: phrase('Ask what Hanzo can do for you'), summary: '', act: { kind: 'send', prompt: phrase('What can you do for me? Give me three concrete things to try today.') } },
402
- { id: 'start:dev', icon: 'agent', title: phrase('Build a landing page with Dev'), summary: '', act: { kind: 'task', prompt: phrase('Build a one-page landing site for my project and give me the preview link.') } },
408
+ { id: 'start:dev', icon: 'agent', title: phrase('Build a landing page with Dev'), summary: '', act: { kind: 'task', prompt: phrase('I want a one-page landing page. Before you build anything, ask me what it is for, who it is for and what it should say.') } },
403
409
  { id: 'start:research', icon: 'file', title: phrase('Get a cited brief on AI agents'), summary: '', act: { kind: 'send', prompt: phrase('Research the state of AI coding agents this month and give me a short brief with sources.') } },
404
410
  ];
405
411
  /** Whether a row is a starter: authored, so drawn through `t`; every other row is the person's own words. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/build",
3
- "version": "0.2.127",
3
+ "version": "0.2.129",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "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.",
@@ -65,6 +65,11 @@
65
65
  "import": "./lib/dev-mode.js",
66
66
  "default": "./lib/dev-mode.js"
67
67
  },
68
+ "./names": {
69
+ "types": "./lib/names.d.ts",
70
+ "import": "./lib/names.js",
71
+ "default": "./lib/names.js"
72
+ },
68
73
  "./package.json": "./package.json"
69
74
  },
70
75
  "files": [