- Add required Authorization header (CONTROLPLANE_SHARED_SECRET) - Support selecting assigned role via `just agent-task "..." db-admin` - Update agent-task-status to understand `task_id` and list recent tasks - Update harness handoff Phase 7e example --- Build: pass | Tests: pass — 103 files, 1680 tests
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
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 API not reachable');
|
|
} else {
|
|
console.error('Error:', msg);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|