UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

5 lines (4 loc) • 2.34 kB
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } } import{attachJsonlLineReader}from"./chunk-SF4MQDKZ.js";import{inheritedDuplex}from"./chunk-42XRJQM6.js";import{Socket}from"node:net";var MCP_PRESENTER_BOOTSTRAP_FD=4,PRESENTER_EXCHANGE_MS=3e4,PRESENTER_PARKING_MS=18e4;function presenterBootstrapStream(fd){if(fd===MCP_PRESENTER_BOOTSTRAP_FD)return inheritedDuplex(fd)}function relayPresenterBootstrap(upstream,child,launch){let downstream=child.stdio[MCP_PRESENTER_BOOTSTRAP_FD];return downstream instanceof Socket?new Promise(resolve=>{let ended=!1,acknowledging,parked=!0,finish=()=>{ended||(ended=!0,clearTimeout(timer),unreadUp(),unreadDown(),upstream.destroy(),downstream.destroy(),resolve(acknowledging??"closed"))},timer=setTimeout(finish,PRESENTER_PARKING_MS),unreadUp=attachJsonlLineReader(upstream,line=>{if(parked&&(parked=!1,clearTimeout(timer),timer=setTimeout(finish,PRESENTER_EXCHANGE_MS)),launch)try{let record=JSON.parse(line);if(typeof record=="object"&&record!==null&&"type"in record&&record.type==="enroll"&&"version"in record&&record.version===2&&(!("launchKind"in record)||record.launchKind!==launch.kind||launch.predecessorHostInstance===void 0||!("predecessorHostInstance"in record)||record.predecessorHostInstance!==launch.predecessorHostInstance))return finish()}catch{return finish()}downstream.write(`${line} `)||finish()},{maxLineLength:16*1024,onOversizedLine:finish}),unreadDown=attachJsonlLineReader(downstream,line=>{try{let record=JSON.parse(line);acknowledging=typeof record=="object"&&record!==null&&"type"in record&&(record.type==="enrolled"||record.type==="unavailable")?record.type:void 0,upstream.write(`${line} `,()=>{acknowledging&&finish()})}catch{finish()}},{maxLineLength:16*1024,onOversizedLine:finish});upstream.once("error",finish),downstream.once("error",finish),upstream.once("end",finish),downstream.once("end",()=>{acknowledging||finish()}),child.once("exit",finish)}):(upstream.destroy(),Promise.resolve("closed"))}export{MCP_PRESENTER_BOOTSTRAP_FD,PRESENTER_EXCHANGE_MS,PRESENTER_PARKING_MS,presenterBootstrapStream,relayPresenterBootstrap};