@d86e/hive-panel 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/panel.js +112 -42
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d86e/hive-panel",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A read-only board for a Hive swarm: agents, task lanes and the event tail, served from the refs and files you already have.",
5
5
  "type": "module",
6
6
  "bin": {
package/public/panel.js CHANGED
@@ -2099,6 +2099,8 @@ export const messages = Object.freeze({
2099
2099
  "agents.workerStarted": "Started {time}",
2100
2100
  "agents.workerElapsed": "Running for {duration}",
2101
2101
  "agents.technical": "Technical details",
2102
+ "agents.waitingReclaim": "Waiting to reclaim {count}",
2103
+ "agents.waitingReclaimTooltip": "{count} tasks are claimed but no agent is running (waiting to be reclaimed after a process restart)",
2102
2104
  "agent.idle": "idle",
2103
2105
  "agent.task": "task",
2104
2106
  "agent.unknown": "unknown",
@@ -2295,6 +2297,9 @@ export const messages = Object.freeze({
2295
2297
  "toast.dismiss": "Dismiss",
2296
2298
  "toast.planWritten": "Tasks written",
2297
2299
  "toast.taskRemoved": "Task deleted",
2300
+ "action.busy": "Working…",
2301
+ "action.retryNotFailed": "The task is no longer failed; it may have been requeued.",
2302
+ "toast.retryQueued": "Task requeued",
2298
2303
  "toast.pickupHint": "The supervisor will pick them up automatically.",
2299
2304
  }),
2300
2305
  zh: Object.freeze({
@@ -2348,6 +2353,8 @@ export const messages = Object.freeze({
2348
2353
  "agents.workerStarted": "开始于 {time}",
2349
2354
  "agents.workerElapsed": "已运行 {duration}",
2350
2355
  "agents.technical": "技术详情",
2356
+ "agents.waitingReclaim": "等待回收 {count}",
2357
+ "agents.waitingReclaimTooltip": "有 {count} 个任务被认领但当前没有运行中的工作单元(进程重启后等待回收)",
2351
2358
  "agent.idle": "空闲",
2352
2359
  "agent.task": "任务",
2353
2360
  "agent.unknown": "未知",
@@ -2544,6 +2551,9 @@ export const messages = Object.freeze({
2544
2551
  "toast.dismiss": "关闭",
2545
2552
  "toast.planWritten": "任务已写入",
2546
2553
  "toast.taskRemoved": "任务已删除",
2554
+ "action.busy": "处理中…",
2555
+ "action.retryNotFailed": "任务已不在失败状态,可能已被重新派发",
2556
+ "toast.retryQueued": "已重新入队",
2547
2557
  "toast.pickupHint": "supervisor 会自动接任务。",
2548
2558
  }),
2549
2559
  });
@@ -3561,6 +3571,8 @@ export function mount(root, options = {}) {
3561
3571
  let drawerNode = null;
3562
3572
  let drawerState = null;
3563
3573
  let drawerTrigger = null;
3574
+ let drawerActionBusy = false;
3575
+ let drawerActionButtons = [];
3564
3576
  let unsubscribeLocale = null;
3565
3577
  let statusKey = null;
3566
3578
  let statusKind = "info";
@@ -5189,6 +5201,8 @@ export function mount(root, options = {}) {
5189
5201
  }
5190
5202
  drawerNode = null;
5191
5203
  drawerState = null;
5204
+ drawerActionBusy = false;
5205
+ drawerActionButtons = [];
5192
5206
  if (typeof doc.removeEventListener === "function") {
5193
5207
  doc.removeEventListener("keydown", onDrawerKeydown);
5194
5208
  }
@@ -5491,6 +5505,8 @@ export function mount(root, options = {}) {
5491
5505
  ),
5492
5506
  );
5493
5507
  }
5508
+ drawerActionBusy = false;
5509
+ drawerActionButtons = [];
5494
5510
  if (runActions.length > 0 || actions.length > 0) {
5495
5511
  const foot = element(doc, "div", "hive-dialog-foot hive-card-actions");
5496
5512
  setAttr(foot, "aria-label", translate("drawer.cardActions"));
@@ -5514,8 +5530,14 @@ export function mount(root, options = {}) {
5514
5530
  button.disabled = true;
5515
5531
  setAttr(button, "aria-disabled", "true");
5516
5532
  }
5533
+ drawerActionButtons.push({
5534
+ button,
5535
+ action: action.name,
5536
+ labelKey: action.labelKey,
5537
+ baseDisabled: button.disabled === true,
5538
+ });
5517
5539
  button.addEventListener("click", () => {
5518
- void runCardAction(action.name, card, lane);
5540
+ void runCardAction(action.name, card, lane, button);
5519
5541
  });
5520
5542
  foot.appendChild(button);
5521
5543
  }
@@ -5696,50 +5718,93 @@ export function mount(root, options = {}) {
5696
5718
  }
5697
5719
  }
5698
5720
 
5699
- async function runCardAction(name, card, lane) {
5700
- if (destroyed) return;
5701
- let ok = false;
5702
- switch (name) {
5703
- case "claim": {
5704
- const agent = ask(translate("prompt.claimAgent"), "panel");
5705
- if (agent === null) return;
5706
- ok = await postAction("claim", { id: card.id, agent: agent.trim() || "panel" });
5707
- break;
5708
- }
5709
- case "done": {
5710
- const sha = ask(translate("prompt.commitSha"), "");
5711
- if (sha === null) return;
5712
- const body = { id: card.id };
5713
- if (sha.trim()) body.sha = sha.trim();
5714
- ok = await postAction("done", body);
5715
- break;
5721
+ function setDrawerActionBusy(activeButton, busy) {
5722
+ for (const entry of drawerActionButtons) {
5723
+ if (busy) {
5724
+ entry.button.disabled = true;
5725
+ setAttr(entry.button, "aria-busy", "true");
5726
+ } else {
5727
+ entry.button.disabled = entry.baseDisabled;
5728
+ if (typeof entry.button.removeAttribute === "function") entry.button.removeAttribute("aria-busy");
5729
+ else delete entry.button.attributes["aria-busy"];
5716
5730
  }
5717
- case "fail": {
5718
- const reason = ask(translate("prompt.failReason"), "");
5719
- if (reason === null || !reason.trim()) return;
5720
- ok = await postAction("fail", { id: card.id, reason: reason.trim() });
5721
- break;
5731
+ }
5732
+ if (!activeButton) return;
5733
+ if (busy) {
5734
+ activeButton.textContent = translate("action.busy");
5735
+ } else {
5736
+ const entry = drawerActionButtons.find((item) => item.button === activeButton);
5737
+ if (entry) activeButton.textContent = translate(entry.labelKey);
5738
+ }
5739
+ }
5740
+
5741
+ function cardActionErrorMessage(name, error) {
5742
+ const detail = actionErrorDetail(error) || translate("status.actionFailed");
5743
+ if (name === "retry" && /not failed/i.test(detail)) return translate("action.retryNotFailed");
5744
+ return detail;
5745
+ }
5746
+
5747
+ async function runCardAction(name, card, lane, button) {
5748
+ if (destroyed || drawerActionBusy) return;
5749
+ drawerActionBusy = true;
5750
+ setDrawerActionBusy(button, true);
5751
+ try {
5752
+ let body = null;
5753
+ switch (name) {
5754
+ case "claim": {
5755
+ const agent = ask(translate("prompt.claimAgent"), "panel");
5756
+ if (agent === null) return;
5757
+ body = { id: card.id, agent: agent.trim() || "panel" };
5758
+ break;
5759
+ }
5760
+ case "done": {
5761
+ const sha = ask(translate("prompt.commitSha"), "");
5762
+ if (sha === null) return;
5763
+ body = { id: card.id };
5764
+ if (sha.trim()) body.sha = sha.trim();
5765
+ break;
5766
+ }
5767
+ case "fail": {
5768
+ const reason = ask(translate("prompt.failReason"), "");
5769
+ if (reason === null || !reason.trim()) return;
5770
+ body = { id: card.id, reason: reason.trim() };
5771
+ break;
5772
+ }
5773
+ case "retry":
5774
+ case "supersede":
5775
+ body = { id: card.id };
5776
+ break;
5777
+ case "remove": {
5778
+ const title = card.title || card.id || translate("card.untitled");
5779
+ const message = translate("confirm.remove").replace("{title}", title);
5780
+ if (!askConfirm(message)) return;
5781
+ body = { id: card.id };
5782
+ break;
5783
+ }
5784
+ default:
5785
+ return;
5722
5786
  }
5723
- case "retry":
5724
- ok = await postAction("retry", { id: card.id });
5725
- break;
5726
- case "remove": {
5727
- const name = card.title || card.id || translate("card.untitled");
5728
- const message = translate("confirm.remove").replace("{title}", name);
5729
- if (!askConfirm(message)) return;
5730
- ok = await postAction("remove", { id: card.id });
5731
- break;
5787
+
5788
+ const result = await requestAction(name, body);
5789
+ if (!result.ok) {
5790
+ if (!destroyed) {
5791
+ setStatus("status.actionFailed", "error");
5792
+ reportError(result.error);
5793
+ showToast("error", translate("status.actionFailed"), cardActionErrorMessage(name, result.error));
5794
+ }
5795
+ return;
5732
5796
  }
5733
- default:
5734
- break;
5735
- }
5736
- if (ok && !destroyed) {
5737
- if (name === "remove") showToast("success", translate("toast.taskRemoved"), "");
5797
+ if (destroyed) return;
5738
5798
  closeDrawer();
5739
- void refresh();
5799
+ await forceRefresh();
5800
+ if (destroyed) return;
5801
+ if (name === "remove") showToast("success", translate("toast.taskRemoved"), "");
5802
+ else if (name === "retry") showToast("success", translate("toast.retryQueued"), "");
5803
+ } finally {
5804
+ if (!destroyed && drawerNode) setDrawerActionBusy(button, false);
5805
+ drawerActionBusy = false;
5740
5806
  }
5741
5807
  }
5742
-
5743
5808
  // --- rendering -----------------------------------------------------------
5744
5809
 
5745
5810
  function renderInit(model) {
@@ -6097,13 +6162,18 @@ export function mount(root, options = {}) {
6097
6162
  const row = currentSupervisorRow();
6098
6163
  const workers = supervisorWorkerCount(row);
6099
6164
  const running = workers !== null ? workers : identities;
6165
+ const claimed = asCount(model.stats.byState.claimed, (model.lanes.claimed || []).length);
6166
+ const waitingToReclaim = workers === 0 && claimed > 0;
6100
6167
  agentsCount.className = "hive-stat hive-agent-count";
6101
- agentsCount.textContent = translate("pane.agents") + " " + String(running);
6168
+ agentsCount.textContent = waitingToReclaim
6169
+ ? translate("agents.waitingReclaim").replace("{count}", String(claimed))
6170
+ : translate("pane.agents") + " " + String(running);
6102
6171
  const first = identities > 0 ? model.agents[0] : null;
6103
6172
  agentsCount._agent = first;
6104
6173
  agentsCount.disabled = false;
6105
- const message =
6106
- workers !== null
6174
+ const message = waitingToReclaim
6175
+ ? translate("agents.waitingReclaimTooltip").replace("{count}", String(claimed))
6176
+ : workers !== null
6107
6177
  ? translate("agents.runningTooltip")
6108
6178
  .replace("{running}", String(running))
6109
6179
  .replace("{identities}", String(identities))