Lines 1-21javascript
2import{spawn as re}from"node:child_process";import{closeSync as ie,existsSync as oe,mkdirSync as ae,openSync as ce,readFileSync as de,rmSync as ue,writeFileSync as le}from"node:fs";import{dirname as he,resolve as gt}from"node:path";import{fileURLToPath as pe}from"node:url";import{randomUUID as $}from"node:crypto";var M="0.1.0";function R(){return new Date().toISOString()}function d(s){return s!==null&&typeof s=="object"&&!Array.isArray(s)}function o(s){return String(s??"").trim()}function g(s,t){let e=Number.parseInt(String(s??""),10);return Number.isFinite(e)?e:t}function k(s){return Array.is ...
3`):""}var C=class{constructor(t){this.agent=t,this.sessionCounter=0}async sessionNew(){return this.sessionCounter+=1,{sessionId:`echo-${this.agent.agentId}-${this.sessionCounter}`}}async sessionPrompt(t,e){let n=P(t.prompt);return e({sessionId:t.sessionId,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:n?`Echo runtime received: ${n}`:"Echo runtime received an empty prompt."}}}),{stopReason:"end_turn"}}async sessionCancel(){return{ok:!0}}};import{spawn as yt}from"node:child_process";var N="2.0",Tt=3e4;function St(s){return{code:Number.isInteger(s?.code)?s.code:-32e3,messag ...
5`);if(e<0)return;let r=this.headerBuffer.subarray(0,e).toString("utf8").match(/content-length:\s*(\d+)/i);if(!r){h("warn","runtime.protocol","missing Content-Length header",{target:this.label}),this.headerBuffer=Buffer.
8`;this.child.stdin.write(r,e)}onNotification(t,e){let n=this.notificationHandlers.get(t)||new Set;return n.add(e),this.notificationHandlers.set(t,n),()=>{n.delete(e),n.size===0&&this.notificationHandlers.delete(t)}}onRequest(t,e){return this.requestHandlers.set(t,e),()=>this.requestHandlers.delete(t)}onExit(t){return this.exitHandlers.add(t),()=>this.exitHandlers.delete(t)}rejectAll(t){for(let e of this.pending.values())clearTimeout(e.timer),e.reject(t);this.pending.clear()}handleExit(t,e){this.rejectAll(new Error(`runtime exited before response (${t}/${e})`));for(let n of this.exitHandlers)n( ...
9`,_,T,r,e);let b=qt(u);b&&!T.emittedTexts.has(b)&&(T.emittedTexts.add(b),e({sessionId:r,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:b}}}));let A=I.trim();A&&h("debug","runtime.cli","runtime stderr",{target:this.agent.targetCode,sessionId:r,stderr:A}),h(
10`}}})}}}async sessionCancel(t){let e=o(t.sessionId),n=this.active.get(e);return n?(h("info","runtime.cli","cancelling runtime child",{target:this.agent.targetCode,sessionId:e,pid:n.pid}),H(n,"SIGTERM"),this.active.delete(e),{ok:!0,cancelled:!0}):{ok:!0,cancelled:!1}}stop(t="stop"){for(let[e,n]of this.active.entries())h("info","runtime.cli","stopping runtime child",{target:this.agent.targetCode,sessionId:e,pid:n.pid,reason:t}),H(n,"SIGTERM");this.active.clear()}};function Gt(s,t,e){let n=d(s?._meta)?s._meta:{};return{...d(s)?s:{},sessionId:t,update:d(s?.update)?s.update:{},_meta:{...n,orchaAgen ...
11`)}];return this.prompt({...t,agentId:n,sessionId:a,prompt:u},e)}async requestPermission({agent:t,runtimeSessionId:e,request:n,emitUpdate:r}){let i=$(),c=this.runtimeSessionIndex.get(`${t.agentId}:${e}`)?.sessionId||e||$(),u={permissionId:i,agentId:t.agentId,sessionId:c,runtimeSessionId:e,request:d(n)?n:{},status:"pending",createdAt:R()};return
12`).replaceAll("\\r","\r").replaceAll("\\t"," ").replaceAll('\\"','"').replaceAll("\\\\","\\")}function se(s){let t=!1,e=!1;for(let n=0;n<s.length;n+=1){let r=s[n],i=s[n-1];if(r==="'"&&!e)t=!t;else if(r==='"'&&!t&&i!=="\\")e=!e;else if(r==="#"&&!t&&!e&&/\s/.test(i||""))return s.slice(0,n)}return s}import{createServer as ne}from"node:http";function J(s,t,e){let n=JSON.stringify(e);s.writeHead(t,{"content-type":"application/json; charset=utf-8","content-length":Buffer.byteLength(n)}),s.end(n)}function y(s={}){return{ok:!0,...s}}function W(s,t,e){return{ok:!1,error:{code:s,message:t,...e===void 0? ...
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
bin/orcha-runtime-bridge.jsView on unpkg · L1 HighCommand Output Exfiltration
Source combines command execution, command-output handling, and outbound requests; review data flow before blocking.
bin/orcha-runtime-bridge.jsView on unpkg · L1 13`),console.log(JSON.stringify({status:"started",pid:r.pid,pidFile:s,logFile:t}))}async function pt({quiet:s=!1}={}){let t=Q(),e=Z(t);if(!e){s||console.log(JSON.stringify({status:"not_running",pidFile:t}));return}
16 run, foreground Run in the foreground. This is the default.
17 start Start in the background and write a pid file.
18 reload, restart Stop the background process and start it again.
19 stop Stop the background process.
20 status Print background process status as JSON.
Long lines were clipped for display.