clawdie-ai/scripts/agent-task-status.ts
Mevy Assistant 9fea739140 Finish controlplane naming propagation sweep
---
Build: pass | Tests: pass — 122 passed (7 files)
2026-04-24 16:03:47 +02:00

81 lines
2.4 KiB
TypeScript

import { CONTROLPLANE_INTERNAL_DOMAIN } from '../src/config.js';
const API_PORT = parseInt(process.env.CONTROLPLANE_PORT ?? '3100', 10);
const API_HOST = process.env.CONTROLPLANE_BIND_HOST ?? '127.0.0.1';
const taskId = process.argv[2];
async function main(): Promise<void> {
try {
const secret = process.env.CONTROLPLANE_SHARED_SECRET;
if (!secret) {
console.error('Missing CONTROLPLANE_SHARED_SECRET in environment');
process.exit(1);
}
const res = await fetch(
`http://${API_HOST}:${API_PORT}/api/controlplane/tasks`,
{
headers: {
Authorization: `Bearer ${secret}`,
},
},
);
if (!res.ok) {
console.error(`API error ${res.status}: ${await res.text()}`);
process.exit(1);
}
const data = (await res.json()) as Record<string, unknown>;
const tasks = (data.tasks as Array<Record<string, unknown>>) ?? [];
if (!taskId) {
const sorted = [...tasks].sort((a, b) => {
const da = new Date(String(a.created_at ?? 0)).getTime();
const db = new Date(String(b.created_at ?? 0)).getTime();
return db - da;
});
const max = 20;
console.log(`Recent tasks (${Math.min(sorted.length, max)}/${sorted.length}):`);
for (const t of sorted.slice(0, max)) {
console.log(
`- ${t.task_id ?? 'N/A'} [${t.status ?? 'N/A'}] (${t.assigned_to ?? 'unassigned'}) ${t.title ?? ''}`,
);
}
return;
}
const task = tasks.find((t) => t.task_id === taskId);
if (!task) {
console.log(`Task not found: ${taskId}`);
process.exit(1);
}
console.log(`Task: ${task.task_id}`);
console.log(` Title: ${task.title ?? 'N/A'}`);
console.log(` Status: ${task.status ?? 'N/A'}`);
console.log(` Assigned: ${task.assigned_to ?? 'unassigned'}`);
console.log(` Priority: ${task.priority ?? 'N/A'}`);
if (task.deadline) console.log(` Deadline: ${task.deadline}`);
const context = task.context as Record<string, unknown> | null | undefined;
if (context?.output) {
console.log(' Output:');
console.log(String(context.output));
}
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
if (msg.includes('ECONNREFUSED')) {
console.error(
`${CONTROLPLANE_INTERNAL_DOMAIN} controlplane API not reachable`,
);
} else {
console.error('Error:', msg);
}
process.exit(1);
}
}
main();