@d86e/hive-panel 1.0.3 → 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 +100 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d86e/hive-panel",
3
- "version": "1.0.3",
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
@@ -2297,6 +2297,9 @@ export const messages = Object.freeze({
2297
2297
  "toast.dismiss": "Dismiss",
2298
2298
  "toast.planWritten": "Tasks written",
2299
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",
2300
2303
  "toast.pickupHint": "The supervisor will pick them up automatically.",
2301
2304
  }),
2302
2305
  zh: Object.freeze({
@@ -2548,6 +2551,9 @@ export const messages = Object.freeze({
2548
2551
  "toast.dismiss": "关闭",
2549
2552
  "toast.planWritten": "任务已写入",
2550
2553
  "toast.taskRemoved": "任务已删除",
2554
+ "action.busy": "处理中…",
2555
+ "action.retryNotFailed": "任务已不在失败状态,可能已被重新派发",
2556
+ "toast.retryQueued": "已重新入队",
2551
2557
  "toast.pickupHint": "supervisor 会自动接任务。",
2552
2558
  }),
2553
2559
  });
@@ -3565,6 +3571,8 @@ export function mount(root, options = {}) {
3565
3571
  let drawerNode = null;
3566
3572
  let drawerState = null;
3567
3573
  let drawerTrigger = null;
3574
+ let drawerActionBusy = false;
3575
+ let drawerActionButtons = [];
3568
3576
  let unsubscribeLocale = null;
3569
3577
  let statusKey = null;
3570
3578
  let statusKind = "info";
@@ -5193,6 +5201,8 @@ export function mount(root, options = {}) {
5193
5201
  }
5194
5202
  drawerNode = null;
5195
5203
  drawerState = null;
5204
+ drawerActionBusy = false;
5205
+ drawerActionButtons = [];
5196
5206
  if (typeof doc.removeEventListener === "function") {
5197
5207
  doc.removeEventListener("keydown", onDrawerKeydown);
5198
5208
  }
@@ -5495,6 +5505,8 @@ export function mount(root, options = {}) {
5495
5505
  ),
5496
5506
  );
5497
5507
  }
5508
+ drawerActionBusy = false;
5509
+ drawerActionButtons = [];
5498
5510
  if (runActions.length > 0 || actions.length > 0) {
5499
5511
  const foot = element(doc, "div", "hive-dialog-foot hive-card-actions");
5500
5512
  setAttr(foot, "aria-label", translate("drawer.cardActions"));
@@ -5518,8 +5530,14 @@ export function mount(root, options = {}) {
5518
5530
  button.disabled = true;
5519
5531
  setAttr(button, "aria-disabled", "true");
5520
5532
  }
5533
+ drawerActionButtons.push({
5534
+ button,
5535
+ action: action.name,
5536
+ labelKey: action.labelKey,
5537
+ baseDisabled: button.disabled === true,
5538
+ });
5521
5539
  button.addEventListener("click", () => {
5522
- void runCardAction(action.name, card, lane);
5540
+ void runCardAction(action.name, card, lane, button);
5523
5541
  });
5524
5542
  foot.appendChild(button);
5525
5543
  }
@@ -5700,50 +5718,93 @@ export function mount(root, options = {}) {
5700
5718
  }
5701
5719
  }
5702
5720
 
5703
- async function runCardAction(name, card, lane) {
5704
- if (destroyed) return;
5705
- let ok = false;
5706
- switch (name) {
5707
- case "claim": {
5708
- const agent = ask(translate("prompt.claimAgent"), "panel");
5709
- if (agent === null) return;
5710
- ok = await postAction("claim", { id: card.id, agent: agent.trim() || "panel" });
5711
- break;
5712
- }
5713
- case "done": {
5714
- const sha = ask(translate("prompt.commitSha"), "");
5715
- if (sha === null) return;
5716
- const body = { id: card.id };
5717
- if (sha.trim()) body.sha = sha.trim();
5718
- ok = await postAction("done", body);
5719
- 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"];
5720
5730
  }
5721
- case "fail": {
5722
- const reason = ask(translate("prompt.failReason"), "");
5723
- if (reason === null || !reason.trim()) return;
5724
- ok = await postAction("fail", { id: card.id, reason: reason.trim() });
5725
- 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;
5726
5786
  }
5727
- case "retry":
5728
- ok = await postAction("retry", { id: card.id });
5729
- break;
5730
- case "remove": {
5731
- const name = card.title || card.id || translate("card.untitled");
5732
- const message = translate("confirm.remove").replace("{title}", name);
5733
- if (!askConfirm(message)) return;
5734
- ok = await postAction("remove", { id: card.id });
5735
- 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;
5736
5796
  }
5737
- default:
5738
- break;
5739
- }
5740
- if (ok && !destroyed) {
5741
- if (name === "remove") showToast("success", translate("toast.taskRemoved"), "");
5797
+ if (destroyed) return;
5742
5798
  closeDrawer();
5743
- 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;
5744
5806
  }
5745
5807
  }
5746
-
5747
5808
  // --- rendering -----------------------------------------------------------
5748
5809
 
5749
5810
  function renderInit(model) {