UNPKG

@code-yeongyu/senpi

Version:

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

3 lines (2 loc) • 3.07 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{listHostEndpoints}from"./chunk-BICMCIHT.js";import{randomBytes}from"node:crypto";var MONITOR_ID_ALPHABET="0123456789ABCDEFGHJKMNPQRSTVWXYZ";function allocateMonitorId(){let id="mon_",buffer=0,bits=0;for(let byte of randomBytes(10))for(buffer=buffer<<8|byte,bits+=8;bits>=5;)bits-=5,id+=MONITOR_ID_ALPHABET[buffer>>bits&31];return id}var sources=[];function registerRpcRemoteSource(source){let entry={source};return sources.push(entry),()=>{let index=sources.indexOf(entry);index!==-1&&sources.splice(index,1)}}function currentRpcRemoteSource(){return sources.at(-1)?.source}var REMOTE_TARGET=/^(?<device>[^/]+)\/(?<session>[^/]+)$/,DRIVE_LETTER=/^[A-Za-z]:$/,STATUS_KINDS=new Set(["session_status","effect_status"]);function parseRpcTarget(target,selfDurableId){let trimmed=target.trim();if(trimmed==="")return{error:'target is empty; pass "children", "all" or a session id, path or st_ task id'};if(trimmed==="children")return selfDurableId===void 0?{error:'target "children" needs a session with a durable id; save the session first, or watch "all"'}:{kind:"children",parent:selfDurableId};if(trimmed==="all")return{kind:"all"};if(trimmed.startsWith("st_"))return{kind:"task",taskId:trimmed};let remote=REMOTE_TARGET.exec(trimmed)?.groups;return remote?.device!==void 0&&remote.session!==void 0&&isRemoteShape(trimmed,remote.device)?currentRpcRemoteSource()===void 0?{error:`target "${trimmed}" names a session on another device; remote targets need the omo remote surface`}:{kind:"remote",device:remote.device,session:remote.session}:{kind:"id",id:trimmed}}function isRemoteShape(target,device){return!target.endsWith(".jsonl")&&!DRIVE_LETTER.test(device)}function defaultEvents(target){return target.kind==="children"?["session_status","effect_status"]:["session_status"]}function subscriptionFor(target,events){let sessions=target.kind==="children"?{childrenOf:target.parent}:target.kind==="id"?{ids:[target.id]}:"all",content=events==="all"?"all":events.filter(kind=>!STATUS_KINDS.has(kind)),mirror=content==="all"?"all":content.length===0?void 0:content;return{sessions,include_workers:!0,include_context:target.kind==="children"||target.kind==="task",effects:events==="all"||events.includes("effect_status"),...mirror===void 0?{}:{mirror}}}function wantsRecord(events,exclude,type){return exclude.includes(type)?!1:events==="all"||events.includes(type)}function matchesTask(target,row){return target.kind!=="task"?!0:row.context?.task_id===target.taskId}async function endpointSockets(agentDir){return(await listHostEndpoints(agentDir)).map(endpoint=>endpoint.socket).filter(socket=>socket!==null)}export{allocateMonitorId,registerRpcRemoteSource,currentRpcRemoteSource,parseRpcTarget,defaultEvents,subscriptionFor,wantsRecord,matchesTask,endpointSockets};