Files
devclaw-gitea/lib/tools/queue-status.ts
Lauren ten Hoor 32eb079521 feat: add TypeScript support and shared types
- Added TypeScript configuration file (tsconfig.json) with strict settings.
- Introduced devDependencies for TypeScript in package.json.
- Added scripts for type checking and watching for changes.
- Created a new types file (lib/types.ts) defining shared types for the DevClaw plugin.
2026-02-09 14:27:13 +08:00

108 lines
3.5 KiB
TypeScript

/**
* queue_status — Show task queue and worker status across projects.
*
* Replaces manual GitLab scanning in HEARTBEAT.md.
*/
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 { listIssuesByLabel, resolveRepoPath, type StateLabel } from "../gitlab.js";
import { log as auditLog } from "../audit.js";
export function createQueueStatusTool(api: OpenClawPluginApi) {
return (ctx: ToolContext) => ({
name: "queue_status",
label: "Queue Status",
description: `Show task queue counts and worker status for all projects (or a specific project). Returns To Improve, To Test, To Do issue counts and active DEV/QA session state.`,
parameters: {
type: "object",
properties: {
projectGroupId: {
type: "string",
description: "Specific project group ID to check. Omit to check all projects.",
},
},
},
async execute(_id: string, params: Record<string, unknown>) {
const groupId = params.projectGroupId as string | undefined;
const workspaceDir = ctx.workspaceDir;
if (!workspaceDir) {
throw new Error("No workspace directory available in tool context");
}
const data = await readProjects(workspaceDir);
const projectIds = groupId
? [groupId]
: Object.keys(data.projects);
const glabPath = (api.pluginConfig as Record<string, unknown>)?.glabPath as string | undefined;
const projects: Array<Record<string, unknown>> = [];
for (const pid of projectIds) {
const project = getProject(data, pid);
if (!project) continue;
const repoPath = resolveRepoPath(project.repo);
const glabOpts = { glabPath, repoPath };
// Fetch queue counts from GitLab
const queueLabels: StateLabel[] = ["To Improve", "To Test", "To Do"];
const queue: Record<string, Array<{ id: number; title: string }>> = {};
for (const label of queueLabels) {
try {
const issues = await listIssuesByLabel(label, glabOpts);
queue[label] = issues.map((i) => ({ id: i.iid, title: i.title }));
} catch {
queue[label] = [];
}
}
projects.push({
name: project.name,
groupId: pid,
dev: {
active: project.dev.active,
issueId: project.dev.issueId,
model: project.dev.model,
sessions: project.dev.sessions,
},
qa: {
active: project.qa.active,
issueId: project.qa.issueId,
model: project.qa.model,
sessions: project.qa.sessions,
},
queue: {
toImprove: queue["To Improve"],
toTest: queue["To Test"],
toDo: queue["To Do"],
},
});
}
// Audit log
await auditLog(workspaceDir, "queue_status", {
projectCount: projects.length,
totalToImprove: projects.reduce(
(sum, p) => sum + ((p.queue as Record<string, unknown[]>).toImprove?.length ?? 0),
0,
),
totalToTest: projects.reduce(
(sum, p) => sum + ((p.queue as Record<string, unknown[]>).toTest?.length ?? 0),
0,
),
totalToDo: projects.reduce(
(sum, p) => sum + ((p.queue as Record<string, unknown[]>).toDo?.length ?? 0),
0,
),
});
return jsonResult({ projects });
},
});
}