hivedesk 0.1.0 → 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 +24 -0
- package/FIRST-RUN.md +14 -0
- package/PROTOCOL.md +16 -3
- package/README.md +50 -6
- package/assets/illustrations/hive-city.svg +113 -0
- package/assets/video-poster.webp +0 -0
- package/i18n/README.pt-BR.md +44 -6
- 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/i18n/zh-CN.json
CHANGED
|
@@ -222,6 +222,178 @@
|
|
|
222
222
|
"chat.send": "发送",
|
|
223
223
|
"chat.thinking": "{count, plural, other {{names} 正在思考}}",
|
|
224
224
|
"chat.waiting": "{names} 正在等待使用模型",
|
|
225
|
+
"city.agent.status.idle": "空闲",
|
|
226
|
+
"city.agent.status.offline": "离线",
|
|
227
|
+
"city.agent.status.reviewing": "评审中",
|
|
228
|
+
"city.agent.status.sleeping": "睡眠中",
|
|
229
|
+
"city.agent.status.testing": "测试中",
|
|
230
|
+
"city.agent.status.thinking": "思考中",
|
|
231
|
+
"city.agent.status.waiting": "等待中",
|
|
232
|
+
"city.agent.status.working": "工作中",
|
|
233
|
+
"city.aria.layer": "Hive City。按 Tab 选中一只蜜蜂,按 Enter 打开它的卡片。把看板上的便签拖到蜜蜂或房间上。",
|
|
234
|
+
"city.board.add": "添加",
|
|
235
|
+
"city.board.count": "{n, plural, =0 {暂无} other {# 个}}",
|
|
236
|
+
"city.board.draft": "拖到蜜蜂或房间上,或按 Enter 放进大厅",
|
|
237
|
+
"city.board.empty": "还没有任务。在上面写一个,或直接拖到房间里。",
|
|
238
|
+
"city.board.placeholder": "给城市的新任务",
|
|
239
|
+
"city.board.sub": "把便签拖到蜜蜂或房间上",
|
|
240
|
+
"city.board.title": "任务看板",
|
|
241
|
+
"city.borrow.accept": "接受",
|
|
242
|
+
"city.borrow.active": "{agent} 正在借用 {machine} 的 GPU",
|
|
243
|
+
"city.borrow.asking": "正在请求 GPU",
|
|
244
|
+
"city.borrow.refuse": "拒绝",
|
|
245
|
+
"city.borrow.request": "{agent} 想借用 {machine} 的 GPU",
|
|
246
|
+
"city.borrow.stop": "停止借用",
|
|
247
|
+
"city.borrow.turns": "{used}/{limit} 轮",
|
|
248
|
+
"city.brain.cloud": "云端",
|
|
249
|
+
"city.brain.lent": "借来的 GPU",
|
|
250
|
+
"city.brain.local": "本地模型",
|
|
251
|
+
"city.brain.remote": "它自己的机器",
|
|
252
|
+
"city.card.addMemory": "要记住的事",
|
|
253
|
+
"city.card.borrow": "借用 {name} 的 GPU",
|
|
254
|
+
"city.card.brain": "大脑",
|
|
255
|
+
"city.card.chat": "聊天",
|
|
256
|
+
"city.card.close": "关闭",
|
|
257
|
+
"city.card.delete": "忘记",
|
|
258
|
+
"city.card.doneEditing": "完成",
|
|
259
|
+
"city.card.editMemory": "编辑记忆",
|
|
260
|
+
"city.card.friendAgent": "这个智能体住在朋友的机器上:只有主人能改它的记忆和工具。",
|
|
261
|
+
"city.card.home": "家",
|
|
262
|
+
"city.card.level": "等级 {n}",
|
|
263
|
+
"city.card.memory": "记忆",
|
|
264
|
+
"city.card.memoryCount": "{n, plural, =0 {暂无} other {# 条}}",
|
|
265
|
+
"city.card.memoryEmpty": "还没有记住任何东西",
|
|
266
|
+
"city.card.moveTo": "移到房间",
|
|
267
|
+
"city.card.none": "暂时没有",
|
|
268
|
+
"city.card.open": "打开卡片",
|
|
269
|
+
"city.card.pin": "置顶",
|
|
270
|
+
"city.card.retire": "让它退休",
|
|
271
|
+
"city.card.room": "房间",
|
|
272
|
+
"city.card.save": "保存",
|
|
273
|
+
"city.card.sleep": "让它休息",
|
|
274
|
+
"city.card.spec": "工作于",
|
|
275
|
+
"city.card.stats": "完成 {done} 个任务,评审 {reviews} 次,测试 {tests} 次",
|
|
276
|
+
"city.card.task": "任务",
|
|
277
|
+
"city.card.tools": "工具",
|
|
278
|
+
"city.card.toolsHelp": "在房间里,房间规则还会进一步收窄。",
|
|
279
|
+
"city.card.unpin": "取消置顶",
|
|
280
|
+
"city.card.wake": "唤醒",
|
|
281
|
+
"city.card.xp": "{xp} XP,距离等级 {next} 还差 {left}",
|
|
282
|
+
"city.demo": "演示",
|
|
283
|
+
"city.demo.borrow": "Dev 的机器很忙,于是他请求借用 Rita 的 GPU 三轮。",
|
|
284
|
+
"city.demo.done": "完成:任务走过了每个房间,每一步都是一个事件。",
|
|
285
|
+
"city.demo.friend": "Rita 用六个词加入。她的大楼在桥对面拔地而起,还带来了评审员 Pip。",
|
|
286
|
+
"city.demo.lent": "Rita 同意了。Dev 走过桥去:他接下来的几轮在她的 GPU 上运行。",
|
|
287
|
+
"city.demo.task": "一张任务便签落进设计室。它依次经过设计、编码、评审、测试,然后完成。",
|
|
288
|
+
"city.dock": "Hive City",
|
|
289
|
+
"city.dock.sub": "每台机器、每个房间和每个智能体",
|
|
290
|
+
"city.drop.agent": "交给 {name}",
|
|
291
|
+
"city.drop.room": "送到 {room}",
|
|
292
|
+
"city.err.generic": "没有成功",
|
|
293
|
+
"city.err.noCity": "这个引擎还没有城市",
|
|
294
|
+
"city.feed": "城市动态",
|
|
295
|
+
"city.feed.agentJoined": "{name} 搬进来了",
|
|
296
|
+
"city.feed.blocked": "「{title}」受阻",
|
|
297
|
+
"city.feed.borrowAsk": "{agent} 请求使用 {machine} 的 GPU",
|
|
298
|
+
"city.feed.borrowEnd": "{agent} 回家了",
|
|
299
|
+
"city.feed.borrowStart": "{agent} 过桥前往 {machine}",
|
|
300
|
+
"city.feed.claimed": "{agent} 认领了「{title}」",
|
|
301
|
+
"city.feed.done": "「{title}」完成了",
|
|
302
|
+
"city.feed.hop": "「{title}」进入了{room}",
|
|
303
|
+
"city.feed.leveled": "{agent} 升到了等级 {n}",
|
|
304
|
+
"city.feed.machineJoined": "{name} 加入了城市",
|
|
305
|
+
"city.feed.machineLeft": "{name} 离开了城市",
|
|
306
|
+
"city.feed.taskCreated": "新任务:{title}",
|
|
307
|
+
"city.feed.verdictBad": "{agent} 退回了「{title}」",
|
|
308
|
+
"city.feed.verdictOk": "{agent} 通过了「{title}」",
|
|
309
|
+
"city.fit": "整个城市",
|
|
310
|
+
"city.fx.borrowing": "借来的 GPU",
|
|
311
|
+
"city.fx.level": "等级 {n}!",
|
|
312
|
+
"city.fx.xp": "+{n} XP",
|
|
313
|
+
"city.invite": "邀请朋友",
|
|
314
|
+
"city.machine.agents": "住在这里的智能体",
|
|
315
|
+
"city.machine.friend": "朋友",
|
|
316
|
+
"city.machine.gpu": "GPU",
|
|
317
|
+
"city.machine.host": "主机",
|
|
318
|
+
"city.machine.lent": "已出借",
|
|
319
|
+
"city.machine.lentValue": "已服务 {turns, plural, other {# 轮}},{active} 个进行中",
|
|
320
|
+
"city.machine.limits": "出借方在接受借用时设定上限。",
|
|
321
|
+
"city.machine.load": "负载",
|
|
322
|
+
"city.machine.model": "模型",
|
|
323
|
+
"city.machine.noGpu": "没有 GPU,在 CPU 上运行",
|
|
324
|
+
"city.machine.offline": "离线",
|
|
325
|
+
"city.machine.online": "在线",
|
|
326
|
+
"city.machine.thisPc": "这台电脑",
|
|
327
|
+
"city.machine.title": "机器",
|
|
328
|
+
"city.machine.via.demo": "在演示中加入",
|
|
329
|
+
"city.machine.via.link": "通过链接加入",
|
|
330
|
+
"city.machine.via.qr": "扫码加入",
|
|
331
|
+
"city.machine.via.words": "用六个词加入",
|
|
332
|
+
"city.machine.vram": "显存",
|
|
333
|
+
"city.machine.you": "你的大楼",
|
|
334
|
+
"city.machines": "机器",
|
|
335
|
+
"city.memory.kind.decision": "决定",
|
|
336
|
+
"city.memory.kind.fact": "事实",
|
|
337
|
+
"city.memory.kind.preference": "偏好",
|
|
338
|
+
"city.memory.kind.task": "过往任务",
|
|
339
|
+
"city.menu.handTo": "交给",
|
|
340
|
+
"city.menu.sendTo": "送到房间",
|
|
341
|
+
"city.mock": "演示城市",
|
|
342
|
+
"city.phase.afternoon": "下午",
|
|
343
|
+
"city.phase.day": "白天",
|
|
344
|
+
"city.phase.evening": "傍晚",
|
|
345
|
+
"city.phase.morning": "早晨",
|
|
346
|
+
"city.phase.night": "夜晚",
|
|
347
|
+
"city.room.about.code": "编写文件的地方。在这里完成的任务会进入评审,然后进入测试。",
|
|
348
|
+
"city.room.about.design": "布局、配色和外观。在这里开始的工作会走完整个流程:设计、编码、评审、测试。",
|
|
349
|
+
"city.room.about.library": "记忆和剧本。文档和笔记在这里写成。",
|
|
350
|
+
"city.room.about.lobby": "前台。Mel 在这里阅读新任务,并把它们规划成其他房间的工作。",
|
|
351
|
+
"city.room.about.ops": "Git 和部署。只有主机能把任务送到这里,每一步都要等你批准。",
|
|
352
|
+
"city.room.about.review": "另一个智能体按照标准阅读改动。评审不通过时任务会退回它的工作房间。",
|
|
353
|
+
"city.room.about.test": "检查在这里运行。测试失败时任务会退回,最多三次。",
|
|
354
|
+
"city.room.code": "编码",
|
|
355
|
+
"city.room.design": "设计",
|
|
356
|
+
"city.room.library": "图书馆",
|
|
357
|
+
"city.room.lobby": "大厅",
|
|
358
|
+
"city.room.ops": "运维",
|
|
359
|
+
"city.room.review": "评审",
|
|
360
|
+
"city.room.test": "测试",
|
|
361
|
+
"city.roomPanel.agents": "现在在这里",
|
|
362
|
+
"city.roomPanel.approval": "等待你的批准",
|
|
363
|
+
"city.roomPanel.back": "回到城市",
|
|
364
|
+
"city.roomPanel.empty": "现在没有人",
|
|
365
|
+
"city.roomPanel.hostOnly": "仅限主机",
|
|
366
|
+
"city.roomPanel.mode.auto": "评审:自动",
|
|
367
|
+
"city.roomPanel.mode.checks": "评审:仅检查",
|
|
368
|
+
"city.roomPanel.mode.model": "评审:由智能体",
|
|
369
|
+
"city.roomPanel.noTasks": "这里没有任务",
|
|
370
|
+
"city.roomPanel.noTools": "这里没有工具:这个房间用来做计划",
|
|
371
|
+
"city.roomPanel.rules": "规则",
|
|
372
|
+
"city.roomPanel.tasks": "这个房间的任务",
|
|
373
|
+
"city.roomPanel.tools": "允许使用的工具",
|
|
374
|
+
"city.rooms": "房间",
|
|
375
|
+
"city.stat.agents": "{n, plural, other {个智能体}}",
|
|
376
|
+
"city.stat.machines": "{n, plural, other {台机器}}",
|
|
377
|
+
"city.stat.moving": "{n, plural, other {个任务进行中}}",
|
|
378
|
+
"city.task.approve": "批准",
|
|
379
|
+
"city.task.awaiting": "等你处理",
|
|
380
|
+
"city.task.cancel": "取消任务",
|
|
381
|
+
"city.task.loops": "第 {n}/{max} 轮",
|
|
382
|
+
"city.task.reject": "退回",
|
|
383
|
+
"city.task.rejectNote": "从城市退回",
|
|
384
|
+
"city.task.retry": "重试",
|
|
385
|
+
"city.task.status.blocked": "受阻",
|
|
386
|
+
"city.task.status.claimed": "已认领",
|
|
387
|
+
"city.task.status.done": "已完成",
|
|
388
|
+
"city.task.status.in_progress": "进行中",
|
|
389
|
+
"city.task.status.in_review": "评审中",
|
|
390
|
+
"city.task.status.in_test": "测试中",
|
|
391
|
+
"city.task.status.open": "待处理",
|
|
392
|
+
"city.title": "Hive City",
|
|
393
|
+
"city.view": "城市",
|
|
394
|
+
"city.you": "你",
|
|
395
|
+
"city.zoomIn": "放大",
|
|
396
|
+
"city.zoomOut": "缩小",
|
|
225
397
|
"cli.brain.choice.cpu": "{why},{ram} 内存:使用 {model}({size}),在 CPU 上运行。",
|
|
226
398
|
"cli.brain.choice.cpuLowRam": "{why},内存仅 {ram}:使用 {model}({size}),在 CPU 上运行。",
|
|
227
399
|
"cli.brain.choice.forced": "已通过 --model 或在设置中选择 {model},{where, select, gpu {在 GPU 上运行} other {在 CPU 上运行}}。",
|
|
@@ -1618,6 +1790,8 @@
|
|
|
1618
1790
|
"tip.chat.cancelReply.title": "取消回复",
|
|
1619
1791
|
"tip.chat.send.help": "发送你写的内容。按 Shift Enter 换行。",
|
|
1620
1792
|
"tip.chat.send.title": "发送消息",
|
|
1793
|
+
"tip.city.view.help": "你的大楼、朋友的大楼和每个正在工作的智能体,实时呈现",
|
|
1794
|
+
"tip.city.view.title": "城市",
|
|
1621
1795
|
"tip.conn.retry.help": "立即再次尝试连接这台电脑上的 hivedesk。",
|
|
1622
1796
|
"tip.conn.retry.title": "立即重试",
|
|
1623
1797
|
"tip.dialog.close.help": "关闭此对话框。",
|
package/package.json
CHANGED
package/src/bus.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { initialState, reduce, replay } from './replay/reduce.js';
|
|
5
|
+
import { reduceCity, replayCity } from './city/state.js';
|
|
5
6
|
|
|
6
7
|
export class EventBus {
|
|
7
8
|
/**
|
|
@@ -21,6 +22,8 @@ export class EventBus {
|
|
|
21
22
|
if (this.file && fs.existsSync(this.file)) this.events = readEventsFile(this.file);
|
|
22
23
|
this.seq = this.events.length ? this.events[this.events.length - 1].seq : 0;
|
|
23
24
|
this.state = replay(this.events, Infinity, this.meta);
|
|
25
|
+
// Hive City (src/city/): the same log, its own pure reducer (CITY-PROTOCOL.md).
|
|
26
|
+
this.state.city = replayCity(this.events);
|
|
24
27
|
this.state.demo = this.demo || this.state.demo;
|
|
25
28
|
this.state.lend = this.meta.lend;
|
|
26
29
|
if (opts.version) this.state.version = opts.version;
|
|
@@ -41,6 +44,7 @@ export class EventBus {
|
|
|
41
44
|
this.events.push(event);
|
|
42
45
|
if (this.file) fs.appendFileSync(this.file, JSON.stringify(event) + '\n');
|
|
43
46
|
reduce(this.state, event);
|
|
47
|
+
reduceCity(this.state.city, event);
|
|
44
48
|
this._scheduleSnapshot();
|
|
45
49
|
for (const fn of this.listeners) {
|
|
46
50
|
try { fn(event); } catch (err) { /* a listener must never break the log */ }
|
|
@@ -71,6 +75,7 @@ export class EventBus {
|
|
|
71
75
|
|
|
72
76
|
stateAt(seq) {
|
|
73
77
|
const s = replay(this.events, seq, this.meta);
|
|
78
|
+
s.city = replayCity(this.events, seq);
|
|
74
79
|
s.demo = this.demo || s.demo;
|
|
75
80
|
return s;
|
|
76
81
|
}
|
|
@@ -122,7 +127,8 @@ export function initHome(dir) {
|
|
|
122
127
|
events: path.join(root, 'events.jsonl'),
|
|
123
128
|
state: path.join(root, 'state.json'),
|
|
124
129
|
playbooks: path.join(root, 'playbooks'),
|
|
125
|
-
workspace: path.join(root, 'workspace')
|
|
130
|
+
workspace: path.join(root, 'workspace'),
|
|
131
|
+
city: path.join(root, 'city')
|
|
126
132
|
};
|
|
127
133
|
for (const p of [root, paths.playbooks, paths.workspace]) fs.mkdirSync(p, { recursive: true });
|
|
128
134
|
return paths;
|
package/src/city/demo.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The --demo city scenario (CITY-PROTOCOL.md section 9). No model runs: the demo brain answers
|
|
2
|
+
// for both machines. Every event is labeled demo by the bus; each step has a city.demo.step caption.
|
|
3
|
+
// 1. Rita joins with the six words, her building rises, she contributes Pip, a reviewer.
|
|
4
|
+
// 2. Dev's machine is busy, so Dev borrows Rita's GPU for three turns, then the borrow ends.
|
|
5
|
+
// 3. A task dropped in the Design room flows Design, Code, Review (Pip), Test and done.
|
|
6
|
+
import { createDemoBrain, DEMO_CITY_TASK } from '../demo.js';
|
|
7
|
+
|
|
8
|
+
export const DEMO_FRIEND = Object.freeze({
|
|
9
|
+
owner: 'peer:demo-rita',
|
|
10
|
+
brainId: 'b_demo_rita',
|
|
11
|
+
machine: { id: 'm_demo_rita', name: "Rita's PC", gpu: { name: 'NVIDIA GeForce RTX 3060', vramBytes: 12 * 1024 ** 3 }, ramBytes: 32 * 1024 ** 3, cpus: 12, model: 'Qwen2.5-Coder 7B (demo)', color: '#7fc98f' },
|
|
12
|
+
agents: [{ id: 'pip', name: 'Pip', role: 'Reviewer', avatar: 'P', color: '#9FD3C7', specialization: ['review', 'test'], tools: ['list_files', 'read_file', 'check'], xp: 30 }]
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** Resolves when no crew job is running (the demo task edits the page the bakery job builds). */
|
|
16
|
+
function jobsIdle(bus, signal) {
|
|
17
|
+
const busy = () => bus.state.jobs.some((j) => ['refining', 'awaiting_brief', 'planning', 'running'].includes(j.status));
|
|
18
|
+
if (!busy()) return Promise.resolve();
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const off = bus.on(() => { if (!busy()) { off(); resolve(); } });
|
|
21
|
+
signal?.addEventListener('abort', () => { off(); resolve(); }, { once: true });
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const sleep = (ms, signal) => new Promise((resolve) => {
|
|
26
|
+
if (!ms) return resolve();
|
|
27
|
+
const t = setTimeout(resolve, ms);
|
|
28
|
+
t.unref?.();
|
|
29
|
+
signal?.addEventListener('abort', () => { clearTimeout(t); resolve(); }, { once: true });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ city: import('./index.js').City, scheduler: any, bus: any, stepMs?: number, signal?: AbortSignal }} opts
|
|
34
|
+
* @returns {Promise<{ taskId: string }>}
|
|
35
|
+
*/
|
|
36
|
+
export async function runCityDemo({ city, scheduler, bus, stepMs = 1800, signal }) {
|
|
37
|
+
const step = (name, text) => bus.emit('city.demo.step', { step: name, text });
|
|
38
|
+
const rita = { guest: true, id: 'demo-rita', name: 'Rita', owner: DEMO_FRIEND.owner };
|
|
39
|
+
const host = { guest: false, id: 'h', name: 'You', owner: 'host' };
|
|
40
|
+
|
|
41
|
+
// 1. A friend joins: her brain is attached first (as the lend relay would), then her building.
|
|
42
|
+
const brain = createDemoBrain({ id: DEMO_FRIEND.brainId, label: "Rita's PC (demo)", delayMs: stepMs ? 300 : 0, tokenDelayMs: stepMs ? 15 : 0 });
|
|
43
|
+
brain.kind = 'remote';
|
|
44
|
+
brain.only = new Set();
|
|
45
|
+
scheduler.addBrain(brain);
|
|
46
|
+
step('friend', 'Rita joined with the six words. Her building rises across the bridge, and she brings Pip, a reviewer.');
|
|
47
|
+
city.joinMachine({ machine: DEMO_FRIEND.machine, agents: DEMO_FRIEND.agents, brainId: DEMO_FRIEND.brainId, via: 'words' }, DEMO_FRIEND.owner);
|
|
48
|
+
await sleep(stepMs, signal);
|
|
49
|
+
if (signal?.aborted || city.closed) return null;
|
|
50
|
+
|
|
51
|
+
// 2. Borrow a GPU across the bridge.
|
|
52
|
+
step('borrow', "Dev's machine is busy with the bakery job, so Dev asks to borrow Rita's GPU for three turns.");
|
|
53
|
+
let borrow = null;
|
|
54
|
+
try { borrow = city.requestBorrow({ agentId: 'dev', machineId: DEMO_FRIEND.machine.id, turns: 3, minutes: 5 }, host); } catch { /* Dev is missing in a custom crew */ }
|
|
55
|
+
await sleep(Math.round(stepMs * 0.8), signal);
|
|
56
|
+
if (signal?.aborted || city.closed) return null;
|
|
57
|
+
if (borrow) {
|
|
58
|
+
city.answerBorrow({ borrowId: borrow.id, accept: true, turns: 3 }, rita);
|
|
59
|
+
step('lent', 'Rita said yes. Dev walks across the bridge: his next three model turns run on her GPU.');
|
|
60
|
+
}
|
|
61
|
+
await sleep(stepMs, signal);
|
|
62
|
+
if (signal?.aborted || city.closed) return null;
|
|
63
|
+
|
|
64
|
+
// 3. A task through every room, once the bakery page it changes is built.
|
|
65
|
+
await jobsIdle(bus, signal);
|
|
66
|
+
if (signal?.aborted || city.closed) return null;
|
|
67
|
+
step('task', 'A task note lands in the Design room. It goes Design, Code, Review, Test, then done.');
|
|
68
|
+
const task = city.createTask({ title: DEMO_CITY_TASK.title, detail: DEMO_CITY_TASK.detail, room: 'design' }, host);
|
|
69
|
+
city.onTaskDone = (id) => {
|
|
70
|
+
if (id !== task.id) return;
|
|
71
|
+
city.onTaskDone = null;
|
|
72
|
+
step('done', 'Done: the task went through Design, Code, Review and Test. Every hop was an event.');
|
|
73
|
+
};
|
|
74
|
+
return { taskId: task.id };
|
|
75
|
+
}
|
package/src/city/hops.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// What happens inside a room: the prompts and checks of the Design, Review and Test hops.
|
|
2
|
+
// Work rooms (Code, Library, Ops) run a crew job with one task; see City._work in index.js.
|
|
3
|
+
import { checkWorkspace } from '../tools/check.js';
|
|
4
|
+
|
|
5
|
+
export const DESIGN_SCHEMA = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
spec: { type: 'string', description: 'a short spec for the builder: what to change, in which files, how it should look' },
|
|
9
|
+
criteria: { type: 'array', items: { type: 'string' }, maxItems: 6, description: 'checkable acceptance criteria' }
|
|
10
|
+
},
|
|
11
|
+
required: ['spec', 'criteria'],
|
|
12
|
+
additionalProperties: false
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const REVIEW_SCHEMA = {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
approved: { type: 'boolean' },
|
|
19
|
+
issues: { type: 'array', items: { type: 'string' }, maxItems: 6, description: 'each a concrete problem and its fix; empty when approved' }
|
|
20
|
+
},
|
|
21
|
+
required: ['approved', 'issues'],
|
|
22
|
+
additionalProperties: false
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const cut = (s, n) => (s.length > n ? `${s.slice(0, n)}\n[cut]` : s);
|
|
26
|
+
|
|
27
|
+
export function designMessages(agent, task, files = []) {
|
|
28
|
+
return [
|
|
29
|
+
{ role: 'system', content: `You are ${agent.name}, ${agent.role}, working in the Design room of a small crew. You do not write files here: you write a short, concrete spec that a developer can build from, and acceptance criteria that a tester can check. Answer with JSON only.` },
|
|
30
|
+
{
|
|
31
|
+
role: 'user',
|
|
32
|
+
content: [
|
|
33
|
+
`Task: ${task.title}`,
|
|
34
|
+
task.detail ? `Detail: ${task.detail}` : '',
|
|
35
|
+
task.criteria?.length ? `Criteria so far:\n- ${task.criteria.join('\n- ')}` : '',
|
|
36
|
+
files.length ? `Files in the workspace: ${files.join(', ')}` : 'The workspace is empty.',
|
|
37
|
+
'Write the spec (at most 12 lines) and up to 6 criteria.'
|
|
38
|
+
].filter(Boolean).join('\n\n')
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** diffs: [{ path, diff }] from the file.changed events of the work hop. */
|
|
44
|
+
export function reviewMessages(agent, task, diffs, checks) {
|
|
45
|
+
let budget = 9000;
|
|
46
|
+
const shown = [];
|
|
47
|
+
for (const d of diffs) {
|
|
48
|
+
if (budget <= 0) break;
|
|
49
|
+
const text = cut(String(d.diff || ''), Math.min(4000, budget));
|
|
50
|
+
budget -= text.length;
|
|
51
|
+
shown.push(`--- ${d.path}\n${text}`);
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
{ role: 'system', content: `You are ${agent.name}, ${agent.role}, in the Review room. A teammate changed files for a task. Read the diff and check it against the task and its criteria. Approve only when the change does what the task asks and nothing is broken. Each issue is one concrete problem with its fix. Answer with JSON only.` },
|
|
55
|
+
{
|
|
56
|
+
role: 'user',
|
|
57
|
+
content: [
|
|
58
|
+
`Task: ${task.title}`,
|
|
59
|
+
task.detail ? `Detail: ${task.detail}` : '',
|
|
60
|
+
task.spec ? `Spec from Design:\n${task.spec}` : '',
|
|
61
|
+
task.criteria?.length ? `Criteria:\n- ${task.criteria.join('\n- ')}` : '',
|
|
62
|
+
`Automatic checks on the changed files: ${checks.issues.length ? `issues:\n- ${checks.issues.join('\n- ')}` : 'all passed'}`,
|
|
63
|
+
shown.length ? `The diff:\n${shown.join('\n')}` : 'No file changed in this task.'
|
|
64
|
+
].filter(Boolean).join('\n\n')
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The static checks of the changed files.
|
|
71
|
+
* links: false ignores "links to" issues (another task may not have written that file yet).
|
|
72
|
+
*/
|
|
73
|
+
export function checkFiles(ws, files, { links = true } = {}) {
|
|
74
|
+
const exist = files.filter((f) => { try { return ws.exists(f); } catch { return false; } });
|
|
75
|
+
if (!exist.length) return { passed: true, issues: [], checked: [] };
|
|
76
|
+
const r = checkWorkspace(ws, exist);
|
|
77
|
+
const issues = links ? r.issues : r.issues.filter((i) => !/ links to /.test(i));
|
|
78
|
+
return { passed: issues.length === 0, issues: issues.slice(0, 12), checked: exist };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Normalizes a model's review answer; the checks win over an approval. */
|
|
82
|
+
export function readReview(json, checks) {
|
|
83
|
+
const issues = Array.isArray(json?.issues) ? json.issues.map((x) => String(x).trim()).filter(Boolean).slice(0, 6) : [];
|
|
84
|
+
let approved = json?.approved === true && issues.length === 0;
|
|
85
|
+
for (const i of checks.issues) if (!issues.includes(i)) issues.push(i);
|
|
86
|
+
if (checks.issues.length) approved = false;
|
|
87
|
+
if (!approved && !issues.length) issues.push('The reviewer did not approve the change.');
|
|
88
|
+
return { passed: approved, issues };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function readDesign(json, task) {
|
|
92
|
+
const spec = String(json?.spec || '').trim().slice(0, 3000);
|
|
93
|
+
const criteria = Array.isArray(json?.criteria) ? json.criteria.map((x) => String(x).trim()).filter(Boolean).slice(0, 6) : [];
|
|
94
|
+
return { spec: spec || task.detail || task.title, criteria: criteria.length ? criteria : task.criteria || [] };
|
|
95
|
+
}
|