@withgraphite/graphite-cli 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.CHANGELOG.md +6 -0
- package/230.js +3 -0
- package/230.js.map +1 -0
- package/build/asset-manifest.json +3 -3
- package/build/index.html +1 -1
- package/build/static/css/{main.1113989d.css → main.44130e6a.css} +2 -2
- package/build/static/css/main.44130e6a.css.map +1 -0
- package/build/static/js/main.js +1 -1
- package/build/static/js/main.js.map +1 -1
- package/child.js +1 -1
- package/child.js.map +1 -1
- package/graphite.js +1 -1
- package/package.json +1 -1
- package/60.js +0 -3
- package/60.js.map +0 -1
- package/build/static/css/main.1113989d.css.map +0 -1
package/.CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Graphite CLI Changelog
|
|
2
2
|
|
|
3
|
+
# 1.2.1 2024-02-11
|
|
4
|
+
|
|
5
|
+
- Fixed an issue where the `gt ab` alias for absorb wasn't recognized.
|
|
6
|
+
- Fixed an issue where `gt absorb --patch` hung instead of opening the patch selector.
|
|
7
|
+
- Fixed an issue where invalid Graphite metadata would prevent any command from being run.
|
|
8
|
+
|
|
3
9
|
# 1.2.0 2024-02-09
|
|
4
10
|
|
|
5
11
|
- Introduced `gt absorb`, which automatically amends staged changes to commits in your stack.
|
package/230.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";exports.id=230,exports.ids=[230],exports.modules={33800:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.labelForComparison=t.ComparisonType=void 0,function(e){e.UncommittedChanges="UNCOMMITTED",e.HeadChanges="HEAD",e.StackChanges="STACK",e.Committed="InCommit",e.Commit="Commit",e.Range="Range"}(n=t.ComparisonType||(t.ComparisonType={})),t.labelForComparison=function(e){switch(e.type){case n.UncommittedChanges:return"Uncommitted changes";case n.HeadChanges:return"Changes in current commit";case n.StackChanges:return"Changes in current branch";case n.Committed:return`Changes in ${e.hash}`;case n.Commit:return`In ${e.sha}`;case n.Range:return`From ${e.fromSha} to ${e.toSha}`}}},2982:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.cached=t.LRU=void 0;const s=n(30826);class r{constructor(e,t=3){this.maxItems=e,this.maxHashCollision=t,this.cache=new Map}get(e){let t;const n=i(e),r=this.cache.get(n);if(void 0!==r){const i=r.get(e);if(void 0!==i)t=i;else for(const[n,i]of r)if((0,s.is)(e,n)){t=i;break}this.cache.delete(n),this.cache.set(n,r)}return t}set(e,t){const n=i(e);let s=this.cache.get(n);if(void 0===s||s.size>=this.maxHashCollision?s=new Map([[e,t]]):s.set(e,t),this.cache.delete(n),void 0!==t&&(this.cache.set(n,s),this.cache.size>this.maxItems)){const e=this.cache.keys().next();e.done||this.cache.delete(e.value)}}delete(e){const t=i(e);this.cache.delete(t)}clear(){this.cache.clear()}}function i(e){const t=null==e?void 0:e.hashCode;return void 0!==t?t.apply(e):e}function o(e,t){var n,i;const o=null!==(n=null==t?void 0:t.cache)&&void 0!==n?n:new r(null!==(i=null==t?void 0:t.cacheSize)&&void 0!==i?i:10),a=null==t?void 0:t.getExtraKeys,l=function(...t){var n,r,i;const l=o.stats;if(!t.every(c))return null!=l&&(l.skip=(null!==(n=l.skip)&&void 0!==n?n:0)+1),e.apply(this,t);const h=(0,s.List)(a?[...a.apply(this),...t]:t),u=o.get(h);if(void 0!==u)return null!=l&&(l.hit=(null!==(r=l.hit)&&void 0!==r?r:0)+1),u;null!=l&&(l.miss=(null!==(i=l.miss)&&void 0!==i?i:0)+1);const d=e.apply(this,t);return o.set(h,d),d};return l.cache=o,l}t.LRU=r,t.cached=function(e,t){return"function"==typeof e?o(e,t):function(e){var t;const n=null!==(t=null==e?void 0:e.getExtraKeys)&&void 0!==t?t:function(){return(0,s.isValueObject)(this)?[this]:null!=this&&"object"==typeof this?Object.values(this).filter(c):[]};return function(t,s,r){const i=r.value;r.value=o(i,Object.assign(Object.assign({},e),{getExtraKeys:n}))}}(e)};const a=new Set(["number","string","boolean","symbol","bigint","undefined","null"]);function c(e){if(null==e)return!0;const t=typeof e;return!!a.has(t)||!("object"!==t||!(0,s.isValueObject)(e))}},61110:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},5693:function(e,t,n){var s=this&&this.__createBinding||(Object.create?function(e,t,n,s){void 0===s&&(s=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,r)}:function(e,t,n,s){void 0===s&&(s=n),e[s]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||s(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(61110),t),r(n(52568),t),r(n(11268),t),r(n(66877),t)},52568:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},11268:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Tracker=void 0;const s=n(48427);class r{constructor(e,t){this.sendData=e,this.context=t}error(e,t,n,s){const r=n instanceof Error?n.message||String(n):n;return this.track(e,Object.assign(Object.assign({},null!=s?s:{}),{errorMessage:r,errorName:t}))}operation(e,t,n,r){var i;const o=Date.now(),a=null!==(i=null==n?void 0:n.id)&&void 0!==i?i:(0,s.randomId)();try{const i=r({parentId:a});if((0,s.isPromise)(i))return i.then((t=>{const s=Date.now()-o;return this.track(e,Object.assign(Object.assign({},null!=n?n:{}),{duration:s,id:a})),t})).catch((s=>{const r=Date.now()-o;return this.error(e,t,s,Object.assign(Object.assign({},null!=n?n:{}),{duration:r,id:a})),Promise.reject(s)}));{const t=Date.now()-o;return this.track(e,Object.assign(Object.assign({},null!=n?n:{}),{duration:t,id:a})),i}}catch(s){const r=Date.now()-o;throw this.error(e,t,s,Object.assign(Object.assign({},null!=n?n:{}),{duration:r,id:a})),s}}trackAsParent(e,t){var n;const i=null!==(n=null==t?void 0:t.id)&&void 0!==n?n:(0,s.randomId)();return this.trackData(Object.assign(Object.assign({},t),{eventName:e,id:i})),new r(((e,t)=>this.trackData(Object.assign(Object.assign({},e),t))),{parentId:i})}track(e,t){return this.trackData(Object.assign(Object.assign({},t),{eventName:e}))}trackData(e){var t,n;const r=null!==(t=null==e?void 0:e.id)&&void 0!==t?t:(0,s.randomId)(),i=null!==(n=null==e?void 0:e.timestamp)&&void 0!==n?n:Date.now(),o=Object.assign({timestamp:i,id:r},null!=e?e:{});this.sendData(o,this.context)}}t.Tracker=r},66877:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},66960:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.debounce=void 0,t.debounce=function(e,t,n=void 0,s=!1){let r,i=!0;function o(...a){let c;if(s){if(c=function(){i=!0,r=void 0},!i)return clearTimeout(r),void(r=setTimeout(c,t));i=!1,e.apply(n,a)}else o.reset(),c=function(){r=void 0,e.apply(n,a)};r=setTimeout(c,t)}return o.reset=function(){clearTimeout(r),r=void 0,i=!0},o.isPending=function(){return null!=r},o}},98696:function(e,t,n){var s=this&&this.__createBinding||(Object.create?function(e,t,n,s){void 0===s&&(s=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,r)}:function(e,t,n,s){void 0===s&&(s=n),e[s]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||s(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(5693),t),r(n(33800),t),r(n(66960),t),r(n(2982),t),r(n(75905),t),r(n(85249),t),r(n(40256),t),r(n(86099),t),r(n(66224),t),r(n(48427),t)},75905:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.parsePatch=t.DiffType=void 0,function(e){e.Modified="Modified",e.Added="Added",e.Removed="Removed",e.Renamed="Renamed",e.Copied="Copied"}(n=t.DiffType||(t.DiffType={}));const s=/^diff --git (.*) (.*)$/,r=/^rename from (.*)$/,i=/^rename to (.*)$/,o=/^copy from (.*)$/,a=/^copy to (.*)$/,c=/^new file mode (\d{6})$/,l=/^deleted file mode (\d{6})$/,h=/^old mode (\d{6})$/,u=/^new mode (\d{6})$/,d=/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/,m=/^--- (.*)$/,p=/^\+\+\+ (.*)$/,g=/\r\n|[\n\v\f\r\x85]/g;function f(e,t){if(!1===e)throw new Error(t)}t.parsePatch=function(e){const t=e.split(g),v=e.match(g)||[],y=[];let C=0;function b(){const e={hunks:[]};for(y.push(e),function(e){for(;C<t.length;){const n=t[C],r=s.exec(n);if(r){e.oldFileName=r[1],e.newFileName=r[2],C++;break}C++}}(e);C<t.length;){const n=t[C];if(/^old mode/.test(n))w(e);else if(/^new mode/.test(n))S(e);else if(/^deleted file mode/.test(n))O(e);else if(/^new file mode/.test(n))R(e);else if(/^copy /.test(n))E(e);else if(/^rename /.test(n))k(e);else{if(/^--- /.test(n)){M(e);break}if(/^diff --git/.test(n))break;C++}}!function(e){for(;C<t.length;){const n=t[C];if(s.test(n))break;/^@@/.test(n)?e.hunks.push(_()):C++}}(e)}function w(e){const s=h.exec(t[C]);f(null!==s,`invalid format '${t[C]}'`),e.oldMode=s[1],e.type=n.Modified,C++}function S(e){const s=u.exec(t[C]);f(null!==s,`invalid format '${t[C]}'`),e.newMode=s[1],e.type=n.Modified,C++}function O(e){const s=l.exec(t[C]);f(null!==s,`invalid format '${t[C]}'`),e.newMode=s[1],e.type=n.Removed,C++}function R(e){const s=c.exec(t[C]);f(null!==s,`invalid format '${t[C]}'`),e.newMode=s[1],e.type=n.Added,C++}function E(e){f(o.test(t[C]),`invalid format '${t[C]}'`),f(a.test(t[C+1]),`invalid format '${t[C+1]}'`),e.type=n.Copied,C+=2}function k(e){f(r.test(t[C]),`invalid format '${t[C]}'`),f(i.test(t[C+1]),`invalid format '${t[C+1]}'`),e.type=n.Renamed,C+=2}function M(e){f(m.test(t[C]),`invalid format '${t[C]}'`),f(p.test(t[C+1]),`invalid format '${t[C+1]}'`),void 0===e.type&&(e.type=n.Modified),C+=2}function _(){const e=t[C++].split(d),n={oldStart:+e[1],oldLines:void 0===e[2]?1:+e[2],newStart:+e[3],newLines:void 0===e[4]?1:+e[4],lines:[],linedelimiters:[]};0===n.oldLines&&(n.oldStart+=1),0===n.newLines&&(n.newStart+=1);let s=0,r=0;for(;C<t.length&&!(0===t[C].indexOf("--- ")&&C+2<t.length&&0===t[C+1].indexOf("+++ ")&&0===t[C+2].indexOf("@@"));C++){const e=0==t[C].length&&C!=t.length-1?" ":t[C][0];if("+"!==e&&"-"!==e&&" "!==e&&"\\"!==e)break;n.lines.push(t[C]),n.linedelimiters.push(v[C]||"\n"),"+"===e?s++:"-"===e?r++:" "===e&&(s++,r++)}return s||1!==n.newLines||(n.newLines=0),r||1!==n.oldLines||(n.oldLines=0),n}for(;C<t.length;)b();return y}},85249:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.deserializeFromString=t.deserialize=t.serializeToString=t.serialize=void 0;const n={__rpcType:"undefined"};function s(e){if(void 0===e)return n;if("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e)return e;if(e instanceof Map)return{__rpcType:"Map",data:Array.from(e.entries()).map((([e,t])=>[s(e),s(t)]))};if(e instanceof Set)return{__rpcType:"Set",data:Array.from(e.values()).map(s)};if(e instanceof Error)return{__rpcType:"Error",data:{message:e.message,stack:e.stack}};if(e instanceof Date)return{__rpcType:"Date",data:e.valueOf()};if(Array.isArray(e))return e.map((e=>s(e)));if("object"==typeof e){const t={__rpcType:"object"};for(const[n,r]of Object.entries(e))t[n]=s(r);return t}throw new Error(`cannot serialize argument ${e}`)}function r(e){if("object"!=typeof e||null==e)return e;if(Array.isArray(e))return e.map((e=>r(e)));const t=e;switch(t.__rpcType){case"undefined":return;case"Map":return new Map(t.data.map((([e,t])=>[r(e),r(t)])));case"Set":return new Set(t.data.map(r));case"Error":{const e=new Error;return e.stack=t.data.stack,e.message=t.data.message,e}case"Date":return new Date(t.data);case"object":{const t=e,n={};for(const[e,s]of Object.entries(t))"__rpcType"!==e&&(n[e]=r(s));return n}default:throw new Error(`cannot deserialize unknown type ${t}`)}}t.serialize=s,t.serializeToString=function(e){return JSON.stringify(s(e))},t.deserialize=r,t.deserializeFromString=function(e){return r(JSON.parse(e))}},40256:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},66224:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},50209:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SucceedableRevset=t.CommandRunner=void 0,(n=t.CommandRunner||(t.CommandRunner={})).Graphite="gt",n.CodeReviewProvider="codeReviewProvider",t.SucceedableRevset=function(e){return{type:"succeedable-revset",revset:e}}},74259:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},45852:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},1018:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorShortMessages=t.DEFAULT_DAYS_OF_COMMITS_TO_LOAD=t.ONE_MINUTE_MS=t.CLOSED_AND_SHOULD_NOT_RECONNECT_CODE=void 0,t.CLOSED_AND_SHOULD_NOT_RECONNECT_CODE=4100,t.ONE_MINUTE_MS=6e4,t.DEFAULT_DAYS_OF_COMMITS_TO_LOAD=void 0,(t.ErrorShortMessages||(t.ErrorShortMessages={})).NoCommitsFetched="No commits found"},29641:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},86099:function(e,t,n){var s=this&&this.__createBinding||(Object.create?function(e,t,n,s){void 0===s&&(s=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,r)}:function(e,t,n,s){void 0===s&&(s=n),e[s]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||s(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),r(n(50209),t),r(n(74259),t),r(n(45852),t),r(n(1018),t),r(n(29641),t),r(n(85119),t)},85119:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},48427:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isPromise=t.truncate=t.zip=t.generatorContains=t.mapObject=t.findParentWithClassName=t.basename=t.defer=t.randomId=t.unwrap=t.notEmpty=void 0,t.notEmpty=function(e){return null!=e},t.unwrap=function(e){if(null==e)throw new Error(`expected value not to be ${e}`);return e},t.randomId=function(){return Date.now().toString(36)+Math.random().toString(36)},t.defer=function(){const e={promise:void 0,resolve:void 0,reject:void 0};return e.promise=new Promise(((t,n)=>{e.resolve=t,e.reject=n})),e},t.basename=function(e,t="/"){const n=e.lastIndexOf(t);return-1===n?e:e.slice(n+1)},t.findParentWithClassName=function(e,t){var n;let s=e;for(;s;){if(null===(n=s.classList)||void 0===n?void 0:n.contains(t))return s;s=s.parentElement}},t.mapObject=function(e,t){return Object.fromEntries(Object.entries(e).map(t))},t.generatorContains=function(e,t){const n="function"==typeof t?t:e=>e===t;for(const t of e)if(n(t))return!0;return!1},t.zip=function*(e,t){const n=e[Symbol.iterator](),s=t[Symbol.iterator]();for(;;){const e=n.next(),t=s.next();if(e.done||t.done)break;yield[e.value,t.value]}},t.truncate=function(e,t=100){return e.length>t?e.substring(0,Math.max(0,t-1))+"…":e},t.isPromise=function(e){return"function"==typeof(null==e?void 0:e.then)}},35230:(e,t,n)=>{n.r(t),n.d(t,{startServer:()=>te});var s=n(98696),r=n(57147),i=n.n(r),o=n(13685),a=n.n(o),c=n(71017),l=n.n(c),h=n(57310),u=n.n(h),d=n(95352),m=n.n(d),p=n(22037),g=n.n(p);function f(){try{return g().userInfo().username}catch(e){try{const{env:e}=process;return(0,s.unwrap)(e.LOGNAME||e.USER||e.LNAME||e.USERNAME)}catch(t){throw new Error(String(t)+String(e))}}}class v{logger;data;constructor(e,t){this.logger=e,this.data=t}setRepo(e){this.data.repo=e?.codeReviewProvider?.getSummaryName()}}const y=e=>{};var C=n(73837),b=n.n(C);const w=console;var S=n(34987),O=n.n(S),R=n(59778),E=n.n(R),k=n(82361);class M extends k.EventEmitter{}class _{codeReviewSystem;runCommand;constructor(e,t){this.codeReviewSystem=e,this.runCommand=t}diffSummaries=new M;onChangeDiffSummaries(e){const t=t=>e({value:t}),n=t=>e({error:t});return this.diffSummaries.on("data",t),this.diffSummaries.on("error",n),{dispose:()=>{this.diffSummaries.off("data",t),this.diffSummaries.off("error",n)}}}async triggerDiffSummariesFetch(e){const t=await this.runCommand(["internal-only","prs"]),n=JSON.parse(t.stdout);this.diffSummaries.emit("data",n)}dispose(){this.diffSummaries.removeAllListeners()}getSummaryName(){return`github:${this.codeReviewSystem.hostname}/${this.codeReviewSystem.owner}/${this.codeReviewSystem.repo}`}runExternalCommand(e,t,n,s){throw new Error("GitHub code review provider does not support running external commands")}async typeahead(e,t){return Promise.resolve([])}}class D{logger;runCallback;constructor(e,t){this.logger=e,this.runCallback=t}queuedOperations=[];runningOperation=void 0;abortController=void 0;async runOrQueueOperation(e,t,n,s){if(null!=this.runningOperation)return this.queuedOperations.push({...e,tracker:n}),void t({id:e.id,kind:"queue",queue:this.queuedOperations.map((e=>e.id))});this.runningOperation=e;const r=(...n)=>{switch(n[0]){case"spawn":t({id:e.id,kind:"spawn",queue:this.queuedOperations.map((e=>e.id))});break;case"stdout":t({id:e.id,kind:"stdout",message:n[1]});break;case"stderr":t({id:e.id,kind:"stderr",message:n[1]});break;case"exit":t({id:e.id,kind:"exit",exitCode:n[1],timestamp:Date.now()})}};try{const i=new AbortController;if(this.abortController=i,await n.operation(e.trackEventName,"RunOperationError",{extras:{args:e.args,runner:e.runner}},(t=>this.runCallback(e,s,r,i.signal))),this.runningOperation=void 0,this.queuedOperations.length>0){const e=this.queuedOperations.shift();null!=e&&this.runOrQueueOperation(e,t,e.tracker,s)}}catch(n){const s=n.toString();this.logger.log("error running operation: ",e.args[0],s),t({id:e.id,kind:"error",error:s}),this.queuedOperations=[],this.runningOperation=void 0}}abortRunningOperation(e){this.runningOperation?.id==e&&this.abortController?.abort()}}class T{focusedPages=new Set;visiblePages=new Set;onChangeHandlers=new Set;setState(e,t){switch(t){case"focused":this.focusedPages.add(e),this.visiblePages.add(e);break;case"visible":this.focusedPages.delete(e),this.visiblePages.add(e);break;case"hidden":this.focusedPages.delete(e),this.visiblePages.delete(e)}for(const e of this.onChangeHandlers)e(t)}disposePage(e){this.focusedPages.delete(e),this.visiblePages.delete(e)}hasPageWithFocus(){return this.focusedPages.size>0}hasVisiblePage(){return this.visiblePages.size>0}onChange(e){return this.onChangeHandlers.add(e),()=>this.onChangeHandlers.delete(e)}}class P{maxSimultaneousRunning;log;queued=[];running=[];runs=new M;constructor(e,t){this.maxSimultaneousRunning=e,this.log=t}nextId=1;generateId(){return this.nextId++}async enqueueRun(e){const t=this.generateId();this.queued.push(t),this.tryDequeueNext(),this.running.includes(t)||(this.log?.(`${this.running.length} tasks are already running, enqueuing ID:${t}`),await new Promise((e=>{this.runs.on("run",(n=>{n===t&&(this.log?.(`now allowing ID:${t} to run`),e(void 0))}))})));try{return await e()}finally{this.notifyFinished(t)}}notifyFinished(e){this.running=this.running.filter((t=>t!==e)),this.tryDequeueNext()}tryDequeueNext(){if(this.running.length<this.maxSimultaneousRunning){const e=this.queued.shift();null!=e&&this.run(e)}}run(e){this.running.push(e),this.runs.emit("run",e)}}function N(e){let t,n;const s=()=>{const t=e();return n=t.then((()=>n=void 0),(()=>n=void 0)),t},r=()=>(t=void 0,s());return()=>null==n?s():(()=>{if(null==t){if(null==n)throw new Error("pendingCall must not be null!");t=n.then(r,r)}return t})()}function I(e){switch(e.type){case s.ComparisonType.UncommittedChanges:return["uncommitted"];case s.ComparisonType.HeadChanges:return["head"];case s.ComparisonType.StackChanges:return["stack"];case s.ComparisonType.Committed:return["stack","--ref",e.hash];default:throw new Error("Unsupported comparison type: "+e.type)}}const j="1.0.14";class F{info;platform;logger;IGNORE_COMMIT_MESSAGE_LINES_REGEX=/^((?:HG|SL):.*)/gm;mergeConflicts=void 0;uncommittedChanges=null;smartlogCommits=null;mergeConflictsEmitter=new M;uncommittedChangesEmitter=new M;smartlogCommitsChangesEmitter=new M;smartlogCommitsBeginFetchingEmitter=new M;uncommittedChangesBeginFetchingEmitter=new M;disposables=[()=>this.mergeConflictsEmitter.removeAllListeners(),()=>this.uncommittedChangesEmitter.removeAllListeners(),()=>this.smartlogCommitsChangesEmitter.removeAllListeners(),()=>this.smartlogCommitsBeginFetchingEmitter.removeAllListeners(),()=>this.uncommittedChangesBeginFetchingEmitter.removeAllListeners()];onDidDispose(e){this.disposables.push(e)}operationQueue;watchForChangesDisposer;pageFocusTracker=new T;codeReviewProvider;currentVisibleCommitRangeIndex=0;visibleCommitRanges=[s.DEFAULT_DAYS_OF_COMMITS_TO_LOAD,60,void 0];constructor(e,t,n){this.info=e,this.platform=t,this.logger=n;const r=e.codeReviewSystem;"github"===r.type&&(this.codeReviewProvider=new _(r,this.runCommand.bind(this))),this.watchForChangesDisposer=t.watchForChanges(e,n,(e=>{"uncommitted changes"===e?(this.fetchUncommittedChanges(),this.checkForMergeConflicts()):"branches"===e?this.fetchSmartlogCommits():"merge conflicts"===e?this.checkForMergeConflicts():"everything"===e&&(this.fetchUncommittedChanges(),this.fetchSmartlogCommits(),this.checkForMergeConflicts())})),this.operationQueue=new D(this.logger,((e,t,n,r)=>{if(e.runner===s.CommandRunner.Graphite)return this.runOperation(e,n,t,r);if(e.runner===s.CommandRunner.CodeReviewProvider){const s=this.normalizeOperationArgs(t,e.args);return null==this.codeReviewProvider?.runExternalCommand?Promise.reject(Error("CodeReviewProvider does not support running external commands")):this.codeReviewProvider?.runExternalCommand(t,s,n,r)??Promise.resolve()}return Promise.resolve()}));const i=new Set,o=this.subscribeToSmartlogCommitsChanges((e=>{if(e.commits.value){const t=[],n=e.commits.value.filter((e=>e.pr)).map((e=>e.pr?.number));for(const e of n)i.has(e)||(t.push(e),i.add(e));t.length>0&&this.codeReviewProvider?.triggerDiffSummariesFetch(this.getAllDiffIds())}}));this.checkForMergeConflicts(),this.disposables.push((()=>o.dispose()))}nextVisibleCommitRangeInDays(){return this.currentVisibleCommitRangeIndex+1<this.visibleCommitRanges.length&&this.currentVisibleCommitRangeIndex++,this.visibleCommitRanges[this.currentVisibleCommitRangeIndex]}dispose(){this.disposables.forEach((e=>e())),this.codeReviewProvider?.dispose(),this.watchForChangesDisposer?.()}onChangeConflictState(e){return this.mergeConflictsEmitter.on("change",e),this.mergeConflicts&&e(this.mergeConflicts),{dispose:()=>this.mergeConflictsEmitter.off("change",e)}}checkForMergeConflicts=(0,s.debounce)(N((async()=>{this.logger.info("checking for merge conflicts");const e=null!=this.mergeConflicts;if(!e&&!await(t=l().join(this.info.dotdir,"rebase-merge"),i().promises.stat(t).then((()=>!0)).catch((e=>{if("ENOENT"===e.code)return!1;throw e}))))return void this.logger.info(`conflict state still the same (${e?"IN merge conflict":"NOT in conflict"})`);var t;null==this.mergeConflicts&&(this.mergeConflicts={state:"loading"},this.mergeConflictsEmitter.emit("change",this.mergeConflicts));const n=Date.now();let s;try{const e=await this.runCommand(["internal-only","status"]);s=JSON.parse(e.stdout)}catch(e){return this.logger.error(`failed to check for merge conflicts: ${e}`),this.mergeConflicts=void 0,void this.mergeConflictsEmitter.emit("change",this.mergeConflicts)}const r=await i().promises.readFile(l().join(this.info.dotdir,"rebase-merge","head-name")).then((e=>{const t=e.toString();return t.startsWith("refs/heads/")?t.slice(11).trimEnd():void 0}),(()=>{}));if(this.mergeConflicts=function(e,t,n,s){const r=n;if(!r?.conflicts||!t)return;const i=r.files.filter((e=>"UNRESOLVED"===e.status)),o={state:"loaded",branchName:t,files:[],fetchStartTimestamp:s,fetchCompletedTimestamp:Date.now()};if(null!=e?.files&&e.files.length>0){const t=new Set(i.map((e=>e.path)));o.files=e.files.map((e=>t.has(e.path)?{path:e.path,status:"UNRESOLVED"}:{path:e.path,status:"RESOLVED"}))}else o.files=i.map((e=>({path:e.path,status:"UNRESOLVED"})));return o}(this.mergeConflicts,r,s,n),this.logger.info(`repo ${this.mergeConflicts?"IS":"IS NOT"} in merge conflicts`,{mergeConflicts:this.mergeConflicts,files:this.mergeConflicts?.files}),this.mergeConflicts){const e=20,t=(this.mergeConflicts.files??[]).filter((e=>"UNRESOLVED"===e.status)).map((e=>e.path)).slice(0,e);this.logger.info("remaining files with conflicts: ",{branchName:r,remainingConflicts:t})}this.mergeConflictsEmitter.emit("change",this.mergeConflicts)})),100);getMergeConflicts(){return this.mergeConflicts}static async getRepoInfo(e,t,n){const s=await async function(e,t,n){try{return(await x({command:e,args:["--version"],logger:t,cwd:n})).stdout}catch(e){throw t.error(`Failed to find gt version in ${n}`,e),e}}(e,t,n).catch((e=>e));if(s instanceof Error)return{type:"invalidCommand",command:e??"gt"};if("local"!==s&&"dev"!==s&&E().lt(s,j))return{type:"invalidVersion",command:e??"gt",versionFound:s,versionRequired:j};const[r,i,o,a]=await Promise.all([L(e,t,n),A(e,t,n),$(e,t,n,"graphite.branch_edit").then((e=>e??"amend")),$(e,t,n,"graphite.create_prs_as").then((e=>e??"draft"))]);if(null==i)return{type:"cwdNotARepository",cwd:n};let c;if(void 0===i.remote)c={type:"none"};else{const{owner:e,name:t,hostname:n}=i.remote;c={type:"github",owner:e,repo:t,hostname:n}}const l={type:"success",command:e,dotdir:i.dotDir,repoRoot:i.rootDir,codeReviewSystem:c,preferredBranchEdit:o,createPrsAs:a,profile:r,trunkBranch:i.trunkBranch};return t.info("repo info: ",l),l}async runOrQueueOperation(e,t,n,s){await this.operationQueue.runOrQueueOperation(e,t,n,s)}abortRunningOpeation(e){this.operationQueue.abortRunningOperation(e)}normalizeOperationArgs(e,t){const n=(0,s.unwrap)(this.info.repoRoot);return t.map((t=>{if("object"==typeof t)switch(t.type){case"repo-relative-file":return l().normalize(l().relative(e,l().join(n,t.path)));case"succeedable-revset":return`max(successors(${t.revset}))`}return t}))}async runOperation(e,t,n,s){const r=this.normalizeOperationArgs(n,e.args),{stdin:i}=e,{command:o,args:a,options:c}=U(this.info.command,r,n,i?{input:i}:void 0);this.logger.log("run operation: ",o,r.join(" "));const l=O()(o,a,{...c,stdout:"pipe",stderr:"pipe"});t("spawn"),l.stdout?.on("data",(e=>{t("stdout",e.toString())})),l.stderr?.on("data",(e=>{t("stderr",e.toString())})),l.on("exit",(e=>{t("exit",e||0)})),s.addEventListener("abort",(()=>{this.logger.log("kill operation: ",o,r.join(" "))})),function(e,t){t.addEventListener("abort",(()=>{"win32"==g().platform()?e.kill("SIGKILL",{forceKillAfterTimeout:!1}):(e.kill("SIGCONT"),e.kill("SIGTERM",{forceKillAfterTimeout:5e3}))}))}(l,s),await l}setPageFocus(e,t){this.pageFocusTracker.setState(e,t)}getUncommittedChanges(){return this.uncommittedChanges}subscribeToUncommittedChanges(e){return this.uncommittedChangesEmitter.on("change",e),{dispose:()=>{this.uncommittedChangesEmitter.off("change",e)}}}fetchUncommittedChanges=(0,s.debounce)(N((async()=>{const e=Date.now();try{this.uncommittedChangesBeginFetchingEmitter.emit("start");const t=await this.runCommand(["internal-only","status"]),n=JSON.parse(t.stdout).files.map((e=>{return{...e,path:(t=e.path,t.startsWith(l().sep)?t.slice(1):t)};var t}));this.uncommittedChanges={fetchStartTimestamp:e,fetchCompletedTimestamp:Date.now(),files:{value:n}},this.uncommittedChangesEmitter.emit("change",this.uncommittedChanges)}catch(n){if(this.logger.error("Error fetching files: ",n),null!=(t=n)&&"object"==typeof t&&"stderr"in t&&n.stderr.includes("checkout is currently in progress"))return void this.logger.info("Ignoring `hg status` error caused by in-progress checkout");this.uncommittedChangesEmitter.emit("change",{fetchStartTimestamp:e,fetchCompletedTimestamp:Date.now(),files:{error:n instanceof Error?n:new Error(n)}})}var t})),100);getSmartlogCommits(){return this.smartlogCommits}subscribeToSmartlogCommitsChanges(e){return this.smartlogCommitsChangesEmitter.on("change",e),{dispose:()=>{this.smartlogCommitsChangesEmitter.off("change",e)}}}subscribeToSmartlogCommitsBeginFetching(e){const t=()=>e(!0);return this.smartlogCommitsBeginFetchingEmitter.on("start",t),{dispose:()=>{this.smartlogCommitsBeginFetchingEmitter.off("start",t)}}}subscribeToUncommittedChangesBeginFetching(e){const t=()=>e(!0);return this.uncommittedChangesBeginFetchingEmitter.on("start",t),{dispose:()=>{this.uncommittedChangesBeginFetchingEmitter.off("start",t)}}}fetchSmartlogCommits=(0,s.debounce)(N((async()=>{const e=Date.now();try{this.smartlogCommitsBeginFetchingEmitter.emit("start");const t=await this.runCommand(["internal-only","log"]),n=function(e,t){let n=[];try{n=JSON.parse(t)}catch(t){e.error("failed to parse branch info",t)}return n}(this.logger,t.stdout.trim());if(0===n.length)throw new Error(s.ErrorShortMessages.NoCommitsFetched);this.smartlogCommits={fetchStartTimestamp:e,fetchCompletedTimestamp:Date.now(),commits:{value:n}},this.smartlogCommitsChangesEmitter.emit("change",this.smartlogCommits)}catch(t){this.logger.error("Error fetching commits: ",t),this.smartlogCommitsChangesEmitter.emit("change",{fetchStartTimestamp:e,fetchCompletedTimestamp:Date.now(),commits:{error:t instanceof Error?t:new Error(t)}})}})),100);subscribeToHeadCommit(e){let t=this.smartlogCommits?.commits.value?.find((e=>e.isHead));null!=t&&e(t);const n=n=>{const s=n?.commits.value?.find((e=>e.isHead));null!=s&&s.branch!==t?.branch&&(e(s),t=s)};return this.smartlogCommitsChangesEmitter.on("change",n),{dispose:()=>{this.smartlogCommitsChangesEmitter.off("change",n)}}}catLimiter=new P(4,(e=>this.logger.info("[cat]",e)));relativeCat(e,t){const n=l().relative(this.info.repoRoot,e);return this.catLimiter.enqueueRun((async()=>(await this.runCommand(["internal-only","relative-cat",...this.catArgs(t,n)],void 0,{stripFinalNewline:!1})).stdout))}cat(e,t){const n=l().relative(this.info.repoRoot,e);return this.catLimiter.enqueueRun((async()=>(await this.runCommand(["internal-only","cat",t,n],void 0,{stripFinalNewline:!1})).stdout))}catArgs(e,t){switch(e.type){case s.ComparisonType.UncommittedChanges:return["uncommitted",t];case s.ComparisonType.HeadChanges:return["head",t];case s.ComparisonType.StackChanges:return["stack",t];case s.ComparisonType.Committed:return["stack",t,"--ref",e.hash]}}getAllDiffIds(){return this.getSmartlogCommits()?.commits.value?.map((e=>e.pr?.number)).filter(s.notEmpty)??[]}runCommand(e,t,n){return x({command:this.info.command,args:e,logger:this.logger,cwd:(0,s.unwrap)(t??this.info.repoRoot),options:n})}getConfig(e){return $(this.info.command,this.logger,this.info.repoRoot,e)}setConfig(e,t,n){return async function({command:e,logger:t,cwd:n,level:s,configName:r,configValue:i}){await x({command:e,args:["internal-only","set-config","--level",s,r,i],logger:t,cwd:n})}({command:this.info.command,logger:this.logger,cwd:this.info.repoRoot,level:e,configName:t,configValue:n})}}function x({command:e,args:t,logger:n,cwd:s,options:r}){const{command:i,args:o,options:a}=U(e,t,s,r);return n&&n.log("run command: ",i,...o,a),O()(i,o,a)}async function A(e,t,n){try{return JSON.parse((await x({command:e,args:["internal-only","repo-info"],logger:t,cwd:n})).stdout)}catch(e){return void t.error(`Failed to find repository info in ${n}`,e)}}async function L(e,t,n){try{return JSON.parse((await x({command:e,args:["internal-only","profile"],logger:t,cwd:n})).stdout)}catch(e){return t.error(`Failed to find repository profile in ${n}`,e),{appUrl:"https://app.graphite.dev/"}}}async function $(e,t,n,s){try{return(await x({command:e,args:["internal-only","config",s],logger:t,cwd:n})).stdout.trim()}catch{return}}function U(e,t,n,s){let r=[...t];"win32"!==process.platform&&(r=r.map((e=>e.replace(/\\\\/g,"\\"))));const i={...s,env:{LANG:"en_US.utf-8",EDITOR:void 0,GRAPHITE_INTERACTIVE:"true",GIT_OPTIONAL_LOCKS:"0"},cwd:n};return!e&&process.argv[1].startsWith("/snapshot/")?(e=process.argv[0],r=["/snapshot/monologue/apps/public/cli/dist/graphite.js",...r]):e||(e="gt"),{command:e,args:r,options:i}}var q=n(32081),B=n(44828);const H={platformName:"browser",watchForChanges:(e,t,n)=>{const{repoRoot:s,dotdir:r}=e,i=B.watch(r,{cwd:r});i.on("ready",(()=>{n("everything")})),i.on("all",((e,t)=>{t.startsWith("rebase-merge")&&n("merge conflicts"),(t.startsWith("index")||t.startsWith("HEAD"))&&n("uncommitted changes"),(t.startsWith("refs/heads")||t.startsWith("refs/branch-metadata")||t.startsWith("HEAD"))&&n("branches")}));const o=l().relative(s,r),a=B.watch(s,{cwd:s,ignored:`${o}/**`});return a.on("all",(()=>{n("uncommitted changes")})),()=>{a.close().catch((()=>t.error(`failed to close chokidar worktree watcher for ${s}`))),i.close().catch((()=>t.error(`failed to close chokidar dotdir watcher for ${r}`)))}},handleMessageFromClient:(e,t)=>{switch(t.type){case"platform/openFile":{const n=l().join((0,s.unwrap)(e?.info.repoRoot),t.path);let r;if(null==r)switch(process.platform){case"darwin":r="/usr/bin/open";break;case"win32":r="notepad.exe";break;case"linux":r="xdg-open"}if(r){e?.logger.log("open file",n);const t=(0,q.spawn)(r,[n],{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!0});t.on("error",(t=>{e?.logger.log("failed to open",n,t)})),t.unref()}break}}}};var z=n(73292),V=n(9826),W=n.n(V);class G{promise;disposeFunc;constructor(e,t){this.promise=e,this.disposeFunc=t}unref(){this.disposed||(this.disposed=!0,this.disposeFunc())}internalReference;disposed=!1}class J{value;constructor(e){this.value=e}references=0;isDisposed=!1;ref(){this.references++}getNumberOfReferences(){return this.references}dispose(){this.references--,this.isDisposed||0!==this.references||(this.isDisposed=!0,this.value.dispose())}}const Q=new class{RepositoryType;constructor(e=F){this.RepositoryType=e}reposByRoot=new Map;activeReposEmitter=new M;lookup(e){for(const n of this.reposByRoot.values())if((e===n.value.info.repoRoot||e.startsWith((t=n.value.info.repoRoot).endsWith(l().sep)?t:t+l().sep))&&!n.isDisposed)return n;var t}getOrCreate(e,t,n,s){const r=this.lookup(s);if(r)return r.ref(),new G(Promise.resolve(r.value),(()=>r.dispose()));let i;return i=new G((async()=>{const r=await this.RepositoryType.getRepoInfo(e,n,s);if(n.info("repoInfo",r),"success"!==r.type)return r;if(i.disposed)return{type:"unknownError",error:new Error("Repository already disposed")};const o=this.lookup(r.repoRoot);if(o)return o.ref(),i.internalReference=o,o.value;const a=new this.RepositoryType(r,t,n),c=new J(a);return c.ref(),i.internalReference=c,this.reposByRoot.set(r.repoRoot,c),this.activeReposEmitter.emit("change"),a})(),(()=>{i.internalReference&&i.internalReference.dispose(),i.unref()})),i}cachedRepositoryForPath(e){const t=this.lookup(e);return t?.value}onChangeActiveRepos(e){const t=()=>{e([...this.reposByRoot.values()].map((e=>e.value)))};return this.activeReposEmitter.on("change",t),t(),()=>this.activeReposEmitter.off("change",t)}clearCache(){this.reposByRoot.forEach((e=>e.dispose())),this.reposByRoot=new Map,this.activeReposEmitter.removeAllListeners()}numberOfActiveServers(){let e=0;for(const t of this.reposByRoot.values())e+=t.getNumberOfReferences();return e}};class K{platform;connection;tracker;logger;listenersByType=new Map;incomingListener;repoDisposables=[];subscriptions=new Map;activeRepoRef;queuedMessages=[];currentState={type:"loading"};pageId=(0,s.randomId)();constructor(e,t,n,r){this.platform=e,this.connection=t,this.tracker=n,this.logger=r;let i=null;this.incomingListener=this.connection.onDidReceiveMessage(((e,n)=>{if(n)return null==i?void t.logger?.error("Error: got a binary message when not expecting one"):(this.handleIncomingMessageWithPayload(i,e),void(i=null));if(null!=i)return t.logger?.error("Error: didnt get binary payload after a message that requires one"),void(i=null);const r=e.toString("utf-8"),o=(0,s.deserializeFromString)(r);if(function(e){return null!=e&&"object"==typeof e&&!0===e.hasBinaryPayload}(o))i=o;else if("loading"===this.currentState.type)this.queuedMessages.push(o);else try{this.handleIncomingMessage(o)}catch(e){t.logger?.error("error handling incoming message: ",o,e)}}))}setRepoError(e){this.disposeRepoDisposables(),this.currentState={type:"error",error:e},this.tracker.context.setRepo(void 0),this.processQueuedMessages()}setCurrentRepo(e,t){this.disposeRepoDisposables(),this.currentState={type:"repo",repo:e,cwd:t},this.tracker.context.setRepo(e),null!=e.codeReviewProvider&&this.repoDisposables.push(e.codeReviewProvider.onChangeDiffSummaries((e=>{this.postMessage({type:"fetchedDiffSummaries",summaries:e})}))),this.repoDisposables.push(e.subscribeToHeadCommit((t=>{const n=e.getSmartlogCommits(),s=function(e,t){let n;if(null!=e){const s=new Map(e.map((e=>[e.branch,e])));let r=t;for(;null!=r;){if(r.partOfTrunk){n=r;break}if(null==r.parents[0])break;r=s.get(r.parents[0])}}return n}(n?.commits.value,t);this.tracker.track("HeadCommitChanged",{extras:{hash:t.branch,public:s?.branch}})}))),this.processQueuedMessages()}postMessage(e){this.connection.postMessage((0,s.serializeToString)(e)).catch((()=>{console.warn("Failed to post message to client")}))}setActiveRepoForCwd(e){void 0!==this.activeRepoRef&&this.activeRepoRef.unref(),this.logger.info(`Setting active repo cwd to ${e}`),this.currentState={type:"loading"};const t=this.connection.command;this.activeRepoRef=Q.getOrCreate(t,this.platform,this.logger,e),this.activeRepoRef.promise.then((t=>{t instanceof F?this.setCurrentRepo(t,e):this.setRepoError(t)}))}dispose(){this.incomingListener.dispose(),this.disposeRepoDisposables(),void 0!==this.activeRepoRef&&this.activeRepoRef.unref()}disposeRepoDisposables(){this.repoDisposables.forEach((e=>e.dispose())),this.repoDisposables=[],this.subscriptions.forEach((e=>e.dispose())),this.subscriptions.clear()}processQueuedMessages(){for(const e of this.queuedMessages)try{this.handleIncomingMessage(e)}catch(t){this.connection.logger?.error("error handling queued message: ",e,t)}this.queuedMessages=[]}handleIncomingMessageWithPayload(e,t){switch(e.type){case"uploadFile":{const{id:n,filename:r}=e,i=null;if(null==i)return;this.tracker.operation("UploadImage","UploadImageError",{},(()=>i((0,s.unwrap)(this.connection.logger),{filename:r,data:t}))).then((e=>{this.connection.logger?.info("sucessfully uploaded file",r,e),this.postMessage({type:"uploadFileResult",id:n,result:{value:e}})})).catch((e=>{this.connection.logger?.info("error uploading file",r,e),this.postMessage({type:"uploadFileResult",id:n,result:{error:e}})}));break}}}handleIncomingMessage(e){this.handleIncomingGeneralMessage(e);const{currentState:t}=this;switch(t.type){case"repo":{const{repo:n,cwd:s}=t;this.handleIncomingMessageWithRepo(e,n,s);break}case"loading":case"error":e.type.startsWith("platform/")&&(this.platform.handleMessageFromClient(void 0,e,(e=>this.postMessage(e)),(e=>{this.repoDisposables.push({dispose:e})})),this.notifyListeners(e))}}handleIncomingGeneralMessage(e){switch(this.logger.info("GeneralMessage",e),e.type){case"installCli":("brew"===e.method?O()("brew",["install","withgraphite/tap/graphite"]):O()("npm",["install","-g","@withgraphite/graphite-cli@stable"])).then((()=>{this.postMessage({type:"installCliResult",result:"success"})})).catch((e=>{const t=e instanceof Error?e.message:"Unknown error";this.postMessage({type:"installCliResult",result:"error",error:t})}));break;case"updateCli":W()("gt").then((async e=>{const t=await(0,z.realpath)(e),n="lib/node_modules/@withgraphite/graphite-cli/graphite.js";if(t.endsWith(n)){const e=t.replace(n,"bin/npm");return O()(e,["install","-g","@withgraphite/graphite-cli@stable"])}if(t.endsWith("/bin/gt")&&t.includes("Cellar"))return await O()("brew",["update"]),O()("brew",["upgrade","withgraphite/tap/graphite"]);throw new Error("Couldn't determine installation method")})).then((()=>{this.postMessage({type:"updateCliResult",result:"success"})})).catch((e=>{this.postMessage({type:"updateCliResult",result:"error",error:e instanceof Error?e.message:"Unknown error"})}));break;case"fetchAllBranches":x({command:this.connection.command||"gt",args:["internal-only","all-branches"],cwd:this.connection.cwd}).then((e=>({value:JSON.parse(e.stdout)}))).catch((e=>(this.logger?.error("error fetching auth status",e.toString()),{error:e}))).then((e=>{e.value&&this.postMessage({type:"fetchedAllBranches",message:e.value})}));break;case"initializeRepository":this.logger.info("init"),x({command:this.connection.command||"gt",args:["init","--trunk",e.trunkBranch],cwd:this.connection.cwd}).then((e=>{this.logger.info("initializeRepository",e),e.exitCode&&this.postMessage({type:"failedToInitializeRepository"}),this.postMessage({type:"initializedRepository"})})).catch((()=>{this.postMessage({type:"failedToInitializeRepository"})}));break;case"track":this.tracker.trackData(e.data);break;case"changeCwd":this.setActiveRepoForCwd(e.cwd);break;case"requestRepoInfo":switch(this.currentState.type){case"repo":this.postMessage({type:"repoInfo",info:this.currentState.repo.info,cwd:this.currentState.cwd});break;case"error":this.postMessage({type:"repoInfo",info:this.currentState.error})}break;case"requestApplicationInfo":this.postMessage({type:"applicationInfo",platformName:this.platform.platformName,version:this.connection.version})}}handleIncomingMessageWithRepo(e,t,n){const{logger:r}=t;switch(e.type){case"subscribe":{const{subscriptionID:n,kind:s}=e;switch(s){case"uncommittedChanges":{const e=e=>{this.postMessage({type:"subscriptionResult",kind:"uncommittedChanges",subscriptionID:n,data:e})},s=t.getUncommittedChanges();null!=s&&e(s);const r=[];r.push(t.subscribeToUncommittedChanges(e)),t.fetchUncommittedChanges(),r.push(t.subscribeToUncommittedChangesBeginFetching((()=>this.postMessage({type:"beganFetchingUncommittedChangesEvent"})))),this.subscriptions.set(n,{dispose:()=>{r.forEach((e=>e.dispose()))}});break}case"smartlogCommits":{const e=e=>{this.postMessage({type:"subscriptionResult",kind:"smartlogCommits",subscriptionID:n,data:e})},s=t.getSmartlogCommits();null!=s&&e(s);const r=[];r.push(t.subscribeToSmartlogCommitsChanges(e)),t.fetchSmartlogCommits(),r.push(t.subscribeToSmartlogCommitsBeginFetching((()=>this.postMessage({type:"beganFetchingSmartlogCommitsEvent"})))),this.subscriptions.set(n,{dispose:()=>{r.forEach((e=>e.dispose()))}});break}case"mergeConflicts":{const e=e=>{this.postMessage({type:"subscriptionResult",kind:"mergeConflicts",subscriptionID:n,data:e})},s=t.getMergeConflicts();null!=s&&e(s),this.subscriptions.set(n,t.onChangeConflictState(e));break}}break}case"unsubscribe":{const t=this.subscriptions.get(e.subscriptionID);t?.dispose(),this.subscriptions.delete(e.subscriptionID);break}case"runOperation":{const{operation:s}=e;t.runOrQueueOperation(s,(e=>{this.postMessage({type:"operationProgress",...e}),"queue"===e.kind&&this.tracker.track("QueueOperation",{extras:{operation:s.trackEventName}})}),this.tracker,n);break}case"abortRunningOperation":{const{operationId:n}=e;t.abortRunningOpeation(n);break}case"getConfig":t.getConfig(e.name).catch((()=>{})).then((t=>{r.info("got config",e.name,t),this.postMessage({type:"gotConfig",name:e.name,value:t})}));break;case"getPersistentViewState":this.postMessage({type:"gotPersistentViewState",name:e.name,value:this.connection.persistentClientSideViewState[e.name]});break;case"fetchRepoMessage":t.runCommand(["internal-only","repo-message"]).then((e=>({value:e.stdout}))).catch((e=>(r?.error("error fetching repo message",e.toString()),{error:e}))).then((e=>this.postMessage({type:"fetchedRepoMessage",message:e.value||""})));break;case"fetchUpgradePrompt":r.info("fetchUpgradePrompt"),t.runCommand(["internal-only","upgrade-prompt"]).then((e=>({value:e.stdout}))).catch((e=>(r?.error("error fetching upgrade prompt",e.toString()),{error:e}))).then((e=>this.postMessage({type:"fetchedUpgradePrompt",message:e.value||""})));break;case"fetchAuthStatus":t.runCommand(["internal-only","check-auth"]).then((e=>({value:JSON.parse(e.stdout)}))).catch((e=>(r?.error("error fetching auth status",e.toString()),{error:e}))).then((e=>{e.value&&this.postMessage({type:"fetchedAuthStatus",message:e.value})}));break;case"fetchPotentialParents":{const{branchToTrack:n}=e;t.runCommand(["internal-only","potential-parents",n]).then((e=>({value:JSON.parse(e.stdout)}))).catch((e=>(r?.error("error fetching potential parents",e.toString()),{error:e}))).then((e=>{e.value&&this.postMessage({type:"fetchedPotentialParents",message:e.value})}));break}case"setConfig":r.info("set config",e.name,e.value),t.setConfig("user",e.name,e.value).catch((t=>{r.error("error setting config",e.name,e.value,t)}));break;case"setPersistentViewState":this.connection.persistentClientSideViewState[e.name]=e.value;break;case"deleteFile":{const{filePath:n}=e,s=function(e,t,n=l()){const s=n.resolve(t.info.repoRoot,e);return s.startsWith(t.info.repoRoot+n.sep)?s:null}(n,t);if(null==s)return void r.warn("can't delete file outside of the repo",n);i().promises.rm(s).then((()=>{r.info("deleted file from filesystem",s)})).catch((e=>{r.error("unable to delete file",s,e)}));break}case"requestComparison":{const{comparison:n}=e;t.runCommand(["internal-only","diff",...I(n)]).then((e=>({value:e.stdout}))).catch((e=>(r?.error("error running diff",e.toString()),{error:e}))).then((e=>this.postMessage({type:"comparison",comparison:n,data:{diff:e}})));break}case"requestChangedFiles":{const{branch:n}=e;t.runCommand(["internal-only","changed-files",n]).then((e=>JSON.parse(e.stdout))).catch((e=>(r?.error("error running diff",e.toString()),{error:e}))).then((e=>this.postMessage({type:"changedFiles",branch:n,data:e})));break}case"requestComparisonContextLines":{const{id:{path:n,comparison:r},start:i,numLines:o}=e;if(r.type===s.ComparisonType.Commit||r.type===s.ComparisonType.Range)throw new Error("Not implemented");t.relativeCat(n,r).catch((()=>"")).then((e=>this.postMessage({type:"comparisonContextLines",lines:e.split("\n").slice(i-1,i-1+o),path:n})));break}case"requestChangedFilesInRange":{const{fromSha:n,toSha:s}=e;t.runCommand(["internal-only","changed-files",s,"--from",n]).then((e=>JSON.parse(e.stdout))).catch((e=>(r?.error("error running diff",e.toString()),{error:e}))).then((e=>this.postMessage({type:"changedFilesInRange",fromSha:n,toSha:s,data:e})));break}case"requestCommitsInBranch":{const{branch:n}=e;t.runCommand(["internal-only","list-commits",n]).then((e=>JSON.parse(e.stdout))).catch((e=>(r?.error("error running diff",e.toString()),{error:e}))).then((e=>this.postMessage({type:"commitsInBranch",branch:n,data:e})));break}case"requestChangedFilesInCommit":{const{commitSha:n}=e;t.runCommand(["internal-only","changed-files",n,"--from",`${n}~`]).then((e=>JSON.parse(e.stdout))).catch((e=>(r?.error("error running diff",e.toString()),{error:e}))).then((e=>this.postMessage({type:"changedFilesInCommit",commitSha:n,data:e})));break}case"refresh":r?.log("refresh requested"),t.fetchSmartlogCommits(),t.fetchUncommittedChanges(),t.codeReviewProvider?.triggerDiffSummariesFetch(t.getAllDiffIds());break;case"pageVisibility":t.setPageFocus(this.pageId,e.state);break;case"fetchCommitMessageTemplate":t.runCommand(["internal-only","templates"]).then((e=>{const n=JSON.parse(e.stdout);this.postMessage({type:"fetchedCommitMessageTemplate",templates:Object.fromEntries(Object.entries(n).map((([e,n])=>[e,n.replace(t.IGNORE_COMMIT_MESSAGE_LINES_REGEX,"")])))})})).catch((e=>{r?.error("Could not fetch commit message template",e)}));break;case"typeahead":t.codeReviewProvider?.typeahead?.(e.kind,e.query)?.then((t=>this.postMessage({type:"typeaheadResult",id:e.id,result:t})));break;case"fetchDiffSummaries":t.codeReviewProvider?.triggerDiffSummariesFetch(t.getAllDiffIds());break;case"loadMoreCommits":{const e=t.nextVisibleCommitRangeInDays();return this.postMessage({type:"commitsShownRange",rangeInDays:e}),this.postMessage({type:"beganLoadingMoreCommits"}),t.fetchSmartlogCommits(),void this.tracker.track("LoadMoreCommits",{extras:{daysToFetch:e??"Infinity"}})}default:this.platform.handleMessageFromClient(t,e,(e=>this.postMessage(e)),(e=>{this.repoDisposables.push({dispose:e})}))}this.notifyListeners(e)}notifyListeners(e){const t=this.listenersByType.get(e.type);t&&t.forEach((t=>t(e)))}}var X=n(6113);const Y="win32"==process.platform?l().join((0,s.unwrap)(process.env.LOCALAPPDATA),"cache"):"darwin"==process.platform?l().join(g().homedir(),"Library/Caches"):process.env.XDG_CACHE_HOME||l().join(g().homedir(),".cache");function Z(e,t){const n=Buffer.from(e),s=Buffer.from(t);return n.length===s.length&&(0,X.timingSafeEqual)(n,s)}function ee(e){const t=e.logger??(e.logFileLocation?function(e){const t=(...t)=>{const n=b().format(...t)+"\n";i().promises.appendFile(e,n)};return{info:t,log:t,warn:t,error:t,getLogFileContents:()=>i().promises.readFile(e,"utf-8")}}(e.logFileLocation):w);e.logger=t;const n=e?.platform??H,r=e?.version??"unknown";t.log(`establish client connection for ${e.cwd}`),t.log(`platform '${n.platformName}', version '${r}', command '${e.command}'`);const o=function(e,t,n,r=y){return new s.Tracker(((e,t)=>{const{logger:n}=t;n.log("[track]",e.eventName,e.errorName??"",e.errorMessage??"",null!=e.extras?JSON.stringify(e.extras):"");try{Promise.resolve(r({...e,...t.data})).catch((e=>{}))}catch{}}),new v(e,function(e,t){return{platform:e,version:t,repo:void 0,sessionId:(0,s.randomId)(),unixname:f(),osArch:g().arch(),osType:g().platform(),osRelease:g().release(),hostname:g().hostname()}}(t.platformName,n)))}(t,n,r,(t=>x({command:e.command||"gt",args:["internal-only","log-action",t.eventName||t.errorName||"UNKNOWN_CLI_EVENT",(t.timestamp?new Date(t.timestamp):new Date).toISOString(),JSON.stringify(t)],cwd:e.cwd})));o.track("ClientConnection",{extras:{cwd:e.cwd}});let a=new K(n,e,o,t);return a.setActiveRepoForCwd(e.cwd),()=>{a?.dispose(),a=null}}function te({port:e,sensitiveToken:t,challengeToken:n,logFileLocation:r,logInfo:o,command:c,gtVersion:h,foreground:d,frontendDir:p}){return new Promise((g=>{try{const e=JSON.parse(i().readFileSync(l().join(p,"build/asset-manifest.json"),"utf-8"));for(const t of Object.values(e.files))t.startsWith("/")||g({type:"error",error:`expected entry to start with / but was: \`${t}\``}),re[t]=t.slice(1)}catch(e){}re["/favicon.ico"]="favicon.ico";const f=a().createServer((async(e,s)=>{if(e.url){const{pathname:o}=u().parse(e.url);if(null!=o&&re.hasOwnProperty(o)){const e=re[o];let t;try{t=await i().promises.readFile(l().join(p,"build",e))}catch(e){return s.writeHead(500,{"Content-Type":"text/plain"}),void s.end((r=e.toString(),r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"")))}const n=e.lastIndexOf("."),a=e.slice(n+1),c=se[a]??"text/plain";return s.writeHead(200,{"Content-Type":c}),void s.end(t)}if("/challenge_authenticity"===o){const r=ne(e.url).get("token");if(r&&Z(r,t)){s.writeHead(200,{"Content-Type":"text/json"});const e={challengeToken:n,pid:process.pid};s.end(JSON.stringify(e))}else s.writeHead(401,{"Content-Type":"text/json"}),s.end(JSON.stringify({error:"invalid token"}));return}}var r;s.writeHead(404,{"Content-Type":"text/html"}),s.end("<html><body>Not Found!</body></html>")})),v=f.listen(e),y=new(m().Server)({noServer:!0,path:"/ws"});y.on("connection",((e,n)=>{let i,a,l;if(n.url){const e=ne(n.url);i=e.get("token");const t=e.get("cwd");l=e.get("platform"),t&&(a=decodeURIComponent(t))}if(!i){const t="No token provided in websocket request";return o("closing ws:",t),void e.close(s.CLOSED_AND_SHOULD_NOT_RECONNECT_CODE,t)}if(!Z(i,t)){const t="Invalid token";return o("closing ws:",t),void e.close(s.CLOSED_AND_SHOULD_NOT_RECONNECT_CODE,t)}const u=ee({postMessage:t=>(e.send(t),Promise.resolve(!0)),onDidReceiveMessage(t){const n=e.on("message",t);return{dispose:()=>n.off("message",t)}},cwd:a??process.cwd(),logFileLocation:"stdout"===r?void 0:r,command:c,version:h,persistentClientSideViewState:{},platform:void 0});e.on("close",(()=>{u(),d||setTimeout((()=>{0===Q.numberOfActiveServers()&&process.exit(0)}),6e4)}))})),v.on("upgrade",((e,t,n)=>{y.handleUpgrade(e,t,n,(t=>{y.emit("connection",t,e)}))})),f.on("error",(function(t){if("listen"!==t.syscall)throw g({type:"error",error:t.toString()}),t;switch(t.code){case"EACCES":throw g({type:"error",error:`Port ${e} requires elevated privileges`}),t;case"EADDRINUSE":return void g({type:"addressInUse"});default:throw g({type:"error",error:t.toString()}),t}})),f.on("listening",(()=>g({type:"success",port:f.address().port,pid:process.pid})))}))}function ne(e){const t=u().parse(e).search?.replace(/^\?/,"").split("&").map((e=>e.split("=")));return new Map(t)}l().join(Y,"graphite-gti");const se={css:"text/css",html:"text/html",js:"text/javascript",ttf:"font/ttf"},re={"/":"index.html"}}};
|
|
3
|
+
//# sourceMappingURL=230.js.map
|