@d86e/hive-panel 1.0.6 → 1.0.8

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 +125 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d86e/hive-panel",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
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
@@ -2143,9 +2143,12 @@ export const messages = Object.freeze({
2143
2143
  "supervisor.unresponsive": "Unresponsive",
2144
2144
  "supervisor.noData": "No supervisor data",
2145
2145
  "supervisor.lastCheck": "Last check {seconds}s ago",
2146
+ "supervisor.lastTick": "Last tick {seconds}s ago",
2146
2147
  "supervisor.tooltipRunning": "Running {count}",
2147
2148
  "supervisor.tooltipQueued": "Queued {count}",
2148
2149
  "supervisor.tooltipError": "Last error: {error}",
2150
+ "supervisor.scopeBlockedTitle": "Cross-repository call blocked",
2151
+ "supervisor.scopeBlocked": "{tool} asked for repository {repo}, but this Session only controls {cwd}. The call was rejected.",
2149
2152
  "supervisor.resume": "resume",
2150
2153
  "supervisor.resumeAria": "Resume the supervisor for {repo}",
2151
2154
  "supervisor.resumeFailed": "Could not resume the supervisor",
@@ -2404,9 +2407,12 @@ export const messages = Object.freeze({
2404
2407
  "supervisor.unresponsive": "未响应",
2405
2408
  "supervisor.noData": "无监督器数据",
2406
2409
  "supervisor.lastCheck": "最近一次检查 {seconds} 秒前",
2410
+ "supervisor.lastTick": "最后 tick {seconds} 秒前",
2407
2411
  "supervisor.tooltipRunning": "运行中 {count} 个",
2408
2412
  "supervisor.tooltipQueued": "待办 {count} 个",
2409
2413
  "supervisor.tooltipError": "最近错误:{error}",
2414
+ "supervisor.scopeBlockedTitle": "跨仓库调用被拒绝",
2415
+ "supervisor.scopeBlocked": "{tool} 发起跨仓库请求:仓库 {repo},但本会话只允许操作 {cwd};该调用已被拒绝。",
2410
2416
  "supervisor.resume": "恢复",
2411
2417
  "supervisor.resumeAria": "恢复 {repo} 的 supervisor",
2412
2418
  "supervisor.resumeFailed": "恢复 supervisor 失败",
@@ -3095,6 +3101,32 @@ function normalizeSupervisorWorkers(source) {
3095
3101
  return rows;
3096
3102
  }
3097
3103
 
3104
+ function supervisorTopTick(payload) {
3105
+ const candidates = [payload];
3106
+ for (const key of ["data", "result", "status", "supervisor"]) {
3107
+ if (isRecord(payload) && isRecord(payload[key])) candidates.push(payload[key]);
3108
+ }
3109
+ for (const source of candidates) {
3110
+ if (!isRecord(source)) continue;
3111
+ const tick = asString(source.lastTickAt || source.last_tick_at);
3112
+ if (tick) return tick;
3113
+ }
3114
+ return "";
3115
+ }
3116
+
3117
+ function supervisorHeartbeatAt(rows) {
3118
+ if (!Array.isArray(rows)) return null;
3119
+ const top = parseDate(rows.lastTickAt);
3120
+ if (top) return top;
3121
+ let latest = null;
3122
+ for (const row of rows) {
3123
+ if (!isRecord(row)) continue;
3124
+ const check = parseDate(row.lastCheckAt);
3125
+ if (check && (latest === null || check.getTime() > latest.getTime())) latest = check;
3126
+ }
3127
+ return latest;
3128
+ }
3129
+
3098
3130
  function normalizeSupervisorStatus(payload) {
3099
3131
  const rows = new Map();
3100
3132
  for (const raw of supervisorEntriesFrom(payload)) {
@@ -3146,7 +3178,51 @@ function normalizeSupervisorStatus(payload) {
3146
3178
  workers: normalizeSupervisorWorkers(source),
3147
3179
  });
3148
3180
  }
3149
- return [...rows.values()].sort((left, right) => left.repo.localeCompare(right.repo));
3181
+ const result = [...rows.values()].sort((left, right) => left.repo.localeCompare(right.repo));
3182
+ result.lastTickAt = supervisorTopTick(payload);
3183
+ return result;
3184
+ }
3185
+
3186
+ /**
3187
+ * Normalize the supervisor's queen cross-repository rejection observability:
3188
+ * \`crossRepoBlocked\` count + \`lastCrossRepoBlocked { tool, repo, cwd, at }\`.
3189
+ * Older/newer supervisors may nest it under queen-prefixed or repoScope names.
3190
+ * @param {unknown} payload - /api/hive-runner?op=status payload.
3191
+ * @returns {{ count: number, last: { tool: string, repo: string, cwd: string, at: string } | null }}
3192
+ */
3193
+ export function normalizeSupervisorMeta(payload) {
3194
+ const source = isRecord(payload) ? payload : {};
3195
+ const nested = isRecord(source.repoScopeBlocked) ? source.repoScopeBlocked : {};
3196
+ const rawCount = supervisorNumber(source.crossRepoBlocked)
3197
+ ?? supervisorNumber(source.queenCrossRepoBlocked)
3198
+ ?? supervisorNumber(nested.count)
3199
+ ?? 0;
3200
+ const rawLast = source.lastCrossRepoBlocked || source.lastQueenCrossRepoBlocked || nested.last || null;
3201
+ const last = isRecord(rawLast)
3202
+ ? {
3203
+ tool: asString(rawLast.tool),
3204
+ repo: asString(rawLast.repo),
3205
+ cwd: asString(rawLast.cwd),
3206
+ at: asString(rawLast.at),
3207
+ }
3208
+ : null;
3209
+ return { count: rawCount > 0 ? rawCount : 0, last };
3210
+ }
3211
+
3212
+ /**
3213
+ * Render the human-readable reason for a blocked cross-repository call.
3214
+ * @param {{ count: number, last: object|null }} meta - normalized supervisor meta.
3215
+ * @param {(key: string) => string} translate - dictionary lookup.
3216
+ * @returns {string} localized reason, or '' when there is no rejection.
3217
+ */
3218
+ export function formatScopeBlocked(meta, translate) {
3219
+ const last = meta && meta.last;
3220
+ if (!last) return "";
3221
+ const t = typeof translate === "function" ? translate : (key) => key;
3222
+ return t("supervisor.scopeBlocked")
3223
+ .replace("{tool}", last.tool || "?")
3224
+ .replace("{repo}", last.repo || "?")
3225
+ .replace("{cwd}", last.cwd || "?");
3150
3226
  }
3151
3227
 
3152
3228
  function supervisorWorkerCount(row) {
@@ -3168,6 +3244,15 @@ function supervisorWorkerCount(row) {
3168
3244
  return found ? total : null;
3169
3245
  }
3170
3246
 
3247
+ function taskDisplayTitle(title) {
3248
+ const full = asString(title);
3249
+ if (!full) return full;
3250
+ const stripped = full
3251
+ .replace(/^[\w.-]+\/[A-Za-z]?\d+\s*[::]\s*/, "")
3252
+ .replace(/^[A-Za-z]+-\d+\s*[::]\s*/, "");
3253
+ return stripped || full;
3254
+ }
3255
+
3171
3256
  function element(doc, tag, className, text) {
3172
3257
  const node = doc.createElement(tag);
3173
3258
  if (className) node.className = className;
@@ -3648,6 +3733,8 @@ export function mount(root, options = {}) {
3648
3733
  let queenBusy = false;
3649
3734
  const queenDismissedFallback = new Set();
3650
3735
  let supervisorData = [];
3736
+ let supervisorMeta = { count: 0, last: null };
3737
+ let supervisorScopeSignature = null;
3651
3738
  let supervisorRequest = null;
3652
3739
  let supervisorInlineRow = null;
3653
3740
  let limitsOverlay = null;
@@ -6018,10 +6105,10 @@ export function mount(root, options = {}) {
6018
6105
  ? supervisorData.find((entry) => entry.repo === lastModel.repo)
6019
6106
  : null;
6020
6107
  const now = Date.now();
6021
- const lastCheck = row ? parseDate(row.lastCheckAt) : null;
6022
- const fresh = lastCheck !== null && now - lastCheck.getTime() <= 90_000;
6108
+ const heartbeat = supervisorHeartbeatAt(supervisorData);
6109
+ const fresh = heartbeat !== null && now - heartbeat.getTime() <= 90_000;
6023
6110
  const paused = Boolean(row && (row.paused === true || row.state === "paused"));
6024
- const status = paused ? "paused" : fresh ? "normal" : "unresponsive";
6111
+ const status = paused ? "paused" : !row ? "unresponsive" : fresh ? "normal" : "unresponsive";
6025
6112
  const label =
6026
6113
  status === "normal"
6027
6114
  ? translate("supervisor.normal")
@@ -6035,11 +6122,12 @@ export function mount(root, options = {}) {
6035
6122
  supervisorInlineState.textContent = label;
6036
6123
 
6037
6124
  const details = [];
6038
- if (lastCheck) {
6125
+ if (heartbeat) {
6126
+ const hasTopTick = Boolean(supervisorData && parseDate(supervisorData.lastTickAt));
6039
6127
  details.push(
6040
- translate("supervisor.lastCheck").replace(
6128
+ translate(hasTopTick ? "supervisor.lastTick" : "supervisor.lastCheck").replace(
6041
6129
  "{seconds}",
6042
- String(Math.max(0, Math.floor((now - lastCheck.getTime()) / 1000))),
6130
+ String(Math.max(0, Math.floor((now - heartbeat.getTime()) / 1000))),
6043
6131
  ),
6044
6132
  );
6045
6133
  } else {
@@ -6051,6 +6139,9 @@ export function mount(root, options = {}) {
6051
6139
  if (row && row.lastError) {
6052
6140
  details.push(translate("supervisor.tooltipError").replace("{error}", asString(row.lastError)));
6053
6141
  }
6142
+ if (supervisorMeta.last && supervisorMeta.last.cwd !== "") {
6143
+ details.push(translate("supervisor.scopeBlockedTitle") + ": " + formatScopeBlocked(supervisorMeta, translate));
6144
+ }
6054
6145
  const tooltip = details.join(" · ");
6055
6146
  setAttr(supervisorInline, "title", tooltip);
6056
6147
  setAttr(supervisorInline, "aria-label", tooltip);
@@ -6068,6 +6159,25 @@ export function mount(root, options = {}) {
6068
6159
  if (lastModel) renderAgents(lastModel);
6069
6160
  }
6070
6161
 
6162
+
6163
+ /**
6164
+ * Surface the supervisor's queen cross-repository rejections in the panel UI:
6165
+ * a toast with the concrete tool/repo/allowed-cwd reason for every new rejection,
6166
+ * plus the same reason in the supervisor strip tooltip. The backend already
6167
+ * refused the tool call; this makes the refusal visible to the human too.
6168
+ */
6169
+ function applySupervisorMeta(payload) {
6170
+ const meta = normalizeSupervisorMeta(payload);
6171
+ supervisorMeta = meta;
6172
+ if (!meta.last) return;
6173
+ const signature = [meta.count, meta.last.at, meta.last.tool, meta.last.repo, meta.last.cwd].join("|");
6174
+ if (signature !== supervisorScopeSignature) {
6175
+ supervisorScopeSignature = signature;
6176
+ showToast("error", translate("supervisor.scopeBlockedTitle"), formatScopeBlocked(meta, translate));
6177
+ }
6178
+ renderSupervisor();
6179
+ }
6180
+
6071
6181
  async function refreshSupervisor(force = false) {
6072
6182
  if (destroyed) return;
6073
6183
  if (!fetchImpl) {
@@ -6096,7 +6206,10 @@ export function mount(root, options = {}) {
6096
6206
  } catch {
6097
6207
  payload = null;
6098
6208
  }
6099
- if (!destroyed) setSupervisorData(normalizeSupervisorStatus(payload));
6209
+ if (!destroyed) {
6210
+ setSupervisorData(normalizeSupervisorStatus(payload));
6211
+ applySupervisorMeta(payload);
6212
+ }
6100
6213
  } catch {
6101
6214
  // The supervisor service is optional; hide the strip without reporting.
6102
6215
  if (!destroyed) setSupervisorData([]);
@@ -6250,7 +6363,8 @@ export function mount(root, options = {}) {
6250
6363
 
6251
6364
  function renderCard(card, lane, existing) {
6252
6365
  const node = existing || element(doc, "article", "hive-card");
6253
- const title = card.title || translate("card.untitled");
6366
+ const fullTitle = card.title || translate("card.untitled");
6367
+ const title = taskDisplayTitle(fullTitle);
6254
6368
  if (!existing) {
6255
6369
  setAttr(node, "tabindex", "0");
6256
6370
  setAttr(node, "role", "button");
@@ -6268,8 +6382,8 @@ export function mount(root, options = {}) {
6268
6382
  node._hiveCard = card;
6269
6383
  node._hiveLane = lane;
6270
6384
  node._hiveTitle.textContent = title;
6271
- setAttr(node, "aria-label", translate("card.openAria") + " " + title);
6272
- setAttr(node, "title", title);
6385
+ setAttr(node, "aria-label", translate("card.openAria") + " " + fullTitle);
6386
+ setAttr(node, "title", fullTitle);
6273
6387
  return node;
6274
6388
  }
6275
6389
  function renderStageChips(model) {