dorkos 0.92.0 → 0.93.0
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/core-extensions/hello-world/index.ts +69 -4
- package/dist/bin/cli.js +1199 -319
- package/dist/client/assets/{AboutPage-CtAhGJVI.js → AboutPage-R35A-Uu-.js} +1 -1
- package/dist/client/assets/{AdapterIcon-DTXuj6Zu.js → AdapterIcon-kPDXiFU1.js} +1 -1
- package/dist/client/assets/{AppearancePage-EJF8LarY.js → AppearancePage-COqDtruX.js} +1 -1
- package/dist/client/assets/{BaseTanStackRouterDevtoolsPanel-B-iktbLX-COy_dBa2.js → BaseTanStackRouterDevtoolsPanel-B-iktbLX-CIKvkn5X.js} +24 -24
- package/dist/client/assets/{BlintzCanvas-Bb84mtl-.js → BlintzCanvas-4FX_eaSh.js} +1 -1
- package/dist/client/assets/{CanvasCsvContent-D1y22lqg.js → CanvasCsvContent-Dq2X1kUl.js} +1 -1
- package/dist/client/assets/{CanvasFileContent-CbOnIUPF.js → CanvasFileContent-CZUc62IR.js} +2 -2
- package/dist/client/assets/{CanvasModel3dContent-Bv86PZ-y.js → CanvasModel3dContent-D1IN_nl9.js} +2 -2
- package/dist/client/assets/{CodeMirrorDiff-CXqMnztG.js → CodeMirrorDiff-BeEhMSvL.js} +1 -1
- package/dist/client/assets/{CodeMirrorEditor-DHSY565t.js → CodeMirrorEditor-BlNLMvbo.js} +1 -1
- package/dist/client/assets/{ConnectionAccessLists-D5Qo1i-D.js → ConnectionAccessLists-s7RnRr1y.js} +1 -1
- package/dist/client/assets/{ConnectionsPage-DFvJRdx7.js → ConnectionsPage-BTTdQBdS.js} +2 -2
- package/dist/client/assets/ConventionPage-CI3PeUHm.js +11 -0
- package/dist/client/assets/{FloatingTanStackRouterDevtools-CqogiFob-BDQA6n2J.js → FloatingTanStackRouterDevtools-CqogiFob-D6OvDT9K.js} +1 -1
- package/dist/client/assets/HandlePage-Dvqztr0N.js +1 -0
- package/dist/client/assets/{LexicalField-a7Ov2ETq.js → LexicalField-Bqq5KeUW.js} +1 -1
- package/dist/client/assets/{ManagesPage-Czapr6qD.js → ManagesPage-CWdKDvw1.js} +1 -1
- package/dist/client/assets/{Model3dViewer-C_lFbWIi.js → Model3dViewer-ClJVGLDb.js} +1 -1
- package/dist/client/assets/NamePage-BgVZ-KD1.js +1 -0
- package/dist/client/assets/{NotificationsPage-CdQCyMJk.js → NotificationsPage-C6tE8iuE.js} +1 -1
- package/dist/client/assets/{PermissionsPage-DLT-RkUE.js → PermissionsPage-BqDl7shN.js} +1 -1
- package/dist/client/assets/{PersonalityPopover-BeOdD7eK.js → PersonalityPopover-B3q8QYcS.js} +1 -1
- package/dist/client/assets/PhotoPage-lt6ZevHW.js +1 -0
- package/dist/client/assets/{RoomsPage-CuZJdN_k.js → RoomsPage-DwYtOhd7.js} +1 -1
- package/dist/client/assets/{RunsOnPopover-DspQEAdG.js → RunsOnPopover-BDPs-RYB.js} +1 -1
- package/dist/client/assets/{SessionsPage-Ctwlg7GN.js → SessionsPage-Du24E934.js} +2 -2
- package/dist/client/assets/{SkillsPage-DJdFnWfL.js → SkillsPage-DjLUEngt.js} +1 -1
- package/dist/client/assets/{TasksPage-9jCfZB7f.js → TasksPage-B6i3r76o.js} +1 -1
- package/dist/client/assets/{ToolsPage-W7zK5P0s.js → ToolsPage-DNoC2MMz.js} +2 -2
- package/dist/client/assets/{TopologyGraph-CQga4Nuw.js → TopologyGraph-DtBDaHqX.js} +1 -1
- package/dist/client/assets/{agent-browser-CoSmBP5N.js → agent-browser-da9rKrej.js} +1 -1
- package/dist/client/assets/{highlighted-body-KPVGNVTW-Bq_O6Zlj.js → highlighted-body-KPVGNVTW-DJ5Xz8gv.js} +1 -1
- package/dist/client/assets/{index-CKY7hz-9.js → index-1o6WO7iZ.js} +1 -1
- package/dist/client/assets/{index-Dx0uYGgf.js → index-3DE2Q3OD.js} +1 -1
- package/dist/client/assets/index-B5yJddXH.js +1 -0
- package/dist/client/assets/{index-DrD7x9EL.js → index-BC9LsNlJ.js} +1 -1
- package/dist/client/assets/{index-bYhLX3oQ.js → index-BCGiD7pg.js} +410 -405
- package/dist/client/assets/index-BG-HtbEP.css +1 -0
- package/dist/client/assets/{index-BBMfKdj-.js → index-BQ-o6bQ0.js} +1 -1
- package/dist/client/assets/{index-D4nkiaT7.js → index-BVpHI-1y.js} +1 -1
- package/dist/client/assets/{index-DCmzSFWM.js → index-Bl2j_xjE.js} +1 -1
- package/dist/client/assets/{index-THAVeZRE.js → index-BnORUrPC.js} +1 -1
- package/dist/client/assets/{index-OidZkt6z.js → index-Bp2CiCey.js} +1 -1
- package/dist/client/assets/{index-BfoOBbWz.js → index-Bu16-jWo.js} +1 -1
- package/dist/client/assets/{index-DT9R_NnS.js → index-BzDP7VXZ.js} +1 -1
- package/dist/client/assets/{index-Bj32H2Xz.js → index-C9wgMNj5.js} +3 -3
- package/dist/client/assets/{index-CpCOMkMm.js → index-CJK5Iw50.js} +1 -1
- package/dist/client/assets/{index-Bat0bq64.js → index-CObinYlG.js} +1 -1
- package/dist/client/assets/{index-CdNENSm7.js → index-CQXxVt4A.js} +1 -1
- package/dist/client/assets/{index-Bn-vRpKY.js → index-CZ0BaV1t.js} +1 -1
- package/dist/client/assets/index-Ca5JlBEc.js +1 -0
- package/dist/client/assets/{index-CmQbhXN6.js → index-CfUAagLY.js} +1 -1
- package/dist/client/assets/{index-ULWpcSAZ.js → index-CotYqF0w.js} +1 -1
- package/dist/client/assets/{index-7AN8MIhq.js → index-CtJTMcuR.js} +1 -1
- package/dist/client/assets/{index-nztBriGg.js → index-CtlzkOJ3.js} +3 -3
- package/dist/client/assets/{index-9RHYMIP_.js → index-Cvzimc0W.js} +1 -1
- package/dist/client/assets/{index-cNE108-h.js → index-D0sn-ct6.js} +1 -1
- package/dist/client/assets/{index-BI051zYq.js → index-D1kH8Sr2.js} +2 -2
- package/dist/client/assets/{index-DV_54TKu.js → index-DJGEk3-H.js} +1 -1
- package/dist/client/assets/{index-B7fRxuTQ.js → index-DQWAoAN-.js} +1 -1
- package/dist/client/assets/{index-B4oYDFdX.js → index-DdsOOmtz.js} +1 -1
- package/dist/client/assets/{index-CIPmtIuV.js → index-DnN4PJaN.js} +1 -1
- package/dist/client/assets/{index-BiqiwP26.js → index-DsH33VjO.js} +4 -4
- package/dist/client/assets/{index-ahTVwxpJ.js → index-DwfaFQZo.js} +1 -1
- package/dist/client/assets/{index-BuAy0fEx.js → index-Dyeo69l2.js} +1 -1
- package/dist/client/assets/{index-E7ZNee_E.js → index-FsBhOkNr.js} +1 -1
- package/dist/client/assets/{index-DcwZU98u.js → index-LcH-4hgH.js} +1 -1
- package/dist/client/assets/{index-EmzeTf1X.js → index-gHd4-GL-.js} +1 -1
- package/dist/client/assets/{index-CFdScmIU.js → index-gIAwAMkn.js} +1 -1
- package/dist/client/assets/{room-files-source-CMj0pEdy.js → room-files-source-DRQNpCWs.js} +1 -1
- package/dist/client/assets/{soul-file-C_AT0A8U.js → soul-file-DcQD5pcS.js} +1 -1
- package/dist/client/assets/{use-personality-commit-ClM-Ahk5.js → use-personality-commit-Dsy9tqWY.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/drizzle/0132_connection_access_levels.sql +84 -0
- package/dist/drizzle/0134_query_indexes.sql +8 -0
- package/dist/drizzle/0135_session_started_by.sql +13 -0
- package/dist/drizzle/meta/0132_snapshot.json +10075 -0
- package/dist/drizzle/meta/0134_snapshot.json +10095 -0
- package/dist/drizzle/meta/0135_snapshot.json +10176 -0
- package/dist/drizzle/meta/_journal.json +22 -1
- package/dist/server/index.js +18659 -13468
- package/dist/server/index.js.map +2 -2
- package/package.json +9 -7
- package/dist/client/assets/ConventionPage-fMfStY8d.js +0 -11
- package/dist/client/assets/HandlePage-8Gv3fBBC.js +0 -1
- package/dist/client/assets/NamePage-CrZUfKVe.js +0 -1
- package/dist/client/assets/PhotoPage-C2mHVHvV.js +0 -1
- package/dist/client/assets/index-B0qJNUoh.css +0 -1
- package/dist/client/assets/index-CtxpF7aO.js +0 -1
- package/dist/client/assets/index-N8BCc19i.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as L,N as $,g as E,D as j,h as y,T as S,I as G}from"./index-Bj32H2Xz.js";var N={};class v{constructor(t,e,s,i,h,r,n,o,a,u=0,f){this.p=t,this.stack=e,this.state=s,this.reducePos=i,this.pos=h,this.score=r,this.buffer=n,this.bufferBase=o,this.curContext=a,this.lookAhead=u,this.parent=f}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let i=t.parser.context;return new v(t,[],e,s,s,0,[],0,i?new R(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,i=t&65535,{parser:h}=this.p,r=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),n=h.dynamicPrecedence(i);if(n&&(this.score+=n),s==0){i<h.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(h.getGoto(this.state,i,!0),this.reducePos),i<h.minRepeatTerm&&this.storeNode(i,this.reducePos,this.reducePos,r?8:4,!0),this.reduceContext(i,this.reducePos);return}let o=this.stack.length-(s-1)*3-(t&262144?6:0),a=o?this.stack[o-2]:this.p.ranges[0].from;i<h.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let u=this.reducePos-a;u>=2e3&&!(!((e=this.p.parser.nodeSet.types[i])===null||e===void 0)&&e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=u):this.p.lastBigReductionSize<u&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=u));let f=o?this.stack[o-1]:0,d=this.bufferBase+this.buffer.length-f;if(i<h.minRepeatTerm||t&131072){let c=h.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(i,a,c,d+4,!0)}if(t&262144)this.state=this.stack[o];else{let c=this.stack[o-3];this.state=h.getGoto(c,i,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(i,a)}storeNode(t,e,s,i=4,h=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let r=this.buffer.length;if(r>0&&this.buffer[r-4]==0&&this.buffer[r-1]>-1){if(e==s)return;if(this.buffer[r-2]>=e){this.buffer[r-2]=s;return}}}if(!h||this.pos==s)this.buffer.push(t,e,s,i);else{let r=this.buffer.length;if(r>0&&(this.buffer[r-4]!=0||this.buffer[r-1]<0)){let n=!1;for(let o=r;o>0&&this.buffer[o-2]>s;o-=4)if(this.buffer[o-1]>=0){n=!0;break}if(n)for(;r>0&&this.buffer[r-2]>s;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,i>4&&(i-=4)}this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=s,this.buffer[r+3]=i}}shift(t,e,s,i){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let h=t,{parser:r}=this.p;this.pos=i;let n=r.stateFlag(h,1);!n&&(i>s||e<=r.maxNode)&&(this.reducePos=i),this.pushState(h,n?s:Math.min(s,this.reducePos)),this.shiftContext(e,s),e<=r.maxNode&&this.buffer.push(e,s,i,4)}else this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4)}apply(t,e,s,i){t&65536?this.reduce(t):this.shift(t,e,s,i)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let i=this.pos;this.reducePos=this.pos=i+t.length,this.pushState(e,i),this.buffer.push(s,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),i=t.bufferBase+e;for(;t&&i==t.bufferBase;)t=t.parent;return new v(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,i,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new U(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(s==0)return!1;if((s&65536)==0)return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let h=0,r;h<e.length;h+=2)(r=e[h+1])!=this.state&&this.p.parser.hasAction(r,t)&&i.push(e[h],r);if(this.stack.length<120)for(let h=0;i.length<8&&h<e.length;h+=2){let r=e[h+1];i.some((n,o)=>o&1&&n==r)||i.push(e[h],r)}e=i}let s=[];for(let i=0;i<e.length&&s.length<4;i+=2){let h=e[i+1];if(h==this.state)continue;let r=this.split();r.pushState(h,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(e[i],this.pos),r.reducePos=this.pos,r.score-=200,s.push(r)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let s=e>>19,i=e&65535,h=this.stack.length-s*3;if(h<0||t.getGoto(this.stack[h],i,!1)<0){let r=this.findForcedReduction();if(r==null)return!1;e=r}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(i,h)=>{if(!e.includes(i))return e.push(i),t.allActions(i,r=>{if(!(r&393216))if(r&65536){let n=(r>>19)-h;if(n>1){let o=r&65535,a=this.stack.length-n*3;if(a>=0&&t.getGoto(this.stack[a],o,!1)>=0)return n<<19|65536|o}}else{let n=s(r,h+1);if(n!=null)return n}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new R(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class R{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class U{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,s=t>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=i}}class A{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new A(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new A(this.stack,this.pos,this.index)}}function x(l,t=Uint16Array){if(typeof l!="string")return l;let e=null;for(let s=0,i=0;s<l.length;){let h=0;for(;;){let r=l.charCodeAt(s++),n=!1;if(r==126){h=65535;break}r>=92&&r--,r>=34&&r--;let o=r-32;if(o>=46&&(o-=46,n=!0),h+=o,n)break;h*=46}e?e[i++]=h:e=new t(h)}return e}class P{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const z=new P;class H{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=z,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,i=this.rangeIndex,h=this.pos+t;for(;h<s.from;){if(!i)return null;let r=this.ranges[--i];h-=s.from-r.to,s=r}for(;e<0?h>s.to:h>=s.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];h+=r.from-s.to,s=r}return h}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,s,i;if(e>=0&&e<this.chunk.length)s=this.pos+t,i=this.chunk.charCodeAt(e);else{let h=this.resolveOffset(t,1);if(h==null)return-1;if(s=h,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let r=this.rangeIndex,n=this.range;for(;n.to<=s;)n=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>n.to&&(this.chunk2=this.chunk2.slice(0,n.to-s)),i=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),i}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=z,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let i of this.ranges){if(i.from>=e)break;i.to>t&&(s+=this.input.read(Math.max(i.from,t),Math.min(i.to,e)))}return s}}class m{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;O(this.data,t,e,this.id,s.data,s.tokenPrecTable)}}m.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class W{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?x(t):t}token(t,e){let s=t.pos,i=0;for(;;){let h=t.next<0,r=t.resolveOffset(1,1);if(O(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(h||i++,r==null)break;t.reset(r,t.token)}i&&(t.reset(s,t.token),t.acceptToken(this.elseToken,i))}}W.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class Z{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function O(l,t,e,s,i,h){let r=0,n=1<<s,{dialect:o}=e.p.parser;t:for(;(n&l[r])!=0;){let a=l[r+1];for(let c=r+3;c<a;c+=2)if((l[c+1]&n)>0){let p=l[c];if(o.allows(p)&&(t.token.value==-1||t.token.value==p||q(p,t.token.value,i,h))){t.acceptToken(p);break}}let u=t.next,f=0,d=l[r+2];if(t.next<0&&d>f&&l[a+d*3-3]==65535){r=l[a+d*3-1];continue t}for(;f<d;){let c=f+d>>1,p=a+c+(c<<1),b=l[p],M=l[p+1]||65536;if(u<b)d=c;else if(u>=M)f=c+1;else{r=l[p+2],t.advance();continue t}}break}}function I(l,t,e){for(let s=t,i;(i=l[s])!=65535;s++)if(i==e)return s-t;return-1}function q(l,t,e,s){let i=I(e,s,t);return i<0||I(e,s,l)<i}const g=typeof process<"u"&&N&&/\bparse\b/.test(N.LOG);let T=null;function D(l,t,e){let s=l.cursor(G.IncludeAnonymous);for(s.moveTo(t);;)if(!(e<0?s.childBefore(t):s.childAfter(t)))for(;;){if((e<0?s.to<t:s.from>t)&&!s.type.isError)return e<0?Math.max(0,Math.min(s.to-1,t-25)):Math.min(l.length,Math.max(s.from+1,t+25));if(e<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return e<0?0:l.length}}class J{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?D(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?D(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let s=this.trees[e],i=this.index[e];if(i==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let h=s.children[i],r=this.start[e]+s.positions[i];if(r>t)return this.nextStart=r,null;if(h instanceof S){if(r==t){if(r<this.safeFrom)return null;let n=r+h.length;if(n<=this.safeTo){let o=h.prop(y.lookAhead);if(!o||n+o<this.fragment.to)return h}}this.index[e]++,r+h.length>=Math.max(this.safeFrom,t)&&(this.trees.push(h),this.start.push(r),this.index.push(0))}else this.index[e]++,this.nextStart=r+h.length}}}class K{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new P)}getActions(t){let e=0,s=null,{parser:i}=t.p,{tokenizers:h}=i,r=i.stateSlot(t.state,3),n=t.curContext?t.curContext.hash:0,o=0;for(let a=0;a<h.length;a++){if((1<<a&r)==0)continue;let u=h[a],f=this.tokens[a];if(!(s&&!u.fallback)&&((u.contextual||f.start!=t.pos||f.mask!=r||f.context!=n)&&(this.updateCachedToken(f,u,t),f.mask=r,f.context=n),f.lookAhead>f.end+25&&(o=Math.max(f.lookAhead,o)),f.value!=0)){let d=e;if(f.extended>-1&&(e=this.addActions(t,f.extended,f.end,e)),e=this.addActions(t,f.value,f.end,e),!u.extend&&(s=f,e>d))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),!s&&t.pos==this.stream.end&&(s=new P,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new P,{pos:s,p:i}=t;return e.start=s,e.end=Math.min(s+1,i.stream.end),e.value=s==i.stream.end?i.parser.eofTerm:0,e}updateCachedToken(t,e,s){let i=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(i,t),s),t.value>-1){let{parser:h}=s.p;for(let r=0;r<h.specialized.length;r++)if(h.specialized[r]==t.value){let n=h.specializers[r](this.stream.read(t.start,t.end),s);if(n>=0&&s.p.parser.dialect.allows(n>>1)){(n&1)==0?t.value=n>>1:t.extended=n>>1;break}}}else t.value=0,t.end=this.stream.clipPos(i+1)}putAction(t,e,s,i){for(let h=0;h<i;h+=3)if(this.actions[h]==t)return i;return this.actions[i++]=t,this.actions[i++]=e,this.actions[i++]=s,i}addActions(t,e,s,i){let{state:h}=t,{parser:r}=t.p,{data:n}=r;for(let o=0;o<2;o++)for(let a=r.stateSlot(h,o?2:1);;a+=3){if(n[a]==65535)if(n[a+1]==1)a=k(n,a+2);else{i==0&&n[a+1]==2&&(i=this.putAction(k(n,a+2),e,s,i));break}n[a]==e&&(i=this.putAction(k(n,a+1),e,s,i))}return i}}class Q{constructor(t,e,s,i){this.parser=t,this.input=e,this.ranges=i,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new H(e,i),this.tokens=new K(t,this.stream),this.topTerm=t.top[1];let{from:h}=i[0];this.stacks=[v.start(this,t.top[0],h)],this.fragments=s.length&&this.stream.end-h>t.bufferLength*4?new J(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],i,h;if(this.bigReductionCount>300&&t.length==1){let[r]=t;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<t.length;r++){let n=t[r];for(;;){if(this.tokens.mainToken=null,n.pos>e)s.push(n);else{if(this.advanceStack(n,s,t))continue;{i||(i=[],h=[]),i.push(n);let o=this.tokens.getMainToken(n);h.push(o.value,o.end)}}break}}if(!s.length){let r=i&&X(i);if(r)return g&&console.log("Finish with "+this.stackID(r)),this.stackToTree(r);if(this.parser.strict)throw g&&i&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,h,s);if(r)return g&&console.log("Force-finish "+this.stackID(r)),this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(s.length>r)for(s.sort((n,o)=>o.score-n.score);s.length>r;)s.pop();s.some(n=>n.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let r=0;r<s.length-1;r++){let n=s[r];for(let o=r+1;o<s.length;o++){let a=s[o];if(n.sameState(a)||n.buffer.length>500&&a.buffer.length>500)if((n.score-a.score||n.buffer.length-a.buffer.length)>0)s.splice(o--,1);else{s.splice(r--,1);continue t}}}s.length>12&&(s.sort((r,n)=>n.score-r.score),s.splice(12,s.length-12))}this.minStackPos=s[0].pos;for(let r=1;r<s.length;r++)s[r].pos<this.minStackPos&&(this.minStackPos=s[r].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,s){let i=t.pos,{parser:h}=this,r=g?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,u=a?t.curContext.hash:0;for(let f=this.fragments.nodeAt(i);f;){let d=this.parser.nodeSet.types[f.type.id]==f.type?h.getGoto(t.state,f.type.id):-1;if(d>-1&&f.length&&(!a||(f.prop(y.contextHash)||0)==u))return t.useNode(f,d),g&&console.log(r+this.stackID(t)+` (via reuse of ${h.getName(f.type.id)})`),!0;if(!(f instanceof S)||f.children.length==0||f.positions[0]>0)break;let c=f.children[0];if(c instanceof S&&f.positions[0]==0)f=c;else break}}let n=h.stateSlot(t.state,4);if(n>0)return t.reduce(n),g&&console.log(r+this.stackID(t)+` (via always-reduce ${h.getName(n&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let o=this.tokens.getActions(t);for(let a=0;a<o.length;){let u=o[a++],f=o[a++],d=o[a++],c=a==o.length||!s,p=c?t:t.split(),b=this.tokens.mainToken;if(p.apply(u,f,b?b.start:p.pos,d),g&&console.log(r+this.stackID(p)+` (via ${(u&65536)==0?"shift":`reduce of ${h.getName(u&65535)}`} for ${h.getName(f)} @ ${i}${p==t?"":", split"})`),c)return!0;p.pos>i?e.push(p):s.push(p)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return B(t,e),!0}}runRecovery(t,e,s){let i=null,h=!1;for(let r=0;r<t.length;r++){let n=t[r],o=e[r<<1],a=e[(r<<1)+1],u=g?this.stackID(n)+" -> ":"";if(n.deadEnd&&(h||(h=!0,n.restart(),g&&console.log(u+this.stackID(n)+" (restarted)"),this.advanceFully(n,s))))continue;let f=n.split(),d=u;for(let c=0;c<10&&f.forceReduce()&&(g&&console.log(d+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,s));c++)g&&(d=this.stackID(f)+" -> ");for(let c of n.recoverByInsert(o))g&&console.log(u+this.stackID(c)+" (via recover-insert)"),this.advanceFully(c,s);this.stream.end>n.pos?(a==n.pos&&(a++,o=0),n.recoverByDelete(o,a),g&&console.log(u+this.stackID(n)+` (via recover-delete ${this.parser.getName(o)})`),B(n,s)):(!i||i.score<f.score)&&(i=f)}return i}stackToTree(t){return t.close(),S.build({buffer:A.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(T||(T=new WeakMap)).get(t);return e||T.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function B(l,t){for(let e=0;e<t.length;e++){let s=t[e];if(s.pos==l.pos&&s.sameState(l)){t[e].score<l.score&&(t[e]=l);return}}t.push(l)}class V{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}}const C=l=>l;class _{constructor(t){this.start=t.start,this.shift=t.shift||C,this.reduce=t.reduce||C,this.reuse=t.reuse||C,this.hash=t.hash||(()=>0),this.strict=t.strict!==!1}}class w extends L{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let n=0;n<t.repeatNodeCount;n++)e.push("");let s=Object.keys(t.topRules).map(n=>t.topRules[n][1]),i=[];for(let n=0;n<e.length;n++)i.push([]);function h(n,o,a){i[n].push([o,o.deserialize(String(a))])}if(t.nodeProps)for(let n of t.nodeProps){let o=n[0];typeof o=="string"&&(o=y[o]);for(let a=1;a<n.length;){let u=n[a++];if(u>=0)h(u,o,n[a++]);else{let f=n[a+-u];for(let d=-u;d>0;d--)h(n[a++],o,f);a++}}}this.nodeSet=new $(e.map((n,o)=>E.define({name:o>=this.minRepeatTerm?void 0:n,id:o,props:i[o],top:s.indexOf(o)>-1,error:o==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(o)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=j;let r=x(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let n=0;n<this.specializerSpecs.length;n++)this.specialized[n]=this.specializerSpecs[n].term;this.specializers=this.specializerSpecs.map(F),this.states=x(t.states,Uint32Array),this.data=x(t.stateData),this.goto=x(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(n=>typeof n=="number"?new m(r,n):n),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let i=new Q(this,t,e,s);for(let h of this.wrappers)i=h(i,t,e,s);return i}getGoto(t,e,s=!1){let i=this.goto;if(e>=i[0])return-1;for(let h=i[e+1];;){let r=i[h++],n=r&1,o=i[h++];if(n&&s)return o;for(let a=h+(r>>1);h<a;h++)if(i[h]==t)return o;if(n)return-1}}hasAction(t,e){let s=this.data;for(let i=0;i<2;i++)for(let h=this.stateSlot(t,i?2:1),r;;h+=3){if((r=s[h])==65535)if(s[h+1]==1)r=s[h=k(s,h+2)];else{if(s[h+1]==2)return k(s,h+2);break}if(r==e||r==0)return k(s,h+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,s=>s==e?!0:null)}allActions(t,e){let s=this.stateSlot(t,4),i=s?e(s):void 0;for(let h=this.stateSlot(t,1);i==null;h+=3){if(this.data[h]==65535)if(this.data[h+1]==1)h=k(this.data,h+2);else break;i=e(k(this.data,h+1))}return i}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=k(this.data,s+2);else break;if((this.data[s+2]&1)==0){let i=this.data[s+1];e.some((h,r)=>r&1&&h==i)||e.push(this.data[s],i)}}return e}configure(t){let e=Object.assign(Object.create(w.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(s=>{let i=t.tokenizers.find(h=>h.from==s);return i?i.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,i)=>{let h=t.specializers.find(n=>n.from==s.external);if(!h)return s;let r=Object.assign(Object.assign({},s),{external:h.to});return e.specializers[i]=F(r),r})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let h of t.split(" ")){let r=e.indexOf(h);r>=0&&(s[r]=!0)}let i=null;for(let h=0;h<e.length;h++)if(!s[h])for(let r=this.dialects[e[h]],n;(n=this.data[r++])!=65535;)(i||(i=new Uint8Array(this.maxTerm+1)))[n]=1;return new V(t,s,i)}static deserialize(t){return new w(t)}}function k(l,t){return l[t]|l[t+1]<<16}function X(l){let t=null;for(let e of l){let s=e.p.stoppedAt;(e.pos==e.p.stream.end||s!=null&&e.pos>s)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function F(l){if(l.external){let t=l.extend?1:0;return(e,s)=>l.external(e,s)<<1|t}return l.get}export{_ as C,Z as E,w as L,W as a};
|
|
1
|
+
import{P as L,N as $,g as E,D as j,h as y,T as S,I as G}from"./index-C9wgMNj5.js";var N={};class v{constructor(t,e,s,i,h,r,n,o,a,u=0,f){this.p=t,this.stack=e,this.state=s,this.reducePos=i,this.pos=h,this.score=r,this.buffer=n,this.bufferBase=o,this.curContext=a,this.lookAhead=u,this.parent=f}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,s=0){let i=t.parser.context;return new v(t,[],e,s,s,0,[],0,i?new R(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let s=t>>19,i=t&65535,{parser:h}=this.p,r=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),n=h.dynamicPrecedence(i);if(n&&(this.score+=n),s==0){i<h.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(h.getGoto(this.state,i,!0),this.reducePos),i<h.minRepeatTerm&&this.storeNode(i,this.reducePos,this.reducePos,r?8:4,!0),this.reduceContext(i,this.reducePos);return}let o=this.stack.length-(s-1)*3-(t&262144?6:0),a=o?this.stack[o-2]:this.p.ranges[0].from;i<h.minRepeatTerm&&a==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let u=this.reducePos-a;u>=2e3&&!(!((e=this.p.parser.nodeSet.types[i])===null||e===void 0)&&e.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=u):this.p.lastBigReductionSize<u&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=u));let f=o?this.stack[o-1]:0,d=this.bufferBase+this.buffer.length-f;if(i<h.minRepeatTerm||t&131072){let c=h.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(i,a,c,d+4,!0)}if(t&262144)this.state=this.stack[o];else{let c=this.stack[o-3];this.state=h.getGoto(c,i,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(i,a)}storeNode(t,e,s,i=4,h=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let r=this.buffer.length;if(r>0&&this.buffer[r-4]==0&&this.buffer[r-1]>-1){if(e==s)return;if(this.buffer[r-2]>=e){this.buffer[r-2]=s;return}}}if(!h||this.pos==s)this.buffer.push(t,e,s,i);else{let r=this.buffer.length;if(r>0&&(this.buffer[r-4]!=0||this.buffer[r-1]<0)){let n=!1;for(let o=r;o>0&&this.buffer[o-2]>s;o-=4)if(this.buffer[o-1]>=0){n=!0;break}if(n)for(;r>0&&this.buffer[r-2]>s;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,i>4&&(i-=4)}this.buffer[r]=t,this.buffer[r+1]=e,this.buffer[r+2]=s,this.buffer[r+3]=i}}shift(t,e,s,i){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let h=t,{parser:r}=this.p;this.pos=i;let n=r.stateFlag(h,1);!n&&(i>s||e<=r.maxNode)&&(this.reducePos=i),this.pushState(h,n?s:Math.min(s,this.reducePos)),this.shiftContext(e,s),e<=r.maxNode&&this.buffer.push(e,s,i,4)}else this.pos=i,this.shiftContext(e,s),e<=this.p.parser.maxNode&&this.buffer.push(e,s,i,4)}apply(t,e,s,i){t&65536?this.reduce(t):this.shift(t,e,s,i)}useNode(t,e){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=t)&&(this.p.reused.push(t),s++);let i=this.pos;this.reducePos=this.pos=i+t.length,this.pushState(e,i),this.buffer.push(s,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let s=t.buffer.slice(e),i=t.bufferBase+e;for(;t&&i==t.bufferBase;)t=t.parent;return new v(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,i,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let s=t<=this.p.parser.maxNode;s&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,s?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new U(this);;){let s=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(s==0)return!1;if((s&65536)==0)return!0;e.reduce(s)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let i=[];for(let h=0,r;h<e.length;h+=2)(r=e[h+1])!=this.state&&this.p.parser.hasAction(r,t)&&i.push(e[h],r);if(this.stack.length<120)for(let h=0;i.length<8&&h<e.length;h+=2){let r=e[h+1];i.some((n,o)=>o&1&&n==r)||i.push(e[h],r)}e=i}let s=[];for(let i=0;i<e.length&&s.length<4;i+=2){let h=e[i+1];if(h==this.state)continue;let r=this.split();r.pushState(h,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(e[i],this.pos),r.reducePos=this.pos,r.score-=200,s.push(r)}return s}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let s=e>>19,i=e&65535,h=this.stack.length-s*3;if(h<0||t.getGoto(this.stack[h],i,!1)<0){let r=this.findForcedReduction();if(r==null)return!1;e=r}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],s=(i,h)=>{if(!e.includes(i))return e.push(i),t.allActions(i,r=>{if(!(r&393216))if(r&65536){let n=(r>>19)-h;if(n>1){let o=r&65535,a=this.stack.length-n*3;if(a>=0&&t.getGoto(this.stack[a],o,!1)>=0)return n<<19|65536|o}}else{let n=s(r,h+1);if(n!=null)return n}})};return s(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new R(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class R{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class U{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,s=t>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=i}}class A{constructor(t,e,s){this.stack=t,this.pos=e,this.index=s,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new A(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new A(this.stack,this.pos,this.index)}}function x(l,t=Uint16Array){if(typeof l!="string")return l;let e=null;for(let s=0,i=0;s<l.length;){let h=0;for(;;){let r=l.charCodeAt(s++),n=!1;if(r==126){h=65535;break}r>=92&&r--,r>=34&&r--;let o=r-32;if(o>=46&&(o-=46,n=!0),h+=o,n)break;h*=46}e?e[i++]=h:e=new t(h)}return e}class P{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const z=new P;class H{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=z,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let s=this.range,i=this.rangeIndex,h=this.pos+t;for(;h<s.from;){if(!i)return null;let r=this.ranges[--i];h-=s.from-r.to,s=r}for(;e<0?h>s.to:h>=s.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];h+=r.from-s.to,s=r}return h}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,s,i;if(e>=0&&e<this.chunk.length)s=this.pos+t,i=this.chunk.charCodeAt(e);else{let h=this.resolveOffset(t,1);if(h==null)return-1;if(s=h,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let r=this.rangeIndex,n=this.range;for(;n.to<=s;)n=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>n.to&&(this.chunk2=this.chunk2.slice(0,n.to-s)),i=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),i}acceptToken(t,e=0){let s=e?this.resolveOffset(e,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=s}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=z,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let s="";for(let i of this.ranges){if(i.from>=e)break;i.to>t&&(s+=this.input.read(Math.max(i.from,t),Math.min(i.to,e)))}return s}}class m{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:s}=e.p;O(this.data,t,e,this.id,s.data,s.tokenPrecTable)}}m.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class W{constructor(t,e,s){this.precTable=e,this.elseToken=s,this.data=typeof t=="string"?x(t):t}token(t,e){let s=t.pos,i=0;for(;;){let h=t.next<0,r=t.resolveOffset(1,1);if(O(this.data,t,e,0,this.data,this.precTable),t.token.value>-1)break;if(this.elseToken==null)return;if(h||i++,r==null)break;t.reset(r,t.token)}i&&(t.reset(s,t.token),t.acceptToken(this.elseToken,i))}}W.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;class Z{constructor(t,e={}){this.token=t,this.contextual=!!e.contextual,this.fallback=!!e.fallback,this.extend=!!e.extend}}function O(l,t,e,s,i,h){let r=0,n=1<<s,{dialect:o}=e.p.parser;t:for(;(n&l[r])!=0;){let a=l[r+1];for(let c=r+3;c<a;c+=2)if((l[c+1]&n)>0){let p=l[c];if(o.allows(p)&&(t.token.value==-1||t.token.value==p||q(p,t.token.value,i,h))){t.acceptToken(p);break}}let u=t.next,f=0,d=l[r+2];if(t.next<0&&d>f&&l[a+d*3-3]==65535){r=l[a+d*3-1];continue t}for(;f<d;){let c=f+d>>1,p=a+c+(c<<1),b=l[p],M=l[p+1]||65536;if(u<b)d=c;else if(u>=M)f=c+1;else{r=l[p+2],t.advance();continue t}}break}}function I(l,t,e){for(let s=t,i;(i=l[s])!=65535;s++)if(i==e)return s-t;return-1}function q(l,t,e,s){let i=I(e,s,t);return i<0||I(e,s,l)<i}const g=typeof process<"u"&&N&&/\bparse\b/.test(N.LOG);let T=null;function D(l,t,e){let s=l.cursor(G.IncludeAnonymous);for(s.moveTo(t);;)if(!(e<0?s.childBefore(t):s.childAfter(t)))for(;;){if((e<0?s.to<t:s.from>t)&&!s.type.isError)return e<0?Math.max(0,Math.min(s.to-1,t-25)):Math.min(l.length,Math.max(s.from+1,t+25));if(e<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return e<0?0:l.length}}class J{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?D(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?D(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let s=this.trees[e],i=this.index[e];if(i==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let h=s.children[i],r=this.start[e]+s.positions[i];if(r>t)return this.nextStart=r,null;if(h instanceof S){if(r==t){if(r<this.safeFrom)return null;let n=r+h.length;if(n<=this.safeTo){let o=h.prop(y.lookAhead);if(!o||n+o<this.fragment.to)return h}}this.index[e]++,r+h.length>=Math.max(this.safeFrom,t)&&(this.trees.push(h),this.start.push(r),this.index.push(0))}else this.index[e]++,this.nextStart=r+h.length}}}class K{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(s=>new P)}getActions(t){let e=0,s=null,{parser:i}=t.p,{tokenizers:h}=i,r=i.stateSlot(t.state,3),n=t.curContext?t.curContext.hash:0,o=0;for(let a=0;a<h.length;a++){if((1<<a&r)==0)continue;let u=h[a],f=this.tokens[a];if(!(s&&!u.fallback)&&((u.contextual||f.start!=t.pos||f.mask!=r||f.context!=n)&&(this.updateCachedToken(f,u,t),f.mask=r,f.context=n),f.lookAhead>f.end+25&&(o=Math.max(f.lookAhead,o)),f.value!=0)){let d=e;if(f.extended>-1&&(e=this.addActions(t,f.extended,f.end,e)),e=this.addActions(t,f.value,f.end,e),!u.extend&&(s=f,e>d))break}}for(;this.actions.length>e;)this.actions.pop();return o&&t.setLookAhead(o),!s&&t.pos==this.stream.end&&(s=new P,s.value=t.p.parser.eofTerm,s.start=s.end=t.pos,e=this.addActions(t,s.value,s.end,e)),this.mainToken=s,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new P,{pos:s,p:i}=t;return e.start=s,e.end=Math.min(s+1,i.stream.end),e.value=s==i.stream.end?i.parser.eofTerm:0,e}updateCachedToken(t,e,s){let i=this.stream.clipPos(s.pos);if(e.token(this.stream.reset(i,t),s),t.value>-1){let{parser:h}=s.p;for(let r=0;r<h.specialized.length;r++)if(h.specialized[r]==t.value){let n=h.specializers[r](this.stream.read(t.start,t.end),s);if(n>=0&&s.p.parser.dialect.allows(n>>1)){(n&1)==0?t.value=n>>1:t.extended=n>>1;break}}}else t.value=0,t.end=this.stream.clipPos(i+1)}putAction(t,e,s,i){for(let h=0;h<i;h+=3)if(this.actions[h]==t)return i;return this.actions[i++]=t,this.actions[i++]=e,this.actions[i++]=s,i}addActions(t,e,s,i){let{state:h}=t,{parser:r}=t.p,{data:n}=r;for(let o=0;o<2;o++)for(let a=r.stateSlot(h,o?2:1);;a+=3){if(n[a]==65535)if(n[a+1]==1)a=k(n,a+2);else{i==0&&n[a+1]==2&&(i=this.putAction(k(n,a+2),e,s,i));break}n[a]==e&&(i=this.putAction(k(n,a+1),e,s,i))}return i}}class Q{constructor(t,e,s,i){this.parser=t,this.input=e,this.ranges=i,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new H(e,i),this.tokens=new K(t,this.stream),this.topTerm=t.top[1];let{from:h}=i[0];this.stacks=[v.start(this,t.top[0],h)],this.fragments=s.length&&this.stream.end-h>t.bufferLength*4?new J(s,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,s=this.stacks=[],i,h;if(this.bigReductionCount>300&&t.length==1){let[r]=t;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<t.length;r++){let n=t[r];for(;;){if(this.tokens.mainToken=null,n.pos>e)s.push(n);else{if(this.advanceStack(n,s,t))continue;{i||(i=[],h=[]),i.push(n);let o=this.tokens.getMainToken(n);h.push(o.value,o.end)}}break}}if(!s.length){let r=i&&X(i);if(r)return g&&console.log("Finish with "+this.stackID(r)),this.stackToTree(r);if(this.parser.strict)throw g&&i&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,h,s);if(r)return g&&console.log("Force-finish "+this.stackID(r)),this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(s.length>r)for(s.sort((n,o)=>o.score-n.score);s.length>r;)s.pop();s.some(n=>n.reducePos>e)&&this.recovering--}else if(s.length>1){t:for(let r=0;r<s.length-1;r++){let n=s[r];for(let o=r+1;o<s.length;o++){let a=s[o];if(n.sameState(a)||n.buffer.length>500&&a.buffer.length>500)if((n.score-a.score||n.buffer.length-a.buffer.length)>0)s.splice(o--,1);else{s.splice(r--,1);continue t}}}s.length>12&&(s.sort((r,n)=>n.score-r.score),s.splice(12,s.length-12))}this.minStackPos=s[0].pos;for(let r=1;r<s.length;r++)s[r].pos<this.minStackPos&&(this.minStackPos=s[r].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,s){let i=t.pos,{parser:h}=this,r=g?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let a=t.curContext&&t.curContext.tracker.strict,u=a?t.curContext.hash:0;for(let f=this.fragments.nodeAt(i);f;){let d=this.parser.nodeSet.types[f.type.id]==f.type?h.getGoto(t.state,f.type.id):-1;if(d>-1&&f.length&&(!a||(f.prop(y.contextHash)||0)==u))return t.useNode(f,d),g&&console.log(r+this.stackID(t)+` (via reuse of ${h.getName(f.type.id)})`),!0;if(!(f instanceof S)||f.children.length==0||f.positions[0]>0)break;let c=f.children[0];if(c instanceof S&&f.positions[0]==0)f=c;else break}}let n=h.stateSlot(t.state,4);if(n>0)return t.reduce(n),g&&console.log(r+this.stackID(t)+` (via always-reduce ${h.getName(n&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let o=this.tokens.getActions(t);for(let a=0;a<o.length;){let u=o[a++],f=o[a++],d=o[a++],c=a==o.length||!s,p=c?t:t.split(),b=this.tokens.mainToken;if(p.apply(u,f,b?b.start:p.pos,d),g&&console.log(r+this.stackID(p)+` (via ${(u&65536)==0?"shift":`reduce of ${h.getName(u&65535)}`} for ${h.getName(f)} @ ${i}${p==t?"":", split"})`),c)return!0;p.pos>i?e.push(p):s.push(p)}return!1}advanceFully(t,e){let s=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>s)return B(t,e),!0}}runRecovery(t,e,s){let i=null,h=!1;for(let r=0;r<t.length;r++){let n=t[r],o=e[r<<1],a=e[(r<<1)+1],u=g?this.stackID(n)+" -> ":"";if(n.deadEnd&&(h||(h=!0,n.restart(),g&&console.log(u+this.stackID(n)+" (restarted)"),this.advanceFully(n,s))))continue;let f=n.split(),d=u;for(let c=0;c<10&&f.forceReduce()&&(g&&console.log(d+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,s));c++)g&&(d=this.stackID(f)+" -> ");for(let c of n.recoverByInsert(o))g&&console.log(u+this.stackID(c)+" (via recover-insert)"),this.advanceFully(c,s);this.stream.end>n.pos?(a==n.pos&&(a++,o=0),n.recoverByDelete(o,a),g&&console.log(u+this.stackID(n)+` (via recover-delete ${this.parser.getName(o)})`),B(n,s)):(!i||i.score<f.score)&&(i=f)}return i}stackToTree(t){return t.close(),S.build({buffer:A.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(T||(T=new WeakMap)).get(t);return e||T.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function B(l,t){for(let e=0;e<t.length;e++){let s=t[e];if(s.pos==l.pos&&s.sameState(l)){t[e].score<l.score&&(t[e]=l);return}}t.push(l)}class V{constructor(t,e,s){this.source=t,this.flags=e,this.disabled=s}allows(t){return!this.disabled||this.disabled[t]==0}}const C=l=>l;class _{constructor(t){this.start=t.start,this.shift=t.shift||C,this.reduce=t.reduce||C,this.reuse=t.reuse||C,this.hash=t.hash||(()=>0),this.strict=t.strict!==!1}}class w extends L{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let n=0;n<t.repeatNodeCount;n++)e.push("");let s=Object.keys(t.topRules).map(n=>t.topRules[n][1]),i=[];for(let n=0;n<e.length;n++)i.push([]);function h(n,o,a){i[n].push([o,o.deserialize(String(a))])}if(t.nodeProps)for(let n of t.nodeProps){let o=n[0];typeof o=="string"&&(o=y[o]);for(let a=1;a<n.length;){let u=n[a++];if(u>=0)h(u,o,n[a++]);else{let f=n[a+-u];for(let d=-u;d>0;d--)h(n[a++],o,f);a++}}}this.nodeSet=new $(e.map((n,o)=>E.define({name:o>=this.minRepeatTerm?void 0:n,id:o,props:i[o],top:s.indexOf(o)>-1,error:o==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(o)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=j;let r=x(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let n=0;n<this.specializerSpecs.length;n++)this.specialized[n]=this.specializerSpecs[n].term;this.specializers=this.specializerSpecs.map(F),this.states=x(t.states,Uint32Array),this.data=x(t.stateData),this.goto=x(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(n=>typeof n=="number"?new m(r,n):n),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,s){let i=new Q(this,t,e,s);for(let h of this.wrappers)i=h(i,t,e,s);return i}getGoto(t,e,s=!1){let i=this.goto;if(e>=i[0])return-1;for(let h=i[e+1];;){let r=i[h++],n=r&1,o=i[h++];if(n&&s)return o;for(let a=h+(r>>1);h<a;h++)if(i[h]==t)return o;if(n)return-1}}hasAction(t,e){let s=this.data;for(let i=0;i<2;i++)for(let h=this.stateSlot(t,i?2:1),r;;h+=3){if((r=s[h])==65535)if(s[h+1]==1)r=s[h=k(s,h+2)];else{if(s[h+1]==2)return k(s,h+2);break}if(r==e||r==0)return k(s,h+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,s=>s==e?!0:null)}allActions(t,e){let s=this.stateSlot(t,4),i=s?e(s):void 0;for(let h=this.stateSlot(t,1);i==null;h+=3){if(this.data[h]==65535)if(this.data[h+1]==1)h=k(this.data,h+2);else break;i=e(k(this.data,h+1))}return i}nextStates(t){let e=[];for(let s=this.stateSlot(t,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=k(this.data,s+2);else break;if((this.data[s+2]&1)==0){let i=this.data[s+1];e.some((h,r)=>r&1&&h==i)||e.push(this.data[s],i)}}return e}configure(t){let e=Object.assign(Object.create(w.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let s=this.topRules[t.top];if(!s)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=s}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(s=>{let i=t.tokenizers.find(h=>h.from==s);return i?i.to:s})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((s,i)=>{let h=t.specializers.find(n=>n.from==s.external);if(!h)return s;let r=Object.assign(Object.assign({},s),{external:h.to});return e.specializers[i]=F(r),r})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),s=e.map(()=>!1);if(t)for(let h of t.split(" ")){let r=e.indexOf(h);r>=0&&(s[r]=!0)}let i=null;for(let h=0;h<e.length;h++)if(!s[h])for(let r=this.dialects[e[h]],n;(n=this.data[r++])!=65535;)(i||(i=new Uint8Array(this.maxTerm+1)))[n]=1;return new V(t,s,i)}static deserialize(t){return new w(t)}}function k(l,t){return l[t]|l[t+1]<<16}function X(l){let t=null;for(let e of l){let s=e.p.stoppedAt;(e.pos==e.p.stream.end||s!=null&&e.pos>s)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function F(l){if(l.external){let t=l.extend?1:0;return(e,s)=>l.external(e,s)<<1|t}return l.get}export{_ as C,Z as E,w as L,W as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{G as t,j as e,J as l,K as i,B as r}from"./index-
|
|
1
|
+
import{G as t,j as e,J as l,K as i,B as r}from"./index-BCGiD7pg.js";import{T as x,L as p,N as u}from"./index-BCGiD7pg.js";function d(){const{pendingOffer:s,pendingOfferId:a,acceptOffer:n,declineOffer:o}=t();return!s||a===null||!s.offerLine?null:e.jsxs(l.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},role:"group","aria-label":"DorkBot suggestion",className:"bg-secondary/60 mt-1.5 flex flex-col gap-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"mt-0.5 shrink-0",children:[e.jsx(i,{size:18,className:"dark:hidden"}),e.jsx(i,{variant:"white",size:18,className:"hidden dark:block"})]}),e.jsx("p",{className:"text-sm leading-relaxed",children:s.offerLine})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-6",children:[e.jsx(r,{size:"sm",onClick:()=>n(a),children:"Show me"}),e.jsx(r,{size:"sm",variant:"ghost",onClick:()=>o(a),children:"Later"})]})]})}export{x as TOUR_DEFINITIONS,p as TourHost,d as TourOfferChips,u as useTourOccasions,t as useTours};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{dT as Se,gi as Me,af as ne,r as a,gj as Ie,gk as Q,gl as G,gm as K,d_ as ie,gn as Ce,cS as J,go as ee,dj as it,gp as lt,bm as ct,gq as dt,aj as oe,gr as ut,gs as ft,eT as ht,gt as pt,ag as Te,gu as mt,j as t,aF as Fe,am as Ke,cW as xt,C as He,gv as gt,dB as be,gw as yt,fR as Ue,fW as vt,al as Oe,gx as qe,gy as Qe,gz as Ct,f3 as bt,f4 as wt,f5 as kt,f6 as Z,f7 as ue,dQ as jt,eh as fe,ei as he,ej as pe,ek as me,el as xe,em as ge,en as ye,eo as ve,B as Y,aG as Et,gA as Ae,g0 as Dt,gB as Rt,ai as ce,gC as Be,gD as We,d4 as Nt,gE as St,gF as Tt,gG as Ft,gH as Ot,e5 as De,gI as Ye,dh as Pt,dU as Mt,cU as At,gJ as _t,gK as Lt,g5 as zt,gL as $t,dW as It,dX as Kt,dY as Ht,dZ as Ut,d$ as qt,e0 as Qt,I as Bt,e1 as Wt}from"./index-BCGiD7pg.js";import{t as ae,g as Yt,C as Gt,n as Ge,r as Ve,a as Vt,p as Xt,F as Zt,w as Jt,c as Xe,b as en}from"./room-files-source-DRQNpCWs.js";import{N as Qn,R as Bn}from"./room-files-source-DRQNpCWs.js";/**
|
|
2
2
|
* @license lucide-react v1.47.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const Ze={name:"corner-left-up",size:24,node:[["path",{d:"M14 9 9 4 4 9",key:"1af5af"}],["path",{d:"M20 20h-7a4 4 0 0 1-4-4V4",key:"1blwi3"}]]};Ze.node;const tn=Se(Ze);/**
|
|
7
7
|
* @license lucide-react v1.47.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
@@ -13,5 +13,5 @@ import{dR as Se,gg as Me,af as ne,r as a,gh as Ie,gi as Q,gj as G,gk as K,dY as
|
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const tt={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};tt.node;const nn=Se(tt);function le(e,n,s){return["file-explorer","tree",e.scopeKey,n,e.filtersHidden?s:null]}function ke(e,n,s,m){return{queryKey:le(e,n,s),queryFn:()=>e.list(n,{showHidden:s}),staleTime:Me.FILE_TREE_STALE_TIME_MS,gcTime:Me.FILE_TREE_GC_TIME_MS,placeholderData:p=>p??m.getQueryData(le(e,n,!s))}}const sn=[".git",".dork",".claude",".agents","node_modules"];function an(e){return e.startsWith(".")||sn.includes(e)}const Re=["ROOM.md","README.md"];function Ne(e){return Re.some(n=>n.toLowerCase()===e.toLowerCase())}function nt(e){return e.filter(n=>!an(n.name))}function rn(e){if(e.reduce((p,i)=>i.type==="file"&&Ne(i.name)?p+1:p,0)===0)return e;const s=[],m=[];for(const p of e)p.type==="file"&&Ne(p.name)?s.push(p):m.push(p);return s.sort((p,i)=>Re.findIndex(o=>o.toLowerCase()===p.name.toLowerCase())-Re.findIndex(o=>o.toLowerCase()===i.name.toLowerCase())),[...s,...m]}const on=/ copy(?: \d+)?$/;function Pe({name:e,isDir:n,taken:s}){const m=new Set(s);if(!m.has(e))return e;const p=n?-1:e.lastIndexOf("."),i=p>0,o=i?e.slice(p):"",g=(i?e.slice(0,p):e).replace(on,"");for(let r=1;;r+=1){const d=r===1?`${g} copy${o}`:`${g} copy ${r}${o}`;if(!m.has(d))return d}}function Ae(e,n,s){return{name:n,path:e,type:s,size:0,mtime:Date.now(),isSymlink:!1}}function ln(e){const n=ne(),{source:s,showHidden:m,queryClient:p,inFlightRef:i}=e,o=s.cwd??"",[g,r]=a.useState(null),d=a.useCallback(async h=>{i.current+=1;try{return await h()}finally{i.current-=1}},[i]),c=a.useMemo(()=>{const h=x=>le(s,x,m);return{getChildren:x=>{var j;return((j=p.getQueryData(h(x)))==null?void 0:j.entries)??[]},isLoaded:x=>p.getQueryData(h(x))!==void 0,takenNames:async x=>(await n.readFileTree(o,{path:x===Q?void 0:x,showHidden:!0})).entries.map(C=>C.name),snapshot:x=>p.getQueryData(h(x)),setChildren:(x,j)=>{p.setQueryData(h(x),C=>({entries:Ie(j((C==null?void 0:C.entries)??[]))}))},restore:(x,j)=>{p.setQueryData(h(x),j)},invalidate:x=>{p.invalidateQueries({queryKey:h(x),exact:!0})}}},[p,n,o,s,m]),D=a.useCallback((h,x,j)=>d(async()=>{const C=ee(h,x),S=!c.getChildren(h).some(A=>A.path===C),I=c.snapshot(h);S&&c.setChildren(h,A=>[...A,Ae(C,x,j)]);try{return await n.createEntry(o,C,j),!0}catch(A){return S&&c.restore(h,I),ae(A,`Couldn’t create ${j==="dir"?"folder":"file"}`),!1}finally{c.invalidate(h)}}),[n,o,c,d]),M=a.useCallback((h,x)=>d(async()=>{if(x===h.name||x.length===0)return!0;const j=G(h.path),C=ee(j,x),S=c.getChildren(j).some(_=>_.path===C),I=c.snapshot(j),A={...h,name:x,path:C};S||c.setChildren(j,_=>_.map(L=>L.path===h.path?A:L));try{return await n.renameEntry(o,h.path,C),K.getState().remapExpandedPaths(h.path,C),!0}catch(_){return S||c.restore(j,I),ae(_,"Couldn’t rename"),!1}finally{c.invalidate(j)}}),[n,o,c,d]),R=a.useCallback(h=>d(async()=>{const x=G(h.path),j=c.snapshot(x);c.setChildren(x,C=>C.filter(S=>S.path!==h.path));try{await n.deleteEntry(o,h.path,{recursive:!0}),K.getState().dropExpandedPaths(h.path)}catch(C){c.restore(x,j),ae(C,"Couldn’t delete")}finally{c.invalidate(x)}}),[n,o,c,d]),q=a.useCallback(h=>d(async()=>{const x=G(h.path);if(h.type==="file"){const j=c.snapshot(x);c.setChildren(x,C=>C.filter(S=>S.path!==h.path));try{await n.deleteEntry(o,h.path),K.getState().dropExpandedPaths(h.path)}catch(C){c.restore(x,j),ae(C,"Couldn’t delete")}finally{c.invalidate(x)}return}try{await n.deleteEntry(o,h.path),c.setChildren(x,j=>j.filter(C=>C.path!==h.path)),K.getState().dropExpandedPaths(h.path),c.invalidate(x)}catch(j){if(Wt(j)==="DIR_NOT_EMPTY"){r(h);return}ae(j,"Couldn’t delete")}}),[n,o,c,d]),b=a.useCallback(async()=>{const h=g;r(null),h&&await R(h)},[g,R]),H=a.useCallback(()=>r(null),[]),$=a.useCallback((h,x)=>d(async()=>{const j=G(h),C=ie(h),S=ee(x,C);if(x===j||S===h||Ce(x,h))return;const I=c.getChildren(j).find(v=>v.path===h);if(!I)return;const A=c.isLoaded(x),_=A&&c.getChildren(x).some(v=>v.path===S),L={...I,name:C,path:S},Y=c.snapshot(j),F=A?c.snapshot(x):void 0;c.setChildren(j,v=>v.filter(z=>z.path!==h)),A&&!_&&c.setChildren(x,v=>[...v,L]);try{await n.renameEntry(o,h,S),K.getState().remapExpandedPaths(h,S)}catch(v){c.restore(j,Y),A&&!_&&c.restore(x,F),ae(v,"Couldn’t move")}finally{c.invalidate(j),A&&c.invalidate(x)}}),[n,o,c,d]),k=a.useCallback((h,x)=>d(async()=>{if(h.isDir&&Ce(x,h.path)){J.error(Gt);return}let j;try{j=await c.takenNames(x)}catch(_){ae(_,"Couldn’t copy");return}const C=Pe({name:ie(h.path),isDir:h.isDir,taken:j}),S=ee(x,C),I=c.isLoaded(x),A=I?c.snapshot(x):void 0;if(I){const _=c.getChildren(G(h.path)).find(Y=>Y.path===h.path),L=_?{..._,name:C,path:S}:Ae(S,C,h.isDir?"dir":"file");c.setChildren(x,Y=>[...Y,L])}try{await n.copyEntry(o,h.path,S)}catch(_){I&&c.restore(x,A),ae(_,"Couldn’t copy")}finally{c.invalidate(x)}}),[n,o,c,d]);return{createEntry:D,renameEntry:M,removeEntry:q,moveEntry:$,copyEntry:k,pendingRecursiveDelete:g,confirmRecursiveDelete:b,cancelRecursiveDelete:H}}function cn(e){return e!=null&&e.startsWith("darwin")?"Reveal in Finder":e!=null&&e.startsWith("win32")?"Reveal in File Explorer":"Show in File Manager"}function dn(e,n){const s=e.includes("\\")&&!e.includes("/"),m=e.replace(/[\\/]+$/,""),p=s?n.split("/").join("\\"):n;return`${m}${s?"\\":"/"}${p}`}function un(e){const n=ne(),{data:s}=it(),m=a.useMemo(()=>n.supportsReveal?cn(s==null?void 0:s.platform):null,[n.supportsReveal,s==null?void 0:s.platform]),p=a.useCallback(async d=>{if(e)try{await n.revealEntry(e,d.path)}catch(c){ae(c,"Couldn’t open the file manager")}},[n,e]),{copy:i}=lt(),o=a.useCallback(async(d,c)=>{const D=c==="absolute"&&e?dn(e,d.path):d.path;await i(D)||J.error("Couldn’t copy to the clipboard")},[e,i]),g=a.useCallback(d=>{ct(dt(d.path))||J.error("Open a chat first to add a file to it")},[]),r=a.useCallback(d=>{K.getState().setClipboard({path:d.path,isDir:d.type==="dir"});try{navigator.clipboard.writeText(d.path).catch(()=>{})}catch{}},[]);return{revealLabel:m,reveal:p,copyPath:o,addToChat:g,copyToClipboard:r}}const fn=1e3;function hn(e){const{source:n,showHidden:s,queryClient:m,inFlightRef:p}=e,i=n.changes,[o,g]=a.useState(null),[r,d]=a.useState(null),[c,D]=a.useState(null),[M,R]=a.useState(0),q=a.useCallback(async u=>{p.current+=1,R(f=>f+1);try{return await u()}finally{p.current-=1,R(f=>f-1)}},[p]),b=a.useMemo(()=>{const u=f=>le(n,f,s);return{listing:f=>m.getQueryData(u(f)),isLoaded:f=>m.getQueryData(u(f))!==void 0,entries:f=>{var T;return((T=m.getQueryData(u(f)))==null?void 0:T.entries)??[]},setEntries:(f,T)=>m.setQueryData(u(f),y=>({...y,entries:Ie(T((y==null?void 0:y.entries)??[]))})),restore:(f,T)=>m.setQueryData(u(f),T),fetch:f=>n.list(f,{showHidden:!0}),refreshAll:()=>{m.invalidateQueries({queryKey:["file-explorer","tree",n.scopeKey]}),m.invalidateQueries({queryKey:["file-explorer","preview",n.scopeKey]})}}},[m,n,s]),H=a.useCallback(async u=>{const f=b.listing(u);return(f==null?void 0:f.commit)!==void 0?f.commit:(await b.fetch(u)).commit??null},[b]),$=a.useCallback((u,f,T,y)=>{switch(u.status){case"changed":return!0;case"conflict":return D({kind:f,path:u.path,lastCommit:u.lastCommit,retry:()=>T(u.commit)}),!1;case"exists":return J.error(y===void 0?u.reason:Ge(y)),!1;case"refused":return J.error(u.reason),!1}},[]),k=a.useCallback((u,f)=>{J.error(Ve(u)??f)},[]),h=a.useCallback((u,f,T)=>{const y=O=>q(async()=>{if(i===void 0)return!1;const E=G(u.path),N=G(f),w=ie(f),U=b.isLoaded(N),te=U&&b.entries(N).some(Z=>Z.path===f),V=b.listing(E),de=N===E?void 0:b.listing(N),l={...u,name:w,path:f};te||(N===E?b.setEntries(E,Z=>Z.map(se=>se.path===u.path?l:se)):(b.setEntries(E,Z=>Z.filter(se=>se.path!==u.path)),U&&b.setEntries(N,Z=>[...Z,l])));const P=()=>{b.restore(E,V),N!==E&&U&&b.restore(N,de)};try{const Z=O??await H(E);if(Z===null)return P(),J.error("There’s nothing in this room’s files to change yet."),!1;const se=await i.move({from:u.path,to:f,baseCommit:Z}),je=$(se,T,async re=>{await y(re)},w);return je?K.getState().remapExpandedPaths(u.path,f):P(),je}catch(Z){return P(),k(Z,T==="rename"?"Couldn’t rename":"Couldn’t move"),!1}finally{b.refreshAll()}});return y(null)},[i,b,q,H,$,k]),x=a.useCallback(async(u,f)=>f===u.name||f.length===0?!0:h(u,ee(G(u.path),f),"rename"),[h]),j=a.useCallback(async(u,f)=>{const T=G(u),y=ee(f,ie(u));if(f===T||y===u||Ce(f,u))return;const O=b.entries(T).find(E=>E.path===u);O&&await h(O,y,"move")},[b,h]),C=a.useCallback(async u=>{let f=0;const T=[u];for(;T.length>0;){const y=T.shift(),O=await b.fetch(y);for(const E of O.entries)if(E.type==="dir"?T.push(E.path):f+=1,f>=fn)return{count:f,moreThan:!0}}return{count:f,moreThan:!1}},[b]),S=a.useCallback(u=>{if(u.type!=="dir"){g({entry:u,fileCount:1,moreThan:!1});return}g({entry:u,fileCount:null,moreThan:!1}),C(u.path).then(({count:f,moreThan:T})=>g(y=>(y==null?void 0:y.entry.path)===u.path?{entry:u,fileCount:f,moreThan:T}:y),()=>{})},[C]),I=a.useCallback(u=>{const f=T=>q(async()=>{if(i===void 0)return;const y=G(u.path),O=b.listing(y);b.setEntries(y,E=>E.filter(N=>N.path!==u.path));try{const E=T??await H(y);if(E===null){b.restore(y,O);return}const N=await i.remove({path:u.path,baseCommit:E});$(N,"delete",U=>f(U))?K.getState().dropExpandedPaths(u.path):b.restore(y,O)}catch(E){b.restore(y,O),k(E,"Couldn’t delete")}finally{b.refreshAll()}});return f(null)},[i,b,q,H,$,k]),A=a.useCallback(async()=>{const u=o;g(null),u&&await I(u.entry)},[o,I]),_=a.useCallback(()=>g(null),[]),L=a.useCallback((u,f,T,y)=>{const O=E=>q(async()=>{if(i===void 0)return;const N=b.isLoaded(u),w=N?b.listing(u):void 0;if(N){const U=new Set(b.entries(u).map(V=>V.name)),te=f.filter(V=>!U.has(V.name)).map(V=>({name:V.name,path:ee(u,V.name),type:"file",size:V.size}));te.length>0&&b.setEntries(u,V=>[...V,...te])}try{const U=await i.upload({dir:u,baseCommit:E,replace:T,files:f});!$(U,"upload",V=>O(V))&&N&&b.restore(u,w)}catch(U){N&&b.restore(u,w),k(U,"Couldn’t upload")}finally{b.refreshAll()}});return O(y)},[i,b,q,$,k]),Y=a.useCallback(async(u,f)=>{if(i===void 0||f.length===0)return;if(f.length>i.maxUploadFiles){J.error(`One upload can carry up to ${i.maxUploadFiles} files, so nothing was uploaded. Try again with fewer.`);return}let T;try{T=await b.fetch(u)}catch(w){k(w,"Couldn’t upload");return}const y=T.entries.map(w=>w.name),O=new Set(y),E=f.map(w=>w.name).filter(w=>O.has(w)),N=T.commit??null;if(E.length===0){await L(u,f,[],N);return}d({dir:u,files:f,names:E,taken:y,baseCommit:N})},[i,b,k,L]),F=a.useCallback(async u=>{const f=r;if(d(null),f===null)return;if(u==="replace"){await L(f.dir,f.files,f.names,f.baseCommit);return}const T=new Set([...f.taken,...f.files.map(E=>E.name)]),y=new Set(f.names),O=f.files.map(E=>{if(!y.has(E.name))return E;const N=Pe({name:E.name,isDir:!1,taken:T});return T.add(N),new File([E],N,{type:E.type,lastModified:E.lastModified})});await L(f.dir,O,[],f.baseCommit)},[r,L]),v=a.useCallback(()=>d(null),[]),z=a.useCallback(()=>D(null),[]),B=a.useMemo(()=>r===null?null:{dir:r.dir,names:r.names},[r]);return{renameEntry:x,moveEntry:j,requestDelete:S,pendingDelete:o,confirmDelete:A,cancelDelete:_,upload:Y,pendingClash:B,resolveClash:F,cancelClash:v,conflict:c,dismissConflict:z,busy:M>0}}const ze={scopeKey:"",cwd:null,writable:!1,provenance:!1,filtersHidden:!0,preview:"canvas",editable:!1,list:()=>Promise.resolve({entries:[]})};function pn(e){var u,f,T;const n=ne(),s=oe(),{setTheme:m}=ut(),p=K(y=>y.showHidden),i=K(y=>y.expanded),o=K(y=>y.loadExplorerForCwd),g=K(y=>y.pruneMissing),r=(e==null?void 0:e.scopeKey)??null,d=(e==null?void 0:e.cwd)??null;a.useEffect(()=>{o(r)},[r,o]);const c=a.useMemo(()=>[Q,...ft(i)],[i]),D=ht({queries:e?c.map(y=>ke(e,y,p,s)):[]}),M=(e==null?void 0:e.filtersHidden)??!0,R=a.useMemo(()=>{const y={};return c.forEach((O,E)=>{var U;const N=D[E];let w=((U=N==null?void 0:N.data)==null?void 0:U.entries)??[];!p&&!M&&(w=nt(w)),O===Q&&(w=rn(w)),y[O]={entries:w,loading:(N==null?void 0:N.isLoading)??!1,error:(N==null?void 0:N.isError)??!1}}),y},[c,D,p,M]),q=a.useRef(0),b=a.useRef({});a.useEffect(()=>{q.current>0||c.forEach((y,O)=>{var N,w,U;const E=(w=(N=D[O])==null?void 0:N.data)==null?void 0:w.entries;!E||(U=D[O])!=null&&U.isError||b.current[y]!==E&&(b.current[y]=E,g(y,E.map(te=>te.name)))})},[c,D,g]);const H=a.useMemo(()=>pt(i,R),[i,R]),$=!!e&&!!((u=R[Q])!=null&&u.loading),k=!!e&&!!((f=R[Q])!=null&&f.error),h=(T=D[0])==null?void 0:T.error,x=k&&h?Vt(h):void 0,j=(x==null?void 0:x.message)??null,C=(x==null?void 0:x.command)??null,S=a.useMemo(()=>{var O;const y=new Set;for(const E of c)E!==Q&&((O=R[E])!=null&&O.error)&&y.add(E);return y},[c,R]),I=a.useCallback(y=>{if(y.type!=="dir")return;const O=K.getState();O.setDirExpanded(y.path,!O.expanded[y.path])},[]),A=a.useCallback(y=>{if(y===Q)return;const O=K.getState();O.expanded[y]||O.setDirExpanded(y,!0)},[]),_=(e==null?void 0:e.preview)==="canvas",L=a.useCallback(y=>{if(y.type!=="file"||!_)return;const O={getStore:Te.getState,setTheme:m,supportsTerminal:n.supportsTerminal};mt(O,{action:"open_file",sourcePath:y.path},"user")},[_,m,n]),Y=a.useCallback(()=>{r!==null&&s.invalidateQueries({queryKey:["file-explorer","tree",r]})},[s,r]),F=a.useCallback(y=>{e!==null&&s.invalidateQueries({queryKey:le(e,y,p),exact:!0})},[s,e,p]);a.useEffect(()=>{if(e!=null&&e.events)return e.events(Y)},[e,Y]);const v=ln({source:e??ze,showHidden:p,queryClient:s,inFlightRef:q}),z=hn({source:e??ze,showHidden:p,queryClient:s,inFlightRef:q}),B=un(d);return{rows:H,rootLoading:$,rootError:k,rootErrorMessage:j,rootErrorCommand:C,errorPaths:S,toggleExpand:I,ensureExpanded:A,openFile:L,reload:Y,retryDir:F,changes:e!=null&&e.changes?z:null,...v,...B}}function mn(e){const{transport:n,cwd:s}=e;return{scopeKey:s,cwd:s,writable:!0,provenance:!1,filtersHidden:!0,preview:"canvas",editable:!1,list(m,p){return n.readFileTree(s,{path:m===""?void 0:m,showHidden:p.showHidden})}}}function we(e){return Array.from(e).includes("Files")}function st(e){const n=Array.from(e.items??[]);if(!(n.length>0&&n.every(i=>"webkitGetAsEntry"in i)))return{files:Array.from(e.files??[]),folders:0};const m=[];let p=0;for(const i of n){if(i.kind!=="file")continue;const o=i.webkitGetAsEntry();if(o!=null&&o.isDirectory){p+=1;continue}const g=i.getAsFile();g&&m.push(g)}return{files:m,folders:p}}const xn=12;function gn({row:e,selected:n,renaming:s,error:m,onSelect:p,onActivate:i,onRetry:o,onSubmitRename:g,onCancelRename:r,onNewFile:d,onNewFolder:c,onStartRename:D,onDelete:M,onMove:R,onCopyInto:q,onCopy:b,onPaste:H,onDuplicate:$,canPasteInto:k,revealLabel:h,onReveal:x,onAddToChat:j,onCopyPath:C,readOnly:S=!1,provenance:I=!1,copyable:A=!0,onDisk:_=!0,onUpload:L,onPickUpload:Y}){const{entry:F,depth:v,expanded:z,loading:B}=e,u=F.type==="dir",f=u?F.path:G(F.path),[T,y]=a.useState(!1),O=!u&&v===0&&Ne(F.name),E=Zt(F.lastCommit),N=t.jsxs("div",{role:"treeitem","aria-label":F.name,"aria-expanded":u?z:void 0,"aria-selected":n,tabIndex:-1,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),p(F),i(F))},draggable:!s&&!S,onDragStart:w=>{S||(w.dataTransfer.setData("text/plain",F.path),w.dataTransfer.setData(Ct,F.path),w.dataTransfer.effectAllowed="copyMove")},onDragOver:w=>{if(w.stopPropagation(),!S&&L&&we(w.dataTransfer.types)){w.preventDefault(),w.dataTransfer.dropEffect="copy",y(!0);return}S||!u||!Qe(w.dataTransfer.types)||(w.preventDefault(),w.dataTransfer.dropEffect=w.altKey&&A?"copy":"move",y(!0))},onDragLeave:()=>y(!1),onDrop:w=>{if(w.stopPropagation(),S)return;if(y(!1),L&&we(w.dataTransfer.types)){w.preventDefault();const{files:te}=st(w.dataTransfer);L(f,te);return}if(!u)return;const U=qe(w.dataTransfer);U!==null&&(w.preventDefault(),w.altKey&&A?q(U,F.path):R(U,F.path))},onClick:()=>{p(F),i(F)},className:Oe("flex w-full cursor-pointer items-center gap-1 py-1 pr-2 text-sm transition-colors",n?"bg-accent text-foreground":"hover:bg-accent/50",T&&"ring-ring/60 bg-accent ring-1"),style:{paddingLeft:v*xn+8},children:[t.jsx("span",{className:"flex size-4 flex-shrink-0 items-center justify-center",children:u&&(B?t.jsx(Fe,{size:"xs",className:"text-muted-foreground"}):m?t.jsx("button",{type:"button","aria-label":"Retry loading",title:"Couldn’t load. Retry",onClick:w=>{w.stopPropagation(),o()},className:"flex items-center justify-center",children:t.jsx(Ke,{className:"text-destructive size-3.5"})}):z?t.jsx(xt,{className:"text-muted-foreground size-3.5"}):t.jsx(He,{className:"text-muted-foreground size-3.5"}))}),u?z?t.jsx(gt,{className:"size-(--size-icon-sm) flex-shrink-0 text-sky-500"}):t.jsx(be,{className:"size-(--size-icon-sm) flex-shrink-0 text-sky-500"}):F.isSymlink===!0?t.jsx(yt,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}):t.jsx(Ue,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}),s?t.jsx(yn,{initialName:F.name,onSubmit:w=>g(F,w),onCancel:r}):t.jsx("span",{className:"min-w-0 flex-1 truncate",children:F.name}),O&&!s&&t.jsx(vt,{"aria-label":"Pinned to the top",className:"text-muted-foreground/60 size-3 flex-shrink-0"}),I&&!s&&t.jsx("span",{className:"text-muted-foreground/70 text-2xs max-w-[45%] flex-shrink-0 truncate tabular-nums",title:E.title??void 0,children:E.label})]});return S?N:t.jsxs(bt,{children:[t.jsx(wt,{asChild:!0,children:N}),t.jsxs(kt,{className:"w-52",children:[t.jsx(X,{movesFocus:!0,onClick:()=>d(f),children:"New file"}),t.jsx(X,{movesFocus:!0,onClick:()=>c(f),children:"New folder"}),Y&&t.jsx(X,{onClick:()=>Y(f),children:"Upload files…"}),_&&t.jsxs(t.Fragment,{children:[t.jsx(ue,{}),h&&t.jsx(X,{onClick:()=>x(F),children:h}),t.jsx(X,{movesFocus:!0,onClick:()=>j(F),children:"Add to chat"})]}),A&&t.jsxs(t.Fragment,{children:[t.jsx(ue,{}),t.jsx(X,{onClick:()=>b(F),children:"Copy"}),t.jsx(X,{disabled:!k(f),onClick:()=>H(f),children:"Paste"}),t.jsx(X,{onClick:()=>$(F),children:"Duplicate"})]}),t.jsx(ue,{}),_?t.jsxs(t.Fragment,{children:[t.jsx(X,{onClick:()=>C(F,"absolute"),children:"Copy path"}),t.jsx(X,{onClick:()=>C(F,"relative"),children:"Copy relative path"})]}):t.jsx(X,{onClick:()=>C(F,"relative"),children:"Copy path"}),t.jsx(ue,{}),t.jsx(X,{movesFocus:!0,onClick:()=>D(F),children:"Rename"}),t.jsx(X,{variant:"destructive",onClick:()=>M(F),children:"Delete"})]})]})}function yn({initialName:e,onSubmit:n,onCancel:s}){const m=a.useRef(null),[p,i]=a.useState(e);a.useEffect(()=>{const g=m.current;if(!g)return;g.focus();const r=e.lastIndexOf(".");g.setSelectionRange(0,r>0?r:e.length)},[e]);const o=()=>{const g=p.trim();g&&g!==e?n(g):s()};return t.jsx("input",{ref:m,type:"text",value:p,"aria-label":"New name",onChange:g=>i(g.target.value),onClick:g=>g.stopPropagation(),onBlur:o,onKeyDown:g=>{g.stopPropagation(),g.key==="Enter"?o():g.key==="Escape"&&s()},className:"border-border bg-background min-w-0 flex-1 rounded border px-1 py-0 text-sm outline-none"})}const vn=100,Cn=28,bn=250;function wn(e){const{rows:n,selectedPath:s,renamingPath:m,errorPaths:p,onSelectPath:i,onRetryDir:o}=e,g=a.useRef(null),r=K(v=>v.setScrollTop),d=K(v=>v.scopeKey),c=a.useCallback(v=>v.type==="dir"?e.onToggle(v):e.onOpen(v),[e]),D=jn(e,c),M=n.length>vn,R=jt({count:n.length,getScrollElement:()=>g.current,estimateSize:()=>Cn,overscan:12,enabled:M}),q=a.useRef({scope:void 0,done:!1}),b=a.useRef(null);a.useLayoutEffect(()=>{const v=q.current;if(v.scope!==d&&(v.scope=d,v.done=!1),v.done||n.length===0)return;const z=g.current;if(!z)return;const B=K.getState().scrollTop;if(B<=0){v.done=!0;return}M?R.scrollToOffset(B):z.scrollTop=B,b.current=z.scrollTop,z.scrollTop>=B&&(v.done=!0)},[n.length,d,M,R]);const H=a.useRef(null),$=a.useRef(null),k=a.useCallback(()=>{const v=g.current;v&&v.scrollTop!==b.current&&(q.current.done=!0,H.current=v.scrollTop,$.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,H.current!==null&&r(H.current)},bn))},[r]);a.useEffect(()=>()=>{$.current&&clearTimeout($.current),H.current!==null&&r(H.current)},[r]);const h=a.useRef(void 0);a.useEffect(()=>{var u,f;const v=h.current;if(h.current=s,v===void 0||s===v||s===null)return;const z=n.findIndex(T=>T.entry.path===s);if(z<0)return;const B=g.current;B&&(M?R.scrollToIndex(z,{align:"auto"}):(f=(u=B.querySelector(`[data-row-index="${z}"]`))==null?void 0:u.scrollIntoView)==null||f.call(u,{block:"nearest"}),b.current=B.scrollTop)},[s,n,M,R]);const[x,j]=a.useState(!1),{onCopyInto:C,onMove:S}=e,I=e.readOnly===!0,A=e.copyable!==!1,_=a.useCallback(v=>{I||!Qe(v.dataTransfer.types)||(v.preventDefault(),v.dataTransfer.dropEffect=v.altKey&&A?"copy":"move",j(!0))},[I,A]),L=a.useCallback((v,z)=>{const B=n.find(u=>u.entry.path===v);B&&C({path:v,isDir:B.entry.type==="dir"},z)},[n,C]),Y=a.useCallback(v=>{if(j(!1),I)return;const z=qe(v.dataTransfer);z!==null&&(v.preventDefault(),v.altKey&&A?L(z,Q):S(z,Q))},[L,S,I,A]),F=v=>t.jsx(gn,{row:v,selected:v.entry.path===s,renaming:v.entry.path===m,error:v.entry.type==="dir"&&v.expanded&&p.has(v.entry.path),onSelect:z=>i(z.path),onActivate:c,onRetry:()=>o(v.entry.path),onSubmitRename:e.onSubmitRename,onCancelRename:e.onCancelRename,onStartRename:e.onStartRename,onNewFile:e.onNewFile,onNewFolder:e.onNewFolder,onDelete:e.onDelete,onMove:e.onMove,onCopyInto:L,onCopy:e.onCopy,onPaste:e.onPaste,onDuplicate:e.onDuplicate,canPasteInto:e.canPasteInto,revealLabel:e.revealLabel,onReveal:e.onReveal,onAddToChat:e.onAddToChat,onCopyPath:e.onCopyPath,readOnly:e.readOnly,provenance:e.provenance,copyable:e.copyable,onDisk:e.onDisk,onUpload:e.onUpload,onPickUpload:e.onPickUpload});return t.jsx("div",{ref:g,role:"tree","aria-label":"File explorer",tabIndex:0,onKeyDown:D,onScroll:k,onDragOver:_,onDragLeave:()=>j(!1),onDrop:Y,className:Oe("focus-visible:ring-ring/40 h-full overflow-auto outline-none focus-visible:ring-1 focus-visible:ring-inset",x&&"ring-ring/60 bg-accent/30 ring-1 ring-inset"),children:M?t.jsx("div",{style:{height:R.getTotalSize()},className:"relative w-full",children:R.getVirtualItems().map(v=>t.jsx("div",{"data-row-index":v.index,className:"absolute top-0 left-0 w-full",style:{transform:`translateY(${v.start}px)`},children:F(n[v.index])},n[v.index].entry.path))}):n.map((v,z)=>t.jsx("div",{"data-row-index":z,children:F(v)},v.entry.path))})}function kn(e){return e?e.type==="dir"?e.path:G(e.path):Q}function jn(e,n){const{rows:s,selectedPath:m,renamingPath:p,onSelectPath:i}=e;return a.useCallback(o=>{var d,c,D,M;if(p!==null)return;const g=s.findIndex(R=>R.entry.path===m),r=g>=0?s[g]:void 0;if(o.metaKey||o.ctrlKey){if(e.readOnly===!0||e.copyable===!1)return;const R=o.key.toLowerCase();if(R==="c"&&r){o.preventDefault(),e.onCopy(r.entry);return}if(R==="v"){o.preventDefault(),e.onPaste(kn(r==null?void 0:r.entry));return}return}switch(o.key){case"ArrowDown":o.preventDefault(),i(((d=s[Math.min(g+1,s.length-1)])==null?void 0:d.entry.path)??((c=s[0])==null?void 0:c.entry.path));break;case"ArrowUp":o.preventDefault(),i(((D=s[Math.max(g-1,0)])==null?void 0:D.entry.path)??((M=s[0])==null?void 0:M.entry.path));break;case"ArrowRight":(r==null?void 0:r.entry.type)==="dir"&&!r.expanded&&(o.preventDefault(),e.onToggle(r.entry));break;case"ArrowLeft":if(!r)break;if(o.preventDefault(),r.entry.type==="dir"&&r.expanded)e.onToggle(r.entry);else{const R=G(r.entry.path);R&&i(R)}break;case"Enter":r&&(o.preventDefault(),n(r.entry));break;case"F2":r&&e.readOnly!==!0&&(o.preventDefault(),e.onStartRename(r.entry));break;case"Delete":case"Backspace":r&&e.readOnly!==!0&&(o.preventDefault(),e.onDelete(r.entry));break}},[s,m,p,i,e,n])}const En={rename:"Rename it anyway",move:"Move it anyway",delete:"Delete it anyway",upload:"Upload mine over it"},Dn={rename:"nothing was renamed",move:"nothing was moved",delete:"nothing was deleted",upload:"nothing was uploaded"};function Rn(e){const{entry:n,fileCount:s,moreThan:m}=e,p="The room’s history keeps a copy, so an agent or git can bring it back if you need it.";if(n.type!=="dir")return`“${n.name}” leaves the room’s files. ${p}`;const i=s===null?"everything in it":m?`the more than ${s.toLocaleString()} files in it`:s===1?"the 1 file in it":`the ${s.toLocaleString()} files in it`;return`“${n.name}” and ${i} leave the room’s files. ${p}`}function Nn({changes:e,onOpenTheirs:n,onReturnFocus:s}){var d;const m=c=>{c.preventDefault();const D=document.activeElement;D!==null&&D!==document.body||s()},{pendingDelete:p,pendingClash:i,conflict:o}=e,g=i===null?"":i.dir===Q?"The top folder":`“${i.dir}”`,r=(i==null?void 0:i.names.length)===1;return t.jsxs(t.Fragment,{children:[t.jsx(fe,{open:p!==null,onOpenChange:c=>!c&&e.cancelDelete(),children:t.jsxs(he,{onCloseAutoFocus:m,children:[t.jsxs(pe,{children:[t.jsx(me,{children:(p==null?void 0:p.entry.type)==="dir"?"Delete this folder?":"Delete this file?"}),t.jsx(xe,{children:p===null?"":Rn(p)})]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:e.cancelDelete,children:"Cancel"}),t.jsx(ve,{onClick:()=>void e.confirmDelete(),className:"bg-destructive hover:bg-destructive/90 dark:bg-destructive/60 text-white",children:"Delete"})]})]})}),t.jsx(fe,{open:i!==null,onOpenChange:c=>!c&&e.cancelClash(),children:t.jsxs(he,{onCloseAutoFocus:m,children:[t.jsxs(pe,{children:[t.jsx(me,{children:r?`Replace “${i==null?void 0:i.names[0]}”?`:`Replace ${(i==null?void 0:i.names.length)??0} files?`}),t.jsx(xe,{children:r?`${g} already has a file with this name. Replace it with yours, or keep both and add yours under a new name.`:`${g} already has files with these names: ${(i==null?void 0:i.names.join(", "))??""}. Replace them with yours, or keep both and add yours under new names.`})]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:e.cancelClash,children:"Cancel"}),t.jsx(W,{variant:"outline",onClick:()=>void e.resolveClash("keep-both"),children:"Keep both"}),t.jsx(ve,{onClick:()=>void e.resolveClash("replace"),children:"Replace"})]})]})}),t.jsx(fe,{open:o!==null,onOpenChange:c=>!c&&e.dismissConflict(),children:t.jsxs(he,{onCloseAutoFocus:m,children:[t.jsxs(pe,{children:[t.jsx(me,{children:"Somebody changed this first"}),t.jsx(xe,{children:o===null?"":`${((d=o.lastCommit)==null?void 0:d.author)??"Somebody"} changed “${o.path}” after you opened it, so ${Dn[o.kind]}.`})]}),(o==null?void 0:o.lastCommit)&&t.jsxs("p",{className:"text-muted-foreground text-xs",children:[o.lastCommit.subject," · ",Et(o.lastCommit.at)]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:e.dismissConflict,children:"Cancel"}),t.jsx(W,{variant:"outline",onClick:()=>{o!==null&&(e.dismissConflict(),n(o.path))},children:"Open their version"}),t.jsx(ve,{onClick:()=>{o!==null&&(e.dismissConflict(),o.retry())},className:"bg-destructive hover:bg-destructive/90 dark:bg-destructive/60 text-white",children:o===null?"":En[o.kind]})]})]})})]})}function Le(e,n){return n.name===e?Ge(e):`There’s already “${n.name}” there, and a name that differs only in capital letters is the same ${n.type==="dir"?"folder":"file"} on some computers. Pick another name.`}const Sn="Folders can’t be uploaded whole. Open the folder and drop the files inside it.";function Tn({source:e,className:n,onCommands:s}={}){var de;const m=ne(),p=Te(l=>l.selectedCwd),i=a.useMemo(()=>p?mn({transport:m,cwd:p}):null,[m,p]),o=e===void 0?i:e,g=o!==null&&!o.writable,r=pn(o),d=r.changes,c=oe(),D=K(l=>l.showHidden),{rows:M,rootLoading:R,rootError:q,rootErrorMessage:b,rootErrorCommand:H,errorPaths:$}=r,k=K(l=>l.setCommands),h=K(l=>l.selectedPath),x=K(l=>l.setSelectedPath),j=K(l=>l.clipboard),[C,S]=a.useState(null),[I,A]=a.useState(null),[_,L]=a.useState(null),Y=a.useCallback(l=>L(l===null?null:{path:l,isNew:!1}),[]),F=a.useRef(null),v=a.useRef(Q),[z,B]=a.useState(!1),u=a.useCallback((l,P)=>{if(d!==null){if(P.length===0){J.error(Sn);return}r.ensureExpanded(l),d.upload(l,P)}},[d,r]),f=a.useRef(null),T=a.useCallback(()=>{var l,P;(P=(l=f.current)==null?void 0:l.querySelector('[role="tree"]'))==null||P.focus()},[]),y=a.useCallback(l=>{var P;v.current=l,(P=F.current)==null||P.click()},[]),O=a.useCallback(l=>j!==null&&!(j.isDir&&Ce(l,j.path)),[j]),E=a.useCallback((l,P)=>{r.ensureExpanded(l),_e.flushSync(()=>{A(null),S({parent:l,type:P})})},[r]),N=a.useCallback(l=>{_e.flushSync(()=>A(l.path))},[]),w=a.useRef({startCreate:E,reload:r.reload,pickUpload:y});a.useEffect(()=>{w.current={startCreate:E,reload:r.reload,pickUpload:y}});const U=d!==null;a.useEffect(()=>{if(g||s===void 0&&U)return;const l=s??k;return l({newFile:()=>w.current.startCreate(Q,"file"),newFolder:()=>w.current.startCreate(Q,"dir"),refresh:()=>w.current.reload(),...U&&{upload:()=>w.current.pickUpload(Q)}}),()=>l(null)},[k,s,g,U]);const te=a.useCallback(async l=>{var se;if(!C||o===null)return;const P=C;if(S(null),d!==null){const re=(((se=c.getQueryData(le(o,P.parent,D)))==null?void 0:se.entries)??[]).find(ot=>ot.name.toLowerCase()===l.toLowerCase());if(P.type==="dir"){if(re!==void 0&&!(re.type==="dir"&&re.name===l)){J.error(Le(l,re));return}S({parent:ee(P.parent,l),type:"file",firstInFolder:l});return}if(re!==void 0){J.error(Le(l,re));return}const rt=ee(P.parent,l);L({path:rt,isNew:!0});return}await r.createEntry(P.parent,l,P.type)&&x(ee(P.parent,l))},[C,o,d,c,D,r,x]),V=a.useCallback(async(l,P)=>{A(null),(d?await d.renameEntry(l,P):await r.renameEntry(l,P))&&x(ee(G(l.path),P))},[d,r,x]);return o===null?e!==void 0?null:t.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-6 text-center text-sm",children:"Select a working directory to browse its files."}):t.jsxs("div",{ref:f,className:Oe("flex h-full flex-col",z&&"ring-ring/60 bg-accent/30 ring-1 ring-inset",n),onDragOver:l=>{d===null||!we(l.dataTransfer.types)||(l.preventDefault(),l.dataTransfer.dropEffect="copy",B(!0))},onDragLeave:l=>{l.currentTarget.contains(l.relatedTarget)||B(!1)},onDrop:l=>{B(!1),!(d===null||!we(l.dataTransfer.types))&&(l.preventDefault(),u(Q,st(l.dataTransfer).files))},children:[d!==null&&t.jsx("input",{ref:F,type:"file",multiple:!0,hidden:!0,"aria-hidden":!0,tabIndex:-1,"data-testid":"room-files-upload-input",onChange:l=>{const P=Array.from(l.target.files??[]);l.target.value="",u(v.current,P)}}),t.jsxs("div",{className:"min-h-0 flex-1",children:[C&&t.jsx(Fn,{type:C.type,firstInFolder:C.firstInFolder,onSubmit:l=>void te(l),onCancel:()=>S(null)},`${C.parent}:${C.type}:${C.firstInFolder??""}`),R&&M.length===0?t.jsx("div",{className:"flex h-20 items-center justify-center",children:t.jsx(Fe,{size:"md",className:"text-muted-foreground",label:"Loading files"})}):q&&M.length===0?t.jsxs("div",{className:"text-muted-foreground flex min-h-20 flex-col items-center justify-center gap-2 px-4 py-3 text-center text-xs [overflow-wrap:anywhere]",children:[t.jsx("span",{children:b??"Couldn’t load files."}),H!==null&&t.jsx("code",{"aria-label":"Command that removes the settings",className:"bg-muted text-foreground block w-full rounded px-2 py-1.5 text-left font-mono select-all",children:H}),t.jsxs(W,{variant:"outline",size:"xs",onClick:r.reload,children:[t.jsx(Ke,{}),"Retry"]})]}):M.length===0&&!C?t.jsx("div",{className:"text-muted-foreground/60 flex h-20 items-center justify-center px-4 text-center text-xs",children:d!==null?"No files yet. Drop files here, or use Upload.":"Empty directory"}):t.jsx(wn,{rows:M,selectedPath:h,renamingPath:I,errorPaths:$,onSelectPath:x,onToggle:r.toggleExpand,onOpen:l=>{o.preview==="inline"?Y(l.path):r.openFile(l)},onRetryDir:r.retryDir,onSubmitRename:(l,P)=>void V(l,P),onCancelRename:()=>A(null),onStartRename:N,onNewFile:l=>E(l,"file"),onNewFolder:l=>E(l,"dir"),onDelete:l=>d?d.requestDelete(l):void r.removeEntry(l),onMove:(l,P)=>void(d?d.moveEntry(l,P):r.moveEntry(l,P)),onCopyInto:(l,P)=>void r.copyEntry(l,P),onCopy:r.copyToClipboard,onPaste:l=>{j&&r.copyEntry(j,l)},onDuplicate:l=>void r.copyEntry({path:l.path,isDir:l.type==="dir"},G(l.path)),canPasteInto:O,readOnly:g,provenance:o.provenance,copyable:d===null,onDisk:o.cwd!==null,onUpload:d?u:void 0,onPickUpload:d?y:void 0,revealLabel:r.revealLabel,onReveal:l=>void r.reveal(l),onAddToChat:r.addToChat,onCopyPath:(l,P)=>void r.copyPath(l,P)})]}),o.preview==="inline"&&t.jsx(Xt,{source:o,path:(_==null?void 0:_.path)??null,isNew:(_==null?void 0:_.isNew)??!1,onCreated:()=>{_!==null&&(L({path:_.path,isNew:!1}),x(_.path))},onClose:()=>L(null)}),d!==null&&t.jsx(Nn,{changes:d,onOpenTheirs:l=>Y(l),onReturnFocus:T}),t.jsx(fe,{open:r.pendingRecursiveDelete!==null,onOpenChange:l=>!l&&r.cancelRecursiveDelete(),children:t.jsxs(he,{children:[t.jsxs(pe,{children:[t.jsx(me,{children:"Delete this folder?"}),t.jsxs(xe,{children:["“",(de=r.pendingRecursiveDelete)==null?void 0:de.name,"” isn’t empty. Deleting it removes everything inside. This can’t be undone."]})]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:r.cancelRecursiveDelete,children:"Cancel"}),t.jsx(ve,{onClick:()=>void r.confirmRecursiveDelete(),className:"bg-destructive hover:bg-destructive/90 dark:bg-destructive/60 text-white",children:"Delete"})]})]})})]})}function Fn({type:e,firstInFolder:n,onSubmit:s,onCancel:m}){const p=a.useRef(null),[i,o]=a.useState("");a.useEffect(()=>{var d;(d=p.current)==null||d.focus()},[]);const g=()=>{const d=i.trim();d?s(d):m()},r=t.jsxs("div",{className:"flex items-center gap-1",children:[e==="dir"?t.jsx(be,{className:"size-(--size-icon-sm) flex-shrink-0 text-sky-500"}):t.jsx(Ue,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}),t.jsx("input",{ref:p,type:"text",value:i,"aria-label":n!==void 0?`First file in ${n}`:e==="dir"?"New folder name":"New file name",placeholder:e==="dir"?"folder-name":"file-name",onChange:d=>o(d.target.value),onBlur:g,onKeyDown:d=>{d.key==="Enter"?g():d.key==="Escape"&&m()},className:"border-border bg-background min-w-0 flex-1 rounded border px-1 py-0 text-sm outline-none"})]});return n===void 0?t.jsx("div",{className:"px-3 py-1",children:r}):t.jsxs("div",{className:"space-y-1 px-3 py-1",children:[t.jsxs("p",{className:"text-muted-foreground flex min-w-0 items-center gap-1 text-xs",children:[t.jsx(be,{className:"size-(--size-icon-xs) flex-shrink-0 text-sky-500"}),t.jsx("span",{className:"truncate",children:n})]}),r,t.jsx("p",{className:"text-muted-foreground text-2xs",children:"Name its first file. The folder appears when you save it."})]})}function at(){const e=K(m=>m.showHidden),n=K(m=>m.setShowHidden),s=e?"Hide hidden files":"Show hidden files";return t.jsx(W,{variant:"ghost",size:"icon-xs","aria-label":s,title:s,onClick:()=>n(!e),children:e?t.jsx(Dt,{className:"text-muted-foreground"}):t.jsx(Rt,{className:"text-muted-foreground"})})}function On({cwd:e}){const n=ne(),{data:s}=ce({queryKey:["file-explorer","workspace",e],queryFn:()=>n.resolveWorkspace(e),staleTime:6e4});return s!=null&&s.branch?t.jsxs("span",{className:"text-muted-foreground bg-muted/50 text-2xs inline-flex min-w-0 items-center gap-1 rounded px-1.5 py-0.5",title:`Workspace ${s.key} on ${s.branch}`,children:[t.jsx(Be,{className:"size-3 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:s.branch})]}):null}function In(){const e=Te(s=>s.selectedCwd),n=K(s=>s.commands);return e?t.jsxs(t.Fragment,{children:[t.jsx(On,{cwd:e}),t.jsx(W,{variant:"ghost",size:"icon-xs","aria-label":"New file",title:"New file",onClick:()=>n==null?void 0:n.newFile(),children:t.jsx(et,{className:"text-muted-foreground"})}),t.jsx(W,{variant:"ghost",size:"icon-xs","aria-label":"New folder",title:"New folder",onClick:()=>n==null?void 0:n.newFolder(),children:t.jsx(Ye,{className:"text-muted-foreground"})}),t.jsx(at,{}),t.jsx(W,{variant:"ghost",size:"icon-xs","aria-label":"Refresh",title:"Refresh",onClick:()=>n==null?void 0:n.refresh(),children:t.jsx(Nt,{className:"text-muted-foreground"})})]}):null}function Pn({roomId:e}){const n=ne(),s=oe(),m=ce(We(n,e));a.useEffect(()=>Jt(s,e,()=>{s.invalidateQueries({queryKey:De.repoStatus(e)})}),[s,e]);const p=a.useMemo(()=>{var r;return((r=m.data)==null?void 0:r.kind)==="ok"?St(m.data.status):[]},[m.data]),i=Tt(p),o=Ft(p);if(!o)return null;const g=p.map((r,d)=>`${i[d]}: ${Ot(r)}`);return t.jsxs("span",{"data-slot":"pending-work-badge",title:g.join(`
|
|
17
|
-
`),className:"text-muted-foreground bg-muted/50 text-2xs inline-flex min-w-0 items-center gap-1 rounded px-1.5 py-0.5",children:[t.jsx(Be,{className:"size-3 flex-shrink-0"}),t.jsxs("span",{className:"sr-only",children:["Not merged into the room yet. ",g.join(". "),"."]}),t.jsx("span",{"aria-hidden":"true",className:"truncate",children:o})]})}const Mn={added:"added",modified:"changed",deleted:"deleted",untracked:"new"},_n=new Map([["OPERATOR_ONLY","Only the person who owns this DorkOS can decide what happens to those changes."],["ROOM_FILE_NOT_FOUND","One of those changes is not there any more, so nothing was discarded. The list below has been refreshed."],["MERGE_IN_FLIGHT","Something else is writing to this room’s files right now. Nothing was changed. Try again in a moment."],["MAIN_CHECKOUT_DIRTY","This room’s files are on another branch, which DorkOS will not move for you. Put them back on main yourself."],["ROOM_REPO_GIT_UNAVAILABLE","This computer doesn’t have git installed, and a room’s files are a git repository."],["ROOM_HAS_NO_REPO","This room does not have files of its own any more."],["ROOM_REPOS_DISABLED","Rooms cannot have files of their own on this install right now."]]);function An({roomId:e}){var H,$;const n=ne(),s=oe(),m=ce(We(n,e)),[p,i]=a.useState([]),[o,g]=a.useState(!1),[r,d]=a.useState(null),c=Pt({mutationFn:k=>n.repairRoomMain(e,k),onSuccess:()=>{i([]),g(!1),d(null),s.invalidateQueries({queryKey:De.repoStatus(e)})},onError:k=>{g(!1);const h=_n.get(Mt(k)??"");d(h??"That didn’t work. Try again in a moment."),s.invalidateQueries({queryKey:De.repoStatus(e)})}});if(((H=m.data)==null?void 0:H.kind)==="unavailable")return t.jsx("p",{role:"alert","data-slot":"room-main-warning",className:"border-border/60 text-muted-foreground rounded-lg border px-3 py-2.5 text-xs",children:"DorkOS couldn’t check whether this room’s files are in order. If saving here is refused, this is why. Try again in a moment."});const D=(($=m.data)==null?void 0:$.kind)==="ok"?m.data.status.main:void 0;if(D===void 0||!D.dirty)return null;const M=D.branch!=="main",R=p.filter(k=>D.strays.some(h=>h.path===k)),q=o&&R.length>0,b=k=>i(h=>h.includes(k)?h.filter(x=>x!==k):[...h,k]);return t.jsxs("div",{role:"alert","data-slot":"room-main-warning",className:"border-border/60 bg-muted/40 space-y-3 rounded-lg border px-3 py-2.5 text-sm",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsx(_t,{className:"text-muted-foreground mt-0.5 size-(--size-icon-sm) flex-shrink-0"}),t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsx("p",{className:"font-medium",children:"Somebody changed this room’s files outside DorkOS"}),t.jsx("p",{className:"text-muted-foreground text-xs",children:M?`This room’s files are on ${D.branch??"no branch"} instead of main. Nobody can save a file here and no agent can merge into it until they are back on main. DorkOS will not move a branch it did not move, in case there is work on it.`:"Nobody can save a file here, and no agent can merge its work in, until these are dealt with."})]})]}),!M&&t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"space-y-1.5",children:D.strays.map(k=>t.jsxs("li",{className:"flex items-center gap-2",children:[t.jsx(At,{id:`stray-${e}-${k.path}`,checked:R.includes(k.path),onCheckedChange:()=>b(k.path),disabled:c.isPending}),t.jsx("label",{htmlFor:`stray-${e}-${k.path}`,className:"min-w-0 flex-1 cursor-pointer truncate font-mono text-xs",title:k.path,children:k.path}),t.jsx("span",{className:"text-muted-foreground flex-shrink-0 text-xs",children:Mn[k.kind]})]},k.path))}),D.strayCount>D.strays.length&&t.jsxs("p",{className:"text-muted-foreground text-xs",children:["…and ",D.strayCount-D.strays.length," more, not listed here. Keeping them all still keeps every one."]}),q?t.jsxs("div",{className:"space-y-2",children:[t.jsx("p",{className:"text-xs",children:R.length===1?"Throw away that change? It cannot be brought back.":`Throw away those ${R.length} changes? They cannot be brought back.`}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(W,{type:"button",variant:"ghost",size:"sm",disabled:c.isPending,onClick:()=>g(!1),children:"Cancel"}),t.jsx(W,{type:"button",variant:"destructive",size:"sm",disabled:c.isPending,onClick:()=>c.mutate({action:"discard",paths:[...R]}),children:"Yes, discard"})]})]}):t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(W,{type:"button",variant:"outline",size:"sm",disabled:c.isPending,onClick:()=>c.mutate({action:"commit"}),children:"Keep them all"}),t.jsx(W,{type:"button",variant:"ghost",size:"sm",disabled:c.isPending||R.length===0,onClick:()=>g(!0),children:R.length===0?"Discard…":`Discard ${R.length}`})]})]}),r!==null&&t.jsx("p",{className:"text-destructive text-xs",children:r})]})}const Ee="pointer-coarse:size-11";function Kn({roomId:e,canChange:n}){const s=ne(),m=oe(),p=K(M=>M.showHidden),[i,o]=a.useState(null),g=a.useMemo(()=>Ze({transport:s,queryClient:m,roomId:e,canChange:n}),[s,m,e,n]),r=ce(ke(g,Q,p,m)),d=r.isSuccess&&r.data.absent!==!0||r.isError,[c,D]=a.useState(null);return d&&c!==e&&D(e),!d&&c!==e?null:t.jsxs("section",{"aria-label":"Room files",className:"space-y-2",children:[t.jsxs("header",{className:"flex items-center gap-2",children:[t.jsx(zt,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}),t.jsx("h3",{className:"text-muted-foreground text-xs font-medium tracking-wide uppercase",children:"Files"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(Pn,{roomId:e})}),n&&t.jsxs(t.Fragment,{children:[t.jsx(W,{variant:"ghost",size:"icon-xs",className:Ee,"aria-label":"New file",title:"New file",disabled:i===null,onClick:()=>i==null?void 0:i.newFile(),children:t.jsx(et,{className:"text-muted-foreground"})}),t.jsx(W,{variant:"ghost",size:"icon-xs",className:Ee,"aria-label":"New folder",title:"New folder",disabled:i===null,onClick:()=>i==null?void 0:i.newFolder(),children:t.jsx(Ye,{className:"text-muted-foreground"})}),t.jsx(W,{variant:"ghost",size:"icon-xs",className:Ee,"aria-label":"Upload files",title:"Upload files",disabled:(i==null?void 0:i.upload)===void 0,onClick:()=>{var M;return(M=i==null?void 0:i.upload)==null?void 0:M.call(i)},children:t.jsx(nn,{className:"text-muted-foreground"})})]}),t.jsx(at,{})]}),t.jsx(An,{roomId:e}),t.jsx("div",{"data-slot":"room-files-body",className:"border-border/60 h-72 overflow-hidden rounded-lg border",children:t.jsx(Tn,{source:g,onCommands:o})})]})}function Hn({roomId:e,attachment:n}){var d;const s=ne(),m=oe(),p=a.useMemo(()=>Ze({transport:s,queryClient:m,roomId:e}),[s,m,e]),i=ce(ke(p,Q,!1,m)),[o,g]=a.useState(!1),r=Lt(e);return!i.isSuccess||i.data.absent===!0||((d=r.data)==null?void 0:d.archived)!==!1?null:t.jsxs(t.Fragment,{children:[t.jsx(W,{type:"button",variant:"ghost",size:"icon-xs","aria-label":`Save ${n.name} to the room’s files`,title:"Save to room files",className:"text-muted-foreground hover:text-foreground mt-0.5 pointer-coarse:size-11",onClick:()=>g(!0),children:t.jsx($t,{})}),o&&t.jsx(zn,{roomId:e,source:p,attachment:n,onClose:()=>g(!1)})]})}function zn({roomId:e,source:n,attachment:s,onClose:m}){const p=ne(),i=oe(),[o,g]=a.useState(Q),[r,d]=a.useState(s.name),[c,D]=a.useState(null),[M,R]=a.useState(!1),q=a.useId(),b=ce(ke(n,o,!1,i)),H=a.useMemo(()=>{var k;return nt(((k=b.data)==null?void 0:k.entries)??[]).filter(h=>h.type==="dir")},[b.data]),$=async()=>{var h,x;const k=r.trim();if(k!==""){R(!0),D(null);try{await p.saveAttachmentToRoomFiles(e,{attachmentId:s.id,dir:o,name:k,baseCommit:((h=b.data)==null?void 0:h.commit)??null}),i.invalidateQueries({queryKey:["file-explorer","tree",n.scopeKey]}),J.success(`Saved ${k} to the room’s files`),m()}catch(j){let C;try{C=en(j,i,e)}catch{C={status:"refused",reason:Ve(j)??"That didn’t save. Try again in a moment."}}if(C.status==="exists"){const S=(((x=b.data)==null?void 0:x.entries)??[]).map(I=>I.name);D({reason:`This folder already has a file called “${k}”. Pick another name.`,suggestion:Pe({name:k,isDir:!1,taken:[...S,k]})})}else C.status==="conflict"?(D({reason:"Somebody changed this folder while you were choosing, so nothing was saved. Try again."}),b.refetch()):C.status==="refused"&&D({reason:C.reason})}finally{R(!1)}}};return t.jsx(It,{open:!0,onOpenChange:k=>!k&&m(),children:t.jsxs(Kt,{className:"sm:max-w-md",children:[t.jsxs(Ht,{children:[t.jsx(Ut,{children:"Save to room files"}),t.jsx(qt,{children:"Keep this file with the room’s files, where everyone in the room and their agents can find it."})]}),t.jsxs(Qt,{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"text-muted-foreground text-xs font-medium",children:"Folder"}),t.jsxs("div",{role:"group","aria-label":"Folders",className:"border-border/60 max-h-56 overflow-auto rounded-md border",children:[t.jsx("p",{className:"bg-muted/40 truncate px-3 py-1.5 font-mono text-xs",children:o===Q?"Top folder":`${o}/`}),o!==Q&&t.jsx($e,{label:"Up one folder",icon:t.jsx(tn,{className:"text-muted-foreground size-(--size-icon-sm)"}),onClick:()=>g(G(o))}),b.isPending?t.jsx("div",{className:"flex h-12 items-center justify-center",children:t.jsx(Fe,{size:"sm",className:"text-muted-foreground",label:"Loading folders"})}):H.length===0?t.jsx("p",{className:"text-muted-foreground px-3 py-2 text-xs",children:"No folders in here."}):H.map(k=>t.jsx($e,{label:k.name,icon:t.jsx(be,{className:"size-(--size-icon-sm) text-sky-500"}),chevron:!0,onClick:()=>g(ee(o,ie(k.path)))},k.path))]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{htmlFor:q,className:"text-muted-foreground text-xs font-medium",children:"Name"}),t.jsx(Bt,{id:q,value:r,onChange:k=>{d(k.target.value),D(null)},spellCheck:!1,autoComplete:"off"})]}),c!==null&&t.jsxs("div",{role:"alert",className:"text-destructive space-y-1 text-xs",children:[t.jsx("p",{children:c.reason}),c.suggestion!==void 0&&t.jsxs(W,{type:"button",variant:"outline",size:"xs",onClick:()=>{d(c.suggestion),D(null)},children:["Use “",c.suggestion,"”"]})]})]}),t.jsxs(Yt,{className:"gap-2",children:[t.jsx(W,{type:"button",variant:"ghost",onClick:m,children:"Cancel"}),t.jsx(W,{type:"button",disabled:M||r.trim()===""||b.isPending,onClick:()=>void $(),children:M?"Saving…":o===Q?"Save to the top folder":`Save to ${ie(o)}`})]})]})})}function $e({label:e,icon:n,chevron:s=!1,onClick:m}){return t.jsxs("button",{type:"button",onClick:m,className:"hover:bg-accent/50 focus-visible:bg-accent flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm outline-none",children:[n,t.jsx("span",{className:"min-w-0 flex-1 truncate",children:e}),s&&t.jsx(He,{className:"text-muted-foreground size-3.5"})]})}export{Tn as FileExplorer,In as FileExplorerActions,Xt as FilePreviewDialog,sn as HIDDEN_ENTRY_NAMES,at as HiddenEntriesToggle,Qn as NO_PROVENANCE,Re as PINNED_ENTRY_NAMES,Bn as ROOM_FILES_REFRESH_INTERVAL_MS,Kn as RoomFilesSection,Hn as SaveToRoomFilesButton,Ze as createRoomFilesSource,mn as createSessionCwdSource,le as explorerDirQueryKey,ke as explorerDirQueryOptions,an as isHiddenEntryName,Ne as isPinnedEntryName,rn as pinnedFirst,Zt as provenanceLine,We as roomRepoStatusQueryOptions,nt as withoutHidden};
|
|
16
|
+
*/const tt={name:"upload",size:24,node:[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]};tt.node;const nn=Se(tt);function le(e,n,s){return["file-explorer","tree",e.scopeKey,n,e.filtersHidden?s:null]}function ke(e,n,s,m){return{queryKey:le(e,n,s),queryFn:()=>e.list(n,{showHidden:s}),staleTime:Me.FILE_TREE_STALE_TIME_MS,gcTime:Me.FILE_TREE_GC_TIME_MS,placeholderData:p=>p??m.getQueryData(le(e,n,!s))}}const sn=[".git",".dork",".claude",".agents","node_modules"];function an(e){return e.startsWith(".")||sn.includes(e)}const Re=["ROOM.md","README.md"];function Ne(e){return Re.some(n=>n.toLowerCase()===e.toLowerCase())}function nt(e){return e.filter(n=>!an(n.name))}function rn(e){if(e.reduce((p,i)=>i.type==="file"&&Ne(i.name)?p+1:p,0)===0)return e;const s=[],m=[];for(const p of e)p.type==="file"&&Ne(p.name)?s.push(p):m.push(p);return s.sort((p,i)=>Re.findIndex(o=>o.toLowerCase()===p.name.toLowerCase())-Re.findIndex(o=>o.toLowerCase()===i.name.toLowerCase())),[...s,...m]}const on=/ copy(?: \d+)?$/;function Pe({name:e,isDir:n,taken:s}){const m=new Set(s);if(!m.has(e))return e;const p=n?-1:e.lastIndexOf("."),i=p>0,o=i?e.slice(p):"",g=(i?e.slice(0,p):e).replace(on,"");for(let r=1;;r+=1){const d=r===1?`${g} copy${o}`:`${g} copy ${r}${o}`;if(!m.has(d))return d}}function _e(e,n,s){return{name:n,path:e,type:s,size:0,mtime:Date.now(),isSymlink:!1}}function ln(e){const n=ne(),{source:s,showHidden:m,queryClient:p,inFlightRef:i}=e,o=s.cwd??"",[g,r]=a.useState(null),d=a.useCallback(async h=>{i.current+=1;try{return await h()}finally{i.current-=1}},[i]),c=a.useMemo(()=>{const h=x=>le(s,x,m);return{getChildren:x=>{var j;return((j=p.getQueryData(h(x)))==null?void 0:j.entries)??[]},isLoaded:x=>p.getQueryData(h(x))!==void 0,takenNames:async x=>(await n.readFileTree(o,{path:x===Q?void 0:x,showHidden:!0})).entries.map(C=>C.name),snapshot:x=>p.getQueryData(h(x)),setChildren:(x,j)=>{p.setQueryData(h(x),C=>({entries:Ie(j((C==null?void 0:C.entries)??[]))}))},restore:(x,j)=>{p.setQueryData(h(x),j)},invalidate:x=>{p.invalidateQueries({queryKey:h(x),exact:!0})}}},[p,n,o,s,m]),D=a.useCallback((h,x,j)=>d(async()=>{const C=ee(h,x),S=!c.getChildren(h).some(_=>_.path===C),I=c.snapshot(h);S&&c.setChildren(h,_=>[..._,_e(C,x,j)]);try{return await n.createEntry(o,C,j),!0}catch(_){return S&&c.restore(h,I),ae(_,`Couldn’t create ${j==="dir"?"folder":"file"}`),!1}finally{c.invalidate(h)}}),[n,o,c,d]),M=a.useCallback((h,x)=>d(async()=>{if(x===h.name||x.length===0)return!0;const j=G(h.path),C=ee(j,x),S=c.getChildren(j).some(A=>A.path===C),I=c.snapshot(j),_={...h,name:x,path:C};S||c.setChildren(j,A=>A.map(z=>z.path===h.path?_:z));try{return await n.renameEntry(o,h.path,C),K.getState().remapExpandedPaths(h.path,C),!0}catch(A){return S||c.restore(j,I),ae(A,"Couldn’t rename"),!1}finally{c.invalidate(j)}}),[n,o,c,d]),R=a.useCallback(h=>d(async()=>{const x=G(h.path),j=c.snapshot(x);c.setChildren(x,C=>C.filter(S=>S.path!==h.path));try{await n.deleteEntry(o,h.path,{recursive:!0}),K.getState().dropExpandedPaths(h.path)}catch(C){c.restore(x,j),ae(C,"Couldn’t delete")}finally{c.invalidate(x)}}),[n,o,c,d]),q=a.useCallback(h=>d(async()=>{const x=G(h.path);if(h.type==="file"){const j=c.snapshot(x);c.setChildren(x,C=>C.filter(S=>S.path!==h.path));try{await n.deleteEntry(o,h.path),K.getState().dropExpandedPaths(h.path)}catch(C){c.restore(x,j),ae(C,"Couldn’t delete")}finally{c.invalidate(x)}return}try{await n.deleteEntry(o,h.path),c.setChildren(x,j=>j.filter(C=>C.path!==h.path)),K.getState().dropExpandedPaths(h.path),c.invalidate(x)}catch(j){if(Yt(j)==="DIR_NOT_EMPTY"){r(h);return}ae(j,"Couldn’t delete")}}),[n,o,c,d]),b=a.useCallback(async()=>{const h=g;r(null),h&&await R(h)},[g,R]),H=a.useCallback(()=>r(null),[]),$=a.useCallback((h,x)=>d(async()=>{const j=G(h),C=ie(h),S=ee(x,C);if(x===j||S===h||Ce(x,h))return;const I=c.getChildren(j).find(v=>v.path===h);if(!I)return;const _=c.isLoaded(x),A=_&&c.getChildren(x).some(v=>v.path===S),z={...I,name:C,path:S},W=c.snapshot(j),F=_?c.snapshot(x):void 0;c.setChildren(j,v=>v.filter(L=>L.path!==h)),_&&!A&&c.setChildren(x,v=>[...v,z]);try{await n.renameEntry(o,h,S),K.getState().remapExpandedPaths(h,S)}catch(v){c.restore(j,W),_&&!A&&c.restore(x,F),ae(v,"Couldn’t move")}finally{c.invalidate(j),_&&c.invalidate(x)}}),[n,o,c,d]),k=a.useCallback((h,x)=>d(async()=>{if(h.isDir&&Ce(x,h.path)){J.error(Gt);return}let j;try{j=await c.takenNames(x)}catch(A){ae(A,"Couldn’t copy");return}const C=Pe({name:ie(h.path),isDir:h.isDir,taken:j}),S=ee(x,C),I=c.isLoaded(x),_=I?c.snapshot(x):void 0;if(I){const A=c.getChildren(G(h.path)).find(W=>W.path===h.path),z=A?{...A,name:C,path:S}:_e(S,C,h.isDir?"dir":"file");c.setChildren(x,W=>[...W,z])}try{await n.copyEntry(o,h.path,S)}catch(A){I&&c.restore(x,_),ae(A,"Couldn’t copy")}finally{c.invalidate(x)}}),[n,o,c,d]);return{createEntry:D,renameEntry:M,removeEntry:q,moveEntry:$,copyEntry:k,pendingRecursiveDelete:g,confirmRecursiveDelete:b,cancelRecursiveDelete:H}}function cn(e){return e!=null&&e.startsWith("darwin")?"Reveal in Finder":e!=null&&e.startsWith("win32")?"Reveal in File Explorer":"Show in File Manager"}function dn(e,n){const s=e.includes("\\")&&!e.includes("/"),m=e.replace(/[\\/]+$/,""),p=s?n.split("/").join("\\"):n;return`${m}${s?"\\":"/"}${p}`}function un(e){const n=ne(),{data:s}=it(),m=a.useMemo(()=>n.supportsReveal?cn(s==null?void 0:s.platform):null,[n.supportsReveal,s==null?void 0:s.platform]),p=a.useCallback(async d=>{if(e)try{await n.revealEntry(e,d.path)}catch(c){ae(c,"Couldn’t open the file manager")}},[n,e]),{copy:i}=lt(),o=a.useCallback(async(d,c)=>{const D=c==="absolute"&&e?dn(e,d.path):d.path;await i(D)||J.error("Couldn’t copy to the clipboard")},[e,i]),g=a.useCallback(d=>{ct(dt(d.path))||J.error("Open a chat first to add a file to it")},[]),r=a.useCallback(d=>{K.getState().setClipboard({path:d.path,isDir:d.type==="dir"});try{navigator.clipboard.writeText(d.path).catch(()=>{})}catch{}},[]);return{revealLabel:m,reveal:p,copyPath:o,addToChat:g,copyToClipboard:r}}const fn=1e3;function hn(e){const{source:n,showHidden:s,queryClient:m,inFlightRef:p}=e,i=n.changes,[o,g]=a.useState(null),[r,d]=a.useState(null),[c,D]=a.useState(null),[M,R]=a.useState(0),q=a.useCallback(async u=>{p.current+=1,R(f=>f+1);try{return await u()}finally{p.current-=1,R(f=>f-1)}},[p]),b=a.useMemo(()=>{const u=f=>le(n,f,s);return{listing:f=>m.getQueryData(u(f)),isLoaded:f=>m.getQueryData(u(f))!==void 0,entries:f=>{var T;return((T=m.getQueryData(u(f)))==null?void 0:T.entries)??[]},setEntries:(f,T)=>m.setQueryData(u(f),y=>({...y,entries:Ie(T((y==null?void 0:y.entries)??[]))})),restore:(f,T)=>m.setQueryData(u(f),T),fetch:f=>n.list(f,{showHidden:!0}),refreshAll:()=>{m.invalidateQueries({queryKey:["file-explorer","tree",n.scopeKey]}),m.invalidateQueries({queryKey:["file-explorer","preview",n.scopeKey]})}}},[m,n,s]),H=a.useCallback(async u=>{const f=b.listing(u);return(f==null?void 0:f.commit)!==void 0?f.commit:(await b.fetch(u)).commit??null},[b]),$=a.useCallback((u,f,T,y)=>{switch(u.status){case"changed":return!0;case"conflict":return D({kind:f,path:u.path,lastCommit:u.lastCommit,retry:()=>T(u.commit)}),!1;case"exists":return J.error(y===void 0?u.reason:Ge(y)),!1;case"refused":return J.error(u.reason),!1}},[]),k=a.useCallback((u,f)=>{J.error(Ve(u)??f)},[]),h=a.useCallback((u,f,T)=>{const y=O=>q(async()=>{if(i===void 0)return!1;const E=G(u.path),N=G(f),w=ie(f),U=b.isLoaded(N),te=U&&b.entries(N).some(X=>X.path===f),V=b.listing(E),de=N===E?void 0:b.listing(N),l={...u,name:w,path:f};te||(N===E?b.setEntries(E,X=>X.map(se=>se.path===u.path?l:se)):(b.setEntries(E,X=>X.filter(se=>se.path!==u.path)),U&&b.setEntries(N,X=>[...X,l])));const P=()=>{b.restore(E,V),N!==E&&U&&b.restore(N,de)};try{const X=O??await H(E);if(X===null)return P(),J.error("There’s nothing in this room’s files to change yet."),!1;const se=await i.move({from:u.path,to:f,baseCommit:X}),je=$(se,T,async re=>{await y(re)},w);return je?K.getState().remapExpandedPaths(u.path,f):P(),je}catch(X){return P(),k(X,T==="rename"?"Couldn’t rename":"Couldn’t move"),!1}finally{b.refreshAll()}});return y(null)},[i,b,q,H,$,k]),x=a.useCallback(async(u,f)=>f===u.name||f.length===0?!0:h(u,ee(G(u.path),f),"rename"),[h]),j=a.useCallback(async(u,f)=>{const T=G(u),y=ee(f,ie(u));if(f===T||y===u||Ce(f,u))return;const O=b.entries(T).find(E=>E.path===u);O&&await h(O,y,"move")},[b,h]),C=a.useCallback(async u=>{let f=0;const T=[u];for(;T.length>0;){const y=T.shift(),O=await b.fetch(y);for(const E of O.entries)if(E.type==="dir"?T.push(E.path):f+=1,f>=fn)return{count:f,moreThan:!0}}return{count:f,moreThan:!1}},[b]),S=a.useCallback(u=>{if(u.type!=="dir"){g({entry:u,fileCount:1,moreThan:!1});return}g({entry:u,fileCount:null,moreThan:!1}),C(u.path).then(({count:f,moreThan:T})=>g(y=>(y==null?void 0:y.entry.path)===u.path?{entry:u,fileCount:f,moreThan:T}:y),()=>{})},[C]),I=a.useCallback(u=>{const f=T=>q(async()=>{if(i===void 0)return;const y=G(u.path),O=b.listing(y);b.setEntries(y,E=>E.filter(N=>N.path!==u.path));try{const E=T??await H(y);if(E===null){b.restore(y,O);return}const N=await i.remove({path:u.path,baseCommit:E});$(N,"delete",U=>f(U))?K.getState().dropExpandedPaths(u.path):b.restore(y,O)}catch(E){b.restore(y,O),k(E,"Couldn’t delete")}finally{b.refreshAll()}});return f(null)},[i,b,q,H,$,k]),_=a.useCallback(async()=>{const u=o;g(null),u&&await I(u.entry)},[o,I]),A=a.useCallback(()=>g(null),[]),z=a.useCallback((u,f,T,y)=>{const O=E=>q(async()=>{if(i===void 0)return;const N=b.isLoaded(u),w=N?b.listing(u):void 0;if(N){const U=new Set(b.entries(u).map(V=>V.name)),te=f.filter(V=>!U.has(V.name)).map(V=>({name:V.name,path:ee(u,V.name),type:"file",size:V.size}));te.length>0&&b.setEntries(u,V=>[...V,...te])}try{const U=await i.upload({dir:u,baseCommit:E,replace:T,files:f});!$(U,"upload",V=>O(V))&&N&&b.restore(u,w)}catch(U){N&&b.restore(u,w),k(U,"Couldn’t upload")}finally{b.refreshAll()}});return O(y)},[i,b,q,$,k]),W=a.useCallback(async(u,f)=>{if(i===void 0||f.length===0)return;if(f.length>i.maxUploadFiles){J.error(`One upload can carry up to ${i.maxUploadFiles} files, so nothing was uploaded. Try again with fewer.`);return}let T;try{T=await b.fetch(u)}catch(w){k(w,"Couldn’t upload");return}const y=T.entries.map(w=>w.name),O=new Set(y),E=f.map(w=>w.name).filter(w=>O.has(w)),N=T.commit??null;if(E.length===0){await z(u,f,[],N);return}d({dir:u,files:f,names:E,taken:y,baseCommit:N})},[i,b,k,z]),F=a.useCallback(async u=>{const f=r;if(d(null),f===null)return;if(u==="replace"){await z(f.dir,f.files,f.names,f.baseCommit);return}const T=new Set([...f.taken,...f.files.map(E=>E.name)]),y=new Set(f.names),O=f.files.map(E=>{if(!y.has(E.name))return E;const N=Pe({name:E.name,isDir:!1,taken:T});return T.add(N),new File([E],N,{type:E.type,lastModified:E.lastModified})});await z(f.dir,O,[],f.baseCommit)},[r,z]),v=a.useCallback(()=>d(null),[]),L=a.useCallback(()=>D(null),[]),B=a.useMemo(()=>r===null?null:{dir:r.dir,names:r.names},[r]);return{renameEntry:x,moveEntry:j,requestDelete:S,pendingDelete:o,confirmDelete:_,cancelDelete:A,upload:W,pendingClash:B,resolveClash:F,cancelClash:v,conflict:c,dismissConflict:L,busy:M>0}}const Le={scopeKey:"",cwd:null,writable:!1,provenance:!1,filtersHidden:!0,preview:"canvas",editable:!1,list:()=>Promise.resolve({entries:[]})};function pn(e){var u,f,T;const n=ne(),s=oe(),{setTheme:m}=ut(),p=K(y=>y.showHidden),i=K(y=>y.expanded),o=K(y=>y.loadExplorerForCwd),g=K(y=>y.pruneMissing),r=(e==null?void 0:e.scopeKey)??null,d=(e==null?void 0:e.cwd)??null;a.useEffect(()=>{o(r)},[r,o]);const c=a.useMemo(()=>[Q,...ft(i)],[i]),D=ht({queries:e?c.map(y=>ke(e,y,p,s)):[]}),M=(e==null?void 0:e.filtersHidden)??!0,R=a.useMemo(()=>{const y={};return c.forEach((O,E)=>{var U;const N=D[E];let w=((U=N==null?void 0:N.data)==null?void 0:U.entries)??[];!p&&!M&&(w=nt(w)),O===Q&&(w=rn(w)),y[O]={entries:w,loading:(N==null?void 0:N.isLoading)??!1,error:(N==null?void 0:N.isError)??!1}}),y},[c,D,p,M]),q=a.useRef(0),b=a.useRef({});a.useEffect(()=>{q.current>0||c.forEach((y,O)=>{var N,w,U;const E=(w=(N=D[O])==null?void 0:N.data)==null?void 0:w.entries;!E||(U=D[O])!=null&&U.isError||b.current[y]!==E&&(b.current[y]=E,g(y,E.map(te=>te.name)))})},[c,D,g]);const H=a.useMemo(()=>pt(i,R),[i,R]),$=!!e&&!!((u=R[Q])!=null&&u.loading),k=!!e&&!!((f=R[Q])!=null&&f.error),h=(T=D[0])==null?void 0:T.error,x=k&&h?Vt(h):void 0,j=(x==null?void 0:x.message)??null,C=(x==null?void 0:x.command)??null,S=a.useMemo(()=>{var O;const y=new Set;for(const E of c)E!==Q&&((O=R[E])!=null&&O.error)&&y.add(E);return y},[c,R]),I=a.useCallback(y=>{if(y.type!=="dir")return;const O=K.getState();O.setDirExpanded(y.path,!O.expanded[y.path])},[]),_=a.useCallback(y=>{if(y===Q)return;const O=K.getState();O.expanded[y]||O.setDirExpanded(y,!0)},[]),A=(e==null?void 0:e.preview)==="canvas",z=a.useCallback(y=>{if(y.type!=="file"||!A)return;const O={getStore:Te.getState,setTheme:m,supportsTerminal:n.supportsTerminal};mt(O,{action:"open_file",sourcePath:y.path},"user")},[A,m,n]),W=a.useCallback(()=>{r!==null&&s.invalidateQueries({queryKey:["file-explorer","tree",r]})},[s,r]),F=a.useCallback(y=>{e!==null&&s.invalidateQueries({queryKey:le(e,y,p),exact:!0})},[s,e,p]);a.useEffect(()=>{if(e!=null&&e.events)return e.events(W)},[e,W]);const v=ln({source:e??Le,showHidden:p,queryClient:s,inFlightRef:q}),L=hn({source:e??Le,showHidden:p,queryClient:s,inFlightRef:q}),B=un(d);return{rows:H,rootLoading:$,rootError:k,rootErrorMessage:j,rootErrorCommand:C,errorPaths:S,toggleExpand:I,ensureExpanded:_,openFile:z,reload:W,retryDir:F,changes:e!=null&&e.changes?L:null,...v,...B}}function mn(e){const{transport:n,cwd:s}=e;return{scopeKey:s,cwd:s,writable:!0,provenance:!1,filtersHidden:!0,preview:"canvas",editable:!1,list(m,p){return n.readFileTree(s,{path:m===""?void 0:m,showHidden:p.showHidden})}}}function we(e){return Array.from(e).includes("Files")}function st(e){const n=Array.from(e.items??[]);if(!(n.length>0&&n.every(i=>"webkitGetAsEntry"in i)))return{files:Array.from(e.files??[]),folders:0};const m=[];let p=0;for(const i of n){if(i.kind!=="file")continue;const o=i.webkitGetAsEntry();if(o!=null&&o.isDirectory){p+=1;continue}const g=i.getAsFile();g&&m.push(g)}return{files:m,folders:p}}const xn=12;function gn({row:e,selected:n,renaming:s,error:m,onSelect:p,onActivate:i,onRetry:o,onSubmitRename:g,onCancelRename:r,onNewFile:d,onNewFolder:c,onStartRename:D,onDelete:M,onMove:R,onCopyInto:q,onCopy:b,onPaste:H,onDuplicate:$,canPasteInto:k,revealLabel:h,onReveal:x,onAddToChat:j,onCopyPath:C,readOnly:S=!1,provenance:I=!1,copyable:_=!0,onDisk:A=!0,onUpload:z,onPickUpload:W}){const{entry:F,depth:v,expanded:L,loading:B}=e,u=F.type==="dir",f=u?F.path:G(F.path),[T,y]=a.useState(!1),O=!u&&v===0&&Ne(F.name),E=Xt(F.lastCommit),N=t.jsxs("div",{role:"treeitem","aria-label":F.name,"aria-expanded":u?L:void 0,"aria-selected":n,tabIndex:-1,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),p(F),i(F))},draggable:!s&&!S,onDragStart:w=>{S||(w.dataTransfer.setData("text/plain",F.path),w.dataTransfer.setData(Ct,F.path),w.dataTransfer.effectAllowed="copyMove")},onDragOver:w=>{if(w.stopPropagation(),!S&&z&&we(w.dataTransfer.types)){w.preventDefault(),w.dataTransfer.dropEffect="copy",y(!0);return}S||!u||!Qe(w.dataTransfer.types)||(w.preventDefault(),w.dataTransfer.dropEffect=w.altKey&&_?"copy":"move",y(!0))},onDragLeave:()=>y(!1),onDrop:w=>{if(w.stopPropagation(),S)return;if(y(!1),z&&we(w.dataTransfer.types)){w.preventDefault();const{files:te}=st(w.dataTransfer);z(f,te);return}if(!u)return;const U=qe(w.dataTransfer);U!==null&&(w.preventDefault(),w.altKey&&_?q(U,F.path):R(U,F.path))},onClick:()=>{p(F),i(F)},className:Oe("flex w-full cursor-pointer items-center gap-1 py-1 pr-2 text-sm transition-colors",n?"bg-accent text-foreground":"hover:bg-accent/50",T&&"ring-ring/60 bg-accent ring-1"),style:{paddingLeft:v*xn+8},children:[t.jsx("span",{className:"flex size-4 flex-shrink-0 items-center justify-center",children:u&&(B?t.jsx(Fe,{size:"xs",className:"text-muted-foreground"}):m?t.jsx("button",{type:"button","aria-label":"Retry loading",title:"Couldn’t load. Retry",onClick:w=>{w.stopPropagation(),o()},className:"flex items-center justify-center",children:t.jsx(Ke,{className:"text-destructive size-3.5"})}):L?t.jsx(xt,{className:"text-muted-foreground size-3.5"}):t.jsx(He,{className:"text-muted-foreground size-3.5"}))}),u?L?t.jsx(gt,{className:"size-(--size-icon-sm) flex-shrink-0 text-sky-500"}):t.jsx(be,{className:"size-(--size-icon-sm) flex-shrink-0 text-sky-500"}):F.isSymlink===!0?t.jsx(yt,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}):t.jsx(Ue,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}),s?t.jsx(yn,{initialName:F.name,onSubmit:w=>g(F,w),onCancel:r}):t.jsx("span",{className:"min-w-0 flex-1 truncate",children:F.name}),O&&!s&&t.jsx(vt,{"aria-label":"Pinned to the top",className:"text-muted-foreground/60 size-3 flex-shrink-0"}),I&&!s&&t.jsx("span",{className:"text-muted-foreground/70 text-2xs max-w-[45%] flex-shrink-0 truncate tabular-nums",title:E.title??void 0,children:E.label})]});return S?N:t.jsxs(bt,{children:[t.jsx(wt,{asChild:!0,children:N}),t.jsxs(kt,{className:"w-52",children:[t.jsx(Z,{movesFocus:!0,onClick:()=>d(f),children:"New file"}),t.jsx(Z,{movesFocus:!0,onClick:()=>c(f),children:"New folder"}),W&&t.jsx(Z,{onClick:()=>W(f),children:"Upload files…"}),A&&t.jsxs(t.Fragment,{children:[t.jsx(ue,{}),h&&t.jsx(Z,{onClick:()=>x(F),children:h}),t.jsx(Z,{movesFocus:!0,onClick:()=>j(F),children:"Add to chat"})]}),_&&t.jsxs(t.Fragment,{children:[t.jsx(ue,{}),t.jsx(Z,{onClick:()=>b(F),children:"Copy"}),t.jsx(Z,{disabled:!k(f),onClick:()=>H(f),children:"Paste"}),t.jsx(Z,{onClick:()=>$(F),children:"Duplicate"})]}),t.jsx(ue,{}),A?t.jsxs(t.Fragment,{children:[t.jsx(Z,{onClick:()=>C(F,"absolute"),children:"Copy path"}),t.jsx(Z,{onClick:()=>C(F,"relative"),children:"Copy relative path"})]}):t.jsx(Z,{onClick:()=>C(F,"relative"),children:"Copy path"}),t.jsx(ue,{}),t.jsx(Z,{movesFocus:!0,onClick:()=>D(F),children:"Rename"}),t.jsx(Z,{variant:"destructive",onClick:()=>M(F),children:"Delete"})]})]})}function yn({initialName:e,onSubmit:n,onCancel:s}){const m=a.useRef(null),[p,i]=a.useState(e);a.useEffect(()=>{const g=m.current;if(!g)return;g.focus();const r=e.lastIndexOf(".");g.setSelectionRange(0,r>0?r:e.length)},[e]);const o=()=>{const g=p.trim();g&&g!==e?n(g):s()};return t.jsx("input",{ref:m,type:"text",value:p,"aria-label":"New name",onChange:g=>i(g.target.value),onClick:g=>g.stopPropagation(),onBlur:o,onKeyDown:g=>{g.stopPropagation(),g.key==="Enter"?o():g.key==="Escape"&&s()},className:"border-border bg-background min-w-0 flex-1 rounded border px-1 py-0 text-sm outline-none"})}const vn=100,Cn=28,bn=250;function wn(e){const{rows:n,selectedPath:s,renamingPath:m,errorPaths:p,onSelectPath:i,onRetryDir:o}=e,g=a.useRef(null),r=K(v=>v.setScrollTop),d=K(v=>v.scopeKey),c=a.useCallback(v=>v.type==="dir"?e.onToggle(v):e.onOpen(v),[e]),D=jn(e,c),M=n.length>vn,R=jt({count:n.length,getScrollElement:()=>g.current,estimateSize:()=>Cn,overscan:12,enabled:M}),q=a.useRef({scope:void 0,done:!1}),b=a.useRef(null);a.useLayoutEffect(()=>{const v=q.current;if(v.scope!==d&&(v.scope=d,v.done=!1),v.done||n.length===0)return;const L=g.current;if(!L)return;const B=K.getState().scrollTop;if(B<=0){v.done=!0;return}M?R.scrollToOffset(B):L.scrollTop=B,b.current=L.scrollTop,L.scrollTop>=B&&(v.done=!0)},[n.length,d,M,R]);const H=a.useRef(null),$=a.useRef(null),k=a.useCallback(()=>{const v=g.current;v&&v.scrollTop!==b.current&&(q.current.done=!0,H.current=v.scrollTop,$.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,H.current!==null&&r(H.current)},bn))},[r]);a.useEffect(()=>()=>{$.current&&clearTimeout($.current),H.current!==null&&r(H.current)},[r]);const h=a.useRef(void 0);a.useEffect(()=>{var u,f;const v=h.current;if(h.current=s,v===void 0||s===v||s===null)return;const L=n.findIndex(T=>T.entry.path===s);if(L<0)return;const B=g.current;B&&(M?R.scrollToIndex(L,{align:"auto"}):(f=(u=B.querySelector(`[data-row-index="${L}"]`))==null?void 0:u.scrollIntoView)==null||f.call(u,{block:"nearest"}),b.current=B.scrollTop)},[s,n,M,R]);const[x,j]=a.useState(!1),{onCopyInto:C,onMove:S}=e,I=e.readOnly===!0,_=e.copyable!==!1,A=a.useCallback(v=>{I||!Qe(v.dataTransfer.types)||(v.preventDefault(),v.dataTransfer.dropEffect=v.altKey&&_?"copy":"move",j(!0))},[I,_]),z=a.useCallback((v,L)=>{const B=n.find(u=>u.entry.path===v);B&&C({path:v,isDir:B.entry.type==="dir"},L)},[n,C]),W=a.useCallback(v=>{if(j(!1),I)return;const L=qe(v.dataTransfer);L!==null&&(v.preventDefault(),v.altKey&&_?z(L,Q):S(L,Q))},[z,S,I,_]),F=v=>t.jsx(gn,{row:v,selected:v.entry.path===s,renaming:v.entry.path===m,error:v.entry.type==="dir"&&v.expanded&&p.has(v.entry.path),onSelect:L=>i(L.path),onActivate:c,onRetry:()=>o(v.entry.path),onSubmitRename:e.onSubmitRename,onCancelRename:e.onCancelRename,onStartRename:e.onStartRename,onNewFile:e.onNewFile,onNewFolder:e.onNewFolder,onDelete:e.onDelete,onMove:e.onMove,onCopyInto:z,onCopy:e.onCopy,onPaste:e.onPaste,onDuplicate:e.onDuplicate,canPasteInto:e.canPasteInto,revealLabel:e.revealLabel,onReveal:e.onReveal,onAddToChat:e.onAddToChat,onCopyPath:e.onCopyPath,readOnly:e.readOnly,provenance:e.provenance,copyable:e.copyable,onDisk:e.onDisk,onUpload:e.onUpload,onPickUpload:e.onPickUpload});return t.jsx("div",{ref:g,role:"tree","aria-label":"File explorer",tabIndex:0,onKeyDown:D,onScroll:k,onDragOver:A,onDragLeave:()=>j(!1),onDrop:W,className:Oe("focus-visible:ring-ring/40 h-full overflow-auto outline-none focus-visible:ring-1 focus-visible:ring-inset",x&&"ring-ring/60 bg-accent/30 ring-1 ring-inset"),children:M?t.jsx("div",{style:{height:R.getTotalSize()},className:"relative w-full",children:R.getVirtualItems().map(v=>t.jsx("div",{"data-row-index":v.index,className:"absolute top-0 left-0 w-full",style:{transform:`translateY(${v.start}px)`},children:F(n[v.index])},n[v.index].entry.path))}):n.map((v,L)=>t.jsx("div",{"data-row-index":L,children:F(v)},v.entry.path))})}function kn(e){return e?e.type==="dir"?e.path:G(e.path):Q}function jn(e,n){const{rows:s,selectedPath:m,renamingPath:p,onSelectPath:i}=e;return a.useCallback(o=>{var d,c,D,M;if(p!==null)return;const g=s.findIndex(R=>R.entry.path===m),r=g>=0?s[g]:void 0;if(o.metaKey||o.ctrlKey){if(e.readOnly===!0||e.copyable===!1)return;const R=o.key.toLowerCase();if(R==="c"&&r){o.preventDefault(),e.onCopy(r.entry);return}if(R==="v"){o.preventDefault(),e.onPaste(kn(r==null?void 0:r.entry));return}return}switch(o.key){case"ArrowDown":o.preventDefault(),i(((d=s[Math.min(g+1,s.length-1)])==null?void 0:d.entry.path)??((c=s[0])==null?void 0:c.entry.path));break;case"ArrowUp":o.preventDefault(),i(((D=s[Math.max(g-1,0)])==null?void 0:D.entry.path)??((M=s[0])==null?void 0:M.entry.path));break;case"ArrowRight":(r==null?void 0:r.entry.type)==="dir"&&!r.expanded&&(o.preventDefault(),e.onToggle(r.entry));break;case"ArrowLeft":if(!r)break;if(o.preventDefault(),r.entry.type==="dir"&&r.expanded)e.onToggle(r.entry);else{const R=G(r.entry.path);R&&i(R)}break;case"Enter":r&&(o.preventDefault(),n(r.entry));break;case"F2":r&&e.readOnly!==!0&&(o.preventDefault(),e.onStartRename(r.entry));break;case"Delete":case"Backspace":r&&e.readOnly!==!0&&(o.preventDefault(),e.onDelete(r.entry));break}},[s,m,p,i,e,n])}const En={rename:"Rename it anyway",move:"Move it anyway",delete:"Delete it anyway",upload:"Upload mine over it"},Dn={rename:"nothing was renamed",move:"nothing was moved",delete:"nothing was deleted",upload:"nothing was uploaded"};function Rn(e){const{entry:n,fileCount:s,moreThan:m}=e,p="The room’s history keeps a copy, so an agent or git can bring it back if you need it.";if(n.type!=="dir")return`“${n.name}” leaves the room’s files. ${p}`;const i=s===null?"everything in it":m?`the more than ${s.toLocaleString()} files in it`:s===1?"the 1 file in it":`the ${s.toLocaleString()} files in it`;return`“${n.name}” and ${i} leave the room’s files. ${p}`}function Nn({changes:e,onOpenTheirs:n,onReturnFocus:s}){var d;const m=c=>{c.preventDefault();const D=document.activeElement;D!==null&&D!==document.body||s()},{pendingDelete:p,pendingClash:i,conflict:o}=e,g=i===null?"":i.dir===Q?"The top folder":`“${i.dir}”`,r=(i==null?void 0:i.names.length)===1;return t.jsxs(t.Fragment,{children:[t.jsx(fe,{open:p!==null,onOpenChange:c=>!c&&e.cancelDelete(),children:t.jsxs(he,{onCloseAutoFocus:m,children:[t.jsxs(pe,{children:[t.jsx(me,{children:(p==null?void 0:p.entry.type)==="dir"?"Delete this folder?":"Delete this file?"}),t.jsx(xe,{children:p===null?"":Rn(p)})]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:e.cancelDelete,children:"Cancel"}),t.jsx(ve,{onClick:()=>void e.confirmDelete(),className:"bg-destructive hover:bg-destructive/90 dark:bg-destructive/60 text-white",children:"Delete"})]})]})}),t.jsx(fe,{open:i!==null,onOpenChange:c=>!c&&e.cancelClash(),children:t.jsxs(he,{onCloseAutoFocus:m,children:[t.jsxs(pe,{children:[t.jsx(me,{children:r?`Replace “${i==null?void 0:i.names[0]}”?`:`Replace ${(i==null?void 0:i.names.length)??0} files?`}),t.jsx(xe,{children:r?`${g} already has a file with this name. Replace it with yours, or keep both and add yours under a new name.`:`${g} already has files with these names: ${(i==null?void 0:i.names.join(", "))??""}. Replace them with yours, or keep both and add yours under new names.`})]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:e.cancelClash,children:"Cancel"}),t.jsx(Y,{variant:"outline",onClick:()=>void e.resolveClash("keep-both"),children:"Keep both"}),t.jsx(ve,{onClick:()=>void e.resolveClash("replace"),children:"Replace"})]})]})}),t.jsx(fe,{open:o!==null,onOpenChange:c=>!c&&e.dismissConflict(),children:t.jsxs(he,{onCloseAutoFocus:m,children:[t.jsxs(pe,{children:[t.jsx(me,{children:"Somebody changed this first"}),t.jsx(xe,{children:o===null?"":`${((d=o.lastCommit)==null?void 0:d.author)??"Somebody"} changed “${o.path}” after you opened it, so ${Dn[o.kind]}.`})]}),(o==null?void 0:o.lastCommit)&&t.jsxs("p",{className:"text-muted-foreground text-xs",children:[o.lastCommit.subject," · ",Et(o.lastCommit.at)]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:e.dismissConflict,children:"Cancel"}),t.jsx(Y,{variant:"outline",onClick:()=>{o!==null&&(e.dismissConflict(),n(o.path))},children:"Open their version"}),t.jsx(ve,{onClick:()=>{o!==null&&(e.dismissConflict(),o.retry())},className:"bg-destructive hover:bg-destructive/90 dark:bg-destructive/60 text-white",children:o===null?"":En[o.kind]})]})]})})]})}function ze(e,n){return n.name===e?Ge(e):`There’s already “${n.name}” there, and a name that differs only in capital letters is the same ${n.type==="dir"?"folder":"file"} on some computers. Pick another name.`}const Sn="Folders can’t be uploaded whole. Open the folder and drop the files inside it.";function Tn({source:e,className:n,onCommands:s}={}){var de;const m=ne(),p=Te(l=>l.selectedCwd),i=a.useMemo(()=>p?mn({transport:m,cwd:p}):null,[m,p]),o=e===void 0?i:e,g=o!==null&&!o.writable,r=pn(o),d=r.changes,c=oe(),D=K(l=>l.showHidden),{rows:M,rootLoading:R,rootError:q,rootErrorMessage:b,rootErrorCommand:H,errorPaths:$}=r,k=K(l=>l.setCommands),h=K(l=>l.selectedPath),x=K(l=>l.setSelectedPath),j=K(l=>l.clipboard),[C,S]=a.useState(null),[I,_]=a.useState(null),[A,z]=a.useState(null),W=a.useCallback(l=>z(l===null?null:{path:l,isNew:!1}),[]),F=a.useRef(null),v=a.useRef(Q),[L,B]=a.useState(!1),u=a.useCallback((l,P)=>{if(d!==null){if(P.length===0){J.error(Sn);return}r.ensureExpanded(l),d.upload(l,P)}},[d,r]),f=a.useRef(null),T=a.useCallback(()=>{var l,P;(P=(l=f.current)==null?void 0:l.querySelector('[role="tree"]'))==null||P.focus()},[]),y=a.useCallback(l=>{var P;v.current=l,(P=F.current)==null||P.click()},[]),O=a.useCallback(l=>j!==null&&!(j.isDir&&Ce(l,j.path)),[j]),E=a.useCallback((l,P)=>{r.ensureExpanded(l),Ae.flushSync(()=>{_(null),S({parent:l,type:P})})},[r]),N=a.useCallback(l=>{Ae.flushSync(()=>_(l.path))},[]),w=a.useRef({startCreate:E,reload:r.reload,pickUpload:y});a.useEffect(()=>{w.current={startCreate:E,reload:r.reload,pickUpload:y}});const U=d!==null;a.useEffect(()=>{if(g||s===void 0&&U)return;const l=s??k;return l({newFile:()=>w.current.startCreate(Q,"file"),newFolder:()=>w.current.startCreate(Q,"dir"),refresh:()=>w.current.reload(),...U&&{upload:()=>w.current.pickUpload(Q)}}),()=>l(null)},[k,s,g,U]);const te=a.useCallback(async l=>{var se;if(!C||o===null)return;const P=C;if(S(null),d!==null){const re=(((se=c.getQueryData(le(o,P.parent,D)))==null?void 0:se.entries)??[]).find(ot=>ot.name.toLowerCase()===l.toLowerCase());if(P.type==="dir"){if(re!==void 0&&!(re.type==="dir"&&re.name===l)){J.error(ze(l,re));return}S({parent:ee(P.parent,l),type:"file",firstInFolder:l});return}if(re!==void 0){J.error(ze(l,re));return}const rt=ee(P.parent,l);z({path:rt,isNew:!0});return}await r.createEntry(P.parent,l,P.type)&&x(ee(P.parent,l))},[C,o,d,c,D,r,x]),V=a.useCallback(async(l,P)=>{_(null),(d?await d.renameEntry(l,P):await r.renameEntry(l,P))&&x(ee(G(l.path),P))},[d,r,x]);return o===null?e!==void 0?null:t.jsx("div",{className:"text-muted-foreground flex h-full items-center justify-center p-6 text-center text-sm",children:"Select a working directory to browse its files."}):t.jsxs("div",{ref:f,className:Oe("flex h-full flex-col",L&&"ring-ring/60 bg-accent/30 ring-1 ring-inset",n),onDragOver:l=>{d===null||!we(l.dataTransfer.types)||(l.preventDefault(),l.dataTransfer.dropEffect="copy",B(!0))},onDragLeave:l=>{l.currentTarget.contains(l.relatedTarget)||B(!1)},onDrop:l=>{B(!1),!(d===null||!we(l.dataTransfer.types))&&(l.preventDefault(),u(Q,st(l.dataTransfer).files))},children:[d!==null&&t.jsx("input",{ref:F,type:"file",multiple:!0,hidden:!0,"aria-hidden":!0,tabIndex:-1,"data-testid":"room-files-upload-input",onChange:l=>{const P=Array.from(l.target.files??[]);l.target.value="",u(v.current,P)}}),t.jsxs("div",{className:"min-h-0 flex-1",children:[C&&t.jsx(Fn,{type:C.type,firstInFolder:C.firstInFolder,onSubmit:l=>void te(l),onCancel:()=>S(null)},`${C.parent}:${C.type}:${C.firstInFolder??""}`),R&&M.length===0?t.jsx("div",{className:"flex h-20 items-center justify-center",children:t.jsx(Fe,{size:"md",className:"text-muted-foreground",label:"Loading files"})}):q&&M.length===0?t.jsxs("div",{className:"text-muted-foreground flex min-h-20 flex-col items-center justify-center gap-2 px-4 py-3 text-center text-xs [overflow-wrap:anywhere]",children:[t.jsx("span",{children:b??"Couldn’t load files."}),H!==null&&t.jsx("code",{"aria-label":"Command that removes the settings",className:"bg-muted text-foreground block w-full rounded px-2 py-1.5 text-left font-mono select-all",children:H}),t.jsxs(Y,{variant:"outline",size:"xs",onClick:r.reload,children:[t.jsx(Ke,{}),"Retry"]})]}):M.length===0&&!C?t.jsx("div",{className:"text-muted-foreground/60 flex h-20 items-center justify-center px-4 text-center text-xs",children:d!==null?"No files yet. Drop files here, or use Upload.":"Empty directory"}):t.jsx(wn,{rows:M,selectedPath:h,renamingPath:I,errorPaths:$,onSelectPath:x,onToggle:r.toggleExpand,onOpen:l=>{o.preview==="inline"?W(l.path):r.openFile(l)},onRetryDir:r.retryDir,onSubmitRename:(l,P)=>void V(l,P),onCancelRename:()=>_(null),onStartRename:N,onNewFile:l=>E(l,"file"),onNewFolder:l=>E(l,"dir"),onDelete:l=>d?d.requestDelete(l):void r.removeEntry(l),onMove:(l,P)=>void(d?d.moveEntry(l,P):r.moveEntry(l,P)),onCopyInto:(l,P)=>void r.copyEntry(l,P),onCopy:r.copyToClipboard,onPaste:l=>{j&&r.copyEntry(j,l)},onDuplicate:l=>void r.copyEntry({path:l.path,isDir:l.type==="dir"},G(l.path)),canPasteInto:O,readOnly:g,provenance:o.provenance,copyable:d===null,onDisk:o.cwd!==null,onUpload:d?u:void 0,onPickUpload:d?y:void 0,revealLabel:r.revealLabel,onReveal:l=>void r.reveal(l),onAddToChat:r.addToChat,onCopyPath:(l,P)=>void r.copyPath(l,P)})]}),o.preview==="inline"&&t.jsx(Zt,{source:o,path:(A==null?void 0:A.path)??null,isNew:(A==null?void 0:A.isNew)??!1,onCreated:()=>{A!==null&&(z({path:A.path,isNew:!1}),x(A.path))},onClose:()=>z(null)}),d!==null&&t.jsx(Nn,{changes:d,onOpenTheirs:l=>W(l),onReturnFocus:T}),t.jsx(fe,{open:r.pendingRecursiveDelete!==null,onOpenChange:l=>!l&&r.cancelRecursiveDelete(),children:t.jsxs(he,{children:[t.jsxs(pe,{children:[t.jsx(me,{children:"Delete this folder?"}),t.jsxs(xe,{children:["“",(de=r.pendingRecursiveDelete)==null?void 0:de.name,"” isn’t empty. Deleting it removes everything inside. This can’t be undone."]})]}),t.jsxs(ge,{children:[t.jsx(ye,{onClick:r.cancelRecursiveDelete,children:"Cancel"}),t.jsx(ve,{onClick:()=>void r.confirmRecursiveDelete(),className:"bg-destructive hover:bg-destructive/90 dark:bg-destructive/60 text-white",children:"Delete"})]})]})})]})}function Fn({type:e,firstInFolder:n,onSubmit:s,onCancel:m}){const p=a.useRef(null),[i,o]=a.useState("");a.useEffect(()=>{var d;(d=p.current)==null||d.focus()},[]);const g=()=>{const d=i.trim();d?s(d):m()},r=t.jsxs("div",{className:"flex items-center gap-1",children:[e==="dir"?t.jsx(be,{className:"size-(--size-icon-sm) flex-shrink-0 text-sky-500"}):t.jsx(Ue,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}),t.jsx("input",{ref:p,type:"text",value:i,"aria-label":n!==void 0?`First file in ${n}`:e==="dir"?"New folder name":"New file name",placeholder:e==="dir"?"folder-name":"file-name",onChange:d=>o(d.target.value),onBlur:g,onKeyDown:d=>{d.key==="Enter"?g():d.key==="Escape"&&m()},className:"border-border bg-background min-w-0 flex-1 rounded border px-1 py-0 text-sm outline-none"})]});return n===void 0?t.jsx("div",{className:"px-3 py-1",children:r}):t.jsxs("div",{className:"space-y-1 px-3 py-1",children:[t.jsxs("p",{className:"text-muted-foreground flex min-w-0 items-center gap-1 text-xs",children:[t.jsx(be,{className:"size-(--size-icon-xs) flex-shrink-0 text-sky-500"}),t.jsx("span",{className:"truncate",children:n})]}),r,t.jsx("p",{className:"text-muted-foreground text-2xs",children:"Name its first file. The folder appears when you save it."})]})}function at(){const e=K(m=>m.showHidden),n=K(m=>m.setShowHidden),s=e?"Hide hidden files":"Show hidden files";return t.jsx(Y,{variant:"ghost",size:"icon-xs","aria-label":s,title:s,onClick:()=>n(!e),children:e?t.jsx(Dt,{className:"text-muted-foreground"}):t.jsx(Rt,{className:"text-muted-foreground"})})}function On({cwd:e}){const n=ne(),{data:s}=ce({queryKey:["file-explorer","workspace",e],queryFn:()=>n.resolveWorkspace(e),staleTime:6e4});return s!=null&&s.branch?t.jsxs("span",{className:"text-muted-foreground bg-muted/50 text-2xs inline-flex min-w-0 items-center gap-1 rounded px-1.5 py-0.5",title:`Workspace ${s.key} on ${s.branch}`,children:[t.jsx(Be,{className:"size-3 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:s.branch})]}):null}function In(){const e=Te(s=>s.selectedCwd),n=K(s=>s.commands);return e?t.jsxs(t.Fragment,{children:[t.jsx(On,{cwd:e}),t.jsx(Y,{variant:"ghost",size:"icon-xs","aria-label":"New file",title:"New file",onClick:()=>n==null?void 0:n.newFile(),children:t.jsx(et,{className:"text-muted-foreground"})}),t.jsx(Y,{variant:"ghost",size:"icon-xs","aria-label":"New folder",title:"New folder",onClick:()=>n==null?void 0:n.newFolder(),children:t.jsx(We,{className:"text-muted-foreground"})}),t.jsx(at,{}),t.jsx(Y,{variant:"ghost",size:"icon-xs","aria-label":"Refresh",title:"Refresh",onClick:()=>n==null?void 0:n.refresh(),children:t.jsx(Nt,{className:"text-muted-foreground"})})]}):null}function Pn({roomId:e}){const n=ne(),s=oe(),m=ce(Ye(n,e));a.useEffect(()=>Jt(s,e,()=>{s.invalidateQueries({queryKey:De.repoStatus(e)})}),[s,e]);const p=a.useMemo(()=>{var r;return((r=m.data)==null?void 0:r.kind)==="ok"?St(m.data.status):[]},[m.data]),i=Tt(p),o=Ft(p);if(!o)return null;const g=p.map((r,d)=>`${i[d]}: ${Ot(r)}`);return t.jsxs("span",{"data-slot":"pending-work-badge",title:g.join(`
|
|
17
|
+
`),className:"text-muted-foreground bg-muted/50 text-2xs inline-flex min-w-0 items-center gap-1 rounded px-1.5 py-0.5",children:[t.jsx(Be,{className:"size-3 flex-shrink-0"}),t.jsxs("span",{className:"sr-only",children:["Not merged into the room yet. ",g.join(". "),"."]}),t.jsx("span",{"aria-hidden":"true",className:"truncate",children:o})]})}const Mn={added:"added",modified:"changed",deleted:"deleted",untracked:"new"},An=new Map([["OPERATOR_ONLY","Only the person who owns this DorkOS can decide what happens to those changes."],["ROOM_FILE_NOT_FOUND","One of those changes is not there any more, so nothing was discarded. The list below has been refreshed."],["MERGE_IN_FLIGHT","Something else is writing to this room’s files right now. Nothing was changed. Try again in a moment."],["MAIN_CHECKOUT_DIRTY","This room’s files are on another branch, which DorkOS will not move for you. Put them back on main yourself."],["ROOM_REPO_GIT_UNAVAILABLE","This computer doesn’t have git installed, and a room’s files are a git repository."],["ROOM_HAS_NO_REPO","This room does not have files of its own any more."],["ROOM_REPOS_DISABLED","Rooms cannot have files of their own on this install right now."]]);function _n({roomId:e}){var H,$;const n=ne(),s=oe(),m=ce(Ye(n,e)),[p,i]=a.useState([]),[o,g]=a.useState(!1),[r,d]=a.useState(null),c=Pt({mutationFn:k=>n.repairRoomMain(e,k),onSuccess:()=>{i([]),g(!1),d(null),s.invalidateQueries({queryKey:De.repoStatus(e)})},onError:k=>{g(!1);const h=An.get(Mt(k)??"");d(h??"That didn’t work. Try again in a moment."),s.invalidateQueries({queryKey:De.repoStatus(e)})}});if(((H=m.data)==null?void 0:H.kind)==="unavailable")return t.jsx("p",{role:"alert","data-slot":"room-main-warning",className:"border-border/60 text-muted-foreground rounded-lg border px-3 py-2.5 text-xs",children:"DorkOS couldn’t check whether this room’s files are in order. If saving here is refused, this is why. Try again in a moment."});const D=(($=m.data)==null?void 0:$.kind)==="ok"?m.data.status.main:void 0;if(D===void 0||!D.dirty)return null;const M=D.branch!=="main",R=p.filter(k=>D.strays.some(h=>h.path===k)),q=o&&R.length>0,b=k=>i(h=>h.includes(k)?h.filter(x=>x!==k):[...h,k]);return t.jsxs("div",{role:"alert","data-slot":"room-main-warning",className:"border-border/60 bg-muted/40 space-y-3 rounded-lg border px-3 py-2.5 text-sm",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsx(At,{className:"text-muted-foreground mt-0.5 size-(--size-icon-sm) flex-shrink-0"}),t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsx("p",{className:"font-medium",children:"Somebody changed this room’s files outside DorkOS"}),t.jsx("p",{className:"text-muted-foreground text-xs",children:M?`This room’s files are on ${D.branch??"no branch"} instead of main. Nobody can save a file here and no agent can merge into it until they are back on main. DorkOS will not move a branch it did not move, in case there is work on it.`:"Nobody can save a file here, and no agent can merge its work in, until these are dealt with."})]})]}),!M&&t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"space-y-1.5",children:D.strays.map(k=>t.jsxs("li",{className:"flex items-center gap-2",children:[t.jsx(_t,{id:`stray-${e}-${k.path}`,checked:R.includes(k.path),onCheckedChange:()=>b(k.path),disabled:c.isPending}),t.jsx("label",{htmlFor:`stray-${e}-${k.path}`,className:"min-w-0 flex-1 cursor-pointer truncate font-mono text-xs",title:k.path,children:k.path}),t.jsx("span",{className:"text-muted-foreground flex-shrink-0 text-xs",children:Mn[k.kind]})]},k.path))}),D.strayCount>D.strays.length&&t.jsxs("p",{className:"text-muted-foreground text-xs",children:["…and ",D.strayCount-D.strays.length," more, not listed here. Keeping them all still keeps every one."]}),q?t.jsxs("div",{className:"space-y-2",children:[t.jsx("p",{className:"text-xs",children:R.length===1?"Throw away that change? It cannot be brought back.":`Throw away those ${R.length} changes? They cannot be brought back.`}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Y,{type:"button",variant:"ghost",size:"sm",disabled:c.isPending,onClick:()=>g(!1),children:"Cancel"}),t.jsx(Y,{type:"button",variant:"destructive",size:"sm",disabled:c.isPending,onClick:()=>c.mutate({action:"discard",paths:[...R]}),children:"Yes, discard"})]})]}):t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(Y,{type:"button",variant:"outline",size:"sm",disabled:c.isPending,onClick:()=>c.mutate({action:"commit"}),children:"Keep them all"}),t.jsx(Y,{type:"button",variant:"ghost",size:"sm",disabled:c.isPending||R.length===0,onClick:()=>g(!0),children:R.length===0?"Discard…":`Discard ${R.length}`})]})]}),r!==null&&t.jsx("p",{className:"text-destructive text-xs",children:r})]})}const Ee="pointer-coarse:size-11";function Kn({roomId:e,canChange:n}){const s=ne(),m=oe(),p=K(M=>M.showHidden),[i,o]=a.useState(null),g=a.useMemo(()=>Xe({transport:s,queryClient:m,roomId:e,canChange:n}),[s,m,e,n]),r=ce(ke(g,Q,p,m)),d=r.isSuccess&&r.data.absent!==!0||r.isError,[c,D]=a.useState(null);return d&&c!==e&&D(e),!d&&c!==e?null:t.jsxs("section",{"aria-label":"Room files",className:"space-y-2",children:[t.jsxs("header",{className:"flex items-center gap-2",children:[t.jsx(Lt,{className:"text-muted-foreground size-(--size-icon-sm) flex-shrink-0"}),t.jsx("h3",{className:"text-muted-foreground text-xs font-medium tracking-wide uppercase",children:"Files"}),t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(Pn,{roomId:e})}),n&&t.jsxs(t.Fragment,{children:[t.jsx(Y,{variant:"ghost",size:"icon-xs",className:Ee,"aria-label":"New file",title:"New file",disabled:i===null,onClick:()=>i==null?void 0:i.newFile(),children:t.jsx(et,{className:"text-muted-foreground"})}),t.jsx(Y,{variant:"ghost",size:"icon-xs",className:Ee,"aria-label":"New folder",title:"New folder",disabled:i===null,onClick:()=>i==null?void 0:i.newFolder(),children:t.jsx(We,{className:"text-muted-foreground"})}),t.jsx(Y,{variant:"ghost",size:"icon-xs",className:Ee,"aria-label":"Upload files",title:"Upload files",disabled:(i==null?void 0:i.upload)===void 0,onClick:()=>{var M;return(M=i==null?void 0:i.upload)==null?void 0:M.call(i)},children:t.jsx(nn,{className:"text-muted-foreground"})})]}),t.jsx(at,{})]}),t.jsx(_n,{roomId:e}),t.jsx("div",{"data-slot":"room-files-body",className:"border-border/60 h-72 overflow-hidden rounded-lg border",children:t.jsx(Tn,{source:g,onCommands:o})})]})}function Hn({roomId:e,attachment:n}){var d;const s=ne(),m=oe(),p=a.useMemo(()=>Xe({transport:s,queryClient:m,roomId:e}),[s,m,e]),i=ce(ke(p,Q,!1,m)),[o,g]=a.useState(!1),r=zt(e);return!i.isSuccess||i.data.absent===!0||((d=r.data)==null?void 0:d.archived)!==!1?null:t.jsxs(t.Fragment,{children:[t.jsx(Y,{type:"button",variant:"ghost",size:"icon-xs","aria-label":`Save ${n.name} to the room’s files`,title:"Save to room files",className:"text-muted-foreground hover:text-foreground mt-0.5 pointer-coarse:size-11",onClick:()=>g(!0),children:t.jsx($t,{})}),o&&t.jsx(Ln,{roomId:e,source:p,attachment:n,onClose:()=>g(!1)})]})}function Ln({roomId:e,source:n,attachment:s,onClose:m}){const p=ne(),i=oe(),[o,g]=a.useState(Q),[r,d]=a.useState(s.name),[c,D]=a.useState(null),[M,R]=a.useState(!1),q=a.useId(),b=ce(ke(n,o,!1,i)),H=a.useMemo(()=>{var k;return nt(((k=b.data)==null?void 0:k.entries)??[]).filter(h=>h.type==="dir")},[b.data]),$=async()=>{var h,x;const k=r.trim();if(k!==""){R(!0),D(null);try{await p.saveAttachmentToRoomFiles(e,{attachmentId:s.id,dir:o,name:k,baseCommit:((h=b.data)==null?void 0:h.commit)??null}),i.invalidateQueries({queryKey:["file-explorer","tree",n.scopeKey]}),J.success(`Saved ${k} to the room’s files`),m()}catch(j){let C;try{C=en(j,i,e)}catch{C={status:"refused",reason:Ve(j)??"That didn’t save. Try again in a moment."}}if(C.status==="exists"){const S=(((x=b.data)==null?void 0:x.entries)??[]).map(I=>I.name);D({reason:`This folder already has a file called “${k}”. Pick another name.`,suggestion:Pe({name:k,isDir:!1,taken:[...S,k]})})}else C.status==="conflict"?(D({reason:"Somebody changed this folder while you were choosing, so nothing was saved. Try again."}),b.refetch()):C.status==="refused"&&D({reason:C.reason})}finally{R(!1)}}};return t.jsx(It,{open:!0,onOpenChange:k=>!k&&m(),children:t.jsxs(Kt,{className:"sm:max-w-md",children:[t.jsxs(Ht,{children:[t.jsx(Ut,{children:"Save to room files"}),t.jsx(qt,{children:"Keep this file with the room’s files, where everyone in the room and their agents can find it."})]}),t.jsxs(Qt,{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"text-muted-foreground text-xs font-medium",children:"Folder"}),t.jsxs("div",{role:"group","aria-label":"Folders",className:"border-border/60 max-h-56 overflow-auto rounded-md border",children:[t.jsx("p",{className:"bg-muted/40 truncate px-3 py-1.5 font-mono text-xs",children:o===Q?"Top folder":`${o}/`}),o!==Q&&t.jsx($e,{label:"Up one folder",icon:t.jsx(tn,{className:"text-muted-foreground size-(--size-icon-sm)"}),onClick:()=>g(G(o))}),b.isPending?t.jsx("div",{className:"flex h-12 items-center justify-center",children:t.jsx(Fe,{size:"sm",className:"text-muted-foreground",label:"Loading folders"})}):H.length===0?t.jsx("p",{className:"text-muted-foreground px-3 py-2 text-xs",children:"No folders in here."}):H.map(k=>t.jsx($e,{label:k.name,icon:t.jsx(be,{className:"size-(--size-icon-sm) text-sky-500"}),chevron:!0,onClick:()=>g(ee(o,ie(k.path)))},k.path))]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{htmlFor:q,className:"text-muted-foreground text-xs font-medium",children:"Name"}),t.jsx(Bt,{id:q,value:r,onChange:k=>{d(k.target.value),D(null)},spellCheck:!1,autoComplete:"off"})]}),c!==null&&t.jsxs("div",{role:"alert",className:"text-destructive space-y-1 text-xs",children:[t.jsx("p",{children:c.reason}),c.suggestion!==void 0&&t.jsxs(Y,{type:"button",variant:"outline",size:"xs",onClick:()=>{d(c.suggestion),D(null)},children:["Use “",c.suggestion,"”"]})]})]}),t.jsxs(Wt,{className:"gap-2",children:[t.jsx(Y,{type:"button",variant:"ghost",onClick:m,children:"Cancel"}),t.jsx(Y,{type:"button",disabled:M||r.trim()===""||b.isPending,onClick:()=>void $(),children:M?"Saving…":o===Q?"Save to the top folder":`Save to ${ie(o)}`})]})]})})}function $e({label:e,icon:n,chevron:s=!1,onClick:m}){return t.jsxs("button",{type:"button",onClick:m,className:"hover:bg-accent/50 focus-visible:bg-accent flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm outline-none",children:[n,t.jsx("span",{className:"min-w-0 flex-1 truncate",children:e}),s&&t.jsx(He,{className:"text-muted-foreground size-3.5"})]})}export{Tn as FileExplorer,In as FileExplorerActions,Zt as FilePreviewDialog,sn as HIDDEN_ENTRY_NAMES,at as HiddenEntriesToggle,Qn as NO_PROVENANCE,Re as PINNED_ENTRY_NAMES,Bn as ROOM_FILES_REFRESH_INTERVAL_MS,Kn as RoomFilesSection,Hn as SaveToRoomFilesButton,Xe as createRoomFilesSource,mn as createSessionCwdSource,le as explorerDirQueryKey,ke as explorerDirQueryOptions,an as isHiddenEntryName,Ne as isPinnedEntryName,rn as pinnedFirst,Xt as provenanceLine,Ye as roomRepoStatusQueryOptions,nt as withoutHidden};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{af as vo,r as V,
|
|
1
|
+
import{af as vo,r as V,eF as Ha,j as re,al as As,eG as Ua,eH as mo,X as Ka,P as qa,ag as Fr,B as Va}from"./index-BCGiD7pg.js";const Ya="dork.terminal.tabs",ns={ids:[],activeIndex:0};function So(t,e){return`${Ya}:${t??""}:${e}`}function wo(t,e){return e<=0||!Number.isInteger(t)||t<0?0:Math.min(t,e-1)}function bo(t,e){try{const i=sessionStorage.getItem(So(t,e));if(!i)return ns;const s=JSON.parse(i);if(typeof s!="object"||s===null)return ns;const{ids:r,activeIndex:n}=s,o=Array.isArray(r)?r.filter(l=>typeof l=="string"&&l.length>0):[];return{ids:o,activeIndex:wo(typeof n=="number"?n:0,o.length)}}catch{return ns}}function Nr(t,e,i){try{const s={ids:i.ids,activeIndex:wo(i.activeIndex,i.ids.length)};sessionStorage.setItem(So(t,e),JSON.stringify(s))}catch{}}/**
|
|
2
2
|
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
3
3
|
* @license MIT
|
|
4
4
|
*
|