dsh-hive-panel 0.1.0 → 0.1.2

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/lib/client.js CHANGED
@@ -730,6 +730,61 @@ const PANEL_STYLES = `.hive { position: relative; }
730
730
  }
731
731
 
732
732
  .hive-queen-hint.is-visible { display: flex; }
733
+ .hive-queen-badge {
734
+ padding: 2px 8px;
735
+ border: 1px solid var(--hive-line, #232b38);
736
+ border-radius: 999px;
737
+ font-size: 10px;
738
+ font-weight: 650;
739
+ letter-spacing: 0.09em;
740
+ line-height: 1.5;
741
+ text-transform: uppercase;
742
+ white-space: nowrap;
743
+ }
744
+
745
+ .hive-queen-badge.is-hidden { display: none; }
746
+
747
+ .hive-queen-badge.is-active {
748
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 45%, transparent);
749
+ background: var(--hive-accent-soft);
750
+ color: var(--hive-accent, #58c4dc);
751
+ }
752
+
753
+ .hive-queen-badge.is-inactive {
754
+ border-color: var(--hive-line, #232b38);
755
+ background: var(--hive-surface);
756
+ color: var(--hive-fg-soft);
757
+ }
758
+
759
+ .hive-queen-hint.is-offer {
760
+ border-bottom-color: var(--hive-line, #232b38);
761
+ background: var(--hive-surface);
762
+ color: var(--hive-fg-soft);
763
+ }
764
+
765
+ .hive-queen-offer {
766
+ display: flex;
767
+ flex-wrap: wrap;
768
+ align-items: center;
769
+ gap: 8px;
770
+ max-width: 76ch;
771
+ }
772
+
773
+ .hive-queen-offer.is-hidden,
774
+ .hive-queen-exit.is-hidden { display: none; }
775
+
776
+ .hive-queen-takeover {
777
+ border-color: color-mix(in srgb, var(--hive-accent, #58c4dc) 45%, var(--hive-line, #232b38));
778
+ background: var(--hive-accent-soft);
779
+ color: var(--hive-accent, #58c4dc);
780
+ }
781
+
782
+ .hive-queen-takeover:disabled {
783
+ opacity: 0.6;
784
+ cursor: wait;
785
+ }
786
+
787
+
733
788
 
734
789
  .hive-queen-text {
735
790
  max-width: 76ch;
@@ -964,6 +1019,23 @@ const PANEL_STYLES = `.hive { position: relative; }
964
1019
  line-height: 1.5;
965
1020
  }
966
1021
 
1022
+ .hive-oldest {
1023
+ max-width: 100%;
1024
+ overflow-wrap: anywhere;
1025
+ white-space: normal;
1026
+ }
1027
+
1028
+ .hive-oldest-label { min-width: 0; }
1029
+
1030
+ .hive-oldest-sep { opacity: 0.65; }
1031
+
1032
+ .hive-oldest-id {
1033
+ font-family: var(--hive-mono);
1034
+ font-size: 9.5px;
1035
+ font-weight: 400;
1036
+ overflow-wrap: anywhere;
1037
+ }
1038
+
967
1039
  /* -------------------------------------------------------------------- spacing */
968
1040
  .hive {
969
1041
  gap: 8px;
@@ -1090,7 +1162,7 @@ const messages = Object.freeze({
1090
1162
  "action.modeTitle": "Toggle board mode",
1091
1163
  "action.retry": "retry",
1092
1164
  "action.unfreeze": "unfreeze",
1093
- "pane.agents": "agents",
1165
+ "pane.agents": "workers",
1094
1166
  "pane.board": "board",
1095
1167
  "pane.events": "events",
1096
1168
  "board.hint": "5 lanes",
@@ -1112,11 +1184,18 @@ const messages = Object.freeze({
1112
1184
  "mode.title": "mode:",
1113
1185
  "stats.cards": "tasks",
1114
1186
  "stats.oldest": "oldest",
1187
+ "stats.duration.justNow": "just now",
1188
+ "stats.duration.minute": "{count} min",
1189
+ "stats.duration.minutes": "{count} min",
1190
+ "stats.duration.hour": "{count} hr",
1191
+ "stats.duration.hours": "{count} hr",
1192
+ "stats.duration.day": "{count} day",
1193
+ "stats.duration.days": "{count} days",
1115
1194
  "stats.byRoleTitle": "by role: ",
1116
1195
  "status.actionFailed": "action failed",
1117
1196
  "status.disconnected": "disconnected",
1118
- "agents.empty": "No agents on the board.",
1119
- "agents.openAria": "Open agent",
1197
+ "agents.empty": "No workers in the background.",
1198
+ "agents.openAria": "Open worker",
1120
1199
  "agent.idle": "idle",
1121
1200
  "agent.task": "task",
1122
1201
  "agent.unknown": "unknown",
@@ -1173,7 +1252,7 @@ const messages = Object.freeze({
1173
1252
  "prompt.after": "After task ids (comma separated, optional)",
1174
1253
  "prompt.commitMessage": "Commit message",
1175
1254
  "prompt.paths": "Paths (comma separated, optional)",
1176
- "prompt.claimAgent": "Claim as agent",
1255
+ "prompt.claimAgent": "Claim as worker",
1177
1256
  "prompt.commitSha": "Commit sha (optional)",
1178
1257
  "prompt.failReason": "Failure reason",
1179
1258
  "action.plan": "Give the Queen a goal",
@@ -1190,7 +1269,7 @@ const messages = Object.freeze({
1190
1269
  "help.uninitialised": "Initialise Hive with the button in the main area before using board actions.",
1191
1270
  "init.repo": "repository",
1192
1271
  "init.title": "This repo hasn't been initialised for Hive.",
1193
- "init.description": "Initialising writes the role files, hooks and task refs this board reads, and turns this session into the swarm: the queen splits the goal, and the swarm keeps taking tasks until they are done — as long as the DSH process stays up.",
1272
+ "init.description": "Initialising writes the role files, hooks and task refs this board reads, and turns this session into the swarm: the Queen splits the goal, and the swarm keeps taking tasks until they are done — as long as the DSH process stays up.",
1194
1273
  "init.button": "Initialise Hive",
1195
1274
  "init.buttonAria": "Initialise Hive in this repository",
1196
1275
  "init.busy": "Initialising Hive…",
@@ -1203,13 +1282,23 @@ const messages = Object.freeze({
1203
1282
  "init.queenExit": "Exit from the chat window:",
1204
1283
  "init.queenCommand": "/queen off",
1205
1284
  "init.queenOutput": "Initialisation output",
1285
+ "queen.status.active": "Queen active",
1286
+ "queen.status.inactive": "Queen not active",
1287
+ "queen.source.auto": "auto",
1288
+ "queen.source.manual": "manual",
1289
+ "queen.activeTitle": "Queen mode is active ({source})",
1290
+ "queen.inactiveTitle": "The Queen has not taken over this session",
1291
+ "queen.offer": "The Queen has not taken over this session.",
1292
+ "queen.takeover": "Let the Queen take over",
1293
+ "queen.takeoverAria": "Let the Queen take over this session",
1294
+ "queen.takeoverBusy": "Taking over...",
1206
1295
  "help.hint": "Open a task to see the actions for that task.",
1207
1296
  "help.action.freeze": "Freeze: nobody can claim new tasks except tasks tagged fix.",
1208
- "help.action.unfreeze": "Unfreeze: agents can claim pending tasks again.",
1297
+ "help.action.unfreeze": "Unfreeze: workers can claim pending tasks again.",
1209
1298
  "help.action.add": "New task: create a pending task with a role and file scope.",
1210
1299
  "help.action.plan": "Give the Queen a goal: split a goal into tasks, preview the plan, then write it to the board.",
1211
1300
  "help.action.commit": "Commit: commit the selected paths with a message.",
1212
- "help.action.claim": "Claim: lease a pending task for an agent.",
1301
+ "help.action.claim": "Claim: lease a pending task for a worker.",
1213
1302
  "help.action.done": "Done: mark a claimed task complete, optionally with a commit sha.",
1214
1303
  "help.action.fail": "Fail: mark a claimed task failed and record the reason.",
1215
1304
  "help.action.retry": "Retry: put a failed or blocked task back in the queue.",
@@ -1217,7 +1306,7 @@ const messages = Object.freeze({
1217
1306
  "help.params.add": "title, role, scope[], after[]",
1218
1307
  "help.params.plan": "goal, maxCards",
1219
1308
  "help.params.commit": "message, set[]",
1220
- "help.params.claim": "id, agent",
1309
+ "help.params.claim": "id, worker",
1221
1310
  "help.params.done": "id, sha?",
1222
1311
  "help.params.fail": "id, reason",
1223
1312
  "help.params.retry": "id",
@@ -1268,7 +1357,7 @@ const messages = Object.freeze({
1268
1357
  "action.modeTitle": "切换看板模式",
1269
1358
  "action.retry": "重试",
1270
1359
  "action.unfreeze": "解冻",
1271
- "pane.agents": "代理",
1360
+ "pane.agents": "工蜂",
1272
1361
  "pane.board": "任务",
1273
1362
  "pane.events": "事件",
1274
1363
  "board.hint": "5 条泳道",
@@ -1290,11 +1379,18 @@ const messages = Object.freeze({
1290
1379
  "mode.title": "模式:",
1291
1380
  "stats.cards": "个任务",
1292
1381
  "stats.oldest": "最久待办",
1382
+ "stats.duration.justNow": "刚刚",
1383
+ "stats.duration.minute": "{count} 分钟",
1384
+ "stats.duration.minutes": "{count} 分钟",
1385
+ "stats.duration.hour": "{count} 小时",
1386
+ "stats.duration.hours": "{count} 小时",
1387
+ "stats.duration.day": "{count} 天",
1388
+ "stats.duration.days": "{count} 天",
1293
1389
  "stats.byRoleTitle": "按角色:",
1294
1390
  "status.actionFailed": "操作失败",
1295
1391
  "status.disconnected": "连接断开",
1296
- "agents.empty": "看板上暂无代理。",
1297
- "agents.openAria": "打开代理",
1392
+ "agents.empty": "后台暂无工蜂。",
1393
+ "agents.openAria": "打开工蜂",
1298
1394
  "agent.idle": "空闲",
1299
1395
  "agent.task": "任务",
1300
1396
  "agent.unknown": "未知",
@@ -1351,7 +1447,7 @@ const messages = Object.freeze({
1351
1447
  "prompt.after": "排在哪些任务之后(任务 ID,逗号分隔,可选)",
1352
1448
  "prompt.commitMessage": "提交信息",
1353
1449
  "prompt.paths": "路径(逗号分隔,可选)",
1354
- "prompt.claimAgent": "以哪个代理认领",
1450
+ "prompt.claimAgent": "以哪个工蜂认领",
1355
1451
  "prompt.commitSha": "提交 SHA(可选)",
1356
1452
  "prompt.failReason": "失败原因",
1357
1453
  "action.plan": "给女王下目标",
@@ -1368,7 +1464,7 @@ const messages = Object.freeze({
1368
1464
  "help.uninitialised": "请先用主区的按钮初始化 Hive,再使用看板操作。",
1369
1465
  "init.repo": "仓库",
1370
1466
  "init.title": "这个仓库还没初始化 Hive。",
1371
- "init.description": "初始化后,这块看板才能读数据,同时进入蜂群模式:Hive 会写入角色文件、hooks 和任务引用,蜂皇分解任务;只要 DSH 进程不退出,蜂群会一直执行任务直到完成。",
1467
+ "init.description": "初始化后,这块看板才能读数据,同时进入蜂群模式:Hive 会写入角色文件、hooks 和任务引用,女王分解任务;只要 DSH 进程不退出,蜂群会一直执行任务直到完成。",
1372
1468
  "init.button": "初始化 Hive",
1373
1469
  "init.buttonAria": "在这个仓库初始化 Hive",
1374
1470
  "init.busy": "正在初始化 Hive…",
@@ -1381,13 +1477,23 @@ const messages = Object.freeze({
1381
1477
  "init.queenExit": "退出请在聊天窗口输入:",
1382
1478
  "init.queenCommand": "/queen off",
1383
1479
  "init.queenOutput": "初始化输出",
1480
+ "queen.status.active": "女王已接管",
1481
+ "queen.status.inactive": "女王未接管",
1482
+ "queen.source.auto": "自动",
1483
+ "queen.source.manual": "手动",
1484
+ "queen.activeTitle": "女王模式已接管({source})",
1485
+ "queen.inactiveTitle": "女王尚未接管本会话",
1486
+ "queen.offer": "女王尚未接管本会话。",
1487
+ "queen.takeover": "让女王接管",
1488
+ "queen.takeoverAria": "让女王接管本会话",
1489
+ "queen.takeoverBusy": "正在接管…",
1384
1490
  "help.hint": "点开任务可查看该任务自己的操作。",
1385
1491
  "help.action.freeze": "冻结:除带 fix 标签的任务外,任何人都不再能认领新任务。",
1386
- "help.action.unfreeze": "解冻:恢复认领,代理可以继续接取待办任务。",
1492
+ "help.action.unfreeze": "解冻:恢复认领,工蜂可以继续接取待办任务。",
1387
1493
  "help.action.add": "新建任务:添加一条带角色和文件范围的待办任务。",
1388
- "help.action.plan": "给女王下目标:让蜂皇把目标拆成任务计划,预览后再写入看板。",
1494
+ "help.action.plan": "给女王下目标:让女王把目标拆成任务计划,预览后再写入看板。",
1389
1495
  "help.action.commit": "提交:按提交信息提交选中的路径。",
1390
- "help.action.claim": "认领:以某个代理的名义短期租下这条待办任务。",
1496
+ "help.action.claim": "认领:以某个工蜂的名义短期租下这条待办任务。",
1391
1497
  "help.action.done": "完成:把已认领的任务标为完成,可选填写提交 SHA。",
1392
1498
  "help.action.fail": "标记失败:把已认领的任务标为失败,并写明原因。",
1393
1499
  "help.action.retry": "重试:把失败或受阻的任务放回队列。",
@@ -1395,7 +1501,7 @@ const messages = Object.freeze({
1395
1501
  "help.params.add": "title、role、scope[]、after[]",
1396
1502
  "help.params.plan": "goal、maxCards",
1397
1503
  "help.params.commit": "message、set[]",
1398
- "help.params.claim": "id、agent",
1504
+ "help.params.claim": "id、工蜂",
1399
1505
  "help.params.done": "id、sha?",
1400
1506
  "help.params.fail": "id、reason",
1401
1507
  "help.params.retry": "id",
@@ -1531,10 +1637,26 @@ function normalizeStats(stats, tasks) {
1531
1637
  }
1532
1638
  }
1533
1639
 
1534
- const oldestPending =
1535
- source.oldestPending === undefined || source.oldestPending === null
1536
- ? null
1537
- : asString(source.oldestPending);
1640
+ let oldestPending = null;
1641
+ const rawOldest = source.oldestPending;
1642
+ if (isRecord(rawOldest)) {
1643
+ const id =
1644
+ typeof rawOldest.id === "string" || typeof rawOldest.id === "number" ? String(rawOldest.id) : "";
1645
+ const createdValue =
1646
+ rawOldest.createdAt !== undefined && rawOldest.createdAt !== null
1647
+ ? rawOldest.createdAt
1648
+ : rawOldest.created !== undefined && rawOldest.created !== null
1649
+ ? rawOldest.created
1650
+ : rawOldest.at;
1651
+ const createdAt =
1652
+ typeof createdValue === "string" || typeof createdValue === "number" ? String(createdValue) : "";
1653
+ if (id || createdAt) oldestPending = { id, createdAt };
1654
+ } else if (typeof rawOldest === "string" || typeof rawOldest === "number") {
1655
+ const text = String(rawOldest);
1656
+ if (text) {
1657
+ oldestPending = parseDate(text) ? { id: "", createdAt: text } : { id: text, createdAt: "" };
1658
+ }
1659
+ }
1538
1660
 
1539
1661
  return { total, byState, byRole, oldestPending };
1540
1662
  }
@@ -1609,9 +1731,10 @@ function helpGroups(mode) {
1609
1731
  * @param {object} snapshot
1610
1732
  * @returns {{
1611
1733
  * at: string, repo: string, mode: string, initialised: boolean, writable: boolean,
1734
+ * queen: {active:boolean, source:"auto"|"manual"|null, repo:string}|null,
1612
1735
  * lanes: Record<string, Array<{id:string,title:string,role:string,owner:string,scope:string[],reason:string}>>,
1613
1736
  * laneOrder: string[],
1614
- * stats: {total:number, byState:Record<string,number>, byRole:Record<string,number>, oldestPending:string|null},
1737
+ * stats: {total:number, byState:Record<string,number>, byRole:Record<string,number>, oldestPending:{id:string,createdAt:string}|null},
1615
1738
  * agents: Array<{agent:string,state:string,task:string,files:string[],updatedAt:string}>,
1616
1739
  * events: Array<{ts:string,kind:string,task:string,actor:string}>,
1617
1740
  * actions: Array<{name:string,labelKey:string,body?:object}>
@@ -1639,12 +1762,26 @@ function renderModel(snapshot) {
1639
1762
  : "free";
1640
1763
  const writable = source.writable === true;
1641
1764
  const initialised = source.initialised !== false;
1765
+ const rawQueen = isRecord(source.queen) ? source.queen : null;
1766
+ const queenActive = rawQueen !== null && rawQueen.active === true;
1767
+ const queen =
1768
+ rawQueen === null
1769
+ ? null
1770
+ : {
1771
+ active: queenActive,
1772
+ source:
1773
+ queenActive && (rawQueen.source === "auto" || rawQueen.source === "manual")
1774
+ ? rawQueen.source
1775
+ : null,
1776
+ repo: typeof rawQueen.repo === "string" ? rawQueen.repo : "",
1777
+ };
1642
1778
 
1643
1779
  return {
1644
1780
  at: asString(source.at),
1645
1781
  repo: asString(source.repo),
1646
1782
  mode,
1647
1783
  initialised,
1784
+ queen,
1648
1785
  writable,
1649
1786
  lanes,
1650
1787
  laneOrder: [...LANE_ORDER],
@@ -2150,6 +2287,7 @@ function mount(root, options = {}) {
2150
2287
  let initErrorMessage = "";
2151
2288
  let initRequestSeq = 0;
2152
2289
  let queenNotice = false;
2290
+ let queenBusy = false;
2153
2291
  let supervisorData = [];
2154
2292
  let supervisorRequest = null;
2155
2293
  let limitsOverlay = null;
@@ -2175,6 +2313,9 @@ function mount(root, options = {}) {
2175
2313
  const statsNode = element(doc, "div", "hive-stats");
2176
2314
  bar.appendChild(statsNode);
2177
2315
 
2316
+ const queenBadge = element(doc, "span", "hive-queen-badge is-hidden", "");
2317
+ bar.appendChild(queenBadge);
2318
+
2178
2319
  const statusNode = element(doc, "span", "hive-status", "");
2179
2320
  bar.appendChild(statusNode);
2180
2321
 
@@ -2220,12 +2361,22 @@ function mount(root, options = {}) {
2220
2361
  const queenCommand = element(doc, "code", "hive-queen-command", "");
2221
2362
  queenExit.appendChild(queenExitText);
2222
2363
  queenExit.appendChild(queenCommand);
2364
+ const queenOffer = element(doc, "div", "hive-queen-offer is-hidden");
2365
+ const queenTakeoverButton = element(doc, "button", "hive-btn hive-queen-takeover", translate("queen.takeover"));
2366
+ setAttr(queenTakeoverButton, "type", "button");
2367
+ setAttr(queenTakeoverButton, "title", translate("queen.takeoverAria"));
2368
+ setAttr(queenTakeoverButton, "aria-label", translate("queen.takeoverAria"));
2369
+ queenTakeoverButton.addEventListener("click", () => {
2370
+ void runQueenOn(queenTakeoverButton);
2371
+ });
2372
+ queenOffer.appendChild(queenTakeoverButton);
2223
2373
  const queenOutputDetails = element(doc, "details", "hive-init-output hive-queen-output is-hidden");
2224
2374
  const queenOutputSummary = element(doc, "summary", "hive-output-summary", "");
2225
2375
  const queenOutputPre = element(doc, "pre", "hive-output-pre", "");
2226
2376
  queenOutputDetails.appendChild(queenOutputSummary);
2227
2377
  queenOutputDetails.appendChild(queenOutputPre);
2228
2378
  queenHint.appendChild(queenHintText);
2379
+ queenHint.appendChild(queenOffer);
2229
2380
  queenHint.appendChild(queenExit);
2230
2381
  queenHint.appendChild(queenOutputDetails);
2231
2382
 
@@ -3362,6 +3513,21 @@ function mount(root, options = {}) {
3362
3513
  return result.payload;
3363
3514
  }
3364
3515
 
3516
+ async function runQueenOn(button) {
3517
+ if (destroyed || queenBusy) return;
3518
+ const model = lastModel;
3519
+ if (!model || model.initialised === false || (model.queen && model.queen.active)) return;
3520
+ queenBusy = true;
3521
+ renderQueenHint(model);
3522
+ try {
3523
+ await postAction("queen-on", {});
3524
+ } finally {
3525
+ queenBusy = false;
3526
+ if (!destroyed && lastModel) renderQueenHint(lastModel);
3527
+ else if (button && typeof button.focus === "function") button.focus();
3528
+ }
3529
+ }
3530
+
3365
3531
  async function runInitialise() {
3366
3532
  if (destroyed || initBusy) return;
3367
3533
  const model = lastModel;
@@ -3527,9 +3693,45 @@ function mount(root, options = {}) {
3527
3693
  }
3528
3694
 
3529
3695
  function renderQueenHint(model) {
3530
- const show = Boolean(model && model.initialised !== false && queenNotice);
3531
- queenHint.className = "hive-queen-hint" + (show ? " is-visible" : "");
3532
- queenHintText.textContent = translate("init.queen");
3696
+ const initialised = Boolean(model && model.initialised !== false);
3697
+ const state = model && isRecord(model.queen) ? model.queen : null;
3698
+ const active = state ? state.active === true : Boolean(queenNotice);
3699
+ const show = initialised && Boolean(state || queenNotice);
3700
+ const offer = show && !active;
3701
+
3702
+ if (initialised && state) {
3703
+ const source =
3704
+ state.source === "auto"
3705
+ ? translate("queen.source.auto")
3706
+ : state.source === "manual"
3707
+ ? translate("queen.source.manual")
3708
+ : "";
3709
+ const title = active
3710
+ ? source
3711
+ ? translate("queen.activeTitle").replace("{source}", source)
3712
+ : translate("queen.status.active")
3713
+ : translate("queen.inactiveTitle");
3714
+ queenBadge.className = "hive-queen-badge " + (active ? "is-active" : "is-inactive");
3715
+ queenBadge.textContent = active ? translate("queen.status.active") : translate("queen.status.inactive");
3716
+ setAttr(queenBadge, "title", title);
3717
+ setAttr(queenBadge, "aria-label", title);
3718
+ } else {
3719
+ queenBadge.className = "hive-queen-badge is-hidden";
3720
+ queenBadge.textContent = "";
3721
+ setAttr(queenBadge, "title", "");
3722
+ setAttr(queenBadge, "aria-label", "");
3723
+ }
3724
+
3725
+ queenHint.className = "hive-queen-hint" + (show ? " is-visible" : "") + (offer ? " is-offer" : "");
3726
+ queenHintText.textContent = active ? translate("init.queen") : translate("queen.offer");
3727
+ queenOffer.className = "hive-queen-offer" + (offer ? "" : " is-hidden");
3728
+ queenTakeoverButton.disabled = queenBusy;
3729
+ queenTakeoverButton.textContent = queenBusy ? translate("queen.takeoverBusy") : translate("queen.takeover");
3730
+ const takeoverAria = queenBusy ? translate("queen.takeoverBusy") : translate("queen.takeoverAria");
3731
+ setAttr(queenTakeoverButton, "title", takeoverAria);
3732
+ setAttr(queenTakeoverButton, "aria-label", takeoverAria);
3733
+
3734
+ queenExit.className = "hive-queen-exit" + (active ? "" : " is-hidden");
3533
3735
  queenExitText.textContent = translate("init.queenExit");
3534
3736
  queenCommand.textContent = translate("init.queenCommand");
3535
3737
  queenOutputSummary.textContent = translate("init.queenOutput");
@@ -3537,7 +3739,7 @@ function mount(root, options = {}) {
3537
3739
  const output = initOutput && initOutput.stdout ? initOutput.stdout : translate("init.noOutput");
3538
3740
  queenOutputPre.textContent = output;
3539
3741
  queenOutputDetails.className =
3540
- "hive-init-output hive-queen-output" + (show && initOutput ? "" : " is-hidden");
3742
+ "hive-init-output hive-queen-output" + (show && active && initOutput ? "" : " is-hidden");
3541
3743
  }
3542
3744
 
3543
3745
  function supervisorEndpoint(op) {
@@ -3685,6 +3887,23 @@ function mount(root, options = {}) {
3685
3887
  }
3686
3888
  }
3687
3889
 
3890
+ function durationLabel(count, singularKey, pluralKey) {
3891
+ const key = count === 1 ? singularKey : pluralKey;
3892
+ return translate(key).replace("{count}", String(count));
3893
+ }
3894
+
3895
+ function elapsedLabel(createdAt) {
3896
+ const date = parseDate(createdAt);
3897
+ if (!date) return "";
3898
+ const seconds = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1000));
3899
+ if (seconds < 60) return translate("stats.duration.justNow");
3900
+ const minutes = Math.floor(seconds / 60);
3901
+ if (minutes < 60) return durationLabel(minutes, "stats.duration.minute", "stats.duration.minutes");
3902
+ const hours = Math.floor(minutes / 60);
3903
+ if (hours < 24) return durationLabel(hours, "stats.duration.hour", "stats.duration.hours");
3904
+ return durationLabel(Math.floor(hours / 24), "stats.duration.day", "stats.duration.days");
3905
+ }
3906
+
3688
3907
  function renderStats(model) {
3689
3908
  clearNode(statsNode);
3690
3909
  const total = element(doc, "span", "hive-stat is-total");
@@ -3700,18 +3919,21 @@ function mount(root, options = {}) {
3700
3919
  }
3701
3920
 
3702
3921
  if (model.stats.oldestPending) {
3703
- const oldest = element(
3704
- doc,
3705
- "span",
3706
- "hive-stat is-warn",
3707
- translate("stats.oldest") + " " + formatTime(model.stats.oldestPending),
3708
- );
3709
- setAttr(oldest, "title", model.stats.oldestPending);
3922
+ const pending = model.stats.oldestPending;
3923
+ const duration = elapsedLabel(pending.createdAt);
3924
+ const label = translate("stats.oldest") + (duration ? " " + duration : "");
3925
+ const oldest = element(doc, "span", "hive-stat is-warn hive-oldest");
3926
+ oldest.appendChild(element(doc, "span", "hive-oldest-label", label));
3927
+ if (pending.id) {
3928
+ oldest.appendChild(element(doc, "span", "hive-oldest-sep", " · "));
3929
+ oldest.appendChild(element(doc, "code", "hive-oldest-id", pending.id));
3930
+ }
3931
+ setAttr(oldest, "title", label + (pending.id ? " · " + pending.id : ""));
3710
3932
  statsNode.appendChild(oldest);
3711
3933
  }
3712
3934
 
3713
3935
  const roleSummary = Object.keys(model.stats.byRole)
3714
- .map((role) => role + " " + model.stats.byRole[role])
3936
+ .map((role) => role + " " + asCount(model.stats.byRole[role], 0))
3715
3937
  .join(" · ");
3716
3938
  setAttr(statsNode, "title", roleSummary ? translate("stats.byRoleTitle") + roleSummary : "");
3717
3939
  }
@@ -4003,6 +4225,7 @@ function mount(root, options = {}) {
4003
4225
  initOutput = null;
4004
4226
  initErrorMessage = "";
4005
4227
  queenNotice = false;
4228
+ queenBusy = false;
4006
4229
  stageFilter = "all";
4007
4230
  stageChipEntries = [];
4008
4231
  eventsExpanded = false;
package/lib/index.js CHANGED
@@ -17,16 +17,20 @@
17
17
  * shell syntax. Execution goes through DSH's own shell seam so the Session
18
18
  * sandbox policy, credential scrubbing, timeout, and output caps apply.
19
19
  *
20
- * Queen mode (see lib/queen.js): a successful allowlisted `init` action that
21
- * leaves `refs/hive/v1` in place marks the calling Session as queen; the
22
- * `hive:queen` system-prompt section then renders `<cwd>/.hive/roles/queen.md`
23
- * for that Session only. `/queen off` or `op=action&name=queen-off` exits.
20
+ * Queen mode (see lib/queen.js): while an initialised Session is open the
21
+ * snapshot loop auto-marks it as queen (unless `config.autoQueen` is false or
22
+ * the Session was explicitly closed); a successful allowlisted `init` action
23
+ * and `op=action&name=queen-on` also mark it. The `hive:queen` system-prompt
24
+ * section then renders `<cwd>/.hive/roles/queen.md` for that Session only.
25
+ * Every snapshot reports `queen: { active, source, repo }`; `/queen off` or
26
+ * `op=action&name=queen-off` exits and suppresses auto-activation for that
27
+ * Session.
24
28
  *
25
29
  * @module dsh-hive-panel
26
30
  */
27
31
  import fs from 'node:fs'
28
32
  import path from 'node:path'
29
- import { createQueen, QUEEN_OFF_ACTION } from './queen.js'
33
+ import { createQueen, QUEEN_OFF_ACTION, QUEEN_ON_ACTION } from './queen.js'
30
34
 
31
35
  /** Cordis plugin name used in logs and fiber diagnostics. */
32
36
  export const name = 'hive-panel'
@@ -399,7 +403,8 @@ function createLog(ctx) {
399
403
  *
400
404
  * @param {object} ctx - host Cordis context carrying
401
405
  * connection/sessions/workingDirectory/shell (+ optional sandboxPolicy/sessionPersistence).
402
- * @param {{ writable?: boolean, bins?: object, queen?: object, timeoutMs?: number, actionTimeoutMs?: number, log?: Function }} [config]
406
+ * @param {{ writable?: boolean, autoQueen?: boolean, bins?: object, queen?: object, timeoutMs?: number, actionTimeoutMs?: number, log?: Function }} [config]
407
+ * `autoQueen` (default true) lets an initialised snapshot mark the Session as queen.
403
408
  * @returns {{
404
409
  * snapshot: (sessionId: string, signal?: AbortSignal) => Promise<object>,
405
410
  * actions: (sessionId: string) => Promise<object>,
@@ -408,6 +413,7 @@ function createLog(ctx) {
408
413
  */
409
414
  export function createBridge(ctx, config = {}) {
410
415
  const writable = config.writable === true
416
+ const autoQueen = config.autoQueen !== false
411
417
  const bins = normalizeBins(config.bins)
412
418
  const queen = config.queen
413
419
  const log = typeof config.log === 'function' ? config.log : () => {}
@@ -519,6 +525,38 @@ export function createBridge(ctx, config = {}) {
519
525
  return { mode: 'free' }
520
526
  }
521
527
 
528
+ /** Report the current queen state in the snapshot contract. */
529
+ function queenSnapshot(sessionId, cwd) {
530
+ let state
531
+ if (queen !== undefined && typeof queen.snapshotFor === 'function') {
532
+ try {
533
+ state = queen.snapshotFor(sessionId)
534
+ } catch (error) {
535
+ log('queen snapshot failed', error)
536
+ }
537
+ }
538
+ return {
539
+ active: state?.active === true,
540
+ source: state?.active === true ? (state.source ?? null) : null,
541
+ repo: cwd,
542
+ }
543
+ }
544
+
545
+ /**
546
+ * Auto-activate queen mode for an initialised Session before a snapshot is
547
+ * returned. Idempotent: the controller does not rewrite an active session and
548
+ * refuses sessions the user explicitly closed.
549
+ */
550
+ function autoActivateQueen(sessionId, cwd) {
551
+ if (!autoQueen || queen === undefined || typeof queen.autoMark !== 'function') return false
552
+ try {
553
+ return queen.autoMark({ sessionId, cwd }) === true
554
+ } catch (error) {
555
+ log('queen auto-activation failed', error)
556
+ return false
557
+ }
558
+ }
559
+
522
560
  async function snapshot(sessionId, signal) {
523
561
  const { session, cwd } = await resolveSession(sessionId)
524
562
  const payload = {
@@ -531,9 +569,12 @@ export function createBridge(ctx, config = {}) {
531
569
  stats: null,
532
570
  events: [],
533
571
  writable,
572
+ queen: { active: false, source: null, repo: cwd },
534
573
  }
535
574
  const refs = await tryExecute(SNAPSHOT_READS.refs, { cwd, session, timeoutMs: PROBE_TIMEOUT_MS, signal })
536
575
  const initialised = refs !== undefined && refs.exitCode === 0 && String(refs.stdout?.text ?? '').trim() !== ''
576
+ if (initialised) autoActivateQueen(sessionId, cwd)
577
+ payload.queen = queenSnapshot(sessionId, cwd)
537
578
  if (!initialised) {
538
579
  payload.events = readEvents(cwd)
539
580
  return payload
@@ -558,7 +599,12 @@ export function createBridge(ctx, config = {}) {
558
599
 
559
600
  async function actions(sessionId) {
560
601
  const { cwd } = await resolveSession(sessionId)
561
- return { writable, actions: [...ACTION_NAMES, QUEEN_OFF_ACTION], repo: cwd }
602
+ return {
603
+ writable,
604
+ autoQueen,
605
+ actions: [...ACTION_NAMES, QUEEN_ON_ACTION, QUEEN_OFF_ACTION],
606
+ repo: cwd,
607
+ }
562
608
  }
563
609
 
564
610
  /** Normalize one shell result into the action contract `{ ok, code, stdout, stderr }`. */
@@ -599,10 +645,24 @@ export function createBridge(ctx, config = {}) {
599
645
  throw new HiveRequestError('hive/invalid-argument', 'name is required', 400)
600
646
  }
601
647
  const { session, cwd } = await resolveSession(sessionId)
648
+ // Queen mode is host memory, not a repository write: both actions work in
649
+ // read-only mode. They are idempotent and return the standard envelope.
650
+ if (actionName === QUEEN_ON_ACTION) {
651
+ if (queen === undefined || typeof queen.mark !== 'function') {
652
+ throw new HiveRequestError('hive/queen-unavailable', 'queen controller is unavailable', 500)
653
+ }
654
+ queen.mark({ sessionId, cwd, source: 'manual' })
655
+ return { status: 200, body: { ok: true, code: 0, stdout: '', stderr: '' } }
656
+ }
602
657
  if (actionName === QUEEN_OFF_ACTION) {
603
- if (queen !== undefined && typeof queen.clear === 'function') queen.clear(sessionId)
658
+ if (queen !== undefined && typeof queen.disable === 'function') queen.disable(sessionId)
604
659
  return { status: 200, body: { ok: true, code: 0, stdout: '', stderr: '' } }
605
660
  }
661
+ // Validate the action name before the read-only gate so `hive/unknown-action`
662
+ // is deterministic in both modes.
663
+ if (!ACTION_NAMES.includes(actionName)) {
664
+ throw new HiveRequestError('hive/unknown-action', 'unknown action ' + JSON.stringify(actionName))
665
+ }
606
666
  if (!writable) {
607
667
  return {
608
668
  status: 403,
@@ -625,7 +685,9 @@ export function createBridge(ctx, config = {}) {
625
685
 
626
686
  function actionFailure(error) {
627
687
  const message = error instanceof Error ? error.message : String(error)
628
- return { ok: false, code: 2, stdout: '', stderr: message }
688
+ // Host-side failures carry a stable code in stderr: `hive/<code>: message`.
689
+ const code = error instanceof HiveRequestError ? error.code + ': ' : ''
690
+ return { ok: false, code: 2, stdout: '', stderr: code + message }
629
691
  }
630
692
 
631
693
  function errorResponse(error) {
@@ -716,9 +778,11 @@ export function createFetchHandler(bridge) {
716
778
  * Host plugin body: register the queen controller and the exact Fetch route.
717
779
  *
718
780
  * @param {object} ctx - host Cordis context.
719
- * @param {{ writable?: boolean, bins?: object, timeoutMs?: number, actionTimeoutMs?: number }} [config]
781
+ * @param {{ writable?: boolean, autoQueen?: boolean, bins?: object, timeoutMs?: number, actionTimeoutMs?: number }} [config]
720
782
  * `writable` (default false) enables the mutating action allowlist;
721
- * `bins` overrides the four CLI executables (trusted host config only).
783
+ * `autoQueen` (default true) lets an initialised Session auto-enter queen
784
+ * mode from the snapshot loop; `bins` overrides the four CLI executables
785
+ * (trusted host config only).
722
786
  */
723
787
  export function apply(ctx, config = {}) {
724
788
  const settings = config !== null && typeof config === 'object' ? config : {}
@@ -727,6 +791,7 @@ export function apply(ctx, config = {}) {
727
791
  ctx.effect(() => () => { queen.dispose() }, 'hive-panel: queen state')
728
792
  const bridge = createBridge(ctx, {
729
793
  writable: settings.writable === true,
794
+ autoQueen: settings.autoQueen !== false,
730
795
  bins: settings.bins,
731
796
  queen,
732
797
  log,