← 返回 Skills 市场
maverick-software

Background Job Toasts

作者 maverick-software · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
259
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install bg-job-toasts
功能描述
Background job toast notification system for the OpenClaw Control UI. Bottom-right corner toast bar that shows running/complete/error status for all backgrou...
使用说明 (SKILL.md)

Background Job Toasts — OpenClaw Control UI

Real-time bottom-right toast bar that shows running / complete / error status for all background processes in the OpenClaw Control UI: cron jobs, memory compaction, knowledge extraction, and any consumer that pushes to backgroundJobToasts.

Status: ✅ Active

Component Status
Toast bar (bottom-right) ✅ Working
Cron job name enrichment (gateway) ✅ Working
Context gauge spinner during compaction ✅ Working
Compaction modal phase labels + progress bar ✅ Working
Auto-dismiss after completion ✅ Working

Architecture

Data Type (ui/src/ui/app-view-state.ts)

export type BackgroundJobToast = {
  jobId: string;        // Unique identifier (use "cmp-" prefix for compaction)
  jobName: string;      // Human-readable label shown in the toast
  status: "running" | "complete" | "error";
  startedAt: number;    // Date.now()
  completedAt: number | null;
  errorMsg?: string;
};

backgroundJobToasts: BackgroundJobToast[] is a LitElement @state() property on OpenClawApp (app.ts). Assigning to it directly triggers an automatic re-render — no requestUpdate() needed for the toast array itself.

Toast Rendering (ui/src/ui/app-render.ts)

renderBackgroundJobToasts(state) renders the .bg-job-toasts container at the bottom of the app shell (called in the root render() function). It maps each toast to a .bg-job-toast--{status} div with an icon, name, and label.

Status indicators:

  • running → spinner icon (CSS animation compaction-spin), blue tint, "running..."
  • complete → checkmark icon, green tint, "done"
  • error → X icon, red tint, "failed"

Styles (ui/src/styles/components.css)

.bg-job-toasts   { position: fixed; bottom: 24px; right: 24px; z-index: 9000; … }
.bg-job-toast    { border-radius: var(--radius-lg); background: var(--panel-strong); … }
.bg-job-toast--running  { color: var(--info); … }
.bg-job-toast--complete { color: var(--ok); … }
.bg-job-toast--error    { color: var(--danger); … }

Entry animation: bg-job-toast-in (0.2s, slide up from 6px).

Gateway Cron Event Enrichment (src/gateway/server-cron.ts)

The gateway's onEvent callback enriches cron events with the job name before broadcasting, so the UI can display a meaningful label even when the Cron tab hasn't been opened yet (and thus cronJobs isn't loaded):

onEvent: (evt) => {
  const jobForName = cron.getJob(evt.jobId);
  const enriched = jobForName?.name ? { ...evt, name: jobForName.name } : evt;
  params.broadcast("cron", enriched, { dropIfSlow: true });
  // ... rest of webhook handling
}

UI Cron Event Handler (ui/src/ui/app-gateway.ts)

const cronPayload = evt.payload as {
  jobId?: string;
  name?: string;       // ← enriched by gateway
  action?: string;
  status?: string;
  error?: string;
};
// Priority: event.name > loaded cronJobs list > fallback
const jobName = cronPayload.name ?? matchedJob?.name ?? "Background job";

Context Gauge + Compaction Button (ui/src/ui/app-render.helpers.ts)

The renderContextGauge(state) function renders a circular SVG ring in the chat toolbar. When compaction is running:

  • The gauge ring is replaced by a spinning icon
  • A compactState.phase overlay modal appears with live status

Phase variables must be defined before the template:

const phaseLabel =
  compactState.phase === "running"
    ? "Summarizing your conversation…"
    : compactState.phase === "complete"
      ? "Done! Context has been reduced."
      : compactState.phase === "error"
        ? "Something went wrong."
        : "";
const isWorking = compactState.phase === "running";

compactState is read from (state as unknown as Record\x3Cstring, unknown>).__compactState — a plain property (not @state()), so app.requestUpdate() must be called explicitly after mutations.

Compaction flow:

  1. Button click → __compactState = { active: true, phase: "running" } + push "running" toast → requestUpdate()
  2. RPC sessions.compact resolves → update toast to "complete" with token counts → __compactState = {}requestUpdate()
  3. Auto-dismiss toast after 5 seconds

Files Modified

File Change
src/gateway/server-cron.ts Enrich cron event with name before broadcasting
ui/src/ui/app-gateway.ts Read cronPayload.name first in job name resolution
ui/src/ui/app-render.helpers.ts Define phaseLabel/isWorking; spinner on gauge button while running

How to Push a Custom Toast from Anywhere

Any code with access to the OpenClawApp instance can push a toast:

const app = state as unknown as OpenClawApp;
const jobId = "my-job-" + Date.now();

// Start
app.backgroundJobToasts = [
  ...(app.backgroundJobToasts ?? []).filter(t => t.jobId !== jobId),
  { jobId, jobName: "My Task", status: "running", startedAt: Date.now(), completedAt: null },
];

// Complete (with auto-dismiss)
app.backgroundJobToasts = [
  ...(app.backgroundJobToasts ?? []).filter(t => t.jobId !== jobId),
  { jobId, jobName: "My Task done", status: "complete", startedAt: Date.now(), completedAt: Date.now() },
];
window.setTimeout(() => {
  app.backgroundJobToasts = (app.backgroundJobToasts ?? []).filter(t => t.jobId !== jobId);
}, 5000);

Prefix convention: Use "cmp-" for compaction jobs (filtered when a new compaction starts). Use a unique domain prefix for other job types.

Known Gotchas

  • phaseLabel/isWorking must be defined before the template literal — referencing them without defining them compiles fine (TypeScript doesn't catch undeclared variables inside template literals) but renders as undefined at runtime, producing a blank modal with no text and no progress bar.
  • __compactState is not @state() — always call app.requestUpdate() after mutating it, or the UI won't re-render.
  • Cron job name fallback order matters — the name field in the event payload (gateway-enriched) must be checked before the local cronJobs list, because the list is only loaded when the Cron tab is open.
  • backgroundJobToasts IS @state() — assigning the array triggers a re-render automatically; no requestUpdate() needed specifically for that.

Reference

See references/source-snapshot.md for a snapshot of the key code sections at time of writing.

安全使用建议
This skill appears coherent and limited to modifying the OpenClaw UI and the gateway event enrichment. Before installing: (1) verify the skill's source/repository since no homepage or owner info is provided; (2) review and test the gateway enrichment to ensure cron event payloads are authenticated and cannot be spoofed; (3) ensure any jobName values displayed in toasts are properly escaped/sanitized to avoid UI injection/XSS from untrusted event data; and (4) note that applying these instructions will change application/gateway code — perform code review and deploy in a staging environment first.
功能分析
Type: OpenClaw Skill Name: bg-job-toasts Version: 1.0.0 The skill bundle implements a UI notification system (toasts) for background processes in the OpenClaw interface. It includes standard TypeScript/LitElement code for rendering, CSS for styling, and minor server-side logic in 'src/gateway/server-cron.ts' to enrich event data with human-readable names. No malicious patterns, data exfiltration, or prompt injection risks were detected.
能力评估
Purpose & Capability
Name/description match the content: all required behavior is UI-facing (toasts, compaction spinner, gateway cron enrichment). The skill does not request unrelated binaries, cloud credentials, or system access.
Instruction Scope
SKILL.md only describes in-app UI changes and gateway event enrichment, reads/writes application state, and calls existing RPCs (e.g., sessions.compact). It does not instruct reading system files, environment secrets, or sending data to external endpoints outside the app's broadcast mechanism.
Install Mechanism
No install spec and no code files to execute; this is instruction-only, meaning nothing is written to disk or downloaded by the skill itself.
Credentials
No environment variables, credentials, or config paths are required. The declared needs are proportional to an in-app UI feature.
Persistence & Privilege
always:false and model invocation defaults are unchanged. The skill does not request permanent/privileged presence or modify other skills' configs.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install bg-job-toasts
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /bg-job-toasts 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release: bottom-right toast bar, cron job name enrichment, compaction button live progress
元数据
Slug bg-job-toasts
版本 1.0.0
许可证
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Background Job Toasts 是什么?

Background job toast notification system for the OpenClaw Control UI. Bottom-right corner toast bar that shows running/complete/error status for all backgrou... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 259 次。

如何安装 Background Job Toasts?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install bg-job-toasts」即可一键安装,无需额外配置。

Background Job Toasts 是免费的吗?

是的,Background Job Toasts 完全免费(开源免费),可自由下载、安装和使用。

Background Job Toasts 支持哪些平台?

Background Job Toasts 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Background Job Toasts?

由 maverick-software(@maverick-software)开发并维护,当前版本 v1.0.0。

💬 留言讨论