ripplo 0.7.34 → 0.7.36

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.
@@ -1,102 +0,0 @@
1
- #!/usr/bin/env node
2
- import{$ as Te,B as te,D as pe,F as fe,U as we,V as be,W as xe,X as Pe,Y as he,Z as Re,_ as Ee,b as V,ba as h,ca as R,da as Ce,e as K,ea as q,fa as Ie,h as P,ha as M,i as ee,ia as We,j as H,ja as Ae,m as _,ma as E,na as Le,oa as De,pa as He,r as re,ra as _e,u as v,w as oe,x as ne}from"./chunk-FV2QLFNK.js";import{$ as ge,E as ae,G as le,H as se,I as ce,J as de,T as ue,Z as me,_ as ye,aa as Se,ba as ke,ca as ve,e as X,h as Y,i as D,l as Z,o as ie}from"./chunk-JZ7VSGAN.js";import{b as qe}from"./chunk-RLXQYG7H.js";import{c as Q,d as g,e as s,f as L,g as G}from"./chunk-5VRJXHWH.js";import"./chunk-IHSHBPJY.js";import"./chunk-7UWDMECF.js";import Mo from"path";import{createClient as Oo}from"graphql-sse";import Fo,{AbortError as $o}from"p-retry";import{graphql as B}from"gql.tada";import{graphql as Wr}from"gql.tada";import{print as Ar}from"graphql";async function Me({config:e,cwd:r,headed:o,pool:n,runId:t,signal:i,testSlug:a,workClass:l,workflowSlug:c}){let u=await P(r);if(u.isErr())return await E(e,t,`lockfile:${u.error.kind}`),{kind:"dispatch-error",reason:{detail:`lockfile:${u.error.kind}`,type:"generic"}};let d=Ir(u.value,{testSlug:a,workflowSlug:c});if(d==null)return await E(e,t,`no-test:${c}/${a}`),{kind:"dispatch-error",reason:{detail:`no-test:${c}/${a}`,type:"generic"}};let p=await h({headed:o,workClass:l,task:()=>n.execute({headed:o,runId:t,testRef:d},i)});return!p.serverNotified&&p.outcome.kind==="error"&&await E(e,t,p.outcome.detail),p.outcome}function Ir(e,{testSlug:r,workflowSlug:o}){let t=e.workflows.find(i=>Z(i.name)===o)?.tests.find(i=>i.slug===r);return t==null?void 0:ie(t)}var Lr=6e4,Dr=Wr(`
3
- subscription RunRequestedWatch($devSessionId: String!) {
4
- runRequested(devSessionId: $devSessionId) {
5
- runId
6
- testSlug
7
- workflowId
8
- workflowSlug
9
- }
10
- }
11
- `);async function Oe(e){let r=Math.min(1e3*2**e,Lr)+qr();await new Promise(o=>setTimeout(o,r))}function Fe({claim:e,cwd:r,devSessionId:o,onSubscriptionDead:n,pool:t,sseClient:i,sseHealth:a}){let l=new Set;return i.subscribe({query:Ar(Dr),variables:{devSessionId:o}},{complete:()=>{},error:c=>{let u=c instanceof Error?c.message:String(c);s.warn("runRequested SSE failed: %s; re-registering session",u),n(u)},next:c=>{Hr({claim:e,cwd:r,event:c.data?.runRequested,inFlightRunIds:l,pool:t})}},{connected:()=>{a.onConnected()},connecting:c=>{a.onConnecting(c),c&&s.debug("runRequested SSE reconnecting")}})}function Hr({claim:e,cwd:r,event:o,inFlightRunIds:n,pool:t}){if(o==null)return;if(n.has(o.runId)){s.warn({runId:o.runId,workflowSlug:o.workflowSlug},"duplicate runRequested event; skipping dispatch");return}n.add(o.runId),process.stdout.write(`ripplo: run ${o.workflowSlug}
12
- `),V(r);let i=v(r).match(l=>l,l=>{s.error({failure:l,runId:o.runId},"failed to load env for run dispatch; skipping")});if(i==null){n.delete(o.runId);return}let a=_r(e(o.runId),o);a.started(),Me({config:i,cwd:r,headed:a.headed,pool:t,runId:o.runId,signal:a.signal,testSlug:o.testSlug,workClass:a.workClass,workflowSlug:o.workflowSlug}).then(l=>{a.finished(l)}).catch(l=>{s.error({err:l,runId:o.runId,workflowSlug:o.workflowSlug},"run execution failed; daemon continuing"),a.finished({detail:l instanceof Error?l.message:String(l),kind:"error"})}).finally(()=>{n.delete(o.runId)})}function _r(e,r){return e==null?(s.debug({runId:r.runId,workflowSlug:r.workflowSlug},"dispatching unclaimed run (externally triggered or replayed)"),{headed:!1,signal:new AbortController().signal,workClass:"p0-ui",finished:()=>{},started:()=>{}}):{headed:e.headed,signal:We(e.token),workClass:"p1-cli",finished:o=>{e.finished(r.runId,o)},started:()=>{e.started(r.runId)}}}function qr(){return Math.floor(Math.random()*2700)+300}import{graphql as O}from"gql.tada";import{print as Mr}from"graphql";var Or=O(`
13
- subscription TeleportRequestedWatch($devSessionId: String!) {
14
- teleportRequested(devSessionId: $devSessionId) {
15
- runId
16
- stepIndex
17
- kind
18
- testSlug
19
- workflowSlug
20
- }
21
- }
22
- `),Fr=O(`
23
- query TeleportRunRepro($id: String!) {
24
- run(id: $id) {
25
- id
26
- reproJson
27
- }
28
- }
29
- `),$r=O(`
30
- mutation ReportTeleportResult($devSessionId: String!, $runId: String!, $status: String!) {
31
- reportTeleportResult(devSessionId: $devSessionId, runId: $runId, status: $status)
32
- }
33
- `);function $e({cwd:e,devSessionId:r,onSubscriptionDead:o,sseClient:n}){let t=new Set,i=n.subscribe({query:Mr(Or),variables:{devSessionId:r}},{complete:()=>{},error:a=>{let l=a instanceof Error?a.message:String(a);s.warn("teleportRequested SSE failed: %s; re-registering session",l),o(l)},next:a=>{Nr({cwd:e,devSessionId:r,event:a.data?.teleportRequested,running:t})}});return()=>{t.forEach(a=>{a.abort()}),t.clear(),i()}}function Nr({cwd:e,devSessionId:r,event:o,running:n}){if(o==null)return;let t=new AbortController;n.add(t),Ur({cwd:e,devSessionId:r,event:o,signal:t.signal}).catch(i=>{s.error({err:i},"teleport failed; daemon continuing")}).finally(()=>{n.delete(t)})}async function Ur({cwd:e,devSessionId:r,event:o,signal:n}){let t=c=>jr({cwd:e,devSessionId:r,runId:o.runId,status:c}),i=await Br(e,o);if(i==null){s.warn({runId:o.runId},"teleport could not resolve target"),await t("unplannable");return}process.stdout.write(`ripplo: teleport ${Jr(o)} step ${String(o.stepIndex+1)}
34
- `);let l=await _e({cwd:e,onReady:()=>{t("opened")},signal:n,step:o.stepIndex+1,target:i});l.kind==="done"&&l.result.kind==="handed-over"||(s.warn({kind:l.kind,runId:o.runId},"teleport could not open"),await t(l.kind==="unplannable"?"unplannable":"error"))}async function jr({cwd:e,devSessionId:r,runId:o,status:n}){let t=v(e).match(i=>i,()=>null);t!=null&&await g({config:t,document:$r,variables:{devSessionId:r,runId:o,status:n}}).catch(()=>null)}async function Br(e,r){if(r.kind==="explore"){let o=await zr(e,r.runId);return o==null?null:{kind:"explore",repro:o}}return r.testSlug==null||r.workflowSlug==null?null:{kind:"test",ref:`${r.workflowSlug}/${r.testSlug}`}}async function zr(e,r){let o=v(e).match(t=>t,()=>null);if(o==null)return null;let n=await g({config:o,document:Fr,variables:{id:r}}).catch(()=>null);return n?.run?.reproJson==null?null:le.parse(JSON.parse(n.run.reproJson))}function Jr(e){return e.kind==="explore"?"explore finding":`${String(e.workflowSlug)}/${String(e.testSlug)}`}function Ne(){let e=!0,r,o=null,n=()=>{o!=null&&(clearTimeout(o),o=null)};return{markUnhealthy:t=>{e=!1,r=t,n()},onConnected:()=>{n(),o=setTimeout(()=>{e=!0,r=void 0,o=null},1e4)},onConnecting:()=>{n()},snapshot:()=>({detail:r,ok:e})}}import Qr from"fs";import ze from"net";import{err as Je,ok as Gr}from"neverthrow";async function Qe({cwd:e,onConnection:r}){G(e);let o=fe(e),n=await Ue({onConnection:r,socketPath:o});return n.isOk()||n.error.kind!=="stale-candidate"?n.map(je(o)).mapErr(Be(o)):await Vr(o)?Je({kind:"already-running",socketPath:o}):(Ge(o),(await Ue({onConnection:r,socketPath:o})).map(je(o)).mapErr(Be(o)))}function Vr(e){return new Promise(r=>{let o=ze.connect(e);o.once("connect",()=>{o.destroy(),r(!0)}),o.once("error",()=>{r(!1)})})}async function Ue(e){let r=await Kr(e);return r.kind==="listening"?Gr(r.server):Je(r.error)}function Kr({onConnection:e,socketPath:r}){return new Promise(o=>{let n=ze.createServer(e);n.once("error",t=>{o({error:t.code==="EADDRINUSE"?{kind:"stale-candidate"}:{kind:"listen-failed",message:t.message},kind:"failed"})}),n.listen(r,()=>{o({kind:"listening",server:n})})})}function je(e){return r=>({socketPath:e,close:()=>{r.close(),Ge(e)}})}function Ge(e){Qr.rmSync(e,{force:!0})}function Be(e){return r=>r.kind==="stale-candidate"?{kind:"already-running",socketPath:e}:{kind:"bind-failed",message:r.message}}import{randomInt as Xr,randomUUID as Yr}from"crypto";function Ye(e){let r={attempts:0,consecutiveErrors:0,findings:0,haltedUntil:0,lockfile:null,prepared:null,preparing:!1,refreshing:!1,scopedAt:0,scopedTests:new Set,scoping:!1,windowAttempts:0,windowFindings:0,windowStartMs:Date.now()},o=F(e,r);return{priority:"p3",next:()=>to(e,r),onResult:()=>{},ready:()=>o,status:()=>({attempts:r.attempts,findings:r.findings}),stop:()=>Promise.resolve()}}var Zr=10;async function F(e,r){if(!r.preparing){r.preparing=!0;try{let o=await e.loadLockfile(),n=o==null?null:await eo(o);if(n==null||o==null)return;r.lockfile=o.lockfile,r.scopedAt=0,r.prepared=n,r.consecutiveErrors=0,r.haltedUntil=0,e.notifyWork()}finally{r.preparing=!1}}}async function eo({lockfile:e}){let r=await ce(e);return r==null?null:{exploration:r,lockfileHashValue:D(e),strategy:ae("even")}}var Ve=20,Ke=3e5;async function ro(e,r){if(!(r.refreshing||r.preparing||r.prepared==null)){r.refreshing=!0;try{let o=await e.loadLockfile();if(o==null||D(o.lockfile)===r.prepared.lockfileHashValue)return;s.info("workflow definitions changed, re-preparing exploration"),r.prepared=null,await F(e,r)}finally{r.refreshing=!1}}}var oo=15e3;async function no(e,r){if(!(r.scoping||r.lockfile==null||Date.now()-r.scopedAt<oo)){r.scoping=!0;try{r.scopedTests=await e.scopedTestRefs(r.lockfile),r.scopedAt=Date.now()}finally{r.scoping=!1}}}function to(e,r){ro(e,r),no(e,r);let o=r.prepared;if(o==null||Date.now()<r.haltedUntil)return null;let n=de({lockfileHash:o.lockfileHashValue,prepared:o.exploration,random:io,scopedTests:r.scopedTests,strategy:{...o.strategy,maxAttemptLength:e.maxTrailLength()}});if(n==null)return null;let t=n.baseStateTest.name;return{id:`explore:${Yr()}`,label:t,run:i=>ao({assign:n,params:e,signal:i,state:r})}}var Xe=2**31;function io(){return Xr(Xe)/Xe}async function ao({assign:e,params:r,signal:o,state:n}){if(!await r.probeApp()){Ze(n,"app-unreachable");return}let t=await r.executeTrail(e,o);if(t.kind==="aborted")return;if(t.kind==="error"){so({params:r,reason:t.reason,state:n});return}n.consecutiveErrors=0,n.attempts+=1,n.windowAttempts+=1;let i=t.kind==="finding";i&&(n.findings+=1,n.windowFindings+=1,s.info("exploration finding recorded")),r.reportProgress({attempts:1,findings:i?1:0,result:t}),n.windowAttempts>=Zr&&lo(n)}function lo(e){let r=Date.now()-e.windowStartMs;s.info({attempts:e.windowAttempts,avgTrailMs:Math.round(r/e.windowAttempts),findings:e.windowFindings,windowMs:r,yield:Number((e.windowFindings/e.windowAttempts).toFixed(3))},"explore window"),e.windowAttempts=0,e.windowFindings=0,e.windowStartMs=Date.now()}function so({params:e,reason:r,state:o}){if(r?.startsWith("lockfile:daemon-load-failed")===!0){co(e,o);return}Ze(o,r)}function co(e,r){r.preparing||(r.prepared=null,F(e,r))}function Ze(e,r){e.consecutiveErrors+=1,s.debug("exploration trail error: %s",r),e.consecutiveErrors>=Ve&&(e.haltedUntil=Date.now()+Ke,e.consecutiveErrors=0,s.warn("exploration cooling down for %ds after %d consecutive trail errors (last: %s)",Ke/1e3,Ve,r))}function uo(e){let{backoffActive:r,exploreEnabled:o,headedActive:n,interactiveActive:t,interactiveQueued:i}=e,{explorationActive:a,exploreConcurrency:l,poolSize:c}=e;if(!o||n||i>0)return{abortCount:a,refillCount:0};if(r)return{abortCount:0,refillCount:0};let u=Math.min(l,c-1,c-t);return{abortCount:0,refillCount:Math.max(0,u-a)}}function or(e){let r={active:new Map,backoffUntil:0,cancelBackoffTimer:null,cancelHeartbeat:null,prevInteractiveActive:e.probe().interactiveActive,stopped:!1};return nr(r,e),{explorationActive:()=>r.active.size,notifyQueueChange:()=>{po(r,e)},stop:()=>{r.stopped=!0,r.cancelBackoffTimer?.(),r.cancelBackoffTimer=null,r.cancelHeartbeat?.(),r.cancelHeartbeat=null,tr(r,r.active.size)}}}function nr(e,r){e.stopped||(e.cancelHeartbeat=r.setTimer(()=>{T(e,r),nr(e,r)},15e3))}function T(e,r){if(e.stopped)return;let o=r.probe(),n=uo({backoffActive:r.now()<e.backoffUntil,explorationActive:e.active.size,exploreConcurrency:r.exploreConcurrency(),exploreEnabled:r.exploreEnabled(),headedActive:o.headedActive>0,interactiveActive:o.interactiveActive,interactiveQueued:o.interactiveQueued,poolSize:o.poolSize});tr(e,n.abortCount),ir({count:n.refillCount,params:r,state:e})}function tr(e,r){[...e.active.values()].slice(0,r).forEach(({controller:o})=>{o.abort()})}function po(e,r){let o=r.probe();o.interactiveActive<e.prevInteractiveActive&&fo(e,r),e.prevInteractiveActive=o.interactiveActive,T(e,r)}function fo(e,r){e.backoffUntil=r.now()+3e4,e.cancelBackoffTimer?.(),e.cancelBackoffTimer=r.setTimer(()=>{e.cancelBackoffTimer=null,T(e,r)},3e4)}function ir({count:e,params:r,state:o}){if(e<=0)return;let n=mo(r.sources);n!=null&&(yo({params:r,pulled:n,state:o}),ir({count:e-1,params:r,state:o}))}function mo(e){return e.reduce((r,o)=>{if(r!=null)return r;let n=o.next();return n==null?null:{job:n,source:o}},null)}function yo({params:e,pulled:r,state:o}){let{job:n,source:t}=r,i=new AbortController;o.active.set(n.id,{controller:i,job:n,source:t}),e.execute({job:n,priority:t.priority,signal:i.signal}).then(()=>{rr({job:n,outcome:er(i.signal,null),params:e,source:t,state:o})}).catch(a=>{rr({job:n,outcome:er(i.signal,{error:a}),params:e,source:t,state:o})})}function er(e,r){return e.aborted?{kind:"aborted"}:r==null?{kind:"completed"}:{error:r.error,kind:"error"}}function rr({job:e,outcome:r,params:o,source:n,state:t}){t.active.delete(e.id),n.onResult(e,r),T(t,o)}function $(e){return{priority:e,next:()=>null,onResult:()=>{}}}var So=12;function ar({config:e,executor:r,pool:o}){return ko({appUrl:e.appUrl,cwd:e.cwd,localExecutor:r==="local",executeTrail:async(n,t)=>(await o).exploreTrail(n,t)})}function ko({appUrl:e,cwd:r,executeTrail:o,localExecutor:n}){let t={concurrency:2,enabled:!1,maxTrailLength:So},i={notify:()=>{}},a={report:d=>{}},l={fetch:d=>Promise.resolve(new Set)},c=vo({appUrl:e,cwd:r,executeTrail:o,maxTrailLength:()=>t.maxTrailLength,notifyWork:()=>{i.notify()},reportProgress:d=>{a.report(d)},scopedTestRefs:d=>l.fetch(d)}),u=or({now:Date.now,probe:wo,setTimer:bo,sources:[$("p0"),$("p1"),c],execute:({job:d,priority:p,signal:S})=>h({headed:!1,workClass:xo(p),task:()=>d.run(S)}),exploreConcurrency:()=>t.concurrency,exploreEnabled:()=>t.enabled});return q(()=>{u.notifyQueueChange()}),i.notify=()=>{u.notifyQueueChange()},{progress:()=>c.status(),setConcurrency:d=>{n&&d!==t.concurrency&&s.info({workers:d},"explore local worker count changed"),t.concurrency=d,u.notifyQueueChange()},setEnabled:d=>{t.enabled=d&&n,u.notifyQueueChange()},setMaxTrailLength:d=>{t.maxTrailLength=d},setReportProgress:d=>{a.report=d},setScopedTestRefs:d=>{l.fetch=d},status:()=>({explorer:t.enabled?"on":"off",exploring:u.explorationActive(),progress:c.status()}),stop:()=>{u.stop(),q(null),c.stop()}}}function vo({appUrl:e,cwd:r,executeTrail:o,maxTrailLength:n,notifyWork:t,reportProgress:i,scopedTestRefs:a}){return Ye({cwd:r,executeTrail:o,maxTrailLength:n,notifyWork:t,reportProgress:i,scopedTestRefs:a,loadLockfile:async()=>{let{fingerprint:l,result:c}=await ee(r);return c.match(u=>({fingerprint:l,lockfile:u}),()=>null)},probeApp:async()=>await te(e)==null})}function wo(){let e=Ce();return{headedActive:e.headedActive,interactiveActive:e.active,interactiveQueued:e.queued,poolSize:e.poolSize}}function bo(e,r){let o=setTimeout(e,r);return()=>{clearTimeout(o)}}function xo(e){switch(e){case"p0":return"p0-ui";case"p1":return"p1-cli";case"p2":return"p2-cover";case"p3":return"p3-explore"}}import{fork as Po}from"child_process";import lr from"os";import{CancellationTokenSource as sr,ResponseError as cr}from"vscode-jsonrpc/node";function dr(e,r){return()=>{let o=Po(e,["run-worker"],{cwd:r,detached:!0,stdio:["ignore","inherit","inherit","ipc"]});return{connection:Te(o),kill:()=>{ho(o)},onExit:n=>{o.once("exit",n)}}}}function ur(e){let r={closed:!1,lockfileProvider:e.lockfileProvider,nextId:0,size:e.initialSize,spawn:e.spawn,waiters:[],workers:[]};return{close:async()=>{r.closed=!0,await Promise.all([...r.workers].map(o=>N(o,r)))},execute:(o,n)=>Eo(o,n,r),exploreTrail:(o,n)=>Io(o,n,r),routeSpan:(o,n)=>{let t=r.workers.find(i=>i.runId===o);t?.worker.connection.sendNotification(Re,{runId:o,span:n})},setSize:o=>{Ao(o,r)}}}function ho(e){let r=e.pid;if(r!=null)try{process.kill(-r,"SIGKILL")}catch{e.kill("SIGKILL")}}var Ro=1e4,pr=-32800;async function Eo(e,r,o){let n=await fr(o);if(n.runId=e.runId,!n.alive)return C(n,o),{outcome:{detail:"worker-exit",kind:"error"},serverNotified:!1};let t=new sr,i=()=>{t.cancel()};r.aborted&&t.cancel(),r.addEventListener("abort",i,{once:!0});try{let a=await n.worker.connection.sendRequest(xe,e,t.token),l=we.safeParse(a);return l.success?l.data:{outcome:{detail:"bad-outcome-frame",kind:"error"},serverNotified:!1}}catch(a){return Co(a,n)}finally{r.removeEventListener("abort",i),t.dispose(),C(n,o)}}async function fr(e){let r=e.workers.find(o=>o.alive&&o.runId===void 0);if(r!=null)return r.runId="pending",r;if(e.workers.length<e.size){let o=To(e);return o.runId="pending",await o.ready,o}return new Promise(o=>{e.waiters.push(n=>{n.runId="pending",o(n)})})}function To(e){let r=e.spawn(),o={resolve:()=>{}},n={alive:!0,id:e.nextId,ready:new Promise(t=>{o.resolve=t,r.connection.onNotification(be,t)}),runId:void 0,worker:r};return e.nextId+=1,r.connection.onRequest(Pe,()=>e.lockfileProvider()),r.onExit(()=>{n.alive=!1,e.workers=e.workers.filter(t=>t!==n),r.connection.dispose(),o.resolve()}),e.workers.push(n),n}function C(e,r){if(e.runId=void 0,!e.alive||r.closed)return;if(r.workers.length>r.size){N(e,r);return}let o=r.waiters.shift();o?.(e)}async function N(e,r){if(r.workers=r.workers.filter(t=>t!==e),!e.alive)return;let o=new Promise(t=>{e.worker.onExit(t)});await e.worker.connection.sendNotification(Ee).catch(()=>{});let n=setTimeout(()=>{e.worker.kill()},Ro);await o,clearTimeout(n)}function Co(e,r){return e instanceof cr&&e.code===pr?{outcome:{detail:"aborted",kind:"error"},serverNotified:!1}:r.alive?{outcome:{detail:e instanceof Error?e.message:String(e),kind:"error"},serverNotified:!1}:{outcome:{detail:"worker-exit",kind:"error"},serverNotified:!1}}async function Io(e,r,o){let n=await fr(o);if(n.runId="explore",!n.alive)return C(n,o),{kind:"error"};let t=new sr,i=()=>{t.cancel()};r.aborted&&t.cancel(),r.addEventListener("abort",i,{once:!0});try{let a=await n.worker.connection.sendRequest(he,e,t.token),l=se.safeParse(a);return l.success?l.data:{kind:"error"}}catch(a){return Wo(a)}finally{r.removeEventListener("abort",i),t.dispose(),C(n,o)}}function Wo(e){return e instanceof cr&&e.code===pr?{kind:"aborted"}:{kind:"error",reason:`transport:${e instanceof Error?e.message.slice(0,120):"unknown"}`}}function Ao(e,r){r.size=e,e>lr.availableParallelism()&&s.warn({cores:lr.availableParallelism(),size:e},"worker pool size exceeds available cores");let o=r.workers.filter(t=>t.alive&&t.runId===void 0),n=r.workers.length-e;o.slice(0,Math.max(0,n)).forEach(t=>{N(t,r)})}import I from"fs";import{graphql as W}from"gql.tada";import{print as U}from"graphql";var Lo=W(`
35
- query DaemonExploration($devSessionId: String!) {
36
- exploration(devSessionId: $devSessionId) {
37
- active
38
- localWorkers
39
- maxTrailLength
40
- }
41
- }
42
- `),Do=W(`
43
- subscription WatchExplorationChanged($devSessionId: String!) {
44
- explorationChanged(devSessionId: $devSessionId) {
45
- exploration {
46
- active
47
- localWorkers
48
- maxTrailLength
49
- }
50
- }
51
- }
52
- `);function mr({config:e,devSessionId:r,machinery:o,sseClient:n}){return Ho({config:e,devSessionId:r,machinery:o}),n.subscribe({query:U(Do),variables:{devSessionId:r}},{complete:()=>{},error:t=>{s.error(t,"exploration subscription error")},next:t=>{yr(o,t.data?.explorationChanged.exploration)}})}async function Ho({config:e,devSessionId:r,machinery:o}){let n=await g({config:e,document:Lo,variables:{devSessionId:r}});yr(o,n.exploration)}function yr(e,r){r!=null&&(e.setMaxTrailLength(r.maxTrailLength),e.setConcurrency(r.localWorkers),e.setEnabled(r.active))}function gr({config:e,devSessionId:r,machinery:o}){o.setScopedTestRefs(n=>He(e,r,n)),o.setReportProgress(n=>{De({attempts:n.attempts,config:e,devSessionId:r,findings:n.findings,trail:Le(n.result)}).catch(t=>{s.warn({error:t},"exploration progress report failed")})})}var _o=W(`
53
- subscription HooksPausedWatch($projectId: String!) {
54
- hooksPausedRequested(projectId: $projectId) {
55
- paused
56
- projectId
57
- }
58
- }
59
- `),qo=W(`
60
- subscription WatchLocalConcurrencyChanged {
61
- myMaxLocalConcurrentRunsChanged
62
- }
63
- `);function Sr({pool:e,sseClient:r}){return r.subscribe({query:U(qo)},{complete:()=>{},error:o=>{s.error(o,"localConcurrency subscription error")},next:o=>{let n=o.data?.myMaxLocalConcurrentRunsChanged;n!=null&&(R(n),e.setSize(n))}})}function kr({cwd:e,projectId:r,sseClient:o}){return o.subscribe({query:U(_o),variables:{projectId:r}},{complete:()=>{},error:n=>{s.error(n,"hooksPaused subscription error")},next:n=>{let t=n.data?.hooksPausedRequested?.paused;t!=null&&j({cwd:e,paused:t})}})}function j({cwd:e,paused:r}){let o=pe(e);if(r&&!I.existsSync(o)){I.writeFileSync(o,"");return}!r&&I.existsSync(o)&&I.unlinkSync(o)}var No=6e4,vr=500,Uo=15e3,wr=6e4,jo=3,Bo=B(`
64
- mutation HeartbeatDevSessionWatch($id: String!) {
65
- heartbeatDevSession(id: $id) {
66
- __typename
67
- ... on DevSession {
68
- id
69
- }
70
- ... on DevSessionEndedError {
71
- message
72
- }
73
- }
74
- }
75
- `),zo=B(`
76
- query WatchLocalConcurrency {
77
- currentUser {
78
- id
79
- maxLocalConcurrentRuns
80
- }
81
- }
82
- `),Jo=B(`
83
- mutation EndDevSessionWatch($projectId: String!, $cwd: String!) {
84
- endDevSession(projectId: $projectId, cwd: $cwd) {
85
- __typename
86
- ... on DevSession {
87
- id
88
- }
89
- ... on NoActiveDevSessionError {
90
- message
91
- }
92
- }
93
- }
94
- `);async function Bt(e){let{executor:r}=e;un();let o=ln(process.cwd()),n=o.cwd,t=rn(n),i=an(),a=ar({config:o,executor:r,pool:i.pool}),l={handler:()=>{}},c=nn(),u=Ne(),d=Ae({config:o,cwd:n,executor:r,explorationStatus:a.status,ready:c.promise,onShutdownRequest:()=>{l.handler()},sseHealth:()=>u.snapshot()}),p=await tn({cwd:n,ipc:d,releasePid:t}),S=await H(n);S.isErr()&&(process.stderr.write(`ripplo: ${_(S.error)}
95
- `),process.exit(1));let w=S.value,k=await br(()=>M({config:o,cwd:n,lockfile:w}),{config:o,label:"initial sync"}),x=await fn(o);j({cwd:n,paused:k.hooksPaused});let f=Ie(n);f!=null&&s.info("watching branch %s in %s",f,n);let m=Oo({headers:{Authorization:`Bearer ${o.token}`},retry:Oe,retryAttempts:1/0,url:`${o.ripploServerUrl}/graphql`}),y=en({cwd:n,initialConcurrency:x});i.provide(y);let A=await Vo({cwd:n,pool:y}),z=Yo({claim:d.claim,config:o,cwd:n,initialId:k.devSessionId,pool:y,sseClient:m,sseHealth:u}),xr=kr({cwd:n,projectId:o.projectId,sseClient:m}),Pr=Sr({pool:y,sseClient:m}),hr=mr({config:o,devSessionId:k.devSessionId,machinery:a,sseClient:m});gr({config:o,devSessionId:k.devSessionId,machinery:a});let Rr=Xo({config:o,session:z}),Er=dn(),J=await Qo({config:o,devSessionId:k.devSessionId,executor:r});c.resolve(),Ko({devSessionId:k.devSessionId,executor:r,tunnel:J});let Tr=async()=>{Rr(),Er(),a.stop(),p.close(),z.stop(),xr(),Pr(),hr(),await y.close(),await Go(J),await A.stop().catch(()=>{}),await Promise.race([g({config:o,document:Jo,variables:{cwd:o.cwd,projectId:o.projectId}}).catch(()=>{}),new Promise(Cr=>setTimeout(Cr,3e3))]),t()},b=()=>{Tr().finally(()=>process.exit(0))};l.handler=b,process.on("SIGINT",b),process.on("SIGTERM",b),process.on("SIGHUP",b),process.on("SIGBREAK",b),await new Promise(()=>{})}async function Qo({config:e,devSessionId:r,executor:o}){if(o==="cloud")return qe({config:e,devSessionId:r})}async function Go(e){e!=null&&await e.stop()}function Vo({cwd:e,pool:r}){return ue({localDir:Mo.join(e,".ripplo",".local"),writePortFile:!0,onRrwebBatch:()=>{},onSpan:o=>{let n=o.attributes["ripplo.run"];n!=null&&r.routeSpan(n,o)}})}function Ko({devSessionId:e,executor:r,tunnel:o}){process.stdout.write(`${Se({devSessionId:e,executor:r,tunnelHostname:o?.hostname,version:K()})}
96
- `)}function Xo({config:e,session:r}){let o=async()=>{try{let t=await g({config:e,document:Bo,variables:{id:r.getId()}});t.heartbeatDevSession?.__typename==="DevSessionEndedError"&&(s.warn("dev session ended server-side (%s); re-registering",t.heartbeatDevSession.message),await r.reregister())}catch(t){s.warn("heartbeat failed: %s",t instanceof Error?t.message:String(t))}},n=setInterval(()=>{o()},Uo);return()=>{clearInterval(n)}}function Yo({claim:e,config:r,cwd:o,initialId:n,pool:t,sseClient:i,sseHealth:a}){let l=n,c=null,u=0,d=0,p=f=>{x(f)},S=()=>{let f=Fe({claim:e,cwd:o,devSessionId:l,onSubscriptionDead:p,pool:t,sseClient:i,sseHealth:a}),m=$e({cwd:o,devSessionId:l,onSubscriptionDead:p,sseClient:i});return()=>{f(),m()}},w=S(),k=async f=>{let m=Date.now();u=m-d>wr*2?1:u+1,d=m,u>=jo&&a.markUnhealthy(f),await Zo(Math.min(1e3*2**(u-1),wr));let y=await H(o);if(y.isErr()){s.error("re-register: compile failed: %s",_(y.error));return}let A=await br(()=>M({config:r,cwd:o,lockfile:y.value}),{config:r,label:"re-register sync"});w(),l=A.devSessionId,w=S(),s.info("re-registered dev session as %s",l)},x=f=>(c!=null||(c=k(f).finally(()=>{c=null})),c);return{getId:()=>l,reregister:()=>x("dev session ended server-side"),stop:()=>{w()}}}function Zo(e){return new Promise(r=>setTimeout(r,e))}function en({cwd:e,initialConcurrency:r}){return ur({initialSize:r,spawn:dr(mn(),e),lockfileProvider:async()=>{let o=await P(e);return o.isErr()?{unavailable:`daemon-load-failed:${o.error.kind}`}:{lockfileJson:X(Y,o.value)}}})}function rn(e){try{return ne({cwd:e,onCompromised:on})}catch(r){throw r instanceof oe&&(process.stderr.write(`${ke({cwd:r.cwd,pid:r.pid})}
97
- `),process.exit(1)),r}}function on(){s.error("daemon lock compromised; shutting down"),process.stderr.write(`${ve()}
98
- `),process.exit(1)}function nn(){let e={handler:()=>{}};return{promise:new Promise(o=>{e.handler=o}),resolve:()=>{e.handler()}}}async function tn({cwd:e,ipc:r,releasePid:o}){return(await Qe({cwd:e,onConnection:r.handleConnection})).match(t=>t,t=>{process.stderr.write(`${me(t)}
99
- `),o(),process.exit(1)})}function an(){let e={provide:()=>{}};return{pool:new Promise(o=>{e.provide=o}),provide:o=>{e.provide(o)}}}function ln(e){return v(e).match(r=>r,r=>{process.stderr.write(`${re(r)}
100
- `),process.exit(1)})}function br(e,{config:r,label:o}){let n=r.ripploServerUrl.includes("localhost")||r.ripploServerUrl.includes("127.0.0.1");return Fo(async()=>{try{return await e()}catch(t){sn({config:r,error:t});let i=t instanceof Error?t.message:String(t);throw cn(i)?t:(s.error("%s failed: %s",o,i),new $o(i))}},{factor:2,maxTimeout:n?2e3:1e4,minTimeout:n?100:1e3,retries:1/0,onFailedAttempt:({attemptNumber:t,error:i})=>{s.warn("%s attempt %d failed \u2014 retrying: %s",o,t,i.message)}})}function sn({config:e,error:r}){let o=Q(r);o==="UNAUTHENTICATED"&&(process.stderr.write(`ripplo: ${ge()}
101
- `),process.exit(1)),o==="FORBIDDEN"&&(process.stderr.write(`ripplo: ${ye({projectId:e.projectId,serverUrl:e.ripploServerUrl})}
102
- `),process.exit(1))}function cn(e){return e.includes("status 502")||e.includes("ECONNREFUSED")||e.includes("Failed to connect")||e.includes("fetch failed")}function dn(){L({maxRuns:vr});let e=setInterval(()=>{L({maxRuns:vr})},No);return()=>{clearInterval(e)}}function un(){process.on("unhandledRejection",e=>{s.error({err:e},"unhandledRejection in watch; continuing")}),process.on("uncaughtException",e=>{s.error({err:e},"uncaughtException in watch; continuing")})}var pn=4;async function fn(e){try{let o=(await g({config:e,document:zo,variables:void 0})).currentUser?.maxLocalConcurrentRuns;if(o!=null)return R(o),o}catch(r){s.warn({err:r},"failed to fetch local concurrency setting; using default")}return pn}function mn(){let e=process.argv[1];if(e==null)throw new Error("cli entry unavailable");return e}export{Bt as runDaemon};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{$ as d,Y as a,Z as b,_ as c,aa as e,ba as f,ca as g,da as h,ea as i,fa as j,ga as k}from"./chunk-JZ7VSGAN.js";import"./chunk-IHSHBPJY.js";import"./chunk-7UWDMECF.js";export{b as renderDaemonBindError,g as renderDaemonLockCompromised,f as renderDaemonLockHeld,e as renderDaemonReady,h as renderDaemonStatus,j as renderDaemonVersionNote,i as renderExplorationProgress,d as renderNotSignedIn,c as renderProjectAccessDenied,a as renderTunnelProvisionFailed,k as wireOutcome};