@sourcegraph/amp 0.0.1774123285-gb6e451 → 0.0.1774126892-geb7ca3

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.
Files changed (2) hide show
  1. package/dist/main.js +9 -9
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -116,7 +116,7 @@ Expected format:
116
116
  `+Object.keys(Y).map((X)=>`${X}: ${Y[X]}`).join(`\r
117
117
  `)+`\r
118
118
  \r
119
- `+Q)}function NE(J,Z,Q,Y,X,K){if(J.listenerCount("wsClientError")){let V=Error(X);Error.captureStackTrace(V,NE),J.emit("wsClientError",V,Q,Z)}else fb(Q,Y,X,K)}});var nb1={};J9(nb1,{default:()=>sx6,createWebSocketStream:()=>db1.default,WebSocketServer:()=>ib1.default,WebSocket:()=>aR0.default,Sender:()=>lb1.default,Receiver:()=>cb1.default});var db1,cb1,lb1,aR0,ib1,sx6;var ab1=Y0(()=>{db1=z4(xb1(),1),cb1=z4(hR0(),1),lb1=z4(mR0(),1),aR0=z4(F40(),1),ib1=z4(pb1(),1),sx6=aR0.default});class rb1{_status={};statusSubject=new Y4(this._status);messageSubject=new Y4(null);appendToPromptSubject=new Y4(null);projectConfig;queryPollTimeout;queryPollToken=0;querySource;ws;id=1;reconnectTimeoutId;reconnectStartTime;isReconnecting=!1;connectionSource="never-connected";pendingRequests=new Map;constructor(){this.statusSubject.subscribe((J)=>{if(J.ideName){let Z=t10(J.ideName);if(Z)VE(Z)}})}get status(){return new k0((J)=>{J.next(this._status);let Z=this.statusSubject.subscribe(J);return()=>Z.unsubscribe()})}sendStatus(J){this._status={...this._status,...J},this.statusSubject.next(this._status)}getIdeName(){return this._status.ideName||"ide"}get messages(){return new k0((J)=>{let Z=this.messageSubject.subscribe((Q)=>{if(Q!==null)J.next(Q)});return()=>Z.unsubscribe()})}get appendToPrompt(){return new k0((J)=>{let Z=this.appendToPromptSubject.subscribe((Q)=>{if(Q!==null)J.next(Q)});return()=>Z.unsubscribe()})}emitMessage(J){this.messageSubject.next(J)}emitAppendToPrompt(J){this.appendToPromptSubject.next(J)}async start(J,Z=!1,Q){let Y=Z||!this.projectConfig||this.projectConfig.port!==J.port||this.projectConfig.authToken!==J.authToken||this.projectConfig.connection!==J.connection||this.projectConfig.workspaceId!==J.workspaceId;if(this.projectConfig=J,this.sendStatus({enabled:!0}),this.connectionSource=Q??"auto-startup",Y&&this.ws)this.ws.close(),this.ws=void 0,this.clearPendingRequests();this.stopQueryPolling(),await this.tryConnect(this.projectConfig)}sendRequest=(J,Z)=>{let Q=this.ws;if(!Q)return Promise.resolve(void 0);if(!this.isWsOpen())return Promise.reject(Error("WebSocket is not open"));return new Promise((Y,X)=>{let K=`${this.id++}`,V={clientRequest:{id:K,[J]:Z}},z=setTimeout(()=>{this.pendingRequests.delete(K),X(Error(`Timeout after ${ob1}ms for request ${JSON.stringify(V,null,2)}`))},ob1);this.pendingRequests.set(K,{resolve:Y,reject:X,timeout:z,method:J}),Q.send(JSON.stringify(V))})};clearPendingRequests(){for(let[J,Z]of this.pendingRequests.entries())clearTimeout(Z.timeout),Z.reject(Error("WebSocket connection closed"));this.pendingRequests.clear()}handleResponse(J){if(!J?.id)return;let Z=this.pendingRequests.get(J.id);if(!Z)return;if(I.debug("ide-client: received response",{type:"response_received",source:this.getIdeName(),responseId:J?.id,hasError:!!J?.error}),clearTimeout(Z.timeout),this.pendingRequests.delete(J.id),J.error){Z.reject(Error(JSON.stringify(J.error)));return}let Q=J[Z.method];if(Q)Z.resolve(Q);else Z.reject(Error(`Invalid response for method ${Z.method}. Got ${JSON.stringify(J,null,2)}`))}async tryConnect(J){if(J.connection==="query"){let Y=this.resolveQuery(J);if(Y)this.startQueryPolling(J,Y);return}if(await this.isConnected()){I.debug("ide-client: already connected",{type:"already_connected",source:this.getIdeName()});return}if(this.clearReconnectTimeout(),this.ws?.close(),this.clearPendingRequests(),!J){this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE Not Connected"});return}this.sendStatus({ideName:J.ideName});let Q=new(await Jf6())(`ws://localhost:${J.port}?auth=${encodeURIComponent(J.authToken)}`);this.ws=Q,this.id=1,Q.onopen=async()=>{try{if(I.info("ide-client: connected",{type:"connected",source:this.getIdeName(),ideName:J.ideName,port:J.port}),this.connectionSource!=="never-connected")this.connectionSource="user-initiated";this.clearReconnectTimeout(),this.reconnectStartTime=void 0,this.isReconnecting=!1,this.sendStatus({connected:!0,authenticated:!0,connectionState:"connected",reconnectElapsedMs:void 0,errorMessage:void 0})}catch(Y){I.error("ide-client: connection error",Y),this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE Not Connected"})}},Q.onclose=(Y)=>{try{if(this.clearPendingRequests(),Y.code===1000&&Y.reason==="Authentication failed")this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE authentication failed - try restarting your IDE"});else I.warn("ide-client: disconnected",{code:Y.code,reason:Y.reason}),this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE Not Connected"});this.ws=void 0,this.scheduleReconnect()}catch(X){I.error("ide-client: disconnect error",X)}},Q.onerror=()=>{this.clearPendingRequests()},Q.onmessage=async(Y)=>{let X=Y.data.toString();try{let K=Du1.safeParse(JSON.parse(X));if(K.error){I.error("ide-client: failed to parse server message",y.prettifyError(K.error));return}if(K.data?.serverResponse)this.handleResponse(K.data.serverResponse);this.handleNotification(K.data?.serverNotification)}catch(K){I.error("ide-client: error handling server message",{error:K,data:X})}}}clearReconnectTimeout(){if(this.reconnectTimeoutId)clearTimeout(this.reconnectTimeoutId),this.reconnectTimeoutId=void 0}scheduleReconnect(){if(this.connectionSource==="never-connected")return;if(this.isReconnecting)return;if(!this.reconnectStartTime)this.reconnectStartTime=Date.now();let J=Date.now()-this.reconnectStartTime;if(J>=ex6){this.sendStatus({connectionState:"disconnected",reconnectElapsedMs:J});let Z=60000-J;if(Z>0)this.clearReconnectTimeout(),this.reconnectTimeoutId=setTimeout(()=>{let Q=Date.now()-(this.reconnectStartTime||Date.now());this.sendStatus({connectionState:"disconnected",reconnectElapsedMs:Q})},Z);return}this.isReconnecting=!0,this.sendStatus({connectionState:"reconnecting",reconnectElapsedMs:J,ideName:this.projectConfig?.ideName}),this.reconnectTimeoutId=setTimeout(()=>{this.executeReconnectAttempt().catch((Z)=>{I.error("ide-client: reconnect timer failed",Z)})},tx6)}async executeReconnectAttempt(){try{if(!this.projectConfig){I.debug("ide-client: no config available during reconnect, will retry");return}let J=await this.resolveActiveConfig(this.projectConfig);this.projectConfig=J,await this.tryConnect(J)}catch(J){I.error("ide-client: reconnect loop error",J)}finally{this.handleReconnectResult(await this.isConnected())}}async resolveActiveConfig(J){if(J.connection==="query"){let{config:Q}=await this.findQueryConfig(J);return Q??J}if(CW(J.pid))return J;return(await UE()).find((Q)=>Q.ideName===J.ideName&&Q.workspaceFolders.length===J.workspaceFolders.length&&Q.workspaceFolders.every((Y)=>J.workspaceFolders.includes(Y)))??J}handleReconnectResult(J){if(this.isReconnecting=!1,!J)this.scheduleReconnect();else this.clearReconnectTimeout(),this.reconnectStartTime=void 0,this.sendStatus({connectionState:"connected",reconnectElapsedMs:void 0})}startQueryPolling(J,Z){this.stopQueryPolling();let Q=++this.queryPollToken;this.querySource={config:J,query:Z},this.sendStatus({ideName:Z.ideName,workspace:J.workspaceFolders[0],connected:!0,authenticated:!0,connectionState:"connected",reconnectElapsedMs:void 0,errorMessage:void 0});let Y=async()=>{if(Q!==this.queryPollToken)return;let X;try{X=await Z.readWorkspaceState(J)}catch(K){I.warn("ide-client: query poll failed",{ideName:Z.ideName,error:K}),X=null}if(Q!==this.queryPollToken)return;if(!X){this.sendStatus({connected:!1,authenticated:!1,connectionState:"disconnected",errorMessage:`${Z.ideName} Not Connected`,openFile:void 0,selections:void 0,visibleFiles:void 0}),this.stopQueryPolling(),this.scheduleReconnect();return}this.sendStatus({connected:!0,authenticated:!0,connectionState:"connected",openFile:X.openFile,selections:X.selection?[X.selection]:void 0,visibleFiles:X.openFiles}),this.queryPollTimeout=setTimeout(()=>{Y()},$f6)};Y()}stopQueryPolling(){if(this.queryPollToken+=1,this.queryPollTimeout)clearTimeout(this.queryPollTimeout),this.queryPollTimeout=void 0}isWsOpen(){return this.ws?.readyState===1}async isConnected(){if(this.projectConfig?.connection==="query")return this._status.connected===!0;if(!this._status.authenticated)return!1;if(!this.isWsOpen())return!1;try{return(await this.sendRequest("ping",{message:"beepboop"}))?.message==="beepboop"}catch(J){return I.debug("isConnected ping failed",{error:J}),!1}}async requestDiagnosticsFromIDE(J){try{return await this.sendRequest("getDiagnostics",{path:J})}catch(Z){I.debug("ide-diags: failed to request diagnostics from IDE",{error:Z,path:J});return}}async openURIInIDE(J){if(this.projectConfig?.connection==="query")return this.querySource?.query.openURI(J);if(!this.isWsOpen())return;try{let Z=await this.sendRequest("openURI",{uri:J});if(!Z)return!1;return!!Z.success}catch(Z){return I.debug("ide-client: openURI request failed",{error:Z,uri:J}),!1}}handleNotification(J){if(!J)return;if(J.selectionDidChange)this.sendStatus({selections:J.selectionDidChange.selections,openFile:J.selectionDidChange.uri});else if(J.visibleFilesDidChange){let Z=J.visibleFilesDidChange.uris;this.sendStatus({visibleFiles:Z,...Z.length===0&&{openFile:void 0,selections:void 0}})}else if(J.pluginMetadata)this.sendStatus({pluginVersion:J.pluginMetadata.version,pluginDirectory:J.pluginMetadata.pluginDirectory});else if(J.userSentMessage)this.handleMessageFromIDE(J.userSentMessage.message);else if(J.appendToPrompt)this.handleAppendToPrompt(J.appendToPrompt.message)}async handleMessageFromIDE(J){I.debug("Received message from IDE",{message:J.slice(0,100)}),this.emitMessage(J)}handleAppendToPrompt(J){I.debug("Received appendToPrompt from IDE",{text:J.slice(0,100)}),this.emitAppendToPrompt(J)}async findQueryConfig(J){let Q=(J.workspaceId?J:(await this.listQueryConfigs()).find((X)=>X.workspaceFolders.every((K)=>J.workspaceFolders.includes(K))))??(await UE({includeAll:!0})).find((X)=>X.connection==="query"&&X.workspaceId===J.workspaceId);if(!Q)return{};let Y=this.resolveQuery(Q);if(!Y)return{config:Q};return{query:Y,config:Q}}async listQueryConfigs(){return(await Promise.all(qE.map(async(Z)=>{try{return await Z.listConfigs()}catch(Q){return I.debug("ide-client: failed to list query configs",{ideName:Z.ideName,error:Q}),[]}}))).flat()}resolveQuery(J){return qE.find((Z)=>Z.ideName===J.ideName)}selectConfig(J){this.projectConfig=J}getSelectedConfig(){return this.projectConfig}}async function Jf6(){if(typeof WebSocket<"u")return WebSocket;let{default:J}=await Promise.resolve().then(() => (ab1(),nb1));return J}var ob1=2000,tx6=1000,ex6=30000,$f6=1000,N$;var wE=Y0(()=>{N1();j9();g0();ZJ();r10();FE();e10();OR0();N$=new rb1});var rR0,sR0,tR0,ub;var W40=Y0(()=>{rR0=class rR0 extends Error{constructor(J="Unauthorized"){super(J);this.name="UnauthorizedError"}};sR0=class sR0 extends Error{constructor(J="OAuth callback timeout"){super(J);this.name="OAuthTimeoutError"}};tR0=class tR0 extends Error{serverName;constructor(J){super(`OAuth flow skipped for "${J}"`);this.serverName=J;this.name="OAuthSkippedError"}};ub=class ub extends Error{serverName;holderPid;constructor(J,Z){super(`OAuth flow already in progress for "${J}" (held by PID ${Z})`);this.serverName=J;this.holderPid=Z;this.name="OAuthFlowInProgressError"}}});import{randomBytes as qf6}from"node:crypto";import*as sZ from"node:fs/promises";import*as JI0 from"node:path";function $h1(J){return N40(J)}function Uf6(J){return J.replace(/[^a-zA-Z0-9_-]/g,"_")}function N40(J){return JI0.join(eb1,`${Uf6(J)}.lock`)}async function Df6(){await sZ.mkdir(eb1,{recursive:!0,mode:448})}function Hf6(J){try{return process.kill(J,0),!0}catch{return!1}}function $I0(J){if(Date.now()-J.timestamp>Wf6)return!0;let Q=R0("node:os").hostname();if(J.hostname===Q&&!Hf6(J.pid))return!0;return!1}async function D40(J){let Z=N40(J);try{let Q=await sZ.readFile(Z,"utf8"),Y=JSON.parse(Q);if(typeof Y.pid!=="number"||typeof Y.timestamp!=="number")return I.warn("Invalid lock file structure, treating as stale",{serverName:J,lockPath:Z}),null;return Y}catch(Q){if(Q?.code==="ENOENT")return null;return I.debug("Failed to read lock file",{serverName:J,error:Q.message}),null}}async function OE(J){await Df6();let Z=N40(J),Q=await D40(J);if(Q)if($I0(Q)){I.info("Removing stale OAuth lock",{serverName:J,stalePid:Q.pid,ageMs:Date.now()-Q.timestamp});try{await sZ.unlink(Z)}catch{}}else return I.debug("OAuth lock held by another process",{serverName:J,holderPid:Q.pid,ageMs:Date.now()-Q.timestamp}),{acquired:!1,holder:Q};let Y={pid:process.pid,timestamp:Date.now(),hostname:R0("node:os").hostname()},X=JSON.stringify(Y),K=`${Z}.${process.pid}.${qf6(4).toString("hex")}`;try{let V=await sZ.open(K,"wx",384);try{await V.writeFile(X),await V.sync()}finally{await V.close()}try{return await sZ.link(K,Z),await sZ.unlink(K).catch(()=>{}),I.info("Acquired OAuth lock",{serverName:J,pid:process.pid}),{acquired:!0}}catch(z){if(await sZ.unlink(K).catch(()=>{}),z?.code==="EEXIST"){let G=await D40(J);if(G&&!$I0(G))return I.debug("Lost OAuth lock race to another process",{serverName:J,winnerPid:G.pid}),{acquired:!1,holder:G};return OE(J)}throw z}}catch(V){if(await sZ.unlink(K).catch(()=>{}),V?.code==="EEXIST"){let z=await D40(J);if(z&&!$I0(z))return{acquired:!1,holder:z};return OE(J)}throw I.error("Failed to acquire OAuth lock",{serverName:J,error:V.message}),V}}async function NC(J){let Z=N40(J);try{let Q=await D40(J);if(!Q){I.debug("No lock to release",{serverName:J});return}if(Q.pid!==process.pid){I.warn("Cannot release lock owned by another process",{serverName:J,ownerPid:Q.pid,ourPid:process.pid});return}await sZ.unlink(Z),I.info("Released OAuth lock",{serverName:J,pid:process.pid})}catch(Q){if(Q?.code==="ENOENT")return;I.error("Failed to release OAuth lock",{serverName:J,error:Q.message})}}var eb1,Wf6=300000,H40=2000,B40=300000;var ZI0=Y0(()=>{TX();g0();eb1=JI0.join($C,"oauth","locks")});function Qh1(J){return J.replace(/ /g,"\\ ")}var Zh1=100;var XI0=()=>{};var hb=b((T68,Xh1)=>{var Yh1={DOT_LITERAL:"\\.",PLUS_LITERAL:"\\+",QMARK_LITERAL:"\\?",SLASH_LITERAL:"\\/",ONE_CHAR:"(?=.)",QMARK:"[^/]",END_ANCHOR:"(?:\\/|$)",DOTS_SLASH:"\\.{1,2}(?:\\/|$)",NO_DOT:"(?!\\.)",NO_DOTS:"(?!(?:^|\\/)\\.{1,2}(?:\\/|$))",NO_DOT_SLASH:"(?!\\.{0,1}(?:\\/|$))",NO_DOTS_SLASH:"(?!\\.{1,2}(?:\\/|$))",QMARK_NO_DOT:"[^.\\/]",STAR:"[^/]*?",START_ANCHOR:"(?:^|\\/)",SEP:"/"},Of6={...Yh1,SLASH_LITERAL:"[\\\\/]",QMARK:"[^\\\\/]",STAR:"[^\\\\/]*?",DOTS_SLASH:"\\.{1,2}(?:[\\\\/]|$)",NO_DOT:"(?!\\.)",NO_DOTS:"(?!(?:^|[\\\\/])\\.{1,2}(?:[\\\\/]|$))",NO_DOT_SLASH:"(?!\\.{0,1}(?:[\\\\/]|$))",NO_DOTS_SLASH:"(?!\\.{1,2}(?:[\\\\/]|$))",QMARK_NO_DOT:"[^.\\\\/]",START_ANCHOR:"(?:^|[\\\\/])",END_ANCHOR:"(?:[\\\\/]|$)",SEP:"\\"},Lf6={alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"\\x21-\\x7E",lower:"a-z",print:"\\x20-\\x7E ",punct:"\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",space:" \\t\\r\\n\\v\\f",upper:"A-Z",word:"A-Za-z0-9_",xdigit:"A-Fa-f0-9"};Xh1.exports={MAX_LENGTH:65536,POSIX_REGEX_SOURCE:Lf6,REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{__proto__:null,"***":"*","**/**":"**","**/**/**":"**"},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(J){return{"!":{type:"negate",open:"(?:(?!(?:",close:`))${J.STAR})`},"?":{type:"qmark",open:"(?:",close:")?"},"+":{type:"plus",open:"(?:",close:")+"},"*":{type:"star",open:"(?:",close:")*"},"@":{type:"at",open:"(?:",close:")"}}},globChars(J){return J===!0?Of6:Yh1}}});var gb=b((Rf6)=>{var{REGEX_BACKSLASH:Ef6,REGEX_REMOVE_BACKSLASH:Mf6,REGEX_SPECIAL_CHARS:Af6,REGEX_SPECIAL_CHARS_GLOBAL:jf6}=hb();Rf6.isObject=(J)=>J!==null&&typeof J==="object"&&!Array.isArray(J);Rf6.hasRegexChars=(J)=>Af6.test(J);Rf6.isRegexChar=(J)=>J.length===1&&Rf6.hasRegexChars(J);Rf6.escapeRegex=(J)=>J.replace(jf6,"\\$1");Rf6.toPosixSlashes=(J)=>J.replace(Ef6,"/");Rf6.isWindows=()=>{if(typeof navigator<"u"&&navigator.platform){let J=navigator.platform.toLowerCase();return J==="win32"||J==="windows"}if(typeof process<"u"&&process.platform)return process.platform==="win32";return!1};Rf6.removeBackslashes=(J)=>{return J.replace(Mf6,(Z)=>{return Z==="\\"?"":Z})};Rf6.escapeLast=(J,Z,Q)=>{let Y=J.lastIndexOf(Z,Q);if(Y===-1)return J;if(J[Y-1]==="\\")return Rf6.escapeLast(J,Z,Y-1);return`${J.slice(0,Y)}\\${J.slice(Y)}`};Rf6.removePrefix=(J,Z={})=>{let Q=J;if(Q.startsWith("./"))Q=Q.slice(2),Z.prefix="./";return Q};Rf6.wrapOutput=(J,Z={},Q={})=>{let Y=Q.contains?"":"^",X=Q.contains?"":"$",K=`${Y}(?:${J})${X}`;if(Z.negated===!0)K=`(?:^(?!${K}).*$)`;return K};Rf6.basename=(J,{windows:Z}={})=>{let Q=J.split(Z?/[\\/]/:"/"),Y=Q[Q.length-1];if(Y==="")return Q[Q.length-2];return Y}});var Hh1=b((S68,Dh1)=>{var zh1=gb(),{CHAR_ASTERISK:KI0,CHAR_AT:xf6,CHAR_BACKWARD_SLASH:mb,CHAR_COMMA:ff6,CHAR_DOT:VI0,CHAR_EXCLAMATION_MARK:zI0,CHAR_FORWARD_SLASH:Uh1,CHAR_LEFT_CURLY_BRACE:GI0,CHAR_LEFT_PARENTHESES:FI0,CHAR_LEFT_SQUARE_BRACKET:uf6,CHAR_PLUS:bf6,CHAR_QUESTION_MARK:Gh1,CHAR_RIGHT_CURLY_BRACE:hf6,CHAR_RIGHT_PARENTHESES:Fh1,CHAR_RIGHT_SQUARE_BRACKET:gf6}=hb(),qh1=(J)=>{return J===Uh1||J===mb},Wh1=(J)=>{if(J.isPrefix!==!0)J.depth=J.isGlobstar?1/0:1},mf6=(J,Z)=>{let Q=Z||{},Y=J.length-1,X=Q.parts===!0||Q.scanToEnd===!0,K=[],V=[],z=[],G=J,F=-1,q=0,W=0,U=!1,D=!1,H=!1,B=!1,N=!1,w=!1,O=!1,L=!1,E=!1,M=!1,A=0,j,R,_={value:"",depth:0,isGlob:!1},k=()=>F>=Y,u=()=>G.charCodeAt(F+1),m=()=>{return j=R,G.charCodeAt(++F)};while(F<Y){R=m();let d;if(R===mb){if(O=_.backslashes=!0,R=m(),R===GI0)w=!0;continue}if(w===!0||R===GI0){A++;while(k()!==!0&&(R=m())){if(R===mb){O=_.backslashes=!0,m();continue}if(R===GI0){A++;continue}if(w!==!0&&R===VI0&&(R=m())===VI0){if(U=_.isBrace=!0,H=_.isGlob=!0,M=!0,X===!0)continue;break}if(w!==!0&&R===ff6){if(U=_.isBrace=!0,H=_.isGlob=!0,M=!0,X===!0)continue;break}if(R===hf6){if(A--,A===0){w=!1,U=_.isBrace=!0,M=!0;break}}}if(X===!0)continue;break}if(R===Uh1){if(K.push(F),V.push(_),_={value:"",depth:0,isGlob:!1},M===!0)continue;if(j===VI0&&F===q+1){q+=2;continue}W=F+1;continue}if(Q.noext!==!0){if((R===bf6||R===xf6||R===KI0||R===Gh1||R===zI0)===!0&&u()===FI0){if(H=_.isGlob=!0,B=_.isExtglob=!0,M=!0,R===zI0&&F===q)E=!0;if(X===!0){while(k()!==!0&&(R=m())){if(R===mb){O=_.backslashes=!0,R=m();continue}if(R===Fh1){H=_.isGlob=!0,M=!0;break}}continue}break}}if(R===KI0){if(j===KI0)N=_.isGlobstar=!0;if(H=_.isGlob=!0,M=!0,X===!0)continue;break}if(R===Gh1){if(H=_.isGlob=!0,M=!0,X===!0)continue;break}if(R===uf6){while(k()!==!0&&(d=m())){if(d===mb){O=_.backslashes=!0,m();continue}if(d===gf6){D=_.isBracket=!0,H=_.isGlob=!0,M=!0;break}}if(X===!0)continue;break}if(Q.nonegate!==!0&&R===zI0&&F===q){L=_.negated=!0,q++;continue}if(Q.noparen!==!0&&R===FI0){if(H=_.isGlob=!0,X===!0){while(k()!==!0&&(R=m())){if(R===FI0){O=_.backslashes=!0,R=m();continue}if(R===Fh1){M=!0;break}}continue}break}if(H===!0){if(M=!0,X===!0)continue;break}}if(Q.noext===!0)B=!1,H=!1;let x=G,T="",f="";if(q>0)T=G.slice(0,q),G=G.slice(q),W-=q;if(x&&H===!0&&W>0)x=G.slice(0,W),f=G.slice(W);else if(H===!0)x="",f=G;else x=G;if(x&&x!==""&&x!=="/"&&x!==G){if(qh1(x.charCodeAt(x.length-1)))x=x.slice(0,-1)}if(Q.unescape===!0){if(f)f=zh1.removeBackslashes(f);if(x&&O===!0)x=zh1.removeBackslashes(x)}let p={prefix:T,input:J,start:q,base:x,glob:f,isBrace:U,isBracket:D,isGlob:H,isExtglob:B,isGlobstar:N,negated:L,negatedExtglob:E};if(Q.tokens===!0){if(p.maxDepth=0,!qh1(R))V.push(_);p.tokens=V}if(Q.parts===!0||Q.tokens===!0){let d;for(let h=0;h<K.length;h++){let n=d?d+1:q,c=K[h],s=J.slice(n,c);if(Q.tokens){if(h===0&&q!==0)V[h].isPrefix=!0,V[h].value=T;else V[h].value=s;Wh1(V[h]),p.maxDepth+=V[h].depth}if(h!==0||s!=="")z.push(s);d=c}if(d&&d+1<J.length){let h=J.slice(d+1);if(z.push(h),Q.tokens)V[V.length-1].value=h,Wh1(V[V.length-1]),p.maxDepth+=V[V.length-1].depth}p.slashes=K,p.parts=z}return p};Dh1.exports=mf6});var wh1=b((k68,Nh1)=>{var w40=hb(),uG=gb(),{MAX_LENGTH:O40,POSIX_REGEX_SOURCE:pf6,REGEX_NON_SPECIAL_CHARS:df6,REGEX_SPECIAL_CHARS_BACKREF:cf6,REPLACEMENTS:Bh1}=w40,lf6=(J,Z)=>{if(typeof Z.expandRange==="function")return Z.expandRange(...J,Z);J.sort();let Q=`[${J.join("-")}]`;try{new RegExp(Q)}catch(Y){return J.map((X)=>uG.escapeRegex(X)).join("..")}return Q},wC=(J,Z)=>{return`Missing ${J}: "${Z}" - use "\\\\${Z}" to match literal characters`},qI0=(J,Z)=>{if(typeof J!=="string")throw TypeError("Expected a string");J=Bh1[J]||J;let Q={...Z},Y=typeof Q.maxLength==="number"?Math.min(O40,Q.maxLength):O40,X=J.length;if(X>Y)throw SyntaxError(`Input length: ${X}, exceeds maximum allowed length: ${Y}`);let K={type:"bos",value:"",output:Q.prepend||""},V=[K],z=Q.capture?"":"?:",G=w40.globChars(Q.windows),F=w40.extglobChars(G),{DOT_LITERAL:q,PLUS_LITERAL:W,SLASH_LITERAL:U,ONE_CHAR:D,DOTS_SLASH:H,NO_DOT:B,NO_DOT_SLASH:N,NO_DOTS_SLASH:w,QMARK:O,QMARK_NO_DOT:L,STAR:E,START_ANCHOR:M}=G,A=(W0)=>{return`(${z}(?:(?!${M}${W0.dot?H:q}).)*?)`},j=Q.dot?"":B,R=Q.dot?O:L,_=Q.bash===!0?A(Q):E;if(Q.capture)_=`(${_})`;if(typeof Q.noext==="boolean")Q.noextglob=Q.noext;let k={input:J,index:-1,start:0,dot:Q.dot===!0,consumed:"",output:"",prefix:"",backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:V};J=uG.removePrefix(J,k),X=J.length;let u=[],m=[],x=[],T=K,f,p=()=>k.index===X-1,d=k.peek=(W0=1)=>J[k.index+W0],h=k.advance=()=>J[++k.index]||"",n=()=>J.slice(k.index+1),c=(W0="",i=0)=>{k.consumed+=W0,k.index+=i},s=(W0)=>{k.output+=W0.output!=null?W0.output:W0.value,c(W0.value)},F0=()=>{let W0=1;while(d()==="!"&&(d(2)!=="("||d(3)==="?"))h(),k.start++,W0++;if(W0%2===0)return!1;return k.negated=!0,k.start++,!0},a=(W0)=>{k[W0]++,x.push(W0)},U0=(W0)=>{k[W0]--,x.pop()},O0=(W0)=>{if(T.type==="globstar"){let i=k.braces>0&&(W0.type==="comma"||W0.type==="brace"),o=W0.extglob===!0||u.length&&(W0.type==="pipe"||W0.type==="paren");if(W0.type!=="slash"&&W0.type!=="paren"&&!i&&!o)k.output=k.output.slice(0,-T.output.length),T.type="star",T.value="*",T.output=_,k.output+=T.output}if(u.length&&W0.type!=="paren")u[u.length-1].inner+=W0.value;if(W0.value||W0.output)s(W0);if(T&&T.type==="text"&&W0.type==="text"){T.output=(T.output||T.value)+W0.value,T.value+=W0.value;return}W0.prev=T,V.push(W0),T=W0},G0=(W0,i)=>{let o={...F[i],conditions:1,inner:""};o.prev=T,o.parens=k.parens,o.output=k.output;let t=(Q.capture?"(":"")+o.open;a("parens"),O0({type:W0,value:i,output:k.output?"":D}),O0({type:"paren",extglob:!0,value:h(),output:t}),u.push(o)},e=(W0)=>{let i=W0.close+(Q.capture?")":""),o;if(W0.type==="negate"){let t=_;if(W0.inner&&W0.inner.length>1&&W0.inner.includes("/"))t=A(Q);if(t!==_||p()||/^\)+$/.test(n()))i=W0.close=`)$))${t}`;if(W0.inner.includes("*")&&(o=n())&&/^\.[^\\/.]+$/.test(o)){let Z0=qI0(o,{...Z,fastpaths:!1}).output;i=W0.close=`)${Z0})${t})`}if(W0.prev.type==="bos")k.negatedExtglob=!0}O0({type:"paren",extglob:!0,value:f,output:i}),U0("parens")};if(Q.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(J)){let W0=!1,i=J.replace(cf6,(o,t,Z0,X0,Q0,J0)=>{if(X0==="\\")return W0=!0,o;if(X0==="?"){if(t)return t+X0+(Q0?O.repeat(Q0.length):"");if(J0===0)return R+(Q0?O.repeat(Q0.length):"");return O.repeat(Z0.length)}if(X0===".")return q.repeat(Z0.length);if(X0==="*"){if(t)return t+X0+(Q0?_:"");return _}return t?o:`\\${o}`});if(W0===!0)if(Q.unescape===!0)i=i.replace(/\\/g,"");else i=i.replace(/\\+/g,(o)=>{return o.length%2===0?"\\\\":o?"\\":""});if(i===J&&Q.contains===!0)return k.output=J,k;return k.output=uG.wrapOutput(i,k,Z),k}while(!p()){if(f=h(),f==="\x00")continue;if(f==="\\"){let o=d();if(o==="/"&&Q.bash!==!0)continue;if(o==="."||o===";")continue;if(!o){f+="\\",O0({type:"text",value:f});continue}let t=/^\\+/.exec(n()),Z0=0;if(t&&t[0].length>2){if(Z0=t[0].length,k.index+=Z0,Z0%2!==0)f+="\\"}if(Q.unescape===!0)f=h();else f+=h();if(k.brackets===0){O0({type:"text",value:f});continue}}if(k.brackets>0&&(f!=="]"||T.value==="["||T.value==="[^")){if(Q.posix!==!1&&f===":"){let o=T.value.slice(1);if(o.includes("[")){if(T.posix=!0,o.includes(":")){let t=T.value.lastIndexOf("["),Z0=T.value.slice(0,t),X0=T.value.slice(t+2),Q0=pf6[X0];if(Q0){if(T.value=Z0+Q0,k.backtrack=!0,h(),!K.output&&V.indexOf(T)===1)K.output=D;continue}}}}if(f==="["&&d()!==":"||f==="-"&&d()==="]")f=`\\${f}`;if(f==="]"&&(T.value==="["||T.value==="[^"))f=`\\${f}`;if(Q.posix===!0&&f==="!"&&T.value==="[")f="^";T.value+=f,s({value:f});continue}if(k.quotes===1&&f!=='"'){f=uG.escapeRegex(f),T.value+=f,s({value:f});continue}if(f==='"'){if(k.quotes=k.quotes===1?0:1,Q.keepQuotes===!0)O0({type:"text",value:f});continue}if(f==="("){a("parens"),O0({type:"paren",value:f});continue}if(f===")"){if(k.parens===0&&Q.strictBrackets===!0)throw SyntaxError(wC("opening","("));let o=u[u.length-1];if(o&&k.parens===o.parens+1){e(u.pop());continue}O0({type:"paren",value:f,output:k.parens?")":"\\)"}),U0("parens");continue}if(f==="["){if(Q.nobracket===!0||!n().includes("]")){if(Q.nobracket!==!0&&Q.strictBrackets===!0)throw SyntaxError(wC("closing","]"));f=`\\${f}`}else a("brackets");O0({type:"bracket",value:f});continue}if(f==="]"){if(Q.nobracket===!0||T&&T.type==="bracket"&&T.value.length===1){O0({type:"text",value:f,output:`\\${f}`});continue}if(k.brackets===0){if(Q.strictBrackets===!0)throw SyntaxError(wC("opening","["));O0({type:"text",value:f,output:`\\${f}`});continue}U0("brackets");let o=T.value.slice(1);if(T.posix!==!0&&o[0]==="^"&&!o.includes("/"))f=`/${f}`;if(T.value+=f,s({value:f}),Q.literalBrackets===!1||uG.hasRegexChars(o))continue;let t=uG.escapeRegex(T.value);if(k.output=k.output.slice(0,-T.value.length),Q.literalBrackets===!0){k.output+=t,T.value=t;continue}T.value=`(${z}${t}|${T.value})`,k.output+=T.value;continue}if(f==="{"&&Q.nobrace!==!0){a("braces");let o={type:"brace",value:f,output:"(",outputIndex:k.output.length,tokensIndex:k.tokens.length};m.push(o),O0(o);continue}if(f==="}"){let o=m[m.length-1];if(Q.nobrace===!0||!o){O0({type:"text",value:f,output:f});continue}let t=")";if(o.dots===!0){let Z0=V.slice(),X0=[];for(let Q0=Z0.length-1;Q0>=0;Q0--){if(V.pop(),Z0[Q0].type==="brace")break;if(Z0[Q0].type!=="dots")X0.unshift(Z0[Q0].value)}t=lf6(X0,Q),k.backtrack=!0}if(o.comma!==!0&&o.dots!==!0){let Z0=k.output.slice(0,o.outputIndex),X0=k.tokens.slice(o.tokensIndex);o.value=o.output="\\{",f=t="\\}",k.output=Z0;for(let Q0 of X0)k.output+=Q0.output||Q0.value}O0({type:"brace",value:f,output:t}),U0("braces"),m.pop();continue}if(f==="|"){if(u.length>0)u[u.length-1].conditions++;O0({type:"text",value:f});continue}if(f===","){let o=f,t=m[m.length-1];if(t&&x[x.length-1]==="braces")t.comma=!0,o="|";O0({type:"comma",value:f,output:o});continue}if(f==="/"){if(T.type==="dot"&&k.index===k.start+1){k.start=k.index+1,k.consumed="",k.output="",V.pop(),T=K;continue}O0({type:"slash",value:f,output:U});continue}if(f==="."){if(k.braces>0&&T.type==="dot"){if(T.value===".")T.output=q;let o=m[m.length-1];T.type="dots",T.output+=f,T.value+=f,o.dots=!0;continue}if(k.braces+k.parens===0&&T.type!=="bos"&&T.type!=="slash"){O0({type:"text",value:f,output:q});continue}O0({type:"dot",value:f,output:q});continue}if(f==="?"){if(!(T&&T.value==="(")&&Q.noextglob!==!0&&d()==="("&&d(2)!=="?"){G0("qmark",f);continue}if(T&&T.type==="paren"){let t=d(),Z0=f;if(T.value==="("&&!/[!=<:]/.test(t)||t==="<"&&!/<([!=]|\w+>)/.test(n()))Z0=`\\${f}`;O0({type:"text",value:f,output:Z0});continue}if(Q.dot!==!0&&(T.type==="slash"||T.type==="bos")){O0({type:"qmark",value:f,output:L});continue}O0({type:"qmark",value:f,output:O});continue}if(f==="!"){if(Q.noextglob!==!0&&d()==="("){if(d(2)!=="?"||!/[!=<:]/.test(d(3))){G0("negate",f);continue}}if(Q.nonegate!==!0&&k.index===0){F0();continue}}if(f==="+"){if(Q.noextglob!==!0&&d()==="("&&d(2)!=="?"){G0("plus",f);continue}if(T&&T.value==="("||Q.regex===!1){O0({type:"plus",value:f,output:W});continue}if(T&&(T.type==="bracket"||T.type==="paren"||T.type==="brace")||k.parens>0){O0({type:"plus",value:f});continue}O0({type:"plus",value:W});continue}if(f==="@"){if(Q.noextglob!==!0&&d()==="("&&d(2)!=="?"){O0({type:"at",extglob:!0,value:f,output:""});continue}O0({type:"text",value:f});continue}if(f!=="*"){if(f==="$"||f==="^")f=`\\${f}`;let o=df6.exec(n());if(o)f+=o[0],k.index+=o[0].length;O0({type:"text",value:f});continue}if(T&&(T.type==="globstar"||T.star===!0)){T.type="star",T.star=!0,T.value+=f,T.output=_,k.backtrack=!0,k.globstar=!0,c(f);continue}let W0=n();if(Q.noextglob!==!0&&/^\([^?]/.test(W0)){G0("star",f);continue}if(T.type==="star"){if(Q.noglobstar===!0){c(f);continue}let o=T.prev,t=o.prev,Z0=o.type==="slash"||o.type==="bos",X0=t&&(t.type==="star"||t.type==="globstar");if(Q.bash===!0&&(!Z0||W0[0]&&W0[0]!=="/")){O0({type:"star",value:f,output:""});continue}let Q0=k.braces>0&&(o.type==="comma"||o.type==="brace"),J0=u.length&&(o.type==="pipe"||o.type==="paren");if(!Z0&&o.type!=="paren"&&!Q0&&!J0){O0({type:"star",value:f,output:""});continue}while(W0.slice(0,3)==="/**"){let V0=J[k.index+4];if(V0&&V0!=="/")break;W0=W0.slice(3),c("/**",3)}if(o.type==="bos"&&p()){T.type="globstar",T.value+=f,T.output=A(Q),k.output=T.output,k.globstar=!0,c(f);continue}if(o.type==="slash"&&o.prev.type!=="bos"&&!X0&&p()){k.output=k.output.slice(0,-(o.output+T.output).length),o.output=`(?:${o.output}`,T.type="globstar",T.output=A(Q)+(Q.strictSlashes?")":"|$)"),T.value+=f,k.globstar=!0,k.output+=o.output+T.output,c(f);continue}if(o.type==="slash"&&o.prev.type!=="bos"&&W0[0]==="/"){let V0=W0[1]!==void 0?"|$":"";k.output=k.output.slice(0,-(o.output+T.output).length),o.output=`(?:${o.output}`,T.type="globstar",T.output=`${A(Q)}${U}|${U}${V0})`,T.value+=f,k.output+=o.output+T.output,k.globstar=!0,c(f+h()),O0({type:"slash",value:"/",output:""});continue}if(o.type==="bos"&&W0[0]==="/"){T.type="globstar",T.value+=f,T.output=`(?:^|${U}|${A(Q)}${U})`,k.output=T.output,k.globstar=!0,c(f+h()),O0({type:"slash",value:"/",output:""});continue}k.output=k.output.slice(0,-T.output.length),T.type="globstar",T.output=A(Q),T.value+=f,k.output+=T.output,k.globstar=!0,c(f);continue}let i={type:"star",value:f,output:_};if(Q.bash===!0){if(i.output=".*?",T.type==="bos"||T.type==="slash")i.output=j+i.output;O0(i);continue}if(T&&(T.type==="bracket"||T.type==="paren")&&Q.regex===!0){i.output=f,O0(i);continue}if(k.index===k.start||T.type==="slash"||T.type==="dot"){if(T.type==="dot")k.output+=N,T.output+=N;else if(Q.dot===!0)k.output+=w,T.output+=w;else k.output+=j,T.output+=j;if(d()!=="*")k.output+=D,T.output+=D}O0(i)}while(k.brackets>0){if(Q.strictBrackets===!0)throw SyntaxError(wC("closing","]"));k.output=uG.escapeLast(k.output,"["),U0("brackets")}while(k.parens>0){if(Q.strictBrackets===!0)throw SyntaxError(wC("closing",")"));k.output=uG.escapeLast(k.output,"("),U0("parens")}while(k.braces>0){if(Q.strictBrackets===!0)throw SyntaxError(wC("closing","}"));k.output=uG.escapeLast(k.output,"{"),U0("braces")}if(Q.strictSlashes!==!0&&(T.type==="star"||T.type==="bracket"))O0({type:"maybe_slash",value:"",output:`${U}?`});if(k.backtrack===!0){k.output="";for(let W0 of k.tokens)if(k.output+=W0.output!=null?W0.output:W0.value,W0.suffix)k.output+=W0.suffix}return k};qI0.fastpaths=(J,Z)=>{let Q={...Z},Y=typeof Q.maxLength==="number"?Math.min(O40,Q.maxLength):O40,X=J.length;if(X>Y)throw SyntaxError(`Input length: ${X}, exceeds maximum allowed length: ${Y}`);J=Bh1[J]||J;let{DOT_LITERAL:K,SLASH_LITERAL:V,ONE_CHAR:z,DOTS_SLASH:G,NO_DOT:F,NO_DOTS:q,NO_DOTS_SLASH:W,STAR:U,START_ANCHOR:D}=w40.globChars(Q.windows),H=Q.dot?q:F,B=Q.dot?W:F,N=Q.capture?"":"?:",w={negated:!1,prefix:""},O=Q.bash===!0?".*?":U;if(Q.capture)O=`(${O})`;let L=(j)=>{if(j.noglobstar===!0)return O;return`(${N}(?:(?!${D}${j.dot?G:K}).)*?)`},E=(j)=>{switch(j){case"*":return`${H}${z}${O}`;case".*":return`${K}${z}${O}`;case"*.*":return`${H}${O}${K}${z}${O}`;case"*/*":return`${H}${O}${V}${z}${B}${O}`;case"**":return H+L(Q);case"**/*":return`(?:${H}${L(Q)}${V})?${B}${z}${O}`;case"**/*.*":return`(?:${H}${L(Q)}${V})?${B}${O}${K}${z}${O}`;case"**/.*":return`(?:${H}${L(Q)}${V})?${K}${z}${O}`;default:{let R=/^(.*?)\.(\w+)$/.exec(j);if(!R)return;let _=E(R[1]);if(!_)return;return _+K+R[2]}}},M=uG.removePrefix(J,w),A=E(M);if(A&&Q.strictSlashes!==!0)A+=`${V}?`;return A};Nh1.exports=qI0});var UI0=b((y68,Lh1)=>{var if6=Hh1(),WI0=wh1(),Oh1=gb(),nf6=hb(),af6=(J)=>J&&typeof J==="object"&&!Array.isArray(J),G2=(J,Z,Q=!1)=>{if(Array.isArray(J)){let q=J.map((U)=>G2(U,Z,Q));return(U)=>{for(let D of q){let H=D(U);if(H)return H}return!1}}let Y=af6(J)&&J.tokens&&J.input;if(J===""||typeof J!=="string"&&!Y)throw TypeError("Expected pattern to be a non-empty string");let X=Z||{},K=X.windows,V=Y?G2.compileRe(J,Z):G2.makeRe(J,Z,!1,!0),z=V.state;delete V.state;let G=()=>!1;if(X.ignore){let q={...Z,ignore:null,onMatch:null,onResult:null};G=G2(X.ignore,q,Q)}let F=(q,W=!1)=>{let{isMatch:U,match:D,output:H}=G2.test(q,V,Z,{glob:J,posix:K}),B={glob:J,state:z,regex:V,posix:K,input:q,output:H,match:D,isMatch:U};if(typeof X.onResult==="function")X.onResult(B);if(U===!1)return B.isMatch=!1,W?B:!1;if(G(q)){if(typeof X.onIgnore==="function")X.onIgnore(B);return B.isMatch=!1,W?B:!1}if(typeof X.onMatch==="function")X.onMatch(B);return W?B:!0};if(Q)F.state=z;return F};G2.test=(J,Z,Q,{glob:Y,posix:X}={})=>{if(typeof J!=="string")throw TypeError("Expected input to be a string");if(J==="")return{isMatch:!1,output:""};let K=Q||{},V=K.format||(X?Oh1.toPosixSlashes:null),z=J===Y,G=z&&V?V(J):J;if(z===!1)G=V?V(J):J,z=G===Y;if(z===!1||K.capture===!0)if(K.matchBase===!0||K.basename===!0)z=G2.matchBase(J,Z,Q,X);else z=Z.exec(G);return{isMatch:Boolean(z),match:z,output:G}};G2.matchBase=(J,Z,Q)=>{return(Z instanceof RegExp?Z:G2.makeRe(Z,Q)).test(Oh1.basename(J))};G2.isMatch=(J,Z,Q)=>G2(Z,Q)(J);G2.parse=(J,Z)=>{if(Array.isArray(J))return J.map((Q)=>G2.parse(Q,Z));return WI0(J,{...Z,fastpaths:!1})};G2.scan=(J,Z)=>if6(J,Z);G2.compileRe=(J,Z,Q=!1,Y=!1)=>{if(Q===!0)return J.output;let X=Z||{},K=X.contains?"":"^",V=X.contains?"":"$",z=`${K}(?:${J.output})${V}`;if(J&&J.negated===!0)z=`^(?!${z}).*$`;let G=G2.toRegex(z,Z);if(Y===!0)G.state=J;return G};G2.makeRe=(J,Z={},Q=!1,Y=!1)=>{if(!J||typeof J!=="string")throw TypeError("Expected a non-empty string");let X={negated:!1,fastpaths:!0};if(Z.fastpaths!==!1&&(J[0]==="."||J[0]==="*"))X.output=WI0.fastpaths(J,Z);if(!X.output)X=WI0(J,Z);return G2.compileRe(X,Z,Q,Y)};G2.toRegex=(J,Z)=>{try{let Q=Z||{};return new RegExp(J,Q.flags||(Q.nocase?"i":""))}catch(Q){if(Z&&Z.debug===!0)throw Q;return/$^/}};G2.constants=nf6;Lh1.exports=G2});var yW=b((v68,Ah1)=>{var Eh1=UI0(),of6=gb();function Mh1(J,Z,Q=!1){if(Z&&(Z.windows===null||Z.windows===void 0))Z={...Z,windows:of6.isWindows()};return Eh1(J,Z,Q)}Object.assign(Mh1,Eh1);Ah1.exports=Mh1});function BI0(J){let Z=J;if(Z.startsWith("~/")){let Q=process.env.HOME||process.env.USERPROFILE||"";Z=Z.replace("~/",`${Q}/`)}else if(Z==="~")Z=process.env.HOME||process.env.USERPROFILE||"";if(Z=Z.replace(/%([^%]+)%/g,(Q,Y)=>{return process.env[Y]||`%${Y}%`}),Z.includes("%USERPROFILE%")&&process.env.USERPROFILE)Z=Z.replace(/%USERPROFILE%/g,process.env.USERPROFILE);return X1.file(Z)}function DI0(J,Z){let Q=BI0(Z);if(Q.path.includes("*")){let Y=J.toString(),X=Q.path;if(!X.startsWith("file://")){if(!X.startsWith("/"))X=`/${X}`;X=`file://${X}`}let K=X.replace(/\./g,"\\.").replace(/\*\*/g,"§DOUBLESTAR§").replace(/\*/g,"[^/]*").replace(/§DOUBLESTAR§/g,".*");return new RegExp(`^${K}$`,"i").test(Y)}else return Q.toString().toLowerCase()===J.toString().toLowerCase()}function jh1(J,Z){return Z.some((Q)=>DI0(J,Q))}async function rf6(J,Z){try{return await Z.realpath(J)}catch{}let Q=[],Y=J;while(!0){let X=K1.dirname(Y);if(X.toString()===Y.toString())break;Q.unshift(K1.basename(Y)),Y=X;try{let V=await Z.realpath(Y);for(let z of Q)V=K1.joinPath(V,z);return V}catch{}}return J}async function sf6(J,Z,Q){try{let Y=await rf6(J,Z),K=[...["~/.config/AGENT.md"],...Q];for(let V of K)if(DI0(Y,V)||DI0(J,V))return null;for(let{key:V,pattern:z}of HI0)if(jh1(Y,z.patterns)||jh1(J,z.patterns))return{key:V,pattern:z};return null}catch{return null}}async function NI0(J,Z,Q){if(Q?.dangerouslyAllowAll??!1)return{requiresConsent:!1};try{let X=await sf6(J,Z,Q["guardedFiles.allowlist"]??[]);if(X)return{requiresConsent:!0,reason:`${X.pattern.description}`,toAllow:J.fsPath};return{requiresConsent:!1}}catch{return{requiresConsent:!0,reason:"Unable to resolve file path",toAllow:J.fsPath}}}var HI0;var L40=Y0(()=>{U4();HI0=[{key:"cursor-config",pattern:{description:"Cursor Configuration",patterns:["**/.cursor/**","~/.cursor/**","~/Library/Application Support/Cursor/**","~/.config/Cursor/**","%APPDATA%/Cursor/**"]}},{key:"windsurf-config",pattern:{description:"Windsurf Configuration",patterns:["**/.windsurf/**","~/.codeium/windsurf/**","~/Library/Application Support/Windsurf/**","~/.config/Windsurf/**","%APPDATA%/Windsurf/**","/Library/Application Support/Windsurf/**","/etc/windsurf/**","%ProgramData%/Windsurf/**"]}},{key:"antigravity-config",pattern:{description:"Antigravity Configuration",patterns:["~/.gemini/**"]}},{key:"jetbrains-config",pattern:{description:"JetBrains IDE Configuration",patterns:["~/Library/Application Support/JetBrains/**","~/.config/JetBrains/**","~/.local/share/JetBrains/**","%APPDATA%/JetBrains/**","%LOCALAPPDATA%/JetBrains/**"]}},{key:"jetbrains-idea-config",pattern:{description:"JetBrains IDE Project Configuration",patterns:["**/.idea/**"]}},{key:"neovim-config",pattern:{description:"Neovim Configuration",patterns:["~/.config/nvim/**","~/.local/share/nvim/**","~/.local/state/nvim/**"]}},{key:"amp-settings",pattern:{description:"Amp Configuration Files",patterns:["**/amp.json","**/.amp/**"]}},{key:"shell-configs",pattern:{description:"Shell Configuration Files",patterns:["~/.bashrc","~/.zshrc","~/.fishrc","~/.cshrc","~/.tcshrc"]}},{key:"ssh-keys",pattern:{description:"SSH Keys and Configuration",patterns:["**/.ssh/**","~/.ssh/**"]}},{key:"gnupg-keys",pattern:{description:"GnuPG Keys and Configuration",patterns:["**/.gnupg/**","~/.gnupg/**"]}},{key:"environment-files",pattern:{description:"Environment Variable Files",patterns:["**/.env","**/.env.*"]}},{key:"claude-config",pattern:{description:"Claude AI Configuration",patterns:["**/.claude/**","~/.claude/**"]}},{key:"codex-config",pattern:{description:"Codex Configuration",patterns:["**/.codex/**","~/.codex/**"]}},{key:"git-internals",pattern:{description:"Git Internal Files",patterns:["**/.git/**"]}},{key:"kubernetes-config",pattern:{description:"Kubernetes Configuration",patterns:["**/.kube/**","~/.kube/**"]}},{key:"cache-directories",pattern:{description:"Cache Directories",patterns:["**/.cache/**","~/.cache/**"]}},{key:"windows-appdata",pattern:{description:"Windows Application Data",patterns:["%APPDATA%/**"]}},{key:"windows-system-directories",pattern:{description:"Windows System Directories",patterns:["%WINDIR%/**","%SYSTEMROOT%/**","%ProgramFiles%/**","%ProgramFiles(x86)%/**","%ProgramData%/**"]}},{key:"sqlite3-files",pattern:{description:"SQLite Database Files",patterns:["**/*.db","**/*.sqlite","**/*.sqlite3"]}},{key:"common-configuration-patterns",pattern:{description:"Configuration Directories",patterns:["~/.*","~/.*/**","~/.config/**","~/Library/**","~/Library/Preferences/**"]}},{key:"macos-applications",pattern:{description:"macOS Applications",patterns:["/Applications/**","~/Applications/**"]}},{key:"macos-system-library",pattern:{description:"macOS System Library",patterns:["/Library/**"]}},{key:"unix-system-directories",pattern:{description:"Unix System Directories",patterns:["/usr/**","/bin/**","/sbin/**","/lib/**","/lib64/**","/boot/**"]}},{key:"system-config-directories",pattern:{description:"System Configuration and State",patterns:["/private/etc/**","/etc/**","/private/var/**","/var/**"]}},{key:"opt-directory",pattern:{description:"Optional Software Installs (/opt, e.g., Homebrew)",patterns:["/opt/**"]}}]});function tf6(){if(vW.size===0)return;I.info("Killing all child processes");for(let J of vW)wI0(J);vW.clear(),I.info("All child processes killed")}function wI0(J){if(!J.pid){try{J.kill("SIGKILL")}catch(Z){I.error("Failed to kill process without PID",Z)}return}if(pb.has(J.pid)){I.debug(`Process ${J.pid} already being killed, skipping`);return}pb.add(J.pid);try{if(process.platform==="win32"){let{spawn:Z}=R0("node:child_process"),Q=Z("taskkill",["/F","/T","/PID",J.pid.toString()],{stdio:"ignore"});Q.on("error",(Y)=>{I.error(`Failed to kill Windows process tree ${J.pid}`,Y);try{J.kill("SIGKILL")}catch(X){I.error(`Fallback kill also failed for ${J.pid}`,X)}}),Q.on("exit",()=>{pb.delete(J.pid)})}else{try{process.kill(J.pid,0),process.kill(-J.pid,"SIGKILL")}catch(Z){I.debug(`Process ${J.pid} no longer exists, skipping kill`)}pb.delete(J.pid)}}catch(Z){I.error(`Failed to kill process ${J.pid}`,Z),pb.delete(J.pid)}}function OI0(J){wI0(J),vW.delete(J)}function Rh1(J){vW.add(J)}function ef6(J){let Z={...J,detached:process.platform!=="win32",env:{...process.env,...J?.env||{},NONINTERACTIVE:"1",DEBIAN_FRONTEND:"noninteractive"}};if(!Z.stdio)Z.stdio=["pipe","pipe","pipe"];return Z}function LI0(...J){return new k0((Z)=>{let Q=!1,Y,X=!1;return(async()=>{try{let{spawn:V}=await import("node:child_process");if(Q)return;Y=V(J[0],J[1],ef6(J[2])),vW.add(Y),Y.on("spawn",()=>{Z.next({type:"spawn",pid:Y?.pid,process:Y})}),Y.stdout?.on("data",(z)=>{if(Q||X)return;Z.next({type:"data",stream:"stdout",chunk:Buffer.isBuffer(z)?z:Buffer.from(String(z)),pid:Y?.pid,process:Y})}),Y.stderr?.on("data",(z)=>{if(Q||X)return;Z.next({type:"data",stream:"stderr",chunk:Buffer.isBuffer(z)?z:Buffer.from(String(z)),pid:Y?.pid,process:Y})}),Y.on("exit",(z)=>{if(Q||X)return;Z.next({type:"exit",exitCode:z})}),Y.on("close",(z)=>{if(Q)return;if(X)return;if(X=!0,Z.next({type:"close",exitCode:z}),Z.complete(),Y)vW.delete(Y)}),Y.on("error",(z)=>{if(Q||X)return;if(X=!0,Z.error(z),Y)vW.delete(Y)})}catch(V){if(Q)return;Z.error(V)}})(),()=>{if(Q=!0,Y&&!X)wI0(Y),vW.delete(Y)}})}function xW(...J){return new k0((Z)=>{let Q={stdout:"",stderr:"",combinedOutput:"",exitCode:null,exited:!1},Y=LI0(...J).subscribe({next:(X)=>{switch(X.type){case"spawn":Q.pid=X.pid,Q.process=X.process,Z.next({...Q,process:X.process});break;case"data":{let K=X.chunk.toString();if(X.stream==="stdout")Q.stdout+=K;else Q.stderr+=K;Q.combinedOutput+=K,Q.lastData=X.chunk,Z.next({...Q,process:X.process??Q.process});break}case"exit":Q.exitCode=X.exitCode??-1,Q.exited=!0;break;case"close":if(Q.exitCode===null)Q.exitCode=X.exitCode??-1;Q.exited=!0,Q.lastData=void 0,Z.next({...Q,process:Q.process}),Z.complete();break}},error:(X)=>Z.error(X)});return()=>Y.unsubscribe()})}function E40(J){if(typeof J!=="string")throw Error("arg is not a string");if(J.startsWith("-"))throw Error("arg is not safe")}function aH(J){if(!J)throw Error("tool requires a working directory");if(J.scheme!=="file")throw Error(`tool requires a dir with a file: URI (got ${JSON.stringify(J.scheme)})`)}var vW,pb;var RV=Y0(()=>{N1();g0();vW=new Set,pb=new Set;if(typeof process<"u")process.on("exit",()=>{tf6()})});function EE(J,Z){if(Z==="")return!1;let Q=J.toLowerCase(),Y=Z.toLowerCase();if(Y.length===1){if(Y==="*")return!0;return Y===Q}if(Q===Y)return!0;if(Y.includes("*")||Y.includes("?")||Y.includes("[")||Y.includes("{"))try{return Ih1.default(Y,{dot:!0})(Q)}catch(X){return!1}return!1}function EI0(J,Z){let Q=Z.split("."),Y=J;for(let X of Q){if(Y===null||Y===void 0)return;if(Array.isArray(Y)){let K=parseInt(X,10);if(isNaN(K)||K<0||K>=Y.length)return;Y=Y[K]}else if(typeof Y==="object")Y=Y[X];else return}return Y}function $u6(J,Z,Q,Y){if(!EE(Z,J.tool))return!1;if(J.context&&J.context!==Y)return!1;if(!J.matches||Object.keys(J.matches).length===0)return!0;return Object.entries(J.matches).every(([X,K])=>{if(K===void 0){if(X.includes("."))return EI0(Q,X)===void 0;return X in Q&&Q[X]===void 0}let V=X.includes(".")?EI0(Q,X):Q[X];return M40(V,K)})}async function Ju6(J,Z,Q,Y,X,K){if(J.action!=="delegate"){if(J.action==="reject"&&J.message)return{action:J.action,matchedEntry:J,error:J.message};return{action:J.action,matchedEntry:J}}if(!Q||!J.to)return{action:null,matchedEntry:J,error:"No spawn function provided"};try{let V=await Zu6(J.to,Z,Q,Y,X,K);return Qu6(V,J)}catch(V){return{action:"reject",error:V instanceof Error?V.message:"Unknown error",matchedEntry:J}}}async function Zu6(J,Z,Q,Y,X,K){let V={AGENT:"amp"};if(Y)V.AMP_THREAD_ID=Y;if(X)V.AGENT_TOOL_NAME=X;if(K)V.AGENT_TOOL_USE_ID=K;let G=J.includes("~")||J.includes("%")?BI0(J).path:J,q=Q(G,[],{env:V});return new Promise((W,U)=>{let D;q.subscribe({next:(H)=>{if(typeof H==="object"&&H!==null&&"status"in H&&H.status==="error"){U(Error("Delegate command timed out after 10 seconds"));return}if(H.process&&!H.exited)H.process.stdin?.write(JSON.stringify(Z)),H.process.stdin?.end();D=H},complete:()=>{if(D?.exited)W({exitCode:D.exitCode??-1,stdout:D.stdout,stderr:D.stderr});else U(Error("Process did not exit properly"))},error:(H)=>{U(H)}})})}function Qu6({exitCode:J,stderr:Z},Q){switch(J){case 0:return{action:"allow",matchedEntry:Q};case 1:return{action:"ask",matchedEntry:Q};default:return{action:"reject",matchedEntry:Q,error:Z}}}async function OC(J,Z,Q,Y,X,K,V,z){let G=0;for(let F of Q)try{if(!$u6(F,J,Z,Y)){G=G+1;continue}let q=await Ju6(F,Z,X,K,J,z);if(q.matchIndex=G,V)q.source=V;return q}catch(q){return{action:null,error:q instanceof Error?q.message:"Unknown error"}}return{action:null}}function M40(J,Z){if(typeof Z==="string"){if(typeof J!=="string")return!1;return Xu6(J,Z)}if(Array.isArray(Z))return Z.some((Q)=>{if(typeof Q==="string")return typeof J==="string"&&MI0(J,Q);return J===Q});if(typeof Z==="object"&&Z!==null)return Yu6(J,Z);return J===Z}function Yu6(J,Z){if(Object.keys(Z).length===0)return typeof J==="object"&&J!==null;if(typeof J!=="object"||J===null)return!1;for(let[Q,Y]of Object.entries(Z)){let X=EI0(J,Q);if(!M40(X,Y))return!1}return!0}function Xu6(J,Z){if(typeof Z==="string")return MI0(J,Z);if(Array.isArray(Z))return Z.some((Q)=>typeof Q==="string"&&MI0(J,Q));return!1}function MI0(J,Z){if(Z.length>=3&&Z.startsWith("/")&&Z.endsWith("/"))try{let X=Z.slice(1,-1);return new RegExp(X,"m").test(J)}catch(X){throw Error(`Invalid regex pattern: ${Z}`)}if(Z==="*")return!0;if(!Z.includes("*"))return J===Z;let Q=Z.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${Q}$`,"m").test(J)}var Ih1,db;var LC=Y0(()=>{L40();RV();Ih1=z4(yW(),1),db=xW});function cb(J,Z){if(J===Z)return!0;if(J==null||Z==null||typeof J!=="object"||typeof Z!=="object")return!1;let Q=Array.isArray(J),Y=Array.isArray(Z);if(Q!==Y)return!1;if(Q&&Y)return J.length===Z.length&&J.every((K,V)=>cb(K,Z[V]));let X=new Set([...Object.keys(J),...Object.keys(Z)]);for(let K of X)if(!cb(J[K],Z[K]))return!1;return!0}function IC(J){let Z=J.length;while(--Z>=0)J[Z]=0}function jI0(J,Z,Q,Y,X){this.static_tree=J,this.extra_bits=Z,this.extra_base=Q,this.elems=Y,this.max_length=X,this.has_stree=J&&J.length}function RI0(J,Z){this.dyn_tree=J,this.max_code=0,this.stat_desc=Z}function bG(J,Z,Q,Y,X){this.good_length=J,this.max_lazy=Z,this.nice_length=Q,this.max_chain=Y,this.func=X}function Vb6(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=k40,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(tu6*2),this.dyn_dtree=new Uint16Array((2*ru6+1)*2),this.bl_tree=new Uint16Array((2*su6+1)*2),oH(this.dyn_ltree),oH(this.dyn_dtree),oH(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(eu6+1),this.heap=new Uint16Array(2*gI0+1),oH(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*gI0+1),oH(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Tb6(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function Vh(J){this.options=y40.assign({level:xb6,method:ub6,chunkSize:16384,windowBits:15,memLevel:8,strategy:fb6},J||{});let Z=this.options;if(Z.raw&&Z.windowBits>0)Z.windowBits=-Z.windowBits;else if(Z.gzip&&Z.windowBits>0&&Z.windowBits<16)Z.windowBits+=16;this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new kg1,this.strm.avail_out=0;let Q=ob.deflateInit2(this.strm,Z.level,Z.method,Z.windowBits,Z.memLevel,Z.strategy);if(Q!==_40)throw Error(RE[Q]);if(Z.header)ob.deflateSetHeader(this.strm,Z.header);if(Z.dictionary){let Y;if(typeof Z.dictionary==="string")Y=Qh.string2buf(Z.dictionary);else if(yg1.call(Z.dictionary)==="[object ArrayBuffer]")Y=new Uint8Array(Z.dictionary);else Y=Z.dictionary;if(Q=ob.deflateSetDictionary(this.strm,Y),Q!==_40)throw Error(RE[Q]);this._dict_set=!0}}function sI0(J,Z){let Q=new Vh(Z);if(Q.push(J,!0),Q.err)throw Q.msg||RE[Q.err];return Q.result}function bb6(J,Z){return Z=Z||{},Z.raw=!0,sI0(J,Z)}function hb6(J,Z){return Z=Z||{},Z.gzip=!0,sI0(J,Z)}function zh6(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Rh6(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}function zh(J){this.options=y40.assign({chunkSize:65536,windowBits:15,to:""},J||{});let Z=this.options;if(Z.raw&&Z.windowBits>=0&&Z.windowBits<16){if(Z.windowBits=-Z.windowBits,Z.windowBits===0)Z.windowBits=-15}if(Z.windowBits>=0&&Z.windowBits<16&&!(J&&J.windowBits))Z.windowBits+=32;if(Z.windowBits>15&&Z.windowBits<48){if((Z.windowBits&15)===0)Z.windowBits|=15}this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new kg1,this.strm.avail_out=0;let Q=bW.inflateInit2(this.strm,Z.windowBits);if(Q!==Yh)throw Error(RE[Q]);if(this.header=new Ih6,bW.inflateGetHeader(this.strm,this.header),Z.dictionary){if(typeof Z.dictionary==="string")Z.dictionary=Qh.string2buf(Z.dictionary);else if(lg1.call(Z.dictionary)==="[object ArrayBuffer]")Z.dictionary=new Uint8Array(Z.dictionary);if(Z.raw){if(Q=bW.inflateSetDictionary(this.strm,Z.dictionary),Q!==Yh)throw Error(RE[Q])}}}function tI0(J,Z){let Q=new zh(Z);if(Q.push(J),Q.err)throw Q.msg||RE[Q.err];return Q.result}function Sh6(J,Z){return Z=Z||{},Z.raw=!0,tI0(J,Z)}var Ku6=0,qg1=1,Vu6=2,zu6=3,Gu6=258,iI0=29,Xh=256,sb,AC=30,nI0=19,Wg1,ME=15,AI0=16,Fu6=7,aI0=256,Ug1=16,Dg1=17,Hg1=18,uI0,C40,qu6,Bg1,Wu6=512,uW,ab,tb,eb,oI0,T40,Ng1,wg1,Og1,Lg1=(J)=>{return J<256?tb[J]:tb[256+(J>>>7)]},$h=(J,Z)=>{J.pending_buf[J.pending++]=Z&255,J.pending_buf[J.pending++]=Z>>>8&255},tZ=(J,Z,Q)=>{if(J.bi_valid>AI0-Q)J.bi_buf|=Z<<J.bi_valid&65535,$h(J,J.bi_buf),J.bi_buf=Z>>AI0-J.bi_valid,J.bi_valid+=Q-AI0;else J.bi_buf|=Z<<J.bi_valid&65535,J.bi_valid+=Q},hG=(J,Z,Q)=>{tZ(J,Q[Z*2],Q[Z*2+1])},Eg1=(J,Z)=>{let Q=0;do Q|=J&1,J>>>=1,Q<<=1;while(--Z>0);return Q>>>1},Uu6=(J)=>{if(J.bi_valid===16)$h(J,J.bi_buf),J.bi_buf=0,J.bi_valid=0;else if(J.bi_valid>=8)J.pending_buf[J.pending++]=J.bi_buf&255,J.bi_buf>>=8,J.bi_valid-=8},Du6=(J,Z)=>{let{dyn_tree:Q,max_code:Y}=Z,X=Z.stat_desc.static_tree,K=Z.stat_desc.has_stree,V=Z.stat_desc.extra_bits,z=Z.stat_desc.extra_base,G=Z.stat_desc.max_length,F,q,W,U,D,H,B=0;for(U=0;U<=ME;U++)J.bl_count[U]=0;Q[J.heap[J.heap_max]*2+1]=0;for(F=J.heap_max+1;F<Wg1;F++){if(q=J.heap[F],U=Q[Q[q*2+1]*2+1]+1,U>G)U=G,B++;if(Q[q*2+1]=U,q>Y)continue;if(J.bl_count[U]++,D=0,q>=z)D=V[q-z];if(H=Q[q*2],J.opt_len+=H*(U+D),K)J.static_len+=H*(X[q*2+1]+D)}if(B===0)return;do{U=G-1;while(J.bl_count[U]===0)U--;J.bl_count[U]--,J.bl_count[U+1]+=2,J.bl_count[G]--,B-=2}while(B>0);for(U=G;U!==0;U--){q=J.bl_count[U];while(q!==0){if(W=J.heap[--F],W>Y)continue;if(Q[W*2+1]!==U)J.opt_len+=(U-Q[W*2+1])*Q[W*2],Q[W*2+1]=U;q--}}},Mg1=(J,Z,Q)=>{let Y=Array(ME+1),X=0,K,V;for(K=1;K<=ME;K++)X=X+Q[K-1]<<1,Y[K]=X;for(V=0;V<=Z;V++){let z=J[V*2+1];if(z===0)continue;J[V*2]=Eg1(Y[z]++,z)}},Hu6=()=>{let J,Z,Q,Y,X,K=Array(ME+1);Q=0;for(Y=0;Y<iI0-1;Y++){oI0[Y]=Q;for(J=0;J<1<<uI0[Y];J++)eb[Q++]=Y}eb[Q-1]=Y,X=0;for(Y=0;Y<16;Y++){T40[Y]=X;for(J=0;J<1<<C40[Y];J++)tb[X++]=Y}X>>=7;for(;Y<AC;Y++){T40[Y]=X<<7;for(J=0;J<1<<C40[Y]-7;J++)tb[256+X++]=Y}for(Z=0;Z<=ME;Z++)K[Z]=0;J=0;while(J<=143)uW[J*2+1]=8,J++,K[8]++;while(J<=255)uW[J*2+1]=9,J++,K[9]++;while(J<=279)uW[J*2+1]=7,J++,K[7]++;while(J<=287)uW[J*2+1]=8,J++,K[8]++;Mg1(uW,sb+1,K);for(J=0;J<AC;J++)ab[J*2+1]=5,ab[J*2]=Eg1(J,5);Ng1=new jI0(uW,uI0,Xh+1,sb,ME),wg1=new jI0(ab,C40,0,AC,ME),Og1=new jI0([],qu6,0,nI0,Fu6)},Ag1=(J)=>{let Z;for(Z=0;Z<sb;Z++)J.dyn_ltree[Z*2]=0;for(Z=0;Z<AC;Z++)J.dyn_dtree[Z*2]=0;for(Z=0;Z<nI0;Z++)J.bl_tree[Z*2]=0;J.dyn_ltree[aI0*2]=1,J.opt_len=J.static_len=0,J.sym_next=J.matches=0},jg1=(J)=>{if(J.bi_valid>8)$h(J,J.bi_buf);else if(J.bi_valid>0)J.pending_buf[J.pending++]=J.bi_buf;J.bi_buf=0,J.bi_valid=0},Ph1=(J,Z,Q,Y)=>{let X=Z*2,K=Q*2;return J[X]<J[K]||J[X]===J[K]&&Y[Z]<=Y[Q]},II0=(J,Z,Q)=>{let Y=J.heap[Q],X=Q<<1;while(X<=J.heap_len){if(X<J.heap_len&&Ph1(Z,J.heap[X+1],J.heap[X],J.depth))X++;if(Ph1(Z,Y,J.heap[X],J.depth))break;J.heap[Q]=J.heap[X],Q=X,X<<=1}J.heap[Q]=Y},Ch1=(J,Z,Q)=>{let Y,X,K=0,V,z;if(J.sym_next!==0)do if(Y=J.pending_buf[J.sym_buf+K++]&255,Y+=(J.pending_buf[J.sym_buf+K++]&255)<<8,X=J.pending_buf[J.sym_buf+K++],Y===0)hG(J,X,Z);else{if(V=eb[X],hG(J,V+Xh+1,Z),z=uI0[V],z!==0)X-=oI0[V],tZ(J,X,z);if(Y--,V=Lg1(Y),hG(J,V,Q),z=C40[V],z!==0)Y-=T40[V],tZ(J,Y,z)}while(K<J.sym_next);hG(J,aI0,Z)},bI0=(J,Z)=>{let Q=Z.dyn_tree,Y=Z.stat_desc.static_tree,X=Z.stat_desc.has_stree,K=Z.stat_desc.elems,V,z,G=-1,F;J.heap_len=0,J.heap_max=Wg1;for(V=0;V<K;V++)if(Q[V*2]!==0)J.heap[++J.heap_len]=G=V,J.depth[V]=0;else Q[V*2+1]=0;while(J.heap_len<2)if(F=J.heap[++J.heap_len]=G<2?++G:0,Q[F*2]=1,J.depth[F]=0,J.opt_len--,X)J.static_len-=Y[F*2+1];Z.max_code=G;for(V=J.heap_len>>1;V>=1;V--)II0(J,Q,V);F=K;do V=J.heap[1],J.heap[1]=J.heap[J.heap_len--],II0(J,Q,1),z=J.heap[1],J.heap[--J.heap_max]=V,J.heap[--J.heap_max]=z,Q[F*2]=Q[V*2]+Q[z*2],J.depth[F]=(J.depth[V]>=J.depth[z]?J.depth[V]:J.depth[z])+1,Q[V*2+1]=Q[z*2+1]=F,J.heap[1]=F++,II0(J,Q,1);while(J.heap_len>=2);J.heap[--J.heap_max]=J.heap[1],Du6(J,Z),Mg1(Q,G,J.bl_count)},Th1=(J,Z,Q)=>{let Y,X=-1,K,V=Z[1],z=0,G=7,F=4;if(V===0)G=138,F=3;Z[(Q+1)*2+1]=65535;for(Y=0;Y<=Q;Y++){if(K=V,V=Z[(Y+1)*2+1],++z<G&&K===V)continue;else if(z<F)J.bl_tree[K*2]+=z;else if(K!==0){if(K!==X)J.bl_tree[K*2]++;J.bl_tree[Ug1*2]++}else if(z<=10)J.bl_tree[Dg1*2]++;else J.bl_tree[Hg1*2]++;if(z=0,X=K,V===0)G=138,F=3;else if(K===V)G=6,F=3;else G=7,F=4}},_h1=(J,Z,Q)=>{let Y,X=-1,K,V=Z[1],z=0,G=7,F=4;if(V===0)G=138,F=3;for(Y=0;Y<=Q;Y++){if(K=V,V=Z[(Y+1)*2+1],++z<G&&K===V)continue;else if(z<F)do hG(J,K,J.bl_tree);while(--z!==0);else if(K!==0){if(K!==X)hG(J,K,J.bl_tree),z--;hG(J,Ug1,J.bl_tree),tZ(J,z-3,2)}else if(z<=10)hG(J,Dg1,J.bl_tree),tZ(J,z-3,3);else hG(J,Hg1,J.bl_tree),tZ(J,z-11,7);if(z=0,X=K,V===0)G=138,F=3;else if(K===V)G=6,F=3;else G=7,F=4}},Bu6=(J)=>{let Z;Th1(J,J.dyn_ltree,J.l_desc.max_code),Th1(J,J.dyn_dtree,J.d_desc.max_code),bI0(J,J.bl_desc);for(Z=nI0-1;Z>=3;Z--)if(J.bl_tree[Bg1[Z]*2+1]!==0)break;return J.opt_len+=3*(Z+1)+5+5+4,Z},Nu6=(J,Z,Q,Y)=>{let X;tZ(J,Z-257,5),tZ(J,Q-1,5),tZ(J,Y-4,4);for(X=0;X<Y;X++)tZ(J,J.bl_tree[Bg1[X]*2+1],3);_h1(J,J.dyn_ltree,Z-1),_h1(J,J.dyn_dtree,Q-1)},wu6=(J)=>{let Z=4093624447,Q;for(Q=0;Q<=31;Q++,Z>>>=1)if(Z&1&&J.dyn_ltree[Q*2]!==0)return 0;if(J.dyn_ltree[18]!==0||J.dyn_ltree[20]!==0||J.dyn_ltree[26]!==0)return 1;for(Q=32;Q<Xh;Q++)if(J.dyn_ltree[Q*2]!==0)return 1;return 0},Sh1=!1,Ou6=(J)=>{if(!Sh1)Hu6(),Sh1=!0;J.l_desc=new RI0(J.dyn_ltree,Ng1),J.d_desc=new RI0(J.dyn_dtree,wg1),J.bl_desc=new RI0(J.bl_tree,Og1),J.bi_buf=0,J.bi_valid=0,Ag1(J)},Rg1=(J,Z,Q,Y)=>{if(tZ(J,(Ku6<<1)+(Y?1:0),3),jg1(J),$h(J,Q),$h(J,~Q),Q)J.pending_buf.set(J.window.subarray(Z,Z+Q),J.pending);J.pending+=Q},Lu6=(J)=>{tZ(J,qg1<<1,3),hG(J,aI0,uW),Uu6(J)},Eu6=(J,Z,Q,Y)=>{let X,K,V=0;if(J.level>0){if(J.strm.data_type===2)J.strm.data_type=wu6(J);if(bI0(J,J.l_desc),bI0(J,J.d_desc),V=Bu6(J),X=J.opt_len+3+7>>>3,K=J.static_len+3+7>>>3,K<=X)X=K}else X=K=Q+5;if(Q+4<=X&&Z!==-1)Rg1(J,Z,Q,Y);else if(J.strategy===4||K===X)tZ(J,(qg1<<1)+(Y?1:0),3),Ch1(J,uW,ab);else tZ(J,(Vu6<<1)+(Y?1:0),3),Nu6(J,J.l_desc.max_code+1,J.d_desc.max_code+1,V+1),Ch1(J,J.dyn_ltree,J.dyn_dtree);if(Ag1(J),Y)jg1(J)},Mu6=(J,Z,Q)=>{if(J.pending_buf[J.sym_buf+J.sym_next++]=Z,J.pending_buf[J.sym_buf+J.sym_next++]=Z>>8,J.pending_buf[J.sym_buf+J.sym_next++]=Q,Z===0)J.dyn_ltree[Q*2]++;else J.matches++,Z--,J.dyn_ltree[(eb[Q]+Xh+1)*2]++,J.dyn_dtree[Lg1(Z)*2]++;return J.sym_next===J.sym_end},Au6,ju6,Ru6,Iu6,Pu6,Cu6,Tu6=(J,Z,Q,Y)=>{let X=J&65535|0,K=J>>>16&65535|0,V=0;while(Q!==0){V=Q>2000?2000:Q,Q-=V;do X=X+Z[Y++]|0,K=K+X|0;while(--V);X%=65521,K%=65521}return X|K<<16|0},Jh,_u6=()=>{let J,Z=[];for(var Q=0;Q<256;Q++){J=Q;for(var Y=0;Y<8;Y++)J=J&1?3988292384^J>>>1:J>>>1;Z[Q]=J}return Z},Su6,ku6=(J,Z,Q,Y)=>{let X=Su6,K=Y+Q;J^=-1;for(let V=Y;V<K;V++)J=J>>>8^X[(J^Z[V])&255];return J^-1},T7,RE,CE,yu6,hI0,vu6,sH,xu6,tH,fu6,uu6,vX,kh1,w$,yh1,gG,bu6,PI0,hu6,gu6,A40,mu6,pu6,du6,cu6,k40,lu6=9,iu6=15,nu6=8,au6=29,ou6=256,gI0,ru6=30,su6=19,tu6,eu6=15,i5=3,rH=258,mG,$b6=32,jC=42,rI0=57,mI0=69,pI0=73,dI0=91,cI0=103,AE=113,ib=666,oJ=1,PC=2,IE=3,CC=4,Jb6=3,jE=(J,Z)=>{return J.msg=RE[Z],Z},vh1=(J)=>{return J*2-(J>4?9:0)},oH=(J)=>{let Z=J.length;while(--Z>=0)J[Z]=0},Zb6=(J)=>{let Z,Q,Y,X=J.w_size;Z=J.hash_size,Y=Z;do Q=J.head[--Y],J.head[Y]=Q>=X?Q-X:0;while(--Z);Z=X,Y=Z;do Q=J.prev[--Y],J.prev[Y]=Q>=X?Q-X:0;while(--Z)},Qb6=(J,Z,Q)=>(Z<<J.hash_shift^Q)&J.hash_mask,eH,zY=(J)=>{let Z=J.state,Q=Z.pending;if(Q>J.avail_out)Q=J.avail_out;if(Q===0)return;if(J.output.set(Z.pending_buf.subarray(Z.pending_out,Z.pending_out+Q),J.next_out),J.next_out+=Q,Z.pending_out+=Q,J.total_out+=Q,J.avail_out-=Q,Z.pending-=Q,Z.pending===0)Z.pending_out=0},GY=(J,Z)=>{vu6(J,J.block_start>=0?J.block_start:-1,J.strstart-J.block_start,Z),J.block_start=J.strstart,zY(J.strm)},P3=(J,Z)=>{J.pending_buf[J.pending++]=Z},lb=(J,Z)=>{J.pending_buf[J.pending++]=Z>>>8&255,J.pending_buf[J.pending++]=Z&255},lI0=(J,Z,Q,Y)=>{let X=J.avail_in;if(X>Y)X=Y;if(X===0)return 0;if(J.avail_in-=X,Z.set(J.input.subarray(J.next_in,J.next_in+X),Q),J.state.wrap===1)J.adler=Jh(J.adler,Z,X,Q);else if(J.state.wrap===2)J.adler=T7(J.adler,Z,X,Q);return J.next_in+=X,J.total_in+=X,X},Ig1=(J,Z)=>{let{max_chain_length:Q,strstart:Y}=J,X,K,V=J.prev_length,z=J.nice_match,G=J.strstart>J.w_size-mG?J.strstart-(J.w_size-mG):0,F=J.window,q=J.w_mask,W=J.prev,U=J.strstart+rH,D=F[Y+V-1],H=F[Y+V];if(J.prev_length>=J.good_match)Q>>=2;if(z>J.lookahead)z=J.lookahead;do{if(X=Z,F[X+V]!==H||F[X+V-1]!==D||F[X]!==F[Y]||F[++X]!==F[Y+1])continue;Y+=2,X++;do;while(F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&Y<U);if(K=rH-(U-Y),Y=U-rH,K>V){if(J.match_start=Z,V=K,K>=z)break;D=F[Y+V-1],H=F[Y+V]}}while((Z=W[Z&q])>G&&--Q!==0);if(V<=J.lookahead)return V;return J.lookahead},RC=(J)=>{let Z=J.w_size,Q,Y,X;do{if(Y=J.window_size-J.lookahead-J.strstart,J.strstart>=Z+(Z-mG)){if(J.window.set(J.window.subarray(Z,Z+Z-Y),0),J.match_start-=Z,J.strstart-=Z,J.block_start-=Z,J.insert>J.strstart)J.insert=J.strstart;Zb6(J),Y+=Z}if(J.strm.avail_in===0)break;if(Q=lI0(J.strm,J.window,J.strstart+J.lookahead,Y),J.lookahead+=Q,J.lookahead+J.insert>=i5){X=J.strstart-J.insert,J.ins_h=J.window[X],J.ins_h=eH(J,J.ins_h,J.window[X+1]);while(J.insert)if(J.ins_h=eH(J,J.ins_h,J.window[X+i5-1]),J.prev[X&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=X,X++,J.insert--,J.lookahead+J.insert<i5)break}}while(J.lookahead<mG&&J.strm.avail_in!==0)},Pg1=(J,Z)=>{let Q=J.pending_buf_size-5>J.w_size?J.w_size:J.pending_buf_size-5,Y,X,K,V=0,z=J.strm.avail_in;do{if(Y=65535,K=J.bi_valid+42>>3,J.strm.avail_out<K)break;if(K=J.strm.avail_out-K,X=J.strstart-J.block_start,Y>X+J.strm.avail_in)Y=X+J.strm.avail_in;if(Y>K)Y=K;if(Y<Q&&(Y===0&&Z!==vX||Z===tH||Y!==X+J.strm.avail_in))break;if(V=Z===vX&&Y===X+J.strm.avail_in?1:0,hI0(J,0,0,V),J.pending_buf[J.pending-4]=Y,J.pending_buf[J.pending-3]=Y>>8,J.pending_buf[J.pending-2]=~Y,J.pending_buf[J.pending-1]=~Y>>8,zY(J.strm),X){if(X>Y)X=Y;J.strm.output.set(J.window.subarray(J.block_start,J.block_start+X),J.strm.next_out),J.strm.next_out+=X,J.strm.avail_out-=X,J.strm.total_out+=X,J.block_start+=X,Y-=X}if(Y)lI0(J.strm,J.strm.output,J.strm.next_out,Y),J.strm.next_out+=Y,J.strm.avail_out-=Y,J.strm.total_out+=Y}while(V===0);if(z-=J.strm.avail_in,z){if(z>=J.w_size)J.matches=2,J.window.set(J.strm.input.subarray(J.strm.next_in-J.w_size,J.strm.next_in),0),J.strstart=J.w_size,J.insert=J.strstart;else{if(J.window_size-J.strstart<=z){if(J.strstart-=J.w_size,J.window.set(J.window.subarray(J.w_size,J.w_size+J.strstart),0),J.matches<2)J.matches++;if(J.insert>J.strstart)J.insert=J.strstart}J.window.set(J.strm.input.subarray(J.strm.next_in-z,J.strm.next_in),J.strstart),J.strstart+=z,J.insert+=z>J.w_size-J.insert?J.w_size-J.insert:z}J.block_start=J.strstart}if(J.high_water<J.strstart)J.high_water=J.strstart;if(V)return CC;if(Z!==tH&&Z!==vX&&J.strm.avail_in===0&&J.strstart===J.block_start)return PC;if(K=J.window_size-J.strstart,J.strm.avail_in>K&&J.block_start>=J.w_size){if(J.block_start-=J.w_size,J.strstart-=J.w_size,J.window.set(J.window.subarray(J.w_size,J.w_size+J.strstart),0),J.matches<2)J.matches++;if(K+=J.w_size,J.insert>J.strstart)J.insert=J.strstart}if(K>J.strm.avail_in)K=J.strm.avail_in;if(K)lI0(J.strm,J.window,J.strstart,K),J.strstart+=K,J.insert+=K>J.w_size-J.insert?J.w_size-J.insert:K;if(J.high_water<J.strstart)J.high_water=J.strstart;if(K=J.bi_valid+42>>3,K=J.pending_buf_size-K>65535?65535:J.pending_buf_size-K,Q=K>J.w_size?J.w_size:K,X=J.strstart-J.block_start,X>=Q||(X||Z===vX)&&Z!==tH&&J.strm.avail_in===0&&X<=K)Y=X>K?K:X,V=Z===vX&&J.strm.avail_in===0&&Y===X?1:0,hI0(J,J.block_start,Y,V),J.block_start+=Y,zY(J.strm);return V?IE:oJ},CI0=(J,Z)=>{let Q,Y;for(;;){if(J.lookahead<mG){if(RC(J),J.lookahead<mG&&Z===tH)return oJ;if(J.lookahead===0)break}if(Q=0,J.lookahead>=i5)J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;if(Q!==0&&J.strstart-Q<=J.w_size-mG)J.match_length=Ig1(J,Q);if(J.match_length>=i5)if(Y=sH(J,J.strstart-J.match_start,J.match_length-i5),J.lookahead-=J.match_length,J.match_length<=J.max_lazy_match&&J.lookahead>=i5){J.match_length--;do J.strstart++,J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;while(--J.match_length!==0);J.strstart++}else J.strstart+=J.match_length,J.match_length=0,J.ins_h=J.window[J.strstart],J.ins_h=eH(J,J.ins_h,J.window[J.strstart+1]);else Y=sH(J,0,J.window[J.strstart]),J.lookahead--,J.strstart++;if(Y){if(GY(J,!1),J.strm.avail_out===0)return oJ}}if(J.insert=J.strstart<i5-1?J.strstart:i5-1,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},EC=(J,Z)=>{let Q,Y,X;for(;;){if(J.lookahead<mG){if(RC(J),J.lookahead<mG&&Z===tH)return oJ;if(J.lookahead===0)break}if(Q=0,J.lookahead>=i5)J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;if(J.prev_length=J.match_length,J.prev_match=J.match_start,J.match_length=i5-1,Q!==0&&J.prev_length<J.max_lazy_match&&J.strstart-Q<=J.w_size-mG){if(J.match_length=Ig1(J,Q),J.match_length<=5&&(J.strategy===gu6||J.match_length===i5&&J.strstart-J.match_start>4096))J.match_length=i5-1}if(J.prev_length>=i5&&J.match_length<=J.prev_length){X=J.strstart+J.lookahead-i5,Y=sH(J,J.strstart-1-J.prev_match,J.prev_length-i5),J.lookahead-=J.prev_length-1,J.prev_length-=2;do if(++J.strstart<=X)J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;while(--J.prev_length!==0);if(J.match_available=0,J.match_length=i5-1,J.strstart++,Y){if(GY(J,!1),J.strm.avail_out===0)return oJ}}else if(J.match_available){if(Y=sH(J,0,J.window[J.strstart-1]),Y)GY(J,!1);if(J.strstart++,J.lookahead--,J.strm.avail_out===0)return oJ}else J.match_available=1,J.strstart++,J.lookahead--}if(J.match_available)Y=sH(J,0,J.window[J.strstart-1]),J.match_available=0;if(J.insert=J.strstart<i5-1?J.strstart:i5-1,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},Yb6=(J,Z)=>{let Q,Y,X,K,V=J.window;for(;;){if(J.lookahead<=rH){if(RC(J),J.lookahead<=rH&&Z===tH)return oJ;if(J.lookahead===0)break}if(J.match_length=0,J.lookahead>=i5&&J.strstart>0){if(X=J.strstart-1,Y=V[X],Y===V[++X]&&Y===V[++X]&&Y===V[++X]){K=J.strstart+rH;do;while(Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&X<K);if(J.match_length=rH-(K-X),J.match_length>J.lookahead)J.match_length=J.lookahead}}if(J.match_length>=i5)Q=sH(J,1,J.match_length-i5),J.lookahead-=J.match_length,J.strstart+=J.match_length,J.match_length=0;else Q=sH(J,0,J.window[J.strstart]),J.lookahead--,J.strstart++;if(Q){if(GY(J,!1),J.strm.avail_out===0)return oJ}}if(J.insert=0,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},Xb6=(J,Z)=>{let Q;for(;;){if(J.lookahead===0){if(RC(J),J.lookahead===0){if(Z===tH)return oJ;break}}if(J.match_length=0,Q=sH(J,0,J.window[J.strstart]),J.lookahead--,J.strstart++,Q){if(GY(J,!1),J.strm.avail_out===0)return oJ}}if(J.insert=0,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},nb,Kb6=(J)=>{J.window_size=2*J.w_size,oH(J.head),J.max_lazy_match=nb[J.level].max_lazy,J.good_match=nb[J.level].good_length,J.nice_match=nb[J.level].nice_length,J.max_chain_length=nb[J.level].max_chain,J.strstart=0,J.block_start=0,J.lookahead=0,J.insert=0,J.match_length=J.prev_length=i5-1,J.match_available=0,J.ins_h=0},Kh=(J)=>{if(!J)return 1;let Z=J.state;if(!Z||Z.strm!==J||Z.status!==jC&&Z.status!==rI0&&Z.status!==mI0&&Z.status!==pI0&&Z.status!==dI0&&Z.status!==cI0&&Z.status!==AE&&Z.status!==ib)return 1;return 0},Cg1=(J)=>{if(Kh(J))return jE(J,gG);J.total_in=J.total_out=0,J.data_type=cu6;let Z=J.state;if(Z.pending=0,Z.pending_out=0,Z.wrap<0)Z.wrap=-Z.wrap;return Z.status=Z.wrap===2?rI0:Z.wrap?jC:AE,J.adler=Z.wrap===2?0:1,Z.last_flush=-2,yu6(Z),w$},Tg1=(J)=>{let Z=Cg1(J);if(Z===w$)Kb6(J.state);return Z},zb6=(J,Z)=>{if(Kh(J)||J.state.wrap!==2)return gG;return J.state.gzhead=Z,w$},_g1=(J,Z,Q,Y,X,K)=>{if(!J)return gG;let V=1;if(Z===hu6)Z=6;if(Y<0)V=0,Y=-Y;else if(Y>15)V=2,Y-=16;if(X<1||X>lu6||Q!==k40||Y<8||Y>15||Z<0||Z>9||K<0||K>pu6||Y===8&&V!==1)return jE(J,gG);if(Y===8)Y=9;let z=new Vb6;return J.state=z,z.strm=J,z.status=jC,z.wrap=V,z.gzhead=null,z.w_bits=Y,z.w_size=1<<z.w_bits,z.w_mask=z.w_size-1,z.hash_bits=X+7,z.hash_size=1<<z.hash_bits,z.hash_mask=z.hash_size-1,z.hash_shift=~~((z.hash_bits+i5-1)/i5),z.window=new Uint8Array(z.w_size*2),z.head=new Uint16Array(z.hash_size),z.prev=new Uint16Array(z.w_size),z.lit_bufsize=1<<X+6,z.pending_buf_size=z.lit_bufsize*4,z.pending_buf=new Uint8Array(z.pending_buf_size),z.sym_buf=z.lit_bufsize,z.sym_end=(z.lit_bufsize-1)*3,z.level=Z,z.strategy=K,z.method=Q,Tg1(J)},Gb6=(J,Z)=>{return _g1(J,Z,k40,iu6,nu6,du6)},Fb6=(J,Z)=>{if(Kh(J)||Z>kh1||Z<0)return J?jE(J,gG):gG;let Q=J.state;if(!J.output||J.avail_in!==0&&!J.input||Q.status===ib&&Z!==vX)return jE(J,J.avail_out===0?PI0:gG);let Y=Q.last_flush;if(Q.last_flush=Z,Q.pending!==0){if(zY(J),J.avail_out===0)return Q.last_flush=-1,w$}else if(J.avail_in===0&&vh1(Z)<=vh1(Y)&&Z!==vX)return jE(J,PI0);if(Q.status===ib&&J.avail_in!==0)return jE(J,PI0);if(Q.status===jC&&Q.wrap===0)Q.status=AE;if(Q.status===jC){let X=k40+(Q.w_bits-8<<4)<<8,K=-1;if(Q.strategy>=A40||Q.level<2)K=0;else if(Q.level<6)K=1;else if(Q.level===6)K=2;else K=3;if(X|=K<<6,Q.strstart!==0)X|=$b6;if(X+=31-X%31,lb(Q,X),Q.strstart!==0)lb(Q,J.adler>>>16),lb(Q,J.adler&65535);if(J.adler=1,Q.status=AE,zY(J),Q.pending!==0)return Q.last_flush=-1,w$}if(Q.status===rI0)if(J.adler=0,P3(Q,31),P3(Q,139),P3(Q,8),!Q.gzhead){if(P3(Q,0),P3(Q,0),P3(Q,0),P3(Q,0),P3(Q,0),P3(Q,Q.level===9?2:Q.strategy>=A40||Q.level<2?4:0),P3(Q,Jb6),Q.status=AE,zY(J),Q.pending!==0)return Q.last_flush=-1,w$}else{if(P3(Q,(Q.gzhead.text?1:0)+(Q.gzhead.hcrc?2:0)+(!Q.gzhead.extra?0:4)+(!Q.gzhead.name?0:8)+(!Q.gzhead.comment?0:16)),P3(Q,Q.gzhead.time&255),P3(Q,Q.gzhead.time>>8&255),P3(Q,Q.gzhead.time>>16&255),P3(Q,Q.gzhead.time>>24&255),P3(Q,Q.level===9?2:Q.strategy>=A40||Q.level<2?4:0),P3(Q,Q.gzhead.os&255),Q.gzhead.extra&&Q.gzhead.extra.length)P3(Q,Q.gzhead.extra.length&255),P3(Q,Q.gzhead.extra.length>>8&255);if(Q.gzhead.hcrc)J.adler=T7(J.adler,Q.pending_buf,Q.pending,0);Q.gzindex=0,Q.status=mI0}if(Q.status===mI0){if(Q.gzhead.extra){let X=Q.pending,K=(Q.gzhead.extra.length&65535)-Q.gzindex;while(Q.pending+K>Q.pending_buf_size){let z=Q.pending_buf_size-Q.pending;if(Q.pending_buf.set(Q.gzhead.extra.subarray(Q.gzindex,Q.gzindex+z),Q.pending),Q.pending=Q.pending_buf_size,Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);if(Q.gzindex+=z,zY(J),Q.pending!==0)return Q.last_flush=-1,w$;X=0,K-=z}let V=new Uint8Array(Q.gzhead.extra);if(Q.pending_buf.set(V.subarray(Q.gzindex,Q.gzindex+K),Q.pending),Q.pending+=K,Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);Q.gzindex=0}Q.status=pI0}if(Q.status===pI0){if(Q.gzhead.name){let X=Q.pending,K;do{if(Q.pending===Q.pending_buf_size){if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);if(zY(J),Q.pending!==0)return Q.last_flush=-1,w$;X=0}if(Q.gzindex<Q.gzhead.name.length)K=Q.gzhead.name.charCodeAt(Q.gzindex++)&255;else K=0;P3(Q,K)}while(K!==0);if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);Q.gzindex=0}Q.status=dI0}if(Q.status===dI0){if(Q.gzhead.comment){let X=Q.pending,K;do{if(Q.pending===Q.pending_buf_size){if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);if(zY(J),Q.pending!==0)return Q.last_flush=-1,w$;X=0}if(Q.gzindex<Q.gzhead.comment.length)K=Q.gzhead.comment.charCodeAt(Q.gzindex++)&255;else K=0;P3(Q,K)}while(K!==0);if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X)}Q.status=cI0}if(Q.status===cI0){if(Q.gzhead.hcrc){if(Q.pending+2>Q.pending_buf_size){if(zY(J),Q.pending!==0)return Q.last_flush=-1,w$}P3(Q,J.adler&255),P3(Q,J.adler>>8&255),J.adler=0}if(Q.status=AE,zY(J),Q.pending!==0)return Q.last_flush=-1,w$}if(J.avail_in!==0||Q.lookahead!==0||Z!==tH&&Q.status!==ib){let X=Q.level===0?Pg1(Q,Z):Q.strategy===A40?Xb6(Q,Z):Q.strategy===mu6?Yb6(Q,Z):nb[Q.level].func(Q,Z);if(X===IE||X===CC)Q.status=ib;if(X===oJ||X===IE){if(J.avail_out===0)Q.last_flush=-1;return w$}if(X===PC){if(Z===fu6)xu6(Q);else if(Z!==kh1){if(hI0(Q,0,0,!1),Z===uu6){if(oH(Q.head),Q.lookahead===0)Q.strstart=0,Q.block_start=0,Q.insert=0}}if(zY(J),J.avail_out===0)return Q.last_flush=-1,w$}}if(Z!==vX)return w$;if(Q.wrap<=0)return yh1;if(Q.wrap===2)P3(Q,J.adler&255),P3(Q,J.adler>>8&255),P3(Q,J.adler>>16&255),P3(Q,J.adler>>24&255),P3(Q,J.total_in&255),P3(Q,J.total_in>>8&255),P3(Q,J.total_in>>16&255),P3(Q,J.total_in>>24&255);else lb(Q,J.adler>>>16),lb(Q,J.adler&65535);if(zY(J),Q.wrap>0)Q.wrap=-Q.wrap;return Q.pending!==0?w$:yh1},qb6=(J)=>{if(Kh(J))return gG;let Z=J.state.status;return J.state=null,Z===AE?jE(J,bu6):w$},Wb6=(J,Z)=>{let Q=Z.length;if(Kh(J))return gG;let Y=J.state,X=Y.wrap;if(X===2||X===1&&Y.status!==jC||Y.lookahead)return gG;if(X===1)J.adler=Jh(J.adler,Z,Q,0);if(Y.wrap=0,Q>=Y.w_size){if(X===0)oH(Y.head),Y.strstart=0,Y.block_start=0,Y.insert=0;let G=new Uint8Array(Y.w_size);G.set(Z.subarray(Q-Y.w_size,Q),0),Z=G,Q=Y.w_size}let{avail_in:K,next_in:V,input:z}=J;J.avail_in=Q,J.next_in=0,J.input=Z,RC(Y);while(Y.lookahead>=i5){let G=Y.strstart,F=Y.lookahead-(i5-1);do Y.ins_h=eH(Y,Y.ins_h,Y.window[G+i5-1]),Y.prev[G&Y.w_mask]=Y.head[Y.ins_h],Y.head[Y.ins_h]=G,G++;while(--F);Y.strstart=G,Y.lookahead=i5-1,RC(Y)}return Y.strstart+=Y.lookahead,Y.block_start=Y.strstart,Y.insert=Y.lookahead,Y.lookahead=0,Y.match_length=Y.prev_length=i5-1,Y.match_available=0,J.next_in=V,J.input=z,J.avail_in=K,Y.wrap=X,w$},Ub6,Db6,Hb6,Bb6,Nb6,wb6,Ob6,Lb6,Eb6="pako deflate (from Nodeca project)",ob,Mb6=(J,Z)=>{return Object.prototype.hasOwnProperty.call(J,Z)},Ab6=function(J){let Z=Array.prototype.slice.call(arguments,1);while(Z.length){let Q=Z.shift();if(!Q)continue;if(typeof Q!=="object")throw TypeError(Q+"must be non-object");for(let Y in Q)if(Mb6(Q,Y))J[Y]=Q[Y]}return J},jb6=(J)=>{let Z=0;for(let Y=0,X=J.length;Y<X;Y++)Z+=J[Y].length;let Q=new Uint8Array(Z);for(let Y=0,X=0,K=J.length;Y<K;Y++){let V=J[Y];Q.set(V,X),X+=V.length}return Q},y40,Sg1=!0,Zh,Rb6=(J)=>{if(typeof TextEncoder==="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(J);let Z,Q,Y,X,K,V=J.length,z=0;for(X=0;X<V;X++){if(Q=J.charCodeAt(X),(Q&64512)===55296&&X+1<V){if(Y=J.charCodeAt(X+1),(Y&64512)===56320)Q=65536+(Q-55296<<10)+(Y-56320),X++}z+=Q<128?1:Q<2048?2:Q<65536?3:4}Z=new Uint8Array(z);for(K=0,X=0;K<z;X++){if(Q=J.charCodeAt(X),(Q&64512)===55296&&X+1<V){if(Y=J.charCodeAt(X+1),(Y&64512)===56320)Q=65536+(Q-55296<<10)+(Y-56320),X++}if(Q<128)Z[K++]=Q;else if(Q<2048)Z[K++]=192|Q>>>6,Z[K++]=128|Q&63;else if(Q<65536)Z[K++]=224|Q>>>12,Z[K++]=128|Q>>>6&63,Z[K++]=128|Q&63;else Z[K++]=240|Q>>>18,Z[K++]=128|Q>>>12&63,Z[K++]=128|Q>>>6&63,Z[K++]=128|Q&63}return Z},Ib6=(J,Z)=>{if(Z<65534){if(J.subarray&&Sg1)return String.fromCharCode.apply(null,J.length===Z?J:J.subarray(0,Z))}let Q="";for(let Y=0;Y<Z;Y++)Q+=String.fromCharCode(J[Y]);return Q},Pb6=(J,Z)=>{let Q=Z||J.length;if(typeof TextDecoder==="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(J.subarray(0,Z));let Y,X,K=Array(Q*2);for(X=0,Y=0;Y<Q;){let V=J[Y++];if(V<128){K[X++]=V;continue}let z=Zh[V];if(z>4){K[X++]=65533,Y+=z-1;continue}V&=z===2?31:z===3?15:7;while(z>1&&Y<Q)V=V<<6|J[Y++]&63,z--;if(z>1){K[X++]=65533;continue}if(V<65536)K[X++]=V;else V-=65536,K[X++]=55296|V>>10&1023,K[X++]=56320|V&1023}return Ib6(K,X)},Cb6=(J,Z)=>{if(Z=Z||J.length,Z>J.length)Z=J.length;let Q=Z-1;while(Q>=0&&(J[Q]&192)===128)Q--;if(Q<0)return Z;if(Q===0)return Z;return Q+Zh[J[Q]]>Z?Q:Z},Qh,kg1,yg1,_b6,Sb6,kb6,yb6,_40,vb6,xb6,fb6,ub6,gb6,mb6,pb6,db6,cb6,lb6,j40=16209,ib6=16191,nb6=function(Z,Q){let Y,X,K,V,z,G,F,q,W,U,D,H,B,N,w,O,L,E,M,A,j,R,_,k,u=Z.state;Y=Z.next_in,_=Z.input,X=Y+(Z.avail_in-5),K=Z.next_out,k=Z.output,V=K-(Q-Z.avail_out),z=K+(Z.avail_out-257),G=u.dmax,F=u.wsize,q=u.whave,W=u.wnext,U=u.window,D=u.hold,H=u.bits,B=u.lencode,N=u.distcode,w=(1<<u.lenbits)-1,O=(1<<u.distbits)-1;$:do{if(H<15)D+=_[Y++]<<H,H+=8,D+=_[Y++]<<H,H+=8;L=B[D&w];J:for(;;){if(E=L>>>24,D>>>=E,H-=E,E=L>>>16&255,E===0)k[K++]=L&65535;else if(E&16){if(M=L&65535,E&=15,E){if(H<E)D+=_[Y++]<<H,H+=8;M+=D&(1<<E)-1,D>>>=E,H-=E}if(H<15)D+=_[Y++]<<H,H+=8,D+=_[Y++]<<H,H+=8;L=N[D&O];Z:for(;;){if(E=L>>>24,D>>>=E,H-=E,E=L>>>16&255,E&16){if(A=L&65535,E&=15,H<E){if(D+=_[Y++]<<H,H+=8,H<E)D+=_[Y++]<<H,H+=8}if(A+=D&(1<<E)-1,A>G){Z.msg="invalid distance too far back",u.mode=j40;break $}if(D>>>=E,H-=E,E=K-V,A>E){if(E=A-E,E>q){if(u.sane){Z.msg="invalid distance too far back",u.mode=j40;break $}}if(j=0,R=U,W===0){if(j+=F-E,E<M){M-=E;do k[K++]=U[j++];while(--E);j=K-A,R=k}}else if(W<E){if(j+=F+W-E,E-=W,E<M){M-=E;do k[K++]=U[j++];while(--E);if(j=0,W<M){E=W,M-=E;do k[K++]=U[j++];while(--E);j=K-A,R=k}}}else if(j+=W-E,E<M){M-=E;do k[K++]=U[j++];while(--E);j=K-A,R=k}while(M>2)k[K++]=R[j++],k[K++]=R[j++],k[K++]=R[j++],M-=3;if(M){if(k[K++]=R[j++],M>1)k[K++]=R[j++]}}else{j=K-A;do k[K++]=k[j++],k[K++]=k[j++],k[K++]=k[j++],M-=3;while(M>2);if(M){if(k[K++]=k[j++],M>1)k[K++]=k[j++]}}}else if((E&64)===0){L=N[(L&65535)+(D&(1<<E)-1)];continue Z}else{Z.msg="invalid distance code",u.mode=j40;break $}break}}else if((E&64)===0){L=B[(L&65535)+(D&(1<<E)-1)];continue J}else if(E&32){u.mode=ib6;break $}else{Z.msg="invalid literal/length code",u.mode=j40;break $}break}}while(Y<X&&K<z);M=H>>3,Y-=M,H-=M<<3,D&=(1<<H)-1,Z.next_in=Y,Z.next_out=K,Z.avail_in=Y<X?5+(X-Y):5-(Y-X),Z.avail_out=K<z?257+(z-K):257-(K-z),u.hold=D,u.bits=H;return},MC=15,xh1=852,fh1=592,uh1=0,TI0=1,bh1=2,ab6,ob6,rb6,sb6,tb6=(J,Z,Q,Y,X,K,V,z)=>{let G=z.bits,F=0,q=0,W=0,U=0,D=0,H=0,B=0,N=0,w=0,O=0,L,E,M,A,j,R=null,_,k=new Uint16Array(MC+1),u=new Uint16Array(MC+1),m=null,x,T,f;for(F=0;F<=MC;F++)k[F]=0;for(q=0;q<Y;q++)k[Z[Q+q]]++;D=G;for(U=MC;U>=1;U--)if(k[U]!==0)break;if(D>U)D=U;if(U===0)return X[K++]=20971520,X[K++]=20971520,z.bits=1,0;for(W=1;W<U;W++)if(k[W]!==0)break;if(D<W)D=W;N=1;for(F=1;F<=MC;F++)if(N<<=1,N-=k[F],N<0)return-1;if(N>0&&(J===uh1||U!==1))return-1;u[1]=0;for(F=1;F<MC;F++)u[F+1]=u[F]+k[F];for(q=0;q<Y;q++)if(Z[Q+q]!==0)V[u[Z[Q+q]]++]=q;if(J===uh1)R=m=V,_=20;else if(J===TI0)R=ab6,m=ob6,_=257;else R=rb6,m=sb6,_=0;if(O=0,q=0,F=W,j=K,H=D,B=0,M=-1,w=1<<D,A=w-1,J===TI0&&w>xh1||J===bh1&&w>fh1)return 1;for(;;){if(x=F-B,V[q]+1<_)T=0,f=V[q];else if(V[q]>=_)T=m[V[q]-_],f=R[V[q]-_];else T=96,f=0;L=1<<F-B,E=1<<H,W=E;do E-=L,X[j+(O>>B)+E]=x<<24|T<<16|f|0;while(E!==0);L=1<<F-1;while(O&L)L>>=1;if(L!==0)O&=L-1,O+=L;else O=0;if(q++,--k[F]===0){if(F===U)break;F=Z[Q+V[q]]}if(F>D&&(O&A)!==M){if(B===0)B=D;j+=W,H=F-B,N=1<<H;while(H+B<U){if(N-=k[H+B],N<=0)break;H++,N<<=1}if(w+=1<<H,J===TI0&&w>xh1||J===bh1&&w>fh1)return 1;M=O&A,X[M]=D<<24|H<<16|j-K|0}}if(O!==0)X[j+O]=F-B<<24|4194304|0;return z.bits=D,0},rb,eb6=0,vg1=1,xg1=2,hh1,$h6,R40,PE,Jh6,Zh6,xX,fg1,ug1,Qh6,gh1,v40=16180,mh1=16181,ph1=16182,dh1=16183,ch1=16184,lh1=16185,ih1=16186,nh1=16187,ah1=16188,oh1=16189,S40=16190,fW=16191,_I0=16192,rh1=16193,SI0=16194,sh1=16195,th1=16196,eh1=16197,$g1=16198,I40=16199,P40=16200,Jg1=16201,Zg1=16202,Qg1=16203,Yg1=16204,Xg1=16205,kI0=16206,Kg1=16207,Vg1=16208,Y9=16209,bg1=16210,hg1=16211,Yh6=852,Xh6=592,Kh6=15,Vh6,zg1=(J)=>{return(J>>>24&255)+(J>>>8&65280)+((J&65280)<<8)+((J&255)<<24)},TE=(J)=>{if(!J)return 1;let Z=J.state;if(!Z||Z.strm!==J||Z.mode<v40||Z.mode>hg1)return 1;return 0},gg1=(J)=>{if(TE(J))return xX;let Z=J.state;if(J.total_in=J.total_out=Z.total=0,J.msg="",Z.wrap)J.adler=Z.wrap&1;return Z.mode=v40,Z.last=0,Z.havedict=0,Z.flags=-1,Z.dmax=32768,Z.head=null,Z.hold=0,Z.bits=0,Z.lencode=Z.lendyn=new Int32Array(Yh6),Z.distcode=Z.distdyn=new Int32Array(Xh6),Z.sane=1,Z.back=-1,PE},mg1=(J)=>{if(TE(J))return xX;let Z=J.state;return Z.wsize=0,Z.whave=0,Z.wnext=0,gg1(J)},pg1=(J,Z)=>{let Q;if(TE(J))return xX;let Y=J.state;if(Z<0)Q=0,Z=-Z;else if(Q=(Z>>4)+5,Z<48)Z&=15;if(Z&&(Z<8||Z>15))return xX;if(Y.window!==null&&Y.wbits!==Z)Y.window=null;return Y.wrap=Q,Y.wbits=Z,mg1(J)},dg1=(J,Z)=>{if(!J)return xX;let Q=new zh6;J.state=Q,Q.strm=J,Q.window=null,Q.mode=v40;let Y=pg1(J,Z);if(Y!==PE)J.state=null;return Y},Gh6=(J)=>{return dg1(J,Vh6)},Gg1=!0,yI0,vI0,Fh6=(J)=>{if(Gg1){yI0=new Int32Array(512),vI0=new Int32Array(32);let Z=0;while(Z<144)J.lens[Z++]=8;while(Z<256)J.lens[Z++]=9;while(Z<280)J.lens[Z++]=7;while(Z<288)J.lens[Z++]=8;rb(vg1,J.lens,0,288,yI0,0,J.work,{bits:9}),Z=0;while(Z<32)J.lens[Z++]=5;rb(xg1,J.lens,0,32,vI0,0,J.work,{bits:5}),Gg1=!1}J.lencode=yI0,J.lenbits=9,J.distcode=vI0,J.distbits=5},cg1=(J,Z,Q,Y)=>{let X,K=J.state;if(K.window===null)K.wsize=1<<K.wbits,K.wnext=0,K.whave=0,K.window=new Uint8Array(K.wsize);if(Y>=K.wsize)K.window.set(Z.subarray(Q-K.wsize,Q),0),K.wnext=0,K.whave=K.wsize;else{if(X=K.wsize-K.wnext,X>Y)X=Y;if(K.window.set(Z.subarray(Q-Y,Q-Y+X),K.wnext),Y-=X,Y)K.window.set(Z.subarray(Q-Y,Q),0),K.wnext=Y,K.whave=K.wsize;else{if(K.wnext+=X,K.wnext===K.wsize)K.wnext=0;if(K.whave<K.wsize)K.whave+=X}}return 0},qh6=(J,Z)=>{let Q,Y,X,K,V,z,G,F,q,W,U,D,H,B,N=0,w,O,L,E,M,A,j,R,_=new Uint8Array(4),k,u,m=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(TE(J)||!J.output||!J.input&&J.avail_in!==0)return xX;if(Q=J.state,Q.mode===fW)Q.mode=_I0;V=J.next_out,X=J.output,G=J.avail_out,K=J.next_in,Y=J.input,z=J.avail_in,F=Q.hold,q=Q.bits,W=z,U=G,R=PE;$:for(;;)switch(Q.mode){case v40:if(Q.wrap===0){Q.mode=_I0;break}while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.wrap&2&&F===35615){if(Q.wbits===0)Q.wbits=15;Q.check=0,_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0),F=0,q=0,Q.mode=mh1;break}if(Q.head)Q.head.done=!1;if(!(Q.wrap&1)||(((F&255)<<8)+(F>>8))%31){J.msg="incorrect header check",Q.mode=Y9;break}if((F&15)!==gh1){J.msg="unknown compression method",Q.mode=Y9;break}if(F>>>=4,q-=4,j=(F&15)+8,Q.wbits===0)Q.wbits=j;if(j>15||j>Q.wbits){J.msg="invalid window size",Q.mode=Y9;break}Q.dmax=1<<Q.wbits,Q.flags=0,J.adler=Q.check=1,Q.mode=F&512?oh1:fW,F=0,q=0;break;case mh1:while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.flags=F,(Q.flags&255)!==gh1){J.msg="unknown compression method",Q.mode=Y9;break}if(Q.flags&57344){J.msg="unknown header flags set",Q.mode=Y9;break}if(Q.head)Q.head.text=F>>8&1;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0);F=0,q=0,Q.mode=ph1;case ph1:while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.head)Q.head.time=F;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,_[2]=F>>>16&255,_[3]=F>>>24&255,Q.check=T7(Q.check,_,4,0);F=0,q=0,Q.mode=dh1;case dh1:while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.head)Q.head.xflags=F&255,Q.head.os=F>>8;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0);F=0,q=0,Q.mode=ch1;case ch1:if(Q.flags&1024){while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.length=F,Q.head)Q.head.extra_len=F;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0);F=0,q=0}else if(Q.head)Q.head.extra=null;Q.mode=lh1;case lh1:if(Q.flags&1024){if(D=Q.length,D>z)D=z;if(D){if(Q.head){if(j=Q.head.extra_len-Q.length,!Q.head.extra)Q.head.extra=new Uint8Array(Q.head.extra_len);Q.head.extra.set(Y.subarray(K,K+D),j)}if(Q.flags&512&&Q.wrap&4)Q.check=T7(Q.check,Y,D,K);z-=D,K+=D,Q.length-=D}if(Q.length)break $}Q.length=0,Q.mode=ih1;case ih1:if(Q.flags&2048){if(z===0)break $;D=0;do if(j=Y[K+D++],Q.head&&j&&Q.length<65536)Q.head.name+=String.fromCharCode(j);while(j&&D<z);if(Q.flags&512&&Q.wrap&4)Q.check=T7(Q.check,Y,D,K);if(z-=D,K+=D,j)break $}else if(Q.head)Q.head.name=null;Q.length=0,Q.mode=nh1;case nh1:if(Q.flags&4096){if(z===0)break $;D=0;do if(j=Y[K+D++],Q.head&&j&&Q.length<65536)Q.head.comment+=String.fromCharCode(j);while(j&&D<z);if(Q.flags&512&&Q.wrap&4)Q.check=T7(Q.check,Y,D,K);if(z-=D,K+=D,j)break $}else if(Q.head)Q.head.comment=null;Q.mode=ah1;case ah1:if(Q.flags&512){while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.wrap&4&&F!==(Q.check&65535)){J.msg="header crc mismatch",Q.mode=Y9;break}F=0,q=0}if(Q.head)Q.head.hcrc=Q.flags>>9&1,Q.head.done=!0;J.adler=Q.check=0,Q.mode=fW;break;case oh1:while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}J.adler=Q.check=zg1(F),F=0,q=0,Q.mode=S40;case S40:if(Q.havedict===0)return J.next_out=V,J.avail_out=G,J.next_in=K,J.avail_in=z,Q.hold=F,Q.bits=q,Zh6;J.adler=Q.check=1,Q.mode=fW;case fW:if(Z===$h6||Z===R40)break $;case _I0:if(Q.last){F>>>=q&7,q-=q&7,Q.mode=kI0;break}while(q<3){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}switch(Q.last=F&1,F>>>=1,q-=1,F&3){case 0:Q.mode=rh1;break;case 1:if(Fh6(Q),Q.mode=I40,Z===R40){F>>>=2,q-=2;break $}break;case 2:Q.mode=th1;break;case 3:J.msg="invalid block type",Q.mode=Y9}F>>>=2,q-=2;break;case rh1:F>>>=q&7,q-=q&7;while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if((F&65535)!==(F>>>16^65535)){J.msg="invalid stored block lengths",Q.mode=Y9;break}if(Q.length=F&65535,F=0,q=0,Q.mode=SI0,Z===R40)break $;case SI0:Q.mode=sh1;case sh1:if(D=Q.length,D){if(D>z)D=z;if(D>G)D=G;if(D===0)break $;X.set(Y.subarray(K,K+D),V),z-=D,K+=D,G-=D,V+=D,Q.length-=D;break}Q.mode=fW;break;case th1:while(q<14){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.nlen=(F&31)+257,F>>>=5,q-=5,Q.ndist=(F&31)+1,F>>>=5,q-=5,Q.ncode=(F&15)+4,F>>>=4,q-=4,Q.nlen>286||Q.ndist>30){J.msg="too many length or distance symbols",Q.mode=Y9;break}Q.have=0,Q.mode=eh1;case eh1:while(Q.have<Q.ncode){while(q<3){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}Q.lens[m[Q.have++]]=F&7,F>>>=3,q-=3}while(Q.have<19)Q.lens[m[Q.have++]]=0;if(Q.lencode=Q.lendyn,Q.lenbits=7,k={bits:Q.lenbits},R=rb(eb6,Q.lens,0,19,Q.lencode,0,Q.work,k),Q.lenbits=k.bits,R){J.msg="invalid code lengths set",Q.mode=Y9;break}Q.have=0,Q.mode=$g1;case $g1:while(Q.have<Q.nlen+Q.ndist){for(;;){if(N=Q.lencode[F&(1<<Q.lenbits)-1],w=N>>>24,O=N>>>16&255,L=N&65535,w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(L<16)F>>>=w,q-=w,Q.lens[Q.have++]=L;else{if(L===16){u=w+2;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(F>>>=w,q-=w,Q.have===0){J.msg="invalid bit length repeat",Q.mode=Y9;break}j=Q.lens[Q.have-1],D=3+(F&3),F>>>=2,q-=2}else if(L===17){u=w+3;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=w,q-=w,j=0,D=3+(F&7),F>>>=3,q-=3}else{u=w+7;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=w,q-=w,j=0,D=11+(F&127),F>>>=7,q-=7}if(Q.have+D>Q.nlen+Q.ndist){J.msg="invalid bit length repeat",Q.mode=Y9;break}while(D--)Q.lens[Q.have++]=j}}if(Q.mode===Y9)break;if(Q.lens[256]===0){J.msg="invalid code -- missing end-of-block",Q.mode=Y9;break}if(Q.lenbits=9,k={bits:Q.lenbits},R=rb(vg1,Q.lens,0,Q.nlen,Q.lencode,0,Q.work,k),Q.lenbits=k.bits,R){J.msg="invalid literal/lengths set",Q.mode=Y9;break}if(Q.distbits=6,Q.distcode=Q.distdyn,k={bits:Q.distbits},R=rb(xg1,Q.lens,Q.nlen,Q.ndist,Q.distcode,0,Q.work,k),Q.distbits=k.bits,R){J.msg="invalid distances set",Q.mode=Y9;break}if(Q.mode=I40,Z===R40)break $;case I40:Q.mode=P40;case P40:if(z>=6&&G>=258){if(J.next_out=V,J.avail_out=G,J.next_in=K,J.avail_in=z,Q.hold=F,Q.bits=q,nb6(J,U),V=J.next_out,X=J.output,G=J.avail_out,K=J.next_in,Y=J.input,z=J.avail_in,F=Q.hold,q=Q.bits,Q.mode===fW)Q.back=-1;break}Q.back=0;for(;;){if(N=Q.lencode[F&(1<<Q.lenbits)-1],w=N>>>24,O=N>>>16&255,L=N&65535,w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(O&&(O&240)===0){E=w,M=O,A=L;for(;;){if(N=Q.lencode[A+((F&(1<<E+M)-1)>>E)],w=N>>>24,O=N>>>16&255,L=N&65535,E+w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=E,q-=E,Q.back+=E}if(F>>>=w,q-=w,Q.back+=w,Q.length=L,O===0){Q.mode=Xg1;break}if(O&32){Q.back=-1,Q.mode=fW;break}if(O&64){J.msg="invalid literal/length code",Q.mode=Y9;break}Q.extra=O&15,Q.mode=Jg1;case Jg1:if(Q.extra){u=Q.extra;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}Q.length+=F&(1<<Q.extra)-1,F>>>=Q.extra,q-=Q.extra,Q.back+=Q.extra}Q.was=Q.length,Q.mode=Zg1;case Zg1:for(;;){if(N=Q.distcode[F&(1<<Q.distbits)-1],w=N>>>24,O=N>>>16&255,L=N&65535,w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if((O&240)===0){E=w,M=O,A=L;for(;;){if(N=Q.distcode[A+((F&(1<<E+M)-1)>>E)],w=N>>>24,O=N>>>16&255,L=N&65535,E+w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=E,q-=E,Q.back+=E}if(F>>>=w,q-=w,Q.back+=w,O&64){J.msg="invalid distance code",Q.mode=Y9;break}Q.offset=L,Q.extra=O&15,Q.mode=Qg1;case Qg1:if(Q.extra){u=Q.extra;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}Q.offset+=F&(1<<Q.extra)-1,F>>>=Q.extra,q-=Q.extra,Q.back+=Q.extra}if(Q.offset>Q.dmax){J.msg="invalid distance too far back",Q.mode=Y9;break}Q.mode=Yg1;case Yg1:if(G===0)break $;if(D=U-G,Q.offset>D){if(D=Q.offset-D,D>Q.whave){if(Q.sane){J.msg="invalid distance too far back",Q.mode=Y9;break}}if(D>Q.wnext)D-=Q.wnext,H=Q.wsize-D;else H=Q.wnext-D;if(D>Q.length)D=Q.length;B=Q.window}else B=X,H=V-Q.offset,D=Q.length;if(D>G)D=G;G-=D,Q.length-=D;do X[V++]=B[H++];while(--D);if(Q.length===0)Q.mode=P40;break;case Xg1:if(G===0)break $;X[V++]=Q.length,G--,Q.mode=P40;break;case kI0:if(Q.wrap){while(q<32){if(z===0)break $;z--,F|=Y[K++]<<q,q+=8}if(U-=G,J.total_out+=U,Q.total+=U,Q.wrap&4&&U)J.adler=Q.check=Q.flags?T7(Q.check,X,U,V-U):Jh(Q.check,X,U,V-U);if(U=G,Q.wrap&4&&(Q.flags?F:zg1(F))!==Q.check){J.msg="incorrect data check",Q.mode=Y9;break}F=0,q=0}Q.mode=Kg1;case Kg1:if(Q.wrap&&Q.flags){while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.wrap&4&&F!==(Q.total&4294967295)){J.msg="incorrect length check",Q.mode=Y9;break}F=0,q=0}Q.mode=Vg1;case Vg1:R=Jh6;break $;case Y9:R=fg1;break $;case bg1:return ug1;case hg1:default:return xX}if(J.next_out=V,J.avail_out=G,J.next_in=K,J.avail_in=z,Q.hold=F,Q.bits=q,Q.wsize||U!==J.avail_out&&Q.mode<Y9&&(Q.mode<kI0||Z!==hh1)){if(cg1(J,J.output,J.next_out,U-J.avail_out));}if(W-=J.avail_in,U-=J.avail_out,J.total_in+=W,J.total_out+=U,Q.total+=U,Q.wrap&4&&U)J.adler=Q.check=Q.flags?T7(Q.check,X,U,J.next_out-U):Jh(Q.check,X,U,J.next_out-U);if(J.data_type=Q.bits+(Q.last?64:0)+(Q.mode===fW?128:0)+(Q.mode===I40||Q.mode===SI0?256:0),(W===0&&U===0||Z===hh1)&&R===PE)R=Qh6;return R},Wh6=(J)=>{if(TE(J))return xX;let Z=J.state;if(Z.window)Z.window=null;return J.state=null,PE},Uh6=(J,Z)=>{if(TE(J))return xX;let Q=J.state;if((Q.wrap&2)===0)return xX;return Q.head=Z,Z.done=!1,PE},Dh6=(J,Z)=>{let Q=Z.length,Y,X,K;if(TE(J))return xX;if(Y=J.state,Y.wrap!==0&&Y.mode!==S40)return xX;if(Y.mode===S40){if(X=1,X=Jh(X,Z,Q,0),X!==Y.check)return fg1}if(K=cg1(J,Z,Q,Q),K)return Y.mode=bg1,ug1;return Y.havedict=1,PE},Hh6,Bh6,Nh6,wh6,Oh6,Lh6,Eh6,Mh6,Ah6,jh6="pako inflate (from Nodeca project)",bW,Ih6,lg1,Ph6,Ch6,Yh,xI0,fI0,Th6,Fg1,_h6,kh6,yh6,vh6,xh6,fh6,uh6,bh6,hh6,gh6,mh6,ph6,dh6,ch6,lh6,ih6,nh6,ah6,oh6,rh6,sh6,th6,eh6,$g6,ig1;var ng1=Y0(()=>{/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */sb=Xh+1+iI0,Wg1=2*sb+1,uI0=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),C40=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),qu6=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Bg1=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),uW=Array((sb+2)*2);IC(uW);ab=Array(AC*2);IC(ab);tb=Array(Wu6);IC(tb);eb=Array(Gu6-zu6+1);IC(eb);oI0=Array(iI0);IC(oI0);T40=Array(AC);IC(T40);Au6=Ou6,ju6=Rg1,Ru6=Eu6,Iu6=Mu6,Pu6=Lu6,Cu6={_tr_init:Au6,_tr_stored_block:ju6,_tr_flush_block:Ru6,_tr_tally:Iu6,_tr_align:Pu6},Jh=Tu6,Su6=new Uint32Array(_u6()),T7=ku6,RE={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},CE={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:yu6,_tr_stored_block:hI0,_tr_flush_block:vu6,_tr_tally:sH,_tr_align:xu6}=Cu6,{Z_NO_FLUSH:tH,Z_PARTIAL_FLUSH:fu6,Z_FULL_FLUSH:uu6,Z_FINISH:vX,Z_BLOCK:kh1,Z_OK:w$,Z_STREAM_END:yh1,Z_STREAM_ERROR:gG,Z_DATA_ERROR:bu6,Z_BUF_ERROR:PI0,Z_DEFAULT_COMPRESSION:hu6,Z_FILTERED:gu6,Z_HUFFMAN_ONLY:A40,Z_RLE:mu6,Z_FIXED:pu6,Z_DEFAULT_STRATEGY:du6,Z_UNKNOWN:cu6,Z_DEFLATED:k40}=CE,gI0=ou6+1+au6,tu6=2*gI0+1,mG=rH+i5+1,eH=Qb6;nb=[new bG(0,0,0,0,Pg1),new bG(4,4,8,4,CI0),new bG(4,5,16,8,CI0),new bG(4,6,32,32,CI0),new bG(4,4,16,16,EC),new bG(8,16,32,32,EC),new bG(8,16,128,128,EC),new bG(8,32,128,256,EC),new bG(32,128,258,1024,EC),new bG(32,258,258,4096,EC)];Ub6=Gb6,Db6=_g1,Hb6=Tg1,Bb6=Cg1,Nb6=zb6,wb6=Fb6,Ob6=qb6,Lb6=Wb6,ob={deflateInit:Ub6,deflateInit2:Db6,deflateReset:Hb6,deflateResetKeep:Bb6,deflateSetHeader:Nb6,deflate:wb6,deflateEnd:Ob6,deflateSetDictionary:Lb6,deflateInfo:Eb6},y40={assign:Ab6,flattenChunks:jb6};try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(J){Sg1=!1}Zh=new Uint8Array(256);for(let J=0;J<256;J++)Zh[J]=J>=252?6:J>=248?5:J>=240?4:J>=224?3:J>=192?2:1;Zh[254]=Zh[254]=1;Qh={string2buf:Rb6,buf2string:Pb6,utf8border:Cb6};kg1=Tb6,yg1=Object.prototype.toString,{Z_NO_FLUSH:_b6,Z_SYNC_FLUSH:Sb6,Z_FULL_FLUSH:kb6,Z_FINISH:yb6,Z_OK:_40,Z_STREAM_END:vb6,Z_DEFAULT_COMPRESSION:xb6,Z_DEFAULT_STRATEGY:fb6,Z_DEFLATED:ub6}=CE;Vh.prototype.push=function(J,Z){let Q=this.strm,Y=this.options.chunkSize,X,K;if(this.ended)return!1;if(Z===~~Z)K=Z;else K=Z===!0?yb6:_b6;if(typeof J==="string")Q.input=Qh.string2buf(J);else if(yg1.call(J)==="[object ArrayBuffer]")Q.input=new Uint8Array(J);else Q.input=J;Q.next_in=0,Q.avail_in=Q.input.length;for(;;){if(Q.avail_out===0)Q.output=new Uint8Array(Y),Q.next_out=0,Q.avail_out=Y;if((K===Sb6||K===kb6)&&Q.avail_out<=6){this.onData(Q.output.subarray(0,Q.next_out)),Q.avail_out=0;continue}if(X=ob.deflate(Q,K),X===vb6){if(Q.next_out>0)this.onData(Q.output.subarray(0,Q.next_out));return X=ob.deflateEnd(this.strm),this.onEnd(X),this.ended=!0,X===_40}if(Q.avail_out===0){this.onData(Q.output);continue}if(K>0&&Q.next_out>0){this.onData(Q.output.subarray(0,Q.next_out)),Q.avail_out=0;continue}if(Q.avail_in===0)break}return!0};Vh.prototype.onData=function(J){this.chunks.push(J)};Vh.prototype.onEnd=function(J){if(J===_40)this.result=y40.flattenChunks(this.chunks);this.chunks=[],this.err=J,this.msg=this.strm.msg};gb6=Vh,mb6=sI0,pb6=bb6,db6=hb6,cb6=CE,lb6={Deflate:gb6,deflate:mb6,deflateRaw:pb6,gzip:db6,constants:cb6},ab6=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),ob6=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),rb6=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),sb6=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),rb=tb6,{Z_FINISH:hh1,Z_BLOCK:$h6,Z_TREES:R40,Z_OK:PE,Z_STREAM_END:Jh6,Z_NEED_DICT:Zh6,Z_STREAM_ERROR:xX,Z_DATA_ERROR:fg1,Z_MEM_ERROR:ug1,Z_BUF_ERROR:Qh6,Z_DEFLATED:gh1}=CE,Vh6=Kh6;Hh6=mg1,Bh6=pg1,Nh6=gg1,wh6=Gh6,Oh6=dg1,Lh6=qh6,Eh6=Wh6,Mh6=Uh6,Ah6=Dh6,bW={inflateReset:Hh6,inflateReset2:Bh6,inflateResetKeep:Nh6,inflateInit:wh6,inflateInit2:Oh6,inflate:Lh6,inflateEnd:Eh6,inflateGetHeader:Mh6,inflateSetDictionary:Ah6,inflateInfo:jh6};Ih6=Rh6,lg1=Object.prototype.toString,{Z_NO_FLUSH:Ph6,Z_FINISH:Ch6,Z_OK:Yh,Z_STREAM_END:xI0,Z_NEED_DICT:fI0,Z_STREAM_ERROR:Th6,Z_DATA_ERROR:Fg1,Z_MEM_ERROR:_h6}=CE;zh.prototype.push=function(J,Z){let Q=this.strm,Y=this.options.chunkSize,X=this.options.dictionary,K,V,z;if(this.ended)return!1;if(Z===~~Z)V=Z;else V=Z===!0?Ch6:Ph6;if(lg1.call(J)==="[object ArrayBuffer]")Q.input=new Uint8Array(J);else Q.input=J;Q.next_in=0,Q.avail_in=Q.input.length;for(;;){if(Q.avail_out===0)Q.output=new Uint8Array(Y),Q.next_out=0,Q.avail_out=Y;if(K=bW.inflate(Q,V),K===fI0&&X){if(K=bW.inflateSetDictionary(Q,X),K===Yh)K=bW.inflate(Q,V);else if(K===Fg1)K=fI0}while(Q.avail_in>0&&K===xI0&&Q.state.wrap>0&&J[Q.next_in]!==0)bW.inflateReset(Q),K=bW.inflate(Q,V);switch(K){case Th6:case Fg1:case fI0:case _h6:return this.onEnd(K),this.ended=!0,!1}if(z=Q.avail_out,Q.next_out){if(Q.avail_out===0||K===xI0)if(this.options.to==="string"){let G=Qh.utf8border(Q.output,Q.next_out),F=Q.next_out-G,q=Qh.buf2string(Q.output,G);if(Q.next_out=F,Q.avail_out=Y-F,F)Q.output.set(Q.output.subarray(G,G+F),0);this.onData(q)}else this.onData(Q.output.length===Q.next_out?Q.output:Q.output.subarray(0,Q.next_out))}if(K===Yh&&z===0)continue;if(K===xI0)return K=bW.inflateEnd(this.strm),this.onEnd(K),this.ended=!0,!0;if(Q.avail_in===0)break}return!0};zh.prototype.onData=function(J){this.chunks.push(J)};zh.prototype.onEnd=function(J){if(J===Yh)if(this.options.to==="string")this.result=this.chunks.join("");else this.result=y40.flattenChunks(this.chunks);this.chunks=[],this.err=J,this.msg=this.strm.msg};kh6=zh,yh6=tI0,vh6=Sh6,xh6=tI0,fh6=CE,uh6={Inflate:kh6,inflate:yh6,inflateRaw:vh6,ungzip:xh6,constants:fh6},{Deflate:bh6,deflate:hh6,deflateRaw:gh6,gzip:mh6}=lb6,{Inflate:ph6,inflate:dh6,inflateRaw:ch6,ungzip:lh6}=uh6,ih6=bh6,nh6=hh6,ah6=gh6,oh6=mh6,rh6=ph6,sh6=dh6,th6=ch6,eh6=lh6,$g6=CE,ig1={Deflate:ih6,deflate:nh6,deflateRaw:ah6,gzip:oh6,Inflate:rh6,inflate:sh6,inflateRaw:th6,ungzip:eh6,constants:$g6}});function Jg6(J){if(J.proxy&&!process.env.HTTP_PROXY&&!process.env.http_proxy)process.env.HTTP_PROXY=J.proxy;if(J.proxy&&!process.env.HTTPS_PROXY&&!process.env.https_proxy)process.env.HTTPS_PROXY=J.proxy}function ag1(J){return J.config.pipe(q4(({settings:Z,secrets:Q})=>{return T4(async()=>{return await Q.getToken("apiKey",Z.url)!==void 0})}))}function $B(J,Z,Q){let Y=Q?`/threads/${Z}/${Q}`:`/threads/${Z}`;return new URL(Y,J)}async function f3(J,Z,Q){let Y=await Q.getLatest(Z?.signal??void 0),X=await rg1(J,Z,Y);return fetch(X)}async function og1(J,Z,Q){let Y=await rg1(Z,Q,J);return fetch(Y)}async function rg1(J,Z,Q){if(J.startsWith("http:")||J.startsWith("https:"))throw Error("input must be a path, not an absolute URL");if(!J.startsWith("/"))throw Error("pathAndQuery must start with /");let Y=Q.settings.url;if(!Y)throw Error("amp.url is not set");let X=await Q.secrets.getToken("apiKey",Y);Jg6({proxy:Q.settings.proxy});let K=new URL(J,Y);return new Request(K,{...Z,duplex:"half",headers:{"Content-Type":"application/json",...Z?.headers,...T2(),...X?{Authorization:`Bearer ${X}`}:{}}})}async function sg1(J,Z,Q,Y,X){let K=await J.get(Z);if(!K)throw Error(`Thread not found: ${Z}`);let V=await g6.shareThreadWithOperator({threadData:K,message:Y||void 0,ephemeralError:X||void 0},{config:Q});if(!V.ok)throw Error(`Failed to share thread: ${V.error.message}`)}async function x40(J,Z){let Q=await f3("/api/telemetry",{method:"POST",redirect:"manual",body:J},Z);if(!Q.ok){let Y=await Q.text(),X;try{X=JSON.parse(Y).error||`HTTP ${Q.status}`}catch{X=Y||`HTTP ${Q.status}`}throw Error(`Failed to submit telemetry: ${X}`)}}var O$=Y0(()=>{N1();ZJ();rJ()});function Qg6(J){if(new Blob([J]).size<=Zg6)return{body:J};return{body:ig1.gzip(J),headers:{"Content-Encoding":"gzip"}}}function Yg6(){return new Proxy({},{get:(J,Z)=>{return async(...Q)=>{let Y=Q.at(1),X=Q.at(0);if(!Y?.config)throw Error("Internal API client requires configService in options. Call with { config: configService }");let{body:K,headers:V={}}=Qg6(JSON.stringify({method:Z,params:X})),z=await f3("/api/internal?"+encodeURIComponent(Z),{method:"POST",body:K,headers:V,signal:Y?.signal},Y.config);if(!z.ok)throw Error(`API request for ${Z} failed: ${z.status}`);return await z.json()}}})}var Zg6=25600,g6;var rJ=Y0(()=>{ng1();O$();g6=Yg6()});function Xg6(J){return J.config.pipe(W1(({settings:Z,secrets:Q})=>({url:Z.url,proxy:Z.proxy,secrets:Q})),y4(cb),q4((Z)=>gP(600000).pipe(z5(void 0),pP(()=>T4(async(Q)=>{let Y=await g6.getUserInfo({},{signal:Q,config:J});if(Y.ok)return Y.result;if(Y.error&&Y.error.code==="auth-required")return null;throw I.error("getUserInfo failed",{error:Y.error}),Error(`getUserInfo error: ${Y.error.code}`)})))),W1((Z)=>{return Z instanceof Error?{error:{message:String(Z)}}:Z===CG?"pending":Z?{user:Z,features:Z.features,workspace:Z?.team,mysteriousMessage:Z?.mysteriousMessage}:{error:{message:"User not found"}}}),y4((Z,Q)=>cb(Z,Q)),c6({shouldCountRefs:!0}))}function eZ(J){let Z=tg1.get(J);if(Z)return Z;let Q=Xg6(J);return tg1.set(J,Q),Q}function m6(J){return Boolean(typeof J==="object"&&"user"in J&&J.user)}function hW(J){return typeof J==="object"&&"error"in J}var tg1;var fX=Y0(()=>{N1();g0();rJ();tg1=new WeakMap});function f40(J,Z,Q){if(J.startsWith("mcp__"))return Z.allowMcp??!1;if(J.startsWith("tb__")){if(!(Z.allowToolbox??!1))return!1;let Y="subagentType"in Z?Z.subagentType:void 0;if(Y&&Q){if(!Q.subagentTypes)return!1;return Q.subagentTypes.includes("all")||Q.subagentTypes.includes(Y)}return!0}return Z.includeTools.includes(J)}var eI0,eg1,Kg6,$P0,Vg6,zg6,Gg6,Fg6,JP0,f8,Y58;var uX=Y0(()=>{I7();eI0=["read_github","search_github","commit_search","diff","list_directory_github","list_repositories","glob_github"],eg1=["read_bitbucket_enterprise","search_bitbucket_enterprise","commit_search_bitbucket_enterprise","diff_bitbucket_enterprise","list_directory_bitbucket_enterprise","list_repositories_bitbucket_enterprise","glob_bitbucket_enterprise"],Kg6=["Grep","glob","Read"],$P0=["Read","Grep","glob","web_search","read_web_page","read_thread","find_thread"],Vg6=["Grep","glob","Read","Bash","edit_file","create_file","read_web_page","get_diagnostics","web_search","finder","skill","task_list"],zg6=["Read","Grep","glob","web_search","read_web_page","Bash"],Gg6=["Read","Grep","glob","web_search","read_web_page","Bash","eval_git_diff","post_explanation"],Fg6=["Read","Grep","glob","Bash"],JP0=["Read","Grep","glob","finder"],f8={finder:{key:"finder",displayName:"Finder",model:i3("CLAUDE_HAIKU_4_5"),includeTools:Kg6,allowMcp:!1,allowToolbox:!1},oracle:{key:"oracle",displayName:"Oracle",model:i3("GPT_5_4"),includeTools:$P0,allowMcp:!1,allowToolbox:!1},librarian:{key:"librarian",displayName:"Librarian",model:i3("CLAUDE_SONNET_4_6"),includeTools:eI0,allowMcp:!1,allowToolbox:!1},"task-subagent":{key:"task-subagent",displayName:"Task Subagent",model:void 0,includeTools:Vg6,allowMcp:!0,allowToolbox:!0},"code-review":{key:"code-review",displayName:"Code Review",model:i3("CLAUDE_SONNET_4_5"),includeTools:zg6,allowMcp:!1,allowToolbox:!1},"code-tour":{key:"code-tour",displayName:"Code Tour",model:i3("CLAUDE_OPUS_4_6"),includeTools:Gg6,allowMcp:!1,allowToolbox:!1},"codereview-check":{key:"codereview-check",displayName:"Codereview Check",model:i3("CLAUDE_HAIKU_4_5"),includeTools:Fg6,allowMcp:!1,allowToolbox:!1}},Y58=Object.keys(f8)});function $m1(J,Z){return new k0((Q)=>{let Y=setTimeout(X,Z);function X(){Q.error(Error(`Tool execution timed out after ${Z/1000} seconds`))}function K(){if(Y)clearTimeout(Y);Y=setTimeout(X,Z)}let V=J.subscribe({next:(z)=>{K(),Q.next(z)},error:(z)=>{if(Y)clearTimeout(Y),Y=null;Q.error(z)},complete:()=>{if(Y)clearTimeout(Y),Y=null;Q.complete()}});return()=>{if(Y)clearTimeout(Y),Y=null;V.unsubscribe()}})}var Jm1=Y0(()=>{N1()});function Qm1(J){return{tool:J,action:"allow"}}function qg6(J){if(!J||!("cmd"in J))return J;let{cmd:Z,...Q}=J;return{...Q,command:Z}}function Wg6(J){return J.flatMap((Z)=>{if(Z.tool!==i6)return[];return[{...Z,tool:JY,matches:qg6(Z.matches)}]})}var Zm1,TC;var u40=Y0(()=>{P4();Zm1=[{tool:"Bash",action:"ask",matches:{cmd:"*git*push*"}},{tool:"mcp__*",action:"allow"},{tool:z10,action:"allow"},{tool:"tb__*",action:"allow"},{tool:"Bash",matches:{cmd:"/^(.*\\s+)?(bazel|ibazel)\\s+.*\\/\\/[^\\s]*.*$/"},action:"allow"},{tool:"Bash",matches:{cmd:["ls","ls *","dir","dir *","cat *","head *","tail *","less *","more *","grep *","egrep *","fgrep *","tree","tree *","file *","wc *","pwd","stat *","du *","df *","ps *","top","htop","echo *","printenv *","id","which *","whereis *","date","cal *","uptime","free *","ping *","dig *","nslookup *","host *","netstat *","ss *","lsof *","ifconfig *","ip *","man *","info *","mkdir *","touch *","uname *","whoami","go version","go env *","go help *","cargo version","cargo --version","cargo help *","rustc --version","rustc --help","rustc --explain *","javac --version","javac -version","javac -help","javac --help","dotnet --info","dotnet --version","dotnet --help","dotnet help *","gcc --version","gcc -v","gcc --help","gcc -dumpversion","g++ --version","g++ -v","g++ --help","g++ -dumpversion","clang --version","clang --help","clang++ --version","clang++ --help","python -V","python --version","python -h","python --help","python3 -V","python3 --version","python3 -h","python3 --help","ruby -v","ruby --version","ruby -h","ruby --help","node -v","node --version","node -h","node --help","npm --help","npm --version","npm -v","npm help *","yarn --help","yarn --version","yarn -v","yarn help *","pnpm --help","pnpm --version","pnpm -v","pnpm help *","pytest -h","pytest --help","pytest --version","jest --help","jest --version","mocha --help","mocha --version","make --version","make --help","docker --version","docker --help","docker version","docker help *","git --version","git --help","git help *","git version"]},action:"allow"},{tool:"Bash",matches:{cmd:["go test *","go run *","go build *","go vet *","go fmt *","go list *","cargo test *","cargo run *","cargo build *","cargo check *","cargo fmt *","cargo tree *","make -n *","make --dry-run *","mvn test *","mvn verify *","mvn dependency:tree *","gradle tasks *","gradle dependencies *","gradle properties *","dotnet test *","dotnet list *","python -c *","ruby -e *","node -e *","npm list *","npm ls *","npm outdated *","npm test*","npm run*","npm view *","npm info *","yarn list*","yarn ls *","yarn info *","yarn test*","yarn run *","yarn why *","pnpm list*","pnpm ls *","pnpm outdated *","pnpm test*","pnpm run *","pytest --collect-only *","jest --listTests *","jest --showConfig *","mocha --list *","git status*","git show *","git diff*","git grep *","git branch *","git tag *","git remote -v *","git rev-parse --is-inside-work-tree *","git rev-parse --show-toplevel *","git config --list *","git log *"]},action:"allow"},{tool:"Bash",matches:{cmd:["./gradlew *","./mvnw *","./build.sh *","./configure *","cmake *","./node_modules/.bin/tsc *","./node_modules/.bin/eslint *","./node_modules/.bin/prettier *","prettier *","./node_modules/.bin/tailwindcss *","./node_modules/.bin/tsx *","./node_modules/.bin/vite *","bun *","tsx *","vite *"]},action:"allow"},{tool:"Bash",matches:{cmd:[".venv/bin/activate *",".venv/Scripts/activate *","source .venv/bin/activate *","source venv/bin/activate *","pip list *","pip show *","pip check *","pip freeze *","uv *","poetry show *","poetry check *","pipenv check *"]},action:"allow"},{tool:"Bash",matches:{cmd:["asdf list *","asdf current *","asdf which *","mise list *","mise current *","mise which *","mise use *","rbenv version *","rbenv versions *","rbenv which *","nvm list *","nvm current *","nvm which *"]},action:"allow"},{tool:"Bash",matches:{cmd:["./test*","./run_tests.sh *","./run_*_tests.sh *","vitest *","bundle exec rspec *","bundle exec rubocop *","rspec *","rubocop *","swiftlint *","clippy *","ruff *","black *","isort *","mypy *","flake8 *","bandit *","safety *","biome check *","biome format *"]},action:"allow"},{tool:"Bash",matches:{cmd:["rails server *","rails s *","bin/rails server *","bin/rails s *","flask run *","django-admin runserver *","python manage.py runserver *","uvicorn *","streamlit run *"]},action:"allow"},{tool:"Bash",matches:{cmd:["bin/rails db:status","bin/rails db:version","rails db:rollback *","rails db:status *","rails db:version *","alembic current *","alembic history *","bundle exec rails db:status","bundle exec rails db:version"]},action:"allow"},{tool:"Bash",matches:{cmd:["docker ps *","docker images *","docker logs *","docker inspect *","docker info *","docker stats *","docker system df *","docker system info *","podman ps *","podman images *","podman logs *","podman inspect *","podman info *"]},action:"allow"},{tool:"Bash",matches:{cmd:["aws --version *","aws configure list *","aws sts get-caller-identity *","aws s3 ls *","gcloud config list *","gcloud auth list *","gcloud projects list *","az account list *","az account show *","kubectl get *","kubectl describe *","kubectl logs *","kubectl version *","helm list *","helm status *","helm version *"]},action:"allow"},{tool:"Bash",matches:{cmd:["swift build *","swift test *","zig build *","zig build test*","kotlinc *","scalac *","javac *","javap *","clang *","jar *","sbt *","gradle *","bazel build *","bazel test *","bazel run *","mix *","lua *","ruby *","php *"]},action:"allow"},{tool:"Bash",matches:{cmd:["mkdir -p *","chmod +x *","dos2unix *","unix2dos *","ln -s *"]},action:"allow"},{tool:"Bash",matches:{cmd:["for *","while *","do *","done *","if *","then *","else *","elif *","fi *","case *","esac *","in *","function *","select *","until *","{ *","} *","[[ *","]] *"]},action:"ask"},{tool:"Bash",matches:{cmd:"/^find(?!.*(-delete|-exec|-execdir)).*$/"},action:"allow"},{tool:"Bash",matches:{cmd:"/^(echo|ls|pwd|date|whoami|id|uname)\\s.*[&|;].*\\s*(echo|ls|pwd|date|whoami|id|uname)($|\\s.*)/"},action:"allow"},{tool:"Bash",matches:{cmd:"/^(cat|grep|head|tail|less|more|find)\\s.*\\|\\s*(grep|head|tail|less|more|wc|sort|uniq)($|\\s.*)/"},action:"allow"},{tool:"Bash",matches:{cmd:"/^rm\\s+.*(-[rf].*-[rf]|-[rf]{2,}|--recursive.*--force|--force.*--recursive).*$/"},action:"ask"},{tool:"Bash",matches:{cmd:"/^find.*(-delete|-exec|-execdir).*$/"},action:"ask"},{tool:"Bash",matches:{cmd:"/^(ls|cat|grep|head|tail|file|stat)\\s+[^/]*$/"},action:"allow"},{tool:"Bash",matches:{cmd:"/(^|\\s)(\\/(?!dev\\/(null|zero|stdout|stderr|stdin))[^\\s]*|\\.\\.\\/)(?![^\\s]*\\.(log|txt|md|json|yml|yaml)$)/"},action:"ask"},{tool:"Bash",action:"ask"},Qm1("Glob")],TC=[...Zm1,...Wg6(Zm1),...bx1.map(Qm1)]});class Ym1{input;position=0;line=1;column=1;tokens=[];constructor(J){this.input=J}current(){return this.position<this.input.length?this.input[this.position]:""}peek(){return this.position+1<this.input.length?this.input[this.position+1]:""}advance(){let J=this.current();if(this.position++,J===`
119
+ `+Q)}function NE(J,Z,Q,Y,X,K){if(J.listenerCount("wsClientError")){let V=Error(X);Error.captureStackTrace(V,NE),J.emit("wsClientError",V,Q,Z)}else fb(Q,Y,X,K)}});var nb1={};J9(nb1,{default:()=>sx6,createWebSocketStream:()=>db1.default,WebSocketServer:()=>ib1.default,WebSocket:()=>aR0.default,Sender:()=>lb1.default,Receiver:()=>cb1.default});var db1,cb1,lb1,aR0,ib1,sx6;var ab1=Y0(()=>{db1=z4(xb1(),1),cb1=z4(hR0(),1),lb1=z4(mR0(),1),aR0=z4(F40(),1),ib1=z4(pb1(),1),sx6=aR0.default});class rb1{_status={};statusSubject=new Y4(this._status);messageSubject=new Y4(null);appendToPromptSubject=new Y4(null);projectConfig;queryPollTimeout;queryPollToken=0;querySource;ws;id=1;reconnectTimeoutId;reconnectStartTime;isReconnecting=!1;connectionSource="never-connected";pendingRequests=new Map;constructor(){this.statusSubject.subscribe((J)=>{if(J.ideName){let Z=t10(J.ideName);if(Z)VE(Z)}})}get status(){return new k0((J)=>{J.next(this._status);let Z=this.statusSubject.subscribe(J);return()=>Z.unsubscribe()})}sendStatus(J){this._status={...this._status,...J},this.statusSubject.next(this._status)}getIdeName(){return this._status.ideName||"ide"}get messages(){return new k0((J)=>{let Z=this.messageSubject.subscribe((Q)=>{if(Q!==null)J.next(Q)});return()=>Z.unsubscribe()})}get appendToPrompt(){return new k0((J)=>{let Z=this.appendToPromptSubject.subscribe((Q)=>{if(Q!==null)J.next(Q)});return()=>Z.unsubscribe()})}emitMessage(J){this.messageSubject.next(J)}emitAppendToPrompt(J){this.appendToPromptSubject.next(J)}async start(J,Z=!1,Q){let Y=Z||!this.projectConfig||this.projectConfig.port!==J.port||this.projectConfig.authToken!==J.authToken||this.projectConfig.connection!==J.connection||this.projectConfig.workspaceId!==J.workspaceId;if(this.projectConfig=J,this.sendStatus({enabled:!0}),this.connectionSource=Q??"auto-startup",Y&&this.ws)this.ws.close(),this.ws=void 0,this.clearPendingRequests();this.stopQueryPolling(),await this.tryConnect(this.projectConfig)}sendRequest=(J,Z)=>{let Q=this.ws;if(!Q)return Promise.resolve(void 0);if(!this.isWsOpen())return Promise.reject(Error("WebSocket is not open"));return new Promise((Y,X)=>{let K=`${this.id++}`,V={clientRequest:{id:K,[J]:Z}},z=setTimeout(()=>{this.pendingRequests.delete(K),X(Error(`Timeout after ${ob1}ms for request ${JSON.stringify(V,null,2)}`))},ob1);this.pendingRequests.set(K,{resolve:Y,reject:X,timeout:z,method:J}),Q.send(JSON.stringify(V))})};clearPendingRequests(){for(let[J,Z]of this.pendingRequests.entries())clearTimeout(Z.timeout),Z.reject(Error("WebSocket connection closed"));this.pendingRequests.clear()}handleResponse(J){if(!J?.id)return;let Z=this.pendingRequests.get(J.id);if(!Z)return;if(I.debug("ide-client: received response",{type:"response_received",source:this.getIdeName(),responseId:J?.id,hasError:!!J?.error}),clearTimeout(Z.timeout),this.pendingRequests.delete(J.id),J.error){Z.reject(Error(JSON.stringify(J.error)));return}let Q=J[Z.method];if(Q)Z.resolve(Q);else Z.reject(Error(`Invalid response for method ${Z.method}. Got ${JSON.stringify(J,null,2)}`))}async tryConnect(J){if(J.connection==="query"){let Y=this.resolveQuery(J);if(Y)this.startQueryPolling(J,Y);return}if(await this.isConnected()){I.debug("ide-client: already connected",{type:"already_connected",source:this.getIdeName()});return}if(this.clearReconnectTimeout(),this.ws?.close(),this.clearPendingRequests(),!J){this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE Not Connected"});return}this.sendStatus({ideName:J.ideName});let Q=new(await Jf6())(`ws://localhost:${J.port}?auth=${encodeURIComponent(J.authToken)}`);this.ws=Q,this.id=1,Q.onopen=async()=>{try{if(I.info("ide-client: connected",{type:"connected",source:this.getIdeName(),ideName:J.ideName,port:J.port}),this.connectionSource!=="never-connected")this.connectionSource="user-initiated";this.clearReconnectTimeout(),this.reconnectStartTime=void 0,this.isReconnecting=!1,this.sendStatus({connected:!0,authenticated:!0,connectionState:"connected",reconnectElapsedMs:void 0,errorMessage:void 0})}catch(Y){I.error("ide-client: connection error",Y),this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE Not Connected"})}},Q.onclose=(Y)=>{try{if(this.clearPendingRequests(),Y.code===1000&&Y.reason==="Authentication failed")this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE authentication failed - try restarting your IDE"});else I.warn("ide-client: disconnected",{code:Y.code,reason:Y.reason}),this.sendStatus({connected:!1,authenticated:!1,openFile:void 0,selections:void 0,errorMessage:"IDE Not Connected"});this.ws=void 0,this.scheduleReconnect()}catch(X){I.error("ide-client: disconnect error",X)}},Q.onerror=()=>{this.clearPendingRequests()},Q.onmessage=async(Y)=>{let X=Y.data.toString();try{let K=Du1.safeParse(JSON.parse(X));if(K.error){I.error("ide-client: failed to parse server message",y.prettifyError(K.error));return}if(K.data?.serverResponse)this.handleResponse(K.data.serverResponse);this.handleNotification(K.data?.serverNotification)}catch(K){I.error("ide-client: error handling server message",{error:K,data:X})}}}clearReconnectTimeout(){if(this.reconnectTimeoutId)clearTimeout(this.reconnectTimeoutId),this.reconnectTimeoutId=void 0}scheduleReconnect(){if(this.connectionSource==="never-connected")return;if(this.isReconnecting)return;if(!this.reconnectStartTime)this.reconnectStartTime=Date.now();let J=Date.now()-this.reconnectStartTime;if(J>=ex6){this.sendStatus({connectionState:"disconnected",reconnectElapsedMs:J});let Z=60000-J;if(Z>0)this.clearReconnectTimeout(),this.reconnectTimeoutId=setTimeout(()=>{let Q=Date.now()-(this.reconnectStartTime||Date.now());this.sendStatus({connectionState:"disconnected",reconnectElapsedMs:Q})},Z);return}this.isReconnecting=!0,this.sendStatus({connectionState:"reconnecting",reconnectElapsedMs:J,ideName:this.projectConfig?.ideName}),this.reconnectTimeoutId=setTimeout(()=>{this.executeReconnectAttempt().catch((Z)=>{I.error("ide-client: reconnect timer failed",Z)})},tx6)}async executeReconnectAttempt(){try{if(!this.projectConfig){I.debug("ide-client: no config available during reconnect, will retry");return}let J=await this.resolveActiveConfig(this.projectConfig);this.projectConfig=J,await this.tryConnect(J)}catch(J){I.error("ide-client: reconnect loop error",J)}finally{this.handleReconnectResult(await this.isConnected())}}async resolveActiveConfig(J){if(J.connection==="query"){let{config:Q}=await this.findQueryConfig(J);return Q??J}if(CW(J.pid))return J;return(await UE()).find((Q)=>Q.ideName===J.ideName&&Q.workspaceFolders.length===J.workspaceFolders.length&&Q.workspaceFolders.every((Y)=>J.workspaceFolders.includes(Y)))??J}handleReconnectResult(J){if(this.isReconnecting=!1,!J)this.scheduleReconnect();else this.clearReconnectTimeout(),this.reconnectStartTime=void 0,this.sendStatus({connectionState:"connected",reconnectElapsedMs:void 0})}startQueryPolling(J,Z){this.stopQueryPolling();let Q=++this.queryPollToken;this.querySource={config:J,query:Z},this.sendStatus({ideName:Z.ideName,workspace:J.workspaceFolders[0],connected:!0,authenticated:!0,connectionState:"connected",reconnectElapsedMs:void 0,errorMessage:void 0});let Y=async()=>{if(Q!==this.queryPollToken)return;let X;try{X=await Z.readWorkspaceState(J)}catch(K){I.warn("ide-client: query poll failed",{ideName:Z.ideName,error:K}),X=null}if(Q!==this.queryPollToken)return;if(!X){this.sendStatus({connected:!1,authenticated:!1,connectionState:"disconnected",errorMessage:`${Z.ideName} Not Connected`,openFile:void 0,selections:void 0,visibleFiles:void 0}),this.stopQueryPolling(),this.scheduleReconnect();return}this.sendStatus({connected:!0,authenticated:!0,connectionState:"connected",openFile:X.openFile,selections:X.selection?[X.selection]:void 0,visibleFiles:X.openFiles}),this.queryPollTimeout=setTimeout(()=>{Y()},$f6)};Y()}stopQueryPolling(){if(this.queryPollToken+=1,this.queryPollTimeout)clearTimeout(this.queryPollTimeout),this.queryPollTimeout=void 0}isWsOpen(){return this.ws?.readyState===1}async isConnected(){if(this.projectConfig?.connection==="query")return this._status.connected===!0;if(!this._status.authenticated)return!1;if(!this.isWsOpen())return!1;try{return(await this.sendRequest("ping",{message:"beepboop"}))?.message==="beepboop"}catch(J){return I.debug("isConnected ping failed",{error:J}),!1}}async requestDiagnosticsFromIDE(J){try{return await this.sendRequest("getDiagnostics",{path:J})}catch(Z){I.debug("ide-diags: failed to request diagnostics from IDE",{error:Z,path:J});return}}async openURIInIDE(J){if(this.projectConfig?.connection==="query")return this.querySource?.query.openURI(J);if(!this.isWsOpen())return;try{let Z=await this.sendRequest("openURI",{uri:J});if(!Z)return!1;return!!Z.success}catch(Z){return I.debug("ide-client: openURI request failed",{error:Z,uri:J}),!1}}handleNotification(J){if(!J)return;if(J.selectionDidChange)this.sendStatus({selections:J.selectionDidChange.selections,openFile:J.selectionDidChange.uri});else if(J.visibleFilesDidChange){let Z=J.visibleFilesDidChange.uris;this.sendStatus({visibleFiles:Z,...Z.length===0&&{openFile:void 0,selections:void 0}})}else if(J.pluginMetadata)this.sendStatus({pluginVersion:J.pluginMetadata.version,pluginDirectory:J.pluginMetadata.pluginDirectory});else if(J.userSentMessage)this.handleMessageFromIDE(J.userSentMessage.message);else if(J.appendToPrompt)this.handleAppendToPrompt(J.appendToPrompt.message)}async handleMessageFromIDE(J){I.debug("Received message from IDE",{message:J.slice(0,100)}),this.emitMessage(J)}handleAppendToPrompt(J){I.debug("Received appendToPrompt from IDE",{text:J.slice(0,100)}),this.emitAppendToPrompt(J)}async findQueryConfig(J){let Q=(J.workspaceId?J:(await this.listQueryConfigs()).find((X)=>X.workspaceFolders.every((K)=>J.workspaceFolders.includes(K))))??(await UE({includeAll:!0})).find((X)=>X.connection==="query"&&X.workspaceId===J.workspaceId);if(!Q)return{};let Y=this.resolveQuery(Q);if(!Y)return{config:Q};return{query:Y,config:Q}}async listQueryConfigs(){return(await Promise.all(qE.map(async(Z)=>{try{return await Z.listConfigs()}catch(Q){return I.debug("ide-client: failed to list query configs",{ideName:Z.ideName,error:Q}),[]}}))).flat()}resolveQuery(J){return qE.find((Z)=>Z.ideName===J.ideName)}selectConfig(J){this.projectConfig=J}getSelectedConfig(){return this.projectConfig}}async function Jf6(){if(typeof WebSocket<"u")return WebSocket;let{default:J}=await Promise.resolve().then(() => (ab1(),nb1));return J}var ob1=2000,tx6=1000,ex6=30000,$f6=1000,N$;var wE=Y0(()=>{N1();j9();g0();ZJ();r10();FE();e10();OR0();N$=new rb1});var rR0,sR0,tR0,ub;var W40=Y0(()=>{rR0=class rR0 extends Error{constructor(J="Unauthorized"){super(J);this.name="UnauthorizedError"}};sR0=class sR0 extends Error{constructor(J="OAuth callback timeout"){super(J);this.name="OAuthTimeoutError"}};tR0=class tR0 extends Error{serverName;constructor(J){super(`OAuth flow skipped for "${J}"`);this.serverName=J;this.name="OAuthSkippedError"}};ub=class ub extends Error{serverName;holderPid;constructor(J,Z){super(`OAuth flow already in progress for "${J}" (held by PID ${Z})`);this.serverName=J;this.holderPid=Z;this.name="OAuthFlowInProgressError"}}});import{randomBytes as qf6}from"node:crypto";import*as sZ from"node:fs/promises";import*as JI0 from"node:path";function $h1(J){return N40(J)}function Uf6(J){return J.replace(/[^a-zA-Z0-9_-]/g,"_")}function N40(J){return JI0.join(eb1,`${Uf6(J)}.lock`)}async function Df6(){await sZ.mkdir(eb1,{recursive:!0,mode:448})}function Hf6(J){try{return process.kill(J,0),!0}catch{return!1}}function $I0(J){if(Date.now()-J.timestamp>Wf6)return!0;let Q=R0("node:os").hostname();if(J.hostname===Q&&!Hf6(J.pid))return!0;return!1}async function D40(J){let Z=N40(J);try{let Q=await sZ.readFile(Z,"utf8"),Y=JSON.parse(Q);if(typeof Y.pid!=="number"||typeof Y.timestamp!=="number")return I.warn("Invalid lock file structure, treating as stale",{serverName:J,lockPath:Z}),null;return Y}catch(Q){if(Q?.code==="ENOENT")return null;return I.debug("Failed to read lock file",{serverName:J,error:Q.message}),null}}async function OE(J){await Df6();let Z=N40(J),Q=await D40(J);if(Q)if($I0(Q)){I.info("Removing stale OAuth lock",{serverName:J,stalePid:Q.pid,ageMs:Date.now()-Q.timestamp});try{await sZ.unlink(Z)}catch{}}else return I.debug("OAuth lock held by another process",{serverName:J,holderPid:Q.pid,ageMs:Date.now()-Q.timestamp}),{acquired:!1,holder:Q};let Y={pid:process.pid,timestamp:Date.now(),hostname:R0("node:os").hostname()},X=JSON.stringify(Y),K=`${Z}.${process.pid}.${qf6(4).toString("hex")}`;try{let V=await sZ.open(K,"wx",384);try{await V.writeFile(X),await V.sync()}finally{await V.close()}try{return await sZ.link(K,Z),await sZ.unlink(K).catch(()=>{}),I.info("Acquired OAuth lock",{serverName:J,pid:process.pid}),{acquired:!0}}catch(z){if(await sZ.unlink(K).catch(()=>{}),z?.code==="EEXIST"){let G=await D40(J);if(G&&!$I0(G))return I.debug("Lost OAuth lock race to another process",{serverName:J,winnerPid:G.pid}),{acquired:!1,holder:G};return OE(J)}throw z}}catch(V){if(await sZ.unlink(K).catch(()=>{}),V?.code==="EEXIST"){let z=await D40(J);if(z&&!$I0(z))return{acquired:!1,holder:z};return OE(J)}throw I.error("Failed to acquire OAuth lock",{serverName:J,error:V.message}),V}}async function NC(J){let Z=N40(J);try{let Q=await D40(J);if(!Q){I.debug("No lock to release",{serverName:J});return}if(Q.pid!==process.pid){I.warn("Cannot release lock owned by another process",{serverName:J,ownerPid:Q.pid,ourPid:process.pid});return}await sZ.unlink(Z),I.info("Released OAuth lock",{serverName:J,pid:process.pid})}catch(Q){if(Q?.code==="ENOENT")return;I.error("Failed to release OAuth lock",{serverName:J,error:Q.message})}}var eb1,Wf6=300000,H40=2000,B40=300000;var ZI0=Y0(()=>{TX();g0();eb1=JI0.join($C,"oauth","locks")});function Qh1(J){return J.replace(/ /g,"\\ ")}var Zh1=100;var XI0=()=>{};var hb=b((T68,Xh1)=>{var Yh1={DOT_LITERAL:"\\.",PLUS_LITERAL:"\\+",QMARK_LITERAL:"\\?",SLASH_LITERAL:"\\/",ONE_CHAR:"(?=.)",QMARK:"[^/]",END_ANCHOR:"(?:\\/|$)",DOTS_SLASH:"\\.{1,2}(?:\\/|$)",NO_DOT:"(?!\\.)",NO_DOTS:"(?!(?:^|\\/)\\.{1,2}(?:\\/|$))",NO_DOT_SLASH:"(?!\\.{0,1}(?:\\/|$))",NO_DOTS_SLASH:"(?!\\.{1,2}(?:\\/|$))",QMARK_NO_DOT:"[^.\\/]",STAR:"[^/]*?",START_ANCHOR:"(?:^|\\/)",SEP:"/"},Of6={...Yh1,SLASH_LITERAL:"[\\\\/]",QMARK:"[^\\\\/]",STAR:"[^\\\\/]*?",DOTS_SLASH:"\\.{1,2}(?:[\\\\/]|$)",NO_DOT:"(?!\\.)",NO_DOTS:"(?!(?:^|[\\\\/])\\.{1,2}(?:[\\\\/]|$))",NO_DOT_SLASH:"(?!\\.{0,1}(?:[\\\\/]|$))",NO_DOTS_SLASH:"(?!\\.{1,2}(?:[\\\\/]|$))",QMARK_NO_DOT:"[^.\\\\/]",START_ANCHOR:"(?:^|[\\\\/])",END_ANCHOR:"(?:[\\\\/]|$)",SEP:"\\"},Lf6={alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"\\x21-\\x7E",lower:"a-z",print:"\\x20-\\x7E ",punct:"\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",space:" \\t\\r\\n\\v\\f",upper:"A-Z",word:"A-Za-z0-9_",xdigit:"A-Fa-f0-9"};Xh1.exports={MAX_LENGTH:65536,POSIX_REGEX_SOURCE:Lf6,REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{__proto__:null,"***":"*","**/**":"**","**/**/**":"**"},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(J){return{"!":{type:"negate",open:"(?:(?!(?:",close:`))${J.STAR})`},"?":{type:"qmark",open:"(?:",close:")?"},"+":{type:"plus",open:"(?:",close:")+"},"*":{type:"star",open:"(?:",close:")*"},"@":{type:"at",open:"(?:",close:")"}}},globChars(J){return J===!0?Of6:Yh1}}});var gb=b((Rf6)=>{var{REGEX_BACKSLASH:Ef6,REGEX_REMOVE_BACKSLASH:Mf6,REGEX_SPECIAL_CHARS:Af6,REGEX_SPECIAL_CHARS_GLOBAL:jf6}=hb();Rf6.isObject=(J)=>J!==null&&typeof J==="object"&&!Array.isArray(J);Rf6.hasRegexChars=(J)=>Af6.test(J);Rf6.isRegexChar=(J)=>J.length===1&&Rf6.hasRegexChars(J);Rf6.escapeRegex=(J)=>J.replace(jf6,"\\$1");Rf6.toPosixSlashes=(J)=>J.replace(Ef6,"/");Rf6.isWindows=()=>{if(typeof navigator<"u"&&navigator.platform){let J=navigator.platform.toLowerCase();return J==="win32"||J==="windows"}if(typeof process<"u"&&process.platform)return process.platform==="win32";return!1};Rf6.removeBackslashes=(J)=>{return J.replace(Mf6,(Z)=>{return Z==="\\"?"":Z})};Rf6.escapeLast=(J,Z,Q)=>{let Y=J.lastIndexOf(Z,Q);if(Y===-1)return J;if(J[Y-1]==="\\")return Rf6.escapeLast(J,Z,Y-1);return`${J.slice(0,Y)}\\${J.slice(Y)}`};Rf6.removePrefix=(J,Z={})=>{let Q=J;if(Q.startsWith("./"))Q=Q.slice(2),Z.prefix="./";return Q};Rf6.wrapOutput=(J,Z={},Q={})=>{let Y=Q.contains?"":"^",X=Q.contains?"":"$",K=`${Y}(?:${J})${X}`;if(Z.negated===!0)K=`(?:^(?!${K}).*$)`;return K};Rf6.basename=(J,{windows:Z}={})=>{let Q=J.split(Z?/[\\/]/:"/"),Y=Q[Q.length-1];if(Y==="")return Q[Q.length-2];return Y}});var Hh1=b((S68,Dh1)=>{var zh1=gb(),{CHAR_ASTERISK:KI0,CHAR_AT:xf6,CHAR_BACKWARD_SLASH:mb,CHAR_COMMA:ff6,CHAR_DOT:VI0,CHAR_EXCLAMATION_MARK:zI0,CHAR_FORWARD_SLASH:Uh1,CHAR_LEFT_CURLY_BRACE:GI0,CHAR_LEFT_PARENTHESES:FI0,CHAR_LEFT_SQUARE_BRACKET:uf6,CHAR_PLUS:bf6,CHAR_QUESTION_MARK:Gh1,CHAR_RIGHT_CURLY_BRACE:hf6,CHAR_RIGHT_PARENTHESES:Fh1,CHAR_RIGHT_SQUARE_BRACKET:gf6}=hb(),qh1=(J)=>{return J===Uh1||J===mb},Wh1=(J)=>{if(J.isPrefix!==!0)J.depth=J.isGlobstar?1/0:1},mf6=(J,Z)=>{let Q=Z||{},Y=J.length-1,X=Q.parts===!0||Q.scanToEnd===!0,K=[],V=[],z=[],G=J,F=-1,q=0,W=0,U=!1,D=!1,H=!1,B=!1,N=!1,w=!1,O=!1,L=!1,E=!1,M=!1,A=0,j,R,_={value:"",depth:0,isGlob:!1},k=()=>F>=Y,u=()=>G.charCodeAt(F+1),m=()=>{return j=R,G.charCodeAt(++F)};while(F<Y){R=m();let d;if(R===mb){if(O=_.backslashes=!0,R=m(),R===GI0)w=!0;continue}if(w===!0||R===GI0){A++;while(k()!==!0&&(R=m())){if(R===mb){O=_.backslashes=!0,m();continue}if(R===GI0){A++;continue}if(w!==!0&&R===VI0&&(R=m())===VI0){if(U=_.isBrace=!0,H=_.isGlob=!0,M=!0,X===!0)continue;break}if(w!==!0&&R===ff6){if(U=_.isBrace=!0,H=_.isGlob=!0,M=!0,X===!0)continue;break}if(R===hf6){if(A--,A===0){w=!1,U=_.isBrace=!0,M=!0;break}}}if(X===!0)continue;break}if(R===Uh1){if(K.push(F),V.push(_),_={value:"",depth:0,isGlob:!1},M===!0)continue;if(j===VI0&&F===q+1){q+=2;continue}W=F+1;continue}if(Q.noext!==!0){if((R===bf6||R===xf6||R===KI0||R===Gh1||R===zI0)===!0&&u()===FI0){if(H=_.isGlob=!0,B=_.isExtglob=!0,M=!0,R===zI0&&F===q)E=!0;if(X===!0){while(k()!==!0&&(R=m())){if(R===mb){O=_.backslashes=!0,R=m();continue}if(R===Fh1){H=_.isGlob=!0,M=!0;break}}continue}break}}if(R===KI0){if(j===KI0)N=_.isGlobstar=!0;if(H=_.isGlob=!0,M=!0,X===!0)continue;break}if(R===Gh1){if(H=_.isGlob=!0,M=!0,X===!0)continue;break}if(R===uf6){while(k()!==!0&&(d=m())){if(d===mb){O=_.backslashes=!0,m();continue}if(d===gf6){D=_.isBracket=!0,H=_.isGlob=!0,M=!0;break}}if(X===!0)continue;break}if(Q.nonegate!==!0&&R===zI0&&F===q){L=_.negated=!0,q++;continue}if(Q.noparen!==!0&&R===FI0){if(H=_.isGlob=!0,X===!0){while(k()!==!0&&(R=m())){if(R===FI0){O=_.backslashes=!0,R=m();continue}if(R===Fh1){M=!0;break}}continue}break}if(H===!0){if(M=!0,X===!0)continue;break}}if(Q.noext===!0)B=!1,H=!1;let x=G,T="",f="";if(q>0)T=G.slice(0,q),G=G.slice(q),W-=q;if(x&&H===!0&&W>0)x=G.slice(0,W),f=G.slice(W);else if(H===!0)x="",f=G;else x=G;if(x&&x!==""&&x!=="/"&&x!==G){if(qh1(x.charCodeAt(x.length-1)))x=x.slice(0,-1)}if(Q.unescape===!0){if(f)f=zh1.removeBackslashes(f);if(x&&O===!0)x=zh1.removeBackslashes(x)}let p={prefix:T,input:J,start:q,base:x,glob:f,isBrace:U,isBracket:D,isGlob:H,isExtglob:B,isGlobstar:N,negated:L,negatedExtglob:E};if(Q.tokens===!0){if(p.maxDepth=0,!qh1(R))V.push(_);p.tokens=V}if(Q.parts===!0||Q.tokens===!0){let d;for(let h=0;h<K.length;h++){let n=d?d+1:q,c=K[h],s=J.slice(n,c);if(Q.tokens){if(h===0&&q!==0)V[h].isPrefix=!0,V[h].value=T;else V[h].value=s;Wh1(V[h]),p.maxDepth+=V[h].depth}if(h!==0||s!=="")z.push(s);d=c}if(d&&d+1<J.length){let h=J.slice(d+1);if(z.push(h),Q.tokens)V[V.length-1].value=h,Wh1(V[V.length-1]),p.maxDepth+=V[V.length-1].depth}p.slashes=K,p.parts=z}return p};Dh1.exports=mf6});var wh1=b((k68,Nh1)=>{var w40=hb(),uG=gb(),{MAX_LENGTH:O40,POSIX_REGEX_SOURCE:pf6,REGEX_NON_SPECIAL_CHARS:df6,REGEX_SPECIAL_CHARS_BACKREF:cf6,REPLACEMENTS:Bh1}=w40,lf6=(J,Z)=>{if(typeof Z.expandRange==="function")return Z.expandRange(...J,Z);J.sort();let Q=`[${J.join("-")}]`;try{new RegExp(Q)}catch(Y){return J.map((X)=>uG.escapeRegex(X)).join("..")}return Q},wC=(J,Z)=>{return`Missing ${J}: "${Z}" - use "\\\\${Z}" to match literal characters`},qI0=(J,Z)=>{if(typeof J!=="string")throw TypeError("Expected a string");J=Bh1[J]||J;let Q={...Z},Y=typeof Q.maxLength==="number"?Math.min(O40,Q.maxLength):O40,X=J.length;if(X>Y)throw SyntaxError(`Input length: ${X}, exceeds maximum allowed length: ${Y}`);let K={type:"bos",value:"",output:Q.prepend||""},V=[K],z=Q.capture?"":"?:",G=w40.globChars(Q.windows),F=w40.extglobChars(G),{DOT_LITERAL:q,PLUS_LITERAL:W,SLASH_LITERAL:U,ONE_CHAR:D,DOTS_SLASH:H,NO_DOT:B,NO_DOT_SLASH:N,NO_DOTS_SLASH:w,QMARK:O,QMARK_NO_DOT:L,STAR:E,START_ANCHOR:M}=G,A=(W0)=>{return`(${z}(?:(?!${M}${W0.dot?H:q}).)*?)`},j=Q.dot?"":B,R=Q.dot?O:L,_=Q.bash===!0?A(Q):E;if(Q.capture)_=`(${_})`;if(typeof Q.noext==="boolean")Q.noextglob=Q.noext;let k={input:J,index:-1,start:0,dot:Q.dot===!0,consumed:"",output:"",prefix:"",backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:V};J=uG.removePrefix(J,k),X=J.length;let u=[],m=[],x=[],T=K,f,p=()=>k.index===X-1,d=k.peek=(W0=1)=>J[k.index+W0],h=k.advance=()=>J[++k.index]||"",n=()=>J.slice(k.index+1),c=(W0="",i=0)=>{k.consumed+=W0,k.index+=i},s=(W0)=>{k.output+=W0.output!=null?W0.output:W0.value,c(W0.value)},F0=()=>{let W0=1;while(d()==="!"&&(d(2)!=="("||d(3)==="?"))h(),k.start++,W0++;if(W0%2===0)return!1;return k.negated=!0,k.start++,!0},a=(W0)=>{k[W0]++,x.push(W0)},U0=(W0)=>{k[W0]--,x.pop()},O0=(W0)=>{if(T.type==="globstar"){let i=k.braces>0&&(W0.type==="comma"||W0.type==="brace"),o=W0.extglob===!0||u.length&&(W0.type==="pipe"||W0.type==="paren");if(W0.type!=="slash"&&W0.type!=="paren"&&!i&&!o)k.output=k.output.slice(0,-T.output.length),T.type="star",T.value="*",T.output=_,k.output+=T.output}if(u.length&&W0.type!=="paren")u[u.length-1].inner+=W0.value;if(W0.value||W0.output)s(W0);if(T&&T.type==="text"&&W0.type==="text"){T.output=(T.output||T.value)+W0.value,T.value+=W0.value;return}W0.prev=T,V.push(W0),T=W0},G0=(W0,i)=>{let o={...F[i],conditions:1,inner:""};o.prev=T,o.parens=k.parens,o.output=k.output;let t=(Q.capture?"(":"")+o.open;a("parens"),O0({type:W0,value:i,output:k.output?"":D}),O0({type:"paren",extglob:!0,value:h(),output:t}),u.push(o)},e=(W0)=>{let i=W0.close+(Q.capture?")":""),o;if(W0.type==="negate"){let t=_;if(W0.inner&&W0.inner.length>1&&W0.inner.includes("/"))t=A(Q);if(t!==_||p()||/^\)+$/.test(n()))i=W0.close=`)$))${t}`;if(W0.inner.includes("*")&&(o=n())&&/^\.[^\\/.]+$/.test(o)){let Z0=qI0(o,{...Z,fastpaths:!1}).output;i=W0.close=`)${Z0})${t})`}if(W0.prev.type==="bos")k.negatedExtglob=!0}O0({type:"paren",extglob:!0,value:f,output:i}),U0("parens")};if(Q.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(J)){let W0=!1,i=J.replace(cf6,(o,t,Z0,X0,Q0,J0)=>{if(X0==="\\")return W0=!0,o;if(X0==="?"){if(t)return t+X0+(Q0?O.repeat(Q0.length):"");if(J0===0)return R+(Q0?O.repeat(Q0.length):"");return O.repeat(Z0.length)}if(X0===".")return q.repeat(Z0.length);if(X0==="*"){if(t)return t+X0+(Q0?_:"");return _}return t?o:`\\${o}`});if(W0===!0)if(Q.unescape===!0)i=i.replace(/\\/g,"");else i=i.replace(/\\+/g,(o)=>{return o.length%2===0?"\\\\":o?"\\":""});if(i===J&&Q.contains===!0)return k.output=J,k;return k.output=uG.wrapOutput(i,k,Z),k}while(!p()){if(f=h(),f==="\x00")continue;if(f==="\\"){let o=d();if(o==="/"&&Q.bash!==!0)continue;if(o==="."||o===";")continue;if(!o){f+="\\",O0({type:"text",value:f});continue}let t=/^\\+/.exec(n()),Z0=0;if(t&&t[0].length>2){if(Z0=t[0].length,k.index+=Z0,Z0%2!==0)f+="\\"}if(Q.unescape===!0)f=h();else f+=h();if(k.brackets===0){O0({type:"text",value:f});continue}}if(k.brackets>0&&(f!=="]"||T.value==="["||T.value==="[^")){if(Q.posix!==!1&&f===":"){let o=T.value.slice(1);if(o.includes("[")){if(T.posix=!0,o.includes(":")){let t=T.value.lastIndexOf("["),Z0=T.value.slice(0,t),X0=T.value.slice(t+2),Q0=pf6[X0];if(Q0){if(T.value=Z0+Q0,k.backtrack=!0,h(),!K.output&&V.indexOf(T)===1)K.output=D;continue}}}}if(f==="["&&d()!==":"||f==="-"&&d()==="]")f=`\\${f}`;if(f==="]"&&(T.value==="["||T.value==="[^"))f=`\\${f}`;if(Q.posix===!0&&f==="!"&&T.value==="[")f="^";T.value+=f,s({value:f});continue}if(k.quotes===1&&f!=='"'){f=uG.escapeRegex(f),T.value+=f,s({value:f});continue}if(f==='"'){if(k.quotes=k.quotes===1?0:1,Q.keepQuotes===!0)O0({type:"text",value:f});continue}if(f==="("){a("parens"),O0({type:"paren",value:f});continue}if(f===")"){if(k.parens===0&&Q.strictBrackets===!0)throw SyntaxError(wC("opening","("));let o=u[u.length-1];if(o&&k.parens===o.parens+1){e(u.pop());continue}O0({type:"paren",value:f,output:k.parens?")":"\\)"}),U0("parens");continue}if(f==="["){if(Q.nobracket===!0||!n().includes("]")){if(Q.nobracket!==!0&&Q.strictBrackets===!0)throw SyntaxError(wC("closing","]"));f=`\\${f}`}else a("brackets");O0({type:"bracket",value:f});continue}if(f==="]"){if(Q.nobracket===!0||T&&T.type==="bracket"&&T.value.length===1){O0({type:"text",value:f,output:`\\${f}`});continue}if(k.brackets===0){if(Q.strictBrackets===!0)throw SyntaxError(wC("opening","["));O0({type:"text",value:f,output:`\\${f}`});continue}U0("brackets");let o=T.value.slice(1);if(T.posix!==!0&&o[0]==="^"&&!o.includes("/"))f=`/${f}`;if(T.value+=f,s({value:f}),Q.literalBrackets===!1||uG.hasRegexChars(o))continue;let t=uG.escapeRegex(T.value);if(k.output=k.output.slice(0,-T.value.length),Q.literalBrackets===!0){k.output+=t,T.value=t;continue}T.value=`(${z}${t}|${T.value})`,k.output+=T.value;continue}if(f==="{"&&Q.nobrace!==!0){a("braces");let o={type:"brace",value:f,output:"(",outputIndex:k.output.length,tokensIndex:k.tokens.length};m.push(o),O0(o);continue}if(f==="}"){let o=m[m.length-1];if(Q.nobrace===!0||!o){O0({type:"text",value:f,output:f});continue}let t=")";if(o.dots===!0){let Z0=V.slice(),X0=[];for(let Q0=Z0.length-1;Q0>=0;Q0--){if(V.pop(),Z0[Q0].type==="brace")break;if(Z0[Q0].type!=="dots")X0.unshift(Z0[Q0].value)}t=lf6(X0,Q),k.backtrack=!0}if(o.comma!==!0&&o.dots!==!0){let Z0=k.output.slice(0,o.outputIndex),X0=k.tokens.slice(o.tokensIndex);o.value=o.output="\\{",f=t="\\}",k.output=Z0;for(let Q0 of X0)k.output+=Q0.output||Q0.value}O0({type:"brace",value:f,output:t}),U0("braces"),m.pop();continue}if(f==="|"){if(u.length>0)u[u.length-1].conditions++;O0({type:"text",value:f});continue}if(f===","){let o=f,t=m[m.length-1];if(t&&x[x.length-1]==="braces")t.comma=!0,o="|";O0({type:"comma",value:f,output:o});continue}if(f==="/"){if(T.type==="dot"&&k.index===k.start+1){k.start=k.index+1,k.consumed="",k.output="",V.pop(),T=K;continue}O0({type:"slash",value:f,output:U});continue}if(f==="."){if(k.braces>0&&T.type==="dot"){if(T.value===".")T.output=q;let o=m[m.length-1];T.type="dots",T.output+=f,T.value+=f,o.dots=!0;continue}if(k.braces+k.parens===0&&T.type!=="bos"&&T.type!=="slash"){O0({type:"text",value:f,output:q});continue}O0({type:"dot",value:f,output:q});continue}if(f==="?"){if(!(T&&T.value==="(")&&Q.noextglob!==!0&&d()==="("&&d(2)!=="?"){G0("qmark",f);continue}if(T&&T.type==="paren"){let t=d(),Z0=f;if(T.value==="("&&!/[!=<:]/.test(t)||t==="<"&&!/<([!=]|\w+>)/.test(n()))Z0=`\\${f}`;O0({type:"text",value:f,output:Z0});continue}if(Q.dot!==!0&&(T.type==="slash"||T.type==="bos")){O0({type:"qmark",value:f,output:L});continue}O0({type:"qmark",value:f,output:O});continue}if(f==="!"){if(Q.noextglob!==!0&&d()==="("){if(d(2)!=="?"||!/[!=<:]/.test(d(3))){G0("negate",f);continue}}if(Q.nonegate!==!0&&k.index===0){F0();continue}}if(f==="+"){if(Q.noextglob!==!0&&d()==="("&&d(2)!=="?"){G0("plus",f);continue}if(T&&T.value==="("||Q.regex===!1){O0({type:"plus",value:f,output:W});continue}if(T&&(T.type==="bracket"||T.type==="paren"||T.type==="brace")||k.parens>0){O0({type:"plus",value:f});continue}O0({type:"plus",value:W});continue}if(f==="@"){if(Q.noextglob!==!0&&d()==="("&&d(2)!=="?"){O0({type:"at",extglob:!0,value:f,output:""});continue}O0({type:"text",value:f});continue}if(f!=="*"){if(f==="$"||f==="^")f=`\\${f}`;let o=df6.exec(n());if(o)f+=o[0],k.index+=o[0].length;O0({type:"text",value:f});continue}if(T&&(T.type==="globstar"||T.star===!0)){T.type="star",T.star=!0,T.value+=f,T.output=_,k.backtrack=!0,k.globstar=!0,c(f);continue}let W0=n();if(Q.noextglob!==!0&&/^\([^?]/.test(W0)){G0("star",f);continue}if(T.type==="star"){if(Q.noglobstar===!0){c(f);continue}let o=T.prev,t=o.prev,Z0=o.type==="slash"||o.type==="bos",X0=t&&(t.type==="star"||t.type==="globstar");if(Q.bash===!0&&(!Z0||W0[0]&&W0[0]!=="/")){O0({type:"star",value:f,output:""});continue}let Q0=k.braces>0&&(o.type==="comma"||o.type==="brace"),J0=u.length&&(o.type==="pipe"||o.type==="paren");if(!Z0&&o.type!=="paren"&&!Q0&&!J0){O0({type:"star",value:f,output:""});continue}while(W0.slice(0,3)==="/**"){let V0=J[k.index+4];if(V0&&V0!=="/")break;W0=W0.slice(3),c("/**",3)}if(o.type==="bos"&&p()){T.type="globstar",T.value+=f,T.output=A(Q),k.output=T.output,k.globstar=!0,c(f);continue}if(o.type==="slash"&&o.prev.type!=="bos"&&!X0&&p()){k.output=k.output.slice(0,-(o.output+T.output).length),o.output=`(?:${o.output}`,T.type="globstar",T.output=A(Q)+(Q.strictSlashes?")":"|$)"),T.value+=f,k.globstar=!0,k.output+=o.output+T.output,c(f);continue}if(o.type==="slash"&&o.prev.type!=="bos"&&W0[0]==="/"){let V0=W0[1]!==void 0?"|$":"";k.output=k.output.slice(0,-(o.output+T.output).length),o.output=`(?:${o.output}`,T.type="globstar",T.output=`${A(Q)}${U}|${U}${V0})`,T.value+=f,k.output+=o.output+T.output,k.globstar=!0,c(f+h()),O0({type:"slash",value:"/",output:""});continue}if(o.type==="bos"&&W0[0]==="/"){T.type="globstar",T.value+=f,T.output=`(?:^|${U}|${A(Q)}${U})`,k.output=T.output,k.globstar=!0,c(f+h()),O0({type:"slash",value:"/",output:""});continue}k.output=k.output.slice(0,-T.output.length),T.type="globstar",T.output=A(Q),T.value+=f,k.output+=T.output,k.globstar=!0,c(f);continue}let i={type:"star",value:f,output:_};if(Q.bash===!0){if(i.output=".*?",T.type==="bos"||T.type==="slash")i.output=j+i.output;O0(i);continue}if(T&&(T.type==="bracket"||T.type==="paren")&&Q.regex===!0){i.output=f,O0(i);continue}if(k.index===k.start||T.type==="slash"||T.type==="dot"){if(T.type==="dot")k.output+=N,T.output+=N;else if(Q.dot===!0)k.output+=w,T.output+=w;else k.output+=j,T.output+=j;if(d()!=="*")k.output+=D,T.output+=D}O0(i)}while(k.brackets>0){if(Q.strictBrackets===!0)throw SyntaxError(wC("closing","]"));k.output=uG.escapeLast(k.output,"["),U0("brackets")}while(k.parens>0){if(Q.strictBrackets===!0)throw SyntaxError(wC("closing",")"));k.output=uG.escapeLast(k.output,"("),U0("parens")}while(k.braces>0){if(Q.strictBrackets===!0)throw SyntaxError(wC("closing","}"));k.output=uG.escapeLast(k.output,"{"),U0("braces")}if(Q.strictSlashes!==!0&&(T.type==="star"||T.type==="bracket"))O0({type:"maybe_slash",value:"",output:`${U}?`});if(k.backtrack===!0){k.output="";for(let W0 of k.tokens)if(k.output+=W0.output!=null?W0.output:W0.value,W0.suffix)k.output+=W0.suffix}return k};qI0.fastpaths=(J,Z)=>{let Q={...Z},Y=typeof Q.maxLength==="number"?Math.min(O40,Q.maxLength):O40,X=J.length;if(X>Y)throw SyntaxError(`Input length: ${X}, exceeds maximum allowed length: ${Y}`);J=Bh1[J]||J;let{DOT_LITERAL:K,SLASH_LITERAL:V,ONE_CHAR:z,DOTS_SLASH:G,NO_DOT:F,NO_DOTS:q,NO_DOTS_SLASH:W,STAR:U,START_ANCHOR:D}=w40.globChars(Q.windows),H=Q.dot?q:F,B=Q.dot?W:F,N=Q.capture?"":"?:",w={negated:!1,prefix:""},O=Q.bash===!0?".*?":U;if(Q.capture)O=`(${O})`;let L=(j)=>{if(j.noglobstar===!0)return O;return`(${N}(?:(?!${D}${j.dot?G:K}).)*?)`},E=(j)=>{switch(j){case"*":return`${H}${z}${O}`;case".*":return`${K}${z}${O}`;case"*.*":return`${H}${O}${K}${z}${O}`;case"*/*":return`${H}${O}${V}${z}${B}${O}`;case"**":return H+L(Q);case"**/*":return`(?:${H}${L(Q)}${V})?${B}${z}${O}`;case"**/*.*":return`(?:${H}${L(Q)}${V})?${B}${O}${K}${z}${O}`;case"**/.*":return`(?:${H}${L(Q)}${V})?${K}${z}${O}`;default:{let R=/^(.*?)\.(\w+)$/.exec(j);if(!R)return;let _=E(R[1]);if(!_)return;return _+K+R[2]}}},M=uG.removePrefix(J,w),A=E(M);if(A&&Q.strictSlashes!==!0)A+=`${V}?`;return A};Nh1.exports=qI0});var UI0=b((y68,Lh1)=>{var if6=Hh1(),WI0=wh1(),Oh1=gb(),nf6=hb(),af6=(J)=>J&&typeof J==="object"&&!Array.isArray(J),G2=(J,Z,Q=!1)=>{if(Array.isArray(J)){let q=J.map((U)=>G2(U,Z,Q));return(U)=>{for(let D of q){let H=D(U);if(H)return H}return!1}}let Y=af6(J)&&J.tokens&&J.input;if(J===""||typeof J!=="string"&&!Y)throw TypeError("Expected pattern to be a non-empty string");let X=Z||{},K=X.windows,V=Y?G2.compileRe(J,Z):G2.makeRe(J,Z,!1,!0),z=V.state;delete V.state;let G=()=>!1;if(X.ignore){let q={...Z,ignore:null,onMatch:null,onResult:null};G=G2(X.ignore,q,Q)}let F=(q,W=!1)=>{let{isMatch:U,match:D,output:H}=G2.test(q,V,Z,{glob:J,posix:K}),B={glob:J,state:z,regex:V,posix:K,input:q,output:H,match:D,isMatch:U};if(typeof X.onResult==="function")X.onResult(B);if(U===!1)return B.isMatch=!1,W?B:!1;if(G(q)){if(typeof X.onIgnore==="function")X.onIgnore(B);return B.isMatch=!1,W?B:!1}if(typeof X.onMatch==="function")X.onMatch(B);return W?B:!0};if(Q)F.state=z;return F};G2.test=(J,Z,Q,{glob:Y,posix:X}={})=>{if(typeof J!=="string")throw TypeError("Expected input to be a string");if(J==="")return{isMatch:!1,output:""};let K=Q||{},V=K.format||(X?Oh1.toPosixSlashes:null),z=J===Y,G=z&&V?V(J):J;if(z===!1)G=V?V(J):J,z=G===Y;if(z===!1||K.capture===!0)if(K.matchBase===!0||K.basename===!0)z=G2.matchBase(J,Z,Q,X);else z=Z.exec(G);return{isMatch:Boolean(z),match:z,output:G}};G2.matchBase=(J,Z,Q)=>{return(Z instanceof RegExp?Z:G2.makeRe(Z,Q)).test(Oh1.basename(J))};G2.isMatch=(J,Z,Q)=>G2(Z,Q)(J);G2.parse=(J,Z)=>{if(Array.isArray(J))return J.map((Q)=>G2.parse(Q,Z));return WI0(J,{...Z,fastpaths:!1})};G2.scan=(J,Z)=>if6(J,Z);G2.compileRe=(J,Z,Q=!1,Y=!1)=>{if(Q===!0)return J.output;let X=Z||{},K=X.contains?"":"^",V=X.contains?"":"$",z=`${K}(?:${J.output})${V}`;if(J&&J.negated===!0)z=`^(?!${z}).*$`;let G=G2.toRegex(z,Z);if(Y===!0)G.state=J;return G};G2.makeRe=(J,Z={},Q=!1,Y=!1)=>{if(!J||typeof J!=="string")throw TypeError("Expected a non-empty string");let X={negated:!1,fastpaths:!0};if(Z.fastpaths!==!1&&(J[0]==="."||J[0]==="*"))X.output=WI0.fastpaths(J,Z);if(!X.output)X=WI0(J,Z);return G2.compileRe(X,Z,Q,Y)};G2.toRegex=(J,Z)=>{try{let Q=Z||{};return new RegExp(J,Q.flags||(Q.nocase?"i":""))}catch(Q){if(Z&&Z.debug===!0)throw Q;return/$^/}};G2.constants=nf6;Lh1.exports=G2});var yW=b((v68,Ah1)=>{var Eh1=UI0(),of6=gb();function Mh1(J,Z,Q=!1){if(Z&&(Z.windows===null||Z.windows===void 0))Z={...Z,windows:of6.isWindows()};return Eh1(J,Z,Q)}Object.assign(Mh1,Eh1);Ah1.exports=Mh1});function BI0(J){let Z=J;if(Z.startsWith("~/")){let Q=process.env.HOME||process.env.USERPROFILE||"";Z=Z.replace("~/",`${Q}/`)}else if(Z==="~")Z=process.env.HOME||process.env.USERPROFILE||"";if(Z=Z.replace(/%([^%]+)%/g,(Q,Y)=>{return process.env[Y]||`%${Y}%`}),Z.includes("%USERPROFILE%")&&process.env.USERPROFILE)Z=Z.replace(/%USERPROFILE%/g,process.env.USERPROFILE);return X1.file(Z)}function DI0(J,Z){let Q=BI0(Z);if(Q.path.includes("*")){let Y=J.toString(),X=Q.path;if(!X.startsWith("file://")){if(!X.startsWith("/"))X=`/${X}`;X=`file://${X}`}let K=X.replace(/\./g,"\\.").replace(/\*\*/g,"§DOUBLESTAR§").replace(/\*/g,"[^/]*").replace(/§DOUBLESTAR§/g,".*");return new RegExp(`^${K}$`,"i").test(Y)}else return Q.toString().toLowerCase()===J.toString().toLowerCase()}function jh1(J,Z){return Z.some((Q)=>DI0(J,Q))}async function rf6(J,Z){try{return await Z.realpath(J)}catch{}let Q=[],Y=J;while(!0){let X=K1.dirname(Y);if(X.toString()===Y.toString())break;Q.unshift(K1.basename(Y)),Y=X;try{let V=await Z.realpath(Y);for(let z of Q)V=K1.joinPath(V,z);return V}catch{}}return J}async function sf6(J,Z,Q){try{let Y=await rf6(J,Z),K=[...["~/.config/AGENT.md"],...Q];for(let V of K)if(DI0(Y,V)||DI0(J,V))return null;for(let{key:V,pattern:z}of HI0)if(jh1(Y,z.patterns)||jh1(J,z.patterns))return{key:V,pattern:z};return null}catch{return null}}async function NI0(J,Z,Q){if(Q?.dangerouslyAllowAll??!1)return{requiresConsent:!1};try{let X=await sf6(J,Z,Q["guardedFiles.allowlist"]??[]);if(X)return{requiresConsent:!0,reason:`${X.pattern.description}`,toAllow:J.fsPath};return{requiresConsent:!1}}catch{return{requiresConsent:!0,reason:"Unable to resolve file path",toAllow:J.fsPath}}}var HI0;var L40=Y0(()=>{U4();HI0=[{key:"cursor-config",pattern:{description:"Cursor Configuration",patterns:["**/.cursor/**","~/.cursor/**","~/Library/Application Support/Cursor/**","~/.config/Cursor/**","%APPDATA%/Cursor/**"]}},{key:"windsurf-config",pattern:{description:"Windsurf Configuration",patterns:["**/.windsurf/**","~/.codeium/windsurf/**","~/Library/Application Support/Windsurf/**","~/.config/Windsurf/**","%APPDATA%/Windsurf/**","/Library/Application Support/Windsurf/**","/etc/windsurf/**","%ProgramData%/Windsurf/**"]}},{key:"antigravity-config",pattern:{description:"Antigravity Configuration",patterns:["~/.gemini/**"]}},{key:"jetbrains-config",pattern:{description:"JetBrains IDE Configuration",patterns:["~/Library/Application Support/JetBrains/**","~/.config/JetBrains/**","~/.local/share/JetBrains/**","%APPDATA%/JetBrains/**","%LOCALAPPDATA%/JetBrains/**"]}},{key:"jetbrains-idea-config",pattern:{description:"JetBrains IDE Project Configuration",patterns:["**/.idea/**"]}},{key:"neovim-config",pattern:{description:"Neovim Configuration",patterns:["~/.config/nvim/**","~/.local/share/nvim/**","~/.local/state/nvim/**"]}},{key:"amp-settings",pattern:{description:"Amp Configuration Files",patterns:["**/amp.json","**/.amp/**"]}},{key:"shell-configs",pattern:{description:"Shell Configuration Files",patterns:["~/.bashrc","~/.zshrc","~/.fishrc","~/.cshrc","~/.tcshrc"]}},{key:"ssh-keys",pattern:{description:"SSH Keys and Configuration",patterns:["**/.ssh/**","~/.ssh/**"]}},{key:"gnupg-keys",pattern:{description:"GnuPG Keys and Configuration",patterns:["**/.gnupg/**","~/.gnupg/**"]}},{key:"environment-files",pattern:{description:"Environment Variable Files",patterns:["**/.env","**/.env.*"]}},{key:"claude-config",pattern:{description:"Claude AI Configuration",patterns:["**/.claude/**","~/.claude/**"]}},{key:"codex-config",pattern:{description:"Codex Configuration",patterns:["**/.codex/**","~/.codex/**"]}},{key:"git-internals",pattern:{description:"Git Internal Files",patterns:["**/.git/**"]}},{key:"kubernetes-config",pattern:{description:"Kubernetes Configuration",patterns:["**/.kube/**","~/.kube/**"]}},{key:"cache-directories",pattern:{description:"Cache Directories",patterns:["**/.cache/**","~/.cache/**"]}},{key:"windows-appdata",pattern:{description:"Windows Application Data",patterns:["%APPDATA%/**"]}},{key:"windows-system-directories",pattern:{description:"Windows System Directories",patterns:["%WINDIR%/**","%SYSTEMROOT%/**","%ProgramFiles%/**","%ProgramFiles(x86)%/**","%ProgramData%/**"]}},{key:"sqlite3-files",pattern:{description:"SQLite Database Files",patterns:["**/*.db","**/*.sqlite","**/*.sqlite3"]}},{key:"common-configuration-patterns",pattern:{description:"Configuration Directories",patterns:["~/.*","~/.*/**","~/.config/**","~/Library/**","~/Library/Preferences/**"]}},{key:"macos-applications",pattern:{description:"macOS Applications",patterns:["/Applications/**","~/Applications/**"]}},{key:"macos-system-library",pattern:{description:"macOS System Library",patterns:["/Library/**"]}},{key:"unix-system-directories",pattern:{description:"Unix System Directories",patterns:["/usr/**","/bin/**","/sbin/**","/lib/**","/lib64/**","/boot/**"]}},{key:"system-config-directories",pattern:{description:"System Configuration and State",patterns:["/private/etc/**","/etc/**","/private/var/**","/var/**"]}},{key:"opt-directory",pattern:{description:"Optional Software Installs (/opt, e.g., Homebrew)",patterns:["/opt/**"]}}]});function tf6(){if(vW.size===0)return;I.info("Killing all child processes");for(let J of vW)wI0(J);vW.clear(),I.info("All child processes killed")}function wI0(J){if(!J.pid){try{J.kill("SIGKILL")}catch(Z){I.error("Failed to kill process without PID",Z)}return}if(pb.has(J.pid)){I.debug(`Process ${J.pid} already being killed, skipping`);return}pb.add(J.pid);try{if(process.platform==="win32"){let{spawn:Z}=R0("node:child_process"),Q=Z("taskkill",["/F","/T","/PID",J.pid.toString()],{stdio:"ignore"});Q.on("error",(Y)=>{I.error(`Failed to kill Windows process tree ${J.pid}`,Y);try{J.kill("SIGKILL")}catch(X){I.error(`Fallback kill also failed for ${J.pid}`,X)}}),Q.on("exit",()=>{pb.delete(J.pid)})}else{try{process.kill(J.pid,0),process.kill(-J.pid,"SIGKILL")}catch(Z){I.debug(`Process ${J.pid} no longer exists, skipping kill`)}pb.delete(J.pid)}}catch(Z){I.error(`Failed to kill process ${J.pid}`,Z),pb.delete(J.pid)}}function OI0(J){wI0(J),vW.delete(J)}function Rh1(J){vW.add(J)}function ef6(J){let Z={...J,detached:process.platform!=="win32",env:{...process.env,...J?.env||{},NONINTERACTIVE:"1",DEBIAN_FRONTEND:"noninteractive"}};if(!Z.stdio)Z.stdio=["pipe","pipe","pipe"];return Z}function LI0(...J){return new k0((Z)=>{let Q=!1,Y,X=!1;return(async()=>{try{let{spawn:V}=await import("node:child_process");if(Q)return;Y=V(J[0],J[1],ef6(J[2])),vW.add(Y),Y.on("spawn",()=>{Z.next({type:"spawn",pid:Y?.pid,process:Y})}),Y.stdout?.on("data",(z)=>{if(Q||X)return;Z.next({type:"data",stream:"stdout",chunk:Buffer.isBuffer(z)?z:Buffer.from(String(z)),pid:Y?.pid,process:Y})}),Y.stderr?.on("data",(z)=>{if(Q||X)return;Z.next({type:"data",stream:"stderr",chunk:Buffer.isBuffer(z)?z:Buffer.from(String(z)),pid:Y?.pid,process:Y})}),Y.on("exit",(z)=>{if(Q||X)return;Z.next({type:"exit",exitCode:z})}),Y.on("close",(z)=>{if(Q)return;if(X)return;if(X=!0,Z.next({type:"close",exitCode:z}),Z.complete(),Y)vW.delete(Y)}),Y.on("error",(z)=>{if(Q||X)return;if(X=!0,Z.error(z),Y)vW.delete(Y)})}catch(V){if(Q)return;Z.error(V)}})(),()=>{if(Q=!0,Y&&!X)wI0(Y),vW.delete(Y)}})}function xW(...J){return new k0((Z)=>{let Q={stdout:"",stderr:"",combinedOutput:"",exitCode:null,exited:!1},Y=LI0(...J).subscribe({next:(X)=>{switch(X.type){case"spawn":Q.pid=X.pid,Q.process=X.process,Z.next({...Q,process:X.process});break;case"data":{let K=X.chunk.toString();if(X.stream==="stdout")Q.stdout+=K;else Q.stderr+=K;Q.combinedOutput+=K,Q.lastData=X.chunk,Z.next({...Q,process:X.process??Q.process});break}case"exit":Q.exitCode=X.exitCode??-1,Q.exited=!0;break;case"close":if(Q.exitCode===null)Q.exitCode=X.exitCode??-1;Q.exited=!0,Q.lastData=void 0,Z.next({...Q,process:Q.process}),Z.complete();break}},error:(X)=>Z.error(X)});return()=>Y.unsubscribe()})}function E40(J){if(typeof J!=="string")throw Error("arg is not a string");if(J.startsWith("-"))throw Error("arg is not safe")}function aH(J){if(!J)throw Error("tool requires a working directory");if(J.scheme!=="file")throw Error(`tool requires a dir with a file: URI (got ${JSON.stringify(J.scheme)})`)}var vW,pb;var RV=Y0(()=>{N1();g0();vW=new Set,pb=new Set;if(typeof process<"u")process.on("exit",()=>{tf6()})});function EE(J,Z){if(Z==="")return!1;let Q=J.toLowerCase(),Y=Z.toLowerCase();if(Y.length===1){if(Y==="*")return!0;return Y===Q}if(Q===Y)return!0;if(Y.includes("*")||Y.includes("?")||Y.includes("[")||Y.includes("{"))try{return Ih1.default(Y,{dot:!0})(Q)}catch(X){return!1}return!1}function EI0(J,Z){let Q=Z.split("."),Y=J;for(let X of Q){if(Y===null||Y===void 0)return;if(Array.isArray(Y)){let K=parseInt(X,10);if(isNaN(K)||K<0||K>=Y.length)return;Y=Y[K]}else if(typeof Y==="object")Y=Y[X];else return}return Y}function $u6(J,Z,Q,Y){if(!EE(Z,J.tool))return!1;if(J.context&&J.context!==Y)return!1;if(!J.matches||Object.keys(J.matches).length===0)return!0;return Object.entries(J.matches).every(([X,K])=>{if(K===void 0){if(X.includes("."))return EI0(Q,X)===void 0;return X in Q&&Q[X]===void 0}let V=X.includes(".")?EI0(Q,X):Q[X];return M40(V,K)})}async function Ju6(J,Z,Q,Y,X,K){if(J.action!=="delegate"){if(J.action==="reject"&&J.message)return{action:J.action,matchedEntry:J,error:J.message};return{action:J.action,matchedEntry:J}}if(!Q||!J.to)return{action:null,matchedEntry:J,error:"No spawn function provided"};try{let V=await Zu6(J.to,Z,Q,Y,X,K);return Qu6(V,J)}catch(V){return{action:"reject",error:V instanceof Error?V.message:"Unknown error",matchedEntry:J}}}async function Zu6(J,Z,Q,Y,X,K){let V={AGENT:"amp"};if(Y)V.AMP_THREAD_ID=Y;if(X)V.AGENT_TOOL_NAME=X;if(K)V.AGENT_TOOL_USE_ID=K;let G=J.includes("~")||J.includes("%")?BI0(J).path:J,q=Q(G,[],{env:V});return new Promise((W,U)=>{let D;q.subscribe({next:(H)=>{if(typeof H==="object"&&H!==null&&"status"in H&&H.status==="error"){U(Error("Delegate command timed out after 10 seconds"));return}if(H.process&&!H.exited)H.process.stdin?.write(JSON.stringify(Z)),H.process.stdin?.end();D=H},complete:()=>{if(D?.exited)W({exitCode:D.exitCode??-1,stdout:D.stdout,stderr:D.stderr});else U(Error("Process did not exit properly"))},error:(H)=>{U(H)}})})}function Qu6({exitCode:J,stderr:Z},Q){switch(J){case 0:return{action:"allow",matchedEntry:Q};case 1:return{action:"ask",matchedEntry:Q};default:return{action:"reject",matchedEntry:Q,error:Z}}}async function OC(J,Z,Q,Y,X,K,V,z){let G=0;for(let F of Q)try{if(!$u6(F,J,Z,Y)){G=G+1;continue}let q=await Ju6(F,Z,X,K,J,z);if(q.matchIndex=G,V)q.source=V;return q}catch(q){return{action:null,error:q instanceof Error?q.message:"Unknown error"}}return{action:null}}function M40(J,Z){if(typeof Z==="string"){if(typeof J!=="string")return!1;return Xu6(J,Z)}if(Array.isArray(Z))return Z.some((Q)=>{if(typeof Q==="string")return typeof J==="string"&&MI0(J,Q);return J===Q});if(typeof Z==="object"&&Z!==null)return Yu6(J,Z);return J===Z}function Yu6(J,Z){if(Object.keys(Z).length===0)return typeof J==="object"&&J!==null;if(typeof J!=="object"||J===null)return!1;for(let[Q,Y]of Object.entries(Z)){let X=EI0(J,Q);if(!M40(X,Y))return!1}return!0}function Xu6(J,Z){if(typeof Z==="string")return MI0(J,Z);if(Array.isArray(Z))return Z.some((Q)=>typeof Q==="string"&&MI0(J,Q));return!1}function MI0(J,Z){if(Z.length>=3&&Z.startsWith("/")&&Z.endsWith("/"))try{let X=Z.slice(1,-1);return new RegExp(X,"m").test(J)}catch(X){throw Error(`Invalid regex pattern: ${Z}`)}if(Z==="*")return!0;if(!Z.includes("*"))return J===Z;let Q=Z.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(`^${Q}$`,"m").test(J)}var Ih1,db;var LC=Y0(()=>{L40();RV();Ih1=z4(yW(),1),db=xW});function cb(J,Z){if(J===Z)return!0;if(J==null||Z==null||typeof J!=="object"||typeof Z!=="object")return!1;let Q=Array.isArray(J),Y=Array.isArray(Z);if(Q!==Y)return!1;if(Q&&Y)return J.length===Z.length&&J.every((K,V)=>cb(K,Z[V]));let X=new Set([...Object.keys(J),...Object.keys(Z)]);for(let K of X)if(!cb(J[K],Z[K]))return!1;return!0}function IC(J){let Z=J.length;while(--Z>=0)J[Z]=0}function jI0(J,Z,Q,Y,X){this.static_tree=J,this.extra_bits=Z,this.extra_base=Q,this.elems=Y,this.max_length=X,this.has_stree=J&&J.length}function RI0(J,Z){this.dyn_tree=J,this.max_code=0,this.stat_desc=Z}function bG(J,Z,Q,Y,X){this.good_length=J,this.max_lazy=Z,this.nice_length=Q,this.max_chain=Y,this.func=X}function Vb6(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=k40,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(tu6*2),this.dyn_dtree=new Uint16Array((2*ru6+1)*2),this.bl_tree=new Uint16Array((2*su6+1)*2),oH(this.dyn_ltree),oH(this.dyn_dtree),oH(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(eu6+1),this.heap=new Uint16Array(2*gI0+1),oH(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*gI0+1),oH(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Tb6(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function Vh(J){this.options=y40.assign({level:xb6,method:ub6,chunkSize:16384,windowBits:15,memLevel:8,strategy:fb6},J||{});let Z=this.options;if(Z.raw&&Z.windowBits>0)Z.windowBits=-Z.windowBits;else if(Z.gzip&&Z.windowBits>0&&Z.windowBits<16)Z.windowBits+=16;this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new kg1,this.strm.avail_out=0;let Q=ob.deflateInit2(this.strm,Z.level,Z.method,Z.windowBits,Z.memLevel,Z.strategy);if(Q!==_40)throw Error(RE[Q]);if(Z.header)ob.deflateSetHeader(this.strm,Z.header);if(Z.dictionary){let Y;if(typeof Z.dictionary==="string")Y=Qh.string2buf(Z.dictionary);else if(yg1.call(Z.dictionary)==="[object ArrayBuffer]")Y=new Uint8Array(Z.dictionary);else Y=Z.dictionary;if(Q=ob.deflateSetDictionary(this.strm,Y),Q!==_40)throw Error(RE[Q]);this._dict_set=!0}}function sI0(J,Z){let Q=new Vh(Z);if(Q.push(J,!0),Q.err)throw Q.msg||RE[Q.err];return Q.result}function bb6(J,Z){return Z=Z||{},Z.raw=!0,sI0(J,Z)}function hb6(J,Z){return Z=Z||{},Z.gzip=!0,sI0(J,Z)}function zh6(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Rh6(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}function zh(J){this.options=y40.assign({chunkSize:65536,windowBits:15,to:""},J||{});let Z=this.options;if(Z.raw&&Z.windowBits>=0&&Z.windowBits<16){if(Z.windowBits=-Z.windowBits,Z.windowBits===0)Z.windowBits=-15}if(Z.windowBits>=0&&Z.windowBits<16&&!(J&&J.windowBits))Z.windowBits+=32;if(Z.windowBits>15&&Z.windowBits<48){if((Z.windowBits&15)===0)Z.windowBits|=15}this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new kg1,this.strm.avail_out=0;let Q=bW.inflateInit2(this.strm,Z.windowBits);if(Q!==Yh)throw Error(RE[Q]);if(this.header=new Ih6,bW.inflateGetHeader(this.strm,this.header),Z.dictionary){if(typeof Z.dictionary==="string")Z.dictionary=Qh.string2buf(Z.dictionary);else if(lg1.call(Z.dictionary)==="[object ArrayBuffer]")Z.dictionary=new Uint8Array(Z.dictionary);if(Z.raw){if(Q=bW.inflateSetDictionary(this.strm,Z.dictionary),Q!==Yh)throw Error(RE[Q])}}}function tI0(J,Z){let Q=new zh(Z);if(Q.push(J),Q.err)throw Q.msg||RE[Q.err];return Q.result}function Sh6(J,Z){return Z=Z||{},Z.raw=!0,tI0(J,Z)}var Ku6=0,qg1=1,Vu6=2,zu6=3,Gu6=258,iI0=29,Xh=256,sb,AC=30,nI0=19,Wg1,ME=15,AI0=16,Fu6=7,aI0=256,Ug1=16,Dg1=17,Hg1=18,uI0,C40,qu6,Bg1,Wu6=512,uW,ab,tb,eb,oI0,T40,Ng1,wg1,Og1,Lg1=(J)=>{return J<256?tb[J]:tb[256+(J>>>7)]},$h=(J,Z)=>{J.pending_buf[J.pending++]=Z&255,J.pending_buf[J.pending++]=Z>>>8&255},tZ=(J,Z,Q)=>{if(J.bi_valid>AI0-Q)J.bi_buf|=Z<<J.bi_valid&65535,$h(J,J.bi_buf),J.bi_buf=Z>>AI0-J.bi_valid,J.bi_valid+=Q-AI0;else J.bi_buf|=Z<<J.bi_valid&65535,J.bi_valid+=Q},hG=(J,Z,Q)=>{tZ(J,Q[Z*2],Q[Z*2+1])},Eg1=(J,Z)=>{let Q=0;do Q|=J&1,J>>>=1,Q<<=1;while(--Z>0);return Q>>>1},Uu6=(J)=>{if(J.bi_valid===16)$h(J,J.bi_buf),J.bi_buf=0,J.bi_valid=0;else if(J.bi_valid>=8)J.pending_buf[J.pending++]=J.bi_buf&255,J.bi_buf>>=8,J.bi_valid-=8},Du6=(J,Z)=>{let{dyn_tree:Q,max_code:Y}=Z,X=Z.stat_desc.static_tree,K=Z.stat_desc.has_stree,V=Z.stat_desc.extra_bits,z=Z.stat_desc.extra_base,G=Z.stat_desc.max_length,F,q,W,U,D,H,B=0;for(U=0;U<=ME;U++)J.bl_count[U]=0;Q[J.heap[J.heap_max]*2+1]=0;for(F=J.heap_max+1;F<Wg1;F++){if(q=J.heap[F],U=Q[Q[q*2+1]*2+1]+1,U>G)U=G,B++;if(Q[q*2+1]=U,q>Y)continue;if(J.bl_count[U]++,D=0,q>=z)D=V[q-z];if(H=Q[q*2],J.opt_len+=H*(U+D),K)J.static_len+=H*(X[q*2+1]+D)}if(B===0)return;do{U=G-1;while(J.bl_count[U]===0)U--;J.bl_count[U]--,J.bl_count[U+1]+=2,J.bl_count[G]--,B-=2}while(B>0);for(U=G;U!==0;U--){q=J.bl_count[U];while(q!==0){if(W=J.heap[--F],W>Y)continue;if(Q[W*2+1]!==U)J.opt_len+=(U-Q[W*2+1])*Q[W*2],Q[W*2+1]=U;q--}}},Mg1=(J,Z,Q)=>{let Y=Array(ME+1),X=0,K,V;for(K=1;K<=ME;K++)X=X+Q[K-1]<<1,Y[K]=X;for(V=0;V<=Z;V++){let z=J[V*2+1];if(z===0)continue;J[V*2]=Eg1(Y[z]++,z)}},Hu6=()=>{let J,Z,Q,Y,X,K=Array(ME+1);Q=0;for(Y=0;Y<iI0-1;Y++){oI0[Y]=Q;for(J=0;J<1<<uI0[Y];J++)eb[Q++]=Y}eb[Q-1]=Y,X=0;for(Y=0;Y<16;Y++){T40[Y]=X;for(J=0;J<1<<C40[Y];J++)tb[X++]=Y}X>>=7;for(;Y<AC;Y++){T40[Y]=X<<7;for(J=0;J<1<<C40[Y]-7;J++)tb[256+X++]=Y}for(Z=0;Z<=ME;Z++)K[Z]=0;J=0;while(J<=143)uW[J*2+1]=8,J++,K[8]++;while(J<=255)uW[J*2+1]=9,J++,K[9]++;while(J<=279)uW[J*2+1]=7,J++,K[7]++;while(J<=287)uW[J*2+1]=8,J++,K[8]++;Mg1(uW,sb+1,K);for(J=0;J<AC;J++)ab[J*2+1]=5,ab[J*2]=Eg1(J,5);Ng1=new jI0(uW,uI0,Xh+1,sb,ME),wg1=new jI0(ab,C40,0,AC,ME),Og1=new jI0([],qu6,0,nI0,Fu6)},Ag1=(J)=>{let Z;for(Z=0;Z<sb;Z++)J.dyn_ltree[Z*2]=0;for(Z=0;Z<AC;Z++)J.dyn_dtree[Z*2]=0;for(Z=0;Z<nI0;Z++)J.bl_tree[Z*2]=0;J.dyn_ltree[aI0*2]=1,J.opt_len=J.static_len=0,J.sym_next=J.matches=0},jg1=(J)=>{if(J.bi_valid>8)$h(J,J.bi_buf);else if(J.bi_valid>0)J.pending_buf[J.pending++]=J.bi_buf;J.bi_buf=0,J.bi_valid=0},Ph1=(J,Z,Q,Y)=>{let X=Z*2,K=Q*2;return J[X]<J[K]||J[X]===J[K]&&Y[Z]<=Y[Q]},II0=(J,Z,Q)=>{let Y=J.heap[Q],X=Q<<1;while(X<=J.heap_len){if(X<J.heap_len&&Ph1(Z,J.heap[X+1],J.heap[X],J.depth))X++;if(Ph1(Z,Y,J.heap[X],J.depth))break;J.heap[Q]=J.heap[X],Q=X,X<<=1}J.heap[Q]=Y},Ch1=(J,Z,Q)=>{let Y,X,K=0,V,z;if(J.sym_next!==0)do if(Y=J.pending_buf[J.sym_buf+K++]&255,Y+=(J.pending_buf[J.sym_buf+K++]&255)<<8,X=J.pending_buf[J.sym_buf+K++],Y===0)hG(J,X,Z);else{if(V=eb[X],hG(J,V+Xh+1,Z),z=uI0[V],z!==0)X-=oI0[V],tZ(J,X,z);if(Y--,V=Lg1(Y),hG(J,V,Q),z=C40[V],z!==0)Y-=T40[V],tZ(J,Y,z)}while(K<J.sym_next);hG(J,aI0,Z)},bI0=(J,Z)=>{let Q=Z.dyn_tree,Y=Z.stat_desc.static_tree,X=Z.stat_desc.has_stree,K=Z.stat_desc.elems,V,z,G=-1,F;J.heap_len=0,J.heap_max=Wg1;for(V=0;V<K;V++)if(Q[V*2]!==0)J.heap[++J.heap_len]=G=V,J.depth[V]=0;else Q[V*2+1]=0;while(J.heap_len<2)if(F=J.heap[++J.heap_len]=G<2?++G:0,Q[F*2]=1,J.depth[F]=0,J.opt_len--,X)J.static_len-=Y[F*2+1];Z.max_code=G;for(V=J.heap_len>>1;V>=1;V--)II0(J,Q,V);F=K;do V=J.heap[1],J.heap[1]=J.heap[J.heap_len--],II0(J,Q,1),z=J.heap[1],J.heap[--J.heap_max]=V,J.heap[--J.heap_max]=z,Q[F*2]=Q[V*2]+Q[z*2],J.depth[F]=(J.depth[V]>=J.depth[z]?J.depth[V]:J.depth[z])+1,Q[V*2+1]=Q[z*2+1]=F,J.heap[1]=F++,II0(J,Q,1);while(J.heap_len>=2);J.heap[--J.heap_max]=J.heap[1],Du6(J,Z),Mg1(Q,G,J.bl_count)},Th1=(J,Z,Q)=>{let Y,X=-1,K,V=Z[1],z=0,G=7,F=4;if(V===0)G=138,F=3;Z[(Q+1)*2+1]=65535;for(Y=0;Y<=Q;Y++){if(K=V,V=Z[(Y+1)*2+1],++z<G&&K===V)continue;else if(z<F)J.bl_tree[K*2]+=z;else if(K!==0){if(K!==X)J.bl_tree[K*2]++;J.bl_tree[Ug1*2]++}else if(z<=10)J.bl_tree[Dg1*2]++;else J.bl_tree[Hg1*2]++;if(z=0,X=K,V===0)G=138,F=3;else if(K===V)G=6,F=3;else G=7,F=4}},_h1=(J,Z,Q)=>{let Y,X=-1,K,V=Z[1],z=0,G=7,F=4;if(V===0)G=138,F=3;for(Y=0;Y<=Q;Y++){if(K=V,V=Z[(Y+1)*2+1],++z<G&&K===V)continue;else if(z<F)do hG(J,K,J.bl_tree);while(--z!==0);else if(K!==0){if(K!==X)hG(J,K,J.bl_tree),z--;hG(J,Ug1,J.bl_tree),tZ(J,z-3,2)}else if(z<=10)hG(J,Dg1,J.bl_tree),tZ(J,z-3,3);else hG(J,Hg1,J.bl_tree),tZ(J,z-11,7);if(z=0,X=K,V===0)G=138,F=3;else if(K===V)G=6,F=3;else G=7,F=4}},Bu6=(J)=>{let Z;Th1(J,J.dyn_ltree,J.l_desc.max_code),Th1(J,J.dyn_dtree,J.d_desc.max_code),bI0(J,J.bl_desc);for(Z=nI0-1;Z>=3;Z--)if(J.bl_tree[Bg1[Z]*2+1]!==0)break;return J.opt_len+=3*(Z+1)+5+5+4,Z},Nu6=(J,Z,Q,Y)=>{let X;tZ(J,Z-257,5),tZ(J,Q-1,5),tZ(J,Y-4,4);for(X=0;X<Y;X++)tZ(J,J.bl_tree[Bg1[X]*2+1],3);_h1(J,J.dyn_ltree,Z-1),_h1(J,J.dyn_dtree,Q-1)},wu6=(J)=>{let Z=4093624447,Q;for(Q=0;Q<=31;Q++,Z>>>=1)if(Z&1&&J.dyn_ltree[Q*2]!==0)return 0;if(J.dyn_ltree[18]!==0||J.dyn_ltree[20]!==0||J.dyn_ltree[26]!==0)return 1;for(Q=32;Q<Xh;Q++)if(J.dyn_ltree[Q*2]!==0)return 1;return 0},Sh1=!1,Ou6=(J)=>{if(!Sh1)Hu6(),Sh1=!0;J.l_desc=new RI0(J.dyn_ltree,Ng1),J.d_desc=new RI0(J.dyn_dtree,wg1),J.bl_desc=new RI0(J.bl_tree,Og1),J.bi_buf=0,J.bi_valid=0,Ag1(J)},Rg1=(J,Z,Q,Y)=>{if(tZ(J,(Ku6<<1)+(Y?1:0),3),jg1(J),$h(J,Q),$h(J,~Q),Q)J.pending_buf.set(J.window.subarray(Z,Z+Q),J.pending);J.pending+=Q},Lu6=(J)=>{tZ(J,qg1<<1,3),hG(J,aI0,uW),Uu6(J)},Eu6=(J,Z,Q,Y)=>{let X,K,V=0;if(J.level>0){if(J.strm.data_type===2)J.strm.data_type=wu6(J);if(bI0(J,J.l_desc),bI0(J,J.d_desc),V=Bu6(J),X=J.opt_len+3+7>>>3,K=J.static_len+3+7>>>3,K<=X)X=K}else X=K=Q+5;if(Q+4<=X&&Z!==-1)Rg1(J,Z,Q,Y);else if(J.strategy===4||K===X)tZ(J,(qg1<<1)+(Y?1:0),3),Ch1(J,uW,ab);else tZ(J,(Vu6<<1)+(Y?1:0),3),Nu6(J,J.l_desc.max_code+1,J.d_desc.max_code+1,V+1),Ch1(J,J.dyn_ltree,J.dyn_dtree);if(Ag1(J),Y)jg1(J)},Mu6=(J,Z,Q)=>{if(J.pending_buf[J.sym_buf+J.sym_next++]=Z,J.pending_buf[J.sym_buf+J.sym_next++]=Z>>8,J.pending_buf[J.sym_buf+J.sym_next++]=Q,Z===0)J.dyn_ltree[Q*2]++;else J.matches++,Z--,J.dyn_ltree[(eb[Q]+Xh+1)*2]++,J.dyn_dtree[Lg1(Z)*2]++;return J.sym_next===J.sym_end},Au6,ju6,Ru6,Iu6,Pu6,Cu6,Tu6=(J,Z,Q,Y)=>{let X=J&65535|0,K=J>>>16&65535|0,V=0;while(Q!==0){V=Q>2000?2000:Q,Q-=V;do X=X+Z[Y++]|0,K=K+X|0;while(--V);X%=65521,K%=65521}return X|K<<16|0},Jh,_u6=()=>{let J,Z=[];for(var Q=0;Q<256;Q++){J=Q;for(var Y=0;Y<8;Y++)J=J&1?3988292384^J>>>1:J>>>1;Z[Q]=J}return Z},Su6,ku6=(J,Z,Q,Y)=>{let X=Su6,K=Y+Q;J^=-1;for(let V=Y;V<K;V++)J=J>>>8^X[(J^Z[V])&255];return J^-1},T7,RE,CE,yu6,hI0,vu6,sH,xu6,tH,fu6,uu6,vX,kh1,w$,yh1,gG,bu6,PI0,hu6,gu6,A40,mu6,pu6,du6,cu6,k40,lu6=9,iu6=15,nu6=8,au6=29,ou6=256,gI0,ru6=30,su6=19,tu6,eu6=15,i5=3,rH=258,mG,$b6=32,jC=42,rI0=57,mI0=69,pI0=73,dI0=91,cI0=103,AE=113,ib=666,oJ=1,PC=2,IE=3,CC=4,Jb6=3,jE=(J,Z)=>{return J.msg=RE[Z],Z},vh1=(J)=>{return J*2-(J>4?9:0)},oH=(J)=>{let Z=J.length;while(--Z>=0)J[Z]=0},Zb6=(J)=>{let Z,Q,Y,X=J.w_size;Z=J.hash_size,Y=Z;do Q=J.head[--Y],J.head[Y]=Q>=X?Q-X:0;while(--Z);Z=X,Y=Z;do Q=J.prev[--Y],J.prev[Y]=Q>=X?Q-X:0;while(--Z)},Qb6=(J,Z,Q)=>(Z<<J.hash_shift^Q)&J.hash_mask,eH,zY=(J)=>{let Z=J.state,Q=Z.pending;if(Q>J.avail_out)Q=J.avail_out;if(Q===0)return;if(J.output.set(Z.pending_buf.subarray(Z.pending_out,Z.pending_out+Q),J.next_out),J.next_out+=Q,Z.pending_out+=Q,J.total_out+=Q,J.avail_out-=Q,Z.pending-=Q,Z.pending===0)Z.pending_out=0},GY=(J,Z)=>{vu6(J,J.block_start>=0?J.block_start:-1,J.strstart-J.block_start,Z),J.block_start=J.strstart,zY(J.strm)},P3=(J,Z)=>{J.pending_buf[J.pending++]=Z},lb=(J,Z)=>{J.pending_buf[J.pending++]=Z>>>8&255,J.pending_buf[J.pending++]=Z&255},lI0=(J,Z,Q,Y)=>{let X=J.avail_in;if(X>Y)X=Y;if(X===0)return 0;if(J.avail_in-=X,Z.set(J.input.subarray(J.next_in,J.next_in+X),Q),J.state.wrap===1)J.adler=Jh(J.adler,Z,X,Q);else if(J.state.wrap===2)J.adler=T7(J.adler,Z,X,Q);return J.next_in+=X,J.total_in+=X,X},Ig1=(J,Z)=>{let{max_chain_length:Q,strstart:Y}=J,X,K,V=J.prev_length,z=J.nice_match,G=J.strstart>J.w_size-mG?J.strstart-(J.w_size-mG):0,F=J.window,q=J.w_mask,W=J.prev,U=J.strstart+rH,D=F[Y+V-1],H=F[Y+V];if(J.prev_length>=J.good_match)Q>>=2;if(z>J.lookahead)z=J.lookahead;do{if(X=Z,F[X+V]!==H||F[X+V-1]!==D||F[X]!==F[Y]||F[++X]!==F[Y+1])continue;Y+=2,X++;do;while(F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&F[++Y]===F[++X]&&Y<U);if(K=rH-(U-Y),Y=U-rH,K>V){if(J.match_start=Z,V=K,K>=z)break;D=F[Y+V-1],H=F[Y+V]}}while((Z=W[Z&q])>G&&--Q!==0);if(V<=J.lookahead)return V;return J.lookahead},RC=(J)=>{let Z=J.w_size,Q,Y,X;do{if(Y=J.window_size-J.lookahead-J.strstart,J.strstart>=Z+(Z-mG)){if(J.window.set(J.window.subarray(Z,Z+Z-Y),0),J.match_start-=Z,J.strstart-=Z,J.block_start-=Z,J.insert>J.strstart)J.insert=J.strstart;Zb6(J),Y+=Z}if(J.strm.avail_in===0)break;if(Q=lI0(J.strm,J.window,J.strstart+J.lookahead,Y),J.lookahead+=Q,J.lookahead+J.insert>=i5){X=J.strstart-J.insert,J.ins_h=J.window[X],J.ins_h=eH(J,J.ins_h,J.window[X+1]);while(J.insert)if(J.ins_h=eH(J,J.ins_h,J.window[X+i5-1]),J.prev[X&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=X,X++,J.insert--,J.lookahead+J.insert<i5)break}}while(J.lookahead<mG&&J.strm.avail_in!==0)},Pg1=(J,Z)=>{let Q=J.pending_buf_size-5>J.w_size?J.w_size:J.pending_buf_size-5,Y,X,K,V=0,z=J.strm.avail_in;do{if(Y=65535,K=J.bi_valid+42>>3,J.strm.avail_out<K)break;if(K=J.strm.avail_out-K,X=J.strstart-J.block_start,Y>X+J.strm.avail_in)Y=X+J.strm.avail_in;if(Y>K)Y=K;if(Y<Q&&(Y===0&&Z!==vX||Z===tH||Y!==X+J.strm.avail_in))break;if(V=Z===vX&&Y===X+J.strm.avail_in?1:0,hI0(J,0,0,V),J.pending_buf[J.pending-4]=Y,J.pending_buf[J.pending-3]=Y>>8,J.pending_buf[J.pending-2]=~Y,J.pending_buf[J.pending-1]=~Y>>8,zY(J.strm),X){if(X>Y)X=Y;J.strm.output.set(J.window.subarray(J.block_start,J.block_start+X),J.strm.next_out),J.strm.next_out+=X,J.strm.avail_out-=X,J.strm.total_out+=X,J.block_start+=X,Y-=X}if(Y)lI0(J.strm,J.strm.output,J.strm.next_out,Y),J.strm.next_out+=Y,J.strm.avail_out-=Y,J.strm.total_out+=Y}while(V===0);if(z-=J.strm.avail_in,z){if(z>=J.w_size)J.matches=2,J.window.set(J.strm.input.subarray(J.strm.next_in-J.w_size,J.strm.next_in),0),J.strstart=J.w_size,J.insert=J.strstart;else{if(J.window_size-J.strstart<=z){if(J.strstart-=J.w_size,J.window.set(J.window.subarray(J.w_size,J.w_size+J.strstart),0),J.matches<2)J.matches++;if(J.insert>J.strstart)J.insert=J.strstart}J.window.set(J.strm.input.subarray(J.strm.next_in-z,J.strm.next_in),J.strstart),J.strstart+=z,J.insert+=z>J.w_size-J.insert?J.w_size-J.insert:z}J.block_start=J.strstart}if(J.high_water<J.strstart)J.high_water=J.strstart;if(V)return CC;if(Z!==tH&&Z!==vX&&J.strm.avail_in===0&&J.strstart===J.block_start)return PC;if(K=J.window_size-J.strstart,J.strm.avail_in>K&&J.block_start>=J.w_size){if(J.block_start-=J.w_size,J.strstart-=J.w_size,J.window.set(J.window.subarray(J.w_size,J.w_size+J.strstart),0),J.matches<2)J.matches++;if(K+=J.w_size,J.insert>J.strstart)J.insert=J.strstart}if(K>J.strm.avail_in)K=J.strm.avail_in;if(K)lI0(J.strm,J.window,J.strstart,K),J.strstart+=K,J.insert+=K>J.w_size-J.insert?J.w_size-J.insert:K;if(J.high_water<J.strstart)J.high_water=J.strstart;if(K=J.bi_valid+42>>3,K=J.pending_buf_size-K>65535?65535:J.pending_buf_size-K,Q=K>J.w_size?J.w_size:K,X=J.strstart-J.block_start,X>=Q||(X||Z===vX)&&Z!==tH&&J.strm.avail_in===0&&X<=K)Y=X>K?K:X,V=Z===vX&&J.strm.avail_in===0&&Y===X?1:0,hI0(J,J.block_start,Y,V),J.block_start+=Y,zY(J.strm);return V?IE:oJ},CI0=(J,Z)=>{let Q,Y;for(;;){if(J.lookahead<mG){if(RC(J),J.lookahead<mG&&Z===tH)return oJ;if(J.lookahead===0)break}if(Q=0,J.lookahead>=i5)J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;if(Q!==0&&J.strstart-Q<=J.w_size-mG)J.match_length=Ig1(J,Q);if(J.match_length>=i5)if(Y=sH(J,J.strstart-J.match_start,J.match_length-i5),J.lookahead-=J.match_length,J.match_length<=J.max_lazy_match&&J.lookahead>=i5){J.match_length--;do J.strstart++,J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;while(--J.match_length!==0);J.strstart++}else J.strstart+=J.match_length,J.match_length=0,J.ins_h=J.window[J.strstart],J.ins_h=eH(J,J.ins_h,J.window[J.strstart+1]);else Y=sH(J,0,J.window[J.strstart]),J.lookahead--,J.strstart++;if(Y){if(GY(J,!1),J.strm.avail_out===0)return oJ}}if(J.insert=J.strstart<i5-1?J.strstart:i5-1,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},EC=(J,Z)=>{let Q,Y,X;for(;;){if(J.lookahead<mG){if(RC(J),J.lookahead<mG&&Z===tH)return oJ;if(J.lookahead===0)break}if(Q=0,J.lookahead>=i5)J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;if(J.prev_length=J.match_length,J.prev_match=J.match_start,J.match_length=i5-1,Q!==0&&J.prev_length<J.max_lazy_match&&J.strstart-Q<=J.w_size-mG){if(J.match_length=Ig1(J,Q),J.match_length<=5&&(J.strategy===gu6||J.match_length===i5&&J.strstart-J.match_start>4096))J.match_length=i5-1}if(J.prev_length>=i5&&J.match_length<=J.prev_length){X=J.strstart+J.lookahead-i5,Y=sH(J,J.strstart-1-J.prev_match,J.prev_length-i5),J.lookahead-=J.prev_length-1,J.prev_length-=2;do if(++J.strstart<=X)J.ins_h=eH(J,J.ins_h,J.window[J.strstart+i5-1]),Q=J.prev[J.strstart&J.w_mask]=J.head[J.ins_h],J.head[J.ins_h]=J.strstart;while(--J.prev_length!==0);if(J.match_available=0,J.match_length=i5-1,J.strstart++,Y){if(GY(J,!1),J.strm.avail_out===0)return oJ}}else if(J.match_available){if(Y=sH(J,0,J.window[J.strstart-1]),Y)GY(J,!1);if(J.strstart++,J.lookahead--,J.strm.avail_out===0)return oJ}else J.match_available=1,J.strstart++,J.lookahead--}if(J.match_available)Y=sH(J,0,J.window[J.strstart-1]),J.match_available=0;if(J.insert=J.strstart<i5-1?J.strstart:i5-1,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},Yb6=(J,Z)=>{let Q,Y,X,K,V=J.window;for(;;){if(J.lookahead<=rH){if(RC(J),J.lookahead<=rH&&Z===tH)return oJ;if(J.lookahead===0)break}if(J.match_length=0,J.lookahead>=i5&&J.strstart>0){if(X=J.strstart-1,Y=V[X],Y===V[++X]&&Y===V[++X]&&Y===V[++X]){K=J.strstart+rH;do;while(Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&Y===V[++X]&&X<K);if(J.match_length=rH-(K-X),J.match_length>J.lookahead)J.match_length=J.lookahead}}if(J.match_length>=i5)Q=sH(J,1,J.match_length-i5),J.lookahead-=J.match_length,J.strstart+=J.match_length,J.match_length=0;else Q=sH(J,0,J.window[J.strstart]),J.lookahead--,J.strstart++;if(Q){if(GY(J,!1),J.strm.avail_out===0)return oJ}}if(J.insert=0,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},Xb6=(J,Z)=>{let Q;for(;;){if(J.lookahead===0){if(RC(J),J.lookahead===0){if(Z===tH)return oJ;break}}if(J.match_length=0,Q=sH(J,0,J.window[J.strstart]),J.lookahead--,J.strstart++,Q){if(GY(J,!1),J.strm.avail_out===0)return oJ}}if(J.insert=0,Z===vX){if(GY(J,!0),J.strm.avail_out===0)return IE;return CC}if(J.sym_next){if(GY(J,!1),J.strm.avail_out===0)return oJ}return PC},nb,Kb6=(J)=>{J.window_size=2*J.w_size,oH(J.head),J.max_lazy_match=nb[J.level].max_lazy,J.good_match=nb[J.level].good_length,J.nice_match=nb[J.level].nice_length,J.max_chain_length=nb[J.level].max_chain,J.strstart=0,J.block_start=0,J.lookahead=0,J.insert=0,J.match_length=J.prev_length=i5-1,J.match_available=0,J.ins_h=0},Kh=(J)=>{if(!J)return 1;let Z=J.state;if(!Z||Z.strm!==J||Z.status!==jC&&Z.status!==rI0&&Z.status!==mI0&&Z.status!==pI0&&Z.status!==dI0&&Z.status!==cI0&&Z.status!==AE&&Z.status!==ib)return 1;return 0},Cg1=(J)=>{if(Kh(J))return jE(J,gG);J.total_in=J.total_out=0,J.data_type=cu6;let Z=J.state;if(Z.pending=0,Z.pending_out=0,Z.wrap<0)Z.wrap=-Z.wrap;return Z.status=Z.wrap===2?rI0:Z.wrap?jC:AE,J.adler=Z.wrap===2?0:1,Z.last_flush=-2,yu6(Z),w$},Tg1=(J)=>{let Z=Cg1(J);if(Z===w$)Kb6(J.state);return Z},zb6=(J,Z)=>{if(Kh(J)||J.state.wrap!==2)return gG;return J.state.gzhead=Z,w$},_g1=(J,Z,Q,Y,X,K)=>{if(!J)return gG;let V=1;if(Z===hu6)Z=6;if(Y<0)V=0,Y=-Y;else if(Y>15)V=2,Y-=16;if(X<1||X>lu6||Q!==k40||Y<8||Y>15||Z<0||Z>9||K<0||K>pu6||Y===8&&V!==1)return jE(J,gG);if(Y===8)Y=9;let z=new Vb6;return J.state=z,z.strm=J,z.status=jC,z.wrap=V,z.gzhead=null,z.w_bits=Y,z.w_size=1<<z.w_bits,z.w_mask=z.w_size-1,z.hash_bits=X+7,z.hash_size=1<<z.hash_bits,z.hash_mask=z.hash_size-1,z.hash_shift=~~((z.hash_bits+i5-1)/i5),z.window=new Uint8Array(z.w_size*2),z.head=new Uint16Array(z.hash_size),z.prev=new Uint16Array(z.w_size),z.lit_bufsize=1<<X+6,z.pending_buf_size=z.lit_bufsize*4,z.pending_buf=new Uint8Array(z.pending_buf_size),z.sym_buf=z.lit_bufsize,z.sym_end=(z.lit_bufsize-1)*3,z.level=Z,z.strategy=K,z.method=Q,Tg1(J)},Gb6=(J,Z)=>{return _g1(J,Z,k40,iu6,nu6,du6)},Fb6=(J,Z)=>{if(Kh(J)||Z>kh1||Z<0)return J?jE(J,gG):gG;let Q=J.state;if(!J.output||J.avail_in!==0&&!J.input||Q.status===ib&&Z!==vX)return jE(J,J.avail_out===0?PI0:gG);let Y=Q.last_flush;if(Q.last_flush=Z,Q.pending!==0){if(zY(J),J.avail_out===0)return Q.last_flush=-1,w$}else if(J.avail_in===0&&vh1(Z)<=vh1(Y)&&Z!==vX)return jE(J,PI0);if(Q.status===ib&&J.avail_in!==0)return jE(J,PI0);if(Q.status===jC&&Q.wrap===0)Q.status=AE;if(Q.status===jC){let X=k40+(Q.w_bits-8<<4)<<8,K=-1;if(Q.strategy>=A40||Q.level<2)K=0;else if(Q.level<6)K=1;else if(Q.level===6)K=2;else K=3;if(X|=K<<6,Q.strstart!==0)X|=$b6;if(X+=31-X%31,lb(Q,X),Q.strstart!==0)lb(Q,J.adler>>>16),lb(Q,J.adler&65535);if(J.adler=1,Q.status=AE,zY(J),Q.pending!==0)return Q.last_flush=-1,w$}if(Q.status===rI0)if(J.adler=0,P3(Q,31),P3(Q,139),P3(Q,8),!Q.gzhead){if(P3(Q,0),P3(Q,0),P3(Q,0),P3(Q,0),P3(Q,0),P3(Q,Q.level===9?2:Q.strategy>=A40||Q.level<2?4:0),P3(Q,Jb6),Q.status=AE,zY(J),Q.pending!==0)return Q.last_flush=-1,w$}else{if(P3(Q,(Q.gzhead.text?1:0)+(Q.gzhead.hcrc?2:0)+(!Q.gzhead.extra?0:4)+(!Q.gzhead.name?0:8)+(!Q.gzhead.comment?0:16)),P3(Q,Q.gzhead.time&255),P3(Q,Q.gzhead.time>>8&255),P3(Q,Q.gzhead.time>>16&255),P3(Q,Q.gzhead.time>>24&255),P3(Q,Q.level===9?2:Q.strategy>=A40||Q.level<2?4:0),P3(Q,Q.gzhead.os&255),Q.gzhead.extra&&Q.gzhead.extra.length)P3(Q,Q.gzhead.extra.length&255),P3(Q,Q.gzhead.extra.length>>8&255);if(Q.gzhead.hcrc)J.adler=T7(J.adler,Q.pending_buf,Q.pending,0);Q.gzindex=0,Q.status=mI0}if(Q.status===mI0){if(Q.gzhead.extra){let X=Q.pending,K=(Q.gzhead.extra.length&65535)-Q.gzindex;while(Q.pending+K>Q.pending_buf_size){let z=Q.pending_buf_size-Q.pending;if(Q.pending_buf.set(Q.gzhead.extra.subarray(Q.gzindex,Q.gzindex+z),Q.pending),Q.pending=Q.pending_buf_size,Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);if(Q.gzindex+=z,zY(J),Q.pending!==0)return Q.last_flush=-1,w$;X=0,K-=z}let V=new Uint8Array(Q.gzhead.extra);if(Q.pending_buf.set(V.subarray(Q.gzindex,Q.gzindex+K),Q.pending),Q.pending+=K,Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);Q.gzindex=0}Q.status=pI0}if(Q.status===pI0){if(Q.gzhead.name){let X=Q.pending,K;do{if(Q.pending===Q.pending_buf_size){if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);if(zY(J),Q.pending!==0)return Q.last_flush=-1,w$;X=0}if(Q.gzindex<Q.gzhead.name.length)K=Q.gzhead.name.charCodeAt(Q.gzindex++)&255;else K=0;P3(Q,K)}while(K!==0);if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);Q.gzindex=0}Q.status=dI0}if(Q.status===dI0){if(Q.gzhead.comment){let X=Q.pending,K;do{if(Q.pending===Q.pending_buf_size){if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X);if(zY(J),Q.pending!==0)return Q.last_flush=-1,w$;X=0}if(Q.gzindex<Q.gzhead.comment.length)K=Q.gzhead.comment.charCodeAt(Q.gzindex++)&255;else K=0;P3(Q,K)}while(K!==0);if(Q.gzhead.hcrc&&Q.pending>X)J.adler=T7(J.adler,Q.pending_buf,Q.pending-X,X)}Q.status=cI0}if(Q.status===cI0){if(Q.gzhead.hcrc){if(Q.pending+2>Q.pending_buf_size){if(zY(J),Q.pending!==0)return Q.last_flush=-1,w$}P3(Q,J.adler&255),P3(Q,J.adler>>8&255),J.adler=0}if(Q.status=AE,zY(J),Q.pending!==0)return Q.last_flush=-1,w$}if(J.avail_in!==0||Q.lookahead!==0||Z!==tH&&Q.status!==ib){let X=Q.level===0?Pg1(Q,Z):Q.strategy===A40?Xb6(Q,Z):Q.strategy===mu6?Yb6(Q,Z):nb[Q.level].func(Q,Z);if(X===IE||X===CC)Q.status=ib;if(X===oJ||X===IE){if(J.avail_out===0)Q.last_flush=-1;return w$}if(X===PC){if(Z===fu6)xu6(Q);else if(Z!==kh1){if(hI0(Q,0,0,!1),Z===uu6){if(oH(Q.head),Q.lookahead===0)Q.strstart=0,Q.block_start=0,Q.insert=0}}if(zY(J),J.avail_out===0)return Q.last_flush=-1,w$}}if(Z!==vX)return w$;if(Q.wrap<=0)return yh1;if(Q.wrap===2)P3(Q,J.adler&255),P3(Q,J.adler>>8&255),P3(Q,J.adler>>16&255),P3(Q,J.adler>>24&255),P3(Q,J.total_in&255),P3(Q,J.total_in>>8&255),P3(Q,J.total_in>>16&255),P3(Q,J.total_in>>24&255);else lb(Q,J.adler>>>16),lb(Q,J.adler&65535);if(zY(J),Q.wrap>0)Q.wrap=-Q.wrap;return Q.pending!==0?w$:yh1},qb6=(J)=>{if(Kh(J))return gG;let Z=J.state.status;return J.state=null,Z===AE?jE(J,bu6):w$},Wb6=(J,Z)=>{let Q=Z.length;if(Kh(J))return gG;let Y=J.state,X=Y.wrap;if(X===2||X===1&&Y.status!==jC||Y.lookahead)return gG;if(X===1)J.adler=Jh(J.adler,Z,Q,0);if(Y.wrap=0,Q>=Y.w_size){if(X===0)oH(Y.head),Y.strstart=0,Y.block_start=0,Y.insert=0;let G=new Uint8Array(Y.w_size);G.set(Z.subarray(Q-Y.w_size,Q),0),Z=G,Q=Y.w_size}let{avail_in:K,next_in:V,input:z}=J;J.avail_in=Q,J.next_in=0,J.input=Z,RC(Y);while(Y.lookahead>=i5){let G=Y.strstart,F=Y.lookahead-(i5-1);do Y.ins_h=eH(Y,Y.ins_h,Y.window[G+i5-1]),Y.prev[G&Y.w_mask]=Y.head[Y.ins_h],Y.head[Y.ins_h]=G,G++;while(--F);Y.strstart=G,Y.lookahead=i5-1,RC(Y)}return Y.strstart+=Y.lookahead,Y.block_start=Y.strstart,Y.insert=Y.lookahead,Y.lookahead=0,Y.match_length=Y.prev_length=i5-1,Y.match_available=0,J.next_in=V,J.input=z,J.avail_in=K,Y.wrap=X,w$},Ub6,Db6,Hb6,Bb6,Nb6,wb6,Ob6,Lb6,Eb6="pako deflate (from Nodeca project)",ob,Mb6=(J,Z)=>{return Object.prototype.hasOwnProperty.call(J,Z)},Ab6=function(J){let Z=Array.prototype.slice.call(arguments,1);while(Z.length){let Q=Z.shift();if(!Q)continue;if(typeof Q!=="object")throw TypeError(Q+"must be non-object");for(let Y in Q)if(Mb6(Q,Y))J[Y]=Q[Y]}return J},jb6=(J)=>{let Z=0;for(let Y=0,X=J.length;Y<X;Y++)Z+=J[Y].length;let Q=new Uint8Array(Z);for(let Y=0,X=0,K=J.length;Y<K;Y++){let V=J[Y];Q.set(V,X),X+=V.length}return Q},y40,Sg1=!0,Zh,Rb6=(J)=>{if(typeof TextEncoder==="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(J);let Z,Q,Y,X,K,V=J.length,z=0;for(X=0;X<V;X++){if(Q=J.charCodeAt(X),(Q&64512)===55296&&X+1<V){if(Y=J.charCodeAt(X+1),(Y&64512)===56320)Q=65536+(Q-55296<<10)+(Y-56320),X++}z+=Q<128?1:Q<2048?2:Q<65536?3:4}Z=new Uint8Array(z);for(K=0,X=0;K<z;X++){if(Q=J.charCodeAt(X),(Q&64512)===55296&&X+1<V){if(Y=J.charCodeAt(X+1),(Y&64512)===56320)Q=65536+(Q-55296<<10)+(Y-56320),X++}if(Q<128)Z[K++]=Q;else if(Q<2048)Z[K++]=192|Q>>>6,Z[K++]=128|Q&63;else if(Q<65536)Z[K++]=224|Q>>>12,Z[K++]=128|Q>>>6&63,Z[K++]=128|Q&63;else Z[K++]=240|Q>>>18,Z[K++]=128|Q>>>12&63,Z[K++]=128|Q>>>6&63,Z[K++]=128|Q&63}return Z},Ib6=(J,Z)=>{if(Z<65534){if(J.subarray&&Sg1)return String.fromCharCode.apply(null,J.length===Z?J:J.subarray(0,Z))}let Q="";for(let Y=0;Y<Z;Y++)Q+=String.fromCharCode(J[Y]);return Q},Pb6=(J,Z)=>{let Q=Z||J.length;if(typeof TextDecoder==="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(J.subarray(0,Z));let Y,X,K=Array(Q*2);for(X=0,Y=0;Y<Q;){let V=J[Y++];if(V<128){K[X++]=V;continue}let z=Zh[V];if(z>4){K[X++]=65533,Y+=z-1;continue}V&=z===2?31:z===3?15:7;while(z>1&&Y<Q)V=V<<6|J[Y++]&63,z--;if(z>1){K[X++]=65533;continue}if(V<65536)K[X++]=V;else V-=65536,K[X++]=55296|V>>10&1023,K[X++]=56320|V&1023}return Ib6(K,X)},Cb6=(J,Z)=>{if(Z=Z||J.length,Z>J.length)Z=J.length;let Q=Z-1;while(Q>=0&&(J[Q]&192)===128)Q--;if(Q<0)return Z;if(Q===0)return Z;return Q+Zh[J[Q]]>Z?Q:Z},Qh,kg1,yg1,_b6,Sb6,kb6,yb6,_40,vb6,xb6,fb6,ub6,gb6,mb6,pb6,db6,cb6,lb6,j40=16209,ib6=16191,nb6=function(Z,Q){let Y,X,K,V,z,G,F,q,W,U,D,H,B,N,w,O,L,E,M,A,j,R,_,k,u=Z.state;Y=Z.next_in,_=Z.input,X=Y+(Z.avail_in-5),K=Z.next_out,k=Z.output,V=K-(Q-Z.avail_out),z=K+(Z.avail_out-257),G=u.dmax,F=u.wsize,q=u.whave,W=u.wnext,U=u.window,D=u.hold,H=u.bits,B=u.lencode,N=u.distcode,w=(1<<u.lenbits)-1,O=(1<<u.distbits)-1;$:do{if(H<15)D+=_[Y++]<<H,H+=8,D+=_[Y++]<<H,H+=8;L=B[D&w];J:for(;;){if(E=L>>>24,D>>>=E,H-=E,E=L>>>16&255,E===0)k[K++]=L&65535;else if(E&16){if(M=L&65535,E&=15,E){if(H<E)D+=_[Y++]<<H,H+=8;M+=D&(1<<E)-1,D>>>=E,H-=E}if(H<15)D+=_[Y++]<<H,H+=8,D+=_[Y++]<<H,H+=8;L=N[D&O];Z:for(;;){if(E=L>>>24,D>>>=E,H-=E,E=L>>>16&255,E&16){if(A=L&65535,E&=15,H<E){if(D+=_[Y++]<<H,H+=8,H<E)D+=_[Y++]<<H,H+=8}if(A+=D&(1<<E)-1,A>G){Z.msg="invalid distance too far back",u.mode=j40;break $}if(D>>>=E,H-=E,E=K-V,A>E){if(E=A-E,E>q){if(u.sane){Z.msg="invalid distance too far back",u.mode=j40;break $}}if(j=0,R=U,W===0){if(j+=F-E,E<M){M-=E;do k[K++]=U[j++];while(--E);j=K-A,R=k}}else if(W<E){if(j+=F+W-E,E-=W,E<M){M-=E;do k[K++]=U[j++];while(--E);if(j=0,W<M){E=W,M-=E;do k[K++]=U[j++];while(--E);j=K-A,R=k}}}else if(j+=W-E,E<M){M-=E;do k[K++]=U[j++];while(--E);j=K-A,R=k}while(M>2)k[K++]=R[j++],k[K++]=R[j++],k[K++]=R[j++],M-=3;if(M){if(k[K++]=R[j++],M>1)k[K++]=R[j++]}}else{j=K-A;do k[K++]=k[j++],k[K++]=k[j++],k[K++]=k[j++],M-=3;while(M>2);if(M){if(k[K++]=k[j++],M>1)k[K++]=k[j++]}}}else if((E&64)===0){L=N[(L&65535)+(D&(1<<E)-1)];continue Z}else{Z.msg="invalid distance code",u.mode=j40;break $}break}}else if((E&64)===0){L=B[(L&65535)+(D&(1<<E)-1)];continue J}else if(E&32){u.mode=ib6;break $}else{Z.msg="invalid literal/length code",u.mode=j40;break $}break}}while(Y<X&&K<z);M=H>>3,Y-=M,H-=M<<3,D&=(1<<H)-1,Z.next_in=Y,Z.next_out=K,Z.avail_in=Y<X?5+(X-Y):5-(Y-X),Z.avail_out=K<z?257+(z-K):257-(K-z),u.hold=D,u.bits=H;return},MC=15,xh1=852,fh1=592,uh1=0,TI0=1,bh1=2,ab6,ob6,rb6,sb6,tb6=(J,Z,Q,Y,X,K,V,z)=>{let G=z.bits,F=0,q=0,W=0,U=0,D=0,H=0,B=0,N=0,w=0,O=0,L,E,M,A,j,R=null,_,k=new Uint16Array(MC+1),u=new Uint16Array(MC+1),m=null,x,T,f;for(F=0;F<=MC;F++)k[F]=0;for(q=0;q<Y;q++)k[Z[Q+q]]++;D=G;for(U=MC;U>=1;U--)if(k[U]!==0)break;if(D>U)D=U;if(U===0)return X[K++]=20971520,X[K++]=20971520,z.bits=1,0;for(W=1;W<U;W++)if(k[W]!==0)break;if(D<W)D=W;N=1;for(F=1;F<=MC;F++)if(N<<=1,N-=k[F],N<0)return-1;if(N>0&&(J===uh1||U!==1))return-1;u[1]=0;for(F=1;F<MC;F++)u[F+1]=u[F]+k[F];for(q=0;q<Y;q++)if(Z[Q+q]!==0)V[u[Z[Q+q]]++]=q;if(J===uh1)R=m=V,_=20;else if(J===TI0)R=ab6,m=ob6,_=257;else R=rb6,m=sb6,_=0;if(O=0,q=0,F=W,j=K,H=D,B=0,M=-1,w=1<<D,A=w-1,J===TI0&&w>xh1||J===bh1&&w>fh1)return 1;for(;;){if(x=F-B,V[q]+1<_)T=0,f=V[q];else if(V[q]>=_)T=m[V[q]-_],f=R[V[q]-_];else T=96,f=0;L=1<<F-B,E=1<<H,W=E;do E-=L,X[j+(O>>B)+E]=x<<24|T<<16|f|0;while(E!==0);L=1<<F-1;while(O&L)L>>=1;if(L!==0)O&=L-1,O+=L;else O=0;if(q++,--k[F]===0){if(F===U)break;F=Z[Q+V[q]]}if(F>D&&(O&A)!==M){if(B===0)B=D;j+=W,H=F-B,N=1<<H;while(H+B<U){if(N-=k[H+B],N<=0)break;H++,N<<=1}if(w+=1<<H,J===TI0&&w>xh1||J===bh1&&w>fh1)return 1;M=O&A,X[M]=D<<24|H<<16|j-K|0}}if(O!==0)X[j+O]=F-B<<24|4194304|0;return z.bits=D,0},rb,eb6=0,vg1=1,xg1=2,hh1,$h6,R40,PE,Jh6,Zh6,xX,fg1,ug1,Qh6,gh1,v40=16180,mh1=16181,ph1=16182,dh1=16183,ch1=16184,lh1=16185,ih1=16186,nh1=16187,ah1=16188,oh1=16189,S40=16190,fW=16191,_I0=16192,rh1=16193,SI0=16194,sh1=16195,th1=16196,eh1=16197,$g1=16198,I40=16199,P40=16200,Jg1=16201,Zg1=16202,Qg1=16203,Yg1=16204,Xg1=16205,kI0=16206,Kg1=16207,Vg1=16208,Y9=16209,bg1=16210,hg1=16211,Yh6=852,Xh6=592,Kh6=15,Vh6,zg1=(J)=>{return(J>>>24&255)+(J>>>8&65280)+((J&65280)<<8)+((J&255)<<24)},TE=(J)=>{if(!J)return 1;let Z=J.state;if(!Z||Z.strm!==J||Z.mode<v40||Z.mode>hg1)return 1;return 0},gg1=(J)=>{if(TE(J))return xX;let Z=J.state;if(J.total_in=J.total_out=Z.total=0,J.msg="",Z.wrap)J.adler=Z.wrap&1;return Z.mode=v40,Z.last=0,Z.havedict=0,Z.flags=-1,Z.dmax=32768,Z.head=null,Z.hold=0,Z.bits=0,Z.lencode=Z.lendyn=new Int32Array(Yh6),Z.distcode=Z.distdyn=new Int32Array(Xh6),Z.sane=1,Z.back=-1,PE},mg1=(J)=>{if(TE(J))return xX;let Z=J.state;return Z.wsize=0,Z.whave=0,Z.wnext=0,gg1(J)},pg1=(J,Z)=>{let Q;if(TE(J))return xX;let Y=J.state;if(Z<0)Q=0,Z=-Z;else if(Q=(Z>>4)+5,Z<48)Z&=15;if(Z&&(Z<8||Z>15))return xX;if(Y.window!==null&&Y.wbits!==Z)Y.window=null;return Y.wrap=Q,Y.wbits=Z,mg1(J)},dg1=(J,Z)=>{if(!J)return xX;let Q=new zh6;J.state=Q,Q.strm=J,Q.window=null,Q.mode=v40;let Y=pg1(J,Z);if(Y!==PE)J.state=null;return Y},Gh6=(J)=>{return dg1(J,Vh6)},Gg1=!0,yI0,vI0,Fh6=(J)=>{if(Gg1){yI0=new Int32Array(512),vI0=new Int32Array(32);let Z=0;while(Z<144)J.lens[Z++]=8;while(Z<256)J.lens[Z++]=9;while(Z<280)J.lens[Z++]=7;while(Z<288)J.lens[Z++]=8;rb(vg1,J.lens,0,288,yI0,0,J.work,{bits:9}),Z=0;while(Z<32)J.lens[Z++]=5;rb(xg1,J.lens,0,32,vI0,0,J.work,{bits:5}),Gg1=!1}J.lencode=yI0,J.lenbits=9,J.distcode=vI0,J.distbits=5},cg1=(J,Z,Q,Y)=>{let X,K=J.state;if(K.window===null)K.wsize=1<<K.wbits,K.wnext=0,K.whave=0,K.window=new Uint8Array(K.wsize);if(Y>=K.wsize)K.window.set(Z.subarray(Q-K.wsize,Q),0),K.wnext=0,K.whave=K.wsize;else{if(X=K.wsize-K.wnext,X>Y)X=Y;if(K.window.set(Z.subarray(Q-Y,Q-Y+X),K.wnext),Y-=X,Y)K.window.set(Z.subarray(Q-Y,Q),0),K.wnext=Y,K.whave=K.wsize;else{if(K.wnext+=X,K.wnext===K.wsize)K.wnext=0;if(K.whave<K.wsize)K.whave+=X}}return 0},qh6=(J,Z)=>{let Q,Y,X,K,V,z,G,F,q,W,U,D,H,B,N=0,w,O,L,E,M,A,j,R,_=new Uint8Array(4),k,u,m=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(TE(J)||!J.output||!J.input&&J.avail_in!==0)return xX;if(Q=J.state,Q.mode===fW)Q.mode=_I0;V=J.next_out,X=J.output,G=J.avail_out,K=J.next_in,Y=J.input,z=J.avail_in,F=Q.hold,q=Q.bits,W=z,U=G,R=PE;$:for(;;)switch(Q.mode){case v40:if(Q.wrap===0){Q.mode=_I0;break}while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.wrap&2&&F===35615){if(Q.wbits===0)Q.wbits=15;Q.check=0,_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0),F=0,q=0,Q.mode=mh1;break}if(Q.head)Q.head.done=!1;if(!(Q.wrap&1)||(((F&255)<<8)+(F>>8))%31){J.msg="incorrect header check",Q.mode=Y9;break}if((F&15)!==gh1){J.msg="unknown compression method",Q.mode=Y9;break}if(F>>>=4,q-=4,j=(F&15)+8,Q.wbits===0)Q.wbits=j;if(j>15||j>Q.wbits){J.msg="invalid window size",Q.mode=Y9;break}Q.dmax=1<<Q.wbits,Q.flags=0,J.adler=Q.check=1,Q.mode=F&512?oh1:fW,F=0,q=0;break;case mh1:while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.flags=F,(Q.flags&255)!==gh1){J.msg="unknown compression method",Q.mode=Y9;break}if(Q.flags&57344){J.msg="unknown header flags set",Q.mode=Y9;break}if(Q.head)Q.head.text=F>>8&1;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0);F=0,q=0,Q.mode=ph1;case ph1:while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.head)Q.head.time=F;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,_[2]=F>>>16&255,_[3]=F>>>24&255,Q.check=T7(Q.check,_,4,0);F=0,q=0,Q.mode=dh1;case dh1:while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.head)Q.head.xflags=F&255,Q.head.os=F>>8;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0);F=0,q=0,Q.mode=ch1;case ch1:if(Q.flags&1024){while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.length=F,Q.head)Q.head.extra_len=F;if(Q.flags&512&&Q.wrap&4)_[0]=F&255,_[1]=F>>>8&255,Q.check=T7(Q.check,_,2,0);F=0,q=0}else if(Q.head)Q.head.extra=null;Q.mode=lh1;case lh1:if(Q.flags&1024){if(D=Q.length,D>z)D=z;if(D){if(Q.head){if(j=Q.head.extra_len-Q.length,!Q.head.extra)Q.head.extra=new Uint8Array(Q.head.extra_len);Q.head.extra.set(Y.subarray(K,K+D),j)}if(Q.flags&512&&Q.wrap&4)Q.check=T7(Q.check,Y,D,K);z-=D,K+=D,Q.length-=D}if(Q.length)break $}Q.length=0,Q.mode=ih1;case ih1:if(Q.flags&2048){if(z===0)break $;D=0;do if(j=Y[K+D++],Q.head&&j&&Q.length<65536)Q.head.name+=String.fromCharCode(j);while(j&&D<z);if(Q.flags&512&&Q.wrap&4)Q.check=T7(Q.check,Y,D,K);if(z-=D,K+=D,j)break $}else if(Q.head)Q.head.name=null;Q.length=0,Q.mode=nh1;case nh1:if(Q.flags&4096){if(z===0)break $;D=0;do if(j=Y[K+D++],Q.head&&j&&Q.length<65536)Q.head.comment+=String.fromCharCode(j);while(j&&D<z);if(Q.flags&512&&Q.wrap&4)Q.check=T7(Q.check,Y,D,K);if(z-=D,K+=D,j)break $}else if(Q.head)Q.head.comment=null;Q.mode=ah1;case ah1:if(Q.flags&512){while(q<16){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.wrap&4&&F!==(Q.check&65535)){J.msg="header crc mismatch",Q.mode=Y9;break}F=0,q=0}if(Q.head)Q.head.hcrc=Q.flags>>9&1,Q.head.done=!0;J.adler=Q.check=0,Q.mode=fW;break;case oh1:while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}J.adler=Q.check=zg1(F),F=0,q=0,Q.mode=S40;case S40:if(Q.havedict===0)return J.next_out=V,J.avail_out=G,J.next_in=K,J.avail_in=z,Q.hold=F,Q.bits=q,Zh6;J.adler=Q.check=1,Q.mode=fW;case fW:if(Z===$h6||Z===R40)break $;case _I0:if(Q.last){F>>>=q&7,q-=q&7,Q.mode=kI0;break}while(q<3){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}switch(Q.last=F&1,F>>>=1,q-=1,F&3){case 0:Q.mode=rh1;break;case 1:if(Fh6(Q),Q.mode=I40,Z===R40){F>>>=2,q-=2;break $}break;case 2:Q.mode=th1;break;case 3:J.msg="invalid block type",Q.mode=Y9}F>>>=2,q-=2;break;case rh1:F>>>=q&7,q-=q&7;while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if((F&65535)!==(F>>>16^65535)){J.msg="invalid stored block lengths",Q.mode=Y9;break}if(Q.length=F&65535,F=0,q=0,Q.mode=SI0,Z===R40)break $;case SI0:Q.mode=sh1;case sh1:if(D=Q.length,D){if(D>z)D=z;if(D>G)D=G;if(D===0)break $;X.set(Y.subarray(K,K+D),V),z-=D,K+=D,G-=D,V+=D,Q.length-=D;break}Q.mode=fW;break;case th1:while(q<14){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.nlen=(F&31)+257,F>>>=5,q-=5,Q.ndist=(F&31)+1,F>>>=5,q-=5,Q.ncode=(F&15)+4,F>>>=4,q-=4,Q.nlen>286||Q.ndist>30){J.msg="too many length or distance symbols",Q.mode=Y9;break}Q.have=0,Q.mode=eh1;case eh1:while(Q.have<Q.ncode){while(q<3){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}Q.lens[m[Q.have++]]=F&7,F>>>=3,q-=3}while(Q.have<19)Q.lens[m[Q.have++]]=0;if(Q.lencode=Q.lendyn,Q.lenbits=7,k={bits:Q.lenbits},R=rb(eb6,Q.lens,0,19,Q.lencode,0,Q.work,k),Q.lenbits=k.bits,R){J.msg="invalid code lengths set",Q.mode=Y9;break}Q.have=0,Q.mode=$g1;case $g1:while(Q.have<Q.nlen+Q.ndist){for(;;){if(N=Q.lencode[F&(1<<Q.lenbits)-1],w=N>>>24,O=N>>>16&255,L=N&65535,w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(L<16)F>>>=w,q-=w,Q.lens[Q.have++]=L;else{if(L===16){u=w+2;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(F>>>=w,q-=w,Q.have===0){J.msg="invalid bit length repeat",Q.mode=Y9;break}j=Q.lens[Q.have-1],D=3+(F&3),F>>>=2,q-=2}else if(L===17){u=w+3;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=w,q-=w,j=0,D=3+(F&7),F>>>=3,q-=3}else{u=w+7;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=w,q-=w,j=0,D=11+(F&127),F>>>=7,q-=7}if(Q.have+D>Q.nlen+Q.ndist){J.msg="invalid bit length repeat",Q.mode=Y9;break}while(D--)Q.lens[Q.have++]=j}}if(Q.mode===Y9)break;if(Q.lens[256]===0){J.msg="invalid code -- missing end-of-block",Q.mode=Y9;break}if(Q.lenbits=9,k={bits:Q.lenbits},R=rb(vg1,Q.lens,0,Q.nlen,Q.lencode,0,Q.work,k),Q.lenbits=k.bits,R){J.msg="invalid literal/lengths set",Q.mode=Y9;break}if(Q.distbits=6,Q.distcode=Q.distdyn,k={bits:Q.distbits},R=rb(xg1,Q.lens,Q.nlen,Q.ndist,Q.distcode,0,Q.work,k),Q.distbits=k.bits,R){J.msg="invalid distances set",Q.mode=Y9;break}if(Q.mode=I40,Z===R40)break $;case I40:Q.mode=P40;case P40:if(z>=6&&G>=258){if(J.next_out=V,J.avail_out=G,J.next_in=K,J.avail_in=z,Q.hold=F,Q.bits=q,nb6(J,U),V=J.next_out,X=J.output,G=J.avail_out,K=J.next_in,Y=J.input,z=J.avail_in,F=Q.hold,q=Q.bits,Q.mode===fW)Q.back=-1;break}Q.back=0;for(;;){if(N=Q.lencode[F&(1<<Q.lenbits)-1],w=N>>>24,O=N>>>16&255,L=N&65535,w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(O&&(O&240)===0){E=w,M=O,A=L;for(;;){if(N=Q.lencode[A+((F&(1<<E+M)-1)>>E)],w=N>>>24,O=N>>>16&255,L=N&65535,E+w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=E,q-=E,Q.back+=E}if(F>>>=w,q-=w,Q.back+=w,Q.length=L,O===0){Q.mode=Xg1;break}if(O&32){Q.back=-1,Q.mode=fW;break}if(O&64){J.msg="invalid literal/length code",Q.mode=Y9;break}Q.extra=O&15,Q.mode=Jg1;case Jg1:if(Q.extra){u=Q.extra;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}Q.length+=F&(1<<Q.extra)-1,F>>>=Q.extra,q-=Q.extra,Q.back+=Q.extra}Q.was=Q.length,Q.mode=Zg1;case Zg1:for(;;){if(N=Q.distcode[F&(1<<Q.distbits)-1],w=N>>>24,O=N>>>16&255,L=N&65535,w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if((O&240)===0){E=w,M=O,A=L;for(;;){if(N=Q.distcode[A+((F&(1<<E+M)-1)>>E)],w=N>>>24,O=N>>>16&255,L=N&65535,E+w<=q)break;if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}F>>>=E,q-=E,Q.back+=E}if(F>>>=w,q-=w,Q.back+=w,O&64){J.msg="invalid distance code",Q.mode=Y9;break}Q.offset=L,Q.extra=O&15,Q.mode=Qg1;case Qg1:if(Q.extra){u=Q.extra;while(q<u){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}Q.offset+=F&(1<<Q.extra)-1,F>>>=Q.extra,q-=Q.extra,Q.back+=Q.extra}if(Q.offset>Q.dmax){J.msg="invalid distance too far back",Q.mode=Y9;break}Q.mode=Yg1;case Yg1:if(G===0)break $;if(D=U-G,Q.offset>D){if(D=Q.offset-D,D>Q.whave){if(Q.sane){J.msg="invalid distance too far back",Q.mode=Y9;break}}if(D>Q.wnext)D-=Q.wnext,H=Q.wsize-D;else H=Q.wnext-D;if(D>Q.length)D=Q.length;B=Q.window}else B=X,H=V-Q.offset,D=Q.length;if(D>G)D=G;G-=D,Q.length-=D;do X[V++]=B[H++];while(--D);if(Q.length===0)Q.mode=P40;break;case Xg1:if(G===0)break $;X[V++]=Q.length,G--,Q.mode=P40;break;case kI0:if(Q.wrap){while(q<32){if(z===0)break $;z--,F|=Y[K++]<<q,q+=8}if(U-=G,J.total_out+=U,Q.total+=U,Q.wrap&4&&U)J.adler=Q.check=Q.flags?T7(Q.check,X,U,V-U):Jh(Q.check,X,U,V-U);if(U=G,Q.wrap&4&&(Q.flags?F:zg1(F))!==Q.check){J.msg="incorrect data check",Q.mode=Y9;break}F=0,q=0}Q.mode=Kg1;case Kg1:if(Q.wrap&&Q.flags){while(q<32){if(z===0)break $;z--,F+=Y[K++]<<q,q+=8}if(Q.wrap&4&&F!==(Q.total&4294967295)){J.msg="incorrect length check",Q.mode=Y9;break}F=0,q=0}Q.mode=Vg1;case Vg1:R=Jh6;break $;case Y9:R=fg1;break $;case bg1:return ug1;case hg1:default:return xX}if(J.next_out=V,J.avail_out=G,J.next_in=K,J.avail_in=z,Q.hold=F,Q.bits=q,Q.wsize||U!==J.avail_out&&Q.mode<Y9&&(Q.mode<kI0||Z!==hh1)){if(cg1(J,J.output,J.next_out,U-J.avail_out));}if(W-=J.avail_in,U-=J.avail_out,J.total_in+=W,J.total_out+=U,Q.total+=U,Q.wrap&4&&U)J.adler=Q.check=Q.flags?T7(Q.check,X,U,J.next_out-U):Jh(Q.check,X,U,J.next_out-U);if(J.data_type=Q.bits+(Q.last?64:0)+(Q.mode===fW?128:0)+(Q.mode===I40||Q.mode===SI0?256:0),(W===0&&U===0||Z===hh1)&&R===PE)R=Qh6;return R},Wh6=(J)=>{if(TE(J))return xX;let Z=J.state;if(Z.window)Z.window=null;return J.state=null,PE},Uh6=(J,Z)=>{if(TE(J))return xX;let Q=J.state;if((Q.wrap&2)===0)return xX;return Q.head=Z,Z.done=!1,PE},Dh6=(J,Z)=>{let Q=Z.length,Y,X,K;if(TE(J))return xX;if(Y=J.state,Y.wrap!==0&&Y.mode!==S40)return xX;if(Y.mode===S40){if(X=1,X=Jh(X,Z,Q,0),X!==Y.check)return fg1}if(K=cg1(J,Z,Q,Q),K)return Y.mode=bg1,ug1;return Y.havedict=1,PE},Hh6,Bh6,Nh6,wh6,Oh6,Lh6,Eh6,Mh6,Ah6,jh6="pako inflate (from Nodeca project)",bW,Ih6,lg1,Ph6,Ch6,Yh,xI0,fI0,Th6,Fg1,_h6,kh6,yh6,vh6,xh6,fh6,uh6,bh6,hh6,gh6,mh6,ph6,dh6,ch6,lh6,ih6,nh6,ah6,oh6,rh6,sh6,th6,eh6,$g6,ig1;var ng1=Y0(()=>{/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */sb=Xh+1+iI0,Wg1=2*sb+1,uI0=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),C40=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),qu6=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Bg1=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),uW=Array((sb+2)*2);IC(uW);ab=Array(AC*2);IC(ab);tb=Array(Wu6);IC(tb);eb=Array(Gu6-zu6+1);IC(eb);oI0=Array(iI0);IC(oI0);T40=Array(AC);IC(T40);Au6=Ou6,ju6=Rg1,Ru6=Eu6,Iu6=Mu6,Pu6=Lu6,Cu6={_tr_init:Au6,_tr_stored_block:ju6,_tr_flush_block:Ru6,_tr_tally:Iu6,_tr_align:Pu6},Jh=Tu6,Su6=new Uint32Array(_u6()),T7=ku6,RE={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},CE={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8},{_tr_init:yu6,_tr_stored_block:hI0,_tr_flush_block:vu6,_tr_tally:sH,_tr_align:xu6}=Cu6,{Z_NO_FLUSH:tH,Z_PARTIAL_FLUSH:fu6,Z_FULL_FLUSH:uu6,Z_FINISH:vX,Z_BLOCK:kh1,Z_OK:w$,Z_STREAM_END:yh1,Z_STREAM_ERROR:gG,Z_DATA_ERROR:bu6,Z_BUF_ERROR:PI0,Z_DEFAULT_COMPRESSION:hu6,Z_FILTERED:gu6,Z_HUFFMAN_ONLY:A40,Z_RLE:mu6,Z_FIXED:pu6,Z_DEFAULT_STRATEGY:du6,Z_UNKNOWN:cu6,Z_DEFLATED:k40}=CE,gI0=ou6+1+au6,tu6=2*gI0+1,mG=rH+i5+1,eH=Qb6;nb=[new bG(0,0,0,0,Pg1),new bG(4,4,8,4,CI0),new bG(4,5,16,8,CI0),new bG(4,6,32,32,CI0),new bG(4,4,16,16,EC),new bG(8,16,32,32,EC),new bG(8,16,128,128,EC),new bG(8,32,128,256,EC),new bG(32,128,258,1024,EC),new bG(32,258,258,4096,EC)];Ub6=Gb6,Db6=_g1,Hb6=Tg1,Bb6=Cg1,Nb6=zb6,wb6=Fb6,Ob6=qb6,Lb6=Wb6,ob={deflateInit:Ub6,deflateInit2:Db6,deflateReset:Hb6,deflateResetKeep:Bb6,deflateSetHeader:Nb6,deflate:wb6,deflateEnd:Ob6,deflateSetDictionary:Lb6,deflateInfo:Eb6},y40={assign:Ab6,flattenChunks:jb6};try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(J){Sg1=!1}Zh=new Uint8Array(256);for(let J=0;J<256;J++)Zh[J]=J>=252?6:J>=248?5:J>=240?4:J>=224?3:J>=192?2:1;Zh[254]=Zh[254]=1;Qh={string2buf:Rb6,buf2string:Pb6,utf8border:Cb6};kg1=Tb6,yg1=Object.prototype.toString,{Z_NO_FLUSH:_b6,Z_SYNC_FLUSH:Sb6,Z_FULL_FLUSH:kb6,Z_FINISH:yb6,Z_OK:_40,Z_STREAM_END:vb6,Z_DEFAULT_COMPRESSION:xb6,Z_DEFAULT_STRATEGY:fb6,Z_DEFLATED:ub6}=CE;Vh.prototype.push=function(J,Z){let Q=this.strm,Y=this.options.chunkSize,X,K;if(this.ended)return!1;if(Z===~~Z)K=Z;else K=Z===!0?yb6:_b6;if(typeof J==="string")Q.input=Qh.string2buf(J);else if(yg1.call(J)==="[object ArrayBuffer]")Q.input=new Uint8Array(J);else Q.input=J;Q.next_in=0,Q.avail_in=Q.input.length;for(;;){if(Q.avail_out===0)Q.output=new Uint8Array(Y),Q.next_out=0,Q.avail_out=Y;if((K===Sb6||K===kb6)&&Q.avail_out<=6){this.onData(Q.output.subarray(0,Q.next_out)),Q.avail_out=0;continue}if(X=ob.deflate(Q,K),X===vb6){if(Q.next_out>0)this.onData(Q.output.subarray(0,Q.next_out));return X=ob.deflateEnd(this.strm),this.onEnd(X),this.ended=!0,X===_40}if(Q.avail_out===0){this.onData(Q.output);continue}if(K>0&&Q.next_out>0){this.onData(Q.output.subarray(0,Q.next_out)),Q.avail_out=0;continue}if(Q.avail_in===0)break}return!0};Vh.prototype.onData=function(J){this.chunks.push(J)};Vh.prototype.onEnd=function(J){if(J===_40)this.result=y40.flattenChunks(this.chunks);this.chunks=[],this.err=J,this.msg=this.strm.msg};gb6=Vh,mb6=sI0,pb6=bb6,db6=hb6,cb6=CE,lb6={Deflate:gb6,deflate:mb6,deflateRaw:pb6,gzip:db6,constants:cb6},ab6=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),ob6=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),rb6=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),sb6=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),rb=tb6,{Z_FINISH:hh1,Z_BLOCK:$h6,Z_TREES:R40,Z_OK:PE,Z_STREAM_END:Jh6,Z_NEED_DICT:Zh6,Z_STREAM_ERROR:xX,Z_DATA_ERROR:fg1,Z_MEM_ERROR:ug1,Z_BUF_ERROR:Qh6,Z_DEFLATED:gh1}=CE,Vh6=Kh6;Hh6=mg1,Bh6=pg1,Nh6=gg1,wh6=Gh6,Oh6=dg1,Lh6=qh6,Eh6=Wh6,Mh6=Uh6,Ah6=Dh6,bW={inflateReset:Hh6,inflateReset2:Bh6,inflateResetKeep:Nh6,inflateInit:wh6,inflateInit2:Oh6,inflate:Lh6,inflateEnd:Eh6,inflateGetHeader:Mh6,inflateSetDictionary:Ah6,inflateInfo:jh6};Ih6=Rh6,lg1=Object.prototype.toString,{Z_NO_FLUSH:Ph6,Z_FINISH:Ch6,Z_OK:Yh,Z_STREAM_END:xI0,Z_NEED_DICT:fI0,Z_STREAM_ERROR:Th6,Z_DATA_ERROR:Fg1,Z_MEM_ERROR:_h6}=CE;zh.prototype.push=function(J,Z){let Q=this.strm,Y=this.options.chunkSize,X=this.options.dictionary,K,V,z;if(this.ended)return!1;if(Z===~~Z)V=Z;else V=Z===!0?Ch6:Ph6;if(lg1.call(J)==="[object ArrayBuffer]")Q.input=new Uint8Array(J);else Q.input=J;Q.next_in=0,Q.avail_in=Q.input.length;for(;;){if(Q.avail_out===0)Q.output=new Uint8Array(Y),Q.next_out=0,Q.avail_out=Y;if(K=bW.inflate(Q,V),K===fI0&&X){if(K=bW.inflateSetDictionary(Q,X),K===Yh)K=bW.inflate(Q,V);else if(K===Fg1)K=fI0}while(Q.avail_in>0&&K===xI0&&Q.state.wrap>0&&J[Q.next_in]!==0)bW.inflateReset(Q),K=bW.inflate(Q,V);switch(K){case Th6:case Fg1:case fI0:case _h6:return this.onEnd(K),this.ended=!0,!1}if(z=Q.avail_out,Q.next_out){if(Q.avail_out===0||K===xI0)if(this.options.to==="string"){let G=Qh.utf8border(Q.output,Q.next_out),F=Q.next_out-G,q=Qh.buf2string(Q.output,G);if(Q.next_out=F,Q.avail_out=Y-F,F)Q.output.set(Q.output.subarray(G,G+F),0);this.onData(q)}else this.onData(Q.output.length===Q.next_out?Q.output:Q.output.subarray(0,Q.next_out))}if(K===Yh&&z===0)continue;if(K===xI0)return K=bW.inflateEnd(this.strm),this.onEnd(K),this.ended=!0,!0;if(Q.avail_in===0)break}return!0};zh.prototype.onData=function(J){this.chunks.push(J)};zh.prototype.onEnd=function(J){if(J===Yh)if(this.options.to==="string")this.result=this.chunks.join("");else this.result=y40.flattenChunks(this.chunks);this.chunks=[],this.err=J,this.msg=this.strm.msg};kh6=zh,yh6=tI0,vh6=Sh6,xh6=tI0,fh6=CE,uh6={Inflate:kh6,inflate:yh6,inflateRaw:vh6,ungzip:xh6,constants:fh6},{Deflate:bh6,deflate:hh6,deflateRaw:gh6,gzip:mh6}=lb6,{Inflate:ph6,inflate:dh6,inflateRaw:ch6,ungzip:lh6}=uh6,ih6=bh6,nh6=hh6,ah6=gh6,oh6=mh6,rh6=ph6,sh6=dh6,th6=ch6,eh6=lh6,$g6=CE,ig1={Deflate:ih6,deflate:nh6,deflateRaw:ah6,gzip:oh6,Inflate:rh6,inflate:sh6,inflateRaw:th6,ungzip:eh6,constants:$g6}});function Jg6(J){if(J.proxy&&!process.env.HTTP_PROXY&&!process.env.http_proxy)process.env.HTTP_PROXY=J.proxy;if(J.proxy&&!process.env.HTTPS_PROXY&&!process.env.https_proxy)process.env.HTTPS_PROXY=J.proxy}function ag1(J){return J.config.pipe(q4(({settings:Z,secrets:Q})=>{return T4(async()=>{return await Q.getToken("apiKey",Z.url)!==void 0})}))}function $B(J,Z,Q){let Y=Q?`/threads/${Z}/${Q}`:`/threads/${Z}`;return new URL(Y,J)}async function f3(J,Z,Q){let Y=await Q.getLatest(Z?.signal??void 0),X=await rg1(J,Z,Y);return fetch(X)}async function og1(J,Z,Q){let Y=await rg1(Z,Q,J);return fetch(Y)}async function rg1(J,Z,Q){if(J.startsWith("http:")||J.startsWith("https:"))throw Error("input must be a path, not an absolute URL");if(!J.startsWith("/"))throw Error("pathAndQuery must start with /");let Y=Q.settings.url;if(!Y)throw Error("amp.url is not set");let X=await Q.secrets.getToken("apiKey",Y);Jg6({proxy:Q.settings.proxy});let K=new URL(J,Y);return new Request(K,{...Z,duplex:"half",headers:{"Content-Type":"application/json",...Z?.headers,...T2(),...X?{Authorization:`Bearer ${X}`}:{}}})}async function sg1(J,Z,Q,Y,X){let K=await J.get(Z);if(!K)throw Error(`Thread not found: ${Z}`);let V=await g6.shareThreadWithOperator({threadData:K,message:Y||void 0,ephemeralError:X||void 0},{config:Q});if(!V.ok)throw Error(`Failed to share thread: ${V.error.message}`)}async function x40(J,Z){let Q=await f3("/api/telemetry",{method:"POST",redirect:"manual",body:J},Z);if(!Q.ok){let Y=await Q.text(),X;try{X=JSON.parse(Y).error||`HTTP ${Q.status}`}catch{X=Y||`HTTP ${Q.status}`}throw Error(`Failed to submit telemetry: ${X}`)}}var O$=Y0(()=>{N1();ZJ();rJ()});function Qg6(J){if(new Blob([J]).size<=Zg6)return{body:J};return{body:ig1.gzip(J),headers:{"Content-Encoding":"gzip"}}}function Yg6(){return new Proxy({},{get:(J,Z)=>{return async(...Q)=>{let Y=Q.at(1),X=Q.at(0);if(!Y?.config)throw Error("Internal API client requires configService in options. Call with { config: configService }");let{body:K,headers:V={}}=Qg6(JSON.stringify({method:Z,params:X})),z=await f3("/api/internal?"+encodeURIComponent(Z),{method:"POST",body:K,headers:V,signal:Y?.signal},Y.config);if(!z.ok)throw Error(`API request for ${Z} failed: ${z.status}`);return await z.json()}}})}var Zg6=25600,g6;var rJ=Y0(()=>{ng1();O$();g6=Yg6()});function Xg6(J){return J.config.pipe(W1(({settings:Z,secrets:Q})=>({url:Z.url,proxy:Z.proxy,secrets:Q})),y4(cb),q4((Z)=>gP(600000).pipe(z5(void 0),pP(()=>T4(async(Q)=>{let Y=await g6.getUserInfo({},{signal:Q,config:J});if(Y.ok)return Y.result;if(Y.error&&Y.error.code==="auth-required")return null;throw I.error("getUserInfo failed",{error:Y.error}),Error(`getUserInfo error: ${Y.error.code}`)})))),W1((Z)=>{return Z instanceof Error?{error:{message:String(Z)}}:Z===CG?"pending":Z?{user:Z,features:Z.features,workspace:Z?.team,mysteriousMessage:Z?.mysteriousMessage}:{error:{message:"User not found"}}}),y4((Z,Q)=>cb(Z,Q)),c6({shouldCountRefs:!0}))}function eZ(J){let Z=tg1.get(J);if(Z)return Z;let Q=Xg6(J);return tg1.set(J,Q),Q}function m6(J){return Boolean(typeof J==="object"&&"user"in J&&J.user)}function hW(J){return typeof J==="object"&&"error"in J}var tg1;var fX=Y0(()=>{N1();g0();rJ();tg1=new WeakMap});function f40(J,Z,Q){if(J.startsWith("mcp__"))return Z.allowMcp??!1;if(J.startsWith("tb__")){if(!(Z.allowToolbox??!1))return!1;let Y="subagentType"in Z?Z.subagentType:void 0;if(Y&&Q){if(!Q.subagentTypes)return!1;return Q.subagentTypes.includes("all")||Q.subagentTypes.includes(Y)}return!0}return Z.includeTools.includes(J)}var eI0,eg1,Kg6,$P0,Vg6,zg6,Gg6,Fg6,JP0,f8,Y58;var uX=Y0(()=>{I7();eI0=["read_github","search_github","commit_search","diff","list_directory_github","list_repositories","glob_github"],eg1=["read_bitbucket_enterprise","search_bitbucket_enterprise","commit_search_bitbucket_enterprise","diff_bitbucket_enterprise","list_directory_bitbucket_enterprise","list_repositories_bitbucket_enterprise","glob_bitbucket_enterprise"],Kg6=["Grep","glob","Read"],$P0=["Read","Grep","glob","web_search","read_web_page","read_thread","find_thread"],Vg6=["Grep","glob","Read","Bash","edit_file","create_file","read_web_page","get_diagnostics","web_search","finder","skill","task_list","look_at"],zg6=["Read","Grep","glob","web_search","read_web_page","Bash"],Gg6=["Read","Grep","glob","web_search","read_web_page","Bash","eval_git_diff","post_explanation"],Fg6=["Read","Grep","glob","Bash"],JP0=["Read","Grep","glob","finder"],f8={finder:{key:"finder",displayName:"Finder",model:i3("CLAUDE_HAIKU_4_5"),includeTools:Kg6,allowMcp:!1,allowToolbox:!1},oracle:{key:"oracle",displayName:"Oracle",model:i3("GPT_5_4"),includeTools:$P0,allowMcp:!1,allowToolbox:!1},librarian:{key:"librarian",displayName:"Librarian",model:i3("CLAUDE_SONNET_4_6"),includeTools:eI0,allowMcp:!1,allowToolbox:!1},"task-subagent":{key:"task-subagent",displayName:"Task Subagent",model:void 0,includeTools:Vg6,allowMcp:!0,allowToolbox:!0},"code-review":{key:"code-review",displayName:"Code Review",model:i3("CLAUDE_SONNET_4_5"),includeTools:zg6,allowMcp:!1,allowToolbox:!1},"code-tour":{key:"code-tour",displayName:"Code Tour",model:i3("CLAUDE_OPUS_4_6"),includeTools:Gg6,allowMcp:!1,allowToolbox:!1},"codereview-check":{key:"codereview-check",displayName:"Codereview Check",model:i3("CLAUDE_HAIKU_4_5"),includeTools:Fg6,allowMcp:!1,allowToolbox:!1}},Y58=Object.keys(f8)});function $m1(J,Z){return new k0((Q)=>{let Y=setTimeout(X,Z);function X(){Q.error(Error(`Tool execution timed out after ${Z/1000} seconds`))}function K(){if(Y)clearTimeout(Y);Y=setTimeout(X,Z)}let V=J.subscribe({next:(z)=>{K(),Q.next(z)},error:(z)=>{if(Y)clearTimeout(Y),Y=null;Q.error(z)},complete:()=>{if(Y)clearTimeout(Y),Y=null;Q.complete()}});return()=>{if(Y)clearTimeout(Y),Y=null;V.unsubscribe()}})}var Jm1=Y0(()=>{N1()});function Qm1(J){return{tool:J,action:"allow"}}function qg6(J){if(!J||!("cmd"in J))return J;let{cmd:Z,...Q}=J;return{...Q,command:Z}}function Wg6(J){return J.flatMap((Z)=>{if(Z.tool!==i6)return[];return[{...Z,tool:JY,matches:qg6(Z.matches)}]})}var Zm1,TC;var u40=Y0(()=>{P4();Zm1=[{tool:"Bash",action:"ask",matches:{cmd:"*git*push*"}},{tool:"mcp__*",action:"allow"},{tool:z10,action:"allow"},{tool:"tb__*",action:"allow"},{tool:"Bash",matches:{cmd:"/^(.*\\s+)?(bazel|ibazel)\\s+.*\\/\\/[^\\s]*.*$/"},action:"allow"},{tool:"Bash",matches:{cmd:["ls","ls *","dir","dir *","cat *","head *","tail *","less *","more *","grep *","egrep *","fgrep *","tree","tree *","file *","wc *","pwd","stat *","du *","df *","ps *","top","htop","echo *","printenv *","id","which *","whereis *","date","cal *","uptime","free *","ping *","dig *","nslookup *","host *","netstat *","ss *","lsof *","ifconfig *","ip *","man *","info *","mkdir *","touch *","uname *","whoami","go version","go env *","go help *","cargo version","cargo --version","cargo help *","rustc --version","rustc --help","rustc --explain *","javac --version","javac -version","javac -help","javac --help","dotnet --info","dotnet --version","dotnet --help","dotnet help *","gcc --version","gcc -v","gcc --help","gcc -dumpversion","g++ --version","g++ -v","g++ --help","g++ -dumpversion","clang --version","clang --help","clang++ --version","clang++ --help","python -V","python --version","python -h","python --help","python3 -V","python3 --version","python3 -h","python3 --help","ruby -v","ruby --version","ruby -h","ruby --help","node -v","node --version","node -h","node --help","npm --help","npm --version","npm -v","npm help *","yarn --help","yarn --version","yarn -v","yarn help *","pnpm --help","pnpm --version","pnpm -v","pnpm help *","pytest -h","pytest --help","pytest --version","jest --help","jest --version","mocha --help","mocha --version","make --version","make --help","docker --version","docker --help","docker version","docker help *","git --version","git --help","git help *","git version"]},action:"allow"},{tool:"Bash",matches:{cmd:["go test *","go run *","go build *","go vet *","go fmt *","go list *","cargo test *","cargo run *","cargo build *","cargo check *","cargo fmt *","cargo tree *","make -n *","make --dry-run *","mvn test *","mvn verify *","mvn dependency:tree *","gradle tasks *","gradle dependencies *","gradle properties *","dotnet test *","dotnet list *","python -c *","ruby -e *","node -e *","npm list *","npm ls *","npm outdated *","npm test*","npm run*","npm view *","npm info *","yarn list*","yarn ls *","yarn info *","yarn test*","yarn run *","yarn why *","pnpm list*","pnpm ls *","pnpm outdated *","pnpm test*","pnpm run *","pytest --collect-only *","jest --listTests *","jest --showConfig *","mocha --list *","git status*","git show *","git diff*","git grep *","git branch *","git tag *","git remote -v *","git rev-parse --is-inside-work-tree *","git rev-parse --show-toplevel *","git config --list *","git log *"]},action:"allow"},{tool:"Bash",matches:{cmd:["./gradlew *","./mvnw *","./build.sh *","./configure *","cmake *","./node_modules/.bin/tsc *","./node_modules/.bin/eslint *","./node_modules/.bin/prettier *","prettier *","./node_modules/.bin/tailwindcss *","./node_modules/.bin/tsx *","./node_modules/.bin/vite *","bun *","tsx *","vite *"]},action:"allow"},{tool:"Bash",matches:{cmd:[".venv/bin/activate *",".venv/Scripts/activate *","source .venv/bin/activate *","source venv/bin/activate *","pip list *","pip show *","pip check *","pip freeze *","uv *","poetry show *","poetry check *","pipenv check *"]},action:"allow"},{tool:"Bash",matches:{cmd:["asdf list *","asdf current *","asdf which *","mise list *","mise current *","mise which *","mise use *","rbenv version *","rbenv versions *","rbenv which *","nvm list *","nvm current *","nvm which *"]},action:"allow"},{tool:"Bash",matches:{cmd:["./test*","./run_tests.sh *","./run_*_tests.sh *","vitest *","bundle exec rspec *","bundle exec rubocop *","rspec *","rubocop *","swiftlint *","clippy *","ruff *","black *","isort *","mypy *","flake8 *","bandit *","safety *","biome check *","biome format *"]},action:"allow"},{tool:"Bash",matches:{cmd:["rails server *","rails s *","bin/rails server *","bin/rails s *","flask run *","django-admin runserver *","python manage.py runserver *","uvicorn *","streamlit run *"]},action:"allow"},{tool:"Bash",matches:{cmd:["bin/rails db:status","bin/rails db:version","rails db:rollback *","rails db:status *","rails db:version *","alembic current *","alembic history *","bundle exec rails db:status","bundle exec rails db:version"]},action:"allow"},{tool:"Bash",matches:{cmd:["docker ps *","docker images *","docker logs *","docker inspect *","docker info *","docker stats *","docker system df *","docker system info *","podman ps *","podman images *","podman logs *","podman inspect *","podman info *"]},action:"allow"},{tool:"Bash",matches:{cmd:["aws --version *","aws configure list *","aws sts get-caller-identity *","aws s3 ls *","gcloud config list *","gcloud auth list *","gcloud projects list *","az account list *","az account show *","kubectl get *","kubectl describe *","kubectl logs *","kubectl version *","helm list *","helm status *","helm version *"]},action:"allow"},{tool:"Bash",matches:{cmd:["swift build *","swift test *","zig build *","zig build test*","kotlinc *","scalac *","javac *","javap *","clang *","jar *","sbt *","gradle *","bazel build *","bazel test *","bazel run *","mix *","lua *","ruby *","php *"]},action:"allow"},{tool:"Bash",matches:{cmd:["mkdir -p *","chmod +x *","dos2unix *","unix2dos *","ln -s *"]},action:"allow"},{tool:"Bash",matches:{cmd:["for *","while *","do *","done *","if *","then *","else *","elif *","fi *","case *","esac *","in *","function *","select *","until *","{ *","} *","[[ *","]] *"]},action:"ask"},{tool:"Bash",matches:{cmd:"/^find(?!.*(-delete|-exec|-execdir)).*$/"},action:"allow"},{tool:"Bash",matches:{cmd:"/^(echo|ls|pwd|date|whoami|id|uname)\\s.*[&|;].*\\s*(echo|ls|pwd|date|whoami|id|uname)($|\\s.*)/"},action:"allow"},{tool:"Bash",matches:{cmd:"/^(cat|grep|head|tail|less|more|find)\\s.*\\|\\s*(grep|head|tail|less|more|wc|sort|uniq)($|\\s.*)/"},action:"allow"},{tool:"Bash",matches:{cmd:"/^rm\\s+.*(-[rf].*-[rf]|-[rf]{2,}|--recursive.*--force|--force.*--recursive).*$/"},action:"ask"},{tool:"Bash",matches:{cmd:"/^find.*(-delete|-exec|-execdir).*$/"},action:"ask"},{tool:"Bash",matches:{cmd:"/^(ls|cat|grep|head|tail|file|stat)\\s+[^/]*$/"},action:"allow"},{tool:"Bash",matches:{cmd:"/(^|\\s)(\\/(?!dev\\/(null|zero|stdout|stderr|stdin))[^\\s]*|\\.\\.\\/)(?![^\\s]*\\.(log|txt|md|json|yml|yaml)$)/"},action:"ask"},{tool:"Bash",action:"ask"},Qm1("Glob")],TC=[...Zm1,...Wg6(Zm1),...bx1.map(Qm1)]});class Ym1{input;position=0;line=1;column=1;tokens=[];constructor(J){this.input=J}current(){return this.position<this.input.length?this.input[this.position]:""}peek(){return this.position+1<this.input.length?this.input[this.position+1]:""}advance(){let J=this.current();if(this.position++,J===`
120
120
  `)this.line++,this.column=1;else this.column++;return J}skipWhitespace(){while(this.current()&&/\s/.test(this.current())&&this.current()!==`
121
121
  `)this.advance()}readString(){let J="",Z=this.current();this.advance();while(this.current()&&this.current()!==Z)if(this.current()==="\\"&&this.peek()===Z)this.advance(),J+=this.advance();else J+=this.advance();if(!this.current())throw Error("Unterminated string");return this.advance(),J}readIdentifier(){let J="";if(this.current()==="-"&&/\d/.test(this.peek()))J+=this.advance();while(this.current()&&/[a-zA-Z0-9_*.-]/.test(this.current()))J+=this.advance();if((this.current()==="e"||this.current()==="E")&&/[-+]?\d/.test(this.peek())){if(J+=this.advance(),this.current()==="+"||this.current()==="-")J+=this.advance();while(this.current()&&/\d/.test(this.current()))J+=this.advance()}return J}readFlag(){let J="";this.advance(),this.advance();while(this.current()&&/[a-zA-Z0-9_*:.-]/.test(this.current()))J+=this.advance();return J}readComment(){let J="";this.advance();while(this.current()&&this.current()!==`
122
122
  `)J+=this.advance();return J.trim()}tokenize(){this.tokens=[];while(this.position<this.input.length){let J={position:this.position,line:this.line,column:this.column};if(this.skipWhitespace(),!this.current())break;if(this.current()==="'"||this.current()==='"'){try{let Z=this.readString();this.tokens.push({type:"STRING",value:Z,...J})}catch(Z){throw Error(`Parse error at line ${this.line}, column ${this.column}: ${Z}`)}continue}if(this.current()===`
@@ -6159,11 +6159,11 @@ ${D}`))}},error:(U)=>{if(!W)W=!0,z(Error(`Failed to spawn brew: ${U.message}`))}
6159
6159
  ${D}`;if(X==="pnpm"&&D.includes("Unable to find the global bin directory"))H+=`
6160
6160
 
6161
6161
  Hint: Try running "pnpm setup" to configure pnpm global directory, or use npm instead:
6162
- npm install -g @sourcegraph/amp`;z(Error(H))}},error:(U)=>{if(!q)q=!0,z(Error(`Failed to spawn ${X}: ${U.message}`))},complete:()=>{if(!q)q=!0,V()}})})}g0();g0();nM();async function VQ0(J,Z){let X=`${Z||"https://registry.npmjs.org"}/@sourcegraph/amp/latest`,K=new AbortController,V=setTimeout(()=>K.abort(),5000);try{let z=await fetch(X,{signal:K.signal});if(!z.ok)return{hasUpdate:!1,currentVersion:J,source:"npm"};let G=await z.json(),F=G.version??G["dist-tags"]?.latest;if(!F)return{hasUpdate:!1,currentVersion:J,source:"npm"};let q=jL4(J,F),W=q<0,U,D;if(G.time){let H=G.time[J],B=G.time[F],N=Date.now();if(H)U=Math.floor((N-new Date(H).getTime())/3600000);if(B)D=Math.floor((N-new Date(B).getTime())/3600000)}return I.info("NPM version comparison",{currentVersion:J,latestVersion:F,compareResult:q,hasUpdate:W,currentVersionAge:U,latestVersionAge:D}),{hasUpdate:W,latestVersion:F,currentVersion:J,currentVersionAge:U,latestVersionAge:D,source:"npm"}}catch(z){return I.debug("Error checking npm version",{error:z}),{hasUpdate:!1,currentVersion:J,source:"npm"}}finally{clearTimeout(V)}}var Fa5="https://storage.googleapis.com/amp-public-assets-prod-0/cli/cli-version.txt";async function zQ0(J){let Z=new AbortController,Q=setTimeout(()=>Z.abort(),5000);try{let Y=await fetch(`${Fa5}?t=${Date.now()}`,{signal:Z.signal,cache:"no-store"});if(!Y.ok)return{hasUpdate:!1,currentVersion:J,source:"bin"};let X=(await Y.text()).trim();if(!X||!/^\d+\.\d+\.\d+/.test(X))return{hasUpdate:!1,currentVersion:J,source:"bin"};let K=jL4(J,X),V=K<0;return I.info("Bin version comparison",{currentVersion:J,latestVersion:X,compareResult:K,hasUpdate:V}),{hasUpdate:V,latestVersion:X,currentVersion:J,source:"bin"}}catch(Y){return I.debug("Error checking bin version",{error:Y}),{hasUpdate:!1,currentVersion:J,source:"bin"}}finally{clearTimeout(Q)}}var qa5=604800000;function AL4(J){if(!J)return null;let Z=typeof J==="number"?J:new Date(J).getTime();if(isNaN(Z))return null;let Q=Date.now()-Z;if(Q>qa5)return{ageMs:Q};return null}function jL4(J,Z){let Q=(V)=>{let[z,G]=V.split("-");return{parts:z?.split(".").map(Number)||[],label:G}},Y=Q(J),X=Q(Z),K=Math.max(Y.parts.length,X.parts.length);for(let V=0;V<K;V++){let z=Y.parts[V]||0,G=X.parts[V]||0;if(z<G)return-1;if(z>G)return 1}if(Y.label===X.label)return 0;if(!Y.label&&X.label)return 1;if(Y.label&&!X.label)return-1;if(Y.label&&X.label)return Y.label<X.label?-1:1;return 0}function Il0(J){try{let Z=J.match(/^0\.0\.(\d+)(?:-g?([a-f0-9]+))?/);if(!Z)return null;let Q=parseInt(Z[1],10)*1000,Y=Z[2],X=Q!==0?EF(Q):void 0;return{sha:Y,age:X}}catch{return null}}N1();function Pl0(J,Z,Q={}){let Y=new s1,X=Y.pipe(c6({shouldCountRefs:!1}));return setImmediate(async()=>{let K=new PG().scoped("update"),V=Q.startDelayMs??0;if(V>0)await eG(V);let z=X.subscribe({next:(G)=>{K.debug("emit new state",G)}});try{let G=process.env.AMP_TEST_UPDATE_STATUS;if(G){K.debug("using fake update status for testing",{status:G}),await eG(500),Y.next(G);return}if(process.env.AMP_SKIP_UPDATE_CHECK==="1"){K.debug("checking disabled via AMP_SKIP_UPDATE_CHECK environment variable");return}let F=await Z.get("updates.mode");if(F==="disabled"){K.debug("checking disabled");return}let q=await KQ0(),W=q==="binary"||q==="brew";K.debug("checking",{currentVersion:J,mode:F,packageManager:q,isBinaryDistribution:W});let U=W?await zQ0(J):await VQ0(J,eA());if(!(U.latestVersion&&U.hasUpdate)){K.debug("no update available");return}let D=()=>{if(U.currentVersionAge!==void 0&&U.latestVersionAge!==void 0){let H=U.currentVersionAge-U.latestVersionAge,B=0.5;if(Math.abs(H)<0.5)return K.debug("versions too close together, suppressing update warning",{currentVersionAge:U.currentVersionAge,latestVersionAge:U.latestVersionAge,ageDifferenceHours:H}),!0}return!1};if(!F)F=q==="pnpm"?"warn":"auto",K.debug("no configured update mode; selected default based on package manager",{packageManager:q,mode:F});if(q==="brew"){if(!D())Y.next("update-available-brew");return}if(q==="binary"&&process.execPath!==Ll0()){if(K.debug("non-standard binary path, showing warning"),!D())Y.next("update-available-unrecognized-path");return}if(F==="warn"){if(!D())Y.next("update-available");return}if(!q){if(K.debug("auto-update not supported, falling back to warn mode"),!D())Y.next("update-available");return}if(q==="binary"&&process.platform==="win32"){if(K.debug("binary auto-update not supported on Windows, falling back to warn mode"),!D())Y.next("update-available");return}try{await pl(U.latestVersion,q);let H=await tN(U.latestVersion),B={from:U.currentVersion,to:U.latestVersion,...H};if(H.status==="same")K.info("success",B),Y.next("updated");else K.warn("success with warning",B),Y.next("updated-with-warning")}catch(H){Y.next("update-error")}}catch(G){K.debug("check failed",{error:G})}finally{await eG(5000),Y.next("hidden"),z.unsubscribe(),Y.complete()}}),{state:X}}nM();import{stderr as oF}from"node:process";function RL4(J){let Z=new mN().name("install").description("Install required tools like ripgrep to $AMP_HOME/bin").option("--force","Force reinstallation even if already installed").option("--verbose","Show installation progress and results").action(async(Y)=>{await Bl0(Y.force||!1,Y.verbose||!1,"0.0.1774123285-gb6e451"),process.exit()});J.addCommand(Z,{hidden:!0});let Q=new mN("update").alias("up").summary("Update Amp CLI").description("Update Amp CLI to the latest version. You can specify a particular version to install, or leave blank to get the latest stable release.").option("--target-version <version>","Update to a specific version").allowUnknownOption(!1).action(async(Y)=>{await Wa5(Y.targetVersion)});J.addCommand(Q)}async function Wa5(J){if(process.env.AMP_SKIP_UPDATE_CHECK==="1")oF.write(c0.yellow(`Note: AMP_SKIP_UPDATE_CHECK=1 is set, which disables automatic update checking. Manual updates will still work.
6162
+ npm install -g @sourcegraph/amp`;z(Error(H))}},error:(U)=>{if(!q)q=!0,z(Error(`Failed to spawn ${X}: ${U.message}`))},complete:()=>{if(!q)q=!0,V()}})})}g0();g0();nM();async function VQ0(J,Z){let X=`${Z||"https://registry.npmjs.org"}/@sourcegraph/amp/latest`,K=new AbortController,V=setTimeout(()=>K.abort(),5000);try{let z=await fetch(X,{signal:K.signal});if(!z.ok)return{hasUpdate:!1,currentVersion:J,source:"npm"};let G=await z.json(),F=G.version??G["dist-tags"]?.latest;if(!F)return{hasUpdate:!1,currentVersion:J,source:"npm"};let q=jL4(J,F),W=q<0,U,D;if(G.time){let H=G.time[J],B=G.time[F],N=Date.now();if(H)U=Math.floor((N-new Date(H).getTime())/3600000);if(B)D=Math.floor((N-new Date(B).getTime())/3600000)}return I.info("NPM version comparison",{currentVersion:J,latestVersion:F,compareResult:q,hasUpdate:W,currentVersionAge:U,latestVersionAge:D}),{hasUpdate:W,latestVersion:F,currentVersion:J,currentVersionAge:U,latestVersionAge:D,source:"npm"}}catch(z){return I.debug("Error checking npm version",{error:z}),{hasUpdate:!1,currentVersion:J,source:"npm"}}finally{clearTimeout(V)}}var Fa5="https://storage.googleapis.com/amp-public-assets-prod-0/cli/cli-version.txt";async function zQ0(J){let Z=new AbortController,Q=setTimeout(()=>Z.abort(),5000);try{let Y=await fetch(`${Fa5}?t=${Date.now()}`,{signal:Z.signal,cache:"no-store"});if(!Y.ok)return{hasUpdate:!1,currentVersion:J,source:"bin"};let X=(await Y.text()).trim();if(!X||!/^\d+\.\d+\.\d+/.test(X))return{hasUpdate:!1,currentVersion:J,source:"bin"};let K=jL4(J,X),V=K<0;return I.info("Bin version comparison",{currentVersion:J,latestVersion:X,compareResult:K,hasUpdate:V}),{hasUpdate:V,latestVersion:X,currentVersion:J,source:"bin"}}catch(Y){return I.debug("Error checking bin version",{error:Y}),{hasUpdate:!1,currentVersion:J,source:"bin"}}finally{clearTimeout(Q)}}var qa5=604800000;function AL4(J){if(!J)return null;let Z=typeof J==="number"?J:new Date(J).getTime();if(isNaN(Z))return null;let Q=Date.now()-Z;if(Q>qa5)return{ageMs:Q};return null}function jL4(J,Z){let Q=(V)=>{let[z,G]=V.split("-");return{parts:z?.split(".").map(Number)||[],label:G}},Y=Q(J),X=Q(Z),K=Math.max(Y.parts.length,X.parts.length);for(let V=0;V<K;V++){let z=Y.parts[V]||0,G=X.parts[V]||0;if(z<G)return-1;if(z>G)return 1}if(Y.label===X.label)return 0;if(!Y.label&&X.label)return 1;if(Y.label&&!X.label)return-1;if(Y.label&&X.label)return Y.label<X.label?-1:1;return 0}function Il0(J){try{let Z=J.match(/^0\.0\.(\d+)(?:-g?([a-f0-9]+))?/);if(!Z)return null;let Q=parseInt(Z[1],10)*1000,Y=Z[2],X=Q!==0?EF(Q):void 0;return{sha:Y,age:X}}catch{return null}}N1();function Pl0(J,Z,Q={}){let Y=new s1,X=Y.pipe(c6({shouldCountRefs:!1}));return setImmediate(async()=>{let K=new PG().scoped("update"),V=Q.startDelayMs??0;if(V>0)await eG(V);let z=X.subscribe({next:(G)=>{K.debug("emit new state",G)}});try{let G=process.env.AMP_TEST_UPDATE_STATUS;if(G){K.debug("using fake update status for testing",{status:G}),await eG(500),Y.next(G);return}if(process.env.AMP_SKIP_UPDATE_CHECK==="1"){K.debug("checking disabled via AMP_SKIP_UPDATE_CHECK environment variable");return}let F=await Z.get("updates.mode");if(F==="disabled"){K.debug("checking disabled");return}let q=await KQ0(),W=q==="binary"||q==="brew";K.debug("checking",{currentVersion:J,mode:F,packageManager:q,isBinaryDistribution:W});let U=W?await zQ0(J):await VQ0(J,eA());if(!(U.latestVersion&&U.hasUpdate)){K.debug("no update available");return}let D=()=>{if(U.currentVersionAge!==void 0&&U.latestVersionAge!==void 0){let H=U.currentVersionAge-U.latestVersionAge,B=0.5;if(Math.abs(H)<0.5)return K.debug("versions too close together, suppressing update warning",{currentVersionAge:U.currentVersionAge,latestVersionAge:U.latestVersionAge,ageDifferenceHours:H}),!0}return!1};if(!F)F=q==="pnpm"?"warn":"auto",K.debug("no configured update mode; selected default based on package manager",{packageManager:q,mode:F});if(q==="brew"){if(!D())Y.next("update-available-brew");return}if(q==="binary"&&process.execPath!==Ll0()){if(K.debug("non-standard binary path, showing warning"),!D())Y.next("update-available-unrecognized-path");return}if(F==="warn"){if(!D())Y.next("update-available");return}if(!q){if(K.debug("auto-update not supported, falling back to warn mode"),!D())Y.next("update-available");return}if(q==="binary"&&process.platform==="win32"){if(K.debug("binary auto-update not supported on Windows, falling back to warn mode"),!D())Y.next("update-available");return}try{await pl(U.latestVersion,q);let H=await tN(U.latestVersion),B={from:U.currentVersion,to:U.latestVersion,...H};if(H.status==="same")K.info("success",B),Y.next("updated");else K.warn("success with warning",B),Y.next("updated-with-warning")}catch(H){Y.next("update-error")}}catch(G){K.debug("check failed",{error:G})}finally{await eG(5000),Y.next("hidden"),z.unsubscribe(),Y.complete()}}),{state:X}}nM();import{stderr as oF}from"node:process";function RL4(J){let Z=new mN().name("install").description("Install required tools like ripgrep to $AMP_HOME/bin").option("--force","Force reinstallation even if already installed").option("--verbose","Show installation progress and results").action(async(Y)=>{await Bl0(Y.force||!1,Y.verbose||!1,"0.0.1774126892-geb7ca3"),process.exit()});J.addCommand(Z,{hidden:!0});let Q=new mN("update").alias("up").summary("Update Amp CLI").description("Update Amp CLI to the latest version. You can specify a particular version to install, or leave blank to get the latest stable release.").option("--target-version <version>","Update to a specific version").allowUnknownOption(!1).action(async(Y)=>{await Wa5(Y.targetVersion)});J.addCommand(Q)}async function Wa5(J){if(process.env.AMP_SKIP_UPDATE_CHECK==="1")oF.write(c0.yellow(`Note: AMP_SKIP_UPDATE_CHECK=1 is set, which disables automatic update checking. Manual updates will still work.
6163
6163
 
6164
6164
  `));try{if(!J){oF.write(c0.blue(`Checking for updates...
6165
- `));let{hasUpdate:Y,latestVersion:X}=Nl0()?await zQ0("0.0.1774123285-gb6e451"):await VQ0("0.0.1774123285-gb6e451",eA());if(!Y){let K=Il0("0.0.1774123285-gb6e451"),V=K?.age?`released ${K.age} ago`:`built ${EF(new Date("2026-03-21T20:05:11.799Z"))} ago`;oF.write(c0.green(`✓ Amp is already up to date on version ${"0.0.1774123285-gb6e451"} (${V})
6166
- `));let z=await tN("0.0.1774123285-gb6e451");if(z.warning)oF.write(`
6165
+ `));let{hasUpdate:Y,latestVersion:X}=Nl0()?await zQ0("0.0.1774126892-geb7ca3"):await VQ0("0.0.1774126892-geb7ca3",eA());if(!Y){let K=Il0("0.0.1774126892-geb7ca3"),V=K?.age?`released ${K.age} ago`:`built ${EF(new Date("2026-03-21T21:05:12.391Z"))} ago`;oF.write(c0.green(`✓ Amp is already up to date on version ${"0.0.1774126892-geb7ca3"} (${V})
6166
+ `));let z=await tN("0.0.1774126892-geb7ca3");if(z.warning)oF.write(`
6167
6167
  `+c0.yellow(z.warning)+`
6168
6168
  `);process.exit(0)}if(!X)oF.write(c0.yellow("[WARN] could not find latest version")),process.exit(0);J=X}oF.write(c0.blue(`Updating to version ${J}...
6169
6169
  `)),await pl(J,void 0,(Y)=>{oF.write(c0.dim(`Running: ${Y}
@@ -7371,7 +7371,7 @@ Ctrl-X, Y, Z to unlock`;if(U){let f=F.text.replace(/`([^`]+)`/g,"$1")+`
7371
7371
  `),K=[];for(let V=0;V<X.length;V++){let F=X[V].replace(/\b(SELECT|FROM|WHERE|GROUP BY|ORDER BY|HAVING|LIMIT|JOIN|LEFT JOIN|RIGHT JOIN|INNER JOIN|ON|AND|OR|AS|IN|NOT|NULL|IS|BETWEEN|LIKE|EXISTS|UNION|DISTINCT|COUNT|SUM|AVG|MIN|MAX|DATE|TIMESTAMP_TRUNC|TIMESTAMP_SUB|CURRENT_TIMESTAMP|INTERVAL|CASE|WHEN|THEN|ELSE|END|WITH|INSERT|UPDATE|DELETE|SET|VALUES|INTO|CREATE|ALTER|DROP|TRUE|FALSE|ASC|DESC)\b/gi,"\x00$1\x01").split(/(\x00[^\x01]+\x01)/);for(let q of F)if(q.startsWith("\x00")&&q.endsWith("\x01"))K.push(new C(q.slice(1,-1),new g({color:Y.app.keybind,bold:!0})));else K.push(new C(q,new g({color:Q.colorScheme.foreground})));if(V<X.length-1)K.push(new C(`
7372
7372
  `))}return new i0({decoration:{color:Q.colorScheme.background,border:c1.all(new h1(Y.app.keybind,1,"rounded"))},child:new a0({padding:C0.symmetric(0,1),child:new $0({text:new C(void 0,void 0,K)})})})}}class S01 extends k${chartData;highlightIndex;showAxes;colors;constructor({key:J,chartData:Z,highlightIndex:Q=null,showAxes:Y=!0,colors:X=YG0}){super(J?{key:J}:{});this.chartData=Z,this.highlightIndex=Q,this.showAxes=Y,this.colors=X}createRenderObject(){return new T01({chartData:this.chartData,highlightIndex:this.highlightIndex,showAxes:this.showAxes,colors:this.colors})}updateRenderObject(J){let Z=J;Z.chartData=this.chartData,Z.highlightIndex=this.highlightIndex,Z.showAxes=this.showAxes,Z.colors=this.colors,Z.markNeedsLayout()}}function Vg4(J,Z,Q,Y,X,K,V){if(K<=0)return null;switch(J){case"horizontal-bar":{let z=Q;return z>=0&&z<K?z:null}case"bar":case"stacked-bar":{let z=V?k9:0,G=Y-z;if(G<=0)return null;let F=Z-z;if(F<0||F>=G)return null;let q=Math.max(1,Math.floor(G/K)),W=Math.floor(F/q);return W>=0&&W<K?W:null}case"line":case"sparkline":case"stacked-area":{let z=V?k9:0,G=Y-z;if(G<=0)return null;let F=Math.max(0,Math.min(G-1,Z-z));if(K===1)return 0;let q=G/(K-1),W=Math.round(F/q);return Math.max(0,Math.min(K-1,W))}default:return null}}function pR3(J,Z,Q,Y,X,K,V,z){if(X<=0||Z<0||Z>=X)return null;let G=2;switch(J){case"horizontal-bar":return{x:Math.floor(Q/2),y:Z};case"bar":case"stacked-bar":{let F=K?k9:0,q=Q-F,W=Y-(K?G:0);if(q<=0||W<=0)return null;let U=Math.max(1,Math.floor(q/X)),D=F+Z*U+Math.floor(U/2),H=z>0?V/z:0,B=Math.round((1-H)*(W-1));return{x:D,y:B}}case"line":case"sparkline":case"stacked-area":{let F=K?k9:0,q=Q-F,W=Y-(K?G:0);if(q<=0||W<=0)return null;let U=X>1?F+Math.round(Z/(X-1)*(q-1)):F+Math.floor(q/2),D=z>0?V/z:0,H=Math.round((1-D)*(W-1));return{x:U,y:H}}default:return null}}function dR3(J){let Z=0;for(let Q of J)for(let Y of Q.points)if(Y.value>Z)Z=Y.value;return Z||1}function cR3(J,Z,Q,Y,X){if(Q.length<=1){let z=Y(J.value),G=J.meta?` (${J.meta})`:"";return J.label.length+2+z.length+G.length}let K=J.label.length,V=0;for(let z of Q){let G=z.points[Z];if(!G)continue;V+=G.value;let F=2+z.name.length+2+Y(G.value).length;K=Math.max(K,F)}if(X){let z=9+Y(V).length;K=Math.max(K,z)}return K}function lR3(J,Z,Q,Y,X,K,V){let z;try{let H=_1.of(J),B=f0.of(J);z={foreground:H.colorScheme.foreground,background:H.colorScheme.background,border:B.app.keybind}}catch{z={foreground:{type:"index",value:15},background:{type:"index",value:0},border:{type:"index",value:7}}}let G=new g({color:z.foreground,bold:!0}),F=new g({color:z.foreground}),q=new g({color:z.foreground,dim:!0}),W=[],U=new g({color:z.foreground,underline:!0}),D=(H,B)=>new C(B,U,void 0,OQ0(H),()=>{t3(J,H)});if(Y.length<=1){if(W.push(new C(`${Z.label}: `,G)),Z.link)W.push(D(Z.link,K(Z.value)));else W.push(new C(K(Z.value),F));if(Z.meta)W.push(new C(` (${Z.meta})`,q))}else{let H=V==="stacked-bar"||V==="stacked-area";W.push(new C(`${Z.label}
7373
7373
  `,G));let B=0;for(let N=0;N<Y.length;N++){let w=Y[N],O=w.points[Q];if(!O)continue;B+=O.value;let L=w.color??X[N%X.length]??z.foreground;if(W.push(new C("● ",new g({color:L}))),W.push(new C(`${w.name}: `,q)),O.link)W.push(D(O.link,K(O.value)));else W.push(new C(K(O.value),F));if(N<Y.length-1||H)W.push(new C(`
7374
- `))}if(H)W.push(new C(" ",q)),W.push(new C("Total: ",q)),W.push(new C(K(B),F))}return new i0({decoration:{color:z.background,border:c1.all(new h1(z.border,1,"rounded"))},child:new $0({text:new C(void 0,void 0,W)})})}YE();g0();P2();import{execSync as OI3}from"node:child_process";GE();B$();n3();I7();fd();nM();LV();O$();rJ();FY();RA();f4();ag();ou();N1();var Vm4=z4($U(),1);import{writeFile as Zm4}from"fs/promises";import Qm4 from"path";g0();O$();class k01{enabled;configService;commandCounts=new Map;timer=null;bufferTimeMs=1e4;constructor(J,Z){this.enabled=J;this.configService=Z;this.startTimer()}startTimer(){this.timer=setInterval(()=>{this.flushEvents()},this.bufferTimeMs)}async flushEvents(){if(this.commandCounts.size===0||!await this.enabled())return;let J=Array.from(this.commandCounts.entries()).map(([Z,Q])=>({feature:"cli.command",action:Z,source:{client:"cli",clientVersion:"0.0.1774123285-gb6e451"},parameters:{metadata:{count:Q}},timestamp:Date.now()*1000}));this.commandCounts.clear();try{let Z=JSON.stringify(J);await x40(Z,this.configService)}catch(Z){I.error("Failed to export command telemetry events",Z)}}async submit(J){if(!await this.enabled()||this.timer===null)return;let Z=this.commandCounts.get(J)||0;this.commandCounts.set(J,Z+1)}async dispose(){if(await this.flushEvents(),this.timer!==null)clearInterval(this.timer),this.timer=null}}class VO extends l0{props;constructor(J){super();this.props=J}createState(){return new zg4}}class zg4 extends d0{_state;initState(){super.initState(),this._state=this.widget.props.initialState}build(J){let Z=(Q)=>{this.setState(()=>{this._state=Q(this._state)})};return this.widget.props.builder(J,Z,this._state)}}class Gg4 extends d0{controller=new J$;focusNode=new W6({debugLabel:"CommandArgumentPrompt",onKey:(J)=>{if(J.key==="Escape")return this.widget.props.onDismiss(),"handled";return"ignored"}});_textListener=()=>{this.setState(()=>{})};initState(){this.focusNode.requestFocus(),this.controller.addListener(this._textListener)}dispose(){this.controller.removeListener(this._textListener),this.focusNode.dispose()}build(J){let Z=f0.of(J),{colors:Q,app:Y}=Z,X=this.widget.props.isRequiredArg??!0,K=this.controller.text.trim().length>0,V=!X||K,z=c1.all(new h1(Q.foreground,1,"solid")),G=new CZ({controller:this.controller,focusNode:this.focusNode,placeholder:this.widget.props.placeholder??"Enter command argument...",onSubmitted:(D)=>{let H=D.trim();if(X&&H.length===0)return;this.widget.props.onSubmit(H)},autofocus:!0,style:{textColor:Q.foreground,border:null},maxLines:1}),F=new q1({children:[new i0({decoration:{color:Q.background},child:new $0({text:new C(">",new g({color:Q.foreground}))})}),new k1({child:G})]}),q=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C("",void 0,[new C("Command: ",new g({color:Q.foreground})),new C(this.widget.props.commandName,new g({color:Y.command,bold:!0}))])})}),W=[];if(V)W.push(new C("Enter",new g({color:Y.keybind}))),W.push(new C(" to submit, ",new g({color:Q.foreground,dim:!0})));W.push(new C("Esc",new g({color:Y.keybind}))),W.push(new C(" to cancel",new g({color:Q.foreground,dim:!0})));let U=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C("",void 0,W)})});return new i0({decoration:{border:z,color:Q.background},padding:C0.all(1),child:new x0({children:[q,new I0({height:1}),F,new b3,U]})})}}class pa extends l0{props;constructor(J){super();this.props=J}createState(){return new Gg4}}import{isDeepStrictEqual as y01}from"node:util";var iR3=/[\\/_ +.#"@[({&]/,nR3=/[\\/_ +.#"@[({&]/g,aR3=/[\s-]/,Fg4=/[\s-]/g;function VG0(J,Z,Q,Y,X,K,V){if(K===Z.length){if(X===J.length)return 1;return 0.99}let z=`${X},${K}`;if(V[z]!==void 0)return V[z];let G=Y.charAt(K),F=Q.indexOf(G,X),q=0,W,U,D,H;while(F>=0){if(W=VG0(J,Z,Q,Y,F+1,K+1,V),W>q){if(F===X)W*=1;else if(aR3.test(J.charAt(F-1))){if(W*=0.9,H=J.slice(X,F-1).match(Fg4),H&&X>0)W*=0.999**H.length}else if(iR3.test(J.charAt(F-1))){if(W*=0.8,D=J.slice(X,F-1).match(nR3),D&&X>0)W*=0.999**D.length}else if(W*=0.3,X>0)W*=0.999**(F-X);if(J.charAt(F)!==Z.charAt(K))W*=0.9999}if(W<0.1&&(Q.charAt(F-1)===Y.charAt(K+1)||Y.charAt(K+1)===Y.charAt(K)&&Q.charAt(F-1)!==Y.charAt(K))){if(U=VG0(J,Z,Q,Y,F+1,K+2,V),U*0.1>W)W=U*0.1}if(W>q)q=W;F=Q.indexOf(G,F+1)}return V[z]=q,q}function KG0(J){return J.toLowerCase().replace(Fg4," ")}function qg4(J,Z){let Q=VG0(J,Z,KG0(J),KG0(Z),0,0,{}),Y=Z.trim().split(/\s+/);if(Y.length>1){let X=0,K=0;for(let z of Y){let G=VG0(J,z,KG0(J),KG0(z),0,0,{});if(G===0)return Q;X+=G,K+=z.length}let V=X/Y.length*0.95;return Math.max(Q,V)}return Q}class Ov{}class Lv{}class zG0{}class GG0{}class Wg4 extends l0{child;onContext;constructor(J,Z){super();this.child=J;this.onContext=Z}createState(){return new Ug4}}class Ug4 extends d0{build(J){return this.widget.onContext(J),this.widget.child}}function oR3(J,Z){if(J==="")return{matches:!0,score:1};let Q=qg4(Z,J);return{matches:Q>0.15,score:Q}}class a2 extends l0{props;debugLabel="FuzzyPicker";constructor(J){super();this.props=J}createState(){return new Dg4}}class Dg4 extends d0{textController;focusNode;scrollController=new A5;selectedIndex=0;itemContexts=[];hasUserInteracted=!1;cachedQuery="";cachedItemsRef=null;cachedFiltered=[];initState(){if(this.scrollController.disableFollowMode(),this.textController=new J$(this.widget.props.controller?.query??""),this.focusNode=new W6({debugLabel:this.widget.debugLabel}),this.textController.addListener(()=>{this.hasUserInteracted=!0,this.selectedIndex=0,this.recomputeFilteredItems(),this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()});let J=this.widget.props.controller;if(J)J.query=this.textController.text;this.syncSelection()}),this.recomputeFilteredItems(),this.widget.props.controller?.selectedItem){let J=this.cachedFiltered.findIndex((Z)=>y01(Z,this.widget.props.controller?.selectedItem));if(J>=0)this.selectedIndex=J}this.clampSelectedIndex(),this.syncSelection(),this.ensureSelectedItemVisible()}didUpdateWidget(J){if(!y01(J.props.items,this.widget.props.items)){if(this.recomputeFilteredItems(),this.widget.props.controller?.selectedItem){let Z=this.cachedFiltered.findIndex((Q)=>y01(Q,this.widget.props.controller?.selectedItem));if(Z>=0)this.selectedIndex=Z}this.clampSelectedIndex(),this.ensureSelectedItemVisible(),this.syncSelection()}}dispose(){this.widget.props.onSelectionChange?.(null),this.textController.dispose(),this.focusNode.dispose(),this.scrollController.dispose()}invoke=(J)=>{if(J instanceof Ov){let Z=this.getFilteredItems();if(Z.length>0&&this.selectedIndex<Z.length-1)this.hasUserInteracted=!0,this.selectedIndex++,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.syncSelection();return"handled"}if(J instanceof Lv){if(this.getFilteredItems().length>0&&this.selectedIndex>0)this.hasUserInteracted=!0,this.selectedIndex--,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.syncSelection();return"handled"}if(J instanceof zG0){let Z=this.getFilteredItems();if(Z.length>0&&this.selectedIndex<Z.length){let Q=Z[this.selectedIndex];if(Q){if(!(this.widget.props.isItemDisabled?.(Q)??!1))this.widget.props.onAccept(Q,{hasUserInteracted:this.hasUserInteracted})}}return"handled"}if(J instanceof GG0)return this.widget.props.onDismiss?.(),"handled";return"ignored"};syncSelection(){let Z=this.cachedFiltered[this.selectedIndex]??null;if(this.widget.props.controller)this.widget.props.controller.selectedItem=Z;this.widget.props.onSelectionChange?.(Z)}clampSelectedIndex(){let J=this.cachedFiltered.length-1;if(J<0){this.selectedIndex=0;return}this.selectedIndex=Math.max(0,Math.min(this.selectedIndex,J))}recomputeFilteredItems(){let J=this.textController.text,Z=this.widget.props.items,Q=this.widget.props.normalizeQuery?.(J)??J,Y=Z.filter((X)=>!this.widget.props.filterItem||this.widget.props.filterItem(X,J)).map((X)=>({item:X,...oR3(Q,this.widget.props.getLabel(X))})).filter((X)=>X.matches).sort(this.widget.props.sortItems?(X,K)=>this.widget.props.sortItems(X,K,J):(X,K)=>K.score-X.score).map((X)=>X.item);this.cachedQuery=J,this.cachedItemsRef=Z,this.cachedFiltered=this.widget.props.maxRenderItems?Y.slice(0,this.widget.props.maxRenderItems):Y}getFilteredItems(){let J=this.textController.text,Z=this.widget.props.items;if(this.cachedQuery===J&&this.cachedItemsRef===Z)return this.cachedFiltered;return this.recomputeFilteredItems(),this.cachedFiltered}ensureSelectedItemVisible(){let J=this.itemContexts[this.selectedIndex];if(!J)return;let Z=J.findRenderObject();if(!Z)return;let Q=0,Y=Z.size.height;Uv(J,{top:Q,bottom:Y},{padding:1})}handleScroll=(J)=>{let Z=this.getFilteredItems();if(Z.length===0)return!1;let Q=this.selectedIndex;if(J.direction==="down")if(this.selectedIndex<Z.length-1)this.hasUserInteracted=!0,this.selectedIndex++;else return!1;else if(this.selectedIndex>0)this.hasUserInteracted=!0,this.selectedIndex--;else return!1;return this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.syncSelection(),this.selectedIndex!==Q};handleItemClick=(J,Z)=>{let Q=this.getFilteredItems();if(J>=0&&J<Q.length){let Y=Q[J],X=Y?this.widget.props.isItemDisabled?.(Y)??!1:!1;if(Z===1)this.hasUserInteracted=!0,this.selectedIndex=J,this.setState(),this.syncSelection();else if(Z===2&&!X){if(Y)this.hasUserInteracted=!0,this.widget.props.onAccept(Y,{hasUserInteracted:this.hasUserInteracted})}}};build(J){let Z=f0.of(J),{colors:Q}=Z,Y=this.getFilteredItems(),X=c1.all(new h1(Q.foreground,1,"solid")),K=this.widget.props.hidePromptWhenLoading&&this.widget.props.isLoading,V=this.widget.props.enabled??!0,z=new CZ({controller:this.textController,focusNode:this.focusNode,autofocus:!0,enabled:V,style:{backgroundColor:Q.background,textColor:Q.foreground,cursorColor:Q.cursor,placeholderColor:Q.mutedForeground,border:null},maxLines:1}),G=new h$({shortcuts:new Map([[new D4("ArrowDown"),new Ov],[new D4("ArrowUp"),new Lv],[new D4("Tab"),new Ov],[new D4("Tab",{shift:!0}),new Lv],[new D4("n",{ctrl:!0}),new Ov],[new D4("p",{ctrl:!0}),new Lv],[new D4("Enter"),new zG0],[new D4("Escape"),new GG0]]),focusNode:this.focusNode,child:z}),F=new L2({actions:new Map([[Ov,new U6(this.invoke)],[Lv,new U6(this.invoke)],[zG0,new U6(this.invoke)],[GG0,new U6(this.invoke)]]),child:G}),q=new q1({children:[new i0({decoration:{color:Q.background},child:new $0({text:new C(">",new g({color:Q.foreground}))})}),new k1({child:F})]});this.itemContexts=[];let W;if(this.widget.props.isLoading){let N=this.widget.props.loadingText??"Loading...";W=new I0({height:10,child:new $4({child:new $0({text:new C(N,new g({color:Q.foreground}))})})})}else if(Y.length===0&&this.widget.props.emptyStateText)W=new k1({child:new $4({child:new $0({text:new C(this.widget.props.emptyStateText,new g({color:Q.foreground,dim:!0}))})})});else{let N=Y.map((w,O)=>{let L=O===this.selectedIndex,E=this.widget.props.isItemDisabled?.(w)??!1,M;if(this.widget.props.renderItem)M=this.widget.props.renderItem(w,L,E,J);else{let A=L?Z.app.selectionBackground:void 0,j=L?Z.app.selectionForeground:Q.foreground;M=new i0({decoration:A?{color:A}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C(this.widget.props.getLabel(w),new g({color:j,dim:E}))})})}return new Wg4(new e1({onClick:(A)=>this.handleItemClick(O,A.clickCount),child:M}),(A)=>{this.itemContexts[O]=A})});W=new x0({children:N,crossAxisAlignment:"start"})}let U=new e1({onScroll:this.handleScroll,opaque:!1,child:new T6({controller:this.scrollController,autofocus:!1,child:W})}),D=[];if(this.widget.props.title){let N=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C(this.widget.props.title,new g({color:Z.app.command,bold:!0}))})});D.push(N)}if(!K)D.push(q,new I0({height:1}));if(this.textController.text!==""){let N=Y.length>0?Y[this.selectedIndex]:void 0,w=N&&this.widget.props.buildDisabledReasonWidget?.(N,J);D.push(new k1({child:new x0({mainAxisAlignment:"spaceBetween",children:[new k1({child:U}),new i0({padding:C0.only({top:1}),child:new $4({child:w??new I0({height:1})})})]})}))}else D.push(new k1({child:U}));if(this.widget.props.footer)D.push(this.widget.props.footer);return new i0({decoration:{border:X,color:Q.background},padding:C0.symmetric(1,0),child:new x0({children:D})})}}function Hg4(J){let Q=new Date().getTime()-J.getTime(),Y=Math.floor(Q/60000),X=Math.floor(Q/3600000),K=Math.floor(Q/86400000);if(Y<1)return"just now";if(Y<60)return`${Y}m ago`;if(X<24)return`${X}h ago`;if(K<7)return`${K}d ago`;return J.toLocaleDateString()}class v01 extends t1{props;debugLabel="NewsFeedPicker";constructor(J){super();this.props=J}build(J){let Z=[...this.props.entries].sort((X,K)=>K.pubDate.getTime()-X.pubDate.getTime()),Q=Math.max(0,...Z.map((X)=>Hg4(X.pubDate).length));return new a2({items:Z,getLabel:(X)=>X.title,onAccept:(X)=>this.props.onSelect?.(X),onDismiss:this.props.onDismiss,title:this.props.title,emptyStateText:"No news entries available",maxRenderItems:100,renderItem:(X,K,V,z)=>{let G=f0.of(z),{colors:F}=G,q=G.app,W=K?q.selectionBackground:void 0,U=K?q.selectionForeground:F.foreground,D=F.mutedForeground,H=(B,N)=>new I0({width:N,child:q1.end([new $0({text:new C(B,new g({color:D}))})])});return new i0({decoration:W?{color:W}:void 0,padding:C0.symmetric(2,0),child:new q1({children:[new k1({child:new $0({text:new C(X.title,new g({color:U})),overflow:"ellipsis",maxLines:1})}),new I0({width:2}),H(Hg4(X.pubDate),Q)]})})}})}}class x01 extends l0{createState(){return new Bg4}}class Bg4 extends d0{isGreen=!0;timer;initState(){this.timer=setInterval(()=>{this.isGreen=!this.isGreen,this.setState()},700)}dispose(){if(this.timer)clearInterval(this.timer);super.dispose()}build(J){let Q=f0.of(J).colors;return new $0({text:new C("●",new g({color:this.isGreen?Q.success:Q.mutedForeground,bold:!0})),maxLines:1})}}function rR3(J){return EY(J,{acceptedHostnames:["ampcode.com","localhost"],allowThreadsPathExtraction:!0})}function sR3(J){let Z=new Map,Q=new Map,Y=new Map,X=[];for(let V of J)Z.set(V.id,V);for(let V of J){let z=V.relationships.find((G)=>G.role==="child"&&Z.has(G.threadID)&&(G.type==="fork"||G.type==="handoff"));if(z){Y.set(V.id,z.type);let G=z.threadID,F=Q.get(G)||[];F.push(V),Q.set(G,F)}else X.push(V)}return gV0.flatten(X,(V)=>Q.get(V.id)).map((V)=>({...V.item,depth:V.depth,isLast:V.isLast,ancestorsAreLast:V.ancestorsAreLast,relationshipType:Y.get(V.item.id)}))}function f01(J,Z,Q){return new $0({text:new C(`${J}${Z}`,new g({color:Q})),maxLines:1})}function tR3(J,Z,Q,Y){return[f01("+",J,Y.success),b3.horizontal(1),f01("~",Z,Y.warning),b3.horizontal(1),f01("-",Q,Y.destructive)]}function eR3(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}class FG0 extends l0{props;debugLabel="ThreadContinuationPicker";constructor(J){super();this.props=J}createState(){return new Ng4}}class Ng4 extends d0{spinner=new M3;spinnerInterval=null;isSwitchingThread=!1;get isBusy(){return this.isSwitchingThread||this.widget.props.isLoading===!0}updateSpinnerAnimation(){if(this.isBusy){if(!this.spinnerInterval)this.spinnerInterval=setInterval(()=>{this.spinner.step(),this.setState(()=>{})},100);return}if(this.spinnerInterval)clearInterval(this.spinnerInterval),this.spinnerInterval=null}setSwitchingThread(J){if(this.isSwitchingThread===J)return;this.setState(()=>{this.isSwitchingThread=J}),this.updateSpinnerAnimation()}initState(){super.initState(),this.updateSpinnerAnimation()}didUpdateWidget(J){this.updateSpinnerAnimation()}dispose(){if(this.spinnerInterval)clearInterval(this.spinnerInterval),this.spinnerInterval=null;super.dispose()}build(J){let{props:Z}=this.widget,Q=this.isBusy,Y=this.isSwitchingThread?"Switching thread...":"Loading threads...",X=`${this.spinner.toBraille()} ${Y}`,K=Z.filterByWorkspace&&Z.currentWorkspaceURI?Z.threads.filter((O)=>O.workspaceURI===Z.currentWorkspaceURI):Z.threads;if(Z.excludeCurrentThread&&Z.currentThreadID)K=K.filter((O)=>O.id!==Z.currentThreadID);let V=Z.recentThreadIDs||[],z=new Set(V),G=Z.currentThreadID,F=[...K].sort((O,L)=>{if(G){if(O.id===G)return-1;if(L.id===G)return 1}let E=V.indexOf(O.id),M=V.indexOf(L.id);if(E!==-1&&M!==-1)return E-M;if(E!==-1)return-1;if(M!==-1)return 1;return 0}),q=sR3(F),W=Math.max(0,...q.map((O)=>O.description.timeAgo.length)),U=f0.of(J),D=new a0({padding:C0.symmetric(0,1),child:new $4({child:new $0({text:new C("",new g({color:U.colors.foreground,dim:!0}),[new C("Ctrl+T",new g({color:U.colors.primary,dim:!0})),new C(Z.filterByWorkspace?" for all workspaces":" to filter by workspace",new g({color:U.colors.foreground,dim:!0}))])})})}),H="",B=null,N=(O)=>{if(O!==H)H=O,B=rR3(O);return B};return new a2({items:q,getLabel:(O)=>`${O.title} ${O.id}`,filterItem:(O,L)=>{let E=N(L);if(E)return O.id.toLowerCase()===E.toLowerCase();return!0},normalizeQuery:(O)=>N(O)?"":O,onAccept:async(O,L)=>{if(!Z.onSelect||this.isSwitchingThread)return;let E=Z.onSelect(O.id,L);if(!eR3(E))return;this.setSwitchingThread(!0);try{await E}finally{if(this.mounted)this.setSwitchingThread(!1)}},onDismiss:Z.onDismiss,onSelectionChange:(O)=>{if(Z.previewController){if(O)Z.previewController.select(O.id)}},title:Z.title,enabled:!Q,isLoading:Q,hidePromptWhenLoading:!0,loadingText:X,emptyStateText:"No threads match your filter",maxRenderItems:200,footer:Q?void 0:D,renderItem:(O,L,E,M)=>{let A=f0.of(M),{app:j,colors:R}=A,_=L?j.selectionBackground:void 0,k=L?j.selectionForeground:R.foreground,u=R.mutedForeground,m=(s,F0)=>new I0({width:F0,child:q1.end([new $0({text:new C(s,new g({color:u}))})])}),x=Z.threadViewStates[O.id],T=[],f=O.relationshipType==="handoff",p=new Ha({connectorColor:R.mutedForeground});if(O.depth>0){let s=[],F0=O.ancestorsAreLast.slice(1);for(let O0 of F0)s.push(new C(p.getAncestorPrefix(O0),new g({color:p.connectorColor,dim:p.connectorDim})));let a=O.isLast?p.elbow:p.tee,U0=p.getConnectorText(a);s.push(new C(U0,new g({color:p.connectorColor,dim:p.connectorDim}))),T.push(new $0({text:new C("",void 0,s)}))}let d=[],h=G===O.id?new C("(current) ",new g({color:R.success})):z.has(O.id)?new C("(visited) ",new g({color:R.foreground,dim:!0})):null;if(h)d.push(new $0({text:h}));if(ON(x))d.push(new x01),d.push(new I0({width:1}));let n=O.title;if(O.relationshipType==="fork"){let s=n.match(/^Forked\((\d+)\): /);if(s)n=n.slice(s[0].length);else while(n.startsWith("Forked: "))n=n.slice(8);d.push(new $0({text:new C("[fork] ",new g({color:R.primary}))}))}else if(f)d.push(new $0({text:new C("[handoff] ",new g({color:R.accent}))}));if(d.push(new k1({child:new $0({text:new C(n,new g({color:k})),overflow:"ellipsis",maxLines:1})})),d.push(new I0({width:2})),O.diffStats&&(O.diffStats.added>0||O.diffStats.changed>0||O.diffStats.deleted>0)){let s=L?{success:u,warning:u,destructive:u}:R;d.push(...tR3(O.diffStats.added,O.diffStats.changed,O.diffStats.deleted,s)),d.push(new I0({width:2}))}return d.push(m(O.description.timeAgo,W)),new i0({decoration:_?{color:_}:void 0,padding:C0.symmetric(2,0),child:new q1({children:[...T,...d]})})}})}}function wg4(J){return 1-(1-J)**3}function Og4(J,Z,Q){return J+(Z-J)*Q}function da(J,Z){if(!J)return{x:0,y:0};let Q=Z-J.startTime,Y=Math.min(Q/J.durationX,1),X=Math.min(Q/J.durationY,1),K=wg4(Y),V=wg4(X);return{x:Og4(J.startOffset.x,J.targetOffset.x,K),y:Og4(J.startOffset.y,J.targetOffset.y,V)}}var $I3={nodeWidth:3,horizontalSpacing:3};class Ev{options;constructor(J={}){this.options={...$I3,...J}}layout(J){let{childrenMap:Z,resolvedParent:Q}=this.buildTree(J),Y=[],X=Z.get(void 0)??[];if(this.options.comparator)X.sort(this.options.comparator);let K=0,V=(z,G)=>{let F=Z.get(z.id)??[];if(this.options.comparator)F.sort(this.options.comparator);let q={...z,parentID:Q.get(z.id)};if(F.length===0){Y.push({node:q,position:{x:K,y:G}});let B=K;return K+=this.options.nodeWidth+this.options.horizontalSpacing,B}let W=[];for(let B of F)W.push(V(B,G+1));let U=Math.min(...W),D=Math.max(...W),H=Math.floor((U+D)/2);return Y.push({node:q,position:{x:H,y:G}}),H};for(let z of X)V(z,0);return Y}buildTree(J){let Z=new Set(J.map((K)=>K.id)),Q=[...J].sort((K,V)=>K.id.localeCompare(V.id)),Y=new Map;for(let K of Q){if(!K.parentID||!Z.has(K.parentID)){Y.set(K.id,void 0);continue}let V=!1,z=K.parentID;while(z){if(z===K.id){V=!0;break}z=Y.get(z)}Y.set(K.id,V?void 0:K.parentID)}let X=new Map;for(let K of J){let V=Y.get(K.id);if(!X.has(V))X.set(V,[]);X.get(V).push(K)}return{childrenMap:X,resolvedParent:Y}}}var JI3={nodeWidth:3,nodeHeight:2};class Mv{options;constructor(J={}){this.options={...JI3,...J}}calculate(J){let Z=[],Q=new Map;for(let Y of J)Q.set(Y.node.id,Y);for(let Y of J){if(!Y.node.parentID)continue;let X=Q.get(Y.node.parentID);if(!X)continue;let K=this.calculateConnectorLine(X.position,Y.position);Z.push({points:K,fromNodeID:X.node.id,toNodeID:Y.node.id})}return Z}calculateConnectorLine(J,Z){let Q=Math.floor(this.options.nodeWidth/2),Y=[],X=J.x+Q,K=Z.x+Q,V=J.y*(this.options.nodeHeight+3)+this.options.nodeHeight;Y.push({x:X,y:V});let z=V+1;if(Y.push({x:X,y:z}),X!==K)Y.push({x:K,y:z});let G=Z.y*(this.options.nodeHeight+3)-1;return Y.push({x:K,y:G}),Y}}var ZI3={nodeWidth:3,nodeHeight:2},QI3={x:0,y:0};class WG0{options;constructor(J={}){this.options={...ZI3,...J}}getNodeWidth(){return this.options.nodeWidth}render(J,Z,Q,Y=QI3,X,K,V,z){let G=z?f0.of(z):null,F=G?.colors,q=G?.app,W=F?.mutedForeground??F?.foreground;if(J.length===0)return new $0({text:new C("No nodes",new g({color:W}))});let U=Math.max(...J.map((j)=>j.position.y)),H=Math.max(...J.map((j)=>j.position.x))+this.options.nodeWidth+3,B=this.options.nodeHeight+3,N=[];for(let j=U;j>=0;j--){let R=J.filter((u)=>u.position.y===j);R.sort((u,m)=>u.position.x-m.position.x);let _=[],k=0;for(let u of R){if(u.position.x>k)_.push(new I0({width:u.position.x-k}));let m=u.node.id===Q,x=V?.(u.node.data)??!1,T=K?.activeFlashOn??!1,f=u.node.id===K?.copyFlashNodeId;_.push(this.renderNode(m,x,T,f,q,F)),k=u.position.x+this.options.nodeWidth}if(N.push(new q1({crossAxisAlignment:"start",children:_})),j>0){let u=J.filter((T)=>T.position.y===j-1),m=R,x=this.renderConnectors(u,m,Z,H,F,q);N.push(...x)}}let w=new x0({crossAxisAlignment:"start",children:N}),O=Math.round(Y.x),L=Math.round(Y.y*B),E=(U+1)*B,M=[new I0({width:H,height:E}),new t6({left:O,top:L,child:w})],A=Q?J.find((j)=>j.node.id===Q):void 0;if(A&&X){let j=X(A.node.data),R=U-A.position.y,_=O+A.position.x+this.options.nodeWidth+1,k=L+R*B+1,u=30;if(K?.maxTitleWidthPercent&&K.viewportWidth)u=Math.floor(K.viewportWidth*K.maxTitleWidthPercent/100);M.push(new t6({left:_,top:k,child:this.renderInfoBox(j,u,F,q)}))}return new i0({padding:C0.horizontal(2),child:new xz(new G5({fit:"expand",children:M}))})}renderNode(J,Z,Q,Y,X,K){let V="┌─┐",z="└─┘",G=J?X?.threadGraphNodeSelected??K?.primary??K?.foreground:X?.threadGraphNode??K?.primary??K?.foreground,F=!1;if(Y)G=X?.threadGraphNodeSelected??K?.primary??G,V="┏━┓",z="┗━┛",F=!0;else if(Z&&Q)G=X?.toolSuccess??K?.primary??G,V="┏━┓",z="┗━┛";return new x0({crossAxisAlignment:"start",children:[new $0({text:new C(V,new g({color:G,bold:F}))}),new $0({text:new C(z,new g({color:G,bold:F}))})]})}wrapText(J,Z){let Q=J.split(" "),Y=[],X="";for(let K of Q){if(K.length>Z)K=K.slice(0,Z-1)+"…";if(X.length===0)X=K;else if(X.length+1+K.length<=Z)X+=" "+K;else Y.push(X),X=K}if(X.length>0)Y.push(X);return Y}renderInfoBox(J,Z=30,Q,Y){let X=this.wrapText(J,Z),K=Math.min(Z,Math.max(1,...X.map((U)=>U.length))),V=K+2,z="┌"+"─".repeat(V)+"┐",G="└"+"─".repeat(V)+"┘",F=Q?.border??Y?.threadGraphConnector??Q?.foreground,q=Q?.foreground,W=[new $0({text:new C(z,new g({color:F}))})];for(let U of X){let D=" ".repeat(K-U.length);W.push(new $0({text:new C("│ ",new g({color:F}),[new C(U+D,new g({color:q??F})),new C(" │",new g({color:F}))])}))}return W.push(new $0({text:new C(G,new g({color:F}))})),new x0({crossAxisAlignment:"start",children:W})}renderConnectors(J,Z,Q,Y,X,K){let V=[],z=Math.floor(this.options.nodeWidth/2),G=K?.threadGraphConnector??X?.primary??X?.foreground,F=Array(Y).fill(" ");for(let U of Z){let D=U.position.x+z;if(D>=0&&D<Y)F[D]="▲"}V.push(new $0({text:new C(F.join(""),new g({color:G}))}));let q=Array(Y).fill(" ");for(let U of J){let D=Z.filter((O)=>O.node.parentID===U.node.id);if(D.length===0)continue;let H=U.position.x+z,B=D.map((O)=>O.position.x+z),N=Math.min(...B),w=Math.max(...B);for(let O=N;O<=w;O++)if(O>=0&&O<Y){if(O===H)if(D.length===1&&B[0]===H)q[O]="│";else if(O===N)q[O]="└";else if(O===w)q[O]="┘";else q[O]="┬";else if(B.includes(O))if(O===N)q[O]="└";else if(O===w)q[O]="┘";else q[O]="┴";else if(q[O]===" ")q[O]="─"}}V.push(new $0({text:new C(q.join(""),new g({color:G}))}));let W=Array(Y).fill(" ");for(let U of J){if(Z.filter((B)=>B.node.parentID===U.node.id).length===0)continue;let H=U.position.x+z;if(H>=0&&H<Y)W[H]="│"}return V.push(new $0({text:new C(W.join(""),new g({color:G}))})),V}}var YI3={nodeWidth:1,nodeHeight:1,nodeIcon:"□",selectedIcon:"□"},XI3={x:0,y:0};class u01{options;constructor(J={}){this.options={...YI3,...J}}getNodeWidth(){return this.options.nodeWidth}render(J,Z,Q,Y=XI3,X,K,V,z){let G=z?f0.of(z):null,F=G?.colors,q=G?.app,W=F?.mutedForeground??F?.foreground;if(J.length===0)return new $0({text:new C("No nodes",new g({color:W}))});let U=Math.max(...J.map((j)=>j.position.y)),H=Math.max(...J.map((j)=>j.position.x))+this.options.nodeWidth+3,B=this.options.nodeHeight+1,N=[];for(let j=U;j>=0;j--){let R=J.filter((u)=>u.position.y===j);R.sort((u,m)=>u.position.x-m.position.x);let _=[],k=0;for(let u of R){if(u.position.x>k)_.push(new I0({width:u.position.x-k}));let m=u.node.id===Q,x=V?.(u.node.data)??!1,T=K?.activeFlashOn??!1;_.push(this.renderNode(m,x,T,q,F)),k=u.position.x+this.options.nodeWidth}if(N.push(new q1({crossAxisAlignment:"start",children:_})),j>0){let u=J.filter((T)=>T.position.y===j-1),m=R,x=this.renderConnectors(u,m,Z,H,F,q);N.push(...x)}}let w=new x0({crossAxisAlignment:"start",children:N}),O=Math.round(Y.x),L=Math.round(Y.y*B),E=(U+1)*B,M=[new I0({width:H,height:E}),new t6({left:O,top:L,child:w})],A=Q?J.find((j)=>j.node.id===Q):void 0;if(A&&X){let j=X(A.node.data),R=U-A.position.y,_=O+A.position.x+this.options.nodeWidth+1,k=L+R*B,u=30;if(K?.maxTitleWidthPercent&&K.viewportWidth)u=Math.floor(K.viewportWidth*K.maxTitleWidthPercent/100);M.push(new t6({left:_,top:k,child:this.renderInfoBox(j,u,F)}))}return new i0({padding:C0.horizontal(2),child:new xz(new G5({fit:"expand",children:M}))})}renderNode(J,Z,Q,Y,X){let K=J?this.options.selectedIcon:this.options.nodeIcon,V=J?Y?.threadGraphNodeSelected??X?.primary??X?.foreground:Y?.threadGraphNode??X?.primary??X?.foreground;if(Z&&Q)V=Y?.toolSuccess??X?.primary??V,K="■";return new $0({text:new C(K,new g({color:V}))})}wrapText(J,Z){let Q=J.split(" "),Y=[],X="";for(let K of Q){if(K.length>Z)K=K.slice(0,Z-1)+"…";if(X.length===0)X=K;else if(X.length+1+K.length<=Z)X+=" "+K;else Y.push(X),X=K}if(X.length>0)Y.push(X);return Y}renderInfoBox(J,Z=30,Q){let Y=this.wrapText(J,Z),X=Q?.foreground,K=[];for(let V of Y)K.push(new $0({text:new C(V,new g({color:X??Q?.primary??Q?.foreground}))}));return new x0({crossAxisAlignment:"start",children:K})}renderConnectors(J,Z,Q,Y,X,K){let V=[],z=Math.floor(this.options.nodeWidth/2),G=K?.threadGraphConnector??X?.primary??X?.foreground,F=Array(Y).fill(" ");for(let q of J){let W=Z.filter((N)=>N.node.parentID===q.node.id);if(W.length===0)continue;let U=q.position.x+z,D=W.map((N)=>N.position.x+z),H=Math.min(...D),B=Math.max(...D);for(let N=H;N<=B;N++)if(N>=0&&N<Y){let w=N===U,O=D.includes(N);if(w&&O)if(W.length===1)F[N]="│";else if(N===H)F[N]="└";else if(N===B)F[N]="┘";else F[N]="┼";else if(w)if(N===H)F[N]="└";else if(N===B)F[N]="┘";else F[N]="┬";else if(O)if(N===H)F[N]="└";else if(N===B)F[N]="┘";else F[N]="┴";else if(F[N]===" ")F[N]="─"}}return V.push(new $0({text:new C(F.join(""),new g({color:G}))})),V}}class ca extends o3{onWidth;onHeight;constructor(J){super(J.child);this.onWidth=J.onWidth,this.onHeight=J.onHeight}createRenderObject(){return new Lg4(this.onWidth,this.onHeight)}updateRenderObject(J){J.onWidth=this.onWidth,J.onHeight=this.onHeight}}class Lg4 extends v4{onWidth;onHeight;constructor(J,Z){super();this.onWidth=J,this.onHeight=Z}performLayout(){let J=this._lastConstraints,Z=Number.isFinite(J.maxWidth)?J.maxWidth:80,Q=Number.isFinite(J.maxHeight)?J.maxHeight:24;this.onWidth(Z),this.onHeight?.(Q);let Y=this.children[0];if(Y)Y.layout(J),this.setSize(Y.size.width,Y.size.height);else this.setSize(J.minWidth,J.minHeight)}paint(J,Z,Q){for(let Y of this.children)Y.paint(J,Z,Q)}}class RR extends l0{props;constructor(J){super({key:J.key});this.props=J}createState(){return new Ag4}}var Eg4=400,Mg4=300,KI3=16;class Ag4 extends d0{selectedNodeId=null;positionedNodes=[];dateComparator=(J,Z)=>{let Q=J.data.updatedAt??"",Y=Z.data.updatedAt??"";return Q.localeCompare(Y)};layoutEngine=new Ev({nodeWidth:1,horizontalSpacing:1,comparator:this.dateComparator});lineCalculator=new Mv;renderer=new u01;animation=null;currentOffset={x:0,y:0};animationTimer=null;viewportWidth=80;viewportHeight=24;activeFlashOn=!0;activeFlashTimer=null;initState(){let{initialSelectedThreadID:J}=this.widget.props;if(J){let Q=this.widget.props.threads.find((Y)=>Y.id===J);if(Q)this.selectedNodeId=Q.id}this.startActiveFlashTimer()}startActiveFlashTimer(){if(!this.widget.props.threads.some((Z)=>Z.isActive))return;this.activeFlashTimer=setInterval(()=>{this.activeFlashOn=!this.activeFlashOn,this.setState()},700)}stopActiveFlashTimer(){if(this.activeFlashTimer)clearInterval(this.activeFlashTimer),this.activeFlashTimer=null}didUpdateWidget(J){let Z=new Set(J.props.threads.map((G)=>G.id)),Q=new Set(this.widget.props.threads.map((G)=>G.id));if(Z.size!==Q.size||[...Z].some((G)=>!Q.has(G)))this.stopAnimation(),this.currentOffset={x:0,y:0};let X=J.props.initialSelectedThreadID,K=this.widget.props.initialSelectedThreadID;if(X!==K&&K){let F=this.widget.props.threads.find((q)=>q.id===K);if(F)this.selectedNodeId=F.id,this.stopAnimation(),this.currentOffset={x:0,y:0}}let V=J.props.threads.some((G)=>G.isActive),z=this.widget.props.threads.some((G)=>G.isActive);if(V!==z){if(this.stopActiveFlashTimer(),z)this.startActiveFlashTimer()}}dispose(){this.stopAnimation(),this.stopActiveFlashTimer()}startAnimation(J){this.stopAnimation(),this.animation={startOffset:{...this.currentOffset},targetOffset:J,startTime:Date.now(),durationX:Eg4,durationY:Mg4};let Z=Math.max(Eg4,Mg4);this.animationTimer=setInterval(()=>{let Q=Date.now();if(this.currentOffset=da(this.animation,Q),this.animation&&Q-this.animation.startTime>=Z)this.currentOffset={...this.animation.targetOffset},this.stopAnimation();this.setState()},KI3)}stopAnimation(){if(this.animationTimer)clearInterval(this.animationTimer),this.animationTimer=null;this.animation=null}calculateCenterOffset(J,Z,Q){let Y=Math.floor(this.renderer.getNodeWidth()/2),K=Math.floor(this.viewportWidth/2)-J-Y,V=Q-Z,z=2,G=Math.floor(this.viewportHeight/2),q=Math.floor(G/2)-V;return{x:K,y:q}}animateToNode(J){let Z=this.positionedNodes.find((Q)=>Q.node.id===J);if(Z){let Q=Math.max(...this.positionedNodes.map((X)=>X.position.y)),Y=this.calculateCenterOffset(Z.position.x,Z.position.y,Q);this.startAnimation(Y)}}toGraphNodes(){return this.widget.props.threads.map((J)=>({id:J.id,parentID:J.parentID,data:{title:J.title,updatedAt:J.updatedAt,isActive:J.isActive}}))}toThreadNode(J){return{id:J.node.id,parentID:J.node.parentID,title:J.node.data.title,updatedAt:J.node.data.updatedAt}}handleKeyEvent=(J)=>{if(!this.selectedNodeId)return"ignored";let Z=this.positionedNodes,Q=Z.find((X)=>X.node.id===this.selectedNodeId);if(!Q)return"ignored";let Y;switch(J.key){case"ArrowUp":{let X=Z.filter((K)=>K.node.parentID===Q.node.id);if(X.length>0){X.sort((V,z)=>V.position.x-z.position.x);let K=Math.floor(X.length/2);Y=X[K]}break}case"ArrowDown":{Y=Z.find((X)=>X.node.id===Q.node.parentID);break}case"ArrowLeft":{let X=Z.filter((K)=>K.position.y===Q.position.y&&K.position.x<Q.position.x);if(X.length>0)X.sort((K,V)=>V.position.x-K.position.x),Y=X[0];break}case"ArrowRight":{let X=Z.filter((K)=>K.position.y===Q.position.y&&K.position.x>Q.position.x);if(X.length>0)X.sort((K,V)=>K.position.x-V.position.x),Y=X[0];break}case"Enter":{if(this.widget.props.onSelect)this.widget.props.onSelect(this.toThreadNode(Q));return"handled"}default:{if(this.widget.props.onKey)return this.widget.props.onKey(J);return"ignored"}}if(Y)return this.selectedNodeId=Y.node.id,this.widget.props.onSelectionChange?.(this.toThreadNode(Y)),this.animateToNode(Y.node.id),"handled";if(this.widget.props.onKey)return this.widget.props.onKey(J);return"ignored"};build(J){let Z=this.toGraphNodes();this.positionedNodes=this.layoutEngine.layout(Z);let Q=this.lineCalculator.calculate(this.positionedNodes);if(!this.animation&&this.currentOffset.x===0&&this.currentOffset.y===0){let q=(this.selectedNodeId?this.positionedNodes.find((W)=>W.node.id===this.selectedNodeId):null)??this.positionedNodes.find((W)=>!W.node.parentID);if(q){let W=Math.max(...this.positionedNodes.map((U)=>U.position.y));this.currentOffset=this.calculateCenterOffset(q.position.x,q.position.y,W)}}let X=this.widget.props.showTitle??!0,K=this.widget.props.offsetY??0,V={x:this.currentOffset.x,y:this.currentOffset.y+K},z=this.renderer.render(this.positionedNodes,Q,this.selectedNodeId??void 0,V,X?(F)=>F.title:void 0,{maxTitleWidthPercent:this.widget.props.maxTitleWidthPercent,viewportWidth:this.viewportWidth,activeFlashOn:this.activeFlashOn},(F)=>F.isActive??!1,J),G=new ca({onWidth:(F)=>{if(this.viewportWidth!==F)this.viewportWidth=F,this.stopAnimation(),this.currentOffset={x:0,y:0},this.setState()},onHeight:(F)=>{if(this.viewportHeight!==F)this.viewportHeight=F,this.stopAnimation(),this.currentOffset={x:0,y:0},this.setState()},child:z});return new s4({autofocus:this.widget.props.autofocus??!0,onKey:this.handleKeyEvent,debugLabel:"MiniThreadGraph",child:G})}getSelectedNode(){let J=this.positionedNodes.find((Z)=>Z.node.id===this.selectedNodeId);return J?this.toThreadNode(J):null}}class Rg4 extends l0{child;onContext;constructor(J,Z){super();this.child=J;this.onContext=Z}createState(){return new Ig4}}class Ig4 extends d0{build(J){return this.widget.onContext(J),this.widget.child}}var jg4=30,VI3=30;class Av{}class jv{}class UG0{}class DG0{}class b01 extends l0{props;constructor(J){super();this.props=J}createState(){return new Pg4}}class Pg4 extends d0{highlightedIndex=0;controller=new J$;focusNode;scrollController=new A5;filteredClusters=[];itemContexts=[];initState(){this.focusNode=new W6({debugLabel:"ClusterPicker"}),this.scrollController.disableFollowMode(),this.recomputeFiltered(),this.controller.addListener(()=>{this.highlightedIndex=0,this.recomputeFiltered(),this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()})})}didUpdateWidget(J){if(J.props.clusters!==this.widget.props.clusters){if(this.recomputeFiltered(),this.highlightedIndex>=this.filteredClusters.length)this.highlightedIndex=Math.max(0,this.filteredClusters.length-1)}}ensureSelectedItemVisible(){let J=this.itemContexts[this.highlightedIndex];if(!J)return;let Z=J.findRenderObject();if(!Z)return;let Q=0,Y=Z.size.height;Uv(J,{top:Q,bottom:Y},{padding:1})}dispose(){this.controller.dispose(),this.focusNode.dispose(),this.scrollController.dispose()}recomputeFiltered(){let J=this.controller.text.toLowerCase(),{clusters:Z}=this.widget.props;if(!J)this.filteredClusters=[...Z];else this.filteredClusters=Z.filter((Q)=>Q.label.toLowerCase().includes(J))}invoke=(J)=>{if(J instanceof Av){if(this.highlightedIndex<this.filteredClusters.length-1)this.highlightedIndex++,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()});return"handled"}if(J instanceof jv){if(this.highlightedIndex>0)this.highlightedIndex--,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()});return"handled"}if(J instanceof UG0){let Z=this.filteredClusters[this.highlightedIndex];if(Z)this.widget.props.onAccept(Z);return"handled"}if(J instanceof DG0)return this.widget.props.onDismiss(),"handled";return"ignored"};handleItemClick=(J,Z)=>{if(J>=0&&J<this.filteredClusters.length){if(Z===1)this.highlightedIndex=J,this.setState();else if(Z===2){let Q=this.filteredClusters[J];if(Q)this.widget.props.onAccept(Q)}}};handleScroll=(J)=>{if(this.filteredClusters.length===0)return!1;let Z=this.highlightedIndex;if(J.direction==="down")if(this.highlightedIndex<this.filteredClusters.length-1)this.highlightedIndex++;else return!1;else if(this.highlightedIndex>0)this.highlightedIndex--;else return!1;return this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.highlightedIndex!==Z};build(J){let{currentThreadID:Z}=this.widget.props,Q=f0.of(J),{colors:Y,app:X}=Q,z=K4.of(J).size.width>=VI3+jg4,G=c1.all(new h1(Y.foreground,1,"solid")),F=this.filteredClusters[this.highlightedIndex]??null,q=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C("Select a cluster",new g({color:X.command,bold:!0}))})}),W=new CZ({controller:this.controller,focusNode:this.focusNode,autofocus:!0,enabled:!0,style:{textColor:Y.foreground,border:null},maxLines:1}),U=new h$({shortcuts:new Map([[new D4("ArrowDown"),new Av],[new D4("ArrowUp"),new jv],[new D4("Tab"),new Av],[new D4("Tab",{shift:!0}),new jv],[new D4("n",{ctrl:!0}),new Av],[new D4("p",{ctrl:!0}),new jv],[new D4("Enter"),new UG0],[new D4("Escape"),new DG0]]),focusNode:this.focusNode,child:W}),D=new L2({actions:new Map([[Av,new U6(this.invoke)],[jv,new U6(this.invoke)],[UG0,new U6(this.invoke)],[DG0,new U6(this.invoke)]]),child:U}),H=new q1({children:[new i0({decoration:{color:Y.background},child:new $0({text:new C(">",new g({color:Y.foreground}))})}),new k1({child:D})]});this.itemContexts=[];let B=this.filteredClusters.map((M,A)=>{let j=A===this.highlightedIndex,R=Z?M.threads.some((m)=>m.id===Z):!1,_=j?X.selectionBackground:void 0,k=j?X.selectionForeground:Y.foreground,u=[new C(M.label,new g({color:k})),new C(` (${M.threads.length})`,new g({color:k,dim:!0}))];if(R)u.push(new C(" (current)",new g({color:j?X.selectionForeground:Y.success})));return new Rg4(new e1({onClick:(m)=>this.handleItemClick(A,m.clickCount),child:new i0({decoration:_?{color:_}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C("",void 0,u)})})}),(m)=>{this.itemContexts[A]=m})}),N=new x0({children:B,crossAxisAlignment:"start"}),w=new k1({child:new e1({onScroll:this.handleScroll,child:new T6({controller:this.scrollController,autofocus:!1,child:N})})}),O=F?F.threads.map((M)=>({id:M.id,title:M.title,parentID:M.parentID,updatedAt:M.updatedAt})):[],L=F?new i0({padding:C0.all(1),child:new RR({threads:O,autofocus:!1,offsetY:2})}):null,E;if(z){let M=L?new k1({child:L}):new I0({width:jg4});E=new q1({crossAxisAlignment:"stretch",mainAxisAlignment:"start",children:[w,M]})}else{let M=[new k1({child:new e1({onScroll:this.handleScroll,child:new T6({controller:this.scrollController,autofocus:!1,child:N})})})];if(L)M.push(new k1({child:L}));E=new x0({crossAxisAlignment:"stretch",children:M})}return new i0({decoration:{border:G,color:Y.background},padding:C0.symmetric(1,0),child:new x0({children:[q,H,new I0({height:1}),new k1({child:E})]})})}}class kJ{static _instance=null;_allExpanded=!1;_listeners=new Set;static get instance(){if(!kJ._instance)kJ._instance=new kJ;return kJ._instance}get allExpanded(){return this._allExpanded}setAllExpanded(J){if(this._allExpanded===J)return;this._allExpanded=J,this._notifyListeners()}toggleAll(){this.setAllExpanded(!this._allExpanded)}addListener(J){return this._listeners.add(J),()=>this.removeListener(J)}removeListener(J){this._listeners.delete(J)}_notifyListeners(){for(let J of this._listeners)J()}}g0();class Cg4 extends d0{labels=[];isLoading=!0;currentQuery="";initState(){this.loadLabels()}async loadLabels(){try{let J=await this.widget.props.internalAPIClient.getUserLabels({query:""},{config:this.widget.props.configService});if(!J.ok){I.error("Failed to load labels",J.error),this.isLoading=!1,this.labels=[],this.setState();return}this.labels=J.result,this.isLoading=!1,this.setState()}catch(J){I.error("Failed to load labels",J),this.isLoading=!1,this.labels=[],this.setState()}}getValidationError(J){let Z=J.trim().toLowerCase();if(Z.length===0)return null;if(Z.length>32)return"Label name cannot exceed 32 characters";if(!/^[a-z0-9][a-z0-9-]*$/.test(Z))return"Label must be alphanumeric with hyphens, starting with a letter or number";return null}isValidLabelName(J){return this.getValidationError(J)===null&&J.length>0}getAvailableLabels(){let J=this.widget.props.currentLabels||[];return this.labels.filter((Z)=>!J.includes(Z.name))}shouldShowCreateMarker(J){if(J.length===0||this.isLoading)return!1;let Z=J.trim().toLowerCase();if(!this.isValidLabelName(Z))return!1;let Q=this.widget.props.currentLabels||[],Y=this.labels.some((K)=>K.name===Z),X=Q.includes(Z);return!Y&&!X}build(J){let Z=f0.of(J),{app:Q,colors:Y}=Z,X=this.currentQuery.trim().toLowerCase(),K=X.length>0?this.getValidationError(X):null,V=this.getAvailableLabels(),G=[{id:"__create__",name:"__create_placeholder__",createdAt:"",__isCreateMarker:!0},...V];return new a2({title:"Add Label",items:G,getLabel:(F)=>{if("__isCreateMarker"in F)return this.currentQuery.trim().toLowerCase();return F.name},onAccept:(F)=>{if("__isCreateMarker"in F)this.widget.props.onSelect(this.currentQuery.trim().toLowerCase());else this.widget.props.onSelect(F.name)},onDismiss:this.widget.props.onDismiss,isLoading:this.isLoading,loadingText:"Loading labels...",emptyStateText:K||"Type to create a new label",renderItem:(F,q,W,U)=>{let D=q?Q.selectionBackground:void 0,H=q?Q.selectionForeground:Y.foreground;if("__isCreateMarker"in F&&F.__isCreateMarker){let N=this.currentQuery.trim().toLowerCase();return new i0({decoration:D?{color:D}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C("",void 0,[new C("Create new label: ",new g({color:H})),new C(N,new g({color:H,bold:!0}))])})})}return new i0({decoration:D?{color:D}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C(F.name,new g({color:H}))})})},filterItem:(F,q)=>{if(this.currentQuery!==q)this.currentQuery=q,setTimeout(()=>this.setState(),0);if("__isCreateMarker"in F&&F.__isCreateMarker)return this.shouldShowCreateMarker(q);let U=q.trim().toLowerCase();return U.length===0||F.name.includes(U)},sortItems:(F,q,W)=>{let U="__isCreateMarker"in F.item&&F.item.__isCreateMarker,D="__isCreateMarker"in q.item&&q.item.__isCreateMarker;if(U&&!D)return-1;if(!U&&D)return 1;return q.score-F.score}})}}class h01 extends l0{props;constructor(J){super();this.props=J}createState(){return new Cg4}}class dz extends l0{props;constructor(J){super();this.props=J}createState(){return new Tg4}}class Tg4 extends d0{_spinner=new M3;animationInterval=null;initState(){super.initState(),this.animationInterval=setInterval(()=>{this._spinner.step(),this.setState(()=>{})},100)}dispose(){if(this.animationInterval)clearInterval(this.animationInterval),this.animationInterval=null;super.dispose()}build(J){let Z=f0.of(J),{colors:Q,app:Y}=Z,X=c1.all(new h1(Q.foreground,1,"solid")),K=this._spinner.toBraille(),V=new $0({textAlign:"center",text:new C("",void 0,[new C(K,new g({color:Y.processing})),new C(" ",void 0),new C(this.widget.props.message,new g({color:Q.foreground}))])}),G=[new k1({child:new x0({mainAxisAlignment:"center",crossAxisAlignment:"center",children:[V]})})];if(this.widget.props.onAbort)G.push(new I0({height:2,child:new i0({padding:C0.symmetric(2,0),child:new $0({text:new C("",new g({dim:!0}),[new C("Press ",new g({color:Q.foreground})),new C("Esc",new g({color:Q.info})),new C(" to cancel",new g({color:Q.foreground}))])})})}));let F=new i0({decoration:new r4(Q.background,X),child:new I0({width:60,height:7,child:new x0({mainAxisAlignment:"start",children:G})})});if(this.widget.props.onAbort)return new s4({debugLabel:"LoadingDialog",autofocus:!0,onKey:(q)=>{if(q.key==="Escape")return this.widget.props.onAbort?.(),"handled";return"ignored"},child:F});return F}}var la={workspace:{label:"Workspace",pathHint:".amp/settings.json",description:"workspace config"},global:{label:"Global",pathHint:"~/.config/amp/settings.json",description:"global config"},flag:{label:"Flag",pathHint:"CLI flags",description:"flag config"},default:{label:"Default",pathHint:"built-in defaults",description:"default config"},external:{label:"External",pathHint:"extensions / external",description:"external source"},skill:{label:"Skills",pathHint:".agents/skills/",description:"skill source"},other:{label:"Other",pathHint:"",description:"other source"}},HG0=["workspace","global","flag","default","external","skill","other"];function zI3(J){return Array.from(new Set(J))}function _g4(J){return zI3([...J.skillNames??[],...J.skillName?[J.skillName]:[]])}function Rv(J){if(J.isExternal)return"external";switch(J.spec._target){case"workspace":return"workspace";case"global":return"global";case"flag":return"flag";case"default":return"default"}return _g4(J).length>0?"skill":"other"}function g01(J){return Rv(J)==="skill"}function Sg4(J){let Z=_g4(J);if(Z.length===0)return;let Q=Z.join(", "),Y=Rv(J);if(Y==="skill")return`skills: ${Q}`;return`${Z.length===1?"skill source":"skill sources"} overridden by ${la[Y].description}: ${Q}`}function kg4(J){return J.spec.meta?.skillNames?Array.from(J.spec.meta.skillNames):[]}var yg4=process.platform==="win32"?" ":"█",vg4=process.platform==="win32"?"░":"█";class O9 extends l0{controller;getScrollInfo;thickness;trackChar;thumbChar;showTrack;thumbColor;trackColor;constructor({key:J,controller:Z,getScrollInfo:Q,thickness:Y=1,trackChar:X=yg4,thumbChar:K=vg4,showTrack:V=!0,thumbColor:z,trackColor:G}){super(J?{key:J}:{});this.controller=Z,this.getScrollInfo=Q,this.thickness=Y,this.trackChar=X,this.thumbChar=K,this.showTrack=V,this.thumbColor=z,this.trackColor=G}createState(){return new xg4}}class xg4 extends d0{_dragStartY=null;_dragStartOffset=null;_isOverThumb=!1;_isPositionOverThumb(J){let{totalContentHeight:Z,viewportHeight:Q}=this.widget.getScrollInfo(),X=this.context.findRenderObject()?.size.height??0;if(X===0||Z<=Q)return!1;let K=this.widget.getScrollInfo(),V=Math.min(1,Q/Z),z=Math.max(1,X*V),G=Math.max(0,Math.min(1,K.scrollOffset/(Z-Q))),F=X-z,q=Math.max(0,F*G),W=q+z;return J>=q&&J<=W}_handleHover=(J)=>{let Z=this._isOverThumb;if(this._isOverThumb=this._isPositionOverThumb(J.localPosition.y),Z!==this._isOverThumb)this.setState()};_handleDrag=(J)=>{let{totalContentHeight:Z,viewportHeight:Q,scrollOffset:Y}=this.widget.getScrollInfo(),K=this.context.findRenderObject()?.size.height??0;if(K===0||Z<=Q)return;if(this._dragStartY===null)this._dragStartY=J.localPosition.y,this._dragStartOffset=Y;let V=J.localPosition.y-this._dragStartY,z=Math.min(1,Q/Z),G=Math.max(1,K*z),F=K-G;if(F<=0)return;let q=Z-Q,W=F/q,U=V/W,D=Math.max(0,Math.min(q,this._dragStartOffset+U));this.widget.controller.jumpTo(D)};_handleRelease=()=>{this._dragStartY=null,this._dragStartOffset=null};_handleClick=(J)=>{if(J.button!=="left")return;let Z=J.localPosition.y,{totalContentHeight:Q,viewportHeight:Y,scrollOffset:X}=this.widget.getScrollInfo(),V=this.context.findRenderObject()?.size.height??0;if(V===0||Q<=Y)return;let z=Math.min(1,Y/Q),G=Math.max(1,V*z),F=Q-Y,q=V-G,W=Math.max(0,Math.min(1,X/(Q-Y))),U=Math.max(0,q*W),D=U+G;if(Z>=U&&Z<=D)return;if(Z<U)this.widget.controller.animateTo(Math.max(0,X-Y));else this.widget.controller.animateTo(Math.min(F,X+Y))};build(J){return new e1({onClick:this._handleClick,onHover:this._handleHover,onDrag:this._handleDrag,onRelease:this._handleRelease,cursor:this._isOverThumb?b5.POINTER:b5.DEFAULT,child:new fg4({controller:this.widget.controller,getScrollInfo:this.widget.getScrollInfo,thickness:this.widget.thickness,trackChar:this.widget.trackChar,thumbChar:this.widget.thumbChar,showTrack:this.widget.showTrack,thumbColor:this.widget.thumbColor,trackColor:this.widget.trackColor})})}}class fg4 extends jk{controller;getScrollInfo;thickness;trackChar;thumbChar;showTrack;thumbColor;trackColor;constructor({key:J,controller:Z,getScrollInfo:Q,thickness:Y=1,trackChar:X=yg4,thumbChar:K=vg4,showTrack:V=!0,thumbColor:z,trackColor:G}){super(J?{key:J}:{});this.controller=Z,this.getScrollInfo=Q,this.thickness=Y,this.trackChar=X,this.thumbChar=K,this.showTrack=V,this.thumbColor=z,this.trackColor=G}createRenderObject(){return new ug4(this)}updateRenderObject(J){J.updateWidget(this)}}class ug4 extends v4{_widget;constructor(J){super();this._widget=J}updateWidget(J){this._widget=J,this.markNeedsLayout()}performLayout(){let J=this._lastConstraints;J6(!!J,"performLayout called without constraints");let Z=Math.min(J.maxWidth,this._widget.thickness),Q=J.maxHeight;this.setSize(Z,Q),super.performLayout()}getMinIntrinsicWidth(J){return this._widget.thickness}getMaxIntrinsicWidth(J){return this._widget.thickness}getMinIntrinsicHeight(J){return 0}getMaxIntrinsicHeight(J){return 0}paint(J,Z,Q){let{thumbStartFloat:Y,thumbSizeFloat:X,showScrollbar:K}=this._calculateScrollbarMetrics();if(!K)return;let V=this._widget.trackColor,z=this._widget.thumbColor,G=process.platform==="win32",F=Y,q=Y+X;if(!G){let W=["▁","▂","▃","▄","▅","▆","▇","█"];for(let U=0;U<this.size.height;U++){let D="█",H=!0;if(U===Math.floor(F)){let B=1-(F-U),N=Math.floor(B*8);D=W[N]||"█",H=!1}else if(U===Math.floor(q)){let B=1-(q-U),N=Math.floor(B*8);D=W[N]||"█"}else if(U>F&&U<q)H=!1;J.setChar(Z,Q+U,D,{fg:z,bg:V,reverse:H},1)}return}for(let W=0;W<this.size.height;W++){let U=W+0.5,D=U>=F&&U<q,H=D?this._widget.thumbChar:this._widget.trackChar;J.setChar(Z,Q+W,H,{fg:D?z:V,bg:V,reverse:!1},1)}}_calculateScrollbarMetrics(){let{totalContentHeight:J,viewportHeight:Z,scrollOffset:Q}=this._widget.getScrollInfo(),Y=this.size.height;if(J<=Z||Y<=0)return{thumbStartFloat:0,thumbSizeFloat:0,showScrollbar:!1};let X=Math.max(0,Math.min(1,Q/(J-Z))),K=Math.min(1,Z/J),V=Math.max(1,Y*K),z=Y-V;return{thumbStartFloat:Math.max(0,z*X),thumbSizeFloat:V,showScrollbar:!0}}}class IR extends l0{props;constructor(J){super();this.props=J}createState(){return new bg4}}class bg4 extends d0{scrollController=new A5;scrollAreaKey=new p7("message-dialog-scroll-area");viewportHeight=20;initState(){super.initState(),this.scrollController.followMode=!1,this.scrollController.addListener(()=>{this.setState()})}dispose(){this.scrollController.dispose(),super.dispose()}isWidgetMessage(J){return J instanceof n2}resolveFooterStyle(J){if(this.isWidgetMessage(J))return J.footerStyle;return"default"}getViewportHeight(){let Z=this.scrollAreaKey.currentElement?.renderObject;if(Z&&"size"in Z){let Q=Z.size;if(typeof Q.height==="number"&&Q.height>0)return this.viewportHeight=Q.height,Q.height}return this.viewportHeight}build(J){let Z=f0.of(J),Q=this.widget.props.message,Y=(()=>{if(this.isWidgetMessage(Q))return{title:Q.title,type:Q.type};if(Q instanceof Error&&Q.name==="CommandCancelledError")return{title:"Cancelled",type:"info",description:Q.message};if(Q instanceof Error&&Q.name==="CommandTimeoutError")return{title:"Timeout",type:"error",description:Q.message};let q=dz0(Q);return{title:q.title,type:q.type,description:q.description}})(),X=Y.type==="error"?Z.app.toolError:Z.app.command,K=c1.all(new h1(Z.colors.border,1,"solid")),V=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C(Y.title,new g({color:X,bold:!0}))})}),z=this.isWidgetMessage(Q)?Q.widget:new $0({text:new C(Y.description,new g({color:Z.colors.foreground})),selectable:!0}),G=new k1({child:new g$({child:new i0({padding:C0.symmetric(1,0),child:new q1({key:this.scrollAreaKey,crossAxisAlignment:"stretch",children:[new k1({child:new T6({controller:this.scrollController,autofocus:!0,child:z})}),new O9({controller:this.scrollController,thumbColor:Z.app.scrollbarThumb,trackColor:Z.app.scrollbarTrack,getScrollInfo:()=>{let q=this.scrollController.maxScrollExtent,W=this.scrollController.offset,U=this.getViewportHeight(),D=q+U;return{totalContentHeight:Math.max(D,0),viewportHeight:Math.max(U,1),scrollOffset:Math.max(W,0)}}})]})})})}),F=new i0({padding:C0.symmetric(1,0),child:new $0({text:(()=>{if(this.widget.props.onRetry)return new C("",void 0,[new C("Press ",new g({color:Z.colors.foreground,dim:!0})),new C("R",new g({color:Z.app.keybind})),new C(" to retry, ",new g({color:Z.colors.foreground,dim:!0})),new C("Esc",new g({color:Z.app.keybind})),new C(" to cancel",new g({color:Z.colors.foreground,dim:!0}))]);let q=this.resolveFooterStyle(this.widget.props.message);if(q==="none")return new C("",new g({color:Z.colors.foreground,dim:!0}));if(q==="help"){let W=new g({color:Z.app.keybind}),U=new g({color:Z.colors.foreground,dim:!0});return new C("",U,[new C("Press ",U),new C("Escape",W),new C(" to close • Use ",U),new C("↑↓",W),new C(" or ",U),new C("j/k",W),new C(" to scroll",U)])}return new C("Press any key to close",new g({color:Z.colors.foreground,dim:!0,italic:!0}))})()})});return new s4({onKey:(q)=>{if(this.widget.props.onRetry&&q.key==="r")return this.widget.props.onRetry(),"handled";if(q.key==="Escape")return this.widget.props.onDismiss(),"handled";if(!this.widget.props.onRetry)return this.widget.props.onDismiss(),"handled";return"ignored"},autofocus:!1,child:new i0({decoration:{border:K,color:Z.colors.background},padding:C0.all(1),child:new x0({mainAxisAlignment:"center",children:[V,new I0({height:1}),G,F]})})})}}P2();class hg4 extends l0{props;constructor(J){super();this.props=J}createState(){return new gg4}}class gg4 extends d0{plugins=[];subscription=null;initState(){this.subscription=this.widget.props.pluginService.plugins.subscribe((J)=>{this.plugins=J,this.setState(()=>{})})}dispose(){this.subscription?.unsubscribe(),super.dispose()}getRelativePath(J){let Z=J.startsWith("file://")?J.slice(7):J,Q=this.widget.props.cwd;if(Z.startsWith(Q))return Z.slice(Q.length+1);return Z}statusIcon(J){let Z=_9.default(),{colors:Q,app:Y}=Z;switch(J){case"loading":return{icon:"◌",color:Q.warning};case"active":return{icon:"✓",color:Y.toolSuccess};case"error":return{icon:"✗",color:Y.toolError}}}build(J){let Z=f0.of(J),{app:Q}=Z;if(this.plugins.length===0)return new $0({text:new C("No plugins found.",new g({dim:!0}))});let Y=[],X=this.plugins.length,K=this.plugins.filter((G)=>G.status==="active").length,V=this.plugins.reduce((G,F)=>G+F.registeredCommands.length,0),z=this.plugins.reduce((G,F)=>G+F.registeredTools.length,0);if(Y.push(new C(`${K}/${X} ${d4(X,"plugin")} active`,new g({bold:!0}))),V>0||z>0)Y.push(new C(` (${V} ${d4(V,"command")}, ${z} ${d4(z,"tool")})`,new g({dim:!0})));Y.push(new C(`
7374
+ `))}if(H)W.push(new C(" ",q)),W.push(new C("Total: ",q)),W.push(new C(K(B),F))}return new i0({decoration:{color:z.background,border:c1.all(new h1(z.border,1,"rounded"))},child:new $0({text:new C(void 0,void 0,W)})})}YE();g0();P2();import{execSync as OI3}from"node:child_process";GE();B$();n3();I7();fd();nM();LV();O$();rJ();FY();RA();f4();ag();ou();N1();var Vm4=z4($U(),1);import{writeFile as Zm4}from"fs/promises";import Qm4 from"path";g0();O$();class k01{enabled;configService;commandCounts=new Map;timer=null;bufferTimeMs=1e4;constructor(J,Z){this.enabled=J;this.configService=Z;this.startTimer()}startTimer(){this.timer=setInterval(()=>{this.flushEvents()},this.bufferTimeMs)}async flushEvents(){if(this.commandCounts.size===0||!await this.enabled())return;let J=Array.from(this.commandCounts.entries()).map(([Z,Q])=>({feature:"cli.command",action:Z,source:{client:"cli",clientVersion:"0.0.1774126892-geb7ca3"},parameters:{metadata:{count:Q}},timestamp:Date.now()*1000}));this.commandCounts.clear();try{let Z=JSON.stringify(J);await x40(Z,this.configService)}catch(Z){I.error("Failed to export command telemetry events",Z)}}async submit(J){if(!await this.enabled()||this.timer===null)return;let Z=this.commandCounts.get(J)||0;this.commandCounts.set(J,Z+1)}async dispose(){if(await this.flushEvents(),this.timer!==null)clearInterval(this.timer),this.timer=null}}class VO extends l0{props;constructor(J){super();this.props=J}createState(){return new zg4}}class zg4 extends d0{_state;initState(){super.initState(),this._state=this.widget.props.initialState}build(J){let Z=(Q)=>{this.setState(()=>{this._state=Q(this._state)})};return this.widget.props.builder(J,Z,this._state)}}class Gg4 extends d0{controller=new J$;focusNode=new W6({debugLabel:"CommandArgumentPrompt",onKey:(J)=>{if(J.key==="Escape")return this.widget.props.onDismiss(),"handled";return"ignored"}});_textListener=()=>{this.setState(()=>{})};initState(){this.focusNode.requestFocus(),this.controller.addListener(this._textListener)}dispose(){this.controller.removeListener(this._textListener),this.focusNode.dispose()}build(J){let Z=f0.of(J),{colors:Q,app:Y}=Z,X=this.widget.props.isRequiredArg??!0,K=this.controller.text.trim().length>0,V=!X||K,z=c1.all(new h1(Q.foreground,1,"solid")),G=new CZ({controller:this.controller,focusNode:this.focusNode,placeholder:this.widget.props.placeholder??"Enter command argument...",onSubmitted:(D)=>{let H=D.trim();if(X&&H.length===0)return;this.widget.props.onSubmit(H)},autofocus:!0,style:{textColor:Q.foreground,border:null},maxLines:1}),F=new q1({children:[new i0({decoration:{color:Q.background},child:new $0({text:new C(">",new g({color:Q.foreground}))})}),new k1({child:G})]}),q=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C("",void 0,[new C("Command: ",new g({color:Q.foreground})),new C(this.widget.props.commandName,new g({color:Y.command,bold:!0}))])})}),W=[];if(V)W.push(new C("Enter",new g({color:Y.keybind}))),W.push(new C(" to submit, ",new g({color:Q.foreground,dim:!0})));W.push(new C("Esc",new g({color:Y.keybind}))),W.push(new C(" to cancel",new g({color:Q.foreground,dim:!0})));let U=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C("",void 0,W)})});return new i0({decoration:{border:z,color:Q.background},padding:C0.all(1),child:new x0({children:[q,new I0({height:1}),F,new b3,U]})})}}class pa extends l0{props;constructor(J){super();this.props=J}createState(){return new Gg4}}import{isDeepStrictEqual as y01}from"node:util";var iR3=/[\\/_ +.#"@[({&]/,nR3=/[\\/_ +.#"@[({&]/g,aR3=/[\s-]/,Fg4=/[\s-]/g;function VG0(J,Z,Q,Y,X,K,V){if(K===Z.length){if(X===J.length)return 1;return 0.99}let z=`${X},${K}`;if(V[z]!==void 0)return V[z];let G=Y.charAt(K),F=Q.indexOf(G,X),q=0,W,U,D,H;while(F>=0){if(W=VG0(J,Z,Q,Y,F+1,K+1,V),W>q){if(F===X)W*=1;else if(aR3.test(J.charAt(F-1))){if(W*=0.9,H=J.slice(X,F-1).match(Fg4),H&&X>0)W*=0.999**H.length}else if(iR3.test(J.charAt(F-1))){if(W*=0.8,D=J.slice(X,F-1).match(nR3),D&&X>0)W*=0.999**D.length}else if(W*=0.3,X>0)W*=0.999**(F-X);if(J.charAt(F)!==Z.charAt(K))W*=0.9999}if(W<0.1&&(Q.charAt(F-1)===Y.charAt(K+1)||Y.charAt(K+1)===Y.charAt(K)&&Q.charAt(F-1)!==Y.charAt(K))){if(U=VG0(J,Z,Q,Y,F+1,K+2,V),U*0.1>W)W=U*0.1}if(W>q)q=W;F=Q.indexOf(G,F+1)}return V[z]=q,q}function KG0(J){return J.toLowerCase().replace(Fg4," ")}function qg4(J,Z){let Q=VG0(J,Z,KG0(J),KG0(Z),0,0,{}),Y=Z.trim().split(/\s+/);if(Y.length>1){let X=0,K=0;for(let z of Y){let G=VG0(J,z,KG0(J),KG0(z),0,0,{});if(G===0)return Q;X+=G,K+=z.length}let V=X/Y.length*0.95;return Math.max(Q,V)}return Q}class Ov{}class Lv{}class zG0{}class GG0{}class Wg4 extends l0{child;onContext;constructor(J,Z){super();this.child=J;this.onContext=Z}createState(){return new Ug4}}class Ug4 extends d0{build(J){return this.widget.onContext(J),this.widget.child}}function oR3(J,Z){if(J==="")return{matches:!0,score:1};let Q=qg4(Z,J);return{matches:Q>0.15,score:Q}}class a2 extends l0{props;debugLabel="FuzzyPicker";constructor(J){super();this.props=J}createState(){return new Dg4}}class Dg4 extends d0{textController;focusNode;scrollController=new A5;selectedIndex=0;itemContexts=[];hasUserInteracted=!1;cachedQuery="";cachedItemsRef=null;cachedFiltered=[];initState(){if(this.scrollController.disableFollowMode(),this.textController=new J$(this.widget.props.controller?.query??""),this.focusNode=new W6({debugLabel:this.widget.debugLabel}),this.textController.addListener(()=>{this.hasUserInteracted=!0,this.selectedIndex=0,this.recomputeFilteredItems(),this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()});let J=this.widget.props.controller;if(J)J.query=this.textController.text;this.syncSelection()}),this.recomputeFilteredItems(),this.widget.props.controller?.selectedItem){let J=this.cachedFiltered.findIndex((Z)=>y01(Z,this.widget.props.controller?.selectedItem));if(J>=0)this.selectedIndex=J}this.clampSelectedIndex(),this.syncSelection(),this.ensureSelectedItemVisible()}didUpdateWidget(J){if(!y01(J.props.items,this.widget.props.items)){if(this.recomputeFilteredItems(),this.widget.props.controller?.selectedItem){let Z=this.cachedFiltered.findIndex((Q)=>y01(Q,this.widget.props.controller?.selectedItem));if(Z>=0)this.selectedIndex=Z}this.clampSelectedIndex(),this.ensureSelectedItemVisible(),this.syncSelection()}}dispose(){this.widget.props.onSelectionChange?.(null),this.textController.dispose(),this.focusNode.dispose(),this.scrollController.dispose()}invoke=(J)=>{if(J instanceof Ov){let Z=this.getFilteredItems();if(Z.length>0&&this.selectedIndex<Z.length-1)this.hasUserInteracted=!0,this.selectedIndex++,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.syncSelection();return"handled"}if(J instanceof Lv){if(this.getFilteredItems().length>0&&this.selectedIndex>0)this.hasUserInteracted=!0,this.selectedIndex--,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.syncSelection();return"handled"}if(J instanceof zG0){let Z=this.getFilteredItems();if(Z.length>0&&this.selectedIndex<Z.length){let Q=Z[this.selectedIndex];if(Q){if(!(this.widget.props.isItemDisabled?.(Q)??!1))this.widget.props.onAccept(Q,{hasUserInteracted:this.hasUserInteracted})}}return"handled"}if(J instanceof GG0)return this.widget.props.onDismiss?.(),"handled";return"ignored"};syncSelection(){let Z=this.cachedFiltered[this.selectedIndex]??null;if(this.widget.props.controller)this.widget.props.controller.selectedItem=Z;this.widget.props.onSelectionChange?.(Z)}clampSelectedIndex(){let J=this.cachedFiltered.length-1;if(J<0){this.selectedIndex=0;return}this.selectedIndex=Math.max(0,Math.min(this.selectedIndex,J))}recomputeFilteredItems(){let J=this.textController.text,Z=this.widget.props.items,Q=this.widget.props.normalizeQuery?.(J)??J,Y=Z.filter((X)=>!this.widget.props.filterItem||this.widget.props.filterItem(X,J)).map((X)=>({item:X,...oR3(Q,this.widget.props.getLabel(X))})).filter((X)=>X.matches).sort(this.widget.props.sortItems?(X,K)=>this.widget.props.sortItems(X,K,J):(X,K)=>K.score-X.score).map((X)=>X.item);this.cachedQuery=J,this.cachedItemsRef=Z,this.cachedFiltered=this.widget.props.maxRenderItems?Y.slice(0,this.widget.props.maxRenderItems):Y}getFilteredItems(){let J=this.textController.text,Z=this.widget.props.items;if(this.cachedQuery===J&&this.cachedItemsRef===Z)return this.cachedFiltered;return this.recomputeFilteredItems(),this.cachedFiltered}ensureSelectedItemVisible(){let J=this.itemContexts[this.selectedIndex];if(!J)return;let Z=J.findRenderObject();if(!Z)return;let Q=0,Y=Z.size.height;Uv(J,{top:Q,bottom:Y},{padding:1})}handleScroll=(J)=>{let Z=this.getFilteredItems();if(Z.length===0)return!1;let Q=this.selectedIndex;if(J.direction==="down")if(this.selectedIndex<Z.length-1)this.hasUserInteracted=!0,this.selectedIndex++;else return!1;else if(this.selectedIndex>0)this.hasUserInteracted=!0,this.selectedIndex--;else return!1;return this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.syncSelection(),this.selectedIndex!==Q};handleItemClick=(J,Z)=>{let Q=this.getFilteredItems();if(J>=0&&J<Q.length){let Y=Q[J],X=Y?this.widget.props.isItemDisabled?.(Y)??!1:!1;if(Z===1)this.hasUserInteracted=!0,this.selectedIndex=J,this.setState(),this.syncSelection();else if(Z===2&&!X){if(Y)this.hasUserInteracted=!0,this.widget.props.onAccept(Y,{hasUserInteracted:this.hasUserInteracted})}}};build(J){let Z=f0.of(J),{colors:Q}=Z,Y=this.getFilteredItems(),X=c1.all(new h1(Q.foreground,1,"solid")),K=this.widget.props.hidePromptWhenLoading&&this.widget.props.isLoading,V=this.widget.props.enabled??!0,z=new CZ({controller:this.textController,focusNode:this.focusNode,autofocus:!0,enabled:V,style:{backgroundColor:Q.background,textColor:Q.foreground,cursorColor:Q.cursor,placeholderColor:Q.mutedForeground,border:null},maxLines:1}),G=new h$({shortcuts:new Map([[new D4("ArrowDown"),new Ov],[new D4("ArrowUp"),new Lv],[new D4("Tab"),new Ov],[new D4("Tab",{shift:!0}),new Lv],[new D4("n",{ctrl:!0}),new Ov],[new D4("p",{ctrl:!0}),new Lv],[new D4("Enter"),new zG0],[new D4("Escape"),new GG0]]),focusNode:this.focusNode,child:z}),F=new L2({actions:new Map([[Ov,new U6(this.invoke)],[Lv,new U6(this.invoke)],[zG0,new U6(this.invoke)],[GG0,new U6(this.invoke)]]),child:G}),q=new q1({children:[new i0({decoration:{color:Q.background},child:new $0({text:new C(">",new g({color:Q.foreground}))})}),new k1({child:F})]});this.itemContexts=[];let W;if(this.widget.props.isLoading){let N=this.widget.props.loadingText??"Loading...";W=new I0({height:10,child:new $4({child:new $0({text:new C(N,new g({color:Q.foreground}))})})})}else if(Y.length===0&&this.widget.props.emptyStateText)W=new k1({child:new $4({child:new $0({text:new C(this.widget.props.emptyStateText,new g({color:Q.foreground,dim:!0}))})})});else{let N=Y.map((w,O)=>{let L=O===this.selectedIndex,E=this.widget.props.isItemDisabled?.(w)??!1,M;if(this.widget.props.renderItem)M=this.widget.props.renderItem(w,L,E,J);else{let A=L?Z.app.selectionBackground:void 0,j=L?Z.app.selectionForeground:Q.foreground;M=new i0({decoration:A?{color:A}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C(this.widget.props.getLabel(w),new g({color:j,dim:E}))})})}return new Wg4(new e1({onClick:(A)=>this.handleItemClick(O,A.clickCount),child:M}),(A)=>{this.itemContexts[O]=A})});W=new x0({children:N,crossAxisAlignment:"start"})}let U=new e1({onScroll:this.handleScroll,opaque:!1,child:new T6({controller:this.scrollController,autofocus:!1,child:W})}),D=[];if(this.widget.props.title){let N=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C(this.widget.props.title,new g({color:Z.app.command,bold:!0}))})});D.push(N)}if(!K)D.push(q,new I0({height:1}));if(this.textController.text!==""){let N=Y.length>0?Y[this.selectedIndex]:void 0,w=N&&this.widget.props.buildDisabledReasonWidget?.(N,J);D.push(new k1({child:new x0({mainAxisAlignment:"spaceBetween",children:[new k1({child:U}),new i0({padding:C0.only({top:1}),child:new $4({child:w??new I0({height:1})})})]})}))}else D.push(new k1({child:U}));if(this.widget.props.footer)D.push(this.widget.props.footer);return new i0({decoration:{border:X,color:Q.background},padding:C0.symmetric(1,0),child:new x0({children:D})})}}function Hg4(J){let Q=new Date().getTime()-J.getTime(),Y=Math.floor(Q/60000),X=Math.floor(Q/3600000),K=Math.floor(Q/86400000);if(Y<1)return"just now";if(Y<60)return`${Y}m ago`;if(X<24)return`${X}h ago`;if(K<7)return`${K}d ago`;return J.toLocaleDateString()}class v01 extends t1{props;debugLabel="NewsFeedPicker";constructor(J){super();this.props=J}build(J){let Z=[...this.props.entries].sort((X,K)=>K.pubDate.getTime()-X.pubDate.getTime()),Q=Math.max(0,...Z.map((X)=>Hg4(X.pubDate).length));return new a2({items:Z,getLabel:(X)=>X.title,onAccept:(X)=>this.props.onSelect?.(X),onDismiss:this.props.onDismiss,title:this.props.title,emptyStateText:"No news entries available",maxRenderItems:100,renderItem:(X,K,V,z)=>{let G=f0.of(z),{colors:F}=G,q=G.app,W=K?q.selectionBackground:void 0,U=K?q.selectionForeground:F.foreground,D=F.mutedForeground,H=(B,N)=>new I0({width:N,child:q1.end([new $0({text:new C(B,new g({color:D}))})])});return new i0({decoration:W?{color:W}:void 0,padding:C0.symmetric(2,0),child:new q1({children:[new k1({child:new $0({text:new C(X.title,new g({color:U})),overflow:"ellipsis",maxLines:1})}),new I0({width:2}),H(Hg4(X.pubDate),Q)]})})}})}}class x01 extends l0{createState(){return new Bg4}}class Bg4 extends d0{isGreen=!0;timer;initState(){this.timer=setInterval(()=>{this.isGreen=!this.isGreen,this.setState()},700)}dispose(){if(this.timer)clearInterval(this.timer);super.dispose()}build(J){let Q=f0.of(J).colors;return new $0({text:new C("●",new g({color:this.isGreen?Q.success:Q.mutedForeground,bold:!0})),maxLines:1})}}function rR3(J){return EY(J,{acceptedHostnames:["ampcode.com","localhost"],allowThreadsPathExtraction:!0})}function sR3(J){let Z=new Map,Q=new Map,Y=new Map,X=[];for(let V of J)Z.set(V.id,V);for(let V of J){let z=V.relationships.find((G)=>G.role==="child"&&Z.has(G.threadID)&&(G.type==="fork"||G.type==="handoff"));if(z){Y.set(V.id,z.type);let G=z.threadID,F=Q.get(G)||[];F.push(V),Q.set(G,F)}else X.push(V)}return gV0.flatten(X,(V)=>Q.get(V.id)).map((V)=>({...V.item,depth:V.depth,isLast:V.isLast,ancestorsAreLast:V.ancestorsAreLast,relationshipType:Y.get(V.item.id)}))}function f01(J,Z,Q){return new $0({text:new C(`${J}${Z}`,new g({color:Q})),maxLines:1})}function tR3(J,Z,Q,Y){return[f01("+",J,Y.success),b3.horizontal(1),f01("~",Z,Y.warning),b3.horizontal(1),f01("-",Q,Y.destructive)]}function eR3(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}class FG0 extends l0{props;debugLabel="ThreadContinuationPicker";constructor(J){super();this.props=J}createState(){return new Ng4}}class Ng4 extends d0{spinner=new M3;spinnerInterval=null;isSwitchingThread=!1;get isBusy(){return this.isSwitchingThread||this.widget.props.isLoading===!0}updateSpinnerAnimation(){if(this.isBusy){if(!this.spinnerInterval)this.spinnerInterval=setInterval(()=>{this.spinner.step(),this.setState(()=>{})},100);return}if(this.spinnerInterval)clearInterval(this.spinnerInterval),this.spinnerInterval=null}setSwitchingThread(J){if(this.isSwitchingThread===J)return;this.setState(()=>{this.isSwitchingThread=J}),this.updateSpinnerAnimation()}initState(){super.initState(),this.updateSpinnerAnimation()}didUpdateWidget(J){this.updateSpinnerAnimation()}dispose(){if(this.spinnerInterval)clearInterval(this.spinnerInterval),this.spinnerInterval=null;super.dispose()}build(J){let{props:Z}=this.widget,Q=this.isBusy,Y=this.isSwitchingThread?"Switching thread...":"Loading threads...",X=`${this.spinner.toBraille()} ${Y}`,K=Z.filterByWorkspace&&Z.currentWorkspaceURI?Z.threads.filter((O)=>O.workspaceURI===Z.currentWorkspaceURI):Z.threads;if(Z.excludeCurrentThread&&Z.currentThreadID)K=K.filter((O)=>O.id!==Z.currentThreadID);let V=Z.recentThreadIDs||[],z=new Set(V),G=Z.currentThreadID,F=[...K].sort((O,L)=>{if(G){if(O.id===G)return-1;if(L.id===G)return 1}let E=V.indexOf(O.id),M=V.indexOf(L.id);if(E!==-1&&M!==-1)return E-M;if(E!==-1)return-1;if(M!==-1)return 1;return 0}),q=sR3(F),W=Math.max(0,...q.map((O)=>O.description.timeAgo.length)),U=f0.of(J),D=new a0({padding:C0.symmetric(0,1),child:new $4({child:new $0({text:new C("",new g({color:U.colors.foreground,dim:!0}),[new C("Ctrl+T",new g({color:U.colors.primary,dim:!0})),new C(Z.filterByWorkspace?" for all workspaces":" to filter by workspace",new g({color:U.colors.foreground,dim:!0}))])})})}),H="",B=null,N=(O)=>{if(O!==H)H=O,B=rR3(O);return B};return new a2({items:q,getLabel:(O)=>`${O.title} ${O.id}`,filterItem:(O,L)=>{let E=N(L);if(E)return O.id.toLowerCase()===E.toLowerCase();return!0},normalizeQuery:(O)=>N(O)?"":O,onAccept:async(O,L)=>{if(!Z.onSelect||this.isSwitchingThread)return;let E=Z.onSelect(O.id,L);if(!eR3(E))return;this.setSwitchingThread(!0);try{await E}finally{if(this.mounted)this.setSwitchingThread(!1)}},onDismiss:Z.onDismiss,onSelectionChange:(O)=>{if(Z.previewController){if(O)Z.previewController.select(O.id)}},title:Z.title,enabled:!Q,isLoading:Q,hidePromptWhenLoading:!0,loadingText:X,emptyStateText:"No threads match your filter",maxRenderItems:200,footer:Q?void 0:D,renderItem:(O,L,E,M)=>{let A=f0.of(M),{app:j,colors:R}=A,_=L?j.selectionBackground:void 0,k=L?j.selectionForeground:R.foreground,u=R.mutedForeground,m=(s,F0)=>new I0({width:F0,child:q1.end([new $0({text:new C(s,new g({color:u}))})])}),x=Z.threadViewStates[O.id],T=[],f=O.relationshipType==="handoff",p=new Ha({connectorColor:R.mutedForeground});if(O.depth>0){let s=[],F0=O.ancestorsAreLast.slice(1);for(let O0 of F0)s.push(new C(p.getAncestorPrefix(O0),new g({color:p.connectorColor,dim:p.connectorDim})));let a=O.isLast?p.elbow:p.tee,U0=p.getConnectorText(a);s.push(new C(U0,new g({color:p.connectorColor,dim:p.connectorDim}))),T.push(new $0({text:new C("",void 0,s)}))}let d=[],h=G===O.id?new C("(current) ",new g({color:R.success})):z.has(O.id)?new C("(visited) ",new g({color:R.foreground,dim:!0})):null;if(h)d.push(new $0({text:h}));if(ON(x))d.push(new x01),d.push(new I0({width:1}));let n=O.title;if(O.relationshipType==="fork"){let s=n.match(/^Forked\((\d+)\): /);if(s)n=n.slice(s[0].length);else while(n.startsWith("Forked: "))n=n.slice(8);d.push(new $0({text:new C("[fork] ",new g({color:R.primary}))}))}else if(f)d.push(new $0({text:new C("[handoff] ",new g({color:R.accent}))}));if(d.push(new k1({child:new $0({text:new C(n,new g({color:k})),overflow:"ellipsis",maxLines:1})})),d.push(new I0({width:2})),O.diffStats&&(O.diffStats.added>0||O.diffStats.changed>0||O.diffStats.deleted>0)){let s=L?{success:u,warning:u,destructive:u}:R;d.push(...tR3(O.diffStats.added,O.diffStats.changed,O.diffStats.deleted,s)),d.push(new I0({width:2}))}return d.push(m(O.description.timeAgo,W)),new i0({decoration:_?{color:_}:void 0,padding:C0.symmetric(2,0),child:new q1({children:[...T,...d]})})}})}}function wg4(J){return 1-(1-J)**3}function Og4(J,Z,Q){return J+(Z-J)*Q}function da(J,Z){if(!J)return{x:0,y:0};let Q=Z-J.startTime,Y=Math.min(Q/J.durationX,1),X=Math.min(Q/J.durationY,1),K=wg4(Y),V=wg4(X);return{x:Og4(J.startOffset.x,J.targetOffset.x,K),y:Og4(J.startOffset.y,J.targetOffset.y,V)}}var $I3={nodeWidth:3,horizontalSpacing:3};class Ev{options;constructor(J={}){this.options={...$I3,...J}}layout(J){let{childrenMap:Z,resolvedParent:Q}=this.buildTree(J),Y=[],X=Z.get(void 0)??[];if(this.options.comparator)X.sort(this.options.comparator);let K=0,V=(z,G)=>{let F=Z.get(z.id)??[];if(this.options.comparator)F.sort(this.options.comparator);let q={...z,parentID:Q.get(z.id)};if(F.length===0){Y.push({node:q,position:{x:K,y:G}});let B=K;return K+=this.options.nodeWidth+this.options.horizontalSpacing,B}let W=[];for(let B of F)W.push(V(B,G+1));let U=Math.min(...W),D=Math.max(...W),H=Math.floor((U+D)/2);return Y.push({node:q,position:{x:H,y:G}}),H};for(let z of X)V(z,0);return Y}buildTree(J){let Z=new Set(J.map((K)=>K.id)),Q=[...J].sort((K,V)=>K.id.localeCompare(V.id)),Y=new Map;for(let K of Q){if(!K.parentID||!Z.has(K.parentID)){Y.set(K.id,void 0);continue}let V=!1,z=K.parentID;while(z){if(z===K.id){V=!0;break}z=Y.get(z)}Y.set(K.id,V?void 0:K.parentID)}let X=new Map;for(let K of J){let V=Y.get(K.id);if(!X.has(V))X.set(V,[]);X.get(V).push(K)}return{childrenMap:X,resolvedParent:Y}}}var JI3={nodeWidth:3,nodeHeight:2};class Mv{options;constructor(J={}){this.options={...JI3,...J}}calculate(J){let Z=[],Q=new Map;for(let Y of J)Q.set(Y.node.id,Y);for(let Y of J){if(!Y.node.parentID)continue;let X=Q.get(Y.node.parentID);if(!X)continue;let K=this.calculateConnectorLine(X.position,Y.position);Z.push({points:K,fromNodeID:X.node.id,toNodeID:Y.node.id})}return Z}calculateConnectorLine(J,Z){let Q=Math.floor(this.options.nodeWidth/2),Y=[],X=J.x+Q,K=Z.x+Q,V=J.y*(this.options.nodeHeight+3)+this.options.nodeHeight;Y.push({x:X,y:V});let z=V+1;if(Y.push({x:X,y:z}),X!==K)Y.push({x:K,y:z});let G=Z.y*(this.options.nodeHeight+3)-1;return Y.push({x:K,y:G}),Y}}var ZI3={nodeWidth:3,nodeHeight:2},QI3={x:0,y:0};class WG0{options;constructor(J={}){this.options={...ZI3,...J}}getNodeWidth(){return this.options.nodeWidth}render(J,Z,Q,Y=QI3,X,K,V,z){let G=z?f0.of(z):null,F=G?.colors,q=G?.app,W=F?.mutedForeground??F?.foreground;if(J.length===0)return new $0({text:new C("No nodes",new g({color:W}))});let U=Math.max(...J.map((j)=>j.position.y)),H=Math.max(...J.map((j)=>j.position.x))+this.options.nodeWidth+3,B=this.options.nodeHeight+3,N=[];for(let j=U;j>=0;j--){let R=J.filter((u)=>u.position.y===j);R.sort((u,m)=>u.position.x-m.position.x);let _=[],k=0;for(let u of R){if(u.position.x>k)_.push(new I0({width:u.position.x-k}));let m=u.node.id===Q,x=V?.(u.node.data)??!1,T=K?.activeFlashOn??!1,f=u.node.id===K?.copyFlashNodeId;_.push(this.renderNode(m,x,T,f,q,F)),k=u.position.x+this.options.nodeWidth}if(N.push(new q1({crossAxisAlignment:"start",children:_})),j>0){let u=J.filter((T)=>T.position.y===j-1),m=R,x=this.renderConnectors(u,m,Z,H,F,q);N.push(...x)}}let w=new x0({crossAxisAlignment:"start",children:N}),O=Math.round(Y.x),L=Math.round(Y.y*B),E=(U+1)*B,M=[new I0({width:H,height:E}),new t6({left:O,top:L,child:w})],A=Q?J.find((j)=>j.node.id===Q):void 0;if(A&&X){let j=X(A.node.data),R=U-A.position.y,_=O+A.position.x+this.options.nodeWidth+1,k=L+R*B+1,u=30;if(K?.maxTitleWidthPercent&&K.viewportWidth)u=Math.floor(K.viewportWidth*K.maxTitleWidthPercent/100);M.push(new t6({left:_,top:k,child:this.renderInfoBox(j,u,F,q)}))}return new i0({padding:C0.horizontal(2),child:new xz(new G5({fit:"expand",children:M}))})}renderNode(J,Z,Q,Y,X,K){let V="┌─┐",z="└─┘",G=J?X?.threadGraphNodeSelected??K?.primary??K?.foreground:X?.threadGraphNode??K?.primary??K?.foreground,F=!1;if(Y)G=X?.threadGraphNodeSelected??K?.primary??G,V="┏━┓",z="┗━┛",F=!0;else if(Z&&Q)G=X?.toolSuccess??K?.primary??G,V="┏━┓",z="┗━┛";return new x0({crossAxisAlignment:"start",children:[new $0({text:new C(V,new g({color:G,bold:F}))}),new $0({text:new C(z,new g({color:G,bold:F}))})]})}wrapText(J,Z){let Q=J.split(" "),Y=[],X="";for(let K of Q){if(K.length>Z)K=K.slice(0,Z-1)+"…";if(X.length===0)X=K;else if(X.length+1+K.length<=Z)X+=" "+K;else Y.push(X),X=K}if(X.length>0)Y.push(X);return Y}renderInfoBox(J,Z=30,Q,Y){let X=this.wrapText(J,Z),K=Math.min(Z,Math.max(1,...X.map((U)=>U.length))),V=K+2,z="┌"+"─".repeat(V)+"┐",G="└"+"─".repeat(V)+"┘",F=Q?.border??Y?.threadGraphConnector??Q?.foreground,q=Q?.foreground,W=[new $0({text:new C(z,new g({color:F}))})];for(let U of X){let D=" ".repeat(K-U.length);W.push(new $0({text:new C("│ ",new g({color:F}),[new C(U+D,new g({color:q??F})),new C(" │",new g({color:F}))])}))}return W.push(new $0({text:new C(G,new g({color:F}))})),new x0({crossAxisAlignment:"start",children:W})}renderConnectors(J,Z,Q,Y,X,K){let V=[],z=Math.floor(this.options.nodeWidth/2),G=K?.threadGraphConnector??X?.primary??X?.foreground,F=Array(Y).fill(" ");for(let U of Z){let D=U.position.x+z;if(D>=0&&D<Y)F[D]="▲"}V.push(new $0({text:new C(F.join(""),new g({color:G}))}));let q=Array(Y).fill(" ");for(let U of J){let D=Z.filter((O)=>O.node.parentID===U.node.id);if(D.length===0)continue;let H=U.position.x+z,B=D.map((O)=>O.position.x+z),N=Math.min(...B),w=Math.max(...B);for(let O=N;O<=w;O++)if(O>=0&&O<Y){if(O===H)if(D.length===1&&B[0]===H)q[O]="│";else if(O===N)q[O]="└";else if(O===w)q[O]="┘";else q[O]="┬";else if(B.includes(O))if(O===N)q[O]="└";else if(O===w)q[O]="┘";else q[O]="┴";else if(q[O]===" ")q[O]="─"}}V.push(new $0({text:new C(q.join(""),new g({color:G}))}));let W=Array(Y).fill(" ");for(let U of J){if(Z.filter((B)=>B.node.parentID===U.node.id).length===0)continue;let H=U.position.x+z;if(H>=0&&H<Y)W[H]="│"}return V.push(new $0({text:new C(W.join(""),new g({color:G}))})),V}}var YI3={nodeWidth:1,nodeHeight:1,nodeIcon:"□",selectedIcon:"□"},XI3={x:0,y:0};class u01{options;constructor(J={}){this.options={...YI3,...J}}getNodeWidth(){return this.options.nodeWidth}render(J,Z,Q,Y=XI3,X,K,V,z){let G=z?f0.of(z):null,F=G?.colors,q=G?.app,W=F?.mutedForeground??F?.foreground;if(J.length===0)return new $0({text:new C("No nodes",new g({color:W}))});let U=Math.max(...J.map((j)=>j.position.y)),H=Math.max(...J.map((j)=>j.position.x))+this.options.nodeWidth+3,B=this.options.nodeHeight+1,N=[];for(let j=U;j>=0;j--){let R=J.filter((u)=>u.position.y===j);R.sort((u,m)=>u.position.x-m.position.x);let _=[],k=0;for(let u of R){if(u.position.x>k)_.push(new I0({width:u.position.x-k}));let m=u.node.id===Q,x=V?.(u.node.data)??!1,T=K?.activeFlashOn??!1;_.push(this.renderNode(m,x,T,q,F)),k=u.position.x+this.options.nodeWidth}if(N.push(new q1({crossAxisAlignment:"start",children:_})),j>0){let u=J.filter((T)=>T.position.y===j-1),m=R,x=this.renderConnectors(u,m,Z,H,F,q);N.push(...x)}}let w=new x0({crossAxisAlignment:"start",children:N}),O=Math.round(Y.x),L=Math.round(Y.y*B),E=(U+1)*B,M=[new I0({width:H,height:E}),new t6({left:O,top:L,child:w})],A=Q?J.find((j)=>j.node.id===Q):void 0;if(A&&X){let j=X(A.node.data),R=U-A.position.y,_=O+A.position.x+this.options.nodeWidth+1,k=L+R*B,u=30;if(K?.maxTitleWidthPercent&&K.viewportWidth)u=Math.floor(K.viewportWidth*K.maxTitleWidthPercent/100);M.push(new t6({left:_,top:k,child:this.renderInfoBox(j,u,F)}))}return new i0({padding:C0.horizontal(2),child:new xz(new G5({fit:"expand",children:M}))})}renderNode(J,Z,Q,Y,X){let K=J?this.options.selectedIcon:this.options.nodeIcon,V=J?Y?.threadGraphNodeSelected??X?.primary??X?.foreground:Y?.threadGraphNode??X?.primary??X?.foreground;if(Z&&Q)V=Y?.toolSuccess??X?.primary??V,K="■";return new $0({text:new C(K,new g({color:V}))})}wrapText(J,Z){let Q=J.split(" "),Y=[],X="";for(let K of Q){if(K.length>Z)K=K.slice(0,Z-1)+"…";if(X.length===0)X=K;else if(X.length+1+K.length<=Z)X+=" "+K;else Y.push(X),X=K}if(X.length>0)Y.push(X);return Y}renderInfoBox(J,Z=30,Q){let Y=this.wrapText(J,Z),X=Q?.foreground,K=[];for(let V of Y)K.push(new $0({text:new C(V,new g({color:X??Q?.primary??Q?.foreground}))}));return new x0({crossAxisAlignment:"start",children:K})}renderConnectors(J,Z,Q,Y,X,K){let V=[],z=Math.floor(this.options.nodeWidth/2),G=K?.threadGraphConnector??X?.primary??X?.foreground,F=Array(Y).fill(" ");for(let q of J){let W=Z.filter((N)=>N.node.parentID===q.node.id);if(W.length===0)continue;let U=q.position.x+z,D=W.map((N)=>N.position.x+z),H=Math.min(...D),B=Math.max(...D);for(let N=H;N<=B;N++)if(N>=0&&N<Y){let w=N===U,O=D.includes(N);if(w&&O)if(W.length===1)F[N]="│";else if(N===H)F[N]="└";else if(N===B)F[N]="┘";else F[N]="┼";else if(w)if(N===H)F[N]="└";else if(N===B)F[N]="┘";else F[N]="┬";else if(O)if(N===H)F[N]="└";else if(N===B)F[N]="┘";else F[N]="┴";else if(F[N]===" ")F[N]="─"}}return V.push(new $0({text:new C(F.join(""),new g({color:G}))})),V}}class ca extends o3{onWidth;onHeight;constructor(J){super(J.child);this.onWidth=J.onWidth,this.onHeight=J.onHeight}createRenderObject(){return new Lg4(this.onWidth,this.onHeight)}updateRenderObject(J){J.onWidth=this.onWidth,J.onHeight=this.onHeight}}class Lg4 extends v4{onWidth;onHeight;constructor(J,Z){super();this.onWidth=J,this.onHeight=Z}performLayout(){let J=this._lastConstraints,Z=Number.isFinite(J.maxWidth)?J.maxWidth:80,Q=Number.isFinite(J.maxHeight)?J.maxHeight:24;this.onWidth(Z),this.onHeight?.(Q);let Y=this.children[0];if(Y)Y.layout(J),this.setSize(Y.size.width,Y.size.height);else this.setSize(J.minWidth,J.minHeight)}paint(J,Z,Q){for(let Y of this.children)Y.paint(J,Z,Q)}}class RR extends l0{props;constructor(J){super({key:J.key});this.props=J}createState(){return new Ag4}}var Eg4=400,Mg4=300,KI3=16;class Ag4 extends d0{selectedNodeId=null;positionedNodes=[];dateComparator=(J,Z)=>{let Q=J.data.updatedAt??"",Y=Z.data.updatedAt??"";return Q.localeCompare(Y)};layoutEngine=new Ev({nodeWidth:1,horizontalSpacing:1,comparator:this.dateComparator});lineCalculator=new Mv;renderer=new u01;animation=null;currentOffset={x:0,y:0};animationTimer=null;viewportWidth=80;viewportHeight=24;activeFlashOn=!0;activeFlashTimer=null;initState(){let{initialSelectedThreadID:J}=this.widget.props;if(J){let Q=this.widget.props.threads.find((Y)=>Y.id===J);if(Q)this.selectedNodeId=Q.id}this.startActiveFlashTimer()}startActiveFlashTimer(){if(!this.widget.props.threads.some((Z)=>Z.isActive))return;this.activeFlashTimer=setInterval(()=>{this.activeFlashOn=!this.activeFlashOn,this.setState()},700)}stopActiveFlashTimer(){if(this.activeFlashTimer)clearInterval(this.activeFlashTimer),this.activeFlashTimer=null}didUpdateWidget(J){let Z=new Set(J.props.threads.map((G)=>G.id)),Q=new Set(this.widget.props.threads.map((G)=>G.id));if(Z.size!==Q.size||[...Z].some((G)=>!Q.has(G)))this.stopAnimation(),this.currentOffset={x:0,y:0};let X=J.props.initialSelectedThreadID,K=this.widget.props.initialSelectedThreadID;if(X!==K&&K){let F=this.widget.props.threads.find((q)=>q.id===K);if(F)this.selectedNodeId=F.id,this.stopAnimation(),this.currentOffset={x:0,y:0}}let V=J.props.threads.some((G)=>G.isActive),z=this.widget.props.threads.some((G)=>G.isActive);if(V!==z){if(this.stopActiveFlashTimer(),z)this.startActiveFlashTimer()}}dispose(){this.stopAnimation(),this.stopActiveFlashTimer()}startAnimation(J){this.stopAnimation(),this.animation={startOffset:{...this.currentOffset},targetOffset:J,startTime:Date.now(),durationX:Eg4,durationY:Mg4};let Z=Math.max(Eg4,Mg4);this.animationTimer=setInterval(()=>{let Q=Date.now();if(this.currentOffset=da(this.animation,Q),this.animation&&Q-this.animation.startTime>=Z)this.currentOffset={...this.animation.targetOffset},this.stopAnimation();this.setState()},KI3)}stopAnimation(){if(this.animationTimer)clearInterval(this.animationTimer),this.animationTimer=null;this.animation=null}calculateCenterOffset(J,Z,Q){let Y=Math.floor(this.renderer.getNodeWidth()/2),K=Math.floor(this.viewportWidth/2)-J-Y,V=Q-Z,z=2,G=Math.floor(this.viewportHeight/2),q=Math.floor(G/2)-V;return{x:K,y:q}}animateToNode(J){let Z=this.positionedNodes.find((Q)=>Q.node.id===J);if(Z){let Q=Math.max(...this.positionedNodes.map((X)=>X.position.y)),Y=this.calculateCenterOffset(Z.position.x,Z.position.y,Q);this.startAnimation(Y)}}toGraphNodes(){return this.widget.props.threads.map((J)=>({id:J.id,parentID:J.parentID,data:{title:J.title,updatedAt:J.updatedAt,isActive:J.isActive}}))}toThreadNode(J){return{id:J.node.id,parentID:J.node.parentID,title:J.node.data.title,updatedAt:J.node.data.updatedAt}}handleKeyEvent=(J)=>{if(!this.selectedNodeId)return"ignored";let Z=this.positionedNodes,Q=Z.find((X)=>X.node.id===this.selectedNodeId);if(!Q)return"ignored";let Y;switch(J.key){case"ArrowUp":{let X=Z.filter((K)=>K.node.parentID===Q.node.id);if(X.length>0){X.sort((V,z)=>V.position.x-z.position.x);let K=Math.floor(X.length/2);Y=X[K]}break}case"ArrowDown":{Y=Z.find((X)=>X.node.id===Q.node.parentID);break}case"ArrowLeft":{let X=Z.filter((K)=>K.position.y===Q.position.y&&K.position.x<Q.position.x);if(X.length>0)X.sort((K,V)=>V.position.x-K.position.x),Y=X[0];break}case"ArrowRight":{let X=Z.filter((K)=>K.position.y===Q.position.y&&K.position.x>Q.position.x);if(X.length>0)X.sort((K,V)=>K.position.x-V.position.x),Y=X[0];break}case"Enter":{if(this.widget.props.onSelect)this.widget.props.onSelect(this.toThreadNode(Q));return"handled"}default:{if(this.widget.props.onKey)return this.widget.props.onKey(J);return"ignored"}}if(Y)return this.selectedNodeId=Y.node.id,this.widget.props.onSelectionChange?.(this.toThreadNode(Y)),this.animateToNode(Y.node.id),"handled";if(this.widget.props.onKey)return this.widget.props.onKey(J);return"ignored"};build(J){let Z=this.toGraphNodes();this.positionedNodes=this.layoutEngine.layout(Z);let Q=this.lineCalculator.calculate(this.positionedNodes);if(!this.animation&&this.currentOffset.x===0&&this.currentOffset.y===0){let q=(this.selectedNodeId?this.positionedNodes.find((W)=>W.node.id===this.selectedNodeId):null)??this.positionedNodes.find((W)=>!W.node.parentID);if(q){let W=Math.max(...this.positionedNodes.map((U)=>U.position.y));this.currentOffset=this.calculateCenterOffset(q.position.x,q.position.y,W)}}let X=this.widget.props.showTitle??!0,K=this.widget.props.offsetY??0,V={x:this.currentOffset.x,y:this.currentOffset.y+K},z=this.renderer.render(this.positionedNodes,Q,this.selectedNodeId??void 0,V,X?(F)=>F.title:void 0,{maxTitleWidthPercent:this.widget.props.maxTitleWidthPercent,viewportWidth:this.viewportWidth,activeFlashOn:this.activeFlashOn},(F)=>F.isActive??!1,J),G=new ca({onWidth:(F)=>{if(this.viewportWidth!==F)this.viewportWidth=F,this.stopAnimation(),this.currentOffset={x:0,y:0},this.setState()},onHeight:(F)=>{if(this.viewportHeight!==F)this.viewportHeight=F,this.stopAnimation(),this.currentOffset={x:0,y:0},this.setState()},child:z});return new s4({autofocus:this.widget.props.autofocus??!0,onKey:this.handleKeyEvent,debugLabel:"MiniThreadGraph",child:G})}getSelectedNode(){let J=this.positionedNodes.find((Z)=>Z.node.id===this.selectedNodeId);return J?this.toThreadNode(J):null}}class Rg4 extends l0{child;onContext;constructor(J,Z){super();this.child=J;this.onContext=Z}createState(){return new Ig4}}class Ig4 extends d0{build(J){return this.widget.onContext(J),this.widget.child}}var jg4=30,VI3=30;class Av{}class jv{}class UG0{}class DG0{}class b01 extends l0{props;constructor(J){super();this.props=J}createState(){return new Pg4}}class Pg4 extends d0{highlightedIndex=0;controller=new J$;focusNode;scrollController=new A5;filteredClusters=[];itemContexts=[];initState(){this.focusNode=new W6({debugLabel:"ClusterPicker"}),this.scrollController.disableFollowMode(),this.recomputeFiltered(),this.controller.addListener(()=>{this.highlightedIndex=0,this.recomputeFiltered(),this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()})})}didUpdateWidget(J){if(J.props.clusters!==this.widget.props.clusters){if(this.recomputeFiltered(),this.highlightedIndex>=this.filteredClusters.length)this.highlightedIndex=Math.max(0,this.filteredClusters.length-1)}}ensureSelectedItemVisible(){let J=this.itemContexts[this.highlightedIndex];if(!J)return;let Z=J.findRenderObject();if(!Z)return;let Q=0,Y=Z.size.height;Uv(J,{top:Q,bottom:Y},{padding:1})}dispose(){this.controller.dispose(),this.focusNode.dispose(),this.scrollController.dispose()}recomputeFiltered(){let J=this.controller.text.toLowerCase(),{clusters:Z}=this.widget.props;if(!J)this.filteredClusters=[...Z];else this.filteredClusters=Z.filter((Q)=>Q.label.toLowerCase().includes(J))}invoke=(J)=>{if(J instanceof Av){if(this.highlightedIndex<this.filteredClusters.length-1)this.highlightedIndex++,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()});return"handled"}if(J instanceof jv){if(this.highlightedIndex>0)this.highlightedIndex--,this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()});return"handled"}if(J instanceof UG0){let Z=this.filteredClusters[this.highlightedIndex];if(Z)this.widget.props.onAccept(Z);return"handled"}if(J instanceof DG0)return this.widget.props.onDismiss(),"handled";return"ignored"};handleItemClick=(J,Z)=>{if(J>=0&&J<this.filteredClusters.length){if(Z===1)this.highlightedIndex=J,this.setState();else if(Z===2){let Q=this.filteredClusters[J];if(Q)this.widget.props.onAccept(Q)}}};handleScroll=(J)=>{if(this.filteredClusters.length===0)return!1;let Z=this.highlightedIndex;if(J.direction==="down")if(this.highlightedIndex<this.filteredClusters.length-1)this.highlightedIndex++;else return!1;else if(this.highlightedIndex>0)this.highlightedIndex--;else return!1;return this.setState(),C6.instance.addPostFrameCallback(()=>{this.ensureSelectedItemVisible()}),this.highlightedIndex!==Z};build(J){let{currentThreadID:Z}=this.widget.props,Q=f0.of(J),{colors:Y,app:X}=Q,z=K4.of(J).size.width>=VI3+jg4,G=c1.all(new h1(Y.foreground,1,"solid")),F=this.filteredClusters[this.highlightedIndex]??null,q=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C("Select a cluster",new g({color:X.command,bold:!0}))})}),W=new CZ({controller:this.controller,focusNode:this.focusNode,autofocus:!0,enabled:!0,style:{textColor:Y.foreground,border:null},maxLines:1}),U=new h$({shortcuts:new Map([[new D4("ArrowDown"),new Av],[new D4("ArrowUp"),new jv],[new D4("Tab"),new Av],[new D4("Tab",{shift:!0}),new jv],[new D4("n",{ctrl:!0}),new Av],[new D4("p",{ctrl:!0}),new jv],[new D4("Enter"),new UG0],[new D4("Escape"),new DG0]]),focusNode:this.focusNode,child:W}),D=new L2({actions:new Map([[Av,new U6(this.invoke)],[jv,new U6(this.invoke)],[UG0,new U6(this.invoke)],[DG0,new U6(this.invoke)]]),child:U}),H=new q1({children:[new i0({decoration:{color:Y.background},child:new $0({text:new C(">",new g({color:Y.foreground}))})}),new k1({child:D})]});this.itemContexts=[];let B=this.filteredClusters.map((M,A)=>{let j=A===this.highlightedIndex,R=Z?M.threads.some((m)=>m.id===Z):!1,_=j?X.selectionBackground:void 0,k=j?X.selectionForeground:Y.foreground,u=[new C(M.label,new g({color:k})),new C(` (${M.threads.length})`,new g({color:k,dim:!0}))];if(R)u.push(new C(" (current)",new g({color:j?X.selectionForeground:Y.success})));return new Rg4(new e1({onClick:(m)=>this.handleItemClick(A,m.clickCount),child:new i0({decoration:_?{color:_}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C("",void 0,u)})})}),(m)=>{this.itemContexts[A]=m})}),N=new x0({children:B,crossAxisAlignment:"start"}),w=new k1({child:new e1({onScroll:this.handleScroll,child:new T6({controller:this.scrollController,autofocus:!1,child:N})})}),O=F?F.threads.map((M)=>({id:M.id,title:M.title,parentID:M.parentID,updatedAt:M.updatedAt})):[],L=F?new i0({padding:C0.all(1),child:new RR({threads:O,autofocus:!1,offsetY:2})}):null,E;if(z){let M=L?new k1({child:L}):new I0({width:jg4});E=new q1({crossAxisAlignment:"stretch",mainAxisAlignment:"start",children:[w,M]})}else{let M=[new k1({child:new e1({onScroll:this.handleScroll,child:new T6({controller:this.scrollController,autofocus:!1,child:N})})})];if(L)M.push(new k1({child:L}));E=new x0({crossAxisAlignment:"stretch",children:M})}return new i0({decoration:{border:G,color:Y.background},padding:C0.symmetric(1,0),child:new x0({children:[q,H,new I0({height:1}),new k1({child:E})]})})}}class kJ{static _instance=null;_allExpanded=!1;_listeners=new Set;static get instance(){if(!kJ._instance)kJ._instance=new kJ;return kJ._instance}get allExpanded(){return this._allExpanded}setAllExpanded(J){if(this._allExpanded===J)return;this._allExpanded=J,this._notifyListeners()}toggleAll(){this.setAllExpanded(!this._allExpanded)}addListener(J){return this._listeners.add(J),()=>this.removeListener(J)}removeListener(J){this._listeners.delete(J)}_notifyListeners(){for(let J of this._listeners)J()}}g0();class Cg4 extends d0{labels=[];isLoading=!0;currentQuery="";initState(){this.loadLabels()}async loadLabels(){try{let J=await this.widget.props.internalAPIClient.getUserLabels({query:""},{config:this.widget.props.configService});if(!J.ok){I.error("Failed to load labels",J.error),this.isLoading=!1,this.labels=[],this.setState();return}this.labels=J.result,this.isLoading=!1,this.setState()}catch(J){I.error("Failed to load labels",J),this.isLoading=!1,this.labels=[],this.setState()}}getValidationError(J){let Z=J.trim().toLowerCase();if(Z.length===0)return null;if(Z.length>32)return"Label name cannot exceed 32 characters";if(!/^[a-z0-9][a-z0-9-]*$/.test(Z))return"Label must be alphanumeric with hyphens, starting with a letter or number";return null}isValidLabelName(J){return this.getValidationError(J)===null&&J.length>0}getAvailableLabels(){let J=this.widget.props.currentLabels||[];return this.labels.filter((Z)=>!J.includes(Z.name))}shouldShowCreateMarker(J){if(J.length===0||this.isLoading)return!1;let Z=J.trim().toLowerCase();if(!this.isValidLabelName(Z))return!1;let Q=this.widget.props.currentLabels||[],Y=this.labels.some((K)=>K.name===Z),X=Q.includes(Z);return!Y&&!X}build(J){let Z=f0.of(J),{app:Q,colors:Y}=Z,X=this.currentQuery.trim().toLowerCase(),K=X.length>0?this.getValidationError(X):null,V=this.getAvailableLabels(),G=[{id:"__create__",name:"__create_placeholder__",createdAt:"",__isCreateMarker:!0},...V];return new a2({title:"Add Label",items:G,getLabel:(F)=>{if("__isCreateMarker"in F)return this.currentQuery.trim().toLowerCase();return F.name},onAccept:(F)=>{if("__isCreateMarker"in F)this.widget.props.onSelect(this.currentQuery.trim().toLowerCase());else this.widget.props.onSelect(F.name)},onDismiss:this.widget.props.onDismiss,isLoading:this.isLoading,loadingText:"Loading labels...",emptyStateText:K||"Type to create a new label",renderItem:(F,q,W,U)=>{let D=q?Q.selectionBackground:void 0,H=q?Q.selectionForeground:Y.foreground;if("__isCreateMarker"in F&&F.__isCreateMarker){let N=this.currentQuery.trim().toLowerCase();return new i0({decoration:D?{color:D}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C("",void 0,[new C("Create new label: ",new g({color:H})),new C(N,new g({color:H,bold:!0}))])})})}return new i0({decoration:D?{color:D}:void 0,padding:C0.symmetric(2,0),child:new $0({text:new C(F.name,new g({color:H}))})})},filterItem:(F,q)=>{if(this.currentQuery!==q)this.currentQuery=q,setTimeout(()=>this.setState(),0);if("__isCreateMarker"in F&&F.__isCreateMarker)return this.shouldShowCreateMarker(q);let U=q.trim().toLowerCase();return U.length===0||F.name.includes(U)},sortItems:(F,q,W)=>{let U="__isCreateMarker"in F.item&&F.item.__isCreateMarker,D="__isCreateMarker"in q.item&&q.item.__isCreateMarker;if(U&&!D)return-1;if(!U&&D)return 1;return q.score-F.score}})}}class h01 extends l0{props;constructor(J){super();this.props=J}createState(){return new Cg4}}class dz extends l0{props;constructor(J){super();this.props=J}createState(){return new Tg4}}class Tg4 extends d0{_spinner=new M3;animationInterval=null;initState(){super.initState(),this.animationInterval=setInterval(()=>{this._spinner.step(),this.setState(()=>{})},100)}dispose(){if(this.animationInterval)clearInterval(this.animationInterval),this.animationInterval=null;super.dispose()}build(J){let Z=f0.of(J),{colors:Q,app:Y}=Z,X=c1.all(new h1(Q.foreground,1,"solid")),K=this._spinner.toBraille(),V=new $0({textAlign:"center",text:new C("",void 0,[new C(K,new g({color:Y.processing})),new C(" ",void 0),new C(this.widget.props.message,new g({color:Q.foreground}))])}),G=[new k1({child:new x0({mainAxisAlignment:"center",crossAxisAlignment:"center",children:[V]})})];if(this.widget.props.onAbort)G.push(new I0({height:2,child:new i0({padding:C0.symmetric(2,0),child:new $0({text:new C("",new g({dim:!0}),[new C("Press ",new g({color:Q.foreground})),new C("Esc",new g({color:Q.info})),new C(" to cancel",new g({color:Q.foreground}))])})})}));let F=new i0({decoration:new r4(Q.background,X),child:new I0({width:60,height:7,child:new x0({mainAxisAlignment:"start",children:G})})});if(this.widget.props.onAbort)return new s4({debugLabel:"LoadingDialog",autofocus:!0,onKey:(q)=>{if(q.key==="Escape")return this.widget.props.onAbort?.(),"handled";return"ignored"},child:F});return F}}var la={workspace:{label:"Workspace",pathHint:".amp/settings.json",description:"workspace config"},global:{label:"Global",pathHint:"~/.config/amp/settings.json",description:"global config"},flag:{label:"Flag",pathHint:"CLI flags",description:"flag config"},default:{label:"Default",pathHint:"built-in defaults",description:"default config"},external:{label:"External",pathHint:"extensions / external",description:"external source"},skill:{label:"Skills",pathHint:".agents/skills/",description:"skill source"},other:{label:"Other",pathHint:"",description:"other source"}},HG0=["workspace","global","flag","default","external","skill","other"];function zI3(J){return Array.from(new Set(J))}function _g4(J){return zI3([...J.skillNames??[],...J.skillName?[J.skillName]:[]])}function Rv(J){if(J.isExternal)return"external";switch(J.spec._target){case"workspace":return"workspace";case"global":return"global";case"flag":return"flag";case"default":return"default"}return _g4(J).length>0?"skill":"other"}function g01(J){return Rv(J)==="skill"}function Sg4(J){let Z=_g4(J);if(Z.length===0)return;let Q=Z.join(", "),Y=Rv(J);if(Y==="skill")return`skills: ${Q}`;return`${Z.length===1?"skill source":"skill sources"} overridden by ${la[Y].description}: ${Q}`}function kg4(J){return J.spec.meta?.skillNames?Array.from(J.spec.meta.skillNames):[]}var yg4=process.platform==="win32"?" ":"█",vg4=process.platform==="win32"?"░":"█";class O9 extends l0{controller;getScrollInfo;thickness;trackChar;thumbChar;showTrack;thumbColor;trackColor;constructor({key:J,controller:Z,getScrollInfo:Q,thickness:Y=1,trackChar:X=yg4,thumbChar:K=vg4,showTrack:V=!0,thumbColor:z,trackColor:G}){super(J?{key:J}:{});this.controller=Z,this.getScrollInfo=Q,this.thickness=Y,this.trackChar=X,this.thumbChar=K,this.showTrack=V,this.thumbColor=z,this.trackColor=G}createState(){return new xg4}}class xg4 extends d0{_dragStartY=null;_dragStartOffset=null;_isOverThumb=!1;_isPositionOverThumb(J){let{totalContentHeight:Z,viewportHeight:Q}=this.widget.getScrollInfo(),X=this.context.findRenderObject()?.size.height??0;if(X===0||Z<=Q)return!1;let K=this.widget.getScrollInfo(),V=Math.min(1,Q/Z),z=Math.max(1,X*V),G=Math.max(0,Math.min(1,K.scrollOffset/(Z-Q))),F=X-z,q=Math.max(0,F*G),W=q+z;return J>=q&&J<=W}_handleHover=(J)=>{let Z=this._isOverThumb;if(this._isOverThumb=this._isPositionOverThumb(J.localPosition.y),Z!==this._isOverThumb)this.setState()};_handleDrag=(J)=>{let{totalContentHeight:Z,viewportHeight:Q,scrollOffset:Y}=this.widget.getScrollInfo(),K=this.context.findRenderObject()?.size.height??0;if(K===0||Z<=Q)return;if(this._dragStartY===null)this._dragStartY=J.localPosition.y,this._dragStartOffset=Y;let V=J.localPosition.y-this._dragStartY,z=Math.min(1,Q/Z),G=Math.max(1,K*z),F=K-G;if(F<=0)return;let q=Z-Q,W=F/q,U=V/W,D=Math.max(0,Math.min(q,this._dragStartOffset+U));this.widget.controller.jumpTo(D)};_handleRelease=()=>{this._dragStartY=null,this._dragStartOffset=null};_handleClick=(J)=>{if(J.button!=="left")return;let Z=J.localPosition.y,{totalContentHeight:Q,viewportHeight:Y,scrollOffset:X}=this.widget.getScrollInfo(),V=this.context.findRenderObject()?.size.height??0;if(V===0||Q<=Y)return;let z=Math.min(1,Y/Q),G=Math.max(1,V*z),F=Q-Y,q=V-G,W=Math.max(0,Math.min(1,X/(Q-Y))),U=Math.max(0,q*W),D=U+G;if(Z>=U&&Z<=D)return;if(Z<U)this.widget.controller.animateTo(Math.max(0,X-Y));else this.widget.controller.animateTo(Math.min(F,X+Y))};build(J){return new e1({onClick:this._handleClick,onHover:this._handleHover,onDrag:this._handleDrag,onRelease:this._handleRelease,cursor:this._isOverThumb?b5.POINTER:b5.DEFAULT,child:new fg4({controller:this.widget.controller,getScrollInfo:this.widget.getScrollInfo,thickness:this.widget.thickness,trackChar:this.widget.trackChar,thumbChar:this.widget.thumbChar,showTrack:this.widget.showTrack,thumbColor:this.widget.thumbColor,trackColor:this.widget.trackColor})})}}class fg4 extends jk{controller;getScrollInfo;thickness;trackChar;thumbChar;showTrack;thumbColor;trackColor;constructor({key:J,controller:Z,getScrollInfo:Q,thickness:Y=1,trackChar:X=yg4,thumbChar:K=vg4,showTrack:V=!0,thumbColor:z,trackColor:G}){super(J?{key:J}:{});this.controller=Z,this.getScrollInfo=Q,this.thickness=Y,this.trackChar=X,this.thumbChar=K,this.showTrack=V,this.thumbColor=z,this.trackColor=G}createRenderObject(){return new ug4(this)}updateRenderObject(J){J.updateWidget(this)}}class ug4 extends v4{_widget;constructor(J){super();this._widget=J}updateWidget(J){this._widget=J,this.markNeedsLayout()}performLayout(){let J=this._lastConstraints;J6(!!J,"performLayout called without constraints");let Z=Math.min(J.maxWidth,this._widget.thickness),Q=J.maxHeight;this.setSize(Z,Q),super.performLayout()}getMinIntrinsicWidth(J){return this._widget.thickness}getMaxIntrinsicWidth(J){return this._widget.thickness}getMinIntrinsicHeight(J){return 0}getMaxIntrinsicHeight(J){return 0}paint(J,Z,Q){let{thumbStartFloat:Y,thumbSizeFloat:X,showScrollbar:K}=this._calculateScrollbarMetrics();if(!K)return;let V=this._widget.trackColor,z=this._widget.thumbColor,G=process.platform==="win32",F=Y,q=Y+X;if(!G){let W=["▁","▂","▃","▄","▅","▆","▇","█"];for(let U=0;U<this.size.height;U++){let D="█",H=!0;if(U===Math.floor(F)){let B=1-(F-U),N=Math.floor(B*8);D=W[N]||"█",H=!1}else if(U===Math.floor(q)){let B=1-(q-U),N=Math.floor(B*8);D=W[N]||"█"}else if(U>F&&U<q)H=!1;J.setChar(Z,Q+U,D,{fg:z,bg:V,reverse:H},1)}return}for(let W=0;W<this.size.height;W++){let U=W+0.5,D=U>=F&&U<q,H=D?this._widget.thumbChar:this._widget.trackChar;J.setChar(Z,Q+W,H,{fg:D?z:V,bg:V,reverse:!1},1)}}_calculateScrollbarMetrics(){let{totalContentHeight:J,viewportHeight:Z,scrollOffset:Q}=this._widget.getScrollInfo(),Y=this.size.height;if(J<=Z||Y<=0)return{thumbStartFloat:0,thumbSizeFloat:0,showScrollbar:!1};let X=Math.max(0,Math.min(1,Q/(J-Z))),K=Math.min(1,Z/J),V=Math.max(1,Y*K),z=Y-V;return{thumbStartFloat:Math.max(0,z*X),thumbSizeFloat:V,showScrollbar:!0}}}class IR extends l0{props;constructor(J){super();this.props=J}createState(){return new bg4}}class bg4 extends d0{scrollController=new A5;scrollAreaKey=new p7("message-dialog-scroll-area");viewportHeight=20;initState(){super.initState(),this.scrollController.followMode=!1,this.scrollController.addListener(()=>{this.setState()})}dispose(){this.scrollController.dispose(),super.dispose()}isWidgetMessage(J){return J instanceof n2}resolveFooterStyle(J){if(this.isWidgetMessage(J))return J.footerStyle;return"default"}getViewportHeight(){let Z=this.scrollAreaKey.currentElement?.renderObject;if(Z&&"size"in Z){let Q=Z.size;if(typeof Q.height==="number"&&Q.height>0)return this.viewportHeight=Q.height,Q.height}return this.viewportHeight}build(J){let Z=f0.of(J),Q=this.widget.props.message,Y=(()=>{if(this.isWidgetMessage(Q))return{title:Q.title,type:Q.type};if(Q instanceof Error&&Q.name==="CommandCancelledError")return{title:"Cancelled",type:"info",description:Q.message};if(Q instanceof Error&&Q.name==="CommandTimeoutError")return{title:"Timeout",type:"error",description:Q.message};let q=dz0(Q);return{title:q.title,type:q.type,description:q.description}})(),X=Y.type==="error"?Z.app.toolError:Z.app.command,K=c1.all(new h1(Z.colors.border,1,"solid")),V=new i0({padding:C0.symmetric(1,0),child:new $0({text:new C(Y.title,new g({color:X,bold:!0}))})}),z=this.isWidgetMessage(Q)?Q.widget:new $0({text:new C(Y.description,new g({color:Z.colors.foreground})),selectable:!0}),G=new k1({child:new g$({child:new i0({padding:C0.symmetric(1,0),child:new q1({key:this.scrollAreaKey,crossAxisAlignment:"stretch",children:[new k1({child:new T6({controller:this.scrollController,autofocus:!0,child:z})}),new O9({controller:this.scrollController,thumbColor:Z.app.scrollbarThumb,trackColor:Z.app.scrollbarTrack,getScrollInfo:()=>{let q=this.scrollController.maxScrollExtent,W=this.scrollController.offset,U=this.getViewportHeight(),D=q+U;return{totalContentHeight:Math.max(D,0),viewportHeight:Math.max(U,1),scrollOffset:Math.max(W,0)}}})]})})})}),F=new i0({padding:C0.symmetric(1,0),child:new $0({text:(()=>{if(this.widget.props.onRetry)return new C("",void 0,[new C("Press ",new g({color:Z.colors.foreground,dim:!0})),new C("R",new g({color:Z.app.keybind})),new C(" to retry, ",new g({color:Z.colors.foreground,dim:!0})),new C("Esc",new g({color:Z.app.keybind})),new C(" to cancel",new g({color:Z.colors.foreground,dim:!0}))]);let q=this.resolveFooterStyle(this.widget.props.message);if(q==="none")return new C("",new g({color:Z.colors.foreground,dim:!0}));if(q==="help"){let W=new g({color:Z.app.keybind}),U=new g({color:Z.colors.foreground,dim:!0});return new C("",U,[new C("Press ",U),new C("Escape",W),new C(" to close • Use ",U),new C("↑↓",W),new C(" or ",U),new C("j/k",W),new C(" to scroll",U)])}return new C("Press any key to close",new g({color:Z.colors.foreground,dim:!0,italic:!0}))})()})});return new s4({onKey:(q)=>{if(this.widget.props.onRetry&&q.key==="r")return this.widget.props.onRetry(),"handled";if(q.key==="Escape")return this.widget.props.onDismiss(),"handled";if(!this.widget.props.onRetry)return this.widget.props.onDismiss(),"handled";return"ignored"},autofocus:!1,child:new i0({decoration:{border:K,color:Z.colors.background},padding:C0.all(1),child:new x0({mainAxisAlignment:"center",children:[V,new I0({height:1}),G,F]})})})}}P2();class hg4 extends l0{props;constructor(J){super();this.props=J}createState(){return new gg4}}class gg4 extends d0{plugins=[];subscription=null;initState(){this.subscription=this.widget.props.pluginService.plugins.subscribe((J)=>{this.plugins=J,this.setState(()=>{})})}dispose(){this.subscription?.unsubscribe(),super.dispose()}getRelativePath(J){let Z=J.startsWith("file://")?J.slice(7):J,Q=this.widget.props.cwd;if(Z.startsWith(Q))return Z.slice(Q.length+1);return Z}statusIcon(J){let Z=_9.default(),{colors:Q,app:Y}=Z;switch(J){case"loading":return{icon:"◌",color:Q.warning};case"active":return{icon:"✓",color:Y.toolSuccess};case"error":return{icon:"✗",color:Y.toolError}}}build(J){let Z=f0.of(J),{app:Q}=Z;if(this.plugins.length===0)return new $0({text:new C("No plugins found.",new g({dim:!0}))});let Y=[],X=this.plugins.length,K=this.plugins.filter((G)=>G.status==="active").length,V=this.plugins.reduce((G,F)=>G+F.registeredCommands.length,0),z=this.plugins.reduce((G,F)=>G+F.registeredTools.length,0);if(Y.push(new C(`${K}/${X} ${d4(X,"plugin")} active`,new g({bold:!0}))),V>0||z>0)Y.push(new C(` (${V} ${d4(V,"command")}, ${z} ${d4(z,"tool")})`,new g({dim:!0})));Y.push(new C(`
7375
7375
 
7376
7376
  `));for(let G of this.plugins){let{icon:F,color:q}=this.statusIcon(G.status),W=this.getRelativePath(G.uri.toString());if(Y.push(new C(`${F} `,new g({color:q}))),Y.push(new C(W,new g({bold:!0}))),Y.push(new C(` ${G.status}`,new g({dim:!0}))),Y.push(new C(`
7377
7377
  `)),G.status==="active"&&G.registeredEvents.length>0)Y.push(new C(" Events: ",new g({dim:!0}))),Y.push(new C(G.registeredEvents.join(", "),new g({color:Q.link}))),Y.push(new C(`
@@ -7600,7 +7600,7 @@ ${X0.content||""}`:X0.content||"",J1=[],H1=X0.baseDir.startsWith("file://")?eG0(
7600
7600
  `),process.exit(1)}process.stdout.write(await s_3(G.result.displayText)+`
7601
7601
  `),process.exit(0)})}nM();import{stdout as t_3}from"node:process";function e_3({version:J,buildTimestamp:Z,buildType:Q}){let Y=Q==="dev"?"dev":"released",X=Z?new Date(Z):null,K=X&&!Number.isNaN(X.getTime())?`, ${EF(X)} ago`:"";return`${J} (${Y}${Z?` ${Z}`:""}${K})`}function Tc4(J){t_3.write(`${e_3(J)}
7602
7602
  `)}function _c4(J,Z){J.option("-V, --version","Print the version number and exit",()=>{Tc4(Z),process.exit(0)}),J.command("version").description("Print the version number and exit").action(()=>{Tc4(Z),process.exit(0)})}var Lx3=PO.join(oZ,"logs","headless.log"),U51=PO.join(Ak,"device-id.json");async function Ex3(){for(let J of qE)try{if((await J.listConfigs()).length>0)return J}catch(Z){I.debug("Failed to detect query-based IDE integration",{ideName:J.ideName,error:Z})}return}try{if(process.platform==="win32")await Promise.resolve().then(() => z4($x(),1))}catch{}if(process.env.AMP_PWD)try{process.chdir(process.env.AMP_PWD),delete process.env.AMP_PWD}catch(J){E7.write(`Failed to change directory to ${process.env.AMP_PWD}: ${J}
7603
- `)}function Mx3(J){process.emitWarning=(Z,Q,Y,X)=>{let K=typeof Z==="string"?Z:Z.message||String(Z),V=Q||"Warning",z=!1;J.warn(K,{name:V,code:Y})}}function r2(J,Z){if(J.getOptionValueSourceWithGlobals("dangerouslyAllowAll")==="cli")aJ("dangerouslyAllowAll",Z.dangerouslyAllowAll);if(J.getOptionValueSourceWithGlobals("mode")==="cli")aJ("experimental.agentMode",Z.mode)}function za4(J,Z){if(J.getOptionValueSourceWithGlobals("sp")==="cli"&&Z.sp)return Z.sp;if(J.getOptionValueSourceWithGlobals("systemPrompt")==="cli"&&Z.systemPrompt)return Z.systemPrompt;return}async function Ax3(J){try{return await Ka4(J,"utf-8")}catch{return J}}async function D51(J,Z,Q){let Y=za4(J,Z);if(!Y)return;let X=m6(Q)?Q.features:[],K=m6(Q)?Q.user.email:void 0;if(!O51(X,P7.HARNESS_SYSTEM_PROMPT)&&!Ga4(K))throw new I1("You are not allowed to do this.",1);aJ("systemPrompt",await Ax3(Y))}function Ga4(J){return!!(J&&_10(J))}function O51(J,Z){return J?.some((Q)=>Q.name===Z&&Q.enabled)??!1}function H51(J){return(J.userEmail?$J(J.userEmail):!1)||O51(J.features,P7.DTW_TUI)}function tn4(J){if(J.dtwEnabled&&!J.hasV2TUIAccess)throw new I1("This TUI mode is not enabled for your user;",1)}function B51(J,Z){if(typeof J==="boolean")return J;if(!m6(Z))return!1;return H51({userEmail:Z.user.email,features:Z.features})}function N51(J){if(!m6(J))return null;return{...J.user,features:J.features??[],team:J.workspace??void 0}}function jx3(J){try{let Z=new URL(J);return Z.hostname==="localhost"||Z.hostname==="127.0.0.1"}catch{return J.includes("localhost")||J.includes("127.0.0.1")}}function dF0(J){let Y=jx3(J)?"Run `pnpm dev` to start the local server, then try again.":"Check your network connection or the server URL and try again.";return new I1(`Couldn't connect to the Amp server at ${J}.`,1,Y)}async function en4(J){if(!X5.write(J))await Bx3(X5,"drain")}var $a4=[{name:"notifications",long:"notifications",type:"flag",description:(J)=>`${J?"Enable":"Disable"} sound notifications (enabled by default when not in execute mode)`},{name:"color",long:"color",type:"flag",description:(J)=>`${J?"Enable":"Disable"} color output (enabled by default if stdout and stderr are sent to a TTY)`},{name:"settingsFile",long:"settings-file",type:"option",default:process.env.AMP_SETTINGS_FILE??EK,description:`Custom settings file path (overrides the default location ${EK})`},{name:"logLevel",long:"log-level",type:"option",description:`Set log level (${Object.keys(I).join(", ")})`},{name:"logFile",long:"log-file",type:"option",description:`Set log file location (overrides the default location ${cA})`},{name:"format",long:"format",type:"option",description:"output using the standard or new-ui. Options: `ui`, `new-ui`",choices:["ui","jsonl","new-ui"],hidden:!0,deprecated:!0},{name:"dangerouslyAllowAll",long:"dangerously-allow-all",type:"switch",default:!1,description:"Disable all command confirmation prompts (agent will execute all commands without asking)"},{name:"jetbrains",long:"jetbrains",type:"flag",default:b2(),description:(J)=>J?"Enable JetBrains integration. When enabled, Amp automatically includes your open JetBrains file and text selection with every message.":"Disable JetBrains integration"},{name:"ide",long:"ide",type:"flag",default:!0,description:(J)=>J?"Enable IDE connection (default). When enabled, Amp automatically includes your open IDE's file and text selection with every message.":"Disable IDE connection"},{name:"interactive",long:"interactive",type:"flag",description:(J)=>J?"Enable interactive mode. This will enable the interactive UI.":"Disable interactive mode. This will disable the interactive UI.",hidden:!0,deprecated:!0},{name:"mcpConfig",long:"mcp-config",type:"option",description:"JSON configuration or file path for MCP servers to merge with existing settings"},{name:"mode",long:"mode",short:"m",type:"option",default:vG.SMART.key,description:`Set the agent mode (${EV().map((J)=>J.mode).join(", ")}) — controls the model, system prompt, and tool selection`,choices:EV().map((J)=>J.mode).concat("large","deep","internal")},{name:"takeMeBack",long:"take-me-back",type:"switch",description:"Disable v2 thread mode and use the legacy worker runtime",hidden:!0},{name:"headless",long:"headless",type:"optional-option",description:"Run headless DTW harness (no TUI). Optionally provide a thread ID to connect as executor.",hidden:!0},{name:"threadActors",long:"thread-actors",type:"optional-option",description:"Connect to the thread-actors counter service. Optionally provide a thread ID.",hidden:!0},{name:"apiKey",long:"api-key",type:"option",description:"API key for internal DTW commands (overrides AMP_API_KEY)",hidden:!0},{name:"sp",long:"sp",type:"option",description:"Custom system prompt text or file path",hidden:!0},{name:"systemPrompt",long:"system-prompt",type:"option",description:"Custom system prompt text",hidden:!0}],Ja4=(J)=>("deprecated"in J)&&J.deprecated===!0,Rx3=(J)=>("hidden"in J)&&J.hidden===!0,Ix3=(J)=>("default"in J),Px3=(J)=>("default"in J)?J.default:void 0,Fa4=[{name:"toggle-skills-count",entryPoint:Vi0}];function Cx3(J,Z){let Q=Z.args[0],Y=Z.commands.map((K)=>K.name());if(Q&&!Q.includes(" ")&&Q.length<30&&!/[./\\]/.test(Q)){let K=Y.filter((z)=>Q.includes(z)||z.includes(Q)),V="Run amp --help for a list of available commands.";if(K.length>0)V=`Did you mean: ${K.join(", ")}? Or run amp --help for all commands.`;throw new I1(L3.unknownCommand(Q),1,V)}}async function L51(J){return{...J,getThreadEnvironment:HZ,threadSyncService:J.threadSyncService,osFileSystem:J.fileSystem,skillService:J.skillService,fileChangeTrackerStorage:new bV(J.fileSystem),generateThreadTitle:s80,deleteThread:(Z)=>J.threadService.delete(Z),getServerStatus:()=>eZ(J.configService),pluginService:J.pluginService}}function qa4(J){return{toolService:J.toolService,configService:J.configService,skillService:J.skillService,getThreadEnvironment:HZ,filesystem:J.fileSystem,threadService:J.threadService}}var cF0=X1.file(Va4.homedir()),w51=process.env.XDG_CONFIG_HOME?X1.file(process.env.XDG_CONFIG_HOME):K1.joinPath(cF0,".config");function Tx3(J){return AW4({playNotificationSound:async(Z)=>{if(J.useNotificationsForService){MW4(Z);let Q=oQ0(),Y=Mi0();if((!Q||Y||TM4())&&J.config.settings["notifications.system.enabled"]!==!1){if(Z==="idle")process.stdout.write(QD("\x1B]777;notify;Amp;Agent is ready\x1B\\"));else if(Z==="requires-user-input")process.stdout.write(QD("\x1B]777;notify;Amp;Waiting for approval\x1B\\"))}}},windowFocused:()=>Promise.resolve(oQ0()),threadService:J.threadService,configService:J.configService,threadViewStates$:J.threadViewStates$})}function _x3(){return{sync:async()=>{},uploadThread:async()=>{},discoverThreads:async()=>[],initialSyncComplete:Promise.resolve(),updateThreadMeta:async()=>{},threadSyncInfo:()=>k0.of({}),flushPendingSyncs:async()=>{},dispose:()=>{}}}async function t9(J,Z,Q){let Y=Q?.deferAuth??!1;Pf1("0.0.1774123285-gb6e451");let X=d10({storage:J.settings,secretStorage:J.secrets,workspaceRoot:k0.of(X1.file(process.cwd())),defaultAmpURL:J.ampURL,homeDir:cF0,userConfigDir:w51});CM4(X);let K=await X.getLatest();I.debug("Global configuration initialized",{settingsKeys:Object.keys(K.settings)});let V=!1;{let F0=await J.secrets.get("apiKey",J.ampURL);if(V=Boolean(F0),I.info("API key lookup before login",{found:Boolean(F0),ampURL:J.ampURL,deferAuth:Y}),!F0)if(Y)I.info("No API key found, continuing startup with deferred auth");else{X5.write(`No API key found. Starting login flow...
7603
+ `)}function Mx3(J){process.emitWarning=(Z,Q,Y,X)=>{let K=typeof Z==="string"?Z:Z.message||String(Z),V=Q||"Warning",z=!1;J.warn(K,{name:V,code:Y})}}function r2(J,Z){if(J.getOptionValueSourceWithGlobals("dangerouslyAllowAll")==="cli")aJ("dangerouslyAllowAll",Z.dangerouslyAllowAll);if(J.getOptionValueSourceWithGlobals("mode")==="cli")aJ("experimental.agentMode",Z.mode)}function za4(J,Z){if(J.getOptionValueSourceWithGlobals("sp")==="cli"&&Z.sp)return Z.sp;if(J.getOptionValueSourceWithGlobals("systemPrompt")==="cli"&&Z.systemPrompt)return Z.systemPrompt;return}async function Ax3(J){try{return await Ka4(J,"utf-8")}catch{return J}}async function D51(J,Z,Q){let Y=za4(J,Z);if(!Y)return;let X=m6(Q)?Q.features:[],K=m6(Q)?Q.user.email:void 0;if(!O51(X,P7.HARNESS_SYSTEM_PROMPT)&&!Ga4(K))throw new I1("You are not allowed to do this.",1);aJ("systemPrompt",await Ax3(Y))}function Ga4(J){return!!(J&&_10(J))}function O51(J,Z){return J?.some((Q)=>Q.name===Z&&Q.enabled)??!1}function H51(J){return(J.userEmail?$J(J.userEmail):!1)||O51(J.features,P7.DTW_TUI)}function tn4(J){if(J.dtwEnabled&&!J.hasV2TUIAccess)throw new I1("This TUI mode is not enabled for your user;",1)}function B51(J,Z){if(typeof J==="boolean")return J;if(!m6(Z))return!1;return H51({userEmail:Z.user.email,features:Z.features})}function N51(J){if(!m6(J))return null;return{...J.user,features:J.features??[],team:J.workspace??void 0}}function jx3(J){try{let Z=new URL(J);return Z.hostname==="localhost"||Z.hostname==="127.0.0.1"}catch{return J.includes("localhost")||J.includes("127.0.0.1")}}function dF0(J){let Y=jx3(J)?"Run `pnpm dev` to start the local server, then try again.":"Check your network connection or the server URL and try again.";return new I1(`Couldn't connect to the Amp server at ${J}.`,1,Y)}async function en4(J){if(!X5.write(J))await Bx3(X5,"drain")}var $a4=[{name:"notifications",long:"notifications",type:"flag",description:(J)=>`${J?"Enable":"Disable"} sound notifications (enabled by default when not in execute mode)`},{name:"color",long:"color",type:"flag",description:(J)=>`${J?"Enable":"Disable"} color output (enabled by default if stdout and stderr are sent to a TTY)`},{name:"settingsFile",long:"settings-file",type:"option",default:process.env.AMP_SETTINGS_FILE??EK,description:`Custom settings file path (overrides the default location ${EK})`},{name:"logLevel",long:"log-level",type:"option",description:`Set log level (${Object.keys(I).join(", ")})`},{name:"logFile",long:"log-file",type:"option",description:`Set log file location (overrides the default location ${cA})`},{name:"format",long:"format",type:"option",description:"output using the standard or new-ui. Options: `ui`, `new-ui`",choices:["ui","jsonl","new-ui"],hidden:!0,deprecated:!0},{name:"dangerouslyAllowAll",long:"dangerously-allow-all",type:"switch",default:!1,description:"Disable all command confirmation prompts (agent will execute all commands without asking)"},{name:"jetbrains",long:"jetbrains",type:"flag",default:b2(),description:(J)=>J?"Enable JetBrains integration. When enabled, Amp automatically includes your open JetBrains file and text selection with every message.":"Disable JetBrains integration"},{name:"ide",long:"ide",type:"flag",default:!0,description:(J)=>J?"Enable IDE connection (default). When enabled, Amp automatically includes your open IDE's file and text selection with every message.":"Disable IDE connection"},{name:"interactive",long:"interactive",type:"flag",description:(J)=>J?"Enable interactive mode. This will enable the interactive UI.":"Disable interactive mode. This will disable the interactive UI.",hidden:!0,deprecated:!0},{name:"mcpConfig",long:"mcp-config",type:"option",description:"JSON configuration or file path for MCP servers to merge with existing settings"},{name:"mode",long:"mode",short:"m",type:"option",default:vG.SMART.key,description:`Set the agent mode (${EV().map((J)=>J.mode).join(", ")}) — controls the model, system prompt, and tool selection`,choices:EV().map((J)=>J.mode).concat("large","deep","internal")},{name:"takeMeBack",long:"take-me-back",type:"switch",description:"Disable v2 thread mode and use the legacy worker runtime",hidden:!0},{name:"headless",long:"headless",type:"optional-option",description:"Run headless DTW harness (no TUI). Optionally provide a thread ID to connect as executor.",hidden:!0},{name:"threadActors",long:"thread-actors",type:"optional-option",description:"Connect to the thread-actors counter service. Optionally provide a thread ID.",hidden:!0},{name:"apiKey",long:"api-key",type:"option",description:"API key for internal DTW commands (overrides AMP_API_KEY)",hidden:!0},{name:"sp",long:"sp",type:"option",description:"Custom system prompt text or file path",hidden:!0},{name:"systemPrompt",long:"system-prompt",type:"option",description:"Custom system prompt text",hidden:!0}],Ja4=(J)=>("deprecated"in J)&&J.deprecated===!0,Rx3=(J)=>("hidden"in J)&&J.hidden===!0,Ix3=(J)=>("default"in J),Px3=(J)=>("default"in J)?J.default:void 0,Fa4=[{name:"toggle-skills-count",entryPoint:Vi0}];function Cx3(J,Z){let Q=Z.args[0],Y=Z.commands.map((K)=>K.name());if(Q&&!Q.includes(" ")&&Q.length<30&&!/[./\\]/.test(Q)){let K=Y.filter((z)=>Q.includes(z)||z.includes(Q)),V="Run amp --help for a list of available commands.";if(K.length>0)V=`Did you mean: ${K.join(", ")}? Or run amp --help for all commands.`;throw new I1(L3.unknownCommand(Q),1,V)}}async function L51(J){return{...J,getThreadEnvironment:HZ,threadSyncService:J.threadSyncService,osFileSystem:J.fileSystem,skillService:J.skillService,fileChangeTrackerStorage:new bV(J.fileSystem),generateThreadTitle:s80,deleteThread:(Z)=>J.threadService.delete(Z),getServerStatus:()=>eZ(J.configService),pluginService:J.pluginService}}function qa4(J){return{toolService:J.toolService,configService:J.configService,skillService:J.skillService,getThreadEnvironment:HZ,filesystem:J.fileSystem,threadService:J.threadService}}var cF0=X1.file(Va4.homedir()),w51=process.env.XDG_CONFIG_HOME?X1.file(process.env.XDG_CONFIG_HOME):K1.joinPath(cF0,".config");function Tx3(J){return AW4({playNotificationSound:async(Z)=>{if(J.useNotificationsForService){MW4(Z);let Q=oQ0(),Y=Mi0();if((!Q||Y||TM4())&&J.config.settings["notifications.system.enabled"]!==!1){if(Z==="idle")process.stdout.write(QD("\x1B]777;notify;Amp;Agent is ready\x1B\\"));else if(Z==="requires-user-input")process.stdout.write(QD("\x1B]777;notify;Amp;Waiting for approval\x1B\\"))}}},windowFocused:()=>Promise.resolve(oQ0()),threadService:J.threadService,configService:J.configService,threadViewStates$:J.threadViewStates$})}function _x3(){return{sync:async()=>{},uploadThread:async()=>{},discoverThreads:async()=>[],initialSyncComplete:Promise.resolve(),updateThreadMeta:async()=>{},threadSyncInfo:()=>k0.of({}),flushPendingSyncs:async()=>{},dispose:()=>{}}}async function t9(J,Z,Q){let Y=Q?.deferAuth??!1;Pf1("0.0.1774126892-geb7ca3");let X=d10({storage:J.settings,secretStorage:J.secrets,workspaceRoot:k0.of(X1.file(process.cwd())),defaultAmpURL:J.ampURL,homeDir:cF0,userConfigDir:w51});CM4(X);let K=await X.getLatest();I.debug("Global configuration initialized",{settingsKeys:Object.keys(K.settings)});let V=!1;{let F0=await J.secrets.get("apiKey",J.ampURL);if(V=Boolean(F0),I.info("API key lookup before login",{found:Boolean(F0),ampURL:J.ampURL,deferAuth:Y}),!F0)if(Y)I.info("No API key found, continuing startup with deferred auth");else{X5.write(`No API key found. Starting login flow...
7604
7604
  `);let a=await Sx3(J),U0=await J.secrets.get("apiKey",J.ampURL);if(I.info("Login flow completed",{success:a,storedKeyPresent:Boolean(U0),ampURL:J.ampURL}),!a)await dF(),process.exit(1);V=!0}}{let F0=await X.getLatest(),a=F0.settings.url,U0=F0.secrets.isSet?.[a];I.info("Config secrets state after login",{configURL:a,apiKeySet:U0?.apiKey??!1})}let z=M1(eZ(X).pipe(L5((F0)=>F0!=="pending"))),G=Y?"pending":await z;if(!Y)I.info("Server status resolved",{status:"ready",isAuthenticated:m6(G),isError:hW(G),errorMessage:hW(G)?G.error.message:void 0});let{toolService:F,dispose:q}=NW4({configService:X}),W=new Map,U=()=>W.clear(),D=new A_0(X,J.settings.getWorkspaceRootPath()),H=It1({configService:X,filesystem:E8}),B=Ea1({configService:X,trustStore:D,skillMCPServers:H.skillMCPServers,createOAuthProvider:async(F0,a,U0)=>{let O0=`${F0}:${a}`,G0=W.get(O0);if(G0)return I.debug("Reusing existing OAuth provider for server",{serverName:F0,serverUrl:a}),G0;I.debug("Creating OAuth provider for server",{serverName:F0,serverUrl:a});let e=(async()=>{let W0=new LE(J.secrets),i=await W0.getClientInfo(F0,a),o=U0?.scopes??i?.scopes,t=zO4();I.info("OAuth headless mode check",{useHeadless:t,executeMode:J.executeMode,envVar:process.env.AMP_HEADLESS_OAUTH,isTTY:X5.isTTY});let Z0;if(t)Z0=J.executeMode?VO4():KO4(F0);let X0=new QI0({storage:W0,serverName:F0,serverUrl:a,clientId:U0?.clientId??i?.clientId,clientSecret:U0?.clientSecret??i?.clientSecret,authUrl:U0?.authUrl??i?.authUrl,tokenUrl:U0?.tokenUrl??i?.tokenUrl,scopes:o,headlessAuthHandler:Z0});return I.debug("OAuth provider created",{serverName:F0,serverUrl:a,hasManualClientId:!!(U0?.clientId??i?.clientId),willUseDCR:!(U0?.clientId??i?.clientId),scopes:o,headlessMode:t,executeMode:J.executeMode}),X0})();return W.set(O0,e),e}}),N=Rm0({configService:X,filesystem:E8,spawn:ZJ0}),w;if(J.executeMode){let F0=await EG4({toolService:F,providers:[B,N],initialTimeout:15000});w=F0.registrations;for(let[a,U0]of F0.initErrors)I.warn(`${a} provider initialization slow or failed:`,U0)}else w=Im0({toolService:F,providers:[B,N]});if(Z.jetbrains)VE("JetBrains");else if(Z.ide&&iO4())VE("VS Code");else if(Z.ide&&nO4())VE("Neovim");else if(Z.ide){let F0=await Ex3();if(F0){let a=t10(F0.ideName);if(a)VE(a)}}if(J.executeMode)Cf1(!0);let O,L=N$.status.pipe(W1((F0)=>Boolean(F0.connected&&F0.authenticated&&F0.ideName&&Wu1(F0.ideName))),y4()).subscribe((F0)=>{if(F0){if(!O)O=F.registerTool(LG4)}else O?.dispose(),O=void 0}),E;if(!J.executeMode){let F0=await J.settings.get("fuzzy.alwaysIncludePaths")??[];E=new uZ0(process.cwd(),{alwaysIncludePaths:F0},!0)}else E=new class extends uZ0{async start(){}async query(){return[]}getStats(){return{state:"unstarted",stats:[]}}dispose(){}};let M=await kt1({isDevelopment:!1}),A=new Ay0(M,X),j=new Dk0(M,{lazy:!0,maxThreads:200});I.info("Starting Amp background services");let R=Z.takeMeBack?!1:void 0,_=B51(R,G),k=Boolean(_||Z.headless);if(k)I.info("DTW mode enabled: thread sync service disabled");let u=k?_x3():z04({threadService:A,threadHistoryService:j,configService:X,isExtensionDevelopment:!1}),m;N$.status.subscribe((F0)=>{m=F0});let x=new dj0({workspaceRoots:[X1.file(process.cwd())],fileSystem:E8,getCurrentFile:()=>{if(!m?.openFile)return;try{return X1.parse(m.openFile)}catch(F0){I.warn("Failed to parse current file URI",{uri:m.openFile,error:F0});return}},getOpenFiles:()=>{if(!m?.visibleFiles?.length)return[];let F0=m.openFile;return m.visibleFiles.filter((a)=>a!==F0).map((a)=>{try{return X1.parse(a)}catch(U0){return I.warn("Failed to parse visible file URI",{uri:a,error:U0}),null}}).filter((a)=>a!==null)}}),T=new Ri0,f=process.env.PLUGINS??"off",p=Z.headless?WM4():void 0,d=p??new dQ0({configService:X}),h=d instanceof dQ0?d:void 0;if(h)h.pluginExecutorKind=_?"local":"unknown";let n=h_0({configService:X,fileSystem:E8,platform:d,internalPlugins:Fa4,pluginFilter:f}),c=Ho1({pluginService:n,toolService:F}),s={codebaseContextService:x,configService:X,toolService:F,mcpService:B,skillService:H,toolboxService:N,trustStore:D,threadService:A,threadHistoryService:j,threadSyncService:u,threadStorage:M,secretStorage:J.secrets,settingsStorage:J.settings,fuzzyServer:E,fileSystem:E8,terminal:T,pluginService:n,pluginPlatform:h,headlessPluginPlatform:p,serverStatus:G,serverStatusPromise:z,hasAPIKeyAtStartup:V};return{...s,async asyncDispose(){if(s.mcpService.hasAuthenticatingClients())I.info("Waiting for OAuth authentication to complete before exit..."),await s.mcpService.waitForAuthentication();for(let F0 of w.values())F0.dispose();await s.mcpService.dispose(),U(),await s.threadService.asyncDispose(),s.configService.unsubscribe(),q(),s.fuzzyServer.dispose(),s.threadSyncService.dispose(),s.settingsStorage[Symbol.dispose](),L.unsubscribe(),O?.dispose(),c.dispose(),await s.pluginService.dispose()}}}async function Sx3(J){if(!J.executeMode){if(!await gQ0("Would you like to log in to Amp? [(y)es, (n)o]: "))return X5.write(`Login cancelled. Run the command again to retry.
7605
7605
  `),!1}return await Wa4(J)}async function Wa4(J){let Z=Hx3(32).toString("hex"),Q=await kk(J.ampURL,Z),Y=new AbortController;try{await wV(Q,Y.signal)}catch(K){I.error("Error opening browser",{error:K})}let X=await kk(J.ampURL,Z,!1);X5.write(`If your browser does not open automatically, visit:
7606
7606
 
@@ -7608,7 +7608,7 @@ ${c0.blue.bold(X)}
7608
7608
 
7609
7609
  `);try{return await lE4(J.ampURL,Z,J.secrets,Y),X5.write("\nLogin successful! Run `amp` to get started.\n"),!0}catch(K){return I.error("Login failed",{error:K}),E7.write(`
7610
7610
  Login failed: ${K instanceof Error?K.message:String(K)}
7611
- `),!1}}function Za4(J){if(!J||J.length===0)return;let Z=J.join(" ").trim();return Z.length>0?Z:void 0}async function kx3(J){let Z={...J.agentMode?{agentMode:J.agentMode}:{},...J.repositoryURL?{repositoryURL:J.repositoryURL}:{}},Q=await fetch(`${J.ampURL}/api/durable-thread-workers`,{method:"POST",headers:{Authorization:`Bearer ${J.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(Z)});if(!Q.ok){let X=await Q.text();throw new I1(`Create request failed (${Q.status}): ${X}`,1)}let Y=await Q.json();if(!Y.threadId||!f9(Y.threadId))throw new I1("Create response did not include a valid thread ID",1);return Y.threadId}function yx3(J){return typeof J==="object"&&J!==null&&"durableObjectId"in J&&typeof J.durableObjectId==="string"&&J.durableObjectId.length>0}async function vx3(J){let Z=await fetch(new URL(`/threads/${J.threadID}/durable-object-id`,J.workerURL),{method:"GET",headers:{Authorization:`Bearer ${J.apiKey}`}});if(!Z.ok){let Y=await Z.text();throw new I1(`Durable object ID request failed (${Z.status}): ${Y}`,1)}let Q=await Z.json();if(!yx3(Q))throw new I1("Durable object ID response did not include a durableObjectId",1);return Q.durableObjectId}function xx3(J){return/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(J)}async function fx3(J){let Z=await fetch(`${J.workerURL}/threads/${J.threadID}/spawn`,{method:"POST",headers:{Authorization:`Bearer ${J.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({repositoryURL:J.repositoryURL,...J.projectID?{projectID:J.projectID}:{}})});if(!Z.ok){let Q=await Z.text();throw new I1(`Spawn request failed (${Z.status}): ${Q}`,1)}}function ux3(){let J=new mN().name("amp").description("AI-powered coding assistant").option("--visibility <visibility>","Set thread visibility (private, public, workspace, group)").configureOutput({writeErr:()=>{}});J.exitOverride((H)=>{if(H.code==="commander.help"||H.code==="commander.version"||H.exitCode===0)iA(),process.exit(0);let B=H.originalError??H;Ww4(B)}),_c4(J,{version:"0.0.1774123285-gb6e451",buildTimestamp:"2026-03-21T20:05:11.799Z",buildType:"'release'"}),J.addHelpText("after",dO4()),J.configureHelp({formatHelp:cO4}),J.command("logout").description("Log out by removing stored API key").action(async(H,B)=>{let N=B.optsWithGlobals(),w=await m3(N);await cx3(w)}),J.command("login").description("Log in to Amp").addHelpText("after","If AMP_URL is set during login, it will be persisted to global settings for future CLI invocations, though AMP_URL will continue to take precedence.").action(async(H,B)=>{let N=B.optsWithGlobals(),w=await m3(N);await dx3(w,await Vl0(N,w.settings))}),J.command("git-credential-helper [action]",{hidden:!0}).summary("Git credential helper for GitHub").description("Internal: implements the git credential helper protocol. Used inside sandboxes to authenticate git operations with GitHub.").action(async(H,B,N)=>{let w=N.optsWithGlobals(),O=await m3(w);await bw4(H??"get",O.ampURL,O.secrets),process.exit(process.exitCode??0)}),J.command("sign-commit",{hidden:!0}).summary("Git commit signing helper").description("Internal: implements the gpg signing interface for git commit signing. Used inside sandboxes as gpg.program.").allowUnknownOption().action(async(H,B)=>{let N=B.optsWithGlobals(),w=await m3(N);await hw4(w.ampURL,w.secrets),process.exit(process.exitCode??0)}),J.command("dtw-curl [threadId] [action] [message...]",{hidden:!0}).summary("DTW helper").description("Internal: helper for DTW one-shot commands.").addHelpText("after",`
7611
+ `),!1}}function Za4(J){if(!J||J.length===0)return;let Z=J.join(" ").trim();return Z.length>0?Z:void 0}async function kx3(J){let Z={...J.agentMode?{agentMode:J.agentMode}:{},...J.repositoryURL?{repositoryURL:J.repositoryURL}:{}},Q=await fetch(`${J.ampURL}/api/durable-thread-workers`,{method:"POST",headers:{Authorization:`Bearer ${J.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(Z)});if(!Q.ok){let X=await Q.text();throw new I1(`Create request failed (${Q.status}): ${X}`,1)}let Y=await Q.json();if(!Y.threadId||!f9(Y.threadId))throw new I1("Create response did not include a valid thread ID",1);return Y.threadId}function yx3(J){return typeof J==="object"&&J!==null&&"durableObjectId"in J&&typeof J.durableObjectId==="string"&&J.durableObjectId.length>0}async function vx3(J){let Z=await fetch(new URL(`/threads/${J.threadID}/durable-object-id`,J.workerURL),{method:"GET",headers:{Authorization:`Bearer ${J.apiKey}`}});if(!Z.ok){let Y=await Z.text();throw new I1(`Durable object ID request failed (${Z.status}): ${Y}`,1)}let Q=await Z.json();if(!yx3(Q))throw new I1("Durable object ID response did not include a durableObjectId",1);return Q.durableObjectId}function xx3(J){return/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(J)}async function fx3(J){let Z=await fetch(`${J.workerURL}/threads/${J.threadID}/spawn`,{method:"POST",headers:{Authorization:`Bearer ${J.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({repositoryURL:J.repositoryURL,...J.projectID?{projectID:J.projectID}:{}})});if(!Z.ok){let Q=await Z.text();throw new I1(`Spawn request failed (${Z.status}): ${Q}`,1)}}function ux3(){let J=new mN().name("amp").description("AI-powered coding assistant").option("--visibility <visibility>","Set thread visibility (private, public, workspace, group)").configureOutput({writeErr:()=>{}});J.exitOverride((H)=>{if(H.code==="commander.help"||H.code==="commander.version"||H.exitCode===0)iA(),process.exit(0);let B=H.originalError??H;Ww4(B)}),_c4(J,{version:"0.0.1774126892-geb7ca3",buildTimestamp:"2026-03-21T21:05:12.391Z",buildType:"'release'"}),J.addHelpText("after",dO4()),J.configureHelp({formatHelp:cO4}),J.command("logout").description("Log out by removing stored API key").action(async(H,B)=>{let N=B.optsWithGlobals(),w=await m3(N);await cx3(w)}),J.command("login").description("Log in to Amp").addHelpText("after","If AMP_URL is set during login, it will be persisted to global settings for future CLI invocations, though AMP_URL will continue to take precedence.").action(async(H,B)=>{let N=B.optsWithGlobals(),w=await m3(N);await dx3(w,await Vl0(N,w.settings))}),J.command("git-credential-helper [action]",{hidden:!0}).summary("Git credential helper for GitHub").description("Internal: implements the git credential helper protocol. Used inside sandboxes to authenticate git operations with GitHub.").action(async(H,B,N)=>{let w=N.optsWithGlobals(),O=await m3(w);await bw4(H??"get",O.ampURL,O.secrets),process.exit(process.exitCode??0)}),J.command("sign-commit",{hidden:!0}).summary("Git commit signing helper").description("Internal: implements the gpg signing interface for git commit signing. Used inside sandboxes as gpg.program.").allowUnknownOption().action(async(H,B)=>{let N=B.optsWithGlobals(),w=await m3(N);await hw4(w.ampURL,w.secrets),process.exit(process.exitCode??0)}),J.command("dtw-curl [threadId] [action] [message...]",{hidden:!0}).summary("DTW helper").description("Internal: helper for DTW one-shot commands.").addHelpText("after",`
7612
7612
  Actions:
7613
7613
  create Create a new DTW thread and print its ID
7614
7614
  add-message <message> Send a user message and wait for message_added
@@ -7672,8 +7672,8 @@ ${E}
7672
7672
 
7673
7673
  This thread belongs to a different user and cannot be continued for security reasons. Set AMP_RESUME_OTHER_USER_THREADS_INSECURE=1 to bypass this check.`)}}async function bx3(J){I.info("[createDTWThreadPool] Creating DTW thread pool",{threadId:J.threadId,ampURL:J.ampURL,workerUrl:process.env.AMP_WORKER_URL});try{let Z=new Ln({threadService:J.threadService,configService:J.configService,mcpService:J.mcpService,initialToolDiscovery:Promise.all([J.mcpService.initialized,J.toolboxService.initialized]).then(()=>{return}),toolService:J.toolService,skillService:J.skillService,getThreadEnvironment:HZ,osFileSystem:J.fileSystem,fileChangeTrackerStorage:new bV(J.fileSystem),ampURL:J.ampURL});if(J.threadId)await Z.switchThread(J.threadId);else await Z.createThread();return Z}catch(Z){throw I.error("[createDTWThreadPool] Failed to create DTW thread pool",{threadId:J.threadId,error:Z}),Z}}async function hx3(J){if(J.streamJsonInput)return{userInput:"",stdinInput:null};if(typeof J.execute==="string"){let Z=(await uk()).trimEnd();return{userInput:J.execute,stdinInput:Z||null}}return{userInput:(await uk()).trimEnd(),stdinInput:null}}function gx3(J,Z,Q){if(J.remote&&!Z)throw new I1("The -r/--remote flag requires --execute mode",1,'Use: amp --remote --execute "your message"');if(J.streamJson&&!Z)throw new I1("The --stream-json flag requires --execute mode",1,'Use: amp --execute "your message" --stream-json');if(J.streamJsonInput&&!Z)throw new I1("The --stream-json-input flag requires --execute mode",1,"Use: amp --execute --stream-json --stream-json-input");if(J.streamJsonInput&&!J.streamJson)throw new I1("The --stream-json-input flag requires --stream-json",1,"Use: amp --execute --stream-json --stream-json-input");if(J.stats&&!Z)throw new I1("The --stats flag requires --execute mode",1,'Use: amp --execute "your message" --stats');if(J.archive&&!Z)throw new I1("The --archive flag requires --execute mode",1,'Use: amp --execute "your message" --archive');if(J.streamJsonInput&&typeof J.execute==="string"&&J.execute.trim()!=="")throw new I1("Do not provide a message argument when using --stream-json-input",1,`Supply messages via stdin JSONL instead: echo '{"type":"user","message":{"role":"user","content":[{"type":"text","text":"your message"},{"type":"image","source":{"type":"base64","media_type":"image/png","data":"..."}}]}}' | amp --execute --stream-json --stream-json-input`);if(Z&&Q===""&&!J.streamJsonInput&&!J.headless)throw new I1("User message must be provided through stdin or as argument when using execute mode",1,`Either pass a message as an argument: amp --execute "your message"
7674
7674
  Or pipe via stdin: echo "your message" | amp --execute`)}async function lF0(J,Z,Q){let Y=process.hrtime.bigint(),X=(G0,e)=>{let W0=Number(process.hrtime.bigint()-e)/1e6,i=WU4();I.info("Startup phase",{phase:G0,phaseMs:Math.round(W0),sinceMainMs:i===null?void 0:Math.round(i)})},{userInput:K,stdinInput:V}=await hx3(Z),z=!!Z.streamJson||!!Z.streamJsonThinking;gx3({...Z,streamJson:z},J.executeMode,K),r2(Q,Z);let G=process.hrtime.bigint(),F=Boolean(await J.secrets.get("apiKey",J.ampURL)),q=!J.executeMode&&!Z.headless&&!Z.threadActors&&F;I.info("Interactive auth startup mode",{deferInteractiveAuth:q,hasAPIKeyAtStartup:F,executeMode:J.executeMode,headless:Boolean(Z.headless)});let W=await t9(J,Z,{deferAuth:q});X("runMainThread:createThreadDependencies",G),G=process.hrtime.bigint();let U=await L51(W);X("runMainThread:createWorkerDeps",G);let{serverStatus:D}=W;if(!q&&hW(D)){let G0=Hk(Error(D.error.message));if(G0.message===L3.networkOffline||G0.message===L3.networkTimeout)throw dF0(J.ampURL);throw new I1(L3.invalidAPIKey,1)}let H=m6(D)?D:null,B=H?.user.email,N=Ga4(B),w=H51({userEmail:B,features:H?.features}),O=Z.takeMeBack?!1:void 0,L=H!==null&&B51(O,H);if(!q)await D51(Q,Z,D);let E=N51(D),M=E?.features??[],A=E?.team??null,j=mQ0(Z,E);if(j instanceof Error)p3(j.message);if((J.executeMode||z)&&w8(Z.mode)&&!N)throw new I1(`Execute mode is not permitted with --mode '${Z.mode}'`,1);if(H&&!dH(Z.mode,B))throw new I1(`Agent mode '${Z.mode}' is only available for Amp employees`,1);if(J.executeMode&&Z.remote)await HM4(K,V,W.configService),await W.asyncDispose(),process.exit(0);if(Z.threadActors){if(!B||!$J(B))throw new I1("Thread-actors mode is only available for Amp employees",1);let G0=await W.secretStorage.get("apiKey",J.ampURL);if(!G0)throw new I1("API key required. Please run `amp login` first.",1);let e=typeof Z.threadActors==="string"&&Z.threadActors!=="true"?Z.threadActors:void 0;await u_4({configService:W.configService,apiKey:G0,threadId:e}),await W.asyncDispose(),await dF(),process.exit(0)}if(Z.headless){if(!B||!$J(B))throw new I1("Headless DTW mode is only available for Amp employees",1);let G0=await W.secretStorage.get("apiKey",J.ampURL);if(!G0)throw new I1("API key required for headless mode. Please run `amp login` first.",1);let e=typeof Z.headless==="string"&&Z.headless!=="true"?Z.headless:void 0;if(e&&!f9(e))throw new I1(`Invalid thread ID: ${e}`,1);let W0=e??await tx3({dependencies:W,visibility:j??void 0}),i=await WO4(W0);if(i.status==="already-running")await W.asyncDispose(),await dF(),process.exit(0);try{await XO4({ampURL:J.ampURL,apiKey:G0,workerUrl:process.env.AMP_WORKER_URL,workspaceRoot:process.cwd(),threadId:W0,initialToolDiscovery:Promise.all([W.mcpService.initialized,W.toolboxService.initialized]).then(()=>{return}),configService:W.configService,mcpService:W.mcpService,toolService:W.toolService,skillService:W.skillService,fileSystem:W.fileSystem,pluginService:W.pluginService,pluginPlatform:W.headlessPluginPlatform})}finally{await i.release(),await W.asyncDispose()}await dF(),process.exit(0)}let R=J.executeMode?void 0:async(G0)=>fo(G0,"interactive"),_={threadService:W.threadService,workerDeps:U,createThread:async()=>{let G0=q?await W.serverStatusPromise:D,e=await MZ0(J.settings,process.cwd(),N51(G0),j);if(e instanceof Error)p3(e.message);return Pe0(U,{threadMeta:e?Oz(e):void 0,agentMode:Z.mode,onFirstAssistantMessage:R})},validateThreadOwnership:async(G0,e)=>{if(e?.nonBlockingOwnershipCheck){Qa4(G0,W.configService).catch((W0)=>{if(W0 instanceof I1){if(e.onOwnershipError){e.onOwnershipError(W0,G0);return}Bk(W0,G0);return}I.warn("Failed to validate thread ownership in CLI, allowing to open",{error:W0})});return}try{await Qa4(G0,W.configService)}catch(W0){if(W0 instanceof I1)throw W0;I.warn("Failed to validate thread ownership in CLI, allowing to open",{error:W0})}},switchThreadVisibility:j,switchThreadAgentMode:Z.mode,onFirstAssistantMessage:R},k=async(G0)=>{try{if(G0==="dtw")return bx3({ampURL:J.ampURL,configService:W.configService,threadService:W.threadService,mcpService:W.mcpService,toolboxService:W.toolboxService,toolService:W.toolService,skillService:W.skillService,fileSystem:W.fileSystem,threadId:Z.threadId});return zu4(_,Z.threadId,{nonBlockingOwnershipCheck:Z.nonBlockingThreadOwnershipCheck})}catch(e){if(e instanceof I1)throw e;throw await Bk(e,Z.threadId),Error("handleError should have called process.exit()")}};if(Z.format==="jsonl")E7.write(`jsonl format is deprecated. Version "0.0.1752148945-gd8844f" or earlier is required to use jsonl format.
7675
- `),await dF(),process.exit(1);let u=(async()=>{if(q){I.info("Skipping initial free tier status fetch until auth is complete");return}try{let G0=await W.configService.getLatest(),e=Hb(G0),W0=await g6.getUserFreeTierStatus({},{config:W.configService,signal:AbortSignal.timeout(e)});if(W0.ok)return I.info("User free tier status:",W0),W0.result;return}catch(G0){I.error("Failed to fetch free tier status:",G0);return}})(),x=!J.executeMode?new Ar0:null,T,f=null;if(x)T=x,f=(async()=>{let G0=q?await W.serverStatusPromise:W.serverStatus;await D51(Q,Z,G0);let e=process.hrtime.bigint(),W0=B51(O,G0),i=m6(G0)?H51({userEmail:G0.user.email,features:G0.features}):!1;tn4({dtwEnabled:W0,hasV2TUIAccess:i});let o=await k(W0?"dtw":"worker");if(X("runMainThread:createThreadPool",e),x.attach(o),K){let t=await M1(o.threadHandles$);if(!t)throw new I1("No active thread is available yet.",1);await t.sendMessage({content:[{type:"text",text:K}]})}})(),f.catch(async(G0)=>{let e=G0 instanceof Error?G0:Error(String(G0));x.setInitError(e),await Bk(G0,Z.threadId)});else G=process.hrtime.bigint(),tn4({dtwEnabled:L,hasV2TUIAccess:w}),T=await k(L?"dtw":"worker"),X("runMainThread:createThreadPool",G);let p=Z.notifications!==void 0?Z.notifications:!J.executeMode;G=process.hrtime.bigint();let d=await W.configService.getLatest();if(X("runMainThread:configService.getLatest",G),G=process.hrtime.bigint(),Tx3({configService:W.configService,threadService:W.threadService,config:d,useNotificationsForService:p,threadViewStates$:()=>T.threadHandles$.pipe(q4((G0)=>{if(!G0)return k0.of({});return V5(G0.thread$,G0.threadViewState$).pipe(W1(([e,W0])=>({[e.id]:W0})))}))}),X("runMainThread:createCliNotificationService",G),J.executeMode){QM4(W.mcpService,J.settings);let G0={userInput:K,stdinInput:V,dependencies:W,streamJson:z,streamJsonInput:!!Z.streamJsonInput,streamJsonThinking:!!Z.streamJsonThinking,stats:!!Z.stats,ampURL:J.ampURL,isDogfooding:N,agentMode:Z.mode,labels:Z.label},e=await Aw4({threadPool:T,...G0});if(await fo(e,"execute"),Z.archive)await g6.archiveThread({thread:e,archived:!0},{config:W.configService});await W.asyncDispose(),process.exit(0)}let h=!1,n=!1;if(Z.jetbrains||Z.ide){await wu1();let G0=await UE({jetbrainsOnly:Z.jetbrains});if(G0.length===0){if(Z.jetbrains)h=!await W.configService.get("jetbrains.skipInstall")}else if(G0.length===1){let e=G0[0];if(e)N$.selectConfig(e)}else n=!0}G=process.hrtime.bigint();let c=Pl0("0.0.1774123285-gb6e451",W.settingsStorage,{startDelayMs:3000});X("runMainThread:createUpdateService",G),G=process.hrtime.bigint();let s=new Uk0(W.threadStorage);X("runMainThread:createThreadFuzzyIndexer",G),G=process.hrtime.bigint();let F0=new Ki0(W.mcpService,J.settings.getWorkspaceRootPath());if(X("runMainThread:createMcpTrustHandler",G),K&&J.executeMode){let G0=await M1(T.threadHandles$);if(!G0)throw new I1("No active thread is available yet.",1);await G0.sendMessage({content:[{type:"text",text:K}]})}G=process.hrtime.bigint();let a=await lQ0();X("runMainThread:loadSessionState",G),I.info("Loaded session state:",a);let U0={...a,launchCount:a.launchCount+1};Kj((G0)=>({...G0,launchCount:G0.launchCount+1}));let O0=Z.threadId&&f9(Z.threadId)?Z.threadId:void 0;try{if(G=process.hrtime.bigint(),await su4({codebaseContextService:W.codebaseContextService,history:new dc0,fuzzyServer:W.fuzzyServer,settingsStorage:W.settingsStorage,threadService:W.threadService,threadHistoryService:W.threadHistoryService,threadFuzzyIndexer:s,skillService:W.skillService,configService:W.configService,secretStorage:W.secretStorage,internalAPIClient:g6,threadPool:T,createSystemPromptDeps:async()=>qa4(W),ideClient:N$,mcpService:W.mcpService,toolboxService:W.toolboxService,mcpTrustHandler:F0,updateService:c,pluginPlatform:W.pluginPlatform,pluginService:W.pluginService},{initialServerStatus:W.serverStatus,stdout:process.stdout,hasAPIKeyAtStartup:W.hasAPIKeyAtStartup,ampURL:J.ampURL,startupThreadID:O0,showJetBrainsInstaller:h,showIdePickerHint:n,openThreadSwitcher:Z.openThreadSwitcher,inspector:Z.inspector,inspectorPort:Z.inspectorPort,jetbrainsMode:Z.jetbrains,clientId:Z.clientId,sessionState:U0,freeTierStatusPromise:u,workspace:A??null,features:M,isDogfooding:N,initialAgentMode:Q.getOptionValueSourceWithGlobals("mode")==="cli"?Z.mode:void 0,buildTimestamp:"2026-03-21T20:05:11.799Z"},(G0)=>new ge0({...G0,threadPool:G0.threadPool},(e)=>new h41({...e,threadState:e.threadState}))),X("runMainThread:mountApp-returned",G),f)await f}finally{}await W.asyncDispose(),X("runMainThread:dependencies.asyncDispose",Y),process.exit(0)}async function m3(J){if(I.info("Initializing CLI context",{argv:process.argv,nodeEnv:"production",hasAmpURL:Boolean(process.env.AMP_URL),hasAmpAPIKey:Boolean(process.env.AMP_API_KEY),hasSettingsFile:Boolean(process.env.AMP_SETTINGS_FILE)}),J.interactive)E7.write(`Warning: --interactive flag is deprecated. Interactive mode is now the default unless --execute is used or output is redirected.
7676
- `);let Z=!!J.execute||!process.stdout.isTTY&&!J.streamJson,Q=process.stdout.isTTY&&process.stderr.isTTY;I.info("Execution mode resolved",{executeMode:Z,stdoutTTY:process.stdout.isTTY,stderrTTY:process.stderr.isTTY,streamJson:J.streamJson,executeFlag:J.execute});let Y=await Ia1({get:async(z)=>{if(z!==zg)return;try{let G=await Ka4(U51,"utf-8");return JSON.parse(G).installationID}catch{return}},set:async(z,G)=>{if(z!==zg)return;await Xa4(PO.dirname(U51),{recursive:!0}),await Nx3(U51,JSON.stringify({installationID:G},null,2),{mode:384})}},{clientType:"cli",platform:kG()});Tf1(Y);let X=await RO4({...J,workspaceTrust:{current:!0,changes:su},getHook:process.env.AMP_URL?(z,G)=>{if(z==="url")return Promise.resolve(process.env.AMP_URL);return G()}:void 0});if(J.mcpConfig){let z=await JM4(J.mcpConfig);X=ZM4(X,z)}let K=PO.dirname(X.getSettingsFilePath());EW4(Ak,K);let V=await X.get("url","global");if(!V)V=V2;if(I.info("Resolved Amp URL",{ampURL:V,settingsFile:X.getSettingsFilePath(),workspaceRoot:X.getWorkspaceRootPath()}),!OV(V))I.info("Targeting custom Amp server",{ampURL:V});return X=wf1(X),{executeMode:Z,isTTY:Q,ampURL:V,settings:X,secrets:LM4(await Vl0(J,X))}}function mx3(J){let Z={};for(let Q=0;Q<J.length;Q++){let Y=J[Q];if(Y?.startsWith("--")){let K=Y.slice(2).replace(/-([a-z])/g,(z,G)=>G.toUpperCase()),V=J[Q+1];if(V&&!V.startsWith("--"))Z[K]=V,Q++}}return Z}async function px3(){qU4();let J=mx3(process.argv),Z=process.argv.includes("--headless")||process.argv.some((K)=>K.startsWith("--headless="));jN4({logLevel:J.logLevel||process.env.AMP_LOG_LEVEL,logFile:J.logFile||process.env.AMP_LOG_FILE||(Z?Lx3:void 0)});let Q=process.argv.includes("--no-color"),Y=process.argv.includes("--color"),X=process.stdout.isTTY&&process.stderr.isTTY;if(Q||!Y&&!X)c0.level=0;if(Mx3(I),I.info("Starting Amp CLI.",{version:"0.0.1774123285-gb6e451",buildTimestamp:"2026-03-21T20:05:11.799Z"}),parseInt(process.version.slice(1).split(".")[0]??"")<20)throw new I1(L3.nodeVersion(process.version),1,"Please upgrade your Node.js installation from https://nodejs.org");await ux3().parseAsync(process.argv)}OW4().startActiveSpan("main",async(J)=>{process.on("exit",()=>J.end()),await px3().catch(Bk)});async function dx3(J,Z){let Q=J.ampURL.includes("localhost")||J.ampURL.includes("127.0.0.1");if(process.env.AMP_URL&&!Q)await J.settings.set("url",process.env.AMP_URL,"global"),X5.write(`Saving custom server URL to settings: ${process.env.AMP_URL}
7675
+ `),await dF(),process.exit(1);let u=(async()=>{if(q){I.info("Skipping initial free tier status fetch until auth is complete");return}try{let G0=await W.configService.getLatest(),e=Hb(G0),W0=await g6.getUserFreeTierStatus({},{config:W.configService,signal:AbortSignal.timeout(e)});if(W0.ok)return I.info("User free tier status:",W0),W0.result;return}catch(G0){I.error("Failed to fetch free tier status:",G0);return}})(),x=!J.executeMode?new Ar0:null,T,f=null;if(x)T=x,f=(async()=>{let G0=q?await W.serverStatusPromise:W.serverStatus;await D51(Q,Z,G0);let e=process.hrtime.bigint(),W0=B51(O,G0),i=m6(G0)?H51({userEmail:G0.user.email,features:G0.features}):!1;tn4({dtwEnabled:W0,hasV2TUIAccess:i});let o=await k(W0?"dtw":"worker");if(X("runMainThread:createThreadPool",e),x.attach(o),K){let t=await M1(o.threadHandles$);if(!t)throw new I1("No active thread is available yet.",1);await t.sendMessage({content:[{type:"text",text:K}]})}})(),f.catch(async(G0)=>{let e=G0 instanceof Error?G0:Error(String(G0));x.setInitError(e),await Bk(G0,Z.threadId)});else G=process.hrtime.bigint(),tn4({dtwEnabled:L,hasV2TUIAccess:w}),T=await k(L?"dtw":"worker"),X("runMainThread:createThreadPool",G);let p=Z.notifications!==void 0?Z.notifications:!J.executeMode;G=process.hrtime.bigint();let d=await W.configService.getLatest();if(X("runMainThread:configService.getLatest",G),G=process.hrtime.bigint(),Tx3({configService:W.configService,threadService:W.threadService,config:d,useNotificationsForService:p,threadViewStates$:()=>T.threadHandles$.pipe(q4((G0)=>{if(!G0)return k0.of({});return V5(G0.thread$,G0.threadViewState$).pipe(W1(([e,W0])=>({[e.id]:W0})))}))}),X("runMainThread:createCliNotificationService",G),J.executeMode){QM4(W.mcpService,J.settings);let G0={userInput:K,stdinInput:V,dependencies:W,streamJson:z,streamJsonInput:!!Z.streamJsonInput,streamJsonThinking:!!Z.streamJsonThinking,stats:!!Z.stats,ampURL:J.ampURL,isDogfooding:N,agentMode:Z.mode,labels:Z.label},e=await Aw4({threadPool:T,...G0});if(await fo(e,"execute"),Z.archive)await g6.archiveThread({thread:e,archived:!0},{config:W.configService});await W.asyncDispose(),process.exit(0)}let h=!1,n=!1;if(Z.jetbrains||Z.ide){await wu1();let G0=await UE({jetbrainsOnly:Z.jetbrains});if(G0.length===0){if(Z.jetbrains)h=!await W.configService.get("jetbrains.skipInstall")}else if(G0.length===1){let e=G0[0];if(e)N$.selectConfig(e)}else n=!0}G=process.hrtime.bigint();let c=Pl0("0.0.1774126892-geb7ca3",W.settingsStorage,{startDelayMs:3000});X("runMainThread:createUpdateService",G),G=process.hrtime.bigint();let s=new Uk0(W.threadStorage);X("runMainThread:createThreadFuzzyIndexer",G),G=process.hrtime.bigint();let F0=new Ki0(W.mcpService,J.settings.getWorkspaceRootPath());if(X("runMainThread:createMcpTrustHandler",G),K&&J.executeMode){let G0=await M1(T.threadHandles$);if(!G0)throw new I1("No active thread is available yet.",1);await G0.sendMessage({content:[{type:"text",text:K}]})}G=process.hrtime.bigint();let a=await lQ0();X("runMainThread:loadSessionState",G),I.info("Loaded session state:",a);let U0={...a,launchCount:a.launchCount+1};Kj((G0)=>({...G0,launchCount:G0.launchCount+1}));let O0=Z.threadId&&f9(Z.threadId)?Z.threadId:void 0;try{if(G=process.hrtime.bigint(),await su4({codebaseContextService:W.codebaseContextService,history:new dc0,fuzzyServer:W.fuzzyServer,settingsStorage:W.settingsStorage,threadService:W.threadService,threadHistoryService:W.threadHistoryService,threadFuzzyIndexer:s,skillService:W.skillService,configService:W.configService,secretStorage:W.secretStorage,internalAPIClient:g6,threadPool:T,createSystemPromptDeps:async()=>qa4(W),ideClient:N$,mcpService:W.mcpService,toolboxService:W.toolboxService,mcpTrustHandler:F0,updateService:c,pluginPlatform:W.pluginPlatform,pluginService:W.pluginService},{initialServerStatus:W.serverStatus,stdout:process.stdout,hasAPIKeyAtStartup:W.hasAPIKeyAtStartup,ampURL:J.ampURL,startupThreadID:O0,showJetBrainsInstaller:h,showIdePickerHint:n,openThreadSwitcher:Z.openThreadSwitcher,inspector:Z.inspector,inspectorPort:Z.inspectorPort,jetbrainsMode:Z.jetbrains,clientId:Z.clientId,sessionState:U0,freeTierStatusPromise:u,workspace:A??null,features:M,isDogfooding:N,initialAgentMode:Q.getOptionValueSourceWithGlobals("mode")==="cli"?Z.mode:void 0,buildTimestamp:"2026-03-21T21:05:12.391Z"},(G0)=>new ge0({...G0,threadPool:G0.threadPool},(e)=>new h41({...e,threadState:e.threadState}))),X("runMainThread:mountApp-returned",G),f)await f}finally{}await W.asyncDispose(),X("runMainThread:dependencies.asyncDispose",Y),process.exit(0)}async function m3(J){if(I.info("Initializing CLI context",{argv:process.argv,nodeEnv:"production",hasAmpURL:Boolean(process.env.AMP_URL),hasAmpAPIKey:Boolean(process.env.AMP_API_KEY),hasSettingsFile:Boolean(process.env.AMP_SETTINGS_FILE)}),J.interactive)E7.write(`Warning: --interactive flag is deprecated. Interactive mode is now the default unless --execute is used or output is redirected.
7676
+ `);let Z=!!J.execute||!process.stdout.isTTY&&!J.streamJson,Q=process.stdout.isTTY&&process.stderr.isTTY;I.info("Execution mode resolved",{executeMode:Z,stdoutTTY:process.stdout.isTTY,stderrTTY:process.stderr.isTTY,streamJson:J.streamJson,executeFlag:J.execute});let Y=await Ia1({get:async(z)=>{if(z!==zg)return;try{let G=await Ka4(U51,"utf-8");return JSON.parse(G).installationID}catch{return}},set:async(z,G)=>{if(z!==zg)return;await Xa4(PO.dirname(U51),{recursive:!0}),await Nx3(U51,JSON.stringify({installationID:G},null,2),{mode:384})}},{clientType:"cli",platform:kG()});Tf1(Y);let X=await RO4({...J,workspaceTrust:{current:!0,changes:su},getHook:process.env.AMP_URL?(z,G)=>{if(z==="url")return Promise.resolve(process.env.AMP_URL);return G()}:void 0});if(J.mcpConfig){let z=await JM4(J.mcpConfig);X=ZM4(X,z)}let K=PO.dirname(X.getSettingsFilePath());EW4(Ak,K);let V=await X.get("url","global");if(!V)V=V2;if(I.info("Resolved Amp URL",{ampURL:V,settingsFile:X.getSettingsFilePath(),workspaceRoot:X.getWorkspaceRootPath()}),!OV(V))I.info("Targeting custom Amp server",{ampURL:V});return X=wf1(X),{executeMode:Z,isTTY:Q,ampURL:V,settings:X,secrets:LM4(await Vl0(J,X))}}function mx3(J){let Z={};for(let Q=0;Q<J.length;Q++){let Y=J[Q];if(Y?.startsWith("--")){let K=Y.slice(2).replace(/-([a-z])/g,(z,G)=>G.toUpperCase()),V=J[Q+1];if(V&&!V.startsWith("--"))Z[K]=V,Q++}}return Z}async function px3(){qU4();let J=mx3(process.argv),Z=process.argv.includes("--headless")||process.argv.some((K)=>K.startsWith("--headless="));jN4({logLevel:J.logLevel||process.env.AMP_LOG_LEVEL,logFile:J.logFile||process.env.AMP_LOG_FILE||(Z?Lx3:void 0)});let Q=process.argv.includes("--no-color"),Y=process.argv.includes("--color"),X=process.stdout.isTTY&&process.stderr.isTTY;if(Q||!Y&&!X)c0.level=0;if(Mx3(I),I.info("Starting Amp CLI.",{version:"0.0.1774126892-geb7ca3",buildTimestamp:"2026-03-21T21:05:12.391Z"}),parseInt(process.version.slice(1).split(".")[0]??"")<20)throw new I1(L3.nodeVersion(process.version),1,"Please upgrade your Node.js installation from https://nodejs.org");await ux3().parseAsync(process.argv)}OW4().startActiveSpan("main",async(J)=>{process.on("exit",()=>J.end()),await px3().catch(Bk)});async function dx3(J,Z){let Q=J.ampURL.includes("localhost")||J.ampURL.includes("127.0.0.1");if(process.env.AMP_URL&&!Q)await J.settings.set("url",process.env.AMP_URL,"global"),X5.write(`Saving custom server URL to settings: ${process.env.AMP_URL}
7677
7677
  `);else if(!OV(J.ampURL))X5.write(`Logging in to ${new URL(J.ampURL).hostname}
7678
7678
  `);let Y=process.env.AMP_API_KEY;if(Y)X5.write(`API key found in environment variable, storing...
7679
7679
  `),await Z.set("apiKey",Y,J.ampURL),X5.write(`API key successfully stored.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourcegraph/amp",
3
- "version": "0.0.1774123285-gb6e451",
3
+ "version": "0.0.1774126892-geb7ca3",
4
4
  "description": "CLI for Amp, the frontier coding agent.",
5
5
  "homepage": "https://ampcode.com/",
6
6
  "author": {