@rulemetric/cli 0.12.6 → 0.12.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-EVD5A3VI.js +1 -0
- package/dist/chunk-VMJH4DNA.js +14 -0
- package/dist/commands/evals/agent.js +1 -1
- package/dist/lib/agent-loop.js +1 -1
- package/dist/lib/gateway-entry.js +1 -1
- package/dist/lib/gateway.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
- package/dist/chunk-47YDQYTD.js +0 -14
- package/dist/chunk-ONRQDI3N.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as X}from"./chunk-2KJAM2NG.js";import{b as Y}from"./chunk-IEQDLURA.js";import{d as z,e as Z}from"./chunk-UUFCTEBT.js";import{a as V}from"./chunk-ZYGBABMZ.js";import{a as $}from"./chunk-5OX6YKTR.js";import{a as C}from"./chunk-MJ5H7RDK.js";import{a as L}from"./chunk-W67DO5PT.js";import{a as N}from"./chunk-WO6MS654.js";import{a as F}from"./chunk-UTAETY5Z.js";import{b as x}from"./chunk-E4RGYYBC.js";import{a as B}from"./chunk-O65AQZYB.js";import{a as O}from"./chunk-ARC4Q3GL.js";import{b as D}from"./chunk-5RBLIVBF.js";import{a as G}from"./chunk-GRPUY2EZ.js";import{a as P}from"./chunk-UXB6DRR7.js";import{a as q}from"./chunk-INSKP5ED.js";import{a as J}from"./chunk-UA5GEVGW.js";import{a as R}from"./chunk-PZS55PW2.js";import{a as Q}from"./chunk-AKXGUQ5B.js";import{e as H}from"./chunk-Z4YVOVMM.js";import{b as W}from"./chunk-NKJTNGXR.js";import{a as K}from"./chunk-C6GLNE6X.js";import{a as U}from"./chunk-S2SKT5PV.js";import{l as M}from"./chunk-FUYR7CFD.js";import{d as T}from"./chunk-NF2BIEAF.js";import{b as S,e as A,f as k}from"./chunk-UGACB66X.js";import{a as s}from"./chunk-ZLLER3HP.js";var y=null,b=null,oe={process_eval:L,process_insights:N,process_launch:x,process_send_message:V,process_conversation:C,process_session_goal:$,distill_memories:W,memory_ab:B,process_run_cleanup:O,cron_refine_cases:q,cron_retire_unused_skills:Q,cron_reconcile_attribution:P,cron_suggest_instructions:H,cron_refresh_skills:R,cron_refresh_pricing:J,cron_eval_autorun:U,cron_auto_accept_suggestions:K,cron_instruction_training:G,cron_instruction_evolution:M,process_judge_review:F},j=Object.keys(oe),ae=new Set([]);function ie(e=process.env){return e.DATABASE_URL?j:j.filter(n=>!ae.has(n))}s(ie,"availableCapabilities");var le=3e4,ce=3e4,de=3e4,ee=500,ne=1e4,ue=`thin-agent-${process.pid}`,E=null;function me(e,n,r,c){let i;try{let l=T();i={claude:l.claudeBin!=null,codex:l.codexBin!=null,codexModel:l.codexConfiguredModel}}catch{}let g=s(l=>k("/api/workers/heartbeat",{workerType:"cli-worker",clientName:ue,clientVersion:c,workerVersion:"0.1.0",currentJobId:null,inFlightCount:0,lastError:null,status:l,metadata:{capabilities:e,mode:"thin-agent",llmEngines:i,machine:y?.summary()}}).then(u=>{let d=u?.advisory;d&&d.message!==E?(E=d.message,a(r,{event:"worker_advisory",code:d.code,message:d.message})):d||(E=null)}).catch(u=>{a(r,{event:"presence_heartbeat_error",error:u instanceof Error?u.message:String(u)})}),"send");g("alive");let f=setInterval(()=>g("alive"),de),o=null,m=s(()=>o||(clearInterval(f),o=Promise.race([g("shutting_down"),new Promise(l=>setTimeout(l,2e3).unref())]),o),"sayGoodbye");return n.addEventListener("abort",()=>{m()},{once:!0}),{shutdown:m}}s(me,"startPresenceHeartbeat");function a(e,n){try{e(JSON.stringify({ts:new Date().toISOString(),...n}))}catch{e(`[agent-loop] log_error event=${n.event}`)}}s(a,"structuredLog");function re(e,n){return n.aborted?Promise.resolve(!1):e<=0?Promise.resolve(!0):new Promise(r=>{let c=setTimeout(()=>{n.removeEventListener("abort",i),r(!0)},e),i=s(()=>{clearTimeout(c),n.removeEventListener("abort",i),r(!1)},"onAbort");n.addEventListener("abort",i,{once:!0})})}s(re,"abortableSleep");async function ge(e,n){let r=`capabilities=${encodeURIComponent(e.join(","))}&waitMs=${n}`,c=await A(`/api/work/next?${r}`);return c==null||typeof c=="string"?null:c}s(ge,"pollForWork");function pe(e,n){return{logger:{info:s(r=>n(r),"info"),warn:s(r=>n(r),"warn"),error:s(r=>n(r),"error")},job:{attempts:e}}}s(pe,"makeHelpers");async function _e(e,n,r){let c=oe[e.kind],i=Date.now();if(a(r,{event:"claim",jobId:e.id,kind:e.kind,attempts:e.attempts}),!c){let o=`unknown kind: ${e.kind}`;a(r,{event:"fail",jobId:e.id,kind:e.kind,terminal:!0,error:o}),await k(`/api/work/${e.id}/fail`,{leaseToken:e.leaseToken,error:o,terminal:!0}).catch(()=>{});return}let g=s(()=>{a(r,{event:"heartbeat",jobId:e.id}),k(`/api/work/${e.id}/heartbeat`,{leaseToken:e.leaseToken}).catch(o=>{a(r,{event:"heartbeat_error",jobId:e.id,error:o instanceof Error?o.message:String(o)})})},"beat"),f=setInterval(g,n);b={jobId:e.id,beat:g};try{let o=pe(e.attempts,r),m=await c(e.payload,o)??{};clearInterval(f),a(r,{event:"complete",jobId:e.id,kind:e.kind,durationMs:Date.now()-i}),await k(`/api/work/${e.id}/complete`,{leaseToken:e.leaseToken,result:m})}catch(o){clearInterval(f);let m=D(o),l=Z(y?.pausesSince(i)??[]),u=o instanceof Error?o.message:String(o),d=l?`${l}; ${u}`:u;a(r,{event:"fail",jobId:e.id,kind:e.kind,durationMs:Date.now()-i,terminal:m,error:d,...l?{pausedDuringJob:!0}:{}}),await k(`/api/work/${e.id}/fail`,{leaseToken:e.leaseToken,error:d,terminal:m}).catch(p=>{a(r,{event:"fail_post_error",jobId:e.id,error:p instanceof Error?p.message:String(p)})})}finally{b=null}}s(_e,"runOne");var te=new Set(["process_eval","process_conversation","process_insights","process_session_goal","distill_memories","memory_ab","cron_suggest_instructions","cron_eval_autorun","cron_instruction_evolution","process_judge_review"]);async function Je(e){let n=e.log??(()=>{}),r=e.pollWaitMs??le,c=e.heartbeatIntervalMs??ce,i=e.capabilities??ie();a(n,{event:"agent_start",capabilities:i,pollWaitMs:r,heartbeatIntervalMs:c});try{let t=Y();t.removed.length>0&&a(n,{event:"eval_worktrees_swept",removed:t.removed.length})}catch(t){a(n,{event:"eval_worktree_sweep_failed",error:t instanceof Error?t.message:String(t)})}y=z({signal:e.signal,onPause:s(t=>{a(n,{event:"machine_pause",...t,jobId:b?.jobId??null}),b?.beat()},"onPause")});let g=me(i,e.signal,n,e.version);X({signal:e.signal,log:n}).catch(t=>{a(n,{event:"tt_heartbeat_fatal",error:t instanceof Error?t.message:String(t)})});let f=5*6e4,o=0,m=s(()=>{if(!e.readInstalledVersion||!e.version)return!1;let t=Date.now();if(t-o<f)return!1;o=t;let w=e.readInstalledVersion();return!!(w&&w!==e.version)},"versionDrifted"),l=new AbortController,u=l.signal;e.signal.aborted?l.abort():e.signal.addEventListener("abort",()=>l.abort(),{once:!0});let d=s(async(t,w)=>{let _=ee;for(;!u.aborted;){if(m()){a(n,{event:"agent_version_drift",bootVersion:e.version,installedVersion:e.readInstalledVersion?.()??null}),l.abort(),e.onVersionDrift?.();break}let I=null;try{I=await ge([...w],r)}catch(v){let se=v instanceof S?v.statusCode:void 0;if(a(n,{event:"poll_error",lane:t,status:se,error:v instanceof Error?v.message:String(v)}),!await re(_,u))break;_=Math.min(_*2,ne);continue}if(!I){if(a(n,{event:"poll_204",lane:t}),!await re(_,u))break;_=Math.min(_*2,ne);continue}_=ee,await _e(I,c,n)}},"runLane"),p=i.filter(t=>te.has(t)),h=i.filter(t=>!te.has(t));p.length>0&&h.length>0?(a(n,{event:"agent_lanes",heavy:p.length,fast:h.length}),await Promise.all([d("heavy",p),d("fast",h)])):await d("single",i),await g.shutdown(),a(n,{event:"agent_stop"})}s(Je,"runAgentLoop");export{oe as a,j as b,ie as c,ge as d,Je as e};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{c as $}from"./chunk-VUGRXM7R.js";import{e as I}from"./chunk-QWCEZEDO.js";import{a as R,b as v}from"./chunk-KKDHD4XA.js";import{a as c}from"./chunk-ZLLER3HP.js";import{spawn as O}from"node:child_process";import*as T from"node:fs";import*as m from"node:http";import*as g from"node:net";import*as y from"node:os";import*as E from"node:path";var S=8788,N=3e3,B=500,H=6e4,P=E.join(y.homedir(),".config","rulemetric","proxy-addon.version"),D=E.join(y.homedir(),".config","rulemetric","proxy.pid"),l=!1;var _=null,b=0,C="unknown",h=null;function i(e){let t=new Date().toISOString();console.log(`[${t}] ${e}`)}c(i,"log");function Y(){try{return T.readFileSync(P,"utf-8").trim()||null}catch{return null}}c(Y,"readAddonVersion");function x(e,t){if(e==="unknown"||!t)return;let r=Y();if(!r||r==="unknown"||r===_)return;if(_=r,r===e){i(`addon version matches gateway (${e})`);return}let o=Date.now()-b;if(o<H){i(`addon version drift (gateway=${e}, addon=${r}); restart cooldown active (${Math.round((H-o)/1e3)}s left)`);return}i(`addon version drift detected (gateway=${e}, addon=${r}). Restarting proxy to pick up latest code.`),b=Date.now(),M(t)}c(x,"maybeRestartOnDrift");function M(e){if(!e)return i("cannot restart proxy: no CLI entry recorded (RULEMETRIC_CLI_ENTRY unset)"),!1;try{return O(process.execPath,[e,"proxy","restart"],{detached:!0,stdio:"ignore"}).unref(),!0}catch(t){return i(`restart spawn failed: ${t.message}`),!1}}c(M,"spawnProxyRestart");function U(){try{let e=T.readFileSync(D,"utf-8").trim();return/^\d+$/.test(e)}catch{return!1}}c(U,"proxyCrashEvidence");function L(e){let t=g.connect({port:e,timeout:B});t.on("connect",()=>{t.destroy(),l||(l=!0,i(`mitmproxy up on :${e}, routing through proxy`)),h?.onHealthCheck(!0)}),t.on("error",()=>{l&&(l=!1,i(`mitmproxy down on :${e}, routing direct`)),h?.onHealthCheck(!1)}),t.on("timeout",()=>{t.destroy(),l&&(l=!1,i(`mitmproxy timeout on :${e}, routing direct`)),h?.onHealthCheck(!1)})}c(L,"checkProxyHealth");function V(e,t,r,o){let[a,s]=(e.url??"").split(":"),u=parseInt(s,10)||443;if(l){let n=g.connect({port:o,host:"127.0.0.1"});n.on("connect",()=>{n.write(`CONNECT ${e.url} HTTP/1.1\r
|
|
2
|
+
Host: ${e.url}\r
|
|
3
|
+
\r
|
|
4
|
+
`)});let d=Buffer.alloc(0),p=!1,w=c(f=>{d=Buffer.concat([d,f]),d.toString().includes(`\r
|
|
5
|
+
\r
|
|
6
|
+
`)&&(n.removeListener("data",w),p=!0,t.write(`HTTP/1.1 200 Connection Established\r
|
|
7
|
+
\r
|
|
8
|
+
`),r.length>0&&n.write(r),t.pipe(n),n.pipe(t))},"onData");n.on("data",w),n.on("error",f=>{if(p){i(`proxy socket error for ${e.url} after tunnel established: ${f.message}, closing client`),t.destroy();return}i(`proxy socket error for ${e.url}: ${f.message}, falling back to direct`),A(e,t,r,a,u)}),t.on("error",()=>{n.destroy()})}else A(e,t,r,a,u)}c(V,"handleConnect");function A(e,t,r,o,a){let s=g.connect({port:a,host:o}),u=!1;s.on("connect",()=>{u=!0,t.write(`HTTP/1.1 200 Connection Established\r
|
|
9
|
+
\r
|
|
10
|
+
`),r.length>0&&s.write(r),t.pipe(s),s.pipe(t)}),s.on("error",n=>{if(i(`upstream error for ${e.url}: ${n.message}`),u){t.destroy();return}t.end(`HTTP/1.1 502 Bad Gateway\r
|
|
11
|
+
\r
|
|
12
|
+
`)}),t.on("error",()=>{s.destroy()})}c(A,"connectDirect");function G(e,t,r){if(e.url===R){t.writeHead(200,{"content-type":"application/json"}),t.end(JSON.stringify({service:v,version:C,pid:process.pid,mitmproxyAlive:l}));return}let o=e.url??"",a;try{a=new URL(o)}catch{t.writeHead(400),t.end("Bad Request");return}let s={hostname:l?"127.0.0.1":a.hostname,port:l?r:parseInt(a.port,10)||80,path:l?o:a.pathname+a.search,method:e.method,headers:e.headers},u=m.request(s,n=>{t.writeHead(n.statusCode??502,n.headers),n.pipe(t)});u.on("error",n=>{i(`HTTP proxy error for ${o}: ${n.message}`),t.writeHead(502),t.end("Bad Gateway")}),e.pipe(u)}c(G,"handleRequest");function X(e=I,t=S,r={}){let o=r.cliVersion??process.env.RULEMETRIC_CLI_VERSION??"unknown",a=r.cliEntry??process.env.RULEMETRIC_CLI_ENTRY??null;C=o,h=new $({hasCrashEvidence:U,respawn:c(()=>M(a),"respawn"),log:i});let s=m.createServer((n,d)=>{G(n,d,t)});s.on("connect",(n,d,p)=>{V(n,d,p,t)}),s.on("clientError",(n,d)=>{d.writable&&d.end(`HTTP/1.1 400 Bad Request\r
|
|
13
|
+
\r
|
|
14
|
+
`)});let u=setInterval(()=>{L(t),x(o,a)},N);return L(t),x(o,a),s.listen(e,"127.0.0.1",()=>{i(`gateway listening on 127.0.0.1:${e} (mitmproxy target: :${t}, cli version: ${o})`)}),{server:s,healthInterval:u}}c(X,"startGateway");export{S as a,X as b};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as C,b as L,c as D}from"../../chunk-GWDZNGUP.js";import{c as d}from"../../chunk-LUCVMLHV.js";import{e as I}from"../../chunk-
|
|
1
|
+
import{a as C,b as L,c as D}from"../../chunk-GWDZNGUP.js";import{c as d}from"../../chunk-LUCVMLHV.js";import{e as I}from"../../chunk-EVD5A3VI.js";import"../../chunk-2KJAM2NG.js";import"../../chunk-IEQDLURA.js";import"../../chunk-UUFCTEBT.js";import"../../chunk-ZYGBABMZ.js";import"../../chunk-5OX6YKTR.js";import"../../chunk-MJ5H7RDK.js";import"../../chunk-W67DO5PT.js";import"../../chunk-WO6MS654.js";import"../../chunk-UTAETY5Z.js";import"../../chunk-E4RGYYBC.js";import"../../chunk-O65AQZYB.js";import"../../chunk-ARC4Q3GL.js";import"../../chunk-RFISMWRW.js";import"../../chunk-5RBLIVBF.js";import"../../chunk-GRPUY2EZ.js";import"../../chunk-UXB6DRR7.js";import"../../chunk-INSKP5ED.js";import"../../chunk-UA5GEVGW.js";import"../../chunk-PZS55PW2.js";import"../../chunk-AKXGUQ5B.js";import"../../chunk-3ZHVP3KE.js";import"../../chunk-Z4YVOVMM.js";import"../../chunk-HOQPVOMF.js";import"../../chunk-NKJTNGXR.js";import"../../chunk-C6GLNE6X.js";import"../../chunk-S2SKT5PV.js";import"../../chunk-HQCPGDQE.js";import"../../chunk-3UKZJAFS.js";import"../../chunk-FE2UWAIP.js";import"../../chunk-SJKS3PYX.js";import"../../chunk-XFAFMYIP.js";import"../../chunk-5PM4E27L.js";import"../../chunk-GIRPEMTW.js";import"../../chunk-SIGZEQ3K.js";import"../../chunk-RLEMDKQ4.js";import"../../chunk-PVPYLKB3.js";import"../../chunk-22ZDUL6H.js";import"../../chunk-CPDMJGTC.js";import"../../chunk-E7XOYGL5.js";import"../../chunk-WCIX5KWG.js";import"../../chunk-LJRE3LZ2.js";import"../../chunk-UKOI2Q4J.js";import"../../chunk-5N5S3NKS.js";import"../../chunk-KJRMGTAO.js";import"../../chunk-MILLBGCB.js";import"../../chunk-6UEFCMR2.js";import"../../chunk-MODXEGCU.js";import"../../chunk-RBSEE2Z6.js";import"../../chunk-AFYZYXQ3.js";import"../../chunk-FUYR7CFD.js";import"../../chunk-M7QSC64D.js";import"../../chunk-DPCAPIQB.js";import"../../chunk-G7V4ZZZ3.js";import"../../chunk-W23MESHM.js";import"../../chunk-LB24UKHZ.js";import"../../chunk-PWTTCSQA.js";import"../../chunk-NF2BIEAF.js";import"../../chunk-OZQNSELV.js";import"../../chunk-HFGO5762.js";import"../../chunk-VS5ROGDP.js";import"../../chunk-WTMJSL7R.js";import"../../chunk-GN3ZHQ46.js";import"../../chunk-U2NT5OSQ.js";import"../../chunk-KGURGIZ2.js";import"../../chunk-UPFH72PF.js";import"../../chunk-BJSVATVJ.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-RIVEBBZC.js";import"../../chunk-QBNLZJIR.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-VBXL7XO7.js";import"../../chunk-TZA4HAVF.js";import{b as k,f as h,h as A}from"../../chunk-QXPYGN7I.js";import{a as O}from"../../chunk-DSJNZWCZ.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-OOFGV7EX.js";import"../../chunk-VYZKKSX4.js";import"../../chunk-YSLKV4XC.js";import"../../chunk-3AV3GTMP.js";import{f as b}from"../../chunk-UGACB66X.js";import"../../chunk-WMIUFMDI.js";import{e as P,l as f}from"../../chunk-PZNWH4VQ.js";import{a as e}from"../../chunk-ZLLER3HP.js";import{trace as se,context as ie}from"@opentelemetry/api";import{NodeSDK as j}from"@opentelemetry/sdk-node";import{OTLPTraceExporter as q}from"@opentelemetry/exporter-trace-otlp-http";import{BatchSpanProcessor as F,ConsoleSpanExporter as U,SimpleSpanProcessor as X}from"@opentelemetry/sdk-trace-node";import{Resource as B}from"@opentelemetry/resources";import{ATTR_SERVICE_NAME as H,ATTR_SERVICE_VERSION as K}from"@opentelemetry/semantic-conventions";function $(t){if(!t)return{};let r={};for(let n of t.split(",")){let s=n.indexOf("=");if(s===-1)continue;let i=n.slice(0,s).trim(),a=n.slice(s+1).trim();i&&(r[i]=a)}return r}e($,"parseOtlpHeaders");var p=null;function y(){return process.env.TELEMETRY_ENABLED!=="false"}e(y,"isTelemetryEnabled");function S(t){if(!y()||p!==null)return"off";let r=new B({[H]:t.serviceName,[K]:t.serviceVersion??"0.1.0"}),n=process.env.OTEL_EXPORTER_OTLP_ENDPOINT,s,i;if(n){let a=$(process.env.OTEL_EXPORTER_OTLP_HEADERS),l=new q({url:`${n}/v1/traces`,headers:a});i=new F(l),s="otlp"}else if(process.env.OTEL_SPAN_EXPORT==="none")i=void 0,s="silent";else{let a=new U;i=new X(a),s="console"}return p=new j({resource:r,spanProcessors:i?[i]:[]}),p.start(),s}e(S,"initTelemetry");async function m(){p&&(await p.shutdown(),p=null)}e(m,"shutdownTelemetry");import{SpanKind as he,SpanStatusCode as ye}from"@opentelemetry/api";import{trace as ve,context as we}from"@opentelemetry/api";import*as u from"@sentry/node";var E=!1;function T(t){if(E)return!1;let r=process.env.SENTRY_DSN;return r?(u.init({dsn:r,serverName:t.serviceName,environment:process.env.NODE_ENV??"development",tracesSampleRate:0}),E=!0,!0):!1}e(T,"initSentry");async function g(t){E&&await u.flush(t)}e(g,"flushSentry");import{existsSync as J,mkdirSync as W,readFileSync as R,unlinkSync as V,writeFileSync as M}from"node:fs";import{dirname as z,join as v}from"node:path";import{execFileSync as Q}from"node:child_process";var c=v(f(),"evals-agent.lock");function Z(t){try{return process.kill(t,0),!0}catch(r){return r.code==="EPERM"}}e(Z,"pidAlive");function ee(t){if(!Z(t))return!1;try{let r=Q("ps",["-p",String(t),"-o","command="],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]});return/run\.js\s+evals\s+agent|evals\s+agent/.test(r)}catch{return!0}}e(ee,"isLiveAgent");function te(){try{W(z(c),{recursive:!0})}catch{}for(let t=0;t<2;t++)try{return M(c,String(process.pid),{flag:"wx"}),{ok:!0}}catch(r){if(r.code!=="EEXIST")throw r;let n=0;try{n=Number(R(c,"utf-8").trim())}catch{}if(n&&n!==process.pid&&ee(n))return{ok:!1,holder:n};try{V(c)}catch{}}try{M(c,String(process.pid))}catch{}return{ok:!0}}e(te,"acquireAgentLock");function x(){try{J(c)&&Number(R(c,"utf-8").trim())===process.pid&&V(c)}catch{}}e(x,"releaseAgentLock");var w=class t extends O{static{e(this,"EvalAgentCommand")}static description="The worker daemon: long-polls /api/work/next, claims jobs, and runs them locally. Installed as a launchd service by `rulemetric service install`.";static examples=["<%= config.bin %> evals agent"];async run(){await this.parse(t),this.requireAuth();let r=te();if(!r.ok){this.log(`Another rulemetric evals agent is already running (pid ${r.holder}). Refusing to start a second instance.`);return}process.env.PG_APPLICATION_NAME||="rulemetric-agent",T({serviceName:"rulemetric-agent"})&&this.log("[sentry] error capture enabled");let s=S({serviceName:"rulemetric-agent"});s==="otlp"?this.log(`[otel] traces exporting to ${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}`):s==="console"?this.log("[otel] cron spans printing to stdout (set OTEL_EXPORTER_OTLP_ENDPOINT to ship to a backend)"):this.log("[otel] disabled (TELEMETRY_ENABLED=false)"),!P()&&!process.env.RULEMETRIC_API_KEY&&this.error("No auth token found. Run `rulemetric auth login` first."),this.log("Starting thin agent (Phase 4b parallel-run)..."),this.log(`Long-polling /api/work/next. Press Ctrl+C to stop.
|
|
2
2
|
`);let a=new AbortController,l=await k({configDir:f()});if(this.log(`[transcript-sync] Codex capture: ${h(l)}`),l.error)this.log(`[transcript-sync] WARNING: ${l.error}`);else if(l.mode==="allowlist")for(let o of l.roots)this.log(`[transcript-sync] \u2022 ${o}`);let G=new C({providers:[L(void 0,void 0,A({configDir:f(),onChange:e(o=>this.log(`[transcript-sync] Codex capture changed: ${h(o)}`),"onChange")}))],statePath:v(f(),"transcript-sync-state.json"),importTranscript:e(o=>b("/api/sessions/import",o),"importTranscript"),log:e(o=>this.log(`[transcript-sync] ${o}`),"log")});D(G,{signal:a.signal,log:e(o=>this.log(`[transcript-sync] ${o}`),"log")});let N=e(async o=>{this.log(`
|
|
3
3
|
[${o}] shutting down agent...`),a.abort(),await Promise.allSettled([g(2e3),m(),d()]),x(),process.exit(0)},"shutdown");process.on("SIGINT",()=>{N("SIGINT")}),process.on("SIGTERM",()=>{N("SIGTERM")});let _=!1;try{await I({signal:a.signal,log:e(o=>this.log(o),"log"),version:this.config.version,readInstalledVersion:e(()=>{try{return JSON.parse(R(v(this.config.root,"package.json"),"utf-8")).version??null}catch{return null}},"readInstalledVersion"),onVersionDrift:e(()=>{_=!0},"onVersionDrift")}),_&&(this.log("[upgrade] Installed CLI version changed \u2014 restarting worker onto the new code."),await Promise.allSettled([g(2e3),m(),d()]),x(),process.exit(1))}finally{x(),await d()}}};export{w as default};
|
package/dist/lib/agent-loop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e}from"../chunk-
|
|
1
|
+
import{a,b,c,d,e}from"../chunk-EVD5A3VI.js";import"../chunk-2KJAM2NG.js";import"../chunk-IEQDLURA.js";import"../chunk-UUFCTEBT.js";import"../chunk-ZYGBABMZ.js";import"../chunk-5OX6YKTR.js";import"../chunk-MJ5H7RDK.js";import"../chunk-W67DO5PT.js";import"../chunk-WO6MS654.js";import"../chunk-UTAETY5Z.js";import"../chunk-E4RGYYBC.js";import"../chunk-O65AQZYB.js";import"../chunk-ARC4Q3GL.js";import"../chunk-RFISMWRW.js";import"../chunk-5RBLIVBF.js";import"../chunk-GRPUY2EZ.js";import"../chunk-UXB6DRR7.js";import"../chunk-INSKP5ED.js";import"../chunk-UA5GEVGW.js";import"../chunk-PZS55PW2.js";import"../chunk-AKXGUQ5B.js";import"../chunk-3ZHVP3KE.js";import"../chunk-Z4YVOVMM.js";import"../chunk-HOQPVOMF.js";import"../chunk-NKJTNGXR.js";import"../chunk-C6GLNE6X.js";import"../chunk-S2SKT5PV.js";import"../chunk-HQCPGDQE.js";import"../chunk-3UKZJAFS.js";import"../chunk-FE2UWAIP.js";import"../chunk-SJKS3PYX.js";import"../chunk-XFAFMYIP.js";import"../chunk-5PM4E27L.js";import"../chunk-GIRPEMTW.js";import"../chunk-SIGZEQ3K.js";import"../chunk-RLEMDKQ4.js";import"../chunk-PVPYLKB3.js";import"../chunk-22ZDUL6H.js";import"../chunk-CPDMJGTC.js";import"../chunk-E7XOYGL5.js";import"../chunk-WCIX5KWG.js";import"../chunk-LJRE3LZ2.js";import"../chunk-UKOI2Q4J.js";import"../chunk-5N5S3NKS.js";import"../chunk-KJRMGTAO.js";import"../chunk-MILLBGCB.js";import"../chunk-6UEFCMR2.js";import"../chunk-MODXEGCU.js";import"../chunk-RBSEE2Z6.js";import"../chunk-AFYZYXQ3.js";import"../chunk-FUYR7CFD.js";import"../chunk-M7QSC64D.js";import"../chunk-DPCAPIQB.js";import"../chunk-G7V4ZZZ3.js";import"../chunk-W23MESHM.js";import"../chunk-LB24UKHZ.js";import"../chunk-PWTTCSQA.js";import"../chunk-NF2BIEAF.js";import"../chunk-OZQNSELV.js";import"../chunk-HFGO5762.js";import"../chunk-VS5ROGDP.js";import"../chunk-WTMJSL7R.js";import"../chunk-GN3ZHQ46.js";import"../chunk-U2NT5OSQ.js";import"../chunk-KGURGIZ2.js";import"../chunk-UPFH72PF.js";import"../chunk-BJSVATVJ.js";import"../chunk-CDY7TQFZ.js";import"../chunk-RIVEBBZC.js";import"../chunk-QBNLZJIR.js";import"../chunk-N7ODX6PO.js";import"../chunk-PJ3WHQ67.js";import"../chunk-VBXL7XO7.js";import"../chunk-TZA4HAVF.js";import"../chunk-UGACB66X.js";import"../chunk-WMIUFMDI.js";import"../chunk-PZNWH4VQ.js";import"../chunk-ZLLER3HP.js";export{b as CAPABILITIES,a as HANDLERS,c as availableCapabilities,d as pollForWork,e as runAgentLoop};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as p,b as c}from"../chunk-
|
|
2
|
+
import{a as p,b as c}from"../chunk-VMJH4DNA.js";import"../chunk-VUGRXM7R.js";import{e,k as a,l as n}from"../chunk-QWCEZEDO.js";import{c as r}from"../chunk-KKDHD4XA.js";import"../chunk-SZ62CP55.js";import{a as o}from"../chunk-ZLLER3HP.js";var{server:l,healthInterval:d}=c(e,p,{cliVersion:process.env.RULEMETRIC_CLI_VERSION,cliEntry:process.env.RULEMETRIC_CLI_ENTRY});function s(i){console.log(`[${new Date().toISOString()}] ${i}`)}o(s,"logLine");l.on("error",i=>{clearInterval(d),i.code!=="EADDRINUSE"&&(s(`gateway listener error: ${i.message}`),process.exit(1)),(async()=>{let t=await r(e);t.status==="ours-live"&&(s(`gateway already live on :${e} (pid ${t.pid??"?"}) \u2014 exiting (idempotent spawn)`),process.exit(0)),t.status==="foreign"&&a()&&n()!==process.pid&&(s(`gateway (pre-identity build, pid ${n()}) already holds :${e} \u2014 exiting (idempotent spawn)`),process.exit(0)),t.status==="dead"&&(s(`:${e} was busy at bind time but is silent now \u2014 exiting; next ensure retries`),process.exit(1)),s(`FOREIGN process holds :${e} \u2014 refusing to start (probe: ${t.detail}). Free the port, then re-run: rulemetric hooks install`),process.exit(1)})()});function g(){console.log(`[${new Date().toISOString()}] gateway shutting down`),clearInterval(d),l.close(()=>{process.exit(0)}),setTimeout(()=>process.exit(0),5e3).unref()}o(g,"shutdown");process.on("SIGTERM",g);process.on("SIGINT",g);
|
package/dist/lib/gateway.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,b as c}from"../chunk-
|
|
1
|
+
import{a as b,b as c}from"../chunk-VMJH4DNA.js";import"../chunk-VUGRXM7R.js";import{e as a}from"../chunk-QWCEZEDO.js";import"../chunk-KKDHD4XA.js";import"../chunk-SZ62CP55.js";import"../chunk-ZLLER3HP.js";export{a as GATEWAY_PORT,b as MITMPROXY_PORT,c as startGateway};
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulemetric/cli",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"postgres": "^3.4.0",
|
|
81
81
|
"react": "^19.0.0",
|
|
82
82
|
"zod": "^3.24.0",
|
|
83
|
-
"@rulemetric/proxy": "0.12.
|
|
84
|
-
"@rulemetric/hooks": "0.12.
|
|
85
|
-
"@rulemetric/skills-registry": "0.12.
|
|
83
|
+
"@rulemetric/proxy": "0.12.8",
|
|
84
|
+
"@rulemetric/hooks": "0.12.8",
|
|
85
|
+
"@rulemetric/skills-registry": "0.12.8"
|
|
86
86
|
},
|
|
87
87
|
"//deps": "Worker (`evals agent`) runtime deps: the @opentelemetry/* set, @sentry/node, and postgres are STATIC top-level imports loaded at worker startup (via bundled @rulemetric/{telemetry,db}) — they MUST be runtime deps or a clean `npm i -g` crashes with ModuleLoadError. `better-sqlite3` is optionalDependencies (below): it's a native module, lazy `require()`'d inside a try/catch (packages/session providers cursor/opencode) so a missing binary degrades gracefully — making it a hard dep would break `npm i -g` on platforms without prebuilt binaries. `resend` stays a devDep: lazy `await import('resend')` guarded by RESEND_API_KEY, which end-user workers never set (provider falls back to noop). Classification verified via import-graph scan of dist/commands/evals/agent.js + per-importer static/lazy check.",
|
|
88
88
|
"optionalDependencies": {
|
|
@@ -102,14 +102,14 @@
|
|
|
102
102
|
"tsx": "^4.19.0",
|
|
103
103
|
"typescript": "^5.9.0",
|
|
104
104
|
"vitest": "^3.2.0",
|
|
105
|
-
"@rulemetric/api": "0.0.1",
|
|
106
105
|
"@rulemetric/core": "0.0.1",
|
|
107
106
|
"@rulemetric/db": "0.0.1",
|
|
108
107
|
"@rulemetric/effectiveness": "0.0.1",
|
|
109
108
|
"@rulemetric/email": "0.0.1",
|
|
110
|
-
"@rulemetric/session": "0.2.1",
|
|
111
109
|
"@rulemetric/telemetry": "0.0.1",
|
|
112
|
-
"@rulemetric/typescript-config": "0.0.0"
|
|
110
|
+
"@rulemetric/typescript-config": "0.0.0",
|
|
111
|
+
"@rulemetric/session": "0.2.1",
|
|
112
|
+
"@rulemetric/api": "0.0.1"
|
|
113
113
|
},
|
|
114
114
|
"scripts": {
|
|
115
115
|
"build": "node scripts/build.mjs",
|
package/dist/chunk-47YDQYTD.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import{c as I}from"./chunk-VUGRXM7R.js";import{e as v}from"./chunk-QWCEZEDO.js";import{a as y,b as R}from"./chunk-KKDHD4XA.js";import{a}from"./chunk-ZLLER3HP.js";import{spawn as O}from"node:child_process";import*as T from"node:fs";import*as h from"node:http";import*as m from"node:net";import*as E from"node:os";import*as w from"node:path";var S=8788,b=3e3,N=500,$=6e4,B=w.join(E.homedir(),".config","rulemetric","proxy-addon.version"),P=w.join(E.homedir(),".config","rulemetric","proxy.pid"),u=!1;var H=null,_=0,C="unknown",f=null;function c(e){let t=new Date().toISOString();console.log(`[${t}] ${e}`)}a(c,"log");function D(){try{return T.readFileSync(B,"utf-8").trim()||null}catch{return null}}a(D,"readAddonVersion");function L(e,t){if(e==="unknown"||!t)return;let n=D();if(!n||n==="unknown"||n===H)return;if(H=n,n===e){c(`addon version matches gateway (${e})`);return}let o=Date.now()-_;if(o<$){c(`addon version drift (gateway=${e}, addon=${n}); restart cooldown active (${Math.round(($-o)/1e3)}s left)`);return}c(`addon version drift detected (gateway=${e}, addon=${n}). Restarting proxy to pick up latest code.`),_=Date.now(),M(t)}a(L,"maybeRestartOnDrift");function M(e){if(!e)return c("cannot restart proxy: no CLI entry recorded (RULEMETRIC_CLI_ENTRY unset)"),!1;try{return O(process.execPath,[e,"proxy","restart"],{detached:!0,stdio:"ignore"}).unref(),!0}catch(t){return c(`restart spawn failed: ${t.message}`),!1}}a(M,"spawnProxyRestart");function Y(){try{let e=T.readFileSync(P,"utf-8").trim();return/^\d+$/.test(e)}catch{return!1}}a(Y,"proxyCrashEvidence");function x(e){let t=m.connect({port:e,timeout:N});t.on("connect",()=>{t.destroy(),u||(u=!0,c(`mitmproxy up on :${e}, routing through proxy`)),f?.onHealthCheck(!0)}),t.on("error",()=>{u&&(u=!1,c(`mitmproxy down on :${e}, routing direct`)),f?.onHealthCheck(!1)}),t.on("timeout",()=>{t.destroy(),u&&(u=!1,c(`mitmproxy timeout on :${e}, routing direct`)),f?.onHealthCheck(!1)})}a(x,"checkProxyHealth");function U(e,t,n,o){let[i,s]=(e.url??"").split(":"),d=parseInt(s,10)||443;if(u){let r=m.connect({port:o,host:"127.0.0.1"});r.on("connect",()=>{r.write(`CONNECT ${e.url} HTTP/1.1\r
|
|
2
|
-
Host: ${e.url}\r
|
|
3
|
-
\r
|
|
4
|
-
`)});let l=Buffer.alloc(0),p=a(g=>{l=Buffer.concat([l,g]),l.toString().includes(`\r
|
|
5
|
-
\r
|
|
6
|
-
`)&&(r.removeListener("data",p),t.write(`HTTP/1.1 200 Connection Established\r
|
|
7
|
-
\r
|
|
8
|
-
`),n.length>0&&r.write(n),t.pipe(r),r.pipe(t))},"onData");r.on("data",p),r.on("error",g=>{c(`proxy socket error for ${e.url}: ${g.message}, falling back to direct`),A(e,t,n,i,d)}),t.on("error",()=>{r.destroy()})}else A(e,t,n,i,d)}a(U,"handleConnect");function A(e,t,n,o,i){let s=m.connect({port:i,host:o});s.on("connect",()=>{t.write(`HTTP/1.1 200 Connection Established\r
|
|
9
|
-
\r
|
|
10
|
-
`),n.length>0&&s.write(n),t.pipe(s),s.pipe(t)}),s.on("error",d=>{c(`upstream error for ${e.url}: ${d.message}`),t.end(`HTTP/1.1 502 Bad Gateway\r
|
|
11
|
-
\r
|
|
12
|
-
`)}),t.on("error",()=>{s.destroy()})}a(A,"connectDirect");function V(e,t,n){if(e.url===y){t.writeHead(200,{"content-type":"application/json"}),t.end(JSON.stringify({service:R,version:C,pid:process.pid,mitmproxyAlive:u}));return}let o=e.url??"",i;try{i=new URL(o)}catch{t.writeHead(400),t.end("Bad Request");return}let s={hostname:u?"127.0.0.1":i.hostname,port:u?n:parseInt(i.port,10)||80,path:u?o:i.pathname+i.search,method:e.method,headers:e.headers},d=h.request(s,r=>{t.writeHead(r.statusCode??502,r.headers),r.pipe(t)});d.on("error",r=>{c(`HTTP proxy error for ${o}: ${r.message}`),t.writeHead(502),t.end("Bad Gateway")}),e.pipe(d)}a(V,"handleRequest");function J(e=v,t=S,n={}){let o=n.cliVersion??process.env.RULEMETRIC_CLI_VERSION??"unknown",i=n.cliEntry??process.env.RULEMETRIC_CLI_ENTRY??null;C=o,f=new I({hasCrashEvidence:Y,respawn:a(()=>M(i),"respawn"),log:c});let s=h.createServer((r,l)=>{V(r,l,t)});s.on("connect",(r,l,p)=>{U(r,l,p,t)}),s.on("clientError",(r,l)=>{l.writable&&l.end(`HTTP/1.1 400 Bad Request\r
|
|
13
|
-
\r
|
|
14
|
-
`)});let d=setInterval(()=>{x(t),L(o,i)},b);return x(t),L(o,i),s.listen(e,"127.0.0.1",()=>{c(`gateway listening on 127.0.0.1:${e} (mitmproxy target: :${t}, cli version: ${o})`)}),{server:s,healthInterval:d}}a(J,"startGateway");export{S as a,J as b};
|
package/dist/chunk-ONRQDI3N.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as X}from"./chunk-2KJAM2NG.js";import{b as Y}from"./chunk-IEQDLURA.js";import{d as z,e as Z}from"./chunk-UUFCTEBT.js";import{a as V}from"./chunk-ZYGBABMZ.js";import{a as $}from"./chunk-5OX6YKTR.js";import{a as C}from"./chunk-MJ5H7RDK.js";import{a as L}from"./chunk-W67DO5PT.js";import{a as N}from"./chunk-WO6MS654.js";import{a as F}from"./chunk-UTAETY5Z.js";import{b as x}from"./chunk-E4RGYYBC.js";import{a as B}from"./chunk-O65AQZYB.js";import{a as O}from"./chunk-ARC4Q3GL.js";import{b as D}from"./chunk-5RBLIVBF.js";import{a as G}from"./chunk-GRPUY2EZ.js";import{a as T}from"./chunk-UXB6DRR7.js";import{a as q}from"./chunk-INSKP5ED.js";import{a as J}from"./chunk-UA5GEVGW.js";import{a as R}from"./chunk-PZS55PW2.js";import{a as Q}from"./chunk-AKXGUQ5B.js";import{e as H}from"./chunk-Z4YVOVMM.js";import{b as W}from"./chunk-NKJTNGXR.js";import{a as K}from"./chunk-C6GLNE6X.js";import{a as U}from"./chunk-S2SKT5PV.js";import{l as P}from"./chunk-FUYR7CFD.js";import{d as M}from"./chunk-NF2BIEAF.js";import{b as S,e as A,f as k}from"./chunk-UGACB66X.js";import{a as s}from"./chunk-ZLLER3HP.js";var y=null,b=null,oe={process_eval:L,process_insights:N,process_launch:x,process_send_message:V,process_conversation:C,process_session_goal:$,distill_memories:W,memory_ab:B,process_run_cleanup:O,cron_refine_cases:q,cron_retire_unused_skills:Q,cron_reconcile_attribution:T,cron_suggest_instructions:H,cron_refresh_skills:R,cron_refresh_pricing:J,cron_eval_autorun:U,cron_auto_accept_suggestions:K,cron_instruction_training:G,cron_instruction_evolution:P,process_judge_review:F},j=Object.keys(oe),ae=new Set([]);function ie(e=process.env){return e.DATABASE_URL?j:j.filter(n=>!ae.has(n))}s(ie,"availableCapabilities");var le=3e4,ce=3e4,de=3e4,ee=500,ne=1e4,ue=`thin-agent-${process.pid}`,E=null;function me(e,n,r,c){let i;try{let t=M();i={claude:t.claudeBin!=null,codex:t.codexBin!=null,codexModel:t.codexConfiguredModel}}catch{}let u=s(t=>k("/api/workers/heartbeat",{workerType:"cli-worker",clientName:ue,clientVersion:c,workerVersion:"0.1.0",currentJobId:null,inFlightCount:0,lastError:null,status:t,metadata:{capabilities:e,mode:"thin-agent",llmEngines:i,machine:y?.summary()}}).then(d=>{let l=d?.advisory;l&&l.message!==E?(E=l.message,a(r,{event:"worker_advisory",code:l.code,message:l.message})):l||(E=null)}).catch(d=>{a(r,{event:"presence_heartbeat_error",error:d instanceof Error?d.message:String(d)})}),"send");u("alive");let p=setInterval(()=>u("alive"),de);return{shutdown:s(async()=>{clearInterval(p),await Promise.race([u("shutting_down"),new Promise(t=>setTimeout(t,2e3).unref())])},"shutdown")}}s(me,"startPresenceHeartbeat");function a(e,n){try{e(JSON.stringify({ts:new Date().toISOString(),...n}))}catch{e(`[agent-loop] log_error event=${n.event}`)}}s(a,"structuredLog");function re(e,n){return n.aborted?Promise.resolve(!1):e<=0?Promise.resolve(!0):new Promise(r=>{let c=setTimeout(()=>{n.removeEventListener("abort",i),r(!0)},e),i=s(()=>{clearTimeout(c),n.removeEventListener("abort",i),r(!1)},"onAbort");n.addEventListener("abort",i,{once:!0})})}s(re,"abortableSleep");async function ge(e,n){let r=`capabilities=${encodeURIComponent(e.join(","))}&waitMs=${n}`,c=await A(`/api/work/next?${r}`);return c==null||typeof c=="string"?null:c}s(ge,"pollForWork");function pe(e,n){return{logger:{info:s(r=>n(r),"info"),warn:s(r=>n(r),"warn"),error:s(r=>n(r),"error")},job:{attempts:e}}}s(pe,"makeHelpers");async function _e(e,n,r){let c=oe[e.kind],i=Date.now();if(a(r,{event:"claim",jobId:e.id,kind:e.kind,attempts:e.attempts}),!c){let t=`unknown kind: ${e.kind}`;a(r,{event:"fail",jobId:e.id,kind:e.kind,terminal:!0,error:t}),await k(`/api/work/${e.id}/fail`,{leaseToken:e.leaseToken,error:t,terminal:!0}).catch(()=>{});return}let u=s(()=>{a(r,{event:"heartbeat",jobId:e.id}),k(`/api/work/${e.id}/heartbeat`,{leaseToken:e.leaseToken}).catch(t=>{a(r,{event:"heartbeat_error",jobId:e.id,error:t instanceof Error?t.message:String(t)})})},"beat"),p=setInterval(u,n);b={jobId:e.id,beat:u};try{let t=pe(e.attempts,r),d=await c(e.payload,t)??{};clearInterval(p),a(r,{event:"complete",jobId:e.id,kind:e.kind,durationMs:Date.now()-i}),await k(`/api/work/${e.id}/complete`,{leaseToken:e.leaseToken,result:d})}catch(t){clearInterval(p);let d=D(t),l=Z(y?.pausesSince(i)??[]),_=t instanceof Error?t.message:String(t),f=l?`${l}; ${_}`:_;a(r,{event:"fail",jobId:e.id,kind:e.kind,durationMs:Date.now()-i,terminal:d,error:f,...l?{pausedDuringJob:!0}:{}}),await k(`/api/work/${e.id}/fail`,{leaseToken:e.leaseToken,error:f,terminal:d}).catch(m=>{a(r,{event:"fail_post_error",jobId:e.id,error:m instanceof Error?m.message:String(m)})})}finally{b=null}}s(_e,"runOne");var te=new Set(["process_eval","process_conversation","process_insights","process_session_goal","distill_memories","memory_ab","cron_suggest_instructions","cron_eval_autorun","cron_instruction_evolution","process_judge_review"]);async function Je(e){let n=e.log??(()=>{}),r=e.pollWaitMs??le,c=e.heartbeatIntervalMs??ce,i=e.capabilities??ie();a(n,{event:"agent_start",capabilities:i,pollWaitMs:r,heartbeatIntervalMs:c});try{let o=Y();o.removed.length>0&&a(n,{event:"eval_worktrees_swept",removed:o.removed.length})}catch(o){a(n,{event:"eval_worktree_sweep_failed",error:o instanceof Error?o.message:String(o)})}y=z({signal:e.signal,onPause:s(o=>{a(n,{event:"machine_pause",...o,jobId:b?.jobId??null}),b?.beat()},"onPause")});let u=me(i,e.signal,n,e.version);X({signal:e.signal,log:n}).catch(o=>{a(n,{event:"tt_heartbeat_fatal",error:o instanceof Error?o.message:String(o)})});let p=5*6e4,t=0,d=s(()=>{if(!e.readInstalledVersion||!e.version)return!1;let o=Date.now();if(o-t<p)return!1;t=o;let w=e.readInstalledVersion();return!!(w&&w!==e.version)},"versionDrifted"),l=new AbortController,_=l.signal;e.signal.aborted?l.abort():e.signal.addEventListener("abort",()=>l.abort(),{once:!0});let f=s(async(o,w)=>{let g=ee;for(;!_.aborted;){if(d()){a(n,{event:"agent_version_drift",bootVersion:e.version,installedVersion:e.readInstalledVersion?.()??null}),l.abort(),e.onVersionDrift?.();break}let I=null;try{I=await ge([...w],r)}catch(v){let se=v instanceof S?v.statusCode:void 0;if(a(n,{event:"poll_error",lane:o,status:se,error:v instanceof Error?v.message:String(v)}),!await re(g,_))break;g=Math.min(g*2,ne);continue}if(!I){if(a(n,{event:"poll_204",lane:o}),!await re(g,_))break;g=Math.min(g*2,ne);continue}g=ee,await _e(I,c,n)}},"runLane"),m=i.filter(o=>te.has(o)),h=i.filter(o=>!te.has(o));m.length>0&&h.length>0?(a(n,{event:"agent_lanes",heavy:m.length,fast:h.length}),await Promise.all([f("heavy",m),f("fast",h)])):await f("single",i),await u.shutdown(),a(n,{event:"agent_stop"})}s(Je,"runAgentLoop");export{oe as a,j as b,ie as c,ge as d,Je as e};
|