()
| 666 | * Stop the UDS messaging server and clean up the socket file. |
| 667 | */ |
| 668 | export async function stopUdsMessaging(): Promise<void> { |
| 669 | defaultSocketPath = null |
| 670 | if (!server) return |
| 671 | |
| 672 | // Close all connected clients |
| 673 | for (const socket of clients) { |
| 674 | socket.destroy() |
| 675 | } |
| 676 | clients.clear() |
| 677 | |
| 678 | await new Promise<void>(resolve => { |
| 679 | server!.close(() => resolve()) |
| 680 | }) |
| 681 | server = null |
| 682 | inbox.length = 0 |
| 683 | inboxBytes = 0 |
| 684 | onEnqueueCb = null |
| 685 | |
| 686 | // Remove socket file (skip on Windows — pipe paths aren't files) |
| 687 | if (socketPath) { |
| 688 | await removeSocketPath(socketPath) |
| 689 | delete process.env.CLAUDE_CODE_MESSAGING_SOCKET |
| 690 | logForDebugging( |
| 691 | `[udsMessaging] server stopped, socket removed: ${socketPath}`, |
| 692 | ) |
| 693 | socketPath = null |
| 694 | authToken = null |
| 695 | } |
| 696 | if (capabilityFilePath) { |
| 697 | try { |
| 698 | await unlink(capabilityFilePath) |
| 699 | } catch { |
| 700 | // Already gone |
| 701 | } |
| 702 | capabilityFilePath = null |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Send a UDS message to a specific socket path (outbound — used when this |
no test coverage detected