hivedesk 0.1.1 → 0.2.0
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.
- package/CHANGELOG.md +18 -0
- package/FIRST-RUN.md +14 -0
- package/PROTOCOL.md +16 -3
- package/README.md +45 -5
- package/assets/illustrations/hive-city.svg +113 -0
- package/assets/video-poster.webp +0 -0
- package/i18n/README.pt-BR.md +39 -5
- package/i18n/de.json +174 -0
- package/i18n/en.json +174 -0
- package/i18n/es.json +174 -0
- package/i18n/fr.json +174 -0
- package/i18n/it.json +174 -0
- package/i18n/ja.json +174 -0
- package/i18n/ko.json +174 -0
- package/i18n/pt-BR.json +174 -0
- package/i18n/ru.json +174 -0
- package/i18n/zh-CN.json +174 -0
- package/package.json +1 -1
- package/src/bus.js +7 -1
- package/src/city/demo.js +75 -0
- package/src/city/hops.js +95 -0
- package/src/city/index.js +1507 -0
- package/src/city/router.js +53 -0
- package/src/city/state.js +313 -0
- package/src/city/store.js +91 -0
- package/src/cli.js +3 -0
- package/src/crew/engine.js +40 -3
- package/src/demo.js +30 -2
- package/src/index.js +23 -2
- package/src/server.js +4 -1
- package/ui/city/city.css +204 -0
- package/ui/city/city.js +933 -0
- package/ui/city/collab.js +64 -0
- package/ui/city/layout.js +142 -0
- package/ui/city/mock.js +358 -0
- package/ui/city/model.js +195 -0
- package/ui/city/scene.js +2033 -0
- package/ui/js/main.js +3 -1
- package/ui/lend/collab/roles.js +8 -2
- package/ui/office/office.js +51 -21
- package/ui/office/scene.js +3 -0
- package/ui/screenshots/city-agent-card-1440.png +0 -0
- package/ui/screenshots/city-agent-card-1920.png +0 -0
- package/ui/screenshots/city-bridge-gpu-borrow-1440.png +0 -0
- package/ui/screenshots/city-bridge-gpu-borrow-1920.png +0 -0
- package/ui/screenshots/city-friend-rising-1440.png +0 -0
- package/ui/screenshots/city-friend-rising-1920.png +0 -0
- package/ui/screenshots/city-overview-1440.png +0 -0
- package/ui/screenshots/city-overview-1920.png +0 -0
- package/ui/screenshots/city-review-room-1440.png +0 -0
- package/ui/screenshots/city-review-room-1920.png +0 -0
package/ui/city/model.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Hive City on the UI side: an adapter from the engine's CityState (CITY-PROTOCOL.md, reduced by
|
|
2
|
+
// the engine's own reducer served at /lib/city.js) to the small view the scene and the panels
|
|
3
|
+
// read. Pure module (no DOM), so it runs in the unit tests too. The engine is the source of truth:
|
|
4
|
+
// the scene never moves a bee or raises a building unless this view changed, and the view only
|
|
5
|
+
// changes from a snapshot, an event or a live frame.
|
|
6
|
+
|
|
7
|
+
export const ROOM_KINDS = ['lobby', 'design', 'code', 'review', 'test', 'ops', 'library'];
|
|
8
|
+
export const PIPELINE = ['design', 'code', 'review', 'test'];
|
|
9
|
+
|
|
10
|
+
/** Room colors, the same as the engine's builtin rooms. */
|
|
11
|
+
export const ROOM_COLOR = {
|
|
12
|
+
lobby: '#FFB531', design: '#FF7AB6', code: '#6CC4FF', review: '#C9A7FF', test: '#7BE0A0', ops: '#E8C27A', library: '#9FD3C7',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const MACHINE_COLORS = ['#7DC49B', '#86A9D6', '#FF7AB6', '#C9A7FF', '#E8C27A', '#9FD3C7'];
|
|
16
|
+
|
|
17
|
+
/** Side data the engine state does not keep: presence, live machine load, bridge traffic. */
|
|
18
|
+
export const blankLive = () => ({ people: {}, loads: {}, traffic: [], caption: null, n: 0 });
|
|
19
|
+
|
|
20
|
+
/** XP needed to reach a level: 25 * L * (L - 1) / 2 (the inverse of the engine's levelFor). */
|
|
21
|
+
export const xpFor = (level) => (25 * level * (level - 1)) / 2;
|
|
22
|
+
|
|
23
|
+
/** Progress 0..1 inside the current level. */
|
|
24
|
+
export function xpProgress(a) {
|
|
25
|
+
const lv = Math.max(1, a.level || 1);
|
|
26
|
+
const lo = xpFor(lv); const hi = xpFor(lv + 1);
|
|
27
|
+
return Math.max(0, Math.min(1, ((a.xp || 0) - lo) / Math.max(1, hi - lo)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Notes what a raw event means for the bridges and the captions. The engine reducer handles the
|
|
32
|
+
* state; this only keeps the traffic that the state does not record.
|
|
33
|
+
*/
|
|
34
|
+
export function noteEvent(live, city, ev) {
|
|
35
|
+
const d = ev?.data || {};
|
|
36
|
+
switch (ev?.type) {
|
|
37
|
+
case 'city.borrow.turn': {
|
|
38
|
+
const b = city.borrows?.[d.borrowId];
|
|
39
|
+
if (b) trip(live, 'turn', b.from, b.to, ev, b.agentId);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'turn.started': {
|
|
43
|
+
// a friend's own agent thinks on its own machine: its turns cross the bridge too
|
|
44
|
+
const m = Object.values(city.machines || {}).find((x) => x.brainId && x.brainId === d.brainId);
|
|
45
|
+
const borrowing = Object.values(city.borrows || {}).some((b) => b.status === 'active' && b.to === m?.id);
|
|
46
|
+
if (m && m.id !== city.host && !borrowing) trip(live, 'turn', city.host, m.id, ev, d.workerId);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'city.task.claimed': {
|
|
50
|
+
const a = city.agents?.[d.agentId];
|
|
51
|
+
if (a && a.home && a.home !== city.host) trip(live, 'task', city.host, a.home, ev, d.taskId);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'city.demo.step': live.caption = { step: d.step, text: d.text, at: Date.now() }; break;
|
|
55
|
+
default: break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Applies a live frame (presence, machine load). Returns true when something changed. */
|
|
60
|
+
export function applyLive(live, frame) {
|
|
61
|
+
const d = frame?.data || {};
|
|
62
|
+
switch (frame?.type) {
|
|
63
|
+
case 'city.presence':
|
|
64
|
+
if (!d.id) return false;
|
|
65
|
+
live.people[d.id] = { ...(live.people[d.id] || {}), ...d, seen: Date.now() };
|
|
66
|
+
return true;
|
|
67
|
+
case 'city.presence.left':
|
|
68
|
+
if (!live.people[d.id]) return false;
|
|
69
|
+
delete live.people[d.id];
|
|
70
|
+
return true;
|
|
71
|
+
case 'city.machine.load':
|
|
72
|
+
if (!d.machineId) return false;
|
|
73
|
+
live.loads[d.machineId] = { load: Number(d.load) || 0, queue: d.queue || 0, tps: d.tps || 0 };
|
|
74
|
+
return true;
|
|
75
|
+
default: return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function trip(live, kind, from, to, ev, ref) {
|
|
80
|
+
if (!from || !to || from === to) return;
|
|
81
|
+
live.traffic.push({ id: `${kind}:${ev.seq ?? ++live.n}:${ref || ''}`, kind, from, to, ref });
|
|
82
|
+
if (live.traffic.length > 40) live.traffic.splice(0, live.traffic.length - 40);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const STATUS = { waiting_model: 'waiting', waiting: 'waiting' };
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The view of a CityState. `live` adds presence, load and traffic.
|
|
89
|
+
* @param {any} city CityState
|
|
90
|
+
* @param {ReturnType<typeof blankLive>} [live]
|
|
91
|
+
*/
|
|
92
|
+
export function viewOf(city, live = blankLive()) {
|
|
93
|
+
const v = { ready: !!city, selfId: city?.host || null, machines: {}, rooms: {}, agents: {}, tasks: {}, borrows: {}, pending: [], people: live.people, traffic: live.traffic, caption: live.caption, lastSeq: city?.lastSeq || 0 };
|
|
94
|
+
if (!city) return v;
|
|
95
|
+
let ci = 0;
|
|
96
|
+
const machines = Object.values(city.machines || {}).sort((a, b) => String(a.joinedAt || '').localeCompare(String(b.joinedAt || '')));
|
|
97
|
+
for (const m of machines) {
|
|
98
|
+
const lv = live.loads[m.id];
|
|
99
|
+
v.machines[m.id] = {
|
|
100
|
+
id: m.id, name: m.name || m.id, self: m.id === city.host, host: !!m.host, owner: m.owner || '',
|
|
101
|
+
color: m.color || (m.id === city.host ? '#FFB531' : MACHINE_COLORS[ci++ % MACHINE_COLORS.length]),
|
|
102
|
+
gpu: m.gpu || null, ramBytes: m.ramBytes || null, cpus: m.cpus || null, model: m.model || null,
|
|
103
|
+
load: lv ? lv.load : 0, tps: lv?.tps || 0, queue: lv?.queue || 0,
|
|
104
|
+
lending: { turns: m.lending?.turns || 0, active: m.lending?.active || 0 },
|
|
105
|
+
online: m.online !== false, joinedAt: m.joinedAt || null, via: m.via || null, agents: m.agents || [],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
for (const r of Object.values(city.rooms || {}).sort((a, b) => (a.order ?? 99) - (b.order ?? 99))) {
|
|
109
|
+
v.rooms[r.id] = { id: r.id, name: r.name || r.id, kind: r.kind || 'work', tools: r.tools || [], accepts: r.accepts || [], requireApproval: !!r.requireApproval, hostOnly: !!r.hostOnly, mode: r.mode || null, builtin: !!r.builtin, color: r.color || ROOM_COLOR[r.id] || '#FFB531' };
|
|
110
|
+
}
|
|
111
|
+
if (!Object.keys(v.rooms).length) for (const k of ROOM_KINDS) v.rooms[k] = { id: k, name: k, kind: 'work', tools: [], accepts: [], builtin: true, color: ROOM_COLOR[k] };
|
|
112
|
+
for (const a of Object.values(city.agents || {})) {
|
|
113
|
+
if (a.retired) continue;
|
|
114
|
+
v.agents[a.id] = {
|
|
115
|
+
id: a.id, workerId: a.workerId || a.id, name: a.name || a.id, role: a.role || '', color: a.color || '#FFB531', avatar: a.avatar || null,
|
|
116
|
+
specialization: a.specialization || [], level: a.level || 1, xp: a.xp || 0,
|
|
117
|
+
tools: a.tools || [], permissions: a.permissions || {},
|
|
118
|
+
memory: a.memory?.highlights || [], memoryCount: a.memory?.count || 0,
|
|
119
|
+
room: a.room || 'lobby', taskId: a.taskId || null, status: STATUS[a.status] || a.status || 'idle', rawStatus: a.status || 'idle',
|
|
120
|
+
brain: a.brain || { kind: 'local' }, home: a.home || city.host, builtin: !!a.builtin, stats: a.stats || {},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
for (const t of Object.values(city.tasks || {})) {
|
|
124
|
+
if (t.status === 'cancelled') continue;
|
|
125
|
+
const ag = t.agentId && v.agents[t.agentId];
|
|
126
|
+
v.tasks[t.id] = {
|
|
127
|
+
id: t.id, title: t.title || t.id, detail: t.detail || '', status: t.status || 'open', room: t.room || 'lobby',
|
|
128
|
+
assignee: t.agentId || null, wantAgent: t.wantAgent || null, machineId: ag && ag.home !== city.host ? ag.home : null,
|
|
129
|
+
pipeline: t.pipeline || [], stage: t.stage || 0, loops: t.loops || 0, maxLoops: t.maxLoops || 3, awaiting: t.awaiting || null,
|
|
130
|
+
issues: t.issues || [], files: t.files || [], createdBy: t.createdBy || null, guest: !!t.guest, updatedAt: t.updatedAt || t.createdAt || null,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
for (const b of Object.values(city.borrows || {})) {
|
|
134
|
+
if (b.status === 'active') v.borrows[b.id] = { id: b.id, agentId: b.agentId, from: b.from, to: b.to, limit: b.limit || null, used: b.used || { turns: 0 } };
|
|
135
|
+
else if (b.status === 'pending') v.pending.push({ ...b });
|
|
136
|
+
}
|
|
137
|
+
return v;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* ---------- a city derived from the classic engine state, for an engine without a city ---------- */
|
|
141
|
+
|
|
142
|
+
const ROLE_ROOM = (w) => {
|
|
143
|
+
const r = String(w.role || '').toLowerCase();
|
|
144
|
+
if (w.id === 'mel' || /foreman|plan/.test(r)) return 'lobby';
|
|
145
|
+
if (/review/.test(r)) return 'review';
|
|
146
|
+
if (/qa|test/.test(r)) return 'test';
|
|
147
|
+
if (/design|ui/.test(r)) return 'design';
|
|
148
|
+
if (/writ|doc|copy/.test(r)) return 'library';
|
|
149
|
+
if (/ops|deploy|git/.test(r)) return 'ops';
|
|
150
|
+
return 'code';
|
|
151
|
+
};
|
|
152
|
+
const WSTATUS = { idle: 'idle', queued: 'waiting_model', thinking: 'thinking', tool: 'working', waiting_approval: 'waiting', error: 'idle' };
|
|
153
|
+
const TSTATUS = { pending: 'open', ready: 'open', running: 'in_progress', review: 'in_review', done: 'done', failed: 'blocked', blocked: 'blocked', skipped: 'done' };
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A CityState built from the classic engine State (crew, workers, tasks), so the City view works
|
|
157
|
+
* on an engine that has no city yet.
|
|
158
|
+
*/
|
|
159
|
+
export function deriveCity(s, { hardware = null, label = 'This computer' } = {}) {
|
|
160
|
+
const city = { v: 1, host: 'self', lastSeq: s?.lastSeq || 0, machines: {}, rooms: {}, agents: {}, tasks: {}, borrows: {}, hops: [] };
|
|
161
|
+
city.machines.self = { id: 'self', name: label, host: true, owner: 'host', online: true, gpu: hardware?.gpu || null, model: s?.brain?.model || null, lending: { turns: 0, active: 0 }, agents: [], joinedAt: '' };
|
|
162
|
+
ROOM_KINDS.forEach((k, i) => { city.rooms[k] = { id: k, name: k, kind: k === 'review' ? 'review' : k === 'test' ? 'test' : 'work', tools: [], accepts: [], order: i, builtin: true, color: ROOM_COLOR[k] }; });
|
|
163
|
+
const done = {};
|
|
164
|
+
for (const t of Object.values(s?.tasks || {})) if (t.status === 'done') done[t.assignee] = (done[t.assignee] || 0) + 1;
|
|
165
|
+
for (const w of s?.crew || []) {
|
|
166
|
+
const st = s.workers?.[w.id] || {};
|
|
167
|
+
const xp = (done[w.id] || 0) * 10;
|
|
168
|
+
const level = Math.max(1, Math.floor((1 + Math.sqrt(1 + (8 * xp) / 25)) / 2));
|
|
169
|
+
city.agents[w.id] = { id: w.id, workerId: w.id, name: w.name, role: w.role, color: w.color, specialization: [ROLE_ROOM(w)], level, xp, tools: w.tools || [], memory: { count: 0, highlights: [] }, room: ROLE_ROOM(w), taskId: st.taskId || null, status: w.paused ? 'sleeping' : WSTATUS[st.status] || 'idle', brain: { kind: 'local', machineId: 'self' }, home: 'self', builtin: !!w.builtin };
|
|
170
|
+
city.machines.self.agents.push(w.id);
|
|
171
|
+
}
|
|
172
|
+
const job = [...(s?.jobs || [])].reverse().find((j) => ['refining', 'awaiting_brief', 'planning', 'running'].includes(j.status)) || (s?.jobs || [])[(s?.jobs || []).length - 1];
|
|
173
|
+
for (const id of job?.taskIds || []) {
|
|
174
|
+
const t = s.tasks?.[id];
|
|
175
|
+
if (!t) continue;
|
|
176
|
+
const status = TSTATUS[t.status] || 'open';
|
|
177
|
+
const a = city.agents[t.assignee];
|
|
178
|
+
const room = status === 'open' || status === 'done' ? 'lobby' : status === 'in_review' ? 'review' : (a?.room || 'code');
|
|
179
|
+
city.tasks[id] = { id, title: t.title, detail: t.detail, status, room, agentId: status === 'open' ? null : t.assignee, pipeline: [], stage: 0, loops: 0, issues: [] };
|
|
180
|
+
}
|
|
181
|
+
return city;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* ---------- small helpers shared by the scene and the panels ---------- */
|
|
185
|
+
|
|
186
|
+
export const borrowOf = (v, agentId) => Object.values(v.borrows || {}).find((b) => b.agentId === agentId) || null;
|
|
187
|
+
export const pendingOf = (v, agentId) => (v.pending || []).find((b) => b.agentId === agentId) || null;
|
|
188
|
+
export const friends = (v) => Object.values(v.machines).filter((m) => m.id !== v.selfId);
|
|
189
|
+
export const tasksIn = (v, room) => Object.values(v.tasks).filter((t) => t.room === room && t.status !== 'done');
|
|
190
|
+
export const agentsIn = (v, room) => Object.values(v.agents).filter((a) => a.room === room);
|
|
191
|
+
|
|
192
|
+
export function fmtVram(bytes) {
|
|
193
|
+
if (!bytes) return '';
|
|
194
|
+
return `${(bytes / 1024 ** 3).toFixed(bytes >= 10 * 1024 ** 3 ? 0 : 1)} GB`;
|
|
195
|
+
}
|