@hivey/cli 0.9.64 β†’ 0.9.66

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.
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>hivey office</title>
6
+ <title>hivey fleet</title>
7
7
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🐝</text></svg>">
8
8
  <style>
9
9
  :root{
@@ -19,7 +19,7 @@ a{color:var(--honey)}
19
19
  header{position:sticky;top:0;z-index:20;display:flex;flex-wrap:wrap;align-items:center;gap:10px 14px;
20
20
  padding:10px 18px;background:rgba(13,17,25,.86);backdrop-filter:blur(10px);border-bottom:1px solid var(--line)}
21
21
  .brand{display:flex;align-items:center;gap:10px;margin-right:6px}
22
- .brand .logo{font-size:26px;filter:drop-shadow(0 0 8px rgba(245,184,61,.45))}
22
+ .brand .logo{width:30px;height:30px;display:block;filter:drop-shadow(0 0 8px rgba(155,239,200,.35))}
23
23
  .brand h1{margin:0;font-size:17px;letter-spacing:.2px}
24
24
  .brand .sub{color:var(--muted);font-size:12px}
25
25
  .pills{display:flex;flex-wrap:wrap;gap:6px}
@@ -40,6 +40,15 @@ header{position:sticky;top:0;z-index:20;display:flex;flex-wrap:wrap;align-items:
40
40
  .iconbtn:hover{border-color:var(--honey)}
41
41
  .every{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:7px 9px;color:inherit;font:inherit;cursor:pointer}
42
42
  .every:hover{border-color:var(--honey)}
43
+ .settings{position:fixed;top:58px;right:14px;z-index:70;width:290px;background:rgba(12,18,34,.97);border:1px solid rgba(120,170,255,.4);border-radius:14px;
44
+ padding:12px 14px;box-shadow:0 14px 40px rgba(0,0,0,.55);display:flex;flex-direction:column;gap:10px}
45
+ .settings[hidden]{display:none}
46
+ .settings .t{font-weight:700;font-size:13px;color:#cfe0ff;letter-spacing:.04em}
47
+ .settings label{display:flex;align-items:center;justify-content:space-between;gap:10px;font-size:13px}
48
+ .settings label span{color:#cbd5e1;white-space:nowrap}
49
+ .settings select{width:160px}
50
+ .settings .note{font-size:11px;color:var(--muted);line-height:1.4}
51
+ #gear.on{border-color:var(--honey)}
43
52
  .spin{display:inline-block;animation:spin 1s linear infinite}
44
53
  @keyframes spin{to{transform:rotate(360deg)}}
45
54
  /* ---------- needs-you inbox ---------- */
@@ -76,6 +85,19 @@ main{position:relative}
76
85
  .room-label{position:absolute;transform:translate(0,-50%);font-weight:700;font-size:13px;color:#cbd5e1;
77
86
  text-shadow:0 1px 6px #000;white-space:nowrap;letter-spacing:.2px}
78
87
  .lod-tiny .room-label{font-size:11px}
88
+ .ship-label{position:absolute;left:0;top:0;border-radius:8px;border:1px solid transparent;pointer-events:auto;transition:background .15s,border-color .15s}
89
+ .ship-label .cap{position:absolute;top:100%;left:50%;transform:translateX(-50%);margin-top:4px;white-space:nowrap;font-size:11px;color:#cfe0ff;
90
+ background:rgba(10,16,32,.8);border:1px solid rgba(120,170,255,.35);border-radius:999px;padding:2px 9px;opacity:0;transition:opacity .15s;pointer-events:none}
91
+ .ship-label:hover,.ship-label.dragging{background:rgba(255,200,80,.10);border-color:rgba(255,200,80,.55)}
92
+ .ship-label:hover .cap,.ship-label.dragging .cap{opacity:1}
93
+ .ship-menu{position:fixed;z-index:60;min-width:210px;background:rgba(12,18,34,.96);border:1px solid rgba(120,170,255,.45);border-radius:12px;padding:8px;
94
+ box-shadow:0 10px 30px rgba(0,0,0,.5);display:flex;flex-direction:column;gap:6px}
95
+ .ship-menu .t{font-weight:700;padding:2px 4px 4px;text-transform:uppercase;letter-spacing:.05em;font-size:12px;color:#cfe0ff}
96
+ .ship-menu button{text-align:left;background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:7px 10px;color:inherit;cursor:pointer}
97
+ .ship-menu button:hover{border-color:var(--honey)}
98
+ .ship-menu button.danger{color:#fda4af}.ship-menu button.danger.arm{background:#7f1d1d;color:#fff;border-color:#fb7185}
99
+ .ship-menu .note{font-size:11px;color:#93a4c3;padding:0 4px}
100
+ .ship-label{cursor:grab;touch-action:none;user-select:none}.ship-label.dragging{cursor:grabbing;border-color:var(--honey)}
79
101
  #hud{position:absolute;left:14px;bottom:12px;display:flex;gap:8px;align-items:center;color:var(--muted);font-size:12px}
80
102
  #hud button{background:rgba(21,27,39,.9);border:1px solid var(--line);border-radius:9px;padding:5px 9px}
81
103
  #tip{position:fixed;z-index:30;pointer-events:none;max-width:340px;padding:11px 13px;border-radius:12px;background:rgba(21,27,39,.97);
@@ -153,25 +175,58 @@ td.j{max-width:420px}
153
175
  </head>
154
176
  <body>
155
177
  <header>
156
- <div class="brand"><span class="logo">🐝</span><div><h1>hivey office</h1><div class="sub" id="sub">loading…</div></div></div>
178
+ <div class="brand"><svg class="logo" viewBox="0 0 40 40" role="img" aria-label="hivey"><rect width="40" height="40" rx="9" fill="#9befc8"/><path d="M10 9h7v9h6V9h7v23h-7V22h-6v10h-7z" fill="#122319"/></svg><div><h1>hivey fleet</h1><div class="sub" id="sub">loading…</div></div></div>
157
179
  <div class="pills" id="pills"></div>
158
180
  <div class="spacer"></div>
159
181
  <input class="search" id="q" placeholder="Search agents, jobs… ( / )" autocomplete="off">
160
182
  <div class="seg" id="views">
161
- <button data-v="office" title="3D office (1)">🏒 Office</button>
183
+ <button data-v="office" title="Your spaceships, one per hivey session (1)">πŸš€ Fleet</button>
162
184
  <button data-v="board" title="Cards by what needs you (2)">β–¦ Board</button>
163
185
  <button data-v="list" title="One row per agent, for hundreds (3)">☰ List</button>
164
186
  </div>
165
187
  <button class="iconbtn" id="music" title="Background music on/off (m)">πŸ”‡</button>
166
- <select class="every" id="every" title="How the office updates itself">
167
- <option value="minute">⏱ every minute</option>
168
- <option value="5min">⏱ every 5 min</option>
169
- <option value="15min">⏱ every 15 min</option>
170
- <option value="1h">⏱ every hour</option>
171
- <option value="reload">⏱ on reload only</option>
172
- </select>
173
188
  <button class="iconbtn" id="refresh" title="Read every terminal and session log again now (r)">⟳</button>
189
+ <button class="iconbtn" id="gear" title="Settings: music, updates, background">βš™</button>
174
190
  </header>
191
+ <div id="settings" class="settings" hidden>
192
+ <div class="t">βš™ Settings</div>
193
+ <label><span>🎡 Music</span>
194
+ <select class="every" id="track" title="Music: a new track each time, or always one">
195
+ <option value="random">new each time</option>
196
+ <option value="1">cosmic ambient</option>
197
+ <option value="2">cosmic ambient II</option>
198
+ <option value="3">dark techno</option>
199
+ <option value="4">synthwave cruise</option>
200
+ <option value="5">glitch downtempo</option>
201
+ <option value="6">cinematic drones</option>
202
+ <option value="7">lo-fi stars</option>
203
+ <option value="8">berlin sequencer</option>
204
+ <option value="9">deep house orbit</option>
205
+ <option value="10">liquid drum &amp; bass</option>
206
+ </select>
207
+ </label>
208
+ <label><span>⏱ Updates</span>
209
+ <select class="every" id="every" title="How the office updates itself">
210
+ <option value="minute">every minute</option>
211
+ <option value="5min">every 5 min</option>
212
+ <option value="15min">every 15 min</option>
213
+ <option value="1h">every hour</option>
214
+ <option value="reload">on reload only</option>
215
+ </select>
216
+ </label>
217
+ <label><span>🌌 Background</span>
218
+ <select class="every" id="space" title="Background: a new space scene every time, or always one">
219
+ <option value="random">new each time</option>
220
+ <option value="1">violet</option>
221
+ <option value="2">emerald</option>
222
+ <option value="3">crimson</option>
223
+ <option value="4">deep blue</option>
224
+ <option value="5">golden suns</option>
225
+ <option value="6">singularity</option>
226
+ </select>
227
+ </label>
228
+ <div class="note">Saved for every browser. πŸ”‡ in the header mutes the music; ⟳ updates now.</div>
229
+ </div>
175
230
  <div id="inbox"></div>
176
231
  <main>
177
232
  <section id="office">
@@ -184,7 +239,7 @@ td.j{max-width:420px}
184
239
  <aside id="drawer"></aside>
185
240
  <div id="tip"></div>
186
241
  <div id="toast"></div>
187
- <audio id="bgm" src="./music/space.mp3" loop preload="none"></audio>
242
+ <audio id="bgm" preload="auto"></audio>
188
243
  <script type="module" src="./office.js"></script>
189
244
  </body>
190
245
  </html>
@@ -26,7 +26,9 @@ const ui = JSON.parse(localStorage.getItem('hv-office-ship') || '{}');
26
26
  ui.view ||= 'office';
27
27
  ui.filter ||= null;
28
28
  if (ui.toon === undefined) ui.toon = false;
29
- const save = () => localStorage.setItem('hv-office-ship', JSON.stringify({ view: ui.view, filter: ui.filter, toon: ui.toon, music: ui.music }));
29
+ const save = () => localStorage.setItem('hv-office-ship', JSON.stringify({ view: ui.view, filter: ui.filter, toon: ui.toon, music: ui.music, ships: ui.ships, space: ui.space, track: ui.track }));
30
+ // ship positions also live on the office server, so every browser opens the fleet where you left it
31
+ const saveShips = () => { save(); fetch('/hv-office-settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ships: ui.ships || {} }) }).catch(() => {}); };
30
32
 
31
33
  // ---------------------------------------------------------------- helpers
32
34
  function hue(name) { let h = 0; for (const c of name || '') h = (h * 31 + c.charCodeAt(0)) >>> 0; return h % 360; }
@@ -84,6 +86,58 @@ function warpPing() {
84
86
  setTimeout(() => { fb.gain.value = 0; }, 900);
85
87
  } catch (e) { /* no audio: the flash is enough */ }
86
88
  }
89
+ // a ship's name tag opens a small menu: open (or start) the session, or stop it (a second click confirms)
90
+ function closeShipMenu() { document.querySelector('.ship-menu')?.remove(); }
91
+ function shipMenu(el, s, n) {
92
+ const was = document.querySelector('.ship-menu')?.dataset.name;
93
+ closeShipMenu();
94
+ if (was === s.name) return;
95
+ const m = document.createElement('div');
96
+ m.className = 'ship-menu'; m.dataset.name = s.name;
97
+ m.innerHTML = `<div class="t">${s.running ? 'πŸš€' : 'πŸ’€'} ${esc(s.name)}</div>` + (s.running
98
+ ? `<button data-k="open">β–Ά Open in a terminal</button>` + (s.default ? `<div class="note">the default session is stopped from hivey itself</div>`
99
+ : `<button data-k="stop" class="danger">⏹ Stop session</button>`)
100
+ : `<button data-k="open">β–Ά Start session</button>`)
101
+ + (ui.ships?.[s.name] ? `<button data-k="home">β†Ί Put back in line</button>` : `<div class="note">drag this tag to move the ship</div>`);
102
+ const r = el.getBoundingClientRect();
103
+ m.style.left = Math.min(r.left, innerWidth - 230) + 'px'; m.style.top = (r.bottom + 6) + 'px';
104
+ document.body.appendChild(m);
105
+ m.onclick = e => e.stopPropagation();
106
+ m.querySelector('[data-k="open"]').onclick = () => { closeShipMenu(); openSession(s.name, s.running); };
107
+ const home = m.querySelector('[data-k="home"]');
108
+ if (home) home.onclick = () => { closeShipMenu(); delete ui.ships[s.name]; saveShips(); renderAll(); };
109
+ const stop = m.querySelector('[data-k="stop"]');
110
+ if (stop) stop.onclick = () => {
111
+ if (!stop.classList.contains('arm')) {
112
+ stop.classList.add('arm'); stop.textContent = `Click again: ends its ${n} agent${n === 1 ? '' : 's'}`;
113
+ setTimeout(() => { if (stop.isConnected) { stop.classList.remove('arm'); stop.textContent = '⏹ Stop session'; } }, 3500);
114
+ return;
115
+ }
116
+ closeShipMenu(); stopSession(s.name);
117
+ };
118
+ }
119
+ document.addEventListener('click', closeShipMenu);
120
+ document.addEventListener('keydown', e => { if (e.key === 'Escape') closeShipMenu(); });
121
+ async function stopSession(name) {
122
+ toast(`Stopping session ${name}…`);
123
+ try {
124
+ const r = await fetch('/hv-office-action', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'stop-session', session: name }) });
125
+ const j = await r.json();
126
+ toast(j.message || (j.ok ? `Session ${name} stopped` : `Could not stop session ${name}`));
127
+ if (j.ok) fetch('/hv-office-refresh', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{"quick":true}' }).then(() => setTimeout(poll, 2500));
128
+ } catch (e) { toast('The office server is not answering: run `hivey agent-map office` again'); }
129
+ }
130
+ // click on a ship's name tag: that hivey session in a terminal (a new one if none shows it; starts a stopped one)
131
+ async function openSession(name, running) {
132
+ warpPing();
133
+ toast(running ? `Opening session ${name}…` : `Starting session ${name}…`);
134
+ try {
135
+ const r = await fetch('/hv-office-action', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'session', session: name }) });
136
+ const j = await r.json();
137
+ toast(j.message || (j.ok ? `Session ${name} opened` : `Could not open session ${name}`));
138
+ if (j.ok && !running) setTimeout(() => fetch('/hv-office-refresh', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{"quick":true}' }).then(() => setTimeout(poll, 2500)), 4000);
139
+ } catch (e) { toast('The office server is not answering: run `hivey agent-map office` again'); }
140
+ }
87
141
  async function act(a, action) {
88
142
  if (action === 'focus' || action === 'compact') {
89
143
  warpPing();
@@ -92,9 +146,9 @@ async function act(a, action) {
92
146
  document.querySelectorAll(`[data-id="${CSS.escape(a.id)}"]`).forEach(el => { el.classList.remove('flash'); void el.offsetWidth; el.classList.add('flash'); });
93
147
  }
94
148
  try {
95
- const r = await fetch('/hv-office-action', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ pane: a.pane, action }) });
149
+ const r = await fetch('/hv-office-action', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: a.id, pane: a.pane, action }) });
96
150
  const j = await r.json();
97
- toast(j.ok ? (action === 'focus' ? `${a.name} is open in hivey β†—` : `${a.name}: ${j.message}`) : `${a.name}: ${j.message}`);
151
+ toast(j.ok && action === 'focus' && !/new terminal/.test(j.message || '') ? `${a.name} is open in hivey β†—` : `${a.name}: ${j.message}`);
98
152
  } catch (e) { toast('The office server is not answering: run `hivey agent-map office` again'); }
99
153
  }
100
154
  // clear needs a second click within 3 s (no browser dialogs); compact goes at once
@@ -106,7 +160,7 @@ function armed(btn, a, action) {
106
160
  setTimeout(() => { if (btn.classList.contains('arm')) { btn.classList.remove('arm'); btn.textContent = btn.dataset.label; } }, 3000);
107
161
  }
108
162
  function actionButtons(a) {
109
- const busy = a.status === 'working' || a.status === 'blocked';
163
+ const busy = a.status === 'working' || a.status === 'blocked' || a.asleep;
110
164
  return `<div class="actions">
111
165
  <button class="primary" data-act="focus" title="Open its terminal in hivey">β†— Open</button>
112
166
  ${a.cli_id === 'claude' ? `<button data-act="compact" ${busy ? 'disabled title="Only when it is not working"' : 'title="Type /compact into it and press Enter"'}>πŸ—œ Compact</button>
@@ -158,8 +212,8 @@ function tickSub() {
158
212
  (data.error ? ` Β· <span class="err" title="${esc(data.error)}">summaries from the recap (model call failed)</span>` : '');
159
213
  }
160
214
  function renderInbox() {
161
- const blocked = agents.filter(a => a.status === 'blocked');
162
- const asked = agents.filter(a => a.status !== 'blocked' && a.status !== 'working' && a.summary?.needs_you);
215
+ const blocked = agents.filter(a => a.status === 'blocked' && !a.asleep);
216
+ const asked = agents.filter(a => !a.asleep && a.status !== 'blocked' && a.status !== 'working' && a.summary?.needs_you);
163
217
  const need = [...blocked, ...asked];
164
218
  const lead = [blocked.length ? `βœ‹ ${blocked.length} blocked` : '', asked.length ? `<span style="color:var(--honey)">πŸ’¬ ${asked.length} asked you</span>` : ''].filter(Boolean).join('<br>');
165
219
  $('#inbox').innerHTML = need.length ? `<span class="lead">${lead}</span>` + need.map(a =>
@@ -267,7 +321,7 @@ function closeDrawer() { $('#drawer').classList.remove('open'); selected = null;
267
321
  const office = (() => {
268
322
  const host = $('#office'), labels = $('#labels');
269
323
  let renderer;
270
- try { renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); } catch (e) { return { ok: false, build() {}, markSelected() {}, resize() {}, fit() {}, flash() {} }; }
324
+ try { renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); } catch (e) { return { ok: false, build() {}, markSelected() {}, resize() {}, fit() {}, flash() {}, setSpace() {} }; }
271
325
  renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
272
326
  renderer.shadowMap.enabled = true;
273
327
  renderer.shadowMap.type = THREE.PCFSoftShadowMap;
@@ -387,7 +441,7 @@ const office = (() => {
387
441
  const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z); m.scale.set(sx, sy, sz);
388
442
  m.castShadow = shadow; m.receiveShadow = true; return m;
389
443
  }
390
- const ship = createShip({ mesh, hue, st });
444
+ const ship = createShip({ mesh, hue, st, space: ui.space });
391
445
  scene.background = ship.background; // the ship floats in deep space
392
446
  [M.wall, M.floor, M.hit, holoMat].forEach(m => m.userData.outlineParameters = NO_LINE);
393
447
  Object.values(signs).forEach(m => m.userData.outlineParameters = NO_LINE);
@@ -450,9 +504,8 @@ const office = (() => {
450
504
  labels.appendChild(el);
451
505
  tags.set(a.id, { el, d, prio: ({ blocked: 0, working: 1, done: 2, idle: 3 }[a.status] ?? 4) - (a.summary?.needs_you ? 0.5 : 0) });
452
506
  }
453
- function build(list) {
454
- scene.remove(world); world = new THREE.Group(); scene.add(world);
455
- desks = []; labels.innerHTML = ''; tags = new Map(); roomTags = [];
507
+ // one spaceship (rooms, bridge, hull) for one hivey session's agents, built into grp around its origin
508
+ function buildShip(list, grp, style) {
456
509
  // the CEO's space gets the captain's bridge; everyone else gets team rooms
457
510
  const isCeo = a => /^ceo$/i.test(a.space || '');
458
511
  const ceo = list.filter(isCeo);
@@ -477,31 +530,97 @@ const office = (() => {
477
530
  sizes.forEach(r => {
478
531
  const h = hue(r.s[0].space), rx = ox + r.x, rz = oz + r.z;
479
532
  const rug = mesh(G.plane, rugMatFor(h), rx + r.w / 2, 0.006, rz + r.d / 2, r.w - 0.3, r.d - 0.3, 1, false);
480
- rug.rotation.x = -Math.PI / 2; world.add(rug);
481
- world.add(mesh(G.box, M.wall, rx + r.w / 2, 0.5, rz + 0.06, r.w, 1.0, 0.06, false), mesh(G.box, M.wall, rx + 0.06, 0.5, rz + r.d / 2, 0.06, 1.0, r.d, false));
482
- ship.pod(world, rx + r.w - 0.6, rz + 0.6);
483
- world.add(mesh(G.box, accentFor(h), rx + r.w / 2, 1.02, rz + 0.06, r.w, 0.05, 0.1, false), mesh(G.box, accentFor(h), rx + 0.06, 1.02, rz + r.d / 2, 0.1, 0.05, r.d, false));
533
+ rug.rotation.x = -Math.PI / 2; grp.add(rug);
534
+ grp.add(mesh(G.box, M.wall, rx + r.w / 2, 0.5, rz + 0.06, r.w, 1.0, 0.06, false), mesh(G.box, M.wall, rx + 0.06, 0.5, rz + r.d / 2, 0.06, 1.0, r.d, false));
535
+ ship.pod(grp, rx + r.w - 0.6, rz + 0.6);
536
+ grp.add(mesh(G.box, accentFor(h), rx + r.w / 2, 1.02, rz + 0.06, r.w, 0.05, 0.1, false), mesh(G.box, accentFor(h), rx + 0.06, 1.02, rz + r.d / 2, 0.1, 0.05, r.d, false));
484
537
  r.s.sort((a, b) => (b.team?.length || 0) - (a.team?.length || 0) || (order[a.status] ?? 9) - (order[b.status] ?? 9));
485
538
  r.s.forEach((a, i) => {
486
539
  const d = makeDesk(a, rx + PAD + DX / 2 + (i % 3) * DX, rz + PAD + 1.6 + Math.floor(i / 3) * DZ);
487
- world.add(d.g); desks.push(d); addTag(a, d);
540
+ grp.add(d.g); desks.push(d); addTag(a, d);
488
541
  });
489
542
  const rl = document.createElement('div');
490
543
  rl.className = 'room-label'; rl.textContent = `${r.s[0].emoji} ${r.s[0].space}`;
491
544
  labels.appendChild(rl); roomTags.push({ el: rl, p: new THREE.Vector3(rx + 0.3, 0.9, rz + r.d + 0.2) });
492
545
  });
493
- const e = ship.decorate(world, Math.max(W, 8), Math.max(D, 8));
494
- const br = ship.bridge(world, e);
546
+ const e = ship.decorate(grp, Math.max(W, 8), Math.max(D, 8), style);
547
+ const br = ship.bridge(grp, e);
495
548
  ceo.sort((a, b) => (a.role === 'session') - (b.role === 'session') || (order[a.status] ?? 9) - (order[b.status] ?? 9));
496
549
  ceo.slice(0, br.slots.length).forEach((a, i) => {
497
550
  const slot = br.slots[i], d = makeDesk(a, slot.x, slot.z);
498
551
  if (slot.captain) { d.g.scale.setScalar(1.18); d.anchor.y *= 1.18; }
499
- world.add(d.g); desks.push(d); addTag(a, d);
552
+ grp.add(d.g); desks.push(d); addTag(a, d);
500
553
  });
501
- const bl = document.createElement('div');
502
- bl.className = 'room-label'; bl.textContent = `${ceo[0]?.emoji || 'πŸ‘”'} ceo Β· captain's bridge`;
503
- labels.appendChild(bl); roomTags.push({ el: bl, p: br.label });
554
+ if (ceo.length) {
555
+ const bl = document.createElement('div');
556
+ bl.className = 'room-label'; bl.textContent = `${ceo[0]?.emoji || 'πŸ‘”'} ceo Β· captain's bridge`;
557
+ labels.appendChild(bl); roomTags.push({ el: bl, p: br.label });
558
+ }
504
559
  e.maxX = Math.max(e.maxX, br.bounds.maxX);
560
+ return e;
561
+ }
562
+ // one spaceship per hivey session, flying in a column (the default session first, stopped ones dark and empty)
563
+ function build(list, sessions) {
564
+ scene.remove(world); world = new THREE.Group(); scene.add(world);
565
+ desks = []; labels.innerHTML = ''; tags = new Map(); roomTags = [];
566
+ sessions = sessions?.length ? sessions : [{ name: 'default', running: true, default: true }];
567
+ const known = new Set(sessions.map(s => s.name));
568
+ const fleet = sessions.map(s => ({ s, list: list.filter(a => (a.hv_session || 'default') === s.name || (s.default && !known.has(a.hv_session || 'default'))) }));
569
+ const e = { minX: Infinity, maxX: -Infinity, minZ: Infinity, maxZ: -Infinity };
570
+ let zCur = 0;
571
+ const others = sessions.filter(s => !s.default).map(s => s.name).sort();
572
+ fleet.forEach(({ s, list }) => {
573
+ const grp = new THREE.Group(); world.add(grp);
574
+ const d0 = desks.length, r0 = roomTags.length;
575
+ // the default session flies the classic frigate; the others, in name order, each get their own design
576
+ const v = s.default ? 0 : 1 + others.indexOf(s.name);
577
+ const se = buildShip(list, grp, { v, name: s.name, running: s.running !== false });
578
+ const off = new THREE.Vector3(-(se.minX + se.maxX) / 2, 0, zCur - se.minZ);
579
+ const placed = ui.ships?.[s.name]; // where you dragged this ship last time
580
+ if (placed && isFinite(placed.x) && isFinite(placed.z)) off.set(placed.x, 0, placed.z);
581
+ grp.position.copy(off);
582
+ desks.slice(d0).forEach(d => d.anchor.add(off));
583
+ roomTags.slice(r0).forEach(t => t.p.add(off));
584
+ if (se.plate) { // the name painted on the hull is the ship's handle: click for its menu, drag to move it
585
+ const n = list.length, el = document.createElement('div');
586
+ el.className = 'ship-label' + (s.running ? '' : ' stopped');
587
+ el.innerHTML = `<span class="cap">${s.running ? 'πŸš€' : 'πŸ’€'} ${s.running ? `${n} agent${n === 1 ? '' : 's'}` : `stopped${n ? ` Β· ${n} asleep` : ''}`}</span>`;
588
+ el.title = s.running ? `hivey session "${s.name}": open or stop it` : `hivey session "${s.name}" is stopped: start it`;
589
+ el.onclick = e => { e.stopPropagation(); if (!el.dataset.dragged) shipMenu(el, s, n); };
590
+ // drag the name tag to move the ship anywhere in space (saved in this browser)
591
+ const crew = desks.slice(d0), marks = roomTags.slice(r0);
592
+ el.addEventListener('pointerdown', e => {
593
+ if (e.button !== 0) return;
594
+ e.stopPropagation(); e.preventDefault();
595
+ const start = worldAt(e), base = grp.position.clone(), sx = e.clientX, sy = e.clientY;
596
+ let moved = false;
597
+ const mv = ev => {
598
+ if (!moved && Math.hypot(ev.clientX - sx, ev.clientY - sy) < 5) return;
599
+ if (!moved) { moved = true; closeShipMenu(); el.classList.add('dragging'); }
600
+ const np = base.clone().add(worldAt(ev).sub(start)); np.y = 0;
601
+ const d = np.clone().sub(grp.position);
602
+ grp.position.copy(np);
603
+ crew.forEach(k => k.anchor.add(d)); marks.forEach(t => t.p.add(d)); shipTag.p.add(d); shipTag.p2.add(d);
604
+ dirty = true;
605
+ };
606
+ const up = () => {
607
+ removeEventListener('pointermove', mv); removeEventListener('pointerup', up);
608
+ el.classList.remove('dragging');
609
+ if (!moved) return;
610
+ ui.ships = { ...(ui.ships || {}), [s.name]: { x: +grp.position.x.toFixed(2), z: +grp.position.z.toFixed(2) } }; saveShips();
611
+ el.dataset.dragged = '1'; setTimeout(() => delete el.dataset.dragged, 0);
612
+ };
613
+ addEventListener('pointermove', mv); addEventListener('pointerup', up);
614
+ });
615
+ labels.appendChild(el);
616
+ const pc = new THREE.Vector3(off.x + se.plate.x, se.plate.y, off.z + se.plate.z);
617
+ const shipTag = { el, p: pc, p2: pc.clone().add(new THREE.Vector3(se.plate.w / 2, 0, 0)) };
618
+ roomTags.push(shipTag);
619
+ }
620
+ e.minX = Math.min(e.minX, off.x + se.minX); e.maxX = Math.max(e.maxX, off.x + se.maxX);
621
+ e.minZ = Math.min(e.minZ, off.z + se.minZ); e.maxZ = Math.max(e.maxZ, off.z + se.maxZ);
622
+ zCur += se.maxZ - se.minZ + 30; // room for the next ship's tower so it does not hide this one's name
623
+ })
505
624
  // measure each label once (bubble and plate), for the overlap pass in placeLabels
506
625
  tags.forEach(t => {
507
626
  const b = t.el.querySelector('.bubble'), pl = t.el.querySelector('.plate');
@@ -630,7 +749,7 @@ const office = (() => {
630
749
  const d = desks.find(x => x.a.id === id);
631
750
  if (!d) return;
632
751
  const g = new THREE.Group();
633
- g.position.copy(d.g.position).add(new THREE.Vector3(0, 0, -0.9 * d.g.scale.x));
752
+ d.g.getWorldPosition(g.position).add(new THREE.Vector3(0, 0, -0.9 * d.g.scale.x));
634
753
  const ring = mesh(G.ring, glowMat('#ffd36a'), 0, 0.06, 0, 1, 1, 1, false); ring.rotation.x = -Math.PI / 2;
635
754
  const ring2 = mesh(G.ring, glowMat('#7fe8ff'), 0, 0.07, 0, 1, 1, 1, false); ring2.rotation.x = -Math.PI / 2;
636
755
  const beam = mesh(beamGeo, glowMat('#7fe8ff'), 0, 3.5, 0, 1, 1, 1, false);
@@ -683,7 +802,16 @@ const office = (() => {
683
802
  placed.push(mode === 'full' ? [x - bw, y - t.ph - t.bh, x + bw, y] : [x - pw, y - t.ph, x + pw, y]);
684
803
  el.style.transform = `translate(${x}px, ${y}px) translate(-50%, -100%)`;
685
804
  }
686
- roomTags.forEach(({ el, p }) => { v.copy(p).project(cam); el.style.transform = `translate(${(v.x + 1) / 2 * w}px, ${(1 - v.y) / 2 * h}px)`; });
805
+ roomTags.forEach(({ el, p, p2 }) => {
806
+ v.copy(p).project(cam);
807
+ const x = (v.x + 1) / 2 * w, y = (1 - v.y) / 2 * h;
808
+ if (p2) { // the hull name's click area: as wide as the painted name at this zoom
809
+ v.copy(p2).project(cam);
810
+ const half = Math.hypot((v.x + 1) / 2 * w - x, (1 - v.y) / 2 * h - y);
811
+ el.style.width = `${Math.max(40, half * 2)}px`; el.style.height = `${Math.max(14, half * 0.32)}px`;
812
+ el.style.transform = `translate(${x}px, ${y}px) translate(-50%, -50%)`;
813
+ } else el.style.transform = `translate(${x}px, ${y}px)`;
814
+ });
687
815
  }
688
816
  // the hover class keeps a bubble visible while zoomed out
689
817
  const style = document.createElement('style');
@@ -695,14 +823,16 @@ const office = (() => {
695
823
  function frame(t) {
696
824
  requestAnimationFrame(frame);
697
825
  if (document.hidden || ui.view !== 'office') return;
698
- const moving = flashes.length > 0 || (!REDUCED && desks.some(d => d.a.status === 'working' || d.a.status === 'blocked' || d.team.some(m => m.status === 'working')));
826
+ const busy = flashes.length > 0 || (!REDUCED && desks.some(d => d.a.status === 'working' || d.a.status === 'blocked' || d.team.some(m => m.status === 'working')));
827
+ const moving = busy || (!REDUCED && ship.thrusting());
699
828
  const dt = Math.min(0.1, (t - (frame.prev || t)) / 1000); frame.prev = t;
700
829
  if (!moving && !dirty) return;
701
- if (moving && t - last < 33) return; // ~30 fps is plenty
830
+ if (moving && t - last < (busy ? 33 : 66)) return; // ~30 fps is plenty (15 when only engines burn)
702
831
  last = t;
703
832
  const s = t / 1000;
704
833
  if (moving) {
705
- const pl = ship.planet(); if (pl) pl.rotation.y = s * 0.4;
834
+ ship.planets().forEach(pl => { pl.rotation.y = s * 0.4; });
835
+ ship.thrust(s);
706
836
  if (t - lastCode > 110) { drawCode(); lastCode = t; }
707
837
  for (const d of desks) {
708
838
  const b = d.bot, ph = d.ph;
@@ -737,7 +867,15 @@ const office = (() => {
737
867
  new ResizeObserver(() => { resize(); }).observe(host);
738
868
  resize(); placeCam();
739
869
  requestAnimationFrame(frame);
740
- return { ok: true, build, markSelected, resize, fit, flash, ready: ship.load() };
870
+ // the 🌌 setting: show scene n (1..6) now, or a new random one
871
+ function setSpace(want) {
872
+ const old = scene.background;
873
+ scene.background = ship.space(want);
874
+ old?.dispose?.();
875
+ dirty = true;
876
+ return ship.spaceNo();
877
+ }
878
+ return { ok: true, build, markSelected, resize, fit, flash, setSpace, ready: ship.load() };
741
879
  })();
742
880
 
743
881
  // ---------------------------------------------------------------- views, polling, keys
@@ -751,7 +889,7 @@ function renderAll() {
751
889
  $('#office').style.display = ui.view === 'office' ? '' : 'none';
752
890
  $('#board').style.display = ui.view === 'board' ? 'block' : 'none';
753
891
  $('#list').style.display = ui.view === 'list' ? 'block' : 'none';
754
- if (ui.view === 'office') { office.build(agents.filter(visible)); office.resize(); }
892
+ if (ui.view === 'office') { office.build(agents.filter(visible), data.sessions); office.resize(); }
755
893
  if (ui.view === 'board') renderBoard();
756
894
  if (ui.view === 'list') renderList();
757
895
  if (selected) { const a = agents.find(x => x.id === selected); if (a && $('#drawer').classList.contains('open')) openDrawer(a); }
@@ -766,7 +904,7 @@ async function poll() {
766
904
  if (refreshing && Date.parse(j.generated) > refreshing) { refreshing = false; $('#refresh').innerHTML = '⟳'; toast('Office updated'); }
767
905
  renderAll();
768
906
  }
769
- } catch (e) { console.error('hivey office:', e); $('#sub').textContent = 'cannot read office.json: is the office server running? (hivey menu β†’ agent office)'; }
907
+ } catch (e) { console.error('hivey fleet:', e); $('#sub').textContent = 'cannot read office.json: is the office server running? (hivey menu β†’ agent office)'; }
770
908
  }
771
909
  async function refreshNow() {
772
910
  if (refreshing) return;
@@ -779,18 +917,65 @@ async function refreshNow() {
779
917
  }
780
918
  document.querySelectorAll('#views button').forEach(b => b.onclick = () => { ui.view = b.dataset.v; save(); renderAll(); });
781
919
  $('#refresh').onclick = refreshNow;
782
- // background music: a MusicGen space ambient loop, off until you turn it on (browsers block autoplay)
920
+ // βš™ settings panel (music, updates, background): opens under the gear, closes on a click outside or Escape
921
+ const gear = $('#gear'), panel = $('#settings');
922
+ const showSettings = on => { panel.hidden = !on; gear.classList.toggle('on', on); };
923
+ gear.onclick = e => { e.stopPropagation(); showSettings(panel.hidden); };
924
+ panel.addEventListener('click', e => e.stopPropagation());
925
+ document.addEventListener('click', () => showSettings(false));
926
+ document.addEventListener('keydown', e => { if (e.key === 'Escape') showSettings(false); });
927
+ // background music: MusicGen electronic space tracks; 🎡 setting = a new track each time (moving on to another
928
+ // when one ends) or always one (looping). Browsers only allow sound after you touch the page, so when playing
929
+ // right away is refused, the music starts with your first click or key press anywhere.
930
+ const TRACKS = [
931
+ ['space.mp3', 'cosmic ambient'], ['space_02.mp3', 'cosmic ambient II'], ['track_01.mp3', 'dark techno'],
932
+ ['track_02.mp3', 'synthwave cruise'], ['track_03.mp3', 'glitch downtempo'], ['track_04.mp3', 'cinematic drones'],
933
+ ['track_05.mp3', 'lo-fi stars'], ['track_06.mp3', 'berlin sequencer'], ['track_07.mp3', 'deep house orbit'],
934
+ ['track_08.mp3', 'liquid drum & bass'],
935
+ ];
783
936
  const bgm = $('#bgm');
784
937
  bgm.volume = 0.35;
938
+ let trackNo = 0;
939
+ const fixedTrack = () => /^\d+$/.test(String(ui.track)) && +ui.track >= 1 && +ui.track <= TRACKS.length ? +ui.track : 0;
940
+ function loadTrack(n) {
941
+ trackNo = n;
942
+ bgm.src = './music/' + TRACKS[n - 1][0];
943
+ bgm.loop = !!fixedTrack();
944
+ $('#music').title = ui.music ? `Music: ${TRACKS[n - 1][1]} (click to mute, m)` : 'Background music on/off (m)';
945
+ }
946
+ function pickTrack() { // the fixed one, or a random one that is not the one just played
947
+ const f = fixedTrack();
948
+ if (f) return f;
949
+ let n = 1 + Math.floor(Math.random() * TRACKS.length);
950
+ if (n === trackNo && TRACKS.length > 1) n = n % TRACKS.length + 1;
951
+ return n;
952
+ }
953
+ bgm.addEventListener('ended', () => { if (!fixedTrack()) { loadTrack(pickTrack()); if (ui.music && inFront()) bgm.play().catch(() => {}); } });
954
+ let waitingForTouch = false;
955
+ function startOnTouch() { // the browser refused to play before you touched the page: start on the first touch
956
+ if (waitingForTouch) return;
957
+ waitingForTouch = true;
958
+ const go = () => { waitingForTouch = false; removeEventListener('pointerdown', go, true); removeEventListener('keydown', go, true); if (ui.music && bgm.paused) bgm.play().catch(() => {}); };
959
+ addEventListener('pointerdown', go, true); addEventListener('keydown', go, true);
960
+ }
785
961
  function setMusic(on) {
786
962
  ui.music = on; save();
787
963
  $('#music').textContent = on ? '🎡' : 'πŸ”‡';
788
- $('#music').title = on ? 'Music on: click to mute (m)' : 'Background music on/off (m)';
789
- if (on) bgm.play().catch(() => { $('#music').textContent = 'πŸ”‡'; toast('Click πŸ”‡ to start the music'); }); else bgm.pause();
964
+ if (!trackNo) loadTrack(pickTrack());
965
+ $('#music').title = on ? `Music: ${TRACKS[trackNo - 1][1]} (click to mute, m)` : 'Background music on/off (m)';
966
+ if (on) bgm.play().catch(() => startOnTouch()); else bgm.pause();
790
967
  }
791
- $('#music').onclick = () => setMusic(!ui.music);
792
- if (ui.music) addEventListener('pointerdown', () => { if (ui.music && bgm.paused) setMusic(true); }, { once: true });
968
+ $('#music').onclick = e => { e.stopPropagation(); setMusic(!ui.music); };
793
969
  $('#music').textContent = ui.music ? '🎡' : 'πŸ”‡';
970
+ $('#track').value = fixedTrack() ? String(fixedTrack()) : 'random';
971
+ $('#track').onchange = e => {
972
+ ui.track = e.target.value; save();
973
+ loadTrack(pickTrack());
974
+ if (!ui.music) setMusic(true); else bgm.play().catch(() => startOnTouch());
975
+ toast(ui.track === 'random' ? `A new track each time (now: ${TRACKS[trackNo - 1][1]})` : `Music: ${TRACKS[trackNo - 1][1]}, always`);
976
+ post('/hv-office-settings', { track: ui.track }).catch(() => {});
977
+ };
978
+ if (ui.music) { loadTrack(pickTrack()); bgm.play().catch(() => startOnTouch()); }
794
979
  // only while the page is in front of you: pause when you switch to the terminal or another app or tab
795
980
  const inFront = () => !document.hidden && document.hasFocus();
796
981
  function followFocus() { if (!ui.music) return; if (inFront()) bgm.play().catch(() => {}); else bgm.pause(); }
@@ -821,7 +1006,31 @@ poll();
821
1006
  // refresh setting (every minute: a quick pass, the model only for changed statuses; otherwise a full pass)
822
1007
  const post = (path, body) => fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }).then(r => r.json());
823
1008
  function showEvery(m) { if (EVERY_S[m] || m === 'reload') { every = m; $('#every').value = m; tickSub(); } }
824
- post('/hv-office-refresh', { load: true }).then(j => { showEvery(j.every); setTimeout(poll, 2500); setTimeout(poll, 8000); }).catch(() => {});
1009
+ // 🌌 background: a new scene on every load (random) or always the one you pick
1010
+ const SPACE_NAMES = ['violet', 'emerald', 'crimson', 'deep blue', 'golden', 'singularity'];
1011
+ $('#space').value = /^[1-6]$/.test(String(ui.space)) ? String(ui.space) : 'random';
1012
+ $('#space').onchange = e => {
1013
+ ui.space = e.target.value; save();
1014
+ const n = office.setSpace(ui.space);
1015
+ toast(ui.space === 'random' ? `A new space scene every time you open the page (now: ${SPACE_NAMES[n - 1] || '?'})` : `Background: ${SPACE_NAMES[n - 1]}, always`);
1016
+ post('/hv-office-settings', { space: ui.space }).catch(() => {});
1017
+ };
1018
+ post('/hv-office-refresh', { load: true }).then(j => {
1019
+ showEvery(j.every);
1020
+ if (j.space && j.space !== String(ui.space || 'random')) { // the server's choice wins (set in another browser)
1021
+ ui.space = j.space; save(); $('#space').value = j.space;
1022
+ if (j.space !== 'random') office.setSpace(j.space);
1023
+ } else if (!j.space && ui.space) post('/hv-office-settings', { space: String(ui.space) }).catch(() => {});
1024
+ if (j.track && j.track !== String(ui.track || 'random')) { // the music choice made in another browser
1025
+ ui.track = j.track; save(); $('#track').value = j.track;
1026
+ if (fixedTrack() && fixedTrack() !== trackNo) { loadTrack(fixedTrack()); if (ui.music) bgm.play().catch(() => startOnTouch()); }
1027
+ } else if (!j.track && ui.track) post('/hv-office-settings', { track: String(ui.track) }).catch(() => {});
1028
+ const server = j.ships || {}, local = ui.ships || {};
1029
+ if (Object.keys(server).length) { // the server's positions win; rebuild if they differ from this browser's
1030
+ if (JSON.stringify(server) !== JSON.stringify(local)) { ui.ships = server; save(); if (data) renderAll(); }
1031
+ } else if (Object.keys(local).length) saveShips(); // first time: hand this browser's positions to the server
1032
+ setTimeout(poll, 2500); setTimeout(poll, 8000);
1033
+ }).catch(() => {});
825
1034
  $('#every').onchange = e => post('/hv-office-settings', { every: e.target.value })
826
1035
  .then(j => { showEvery(j.every); toast({ minute: 'Updates every minute (summaries only for agents that changed)', '5min': 'Updates every 5 minutes', '15min': 'Updates every 15 minutes', '1h': 'Updates every hour', reload: 'Updates only when you reload or press ⟳' }[j.every]); })
827
1036
  .catch(() => toast('The office server is not answering'));