MCPcopy
hub / github.com/claude-code-best/claude-code / usePipeIpc

Function usePipeIpc

src/hooks/usePipeIpc.ts:446–620  ·  view source on GitHub ↗
({
  store,
  handleIncomingPrompt,
}: UsePipeIpcOptions)

Source from the content-addressed store, hash-verified

444// ---------------------------------------------------------------------------
445
446export function usePipeIpc({
447 store,
448 handleIncomingPrompt,
449}: UsePipeIpcOptions): void {
450 if (!feature('UDS_INBOX')) return
451
452 useEffect(() => {
453 const sessionId = _getSessionId()
454 if (!sessionId) return
455 const pipeName = `cli-${sessionId.slice(0, 8)}`
456 const disposed = { current: false }
457 let heartbeatTimer: ReturnType<typeof setInterval> | null = null
458 let heartbeatBusy = false
459 let pipeServer: PipeServer | null = null
460
461 void (async () => {
462 try {
463 // --- Phase 1: Role determination ---
464 const machId = await pr.getMachineId()
465 const mac = pr.getMacAddress()
466 const localIp = pt.getLocalIp()
467 const host = osm.hostname()
468 const roleResult = await pr.determineRole(machId)
469
470 const entry = {
471 id: pipeName,
472 pid: process.pid,
473 machineId: machId,
474 startedAt: Date.now(),
475 ip: localIp,
476 mac,
477 hostname: host,
478 pipeName,
479 }
480
481 let initialRole: 'main' | 'sub' = 'main'
482 let subIndex: number | null = null
483 let displayRole = 'main'
484
485 if (roleResult.role === 'main' || roleResult.role === 'main-recover') {
486 await pr.registerAsMain(entry)
487 } else {
488 subIndex = roleResult.subIndex
489 await pr.registerAsSub(entry, subIndex)
490 initialRole = 'sub'
491 displayRole = `sub-${subIndex}`
492 }
493
494 // --- Phase 2: Server creation ---
495 const server = await pt.createPipeServer(
496 pipeName,
497 feature('LAN_PIPES') ? { enableTcp: true, tcpPort: 0 } : undefined,
498 )
499 pipeServer = server
500 if (disposed.current) {
501 await server.close()
502 await pr.unregister(pipeName)
503 return

Callers 1

REPLFunction · 0.85

Calls 13

startMethod · 0.95
stopMethod · 0.95
registerMessageHandlersFunction · 0.85
runMainHeartbeatFunction · 0.85
runSubHeartbeatFunction · 0.85
removeDeadSlaveFunction · 0.85
nowMethod · 0.80
setStateMethod · 0.80
getStateMethod · 0.80
entriesMethod · 0.80
closeMethod · 0.65
sendMethod · 0.65

Tested by

no test coverage detected