orc-ai 0.1.40 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/index.js +470 -455
  2. package/dist/web/assets/{Agents-KNRLNcpI.js → Agents-1lX_DRrR.js} +1 -1
  3. package/dist/web/assets/{Audit-ngeaHJiy.js → Audit-DnRP9Ivm.js} +1 -1
  4. package/dist/web/assets/{Dashboard-3F8aWN_d.js → Dashboard-bT5SABu_.js} +1 -1
  5. package/dist/web/assets/{DocumentWorkspace-VHzjE2ih.js → DocumentWorkspace-BI4JWVsO.js} +1 -1
  6. package/dist/web/assets/{FileEditor-DijNrJWf.js → FileEditor-Cb8uXr6e.js} +1 -1
  7. package/dist/web/assets/{JobWebhooks-BtzsOTHL.js → JobWebhooks-CYE2UA0V.js} +1 -1
  8. package/dist/web/assets/{Jobs-DmkPxHxP.js → Jobs-Fyd46CkI.js} +1 -1
  9. package/dist/web/assets/{Knowledge-R_6uAqDE.js → Knowledge-prZWODFP.js} +7 -7
  10. package/dist/web/assets/{PackageCatalog-CkZgscbx.js → PackageCatalog-R8kcGP28.js} +4 -4
  11. package/dist/web/assets/{Pager-DjrHsuOJ.js → Pager-urh4-P2a.js} +1 -1
  12. package/dist/web/assets/{Rules-BEzXQ7L5.js → Rules-if9ZzABl.js} +1 -1
  13. package/dist/web/assets/Sessions-AfC-wZoj.js +5 -0
  14. package/dist/web/assets/{Settings-O3qQRgTI.js → Settings-CNPE54fO.js} +3 -3
  15. package/dist/web/assets/{Skills-B3R-l8Ou.js → Skills-BJcE6uiQ.js} +1 -1
  16. package/dist/web/assets/{SourceEditor-CHubUpaP.js → SourceEditor-a2_IdCoT.js} +3 -3
  17. package/dist/web/assets/{Tasks-DF9FqHDq.js → Tasks-COQCj4HF.js} +1 -1
  18. package/dist/web/assets/Terminals-D4K_u_ch.js +115 -0
  19. package/dist/web/assets/{Webhooks-DW7d9R_t.js → Webhooks-DvsCfbZY.js} +1 -1
  20. package/dist/web/assets/{abnfDiagram-VCTEODGH-BVZ_t6ts.js → abnfDiagram-VCTEODGH-C1g9AmGT.js} +1 -1
  21. package/dist/web/assets/{arc-Bp1Q5GVT.js → arc-BX1-afFK.js} +1 -1
  22. package/dist/web/assets/{architectureDiagram-5GKGNRK7-Cw_Fh8Fr.js → architectureDiagram-5GKGNRK7-DTDe767x.js} +2 -2
  23. package/dist/web/assets/{blockDiagram-I7D4REHJ-C9qLtS_w.js → blockDiagram-I7D4REHJ-DJnvrUZM.js} +1 -1
  24. package/dist/web/assets/{c4Diagram-7LVT6UL2-k3kt69iB.js → c4Diagram-7LVT6UL2-rpXv4dc9.js} +1 -1
  25. package/dist/web/assets/channel-DsRXlXQz.js +1 -0
  26. package/dist/web/assets/{chunk-2Q5K7J3B-DVLrwP2r.js → chunk-2Q5K7J3B-BEq6zYAO.js} +1 -1
  27. package/dist/web/assets/{chunk-5VM5RSS4-D3tEfTaL.js → chunk-5VM5RSS4-kAS1IBM0.js} +1 -1
  28. package/dist/web/assets/{chunk-F27PBJKO-DfkCzGL9.js → chunk-F27PBJKO-BtG5IndH.js} +1 -1
  29. package/dist/web/assets/{chunk-IMKFNOWR-yN65S3YD.js → chunk-IMKFNOWR-C-NO8OSz.js} +1 -1
  30. package/dist/web/assets/{chunk-JWPE2WC7-ByQ6NS99.js → chunk-JWPE2WC7-2IhqyMft.js} +1 -1
  31. package/dist/web/assets/{chunk-POPQ4Y6H-CHRLyTiT.js → chunk-POPQ4Y6H-DmxK4niw.js} +1 -1
  32. package/dist/web/assets/{chunk-SVP7TREG-DvLoUZ9h.js → chunk-SVP7TREG-BkVeMS09.js} +1 -1
  33. package/dist/web/assets/{chunk-TICWLB2K-BvzbxDY6.js → chunk-TICWLB2K-DzlMwg1V.js} +1 -1
  34. package/dist/web/assets/{chunk-XXDRQBXY-DkfEU2XD.js → chunk-XXDRQBXY-ttUQmtBw.js} +1 -1
  35. package/dist/web/assets/classDiagram-ZZMXUADV-CZXMGXM8.js +1 -0
  36. package/dist/web/assets/classDiagram-v2-VYDZK3BY-CZXMGXM8.js +1 -0
  37. package/dist/web/assets/{cose-bilkent-JH36ORCC-D2Hh7gs6.js → cose-bilkent-JH36ORCC-yhoqj6vM.js} +1 -1
  38. package/dist/web/assets/{cynefin-OW5HDTMX-DwbOregT.js → cynefin-OW5HDTMX-CQZuSJ5b.js} +1 -1
  39. package/dist/web/assets/{cynefinDiagram-5FMLGOSQ-vE21HTel.js → cynefinDiagram-5FMLGOSQ-Dz-2nuEW.js} +1 -1
  40. package/dist/web/assets/{dagre-GXQ25YYZ-Dtj5PNkl.js → dagre-GXQ25YYZ-DZJid-R_.js} +1 -1
  41. package/dist/web/assets/{diagram-S7CK7UJ4-CE958Up8.js → diagram-S7CK7UJ4-DB-Uzpn6.js} +1 -1
  42. package/dist/web/assets/{diagram-UQ7AKVKN-eKQdP4HV.js → diagram-UQ7AKVKN-BjIgjC39.js} +1 -1
  43. package/dist/web/assets/{diagram-VSXAHHWV-CYvYJQrA.js → diagram-VSXAHHWV-CjFlgbiX.js} +1 -1
  44. package/dist/web/assets/{diagram-VX7I27RA-BbKYzLMW.js → diagram-VX7I27RA-BlfR5PYu.js} +1 -1
  45. package/dist/web/assets/{diagram-Z3DM3KII-DV77g65D.js → diagram-Z3DM3KII-DL6_QJQh.js} +1 -1
  46. package/dist/web/assets/{download-36kk3IeP.js → download-CK_EusLu.js} +1 -1
  47. package/dist/web/assets/{ebnfDiagram-PWID7BFC-D0sEmHPl.js → ebnfDiagram-PWID7BFC-BjdizMG0.js} +1 -1
  48. package/dist/web/assets/{erDiagram-RLTQ6QDP-DK-Z6i0m.js → erDiagram-RLTQ6QDP-BxMzPgpM.js} +1 -1
  49. package/dist/web/assets/{flowDiagram-HODETNUW-Dp0aJQEZ.js → flowDiagram-HODETNUW-C-HgPS9G.js} +1 -1
  50. package/dist/web/assets/{folder-open-D1-I40k-.js → folder-open-Bcqha5Pu.js} +1 -1
  51. package/dist/web/assets/{ganttDiagram-EL5Y4UJY-BoG15yoq.js → ganttDiagram-EL5Y4UJY-BEx6HKx_.js} +4 -4
  52. package/dist/web/assets/{gitGraphDiagram-WWUBYQGX-K4reAMXM.js → gitGraphDiagram-WWUBYQGX-D9yMgjsA.js} +1 -1
  53. package/dist/web/assets/{highlighted-body-KPVGNVTW-5ZVqRrCq.js → highlighted-body-KPVGNVTW-Cdq0W8LG.js} +1 -1
  54. package/dist/web/assets/index-BqQDBYwx.js +461 -0
  55. package/dist/web/assets/index-D1sNa9P-.css +1 -0
  56. package/dist/web/assets/{infoDiagram-27XIBGKW-67wFgmJP.js → infoDiagram-27XIBGKW-e_LgGqFP.js} +1 -1
  57. package/dist/web/assets/{ishikawaDiagram-5VMMS53U-B9jfOEH9.js → ishikawaDiagram-5VMMS53U-jOCokdCr.js} +1 -1
  58. package/dist/web/assets/{journeyDiagram-3NMN7TZE-CuSLYkR9.js → journeyDiagram-3NMN7TZE-DfyXRW30.js} +1 -1
  59. package/dist/web/assets/{kanban-definition-UXKFOSKX-Cw5N-uDl.js → kanban-definition-UXKFOSKX-D6Mgx6_N.js} +1 -1
  60. package/dist/web/assets/{layout-CWCq0m-I.js → layout-BFQQ8SSL.js} +1 -1
  61. package/dist/web/assets/{linear-DKAXfoGA.js → linear-C251cMFR.js} +1 -1
  62. package/dist/web/assets/{list-CaqywJgg.js → list-BnZDr6iH.js} +1 -1
  63. package/dist/web/assets/{mermaid-HWGCJPDP-CMQlzgg9.js → mermaid-HWGCJPDP-DE8bnMel.js} +6 -6
  64. package/dist/web/assets/{mindmap-definition-YA3MSWOX-CA6cGhJr.js → mindmap-definition-YA3MSWOX-hX6YQE6d.js} +1 -1
  65. package/dist/web/assets/{pegDiagram-XKGWAZYB-CX-B1UCC.js → pegDiagram-XKGWAZYB-DRRv8KEz.js} +1 -1
  66. package/dist/web/assets/{pencil-C-6rguDb.js → pencil-ClEwbF1x.js} +1 -1
  67. package/dist/web/assets/{pieDiagram-E7YTZNPT-ZxtffUUp.js → pieDiagram-E7YTZNPT-DwRQy5kr.js} +1 -1
  68. package/dist/web/assets/{quadrantDiagram-AXDQQJYC-hp3sjfpX.js → quadrantDiagram-AXDQQJYC-u-NZRX9E.js} +1 -1
  69. package/dist/web/assets/{railroadDiagram-O6MQD6OU-DA06SOlR.js → railroadDiagram-O6MQD6OU-DsGn0lJc.js} +1 -1
  70. package/dist/web/assets/{refresh-cw-BQyph7xD.js → refresh-cw-BGtNOi70.js} +1 -1
  71. package/dist/web/assets/{requirementDiagram-BXWQKSXE-B6uWt2Rc.js → requirementDiagram-BXWQKSXE-Bak7hmyH.js} +1 -1
  72. package/dist/web/assets/{sankeyDiagram-P5KCCOFB-C5_tPpb5.js → sankeyDiagram-P5KCCOFB-Bx5Wxkio.js} +1 -1
  73. package/dist/web/assets/{save-qGawhRKH.js → save-ChNqW56W.js} +1 -1
  74. package/dist/web/assets/{scroll-area-C-MTuK1y.js → scroll-area-YSA2ORI8.js} +1 -1
  75. package/dist/web/assets/{sequenceDiagram-WJ2MYXX4-CP1FmNA0.js → sequenceDiagram-WJ2MYXX4-CyWelz_H.js} +1 -1
  76. package/dist/web/assets/{sizeCapture-INFHLROL-BnZ0rzQe.js → sizeCapture-INFHLROL-BCzEf-8B.js} +1 -1
  77. package/dist/web/assets/{stateDiagram-D77RDMKH-B--86L9i.js → stateDiagram-D77RDMKH-BkqZfGYQ.js} +1 -1
  78. package/dist/web/assets/stateDiagram-v2-MP3YSRHH-PLwI4Xlh.js +1 -0
  79. package/dist/web/assets/{swimlanes-42K2YHIH-BV8_rH1v.js → swimlanes-42K2YHIH-BMYDAy8X.js} +1 -1
  80. package/dist/web/assets/swimlanesDiagram-VR7AAH4N-BEGqjIIe.js +8 -0
  81. package/dist/web/assets/{timeline-definition-24CTP7MA-Cm1hEfH0.js → timeline-definition-24CTP7MA-BrGykZXB.js} +1 -1
  82. package/dist/web/assets/{upload-CCnbjfQN.js → upload-waJ36Q68.js} +1 -1
  83. package/dist/web/assets/{useJobs-DDRY0jra.js → useJobs-By4K4BjX.js} +1 -1
  84. package/dist/web/assets/{useKnowledge-CHZ4AwZh.js → useKnowledge-DMSoPz-b.js} +1 -1
  85. package/dist/web/assets/{useMemories-BGxDOJge.js → useMemories-bv4XvbzQ.js} +1 -1
  86. package/dist/web/assets/useProjectScope-BvcpSOql.js +1 -0
  87. package/dist/web/assets/{vennDiagram-4TSXK5OY-vVCoILPC.js → vennDiagram-4TSXK5OY-CkLSasvk.js} +1 -1
  88. package/dist/web/assets/{wardleyDiagram-VM6X3IG4-CnkLT61Q.js → wardleyDiagram-VM6X3IG4-DfPte2eh.js} +1 -1
  89. package/dist/web/assets/{xychartDiagram-S5SC5T6Z-Bvv63kic.js → xychartDiagram-S5SC5T6Z-ClFkeona.js} +1 -1
  90. package/dist/web/index.html +2 -2
  91. package/package.json +1 -1
  92. package/dist/web/assets/Sessions-CCpWptIl.js +0 -5
  93. package/dist/web/assets/Terminals-wWVDPX68.js +0 -115
  94. package/dist/web/assets/channel-BSVHIa5R.js +0 -1
  95. package/dist/web/assets/classDiagram-ZZMXUADV-3BGzDrBP.js +0 -1
  96. package/dist/web/assets/classDiagram-v2-VYDZK3BY-3BGzDrBP.js +0 -1
  97. package/dist/web/assets/index-CB3c1nr-.css +0 -1
  98. package/dist/web/assets/index-SOCnaNS0.js +0 -453
  99. package/dist/web/assets/stateDiagram-v2-MP3YSRHH-CXtInY-i.js +0 -1
  100. package/dist/web/assets/swimlanesDiagram-VR7AAH4N-DyVW1GT5.js +0 -8
  101. package/dist/web/assets/useProjectScope-B28fk5NO.js +0 -1
@@ -1,4 +1,4 @@
1
- import{c as ua,$ as we,r as z,j as t,k as Fe,i as Ca,u as ve,a2 as Pa,a3 as Sa,a4 as Aa,a5 as Ma,a6 as Fa,B as J,d as V,U as Ee,W as Le,X as De,at as Qe,Y as re,Z as he,ah as We,b as je,a8 as Xe,h as ma,_ as $a,bZ as Ia,a1 as Ea,a as La,g as Da,a0 as Oa,V as za,aB as Ba,b_ as Ra,b$ as Ua}from"./index-SOCnaNS0.js";import{p as $e,i as ra,a as Ta,s as qa}from"./public-api-BvD4z7ja.js";import{r as pa}from"./primitive-files-BwTyowra.js";import{U as Ka}from"./upload-CCnbjfQN.js";/**
1
+ import{c as ua,$ as we,r as z,j as t,k as Fe,i as Ca,u as ve,a2 as Pa,a3 as Sa,a4 as Aa,a5 as Ma,a6 as Fa,B as J,d as V,U as Ee,W as Le,X as De,at as Qe,Y as re,Z as he,ah as We,b as je,a8 as Xe,h as ma,_ as $a,b_ as Ia,a1 as Ea,a as La,g as Da,a0 as Oa,V as za,aC as Ra,b$ as Ua,c0 as Ba}from"./index-BqQDBYwx.js";import{p as $e,i as ra,a as Ta,s as qa}from"./public-api-BvD4z7ja.js";import{r as pa}from"./primitive-files-BwTyowra.js";import{U as Ka}from"./upload-waJ36Q68.js";/**
2
2
  * @license lucide-react v1.27.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,11 +8,11 @@ import{c as ua,$ as we,r as z,j as t,k as Fe,i as Ca,u as ve,a2 as Pa,a3 as Sa,a
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Va=[["path",{d:"M12 22V12",key:"d0xqtd"}],["path",{d:"M16 17h6",key:"1ook5g"}],["path",{d:"M19 14v6",key:"1ckrd5"}],["path",{d:"M21 10.535V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.675-.955",key:"28k6lz"}],["path",{d:"M3.29 7 12 12l8.71-5",key:"19ckod"}],["path",{d:"m7.5 4.27 8.997 5.148",key:"9yrvtv"}]],Ja=ua("package-plus",Va);var Z=Uint8Array,ne=Uint16Array,ea=Int32Array,Oe=new Z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ze=new Z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),He=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ga=function(e,a){for(var r=new ne(31),n=0;n<31;++n)r[n]=a+=1<<e[n-1];for(var s=new ea(r[30]),n=1;n<30;++n)for(var i=r[n];i<r[n+1];++i)s[i]=i-r[n]<<5|n;return{b:r,r:s}},fa=ga(Oe,2),ha=fa.b,Ve=fa.r;ha[28]=258,Ve[258]=28;var va=ga(ze,0),_a=va.b,na=va.r,Je=new ne(32768);for(var K=0;K<32768;++K){var fe=(K&43690)>>1|(K&21845)<<1;fe=(fe&52428)>>2|(fe&13107)<<2,fe=(fe&61680)>>4|(fe&3855)<<4,Je[K]=((fe&65280)>>8|(fe&255)<<8)>>1}var ce=(function(e,a,r){for(var n=e.length,s=0,i=new ne(a);s<n;++s)e[s]&&++i[e[s]-1];var l=new ne(a);for(s=1;s<a;++s)l[s]=l[s-1]+i[s-1]<<1;var f;if(r){f=new ne(1<<a);var o=15-a;for(s=0;s<n;++s)if(e[s])for(var v=s<<4|e[s],d=a-e[s],c=l[e[s]-1]++<<d,m=c|(1<<d)-1;c<=m;++c)f[Je[c]>>o]=v}else for(f=new ne(n),s=0;s<n;++s)e[s]&&(f[s]=Je[l[e[s]-1]++]>>15-e[s]);return f}),xe=new Z(288);for(var K=0;K<144;++K)xe[K]=8;for(var K=144;K<256;++K)xe[K]=9;for(var K=256;K<280;++K)xe[K]=7;for(var K=280;K<288;++K)xe[K]=8;var Pe=new Z(32);for(var K=0;K<32;++K)Pe[K]=5;var Ga=ce(xe,9,0),Ya=ce(xe,9,1),Za=ce(Pe,5,0),Qa=ce(Pe,5,1),Ue=function(e){for(var a=e[0],r=1;r<e.length;++r)e[r]>a&&(a=e[r]);return a},ie=function(e,a,r){var n=a/8|0;return(e[n]|e[n+1]<<8)>>(a&7)&r},Te=function(e,a){var r=a/8|0;return(e[r]|e[r+1]<<8|e[r+2]<<16)>>(a&7)},aa=function(e){return(e+7)/8|0},Se=function(e,a,r){return(a==null||a<0)&&(a=0),(r==null||r>e.length)&&(r=e.length),new Z(e.subarray(a,r))},Xa=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],te=function(e,a,r){var n=new Error(a||Xa[e]);if(n.code=e,Error.captureStackTrace&&Error.captureStackTrace(n,te),!r)throw n;return n},et=function(e,a,r,n){var s=e.length,i=n?n.length:0;if(!s||a.f&&!a.l)return r||new Z(0);var l=!r,f=l||a.i!=2,o=a.i;l&&(r=new Z(s*3));var v=function(pe){var ge=r.length;if(pe>ge){var de=new Z(Math.max(ge*2,pe));de.set(r),r=de}},d=a.f||0,c=a.p||0,m=a.b||0,y=a.l,u=a.d,w=a.m,P=a.n,N=s*8;do{if(!y){d=ie(e,c,1);var b=ie(e,c+1,3);if(c+=3,b)if(b==1)y=Ya,u=Qa,w=9,P=5;else if(b==2){var R=ie(e,c,31)+257,M=ie(e,c+10,15)+4,C=R+ie(e,c+5,31)+1;c+=14;for(var j=new Z(C),O=new Z(19),E=0;E<M;++E)O[He[E]]=ie(e,c+E*3,7);c+=M*3;for(var U=Ue(O),q=(1<<U)-1,h=ce(O,U,1),E=0;E<C;){var I=h[ie(e,c,q)];c+=I&15;var S=I>>4;if(S<16)j[E++]=S;else{var B=0,$=0;for(S==16?($=3+ie(e,c,3),c+=2,B=j[E-1]):S==17?($=3+ie(e,c,7),c+=3):S==18&&($=11+ie(e,c,127),c+=7);$--;)j[E++]=B}}var T=j.subarray(0,R),x=j.subarray(R);w=Ue(T),P=Ue(x),y=ce(T,w,1),u=ce(x,P,1)}else te(1);else{var S=aa(c)+4,A=e[S-4]|e[S-3]<<8,D=S+A;if(D>s){o&&te(0);break}f&&v(m+A),r.set(e.subarray(S,D),m),a.b=m+=A,a.p=c=D*8,a.f=d;continue}if(c>N){o&&te(0);break}}f&&v(m+131072);for(var L=(1<<w)-1,W=(1<<P)-1,Y=c;;Y=c){var B=y[Te(e,c)&L],H=B>>4;if(c+=B&15,c>N){o&&te(0);break}if(B||te(2),H<256)r[m++]=H;else if(H==256){Y=c,y=null;break}else{var p=H-254;if(H>264){var E=H-257,k=Oe[E];p=ie(e,c,(1<<k)-1)+ha[E],c+=k}var _=u[Te(e,c)&W],Q=_>>4;_||te(3),c+=_&15;var x=_a[Q];if(Q>3){var k=ze[Q];x+=Te(e,c)&(1<<k)-1,c+=k}if(c>N){o&&te(0);break}f&&v(m+131072);var ee=m+p;if(m<x){var se=i-x,ke=Math.min(x,ee);for(se+m<0&&te(3);m<ke;++m)r[m]=n[se+m]}for(;m<ee;++m)r[m]=r[m-x]}}a.l=y,a.p=Y,a.b=m,a.f=d,y&&(d=1,a.m=w,a.d=u,a.n=P)}while(!d);return m!=r.length&&l?Se(r,0,m):r.subarray(0,m)},ue=function(e,a,r){r<<=a&7;var n=a/8|0;e[n]|=r,e[n+1]|=r>>8},Ne=function(e,a,r){r<<=a&7;var n=a/8|0;e[n]|=r,e[n+1]|=r>>8,e[n+2]|=r>>16},qe=function(e,a){for(var r=[],n=0;n<e.length;++n)e[n]&&r.push({s:n,f:e[n]});var s=r.length,i=r.slice();if(!s)return{t:ka,l:0};if(s==1){var l=new Z(r[0].s+1);return l[r[0].s]=1,{t:l,l:1}}r.sort(function(D,R){return D.f-R.f}),r.push({s:-1,f:25001});var f=r[0],o=r[1],v=0,d=1,c=2;for(r[0]={s:-1,f:f.f+o.f,l:f,r:o};d!=s-1;)f=r[r[v].f<r[c].f?v++:c++],o=r[v!=d&&r[v].f<r[c].f?v++:c++],r[d++]={s:-1,f:f.f+o.f,l:f,r:o};for(var m=i[0].s,n=1;n<s;++n)i[n].s>m&&(m=i[n].s);var y=new ne(m+1),u=_e(r[d-1],y,0);if(u>a){var n=0,w=0,P=u-a,N=1<<P;for(i.sort(function(R,M){return y[M.s]-y[R.s]||R.f-M.f});n<s;++n){var b=i[n].s;if(y[b]>a)w+=N-(1<<u-y[b]),y[b]=a;else break}for(w>>=P;w>0;){var S=i[n].s;y[S]<a?w-=1<<a-y[S]++-1:++n}for(;n>=0&&w;--n){var A=i[n].s;y[A]==a&&(--y[A],++w)}u=a}return{t:new Z(y),l:u}},_e=function(e,a,r){return e.s==-1?Math.max(_e(e.l,a,r+1),_e(e.r,a,r+1)):a[e.s]=r},sa=function(e){for(var a=e.length;a&&!e[--a];);for(var r=new ne(++a),n=0,s=e[0],i=1,l=function(o){r[n++]=o},f=1;f<=a;++f)if(e[f]==s&&f!=a)++i;else{if(!s&&i>2){for(;i>138;i-=138)l(32754);i>2&&(l(i>10?i-11<<5|28690:i-3<<5|12305),i=0)}else if(i>3){for(l(s),--i;i>6;i-=6)l(8304);i>2&&(l(i-3<<5|8208),i=0)}for(;i--;)l(s);i=1,s=e[f]}return{c:r.subarray(0,n),n:a}},Ce=function(e,a){for(var r=0,n=0;n<a.length;++n)r+=e[n]*a[n];return r},xa=function(e,a,r){var n=r.length,s=aa(a+2);e[s]=n&255,e[s+1]=n>>8,e[s+2]=e[s]^255,e[s+3]=e[s+1]^255;for(var i=0;i<n;++i)e[s+i+4]=r[i];return(s+4+n)*8},oa=function(e,a,r,n,s,i,l,f,o,v,d){ue(a,d++,r),++s[256];for(var c=qe(s,15),m=c.t,y=c.l,u=qe(i,15),w=u.t,P=u.l,N=sa(m),b=N.c,S=N.n,A=sa(w),D=A.c,R=A.n,M=new ne(19),C=0;C<b.length;++C)++M[b[C]&31];for(var C=0;C<D.length;++C)++M[D[C]&31];for(var j=qe(M,7),O=j.t,E=j.l,U=19;U>4&&!O[He[U-1]];--U);var q=v+5<<3,h=Ce(s,xe)+Ce(i,Pe)+l,I=Ce(s,m)+Ce(i,w)+l+14+3*U+Ce(M,O)+2*M[16]+3*M[17]+7*M[18];if(o>=0&&q<=h&&q<=I)return xa(a,d,e.subarray(o,o+v));var B,$,T,x;if(ue(a,d,1+(I<h)),d+=2,I<h){B=ce(m,y,0),$=m,T=ce(w,P,0),x=w;var L=ce(O,E,0);ue(a,d,S-257),ue(a,d+5,R-1),ue(a,d+10,U-4),d+=14;for(var C=0;C<U;++C)ue(a,d+3*C,O[He[C]]);d+=3*U;for(var W=[b,D],Y=0;Y<2;++Y)for(var H=W[Y],C=0;C<H.length;++C){var p=H[C]&31;ue(a,d,L[p]),d+=O[p],p>15&&(ue(a,d,H[C]>>5&127),d+=H[C]>>12)}}else B=Ga,$=xe,T=Za,x=Pe;for(var C=0;C<f;++C){var k=n[C];if(k>255){var p=k>>18&31;Ne(a,d,B[p+257]),d+=$[p+257],p>7&&(ue(a,d,k>>23&31),d+=Oe[p]);var _=k&31;Ne(a,d,T[_]),d+=x[_],_>3&&(Ne(a,d,k>>5&8191),d+=ze[_])}else Ne(a,d,B[k]),d+=$[k]}return Ne(a,d,B[256]),d+$[256]},at=new ea([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),ka=new Z(0),tt=function(e,a,r,n,s,i){var l=i.z||e.length,f=new Z(n+l+5*(1+Math.ceil(l/7e3))+s),o=f.subarray(n,f.length-s),v=i.l,d=(i.r||0)&7;if(a){d&&(o[0]=i.r>>3);for(var c=at[a-1],m=c>>13,y=c&8191,u=(1<<r)-1,w=i.p||new ne(32768),P=i.h||new ne(u+1),N=Math.ceil(r/3),b=2*N,S=function(ye){return(e[ye]^e[ye+1]<<N^e[ye+2]<<b)&u},A=new ea(25e3),D=new ne(288),R=new ne(32),M=0,C=0,j=i.i||0,O=0,E=i.w||0,U=0;j+2<l;++j){var q=S(j),h=j&32767,I=P[q];if(w[h]=I,P[q]=h,E<=j){var B=l-j;if((M>7e3||O>24576)&&(B>423||!v)){d=oa(e,o,0,A,D,R,C,O,U,j-U,d),O=M=C=0,U=j;for(var $=0;$<286;++$)D[$]=0;for(var $=0;$<30;++$)R[$]=0}var T=2,x=0,L=y,W=h-I&32767;if(B>2&&q==S(j-W))for(var Y=Math.min(m,B)-1,H=Math.min(32767,j),p=Math.min(258,B);W<=H&&--L&&h!=I;){if(e[j+T]==e[j+T-W]){for(var k=0;k<p&&e[j+k]==e[j+k-W];++k);if(k>T){if(T=k,x=W,k>Y)break;for(var _=Math.min(W,k-2),Q=0,$=0;$<_;++$){var ee=j-W+$&32767,se=w[ee],ke=ee-se&32767;ke>Q&&(Q=ke,I=ee)}}}h=I,I=w[h],W+=h-I&32767}if(x){A[O++]=268435456|Ve[T]<<18|na[x];var pe=Ve[T]&31,ge=na[x]&31;C+=Oe[pe]+ze[ge],++D[257+pe],++R[ge],E=j+T,++M}else A[O++]=e[j],++D[e[j]]}}for(j=Math.max(j,E);j<l;++j)A[O++]=e[j],++D[e[j]];d=oa(e,o,v,A,D,R,C,O,U,j-U,d),v||(i.r=d&7|o[d/8|0]<<3,d-=7,i.h=P,i.p=w,i.i=j,i.w=E)}else{for(var j=i.w||0;j<l+v;j+=65535){var de=j+65535;de>=l&&(o[d/8|0]=v,de=l),d=xa(o,d+1,e.subarray(j,de))}i.i=l}return Se(f,0,n+aa(d)+s)},rt=(function(){for(var e=new Int32Array(256),a=0;a<256;++a){for(var r=a,n=9;--n;)r=(r&1&&-306674912)^r>>>1;e[a]=r}return e})(),nt=function(){var e=-1;return{p:function(a){for(var r=e,n=0;n<a.length;++n)r=rt[r&255^a[n]]^r>>>8;e=r},d:function(){return~e}}},st=function(e,a,r,n,s){if(!s&&(s={l:1},a.dictionary)){var i=a.dictionary.subarray(-32768),l=new Z(i.length+e.length);l.set(i),l.set(e,i.length),e=l,s.w=i.length}return tt(e,a.level==null?6:a.level,a.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+a.mem,r,n,s)},wa=function(e,a){var r={};for(var n in e)r[n]=e[n];for(var n in a)r[n]=a[n];return r},le=function(e,a){return e[a]|e[a+1]<<8},oe=function(e,a){return(e[a]|e[a+1]<<8|e[a+2]<<16|e[a+3]<<24)>>>0},Ke=function(e,a){return oe(e,a)+oe(e,a+4)*4294967296},X=function(e,a,r){for(;r;++a)e[a]=r,r>>>=8};function ot(e,a){return st(e,a||{},0,0)}function it(e,a){return et(e,{i:2},a&&a.out,a&&a.dictionary)}var ya=function(e,a,r,n){for(var s in e){var i=e[s],l=a+s,f=n;Array.isArray(i)&&(f=wa(n,i[1]),i=i[0]),ArrayBuffer.isView(i)?r[l]=[i,f]:(r[l+="/"]=[new Z(0),f],ya(i,l,r,n))}},ia=typeof TextEncoder<"u"&&new TextEncoder,Ge=typeof TextDecoder<"u"&&new TextDecoder,lt=0;try{Ge.decode(ka,{stream:!0}),lt=1}catch{}var ct=function(e){for(var a="",r=0;;){var n=e[r++],s=(n>127)+(n>223)+(n>239);if(r+s>e.length)return{s:a,r:Se(e,r-1)};s?s==3?(n=((n&15)<<18|(e[r++]&63)<<12|(e[r++]&63)<<6|e[r++]&63)-65536,a+=String.fromCharCode(55296|n>>10,56320|n&1023)):s&1?a+=String.fromCharCode((n&31)<<6|e[r++]&63):a+=String.fromCharCode((n&15)<<12|(e[r++]&63)<<6|e[r++]&63):a+=String.fromCharCode(n)}};function Ie(e,a){var r;if(ia)return ia.encode(e);for(var n=e.length,s=new Z(e.length+(e.length>>1)),i=0,l=function(v){s[i++]=v},r=0;r<n;++r){if(i+5>s.length){var f=new Z(i+8+(n-r<<1));f.set(s),s=f}var o=e.charCodeAt(r);o<128||a?l(o):o<2048?(l(192|o>>6),l(128|o&63)):o>55295&&o<57344?(o=65536+(o&1047552)|e.charCodeAt(++r)&1023,l(240|o>>18),l(128|o>>12&63),l(128|o>>6&63),l(128|o&63)):(l(224|o>>12),l(128|o>>6&63),l(128|o&63))}return Se(s,0,i)}function dt(e,a){if(a){for(var r="",n=0;n<e.length;n+=16384)r+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return r}else{if(Ge)return Ge.decode(e);var s=ct(e),i=s.s,r=s.r;return r.length&&te(8),i}}var ut=function(e,a){return a+30+le(e,a+26)+le(e,a+28)},mt=function(e,a,r){var n=le(e,a+28),s=le(e,a+30),i=dt(e.subarray(a+46,a+46+n),!(le(e,a+8)&2048)),l=a+46+n,f=pt(e,l,s,r,oe(e,a+20),oe(e,a+24),oe(e,a+42)),o=f[0],v=f[1],d=f[2];return[le(e,a+10),o,v,i,l+s+le(e,a+32),d]},pt=function(e,a,r,n,s,i,l){var f=s==4294967295,o=i==4294967295,v=l==4294967295,d=a+r,c=f+o+v;if(n&&c){for(;a+4<d;a+=4+le(e,a+2))if(le(e,a)==1)return[f?Ke(e,a+4+8*o):s,o?Ke(e,a+4):i,v?Ke(e,a+4+8*(o+f)):l,1];n<2&&te(13)}return[s,i,l,0]},Ye=function(e){var a=0;if(e)for(var r in e){var n=e[r].length;n>65535&&te(9),a+=n+4}return a},la=function(e,a,r,n,s,i,l,f){var o=n.length,v=r.extra,d=f&&f.length,c=Ye(v);X(e,a,l!=null?33639248:67324752),a+=4,l!=null&&(e[a++]=20,e[a++]=r.os),e[a]=20,a+=2,e[a++]=r.flag<<1|(i<0&&8),e[a++]=s&&8,e[a++]=r.compression&255,e[a++]=r.compression>>8;var m=new Date(r.mtime==null?Date.now():r.mtime),y=m.getFullYear()-1980;if((y<0||y>119)&&te(10),X(e,a,y<<25|m.getMonth()+1<<21|m.getDate()<<16|m.getHours()<<11|m.getMinutes()<<5|m.getSeconds()>>1),a+=4,i!=-1&&(X(e,a,r.crc),X(e,a+4,i<0?-i-2:i),X(e,a+8,r.size)),X(e,a+12,o),X(e,a+14,c),a+=16,l!=null&&(X(e,a,d),X(e,a+6,r.attrs),X(e,a+10,l),a+=14),e.set(n,a),a+=o,c)for(var u in v){var w=v[u],P=w.length;X(e,a,+u),X(e,a+2,P),e.set(w,a+4),a+=4+P}return d&&(e.set(f,a),a+=d),a},gt=function(e,a,r,n,s){X(e,a,101010256),X(e,a+8,r),X(e,a+10,r),X(e,a+12,n),X(e,a+16,s)};function ft(e,a){a||(a={});var r={},n=[];ya(e,"",r,a);var s=0,i=0;for(var l in r){var f=r[l],o=f[0],v=f[1],d=v.level==0?0:8,c=Ie(l),m=c.length,y=v.comment,u=y&&Ie(y),w=u&&u.length,P=Ye(v.extra);m>65535&&te(11);var N=d?ot(o,v):o,b=N.length,S=nt();S.p(o),n.push(wa(v,{size:o.length,crc:S.d(),c:N,f:c,m:u,u:m!=l.length||u&&y.length!=w,o:s,compression:d})),s+=30+m+P+b,i+=76+2*(m+P)+(w||0)+b}for(var A=new Z(i+22),D=s,R=i-s,M=0;M<n.length;++M){var c=n[M];la(A,c.o,c,c.f,c.u,c.c.length);var C=30+c.f.length+Ye(c.extra);A.set(c.c,c.o+C),la(A,s,c,c.f,c.u,c.c.length,c.o,c.m),s+=16+C+(c.m?c.m.length:0)}return gt(A,s,n.length,R,D),A}function ht(e,a){for(var r={},n=e.length-22;oe(e,n)!=101010256;--n)(!n||e.length-n>65558)&&te(13);var s=le(e,n+8);if(!s)return{};var i=oe(e,n+16),l=oe(e,n-20)==117853008;if(l){var f=oe(e,n-12);l=oe(e,f)==101075792,l&&(s=oe(e,f+32),i=oe(e,f+48))}for(var o=a&&a.filter,v=0;v<s;++v){var d=mt(e,i,l),c=d[0],m=d[1],y=d[2],u=d[3],w=d[4],P=d[5],N=ut(e,P);i=w,(!o||o({name:u,size:m,originalSize:y,compression:c}))&&(c?c==8?r[u]=it(e.subarray(N,N+m),{out:new Z(y)}):te(14,"unknown compression type "+c):r[u]=Se(e,N,N+m))}return r}function ja({files:e,readOnly:a=!1,onChange:r,testId:n}){var c,m,y;const[s,i]=we(a?"packageFile":"packageDraftFile",((c=e[0])==null?void 0:c.path)??""),[l,f]=we("editorMode",a?"read":"edit",["read","edit","split"]),[o,v]=z.useState([((m=e[0])==null?void 0:m.path)??""]),d=e.some(u=>u.path===s)?s:(y=e[0])==null?void 0:y.path;return t.jsxs("div",{className:"min-w-0 overflow-hidden rounded-lg border border-surface-highest",children:[t.jsx("div",{role:"tablist","aria-label":"Package files",className:"flex overflow-x-auto bg-background",children:e.map(u=>t.jsx("button",{type:"button",role:"tab","aria-selected":d===u.path,"data-testid":"package-file","data-file-name":u.path,title:u.path,className:`shrink-0 border-r border-surface-highest px-4 py-3 text-sm ${d===u.path?"border-t-2 border-t-transparent bg-surface-highest text-on-surface":"border-t-2 border-t-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface"}`,onClick:()=>{i(u.path),v(w=>w.includes(u.path)?w:[...w,u.path])},onKeyDown:w=>{var A;const P=e.findIndex(D=>D.path===u.path),N=w.key==="ArrowRight"?P+1:w.key==="ArrowLeft"?P-1:void 0;if(N===void 0)return;w.preventDefault();const b=(A=w.currentTarget.parentElement)==null?void 0:A.querySelectorAll('[role="tab"]'),S=b==null?void 0:b[(N+e.length)%e.length];S==null||S.focus(),S==null||S.click()},children:u.path.endsWith("/SKILL.md")?u.path.split("/").slice(-2).join("/"):u.path.split("/").pop()},u.path))}),e.filter(u=>o.includes(u.path)||d===u.path).map(u=>t.jsxs("div",{role:"tabpanel","aria-label":u.path,hidden:d!==u.path,className:"[&_[data-testid=code-editor]>div>span[title]]:hidden [&_[data-testid=markdown-editor]>div>span[title]]:hidden",children:[t.jsx(Fe,{mode:Ca(u.path)?l:void 0,onModeChange:f,path:u.path,value:u.content,onChange:r?w=>r(u.path,w):void 0,readOnly:a||u.encoding==="base64",height:420,testId:d===u.path?n:void 0}),u.encoding==="base64"&&t.jsx("p",{className:"px-4 py-2 text-xs text-outline",children:"Binary asset shown as base64."})]},u.path))]})}function vt({name:e,onClose:a,onUse:r,onEdit:n,onExport:s,onSource:i,busy:l,operationError:f}){var d,c,m,y;const o=ve({queryKey:["agent-package",e],queryFn:()=>V.agentPackages.get(e)}),v=ve({enabled:!!o.data,queryKey:["agent-package-files",e],queryFn:async()=>{const u=o.data;if(!u)return[];const w=await Promise.all(u.files.map(async P=>{const N=await V.agentPackages.get(e,P.name);return{path:P.name,content:N.content,encoding:N.encoding}}));return[{path:u.manifestFile,content:u.content},...w]}});return t.jsx(Pa,{open:!0,onOpenChange:u=>{u||a()},children:t.jsxs(Sa,{className:"w-screen max-w-full sm:w-[720px] sm:max-w-[90vw]",children:[t.jsx(Aa,{children:t.jsx(Ma,{children:e})}),t.jsxs(Fa,{children:[t.jsxs("div",{className:"mb-5 space-y-3",children:[t.jsx("p",{className:"text-sm text-outline break-words",children:(d=o.data)==null?void 0:d.description}),o.data&&t.jsxs("p",{className:"text-xs text-outline",children:[o.data.files.filter(u=>/(^|\/)SKILL\.md$/.test(u.name)).length," ","skills ·"," ",o.data.files.filter(u=>u.name.endsWith(".instructions.md")).length," ","instruction files ·"," ",o.data.files.filter(u=>u.name.endsWith(".agent.md")).length," agent definitions"]}),(c=o.data)==null?void 0:c.warnings.map(u=>t.jsx("p",{role:"alert",className:"text-xs text-destructive break-words",children:u},u)),t.jsxs("div",{className:"grid gap-2 grid-cols-2",children:[r&&t.jsx(J,{"data-testid":"package-detail-run",onClick:r,disabled:l,children:"Use package"}),n&&t.jsx(J,{"data-testid":"package-edit",variant:"outline",onClick:n,disabled:l,children:"Edit configuration"}),s&&t.jsx(J,{"data-testid":"package-export-artifact",variant:"outline",onClick:s,disabled:l,children:l?"Preparing…":"Export for installation"}),i&&t.jsx(J,{"data-testid":"package-export",variant:"outline",onClick:i,disabled:l,children:"Download source"})]}),t.jsxs("p",{className:"text-xs text-outline",children:["APM builds installation exports (",((m=o.data)==null?void 0:m.format)==="agent-plugin"?"portable Agent Plugin":"Claude plugin","). Download source preserves the editable manifest and all files."]}),f&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f})]}),o.error||v.error?t.jsx("p",{role:"alert",children:(y=o.error??v.error)==null?void 0:y.message}):v.isLoading?t.jsx("p",{children:"Loading files…"}):t.jsx(ja,{files:v.data??[],readOnly:!0,testId:"package-file-content"})]})]})})}const ba="https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",xt="https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";function Ae(e){return e==="apm"?`name: my-agent-package
11
+ */const Va=[["path",{d:"M12 22V12",key:"d0xqtd"}],["path",{d:"M16 17h6",key:"1ook5g"}],["path",{d:"M19 14v6",key:"1ckrd5"}],["path",{d:"M21 10.535V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.675-.955",key:"28k6lz"}],["path",{d:"M3.29 7 12 12l8.71-5",key:"19ckod"}],["path",{d:"m7.5 4.27 8.997 5.148",key:"9yrvtv"}]],Ja=ua("package-plus",Va);var Z=Uint8Array,ne=Uint16Array,ea=Int32Array,Oe=new Z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ze=new Z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),He=new Z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),ga=function(e,a){for(var r=new ne(31),n=0;n<31;++n)r[n]=a+=1<<e[n-1];for(var s=new ea(r[30]),n=1;n<30;++n)for(var i=r[n];i<r[n+1];++i)s[i]=i-r[n]<<5|n;return{b:r,r:s}},fa=ga(Oe,2),ha=fa.b,Ve=fa.r;ha[28]=258,Ve[258]=28;var va=ga(ze,0),_a=va.b,na=va.r,Je=new ne(32768);for(var K=0;K<32768;++K){var fe=(K&43690)>>1|(K&21845)<<1;fe=(fe&52428)>>2|(fe&13107)<<2,fe=(fe&61680)>>4|(fe&3855)<<4,Je[K]=((fe&65280)>>8|(fe&255)<<8)>>1}var ce=(function(e,a,r){for(var n=e.length,s=0,i=new ne(a);s<n;++s)e[s]&&++i[e[s]-1];var l=new ne(a);for(s=1;s<a;++s)l[s]=l[s-1]+i[s-1]<<1;var f;if(r){f=new ne(1<<a);var o=15-a;for(s=0;s<n;++s)if(e[s])for(var v=s<<4|e[s],d=a-e[s],c=l[e[s]-1]++<<d,m=c|(1<<d)-1;c<=m;++c)f[Je[c]>>o]=v}else for(f=new ne(n),s=0;s<n;++s)e[s]&&(f[s]=Je[l[e[s]-1]++]>>15-e[s]);return f}),xe=new Z(288);for(var K=0;K<144;++K)xe[K]=8;for(var K=144;K<256;++K)xe[K]=9;for(var K=256;K<280;++K)xe[K]=7;for(var K=280;K<288;++K)xe[K]=8;var Pe=new Z(32);for(var K=0;K<32;++K)Pe[K]=5;var Ga=ce(xe,9,0),Ya=ce(xe,9,1),Za=ce(Pe,5,0),Qa=ce(Pe,5,1),Be=function(e){for(var a=e[0],r=1;r<e.length;++r)e[r]>a&&(a=e[r]);return a},ie=function(e,a,r){var n=a/8|0;return(e[n]|e[n+1]<<8)>>(a&7)&r},Te=function(e,a){var r=a/8|0;return(e[r]|e[r+1]<<8|e[r+2]<<16)>>(a&7)},aa=function(e){return(e+7)/8|0},Se=function(e,a,r){return(a==null||a<0)&&(a=0),(r==null||r>e.length)&&(r=e.length),new Z(e.subarray(a,r))},Xa=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],te=function(e,a,r){var n=new Error(a||Xa[e]);if(n.code=e,Error.captureStackTrace&&Error.captureStackTrace(n,te),!r)throw n;return n},et=function(e,a,r,n){var s=e.length,i=n?n.length:0;if(!s||a.f&&!a.l)return r||new Z(0);var l=!r,f=l||a.i!=2,o=a.i;l&&(r=new Z(s*3));var v=function(pe){var ge=r.length;if(pe>ge){var de=new Z(Math.max(ge*2,pe));de.set(r),r=de}},d=a.f||0,c=a.p||0,m=a.b||0,y=a.l,u=a.d,w=a.m,P=a.n,N=s*8;do{if(!y){d=ie(e,c,1);var b=ie(e,c+1,3);if(c+=3,b)if(b==1)y=Ya,u=Qa,w=9,P=5;else if(b==2){var U=ie(e,c,31)+257,M=ie(e,c+10,15)+4,C=U+ie(e,c+5,31)+1;c+=14;for(var j=new Z(C),O=new Z(19),E=0;E<M;++E)O[He[E]]=ie(e,c+E*3,7);c+=M*3;for(var B=Be(O),q=(1<<B)-1,h=ce(O,B,1),E=0;E<C;){var I=h[ie(e,c,q)];c+=I&15;var S=I>>4;if(S<16)j[E++]=S;else{var R=0,$=0;for(S==16?($=3+ie(e,c,3),c+=2,R=j[E-1]):S==17?($=3+ie(e,c,7),c+=3):S==18&&($=11+ie(e,c,127),c+=7);$--;)j[E++]=R}}var T=j.subarray(0,U),x=j.subarray(U);w=Be(T),P=Be(x),y=ce(T,w,1),u=ce(x,P,1)}else te(1);else{var S=aa(c)+4,A=e[S-4]|e[S-3]<<8,D=S+A;if(D>s){o&&te(0);break}f&&v(m+A),r.set(e.subarray(S,D),m),a.b=m+=A,a.p=c=D*8,a.f=d;continue}if(c>N){o&&te(0);break}}f&&v(m+131072);for(var L=(1<<w)-1,W=(1<<P)-1,Y=c;;Y=c){var R=y[Te(e,c)&L],H=R>>4;if(c+=R&15,c>N){o&&te(0);break}if(R||te(2),H<256)r[m++]=H;else if(H==256){Y=c,y=null;break}else{var p=H-254;if(H>264){var E=H-257,k=Oe[E];p=ie(e,c,(1<<k)-1)+ha[E],c+=k}var _=u[Te(e,c)&W],Q=_>>4;_||te(3),c+=_&15;var x=_a[Q];if(Q>3){var k=ze[Q];x+=Te(e,c)&(1<<k)-1,c+=k}if(c>N){o&&te(0);break}f&&v(m+131072);var ee=m+p;if(m<x){var se=i-x,ke=Math.min(x,ee);for(se+m<0&&te(3);m<ke;++m)r[m]=n[se+m]}for(;m<ee;++m)r[m]=r[m-x]}}a.l=y,a.p=Y,a.b=m,a.f=d,y&&(d=1,a.m=w,a.d=u,a.n=P)}while(!d);return m!=r.length&&l?Se(r,0,m):r.subarray(0,m)},ue=function(e,a,r){r<<=a&7;var n=a/8|0;e[n]|=r,e[n+1]|=r>>8},Ne=function(e,a,r){r<<=a&7;var n=a/8|0;e[n]|=r,e[n+1]|=r>>8,e[n+2]|=r>>16},qe=function(e,a){for(var r=[],n=0;n<e.length;++n)e[n]&&r.push({s:n,f:e[n]});var s=r.length,i=r.slice();if(!s)return{t:ka,l:0};if(s==1){var l=new Z(r[0].s+1);return l[r[0].s]=1,{t:l,l:1}}r.sort(function(D,U){return D.f-U.f}),r.push({s:-1,f:25001});var f=r[0],o=r[1],v=0,d=1,c=2;for(r[0]={s:-1,f:f.f+o.f,l:f,r:o};d!=s-1;)f=r[r[v].f<r[c].f?v++:c++],o=r[v!=d&&r[v].f<r[c].f?v++:c++],r[d++]={s:-1,f:f.f+o.f,l:f,r:o};for(var m=i[0].s,n=1;n<s;++n)i[n].s>m&&(m=i[n].s);var y=new ne(m+1),u=_e(r[d-1],y,0);if(u>a){var n=0,w=0,P=u-a,N=1<<P;for(i.sort(function(U,M){return y[M.s]-y[U.s]||U.f-M.f});n<s;++n){var b=i[n].s;if(y[b]>a)w+=N-(1<<u-y[b]),y[b]=a;else break}for(w>>=P;w>0;){var S=i[n].s;y[S]<a?w-=1<<a-y[S]++-1:++n}for(;n>=0&&w;--n){var A=i[n].s;y[A]==a&&(--y[A],++w)}u=a}return{t:new Z(y),l:u}},_e=function(e,a,r){return e.s==-1?Math.max(_e(e.l,a,r+1),_e(e.r,a,r+1)):a[e.s]=r},sa=function(e){for(var a=e.length;a&&!e[--a];);for(var r=new ne(++a),n=0,s=e[0],i=1,l=function(o){r[n++]=o},f=1;f<=a;++f)if(e[f]==s&&f!=a)++i;else{if(!s&&i>2){for(;i>138;i-=138)l(32754);i>2&&(l(i>10?i-11<<5|28690:i-3<<5|12305),i=0)}else if(i>3){for(l(s),--i;i>6;i-=6)l(8304);i>2&&(l(i-3<<5|8208),i=0)}for(;i--;)l(s);i=1,s=e[f]}return{c:r.subarray(0,n),n:a}},Ce=function(e,a){for(var r=0,n=0;n<a.length;++n)r+=e[n]*a[n];return r},xa=function(e,a,r){var n=r.length,s=aa(a+2);e[s]=n&255,e[s+1]=n>>8,e[s+2]=e[s]^255,e[s+3]=e[s+1]^255;for(var i=0;i<n;++i)e[s+i+4]=r[i];return(s+4+n)*8},oa=function(e,a,r,n,s,i,l,f,o,v,d){ue(a,d++,r),++s[256];for(var c=qe(s,15),m=c.t,y=c.l,u=qe(i,15),w=u.t,P=u.l,N=sa(m),b=N.c,S=N.n,A=sa(w),D=A.c,U=A.n,M=new ne(19),C=0;C<b.length;++C)++M[b[C]&31];for(var C=0;C<D.length;++C)++M[D[C]&31];for(var j=qe(M,7),O=j.t,E=j.l,B=19;B>4&&!O[He[B-1]];--B);var q=v+5<<3,h=Ce(s,xe)+Ce(i,Pe)+l,I=Ce(s,m)+Ce(i,w)+l+14+3*B+Ce(M,O)+2*M[16]+3*M[17]+7*M[18];if(o>=0&&q<=h&&q<=I)return xa(a,d,e.subarray(o,o+v));var R,$,T,x;if(ue(a,d,1+(I<h)),d+=2,I<h){R=ce(m,y,0),$=m,T=ce(w,P,0),x=w;var L=ce(O,E,0);ue(a,d,S-257),ue(a,d+5,U-1),ue(a,d+10,B-4),d+=14;for(var C=0;C<B;++C)ue(a,d+3*C,O[He[C]]);d+=3*B;for(var W=[b,D],Y=0;Y<2;++Y)for(var H=W[Y],C=0;C<H.length;++C){var p=H[C]&31;ue(a,d,L[p]),d+=O[p],p>15&&(ue(a,d,H[C]>>5&127),d+=H[C]>>12)}}else R=Ga,$=xe,T=Za,x=Pe;for(var C=0;C<f;++C){var k=n[C];if(k>255){var p=k>>18&31;Ne(a,d,R[p+257]),d+=$[p+257],p>7&&(ue(a,d,k>>23&31),d+=Oe[p]);var _=k&31;Ne(a,d,T[_]),d+=x[_],_>3&&(Ne(a,d,k>>5&8191),d+=ze[_])}else Ne(a,d,R[k]),d+=$[k]}return Ne(a,d,R[256]),d+$[256]},at=new ea([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),ka=new Z(0),tt=function(e,a,r,n,s,i){var l=i.z||e.length,f=new Z(n+l+5*(1+Math.ceil(l/7e3))+s),o=f.subarray(n,f.length-s),v=i.l,d=(i.r||0)&7;if(a){d&&(o[0]=i.r>>3);for(var c=at[a-1],m=c>>13,y=c&8191,u=(1<<r)-1,w=i.p||new ne(32768),P=i.h||new ne(u+1),N=Math.ceil(r/3),b=2*N,S=function(ye){return(e[ye]^e[ye+1]<<N^e[ye+2]<<b)&u},A=new ea(25e3),D=new ne(288),U=new ne(32),M=0,C=0,j=i.i||0,O=0,E=i.w||0,B=0;j+2<l;++j){var q=S(j),h=j&32767,I=P[q];if(w[h]=I,P[q]=h,E<=j){var R=l-j;if((M>7e3||O>24576)&&(R>423||!v)){d=oa(e,o,0,A,D,U,C,O,B,j-B,d),O=M=C=0,B=j;for(var $=0;$<286;++$)D[$]=0;for(var $=0;$<30;++$)U[$]=0}var T=2,x=0,L=y,W=h-I&32767;if(R>2&&q==S(j-W))for(var Y=Math.min(m,R)-1,H=Math.min(32767,j),p=Math.min(258,R);W<=H&&--L&&h!=I;){if(e[j+T]==e[j+T-W]){for(var k=0;k<p&&e[j+k]==e[j+k-W];++k);if(k>T){if(T=k,x=W,k>Y)break;for(var _=Math.min(W,k-2),Q=0,$=0;$<_;++$){var ee=j-W+$&32767,se=w[ee],ke=ee-se&32767;ke>Q&&(Q=ke,I=ee)}}}h=I,I=w[h],W+=h-I&32767}if(x){A[O++]=268435456|Ve[T]<<18|na[x];var pe=Ve[T]&31,ge=na[x]&31;C+=Oe[pe]+ze[ge],++D[257+pe],++U[ge],E=j+T,++M}else A[O++]=e[j],++D[e[j]]}}for(j=Math.max(j,E);j<l;++j)A[O++]=e[j],++D[e[j]];d=oa(e,o,v,A,D,U,C,O,B,j-B,d),v||(i.r=d&7|o[d/8|0]<<3,d-=7,i.h=P,i.p=w,i.i=j,i.w=E)}else{for(var j=i.w||0;j<l+v;j+=65535){var de=j+65535;de>=l&&(o[d/8|0]=v,de=l),d=xa(o,d+1,e.subarray(j,de))}i.i=l}return Se(f,0,n+aa(d)+s)},rt=(function(){for(var e=new Int32Array(256),a=0;a<256;++a){for(var r=a,n=9;--n;)r=(r&1&&-306674912)^r>>>1;e[a]=r}return e})(),nt=function(){var e=-1;return{p:function(a){for(var r=e,n=0;n<a.length;++n)r=rt[r&255^a[n]]^r>>>8;e=r},d:function(){return~e}}},st=function(e,a,r,n,s){if(!s&&(s={l:1},a.dictionary)){var i=a.dictionary.subarray(-32768),l=new Z(i.length+e.length);l.set(i),l.set(e,i.length),e=l,s.w=i.length}return tt(e,a.level==null?6:a.level,a.mem==null?s.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+a.mem,r,n,s)},wa=function(e,a){var r={};for(var n in e)r[n]=e[n];for(var n in a)r[n]=a[n];return r},le=function(e,a){return e[a]|e[a+1]<<8},oe=function(e,a){return(e[a]|e[a+1]<<8|e[a+2]<<16|e[a+3]<<24)>>>0},Ke=function(e,a){return oe(e,a)+oe(e,a+4)*4294967296},X=function(e,a,r){for(;r;++a)e[a]=r,r>>>=8};function ot(e,a){return st(e,a||{},0,0)}function it(e,a){return et(e,{i:2},a&&a.out,a&&a.dictionary)}var ya=function(e,a,r,n){for(var s in e){var i=e[s],l=a+s,f=n;Array.isArray(i)&&(f=wa(n,i[1]),i=i[0]),ArrayBuffer.isView(i)?r[l]=[i,f]:(r[l+="/"]=[new Z(0),f],ya(i,l,r,n))}},ia=typeof TextEncoder<"u"&&new TextEncoder,Ge=typeof TextDecoder<"u"&&new TextDecoder,lt=0;try{Ge.decode(ka,{stream:!0}),lt=1}catch{}var ct=function(e){for(var a="",r=0;;){var n=e[r++],s=(n>127)+(n>223)+(n>239);if(r+s>e.length)return{s:a,r:Se(e,r-1)};s?s==3?(n=((n&15)<<18|(e[r++]&63)<<12|(e[r++]&63)<<6|e[r++]&63)-65536,a+=String.fromCharCode(55296|n>>10,56320|n&1023)):s&1?a+=String.fromCharCode((n&31)<<6|e[r++]&63):a+=String.fromCharCode((n&15)<<12|(e[r++]&63)<<6|e[r++]&63):a+=String.fromCharCode(n)}};function Ie(e,a){var r;if(ia)return ia.encode(e);for(var n=e.length,s=new Z(e.length+(e.length>>1)),i=0,l=function(v){s[i++]=v},r=0;r<n;++r){if(i+5>s.length){var f=new Z(i+8+(n-r<<1));f.set(s),s=f}var o=e.charCodeAt(r);o<128||a?l(o):o<2048?(l(192|o>>6),l(128|o&63)):o>55295&&o<57344?(o=65536+(o&1047552)|e.charCodeAt(++r)&1023,l(240|o>>18),l(128|o>>12&63),l(128|o>>6&63),l(128|o&63)):(l(224|o>>12),l(128|o>>6&63),l(128|o&63))}return Se(s,0,i)}function dt(e,a){if(a){for(var r="",n=0;n<e.length;n+=16384)r+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return r}else{if(Ge)return Ge.decode(e);var s=ct(e),i=s.s,r=s.r;return r.length&&te(8),i}}var ut=function(e,a){return a+30+le(e,a+26)+le(e,a+28)},mt=function(e,a,r){var n=le(e,a+28),s=le(e,a+30),i=dt(e.subarray(a+46,a+46+n),!(le(e,a+8)&2048)),l=a+46+n,f=pt(e,l,s,r,oe(e,a+20),oe(e,a+24),oe(e,a+42)),o=f[0],v=f[1],d=f[2];return[le(e,a+10),o,v,i,l+s+le(e,a+32),d]},pt=function(e,a,r,n,s,i,l){var f=s==4294967295,o=i==4294967295,v=l==4294967295,d=a+r,c=f+o+v;if(n&&c){for(;a+4<d;a+=4+le(e,a+2))if(le(e,a)==1)return[f?Ke(e,a+4+8*o):s,o?Ke(e,a+4):i,v?Ke(e,a+4+8*(o+f)):l,1];n<2&&te(13)}return[s,i,l,0]},Ye=function(e){var a=0;if(e)for(var r in e){var n=e[r].length;n>65535&&te(9),a+=n+4}return a},la=function(e,a,r,n,s,i,l,f){var o=n.length,v=r.extra,d=f&&f.length,c=Ye(v);X(e,a,l!=null?33639248:67324752),a+=4,l!=null&&(e[a++]=20,e[a++]=r.os),e[a]=20,a+=2,e[a++]=r.flag<<1|(i<0&&8),e[a++]=s&&8,e[a++]=r.compression&255,e[a++]=r.compression>>8;var m=new Date(r.mtime==null?Date.now():r.mtime),y=m.getFullYear()-1980;if((y<0||y>119)&&te(10),X(e,a,y<<25|m.getMonth()+1<<21|m.getDate()<<16|m.getHours()<<11|m.getMinutes()<<5|m.getSeconds()>>1),a+=4,i!=-1&&(X(e,a,r.crc),X(e,a+4,i<0?-i-2:i),X(e,a+8,r.size)),X(e,a+12,o),X(e,a+14,c),a+=16,l!=null&&(X(e,a,d),X(e,a+6,r.attrs),X(e,a+10,l),a+=14),e.set(n,a),a+=o,c)for(var u in v){var w=v[u],P=w.length;X(e,a,+u),X(e,a+2,P),e.set(w,a+4),a+=4+P}return d&&(e.set(f,a),a+=d),a},gt=function(e,a,r,n,s){X(e,a,101010256),X(e,a+8,r),X(e,a+10,r),X(e,a+12,n),X(e,a+16,s)};function ft(e,a){a||(a={});var r={},n=[];ya(e,"",r,a);var s=0,i=0;for(var l in r){var f=r[l],o=f[0],v=f[1],d=v.level==0?0:8,c=Ie(l),m=c.length,y=v.comment,u=y&&Ie(y),w=u&&u.length,P=Ye(v.extra);m>65535&&te(11);var N=d?ot(o,v):o,b=N.length,S=nt();S.p(o),n.push(wa(v,{size:o.length,crc:S.d(),c:N,f:c,m:u,u:m!=l.length||u&&y.length!=w,o:s,compression:d})),s+=30+m+P+b,i+=76+2*(m+P)+(w||0)+b}for(var A=new Z(i+22),D=s,U=i-s,M=0;M<n.length;++M){var c=n[M];la(A,c.o,c,c.f,c.u,c.c.length);var C=30+c.f.length+Ye(c.extra);A.set(c.c,c.o+C),la(A,s,c,c.f,c.u,c.c.length,c.o,c.m),s+=16+C+(c.m?c.m.length:0)}return gt(A,s,n.length,U,D),A}function ht(e,a){for(var r={},n=e.length-22;oe(e,n)!=101010256;--n)(!n||e.length-n>65558)&&te(13);var s=le(e,n+8);if(!s)return{};var i=oe(e,n+16),l=oe(e,n-20)==117853008;if(l){var f=oe(e,n-12);l=oe(e,f)==101075792,l&&(s=oe(e,f+32),i=oe(e,f+48))}for(var o=a&&a.filter,v=0;v<s;++v){var d=mt(e,i,l),c=d[0],m=d[1],y=d[2],u=d[3],w=d[4],P=d[5],N=ut(e,P);i=w,(!o||o({name:u,size:m,originalSize:y,compression:c}))&&(c?c==8?r[u]=it(e.subarray(N,N+m),{out:new Z(y)}):te(14,"unknown compression type "+c):r[u]=Se(e,N,N+m))}return r}function ja({files:e,readOnly:a=!1,onChange:r,testId:n}){var c,m,y;const[s,i]=we(a?"packageFile":"packageDraftFile",((c=e[0])==null?void 0:c.path)??""),[l,f]=we("editorMode",a?"read":"edit",["read","edit","split"]),[o,v]=z.useState([((m=e[0])==null?void 0:m.path)??""]),d=e.some(u=>u.path===s)?s:(y=e[0])==null?void 0:y.path;return t.jsxs("div",{className:"min-w-0 overflow-hidden rounded-lg border border-surface-highest",children:[t.jsx("div",{role:"tablist","aria-label":"Package files",className:"flex overflow-x-auto bg-background",children:e.map(u=>t.jsx("button",{type:"button",role:"tab","aria-selected":d===u.path,"data-testid":"package-file","data-file-name":u.path,title:u.path,className:`shrink-0 border-r border-surface-highest px-4 py-3 text-sm ${d===u.path?"border-t-2 border-t-transparent bg-surface-highest text-on-surface":"border-t-2 border-t-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface"}`,onClick:()=>{i(u.path),v(w=>w.includes(u.path)?w:[...w,u.path])},onKeyDown:w=>{var A;const P=e.findIndex(D=>D.path===u.path),N=w.key==="ArrowRight"?P+1:w.key==="ArrowLeft"?P-1:void 0;if(N===void 0)return;w.preventDefault();const b=(A=w.currentTarget.parentElement)==null?void 0:A.querySelectorAll('[role="tab"]'),S=b==null?void 0:b[(N+e.length)%e.length];S==null||S.focus(),S==null||S.click()},children:u.path.endsWith("/SKILL.md")?u.path.split("/").slice(-2).join("/"):u.path.split("/").pop()},u.path))}),e.filter(u=>o.includes(u.path)||d===u.path).map(u=>t.jsxs("div",{role:"tabpanel","aria-label":u.path,hidden:d!==u.path,className:"[&_[data-testid=code-editor]>div>span[title]]:hidden [&_[data-testid=markdown-editor]>div>span[title]]:hidden",children:[t.jsx(Fe,{mode:Ca(u.path)?l:void 0,onModeChange:f,path:u.path,value:u.content,onChange:r?w=>r(u.path,w):void 0,readOnly:a||u.encoding==="base64",height:420,testId:d===u.path?n:void 0}),u.encoding==="base64"&&t.jsx("p",{className:"px-4 py-2 text-xs text-outline",children:"Binary asset shown as base64."})]},u.path))]})}function vt({name:e,onClose:a,onUse:r,onEdit:n,onExport:s,onSource:i,busy:l,operationError:f}){var d,c,m,y;const o=ve({queryKey:["agent-package",e],queryFn:()=>V.agentPackages.get(e)}),v=ve({enabled:!!o.data,queryKey:["agent-package-files",e],queryFn:async()=>{const u=o.data;if(!u)return[];const w=await Promise.all(u.files.map(async P=>{const N=await V.agentPackages.get(e,P.name);return{path:P.name,content:N.content,encoding:N.encoding}}));return[{path:u.manifestFile,content:u.content},...w]}});return t.jsx(Pa,{open:!0,onOpenChange:u=>{u||a()},children:t.jsxs(Sa,{className:"w-screen max-w-full sm:w-[720px] sm:max-w-[90vw]",children:[t.jsx(Aa,{children:t.jsx(Ma,{children:e})}),t.jsxs(Fa,{children:[t.jsxs("div",{className:"mb-5 space-y-3",children:[t.jsx("p",{className:"text-sm text-outline break-words",children:(d=o.data)==null?void 0:d.description}),o.data&&t.jsxs("p",{className:"text-xs text-outline",children:[o.data.files.filter(u=>/(^|\/)SKILL\.md$/.test(u.name)).length," ","skills ·"," ",o.data.files.filter(u=>u.name.endsWith(".instructions.md")).length," ","instruction files ·"," ",o.data.files.filter(u=>u.name.endsWith(".agent.md")).length," agent definitions"]}),(c=o.data)==null?void 0:c.warnings.map(u=>t.jsx("p",{role:"alert",className:"text-xs text-destructive break-words",children:u},u)),t.jsxs("div",{className:"grid gap-2 grid-cols-2",children:[r&&t.jsx(J,{"data-testid":"package-detail-run",onClick:r,disabled:l,children:"Use package"}),n&&t.jsx(J,{"data-testid":"package-edit",variant:"outline",onClick:n,disabled:l,children:"Edit configuration"}),s&&t.jsx(J,{"data-testid":"package-export-artifact",variant:"outline",onClick:s,disabled:l,children:l?"Preparing…":"Export for installation"}),i&&t.jsx(J,{"data-testid":"package-export",variant:"outline",onClick:i,disabled:l,children:"Download source"})]}),t.jsxs("p",{className:"text-xs text-outline",children:["APM builds installation exports (",((m=o.data)==null?void 0:m.format)==="agent-plugin"?"portable Agent Plugin":"Claude plugin","). Download source preserves the editable manifest and all files."]}),f&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f})]}),o.error||v.error?t.jsx("p",{role:"alert",children:(y=o.error??v.error)==null?void 0:y.message}):v.isLoading?t.jsx("p",{children:"Loading files…"}):t.jsx(ja,{files:v.data??[],readOnly:!0,testId:"package-file-content"})]})]})})}const ba="https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",xt="https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";function Ae(e){return e==="apm"?`name: my-agent-package
12
12
  version: '1.0.0'
13
13
  description: Describe when to use this configuration
14
14
  dependencies: {}
15
- `:JSON.stringify({$schema:ba,name:"my-agent-package",version:"1.0.0",description:"Describe when to use this configuration"},null,2)}function Be(e,a){var s;const r=a==="apm"?$e(e):null;if(r!=null&&r.errors.length)throw new Error((s=r.errors[0])==null?void 0:s.message);const n=r?r.toJS():JSON.parse(e);if(!n||typeof n!="object"||Array.isArray(n))throw new Error("Manifest must be an object");return n}function kt(e,a,r,n){if(a==="agent-plugin")return JSON.stringify({...Be(e,a),[r]:n},null,2);const s=$e(e);if(s.errors.length)throw new Error("Fix the manifest before switching to fields");return s.set(r,n),s.toString()}function Me(e,a,r){return e.some(s=>s.path===a)?e.map(s=>s.path===a?{...s,content:r,encoding:"utf8"}:s):[...e,{path:a,content:r,encoding:"utf8"}]}function wt(e,a){var n;return`${((n=e==null?void 0:e.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n)?/))==null?void 0:n[0])??`---
15
+ `:JSON.stringify({$schema:ba,name:"my-agent-package",version:"1.0.0",description:"Describe when to use this configuration"},null,2)}function Re(e,a){var s;const r=a==="apm"?$e(e):null;if(r!=null&&r.errors.length)throw new Error((s=r.errors[0])==null?void 0:s.message);const n=r?r.toJS():JSON.parse(e);if(!n||typeof n!="object"||Array.isArray(n))throw new Error("Manifest must be an object");return n}function kt(e,a,r,n){if(a==="agent-plugin")return JSON.stringify({...Re(e,a),[r]:n},null,2);const s=$e(e);if(s.errors.length)throw new Error("Fix the manifest before switching to fields");return s.set(r,n),s.toString()}function Me(e,a,r){return e.some(s=>s.path===a)?e.map(s=>s.path===a?{...s,content:r,encoding:"utf8"}:s):[...e,{path:a,content:r,encoding:"utf8"}]}function wt(e,a){var n;return`${((n=e==null?void 0:e.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n)?/))==null?void 0:n[0])??`---
16
16
  description: Shared package instructions
17
17
  ---
18
- `}${a}`}function yt(e,a){const r=$e(a);if(r.errors.length)throw new Error("Fix the MCP YAML before saving");const n=r.toJS();if(!Array.isArray(n))throw new Error("MCP declarations must be a YAML list (use [] for none)");const s=$e(e);if(s.errors.length)throw new Error("Fix apm.yml before editing MCP declarations");s.setIn(["dependencies","mcp"],n);const i=s.get("dependencies",!0);ra(i)&&(i.flow=!1);const l=s.getIn(["dependencies","mcp"],!0);if(Ta(l)){l.flow=!1;for(const f of l.items)ra(f)&&(f.flow=!1)}return s.toString()}function jt(e,a){const r=Be(e,a);if(typeof r.name!="string"||!/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(r.name)||r.name.length>64)throw new Error("Use a lowercase package name with single hyphens or periods (up to 64 characters)");if(a==="apm"&&(!r.version||typeof r.version!="string"))throw new Error("APM packages require a version");if(a==="agent-plugin"&&r.$schema!==ba)throw new Error("Use the Agent Plugins v1 schema");return r}const me=new Map;typeof window<"u"&&window.addEventListener("beforeunload",e=>{me.size&&(e.preventDefault(),e.returnValue="")});function Na(e){me.delete(e)}function bt(e){var a;return(a=me.get(e))==null?void 0:a.baseline}function Ze(e){return me.has(e)?window.confirm("Discard unsaved package changes?")?(Na(e),!0):!1:!0}const ca=".apm/instructions/general.instructions.md";function Nt({initial:e,pending:a,error:r,onSave:n}){var ee,se,ke,pe,ge,de,ye,ta;const[s,i]=we("packageFormat","",["","apm","agent-plugin"]),l=z.useRef(me.get((e==null?void 0:e.name)??"new")),f=(e==null?void 0:e.format)??(s||void 0),o=f,[v,d]=z.useState(((ee=l.current)==null?void 0:ee.source)??(e==null?void 0:e.content)??Ae(f??"apm")),[c,m]=z.useState(((se=l.current)==null?void 0:se.files)??(e==null?void 0:e.files)??[]),[y,u]=z.useState(((ke=l.current)==null?void 0:ke.selectedSkills)??[]),[w,P]=z.useState(""),[N,b]=we("packageTab",e?"files":"configuration",["files","configuration","skills"]),[S,A]=we("packageSource","fields",["fields","source"]),D=S==="source",R=g=>A(g?"source":"fields"),[M,C]=z.useState(),[j,O]=z.useState(!1),[E,U]=z.useState(""),[q,h]=z.useState((pe=l.current)==null?void 0:pe.mcpDraft),[I,B]=z.useState(),$=ve({queryKey:["package-skill-picker"],queryFn:()=>V.skills.list()}),T=ve({queryKey:["agents"],queryFn:V.agents.list}),x=z.useMemo(()=>{try{return{fields:Be(v,o??"apm"),error:void 0}}catch(g){return{fields:void 0,error:g.message}}},[v,o]),L=x.fields,W=typeof(L==null?void 0:L.name)=="string"?L.name:"",Y=a||j,H=c.find(g=>g.path===ca),p=(H==null?void 0:H.content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,""))??"",k=c.find(g=>g.path==="mcp.json");z.useEffect(()=>{var F,G,ae;v!==((e==null?void 0:e.content)??Ae(o??"apm"))||JSON.stringify(c)!==JSON.stringify((e==null?void 0:e.files)??[])||y.length>0||q!==void 0?me.set((e==null?void 0:e.name)??"new",{format:o??((F=me.get((e==null?void 0:e.name)??"new"))==null?void 0:F.format)??((G=l.current)==null?void 0:G.format),source:v,files:c,selectedSkills:y,mcpDraft:q,baseline:((ae=l.current)==null?void 0:ae.baseline)??e}):me.delete((e==null?void 0:e.name)??"new")},[v,c,y,q,o,e]);function _(g,F){try{d(kt(v,o??"apm",g,F)),C(void 0)}catch(G){C(G.message)}}function Q(g){const F=me.get((e==null?void 0:e.name)??"new");if(F&&F.format===g){i(g),d(F.source),m(F.files),u(F.selectedSkills),h(F.mcpDraft);return}F&&!Ze((e==null?void 0:e.name)??"new")||(i(g),d(Ae(g)),m([]),u([]),h(void 0))}return t.jsxs(Ee,{className:"min-w-0 grid-cols-[minmax(0,1fr)] w-[calc(100%_-_1rem)] max-w-4xl max-h-[94dvh] overflow-x-hidden overflow-y-auto p-4 sm:p-6",children:[t.jsxs(Le,{children:[t.jsx(De,{className:"break-words pr-8",children:e?`Edit ${e.name}`:"New package"}),t.jsx(Qe,{children:"Save a configuration once, then use it in any project."})]}),o?t.jsxs("form",{className:"min-w-0 space-y-4",onSubmit:g=>{if(g.preventDefault(),!I){C(void 0);try{const F=jt(v,o);o==="agent-plugin"&&k&&JSON.parse(k.content),n({name:F.name,content:v,files:c,format:o,skills:y})}catch(F){C(F.message)}}},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[t.jsx("span",{className:"rounded bg-surface-high px-3 py-1",children:o==="apm"?"APM":"Plugin"}),!e&&t.jsx(J,{type:"button",variant:"ghost",disabled:Y,onClick:()=>{Ze("new")&&(i(""),d(Ae("apm")),m([]),u([]),h(void 0))},children:"Change type"})]}),t.jsx("div",{role:"tablist","aria-label":"Package editor",className:"flex flex-wrap gap-1 border-b border-surface-highest pb-2",children:["configuration","skills","files"].map(g=>{var F;return t.jsxs(J,{type:"button",role:"tab","aria-selected":N===g,variant:N===g?"default":"ghost","data-testid":`package-editor-${g}`,onClick:()=>b(g),children:[(F=g[0])==null?void 0:F.toUpperCase(),g.slice(1),g==="skills"&&y.length?` (${y.length})`:""]},g)})}),t.jsxs("fieldset",{disabled:Y,className:"min-w-0 space-y-4",children:[N==="configuration"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("span",{className:"text-sm text-outline",children:o==="apm"?"APM configuration":"Portable plugin identity"}),t.jsx(J,{type:"button",variant:"outline","data-testid":"package-editor-mode",disabled:!!I||D&&!!x.error,onClick:()=>{R(!D),h(void 0)},children:D?"Edit fields":o==="apm"?"Edit YAML":"Edit JSON"})]}),D?t.jsx(Fe,{id:"package-yaml",testId:"package-yaml-input",path:o==="apm"?"apm.yml":"plugin.json",value:v,onChange:d,readOnly:Y,height:320}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:[["name","Package name"],["version","Version"],["description","When would you use this?"]].map(([g,F])=>t.jsxs("div",{className:g==="description"?"space-y-1 sm:col-span-2":"space-y-1",children:[t.jsx(re,{htmlFor:`package-${g}`,children:F}),t.jsx(he,{id:`package-${g}`,"data-testid":`package-${g}-input`,disabled:g==="name"&&!!e,value:typeof(L==null?void 0:L[g])=="string"?L[g]:"",onChange:G=>_(g,G.target.value)})]},g))}),o==="apm"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"package-apm-mcp",children:"MCP servers (YAML declarations)"}),t.jsx(Fe,{id:"package-apm-mcp",path:"mcp-dependencies.yml",testId:"package-apm-mcp",height:180,readOnly:Y,value:q??qa(((ge=L==null?void 0:L.dependencies)==null?void 0:ge.mcp)??[]),onChange:g=>{h(g);try{d(yt(v,g)),B(void 0)}catch(F){B(F.message)}}}),t.jsxs("p",{className:"text-xs text-outline",children:["Use registry names, or named APM mappings with transport and command/URL. Credentials use environment references such as"," ",t.jsxs("code",{children:["$","{API_TOKEN}"]}),"."]}),I&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:I})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"package-instructions",children:"Shared instructions"}),t.jsx(We,{id:"package-instructions","data-testid":"package-instructions",rows:7,placeholder:"What should the agent know and how should it work?",value:p,onChange:g=>m(Me(c,ca,wt(H==null?void 0:H.content,g.target.value)))}),t.jsx("p",{className:"text-xs text-outline",children:"Saved as an APM instruction primitive. Agent-specific model and tool configuration belongs in an agent definition."})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"package-agent-picker",children:"Add an existing agent definition"}),t.jsxs("select",{id:"package-agent-picker","data-testid":"package-agent-picker",className:"w-full rounded border border-control-border bg-background p-3",value:"",onChange:async g=>{var G;const F=g.target.value;if(F){O(!0);try{const ae=await V.agents.get(F),be=((G=F.split("/").slice(-1)[0])==null?void 0:G.replace(/[^a-zA-Z0-9-]/g,"-"))??"agent";m(Re=>Me(Re,`.apm/agents/${be}.agent.md`,ae.raw))}catch(ae){C(ae.message)}finally{O(!1)}}},children:[t.jsx("option",{value:"",children:"Select an agent to copy into this package…"}),(de=T.data)==null?void 0:de.agents.map(g=>t.jsx("option",{value:g.id,children:g.name},g.id))]})]}),t.jsx("p",{className:"text-sm text-outline",children:"Configure targets, MCP dependencies and launch scripts in Edit YAML. Supporting agent files are editable in Files."})]}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-sm text-outline",children:"Agent Plugins v1 contains skills and MCP. Choose APM if you need shared instructions or agent profiles."}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{children:"mcp.json (optional)"}),t.jsx(Fe,{path:"mcp.json",testId:"package-mcp-input",height:220,value:(k==null?void 0:k.content)??JSON.stringify({$schema:xt,mcpServers:{}},null,2),readOnly:Y,onChange:g=>m(Me(c,"mcp.json",g))}),t.jsx("p",{className:"text-xs text-outline",children:"Credentials are managed by the coding agent. Keep secrets out of package files."})]})]})]})]}),N==="skills"&&t.jsxs(t.Fragment,{children:[c.filter(g=>/^(skills|\.apm\/skills)\/[^/]+\/SKILL\.md$/.test(g.path)).map(g=>{const F=g.path.slice(0,-8);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-outline-variant p-3",children:[t.jsxs("span",{className:"min-w-0 break-words text-sm",children:["Included: ",F.split("/").slice(-2)[0]]}),t.jsx(J,{type:"button",variant:"outline","data-testid":"package-skill-remove",onClick:()=>m(G=>G.filter(ae=>!ae.path.startsWith(F))),children:"Remove from package"})]},g.path)}),t.jsx("p",{className:"text-sm text-outline",children:"Choose skills from your library. Their SKILL.md, scripts, references and assets are copied into this package; the originals stay available independently."}),t.jsx(he,{"aria-label":"Search existing skills","data-testid":"package-skill-search",placeholder:"Search your skills…",value:w,onChange:g=>P(g.target.value)}),$.error&&t.jsx("p",{role:"alert",children:$.error.message}),$.isLoading&&t.jsx("p",{children:"Loading skills…"}),t.jsx("div",{className:"max-h-[40dvh] overflow-auto space-y-2",children:(ye=$.data)==null?void 0:ye.skills.filter(g=>`${g.name} ${g.description}`.toLowerCase().includes(w.toLowerCase())).map(g=>{const F=g.name.split("/").slice(-1)[0],G=c.some(ae=>ae.path===`${o==="apm"?".apm/skills":"skills"}/${F}/SKILL.md`);return t.jsxs("label",{className:"flex items-start gap-3 border-b border-outline-variant p-3","data-testid":"package-skill-option","data-skill-name":g.name,children:[t.jsx("input",{type:"checkbox",className:"mt-1 size-5 shrink-0","data-testid":"package-skill-select",checked:G||y.includes(g.name),disabled:G||Y||!y.includes(g.name)&&y.length>=32,onChange:ae=>u(ae.target.checked?[...y,g.name]:y.filter(be=>be!==g.name))}),t.jsxs("span",{className:"min-w-0 break-words",children:[t.jsxs("span",{className:"block text-sm font-medium",children:[g.name,G?" · included":""]}),t.jsx("span",{className:"block text-xs text-outline line-clamp-2",children:g.description})]})]},g.name)})}),!$.isLoading&&((ta=$.data)==null?void 0:ta.skills.length)===0&&t.jsx("p",{children:"No skills yet. Import skills into your library first, or add skill files directly in Files."})]}),N==="files"&&t.jsxs(t.Fragment,{children:[t.jsxs("details",{className:"border-t border-outline-variant p-3",children:[t.jsx("summary",{className:"cursor-pointer text-sm",children:"Add a file or folder"}),t.jsx(re,{htmlFor:"package-files",children:"Add files from a folder"}),t.jsx(he,{id:"package-files","data-testid":"package-files-input",type:"file",multiple:!0,webkitdirectory:"",onChange:async g=>{const F=g.target.files;if(F!=null&&F.length){O(!0);try{const G=(await pa(F)).filter(ae=>!["apm.yml","plugin.json"].includes(ae.path));m(ae=>[...ae.filter(be=>!G.some(Re=>Re.path===be.path)),...G]),C(void 0)}catch(G){C(G.message)}finally{O(!1)}}}}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(he,{"aria-label":"New file path","data-testid":"package-new-file-path",placeholder:o==="apm"?".apm/agents/reviewer.agent.md":"skills/my-skill/SKILL.md",value:E,onChange:g=>U(g.target.value)}),t.jsx(J,{type:"button",variant:"outline",disabled:!E||c.some(g=>g.path===E),onClick:()=>{m(g=>[...g,{path:E,content:"",encoding:"utf8"}]),U("")},children:"Add file"})]})]}),t.jsx(ja,{files:[{path:o==="apm"?"apm.yml":"plugin.json",content:v},...c],readOnly:Y,testId:"package-file-input",onChange:(g,F)=>{g===(o==="apm"?"apm.yml":"plugin.json")?d(F):m(G=>Me(G,g,F))}})]})]}),(r||M||x.error)&&t.jsx("p",{role:"alert","data-testid":"package-editor-error",className:"text-sm text-destructive",children:r||M||x.error}),t.jsxs("div",{className:"sticky bottom-0 border-t border-surface-highest bg-surface pt-3 flex flex-wrap items-center justify-between gap-3",children:[t.jsxs("span",{className:"text-xs text-outline",children:[c.length," files · ",y.length," skills selected"]}),t.jsx(J,{type:"submit","data-testid":"package-submit",disabled:Y||!W.trim()||!!(x.error||I),children:a?"Saving…":e?"Save changes":"Save to catalog"})]})]}):t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"package-type-choice",children:[t.jsxs("button",{type:"button","data-testid":"package-type-apm",onClick:()=>Q("apm"),className:"rounded-lg border border-outline-variant p-5 text-left hover:bg-surface-low",children:[t.jsx("strong",{className:"block mb-2",children:"APM package"}),t.jsx("span",{className:"text-sm text-outline",children:"Instructions, agents, skills, MCP and dependencies. Configure with apm.yml."})]}),t.jsxs("button",{type:"button","data-testid":"package-type-agent-plugin",onClick:()=>Q("agent-plugin"),className:"rounded-lg border border-outline-variant p-5 text-left hover:bg-surface-low",children:[t.jsx("strong",{className:"block mb-2",children:"Agent Plugin"}),t.jsx("span",{className:"text-sm text-outline",children:"Portable skills and MCP. Configure with plugin.json and mcp.json."})]})]})]})}function Ct(e){if(e.length>16*1024*1024)throw new Error("Archive exceeds 16 MiB");let a=0,r=0;const n=ht(e,{filter:o=>{if(o.name.endsWith("/"))return!1;if(a+=o.originalSize,r++,o.originalSize>8*1024*1024||a>16*1024*1024||r>513)throw new Error("Archive exceeds package file or size limits");return!0}}),s=Object.keys(n),l=s.filter(o=>/(^|\/)(apm\.yml|plugin\.json)$/.test(o)).sort((o,v)=>o.split("/").length-v.split("/").length)[0];if(!l)throw new Error("Choose a source ZIP containing apm.yml or portable plugin.json");const f=l.includes("/")?l.slice(0,l.lastIndexOf("/")+1):"";if(s.some(o=>!o.startsWith(f)))throw new Error("Choose an archive containing one package folder");return Object.entries(n).map(([o,v])=>{let d="";for(const c of v)d+=String.fromCharCode(c);try{const c=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}).decode(v);if(!c.includes("\0"))return{path:o.slice(f.length),content:c,encoding:"utf8"}}catch{}return{path:o.slice(f.length),content:btoa(d),encoding:"base64"}})}function Pt({onClose:e,onImported:a}){var M,C,j,O,E,U,q;const[r,n]=we("importMethod","git",["git","zip","folder"]),[s,i]=z.useState(""),[l,f]=z.useState(""),[o,v]=z.useState("auto"),[d,c]=z.useState(),[m,y]=z.useState(!1),u=je({mutationFn:V.agentPackages.discover}),w=je({mutationFn:V.agentPackages.importGit,onSuccess:h=>a(h.name)}),P=je({mutationFn:V.agentPackages.acquire}),N=je({mutationFn:V.agentPackages.importAcquired,onSuccess:h=>a(h.name)}),b=u.isPending||w.isPending||P.isPending||N.isPending||m,S=((M=u.data)==null?void 0:M.packages)??((C=P.data)==null?void 0:C.packages),A=S==null?void 0:S.find(h=>`${h.format}:${h.path}`===l);async function D(){f(""),u.reset(),P.reset(),w.reset(),N.reset();const h=s.trim();if(!h.includes("://")||/^https:\/\/github\.com\//i.test(h))try{await u.mutateAsync(h);return}catch{u.reset()}P.mutate(h)}async function R(h){const I=h.find(W=>W.path==="apm.yml"),B=h.find(W=>W.path==="plugin.json");if(o==="auto"&&I&&B)throw new Error("Both manifests are present. Select a format before importing.");const $=o==="auto"?I?"apm":"agent-plugin":o,T=$==="apm"?I:B;if(!T||T.encoding==="base64")throw new Error("The selected format's manifest is missing");const x=Be(T.content,$);if(typeof x.name!="string")throw new Error("Manifest is missing a package name");const L=await V.agentPackages.create({name:x.name,content:T.content,format:$,imported:!0,files:h.filter(W=>W!==T&&!($==="agent-plugin"&&W.path==="apm.yml"))});a(L.name)}return t.jsx(Xe,{open:!0,onOpenChange:h=>!h&&!b&&e(),children:t.jsxs(Ee,{className:"min-w-0 grid-cols-[minmax(0,1fr)] w-[calc(100%_-_1rem)] max-w-xl max-h-[94dvh] overflow-x-hidden overflow-y-auto p-4 sm:p-6",children:[t.jsxs(Le,{children:[t.jsx(De,{children:"Import a package"}),t.jsx(Qe,{children:"Add reusable configuration to your catalog, then choose where to install it."})]}),t.jsx("div",{role:"tablist","aria-label":"Import source",className:"flex flex-wrap gap-2",children:[["git","Git repository"],["zip","ZIP file"],["folder","Folder"]].map(([h,I])=>t.jsx(J,{role:"tab","aria-selected":r===h,"data-testid":`package-import-${h}`,variant:r===h?"default":"outline",disabled:b,onClick:()=>{n(h),c(void 0)},children:I},h))}),r==="git"?t.jsxs(t.Fragment,{children:[t.jsxs("form",{className:"space-y-3",onSubmit:h=>{h.preventDefault(),D()},children:[t.jsx(re,{htmlFor:"package-git-source",children:"Repository URL"}),t.jsx(he,{id:"package-git-source","data-testid":"package-git-source",placeholder:"https://github.com/owner/repository",value:s,disabled:b,onChange:h=>{i(h.target.value),u.reset(),P.reset(),w.reset(),N.reset(),f("")}}),t.jsx("p",{className:"text-xs text-outline",children:"Paste a GitHub, GitLab, Bitbucket or Azure DevOps repository or package link."}),t.jsx(J,{type:"submit","data-testid":"package-git-discover",disabled:b||!s.trim(),children:u.isPending||P.isPending?"Finding packages…":"Find packages"})]}),S&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"max-h-[40dvh] space-y-2 overflow-auto",children:S.map(h=>t.jsxs("label",{className:"flex items-start gap-3 rounded border border-surface-highest p-3","data-testid":"remote-package",children:[t.jsx("input",{className:"mt-1 size-5",type:"radio",name:"package-import-selection",disabled:b||h.installed,checked:l===`${h.format}:${h.path}`,onChange:()=>f(`${h.format}:${h.path}`)}),t.jsxs("span",{className:"min-w-0 break-words",children:[t.jsxs("strong",{className:"block text-sm",children:[h.name,h.installed?" · already in catalog":""]}),t.jsx("span",{className:"block text-xs text-outline",children:h.description}),t.jsxs("span",{className:"block text-xs text-outline",children:[h.format==="apm"?"APM":"Plugin"," ·"," ",h.path||"Repository root"]})]})]},`${h.format}:${h.path}`))}),!S.length&&t.jsx("p",{children:"No APM or Plugin packages found in this repository."}),(j=u.data)==null?void 0:j.issues.map(h=>t.jsxs("p",{role:"alert",className:"text-xs text-destructive break-words",children:[h.path,": ",h.error]},h.path))]}),S&&t.jsx(J,{"data-testid":"package-git-import",disabled:b||!A,onClick:()=>{A&&(u.data?w.mutate({source:u.data.source,commit:u.data.commit,path:A.path,format:A.format}):P.data&&N.mutate({token:P.data.token,path:A.path}))},children:w.isPending||N.isPending?"Importing…":"Import to catalog"})]}):t.jsxs("div",{className:"space-y-3",children:[t.jsx(re,{htmlFor:"package-import-format",children:"Package format"}),t.jsxs("select",{id:"package-import-format","data-testid":"package-import-format",disabled:b,className:"w-full rounded border border-control-border bg-surface-low p-3",value:o,onChange:h=>v(h.target.value),children:[t.jsx("option",{value:"auto",children:"Detect from manifest"}),t.jsx("option",{value:"apm",children:"APM"}),t.jsx("option",{value:"agent-plugin",children:"Agent Plugin"})]}),t.jsx(re,{htmlFor:"agent-package-folder",children:r==="folder"?"Package folder":"Package source ZIP"}),t.jsx(he,{id:"agent-package-folder","data-testid":r==="folder"?"agent-package-folder":"package-zip-input",type:"file",accept:r==="zip"?".zip":void 0,multiple:r==="folder",...r==="folder"?{webkitdirectory:""}:{},disabled:b,onChange:async h=>{const I=h.target.files;if(I!=null&&I.length){y(!0),c(void 0);try{await R(r==="folder"?await pa(I):Ct(new Uint8Array(await I[0].arrayBuffer())))}catch(B){c(B.message)}finally{y(!1)}}}},r),t.jsx("p",{className:"text-xs text-outline",children:"Original manifests and supporting files are preserved. Import does not launch an agent or run package scripts. Use ZIP on phones where folder selection is unavailable."})]}),(u.error||w.error||P.error||N.error||d)&&t.jsx("p",{role:"alert","data-testid":"package-import-error",className:"text-sm text-destructive",children:((O=u.error)==null?void 0:O.message)??((E=w.error)==null?void 0:E.message)??((U=P.error)==null?void 0:U.message)??((q=N.error)==null?void 0:q.message)??d})]})})}function St({initial:e,onClose:a}){var j,O,E,U,q,h,I,B,$,T;const[r,n]=z.useState({...e,tool:"apm"}),[s,i]=z.useState(),[l,f]=z.useState(!1),[o,v]=z.useState(!1),[d,c]=z.useState("run"),m=z.useRef(null),y=ma(),u=$a(),w=Ia(),P=ve({queryKey:["package-tools"],queryFn:V.packageTools.list}),N=ve({queryKey:["setup-components",r.packages],enabled:r.packages.length>0,queryFn:()=>Promise.all(r.packages.map(x=>V.agentPackages.get(x)))}),b=je({mutationFn:V.agentSetups.command});z.useEffect(()=>{var x;b.data&&((x=m.current)==null||x.scrollIntoView({block:"nearest"}))},[b.data]);const S=(j=N.data)==null?void 0:j.some(x=>x.format==="agent-plugin"),A=S&&r.backend!=="copilot",R=!!(r.cwd.trim()&&r.packages.length&&r.name.trim())&&((O=P.data)==null?void 0:O.apm)&&!A&&!N.error&&!N.isFetching;function M(x){n(L=>({...L,...x})),b.reset(),v(!1),i(void 0)}async function C(x){f(!0),i(void 0);try{const L=await w.create({kind:r.backend,name:`${r.name}${x==="install"?" · install":""}`,setup:{...r,operation:x}});a(),y(Ea(`/terminals/${L.id}`,new URLSearchParams(u.search).get("project")??"all",u.search))}catch(L){i(L.message)}finally{f(!1)}}return t.jsx(Xe,{open:!0,onOpenChange:x=>!x&&!l&&!b.isPending&&a(),children:t.jsxs(Ee,{className:"min-w-0 grid-cols-[minmax(0,1fr)] w-[calc(100%_-_1rem)] max-w-2xl max-h-[94dvh] overflow-x-hidden overflow-y-auto p-4 sm:p-6",children:[t.jsxs(Le,{children:[t.jsx(De,{children:"Use package"}),t.jsx(Qe,{children:"Install it for your coding agent, launch here, or copy a command for your own terminal."})]}),t.jsxs("fieldset",{disabled:l||b.isPending,className:"min-w-0 space-y-4",children:[t.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"setup-backend",children:"Coding agent"}),t.jsx("select",{id:"setup-backend","data-testid":"setup-backend",className:"w-full rounded border border-control-border bg-surface-low p-3",value:r.backend,onChange:x=>M({backend:x.target.value,agent:void 0}),children:["claude","codex","copilot"].map(x=>{var L;return t.jsxs("option",{value:x,disabled:!!(S&&x!=="copilot"),children:[x,S&&x!=="copilot"?" · unsupported for this plugin":(L=w.info)!=null&&L.launchers.includes(x)?"":" · not installed"]},x)})})]})}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"setup-cwd",children:"Project folder on this ORC machine"}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(he,{id:"setup-cwd","data-testid":"setup-cwd",value:r.cwd,onChange:x=>M({cwd:x.target.value})}),t.jsx(J,{type:"button",variant:"outline",disabled:!((E=w.info)!=null&&E.ready),onClick:async()=>{try{const x=await V.terminals.pickFolder(r.cwd||void 0);x.path&&M({cwd:x.path})}catch(x){i(x.message)}},children:"Browse"})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"setup-prompt",children:"What should the agent work on?"}),t.jsx(We,{id:"setup-prompt","data-testid":"setup-prompt",rows:3,value:r.prompt,onChange:x=>M({prompt:x.target.value})})]}),t.jsxs("div",{"data-testid":"setup-components",className:"rounded-lg bg-surface-low p-3 text-sm space-y-1",children:[t.jsx("p",{className:"font-medium",children:"Configuration to apply"}),N.isFetching&&t.jsx("p",{children:"Checking package contents…"}),(U=N.data)==null?void 0:U.map(x=>t.jsxs("p",{className:"break-words",children:[x.name,":"," ",x.files.filter(L=>/^(skills|\.apm\/skills)\/[^/]+\/SKILL\.md$/.test(L.name)).length," ","skill files",x.files.some(L=>L.name==="mcp.json")?", native MCP configuration":"",x.files.some(L=>L.name.endsWith(".instructions.md"))?", shared instructions":""]},x.name))]})]}),t.jsxs("p",{className:"text-xs text-outline",children:["APM installs into this project and retains the configuration after the session. Trust and file-conflict prompts appear in the terminal. Copied commands run on this ORC machine in"," ",navigator.platform.startsWith("Win")?"PowerShell":"your shell","."]}),A&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"APM currently activates whole Agent Plugins for Copilot. Select Copilot for this package."}),P.data&&!P.data.apm&&t.jsx("p",{role:"alert",className:"text-sm",children:"Install APM 0.33.0 or newer on the ORC machine, or set ORC_APM_PATH."}),!((q=w.info)!=null&&q.ready)&&t.jsx("p",{role:"alert",className:"text-sm",children:((h=w.info)==null?void 0:h.reason)??"Checking terminal availability…"}),(s||b.error||N.error)&&t.jsx("p",{role:"alert","data-testid":"setup-error",className:"text-sm text-destructive",children:s??((I=b.error)==null?void 0:I.message)??((B=N.error)==null?void 0:B.message)}),t.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[t.jsx(J,{"data-testid":"setup-install",variant:"outline",disabled:l||!R||!(($=w.info)!=null&&$.ready),onClick:()=>void C("install"),children:"Install for coding agent"}),t.jsx(J,{"data-testid":"setup-launch",disabled:l||!R||!((T=w.info)!=null&&T.ready),onClick:()=>void C("run"),children:l?"Preparing…":"Run in ORC terminal"}),t.jsx(J,{"data-testid":"setup-command",variant:"outline",disabled:l||b.isPending||!R,onClick:()=>b.mutate({...r,operation:d}),children:b.isPending?"Preparing command…":"Command for my terminal"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"command-mode",children:"Command for your terminal"}),t.jsxs("select",{id:"command-mode",className:"w-full rounded border border-control-border bg-surface-low p-3 text-sm",disabled:l||b.isPending,value:d,onChange:x=>{c(x.target.value),b.reset()},children:[t.jsx("option",{value:"run",children:"Install and launch the agent"}),t.jsx("option",{value:"install",children:"Install configuration only"})]})]}),b.data&&t.jsxs("div",{ref:m,className:"min-w-0 space-y-2 rounded border border-surface-highest p-3",children:[t.jsxs(re,{htmlFor:"package-command",children:["Run in ",b.data.shell," on the ORC machine"]}),t.jsx(We,{id:"package-command","data-testid":"package-command",value:b.data.command,readOnly:!0,rows:3,className:"font-mono text-xs"}),t.jsx(J,{variant:"outline",onClick:async()=>{try{await navigator.clipboard.writeText(b.data.command),v(!0)}catch{i("Copy is unavailable in this browser. Select and copy the command above.")}},children:o?"Copied":"Copy command"})]})]})})}function da(e,a){const r=URL.createObjectURL(new Blob([new Uint8Array(a)],{type:"application/zip"})),n=document.createElement("a");n.href=r,n.download=e,n.click(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function It(){const{agentId:e}=Ra();return t.jsx(Ua,{replace:!0,to:`/packages/agents${e?`/${encodeURIComponent(e)}`:""}`})}function Et(){var x,L,W,Y,H;const e=La(),[a,r]=Da(),n=ma(),[s,i]=we("packageAction","",["","new","import","edit"]),l=ve({queryKey:["agent-packages"],queryFn:V.agentPackages.list}),f=ve({queryKey:["package-tools"],queryFn:V.packageTools.list}),{selectedId:o,closeDetail:v}=Oa("/packages/item","packageName"),d=s==="new",c=p=>i(p?"new":""),[m,y]=z.useState(),u=s==="import",w=p=>i(p?"import":"");function P(p){const k=new URLSearchParams(window.location.search);k.delete("packageAction"),n(`/packages/item/${encodeURIComponent(p)}?${k}`)}function N(p){const k=new URLSearchParams(window.location.search);k.set("packageAction","edit"),n(`/packages/item/${encodeURIComponent(p)}?${k}`)}const[b,S]=z.useState(),[A,D]=z.useState(),[R,M]=z.useState(!1),[C,j]=z.useState(),O=a.get("q")??"",E=a.get("format")??"all";async function U(){await Promise.all(["agent-packages","agents","skills","package-skill-picker","agent-package","agent-package-files"].map(p=>e.invalidateQueries({queryKey:[p]})))}const q=je({mutationFn:p=>m?V.agentPackages.update(m.name,{content:p.content,files:p.files,skills:p.skills,expectedRevision:m.revision}):V.agentPackages.create(p),onSuccess:async p=>{await U(),Na((m==null?void 0:m.name)??"new"),c(!1),y(void 0),j(`${p.name} saved to your catalog.`),P(p.name)}}),h=q.reset;z.useEffect(()=>{let p=!0;if(y(void 0),s!=="edit"||!o){M(!1);return}return M(!0),D(void 0),h(),(async()=>{try{const k=await V.agentPackages.get(o),_=await Promise.all(k.files.map(async ee=>{const se=await V.agentPackages.get(o,ee.name);return{path:ee.name,content:se.content,encoding:se.encoding}}));if(!k.revision)throw new Error("Package revision is missing; update the API before editing");const Q=bt(o);p&&y(Q?{...k,content:Q.content,format:Q.format,revision:Q.revision??k.revision,draftFiles:Q.files}:{...k,draftFiles:_})}catch(k){p&&D(k.message)}finally{p&&M(!1)}})(),()=>{p=!1}},[s,o,h]);function I(p){var _;const k=(_=l.data)==null?void 0:_.packages.find(Q=>Q.name===p);v(),S({name:`${p.replace(/\./g,"-")}-setup`,packages:[p],backend:(k==null?void 0:k.format)==="agent-plugin"?"copilot":"claude",tool:"apm",cwd:"",prompt:""})}async function B(p){M(!0),D(void 0);try{const k=await V.agentPackages.get(p),_={[`${p}/${k.manifestFile}`]:Ie(k.content)};for(const Q of k.files){const ee=await V.agentPackages.get(p,Q.name);_[`${p}/${Q.name}`]=ee.encoding==="base64"?Uint8Array.from(atob(ee.content),se=>se.charCodeAt(0)):Ie(ee.content)}da(`${p}-source.zip`,ft(_))}catch(k){D(k.message)}finally{M(!1)}}async function $(p){M(!0),D(void 0),j("APM is building the installation archive…");try{const k=await V.agentPackages.exportArtifact(p);da(k.filename,Uint8Array.from(atob(k.content),_=>_.charCodeAt(0))),j(`Exported ${k.format} installation archive.`)}catch(k){D(k.message),j(void 0)}finally{M(!1)}}const T=((x=l.data)==null?void 0:x.packages.filter(p=>`${p.name} ${p.description}`.toLowerCase().includes(O.toLowerCase())&&(E==="all"||p.format===E)))??[];return t.jsxs("div",{className:"min-w-0 space-y-5",children:[t.jsx(za,{title:"Packages",meta:`${((L=l.data)==null?void 0:L.packages.length)??0} in your catalog`,action:t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsxs(J,{variant:"outline","data-testid":"package-import-button",onClick:()=>w(!0),children:[t.jsx(Ka,{size:16,className:"mr-2"}),"Import"]}),t.jsxs(J,{"data-testid":"new-agent-package-button",onClick:()=>{q.reset(),c(!0)},children:[t.jsx(Ja,{size:16,className:"mr-2"}),"New package"]})]})}),t.jsx("div",{className:"space-y-1",children:t.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Keep the instructions, skills and tools you trust in one place. Save a package once, then install it for your coding agent or launch a configured terminal."})}),C&&t.jsx("p",{role:"status",className:"text-sm text-primary break-words",children:C}),(A||l.error)&&t.jsx("p",{role:"alert","data-testid":"package-error",className:"text-sm text-destructive",children:t.jsx("span",{"data-testid":"page-error",children:A??((W=l.error)==null?void 0:W.message)})}),t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(Ba,{size:16,className:"absolute left-3 top-3 text-muted-foreground"}),t.jsx(he,{className:"pl-9","data-testid":"package-search","aria-label":"Search packages",placeholder:"Find a configuration by name or purpose…",value:O,onChange:p=>{const k=new URLSearchParams(a);p.target.value?k.set("q",p.target.value):k.delete("q"),r(k,{replace:!0})}})]}),t.jsxs("select",{"aria-label":"Filter package type","data-testid":"package-format-filter",className:"rounded border border-control-border bg-background p-2 text-sm",value:E,onChange:p=>{const k=new URLSearchParams(a);k.set("format",p.target.value),r(k,{replace:!0})},children:[t.jsx("option",{value:"all",children:"All formats"}),t.jsx("option",{value:"apm",children:"APM packages"}),t.jsx("option",{value:"agent-plugin",children:"Agent Plugins"})]})]}),l.isLoading&&t.jsx("p",{role:"status","data-testid":"page-loading",children:"Loading your catalog…"}),t.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:T.map(p=>t.jsxs("article",{"data-testid":"agent-package-row","data-package-name":p.name,className:"min-w-0 flex flex-col border-b border-outline-variant p-4",children:[t.jsxs("span",{className:"mb-3 text-xs text-muted-foreground",children:[p.format==="apm"?"APM package":"Agent Plugins",p.version?` · v${p.version}`:""]}),t.jsx("button",{type:"button","data-testid":"package-inspect",onClick:()=>P(p.name),className:"text-left font-medium break-words hover:text-primary",children:p.name}),t.jsx("p",{className:"mt-2 flex-1 text-sm text-muted-foreground break-words",children:p.description||"Add a description to help you choose this configuration later."}),p.warnings.map(k=>t.jsx("p",{className:"mt-2 text-xs text-muted-foreground break-words",children:k},k)),t.jsxs("div",{className:"mt-5 grid grid-cols-2 gap-2",children:[t.jsx(J,{variant:"outline","data-testid":"package-run",disabled:R,onClick:()=>I(p.name),children:"Use package"}),t.jsx(J,{variant:"outline","data-testid":"package-card-edit",onClick:()=>void N(p.name),children:"Edit package"})]})]},p.name))}),!l.isLoading&&!l.error&&!T.length&&t.jsxs("div",{"data-testid":"page-empty",className:"rounded-lg border border-dashed border-outline-variant px-4 py-10 text-center",children:[t.jsx(Ha,{size:32,className:"mx-auto mb-3 text-muted-foreground"}),t.jsx("h3",{className:"font-medium",children:O||E!=="all"?"No matching configurations":"Build your personal agent catalog"}),t.jsx("p",{className:"mx-auto mt-2 max-w-md text-sm text-muted-foreground",children:O||E!=="all"?"Try another search or package format.":"Create an APM package with your instructions and existing skills, or import an Agent Plugin from GitHub."}),!O&&E==="all"&&t.jsx(J,{className:"mt-4",onClick:()=>{q.reset(),c(!0)},children:"Create your first package"})]}),(Y=l.data)==null?void 0:Y.broken.map(p=>t.jsxs("p",{role:"alert",className:"text-destructive break-words",children:[p.path,": ",p.error]},p.path)),f.data&&!f.data.apm&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Catalog editing is available. Installation, Git acquisition and installation exports require APM on this ORC machine."}),o&&!s&&t.jsx(vt,{name:o,onClose:v,onUse:()=>I(o),onEdit:()=>void N(o),onExport:()=>void $(o),onSource:()=>void B(o),busy:R,operationError:A},o),t.jsx(Xe,{open:d||s==="edit",onOpenChange:p=>{if(!p&&!q.isPending){if(!Ze((m==null?void 0:m.name)??"new"))return;c(!1),y(void 0)}},children:d||s==="edit"&&m?t.jsx(Nt,{initial:m?{name:m.name,content:m.content,format:m.format,files:m.draftFiles,revision:m.revision}:void 0,pending:q.isPending,error:(H=q.error)==null?void 0:H.message,onSave:p=>q.mutate(p)}):s==="edit"?t.jsxs(Ee,{children:[t.jsx(Le,{children:t.jsx(De,{children:"Package editor"})}),t.jsx("p",{role:A?"alert":"status",children:A??"Opening package editor…"})]}):null}),u&&t.jsx(Pt,{onClose:()=>w(!1),onImported:p=>{U(),w(!1),j(`${p} added to your catalog.`),P(p)}}),b&&t.jsx(St,{initial:b,onClose:()=>S(void 0)},b.name)]})}export{It as LegacyAgentsRedirect,Et as default};
18
+ `}${a}`}function yt(e,a){const r=$e(a);if(r.errors.length)throw new Error("Fix the MCP YAML before saving");const n=r.toJS();if(!Array.isArray(n))throw new Error("MCP declarations must be a YAML list (use [] for none)");const s=$e(e);if(s.errors.length)throw new Error("Fix apm.yml before editing MCP declarations");s.setIn(["dependencies","mcp"],n);const i=s.get("dependencies",!0);ra(i)&&(i.flow=!1);const l=s.getIn(["dependencies","mcp"],!0);if(Ta(l)){l.flow=!1;for(const f of l.items)ra(f)&&(f.flow=!1)}return s.toString()}function jt(e,a){const r=Re(e,a);if(typeof r.name!="string"||!/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(r.name)||r.name.length>64)throw new Error("Use a lowercase package name with single hyphens or periods (up to 64 characters)");if(a==="apm"&&(!r.version||typeof r.version!="string"))throw new Error("APM packages require a version");if(a==="agent-plugin"&&r.$schema!==ba)throw new Error("Use the Agent Plugins v1 schema");return r}const me=new Map;typeof window<"u"&&window.addEventListener("beforeunload",e=>{me.size&&(e.preventDefault(),e.returnValue="")});function Na(e){me.delete(e)}function bt(e){var a;return(a=me.get(e))==null?void 0:a.baseline}function Ze(e){return me.has(e)?window.confirm("Discard unsaved package changes?")?(Na(e),!0):!1:!0}const ca=".apm/instructions/general.instructions.md";function Nt({initial:e,pending:a,error:r,onSave:n}){var ee,se,ke,pe,ge,de,ye,ta;const[s,i]=we("packageFormat","",["","apm","agent-plugin"]),l=z.useRef(me.get((e==null?void 0:e.name)??"new")),f=(e==null?void 0:e.format)??(s||void 0),o=f,[v,d]=z.useState(((ee=l.current)==null?void 0:ee.source)??(e==null?void 0:e.content)??Ae(f??"apm")),[c,m]=z.useState(((se=l.current)==null?void 0:se.files)??(e==null?void 0:e.files)??[]),[y,u]=z.useState(((ke=l.current)==null?void 0:ke.selectedSkills)??[]),[w,P]=z.useState(""),[N,b]=we("packageTab",e?"files":"configuration",["files","configuration","skills"]),[S,A]=we("packageSource","fields",["fields","source"]),D=S==="source",U=g=>A(g?"source":"fields"),[M,C]=z.useState(),[j,O]=z.useState(!1),[E,B]=z.useState(""),[q,h]=z.useState((pe=l.current)==null?void 0:pe.mcpDraft),[I,R]=z.useState(),$=ve({queryKey:["package-skill-picker"],queryFn:()=>V.skills.list()}),T=ve({queryKey:["agents"],queryFn:V.agents.list}),x=z.useMemo(()=>{try{return{fields:Re(v,o??"apm"),error:void 0}}catch(g){return{fields:void 0,error:g.message}}},[v,o]),L=x.fields,W=typeof(L==null?void 0:L.name)=="string"?L.name:"",Y=a||j,H=c.find(g=>g.path===ca),p=(H==null?void 0:H.content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,""))??"",k=c.find(g=>g.path==="mcp.json");z.useEffect(()=>{var F,G,ae;v!==((e==null?void 0:e.content)??Ae(o??"apm"))||JSON.stringify(c)!==JSON.stringify((e==null?void 0:e.files)??[])||y.length>0||q!==void 0?me.set((e==null?void 0:e.name)??"new",{format:o??((F=me.get((e==null?void 0:e.name)??"new"))==null?void 0:F.format)??((G=l.current)==null?void 0:G.format),source:v,files:c,selectedSkills:y,mcpDraft:q,baseline:((ae=l.current)==null?void 0:ae.baseline)??e}):me.delete((e==null?void 0:e.name)??"new")},[v,c,y,q,o,e]);function _(g,F){try{d(kt(v,o??"apm",g,F)),C(void 0)}catch(G){C(G.message)}}function Q(g){const F=me.get((e==null?void 0:e.name)??"new");if(F&&F.format===g){i(g),d(F.source),m(F.files),u(F.selectedSkills),h(F.mcpDraft);return}F&&!Ze((e==null?void 0:e.name)??"new")||(i(g),d(Ae(g)),m([]),u([]),h(void 0))}return t.jsxs(Ee,{className:"min-w-0 grid-cols-[minmax(0,1fr)] w-[calc(100%_-_1rem)] max-w-4xl max-h-[94dvh] overflow-x-hidden overflow-y-auto p-4 sm:p-6",children:[t.jsxs(Le,{children:[t.jsx(De,{className:"break-words pr-8",children:e?`Edit ${e.name}`:"New package"}),t.jsx(Qe,{children:"Save a configuration once, then use it in any project."})]}),o?t.jsxs("form",{className:"min-w-0 space-y-4",onSubmit:g=>{if(g.preventDefault(),!I){C(void 0);try{const F=jt(v,o);o==="agent-plugin"&&k&&JSON.parse(k.content),n({name:F.name,content:v,files:c,format:o,skills:y})}catch(F){C(F.message)}}},children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[t.jsx("span",{className:"rounded bg-surface-high px-3 py-1",children:o==="apm"?"APM":"Plugin"}),!e&&t.jsx(J,{type:"button",variant:"ghost",disabled:Y,onClick:()=>{Ze("new")&&(i(""),d(Ae("apm")),m([]),u([]),h(void 0))},children:"Change type"})]}),t.jsx("div",{role:"tablist","aria-label":"Package editor",className:"flex flex-wrap gap-1 border-b border-surface-highest pb-2",children:["configuration","skills","files"].map(g=>{var F;return t.jsxs(J,{type:"button",role:"tab","aria-selected":N===g,variant:N===g?"default":"ghost","data-testid":`package-editor-${g}`,onClick:()=>b(g),children:[(F=g[0])==null?void 0:F.toUpperCase(),g.slice(1),g==="skills"&&y.length?` (${y.length})`:""]},g)})}),t.jsxs("fieldset",{disabled:Y,className:"min-w-0 space-y-4",children:[N==="configuration"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[t.jsx("span",{className:"text-sm text-outline",children:o==="apm"?"APM configuration":"Portable plugin identity"}),t.jsx(J,{type:"button",variant:"outline","data-testid":"package-editor-mode",disabled:!!I||D&&!!x.error,onClick:()=>{U(!D),h(void 0)},children:D?"Edit fields":o==="apm"?"Edit YAML":"Edit JSON"})]}),D?t.jsx(Fe,{id:"package-yaml",testId:"package-yaml-input",path:o==="apm"?"apm.yml":"plugin.json",value:v,onChange:d,readOnly:Y,height:320}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:[["name","Package name"],["version","Version"],["description","When would you use this?"]].map(([g,F])=>t.jsxs("div",{className:g==="description"?"space-y-1 sm:col-span-2":"space-y-1",children:[t.jsx(re,{htmlFor:`package-${g}`,children:F}),t.jsx(he,{id:`package-${g}`,"data-testid":`package-${g}-input`,disabled:g==="name"&&!!e,value:typeof(L==null?void 0:L[g])=="string"?L[g]:"",onChange:G=>_(g,G.target.value)})]},g))}),o==="apm"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"package-apm-mcp",children:"MCP servers (YAML declarations)"}),t.jsx(Fe,{id:"package-apm-mcp",path:"mcp-dependencies.yml",testId:"package-apm-mcp",height:180,readOnly:Y,value:q??qa(((ge=L==null?void 0:L.dependencies)==null?void 0:ge.mcp)??[]),onChange:g=>{h(g);try{d(yt(v,g)),R(void 0)}catch(F){R(F.message)}}}),t.jsxs("p",{className:"text-xs text-outline",children:["Use registry names, or named APM mappings with transport and command/URL. Credentials use environment references such as"," ",t.jsxs("code",{children:["$","{API_TOKEN}"]}),"."]}),I&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:I})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"package-instructions",children:"Shared instructions"}),t.jsx(We,{id:"package-instructions","data-testid":"package-instructions",rows:7,placeholder:"What should the agent know and how should it work?",value:p,onChange:g=>m(Me(c,ca,wt(H==null?void 0:H.content,g.target.value)))}),t.jsx("p",{className:"text-xs text-outline",children:"Saved as an APM instruction primitive. Agent-specific model and tool configuration belongs in an agent definition."})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"package-agent-picker",children:"Add an existing agent definition"}),t.jsxs("select",{id:"package-agent-picker","data-testid":"package-agent-picker",className:"w-full rounded border border-control-border bg-background p-3",value:"",onChange:async g=>{var G;const F=g.target.value;if(F){O(!0);try{const ae=await V.agents.get(F),be=((G=F.split("/").slice(-1)[0])==null?void 0:G.replace(/[^a-zA-Z0-9-]/g,"-"))??"agent";m(Ue=>Me(Ue,`.apm/agents/${be}.agent.md`,ae.raw))}catch(ae){C(ae.message)}finally{O(!1)}}},children:[t.jsx("option",{value:"",children:"Select an agent to copy into this package…"}),(de=T.data)==null?void 0:de.agents.map(g=>t.jsx("option",{value:g.id,children:g.name},g.id))]})]}),t.jsx("p",{className:"text-sm text-outline",children:"Configure targets, MCP dependencies and launch scripts in Edit YAML. Supporting agent files are editable in Files."})]}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-sm text-outline",children:"Agent Plugins v1 contains skills and MCP. Choose APM if you need shared instructions or agent profiles."}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{children:"mcp.json (optional)"}),t.jsx(Fe,{path:"mcp.json",testId:"package-mcp-input",height:220,value:(k==null?void 0:k.content)??JSON.stringify({$schema:xt,mcpServers:{}},null,2),readOnly:Y,onChange:g=>m(Me(c,"mcp.json",g))}),t.jsx("p",{className:"text-xs text-outline",children:"Credentials are managed by the coding agent. Keep secrets out of package files."})]})]})]})]}),N==="skills"&&t.jsxs(t.Fragment,{children:[c.filter(g=>/^(skills|\.apm\/skills)\/[^/]+\/SKILL\.md$/.test(g.path)).map(g=>{const F=g.path.slice(0,-8);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-outline-variant p-3",children:[t.jsxs("span",{className:"min-w-0 break-words text-sm",children:["Included: ",F.split("/").slice(-2)[0]]}),t.jsx(J,{type:"button",variant:"outline","data-testid":"package-skill-remove",onClick:()=>m(G=>G.filter(ae=>!ae.path.startsWith(F))),children:"Remove from package"})]},g.path)}),t.jsx("p",{className:"text-sm text-outline",children:"Choose skills from your library. Their SKILL.md, scripts, references and assets are copied into this package; the originals stay available independently."}),t.jsx(he,{"aria-label":"Search existing skills","data-testid":"package-skill-search",placeholder:"Search your skills…",value:w,onChange:g=>P(g.target.value)}),$.error&&t.jsx("p",{role:"alert",children:$.error.message}),$.isLoading&&t.jsx("p",{children:"Loading skills…"}),t.jsx("div",{className:"max-h-[40dvh] overflow-auto space-y-2",children:(ye=$.data)==null?void 0:ye.skills.filter(g=>`${g.name} ${g.description}`.toLowerCase().includes(w.toLowerCase())).map(g=>{const F=g.name.split("/").slice(-1)[0],G=c.some(ae=>ae.path===`${o==="apm"?".apm/skills":"skills"}/${F}/SKILL.md`);return t.jsxs("label",{className:"flex items-start gap-3 border-b border-outline-variant p-3","data-testid":"package-skill-option","data-skill-name":g.name,children:[t.jsx("input",{type:"checkbox",className:"mt-1 size-5 shrink-0","data-testid":"package-skill-select",checked:G||y.includes(g.name),disabled:G||Y||!y.includes(g.name)&&y.length>=32,onChange:ae=>u(ae.target.checked?[...y,g.name]:y.filter(be=>be!==g.name))}),t.jsxs("span",{className:"min-w-0 break-words",children:[t.jsxs("span",{className:"block text-sm font-medium",children:[g.name,G?" · included":""]}),t.jsx("span",{className:"block text-xs text-outline line-clamp-2",children:g.description})]})]},g.name)})}),!$.isLoading&&((ta=$.data)==null?void 0:ta.skills.length)===0&&t.jsx("p",{children:"No skills yet. Import skills into your library first, or add skill files directly in Files."})]}),N==="files"&&t.jsxs(t.Fragment,{children:[t.jsxs("details",{className:"border-t border-outline-variant p-3",children:[t.jsx("summary",{className:"cursor-pointer text-sm",children:"Add a file or folder"}),t.jsx(re,{htmlFor:"package-files",children:"Add files from a folder"}),t.jsx(he,{id:"package-files","data-testid":"package-files-input",type:"file",multiple:!0,webkitdirectory:"",onChange:async g=>{const F=g.target.files;if(F!=null&&F.length){O(!0);try{const G=(await pa(F)).filter(ae=>!["apm.yml","plugin.json"].includes(ae.path));m(ae=>[...ae.filter(be=>!G.some(Ue=>Ue.path===be.path)),...G]),C(void 0)}catch(G){C(G.message)}finally{O(!1)}}}}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(he,{"aria-label":"New file path","data-testid":"package-new-file-path",placeholder:o==="apm"?".apm/agents/reviewer.agent.md":"skills/my-skill/SKILL.md",value:E,onChange:g=>B(g.target.value)}),t.jsx(J,{type:"button",variant:"outline",disabled:!E||c.some(g=>g.path===E),onClick:()=>{m(g=>[...g,{path:E,content:"",encoding:"utf8"}]),B("")},children:"Add file"})]})]}),t.jsx(ja,{files:[{path:o==="apm"?"apm.yml":"plugin.json",content:v},...c],readOnly:Y,testId:"package-file-input",onChange:(g,F)=>{g===(o==="apm"?"apm.yml":"plugin.json")?d(F):m(G=>Me(G,g,F))}})]})]}),(r||M||x.error)&&t.jsx("p",{role:"alert","data-testid":"package-editor-error",className:"text-sm text-destructive",children:r||M||x.error}),t.jsxs("div",{className:"sticky bottom-0 border-t border-surface-highest bg-surface pt-3 flex flex-wrap items-center justify-between gap-3",children:[t.jsxs("span",{className:"text-xs text-outline",children:[c.length," files · ",y.length," skills selected"]}),t.jsx(J,{type:"submit","data-testid":"package-submit",disabled:Y||!W.trim()||!!(x.error||I),children:a?"Saving…":e?"Save changes":"Save to catalog"})]})]}):t.jsxs("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"package-type-choice",children:[t.jsxs("button",{type:"button","data-testid":"package-type-apm",onClick:()=>Q("apm"),className:"rounded-lg border border-outline-variant p-5 text-left hover:bg-surface-low",children:[t.jsx("strong",{className:"block mb-2",children:"APM package"}),t.jsx("span",{className:"text-sm text-outline",children:"Instructions, agents, skills, MCP and dependencies. Configure with apm.yml."})]}),t.jsxs("button",{type:"button","data-testid":"package-type-agent-plugin",onClick:()=>Q("agent-plugin"),className:"rounded-lg border border-outline-variant p-5 text-left hover:bg-surface-low",children:[t.jsx("strong",{className:"block mb-2",children:"Agent Plugin"}),t.jsx("span",{className:"text-sm text-outline",children:"Portable skills and MCP. Configure with plugin.json and mcp.json."})]})]})]})}function Ct(e){if(e.length>16*1024*1024)throw new Error("Archive exceeds 16 MiB");let a=0,r=0;const n=ht(e,{filter:o=>{if(o.name.endsWith("/"))return!1;if(a+=o.originalSize,r++,o.originalSize>8*1024*1024||a>16*1024*1024||r>513)throw new Error("Archive exceeds package file or size limits");return!0}}),s=Object.keys(n),l=s.filter(o=>/(^|\/)(apm\.yml|plugin\.json)$/.test(o)).sort((o,v)=>o.split("/").length-v.split("/").length)[0];if(!l)throw new Error("Choose a source ZIP containing apm.yml or portable plugin.json");const f=l.includes("/")?l.slice(0,l.lastIndexOf("/")+1):"";if(s.some(o=>!o.startsWith(f)))throw new Error("Choose an archive containing one package folder");return Object.entries(n).map(([o,v])=>{let d="";for(const c of v)d+=String.fromCharCode(c);try{const c=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0}).decode(v);if(!c.includes("\0"))return{path:o.slice(f.length),content:c,encoding:"utf8"}}catch{}return{path:o.slice(f.length),content:btoa(d),encoding:"base64"}})}function Pt({onClose:e,onImported:a}){var M,C,j,O,E,B,q;const[r,n]=we("importMethod","git",["git","zip","folder"]),[s,i]=z.useState(""),[l,f]=z.useState(""),[o,v]=z.useState("auto"),[d,c]=z.useState(),[m,y]=z.useState(!1),u=je({mutationFn:V.agentPackages.discover}),w=je({mutationFn:V.agentPackages.importGit,onSuccess:h=>a(h.name)}),P=je({mutationFn:V.agentPackages.acquire}),N=je({mutationFn:V.agentPackages.importAcquired,onSuccess:h=>a(h.name)}),b=u.isPending||w.isPending||P.isPending||N.isPending||m,S=((M=u.data)==null?void 0:M.packages)??((C=P.data)==null?void 0:C.packages),A=S==null?void 0:S.find(h=>`${h.format}:${h.path}`===l);async function D(){f(""),u.reset(),P.reset(),w.reset(),N.reset();const h=s.trim();if(!h.includes("://")||/^https:\/\/github\.com\//i.test(h))try{await u.mutateAsync(h);return}catch{u.reset()}P.mutate(h)}async function U(h){const I=h.find(W=>W.path==="apm.yml"),R=h.find(W=>W.path==="plugin.json");if(o==="auto"&&I&&R)throw new Error("Both manifests are present. Select a format before importing.");const $=o==="auto"?I?"apm":"agent-plugin":o,T=$==="apm"?I:R;if(!T||T.encoding==="base64")throw new Error("The selected format's manifest is missing");const x=Re(T.content,$);if(typeof x.name!="string")throw new Error("Manifest is missing a package name");const L=await V.agentPackages.create({name:x.name,content:T.content,format:$,imported:!0,files:h.filter(W=>W!==T&&!($==="agent-plugin"&&W.path==="apm.yml"))});a(L.name)}return t.jsx(Xe,{open:!0,onOpenChange:h=>!h&&!b&&e(),children:t.jsxs(Ee,{className:"min-w-0 grid-cols-[minmax(0,1fr)] w-[calc(100%_-_1rem)] max-w-xl max-h-[94dvh] overflow-x-hidden overflow-y-auto p-4 sm:p-6",children:[t.jsxs(Le,{children:[t.jsx(De,{children:"Import a package"}),t.jsx(Qe,{children:"Add reusable configuration to your catalog, then choose where to install it."})]}),t.jsx("div",{role:"tablist","aria-label":"Import source",className:"flex flex-wrap gap-2",children:[["git","Git repository"],["zip","ZIP file"],["folder","Folder"]].map(([h,I])=>t.jsx(J,{role:"tab","aria-selected":r===h,"data-testid":`package-import-${h}`,variant:r===h?"default":"outline",disabled:b,onClick:()=>{n(h),c(void 0)},children:I},h))}),r==="git"?t.jsxs(t.Fragment,{children:[t.jsxs("form",{className:"space-y-3",onSubmit:h=>{h.preventDefault(),D()},children:[t.jsx(re,{htmlFor:"package-git-source",children:"Repository URL"}),t.jsx(he,{id:"package-git-source","data-testid":"package-git-source",placeholder:"https://github.com/owner/repository",value:s,disabled:b,onChange:h=>{i(h.target.value),u.reset(),P.reset(),w.reset(),N.reset(),f("")}}),t.jsx("p",{className:"text-xs text-outline",children:"Paste a GitHub, GitLab, Bitbucket or Azure DevOps repository or package link."}),t.jsx(J,{type:"submit","data-testid":"package-git-discover",disabled:b||!s.trim(),children:u.isPending||P.isPending?"Finding packages…":"Find packages"})]}),S&&t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"max-h-[40dvh] space-y-2 overflow-auto",children:S.map(h=>t.jsxs("label",{className:"flex items-start gap-3 rounded border border-surface-highest p-3","data-testid":"remote-package",children:[t.jsx("input",{className:"mt-1 size-5",type:"radio",name:"package-import-selection",disabled:b||h.installed,checked:l===`${h.format}:${h.path}`,onChange:()=>f(`${h.format}:${h.path}`)}),t.jsxs("span",{className:"min-w-0 break-words",children:[t.jsxs("strong",{className:"block text-sm",children:[h.name,h.installed?" · already in catalog":""]}),t.jsx("span",{className:"block text-xs text-outline",children:h.description}),t.jsxs("span",{className:"block text-xs text-outline",children:[h.format==="apm"?"APM":"Plugin"," ·"," ",h.path||"Repository root"]})]})]},`${h.format}:${h.path}`))}),!S.length&&t.jsx("p",{children:"No APM or Plugin packages found in this repository."}),(j=u.data)==null?void 0:j.issues.map(h=>t.jsxs("p",{role:"alert",className:"text-xs text-destructive break-words",children:[h.path,": ",h.error]},h.path))]}),S&&t.jsx(J,{"data-testid":"package-git-import",disabled:b||!A,onClick:()=>{A&&(u.data?w.mutate({source:u.data.source,commit:u.data.commit,path:A.path,format:A.format}):P.data&&N.mutate({token:P.data.token,path:A.path}))},children:w.isPending||N.isPending?"Importing…":"Import to catalog"})]}):t.jsxs("div",{className:"space-y-3",children:[t.jsx(re,{htmlFor:"package-import-format",children:"Package format"}),t.jsxs("select",{id:"package-import-format","data-testid":"package-import-format",disabled:b,className:"w-full rounded border border-control-border bg-surface-low p-3",value:o,onChange:h=>v(h.target.value),children:[t.jsx("option",{value:"auto",children:"Detect from manifest"}),t.jsx("option",{value:"apm",children:"APM"}),t.jsx("option",{value:"agent-plugin",children:"Agent Plugin"})]}),t.jsx(re,{htmlFor:"agent-package-folder",children:r==="folder"?"Package folder":"Package source ZIP"}),t.jsx(he,{id:"agent-package-folder","data-testid":r==="folder"?"agent-package-folder":"package-zip-input",type:"file",accept:r==="zip"?".zip":void 0,multiple:r==="folder",...r==="folder"?{webkitdirectory:""}:{},disabled:b,onChange:async h=>{const I=h.target.files;if(I!=null&&I.length){y(!0),c(void 0);try{await U(r==="folder"?await pa(I):Ct(new Uint8Array(await I[0].arrayBuffer())))}catch(R){c(R.message)}finally{y(!1)}}}},r),t.jsx("p",{className:"text-xs text-outline",children:"Original manifests and supporting files are preserved. Import does not launch an agent or run package scripts. Use ZIP on phones where folder selection is unavailable."})]}),(u.error||w.error||P.error||N.error||d)&&t.jsx("p",{role:"alert","data-testid":"package-import-error",className:"text-sm text-destructive",children:((O=u.error)==null?void 0:O.message)??((E=w.error)==null?void 0:E.message)??((B=P.error)==null?void 0:B.message)??((q=N.error)==null?void 0:q.message)??d})]})})}function St({initial:e,onClose:a}){var j,O,E,B,q,h,I,R,$,T;const[r,n]=z.useState({...e,tool:"apm"}),[s,i]=z.useState(),[l,f]=z.useState(!1),[o,v]=z.useState(!1),[d,c]=z.useState("run"),m=z.useRef(null),y=ma(),u=$a(),w=Ia(),P=ve({queryKey:["package-tools"],queryFn:V.packageTools.list}),N=ve({queryKey:["setup-components",r.packages],enabled:r.packages.length>0,queryFn:()=>Promise.all(r.packages.map(x=>V.agentPackages.get(x)))}),b=je({mutationFn:V.agentSetups.command});z.useEffect(()=>{var x;b.data&&((x=m.current)==null||x.scrollIntoView({block:"nearest"}))},[b.data]);const S=(j=N.data)==null?void 0:j.some(x=>x.format==="agent-plugin"),A=S&&r.backend!=="copilot",U=!!(r.cwd.trim()&&r.packages.length&&r.name.trim())&&((O=P.data)==null?void 0:O.apm)&&!A&&!N.error&&!N.isFetching;function M(x){n(L=>({...L,...x})),b.reset(),v(!1),i(void 0)}async function C(x){f(!0),i(void 0);try{const L=await w.create({kind:r.backend,name:`${r.name}${x==="install"?" · install":""}`,setup:{...r,operation:x}});a(),y(Ea(`/terminals/${L.id}`,new URLSearchParams(u.search).get("project")??"all",u.search))}catch(L){i(L.message)}finally{f(!1)}}return t.jsx(Xe,{open:!0,onOpenChange:x=>!x&&!l&&!b.isPending&&a(),children:t.jsxs(Ee,{className:"min-w-0 grid-cols-[minmax(0,1fr)] w-[calc(100%_-_1rem)] max-w-2xl max-h-[94dvh] overflow-x-hidden overflow-y-auto p-4 sm:p-6",children:[t.jsxs(Le,{children:[t.jsx(De,{children:"Use package"}),t.jsx(Qe,{children:"Install it for your coding agent, launch here, or copy a command for your own terminal."})]}),t.jsxs("fieldset",{disabled:l||b.isPending,className:"min-w-0 space-y-4",children:[t.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"setup-backend",children:"Coding agent"}),t.jsx("select",{id:"setup-backend","data-testid":"setup-backend",className:"w-full rounded border border-control-border bg-surface-low p-3",value:r.backend,onChange:x=>M({backend:x.target.value,agent:void 0}),children:["claude","codex","copilot"].map(x=>{var L;return t.jsxs("option",{value:x,disabled:!!(S&&x!=="copilot"),children:[x,S&&x!=="copilot"?" · unsupported for this plugin":(L=w.info)!=null&&L.launchers.includes(x)?"":" · not installed"]},x)})})]})}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"setup-cwd",children:"Project folder on this ORC machine"}),t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[t.jsx(he,{id:"setup-cwd","data-testid":"setup-cwd",value:r.cwd,onChange:x=>M({cwd:x.target.value})}),t.jsx(J,{type:"button",variant:"outline",disabled:!((E=w.info)!=null&&E.ready),onClick:async()=>{try{const x=await V.terminals.pickFolder(r.cwd||void 0);x.path&&M({cwd:x.path})}catch(x){i(x.message)}},children:"Browse"})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"setup-prompt",children:"What should the agent work on?"}),t.jsx(We,{id:"setup-prompt","data-testid":"setup-prompt",rows:3,value:r.prompt,onChange:x=>M({prompt:x.target.value})})]}),t.jsxs("div",{"data-testid":"setup-components",className:"rounded-lg bg-surface-low p-3 text-sm space-y-1",children:[t.jsx("p",{className:"font-medium",children:"Configuration to apply"}),N.isFetching&&t.jsx("p",{children:"Checking package contents…"}),(B=N.data)==null?void 0:B.map(x=>t.jsxs("p",{className:"break-words",children:[x.name,":"," ",x.files.filter(L=>/^(skills|\.apm\/skills)\/[^/]+\/SKILL\.md$/.test(L.name)).length," ","skill files",x.files.some(L=>L.name==="mcp.json")?", native MCP configuration":"",x.files.some(L=>L.name.endsWith(".instructions.md"))?", shared instructions":""]},x.name))]})]}),t.jsxs("p",{className:"text-xs text-outline",children:["APM installs into this project and retains the configuration after the session. Trust and file-conflict prompts appear in the terminal. Copied commands run on this ORC machine in"," ",navigator.platform.startsWith("Win")?"PowerShell":"your shell","."]}),A&&t.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"APM currently activates whole Agent Plugins for Copilot. Select Copilot for this package."}),P.data&&!P.data.apm&&t.jsx("p",{role:"alert",className:"text-sm",children:"Install APM 0.33.0 or newer on the ORC machine, or set ORC_APM_PATH."}),!((q=w.info)!=null&&q.ready)&&t.jsx("p",{role:"alert",className:"text-sm",children:((h=w.info)==null?void 0:h.reason)??"Checking terminal availability…"}),(s||b.error||N.error)&&t.jsx("p",{role:"alert","data-testid":"setup-error",className:"text-sm text-destructive",children:s??((I=b.error)==null?void 0:I.message)??((R=N.error)==null?void 0:R.message)}),t.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[t.jsx(J,{"data-testid":"setup-install",variant:"outline",disabled:l||!U||!(($=w.info)!=null&&$.ready),onClick:()=>void C("install"),children:"Install for coding agent"}),t.jsx(J,{"data-testid":"setup-launch",disabled:l||!U||!((T=w.info)!=null&&T.ready),onClick:()=>void C("run"),children:l?"Preparing…":"Run in ORC terminal"}),t.jsx(J,{"data-testid":"setup-command",variant:"outline",disabled:l||b.isPending||!U,onClick:()=>b.mutate({...r,operation:d}),children:b.isPending?"Preparing command…":"Command for my terminal"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(re,{htmlFor:"command-mode",children:"Command for your terminal"}),t.jsxs("select",{id:"command-mode",className:"w-full rounded border border-control-border bg-surface-low p-3 text-sm",disabled:l||b.isPending,value:d,onChange:x=>{c(x.target.value),b.reset()},children:[t.jsx("option",{value:"run",children:"Install and launch the agent"}),t.jsx("option",{value:"install",children:"Install configuration only"})]})]}),b.data&&t.jsxs("div",{ref:m,className:"min-w-0 space-y-2 rounded border border-surface-highest p-3",children:[t.jsxs(re,{htmlFor:"package-command",children:["Run in ",b.data.shell," on the ORC machine"]}),t.jsx(We,{id:"package-command","data-testid":"package-command",value:b.data.command,readOnly:!0,rows:3,className:"font-mono text-xs"}),t.jsx(J,{variant:"outline",onClick:async()=>{try{await navigator.clipboard.writeText(b.data.command),v(!0)}catch{i("Copy is unavailable in this browser. Select and copy the command above.")}},children:o?"Copied":"Copy command"})]})]})})}function da(e,a){const r=URL.createObjectURL(new Blob([new Uint8Array(a)],{type:"application/zip"})),n=document.createElement("a");n.href=r,n.download=e,n.click(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function It(){const{agentId:e}=Ua();return t.jsx(Ba,{replace:!0,to:`/packages/agents${e?`/${encodeURIComponent(e)}`:""}`})}function Et(){var x,L,W,Y,H;const e=La(),[a,r]=Da(),n=ma(),[s,i]=we("packageAction","",["","new","import","edit"]),l=ve({queryKey:["agent-packages"],queryFn:V.agentPackages.list}),f=ve({queryKey:["package-tools"],queryFn:V.packageTools.list}),{selectedId:o,closeDetail:v}=Oa("/packages/item","packageName"),d=s==="new",c=p=>i(p?"new":""),[m,y]=z.useState(),u=s==="import",w=p=>i(p?"import":"");function P(p){const k=new URLSearchParams(window.location.search);k.delete("packageAction"),n(`/packages/item/${encodeURIComponent(p)}?${k}`)}function N(p){const k=new URLSearchParams(window.location.search);k.set("packageAction","edit"),n(`/packages/item/${encodeURIComponent(p)}?${k}`)}const[b,S]=z.useState(),[A,D]=z.useState(),[U,M]=z.useState(!1),[C,j]=z.useState(),O=a.get("q")??"",E=a.get("format")??"all";async function B(){await Promise.all(["agent-packages","agents","skills","package-skill-picker","agent-package","agent-package-files"].map(p=>e.invalidateQueries({queryKey:[p]})))}const q=je({mutationFn:p=>m?V.agentPackages.update(m.name,{content:p.content,files:p.files,skills:p.skills,expectedRevision:m.revision}):V.agentPackages.create(p),onSuccess:async p=>{await B(),Na((m==null?void 0:m.name)??"new"),c(!1),y(void 0),j(`${p.name} saved to your catalog.`),P(p.name)}}),h=q.reset;z.useEffect(()=>{let p=!0;if(y(void 0),s!=="edit"||!o){M(!1);return}return M(!0),D(void 0),h(),(async()=>{try{const k=await V.agentPackages.get(o),_=await Promise.all(k.files.map(async ee=>{const se=await V.agentPackages.get(o,ee.name);return{path:ee.name,content:se.content,encoding:se.encoding}}));if(!k.revision)throw new Error("Package revision is missing; update the API before editing");const Q=bt(o);p&&y(Q?{...k,content:Q.content,format:Q.format,revision:Q.revision??k.revision,draftFiles:Q.files}:{...k,draftFiles:_})}catch(k){p&&D(k.message)}finally{p&&M(!1)}})(),()=>{p=!1}},[s,o,h]);function I(p){var _;const k=(_=l.data)==null?void 0:_.packages.find(Q=>Q.name===p);v(),S({name:`${p.replace(/\./g,"-")}-setup`,packages:[p],backend:(k==null?void 0:k.format)==="agent-plugin"?"copilot":"claude",tool:"apm",cwd:"",prompt:""})}async function R(p){M(!0),D(void 0);try{const k=await V.agentPackages.get(p),_={[`${p}/${k.manifestFile}`]:Ie(k.content)};for(const Q of k.files){const ee=await V.agentPackages.get(p,Q.name);_[`${p}/${Q.name}`]=ee.encoding==="base64"?Uint8Array.from(atob(ee.content),se=>se.charCodeAt(0)):Ie(ee.content)}da(`${p}-source.zip`,ft(_))}catch(k){D(k.message)}finally{M(!1)}}async function $(p){M(!0),D(void 0),j("APM is building the installation archive…");try{const k=await V.agentPackages.exportArtifact(p);da(k.filename,Uint8Array.from(atob(k.content),_=>_.charCodeAt(0))),j(`Exported ${k.format} installation archive.`)}catch(k){D(k.message),j(void 0)}finally{M(!1)}}const T=((x=l.data)==null?void 0:x.packages.filter(p=>`${p.name} ${p.description}`.toLowerCase().includes(O.toLowerCase())&&(E==="all"||p.format===E)))??[];return t.jsxs("div",{className:"min-w-0 space-y-5",children:[t.jsx(za,{title:"Packages",meta:`${((L=l.data)==null?void 0:L.packages.length)??0} in your catalog`,action:t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsxs(J,{variant:"outline","data-testid":"package-import-button",onClick:()=>w(!0),children:[t.jsx(Ka,{size:16,className:"mr-2"}),"Import"]}),t.jsxs(J,{"data-testid":"new-agent-package-button",onClick:()=>{q.reset(),c(!0)},children:[t.jsx(Ja,{size:16,className:"mr-2"}),"New package"]})]})}),t.jsx("div",{className:"space-y-1",children:t.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Keep the instructions, skills and tools you trust in one place. Save a package once, then install it for your coding agent or launch a configured terminal."})}),C&&t.jsx("p",{role:"status",className:"text-sm text-primary break-words",children:C}),(A||l.error)&&t.jsx("p",{role:"alert","data-testid":"package-error",className:"text-sm text-destructive",children:t.jsx("span",{"data-testid":"page-error",children:A??((W=l.error)==null?void 0:W.message)})}),t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[t.jsxs("div",{className:"relative min-w-0 flex-1",children:[t.jsx(Ra,{size:16,className:"absolute left-3 top-3 text-muted-foreground"}),t.jsx(he,{className:"pl-9","data-testid":"package-search","aria-label":"Search packages",placeholder:"Find a configuration by name or purpose…",value:O,onChange:p=>{const k=new URLSearchParams(a);p.target.value?k.set("q",p.target.value):k.delete("q"),r(k,{replace:!0})}})]}),t.jsxs("select",{"aria-label":"Filter package type","data-testid":"package-format-filter",className:"rounded border border-control-border bg-background p-2 text-sm",value:E,onChange:p=>{const k=new URLSearchParams(a);k.set("format",p.target.value),r(k,{replace:!0})},children:[t.jsx("option",{value:"all",children:"All formats"}),t.jsx("option",{value:"apm",children:"APM packages"}),t.jsx("option",{value:"agent-plugin",children:"Agent Plugins"})]})]}),l.isLoading&&t.jsx("p",{role:"status","data-testid":"page-loading",children:"Loading your catalog…"}),t.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:T.map(p=>t.jsxs("article",{"data-testid":"agent-package-row","data-package-name":p.name,className:"min-w-0 flex flex-col border-b border-outline-variant p-4",children:[t.jsxs("span",{className:"mb-3 text-xs text-muted-foreground",children:[p.format==="apm"?"APM package":"Agent Plugins",p.version?` · v${p.version}`:""]}),t.jsx("button",{type:"button","data-testid":"package-inspect",onClick:()=>P(p.name),className:"text-left font-medium break-words hover:text-primary",children:p.name}),t.jsx("p",{className:"mt-2 flex-1 text-sm text-muted-foreground break-words",children:p.description||"Add a description to help you choose this configuration later."}),p.warnings.map(k=>t.jsx("p",{className:"mt-2 text-xs text-muted-foreground break-words",children:k},k)),t.jsxs("div",{className:"mt-5 grid grid-cols-2 gap-2",children:[t.jsx(J,{variant:"outline","data-testid":"package-run",disabled:U,onClick:()=>I(p.name),children:"Use package"}),t.jsx(J,{variant:"outline","data-testid":"package-card-edit",onClick:()=>void N(p.name),children:"Edit package"})]})]},p.name))}),!l.isLoading&&!l.error&&!T.length&&t.jsxs("div",{"data-testid":"page-empty",className:"rounded-lg border border-dashed border-outline-variant px-4 py-10 text-center",children:[t.jsx(Ha,{size:32,className:"mx-auto mb-3 text-muted-foreground"}),t.jsx("h3",{className:"font-medium",children:O||E!=="all"?"No matching configurations":"Build your personal agent catalog"}),t.jsx("p",{className:"mx-auto mt-2 max-w-md text-sm text-muted-foreground",children:O||E!=="all"?"Try another search or package format.":"Create an APM package with your instructions and existing skills, or import an Agent Plugin from GitHub."}),!O&&E==="all"&&t.jsx(J,{className:"mt-4",onClick:()=>{q.reset(),c(!0)},children:"Create your first package"})]}),(Y=l.data)==null?void 0:Y.broken.map(p=>t.jsxs("p",{role:"alert",className:"text-destructive break-words",children:[p.path,": ",p.error]},p.path)),f.data&&!f.data.apm&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Catalog editing is available. Installation, Git acquisition and installation exports require APM on this ORC machine."}),o&&!s&&t.jsx(vt,{name:o,onClose:v,onUse:()=>I(o),onEdit:()=>void N(o),onExport:()=>void $(o),onSource:()=>void R(o),busy:U,operationError:A},o),t.jsx(Xe,{open:d||s==="edit",onOpenChange:p=>{if(!p&&!q.isPending){if(!Ze((m==null?void 0:m.name)??"new"))return;c(!1),y(void 0)}},children:d||s==="edit"&&m?t.jsx(Nt,{initial:m?{name:m.name,content:m.content,format:m.format,files:m.draftFiles,revision:m.revision}:void 0,pending:q.isPending,error:(H=q.error)==null?void 0:H.message,onSave:p=>q.mutate(p)}):s==="edit"?t.jsxs(Ee,{children:[t.jsx(Le,{children:t.jsx(De,{children:"Package editor"})}),t.jsx("p",{role:A?"alert":"status",children:A??"Opening package editor…"})]}):null}),u&&t.jsx(Pt,{onClose:()=>w(!1),onImported:p=>{B(),w(!1),j(`${p} added to your catalog.`),P(p)}}),b&&t.jsx(St,{initial:b,onClose:()=>S(void 0)},b.name)]})}export{It as LegacyAgentsRedirect,Et as default};
@@ -1 +1 @@
1
- import{j as t,C as c,f as o}from"./index-SOCnaNS0.js";const i="inline-flex min-h-11 items-center gap-1 font-label text-xs text-primary hover:text-on-surface disabled:opacity-40 disabled:hover:text-primary";function h({page:e,pageSize:s,total:a,onPage:n}){const r=Math.max(1,Math.ceil(a/s));if(a<=s)return null;const l=e*s+1,x=Math.min(a,(e+1)*s);return t.jsxs("div",{"data-testid":"pager",className:"flex flex-wrap gap-2 items-center justify-between border-t border-surface-highest px-3 py-2",children:[t.jsxs("span",{className:"font-label text-xs text-outline",children:[l,"–",x," of ",a]}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("button",{type:"button","data-testid":"pager-prev",className:i,disabled:e===0,onClick:()=>n(e-1),children:[t.jsx(c,{className:"h-3 w-3"}),"Prev"]}),t.jsxs("span",{className:"font-label text-xs text-outline",children:["Page ",e+1," / ",r]}),t.jsxs("button",{type:"button","data-testid":"pager-next",className:i,disabled:e>=r-1,onClick:()=>n(e+1),children:["Next",t.jsx(o,{className:"h-3 w-3"})]})]})]})}export{h as P};
1
+ import{j as t,C as c,f as o}from"./index-BqQDBYwx.js";const i="inline-flex min-h-11 items-center gap-1 font-label text-xs text-primary hover:text-on-surface disabled:opacity-40 disabled:hover:text-primary";function h({page:e,pageSize:s,total:a,onPage:n}){const r=Math.max(1,Math.ceil(a/s));if(a<=s)return null;const l=e*s+1,x=Math.min(a,(e+1)*s);return t.jsxs("div",{"data-testid":"pager",className:"flex flex-wrap gap-2 items-center justify-between border-t border-surface-highest px-3 py-2",children:[t.jsxs("span",{className:"font-label text-xs text-outline",children:[l,"–",x," of ",a]}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("button",{type:"button","data-testid":"pager-prev",className:i,disabled:e===0,onClick:()=>n(e-1),children:[t.jsx(c,{className:"h-3 w-3"}),"Prev"]}),t.jsxs("span",{className:"font-label text-xs text-outline",children:["Page ",e+1," / ",r]}),t.jsxs("button",{type:"button","data-testid":"pager-next",className:i,disabled:e>=r-1,onClick:()=>n(e+1),children:["Next",t.jsx(o,{className:"h-3 w-3"})]})]})]})}export{h as P};
@@ -1,4 +1,4 @@
1
- var bt=Object.defineProperty;var Ht=(n,B,e)=>B in n?bt(n,B,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[B]=e;var F=(n,B,e)=>Ht(n,typeof B!="symbol"?B+"":B,e);import{bH as X,bI as IB,bJ as UB,bK as KB,bL as mt,bM as DB,bN as CB,bO as Ft,bP as jB,bQ as Tt,bR as ke,bS as Me,r as _,j as c,Y as z,Z as uB,B as EB,a as Rt,u as St,n as _t,$ as ye,b as Ee,d as Be,bT as vt,bU as Pt,bV as Je,bW as je,a2 as kt,a3 as Mt,a4 as yt,a5 as Jt,bX as jt,a6 as Ut,V as Kt}from"./index-SOCnaNS0.js";import{u as Qt}from"./useJobs-DDRY0jra.js";function de(n,B,e,t=[]){return Object.entries(n).map(([s,C])=>({native:s,event:C,block:B.includes(s),context:e.includes(s),rewrite_command:t.includes(s)}))}const qt={PreToolUse:"pre_tool",PostToolUse:"post_tool",PostToolUseFailure:"post_tool_failure",PostToolBatch:"post_tool_batch",SessionStart:"session_start",SessionEnd:"session_end",UserPromptSubmit:"prompt_submit",UserPromptExpansion:"prompt_expansion",Stop:"stop",StopFailure:"stop_failure",SubagentStart:"subagent_start",SubagentStop:"subagent_stop",PreCompact:"pre_compact",PostCompact:"post_compact",PermissionRequest:"permission_request",PermissionDenied:"permission_denied",Notification:"notification",Setup:"setup",TeammateIdle:"teammate_idle",TaskCreated:"task_created",TaskCompleted:"task_completed",Elicitation:"elicitation",ElicitationResult:"elicitation_result",ConfigChange:"config_change",WorktreeRemove:"worktree_remove",InstructionsLoaded:"instructions_loaded",CwdChanged:"cwd_changed",FileChanged:"file_changed",DirectoryAdded:"directory_added",MessageDisplay:"message_display"},JB={claude:de(qt,["PreToolUse","UserPromptSubmit","UserPromptExpansion","Stop","SubagentStop","TaskCreated","ConfigChange"],["PreToolUse","PostToolUse","PostToolUseFailure","UserPromptSubmit","SessionStart","SubagentStart","UserPromptExpansion","PostToolBatch","Stop","SubagentStop"],["PreToolUse"]),cursor:de({sessionStart:"session_start",sessionEnd:"session_end",preToolUse:"pre_tool",postToolUse:"post_tool",postToolUseFailure:"post_tool_failure",subagentStart:"subagent_start",subagentStop:"subagent_stop",beforeShellExecution:"before_shell",afterShellExecution:"after_shell",beforeMCPExecution:"before_mcp",afterMCPExecution:"after_mcp",beforeReadFile:"before_read",afterFileEdit:"after_edit",beforeSubmitPrompt:"prompt_submit",preCompact:"pre_compact",stop:"stop",afterAgentResponse:"agent_response",afterAgentThought:"agent_thought",beforeTabFileRead:"before_tab_read",afterTabFileEdit:"after_tab_edit",workspaceOpen:"workspace_open"},["preToolUse","beforeShellExecution","beforeMCPExecution","beforeReadFile","beforeTabFileRead","beforeSubmitPrompt","subagentStart"],["sessionStart"]),gemini:de({BeforeTool:"pre_tool",AfterTool:"post_tool",BeforeAgent:"prompt_submit",AfterAgent:"stop",BeforeModel:"before_model",AfterModel:"after_model",BeforeToolSelection:"before_tool_selection",SessionStart:"session_start",SessionEnd:"session_end",PreCompress:"pre_compact",Notification:"notification"},["BeforeTool","BeforeAgent","AfterAgent","BeforeModel"],["SessionStart","BeforeAgent","BeforeTool","AfterTool","AfterAgent"]),codex:de({PreToolUse:"pre_tool",PermissionRequest:"permission_request",PostToolUse:"post_tool",PreCompact:"pre_compact",PostCompact:"post_compact",UserPromptSubmit:"prompt_submit",SubagentStart:"subagent_start",SubagentStop:"subagent_stop",SessionStart:"session_start",SessionEnd:"session_end",Stop:"stop",Interrupt:"interrupt"},["PreToolUse"],["PreToolUse","PostToolUse","UserPromptSubmit","SessionStart","SubagentStart"])};function Yt(n,B){const e=JB[n];return e==null?void 0:e.find(t=>t.event===B||`native:${t.native}`===B)}/*!
1
+ var bt=Object.defineProperty;var Ht=(n,B,e)=>B in n?bt(n,B,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[B]=e;var F=(n,B,e)=>Ht(n,typeof B!="symbol"?B+"":B,e);import{bI as X,bJ as IB,bK as UB,bL as KB,bM as mt,bN as DB,bO as CB,bP as Ft,bQ as jB,bR as Tt,bS as ke,bT as Me,r as _,j as c,Y as z,Z as uB,B as EB,a as Rt,u as St,n as _t,$ as ye,b as Ee,d as Be,bU as vt,bV as Pt,bW as Je,bX as je,a2 as kt,a3 as Mt,a4 as yt,a5 as Jt,bY as jt,a6 as Ut,V as Kt}from"./index-BqQDBYwx.js";import{u as Qt}from"./useJobs-By4K4BjX.js";function de(n,B,e,t=[]){return Object.entries(n).map(([s,C])=>({native:s,event:C,block:B.includes(s),context:e.includes(s),rewrite_command:t.includes(s)}))}const qt={PreToolUse:"pre_tool",PostToolUse:"post_tool",PostToolUseFailure:"post_tool_failure",PostToolBatch:"post_tool_batch",SessionStart:"session_start",SessionEnd:"session_end",UserPromptSubmit:"prompt_submit",UserPromptExpansion:"prompt_expansion",Stop:"stop",StopFailure:"stop_failure",SubagentStart:"subagent_start",SubagentStop:"subagent_stop",PreCompact:"pre_compact",PostCompact:"post_compact",PermissionRequest:"permission_request",PermissionDenied:"permission_denied",Notification:"notification",Setup:"setup",TeammateIdle:"teammate_idle",TaskCreated:"task_created",TaskCompleted:"task_completed",Elicitation:"elicitation",ElicitationResult:"elicitation_result",ConfigChange:"config_change",WorktreeRemove:"worktree_remove",InstructionsLoaded:"instructions_loaded",CwdChanged:"cwd_changed",FileChanged:"file_changed",DirectoryAdded:"directory_added",MessageDisplay:"message_display"},JB={claude:de(qt,["PreToolUse","UserPromptSubmit","UserPromptExpansion","Stop","SubagentStop","TaskCreated","ConfigChange"],["PreToolUse","PostToolUse","PostToolUseFailure","UserPromptSubmit","SessionStart","SubagentStart","UserPromptExpansion","PostToolBatch","Stop","SubagentStop"],["PreToolUse"]),cursor:de({sessionStart:"session_start",sessionEnd:"session_end",preToolUse:"pre_tool",postToolUse:"post_tool",postToolUseFailure:"post_tool_failure",subagentStart:"subagent_start",subagentStop:"subagent_stop",beforeShellExecution:"before_shell",afterShellExecution:"after_shell",beforeMCPExecution:"before_mcp",afterMCPExecution:"after_mcp",beforeReadFile:"before_read",afterFileEdit:"after_edit",beforeSubmitPrompt:"prompt_submit",preCompact:"pre_compact",stop:"stop",afterAgentResponse:"agent_response",afterAgentThought:"agent_thought",beforeTabFileRead:"before_tab_read",afterTabFileEdit:"after_tab_edit",workspaceOpen:"workspace_open"},["preToolUse","beforeShellExecution","beforeMCPExecution","beforeReadFile","beforeTabFileRead","beforeSubmitPrompt","subagentStart"],["sessionStart"]),gemini:de({BeforeTool:"pre_tool",AfterTool:"post_tool",BeforeAgent:"prompt_submit",AfterAgent:"stop",BeforeModel:"before_model",AfterModel:"after_model",BeforeToolSelection:"before_tool_selection",SessionStart:"session_start",SessionEnd:"session_end",PreCompress:"pre_compact",Notification:"notification"},["BeforeTool","BeforeAgent","AfterAgent","BeforeModel"],["SessionStart","BeforeAgent","BeforeTool","AfterTool","AfterAgent"]),codex:de({PreToolUse:"pre_tool",PermissionRequest:"permission_request",PostToolUse:"post_tool",PreCompact:"pre_compact",PostCompact:"post_compact",UserPromptSubmit:"prompt_submit",SubagentStart:"subagent_start",SubagentStop:"subagent_stop",SessionStart:"session_start",SessionEnd:"session_end",Stop:"stop",Interrupt:"interrupt"},["PreToolUse"],["PreToolUse","PostToolUse","UserPromptSubmit","SessionStart","SubagentStart"])};function Yt(n,B){const e=JB[n];return e==null?void 0:e.find(t=>t.event===B||`native:${t.native}`===B)}/*!
2
2
  * re2js
3
3
  * RE2JS is the JavaScript port of RE2, a regular expression engine that provides linear time matching
4
4
  *
@@ -0,0 +1,5 @@
1
+ import{g as fe,h as Je,a as Ke,n as Ae,r as l,u as le,j as e,B as H,a8 as ce,U as de,W as xe,X as ue,at as me,Y as ee,Z as G,au as Oe,d as z,av as Qe,E as Ue,q as Fe,aw as We,L as Ve,ax as Ge,ay as Ye,az as Xe,o as He,aA as Ze,a2 as et,a3 as tt,a4 as st,a5 as at,z as ae,aB as he,y as ne,R as pe,aC as Be,C as nt,f as rt,a6 as it,S as ot,aD as lt,ab as ct,l as dt,aE as xt,aF as ut,af as mt,T as ht,s as pt,t as qe,v as B,w as gt,x as I,V as ft}from"./index-BqQDBYwx.js";import{P as jt}from"./pencil-ClEwbF1x.js";import{R as Ie}from"./refresh-cw-BGtNOi70.js";import{P as vt}from"./Pager-urh4-P2a.js";import{u as bt}from"./useProjectScope-BvcpSOql.js";function yt({projectId:s}){var je,ve,be,ye,Ne,we,ke,Se,Ce,_e;const[d]=fe(),u=Je(),f=Ke(),p=Ae(),[h,x]=l.useState({key:"",offset:0}),[r,i]=l.useState(null),[w,k]=l.useState(!1),[c,L]=l.useState(!1),[b,o]=l.useState(""),[m,g]=l.useState(""),[A,$]=l.useState(s),[E,T]=l.useState(""),[R,J]=l.useState(""),[O,P]=l.useState(""),[D,U]=l.useState(""),[n,v]=l.useState(0),q=d.get("q")??"",F=d.get("agent")??"",t=d.get("ended")!=="0",N=JSON.stringify([s,q,F]),_=h.key===N?h.offset:0,C=a=>x({key:N,offset:a}),y=le({queryKey:["sessions","archive",s,q,F,_],queryFn:()=>z.sessions.archive({q,...s==="all"?{}:{project_id:s},...["claude","codex"].includes(F)?{agent:F}:{},offset:_,limit:20}),enabled:t,refetchInterval:1e4}),te=le({queryKey:["sessions","archive-transcript",r==null?void 0:r.id,r==null?void 0:r.revision,n],queryFn:()=>z.sessions.archiveTranscript(r==null?void 0:r.id,{revision:r==null?void 0:r.revision,offset:n,limit:50}),enabled:!!r});async function re(a){L(!0),o(""),g("");try{await a(),await f.invalidateQueries({queryKey:["sessions"]})}catch(S){o(S instanceof Error?S.message:"Request failed")}finally{L(!1)}}async function Me(a){var Te,Le;if(!(a!=null&&a.length))return;const S=(Le=(Te=p.data)==null?void 0:Te.find(K=>K.id===A))==null?void 0:Le.name;if(!S){o("Select a project before uploading");return}await re(async()=>{var Pe,Ee,Re,De;let K=localStorage.getItem("orc_session_upload_source");K||(K=crypto.randomUUID(),localStorage.setItem("orc_session_upload_source",K));let $e=0;const Y=[];for(const se of Array.from(a))try{if(se.size>60*1024*1024)throw new Error("File exceeds 60 MiB");const X=await se.text(),ie=X.split(/\r?\n/).filter(Z=>Z.trim()).map(Z=>JSON.parse(Z)),Q=((Pe=ie[0])==null?void 0:Pe.type)==="session_meta",j=Q?ie[0].payload:ie.find(Z=>Z.sessionId),ze=await z.sessions.archiveUpload({project:S,source_id:K,agent:Q?"codex":"claude",session_id:Q?j==null?void 0:j.id:j==null?void 0:j.sessionId,title:se.name.slice(0,200),metadata:{cwd:(j==null?void 0:j.cwd)??"",subdirectory:"",...Q&&((Ee=j==null?void 0:j.git)!=null&&Ee.repository_url)?{repository:j.git.repository_url}:{},...Q&&((Re=j==null?void 0:j.git)!=null&&Re.branch)?{branch:j.git.branch}:{},...Q&&((De=j==null?void 0:j.git)!=null&&De.commit_hash)?{commit:j.git.commit_hash}:{}},bundle:{version:1,files:[{path:"session.jsonl",content:X}]}});["created","updated","unchanged","stale"].includes(ze.outcome)&&$e++}catch(X){Y.push(`${se.name}: ${X instanceof Error?X.message:"Upload failed"}`)}g(`${$e} of ${a.length} sessions synchronized${Y.length?`; ${Y.length} need attention`:""}.`),Y.length&&o(Y.join(`
2
+ `))})}return t?e.jsxs("section",{className:"mt-8 space-y-3","data-testid":"session-archive",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-medium",children:"Archived sessions"}),e.jsx("p",{className:"text-xs text-outline",children:"Uploaded history stays available after the source computer is offline."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{variant:"outline","data-testid":"archive-index",disabled:c,onClick:()=>void re(async()=>{const a=await z.sessions.archiveIndex(s==="all"||s==="unassigned"?void 0:s);g(`${a.indexed} sessions indexed; ${a.failed} failed; ${a.skipped} skipped.`)}),children:"Index discovered sessions"}),e.jsx(H,{"data-testid":"archive-upload-open",onClick:()=>{$(s),k(!0)},children:"Upload sessions"})]})]}),m&&e.jsx("p",{role:"status","data-testid":"archive-feedback",className:"text-sm",children:m}),(b||y.error)&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b||((je=y.error)==null?void 0:je.message)}),((ve=y.data)==null?void 0:ve.degraded)&&e.jsx("p",{role:"status","data-testid":"archive-degraded",className:"text-xs text-outline",children:y.data.degraded}),!!((be=y.data)!=null&&be.pending_chunks)&&e.jsxs("p",{className:"text-xs text-outline",children:[y.data.pending_chunks," passages waiting for embeddings"]}),e.jsxs("div",{className:"divide-y divide-outline-variant rounded border border-outline-variant",children:[y.isLoading&&e.jsx("p",{className:"p-4 text-sm",children:"Loading archived sessions…"}),!y.isLoading&&!((ye=y.data)!=null&&ye.sessions.length)&&e.jsx("p",{className:"p-4 text-sm text-outline",children:"No archived sessions match this view."}),(Ne=y.data)==null?void 0:Ne.sessions.map(a=>e.jsxs("button",{type:"button","data-testid":"archive-session-row","data-archive-id":a.id,className:"block w-full p-3 text-left hover:bg-surface-container",onClick:()=>{i(a),v(0),T(a.metadata.repository??""),J(a.metadata.branch??""),P(a.metadata.commit??""),U(a.metadata.subdirectory)},children:[e.jsx("span",{className:"block text-sm font-medium",children:a.title}),e.jsxs("span",{className:"text-xs text-outline",children:[a.agent," · ended · ",new Date(a.updated_at).toLocaleString()," · revision"," ",a.revision," · ",a.metadata.cwd]}),a.passages.map(S=>e.jsx("span",{className:"mt-1 block text-sm text-outline",children:S.snippet},S.citation)),a.embedding_error&&e.jsx("span",{className:"block text-xs text-error",children:a.embedding_error})]},a.id))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(H,{variant:"ghost",disabled:_===0,onClick:()=>C(Math.max(0,_-20)),children:"Previous"}),e.jsx(H,{variant:"ghost",disabled:!((we=y.data)!=null&&we.has_more),onClick:()=>C(_+20),children:"Next"})]}),e.jsx(ce,{open:w,onOpenChange:k,children:e.jsxs(de,{children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Upload session histories"}),e.jsx(me,{children:"Select an existing project and native Claude/Codex JSONL files. This stores history without starting a terminal. For large collections, use the orc-platform sync script."})]}),e.jsx(ee,{htmlFor:"archive-project",children:"Project"}),e.jsxs("select",{id:"archive-project","data-testid":"archive-project",value:A,onChange:a=>$(a.target.value),className:"rounded border border-outline-variant bg-surface p-2",children:[e.jsx("option",{value:"all",children:"Select a project"}),(ke=p.data)==null?void 0:ke.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsx(G,{"data-testid":"archive-files",type:"file",multiple:!0,accept:".jsonl",disabled:c||!((Se=p.data)!=null&&Se.some(a=>a.id===A)),onChange:a=>void Me(a.target.files)}),c&&e.jsx("p",{role:"status",children:"Uploading…"}),m&&e.jsx("p",{role:"status","data-testid":"archive-upload-feedback",children:m}),b&&e.jsx("p",{role:"alert",className:"whitespace-pre-wrap text-sm text-error",children:b})]})}),e.jsx(ce,{open:!!r,onOpenChange:a=>{a||i(null)},children:e.jsxs(de,{className:"max-h-[90vh] max-w-3xl overflow-y-auto","data-testid":"archive-detail",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:r==null?void 0:r.title}),e.jsxs(me,{children:["Archived history · revision ",r==null?void 0:r.revision,". Prepare a destination checkout to continue in a terminal."]})]}),te.error&&e.jsx("p",{role:"alert",children:te.error.message}),(Ce=te.data)==null?void 0:Ce.turns.map(a=>e.jsxs("div",{className:"border-b border-outline-variant py-2","data-testid":"archive-turn",children:[e.jsx("p",{className:"text-xs text-outline",children:a.role}),e.jsx(Oe,{plain:!0,children:a.blocks.map(S=>S.type==="tool_use"?`${S.name}
3
+ ${S.input}
4
+ ${S.result??""}`:S.text).join(`
5
+ `)})]},a.index)),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(H,{variant:"ghost",disabled:!n,onClick:()=>v(Math.max(0,n-50)),children:"Previous messages"}),e.jsx(H,{variant:"ghost",disabled:n+50>=(((_e=te.data)==null?void 0:_e.total)??0),onClick:()=>v(n+50),children:"Next messages"})]}),e.jsxs("div",{className:"space-y-2 border-t border-outline-variant pt-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Continue on ORC"}),e.jsx("p",{className:"text-xs text-outline",children:"Use the pushed repository, branch and exact commit for the work you want to continue. The destination project must have its repository configured."}),e.jsx(ee,{htmlFor:"archive-repository",children:"Repository"}),e.jsx(G,{id:"archive-repository","data-testid":"archive-repository",value:E,onChange:a=>T(a.target.value)}),e.jsx(ee,{htmlFor:"archive-branch",children:"Branch"}),e.jsx(G,{id:"archive-branch","data-testid":"archive-branch",value:R,onChange:a=>J(a.target.value)}),e.jsx(ee,{htmlFor:"archive-commit",children:"Pushed commit"}),e.jsx(G,{id:"archive-commit","data-testid":"archive-commit",value:O,onChange:a=>P(a.target.value)}),e.jsx(ee,{htmlFor:"archive-subdirectory",children:"Repository subdirectory"}),e.jsx(G,{id:"archive-subdirectory","data-testid":"archive-subdirectory",value:D,onChange:a=>U(a.target.value),placeholder:"Repository root"}),e.jsx(H,{"data-testid":"archive-resume",disabled:c||!E||!R||!/^[a-f0-9]{40}$/i.test(O),onClick:()=>void re(async()=>{if(!r)return;const a=await z.sessions.archiveResume(r.id,{revision:r.revision,repository:E,branch:R,commit:O,subdirectory:D});if(a.status!=="ready"||!a.live_session_id)throw new Error(a.error||"Session preparation failed");const S=await z.terminals.create({kind:r.agent,live_session_id:a.live_session_id});u(`/terminals/${S.id}`)}),children:c?"Preparing…":"Prepare and resume in terminal"}),b&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:b})]})]})})]}):null}function W({text:s,query:d}){const u=d.trim();if(u.length<2)return e.jsx(e.Fragment,{children:s});const f=s.split(new RegExp(`(${Qe(u)})`,"gi"));return e.jsx(e.Fragment,{children:f.map((p,h)=>p.toLowerCase()===u.toLowerCase()?e.jsx("mark",{className:"bg-primary/30 text-on-surface rounded-sm",children:p},h):p)})}function Nt({projectId:s,pending:d,onSelect:u}){var b;const[f,p]=l.useState(""),[h,x]=l.useState(!1),[r,i]=l.useState(null),w=le({queryKey:["tasks","session-picker",s],queryFn:()=>z.tasks.list({...s?{project_id:s}:{},limit:100})});async function k(o){i(null);try{await u(o)}catch(m){i(m instanceof Error?m.message:"Could not link task")}}async function c(){x(!0),i(null);try{const o=await z.tasks.get(f.trim());await k(o.id)}catch(o){i(o instanceof Error?o.message:"Task lookup failed")}finally{x(!1)}}const L=(((b=w.data)==null?void 0:b.tasks)??[]).filter(o=>`${o.title} ${o.id}`.toLowerCase().includes(f.trim().toLowerCase()));return e.jsxs("div",{className:"space-y-3",children:[e.jsx(G,{"data-testid":"session-task-search","aria-label":"Search tasks or enter a task ID",value:f,onChange:o=>{p(o.target.value),i(null)},placeholder:"Search recent tasks or paste a task ID"}),e.jsxs("p",{className:"text-xs text-outline",children:["Up to 100 recent tasks",s?" in this project":" across projects",". Older or other-project tasks can be linked by exact ID."]}),r&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:r}),w.error?e.jsx(Ue,{message:w.error.message,onRetry:()=>w.refetch()}):w.isLoading?e.jsx("p",{role:"status",children:"Loading tasks…"}):e.jsxs("div",{className:"max-h-72 overflow-y-auto divide-y divide-border",children:[L.map(o=>e.jsxs("button",{type:"button","data-testid":"session-task-option","data-task-id":o.id,disabled:d||h,onClick:()=>void k(o.id),className:"w-full min-h-11 py-2 text-left hover:bg-surface-highest disabled:opacity-50",children:[e.jsx("span",{className:"block text-sm break-words",children:o.title}),e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs text-outline",children:[e.jsx(Fe,{status:o.status,className:"px-0"}),o.id]})]},o.id)),L.length===0&&e.jsx("p",{className:"py-4 text-sm text-outline",children:"No recent task matches. Paste its exact ID to look it up."})]}),f.trim()&&e.jsx(H,{variant:"outline",disabled:d||h,onClick:()=>void c(),children:h?"Looking up…":"Link by exact ID"})]})}function ge({session:s,linkTestId:d="open-task"}){const[u]=fe(),[f,p]=l.useState(!1),h=We(),x=u.get("project")??s.project_id;async function r(i){try{await h.mutateAsync({id:s.id,taskId:i}),p(!1)}catch{}}return e.jsxs("div",{className:"min-w-0 space-y-1",children:[s.task&&e.jsxs("div",{className:"min-w-0",children:[e.jsx(Ve,{"data-testid":d,to:Ge(`/tasks/${s.task.id}`,x),className:"block max-w-64 truncate text-sm text-primary hover:underline",title:s.task.title,children:s.task.title}),e.jsx(Fe,{status:s.task.status,className:"px-0"})]}),e.jsxs(ce,{open:f,onOpenChange:i=>{p(i),i&&h.reset()},children:[e.jsx(Ye,{asChild:!0,children:e.jsxs("button",{type:"button","data-testid":"link-task",className:"inline-flex min-h-9 items-center gap-1.5 text-xs text-outline hover:text-on-surface",children:[s.task?e.jsx(jt,{size:12}):e.jsx(Xe,{size:13}),s.task?"Change task":"Link task"]})}),e.jsxs(de,{"data-testid":"session-task-dialog",className:"max-h-[85dvh] w-[calc(100%-2rem)] overflow-y-auto",children:[e.jsxs(xe,{children:[e.jsx(ue,{children:"Link a task"}),e.jsxs(me,{children:["Choose a recent task for ",s.name??"this session",", or paste an exact task ID."]})]}),h.error&&e.jsx("p",{role:"alert",className:"text-sm text-error",children:h.error.message}),e.jsx(Nt,{projectId:s.project_id,pending:h.isPending,onSelect:r}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.task&&e.jsx(H,{variant:"outline","data-testid":"session-task-unlink",disabled:h.isPending,onClick:()=>void r(null),children:"Unlink task"})})]})]})]})}const oe="session-search",wt={user:"border-border/65",assistant:"border-border/65",tool:"border-border/65 bg-transparent",system:"border-border/65 bg-transparent"},kt=["command","cmd","file_path","path","pattern","query","url","description"];function St(s){try{const d=JSON.parse(s);for(const u of kt)if(typeof d[u]=="string")return d[u]}catch{}return s}function Ct(s){try{return JSON.stringify(JSON.parse(s),null,2)}catch{return s}}function _t(s,d,u){l.useEffect(()=>{const f=s.current,p=CSS.highlights,h=window.Highlight;if(!f||!p||!h)return;const x=d.trim().toLowerCase(),r=()=>{var L;if(p.delete(oe),x.length<2)return;const k=[],c=document.createTreeWalker(f,NodeFilter.SHOW_TEXT);for(let b=c.nextNode();b;b=c.nextNode()){const o=((L=b.textContent)==null?void 0:L.toLowerCase())??"";for(let m=o.indexOf(x);m>=0;m=o.indexOf(x,m+x.length)){const g=new Range;g.setStart(b,m),g.setEnd(b,m+x.length),k.push(g)}}k.length>0&&p.set(oe,new h(...k))};r();let i;const w=new MutationObserver(()=>{clearTimeout(i),i=setTimeout(r,150)});return w.observe(f,{childList:!0,subtree:!0,characterData:!0}),()=>{clearTimeout(i),w.disconnect(),p.delete(oe)}},[s,d,u])}function Tt({block:s,open:d}){const u=s.result!==void 0;return e.jsxs("details",{open:d||void 0,"data-testid":"tool-box",className:"border-l border-border bg-background",children:[e.jsxs("summary",{className:"flex cursor-pointer items-center gap-2 px-2 py-1.5 font-label text-xs font-medium text-outline hover:text-on-surface",children:[e.jsx("span",{className:"text-secondary shrink-0",children:s.name}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono normal-case tracking-normal text-on-surface-variant",children:St(s.input)}),e.jsx("span",{className:`shrink-0 ${u?"text-outline":"text-tertiary"}`,children:u?"done":"no result"})]}),e.jsxs("div",{className:"space-y-2 border-t border-border px-2 py-2",children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"input"}),e.jsx("pre",{className:"max-h-72 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:Ct(s.input)}),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[10px] font-medium text-outline",children:"result"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.result})]})]})]})}function Lt({block:s,matched:d}){if(s.type==="text")return e.jsx(Oe,{revealContext:d,children:s.text});if(s.type==="tool_use")return e.jsx(Tt,{block:s,open:d});const u=s.type==="thinking"?"thinking":"result";return e.jsxs("details",{open:d||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:u}),s.type==="thinking"?e.jsx("div",{className:"mt-1",children:e.jsx(ct,{children:s.text})}):e.jsx("pre",{className:"mt-1 max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap break-words",children:s.text})]})}function $t({sessionId:s,initialQuery:d,onClose:u}){const[f,p]=l.useState(d),[h,x]=l.useState(0),{data:r}=He(!1),i=r==null?void 0:r.find(n=>n.id===s),w=i!==void 0&&i.status!=="stopped",k=f.trim().length>=2?f.trim():"",{data:c,isLoading:L,isFetching:b,error:o,refetch:m,dataUpdatedAt:g}=Ze(s,k),A=l.useRef(null),$=l.useRef(null),E=l.useRef(!0),T=l.useRef(0),[R,J]=l.useState(!0),O=l.useCallback(()=>{const n=A.current;n&&(n.scrollTo({top:n.scrollHeight}),requestAnimationFrame(()=>n.scrollTo({top:n.scrollHeight})))},[]);_t($,k,c==null?void 0:c.turns);const P=(c==null?void 0:c.matches)??[],D=P[h];l.useEffect(()=>{var n;if(c){if(D!==void 0){E.current=!1,(n=document.getElementById(`turn-${D}`))==null||n.scrollIntoView({block:"center"});return}E.current&&O()}},[D,c,O]),l.useEffect(()=>{c&&R&&(T.current=c.total)},[c,R]);const U=n=>{P.length>0&&x(v=>(v+n+P.length)%P.length)};return e.jsx(et,{open:!!s,onOpenChange:n=>!n&&u(),children:e.jsxs(tt,{side:"right",className:"w-[1100px] max-w-[95vw]","data-testid":"live-session-detail",children:[e.jsxs(st,{children:[e.jsx(at,{className:"normal-case tracking-normal text-sm pr-8",children:(i==null?void 0:i.name)??"Session"}),i&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-5 gap-y-1 font-body text-xs text-on-surface tabular-nums",children:[e.jsx("span",{className:"font-medium text-primary",children:i.agent}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${ae[i.status].dot}`}),ae[i.status].label]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"tokens "}),he(i)]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-on-surface-variant",children:"active "}),ne(i.last_activity_at)]}),e.jsx(ge,{session:i,linkTestId:"detail-open-task"}),e.jsx(pe,{session:i}),e.jsx("span",{className:"truncate max-w-full text-on-surface-variant",children:i.cwd})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[150px] flex-1",children:[e.jsx(Be,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-outline"}),e.jsx("input",{"data-testid":"transcript-search","aria-label":"Search this session",value:f,onChange:n=>{p(n.target.value),x(0)},placeholder:"Search this session",className:"w-full bg-background border border-control-border rounded-lg min-h-11 pl-7 pr-2 py-2 font-body text-xs text-on-surface"})]}),k&&e.jsx("span",{"data-testid":"transcript-match-count",className:"font-label text-xs font-medium text-outline",children:P.length===0?"no matches":`${h+1} / ${P.length}`}),e.jsx("button",{type:"button","aria-label":"Previous match",onClick:()=>U(-1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(nt,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Next match",onClick:()=>U(1),className:"min-h-11 min-w-11 p-2 text-outline hover:text-on-surface",children:e.jsx(rt,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button","data-testid":"transcript-refresh",onClick:()=>{E.current=!0,m()},className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface",children:[e.jsx(Ie,{className:`h-3 w-3 ${b?"animate-spin":""}`}),"Refresh"]})]}),c&&e.jsxs("div",{"data-testid":"transcript-status",className:"mt-2 font-body text-xs text-on-surface-variant tabular-nums",children:[c.total," turns",w?` · live, updated ${new Date(g).toLocaleTimeString()}`:""]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsx(it,{ref:A,onScroll:n=>{const v=n.currentTarget,q=v.scrollHeight-v.scrollTop-v.clientHeight<160;E.current=q,J(q)},children:L?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((n,v)=>e.jsx(ot,{className:"h-16 w-full bg-surface-highest"},v))}):o||!c?e.jsxs("div",{"data-testid":"transcript-unavailable",className:"font-body text-xs text-outline py-12 text-center",children:[o?`Could not load the conversation: ${o.message}`:"No conversation was recorded for this session.",e.jsx("p",{className:"mt-2",children:"Resume actions remain available when the native agent session exists."}),e.jsx("button",{type:"button",className:"mt-3 min-h-11 text-primary hover:underline",onClick:()=>m(),children:"Retry conversation"})]}):e.jsx("div",{ref:$,className:"space-y-3",children:c.turns.map(n=>{const v=P.includes(n.index),q=n.blocks.map((F,t)=>e.jsx(Lt,{block:F,matched:v},t));return e.jsxs("div",{id:`turn-${n.index}`,"data-testid":"transcript-turn","data-role":n.role,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px"},className:`border-b px-4 py-3 text-on-surface space-y-2 ${wt[n.role]} ${n.index===D?"ring-1 ring-primary":""}`,children:[e.jsxs("div",{className:"font-label text-xs font-medium text-outline",children:[n.role,n.time?` · ${ne(n.time)}`:""]}),n.role==="system"?e.jsxs("details",{open:v||void 0,children:[e.jsx("summary",{className:"cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface",children:"injected context"}),e.jsx("div",{className:"mt-2 space-y-2",children:q})]}):q]},n.index)})})}),c&&!R&&e.jsxs("button",{type:"button","data-testid":"jump-to-latest",onClick:()=>{E.current=!0,O()},className:"absolute bottom-4 right-6 inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 font-body text-xs text-primary shadow-lg hover:bg-surface-bright",children:[e.jsx(lt,{className:"h-3.5 w-3.5"}),"Jump to latest",c.total>T.current&&` · ${c.total-T.current} new`]})]})]})})}const Pt=["claude","codex","cursor","cursor-agent","gemini"],V=25,M="font-label text-xs font-medium text-outline";function Et({projectId:s}){var F;const d=dt("sm"),[u,f]=fe(),p=u.get("agent")??"",h=u.get("ended")!=="0",x=u.get("q")??"",r=u.get("order")==="asc"?"asc":"desc",i=u.get("session"),[w,k]=l.useState(x),[c,L]=l.useState({order:r,page:0}),b=c.order===r?c.page:0,o=l.useCallback(t=>L({order:r,page:t}),[r]),m=l.useCallback((t,N)=>{o(0),f(_=>{const C=new URLSearchParams(_);return N?C.set(t,N):C.delete(t),C},{replace:t==="q"})},[f,o]);l.useEffect(()=>k(x),[x]),l.useEffect(()=>{if(w===x)return;const t=setTimeout(()=>m("q",w.trim()||null),350);return()=>clearTimeout(t)},[w,x,m]);const g=x.trim().length>=2,A=He(!h),$=xt(g?x.trim():"",p),{data:E}=Ae(),T=ut(),R=new Map((E??[]).map(t=>[t.id,t.name])),J=g?((F=$.data)==null?void 0:F.hits)??[]:A.data??[],O=[...new Set([...Pt,...J.map(t=>t.agent)])],P=g?$.isLoading:A.isLoading,D=g?$:A,U=J.filter(t=>{var N;return(!p||t.agent===p)&&(h||t.status!=="stopped"||((N=t.handoff)==null?void 0:N.status)==="ready")}),n=U.filter(t=>s==="all"?!0:s==="unassigned"?t.project_id===null:t.project_id===s).sort((t,N)=>{const C=new Date(t.last_activity_at??t.created_at).getTime()-new Date(N.last_activity_at??N.created_at).getTime()||t.id.localeCompare(N.id);return r==="asc"?C:-C}),v=Math.min(b,Math.max(0,Math.ceil(n.length/V)-1))*V,q=s==="unassigned"?"unassigned":R.get(s)??s;return e.jsxs("section",{className:"mb-8","data-testid":"live-sessions",children:[e.jsx("p",{className:"mb-4 text-sm text-outline",children:"Discovered from your coding agents. Working sessions update automatically; waiting sessions remain available to resume."}),e.jsxs("div",{className:"mb-3 relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-outline"}),e.jsx("input",{"data-testid":"session-search","aria-label":"Search agent sessions",value:w,onChange:t=>k(t.target.value),placeholder:"Search agent sessions: titles, summaries and conversation text",className:"w-full bg-background border border-control-border rounded-lg pl-9 pr-3 py-2 font-body text-xs text-on-surface placeholder:text-outline"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("h2",{className:"font-label text-xs font-medium text-outline",children:[g?"Search results":"Agent sessions"," · ",n.length,n.length!==U.length&&e.jsxs("span",{"data-testid":"scope-hint",className:"normal-case tracking-normal",children:[" ","of ",U.length," · scope: ",q]}),g&&$.data&&e.jsxs("span",{"data-testid":"search-meta",className:"normal-case tracking-normal",children:[" ","· ",($.data.ms/1e3).toFixed(1),"s",$.data.rg?"":" · titles and summaries only (install ripgrep for content)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("select",{"aria-label":"Sort sessions by date","data-testid":"session-date-sort",value:r,onChange:t=>m("order",t.target.value==="asc"?"asc":null),className:"min-h-11 rounded-md border border-control-border bg-background px-3 text-sm text-on-surface",children:[e.jsx("option",{value:"desc",children:"Last active: newest first"}),e.jsx("option",{value:"asc",children:"Last active: oldest first"})]}),e.jsxs("select",{"data-testid":"agent-filter","aria-label":"Agent",className:"bg-background border border-control-border rounded-lg min-h-11 px-3 py-2 font-label text-xs font-medium text-on-surface",value:p,onChange:t=>m("agent",t.target.value||null),children:[e.jsx("option",{value:"",children:"all agents"}),O.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("label",{className:"flex items-center gap-2 font-label text-xs font-medium text-outline cursor-pointer",children:[e.jsx("input",{type:"checkbox","data-testid":"show-ended",checked:h,onChange:t=>m("ended",t.target.checked?"1":"0")}),"Show ended"]}),e.jsxs("button",{type:"button","data-testid":"sync-sessions",disabled:T.isPending,className:"min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface disabled:opacity-50",onClick:()=>T.mutate(),children:[e.jsx(Ie,{className:`h-3 w-3 ${T.isPending?"animate-spin":""}`}),T.isPending?"Syncing":"Refresh"]})]})]}),T.error&&e.jsx("p",{role:"alert",className:"mb-3 text-sm text-error",children:T.error.message}),D.error?e.jsx(Ue,{message:D.error.message,onRetry:()=>D.refetch()}):P?e.jsx("p",{role:"status",className:"py-8 text-sm text-outline",children:"Loading sessions…"}):n.length===0?e.jsx(mt,{message:g?"No sessions match":"No active agent sessions. Enable Show ended to browse previous conversations."}):e.jsxs("div",{className:"min-w-0 overflow-hidden",children:[d?e.jsxs(ht,{children:[e.jsx(pt,{children:e.jsxs(qe,{className:"border-b border-border hover:bg-transparent",children:[e.jsx(B,{className:`${M} w-40`,children:"Status"}),e.jsx(B,{className:`${M} w-20`,children:"Agent"}),e.jsx(B,{className:M,children:"Session"}),e.jsx(B,{className:`${M} w-28`,children:"Project"}),e.jsx(B,{className:`${M} w-20 text-right`,children:"Tokens"}),e.jsx(B,{className:`${M} w-36`,children:"Last active"}),e.jsx(B,{className:`${M} w-56`,children:"Task"}),e.jsx(B,{className:`${M} w-24`})]})}),e.jsx(gt,{children:n.slice(v,v+V).map(t=>{var _,C;const N=ae[t.status];return e.jsxs(qe,{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"border-b border-border/65 cursor-pointer hover:bg-surface-high",onClick:y=>{y.target.closest("button, a, input, [role='dialog']")||m("session",t.id)},children:[e.jsx(I,{className:"font-label text-xs text-on-surface",children:e.jsxs("span",{className:"inline-flex items-center gap-2","data-testid":"live-status",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${N.dot}`}),((_=t.handoff)==null?void 0:_.status)==="ready"?"Ready":N.label]})}),e.jsx(I,{className:"font-label text-xs font-medium text-primary",children:t.agent}),e.jsxs(I,{className:"max-w-md",children:[e.jsx("button",{type:"button",className:"block max-w-full text-left font-body text-sm font-medium text-on-surface truncate hover:text-primary",onClick:y=>{y.stopPropagation(),m("session",t.id)},children:e.jsx(W,{text:t.name??"Untitled session",query:g?x:""})}),t.summary&&t.summary!==t.name&&e.jsx("div",{className:"font-body text-xs text-outline truncate",title:t.summary,children:e.jsx(W,{text:t.summary,query:g?x:""})}),(C=t.snippets)==null?void 0:C.map(y=>e.jsx("div",{"data-testid":"search-snippet",className:"font-mono text-xs text-on-surface-variant truncate",title:y,children:e.jsx(W,{text:y,query:x})},y)),e.jsx("div",{className:"font-label text-xs text-outline truncate",title:t.cwd??void 0,children:t.cwd??""})]}),e.jsx(I,{className:"font-label text-xs text-outline",children:t.project_id&&R.get(t.project_id)||"—"}),e.jsx(I,{"data-testid":"live-tokens",className:"font-body text-xs text-on-surface-variant text-right",children:he(t)}),e.jsx(I,{className:"font-body text-xs text-on-surface-variant",children:ne(t.last_activity_at)}),e.jsx(I,{children:e.jsx(ge,{session:t})}),e.jsx(I,{className:"text-right",children:e.jsx("div",{className:"inline-flex items-center gap-3",children:e.jsx(pe,{session:t})})})]},t.id)})})]}):e.jsx("div",{className:"divide-y divide-border",children:n.slice(v,v+V).map(t=>{var N,_;return e.jsxs("article",{"data-testid":"live-session-row","data-session-id":t.session_id,"data-agent":t.agent,className:"py-4 space-y-3",children:[e.jsx("button",{type:"button",className:"text-left text-sm font-medium break-words hover:text-primary",onClick:()=>m("session",t.id),children:e.jsx(W,{text:t.name??"Untitled session",query:g?x:""})}),e.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-outline",children:[e.jsx("span",{className:"text-primary",children:t.agent}),e.jsx("span",{"data-testid":"live-status",children:((N=t.handoff)==null?void 0:N.status)==="ready"?"Ready":ae[t.status].label}),e.jsxs("span",{"data-testid":"live-tokens",children:[he(t)," tokens"]}),e.jsx("span",{children:ne(t.last_activity_at)})]}),t.summary&&e.jsx("p",{className:"text-sm text-outline break-words",children:e.jsx(W,{text:t.summary,query:g?x:""})}),(_=t.snippets)==null?void 0:_.map(C=>e.jsx("p",{"data-testid":"search-snippet",className:"text-xs break-words text-on-surface-variant",children:e.jsx(W,{text:C,query:x})},C)),e.jsxs("p",{className:"text-xs text-outline break-all",children:[t.project_id&&R.get(t.project_id)||"Unassigned",t.cwd?` · ${t.cwd}`:""]}),e.jsx(ge,{session:t}),e.jsx(pe,{session:t})]},t.id)})}),e.jsx(vt,{page:v/V,pageSize:V,total:n.length,onPage:o})]}),e.jsx($t,{sessionId:i,initialQuery:g?x.trim():"",onClose:()=>m("session",null)},i??"closed")]})}function Ut({projectId:s}){const d=bt(s);return e.jsxs("div",{children:[e.jsx(ft,{title:"Sessions"}),e.jsx(Et,{projectId:d},d),e.jsx(yt,{projectId:d},`archive-${d}`)]})}export{Ut as default};