Files
devclaw-gitea/lib/tools/status.ts
Lauren ten Hoor abbf05777c fix: refactor queue.ts to use workflow config instead of hardcoded labels (#162) (#173)
## Problem

lib/services/queue.ts was not updated during workflow refactor (#147) and still
used hardcoded queue labels: QueueLabel type, QUEUE_PRIORITY constant.

## Solution

- Add getQueueLabelsWithPriority() to derive queue labels from workflow config
- Add getQueuePriority() to get priority for any label
- Update getTaskPriority() and getRoleForLabel() to accept workflow config
- Update fetchProjectQueues() to use workflow-derived labels
- Add getTotalQueuedCount() helper

## Files Changed

- lib/services/queue.ts — use workflow config for all queue operations
- lib/tools/status.ts — handle dynamic queue labels, include queueLabels in response

## Backward Compatibility

- QueueLabel type kept as deprecated alias
- QUEUE_PRIORITY kept as deprecated constant
- All functions accept optional workflow parameter, default to DEFAULT_WORKFLOW
2026-02-13 20:46:25 +08:00

105 lines
3.5 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.
*/
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 { log as auditLog } from "../audit.js";
import { fetchProjectQueues, getTotalQueuedCount, getQueueLabelsWithPriority } from "../services/queue.js";
import { requireWorkspaceDir, getPluginConfig } from "../tool-helpers.js";
import { DEFAULT_WORKFLOW } from "../workflow.js";
export function createStatusTool(api: OpenClawPluginApi) {
return (ctx: ToolContext) => ({
name: "status",
label: "Status",
description: `Show task queue and worker state per project. 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 groupId = params.projectGroupId as string | undefined;
const pluginConfig = getPluginConfig(api);
const projectExecution = (pluginConfig?.projectExecution as string) ?? "parallel";
// TODO: Load per-project workflow when supported
const workflow = DEFAULT_WORKFLOW;
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, workflow);
// Build dynamic queue object with counts
const queueCounts: Record<string, number> = {};
for (const [label, issues] of Object.entries(queues)) {
queueCounts[label] = issues.length;
}
return {
name: project.name,
groupId: pid,
roleExecution: project.roleExecution ?? "parallel",
dev: {
active: project.dev.active,
issueId: project.dev.issueId,
level: project.dev.level,
startTime: project.dev.startTime,
},
qa: {
active: project.qa.active,
issueId: project.qa.issueId,
level: project.qa.level,
startTime: project.qa.startTime,
},
queue: queueCounts,
};
}),
);
const filtered = projects.filter(Boolean) as NonNullable<typeof projects[number]>[];
// Calculate total queued across all projects
const totalQueued = filtered.reduce(
(sum, p) => sum + Object.values(p.queue).reduce((s, c) => s + c, 0),
0,
);
await auditLog(workspaceDir, "status", {
projectCount: filtered.length,
totalQueued,
});
// Include queue labels in response for context
const queueLabels = getQueueLabelsWithPriority(workflow).map((q) => ({
label: q.label,
role: q.role,
priority: q.priority,
}));
return jsonResult({
success: true,
execution: { projectExecution },
queueLabels,
projects: filtered,
});
},
});
}