From 04f26af44d0d0a3c21ecf397fdaf03221a88777c Mon Sep 17 00:00:00 2001 From: clagentic <10177887+akuehner@users.noreply.github.com> Date: Tue, 9 Jun 2026 13:00:02 -0400 Subject: [PATCH] feat(ipc): add push_message case to daemon IPC switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wire relay-injected turns into live Console sessions via the daemon.sock IPC channel. The relay sends {"cmd":"push_message","sessionId":"", "text":""} to daemon.sock; this case finds the matching session across all projects (by cliSessionId UUID) and calls sdk-bridge pushMessage, which handles mid-turn buffering (lr-b61b). Returns {ok:true} on success or {ok:false,error} on any failure — never throws. (lr-f0ca) Co-Authored-By: Claude Sonnet 4.6 --- lib/daemon.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/daemon.js b/lib/daemon.js index a9c2a088..1972368b 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -1400,6 +1400,43 @@ var ipc = createIPCServer(socketPath(), function (msg) { })(); } + case "push_message": { + // Validate inputs before searching — never crash, always return {ok, error}. + if (!msg.sessionId || typeof msg.sessionId !== "string") { + return { ok: false, error: "missing or invalid sessionId" }; + } + if (!msg.text || typeof msg.text !== "string") { + return { ok: false, error: "missing or invalid text" }; + } + try { + // Search for the session by cliSessionId across all registered projects. + // relay.forEachProject iterates (ctx, slug); ctx.sm.sessions is a Map of + // localId -> session. The relay-agent-claims path sets cliSessionId from + // the SDK session UUID — that is the identifier the relay knows. + var found = null; + relay.forEachProject(function (ctx) { + if (found) return; + ctx.sm.sessions.forEach(function (s) { + if (!found && s.cliSessionId === msg.sessionId) { + found = { ctx: ctx, session: s }; + } + }); + }); + if (!found) { + console.log("[daemon] push_message failed: session not found: " + msg.sessionId); + return { ok: false, error: "session not found: " + msg.sessionId }; + } + // Delegate to sdk-bridge pushMessage — same path as the operator typing in the UI. + // Third arg (images) is null: relay turns are plain text. + found.ctx.sdk.pushMessage(found.session, msg.text, null); + console.log("[daemon] push_message delivered to session " + msg.sessionId); + return { ok: true }; + } catch (e) { + console.log("[daemon] push_message failed: " + e.message); + return { ok: false, error: e.message }; + } + } + default: return { ok: false, error: "unknown command: " + msg.cmd }; }