hive-swarm 2.0.0 → 2.1.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/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -3
- package/board.css +314 -163
- package/board.html +108 -40
- package/board.js +924 -100
- package/codex.mjs +16 -5
- package/core.mjs +40 -6
- package/engine.mjs +188 -9
- package/hive-bees.js +110 -64
- package/hive-gif.js +756 -0
- package/hive-graph.js +1409 -383
- package/installer.mjs +36 -16
- package/package.json +2 -1
- package/server.mjs +43 -12
- package/skills/swarm/SKILL.md +6 -5
- package/worktrees.mjs +167 -98
package/codex.mjs
CHANGED
|
@@ -207,6 +207,7 @@ export class CodexRunner {
|
|
|
207
207
|
this.loadedThreads = new Map();
|
|
208
208
|
this.threadHolds = new Map();
|
|
209
209
|
this.modelProviders = new Map();
|
|
210
|
+
this.modelsHydrated = false;
|
|
210
211
|
this.supportsAttachToSource = true;
|
|
211
212
|
this.supportsModelFallbackFlag = true;
|
|
212
213
|
this.sequence = 0;
|
|
@@ -254,6 +255,7 @@ export class CodexRunner {
|
|
|
254
255
|
this.child = null;
|
|
255
256
|
this.ready = null;
|
|
256
257
|
this.loadedThreads.clear();
|
|
258
|
+
this.modelsHydrated = false;
|
|
257
259
|
this.supportsAttachToSource = true;
|
|
258
260
|
this.supportsModelFallbackFlag = true;
|
|
259
261
|
for (const request of this.pending.values()) request.reject(Error(message));
|
|
@@ -311,13 +313,14 @@ export class CodexRunner {
|
|
|
311
313
|
let cursor;
|
|
312
314
|
do {
|
|
313
315
|
const page = await this.rpc('model/list', {cursor, limit: 100, includeHidden: false});
|
|
314
|
-
for (const entry of page
|
|
316
|
+
for (const entry of (page?.data ?? []).filter(model => !model.hidden)) {
|
|
315
317
|
models.push(entry);
|
|
316
318
|
const provider = entry.modelProvider ?? entry.provider;
|
|
317
319
|
if (entry.model && typeof provider === 'string' && provider) this.modelProviders.set(entry.model, provider);
|
|
318
320
|
}
|
|
319
|
-
cursor = page
|
|
321
|
+
cursor = page?.nextCursor;
|
|
320
322
|
} while (cursor);
|
|
323
|
+
this.modelsHydrated = true;
|
|
321
324
|
return models;
|
|
322
325
|
}
|
|
323
326
|
|
|
@@ -462,8 +465,16 @@ export class CodexRunner {
|
|
|
462
465
|
async run({team, member, remember, declaredOutcome, peerToken, peerPort, onActivity}) {
|
|
463
466
|
await this.start();
|
|
464
467
|
const model = member.model ?? team.model;
|
|
468
|
+
let catalog;
|
|
469
|
+
if (model && (member.effort === null || (!this.modelProviders.has(model) && !this.modelsHydrated))) {
|
|
470
|
+
try {
|
|
471
|
+
catalog = await this.listModels();
|
|
472
|
+
} catch (error) {
|
|
473
|
+
if (member.effort === null) throw error;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
465
476
|
const effort = member.effort === null && model
|
|
466
|
-
?
|
|
477
|
+
? catalog?.find(entry => entry.model === model)?.defaultReasoningEffort
|
|
467
478
|
: configuredEffort(team, member);
|
|
468
479
|
const cwd = member.workspace?.cwd ?? team.cwd;
|
|
469
480
|
let scope = {
|
|
@@ -471,8 +482,8 @@ export class CodexRunner {
|
|
|
471
482
|
approvalPolicy: 'never', model,
|
|
472
483
|
config: {...peerConfig(team, member, peerToken, peerPort), ...(effort ? {model_reasoning_effort: effort} : {})},
|
|
473
484
|
};
|
|
474
|
-
if (model
|
|
475
|
-
else if (model
|
|
485
|
+
if (model && this.modelProviders.has(model)) scope.modelProvider = this.modelProviders.get(model);
|
|
486
|
+
else if (model?.startsWith('xingchi/')) scope.modelProvider = 'desktop-xingchi';
|
|
476
487
|
const requestedProvider = scope.modelProvider;
|
|
477
488
|
const configKey = JSON.stringify(scope.config);
|
|
478
489
|
const savedId = member.threadId;
|
package/core.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {mkdirSync,realpathSync} from 'node:fs';
|
|
2
2
|
import {join} from 'node:path';
|
|
3
3
|
import {randomUUID} from 'node:crypto';
|
|
4
|
-
import {TeamBoard,boardWaitTimeout,configuredEffort,pendingWaitFor,stallIssues,teamPhase,visibleChannels} from './engine.mjs';
|
|
4
|
+
import {TeamBoard,boardWaitTimeout,configuredEffort,pendingWaitFor,readSafeScreenshot,stallIssues,teamPhase,visibleChannels} from './engine.mjs';
|
|
5
5
|
import {openWorktree,removeWorktree,worktreeSource} from './worktrees.mjs';
|
|
6
6
|
|
|
7
7
|
const reads=new Set(['list_teams','board_status','board_history','read_board','list_models','read_journal','open_swarm_panel','wait_for_board']);
|
|
@@ -29,17 +29,33 @@ export function presentTeam(team,{activity={},actor,host=team.host??'codex'}={})
|
|
|
29
29
|
const selected=actor&&team.members.find(member=>member.name===actor);
|
|
30
30
|
const visible=visibleChannels(selected);
|
|
31
31
|
const events=visible?team.events.filter(event=>visible.includes(event.channel??'main')):team.events;
|
|
32
|
+
const phase=teamPhase(team);
|
|
33
|
+
const issues=stallIssues(team);
|
|
34
|
+
const blockers=issues.filter(issue=>['quota','failed','cycle'].includes(issue.kind)||
|
|
35
|
+
(issue.kind==='dependency'&&!team.members.some(member=>member.name===issue.member&&['working','queued'].includes(member.status))));
|
|
32
36
|
const recovery=team.members.filter(m=>m.recoveryRequired).map(m=>({kind:'recovery',member:m.name,text:'@'+m.name+' outcome unconfirmed. Inspect the owned session before continuing.'}));
|
|
33
37
|
const input=team.members.filter(m=>m.inputRequired).map(m=>({kind:'input',member:m.name,text:'@'+m.name+' needs your permission or input in its owned DSH session.'}));
|
|
38
|
+
const attention=[...input,...recovery,...(phase==='stalled'?issues:phase==='budget'
|
|
39
|
+
?[{kind:'budget',text:'Turn limit reached ('+team.turns+'/'+team.turnLimit+'). Add 8 turns to continue.'},...blockers]
|
|
40
|
+
:blockers)];
|
|
41
|
+
const screenshots=team.screenshots?.length?team.screenshots.map(({id,seq,index,author,caption,time})=>({
|
|
42
|
+
id,seq,index,author,caption,time,
|
|
43
|
+
url:host==='codex'
|
|
44
|
+
?'/board/'+team.id+'/screenshot/'+seq+'/'+index
|
|
45
|
+
:'/api/hive-swarm/v1/screenshot?teamId='+encodeURIComponent(team.id)+'&seq='+seq+'&index='+index,
|
|
46
|
+
})):undefined;
|
|
34
47
|
return {id:team.id,host,title:team.title,cwd:team.cwd,task:team.task,model:team.model,effort:team.effort,
|
|
48
|
+
...(team.goalLine?{goalLine:team.goalLine}:{}),
|
|
35
49
|
...(team.parentSessionId?{parentSessionId:team.parentSessionId}:{}),
|
|
36
50
|
...(team.fallbackModel?{fallbackModel:team.fallbackModel,...(team.fallbackEffort!==undefined?{fallbackEffort:team.fallbackEffort}:{})}:{}),
|
|
37
51
|
...(team.threads?.length?{threads:team.threads}:{}),
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
...(screenshots?{screenshots}:{}),
|
|
53
|
+
paused:team.paused,turns:team.turns,turnLimit:team.turnLimit,phase,channels:team.channels,activity,
|
|
54
|
+
attention,events:events.slice(-60),
|
|
40
55
|
members:team.members.map(member=>{
|
|
41
56
|
const executionMode=member.executionMode??(member.threadId?'session':undefined);
|
|
42
57
|
return {name:member.name,role:member.role,group:member.group,brief:member.brief,
|
|
58
|
+
...(member.taskLabel?{taskLabel:member.taskLabel}:{}),
|
|
43
59
|
status:member.status,writable:member.writable,threadId:member.threadId,
|
|
44
60
|
...(executionMode?{executionMode}:{}),
|
|
45
61
|
...(member.subagentName?{subagentName:member.subagentName}:{}),
|
|
@@ -131,7 +147,10 @@ export function createSwarmApplication({dataDirectory,runner,host='codex',worksp
|
|
|
131
147
|
case 'open_swarm_panel':return {teamId:team.id,title:team.title,host,navigation:{kind:'hive-swarm',teamId:team.id}};
|
|
132
148
|
case 'board_history':return board.readHistory(id,{...args,actor:actor?.member});
|
|
133
149
|
case 'read_board':return board.readPosts(id,{...args,actor:actor?.member});
|
|
134
|
-
case 'wait_for_board':
|
|
150
|
+
case 'wait_for_board': {
|
|
151
|
+
const result=await board.waitForBoard(id,args,context.signal);
|
|
152
|
+
return {...result,status:view(result.status,actor?.member)};
|
|
153
|
+
}
|
|
135
154
|
case 'post_message':return view(board.post(id,args.text,args.channel));
|
|
136
155
|
case 'post_to_board':if(!actor)throw Error('An active worker identity is required.');return board.postFrom(id,actor.member,args.text,args.channel);
|
|
137
156
|
case 'set_turn_outcome':
|
|
@@ -142,7 +161,14 @@ export function createSwarmApplication({dataDirectory,runner,host='codex',worksp
|
|
|
142
161
|
case 'resolve_recovery':return view(board.resolveRecovery(id,args.member,{action:args.action}));
|
|
143
162
|
case 'retire_member':return view(board.retireMember(id,args.member,{actor:actor?.member}));
|
|
144
163
|
case 'set_team_title':return view(board.setTeamTitle(id,args.title,actor?.member));
|
|
145
|
-
case 'set_team_plan':
|
|
164
|
+
case 'set_team_plan': {
|
|
165
|
+
const plan=Array.isArray(args)?args:{
|
|
166
|
+
...(Object.hasOwn(args,'goalLine')?{goalLine:args.goalLine}:{}),
|
|
167
|
+
...(Object.hasOwn(args,'tasks')?{tasks:args.tasks}:{}),
|
|
168
|
+
...(Object.hasOwn(args,'threads')?{threads:args.threads}:{}),
|
|
169
|
+
};
|
|
170
|
+
return view(board.setTeamPlan(id,plan,actor?.member));
|
|
171
|
+
}
|
|
146
172
|
case 'manage_channel':return board.manageChannel(id,args,actor?.member);
|
|
147
173
|
case 'add_member': {
|
|
148
174
|
const m=args.member;
|
|
@@ -220,6 +246,14 @@ export function createSwarmApplication({dataDirectory,runner,host='codex',worksp
|
|
|
220
246
|
timer=setTimeout(()=>finish(current('timeout')),duration);
|
|
221
247
|
});
|
|
222
248
|
}
|
|
249
|
+
async function screenshot({teamId,seq,index}={},context={}) {
|
|
250
|
+
ensureOpen();
|
|
251
|
+
const actor=actorOf(context.actor,{teamId});
|
|
252
|
+
const id=teamId??actor?.teamId;
|
|
253
|
+
if(!id)return null;
|
|
254
|
+
await ownTeam(id,context);
|
|
255
|
+
return readSafeScreenshot(board,dataDirectory,id,seq,index);
|
|
256
|
+
}
|
|
223
257
|
function close() {
|
|
224
258
|
if(closing)return closing;if(closed)return Promise.resolve({quiescent:true});
|
|
225
259
|
closing=(async()=>{
|
|
@@ -231,5 +265,5 @@ export function createSwarmApplication({dataDirectory,runner,host='codex',worksp
|
|
|
231
265
|
return {quiescent};
|
|
232
266
|
})();return closing;
|
|
233
267
|
}
|
|
234
|
-
return {board,host,snapshot,command,subscribe,waitForUpdate,close};
|
|
268
|
+
return {board,host,snapshot,command,subscribe,waitForUpdate,screenshot,close};
|
|
235
269
|
}
|
package/engine.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { closeSync, fstatSync, openSync, readSync, realpathSync, statSync } from 'node:fs';
|
|
4
|
+
import { extname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
4
5
|
import { DatabaseSync } from 'node:sqlite';
|
|
5
6
|
|
|
6
7
|
function text(value, label, max) {
|
|
@@ -10,6 +11,11 @@ function text(value, label, max) {
|
|
|
10
11
|
return value.trim();
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
function optionalText(value, label, max) {
|
|
15
|
+
if (value === undefined || value === null || value === '') return undefined;
|
|
16
|
+
return text(value, label, max);
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
function integer(value, min, max, label) {
|
|
14
20
|
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
15
21
|
throw new Error(label + ' must be between ' + min + ' and ' + max + '.');
|
|
@@ -175,10 +181,12 @@ function newMember(spec) {
|
|
|
175
181
|
if (!spec || typeof spec !== 'object') throw Error('Member details are required.');
|
|
176
182
|
const waitFor = spec.waitFor ?? [];
|
|
177
183
|
if (!Array.isArray(waitFor)) throw Error('waitFor must be a list of member names.');
|
|
184
|
+
const taskLabel = optionalText(spec.taskLabel, 'Task label', 96);
|
|
178
185
|
return {
|
|
179
186
|
name: memberLabel(spec.name, 'Member name'),
|
|
180
187
|
group: spec.group == null ? undefined : memberLabel(spec.group, 'Group name'),
|
|
181
188
|
brief: text(spec.brief, 'Member brief', 4000),
|
|
189
|
+
...(taskLabel ? {taskLabel} : {}),
|
|
182
190
|
model: spec.model == null ? undefined : text(spec.model, 'Model', 100),
|
|
183
191
|
effort: reasoningEffort(spec.effort),
|
|
184
192
|
...(spec.fallbackModel ? {fallbackModel: text(spec.fallbackModel, 'Fallback model', 100)} : {}),
|
|
@@ -268,6 +276,105 @@ function numberPosts(team) {
|
|
|
268
276
|
return team;
|
|
269
277
|
}
|
|
270
278
|
|
|
279
|
+
const screenshotLine = /^Screenshot:\s*(.+?)\s*\|\s*(.{1,140})$/gm;
|
|
280
|
+
const screenshotMimeTypes = new Map([
|
|
281
|
+
['.png', 'image/png'],
|
|
282
|
+
['.jpg', 'image/jpeg'],
|
|
283
|
+
['.jpeg', 'image/jpeg'],
|
|
284
|
+
['.webp', 'image/webp'],
|
|
285
|
+
]);
|
|
286
|
+
const maxScreenshotBytes = 10 * 1024 * 1024;
|
|
287
|
+
|
|
288
|
+
export function extractScreenshots(event) {
|
|
289
|
+
if (!event || event.author === 'system' || ['brief', 'monitor', 'checkpoint'].includes(event.kind)) {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
if (typeof event.text !== 'string' || !event.text.includes('Screenshot:')) return [];
|
|
293
|
+
const normalized = event.text.replace(/\r\n?/g, '\n');
|
|
294
|
+
const items = [];
|
|
295
|
+
screenshotLine.lastIndex = 0;
|
|
296
|
+
let match;
|
|
297
|
+
while ((match = screenshotLine.exec(normalized)) !== null) {
|
|
298
|
+
const path = match[1].trim();
|
|
299
|
+
const caption = match[2].trim();
|
|
300
|
+
if (!path || !caption || caption.length > 140) continue;
|
|
301
|
+
const index = items.length;
|
|
302
|
+
items.push({
|
|
303
|
+
id: event.seq + ':' + index,
|
|
304
|
+
seq: event.seq,
|
|
305
|
+
index,
|
|
306
|
+
author: event.author,
|
|
307
|
+
caption,
|
|
308
|
+
time: event.time,
|
|
309
|
+
path,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return items;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function publicScreenshot({id, seq, index, author, caption, time}) {
|
|
316
|
+
return {id, seq, index, author, caption, time};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function realPathSync(target) {
|
|
320
|
+
return (realpathSync.native ?? realpathSync)(target);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function withinScreenshotRoot(root, target) {
|
|
324
|
+
const a = process.platform === 'win32' ? root.toLowerCase() : root;
|
|
325
|
+
const b = process.platform === 'win32' ? target.toLowerCase() : target;
|
|
326
|
+
const offset = relative(a, b);
|
|
327
|
+
return Boolean(offset) && !isAbsolute(offset) && offset !== '..' && !offset.startsWith('..' + sep);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function readSafeScreenshot(board, dataDirectory, teamId, seq, index) {
|
|
331
|
+
if (typeof teamId !== 'string' || !teamId || !Number.isSafeInteger(seq) || seq < 1 ||
|
|
332
|
+
!Number.isSafeInteger(index) || index < 0) return null;
|
|
333
|
+
let team;
|
|
334
|
+
try { team = board.get(teamId); } catch { return null; }
|
|
335
|
+
const row = board.readPost?.get(teamId, seq);
|
|
336
|
+
const post = row ? JSON.parse(row.value) : team.events?.find(event => event.seq === seq);
|
|
337
|
+
if (!post) return null;
|
|
338
|
+
const shot = extractScreenshots(post)[index];
|
|
339
|
+
if (!shot?.path || shot.path.includes('\0')) return null;
|
|
340
|
+
if (!screenshotMimeTypes.has(extname(shot.path).toLowerCase())) return null;
|
|
341
|
+
let realCwd;
|
|
342
|
+
try { realCwd = realPathSync(team.cwd); } catch { return null; }
|
|
343
|
+
let realData = null;
|
|
344
|
+
if (dataDirectory) {
|
|
345
|
+
try { realData = realPathSync(dataDirectory); } catch {}
|
|
346
|
+
}
|
|
347
|
+
const relativeTarget = !isAbsolute(shot.path);
|
|
348
|
+
const candidate = relativeTarget ? resolve(realCwd, shot.path) : resolve(shot.path);
|
|
349
|
+
let realTarget;
|
|
350
|
+
try { realTarget = realPathSync(candidate); } catch { return null; }
|
|
351
|
+
const contentType = screenshotMimeTypes.get(extname(realTarget).toLowerCase());
|
|
352
|
+
if (!contentType) return null;
|
|
353
|
+
const allowed = relativeTarget
|
|
354
|
+
? withinScreenshotRoot(realCwd, realTarget)
|
|
355
|
+
: (withinScreenshotRoot(realCwd, realTarget) || (realData !== null && withinScreenshotRoot(realData, realTarget)));
|
|
356
|
+
if (!allowed) return null;
|
|
357
|
+
let fd;
|
|
358
|
+
try {
|
|
359
|
+
fd = openSync(realTarget, 'r');
|
|
360
|
+
const info = fstatSync(fd);
|
|
361
|
+
if (!info.isFile() || info.size < 0 || info.size > maxScreenshotBytes) return null;
|
|
362
|
+
const body = Buffer.allocUnsafe(info.size);
|
|
363
|
+
let offset = 0;
|
|
364
|
+
while (offset < info.size) {
|
|
365
|
+
const bytesRead = readSync(fd, body, offset, info.size - offset, offset);
|
|
366
|
+
if (!bytesRead) break;
|
|
367
|
+
offset += bytesRead;
|
|
368
|
+
}
|
|
369
|
+
if (offset !== info.size || offset > maxScreenshotBytes) return null;
|
|
370
|
+
return {body, contentType};
|
|
371
|
+
} catch {
|
|
372
|
+
return null;
|
|
373
|
+
} finally {
|
|
374
|
+
if (fd !== undefined) try { closeSync(fd); } catch {}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
271
378
|
function restore(team) {
|
|
272
379
|
numberPosts(team);
|
|
273
380
|
team.host ??= 'codex';
|
|
@@ -276,6 +383,12 @@ function restore(team) {
|
|
|
276
383
|
member.channels ??= [];
|
|
277
384
|
if (member.threadId && !executionModes.has(member.executionMode)) member.executionMode = 'session';
|
|
278
385
|
}
|
|
386
|
+
if (!Array.isArray(team.screenshots)) {
|
|
387
|
+
const recovered = team.events.flatMap(event => extractScreenshots(event).map(publicScreenshot));
|
|
388
|
+
if (recovered.length) team.screenshots = recovered.slice(-200);
|
|
389
|
+
} else {
|
|
390
|
+
team.screenshots = team.screenshots.map(publicScreenshot);
|
|
391
|
+
}
|
|
279
392
|
delete team.overview;
|
|
280
393
|
const removed = new Set(team.members.filter(member=>member.role==='narrator').map(member=>member.name));
|
|
281
394
|
if (removed.size) {
|
|
@@ -309,18 +422,38 @@ function completedWorkerRound(workers) {
|
|
|
309
422
|
return workers.map(worker => worker.name + ':' + worker.completed).join(',');
|
|
310
423
|
}
|
|
311
424
|
|
|
425
|
+
function hasCoordinatorSummary(team, coordinator, workers) {
|
|
426
|
+
const events = team.events ?? [];
|
|
427
|
+
const workerNames = new Set(workers.map(worker => worker.name));
|
|
428
|
+
const lastSummarySeq = Math.max(
|
|
429
|
+
coordinator.lastReport?.seq ?? 0,
|
|
430
|
+
events.findLast(event => event.author === coordinator.name && event.kind !== 'brief')?.seq ?? 0,
|
|
431
|
+
);
|
|
432
|
+
if (!lastSummarySeq) return false;
|
|
433
|
+
const lastWorkerSeq = Math.max(
|
|
434
|
+
0,
|
|
435
|
+
...workers.map(worker => worker.lastReport?.seq ?? 0),
|
|
436
|
+
events.findLast(event => workerNames.has(event.author) && event.kind !== 'brief')?.seq ?? 0,
|
|
437
|
+
);
|
|
438
|
+
return lastSummarySeq >= lastWorkerSeq;
|
|
439
|
+
}
|
|
440
|
+
|
|
312
441
|
export function teamPhase(team) {
|
|
313
442
|
if (team.paused) return 'paused';
|
|
314
443
|
const members = team.members.filter(member => member.status !== 'retired');
|
|
315
444
|
if (!members.length && team.members.length) return 'retired';
|
|
316
445
|
const coordinator = members.find(member => member.role === 'coordinator');
|
|
317
|
-
const
|
|
318
|
-
const
|
|
446
|
+
const workers = members.filter(isWorker);
|
|
447
|
+
const round = coordinator && completedWorkerRound(workers);
|
|
448
|
+
const summaryPosted = coordinator && (!workers.length || hasCoordinatorSummary(team, coordinator, workers));
|
|
449
|
+
const summaryPending = Boolean(round && coordinator.lastRound !== round && !summaryPosted);
|
|
450
|
+
const coordinatorCanSummarize = coordinator && !['failed', 'quota'].includes(coordinator.status);
|
|
319
451
|
if (!summaryPending && members.every(member => member.status === 'done' ||
|
|
320
|
-
(member === coordinator && member.status === 'waiting' &&
|
|
452
|
+
(member === coordinator && member.status === 'waiting' &&
|
|
453
|
+
!pendingWaitFor(team, member).length && !(member.inbox?.some(post => post.addressed))))) return 'done';
|
|
321
454
|
if (members.some(member => member.status === 'working')) return 'working';
|
|
322
455
|
if (team.turns >= team.turnLimit) return 'budget';
|
|
323
|
-
if (members.some(member => member.status === 'queued')) return 'queued';
|
|
456
|
+
if (members.some(member => member.status === 'queued') || (summaryPending && coordinatorCanSummarize)) return 'queued';
|
|
324
457
|
return 'stalled';
|
|
325
458
|
}
|
|
326
459
|
|
|
@@ -445,6 +578,7 @@ export class TeamBoard {
|
|
|
445
578
|
`);
|
|
446
579
|
this.read = this.db.prepare('SELECT value FROM teams WHERE id = ?');
|
|
447
580
|
this.write = this.db.prepare('INSERT INTO teams VALUES (?, ?) ON CONFLICT(id) DO UPDATE SET value = excluded.value');
|
|
581
|
+
this.readPost = this.db.prepare('SELECT value FROM posts WHERE team_id = ? AND seq = ?');
|
|
448
582
|
this.writePost = this.db.prepare('INSERT INTO posts VALUES (?, ?, ?) ON CONFLICT(team_id,seq) DO NOTHING');
|
|
449
583
|
this.bounds = this.db.prepare('SELECT coalesce(min(seq),0) AS earliest, coalesce(max(seq),0) AS head FROM posts WHERE team_id = ?');
|
|
450
584
|
const filter = " AND (? IS NULL OR COALESCE(json_extract(posts.value,'$.channel'),'main') IN (SELECT value FROM json_each(?)))" +
|
|
@@ -527,9 +661,11 @@ export class TeamBoard {
|
|
|
527
661
|
if (members.some(member => member.worktree) && !worktreeSource) throw Error('A Git workspace is required for worktrees.');
|
|
528
662
|
|
|
529
663
|
const task = text(input.task, 'Task', 8000);
|
|
664
|
+
const goalLine = optionalText(input.goalLine, 'Goal line', 140);
|
|
530
665
|
const threads = normalizeThreads(input.threads, members);
|
|
531
666
|
const team = {
|
|
532
667
|
id: randomUUID(), host: this.host, cwd, task, title: text(input.title ?? task.slice(0, 95), 'Title', 95),
|
|
668
|
+
...(goalLine ? {goalLine} : {}),
|
|
533
669
|
...(parent ? {parentSessionId: parent} : {}),
|
|
534
670
|
...(input.model ? {model: text(input.model, 'Model', 100)} : {}),
|
|
535
671
|
effort: reasoningEffort(input.effort),
|
|
@@ -700,14 +836,51 @@ export class TeamBoard {
|
|
|
700
836
|
return team;
|
|
701
837
|
}
|
|
702
838
|
|
|
703
|
-
setTeamPlan(id,
|
|
839
|
+
setTeamPlan(id, plan, actor) {
|
|
704
840
|
const team = this.get(id);
|
|
705
841
|
if (actor && this.peerMember(team, actor).role !== 'coordinator') {
|
|
706
842
|
throw Error('Only the user or coordinator can update outcome threads.');
|
|
707
843
|
}
|
|
708
|
-
const
|
|
709
|
-
if (
|
|
710
|
-
|
|
844
|
+
const spec = plan === undefined ? {threads: []} : Array.isArray(plan) ? {threads: plan} : plan;
|
|
845
|
+
if (!spec || typeof spec !== 'object' || Array.isArray(spec)) {
|
|
846
|
+
throw Error('Team plan must be an object or a list of outcome threads.');
|
|
847
|
+
}
|
|
848
|
+
const {goalLine, tasks, threads} = spec;
|
|
849
|
+
if (goalLine === undefined && tasks === undefined && threads === undefined) {
|
|
850
|
+
throw Error('Specify goalLine, tasks, or threads to update the team plan.');
|
|
851
|
+
}
|
|
852
|
+
if (goalLine !== undefined) {
|
|
853
|
+
const next = optionalText(goalLine, 'Goal line', 140);
|
|
854
|
+
if (next) team.goalLine = next;
|
|
855
|
+
else delete team.goalLine;
|
|
856
|
+
}
|
|
857
|
+
if (tasks !== undefined && tasks !== null) {
|
|
858
|
+
let entries;
|
|
859
|
+
if (Array.isArray(tasks)) {
|
|
860
|
+
entries = tasks.map(entry => {
|
|
861
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
862
|
+
throw Error('Each task label entry must be a {member, label} object.');
|
|
863
|
+
}
|
|
864
|
+
return [entry.member, entry.label];
|
|
865
|
+
});
|
|
866
|
+
} else if (typeof tasks === 'object') {
|
|
867
|
+
entries = Object.entries(tasks);
|
|
868
|
+
} else {
|
|
869
|
+
throw Error('Task labels must be a member map or a list of {member, label} entries.');
|
|
870
|
+
}
|
|
871
|
+
for (const [rawName, rawLabel] of entries) {
|
|
872
|
+
const name = normalizeTarget(text(rawName, 'Member name', 30));
|
|
873
|
+
const target = this.liveMember(team, name);
|
|
874
|
+
const label = optionalText(rawLabel, 'Task label', 96);
|
|
875
|
+
if (label) target.taskLabel = label;
|
|
876
|
+
else delete target.taskLabel;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
if (threads !== undefined) {
|
|
880
|
+
const normalized = normalizeThreads(threads, team.members);
|
|
881
|
+
if (normalized?.length) team.threads = normalized;
|
|
882
|
+
else delete team.threads;
|
|
883
|
+
}
|
|
711
884
|
this.save(team);
|
|
712
885
|
return team;
|
|
713
886
|
}
|
|
@@ -919,6 +1092,12 @@ export class TeamBoard {
|
|
|
919
1092
|
const event = {seq: (team.events.at(-1)?.seq ?? 0) + 1, time: new Date().toISOString(), kind, author, text: body, targets,channel};
|
|
920
1093
|
team.events.push(event);
|
|
921
1094
|
if (team.events.length > 300) team.events.shift();
|
|
1095
|
+
const shots = extractScreenshots(event);
|
|
1096
|
+
if (shots.length) {
|
|
1097
|
+
team.screenshots ??= [];
|
|
1098
|
+
team.screenshots.push(...shots.map(publicScreenshot));
|
|
1099
|
+
if (team.screenshots.length > 200) team.screenshots.splice(0, team.screenshots.length - 200);
|
|
1100
|
+
}
|
|
922
1101
|
return event;
|
|
923
1102
|
}
|
|
924
1103
|
|
package/hive-bees.js
CHANGED
|
@@ -1,64 +1,110 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
'use strict';
|
|
3
|
-
const palette=[
|
|
4
|
-
['#efac37','#ffe18d','#bb641d'],
|
|
5
|
-
['#75baef','#cdefff','#3974bb'],
|
|
6
|
-
['#55cbb2','#b8f8df','#268c7d'],
|
|
7
|
-
['#e68db3','#ffcee2','#a24275'],
|
|
8
|
-
['#b3ce64','#e9f6a1','#6c9137'],
|
|
9
|
-
['#ad9ce8','#e3d4ff','#6d58af'],
|
|
10
|
-
['#f09a71','#ffd3b7','#af5833'],
|
|
11
|
-
['#95cbd1','#defbfa','#4a8d9d'],
|
|
12
|
-
['#d1a76a','#ffe2a9','#987044'],
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return palette[
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
(() => {
|
|
2
|
+
'use strict';
|
|
3
|
+
const palette = [
|
|
4
|
+
['#efac37', '#ffe18d', '#bb641d'],
|
|
5
|
+
['#75baef', '#cdefff', '#3974bb'],
|
|
6
|
+
['#55cbb2', '#b8f8df', '#268c7d'],
|
|
7
|
+
['#e68db3', '#ffcee2', '#a24275'],
|
|
8
|
+
['#b3ce64', '#e9f6a1', '#6c9137'],
|
|
9
|
+
['#ad9ce8', '#e3d4ff', '#6d58af'],
|
|
10
|
+
['#f09a71', '#ffd3b7', '#af5833'],
|
|
11
|
+
['#95cbd1', '#defbfa', '#4a8d9d'],
|
|
12
|
+
['#d1a76a', '#ffe2a9', '#987044'],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const mutedPalette = ['#aaafb6', '#d6dae0', '#848991'];
|
|
16
|
+
|
|
17
|
+
function colors(name, coordinator, tint) {
|
|
18
|
+
if (coordinator) return palette[0];
|
|
19
|
+
if (Number.isInteger(tint)) return palette[1 + (Math.abs(tint) % (palette.length - 1))];
|
|
20
|
+
const hash = [...String(name ?? '')].reduce((sum, letter) => sum * 31 + letter.charCodeAt(0), 0) >>> 0;
|
|
21
|
+
return palette[hash % palette.length];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function hexRgb(hex) {
|
|
25
|
+
const clean = String(hex).replace('#', '');
|
|
26
|
+
const value = Number.parseInt(clean, 16);
|
|
27
|
+
return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function tintStyle(name, coordinator, tint) {
|
|
31
|
+
const [base, highlight, shade] = colors(name, coordinator, tint);
|
|
32
|
+
const [r, g, b] = hexRgb(base);
|
|
33
|
+
const [sr, sg, sb] = hexRgb(shade);
|
|
34
|
+
const tr = Math.round(sr * 0.78);
|
|
35
|
+
const tg = Math.round(sg * 0.78);
|
|
36
|
+
const tb = Math.round(sb * 0.78);
|
|
37
|
+
const text = '#' + [tr, tg, tb].map(c => c.toString(16).padStart(2, '0')).join('');
|
|
38
|
+
return {
|
|
39
|
+
base,
|
|
40
|
+
highlight,
|
|
41
|
+
shade,
|
|
42
|
+
bg: `rgba(${r}, ${g}, ${b}, 0.14)`,
|
|
43
|
+
border: `rgba(${r}, ${g}, ${b}, 0.42)`,
|
|
44
|
+
text,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function paintRects(ctx, color, rects, ox = 0, oy = 0, scale = 1) {
|
|
49
|
+
ctx.fillStyle = color;
|
|
50
|
+
for (const [rx, ry, rw, rh] of rects) {
|
|
51
|
+
if (ox === 0 && oy === 0 && scale === 1) ctx.fillRect(rx, ry, rw, rh);
|
|
52
|
+
else ctx.fillRect(ox + rx * scale, oy + ry * scale, rw * scale, rh * scale);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function drawSprite(ctx, x, y, name, { status = 'working', coordinator = false, tint, muted = false, scale = 1 } = {}) {
|
|
57
|
+
if (!ctx) return;
|
|
58
|
+
const [base, highlight, shade] = muted ? mutedPalette : colors(name, coordinator, tint);
|
|
59
|
+
const asleep = !muted && ['waiting', 'quota', 'retired', 'done'].includes(status);
|
|
60
|
+
|
|
61
|
+
const outline = muted ? '#727880' : '#201915';
|
|
62
|
+
const wingRim = muted ? '#828a94' : '#24313d';
|
|
63
|
+
const wingFill = muted ? '#ced3d9' : '#a9c6db';
|
|
64
|
+
const wingLight = muted ? '#eef1f4' : '#e7f2fa';
|
|
65
|
+
const stripe = muted ? '#767c84' : '#2c221c';
|
|
66
|
+
|
|
67
|
+
paintRects(ctx, outline, [[3, 2, 1, 3], [6, 3, 1, 2], [5, 1, 2, 1], [2, 3, 1, 1], [5, 5, 10, 8], [3, 7, 13, 5],
|
|
68
|
+
[4, 12, 11, 2], [6, 14, 7, 1], [16, 9, 2, 2], [7, 14, 1, 2], [12, 14, 1, 2]], x, y, scale);
|
|
69
|
+
paintRects(ctx, wingRim, [[7, 3, 6, 4], [8, 2, 4, 6], [12, 3, 4, 4], [13, 2, 2, 1]], x, y, scale);
|
|
70
|
+
paintRects(ctx, wingFill, [[8, 3, 3, 4], [12, 4, 3, 2], [9, 7, 2, 1]], x, y, scale);
|
|
71
|
+
paintRects(ctx, wingLight, [[9, 3, 2, 2], [12, 4, 2, 1], [8, 4, 1, 2]], x, y, scale);
|
|
72
|
+
paintRects(ctx, base, [[4, 7, 8, 5], [5, 6, 6, 7], [12, 7, 3, 5], [13, 12, 1, 1], [6, 13, 1, 1]], x, y, scale);
|
|
73
|
+
paintRects(ctx, highlight, [[5, 7, 3, 1], [4, 9, 2, 2], [10, 7, 2, 1], [13, 8, 1, 2], [5, 12, 2, 1]], x, y, scale);
|
|
74
|
+
paintRects(ctx, shade, [[6, 12, 7, 1], [12, 11, 3, 1], [13, 12, 1, 1]], x, y, scale);
|
|
75
|
+
paintRects(ctx, stripe, [[8, 6, 2, 7], [12, 7, 1, 6], [15, 9, 2, 1]], x, y, scale);
|
|
76
|
+
|
|
77
|
+
if (asleep) {
|
|
78
|
+
paintRects(ctx, outline, [[4, 10, 2, 1]], x, y, scale);
|
|
79
|
+
paintRects(ctx, '#d7dcff', coordinator
|
|
80
|
+
? [[0, 0, 2, 1], [1, 1, 1, 1], [0, 2, 2, 1], [15, 0, 4, 1], [17, 1, 1, 2], [15, 3, 4, 1]]
|
|
81
|
+
: [[1, 1, 3, 1], [2, 2, 1, 1], [1, 3, 3, 1], [15, 0, 4, 1], [17, 1, 1, 2], [15, 3, 4, 1]], x, y, scale);
|
|
82
|
+
} else {
|
|
83
|
+
paintRects(ctx, muted ? '#555b63' : '#201915', [[5, 8, 1, 2]], x, y, scale);
|
|
84
|
+
paintRects(ctx, muted ? '#e5e8ec' : '#fff6d7', [[5, 8, 1, 1]], x, y, scale);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (coordinator) {
|
|
88
|
+
paintRects(ctx, muted ? '#727880' : '#6d4219', [[2, 1, 1, 4], [8, 1, 1, 4], [2, 4, 7, 1]], x, y, scale);
|
|
89
|
+
paintRects(ctx, muted ? '#c7cbd1' : '#ffd86b', [[2, 0, 1, 2], [5, 0, 1, 3], [8, 0, 1, 2], [3, 2, 5, 2], [4, 1, 3, 1]], x, y, scale);
|
|
90
|
+
paintRects(ctx, muted ? '#9da3ab' : '#e7a52f', [[3, 4, 5, 1], [3, 3, 5, 1]], x, y, scale);
|
|
91
|
+
paintRects(ctx, muted ? '#eceef1' : '#fff3bf', [[3, 2, 1, 1], [7, 2, 1, 1], [5, 3, 1, 1]], x, y, scale);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function sprite(name, { status = 'working', coordinator = false, tint, muted = false } = {}) {
|
|
96
|
+
const canvas = document.createElement('canvas');
|
|
97
|
+
canvas.className = 'bee-pixel';
|
|
98
|
+
canvas.width = 20;
|
|
99
|
+
canvas.height = 18;
|
|
100
|
+
canvas.setAttribute('aria-hidden', 'true');
|
|
101
|
+
const asleep = !muted && ['waiting', 'quota', 'retired', 'done'].includes(status);
|
|
102
|
+
canvas.dataset.pose = muted ? 'muted' : (asleep ? 'sleeping' : 'awake');
|
|
103
|
+
if (muted) canvas.dataset.muted = 'true';
|
|
104
|
+
const ctx = canvas.getContext('2d');
|
|
105
|
+
drawSprite(ctx, 0, 0, name, { status, coordinator, tint, muted, scale: 1 });
|
|
106
|
+
return canvas;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
globalThis.HiveBee = Object.freeze({ sprite, colors, tintStyle, drawSprite });
|
|
110
|
+
})();
|