ripplo 0.7.18 → 0.7.20
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/assets/rrweb.js +3 -3
- package/dist/chunk-7UWDMECF.js +2 -0
- package/dist/{chunk-WNUKCEN6.js → chunk-BJVAPI4P.js} +1 -1
- package/dist/chunk-DAULBZMT.js +167 -0
- package/dist/chunk-EVYYSTR7.js +46 -0
- package/dist/chunk-IHSHBPJY.js +2 -0
- package/dist/chunk-XZTICXYD.js +206 -0
- package/dist/daemon-5FTGPJ3L.js +62 -0
- package/dist/daemon-XZ5HWQJA.js +2 -0
- package/dist/daemon-tunnel-AG6FGNXC.js +2 -0
- package/dist/gifenc.esm-GMV2LJ5K.js +2 -0
- package/dist/index.js +183 -194
- package/package.json +4 -4
- package/dist/chunk-LYAUCRJZ.js +0 -145
- package/dist/chunk-RZKJVOMP.js +0 -137
- package/dist/chunk-SB7H6IAS.js +0 -2
- package/dist/chunk-Y5IXMRSB.js +0 -46
- package/dist/daemon-HZS7WYEG.js +0 -2
- package/dist/daemon-T77UK4AQ.js +0 -61
- package/dist/daemon-tunnel-MOYCRSSC.js +0 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as q}from"./chunk-IHSHBPJY.js";import{b as G}from"./chunk-7UWDMECF.js";import{execFileSync as O}from"child_process";import U from"fs";import p from"path";function F(e){let r=L(e);return r??P(e)}function P(e){let r=p.dirname(e);return N(p.join(e,".ripplo"))?e:r===e?null:P(r)}function N(e){try{return U.statSync(e).isDirectory()}catch{return!1}}function L(e){let r=j(["rev-parse","--show-toplevel"],e);if(r==null)return null;let t=r.trim();return t.length===0?null:p.isAbsolute(t)?t:p.resolve(e,t)}function j(e,r){try{return O("git",e,{cwd:r,encoding:"utf8",stdio:["ignore","pipe","ignore"]})}catch{return null}}var f=class extends Error{detail;serverUrl;constructor({detail:r,serverUrl:t}){super(`Failed to connect to Ripplo server at ${t}. Check the server is running and reachable. Details: ${r}`),this.name="GqlConnectionError",this.detail=r,this.serverUrl=t}},c=class extends Error{errors;constructor(r){super(r.map(t=>t.message).join(", ")),this.name="GqlRequestError",this.errors=r}};function B(e){if(e instanceof c)return e.errors[0]?.extensions?.code}async function x(e){let{print:r}=await import("graphql"),t=r(e.document),n=JSON.stringify({query:t,variables:e.variables}),o=`${e.config.ripploServerUrl}/graphql`,d=await W({init:{body:n,headers:{Authorization:`Bearer ${e.config.token}`,"Content-Type":"application/json"},method:"POST"},serverUrl:e.config.ripploServerUrl,url:o}),s=await Q({res:d,url:o});if(!J(s))throw new Error("Invalid GraphQL response");if(K(s))throw new c(s.errors);if(s.data==null)throw new Error("No data returned from server");return s.data}async function W({init:e,serverUrl:r,url:t}){let n=1,o=await E({init:e,url:t});for(;o.retryable&&n<3;)await H(V(n)),n+=1,o=await E({init:e,url:t});if(o.response!=null)return o.response;throw new f({detail:o.detail,serverUrl:r})}async function E({init:e,url:r}){try{let t=await fetch(r,{...e,signal:AbortSignal.timeout(15e3)});return{detail:"",response:t,retryable:t.status>=500}}catch(t){return{detail:t instanceof Error?t.message:String(t),response:void 0,retryable:!0}}}function V(e){return 300*3**(e-1)*(.5+Math.random())}function H(e){return new Promise(r=>{setTimeout(r,e)})}async function Q({res:e,url:r}){let t=await e.text();if(t.length===0)throw new Error(`Empty response from Ripplo server at ${r} (status ${String(e.status)}). The server may have restarted or the request was rejected before a body was sent.`);try{return JSON.parse(t)}catch{throw new Error(`Non-JSON response from Ripplo server at ${r} (status ${String(e.status)}): ${t.slice(0,200)}`)}}function J(e){return typeof e=="object"&&e!=null&&("data"in e||"errors"in e)}function K(e){return Array.isArray(e.errors)&&e.errors.length>0}import X from"pino";import z from"pino-pretty";var y=X({level:process.env.LOG_LEVEL??"info"},z({ignore:"pid,hostname"}));import{readdir as Y,rm as Z,stat as ee}from"fs/promises";import k from"path";var b=k.join(process.cwd(),".ripplo","debug"),T=360*60*1e3;async function re({maxRuns:e}){try{let t=(await Y(b,{withFileTypes:!0})).filter(i=>i.isDirectory()),n=Date.now(),o=await Promise.all(t.map(async i=>{let m=k.join(b,i.name),$=await ee(m);return{dirPath:m,mtime:$.mtimeMs}})),d=o.filter(i=>n-i.mtime>T),M=o.filter(i=>n-i.mtime<=T).toSorted((i,m)=>m.mtime-i.mtime).slice(e),R=[...d,...M];if(R.length===0)return;await Promise.allSettled(R.map(i=>Z(i.dirPath,{force:!0,recursive:!0}))),y.debug("Pruned %d old debug run(s)",R.length)}catch{y.warn("Debug run pruning failed, ignoring")}}import{Agent as te,RetryAgent as ne,setGlobalDispatcher as oe}from"undici";var ie=1500,se=4e3,ae=3,le=50,de=100,C=!1;function ce(){if(C)return;C=!0;let e=new te({connections:de,keepAliveMaxTimeout:se,keepAliveTimeout:ie}),r=new ne(e,{errorCodes:["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_REQ_CONTENT_LENGTH_MISMATCH","UND_ERR_SOCKET"],maxRetries:ae,methods:["GET","POST","HEAD","OPTIONS","PUT","DELETE"],minTimeout:le});oe(r)}import{graphql as u}from"gql.tada";var Ue=u(`
|
|
3
|
+
query AgentReviewContextWorker($reviewId: String!) {
|
|
4
|
+
agentReview(id: $reviewId) {
|
|
5
|
+
id
|
|
6
|
+
runId
|
|
7
|
+
agentProfile {
|
|
8
|
+
id
|
|
9
|
+
name
|
|
10
|
+
description
|
|
11
|
+
output
|
|
12
|
+
successCriteria
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`);var Fe=u(`
|
|
17
|
+
mutation StartAgentReviewWorker($reviewId: String!) {
|
|
18
|
+
startAgentReview(reviewId: $reviewId)
|
|
19
|
+
}
|
|
20
|
+
`);var Ne=u(`
|
|
21
|
+
mutation CompleteAgentReviewWorker(
|
|
22
|
+
$reviewId: String!
|
|
23
|
+
$markdown: String!
|
|
24
|
+
$shortSummary: String!
|
|
25
|
+
$verdict: AgentReviewVerdict!
|
|
26
|
+
$comments: [AgentReviewCommentInput!]!
|
|
27
|
+
) {
|
|
28
|
+
completeAgentReview(
|
|
29
|
+
reviewId: $reviewId
|
|
30
|
+
markdown: $markdown
|
|
31
|
+
shortSummary: $shortSummary
|
|
32
|
+
verdict: $verdict
|
|
33
|
+
comments: $comments
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
`);var Le=u(`
|
|
37
|
+
mutation UpdateAgentReviewProgressWorker($reviewId: String!, $text: String!) {
|
|
38
|
+
updateAgentReviewProgress(reviewId: $reviewId, text: $text)
|
|
39
|
+
}
|
|
40
|
+
`);var je=u(`
|
|
41
|
+
mutation FailAgentReviewWorker($reviewId: String!, $reason: String!) {
|
|
42
|
+
failAgentReview(reviewId: $reviewId, reason: $reason)
|
|
43
|
+
}
|
|
44
|
+
`);import l from"fs";import I from"path";import a from"fs";import ue from"os";import g from"path";var ge=".local",me=".ripplo";function v(e){return g.join(e,".ripplo",ge)}function pe(e){let r=v(e);a.existsSync(r)||a.mkdirSync(r,{recursive:!0});let t=g.join(r,".gitignore");return a.existsSync(t)||a.writeFileSync(t,`*
|
|
45
|
+
`),r}function fe(e,r){return g.join(v(e),r)}function h(){return g.join(ue.homedir(),me)}function S(){let e=h();return a.existsSync(e)?a.chmodSync(e,448):a.mkdirSync(e,{mode:448,recursive:!0}),e}function A(e){return g.join(h(),e)}function ye(e){let r=process.env.RIPPLO_TOKEN;if(r!=null&&r.trim().length>0)return r.trim();let t=w(e);if(!l.existsSync(t))return null;let n=l.readFileSync(t,"utf8").trim();return n.length===0?null:n}function we({serverUrl:e,token:r}){S();let t=w(e);l.mkdirSync(I.dirname(t),{mode:448,recursive:!0}),l.writeFileSync(t,r+`
|
|
46
|
+
`,{mode:384})}function Re(e){let r=w(e);return l.existsSync(r)?(l.unlinkSync(r),!0):!1}function w(e){return A(I.join("tokens",ve(e)))}function ve(e){return new URL(e).host.replaceAll(/[^a-zA-Z0-9.]/g,"_")}var D=G(q(),1);import _ from"crypto";function he({body:e,secret:r}){let t=new D.Webhook(r),n=`msg_${_.randomUUID()}`,o=new Date,d=t.sign(n,o,e),s=Math.floor(o.getTime()/1e3);return{"webhook-id":n,"webhook-signature":d,"webhook-timestamp":String(s)}}function Se(){return`whsec_${_.randomBytes(24).toString("base64")}`}export{F as a,f as b,B as c,x as d,y as e,re as f,pe as g,fe as h,S as i,A as j,ye as k,we as l,Re as m,w as n,ce as o,he as p,Se as q};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as P}from"./chunk-7UWDMECF.js";var T=P(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.timingSafeEqual=void 0;function N(n,e=""){if(!n)throw new Error(e)}function F(n,e){if(n.byteLength!==e.byteLength)return!1;n instanceof DataView||(n=new DataView(ArrayBuffer.isView(n)?n.buffer:n)),e instanceof DataView||(e=new DataView(ArrayBuffer.isView(e)?e.buffer:e)),N(n instanceof DataView),N(e instanceof DataView);let r=n.byteLength,i=0,a=-1;for(;++a<r;)i|=n.getUint8(a)^e.getUint8(a);return i===0}V.timingSafeEqual=F});var W=P(S=>{"use strict";var G=S&&S.__extends||(function(){var n=function(e,r){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,a){i.__proto__=a}||function(i,a){for(var g in a)a.hasOwnProperty(g)&&(i[g]=a[g])},n(e,r)};return function(e,r){n(e,r);function i(){this.constructor=e}e.prototype=r===null?Object.create(r):(i.prototype=r.prototype,new i)}})();Object.defineProperty(S,"__esModule",{value:!0});var l=256,z=(function(){function n(e){e===void 0&&(e="="),this._paddingCharacter=e}return n.prototype.encodedLength=function(e){return this._paddingCharacter?(e+2)/3*4|0:(e*8+5)/6|0},n.prototype.encode=function(e){for(var r="",i=0;i<e.length-2;i+=3){var a=e[i]<<16|e[i+1]<<8|e[i+2];r+=this._encodeByte(a>>>18&63),r+=this._encodeByte(a>>>12&63),r+=this._encodeByte(a>>>6&63),r+=this._encodeByte(a>>>0&63)}var g=e.length-i;if(g>0){var a=e[i]<<16|(g===2?e[i+1]<<8:0);r+=this._encodeByte(a>>>18&63),r+=this._encodeByte(a>>>12&63),g===2?r+=this._encodeByte(a>>>6&63):r+=this._paddingCharacter||"",r+=this._paddingCharacter||""}return r},n.prototype.maxDecodedLength=function(e){return this._paddingCharacter?e/4*3|0:(e*6+7)/8|0},n.prototype.decodedLength=function(e){return this.maxDecodedLength(e.length-this._getPaddingLength(e))},n.prototype.decode=function(e){if(e.length===0)return new Uint8Array(0);for(var r=this._getPaddingLength(e),i=e.length-r,a=new Uint8Array(this.maxDecodedLength(i)),g=0,p=0,m=0,E=0,C=0,A=0,s=0;p<i-4;p+=4)E=this._decodeChar(e.charCodeAt(p+0)),C=this._decodeChar(e.charCodeAt(p+1)),A=this._decodeChar(e.charCodeAt(p+2)),s=this._decodeChar(e.charCodeAt(p+3)),a[g++]=E<<2|C>>>4,a[g++]=C<<4|A>>>2,a[g++]=A<<6|s,m|=E&l,m|=C&l,m|=A&l,m|=s&l;if(p<i-1&&(E=this._decodeChar(e.charCodeAt(p)),C=this._decodeChar(e.charCodeAt(p+1)),a[g++]=E<<2|C>>>4,m|=E&l,m|=C&l),p<i-2&&(A=this._decodeChar(e.charCodeAt(p+2)),a[g++]=C<<4|A>>>2,m|=A&l),p<i-3&&(s=this._decodeChar(e.charCodeAt(p+3)),a[g++]=A<<6|s,m|=s&l),m!==0)throw new Error("Base64Coder: incorrect characters for decoding");return a},n.prototype._encodeByte=function(e){var r=e;return r+=65,r+=25-e>>>8&6,r+=51-e>>>8&-75,r+=61-e>>>8&-15,r+=62-e>>>8&3,String.fromCharCode(r)},n.prototype._decodeChar=function(e){var r=l;return r+=(42-e&e-44)>>>8&-l+e-43+62,r+=(46-e&e-48)>>>8&-l+e-47+63,r+=(47-e&e-58)>>>8&-l+e-48+52,r+=(64-e&e-91)>>>8&-l+e-65+0,r+=(96-e&e-123)>>>8&-l+e-97+26,r},n.prototype._getPaddingLength=function(e){var r=0;if(this._paddingCharacter){for(var i=e.length-1;i>=0&&e[i]===this._paddingCharacter;i--)r++;if(e.length<4||r>2)throw new Error("Base64Coder: incorrect padding")}return r},n})();S.Coder=z;var D=new z;function Q(n){return D.encode(n)}S.encode=Q;function X(n){return D.decode(n)}S.decode=X;var I=(function(n){G(e,n);function e(){return n!==null&&n.apply(this,arguments)||this}return e.prototype._encodeByte=function(r){var i=r;return i+=65,i+=25-r>>>8&6,i+=51-r>>>8&-75,i+=61-r>>>8&-13,i+=62-r>>>8&49,String.fromCharCode(i)},e.prototype._decodeChar=function(r){var i=l;return i+=(44-r&r-46)>>>8&-l+r-45+62,i+=(94-r&r-96)>>>8&-l+r-95+63,i+=(47-r&r-58)>>>8&-l+r-48+52,i+=(64-r&r-91)>>>8&-l+r-65+0,i+=(96-r&r-123)>>>8&-l+r-97+26,i},e})(z);S.URLSafeCoder=I;var R=new I;function Z(n){return R.encode(n)}S.encodeURLSafe=Z;function ee(n){return R.decode(n)}S.decodeURLSafe=ee;S.encodedLength=function(n){return D.encodedLength(n)};S.maxDecodedLength=function(n){return D.maxDecodedLength(n)};S.decodedLength=function(n){return D.decodedLength(n)}});var K=P(($,j)=>{"use strict";(function(n,e){var r={};e(r);var i=r.default;for(var a in r)i[a]=r[a];typeof j=="object"&&typeof j.exports=="object"?j.exports=i:typeof define=="function"&&define.amd?define(function(){return i}):n.sha256=i})($,function(n){"use strict";n.__esModule=!0,n.digestLength=32,n.blockSize=64;var e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function r(s,t,o,f,x){for(var c,u,h,_,v,d,U,b,w,y,B,O,M;x>=64;){for(c=t[0],u=t[1],h=t[2],_=t[3],v=t[4],d=t[5],U=t[6],b=t[7],y=0;y<16;y++)B=f+y*4,s[y]=(o[B]&255)<<24|(o[B+1]&255)<<16|(o[B+2]&255)<<8|o[B+3]&255;for(y=16;y<64;y++)w=s[y-2],O=(w>>>17|w<<15)^(w>>>19|w<<13)^w>>>10,w=s[y-15],M=(w>>>7|w<<25)^(w>>>18|w<<14)^w>>>3,s[y]=(O+s[y-7]|0)+(M+s[y-16]|0);for(y=0;y<64;y++)O=(((v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7))+(v&d^~v&U)|0)+(b+(e[y]+s[y]|0)|0)|0,M=((c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10))+(c&u^c&h^u&h)|0,b=U,U=d,d=v,v=_+O|0,_=h,h=u,u=c,c=O+M|0;t[0]+=c,t[1]+=u,t[2]+=h,t[3]+=_,t[4]+=v,t[5]+=d,t[6]+=U,t[7]+=b,f+=64,x-=64}return f}var i=(function(){function s(){this.digestLength=n.digestLength,this.blockSize=n.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return s.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},s.prototype.clean=function(){for(var t=0;t<this.buffer.length;t++)this.buffer[t]=0;for(var t=0;t<this.temp.length;t++)this.temp[t]=0;this.reset()},s.prototype.update=function(t,o){if(o===void 0&&(o=t.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var f=0;if(this.bytesHashed+=o,this.bufferLength>0){for(;this.bufferLength<64&&o>0;)this.buffer[this.bufferLength++]=t[f++],o--;this.bufferLength===64&&(r(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(o>=64&&(f=r(this.temp,this.state,t,f,o),o%=64);o>0;)this.buffer[this.bufferLength++]=t[f++],o--;return this},s.prototype.finish=function(t){if(!this.finished){var o=this.bytesHashed,f=this.bufferLength,x=o/536870912|0,c=o<<3,u=o%64<56?64:128;this.buffer[f]=128;for(var h=f+1;h<u-8;h++)this.buffer[h]=0;this.buffer[u-8]=x>>>24&255,this.buffer[u-7]=x>>>16&255,this.buffer[u-6]=x>>>8&255,this.buffer[u-5]=x>>>0&255,this.buffer[u-4]=c>>>24&255,this.buffer[u-3]=c>>>16&255,this.buffer[u-2]=c>>>8&255,this.buffer[u-1]=c>>>0&255,r(this.temp,this.state,this.buffer,0,u),this.finished=!0}for(var h=0;h<8;h++)t[h*4+0]=this.state[h]>>>24&255,t[h*4+1]=this.state[h]>>>16&255,t[h*4+2]=this.state[h]>>>8&255,t[h*4+3]=this.state[h]>>>0&255;return this},s.prototype.digest=function(){var t=new Uint8Array(this.digestLength);return this.finish(t),t},s.prototype._saveState=function(t){for(var o=0;o<this.state.length;o++)t[o]=this.state[o]},s.prototype._restoreState=function(t,o){for(var f=0;f<this.state.length;f++)this.state[f]=t[f];this.bytesHashed=o,this.finished=!1,this.bufferLength=0},s})();n.Hash=i;var a=(function(){function s(t){this.inner=new i,this.outer=new i,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var o=new Uint8Array(this.blockSize);if(t.length>this.blockSize)new i().update(t).finish(o).clean();else for(var f=0;f<t.length;f++)o[f]=t[f];for(var f=0;f<o.length;f++)o[f]^=54;this.inner.update(o);for(var f=0;f<o.length;f++)o[f]^=106;this.outer.update(o),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var f=0;f<o.length;f++)o[f]=0}return s.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},s.prototype.clean=function(){for(var t=0;t<this.istate.length;t++)this.ostate[t]=this.istate[t]=0;this.inner.clean(),this.outer.clean()},s.prototype.update=function(t){return this.inner.update(t),this},s.prototype.finish=function(t){return this.outer.finished?this.outer.finish(t):(this.inner.finish(t),this.outer.update(t,this.digestLength).finish(t)),this},s.prototype.digest=function(){var t=new Uint8Array(this.digestLength);return this.finish(t),t},s})();n.HMAC=a;function g(s){var t=new i().update(s),o=t.digest();return t.clean(),o}n.hash=g,n.default=g;function p(s,t){var o=new a(s).update(t),f=o.digest();return o.clean(),f}n.hmac=p;function m(s,t,o,f){var x=f[0];if(x===0)throw new Error("hkdf: cannot expand more");t.reset(),x>1&&t.update(s),o&&t.update(o),t.update(f),t.finish(s),f[0]++}var E=new Uint8Array(n.digestLength);function C(s,t,o,f){t===void 0&&(t=E),f===void 0&&(f=32);for(var x=new Uint8Array([1]),c=p(t,s),u=new a(c),h=new Uint8Array(u.digestLength),_=h.length,v=new Uint8Array(f),d=0;d<f;d++)_===h.length&&(m(h,u,o,x),_=0),v[d]=h[_++];return u.clean(),h.fill(0),x.fill(0),v}n.hkdf=C;function A(s,t,o,f){for(var x=new a(s),c=x.digestLength,u=new Uint8Array(4),h=new Uint8Array(c),_=new Uint8Array(c),v=new Uint8Array(f),d=0;d*c<f;d++){var U=d+1;u[0]=U>>>24&255,u[1]=U>>>16&255,u[2]=U>>>8&255,u[3]=U>>>0&255,x.reset(),x.update(t),x.update(u),x.finish(_);for(var b=0;b<c;b++)h[b]=_[b];for(var b=2;b<=o;b++){x.reset(),x.update(_).finish(_);for(var w=0;w<c;w++)h[w]^=_[w]}for(var b=0;b<c&&d*c+b<f;b++)v[d*c+b]=h[b]}for(var d=0;d<c;d++)h[d]=_[d]=0;for(var d=0;d<4;d++)u[d]=0;return x.clean(),v}n.pbkdf2=A})});var ie=P(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.Webhook=L.WebhookVerificationError=void 0;var te=T(),J=W(),re=K(),Y=300,H=class n extends Error{constructor(e){super(e),Object.setPrototypeOf(this,n.prototype),this.name="ExtendableError",this.stack=new Error(e).stack}},k=class n extends H{constructor(e){super(e),Object.setPrototypeOf(this,n.prototype),this.name="WebhookVerificationError"}};L.WebhookVerificationError=k;var q=class n{constructor(e,r){if(!e)throw new Error("Secret can't be empty.");if(r?.format==="raw")e instanceof Uint8Array?this.key=e:this.key=Uint8Array.from(e,i=>i.charCodeAt(0));else{if(typeof e!="string")throw new Error("Expected secret to be of type string");e.startsWith(n.prefix)&&(e=e.substring(n.prefix.length)),this.key=J.decode(e)}}verify(e,r){let i={};for(let t of Object.keys(r))i[t.toLowerCase()]=r[t];let a=i["webhook-id"],g=i["webhook-signature"],p=i["webhook-timestamp"];if(!g||!a||!p)throw new k("Missing required headers");let m=this.verifyTimestamp(p),C=this.sign(a,m,e).split(",")[1],A=g.split(" "),s=new globalThis.TextEncoder;for(let t of A){let[o,f]=t.split(",");if(o==="v1"&&(0,te.timingSafeEqual)(s.encode(f),s.encode(C)))return JSON.parse(e.toString())}throw new k("No matching signature found")}sign(e,r,i){if(typeof i!="string")if(i.constructor.name==="Buffer")i=i.toString();else throw new Error("Expected payload to be of type string or Buffer.");let a=new TextEncoder,g=Math.floor(r.getTime()/1e3),p=a.encode(`${e}.${g}.${i}`);return`v1,${J.encode(re.hmac(this.key,p))}`}verifyTimestamp(e){let r=Math.floor(Date.now()/1e3),i=parseInt(e,10);if(isNaN(i))throw new k("Invalid Signature Headers");if(r-i>Y)throw new k("Message timestamp too old");if(i>r+Y)throw new k("Message timestamp too new");return new Date(i*1e3)}};L.Webhook=q;q.prefix="whsec_"});export{ie as a};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{H as Ge,I as Qe,J as Xe,K as Ye,L as ie,M as O,N,O as D,P as Ze,R as er,S as rr,T as nr,U as tr,V as or,X as ir,Y as ar,a as Ue,b as $,e as We,f as qe,h as _,i as Be,j as Ve,k as h,l as Ke,m as ze,n as I,o as oe,p as Je,s as C}from"./chunk-DAULBZMT.js";import{b as _e,d as f,e as y,g as Oe,h as S,i as Ne,j as De,k as He}from"./chunk-EVYYSTR7.js";import cr from"fs";import B from"path";import{config as zn}from"dotenv";import{z as W}from"zod";import{err as Jn,ok as dr}from"neverthrow";import U from"fs";import le from"path";import{err as ae,ok as sr}from"neverthrow";import{z as H}from"zod";var qn=le.join(".ripplo","project.json"),se=[".env",".env.local"],Bn=H.object({envFiles:H.array(H.string().min(1)).optional(),projectId:H.string().min(1)});function lr(e){return le.join(e,qn)}function ce(e){let r=lr(e);return U.existsSync(r)?Vn(r).andThen(n=>{let t=Bn.safeParse(n);return t.success?sr({envFiles:t.data.envFiles??se,projectId:t.data.projectId}):ae({issues:t.error.issues.map(o=>`${o.path.join(".")}: ${o.message}`),kind:"project-file-invalid",path:r})}):ae({kind:"project-file-missing",path:r})}function de(e){return ce(e).match(r=>r,()=>{})}function Vn(e){try{return sr(JSON.parse(U.readFileSync(e,"utf8")))}catch(r){return ae({issues:[r instanceof Error?r.message:String(r)],kind:"project-file-invalid",path:e})}}function Aa({cwd:e,envFiles:r,projectId:n}){let t=lr(e);U.mkdirSync(le.dirname(t),{recursive:!0});let o={projectId:n};r!=null&&!Kn(r)&&(o.envFiles=[...r]),U.writeFileSync(t,JSON.stringify(o,null,2)+`
|
|
3
|
+
`)}function Kn(e){return e.length!==se.length?!1:e.every((r,n)=>r===se[n])}function Oa(e){let n=de(e)?.envFiles??[".env",".env.local"],t=B.join(e,".ripplo");n.forEach(o=>{let i=B.resolve(t,o);cr.existsSync(i)&&zn({override:!0,path:i,quiet:!0})}),q=void 0}var Gn=W.object({RIPPLO_APP_URL:W.url(),RIPPLO_ENGINE_URL:W.url(),RIPPLO_WEBHOOK_SECRET:W.string().min(1)}),q;function V(){return q!=null?dr(q):Xn().map(e=>(q=e,e))}function Qn(e){let n=de(e)?.envFiles??[],t=B.join(e,".ripplo");return n.map(o=>B.resolve(t,o)).filter(o=>!cr.existsSync(o))}function Xn(){let e=Gn.safeParse(process.env);if(!e.success)return Jn({issues:e.error.issues.map(n=>`${n.path.join(".")}: ${n.message}`),kind:"env-invalid",missingEnvFiles:Qn(process.cwd())});let r=e.data;return dr({appUrl:r.RIPPLO_APP_URL,engineUrl:r.RIPPLO_ENGINE_URL,webhookSecret:r.RIPPLO_WEBHOOK_SECRET})}import{readFileSync as Yn}from"fs";import{z as ur}from"zod";var Zn=ur.object({version:ur.string()});function K(){let e=Yn(new URL("../package.json",import.meta.url),"utf8");return Zn.parse(JSON.parse(e)).version}import ge from"fs";import z from"path";import{createJiti as ct}from"jiti";import{err as T,ok as yr}from"neverthrow";import et from"fs";import A from"path";import x from"typescript";function pr(e){let r=A.join(e,"index.ts"),n=tt(e);et.mkdirSync(A.dirname(n.tsBuildInfoFile??""),{recursive:!0});let t=x.createIncrementalCompilerHost(n),o=x.createIncrementalProgram({host:t,options:n,rootNames:[r]}),i=[...o.getSyntacticDiagnostics(),...o.getSemanticDiagnostics()];o.emit();let s=i.filter(d=>rt(d,e));if(s.length===0)return{diagnostics:[],ok:!0};let l={getCanonicalFileName:d=>d,getCurrentDirectory:()=>A.dirname(e),getNewLine:()=>`
|
|
4
|
+
`};return{diagnostics:x.formatDiagnosticsWithColorAndContext(s,l).split(`
|
|
5
|
+
`).filter(d=>d.length>0),ok:!1}}function rt(e,r){let n=e.file?.fileName;return n==null?!0:n.startsWith(r)}var nt=A.join(".local","tsbuildinfo");function tt(e){return{allowImportingTsExtensions:!0,allowJs:!1,esModuleInterop:!0,incremental:!0,module:x.ModuleKind.Preserve,moduleResolution:x.ModuleResolutionKind.Bundler,noEmit:!0,resolveJsonModule:!0,skipLibCheck:!0,strict:!1,target:x.ScriptTarget.ES2022,tsBuildInfoFile:A.join(e,nt)}}import{createHash as ot}from"crypto";import fr from"fs/promises";import ue from"path";import{err as b,ok as pe,Result as it}from"neverthrow";var fe=".ripplo/fixtures",me=10*1024*1024,ye=50*1024*1024;async function mr(e,r){let n=at(r);if(n.length===0)return pe({});let t=ue.join(e,fe),o=await Promise.all(n.map(i=>st({fixturesRoot:t,name:i})));return it.combine(o).andThen(lt)}function at(e){let n=e.workflows.flatMap(t=>[...t.steps,...t.tests.flatMap(o=>o.steps)]).flatMap(t=>t.action.kind==="upload"?t.action.files:[]);return[...new Set(n)].toSorted((t,o)=>t.localeCompare(o))}async function st({fixturesRoot:e,name:r}){if(r.includes("..")||ue.isAbsolute(r))return b({kind:"fixture-invalid-name",name:r});let n=ue.join(e,r),t=await fr.lstat(n).catch(()=>null);if(t==null)return b({kind:"fixture-missing",name:r,path:n});if(t.isSymbolicLink())return b({kind:"fixture-symlink",name:r});if(!t.isFile())return b({kind:"fixture-not-file",name:r});let o=await fr.readFile(n);if(o.byteLength>me)return b({kind:"fixture-too-large",name:r,size:o.byteLength});let i=ot("sha256").update(o).digest("hex");return pe([r,{sha256:i,size:o.byteLength}])}function lt(e){let r=e.reduce((n,[,t])=>n+t.size,0);return r>ye?b({kind:"fixtures-total-too-large",total:r}):pe(Object.fromEntries(e))}var v=".ripplo/ripplo.lock",j;async function gr(e){let{result:r}=await dt(e);return r}async function dt(e){let r=pt(z.join(e,".ripplo"));if(j!=null&&j.fingerprint===r&&j.result.isOk())return{fingerprint:r,result:j.result};let n=await F(e);return j={fingerprint:r,result:n},{fingerprint:r,result:n}}async function F(e){let r=z.join(e,".ripplo"),n=z.join(r,"index.ts"),t=pr(r);return t.ok?(await ft(n)).andThen(s=>yt({entryPath:n,exported:s})).match(async s=>(await mr(e,s)).map(u=>({...s,fixtures:u})).mapErr(u=>({error:u,kind:"fixture-failed"})),s=>Promise.resolve(T(s))):T({diagnostics:t.diagnostics,kind:"typecheck-failed"})}var ut=new Set([".local","debug","node_modules"]);function pt(e){return hr(e).toSorted((r,n)=>r.localeCompare(n)).join("|")}function hr(e){return(ge.existsSync(e)?ge.readdirSync(e,{withFileTypes:!0}):[]).flatMap(n=>{if(ut.has(n.name))return[];let t=z.join(e,n.name);if(n.isDirectory())return hr(t);let o=ge.statSync(t);return[`${t}:${String(o.mtimeMs)}:${String(o.size)}`]})}async function ft(e){try{let n=await ct(import.meta.url,{fsCache:!1,moduleCache:!1,sourceMaps:!0}).import(e),t=n!=null&&typeof n=="object"&&"default"in n?Reflect.get(n,"default"):n;return yr(t)}catch(r){return T({kind:"load-threw",message:mt(r)})}}function mt(e){return e instanceof Error?e.message:String(e)}function yt({entryPath:e,exported:r}){if(r==null||typeof r!="object"||!("lockfile"in r))return T({entryPath:e,kind:"not-ripplo"});let n=qe.safeParse(Reflect.get(r,"lockfile"));return n.success?yr(n.data):T({issues:n.error.issues.map(t=>`${t.path.join(".")}: ${t.message}`),kind:"invalid-lockfile"})}function E(e,r){return r==null?`Load \`/ripplo:${e}\` skill for instructions.`:`Load \`/ripplo:${e}\` skill for instructions on ${r}.`}function is(e){return e.length===1?E(e[0]):`Before proceeding, load the ${e.map(n=>`\`/ripplo:${n}\``).join(" and ")} skills \u2014 every one, each carries rules the others don't.`}function G(e){return[`Compilation failed: ${gt(e)}`,E("create","DSL authoring + lint rules")].join(`
|
|
6
|
+
`)}function ds(){return`${v} is up to date`}function us(e){return[`${v} is ${e==="missing"?"missing":"out of date"} \u2014 run \`npx ripplo compile\` and commit the result`,E("setup")].join(`
|
|
7
|
+
`)}function ps(){return`Wrote ${v}`}function gt(e){switch(e.kind){case"typecheck-failed":return["TypeScript errors in .ripplo/:",...kr(e.diagnostics)].join(`
|
|
8
|
+
`);case"not-ripplo":return`${e.entryPath} must default-export a Ripplo (createRipplo({ entities, singletons, workflows })). Check that the default export is the value returned by createRipplo, not a function or a re-export.`;case"invalid-lockfile":return["Lockfile failed schema validation (stale or hand-edited .ripplo/ripplo.lock?):",...kr(e.issues),"Regenerate with `npx ripplo compile` \u2014 never hand-edit the lockfile."].join(`
|
|
9
|
+
`);case"load-threw":return[`.ripplo/index.ts threw while loading: ${e.message}`,"Usually a bad import or a top-level throw in .ripplo/ \u2014 run `npx ripplo compile` for the stack."].join(`
|
|
10
|
+
`);case"fixture-failed":return ht(e.error)}}function kr(e,r=8){return e.length<=r?e:[...e.slice(0,r),`\u2026 and ${String(e.length-r)} more`]}function ht(e){switch(e.kind){case"fixture-missing":return`Fixture "${e.name}" not found at ${e.path} \u2014 add the file under .ripplo/fixtures/ or fix the upload() name.`;case"fixture-invalid-name":return`Invalid fixture name "${e.name}" \u2014 upload() takes a bare name under .ripplo/fixtures/, no .. or absolute paths.`;case"fixture-symlink":return`Fixture "${e.name}" is a symlink \u2014 only regular files are allowed.`;case"fixture-not-file":return`Fixture "${e.name}" is not a regular file.`;case"fixture-too-large":return`Fixture "${e.name}" is ${J(e.size)} \u2014 over the ${J(me)} per-file limit.`;case"fixtures-total-too-large":return`Fixtures total ${J(e.total)} \u2014 over the ${J(ye)} limit.`}}function J(e){return`${String(Math.round(e/(1024*1024)*10)/10)} MB`}var Q=class extends Error{failure;constructor(r){super(r.kind),this.name="CliError",this.failure=r}};function ks(e){return e instanceof Q?he(e.failure):e instanceof Error?e.message:String(e)}function he(e){switch(e.kind){case"project-file-missing":return[`Missing ${e.path} \u2014 this directory is not a Ripplo project.`,"Run `npx ripplo init` to create it (or cd into the project root).",E("setup")].join(`
|
|
11
|
+
`);case"project-file-invalid":return[`${e.path} is invalid:`,...e.issues.map(r=>` ${r}`),"Fix the file by hand or re-run `npx ripplo init`."].join(`
|
|
12
|
+
`);case"not-authenticated":return["Not signed in. Run `npx ripplo auth login`.","(Claude Code: run it yourself in the background \u2014 the user just approves in the browser.)"].join(`
|
|
13
|
+
`);case"env-invalid":return kt(e);case"playwright-install-failed":return["Playwright browser install failed \u2014 Chromium is still missing.","Run `npx playwright install chromium` and check its output for network, proxy, or disk-space errors."].join(`
|
|
14
|
+
`);case"gitdir-unrecognized":return`Unrecognized .git file at ${e.marker} \u2014 expected a directory or a "gitdir:" pointer (worktree). Is the repo corrupted?`;case"gitdir-empty":return`Empty gitdir pointer at ${e.marker} \u2014 the worktree's .git file points nowhere. Re-create the worktree.`;case"oauth-device-code-failed":return[`Could not start sign-in (device-code request failed): ${e.description}`,"Is the Ripplo server reachable? Check RIPPLO_SERVER_URL and retry."].join(`
|
|
15
|
+
`);case"oauth-authorization-failed":return[`Sign-in failed (${e.code}): ${e.description}`,e.code==="expired_token"?"The approval window expired \u2014 run `npx ripplo auth login` again.":"Run `npx ripplo auth login` to retry."].join(`
|
|
16
|
+
`);case"compilation-failed":return G(e.error)}}function kt(e){let r=e.missingEnvFiles.length===0?[]:["Declared env files not found:",...e.missingEnvFiles.map(n=>` ${n}`),"In a git worktree? Env files aren't copied from the main checkout \u2014 recreate them, or symlink to a shared file outside the working tree."];return["Env config invalid:",...e.issues.map(n=>` ${n}`),"Add the missing values to the env files declared in .ripplo/project.json.",...r].join(`
|
|
17
|
+
`)}import{err as xt,ok as bt}from"neverthrow";import{z as ke}from"zod";var St="https://ripplo.ai";function Rr(){return br().RIPPLO_SERVER_URL}function xr(){return br().RIPPLO_PROJECT_ID}var Rt=ke.object({RIPPLO_PROJECT_ID:ke.string().min(1).optional(),RIPPLO_SERVER_URL:ke.string().min(1).default(St)}),Sr;function br(){return Sr??=Rt.parse(process.env),Sr}import vr from"fs";import Se from"path";function Er(e){let r=vr.realpathSync(e),n=r,t=Se.dirname(n);for(;t!==n;){if(vr.existsSync(Se.join(n,".git")))return n;n=t,t=Se.dirname(n)}return r}function Ts(e){return ce(e).andThen(r=>V().andThen(n=>{let t=Rr(),o=He(t);return o==null?xt({kind:"not-authenticated"}):bt({appUrl:n.appUrl,cwd:Er(e),engineUrl:n.engineUrl,projectId:xr()??r.projectId,ripploServerUrl:t,token:o,tunnelAuth:void 0,webhookSecret:n.webhookSecret})}))}import wr from"fs";import{checkSync as vt,lockSync as Et}from"proper-lockfile";var wt="dev.pid",Pr=15e3;function Ir(e){return S(e,wt)}function Cr(e){try{return vt(Ir(e),{realpath:!1,stale:Pr})}catch{return!1}}var Re=class extends Error{pid;cwd;constructor({cwd:r,pid:n}){super("dev-lock-held"),this.name="DevLockHeldError",this.pid=n,this.cwd=r}};function _s({cwd:e,onCompromised:r}){Oe(e);let n=Ir(e),t=Pt({cwd:e,onCompromised:r,path:n});return wr.writeFileSync(n,String(process.pid)),()=>{try{t()}catch{}}}function Pt({cwd:e,onCompromised:r,path:n}){try{return Et(n,{realpath:!1,stale:Pr,onCompromised:()=>{r()}})}catch(t){throw It(t)?new Re({cwd:e,pid:Ct(n)}):t}}function It(e){if(!(e instanceof Error)||!("code"in e))return!1;let{code:r}=e;return r==="ELOCKED"}function Ct(e){try{let r=wr.readFileSync(e,"utf8").trim(),n=Number.parseInt(r,10);return Number.isFinite(n)&&n>0?n:null}catch{return null}}import At from"p-queue";var jt=4,Tt={"p0-ui":3,"p1-cli":2,"p2-cover":1,"p3-explore":0},X=new At({concurrency:jt}),k={headedActive:0,interactiveActive:0,interactiveQueued:0},Ar={current:null};function Ds({headed:e,task:r,workClass:n}){let t=Tt[n];return n==="p3-explore"?X.add(r,{priority:t}):(k.interactiveQueued+=1,Y(),X.add(()=>Ft({headed:e,task:r}),{priority:t}))}function Hs(e){!Number.isFinite(e)||e<1||(X.concurrency=Math.floor(e),Y())}function xe(){return{active:k.interactiveActive,headedActive:k.headedActive,poolSize:X.concurrency,queued:k.interactiveQueued}}function Us(e){Ar.current=e}async function Ft({headed:e,task:r}){k.interactiveQueued-=1,k.interactiveActive+=1,k.headedActive+=e?1:0,Y();try{return await r()}finally{k.interactiveActive-=1,k.headedActive-=e?1:0,Y()}}function Y(){Ar.current?.()}import be from"fs";import ve from"path";function jr(e){try{let r=Lt(e);if(r==null)return;let n=ve.join(r,"HEAD"),t=be.readFileSync(n,"utf8").trim(),o="ref: refs/heads/";return t.startsWith(o)?t.slice(o.length):t.length===0?void 0:t.slice(0,7)}catch{return}}function Lt(e){let r=ve.join(e,".git");if(be.statSync(r).isDirectory())return r;let t=be.readFileSync(r,"utf8").trim(),o="gitdir:";if(!t.startsWith(o))return;let i=t.slice(o.length).trim();if(i.length!==0)return ve.resolve(e,i)}import Mt from"crypto";import{readFile as Tr}from"fs/promises";import Fr from"path";import{graphql as $t}from"gql.tada";import{err as _t,ok as Ot}from"neverthrow";var Nt=$t(`
|
|
18
|
+
mutation SyncDevSession(
|
|
19
|
+
$projectId: String!
|
|
20
|
+
$cwd: String!
|
|
21
|
+
$branch: String
|
|
22
|
+
$lockfileContent: String
|
|
23
|
+
$fixtures: [SyncDevFixtureInput!]
|
|
24
|
+
$preconditions: [SyncDevPreconditionInput!]!
|
|
25
|
+
$singletons: [SyncDevSingletonInput!]
|
|
26
|
+
$workflows: [SyncDevWorkflowInput!]!
|
|
27
|
+
) {
|
|
28
|
+
syncDevSession(
|
|
29
|
+
projectId: $projectId
|
|
30
|
+
cwd: $cwd
|
|
31
|
+
branch: $branch
|
|
32
|
+
lockfileContent: $lockfileContent
|
|
33
|
+
fixtures: $fixtures
|
|
34
|
+
preconditions: $preconditions
|
|
35
|
+
singletons: $singletons
|
|
36
|
+
workflows: $workflows
|
|
37
|
+
) {
|
|
38
|
+
id
|
|
39
|
+
hooksPaused
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`);async function nl(e,r){let n=await F(e);if(n.isErr())return _t({error:n.error,kind:"compilation-failed"});let t=await Ee({config:r,cwd:e,lockfile:n.value});return Ot({devSessionId:t.devSessionId,lockfile:n.value})}async function Ee(e){let r=Be(e.lockfile);return Ht({config:e.config,cwd:e.cwd,fixtures:e.lockfile.fixtures,payload:r})}function Dt(e){return Mt.createHash("sha256").update(JSON.stringify(e)).digest("hex")}async function Ht({config:e,cwd:r,fixtures:n,payload:t}){let o=Dt(t),i=jr(r),s=await Wt(r),l=await Ut(r,n),u=await f({config:e,document:Nt,variables:{branch:i??null,cwd:r,fixtures:l,lockfileContent:s,preconditions:t.preconditions.map(d=>({depends:[...d.depends],description:d.description,name:d.name,returns:[...d.returns]})),projectId:e.projectId,singletons:t.singletons.map(d=>({defaultValue:d.defaultValue,description:d.description,name:d.name,type:d.type})),workflows:t.workflows.map(d=>({expectedOutcome:d.expectedOutcome,name:d.name,preconditions:[...d.preconditions],requiresKeys:d.requiresKeys.map(m=>({namespace:m.namespace,preconditionName:m.preconditionName})),slug:d.slug,sourcePath:d.sourcePath,spec:JSON.stringify(d.spec)}))}});if(u.syncDevSession==null)throw new Error("syncDevSession returned null");return{devSessionId:u.syncDevSession.id,hash:o,hooksPaused:u.syncDevSession.hooksPaused}}async function Ut(e,r){let n=Object.entries(r);return Promise.all(n.map(async([t,o])=>({contentBase64:(await Tr(Fr.join(e,fe,t))).toString("base64"),sha256:o.sha256})))}async function Wt(e){try{return await Tr(Fr.join(e,v),"utf8")}catch{return null}}import{randomUUID as xo}from"crypto";import{createId as bo}from"@paralleldrive/cuid2";import{CancellationTokenSource as vo,ResponseError as Eo}from"vscode-jsonrpc/node";import{graphql as qt}from"gql.tada";var Bt=qt(`
|
|
43
|
+
mutation DaemonCreateRun(
|
|
44
|
+
$id: String
|
|
45
|
+
$workflowId: String!
|
|
46
|
+
$testId: String
|
|
47
|
+
$clientVersion: String
|
|
48
|
+
$executor: RunExecutor
|
|
49
|
+
$target: RunTarget
|
|
50
|
+
$lockfileHash: String
|
|
51
|
+
) {
|
|
52
|
+
createRun(
|
|
53
|
+
id: $id
|
|
54
|
+
workflowId: $workflowId
|
|
55
|
+
testId: $testId
|
|
56
|
+
executor: $executor
|
|
57
|
+
target: $target
|
|
58
|
+
clientVersion: $clientVersion
|
|
59
|
+
lockfileHash: $lockfileHash
|
|
60
|
+
) {
|
|
61
|
+
__typename
|
|
62
|
+
... on MutationCreateRunSuccess {
|
|
63
|
+
data {
|
|
64
|
+
id
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
... on LimitExceededError {
|
|
68
|
+
code
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`);async function Lr(e){try{let n=(await f({config:e.config,document:Bt,variables:Vt(e)})).createRun;return n==null?Z({detail:"create-run-null",type:"generic"}):n.__typename==="MutationCreateRunSuccess"?null:n.__typename==="LimitExceededError"?Z({code:n.code,type:"limit"}):Z({detail:n.__typename,type:"generic"})}catch(r){return Kt(r)}}function Vt({executor:e,lockfileHash:r,runId:n,target:t}){return{clientVersion:K(),executor:e,id:n,lockfileHash:r,target:e==="cloud"?"tunnel":void 0,testId:t.testId,workflowId:t.workflowId}}function Z(e){return{kind:"dispatch-error",reason:e}}function Kt(e){return e instanceof _e?{detail:e.message,kind:"infra-error"}:Z({detail:e instanceof Error?e.message:String(e),type:"generic"})}import{createMessageConnection as zt,NotificationType as Mr,RequestType as $r,RequestType0 as _r,SocketMessageReader as Jt,SocketMessageWriter as Gt}from"vscode-jsonrpc/node";import{z as a}from"zod";var Qt="daemon.sock",Xt="daemon.log";function ul(e){return S(e,Qt)}function pl(e){return S(e,Xt)}function Or(e){return zt(new Jt(e),new Gt(e))}var Nr=a.object({all:a.boolean(),headed:a.boolean(),tests:a.array(a.string())}),fl=a.object({jobId:a.string(),total:a.number()}),Yt=a.enum(["holder","standby","off"]),Zt=a.object({covered:a.number(),deferred:a.number(),findings:a.number(),saturated:a.boolean(),total:a.number()}),ml=a.object({active:a.number(),explorer:Yt,exploring:a.number(),progress:Zt,queued:a.number(),sseHealth:a.object({detail:a.string().optional(),ok:a.boolean()}).optional(),version:a.string().optional()}),eo=a.enum(["MAX_RUNS","OVERAGE_CAP","MAX_AGENTS","MAX_CONCURRENT_RUNS","MAX_PROJECTS"]),ro=a.discriminatedUnion("type",[a.object({code:eo,type:a.literal("limit")}),a.object({detail:a.string(),type:a.literal("generic")})]),we=a.discriminatedUnion("kind",[a.object({kind:a.literal("pass")}),a.object({findingLines:a.array(a.string()),kind:a.literal("findings")}),a.object({detail:a.string(),kind:a.literal("error")}),a.object({kind:a.literal("dispatch-error"),reason:ro}),a.object({detail:a.string(),kind:a.literal("dispatch-timeout")}),a.object({detail:a.string(),kind:a.literal("infra-error")})]),no=a.discriminatedUnion("kind",[a.object({kind:a.literal("test-started"),runId:a.string(),testName:a.string(),workflowName:a.string()}),a.object({kind:a.literal("test-outcome"),outcome:we,runId:a.string(),testName:a.string(),workflowName:a.string()})]),yl=a.object({event:no,jobId:a.string()}),gl=a.object({failed:a.number(),jobId:a.string(),notRun:a.number(),passed:a.number()}),hl=a.discriminatedUnion("code",[a.object({code:a.literal("compile-failed"),detail:a.string(),diagnostics:a.array(a.string()).default([])}),a.object({code:a.literal("selection-conflicting-flags")}),a.object({code:a.literal("selection-nothing-selected")}),a.object({code:a.literal("selection-unknown-ids"),known:a.array(a.string()),unknown:a.array(a.string())}),a.object({code:a.literal("scope-failed"),detail:a.string()}),a.object({code:a.literal("app-unreachable"),detail:a.string(),url:a.string()}),a.object({code:a.literal("sync-failed"),detail:a.string()}),a.object({code:a.literal("bad-message")})]),Dr=a.object({findingId:a.string().min(1)}),kl=a.discriminatedUnion("kind",[a.object({kind:a.literal("resolved")}),a.object({kind:a.literal("unreachable")}),a.object({kind:a.literal("still-failing"),runId:a.string().optional()}),a.object({kind:a.literal("diverged"),runId:a.string().optional()}),a.object({kind:a.literal("flaky")}),a.object({kind:a.literal("aborted")}),a.object({kind:a.literal("finding-not-found")}),a.object({kind:a.literal("unreplayable"),reason:a.enum(["base-state-missing","action-missing","ledger-unreadable"])}),a.object({kind:a.literal("error"),reason:a.string()})]),Hr=new $r("ripplo/exploreReplay"),Ur=new $r("ripplo/enqueue"),Wr=new _r("ripplo/status"),qr=new _r("ripplo/shutdownIfIdle"),Br=new Mr("ripplo/jobEvent"),Vr=new Mr("ripplo/jobDone");import{graphql as to}from"gql.tada";async function Kr(e,r){let t=(await f({config:e,document:oo,variables:{cwd:r,projectId:e.projectId}})).project?.devSession?.workflows??[];return new Map(t.flatMap(o=>o.tests.map(i=>[`${o.slug}/${i.slug}`,{testId:i.id,workflowId:o.id}])))}var oo=to(`
|
|
73
|
+
query DaemonWorkflows($projectId: String!, $cwd: String!) {
|
|
74
|
+
project(id: $projectId) {
|
|
75
|
+
id
|
|
76
|
+
devSession(cwd: $cwd) {
|
|
77
|
+
id
|
|
78
|
+
workflows {
|
|
79
|
+
id
|
|
80
|
+
slug
|
|
81
|
+
tests {
|
|
82
|
+
id
|
|
83
|
+
slug
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`);import{CancellationTokenSource as io}from"vscode-jsonrpc/node";function Pe(e){return`${e.workflowSlug}/${e.testSlug}`}function zr(e){let{headed:r,inflight:n,jobId:t,lockfileHashValue:o,onExpire:i,runId:s,selection:l,timeoutMs:u}=e,d=Pe(l),m=`${d}@${o}@${String(r)}`,p=n.get(m);if(p!=null)return p.jobIds.add(t),null;let g={cancellation:new io,claimed:!1,claimKey:d,headed:r,inflightKey:m,jobIds:new Set([t]),runId:s,testName:l.testName,timer:null,workflowName:l.workflowName};return g.timer=setTimeout(()=>{ee(n,g),i(g)},u),n.set(m,g),g}function ee(e,r){r.timer!=null&&(clearTimeout(r.timer),r.timer=null),e.delete(r.inflightKey)}function Ie(e,r){let n=[...e.values()].find(t=>t.runId===r&&!t.claimed);return n==null?null:(n.claimed=!0,n.timer!=null&&(clearTimeout(n.timer),n.timer=null),n)}function Jr(e,r){[...e.values()].filter(n=>n.jobIds.has(r)).forEach(n=>{n.jobIds.delete(r),n.jobIds.size===0&&(ee(e,n),n.cancellation.cancel())})}import{err as Ce,ok as Gr}from"neverthrow";function Xr({all:e,ids:r,lockfile:n}){if(e&&r.length>0)return Ce({kind:"conflicting-flags"});if(e)return Gr(n.workflows.filter(i=>!i.stub).flatMap(i=>i.tests.map(s=>I(s))));if(r.length===0)return Ce({kind:"nothing-selected"});let t=r.map(i=>({id:i,refs:so(n,i)})),o=t.filter(i=>i.refs.length===0).map(i=>i.id);return o.length>0?Ce({kind:"unknown-ids",known:ao(n),unknown:o}):Gr([...new Set(t.flatMap(i=>i.refs))])}function Yr(e,r){let n=new Map(oe(e).map(t=>[t.ref,{testName:t.test.name,testSlug:t.test.slug,workflowName:t.workflow.name,workflowSlug:h(t.workflow.name)}]));return r.map(t=>{let o=n.get(t);if(o==null)throw new Error(`selectionsFor: ref not in lockfile: ${t}`);return o})}function ao(e){return e.workflows.map(r=>h(r.name))}function so(e,r){let n=e.workflows.find(t=>t.name===r||h(t.name)===h(r));return n!=null?n.tests.map(t=>I(t)):oe(e).filter(t=>t.ref===r||Qr(t.ref)===Qr(r)).map(t=>t.ref)}function Qr(e){let r=e.lastIndexOf("/");return r===-1?h(e):`${h(e.slice(0,r))}/${h(e.slice(r+1))}`}import{err as Ae,ok as en}from"neverthrow";import{graphql as rn}from"gql.tada";import{execFileSync as lo}from"child_process";var co=256*1024*1024;function re(e,r){return lo("git",[...e],{cwd:r,encoding:"utf8",maxBuffer:co,stdio:["ignore","pipe","pipe"]})}async function nn({config:e,cwd:r,lockfile:n}){await po({config:e,cwd:r,lockfile:n});let t=await mo(e);if(t.isErr())return Ae(t.error);let o=new Map(n.workflows.filter(s=>!s.stub).map(s=>[h(s.name),s])),i=[...new Set(t.value)].flatMap(s=>{let l=o.get(s);return l==null?[]:l.tests.map(u=>I(u))});return i.length===0?Ae({kind:"scope-empty"}):en(i)}var uo=rn(`
|
|
90
|
+
mutation AddDirtyTestsToScope($projectId: String!, $cwd: String!, $workflowSlugs: [String!]!) {
|
|
91
|
+
addDirtyTestsToScope(projectId: $projectId, cwd: $cwd, workflowSlugs: $workflowSlugs) {
|
|
92
|
+
__typename
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`);async function po({config:e,cwd:r,lockfile:n}){let t=new Set(yo(r)),o=n.workflows.filter(i=>i.sourcePath!=null&&t.has(i.sourcePath)).map(i=>h(i.name));o.length!==0&&await f({config:e,document:uo,variables:{cwd:e.cwd,projectId:e.projectId,workflowSlugs:o}}).catch(i=>{y.warn({err:i},"auto-scope of dirty tests failed")})}var fo=rn(`
|
|
96
|
+
query ScopeSelection($projectId: String!, $cwd: String!) {
|
|
97
|
+
project(id: $projectId) {
|
|
98
|
+
id
|
|
99
|
+
devSession(cwd: $cwd) {
|
|
100
|
+
id
|
|
101
|
+
scopeItems {
|
|
102
|
+
id
|
|
103
|
+
workflow {
|
|
104
|
+
id
|
|
105
|
+
slug
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
`);async function mo(e){try{let n=(await f({config:e,document:fo,variables:{cwd:e.cwd,projectId:e.projectId}})).project?.devSession?.scopeItems??[];return en(n.flatMap(t=>t.workflow==null?[]:[t.workflow.slug]))}catch(r){return Ae({detail:r instanceof Error?r.message:String(r),kind:"scope-fetch-failed"})}}var Zr=".ripplo/workflows/";function yo(e){try{return re(["status","--porcelain","--",".ripplo/workflows"],e).split(`
|
|
112
|
+
`).map(r=>r.slice(3).trim()).filter(r=>r.startsWith(Zr)&&r.endsWith(".ts")).map(r=>r.slice(Zr.length)).filter(r=>r!=="index.ts"&&!r.endsWith("/index.ts"))}catch{return[]}}import{graphql as go}from"gql.tada";var ho=2e3,ko=go(`
|
|
113
|
+
query DaemonCloudRunStatus($runId: String!) {
|
|
114
|
+
run(id: $runId) {
|
|
115
|
+
status
|
|
116
|
+
failureReason
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
`);function on({config:e,onComplete:r,onStarted:n,runId:t,signal:o}){let i=!1,s,l=!1,u=async()=>{if(i||o.aborted)return;let d=await So(e,t).catch(()=>"unknown");if(!l&&(d==="running"||tn(d))&&(l=!0,n()),tn(d)){i=!0,r(Ro(d));return}s=setTimeout(()=>{u()},ho)};return u(),{stop:()=>{i=!0,s!=null&&clearTimeout(s)}}}async function So(e,r){let t=(await f({config:e,document:ko,variables:{runId:r}})).run?.status;return t??"unknown"}function tn(e){return e==="passed"||e==="failed"||e==="warning"||e==="cancelled"}function Ro(e){return e==="passed"?{kind:"pass"}:e==="failed"?{detail:"failed",kind:"error"}:e==="warning"?{findingLines:[],kind:"findings"}:e==="cancelled"?{detail:"cancelled",kind:"error"}:{detail:"unknown",kind:"error"}}var wo=12e4,Po=-32099;function ln(e){let r=new AbortController;return e.isCancellationRequested?(r.abort(),r.signal):(e.onCancellationRequested(()=>{r.abort()}),r.signal)}function tc(e){let r={...e,inflight:new Map,jobs:new Map};return{claim:n=>To(r,n),handleConnection:n=>{Io(r,n)},idle:()=>cn(r)}}function Io(e,r){let n=Or(r);n.onRequest(Ur,(t,o)=>Co({connection:n,ctx:e,params:t,token:o})),n.onRequest(Wr,()=>{let t=xe();return{active:t.active,queued:t.queued,sseHealth:e.sseHealth(),version:K(),...e.explorationStatus()}}),n.onRequest(Hr,async(t,o)=>{let i=Dr.safeParse(t);return i.success?(await e.ready,e.replayFinding(i.data.findingId,ln(o))):{kind:"error",reason:"bad-message"}}),n.onRequest(qr,()=>{let t=cn(e);return t&&e.onShutdownRequest(),t}),n.onClose(()=>{Ao(e,n)}),n.onError(t=>{y.warn({err:t},"ipc connection error")}),r.on("error",t=>{y.warn({err:t},"ipc socket error")}),n.listen()}function cn(e){let r=xe();return e.jobs.size===0&&r.active===0&&r.queued===0}async function Co({connection:e,ctx:r,params:n,token:t}){let o=Nr.safeParse(n);if(!o.success)throw an({code:"bad-message"});await r.ready;let i=await Lo({config:r.config,cwd:r.cwd,message:o.data});if(i.kind==="error")throw an(i.error);let s=xo(),l=new vo;return t.onCancellationRequested(()=>{dn(r,s)}),r.jobs.set(s,{cancellation:l,connection:e,failed:0,notRun:0,passed:0,total:i.selections.length}),Uo({ctx:r,headed:o.data.headed,jobId:s,lockfileHashValue:i.lockfileHashValue,selections:i.selections,targetsByClaimKey:i.targetsByClaimKey,token:l.token}).catch(u=>{y.error({err:u},"ipc dispatch failed")}),{jobId:s,total:i.selections.length}}function an(e){return new Eo(Po,e.code,e)}function dn(e,r){let n=e.jobs.get(r);n!=null&&(n.cancellation.cancel(),e.jobs.delete(r),Jr(e.inflight,r))}function Ao(e,r){[...e.jobs.entries()].filter(([,n])=>n.connection===r).forEach(([n])=>{dn(e,n)})}function un(e,r,n){let t=e.jobs.get(r);t!=null&&(sn(()=>t.connection.sendNotification(Br,{event:n,jobId:r})),n.kind==="test-outcome"&&(jo(t,n.outcome.kind),t.passed+t.failed+t.notRun>=t.total&&(sn(()=>t.connection.sendNotification(Vr,{failed:t.failed,jobId:r,notRun:t.notRun,passed:t.passed})),e.jobs.delete(r))))}function sn(e){e().catch(r=>{y.warn({err:r},"ipc notification failed")})}function jo(e,r){if(r==="pass"){e.passed+=1;return}if(r==="dispatch-error"||r==="dispatch-timeout"||r==="infra-error"){e.notRun+=1;return}e.failed+=1}function w(e,r,n){r.jobIds.forEach(t=>{un(e,t,n)})}function To(e,r){let n=Ie(e.inflight,r);return n==null?null:{headed:n.headed,token:n.cancellation.token,finished:(t,o)=>{e.inflight.delete(n.inflightKey),w(e,n,{kind:"test-outcome",outcome:o,runId:n.runId,testName:n.testName,workflowName:n.workflowName})},started:()=>{w(e,n,{kind:"test-started",runId:n.runId,testName:n.testName,workflowName:n.workflowName})}}}function Fo(e){return e.kind==="typecheck-failed"?e.diagnostics.slice(0,5):e.kind==="invalid-lockfile"?e.issues.slice(0,5):e.kind==="load-threw"?[e.message]:[]}async function Lo({config:e,cwd:r,message:n}){return(await gr(r)).match(o=>Mo({config:e,cwd:r,lockfile:o,message:n}),o=>Promise.resolve({error:{code:"compile-failed",detail:o.kind,diagnostics:[...Fo(o)]},kind:"error"}))}async function Mo({config:e,cwd:r,lockfile:n,message:t}){let o=await _o(e.appUrl);if(o!=null)return{error:{code:"app-unreachable",detail:o,url:e.appUrl},kind:"error"};let i=await Oo({config:e,cwd:r,lockfile:n});return i!=null?{error:{code:"sync-failed",detail:i},kind:"error"}:(await No({config:e,cwd:r,lockfile:n,message:t})).match(async l=>({kind:"ready",lockfileHashValue:_(n),selections:Yr(n,l),targetsByClaimKey:await Kr(e,r)}),l=>Promise.resolve({error:l,kind:"error"}))}var $o=2e3;async function _o(e){try{return await fetch(e,{method:"HEAD",signal:AbortSignal.timeout($o)}),null}catch(r){return r instanceof Error?r.message:String(r)}}async function Oo(e){try{return await Ee(e),null}catch(r){return r instanceof Error?r.message:String(r)}}async function No({config:e,cwd:r,lockfile:n,message:t}){return!t.all&&t.tests.length===0?(await nn({config:e,cwd:r,lockfile:n})).mapErr(Do):Xr({all:t.all,ids:t.tests,lockfile:n}).mapErr(Ho)}function Do(e){return e.kind==="scope-empty"?{code:"selection-nothing-selected"}:{code:"scope-failed",detail:e.detail}}function Ho(e){switch(e.kind){case"conflicting-flags":return{code:"selection-conflicting-flags"};case"nothing-selected":return{code:"selection-nothing-selected"};case"unknown-ids":return{code:"selection-unknown-ids",known:[...e.known],unknown:[...e.unknown]}}}async function Uo(e){await e.selections.reduce((r,n)=>r.then(()=>Wo(e,n)),Promise.resolve())}async function Wo(e,r){let{ctx:n,headed:t,jobId:o,lockfileHashValue:i,targetsByClaimKey:s,token:l}=e;if(l.isCancellationRequested)return;let u=Pe(r),d=s.get(u);if(d==null){un(n,o,{kind:"test-outcome",outcome:{kind:"dispatch-error",reason:{detail:"test-not-found",type:"generic"}},runId:"",testName:r.testName,workflowName:r.workflowName});return}let m=zr({headed:t,inflight:n.inflight,jobId:o,lockfileHashValue:i,runId:bo(),selection:r,timeoutMs:wo,onExpire:g=>{w(n,g,{kind:"test-outcome",outcome:{detail:"dispatch-timeout",kind:"dispatch-timeout"},runId:"",testName:g.testName,workflowName:g.workflowName})}});if(m==null)return;let p=await qo(n,d,m.runId,i);if(p!=null){ee(n.inflight,m),w(n,m,{kind:"test-outcome",outcome:p,runId:"",testName:r.testName,workflowName:r.workflowName});return}n.executor==="cloud"&&Bo(n,m)}function qo(e,r,n,t){return Lr({config:e.config,executor:e.executor,lockfileHash:t,runId:n,target:r})}function Bo(e,r){let n=Ie(e.inflight,r.runId);n!=null&&on({config:e.config,runId:n.runId,signal:ln(n.cancellation.token),onComplete:t=>{e.inflight.delete(n.inflightKey),w(e,n,{kind:"test-outcome",outcome:t,runId:n.runId,testName:n.testName,workflowName:n.workflowName})},onStarted:()=>{w(e,n,{kind:"test-started",runId:n.runId,testName:n.testName,workflowName:n.workflowName})}})}function Vo(e){let{backoffActive:r,explorerHolder:n,headedActive:t,interactiveActive:o,interactiveQueued:i}=e,{explorationActive:s,exploreConcurrency:l,poolSize:u}=e;if(!n||t||i>0)return{abortCount:s,refillCount:0};if(r)return{abortCount:0,refillCount:0};let d=Math.min(l,u-1,u-o);return{abortCount:0,refillCount:Math.max(0,d-s)}}function ic(e){let r={active:new Map,backoffUntil:0,cancelBackoffTimer:null,cancelHeartbeat:null,holder:!1,prevInteractiveActive:e.probe().interactiveActive,stopped:!1};return mn(r,e),{explorationActive:()=>r.active.size,explorerHolder:()=>r.holder,notifyQueueChange:()=>{Ko(r,e)},setExplorerHolder:n=>{r.holder=n,L(r,e)},stop:()=>{r.stopped=!0,r.cancelBackoffTimer?.(),r.cancelBackoffTimer=null,r.cancelHeartbeat?.(),r.cancelHeartbeat=null,yn(r,r.active.size)}}}function mn(e,r){e.stopped||(e.cancelHeartbeat=r.setTimer(()=>{L(e,r),mn(e,r)},15e3))}function L(e,r){if(e.stopped)return;let n=r.probe(),t=Vo({backoffActive:r.now()<e.backoffUntil,explorationActive:e.active.size,exploreConcurrency:r.exploreConcurrency,explorerHolder:e.holder&&r.exploreEnabled,headedActive:n.headedActive>0,interactiveActive:n.interactiveActive,interactiveQueued:n.interactiveQueued,poolSize:n.poolSize});yn(e,t.abortCount),gn({count:t.refillCount,params:r,state:e})}function yn(e,r){[...e.active.values()].slice(0,r).forEach(({controller:n})=>{n.abort()})}function Ko(e,r){let n=r.probe();n.interactiveActive<e.prevInteractiveActive&&zo(e,r),e.prevInteractiveActive=n.interactiveActive,L(e,r)}function zo(e,r){e.backoffUntil=r.now()+3e4,e.cancelBackoffTimer?.(),e.cancelBackoffTimer=r.setTimer(()=>{e.cancelBackoffTimer=null,L(e,r)},3e4)}function gn({count:e,params:r,state:n}){if(e<=0)return;let t=Jo(r.sources);t!=null&&(Go({params:r,pulled:t,state:n}),gn({count:e-1,params:r,state:n}))}function Jo(e){return e.reduce((r,n)=>{if(r!=null)return r;let t=n.next();return t==null?null:{job:t,source:n}},null)}function Go({params:e,pulled:r,state:n}){let{job:t,source:o}=r,i=new AbortController;n.active.set(t.id,{controller:i,job:t,source:o}),e.execute({job:t,priority:o.priority,signal:i.signal}).then(()=>{fn({job:t,outcome:pn(i.signal,null),params:e,source:o,state:n})}).catch(s=>{fn({job:t,outcome:pn(i.signal,{error:s}),params:e,source:o,state:n})})}function pn(e,r){return e.aborted?{kind:"aborted"}:r==null?{kind:"completed"}:{error:r.error,kind:"error"}}function fn({job:e,outcome:r,params:n,source:t,state:o}){o.active.delete(e.id),t.onResult(e,r),L(o,n)}import Qo from"fs";import Xo from"path";async function fc(e){let r=Xo.join(e,".ripplo","index.ts");if(!Qo.existsSync(r))return{appUrl:void 0,engineUrl:void 0,errors:[{message:".ripplo/index.ts not found",path:""}],valid:!1,warnings:[]};let n=await F(e);return n.isErr()?{appUrl:void 0,engineUrl:void 0,errors:[{message:G(n.error),path:".ripplo/"}],valid:!1,warnings:[]}:V().match(t=>({appUrl:t.appUrl,engineUrl:t.engineUrl,errors:[],valid:!0,warnings:[]}),t=>({appUrl:void 0,engineUrl:void 0,errors:[{message:he(t),path:""}],valid:!1,warnings:[]}))}async function mc(e){try{await fetch(e,{method:"HEAD",signal:AbortSignal.timeout(5e3)});return}catch{return`appUrl (${e}) is not responding. Make sure your dev server is running on that port.`}}async function yc({appUrl:e,engineUrl:r}){let n=r.startsWith("http://")||r.startsWith("https://")?r:`${e}${r}`;try{return(await fetch(`${n}/setup`,{body:JSON.stringify({}),headers:{"Content-Type":"application/json"},method:"PUT",signal:AbortSignal.timeout(5e3)})).ok?"Engine endpoint accepted an unsigned request \u2014 webhook signature verification may be missing.":void 0}catch{return}}import ri from"fs";import Yo from"fs";import je from"path";var Zo=["MERGE_HEAD","rebase-merge","rebase-apply","CHERRY_PICK_HEAD","REVERT_HEAD"];function hn(e){let r=ei(e);return r==null?!1:Zo.some(n=>Yo.existsSync(je.join(r,n)))}function ei(e){try{let r=re(["rev-parse","--git-dir"],e).trim();return r.length===0?null:je.isAbsolute(r)?r:je.resolve(e,r)}catch{return null}}function ni(e){return S(e,"hooks-paused")}function wc(e){return ri.existsSync(ni(e))||hn(e)?!1:Cr(e)}import{graphql as te}from"gql.tada";import{gzip as di}from"zlib";import{promisify as ui}from"util";import{existsSync as xn,readFileSync as bn}from"fs";import Fe from"path";import{graphql as R}from"gql.tada";function kn(e){return[e.kind,e.target,e.value].filter(r=>r.length>0).join(" ")}var ti={"no-effect":"noEffect","required-state-unsatisfied":"requiredStateUnsatisfied",unresolvable:"unresolvable"},oi={"data-rule":"dataRule","page-rule":"pageRule",step:"step"},ii={aborted:"aborted","action-failed":"actionFailed","check-failed":"checkFailed","client-mount-missing":"clientMountMissing","conflicting-sessions":"conflictingSessions","driver-launch":"driverLaunch","engine-decode":"engineDecode","engine-http":"engineHttp","engine-network":"engineNetwork","engine-unreachable":"engineUnreachable","setup-missing-row":"setupMissingRow","state-identity":"stateIdentity"};function Sn(e){return e.kind==="consistency"?{consistency:{mismatch:li(e.mismatch),pending:e.pending}}:e.kind==="pending-check"?{pendingCheck:{budget:e.budget,source:oi[e.source.kind],...ai(e.source)}}:e.kind==="unrunnable"?{unrunnable:{reason:ti[e.reason]}}:e.kind==="driver-error"?{driverError:{errorKind:ii[e.error.kind],message:ci(e.error)}}:{impossibleAction:{subject:si(e.step.action)}}}function ai(e){return"check"in e?Rn(e.check,!1):{checkKind:void 0,expected:void 0,negated:void 0,subject:void 0}}function Rn(e,r){return e.kind==="not"?Rn(e.inner,!r):e.kind==="browser"?{checkKind:"browser",expected:e.value,negated:r,subject:e.name}:e.kind==="value"||e.kind==="text"?{checkKind:e.kind,expected:e.value,negated:r,subject:$(e.locator)}:{checkKind:e.kind,expected:void 0,negated:r,subject:$(e.locator)}}function si(e){let r=e.locator==null?e.url??"":$(e.locator);return`${e.kind} ${r}`.trim()}function li(e){return e.kind==="wrong-value"?{wrongValue:{entity:e.entity,field:e.field,key:e.key,snapshot:M(e.snapshot),sut:M(e.sut)}}:e.kind==="expected-change"?{expectedChange:{entity:e.entity,field:e.field,key:e.key,value:M(e.value)}}:e.kind==="singleton-mismatch"?{singletonMismatch:{singleton:e.singleton,snapshot:M(e.snapshot),sut:M(e.sut)}}:e.kind==="unexpected-row"?{unexpectedRow:{entity:e.entity,key:e.key}}:{missingRow:{entity:e.entity,key:e.key}}}function M(e){return e==null?null:String(e)}function ci(e){return"message"in e?e.message:"detail"in e?e.detail:null}async function pi({config:e,cwd:r,fixturesDir:n,headed:t,lockfile:o,runId:i,session:s,signal:l,test:u}){if(!await Li(e,i))return{kind:"dispatch-failed",reason:"already-claimed",runId:i};let m=Fe.join(r,".ripplo","debug"),p=[];return(await s.runOnce({capture:!0,lockfile:o,options:{baseUrl:e.appUrl,engineUrl:e.engineUrl,fixturesDir:n,generate:C,headed:t,secret:e.webhookSecret,tunnelAuth:e.tunnelAuth},params:void 0,runId:i,sequence:void 0,test:u,onEvent:P=>{p.push(P)}},l)).match(async P=>{await ne({config:e,debugDir:m,events:p,recordingOptional:!1,runId:i,stepSources:void 0});let $e=vn(p).flatMap(Wn=>Wn.findings);return $e.length>0?{findings:$e,kind:"findings",runId:i}:{kind:"pass",runId:i}},async P=>(await wn(e,i,Ke(P)),{error:P,kind:"error",runId:i}))}async function ne({config:e,debugDir:r,events:n,recordingOptional:t,runId:o,stepSources:i}){let s=vn(n),l=gi(r,o);if(l==null&&!t)throw new Error("recording-missing");await Ei({aliases:[...Si(n),...Ri(s)],config:e,generated:xi(n),generatedSingletons:bi(n),origin:l==null?yi(s):l.origin,records:s,rrwebEvents:l==null?[]:l.events,runId:o,stepSources:i}),l!=null&&await Ti(e,o,l),await Fi(e,o,s),await mi(e,r,o)}var fi=R(`
|
|
120
|
+
mutation ClipUploadUrl($runId: ID!) {
|
|
121
|
+
clipUploadUrl(runId: $runId)
|
|
122
|
+
}
|
|
123
|
+
`);async function mi(e,r,n){let t=Fe.join(r,n,"clip.gif");if(xn(t))try{let o=await f({config:e,document:fi,variables:{runId:n}});if(o.clipUploadUrl==null)return;let i=await fetch(o.clipUploadUrl,{body:new Uint8Array(bn(t)),headers:{"Content-Type":"image/gif"},method:"PUT"});i.ok||y.warn({runId:n,status:i.status},"Clip upload failed")}catch(o){y.warn({err:o,runId:n},"Clip upload skipped")}}function yi(e){return e.reduce((r,n)=>Math.min(r,n.startMs),e[0]?.startMs??0)}function vn(e){return e.flatMap(r=>r.kind==="step"?[{annotations:r.annotations,endMs:r.endMs,findings:r.findings,index:r.index,source:r.source,startMs:r.startMs,state:r.state,url:r.url}]:[])}function gi(e,r){let n=Fe.join(e,r,"behavior.jsonl");if(!xn(n))return null;let t=bn(n,"utf8").split(`
|
|
124
|
+
`).filter(i=>i.length>0).map(i=>hi(i)).flatMap(i=>ki(i)?[i.event]:[]),o=t[0];return o==null?null:{events:t,origin:o.timestamp}}function hi(e){return JSON.parse(e)}function ki(e){return typeof e=="object"&&e!=null&&Reflect.get(e,"kind")==="rrweb"}function Si(e){return e.flatMap(r=>r.kind==="world"?r.aliases:[])}function Ri(e){return e.flatMap(r=>{let n=vi(r.source);return n.flatMap(t=>{let i=n.filter(l=>l.entity===t.entity).indexOf(t),s=r.state.rows.filter(l=>l.status==="created"&&l.entity===t.entity).at(i);return s==null?[]:[{alias:t.as,entity:t.entity,key:s.key}]})})}function xi(e){return new Set(e.flatMap(r=>r.kind==="world"?r.generated.map(n=>En(n)):[]))}function En({entity:e,field:r,key:n}){return`${e}\0${n}\0${r}`}function bi(e){return new Set(e.flatMap(r=>r.kind==="world"?r.generatedSingletons:[]))}function vi(e){return e==null?[]:e.expect.flatMap(r=>Te(r))}function Te(e){return e.kind==="state"&&e.assertion.kind==="created"?[{as:e.assertion.as,entity:e.entity}]:e.kind==="and"?e.predicates.flatMap(r=>Te(r)):e.kind==="when"?e.branches.flatMap(r=>r.consequence.flatMap(n=>Te(n))):[]}async function Ei({aliases:e,config:r,generated:n,generatedSingletons:t,origin:o,records:i,rrwebEvents:s,runId:l,stepSources:u}){let d=i.map((m,p)=>Ci({aliases:e,generated:n,generatedSingletons:t,origin:o,record:m,rrwebEvents:s,sourceTest:u?.[p]??null}));await f({config:r,document:$i,variables:{items:[{runId:l,steps:d}]}})}var wi=3,Pi=0;function Ii({endMs:e,rrwebEvents:r,startMs:n}){let t=r.find(o=>o.type===wi&&o.data?.source===Pi&&o.timestamp>=n&&o.timestamp<=e);return t==null?n:t.timestamp}function Ci({aliases:e,generated:r,generatedSingletons:n,origin:t,record:o,rrwebEvents:i,sourceTest:s}){let l=Ve(o.source,o.index),u=Ii({endMs:o.endMs,rrwebEvents:i,startMs:o.startMs}),d=o.annotations.map(p=>({kind:p.kind,label:p.label,outcome:p.outcome,recordingStartMs:Math.max(0,(p.kind==="action"?u:p.atMs)-t),rrwebIds:[...p.rrwebIds]})),m=o.annotations.find(p=>p.kind==="action")?.rrwebIds??[];return{annotations:d,detail:null,duration:Math.max(0,o.endMs-o.startMs),findings:o.findings.map(p=>Sn(p)),nodeType:l.kind,recordingEndMs:Math.max(0,o.endMs-t),recordingStartMs:Math.max(0,u-t),rrwebIds:[...m],snapshotTimestamp:Math.max(0,o.endMs-t),sourceTest:s,stateRows:o.state.rows.map(p=>Ai({aliases:e,generated:r,row:p})),stateSingletons:o.state.singletons.map(p=>({changed:p.changed,generated:n.has(p.name),name:p.name,value:p.value==null?null:String(p.value)})),status:o.findings.length>0?"failed":"passed",stepIndex:o.index,title:kn(l),url:o.url}}function Ai({aliases:e,generated:r,row:n}){let t=e.find(o=>o.entity===n.entity&&o.key===n.key);return{entity:n.entity,fields:n.fields.map(o=>({changed:o.changed,field:o.field,generated:r.has(En({entity:n.entity,field:o.field,key:n.key})),value:o.value==null?null:String(o.value)})),key:n.key,label:t?.alias??n.key,status:n.status}}var ji=ui(di);async function wn(e,r,n){await f({config:e,document:Ni,variables:{reason:n,runId:r}}).catch(t=>{y.error(t,"failRun submission failed")})}async function Ti(e,r,n){let t=n.events.map(s=>JSON.stringify(s)).join(`
|
|
125
|
+
`),o=await ji(Buffer.from(t,"utf8")),i=n.events.at(-1);await f({config:e,document:_i,variables:{input:{bodyBase64:o.toString("base64"),chunkIndex:0,endTimestamp:Math.max(0,(i?.timestamp??n.origin)-n.origin),eventCount:n.events.length,runId:r,startTimestamp:0}}})}async function Fi(e,r,n){let t=n.filter(s=>s.findings.length>0).length,o=n.length-t,i=n.reduce((s,l)=>s+Math.max(0,l.endMs-l.startMs),0);await f({config:e,document:Oi,variables:{items:[{duration:i,failCount:t,passCount:o,runId:r,status:t>0?"failed":"passed",summary:null,warnCount:0}]}})}async function Li(e,r){return((await f({config:e,document:Mi,variables:{runIds:[r]}})).startRunsBatch??[]).some(t=>t.id===r)}var Mi=R(`
|
|
126
|
+
mutation StartRunsBatch($runIds: [String!]!) {
|
|
127
|
+
startRunsBatch(runIds: $runIds) {
|
|
128
|
+
id
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`),$i=R(`
|
|
132
|
+
mutation SubmitRunStepsBatch($items: [SubmitRunStepsItem!]!) {
|
|
133
|
+
submitRunStepsBatch(items: $items)
|
|
134
|
+
}
|
|
135
|
+
`),_i=R(`
|
|
136
|
+
mutation SubmitRunRecordingChunk($input: SubmitRunRecordingChunkInput!) {
|
|
137
|
+
submitRunRecordingChunk(input: $input)
|
|
138
|
+
}
|
|
139
|
+
`),Oi=R(`
|
|
140
|
+
mutation CompleteRunsBatch($items: [CompleteRunItem!]!) {
|
|
141
|
+
completeRunsBatch(items: $items) {
|
|
142
|
+
id
|
|
143
|
+
status
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
`),Ni=R(`
|
|
147
|
+
mutation FailRun($runId: String!, $reason: String!) {
|
|
148
|
+
failRun(runId: $runId, reason: $reason)
|
|
149
|
+
}
|
|
150
|
+
`),Hc=R(`
|
|
151
|
+
mutation MarkRunArtifactsUploadedBatch($runIds: [String!]!) {
|
|
152
|
+
markRunArtifactsUploadedBatch(runIds: $runIds)
|
|
153
|
+
}
|
|
154
|
+
`);async function Di({baseState:e,branchName:r,category:n,commitSha:t,config:o,debugDir:i,devSessionId:s,events:l,lockfileHash:u,runId:d,signature:m,spec:p,stepSources:g}){await f({config:o,document:Ui,variables:{branchName:r??null,commitSha:t??null,devSessionId:s??null,lockfileHash:u??null,projectId:o.projectId,runId:d,spec:p??null}}),await ne({config:o,debugDir:i,events:l,recordingOptional:!0,runId:d,stepSources:g}),await f({config:o,document:Wi,variables:{baseState:e,category:n,projectId:o.projectId,reproRunId:d,signature:m}})}async function Hi(e,r,n){await f({config:e,document:qi,variables:{projectId:e.projectId,signature:r,status:n}})}var Ui=te(`
|
|
155
|
+
mutation CreateExploreRun(
|
|
156
|
+
$projectId: String!
|
|
157
|
+
$runId: String!
|
|
158
|
+
$devSessionId: String
|
|
159
|
+
$branchName: String
|
|
160
|
+
$commitSha: String
|
|
161
|
+
$lockfileHash: String
|
|
162
|
+
$spec: String
|
|
163
|
+
) {
|
|
164
|
+
createExploreRun(
|
|
165
|
+
projectId: $projectId
|
|
166
|
+
runId: $runId
|
|
167
|
+
devSessionId: $devSessionId
|
|
168
|
+
branchName: $branchName
|
|
169
|
+
commitSha: $commitSha
|
|
170
|
+
lockfileHash: $lockfileHash
|
|
171
|
+
spec: $spec
|
|
172
|
+
) {
|
|
173
|
+
id
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
`),Wi=te(`
|
|
177
|
+
mutation SubmitExploreFinding(
|
|
178
|
+
$projectId: String!
|
|
179
|
+
$signature: String!
|
|
180
|
+
$baseState: String!
|
|
181
|
+
$category: ExploreFindingCategory!
|
|
182
|
+
$reproRunId: String!
|
|
183
|
+
) {
|
|
184
|
+
submitExploreFinding(
|
|
185
|
+
projectId: $projectId
|
|
186
|
+
signature: $signature
|
|
187
|
+
baseState: $baseState
|
|
188
|
+
category: $category
|
|
189
|
+
reproRunId: $reproRunId
|
|
190
|
+
) {
|
|
191
|
+
id
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
`),qi=te(`
|
|
195
|
+
mutation SetExploreFindingStatus(
|
|
196
|
+
$projectId: String!
|
|
197
|
+
$signature: String!
|
|
198
|
+
$status: ExploreFindingStatus!
|
|
199
|
+
) {
|
|
200
|
+
setExploreFindingStatus(projectId: $projectId, signature: $signature, status: $status)
|
|
201
|
+
}
|
|
202
|
+
`),Vc=te(`
|
|
203
|
+
query ExploreFindingExists($projectId: String!, $signature: String!, $lockfileHash: String!) {
|
|
204
|
+
exploreFindingExists(projectId: $projectId, signature: $signature, lockfileHash: $lockfileHash)
|
|
205
|
+
}
|
|
206
|
+
`);import Bi from"fs";import{lockSync as Vi}from"proper-lockfile";var Ki="explorer.lock",zi=15e3,Ji=15e3;function Gi(){return De(Ki)}function rd({onChange:e}){let r={release:null,stopped:!1},n=()=>{r.release=null,r.stopped||e(!1)},t=()=>{if(r.stopped||r.release!=null)return;let i=Qi(n);i!=null&&(r.release=i,e(!0))};t();let o=setInterval(t,Ji);return{holder:()=>r.release!=null,stop:()=>{r.stopped=!0,clearInterval(o),r.release?.(),r.release=null}}}function Qi(e){try{Ne();let r=Gi(),n=Vi(r,{onCompromised:e,realpath:!1,stale:zi});return Bi.writeFileSync(r,String(process.pid)),()=>{try{n()}catch{}}}catch{return null}}import Xi from"path";import{randomUUID as Yi}from"crypto";function Pn(e){return{axes:[Qe("unit"),Xe(e)]}}var In=12,Cn=15,An=4,jn=2;var Ln={covered:0,deferred:0,findings:0,saturated:!1,total:0};function dd(){return{priority:"p3",next:()=>null,onResult:()=>{},ready:()=>Promise.resolve(),status:()=>Ln,stop:()=>Promise.resolve()}}function ud(e){let r={claimed:new Set,consecutiveErrors:0,covered:new Set,deferred:new Map,findings:0,haltedUntil:0,prepared:null,preparing:!1,refreshing:!1,saturated:!1,tick:0},n=Le(e,r);return{priority:"p3",next:()=>oa(e,r),onResult:()=>{},ready:()=>n,status:()=>r.prepared==null?Ln:na(r.prepared,r),stop:()=>Promise.resolve()}}async function Le(e,r){if(!r.preparing){r.preparing=!0;try{let n=await e.loadLockfile();if(n==null)return;let t=await Zi(n);if(t==null)return;await D(Mn(e.cwd)).match(o=>{let i=N(o);r.covered=new Set(i.covered),r.findings=[...i.findings.values()].filter(s=>s.resolvedAt==null).length,r.prepared=t,r.consecutiveErrors=0,r.haltedUntil=0,r.deferred.clear(),e.notifyWork()},o=>{y.warn("explore findings log unreadable, exploration disabled: %s",o.kind)})}finally{r.preparing=!1}}}async function Zi({fingerprint:e,lockfile:r}){let n=Pn(r),t=Je(r);if(t.length===0)return null;let o=ir(r,{sweep:!1}),i=await ea(r,o),s=rr({baseStates:i,corpus:t,lens:n,maxCount:jn,maxDepth:An});return{actionHashes:t.map(l=>er(r,l)),baseStates:o,corpus:t,fingerprint:e,graph:s,lens:n,lensIdValue:Ge(n),lockfile:r,lockfileHashValue:_(r)}}async function ea(e,r){let n={generate:C,materialize:ze(C,e.valueSpaces),params:void 0};return(await Promise.all(r.map(async o=>(await ar(e,o,n)).match(s=>({name:o.name,snapshot:s.snapshot}),()=>null)))).flatMap(o=>o==null?[]:[o])}var Tn=20,ra=6e5,Fn=3e5;function na(e,r){let n=tr(e.graph),t=nr({actionHashes:e.actionHashes,corpus:e.corpus,covered:r.covered,graph:e.graph,lensId:e.lensIdValue,tick:r.tick});return{covered:n-t,deferred:_n(r).size,findings:r.findings,saturated:r.saturated,total:n}}async function ta(e,r){if(!(r.refreshing||r.preparing||r.prepared==null)){r.refreshing=!0;try{let n=await e.loadLockfile();if(n==null||n.fingerprint===r.prepared.fingerprint)return;y.info("workflow definitions changed, re-preparing exploration targets"),r.prepared=null,await Le(e,r)}finally{r.refreshing=!1}}}function oa(e,r){ta(e,r);let n=r.prepared;if(n==null||Date.now()<r.haltedUntil)return null;let t=or({actionHashes:n.actionHashes,corpus:n.corpus,covered:new Set([...r.covered,...r.claimed,..._n(r)]),graph:n.graph,lensId:n.lensIdValue,tick:r.tick});if(r.tick+=1,t.kind==="saturated")return r.saturated=!0,null;r.saturated=!1;let o=pa(n,t.target);return r.claimed.add(o),{id:`explore:${Yi()}`,label:t.target.targetKey,run:i=>ia({choice:t.target,key:o,params:e,prepared:n,signal:i,state:r})}}async function ia({choice:e,key:r,params:n,prepared:t,signal:o,state:i}){try{let s=sa({choice:e,params:n,prepared:t});if(s==null)return;if(!await n.probeApp()){$n(i,"app-unreachable");return}let l=await n.executeTrail(s,o);if(l.kind==="aborted")return;if(l.kind==="error"){ca({key:r,params:n,reason:l.reason,state:i});return}i.consecutiveErrors=0,y.info("exploration trail %s: %s @ %s",l.kind,l.trail.map(u=>u.label).join(" -> "),e.targetKey.slice(0,80)),n.onTrailDone?.({kind:l.kind,label:e.targetKey,trail:l.trail}),await la({outcome:aa(l,e,t),params:n,state:i})}finally{i.claimed.delete(r)}}function aa(e,r,n){let t={actionHash:r.actionHash,at:new Date().toISOString(),kind:"covered",lensId:n.lensIdValue,targetKey:r.targetKey};return{...e,rows:[...e.rows,t]}}function sa({choice:e,params:r,prepared:n}){let t=n.baseStates.find(o=>o.name===e.witness.baseState);return t==null?null:{baseStateTest:t.test,lensId:n.lensIdValue,lockfileFingerprint:n.fingerprint,lockfileHash:n.lockfileHashValue,maxLength:r.maxTrailLength??In,shrinkBudget:Cn,stepRuns:e.witness.trail.map(o=>({idx:o.idx,params:o.params}))}}async function la({outcome:e,params:r,state:n}){let t=e.rows.filter(o=>o.kind!=="covered"||!n.covered.has(O(o)));t.forEach(o=>{(o.kind==="covered"||o.kind==="finding"||o.kind==="flaky-candidate")&&n.covered.add(O(o))}),e.kind==="finding"&&(n.findings+=1,y.info("exploration finding recorded")),t.length!==0&&await Ze(Mn(r.cwd),t).match(()=>{},o=>{y.warn("explore findings log append failed: %s",o.kind)})}function Mn(e){return Xi.join(e,".ripplo",".local","explore-ledger.jsonl")}function ca({key:e,params:r,reason:n,state:t}){if(n==="lockfile:fingerprint-mismatch"){da(r,t);return}ua(t,e),$n(t,n)}function da(e,r){r.preparing||(r.prepared=null,Le(e,r))}function ua(e,r){e.deferred.set(r,Date.now()+ra)}function $n(e,r){e.consecutiveErrors+=1,y.debug("exploration trail error: %s",r),e.consecutiveErrors>=Tn&&(e.haltedUntil=Date.now()+Fn,e.consecutiveErrors=0,y.warn("exploration cooling down for %ds after %d consecutive trail errors (last: %s)",Fn/1e3,Tn,r))}function _n(e){let r=Date.now();return[...e.deferred].filter(([,n])=>n<=r).forEach(([n])=>e.deferred.delete(n)),new Set(e.deferred.keys())}function pa(e,r){return O({actionHash:r.actionHash,lensId:e.lensIdValue,targetKey:r.targetKey})}import fa from"path";var ma=3;function yd(e){return D(ya(e)).map(r=>ga(N(r)))}function ya(e){return fa.join(e,".ripplo",".local","explore-ledger.jsonl")}function ga(e){let r=[...e.findings.entries()].filter(([,t])=>t.resolvedAt==null).map(([t,o])=>ha(t,o)).toSorted(Sa),n=[...e.flaky.entries()].filter(([,t])=>t.occurrences>=ma).map(([t,o])=>ka(t,o)).toSorted((t,o)=>o.occurrences-t.occurrences);return{pending:r,recurrentFlaky:n}}function ha(e,r){let n=r.latest;return{baseState:n.baseState,evidence:n.evidence,firstSeen:r.first.at,id:ie(e),lastSeen:n.at,occurrences:r.occurrences,parts:n.parts,runId:n.runId,trail:n.trail,verifierLayer:n.verifierLayer}}function ka(e,r){return{at:r.first.at,baseState:r.first.baseState,id:ie(e),occurrences:r.occurrences,trail:r.first.trail}}var On={crash:0,"data-rule":1,frame:3,"page-rule":2};function Sa(e,r){let n=On[e.verifierLayer]-On[r.verifierLayer];return n===0?r.occurrences-e.occurrences:n}import{createMessageConnection as Nn,IPCMessageReader as Dn,IPCMessageWriter as Hn,NotificationType as Ra,NotificationType0 as Un,RequestType as Me}from"vscode-jsonrpc/node";import{z as c}from"zod";var bd=c.object({headed:c.boolean(),lockfileFingerprint:c.string(),runId:c.string().min(1),testRef:c.string().min(1)}),vd=c.object({fingerprint:c.string()}),Ed=c.object({lockfileJson:c.string().optional(),unavailable:c.string().optional()}),xa=c.enum(["unspecified","internal","server","client","producer","consumer"]),ba=c.enum(["unset","ok","error"]),va=c.object({attributes:c.record(c.string(),c.string()),durationMs:c.number(),kind:c.literal("span"),name:c.string(),parentSpanId:c.union([c.string(),c.undefined()]),source:c.literal("server"),spanId:c.string(),spanKind:xa,status:c.object({code:ba,message:c.union([c.string(),c.undefined()])}),timeNanos:c.string(),traceId:c.string()}),wd=c.object({runId:c.string().min(1),span:va}),Pd=c.object({outcome:we,serverNotified:c.boolean()}),Id=c.object({baseStateTest:We,lensId:c.string().min(1),lockfileFingerprint:c.string(),lockfileHash:c.string().min(1),maxLength:c.number().int().positive(),shrinkBudget:c.number().int().nonnegative(),stepRuns:c.array(c.object({idx:c.number().int().nonnegative(),params:c.record(c.string(),c.union([Ue,c.null()]))}))}),Ea=c.object({actions:c.array(c.string()),label:c.string().min(1)}),Cd=c.object({kind:c.enum(["aborted","clean","error","flaky","finding"]),reason:c.string().optional(),rows:c.array(Ye),trail:c.array(Ea).default([])}),Ad=new Un("worker/ready"),jd=new Me("worker/run"),Td=new Me("worker/lockfile"),Fd=new Me("worker/exploreTrail"),Ld=new Ra("worker/span"),Md=new Un("worker/shutdown");function $d(e){let r=Nn(new Dn(e),new Hn(e));return r.listen(),r}function _d(){let e=Nn(new Dn(process),new Hn(process));return e.listen(),e}export{Aa as a,Oa as b,V as c,Qn as d,K as e,fe as f,v as g,dt as h,F as i,E as j,is as k,G as l,ds as m,us as n,ps as o,ks as p,he as q,Rr as r,br as s,Ts as t,Cr as u,Re as v,_s as w,re as x,hn as y,fc as z,mc as A,yc as B,ni as C,wc as D,pi as E,wn as F,Di as G,Hi as H,rd as I,Pn as J,dd as K,ud as L,yd as M,ya as N,ul as O,pl as P,Or as Q,fl as R,ml as S,yl as T,gl as U,hl as V,kl as W,Hr as X,Ur as Y,Wr as Z,qr as _,Br as $,Vr as aa,Ds as ba,Hs as ca,xe as da,Us as ea,jr as fa,nl as ga,Ee as ha,ln as ia,tc as ja,bd as ka,vd as la,wd as ma,Pd as na,Id as oa,Cd as pa,Ad as qa,jd as ra,Td as sa,Fd as ta,Ld as ua,Md as va,$d as wa,_d as xa,ic as ya};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{A as re,C as de,F as I,H as ce,I as ue,K as pe,L as fe,N as x,O as Re,b as G,ba as k,ca as T,da as ve,e as Q,ea as q,fa as Pe,h as y,ha as _,i as A,ia as xe,ja as he,l as H,la as be,na as Ee,pa as Ce,q as X,qa as Ie,ra as Te,sa as We,t as C,ta as Le,ua as De,v as Z,va as Ae,w as ee,wa as He,ya as Fe}from"./chunk-XZTICXYD.js";import{$ as me,L as ie,N as ae,O as se,P as F,X as le,aa as ye,ba as ge,c as J,ca as ke,da as we,ea as Se,g as K,h as V,k as Y,n as ne,p as oe,x as te}from"./chunk-DAULBZMT.js";import{b as qe}from"./chunk-BJVAPI4P.js";import{c as B,d as E,e as l,f as D,g as z}from"./chunk-EVYYSTR7.js";import"./chunk-IHSHBPJY.js";import"./chunk-7UWDMECF.js";import en from"path";import{createClient as rn}from"graphql-sse";import nn,{AbortError as on}from"p-retry";import{graphql as M}from"gql.tada";import{graphql as Rr}from"gql.tada";import{print as vr}from"graphql";async function _e({config:e,cwd:n,headed:r,pool:t,runId:o,signal:i,testSlug:a,workClass:s,workflowSlug:d}){let{fingerprint:c,result:u}=await y(n);if(u.isErr())return await I(e,o,`lockfile:${u.error.kind}`),{kind:"dispatch-error",reason:{detail:`lockfile:${u.error.kind}`,type:"generic"}};let m=Sr(u.value,{testSlug:a,workflowSlug:d});if(m==null)return await I(e,o,`no-test:${d}/${a}`),{kind:"dispatch-error",reason:{detail:`no-test:${d}/${a}`,type:"generic"}};let p=await k({headed:r,workClass:s,task:()=>t.execute({headed:r,lockfileFingerprint:c,runId:o,testRef:m},i)});return!p.serverNotified&&p.outcome.kind==="error"&&await I(e,o,p.outcome.detail),p.outcome}function Sr(e,{testSlug:n,workflowSlug:r}){let o=e.workflows.find(i=>Y(i.name)===r)?.tests.find(i=>i.slug===n);return o==null?void 0:ne(o)}var Pr=6e4,xr=Rr(`
|
|
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 n=Math.min(1e3*2**e,Pr)+Er();await new Promise(r=>setTimeout(r,n))}function je({claim:e,cwd:n,devSessionId:r,onSubscriptionDead:t,pool:o,sseClient:i,sseHealth:a}){let s=new Set;return i.subscribe({query:vr(xr),variables:{devSessionId:r}},{complete:()=>{},error:d=>{let c=d instanceof Error?d.message:String(d);l.warn("runRequested SSE failed: %s; re-registering session",c),t(c)},next:d=>{hr({claim:e,cwd:n,event:d.data?.runRequested,inFlightRunIds:s,pool:o})}},{connected:()=>{a.onConnected()},connecting:d=>{a.onConnecting(d),d&&l.debug("runRequested SSE reconnecting")}})}function hr({claim:e,cwd:n,event:r,inFlightRunIds:t,pool:o}){if(r==null)return;if(t.has(r.runId)){l.warn({runId:r.runId,workflowSlug:r.workflowSlug},"duplicate runRequested event; skipping dispatch");return}t.add(r.runId),process.stdout.write(`ripplo: run ${r.workflowSlug}
|
|
12
|
+
`),G(n);let i=C(n).match(s=>s,s=>{l.error({failure:s,runId:r.runId},"failed to load env for run dispatch; skipping")});if(i==null){t.delete(r.runId);return}let a=br(e(r.runId),r);a.started(),_e({config:i,cwd:n,headed:a.headed,pool:o,runId:r.runId,signal:a.signal,testSlug:r.testSlug,workClass:a.workClass,workflowSlug:r.workflowSlug}).then(s=>{a.finished(s)}).catch(s=>{l.error({err:s,runId:r.runId,workflowSlug:r.workflowSlug},"run execution failed; daemon continuing"),a.finished({detail:s instanceof Error?s.message:String(s),kind:"error"})}).finally(()=>{t.delete(r.runId)})}function br(e,n){return e==null?(l.debug({runId:n.runId,workflowSlug:n.workflowSlug},"dispatching unclaimed run (externally triggered or replayed)"),{headed:!1,signal:new AbortController().signal,workClass:"p0-ui",finished:()=>{},started:()=>{}}):{headed:e.headed,signal:xe(e.token),workClass:"p1-cli",finished:r=>{e.finished(n.runId,r)},started:()=>{e.started(n.runId)}}}function Er(){return Math.floor(Math.random()*2700)+300}function Ne(){let e=!0,n,r=null,t=()=>{r!=null&&(clearTimeout(r),r=null)};return{markUnhealthy:o=>{e=!1,n=o,t()},onConnected:()=>{t(),r=setTimeout(()=>{e=!0,n=void 0,r=null},1e4)},onConnecting:()=>{t()},snapshot:()=>({detail:n,ok:e})}}import Cr from"fs";import Be from"net";import{err as ze,ok as Ir}from"neverthrow";async function Ge({cwd:e,onConnection:n}){z(e);let r=Re(e),t=await Me({onConnection:n,socketPath:r});return t.isOk()||t.error.kind!=="stale-candidate"?t.map($e(r)).mapErr(Ue(r)):await Tr(r)?ze({kind:"already-running",socketPath:r}):(Qe(r),(await Me({onConnection:n,socketPath:r})).map($e(r)).mapErr(Ue(r)))}function Tr(e){return new Promise(n=>{let r=Be.connect(e);r.once("connect",()=>{r.destroy(),n(!0)}),r.once("error",()=>{n(!1)})})}async function Me(e){let n=await Wr(e);return n.kind==="listening"?Ir(n.server):ze(n.error)}function Wr({onConnection:e,socketPath:n}){return new Promise(r=>{let t=Be.createServer(e);t.once("error",o=>{r({error:o.code==="EADDRINUSE"?{kind:"stale-candidate"}:{kind:"listen-failed",message:o.message},kind:"failed"})}),t.listen(n,()=>{r({kind:"listening",server:t})})})}function $e(e){return n=>({socketPath:e,close:()=>{n.close(),Qe(e)}})}function Qe(e){Cr.rmSync(e,{force:!0})}function Ue(e){return n=>n.kind==="stale-candidate"?{kind:"already-running",socketPath:e}:{kind:"bind-failed",message:n.message}}function O(e){return{priority:e,next:()=>null,onResult:()=>{}}}function Je({config:e,executor:n,explore:r,exploreConcurrency:t,pool:o}){return Lr({appUrl:e.appUrl,cwd:e.cwd,explore:r&&n==="local",exploreConcurrency:t,executeTrail:async(i,a)=>(await o).exploreTrail(i,a)})}function Lr({appUrl:e,cwd:n,executeTrail:r,explore:t,exploreConcurrency:o}){let i={notify:()=>{}},a=t?Dr({appUrl:e,cwd:n,executeTrail:r,notifyWork:()=>{i.notify()}}):pe(),s=Fe({exploreConcurrency:o,exploreEnabled:t,now:Date.now,probe:Ar,setTimer:Hr,sources:[O("p0"),O("p1"),a],execute:({job:c,priority:u,signal:m})=>k({headed:!1,workClass:Fr(u),task:()=>c.run(m)})});q(()=>{s.notifyQueueChange()}),i.notify=()=>{s.notifyQueueChange()};let d=t?ue({onChange:c=>{s.setExplorerHolder(c)}}):null;return{status:()=>({explorer:qr({explore:t,holder:s.explorerHolder()}),exploring:s.explorationActive(),progress:a.status()}),stop:()=>{d?.stop(),s.stop(),q(null),a.stop()}}}function Dr({appUrl:e,cwd:n,executeTrail:r,notifyWork:t}){return fe({cwd:n,executeTrail:r,notifyWork:t,loadLockfile:async()=>{let{fingerprint:o,result:i}=await y(n);return i.match(a=>({fingerprint:o,lockfile:a}),()=>null)},probeApp:async()=>await re(e)==null})}function Ar(){let e=ve();return{headedActive:e.headedActive,interactiveActive:e.active,interactiveQueued:e.queued,poolSize:e.poolSize}}function Hr(e,n){let r=setTimeout(e,n);return()=>{clearTimeout(r)}}function Fr(e){switch(e){case"p0":return"p0-ui";case"p1":return"p1-cli";case"p2":return"p2-cover";case"p3":return"p3-explore"}}function qr({explore:e,holder:n}){return e?n?"holder":"standby":"off"}async function Ke({cwd:e,finding:n}){let r={at:new Date().toISOString(),kind:"resolution",signature:n.signature};await F(x(e),[r]).match(()=>{},t=>{l.warn("explore findings log append failed: %s",t.kind)})}async function Ve({cwd:e,finding:n,outcome:r}){let t=r.kind==="clean"?[...r.rows,{at:new Date().toISOString(),kind:"resolution",signature:n.signature}]:r.rows;t.length!==0&&await F(x(e),t).match(()=>{},o=>{l.warn("explore findings log append failed: %s",o.kind)})}function Ye({config:e,cwd:n,pool:r}){let t={cwd:n,executeTrail:(o,i)=>k({headed:!1,workClass:"p1-cli",task:async()=>(await r).exploreTrail(o,i)}),loadLockfile:async()=>{let o=await y(n);return o.result.match(i=>({fingerprint:o.fingerprint,lockfile:i}),()=>null)},pushResolved:o=>ce(e,o,"resolved").catch(i=>{l.warn({error:i},"explore finding status push failed")})};return(o,i)=>_r(t,{findingId:o,signal:i})}async function _r(e,n){let r=await Or(e.cwd,n.findingId);if("reply"in r)return r.reply;let t=await e.loadLockfile();if(t==null)return{kind:"error",reason:"lockfile-unavailable"};let o=jr(t,r.finding);if("reply"in o)return o.reply;let i=await e.executeTrail(o.assign,n.signal),a=await Mr({cwd:e.cwd,finding:r.finding,outcome:i});return(a.kind==="resolved"||a.kind==="unreachable")&&await e.pushResolved(r.finding.signature),a}async function Or(e,n){return se(x(e)).match(r=>{let o=[...ae(r).findings.entries()].find(([a])=>ie(a)===n);if(o==null)return{reply:{kind:"finding-not-found"}};let[,i]=o;return i.resolvedAt!=null?{reply:{kind:"finding-not-found"}}:{finding:i.latest}},()=>({reply:{kind:"unreplayable",reason:"ledger-unreadable"}}))}function jr(e,n){let r=le(e.lockfile,{sweep:!1}).find(o=>o.name===n.baseState);if(r==null)return{reply:{kind:"unreplayable",reason:"base-state-missing"}};let t=Nr(e.lockfile,n);return t==null?{reply:{kind:"unreplayable",reason:"action-missing"}}:{assign:{baseStateTest:r.test,lensId:n.lensId,lockfileFingerprint:e.fingerprint,lockfileHash:V(e.lockfile),maxLength:t.length,shrinkBudget:0,stepRuns:t}}}function Nr(e,n){let t=oe(e).map(a=>`${a.test}#${String(a.index)}`),i=n.trail.map((a,s)=>{let d=t.indexOf(a),c=n.trailParams[s];return d===-1||c==null?null:{idx:d,params:c}}).flatMap(a=>a==null?[]:[a]);return i.length===n.trail.length?i:null}async function Mr({cwd:e,finding:n,outcome:r}){return r.kind==="aborted"?{kind:"aborted"}:r.kind==="error"?$r({cwd:e,finding:n,reason:r.reason}):(await Ve({cwd:e,finding:n,outcome:r}),r.kind==="clean"?{kind:"resolved"}:r.kind==="flaky"?{kind:"flaky"}:Ur(n,r))}async function $r({cwd:e,finding:n,reason:r}){return r==="empty-trail"?(await Ke({cwd:e,finding:n}),{kind:"unreachable"}):{kind:"error",reason:r??"trail-error"}}function Ur(e,n){let r=n.rows.find(o=>o.kind==="finding"),t=r?.kind==="finding"?r.runId:void 0;return r!=null&&r.signature===e.signature?{kind:"still-failing",runId:t}:{kind:"diverged",runId:t}}import{fork as Br}from"child_process";import Xe from"os";import{CancellationTokenSource as Ze,ResponseError as er}from"vscode-jsonrpc/node";function rr(e,n){return()=>{let r=Br(e,["run-worker"],{cwd:n,stdio:["ignore","inherit","inherit","ipc"]});return{connection:He(r),kill:()=>{r.kill("SIGKILL")},onExit:t=>{r.once("exit",t)}}}}function nr(e){let n={closed:!1,lockfileProvider:e.lockfileProvider,nextId:0,size:e.initialSize,spawn:e.spawn,waiters:[],workers:[]};return{close:async()=>{n.closed=!0,await Promise.all([...n.workers].map(r=>j(r,n)))},execute:(r,t)=>Gr(r,t,n),exploreTrail:(r,t)=>Kr(r,t,n),routeSpan:(r,t)=>{let o=n.workers.find(i=>i.runId===r);o?.worker.connection.sendNotification(De,{runId:r,span:t})},setSize:r=>{Yr(r,n)}}}var zr=1e4,or=-32800;async function Gr(e,n,r){let t=await tr(r);if(t.runId=e.runId,!t.alive)return W(t,r),{outcome:{detail:"worker-exit",kind:"error"},serverNotified:!1};let o=new Ze,i=()=>{o.cancel()};n.aborted&&o.cancel(),n.addEventListener("abort",i,{once:!0});try{let a=await t.worker.connection.sendRequest(Te,e,o.token),s=Ee.safeParse(a);return s.success?s.data:{outcome:{detail:"bad-outcome-frame",kind:"error"},serverNotified:!1}}catch(a){return Jr(a,t)}finally{n.removeEventListener("abort",i),o.dispose(),W(t,r)}}async function tr(e){let n=e.workers.find(r=>r.alive&&r.runId===void 0);if(n!=null)return n.runId="pending",n;if(e.workers.length<e.size){let r=Qr(e);return r.runId="pending",await r.ready,r}return new Promise(r=>{e.waiters.push(t=>{t.runId="pending",r(t)})})}function Qr(e){let n=e.spawn(),r={resolve:()=>{}},t={alive:!0,id:e.nextId,ready:new Promise(o=>{r.resolve=o,n.connection.onNotification(Ie,o)}),runId:void 0,worker:n};return e.nextId+=1,n.connection.onRequest(We,async o=>{let i=be.safeParse(o);return i.success?e.lockfileProvider(i.data.fingerprint):{unavailable:"bad-lockfile-request"}}),n.onExit(()=>{t.alive=!1,e.workers=e.workers.filter(o=>o!==t),n.connection.dispose(),r.resolve()}),e.workers.push(t),t}function W(e,n){if(e.runId=void 0,!e.alive||n.closed)return;if(n.workers.length>n.size){j(e,n);return}let r=n.waiters.shift();r?.(e)}async function j(e,n){if(n.workers=n.workers.filter(o=>o!==e),!e.alive)return;let r=new Promise(o=>{e.worker.onExit(o)});await e.worker.connection.sendNotification(Ae).catch(()=>{});let t=setTimeout(()=>{e.worker.kill()},zr);await r,clearTimeout(t)}function Jr(e,n){return e instanceof er&&e.code===or?{outcome:{detail:"aborted",kind:"error"},serverNotified:!1}:n.alive?{outcome:{detail:e instanceof Error?e.message:String(e),kind:"error"},serverNotified:!1}:{outcome:{detail:"worker-exit",kind:"error"},serverNotified:!1}}async function Kr(e,n,r){let t=await tr(r);if(t.runId="explore",!t.alive)return W(t,r),{kind:"error",rows:[],trail:[]};let o=new Ze,i=()=>{o.cancel()};n.aborted&&o.cancel(),n.addEventListener("abort",i,{once:!0});try{let a=await t.worker.connection.sendRequest(Le,e,o.token),s=Ce.safeParse(a);return s.success?s.data:{kind:"error",rows:[],trail:[]}}catch(a){return Vr(a)}finally{n.removeEventListener("abort",i),o.dispose(),W(t,r)}}function Vr(e){return e instanceof er&&e.code===or?{kind:"aborted",rows:[],trail:[]}:{kind:"error",reason:`transport:${e instanceof Error?e.message.slice(0,120):"unknown"}`,rows:[],trail:[]}}function Yr(e,n){n.size=e,e>Xe.availableParallelism()&&l.warn({cores:Xe.availableParallelism(),size:e},"worker pool size exceeds available cores");let r=n.workers.filter(o=>o.alive&&o.runId===void 0),t=n.workers.length-e;r.slice(0,Math.max(0,t)).forEach(o=>{j(o,n)})}import L from"fs";import{graphql as ir}from"gql.tada";import{print as ar}from"graphql";var Xr=ir(`
|
|
13
|
+
subscription HooksPausedWatch($projectId: String!) {
|
|
14
|
+
hooksPausedRequested(projectId: $projectId) {
|
|
15
|
+
paused
|
|
16
|
+
projectId
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`),Zr=ir(`
|
|
20
|
+
subscription WatchLocalConcurrencyChanged {
|
|
21
|
+
myMaxLocalConcurrentRunsChanged
|
|
22
|
+
}
|
|
23
|
+
`);function sr({pool:e,sseClient:n}){return n.subscribe({query:ar(Zr)},{complete:()=>{},error:r=>{l.error(r,"localConcurrency subscription error")},next:r=>{let t=r.data?.myMaxLocalConcurrentRunsChanged;t!=null&&(T(t),e.setSize(t))}})}function lr({cwd:e,projectId:n,sseClient:r}){return r.subscribe({query:ar(Xr),variables:{projectId:n}},{complete:()=>{},error:t=>{l.error(t,"hooksPaused subscription error")},next:t=>{let o=t.data?.hooksPausedRequested?.paused;o!=null&&N({cwd:e,paused:o})}})}function N({cwd:e,paused:n}){let r=de(e);if(n&&!L.existsSync(r)){L.writeFileSync(r,"");return}!n&&L.existsSync(r)&&L.unlinkSync(r)}var tn=6e4,dr=500,an=15e3,cr=6e4,sn=3,ln=M(`
|
|
24
|
+
mutation HeartbeatDevSessionWatch($id: String!) {
|
|
25
|
+
heartbeatDevSession(id: $id) {
|
|
26
|
+
__typename
|
|
27
|
+
... on DevSession {
|
|
28
|
+
id
|
|
29
|
+
}
|
|
30
|
+
... on DevSessionEndedError {
|
|
31
|
+
message
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`),dn=M(`
|
|
36
|
+
query WatchLocalConcurrency {
|
|
37
|
+
currentUser {
|
|
38
|
+
id
|
|
39
|
+
maxLocalConcurrentRuns
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`),cn=M(`
|
|
43
|
+
mutation EndDevSessionWatch($projectId: String!, $cwd: String!) {
|
|
44
|
+
endDevSession(projectId: $projectId, cwd: $cwd) {
|
|
45
|
+
__typename
|
|
46
|
+
... on DevSession {
|
|
47
|
+
id
|
|
48
|
+
}
|
|
49
|
+
... on NoActiveDevSessionError {
|
|
50
|
+
message
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`);async function at(e){let{executor:n,explore:r,exploreConcurrency:t}=e;In();let o=hn(process.cwd()),i=o.cwd,a=Sn(i),s=xn(),d=Je({config:o,executor:n,explore:r,exploreConcurrency:t,pool:s.pool}),c={handler:()=>{}},u=vn(),m=Ne(),p=he({config:o,cwd:i,executor:n,explorationStatus:d.status,ready:u.promise,replayFinding:Ye({config:o,cwd:i,pool:s.pool}),onShutdownRequest:()=>{c.handler()},sseHealth:()=>m.snapshot()}),w=await Pn({cwd:i,ipc:p,releasePid:a}),S=await A(i);S.isErr()&&(process.stderr.write(`ripplo: ${H(S.error)}
|
|
55
|
+
`),process.exit(1));let h=S.value,f=await ur(()=>_({config:o,cwd:i,lockfile:h}),{config:o,label:"initial sync"}),b=await Wn(o);N({cwd:i,paused:f.hooksPaused});let g=Pe(i);g!=null&&l.info("watching branch %s in %s",g,i);let R=rn({headers:{Authorization:`Bearer ${o.token}`},retry:Oe,retryAttempts:1/0,url:`${o.ripploServerUrl}/graphql`}),v=wn({cwd:i,initialConcurrency:b});s.provide(v);let pr=await fn({cwd:i,pool:v}),$=gn({claim:p.claim,config:o,cwd:i,initialId:f.devSessionId,pool:v,sseClient:R,sseHealth:m}),fr=lr({cwd:i,projectId:o.projectId,sseClient:R}),mr=sr({pool:v,sseClient:R}),yr=yn({config:o,session:$}),gr=Cn(),U=await un({config:o,devSessionId:f.devSessionId,executor:n});u.resolve(),mn({devSessionId:f.devSessionId,executor:n,tunnel:U});let kr=async()=>{yr(),gr(),d.stop(),w.close(),$.stop(),fr(),mr(),await v.close(),await pn(U),await pr.stop().catch(()=>{}),await Promise.race([E({config:o,document:cn,variables:{cwd:o.cwd,projectId:o.projectId}}).catch(()=>{}),new Promise(wr=>setTimeout(wr,3e3))]),a()},P=()=>{kr().finally(()=>process.exit(0))};c.handler=P,process.on("SIGINT",P),process.on("SIGTERM",P),process.on("SIGHUP",P),process.on("SIGBREAK",P),await new Promise(()=>{})}async function un({config:e,devSessionId:n,executor:r}){if(r==="cloud")return qe({config:e,devSessionId:n})}async function pn(e){e!=null&&await e.stop()}function fn({cwd:e,pool:n}){return te({localDir:en.join(e,".ripplo",".local"),writePortFile:!0,onRrwebBatch:()=>{},onSpan:r=>{let t=r.attributes["ripplo.run"];t!=null&&n.routeSpan(t,r)}})}function mn({devSessionId:e,executor:n,tunnel:r}){process.stdout.write(`${ke({devSessionId:e,executor:n,tunnelHostname:r?.hostname,version:Q()})}
|
|
56
|
+
`)}function yn({config:e,session:n}){let r=async()=>{try{let o=await E({config:e,document:ln,variables:{id:n.getId()}});o.heartbeatDevSession?.__typename==="DevSessionEndedError"&&(l.warn("dev session ended server-side (%s); re-registering",o.heartbeatDevSession.message),await n.reregister())}catch(o){l.warn("heartbeat failed: %s",o instanceof Error?o.message:String(o))}},t=setInterval(()=>{r()},an);return()=>{clearInterval(t)}}function gn({claim:e,config:n,cwd:r,initialId:t,pool:o,sseClient:i,sseHealth:a}){let s=t,d=null,c=0,u=0,m=f=>{h(f)},p=()=>je({claim:e,cwd:r,devSessionId:s,onSubscriptionDead:m,pool:o,sseClient:i,sseHealth:a}),w=p(),S=async f=>{let b=Date.now();c=b-u>cr*2?1:c+1,u=b,c>=sn&&a.markUnhealthy(f),await kn(Math.min(1e3*2**(c-1),cr));let g=await A(r);if(g.isErr()){l.error("re-register: compile failed: %s",H(g.error));return}let R=await ur(()=>_({config:n,cwd:r,lockfile:g.value}),{config:n,label:"re-register sync"});w(),s=R.devSessionId,w=p(),l.info("re-registered dev session as %s",s)},h=f=>(d!=null||(d=S(f).finally(()=>{d=null})),d);return{getId:()=>s,reregister:()=>h("dev session ended server-side"),stop:()=>{w()}}}function kn(e){return new Promise(n=>setTimeout(n,e))}function wn({cwd:e,initialConcurrency:n}){return nr({initialSize:n,spawn:rr(Ln(),e),lockfileProvider:async r=>{let t=await y(e);return t.result.isErr()?{unavailable:`daemon-load-failed:${t.result.error.kind}`}:t.fingerprint!==r?{unavailable:"fingerprint-mismatch"}:{lockfileJson:J(K,t.result.value)}}})}function Sn(e){try{return ee({cwd:e,onCompromised:Rn})}catch(n){throw n instanceof Z&&(process.stderr.write(`${we({cwd:n.cwd,pid:n.pid})}
|
|
57
|
+
`),process.exit(1)),n}}function Rn(){l.error("daemon lock compromised; shutting down"),process.stderr.write(`${Se()}
|
|
58
|
+
`),process.exit(1)}function vn(){let e={handler:()=>{}};return{promise:new Promise(r=>{e.handler=r}),resolve:()=>{e.handler()}}}async function Pn({cwd:e,ipc:n,releasePid:r}){return(await Ge({cwd:e,onConnection:n.handleConnection})).match(o=>o,o=>{process.stderr.write(`${me(o)}
|
|
59
|
+
`),r(),process.exit(1)})}function xn(){let e={provide:()=>{}};return{pool:new Promise(r=>{e.provide=r}),provide:r=>{e.provide(r)}}}function hn(e){return C(e).match(n=>n,n=>{process.stderr.write(`${X(n)}
|
|
60
|
+
`),process.exit(1)})}function ur(e,{config:n,label:r}){let t=n.ripploServerUrl.includes("localhost")||n.ripploServerUrl.includes("127.0.0.1");return nn(async()=>{try{return await e()}catch(o){bn({config:n,error:o});let i=o instanceof Error?o.message:String(o);throw En(i)?o:(l.error("%s failed: %s",r,i),new on(i))}},{factor:2,maxTimeout:t?2e3:1e4,minTimeout:t?100:1e3,retries:1/0,onFailedAttempt:({attemptNumber:o,error:i})=>{l.warn("%s attempt %d failed \u2014 retrying: %s",r,o,i.message)}})}function bn({config:e,error:n}){let r=B(n);r==="UNAUTHENTICATED"&&(process.stderr.write(`ripplo: ${ge()}
|
|
61
|
+
`),process.exit(1)),r==="FORBIDDEN"&&(process.stderr.write(`ripplo: ${ye({projectId:e.projectId,serverUrl:e.ripploServerUrl})}
|
|
62
|
+
`),process.exit(1))}function En(e){return e.includes("status 502")||e.includes("ECONNREFUSED")||e.includes("Failed to connect")||e.includes("fetch failed")}function Cn(){D({maxRuns:dr});let e=setInterval(()=>{D({maxRuns:dr})},tn);return()=>{clearInterval(e)}}function In(){process.on("unhandledRejection",e=>{l.error({err:e},"unhandledRejection in watch; continuing")}),process.on("uncaughtException",e=>{l.error({err:e},"uncaughtException in watch; continuing")})}var Tn=4;async function Wn(e){try{let r=(await E({config:e,document:dn,variables:void 0})).currentUser?.maxLocalConcurrentRuns;if(r!=null)return T(r),r}catch(n){l.warn({err:n},"failed to fetch local concurrency setting; using default")}return Tn}function Ln(){let e=process.argv[1];if(e==null)throw new Error("cli entry unavailable");return e}export{at as runDaemon};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{$ as b,_ as a,aa as c,ba as d,ca as e,da as f,ea as g,fa as h,ga as i,ha as j,ia as k}from"./chunk-DAULBZMT.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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import"./chunk-7UWDMECF.js";var Z={signature:"GIF",version:"89a",trailer:59,extensionIntroducer:33,applicationExtensionLabel:255,graphicControlExtensionLabel:249,imageSeparator:44,signatureSize:3,versionSize:3,globalColorTableFlagMask:128,colorResolutionMask:112,sortFlagMask:8,globalColorTableSizeMask:7,applicationIdentifierSize:8,applicationAuthCodeSize:3,disposalMethodMask:28,userInputFlagMask:2,transparentColorFlagMask:1,localColorTableFlagMask:128,interlaceFlagMask:64,idSortFlagMask:32,localColorTableSizeMask:7};function K(t=256){let e=0,o=new Uint8Array(t);return{get buffer(){return o.buffer},reset(){e=0},bytesView(){return o.subarray(0,e)},bytes(){return o.slice(0,e)},writeByte(n){r(e+1),o[e]=n,e++},writeBytes(n,a=0,i=n.length){r(e+i);for(let c=0;c<i;c++)o[e++]=n[c+a]},writeBytesView(n,a=0,i=n.byteLength){r(e+i),o.set(n.subarray(a,a+i),e),e+=i}};function r(n){var a=o.length;if(a>=n)return;var i=1024*1024;n=Math.max(n,a*(a<i?2:1.125)>>>0),a!=0&&(n=Math.max(n,256));let c=o;o=new Uint8Array(n),e>0&&o.set(c.subarray(0,e),0)}}var D=12,_=5003,$=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535];function tt(t,e,o,r,n=K(512),a=new Uint8Array(256),i=new Int32Array(_),c=new Int32Array(_)){let w=i.length,u=Math.max(2,r);a.fill(0),c.fill(0),i.fill(-1);let f=0,l=0,h=u+1,B=h,y=!1,b=B,s=(1<<b)-1,A=1<<h-1,C=A+1,x=A+2,g=0,m=o[0],F=0;for(let M=w;M<65536;M*=2)++F;F=8-F,n.writeByte(u),v(A);let p=o.length;for(let M=1;M<p;M++)t:{let U=o[M],z=(U<<D)+m,k=U<<F^m;if(i[k]===z){m=c[k];break t}let R=k===0?1:w-k;for(;i[k]>=0;)if(k-=R,k<0&&(k+=w),i[k]===z){m=c[k];break t}v(m),m=U,x<1<<D?(c[k]=x++,i[k]=z):(i.fill(-1),x=A+2,y=!0,v(A))}return v(m),v(C),n.writeByte(0),n.bytesView();function v(M){for(f&=$[l],l>0?f|=M<<l:f=M,l+=b;l>=8;)a[g++]=f&255,g>=254&&(n.writeByte(g),n.writeBytesView(a,0,g),g=0),f>>=8,l-=8;if((x>s||y)&&(y?(b=B,s=(1<<b)-1,y=!1):(++b,s=b===D?1<<b:(1<<b)-1)),M==C){for(;l>0;)a[g++]=f&255,g>=254&&(n.writeByte(g),n.writeBytesView(a,0,g),g=0),f>>=8,l-=8;g>0&&(n.writeByte(g),n.writeBytesView(a,0,g),g=0)}}}var et=tt;function O(t,e,o){return t<<8&63488|e<<2&992|o>>3}function Q(t,e,o,r){return t>>4|e&240|(o&240)<<4|(r&240)<<8}function X(t,e,o){return t>>4<<8|e&240|o>>4}function V(t,e,o){return t<e?e:t>o?o:t}function q(t){return t*t}function j(t,e,o){var r=0,n=1e100;let a=t[e],i=a.cnt,c=a.ac,w=a.rc,u=a.gc,f=a.bc;for(var l=a.fw;l!=0;l=t[l].fw){let B=t[l],y=B.cnt,b=i*y/(i+y);if(!(b>=n)){var h=0;o&&(h+=b*q(B.ac-c),h>=n)||(h+=b*q(B.rc-w),!(h>=n)&&(h+=b*q(B.gc-u),!(h>=n)&&(h+=b*q(B.bc-f),!(h>=n)&&(n=h,r=l))))}}a.err=n,a.nn=r}function H(){return{ac:0,rc:0,gc:0,bc:0,cnt:0,nn:0,fw:0,bk:0,tm:0,mtm:0,err:0}}function rt(t,e){let o=e==="rgb444"?4096:65536,r=new Array(o),n=t.length;if(e==="rgba4444")for(let a=0;a<n;++a){let i=t[a],c=i>>24&255,w=i>>16&255,u=i>>8&255,f=i&255,l=Q(f,u,w,c),h=l in r?r[l]:r[l]=H();h.rc+=f,h.gc+=u,h.bc+=w,h.ac+=c,h.cnt++}else if(e==="rgb444")for(let a=0;a<n;++a){let i=t[a],c=i>>16&255,w=i>>8&255,u=i&255,f=X(u,w,c),l=f in r?r[f]:r[f]=H();l.rc+=u,l.gc+=w,l.bc+=c,l.cnt++}else for(let a=0;a<n;++a){let i=t[a],c=i>>16&255,w=i>>8&255,u=i&255,f=O(u,w,c),l=f in r?r[f]:r[f]=H();l.rc+=u,l.gc+=w,l.bc+=c,l.cnt++}return r}function bt(t,e,o={}){let{format:r="rgb565",clearAlpha:n=!0,clearAlphaColor:a=0,clearAlphaThreshold:i=0,oneBitAlpha:c=!1}=o;if(!t||!t.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(t instanceof Uint8Array)&&!(t instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");let w=new Uint32Array(t.buffer),u=o.useSqrt!==!1,f=r==="rgba4444",l=rt(w,r),h=l.length,B=h-1,y=new Uint32Array(h+1);for(var b=0,s=0;s<h;++s){let d=l[s];if(d!=null){var A=1/d.cnt;f&&(d.ac*=A),d.rc*=A,d.gc*=A,d.bc*=A,l[b++]=d}}q(e)/b<.022&&(u=!1);for(var s=0;s<b-1;++s)l[s].fw=s+1,l[s+1].bk=s,u&&(l[s].cnt=Math.sqrt(l[s].cnt));u&&(l[s].cnt=Math.sqrt(l[s].cnt));var C,x,g;for(s=0;s<b;++s){j(l,s,!1);var m=l[s].err;for(x=++y[0];x>1&&(g=x>>1,!(l[C=y[g]].err<=m));x=g)y[x]=C;y[x]=s}var F=b-e;for(s=0;s<F;){for(var p;;){var v=y[1];if(p=l[v],p.tm>=p.mtm&&l[p.nn].mtm<=p.tm)break;p.mtm==B?v=y[1]=y[y[0]--]:(j(l,v,!1),p.tm=s);var m=l[v].err;for(x=1;(g=x+x)<=y[0]&&(g<y[0]&&l[y[g]].err>l[y[g+1]].err&&g++,!(m<=l[C=y[g]].err));x=g)y[x]=C;y[x]=v}var M=l[p.nn],U=p.cnt,z=M.cnt,A=1/(U+z);f&&(p.ac=A*(U*p.ac+z*M.ac)),p.rc=A*(U*p.rc+z*M.rc),p.gc=A*(U*p.gc+z*M.gc),p.bc=A*(U*p.bc+z*M.bc),p.cnt+=M.cnt,p.mtm=++s,l[M.bk].fw=M.fw,l[M.fw].bk=M.bk,M.mtm=B}let k=[];var R=0;for(s=0;;++R){let d=V(Math.round(l[s].rc),0,255),P=V(Math.round(l[s].gc),0,255),L=V(Math.round(l[s].bc),0,255),S=255;f&&(S=V(Math.round(l[s].ac),0,255),c&&(S=S<=(typeof c=="number"?c:127)?0:255),n&&S<=i&&(d=P=L=a,S=0));let W=f?[d,P,L,S]:[d,P,L];if(nt(k,W)||k.push(W),(s=l[s].fw)==0)break}return k}function nt(t,e){for(let o=0;o<t.length;o++){let r=t[o],n=r[0]===e[0]&&r[1]===e[1]&&r[2]===e[2],a=r.length>=4&&e.length>=4?r[3]===e[3]:!0;if(n&&a)return!0}return!1}function T(t,e){var o=0,r;for(r=0;r<t.length;r++){let n=t[r]-e[r];o+=n*n}return o}function G(t,e){return e>1?Math.round(t/e)*e:t}function gt(t,{roundRGB:e=5,roundAlpha:o=10,oneBitAlpha:r=null}={}){let n=new Uint32Array(t.buffer);for(let a=0;a<n.length;a++){let i=n[a],c=i>>24&255,w=i>>16&255,u=i>>8&255,f=i&255;c=G(c,o),r&&(c=c<=(typeof r=="number"?r:127)?0:255),f=G(f,e),u=G(u,e),w=G(w,e),n[a]=c<<24|w<<16|u<<8|f<<0}}function pt(t,e,o="rgb565"){if(!t||!t.buffer)throw new Error("quantize() expected RGBA Uint8Array data");if(!(t instanceof Uint8Array)&&!(t instanceof Uint8ClampedArray))throw new Error("quantize() expected RGBA Uint8Array data");if(e.length>256)throw new Error("applyPalette() only works with 256 colors or less");let r=new Uint32Array(t.buffer),n=r.length,a=o==="rgb444"?4096:65536,i=new Uint8Array(n),c=new Array(a),w=o==="rgba4444";if(o==="rgba4444")for(let u=0;u<n;u++){let f=r[u],l=f>>24&255,h=f>>16&255,B=f>>8&255,y=f&255,b=Q(y,B,h,l),s=b in c?c[b]:c[b]=at(y,B,h,l,e);i[u]=s}else{let u=o==="rgb444"?X:O;for(let f=0;f<n;f++){let l=r[f],h=l>>16&255,B=l>>8&255,y=l&255,b=u(y,B,h),s=b in c?c[b]:c[b]=it(y,B,h,e);i[f]=s}}return i}function at(t,e,o,r,n){let a=0,i=1e100;for(let c=0;c<n.length;c++){let w=n[c],u=w[3],f=I(u-r);if(f>i)continue;let l=w[0];if(f+=I(l-t),f>i)continue;let h=w[1];if(f+=I(h-e),f>i)continue;let B=w[2];f+=I(B-o),!(f>i)&&(i=f,a=c)}return a}function it(t,e,o,r){let n=0,a=1e100;for(let i=0;i<r.length;i++){let c=r[i],w=c[0],u=I(w-t);if(u>a)continue;let f=c[1];if(u+=I(f-e),u>a)continue;let l=c[2];u+=I(l-o),!(u>a)&&(a=u,n=i)}return n}function Bt(t,e,o=5){if(!t.length||!e.length)return;let r=t.map(i=>i.slice(0,3)),n=o*o,a=t[0].length;for(let i=0;i<e.length;i++){let c=e[i];c.length<a?c=[c[0],c[1],c[2],255]:c.length>a?c=c.slice(0,3):c=c.slice();let w=ot(r,c.slice(0,3),T),u=w[0],f=w[1];f>0&&f<=n&&(t[u]=c)}}function I(t){return t*t}function lt(t,e,o=T){let r=1/0,n=-1;for(let a=0;a<t.length;a++){let i=t[a],c=o(e,i);c<r&&(r=c,n=a)}return n}function ot(t,e,o=T){let r=1/0,n=-1;for(let a=0;a<t.length;a++){let i=t[a],c=o(e,i);c<r&&(r=c,n=a)}return[n,r]}function At(t,e,o=T){return t[lt(t,e,o)]}function ct(t={}){let{initialCapacity:e=4096,auto:o=!0}=t,r=K(e),n=5003,a=new Uint8Array(256),i=new Int32Array(n),c=new Int32Array(n),w=!1;return{reset(){r.reset(),w=!1},finish(){r.writeByte(Z.trailer)},bytes(){return r.bytes()},bytesView(){return r.bytesView()},get buffer(){return r.buffer},get stream(){return r},writeHeader:u,writeFrame(f,l,h,B={}){let{transparent:y=!1,transparentIndex:b=0,delay:s=0,palette:A=null,repeat:C=0,colorDepth:x=8,dispose:g=-1}=B,m=!1;if(o?w||(m=!0,u(),w=!0):m=!!B.first,l=Math.max(0,Math.floor(l)),h=Math.max(0,Math.floor(h)),m){if(!A)throw new Error("First frame must include a { palette } option");ut(r,l,h,A,x),J(r,A),C>=0&&st(r,C)}let F=Math.round(s/10);ft(r,g,F,y,b);let p=!!A&&!m;wt(r,l,h,p?A:null),p&&J(r,A),ht(r,f,l,h,x,a,i,c)}};function u(){Y(r,"GIF89a")}}function ft(t,e,o,r,n){t.writeByte(33),t.writeByte(249),t.writeByte(4),n<0&&(n=0,r=!1);var a,i;r?(a=1,i=2):(a=0,i=0),e>=0&&(i=e&7),i<<=2,t.writeByte(0|i|0|a),E(t,o),t.writeByte(n||0),t.writeByte(0)}function ut(t,e,o,r,n=8){let a=1,i=0,c=N(r.length)-1,w=a<<7|n-1<<4|i<<3|c;E(t,e),E(t,o),t.writeBytes([w,0,0])}function st(t,e){t.writeByte(33),t.writeByte(255),t.writeByte(11),Y(t,"NETSCAPE2.0"),t.writeByte(3),t.writeByte(1),E(t,e),t.writeByte(0)}function J(t,e){let o=1<<N(e.length);for(let r=0;r<o;r++){let n=[0,0,0];r<e.length&&(n=e[r]),t.writeByte(n[0]),t.writeByte(n[1]),t.writeByte(n[2])}}function wt(t,e,o,r){if(t.writeByte(44),E(t,0),E(t,0),E(t,e),E(t,o),r){let n=0,a=0,i=N(r.length)-1;t.writeByte(128|n|a|0|i)}else t.writeByte(0)}function ht(t,e,o,r,n=8,a,i,c){et(o,r,e,n,t,a,i,c)}function E(t,e){t.writeByte(e&255),t.writeByte(e>>8&255)}function Y(t,e){for(var o=0;o<e.length;o++)t.writeByte(e.charCodeAt(o))}function N(t){return Math.max(Math.ceil(Math.log2(t)),1)}var Mt=ct;export{ct as GIFEncoder,pt as applyPalette,Mt as default,At as nearestColor,lt as nearestColorIndex,ot as nearestColorIndexWithDistance,gt as prequantize,bt as quantize,Bt as snapColorsToPalette};
|