- Introduced a new heartbeat service that runs at defined intervals to perform health checks on workers and fill available task slots based on priority. - Added a health tool to scan worker health across projects with optional auto-fix capabilities. - Updated the status tool to provide a lightweight overview of worker states and queue counts without health checks. - Enhanced task creation tool descriptions to clarify task state handling. - Implemented tests for the work heartbeat logic, ensuring proper project resolution, worker state management, and task prioritization.
92 lines
3.6 KiB
TypeScript
92 lines
3.6 KiB
TypeScript
/**
|
|
* status — Lightweight queue + worker state dashboard.
|
|
*
|
|
* Shows worker state and queue counts per project. No health checks
|
|
* (use `health` tool), no complex sequencing.
|
|
* Context-aware: auto-filters to project in group chats.
|
|
*/
|
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
import { jsonResult } from "openclaw/plugin-sdk";
|
|
import type { ToolContext } from "../types.js";
|
|
import { readProjects, getProject } from "../projects.js";
|
|
import { generateGuardrails } from "../context-guard.js";
|
|
import { log as auditLog } from "../audit.js";
|
|
import { fetchProjectQueues, type QueueLabel } from "../services/queue.js";
|
|
import { requireWorkspaceDir, resolveContext, getPluginConfig } from "../tool-helpers.js";
|
|
|
|
export function createStatusTool(api: OpenClawPluginApi) {
|
|
return (ctx: ToolContext) => ({
|
|
name: "status",
|
|
label: "Status",
|
|
description: `Show task queue and worker state per project. Context-aware: auto-filters in group chats. Use \`health\` tool for worker health checks.`,
|
|
parameters: {
|
|
type: "object",
|
|
properties: {
|
|
projectGroupId: { type: "string", description: "Filter to specific project. Omit for all." },
|
|
},
|
|
},
|
|
|
|
async execute(_id: string, params: Record<string, unknown>) {
|
|
const workspaceDir = requireWorkspaceDir(ctx);
|
|
|
|
const context = await resolveContext(ctx, api);
|
|
if (context.type === "via-agent") {
|
|
return jsonResult({
|
|
success: false,
|
|
warning: "status is for operational use, not setup.",
|
|
recommendation: "Use onboard instead for DevClaw setup.",
|
|
contextGuidance: generateGuardrails(context),
|
|
});
|
|
}
|
|
|
|
// Auto-filter in group context
|
|
let groupId = params.projectGroupId as string | undefined;
|
|
if (context.type === "group" && !groupId) groupId = context.groupId;
|
|
|
|
const pluginConfig = getPluginConfig(api);
|
|
const projectExecution = (pluginConfig?.projectExecution as string) ?? "parallel";
|
|
|
|
const data = await readProjects(workspaceDir);
|
|
const projectIds = groupId ? [groupId] : Object.keys(data.projects);
|
|
|
|
// Build project summaries with queue counts
|
|
const projects = await Promise.all(
|
|
projectIds.map(async (pid) => {
|
|
const project = getProject(data, pid);
|
|
if (!project) return null;
|
|
|
|
const queues = await fetchProjectQueues(project);
|
|
const count = (label: QueueLabel) => queues[label].length;
|
|
|
|
return {
|
|
name: project.name,
|
|
groupId: pid,
|
|
roleExecution: project.roleExecution ?? "parallel",
|
|
dev: { active: project.dev.active, issueId: project.dev.issueId, tier: project.dev.tier, startTime: project.dev.startTime },
|
|
qa: { active: project.qa.active, issueId: project.qa.issueId, tier: project.qa.tier, startTime: project.qa.startTime },
|
|
queue: { toImprove: count("To Improve"), toTest: count("To Test"), toDo: count("To Do") },
|
|
};
|
|
}),
|
|
);
|
|
|
|
const filtered = projects.filter(Boolean);
|
|
|
|
await auditLog(workspaceDir, "status", {
|
|
projectCount: filtered.length,
|
|
totalQueued: filtered.reduce((s, p) => s + p!.queue.toImprove + p!.queue.toTest + p!.queue.toDo, 0),
|
|
});
|
|
|
|
return jsonResult({
|
|
success: true,
|
|
execution: { projectExecution },
|
|
projects: filtered,
|
|
context: {
|
|
type: context.type,
|
|
...(context.type === "group" && { projectName: context.projectName, autoFiltered: !params.projectGroupId }),
|
|
},
|
|
contextGuidance: generateGuardrails(context),
|
|
});
|
|
},
|
|
});
|
|
}
|