diff --git a/src/cli/commands/startAgent.ts b/src/cli/commands/startAgent.ts index fd1ad9c..0537fee 100644 --- a/src/cli/commands/startAgent.ts +++ b/src/cli/commands/startAgent.ts @@ -38,10 +38,16 @@ export function agentBriefing(agent: string, role: string): string { '2. Deine Aufgabe steht IMMER im Handoff des Tasks. Lies ihn, bevor du baust.', `3. Logge nach jedem Teilschritt: agenthub_task_log(id, text, agent="${agent}").`, '', - 'WÄHREND DER ARBEIT BIST DU TAUB — das ist der wichtigste Punkt:', - 'Solange du einen Task ausführst, erreichen dich KEINE Events. Der einzige', - 'Draht nach außen ist die ANTWORT von agenthub_task_log. Deshalb ist Loggen', - 'keine Höflichkeit, sondern dein Empfang.', + 'DU WIRST GEPUSHT — auch ohne laufenden Tool-Call:', + 'Die AgentHub-Bridge schickt dir MCP-Benachrichtigungen, sobald etwas für', + 'dich anliegt: neue oder zurückgegebene Task, Nachricht, beantwortete Frage,', + 'Abbruch. Diese Meldungen sind VERBINDLICH — reagiere sofort darauf, statt', + 'zu warten. Steht dort ein Abbruch oder eine Rückgabe: aufhören, nicht', + 'einreichen.', + '', + 'ZUSÄTZLICH (Netz, kein Ersatz): die ANTWORT von agenthub_task_log trägt', + 'einen `pending`-Block, wenn etwas offen ist. Loggen bleibt Pflicht — es ist', + 'dein zweiter Empfangsweg und macht deinen Fortschritt sichtbar.', '', ' - Enthält die Antwort `pending.interrupted`, wurde dir der Task', ' zurückgegeben, abgebrochen oder entzogen: SOFORT aufhören, NICHT', diff --git a/src/cli/index.ts b/src/cli/index.ts index b0af1d0..2c155d2 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -838,12 +838,13 @@ export function createProgram(cwd: string): Command { .command('mcp [action]') .description('Start the MCP server (stdio). `agenthub mcp install` writes .mcp.json so MCP-aware agents auto-register.') .option('--print', 'Dry run: print the config instead of writing .mcp.json') - .action(async (action: string | undefined, options: { print?: boolean }) => { + .option('--agent ', 'Bind the MCP push channel to this agent at startup (recommended: the bridge then pushes from the first second, without waiting for a tool call)') + .action(async (action: string | undefined, options: { print?: boolean; agent?: string }) => { if (action === 'install') { installMcp(cwd, { print: options.print }); return; } - await startMcpServer(cwd); + await startMcpServer(cwd, { agent: options.agent }); }); // ─── hello (presence) ────────────────────────────────────────────────────── diff --git a/src/mcp/server.ts b/src/mcp/server.ts index c8d8fa8..bee2bb1 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -198,7 +198,7 @@ export function waitForTask( }); } -export async function startMcpServer(cwd: string): Promise { +export async function startMcpServer(cwd: string, options: { agent?: string } = {}): Promise { const { root, serverUrl } = await resolveMcpContext(cwd); const remote = !!serverUrl; // `logging` MUSS deklariert werden: sendLoggingMessage prueft @@ -213,6 +213,11 @@ export async function startMcpServer(cwd: string): Promise { const bindPush = (agent?: string) => { if (remote && agent) bindPushChannel(server, serverUrl!, agent); }; + // Beim Start binden, wenn der Name bekannt ist (`agenthub mcp --agent codex`). + // Ohne das beginnt der Push erst mit dem ersten Tool-Aufruf — und genau in + // dem Fenster davor ist der Agent wieder taub, also fuer den Zustand, den + // wir beheben wollen. + bindPush(options.agent); server.tool('agenthub_hello', 'Announce yourself to the hub (presence). Run once when you start.', { agent: z.string(), role: z.string().optional() },