feat: Implement daemon support for piping LLM output to stdout or clipboard via an extended socket protocol and update project documentation.
This commit is contained in:
@@ -20,13 +20,29 @@ public static class ToggleCommand
|
||||
var endPoint = new UnixDomainSocketEndPoint(socketPath);
|
||||
await socket.ConnectAsync(endPoint);
|
||||
|
||||
// Send TOGGLE (cmd == 4)
|
||||
await socket.SendAsync(new byte[] { 4 }, SocketFlags.None);
|
||||
// Send TOGGLE (cmd == 4), pipeToStdout, copyToClipboard
|
||||
var msg = new byte[] { 4, (byte)(pipeToStdout ? 1 : 0), (byte)(copyToClipboard ? 1 : 0) };
|
||||
await socket.SendAsync(msg, SocketFlags.None);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Console.WriteLine("Sent TOGGLE command to daemon.");
|
||||
}
|
||||
|
||||
// Wait for response text if pipeToStdout or if it takes a while we just wait until the socket closes
|
||||
// This is required so the client process stays alive to receive the text through stdout
|
||||
var responseBuffer = new byte[4096];
|
||||
while (true)
|
||||
{
|
||||
int received = await socket.ReceiveAsync(responseBuffer, SocketFlags.None);
|
||||
if (received == 0) break; // socket closed by daemon
|
||||
|
||||
if (pipeToStdout)
|
||||
{
|
||||
var text = System.Text.Encoding.UTF8.GetString(responseBuffer, 0, received);
|
||||
Console.Write(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user