const API_PORT = parseInt(process.env.CONTROLPLANE_PORT ?? '3100', 10); const API_HOST = process.env.CONTROLPLANE_BIND_HOST ?? '127.0.0.1'; const description = process.argv[2]; if (!description) { console.error('Usage: agent-task.ts '); process.exit(1); } async function main(): Promise { try { const res = await fetch( `http://${API_HOST}:${API_PORT}/api/controlplane/tasks`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: description, description }), }, ); if (!res.ok) { console.error(`API error ${res.status}: ${await res.text()}`); process.exit(1); } const data = (await res.json()) as Record; const task = data.task as Record | undefined; if (task?.id) { console.log(`Task created: ${task.id}`); console.log(` Title: ${description}`); } else { console.log('Task created (no id returned)'); } } catch (err) { const msg = err instanceof Error ? err.message : String(err); if (msg.includes('ECONNREFUSED')) { console.error( 'Controlplane API not reachable at', `${API_HOST}:${API_PORT}`, ); } else { console.error('Error:', msg); } process.exit(1); } } main();