H T T P / 1 . 1   2 0 0   O K 
 
 A c c e s s - C o n t r o l - A l l o w - O r i g i n :   * 
 
 A g e :   1 5 5 
 
 C a c h e - C o n t r o l :   p u b l i c ,   m a x - a g e = 3 0 0 
 
 C o n t e n t - L e n g t h :   3 1 1 5 4 7 
 
 C o n t e n t - T y p e :   t e x t / m a r k d o w n ;   c h a r s e t = u t f - 8 
 
 D a t e :   S a t ,   1 3   J u n   2 0 2 6   1 6 : 1 3 : 3 9   G M T 
 
 S e r v e r :   V e r c e l 
 
 S t r i c t - T r a n s p o r t - S e c u r i t y :   m a x - a g e = 6 3 0 7 2 0 0 0 ;   i n c l u d e S u b D o m a i n s ;   p r e l o a d 
 
 X - V e r c e l - C a c h e :   H I T 
 
 X - V e r c e l - I d :   b o m 1 : : i a d 1 : : b q 6 x 9 - 1 7 8 1 3 6 7 3 7 5 0 5 0 - 5 c 6 4 9 c 3 1 0 3 6 b 
 
 
 
 #   K r a i m i n d   C o d e b a s e   S h a r e       k r a i m i n d 
 
 
 
 G e n e r a t e d :   2 0 2 6 - 0 6 - 1 3   1 6 : 1 0   U T C           F i l e s :   5 3           S i z e :   2 9 9   K B 
 
 
 
 # #   H o w   t o   u s e   t h i s 
 
 P a s t e   t h i s   U R L   i n t o   C h a t G P T   ( w i t h   b r o w s i n g ) ,   C l a u d e . a i ,   G e m i n i ,   o r   a n y 
 
 w e b   A I   t h a t   c a n   f e t c h   U R L s .   T h e n   a s k   q u e s t i o n s   a b o u t   t h e   c o d e b a s e     
 
 t h e   A I   w i l l   r e a d   t h e   f i l e s   b e l o w   a n d   a n s w e r . 
 
 
 
 # #   F i l e   t r e e 
 
 
 
 ` ` ` 
 
     R E A D M E . m d 
 
 -   a p i 
 
         i n d e x . p y 
 
         r e q u i r e m e n t s . t x t 
 
 -   e x a m p l e s 
 
     -   s a m p l e - p y t h o n - p r o j e c t 
 
             p y p r o j e c t . t o m l 
 
         -   s r c 
 
                 a p p . p y 
 
     p y p r o j e c t . t o m l 
 
 -   s r c 
 
     -   k r a i m i n d 
 
             _ _ i n i t _ _ . p y 
 
         -   a i 
 
                 _ _ i n i t _ _ . p y 
 
                 c l o u d _ l l m . p y 
 
                 e x p l a i n e r . p y 
 
                 l o c a l _ l l m . p y 
 
             a l t e r n a t i v e s . p y 
 
             a r c h i t e c t . p y 
 
             a s y n c _ c l i e n t s . p y 
 
             b i s e c t . p y 
 
             c l i . p y 
 
             c o s t . p y 
 
         -   d e t e c t i o n 
 
                 _ _ i n i t _ _ . p y 
 
                 a s t _ s i g n a l s . p y 
 
                 c o n f i d e n c e . p y 
 
                 e n t r y _ p o i n t s . p y 
 
                 g i t _ s i g n a l s . p y 
 
                 s t r i n g _ s i g n a l s . p y 
 
             g i t h u b . p y 
 
             h a n d o f f . p y 
 
         -   m i g r a t e 
 
                 _ _ i n i t _ _ . p y 
 
                 a i _ r e w r i t e r . p y 
 
                 a s t _ r e w r i t e r . p y 
 
                 d i f f _ p r e v i e w . p y 
 
                 r e c i p e s . p y 
 
         -   p a r s e r 
 
                 _ _ i n i t _ _ . p y 
 
                 a s t _ s c a n n e r . p y 
 
                 l o c k f i l e . p y 
 
                 p a c k a g e _ j s o n . p y 
 
                 p y p r o j e c t . p y 
 
                 r e q u i r e m e n t s . p y 
 
             p y p i . p y 
 
         -   r e m o v e 
 
                 _ _ i n i t _ _ . p y 
 
                 e x e c u t o r . p y 
 
                 r o l l b a c k . p y 
 
                 s n a p s h o t . p y 
 
                 t e s t _ s e l e c t o r . p y 
 
                 t r a n s i t i v e . p y 
 
             r e p l . p y 
 
             s h a r e . p y 
 
             s u p p l y _ c h a i n . p y 
 
             t r u s t . p y 
 
         -   u t i l s 
 
                 _ _ i n i t _ _ . p y 
 
                 c a c h e . p y 
 
                 c o n f i g . p y 
 
                 f o r m a t t i n g . p y 
 
                 m a p p i n g s . p y 
 
 -   t e s t s 
 
         t e s t _ s h a r e . p y 
 
 ` ` ` 
 
 
 
 # #   F i l e s 
 
 
 
 # # #   ` R E A D M E . m d ` 
 
 
 
 ` ` ` m a r k d o w n 
 
 #   K r a i m i n d 
 
 
 
 * * b y   K r a i o n y x   A I * * 
 
 
 
 >   * * A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e   f o r   d e v e l o p e r s . * * 
 
 >   _ U n d e r s t a n d .   O p t i m i z e .   T r u s t . _ 
 
 
 
 K r a i m i n d   h e l p s   y o u   a u d i t ,   u n d e r s t a n d ,   a n d   o p t i m i z e   y o u r   P y t h o n   p r o j e c t ' s   d e p e n d e n c i e s   u s i n g   r u l e - b a s e d   i n t e l l i g e n c e ,   r e a l   C V E   d a t a ,   a n d   o p t i o n a l   A I   i n s i g h t s . 
 
 
 
 ` ` ` 
 
 E x i s t i n g   t o o l s   a s k :   " I s   t h i s   p a c k a g e   v u l n e r a b l e ? " 
 
 K r a i m i n d   a s k s : 
 
         S h o u l d   I   u s e   t h i s   p a c k a g e ? 
 
         I s   t h e r e   a   b e t t e r   a l t e r n a t i v e ? 
 
         W h i c h   d e p e n d e n c i e s   a r e   u n u s e d ? 
 
         W h i c h   p a c k a g e s   m i g h t   b e   a b a n d o n e d ? 
 
         W h a t   C V E s   a f f e c t   t h i s   v e r s i o n ? 
 
 ` ` ` 
 
 
 
 - - - 
 
 
 
 # #   W h a t   K r a i m i n d   D o e s   ( v 0 . 2 . 0 ) 
 
 
 
 |   F e a t u r e   |   D e s c r i p t i o n   | 
 
 | - - - - - - - - - | - - - - - - - - - - - - - | 
 
 |   a" c%  * * U n u s e d   d e p e n d e n c y   d e t e c t i o n * *   |   A S T - s c a n s   y o u r   c o d e ,   c o m p a r e s   t o   d e c l a r e d   d e p s ,   f i n d s   d e a d   w e i g h t   | 
 
 |   a"  )"U%   * * T r u s t   s c o r i n g   ( 0 - 1 0 0 ) * *   |   T r a n s p a r e n t ,   r u l e - b a s e d   s c o r e   f r o m   G i t H u b   +   P y P I   +   C V E   s i g n a l s   | 
 
 |   a"    * * R e a l   C V E   s c a n n i n g * *   |   L i v e   O S V . d e v   q u e r i e s       a c t u a l   v u l n e r a b i l i t i e s ,   n o t   h a n d - c u r a t e d   l i s t s   | 
 
 |   a"    * * M i g r a t i o n   a l t e r n a t i v e s * *   |   C u r a t e d   d a t a b a s e   o f   b e t t e r / m o d e r n   r e p l a c e m e n t s   ( e . g .   ` r e q u e s t s `       ` h t t p x ` )   | 
 
 |     )"U%   * * S i d e - b y - s i d e   c o m p a r i s o n * *   |   ` k r a i m i n d   c o m p a r e   r e q u e s t s   h t t p x `   | 
 
 |   a"    * * L o c k f i l e   s u p p o r t * *   |   p o e t r y . l o c k ,   P i p f i l e . l o c k ,   u v . l o c k   f o r   a c c u r a t e   a n a l y s i s   | 
 
 |       * * A s y n c   p a r a l l e l   f e t c h i n g * *   |   5 - 1 0 x   f a s t e r   t h a n   s e q u e n t i a l       1 0   c o n c u r r e n t   c o n n e c t i o n s   | 
 
 |   a"    * * J S O N   o u t p u t * *   |   ` - - f o r m a t   j s o n `   f o r   C I / C D   p i p e l i n e s   | 
 
 |   a"    * * O p t i o n a l   A I   i n s i g h t s * *   |   O p e n A I   /   G r o q   /   G e m i n i   /   l o c a l   O l l a m a       g r a c e f u l   f a l l b a c k   | 
 
 |   a" [%  * * 2 4 h   l o c a l   c a c h e * *   |   N e t w o r k - f r i e n d l y ,   i n s t a n t   r e p e a t   r u n s   | 
 
 
 
 - - - 
 
 
 
 # #   I n s t a l l a t i o n 
 
 
 
 ` ` ` b a s h 
 
 p i p   i n s t a l l   k r a i m i n d 
 
 ` ` ` 
 
 
 
 # # #   W i t h   o p t i o n a l   A I   s u p p o r t 
 
 
 
 ` ` ` b a s h 
 
 p i p   i n s t a l l   " k r a i m i n d [ a i ] " 
 
 ` ` ` 
 
 
 
 - - - 
 
 
 
 # #   Q u i c k   S t a r t 
 
 
 
 ` ` ` b a s h 
 
 #   V e r i f y   i n s t a l l a t i o n 
 
 k r a i m i n d   h e l l o 
 
 
 
 #   A n a l y z e   y o u r   p r o j e c t 
 
 k r a i m i n d   a n a l y z e 
 
 
 
 #   I n s p e c t   a   s p e c i f i c   p a c k a g e   ( w i t h   C V E s   +   a l t e r n a t i v e s ) 
 
 k r a i m i n d   e x p l a i n   r e q u e s t s 
 
 
 
 #   C o m p a r e   t w o   p a c k a g e s   s i d e - b y - s i d e 
 
 k r a i m i n d   c o m p a r e   r e q u e s t s   h t t p x 
 
 
 
 #   F u l l   h e a l t h   r e p o r t 
 
 k r a i m i n d   d o c t o r 
 
 
 
 #   C a c h e   m a n a g e m e n t 
 
 k r a i m i n d   c a c h e   i n f o 
 
 k r a i m i n d   c a c h e   c l e a r 
 
 ` ` ` 
 
 
 
 - - - 
 
 
 
 # #   C o m m a n d s 
 
 
 
 # # #   ` k r a i m i n d   a n a l y z e   [ P A T H ] ` 
 
 
 
 D e t e c t s   u n u s e d   d e p s ,   f e t c h e s   r e a l   C V E   d a t a ,   s u g g e s t s   m i g r a t i o n s . 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   a n a l y z e                                                         #   c u r r e n t   d i r 
 
 k r a i m i n d   a n a l y z e   . / m y - p r o j e c t                               #   s p e c i f i c   p a t h 
 
 k r a i m i n d   a n a l y z e   - - f o r m a t   j s o n                             #   C I - f r i e n d l y   o u t p u t 
 
 k r a i m i n d   a n a l y z e   - - c o n c u r r e n c y   2 0                       #   p a r a l l e l   A P I   c a l l s 
 
 k r a i m i n d   a n a l y z e   - - n o - a i                                         #   s k i p   A I   i n s i g h t s 
 
 ` ` ` 
 
 
 
 # # #   ` k r a i m i n d   e x p l a i n   < P A C K A G E > ` 
 
 
 
 D e t a i l e d   p a c k a g e   r e p o r t       t r u s t   s c o r e ,   G i t H u b   s t a t s ,   C V E s ,   a l t e r n a t i v e s ,   A I   i n s i g h t . 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   e x p l a i n   r e q u e s t s 
 
 k r a i m i n d   e x p l a i n   n o s e                                     #   s h o w s       d e p r e c a t e d   w a r n i n g 
 
 k r a i m i n d   e x p l a i n   t e n s o r f l o w   - - n o - a i 
 
 ` ` ` 
 
 
 
 # # #   ` k r a i m i n d   c o m p a r e   < P K G _ A >   < P K G _ B > ` 
 
 
 
 S i d e - b y - s i d e   c o m p a r i s o n :   t r u s t ,   s t a r s ,   l i c e n s e ,   s i z e ,   C V E   c o u n t s . 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   c o m p a r e   r e q u e s t s   h t t p x 
 
 k r a i m i n d   c o m p a r e   f l a s k   f a s t a p i 
 
 k r a i m i n d   c o m p a r e   a   b   - - f o r m a t   j s o n 
 
 ` ` ` 
 
 
 
 # # #   ` k r a i m i n d   d o c t o r   [ P A T H ] ` 
 
 
 
 A g g r e g a t e   h e a l t h   s u m m a r y :   t o t a l   d e p s ,   u n u s e d   c o u n t ,   a v e r a g e   t r u s t   s c o r e ,   r i s k   d i s t r i b u t i o n . 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   d o c t o r 
 
 k r a i m i n d   d o c t o r   . / a n o t h e r - p r o j e c t   - - f o r m a t   j s o n 
 
 ` ` ` 
 
 
 
 # # #   ` k r a i m i n d   c a c h e   < S U B C O M M A N D > ` 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   c a c h e   i n f o                     #   s h o w   e n t r i e s ,   s i z e ,   l o c a t i o n 
 
 k r a i m i n d   c a c h e   c l e a r                   #   d e l e t e   a l l   c a c h e d   r e s p o n s e s 
 
 k r a i m i n d   c a c h e   c l e a r   - - y e s       #   s k i p   c o n f i r m a t i o n 
 
 ` ` ` 
 
 
 
 # # #   ` k r a i m i n d   s h a r e   [ P A T H ] ` 
 
 
 
 O u t   o f   C l a u d e   C o d e   c r e d i t s   m i d - t a s k ?   B u n d l e   y o u r   c o d e b a s e   i n t o   a   s i n g l e   l i n k 
 
 a n y   b r o w s i n g - c a p a b l e   w e b   A I   c a n   r e a d       C l a u d e . a i ,   C h a t G P T   ( w i t h   b r o w s i n g ) , 
 
 G e m i n i ,   P e r p l e x i t y .   P a s t e   t h e   U R L ,   t h e n   k e e p   i t e r a t i n g   w i t h o u t   r e - e x p l a i n i n g 
 
 t h e   w h o l e   p r o j e c t . 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   s h a r e                                       #       p u b l i c   U R L ,   e x p i r e s   i n   2 4 h 
 
 k r a i m i n d   s h a r e   - - f u l l                         #   i n c l u d e   l o c k f i l e s ,   l a r g e r   b u n d l e 
 
 k r a i m i n d   s h a r e   - - f i l e                         #   w r i t e   k r a i m i n d - b u n d l e . m d   l o c a l l y   i n s t e a d 
 
 k r a i m i n d   s h a r e   - - t t l   1                       #   l i n k   e x p i r e s   i n   1   h o u r 
 
 ` ` ` 
 
 
 
 S m a r t   m o d e   ( d e f a u l t )   p a c k s   t h e   R E A D M E ,   m a n i f e s t s ,   e n t r y   p o i n t s ,   a n d   t h e   m o s t 
 
 r e c e n t l y - m o d i f i e d   s o u r c e   f i l e s   i n t o   a   ~ 1 5 0   K B   m a r k d o w n   b u n d l e   t h a t   f i t s   i n   a n y 
 
 A I ' s   f e t c h   l i m i t s . 
 
 
 
 * * A l w a y s   e x c l u d e d : * *   ` . e n v * `   ( e x c e p t   ` . e n v . e x a m p l e ` ) ,   ` * . k e y ` ,   ` * . p e m ` , 
 
 ` i d _ r s a * ` ,   a n y t h i n g   m a t c h i n g   ` * s e c r e t * ` / ` * c r e d e n t i a l * ` ,   p l u s   t h e   u s u a l 
 
 ` . v e n v / ` ,   ` n o d e _ m o d u l e s / ` ,   b u i l d   a r t i f a c t s .   A d d   a   ` . k r a i m i n d i g n o r e `   ( g i t i g n o r e 
 
 s y n t a x )   t o   e x c l u d e   m o r e . 
 
 
 
 I f   t h e   s h a r e   e n d p o i n t   i s   u n r e a c h a b l e   o r   r a t e - l i m i t e d ,   t h e   C L I   a u t o - f a l l s   b a c k 
 
 t o   w r i t i n g   t h e   b u n d l e   l o c a l l y   s o   y o u   a l w a y s   g e t   * s o m e t h i n g * . 
 
 
 
 - - - 
 
 
 
 # #   T r u s t   S c o r e   A l g o r i t h m 
 
 
 
 E v e r y   p a c k a g e   g e t s   a   t r a n s p a r e n t ,   a u d i t a b l e   0 - 1 0 0   t r u s t   s c o r e : 
 
 
 
 |   S i g n a l   |   I m p a c t   | 
 
 | - - - - - - - - | - - - - - - - - | 
 
 |   S t a r s   >   1 0 k   |   + 1 5   | 
 
 |   S t a r s   1 k - 1 0 k   |   + 1 5   | 
 
 |   S t a r s   1 0 0 - 1 k   |   + 1 0   | 
 
 |   S t a r s   <   5 0   |   - 1 0   | 
 
 |   L a s t   c o m m i t   <   9 0   d a y s   |   + 1 5   | 
 
 |   L a s t   c o m m i t   <   3 6 5   d a y s   |   + 5   | 
 
 |   L a s t   c o m m i t   >   3 6 5   d a y s   |   - 2 0   | 
 
 |   F o r k s   >   1 k   |   + 5   | 
 
 |   O p e n   i s s u e s   <   5 0   |   + 5   | 
 
 |   O p e n   i s s u e s   >   5 0 0   |   - 1 5   | 
 
 |   S e c u r i t y   p o l i c y   e n a b l e d   |   + 1 0   | 
 
 |   R e p o s i t o r y   a r c h i v e d   |   - 2 5   | 
 
 |   C r i t i c a l   C V E   |   - 2 5   | 
 
 |   H i g h - s e v e r i t y   C V E   |   - 1 5   | 
 
 |   M e d i u m - s e v e r i t y   C V E   |   - 8   | 
 
 |   L o w - s e v e r i t y   C V E   |   - 3   | 
 
 |   5 +   C V E s   |   e x t r a   - 5   | 
 
 |   P u b l i s h e d   o n   P y P I   |   + 5   | 
 
 
 
 # # #   S c o r e   l a b e l s 
 
 
 
 |   S c o r e   |   L a b e l   | 
 
 | - - - - - - - | - - - - - - - | 
 
 |   9 0 - 1 0 0   |   E x c e l l e n t   | 
 
 |   7 5 - 8 9   |   G o o d   | 
 
 |   6 0 - 7 4   |   A c c e p t a b l e   | 
 
 |   4 0 - 5 9   |   C a u t i o n   | 
 
 |   0 - 3 9   |   H i g h   R i s k   | 
 
 
 
 - - - 
 
 
 
 # #   M i g r a t i o n   A l t e r n a t i v e s 
 
 
 
 K r a i m i n d   s h i p s   w i t h   a   c u r a t e d   a l t e r n a t i v e s   d a t a b a s e .   E x a m p l e s : 
 
 
 
 |   P a c k a g e   |   S u g g e s t i o n   |   E f f o r t   | 
 
 | - - - - - - - - - | - - - - - - - - - - - - | - - - - - - - - | 
 
 |   ` n o s e `   |   p y t e s t   |   l o w   | 
 
 |   ` r e q u e s t s `   |   h t t p x   ( s y n c   +   a s y n c )   |   l o w   | 
 
 |   ` s i m p l e j s o n `   |   s t d l i b   j s o n   o r   o r j s o n   |   l o w   | 
 
 |   ` m o c k `   |   s t d l i b   u n i t t e s t . m o c k   |   l o w   | 
 
 |   ` t e n s o r f l o w `   |   p y t o r c h   /   j a x   |   h i g h   | 
 
 |   ` m a r s h m a l l o w `   |   p y d a n t i c   v 2   |   m e d i u m   | 
 
 |   ` a r g p a r s e `   |   t y p e r   /   c l i c k   |   m e d i u m   | 
 
 
 
 R u n   ` k r a i m i n d   e x p l a i n   < p k g > `   t o   s e e   f u l l   m i g r a t i o n   g u i d a n c e . 
 
 
 
 - - - 
 
 
 
 # #   A I   I n s i g h t s   ( O p t i o n a l ) 
 
 
 
 K r a i m i n d   w o r k s   g r e a t   w i t h o u t   a n y   A P I   k e y .   A I   i s   a   p r o g r e s s i v e   e n h a n c e m e n t . 
 
 
 
 # # #   L o c a l   A I   ( p r i v a t e ,   o f f l i n e   a f t e r   s e t u p ) 
 
 
 
 ` ` ` b a s h 
 
 o l l a m a   p u l l   l l a m a 3 . 2 
 
 e x p o r t   K R A I M I N D _ L O C A L _ A I = 1 
 
 k r a i m i n d   e x p l a i n   r e q u e s t s 
 
 ` ` ` 
 
 
 
 # # #   C l o u d   A I   ( a n y   o f   t h e s e ) 
 
 
 
 ` ` ` b a s h 
 
 e x p o r t   O P E N A I _ A P I _ K E Y = s k - p r o j - . . . 
 
 e x p o r t   G R O Q _ A P I _ K E Y = g s k _ . . . 
 
 e x p o r t   G E M I N I _ A P I _ K E Y = . . . 
 
 ` ` ` 
 
 
 
 K r a i m i n d   t r i e s   t h e m   i n   o r d e r :   l o c a l   O l l a m a       O p e n A I       G r o q       G e m i n i       r u l e - b a s e d   f a l l b a c k . 
 
 
 
 - - - 
 
 
 
 # #   J S O N   O u t p u t   ( C I / C D ) 
 
 
 
 ` ` ` b a s h 
 
 k r a i m i n d   a n a l y z e   - - f o r m a t   j s o n   |   j q   ' . s u m m a r y ' 
 
 #   { 
 
 #       " t o t a l _ d e p e n d e n c i e s " :   4 2 , 
 
 #       " u n u s e d _ c o u n t " :   3 , 
 
 #       " a v e r a g e _ t r u s t _ s c o r e " :   8 4 . 7 
 
 #   } 
 
 
 
 k r a i m i n d   d o c t o r   - - f o r m a t   j s o n   |   j q   ' . h e a l t h . t o t a l _ v u l n e r a b i l i t i e s ' 
 
 #   0 
 
 ` ` ` 
 
 
 
 P e r f e c t   f o r   f a i l i n g   C I   b u i l d s   w h e n   C V E   c o u n t s   s p i k e   o r   t r u s t   d r o p s . 
 
 
 
 - - - 
 
 
 
 # #   C a c h i n g 
 
 
 
 K r a i m i n d   c a c h e s   G i t H u b ,   P y P I ,   a n d   O S V . d e v   r e s p o n s e s   i n   ` ~ / . k r a i m i n d / c a c h e / ` : 
 
 -   2 4 h   T T L   f o r   G i t H u b / P y P I 
 
 -   1 2 h   T T L   f o r   O S V   ( s e c u r i t y   d a t a   r e f r e s h e s   f a s t e r ) 
 
 -   I n s p e c t   v i a   ` k r a i m i n d   c a c h e   i n f o ` 
 
 -   C l e a r   v i a   ` k r a i m i n d   c a c h e   c l e a r ` 
 
 
 
 - - - 
 
 
 
 # #   D e v e l o p m e n t 
 
 
 
 ` ` ` b a s h 
 
 g i t   c l o n e   h t t p s : / / g i t h u b . c o m / k r a i m i n d / k r a i m i n d 
 
 c d   k r a i m i n d 
 
 
 
 p y t h o n   - m   v e n v   . v e n v 
 
 . v e n v \ S c r i p t s \ a c t i v a t e         #   W i n d o w s 
 
 #   s o u r c e   . v e n v / b i n / a c t i v a t e       #   m a c O S / L i n u x 
 
 
 
 p i p   i n s t a l l   - e   " . [ a i , d e v ] " 
 
 
 
 p y t e s t   t e s t s /   - v                     #   8 4   t e s t s 
 
 k r a i m i n d   h e l l o 
 
 k r a i m i n d   a n a l y z e   e x a m p l e s / s a m p l e - p y t h o n - p r o j e c t 
 
 ` ` ` 
 
 
 
 # # #   A r c h i t e c t u r e 
 
 
 
 ` ` ` 
 
 s r c / k r a i m i n d / 
 
         c l i . p y                                   #   T y p e r   e n t r y p o i n t   ( h e l l o / a n a l y z e / e x p l a i n / c o m p a r e / d o c t o r / c a c h e ) 
 
         a s y n c _ c l i e n t s . p y               #   a s y n c i o . g a t h e r   p a r a l l e l   A P I   f e t c h e r 
 
         g i t h u b . p y                             #   s y n c   G i t H u b   c l i e n t   +   U R L   s l u g   e x t r a c t o r 
 
         p y p i . p y                                 #   s y n c   P y P I   c l i e n t 
 
         v u l n e r a b i l i t y . p y               #   O S V . d e v   C V E   s c a n n e r 
 
         a l t e r n a t i v e s . p y                 #   c u r a t e d   m i g r a t i o n   d a t a b a s e 
 
         t r u s t . p y                               #   0 - 1 0 0   r u l e - b a s e d   s c o r e r 
 
         p a r s e r / 
 
                 r e q u i r e m e n t s . p y         #   r e q u i r e m e n t s . t x t 
 
                 p y p r o j e c t . p y               #   P E P   6 2 1   +   P o e t r y 
 
                 p a c k a g e _ j s o n . p y         #   N o d e . j s 
 
                 l o c k f i l e . p y                 #   p o e t r y . l o c k ,   P i p f i l e . l o c k ,   u v . l o c k 
 
                 a s t _ s c a n n e r . p y           #   A S T   i m p o r t   s c a n n e r 
 
         a i / 
 
                 e x p l a i n e r . p y               #   p r o v i d e r   o r c h e s t r a t o r 
 
                 l o c a l _ l l m . p y               #   O l l a m a 
 
                 c l o u d _ l l m . p y               #   O p e n A I   /   G r o q   /   G e m i n i 
 
         u t i l s / 
 
                 c a c h e . p y                       #   f i l e s y s t e m   c a c h e 
 
                 f o r m a t t i n g . p y             #   R i c h   p a n e l s ,   t a b l e s ,   s c o r e   b a r s 
 
                 m a p p i n g s . p y                 #   i m p o r t       p a c k a g e   c a n o n i c a l   n a m e s 
 
 ` ` ` 
 
 
 
 - - - 
 
 
 
 # #   L i c e n s e 
 
 
 
 M I T       s e e   [ L I C E N S E ] ( L I C E N S E ) . 
 
 ` ` ` 
 
 
 
 # # #   ` a p i / i n d e x . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " K r a i m i n d   V e r c e l   p r o x y   +   s t a t u s   d a s h b o a r d . 
 
 
 
 E n d p o i n t s : 
 
     G E T     /                                     - >   H T M L   s t a t u s   d a s h b o a r d   f o r   d e v e l o p e r s 
 
     G E T     / a p i / s t a t u s                 - >   J S O N   h e a l t h   c h e c k   ( p i n g s   e a c h   p r o v i d e r ) 
 
     P O S T   / a p i                               - >   p r o x i e s   c h a t   c o m p l e t i o n s   ( G r o q       C e r e b r a s   f a l l b a c k ) 
 
     P O S T   / a p i / s h a r e                   - >   s t o r e s   a   c o d e b a s e   b u n d l e   i n   U p s t a s h 
 
     G E T     / a p i / s / < i d >                 - >   s e r v e s   t h e   s t o r e d   b u n d l e   a s   t e x t / m a r k d o w n 
 
 " " " 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   j s o n 
 
 i m p o r t   o s 
 
 i m p o r t   s e c r e t s 
 
 i m p o r t   t i m e 
 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e d e l t a ,   t i m e z o n e 
 
 f r o m   h t t p . s e r v e r   i m p o r t   B a s e H T T P R e q u e s t H a n d l e r 
 
 i m p o r t   s y s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 
 
 #   A d d   r o o t   s r c   d i r e c t o r y   t o   s y s . p a t h   s o   w e   c a n   i m p o r t   k r a i m i n d   o n   V e r c e l 
 
 r o o t _ d i r   =   P a t h ( _ _ f i l e _ _ ) . p a r e n t . p a r e n t 
 
 s y s . p a t h . a p p e n d ( s t r ( r o o t _ d i r   /   " s r c " ) ) 
 
 t r y : 
 
         f r o m   k r a i m i n d . s h a r e   i m p o r t   r e n d e r _ s h a r e _ p a g e 
 
 e x c e p t   I m p o r t E r r o r : 
 
         r e n d e r _ s h a r e _ p a g e   =   N o n e     #   f a l l b a c k   i f   n o t   f o u n d   i n   s o m e   e n v i r o n m e n t s 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 #         c o n s t a n t s                                                                                                                                       
 
 M A X _ B U N D L E _ B Y T E S   =   2   *   1 0 2 4   *   1 0 2 4 
 
 D E F A U L T _ T T L _ H O U R S   =   2 4 
 
 M A X _ T T L _ H O U R S   =   7 2 
 
 
 
 _ L O C A L _ S T O R E :   d i c t [ s t r ,   t u p l e [ s t r ,   d a t e t i m e ] ]   =   { } 
 
 
 
 #         U p s t a s h   h e l p e r s                                                                                                                           
 
 
 
 d e f   _ u p s t a s h _ c r e d s ( )   - >   t u p l e [ s t r   |   N o n e ,   s t r   |   N o n e ] : 
 
         r e t u r n   o s . g e t e n v ( " U P S T A S H _ R E D I S _ R E S T _ U R L " ) ,   o s . g e t e n v ( " U P S T A S H _ R E D I S _ R E S T _ T O K E N " ) 
 
 
 
 
 
 d e f   _ s h a r e _ s e t ( s h a r e _ i d :   s t r ,   c o n t e n t :   s t r ,   t t l _ s e c o n d s :   i n t )   - >   b o o l : 
 
         u r l ,   t o k e n   =   _ u p s t a s h _ c r e d s ( ) 
 
         i f   n o t   u r l   o r   n o t   t o k e n : 
 
                 i f   o s . g e t e n v ( " V E R C E L " )   = =   " 1 " : 
 
                         r e t u r n   F a l s e     #   D o   n o t   u s e   s t a t e l e s s   l o c a l   d i c t   o n   V e r c e l   p r o d u c t i o n 
 
                 _ L O C A L _ S T O R E [ s h a r e _ i d ]   =   ( c o n t e n t ,   d a t e t i m e . n o w ( t i m e z o n e . u t c )   +   t i m e d e l t a ( s e c o n d s = t t l _ s e c o n d s ) ) 
 
                 r e t u r n   T r u e 
 
         t r y : 
 
                 #   U p s t a s h   R E S T   A P I   e x p e c t s   c o m m a n d   a n d   a r g u m e n t s   i n   r e q u e s t   b o d y   a s   J S O N   a r r a y 
 
                 p a y l o a d   =   [ " S E T " ,   s h a r e _ i d ,   c o n t e n t ,   " E X " ,   s t r ( t t l _ s e c o n d s ) ] 
 
                 r e s p   =   h t t p x . p o s t ( 
 
                         u r l . r s t r i p ( " / " ) , 
 
                         j s o n = p a y l o a d , 
 
                         h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { t o k e n } " ,   " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                         t i m e o u t = 1 5 . 0 
 
                 ) 
 
                 r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                 r e t u r n   T r u e 
 
         e x c e p t   h t t p x . H T T P E r r o r : 
 
                 r e t u r n   F a l s e 
 
 
 
 
 
 d e f   _ s h a r e _ g e t ( s h a r e _ i d :   s t r )   - >   s t r   |   N o n e : 
 
         u r l ,   t o k e n   =   _ u p s t a s h _ c r e d s ( ) 
 
         i f   n o t   u r l   o r   n o t   t o k e n : 
 
                 e n t r y   =   _ L O C A L _ S T O R E . g e t ( s h a r e _ i d ) 
 
                 i f   n o t   e n t r y : 
 
                         r e t u r n   N o n e 
 
                 c o n t e n t ,   e x p i r e s   =   e n t r y 
 
                 i f   d a t e t i m e . n o w ( t i m e z o n e . u t c )   >   e x p i r e s : 
 
                         _ L O C A L _ S T O R E . p o p ( s h a r e _ i d ,   N o n e ) 
 
                         r e t u r n   N o n e 
 
                 r e t u r n   c o n t e n t 
 
         t r y : 
 
                 r e s p   =   h t t p x . g e t ( f " { u r l . r s t r i p ( ' / ' ) } / g e t / { s h a r e _ i d } " , 
 
                                                   h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { t o k e n } " } ,   t i m e o u t = 1 5 . 0 ) 
 
                 r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                 d a t a   =   r e s p . j s o n ( ) 
 
                 r e s u l t   =   d a t a . g e t ( " r e s u l t " ) 
 
                 r e t u r n   r e s u l t   i f   i s i n s t a n c e ( r e s u l t ,   s t r )   e l s e   N o n e 
 
         e x c e p t   ( h t t p x . H T T P E r r o r ,   V a l u e E r r o r ) : 
 
                 r e t u r n   N o n e 
 
 
 
 #         p r o v i d e r   h e a l t h   c h e c k s                                                                                                             
 
 
 
 d e f   _ p i n g _ p r o v i d e r ( u r l :   s t r ,   a p i _ k e y :   s t r ,   m o d e l :   s t r ,   t i m e o u t :   f l o a t   =   6 . 0 )   - >   d i c t : 
 
         t 0   =   t i m e . m o n o t o n i c ( ) 
 
         t r y : 
 
                 r e s p   =   h t t p x . p o s t ( u r l , 
 
                         h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " ,   " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                         j s o n = { " m o d e l " :   m o d e l ,   " m e s s a g e s " :   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   " h i " } ] ,   " m a x _ t o k e n s " :   1 } , 
 
                         t i m e o u t = t i m e o u t ) 
 
                 l a t e n c y   =   r o u n d ( ( t i m e . m o n o t o n i c ( )   -   t 0 )   *   1 0 0 0 ) 
 
                 i f   r e s p . s t a t u s _ c o d e   = =   2 0 0 : 
 
                         r e t u r n   { " s t a t u s " :   " u p " ,   " l a t e n c y _ m s " :   l a t e n c y ,   " h t t p " :   2 0 0 } 
 
                 r e t u r n   { " s t a t u s " :   " d o w n " ,   " l a t e n c y _ m s " :   l a t e n c y ,   " h t t p " :   r e s p . s t a t u s _ c o d e , 
 
                                 " e r r o r " :   r e s p . j s o n ( ) . g e t ( " e r r o r " ,   { } ) . g e t ( " m e s s a g e " ,   " " ) [ : 1 2 0 ]   i f   r e s p . c o n t e n t   e l s e   " " } 
 
         e x c e p t   h t t p x . T i m e o u t E x c e p t i o n : 
 
                 r e t u r n   { " s t a t u s " :   " d o w n " ,   " l a t e n c y _ m s " :   N o n e ,   " e r r o r " :   " t i m e o u t " } 
 
         e x c e p t   E x c e p t i o n   a s   e x c : 
 
                 r e t u r n   { " s t a t u s " :   " d o w n " ,   " l a t e n c y _ m s " :   N o n e ,   " e r r o r " :   s t r ( e x c ) [ : 1 2 0 ] } 
 
 
 
 
 
 d e f   _ c h e c k _ u p s t a s h ( )   - >   d i c t : 
 
         u r l ,   t o k e n   =   _ u p s t a s h _ c r e d s ( ) 
 
         i f   n o t   u r l   o r   n o t   t o k e n : 
 
                 r e t u r n   { " s t a t u s " :   " n o t _ c o n f i g u r e d " ,   " c o n f i g u r e d " :   F a l s e } 
 
         t 0   =   t i m e . m o n o t o n i c ( ) 
 
         t r y : 
 
                 r e s p   =   h t t p x . g e t ( f " { u r l . r s t r i p ( ' / ' ) } / p i n g " , 
 
                                                   h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { t o k e n } " } ,   t i m e o u t = 6 . 0 ) 
 
                 l a t e n c y   =   r o u n d ( ( t i m e . m o n o t o n i c ( )   -   t 0 )   *   1 0 0 0 ) 
 
                 i f   r e s p . s t a t u s _ c o d e   = =   2 0 0 : 
 
                         r e t u r n   { " s t a t u s " :   " u p " ,   " l a t e n c y _ m s " :   l a t e n c y ,   " c o n f i g u r e d " :   T r u e } 
 
                 r e t u r n   { " s t a t u s " :   " d o w n " ,   " l a t e n c y _ m s " :   l a t e n c y ,   " c o n f i g u r e d " :   T r u e } 
 
         e x c e p t   E x c e p t i o n   a s   e x c : 
 
                 r e t u r n   { " s t a t u s " :   " d o w n " ,   " e r r o r " :   s t r ( e x c ) [ : 8 0 ] ,   " c o n f i g u r e d " :   T r u e } 
 
 
 
 
 
 d e f   _ b u i l d _ s t a t u s ( )   - >   d i c t : 
 
         g r o q _ k e y   =   o s . g e t e n v ( " G R O Q _ A P I _ K E Y " ) 
 
         c e r e b r a s _ k e y   =   o s . g e t e n v ( " C E R E B R A S _ A P I _ K E Y " ) 
 
         o p e n a i _ k e y   =   o s . g e t e n v ( " O P E N A I _ A P I _ K E Y " ) 
 
 
 
         p r o v i d e r s :   d i c t   =   { } 
 
 
 
         i f   g r o q _ k e y : 
 
                 p r o v i d e r s [ " g r o q " ]   =   { 
 
                         " k e y _ c o n f i g u r e d " :   T r u e , 
 
                         " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                         * * _ p i n g _ p r o v i d e r ( " h t t p s : / / a p i . g r o q . c o m / o p e n a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                                           g r o q _ k e y ,   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " ) , 
 
                 } 
 
         e l s e : 
 
                 p r o v i d e r s [ " g r o q " ]   =   { " k e y _ c o n f i g u r e d " :   F a l s e ,   " s t a t u s " :   " n o _ k e y " ,   " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " } 
 
 
 
         i f   c e r e b r a s _ k e y : 
 
                 p r o v i d e r s [ " c e r e b r a s " ]   =   { 
 
                         " k e y _ c o n f i g u r e d " :   T r u e , 
 
                         " m o d e l " :   " l l a m a 3 . 1 - 8 b " , 
 
                         * * _ p i n g _ p r o v i d e r ( " h t t p s : / / a p i . c e r e b r a s . a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                                           c e r e b r a s _ k e y ,   " l l a m a 3 . 1 - 8 b " ) , 
 
                 } 
 
         e l s e : 
 
                 p r o v i d e r s [ " c e r e b r a s " ]   =   { " k e y _ c o n f i g u r e d " :   F a l s e ,   " s t a t u s " :   " n o _ k e y " ,   " m o d e l " :   " l l a m a 3 . 1 - 8 b " } 
 
 
 
         i f   o p e n a i _ k e y : 
 
                 p r o v i d e r s [ " o p e n a i " ]   =   { 
 
                         " k e y _ c o n f i g u r e d " :   T r u e , 
 
                         " m o d e l " :   " g p t - 4 o - m i n i " , 
 
                         * * _ p i n g _ p r o v i d e r ( " h t t p s : / / a p i . o p e n a i . c o m / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                                           o p e n a i _ k e y ,   " g p t - 4 o - m i n i " ) , 
 
                 } 
 
         e l s e : 
 
                 p r o v i d e r s [ " o p e n a i " ]   =   { " k e y _ c o n f i g u r e d " :   F a l s e ,   " s t a t u s " :   " n o _ k e y " ,   " m o d e l " :   " g p t - 4 o - m i n i " } 
 
 
 
         r e t u r n   { 
 
                 " t i m e s t a m p " :   d a t e t i m e . n o w ( t i m e z o n e . u t c ) . i s o f o r m a t ( ) , 
 
                 " p r o x y " :   { " s t a t u s " :   " o k " } , 
 
                 " p r o v i d e r s " :   p r o v i d e r s , 
 
                 " s t o r a g e " :   { " u p s t a s h " :   _ c h e c k _ u p s t a s h ( ) } , 
 
         } 
 
 
 
 #         s t a t u s   H T M L   d a s h b o a r d                                                                                                               
 
 
 
 _ S T A T U S _ H T M L   =   " " " < ! D O C T Y P E   h t m l > 
 
 < h t m l   l a n g = " e n " > 
 
 < h e a d > 
 
 < m e t a   c h a r s e t = " U T F - 8 " > 
 
 < m e t a   n a m e = " v i e w p o r t "   c o n t e n t = " w i d t h = d e v i c e - w i d t h , i n i t i a l - s c a l e = 1 " > 
 
 < t i t l e > K r a i m i n d   A P I   S t a t u s < / t i t l e > 
 
 < s t y l e > 
 
 * { b o x - s i z i n g : b o r d e r - b o x ; m a r g i n : 0 ; p a d d i n g : 0 } 
 
 b o d y { f o n t - f a m i l y : - a p p l e - s y s t e m , B l i n k M a c S y s t e m F o n t , ' S e g o e   U I ' , s a n s - s e r i f ; b a c k g r o u n d : # 0 a 0 a 0 a ; c o l o r : # e 0 e 0 e 0 ; m i n - h e i g h t : 1 0 0 v h } 
 
 . w r a p { m a x - w i d t h : 7 8 0 p x ; m a r g i n : 0   a u t o ; p a d d i n g : 4 0 p x   2 0 p x } 
 
 h e a d e r { m a r g i n - b o t t o m : 3 6 p x } 
 
 . l o g o { f o n t - s i z e : 2 2 p x ; f o n t - w e i g h t : 7 0 0 ; c o l o r : # 0 0 d 4 f f ; l e t t e r - s p a c i n g : 1 p x } 
 
 . s u b { f o n t - s i z e : 1 3 p x ; c o l o r : # 5 5 5 ; m a r g i n - t o p : 4 p x } 
 
 . c a r d { b a c k g r o u n d : # 1 4 1 4 1 4 ; b o r d e r : 1 p x   s o l i d   # 2 2 2 ; b o r d e r - r a d i u s : 1 0 p x ; p a d d i n g : 2 2 p x ; m a r g i n - b o t t o m : 1 4 p x } 
 
 . c a r d - t i t l e { f o n t - s i z e : 1 0 p x ; f o n t - w e i g h t : 7 0 0 ; l e t t e r - s p a c i n g : 2 p x ; t e x t - t r a n s f o r m : u p p e r c a s e ; c o l o r : # 5 5 5 ; m a r g i n - b o t t o m : 1 6 p x } 
 
 . r o w { d i s p l a y : f l e x ; a l i g n - i t e m s : c e n t e r ; j u s t i f y - c o n t e n t : s p a c e - b e t w e e n ; p a d d i n g : 1 1 p x   0 ; b o r d e r - b o t t o m : 1 p x   s o l i d   # 1 e 1 e 1 e } 
 
 . r o w : l a s t - c h i l d { b o r d e r - b o t t o m : n o n e } 
 
 . r l e f t { d i s p l a y : f l e x ; a l i g n - i t e m s : c e n t e r ; g a p : 1 2 p x } 
 
 . d o t { w i d t h : 8 p x ; h e i g h t : 8 p x ; b o r d e r - r a d i u s : 5 0 % ; f l e x - s h r i n k : 0 } 
 
 . d o t - u p { b a c k g r o u n d : # 2 2 c 5 5 e ; b o x - s h a d o w : 0   0   6 p x   # 2 2 c 5 5 e 8 8 } 
 
 . d o t - d o w n { b a c k g r o u n d : # e f 4 4 4 4 ; b o x - s h a d o w : 0   0   6 p x   # e f 4 4 4 4 8 8 } 
 
 . d o t - w a r n { b a c k g r o u n d : # e a b 3 0 8 ; b o x - s h a d o w : 0   0   6 p x   # e a b 3 0 8 8 8 } 
 
 . d o t - o f f { b a c k g r o u n d : # 3 3 3 } 
 
 . p n a m e { f o n t - s i z e : 1 4 p x ; f o n t - w e i g h t : 5 0 0 } 
 
 . p m o d e l { f o n t - s i z e : 1 1 p x ; c o l o r : # 5 5 5 ; m a r g i n - t o p : 2 p x } 
 
 . b a d g e { f o n t - s i z e : 1 1 p x ; f o n t - w e i g h t : 6 0 0 ; p a d d i n g : 2 p x   9 p x ; b o r d e r - r a d i u s : 2 0 p x ; w h i t e - s p a c e : n o w r a p } 
 
 . u p { b a c k g r o u n d : # 0 d 2 3 1 8 ; c o l o r : # 2 2 c 5 5 e ; b o r d e r : 1 p x   s o l i d   # 1 4 5 3 2 d } 
 
 . d o w n { b a c k g r o u n d : # 2 d 0 f 0 f ; c o l o r : # e f 4 4 4 4 ; b o r d e r : 1 p x   s o l i d   # 7 f 1 d 1 d } 
 
 . w a r n { b a c k g r o u n d : # 1 c 1 a 0 0 ; c o l o r : # e a b 3 0 8 ; b o r d e r : 1 p x   s o l i d   # 7 1 3 f 1 2 } 
 
 . o f f { b a c k g r o u n d : # 1 a 1 a 1 a ; c o l o r : # 5 5 5 ; b o r d e r : 1 p x   s o l i d   # 2 a 2 a 2 a } 
 
 . l a t { f o n t - s i z e : 1 1 p x ; c o l o r : # 4 4 4 ; m i n - w i d t h : 6 0 p x ; t e x t - a l i g n : r i g h t } 
 
 . s u m m a r y { d i s p l a y : f l e x ; g a p : 2 0 p x ; m a r g i n - b o t t o m : 1 4 p x } 
 
 . s c a r d { f l e x : 1 ; b a c k g r o u n d : # 1 4 1 4 1 4 ; b o r d e r : 1 p x   s o l i d   # 2 2 2 ; b o r d e r - r a d i u s : 1 0 p x ; p a d d i n g : 1 8 p x   2 2 p x } 
 
 . s l a b e l { f o n t - s i z e : 1 0 p x ; c o l o r : # 5 5 5 ; l e t t e r - s p a c i n g : 1 p x ; t e x t - t r a n s f o r m : u p p e r c a s e ; m a r g i n - b o t t o m : 6 p x } 
 
 . s v a l { f o n t - s i z e : 2 6 p x ; f o n t - w e i g h t : 7 0 0 } 
 
 . g r e e n { c o l o r : # 2 2 c 5 5 e } . y e l l o w { c o l o r : # e a b 3 0 8 } . r e d { c o l o r : # e f 4 4 4 4 } . g r e y { c o l o r : # 4 4 4 } 
 
 . t o p b a r { d i s p l a y : f l e x ; j u s t i f y - c o n t e n t : s p a c e - b e t w e e n ; a l i g n - i t e m s : c e n t e r ; m a r g i n - b o t t o m : 2 0 p x } 
 
 . t s { f o n t - s i z e : 1 2 p x ; c o l o r : # 4 4 4 } 
 
 . r b t n { f o n t - s i z e : 1 2 p x ; c o l o r : # 0 0 d 4 f f ; b a c k g r o u n d : n o n e ; b o r d e r : 1 p x   s o l i d   # 0 d 2 a 3 5 ; p a d d i n g : 4 p x   1 4 p x ; b o r d e r - r a d i u s : 6 p x ; c u r s o r : p o i n t e r } 
 
 . r b t n : h o v e r { b a c k g r o u n d : # 0 a 1 f 2 8 } 
 
 . f o o t e r { f o n t - s i z e : 1 1 p x ; c o l o r : # 3 3 3 ; t e x t - a l i g n : c e n t e r ; m a r g i n - t o p : 2 8 p x } 
 
 . f o o t e r   a { c o l o r : # 4 4 4 ; t e x t - d e c o r a t i o n : n o n e } 
 
 . e r r o r - m s g { f o n t - s i z e : 1 1 p x ; c o l o r : # 5 5 5 ; m a x - w i d t h : 2 6 0 p x ; t e x t - a l i g n : r i g h t ; o v e r f l o w : h i d d e n ; t e x t - o v e r f l o w : e l l i p s i s ; w h i t e - s p a c e : n o w r a p } 
 
 < / s t y l e > 
 
 < / h e a d > 
 
 < b o d y > 
 
 < d i v   c l a s s = " w r a p " > 
 
     < h e a d e r > 
 
         < d i v   c l a s s = " l o g o " > K R A I M I N D < / d i v > 
 
         < d i v   c l a s s = " s u b " > A P I   S t a t u s   D a s h b o a r d   & m d a s h ;   f o r   d e v e l o p e r s < / d i v > 
 
     < / h e a d e r > 
 
     < d i v   c l a s s = " t o p b a r " > 
 
         < s p a n   c l a s s = " t s "   i d = " t s " > C h e c k i n g & h e l l i p ; < / s p a n > 
 
         < b u t t o n   c l a s s = " r b t n "   o n c l i c k = " l o a d ( ) " >  W%  R e f r e s h < / b u t t o n > 
 
     < / d i v > 
 
     < d i v   c l a s s = " s u m m a r y " > 
 
         < d i v   c l a s s = " s c a r d " > < d i v   c l a s s = " s l a b e l " > P r o v i d e r s   U p < / d i v > < d i v   c l a s s = " s v a l   g r e y "   i d = " s u p " > & m d a s h ; < / d i v > < / d i v > 
 
         < d i v   c l a s s = " s c a r d " > < d i v   c l a s s = " s l a b e l " > P r o x y < / d i v > < d i v   c l a s s = " s v a l   g r e y "   i d = " s p r o x y " > & m d a s h ; < / d i v > < / d i v > 
 
         < d i v   c l a s s = " s c a r d " > < d i v   c l a s s = " s l a b e l " > S t o r a g e < / d i v > < d i v   c l a s s = " s v a l   g r e y "   i d = " s s t g " > & m d a s h ; < / d i v > < / d i v > 
 
     < / d i v > 
 
     < d i v   c l a s s = " c a r d " > 
 
         < d i v   c l a s s = " c a r d - t i t l e " > A I   P r o v i d e r s < / d i v > 
 
         < d i v   i d = " p r o v i d e r s " > < d i v   s t y l e = " c o l o r : # 4 4 4 ; f o n t - s i z e : 1 3 p x " > L o a d i n g & h e l l i p ; < / d i v > < / d i v > 
 
     < / d i v > 
 
     < d i v   c l a s s = " c a r d " > 
 
         < d i v   c l a s s = " c a r d - t i t l e " > I n f r a s t r u c t u r e < / d i v > 
 
         < d i v   i d = " i n f r a " > < d i v   s t y l e = " c o l o r : # 4 4 4 ; f o n t - s i z e : 1 3 p x " > L o a d i n g & h e l l i p ; < / d i v > < / d i v > 
 
     < / d i v > 
 
     < d i v   c l a s s = " f o o t e r " > K r a i m i n d   & m i d d o t ;   < a   h r e f = " h t t p s : / / g i t h u b . c o m / k r a i m i n d / k r a i m i n d " > G i t H u b < / a >   & m i d d o t ;   A u t o - r e f r e s h   6 0 s < / d i v > 
 
 < / d i v > 
 
 < s c r i p t > 
 
 f u n c t i o n   b a d g e ( p ) { 
 
     i f ( p . s t a t u s = = = ' u p ' )   r e t u r n   ' < s p a n   c l a s s = " b a d g e   u p " > U P < / s p a n > ' ; 
 
     i f ( p . s t a t u s = = = ' n o _ k e y ' )   r e t u r n   ' < s p a n   c l a s s = " b a d g e   w a r n " > N O   K E Y < / s p a n > ' ; 
 
     i f ( p . s t a t u s = = = ' n o t _ c o n f i g u r e d ' )   r e t u r n   ' < s p a n   c l a s s = " b a d g e   o f f " > N O T   S E T < / s p a n > ' ; 
 
     r e t u r n   ' < s p a n   c l a s s = " b a d g e   d o w n " > D O W N < / s p a n > ' ; 
 
 } 
 
 f u n c t i o n   d o t ( p ) { 
 
     i f ( p . s t a t u s = = = ' u p ' )   r e t u r n   ' d o t - u p ' ; 
 
     i f ( p . s t a t u s = = = ' n o _ k e y ' | | p . s t a t u s = = = ' n o t _ c o n f i g u r e d ' )   r e t u r n   ' d o t - w a r n ' ; 
 
     r e t u r n   ' d o t - d o w n ' ; 
 
 } 
 
 f u n c t i o n   l a t ( p ) {   r e t u r n   p . l a t e n c y _ m s   ?   p . l a t e n c y _ m s + ' m s '   :   ' ' ;   } 
 
 f u n c t i o n   e r r ( p ) {   r e t u r n   p . e r r o r   ?   ' < s p a n   c l a s s = " e r r o r - m s g "   t i t l e = " ' + p . e r r o r + ' " > ' + p . e r r o r + ' < / s p a n > '   :   ' ' ;   } 
 
 
 
 f u n c t i o n   r e n d e r P r o v i d e r s ( d a t a ) { 
 
     c o n s t   n a m e s = { g r o q : ' G r o q ' , c e r e b r a s : ' C e r e b r a s ' , o p e n a i : ' O p e n A I ' } ; 
 
     r e t u r n   O b j e c t . e n t r i e s ( d a t a . p r o v i d e r s ) . m a p ( ( [ k , p ] ) = > 
 
         ` < d i v   c l a s s = " r o w " > 
 
             < d i v   c l a s s = " r l e f t " > 
 
                 < d i v   c l a s s = " d o t   $ { d o t ( p ) } " > < / d i v > 
 
                 < d i v > < d i v   c l a s s = " p n a m e " > $ { n a m e s [ k ] | | k } < / d i v > < d i v   c l a s s = " p m o d e l " > $ { p . m o d e l | | ' ' } < / d i v > < / d i v > 
 
             < / d i v > 
 
             < d i v   s t y l e = " d i s p l a y : f l e x ; a l i g n - i t e m s : c e n t e r ; g a p : 1 2 p x " > 
 
                 $ { e r r ( p ) } 
 
                 < s p a n   c l a s s = " l a t " > $ { l a t ( p ) } < / s p a n > 
 
                 $ { b a d g e ( p ) } 
 
             < / d i v > 
 
         < / d i v > ` 
 
     ) . j o i n ( ' ' ) ; 
 
 } 
 
 
 
 f u n c t i o n   r e n d e r I n f r a ( d a t a ) { 
 
     c o n s t   u = d a t a . s t o r a g e . u p s t a s h ; 
 
     c o n s t   s t g B a d g e   =   u . s t a t u s = = = ' u p ' ? ' < s p a n   c l a s s = " b a d g e   u p " > U P < / s p a n > ' : 
 
                                       ! u . c o n f i g u r e d ? ' < s p a n   c l a s s = " b a d g e   o f f " > N O T   C O N F I G U R E D < / s p a n > ' : 
 
                                       ' < s p a n   c l a s s = " b a d g e   d o w n " > D O W N < / s p a n > ' ; 
 
     c o n s t   s t g D o t   =   u . s t a t u s = = = ' u p ' ? ' d o t - u p ' : ( ! u . c o n f i g u r e d ? ' d o t - o f f ' : ' d o t - d o w n ' ) ; 
 
     c o n s t   p r o x y = d a t a . p r o x y ; 
 
     r e t u r n   ` 
 
         < d i v   c l a s s = " r o w " > 
 
             < d i v   c l a s s = " r l e f t " > < d i v   c l a s s = " d o t   d o t - u p " > < / d i v > < d i v > < d i v   c l a s s = " p n a m e " > P r o x y < / d i v > < d i v   c l a s s = " p m o d e l " > P O S T   / a p i < / d i v > < / d i v > < / d i v > 
 
             < d i v > < s p a n   c l a s s = " b a d g e   u p " > O K < / s p a n > < / d i v > 
 
         < / d i v > 
 
         < d i v   c l a s s = " r o w " > 
 
             < d i v   c l a s s = " r l e f t " > < d i v   c l a s s = " d o t   $ { s t g D o t } " > < / d i v > < d i v > < d i v   c l a s s = " p n a m e " > U p s t a s h   ( S h a r e   S t o r a g e ) < / d i v > < d i v   c l a s s = " p m o d e l " > K V   /   R e d i s < / d i v > < / d i v > < / d i v > 
 
             < d i v   s t y l e = " d i s p l a y : f l e x ; a l i g n - i t e m s : c e n t e r ; g a p : 1 2 p x " > < s p a n   c l a s s = " l a t " > $ { u . l a t e n c y _ m s ? u . l a t e n c y _ m s + ' m s ' : ' ' } < / s p a n > $ { s t g B a d g e } < / d i v > 
 
         < / d i v > ` ; 
 
 } 
 
 
 
 f u n c t i o n   s u m m a r i z e ( d a t a ) { 
 
     c o n s t   p s = O b j e c t . v a l u e s ( d a t a . p r o v i d e r s ) ; 
 
     c o n s t   u p = p s . f i l t e r ( p = > p . s t a t u s = = = ' u p ' ) . l e n g t h ; 
 
     c o n s t   t o t a l = p s . f i l t e r ( p = > p . k e y _ c o n f i g u r e d ) . l e n g t h ; 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' s u p ' ) . t e x t C o n t e n t = t o t a l ? u p + ' / ' + t o t a l : ' 0 ' ; 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' s u p ' ) . c l a s s N a m e = ' s v a l   ' + ( u p > 0 ? ' g r e e n ' : ( t o t a l ? ' r e d ' : ' g r e y ' ) ) ; 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' s p r o x y ' ) . t e x t C o n t e n t = ' O K ' ; 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' s p r o x y ' ) . c l a s s N a m e = ' s v a l   g r e e n ' ; 
 
     c o n s t   u = d a t a . s t o r a g e . u p s t a s h ; 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' s s t g ' ) . t e x t C o n t e n t = u . s t a t u s = = = ' u p ' ? ' U P ' : ( ! u . c o n f i g u r e d ? '   ' : ' D O W N ' ) ; 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' s s t g ' ) . c l a s s N a m e = ' s v a l   ' + ( u . s t a t u s = = = ' u p ' ? ' g r e e n ' : ( ! u . c o n f i g u r e d ? ' g r e y ' : ' r e d ' ) ) ; 
 
 } 
 
 
 
 a s y n c   f u n c t i o n   l o a d ( ) { 
 
     d o c u m e n t . g e t E l e m e n t B y I d ( ' t s ' ) . t e x t C o n t e n t = ' C h e c k i n g   ' ; 
 
     t r y { 
 
         c o n s t   r = a w a i t   f e t c h ( ' / a p i / s t a t u s ' ) ; 
 
         c o n s t   d = a w a i t   r . j s o n ( ) ; 
 
         d o c u m e n t . g e t E l e m e n t B y I d ( ' p r o v i d e r s ' ) . i n n e r H T M L = r e n d e r P r o v i d e r s ( d ) ; 
 
         d o c u m e n t . g e t E l e m e n t B y I d ( ' i n f r a ' ) . i n n e r H T M L = r e n d e r I n f r a ( d ) ; 
 
         s u m m a r i z e ( d ) ; 
 
         c o n s t   t = n e w   D a t e ( d . t i m e s t a m p ) ; 
 
         d o c u m e n t . g e t E l e m e n t B y I d ( ' t s ' ) . t e x t C o n t e n t = ' L a s t   c h e c k e d :   ' + t . t o L o c a l e T i m e S t r i n g ( ) ; 
 
     } c a t c h ( e ) { 
 
         d o c u m e n t . g e t E l e m e n t B y I d ( ' t s ' ) . t e x t C o n t e n t = ' E r r o r   f e t c h i n g   s t a t u s ' ; 
 
     } 
 
 } 
 
 l o a d ( ) ; 
 
 s e t I n t e r v a l ( l o a d , 6 0 0 0 0 ) ; 
 
 < / s c r i p t > 
 
 < / b o d y > 
 
 < / h t m l > " " " 
 
 
 
 #         H T T P   h a n d l e r                                                                                                                                 
 
 
 
 c l a s s   h a n d l e r ( B a s e H T T P R e q u e s t H a n d l e r ) : 
 
 
 
         d e f   l o g _ m e s s a g e ( s e l f ,   f m t :   s t r ,   * a r g s :   o b j e c t )   - >   N o n e :     #   n o q a :   N 8 0 2 
 
                 p a s s     #   s u p p r e s s   d e f a u l t   a c c e s s   l o g   n o i s e 
 
 
 
         #         h e l p e r s                                                                                                                           
 
         d e f   _ j s o n ( s e l f ,   s t a t u s :   i n t ,   p a y l o a d :   d i c t )   - >   N o n e : 
 
                 b o d y   =   j s o n . d u m p s ( p a y l o a d ) . e n c o d e ( " u t f - 8 " ) 
 
                 s e l f . s e n d _ r e s p o n s e ( s t a t u s ) 
 
                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - T y p e " ,   " a p p l i c a t i o n / j s o n " ) 
 
                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - O r i g i n " ,   " * " ) 
 
                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - L e n g t h " ,   s t r ( l e n ( b o d y ) ) ) 
 
                 s e l f . e n d _ h e a d e r s ( ) 
 
                 s e l f . w f i l e . w r i t e ( b o d y ) 
 
 
 
         d e f   _ h t m l ( s e l f ,   s t a t u s :   i n t ,   h t m l :   s t r )   - >   N o n e : 
 
                 b o d y   =   h t m l . e n c o d e ( " u t f - 8 " ) 
 
                 s e l f . s e n d _ r e s p o n s e ( s t a t u s ) 
 
                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - T y p e " ,   " t e x t / h t m l ;   c h a r s e t = u t f - 8 " ) 
 
                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - L e n g t h " ,   s t r ( l e n ( b o d y ) ) ) 
 
                 s e l f . e n d _ h e a d e r s ( ) 
 
                 s e l f . w f i l e . w r i t e ( b o d y ) 
 
 
 
         d e f   _ m a r k d o w n ( s e l f ,   s t a t u s :   i n t ,   t e x t :   s t r )   - >   N o n e : 
 
                 b o d y   =   t e x t . e n c o d e ( " u t f - 8 " ) 
 
                 s e l f . s e n d _ r e s p o n s e ( s t a t u s ) 
 
                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - T y p e " ,   " t e x t / m a r k d o w n ;   c h a r s e t = u t f - 8 " ) 
 
                 s e l f . s e n d _ h e a d e r ( " C a c h e - C o n t r o l " ,   " p u b l i c ,   m a x - a g e = 3 0 0 " ) 
 
                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - O r i g i n " ,   " * " ) 
 
                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - L e n g t h " ,   s t r ( l e n ( b o d y ) ) ) 
 
                 s e l f . e n d _ h e a d e r s ( ) 
 
                 s e l f . w f i l e . w r i t e ( b o d y ) 
 
 
 
         d e f   _ r e a d _ b o d y ( s e l f )   - >   b y t e s : 
 
                 l e n g t h   =   i n t ( s e l f . h e a d e r s . g e t ( " C o n t e n t - L e n g t h " ,   0 ) ) 
 
                 r e t u r n   s e l f . r f i l e . r e a d ( l e n g t h )   i f   l e n g t h   >   0   e l s e   b " " 
 
 
 
         #         d i s p a t c h                                                                                                                         
 
         d e f   d o _ G E T ( s e l f )   - >   N o n e :     #   n o q a :   N 8 0 2 
 
                 p a t h   =   s e l f . p a t h . s p l i t ( " ? " ,   1 ) [ 0 ] 
 
                 i f   p a t h   i n   ( " / " ,   " / s t a t u s " ) : 
 
                         r e t u r n   s e l f . _ h t m l ( 2 0 0 ,   _ S T A T U S _ H T M L ) 
 
                 i f   p a t h   = =   " / a p i / s t a t u s " : 
 
                         r e t u r n   s e l f . _ j s o n ( 2 0 0 ,   _ b u i l d _ s t a t u s ( ) ) 
 
                 i f   p a t h . s t a r t s w i t h ( " / a p i / s / " ) : 
 
                         s h a r e _ i d   =   p a t h [ l e n ( " / a p i / s / " ) : ] . s t r i p ( " / " ) 
 
                         r e t u r n   s e l f . _ h a n d l e _ s h a r e _ g e t ( s h a r e _ i d ) 
 
                 i f   p a t h   i n   ( " / a p i " ,   " / a p i / " ) : 
 
                         r e t u r n   s e l f . _ j s o n ( 2 0 0 ,   { " s e r v i c e " :   " k r a i m i n d - p r o x y " ,   " o k " :   T r u e } ) 
 
                 s e l f . s e n d _ r e s p o n s e ( 4 0 4 ) 
 
                 s e l f . e n d _ h e a d e r s ( ) 
 
 
 
         d e f   d o _ P O S T ( s e l f )   - >   N o n e :     #   n o q a :   N 8 0 2 
 
                 p a t h   =   s e l f . p a t h . s p l i t ( " ? " ,   1 ) [ 0 ] 
 
                 i f   p a t h . s t a r t s w i t h ( " / a p i / s h a r e " ) : 
 
                         r e t u r n   s e l f . _ h a n d l e _ s h a r e _ c r e a t e ( ) 
 
                 r e t u r n   s e l f . _ h a n d l e _ c h a t _ p r o x y ( ) 
 
 
 
         d e f   d o _ O P T I O N S ( s e l f )   - >   N o n e :     #   n o q a :   N 8 0 2 
 
                 s e l f . s e n d _ r e s p o n s e ( 2 0 0 ) 
 
                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - O r i g i n " ,   " * " ) 
 
                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - M e t h o d s " ,   " G E T ,   P O S T ,   O P T I O N S " ) 
 
                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - H e a d e r s " ,   " C o n t e n t - T y p e " ) 
 
                 s e l f . e n d _ h e a d e r s ( ) 
 
 
 
         #         s h a r e   e n d p o i n t s                                                                                                           
 
         d e f   _ h a n d l e _ s h a r e _ c r e a t e ( s e l f )   - >   N o n e : 
 
                 r a w   =   s e l f . _ r e a d _ b o d y ( ) 
 
                 i f   l e n ( r a w )   >   M A X _ B U N D L E _ B Y T E S   +   4 0 9 6 : 
 
                         r e t u r n   s e l f . _ j s o n ( 4 1 3 ,   { " e r r o r " :   " b u n d l e   t o o   l a r g e " ,   " m a x _ b y t e s " :   M A X _ B U N D L E _ B Y T E S } ) 
 
                 t r y : 
 
                         b o d y   =   j s o n . l o a d s ( r a w ) 
 
                 e x c e p t   j s o n . J S O N D e c o d e E r r o r : 
 
                         r e t u r n   s e l f . _ j s o n ( 4 0 0 ,   { " e r r o r " :   " i n v a l i d   J S O N " } ) 
 
 
 
                 c o n t e n t   =   b o d y . g e t ( " c o n t e n t " ) 
 
                 i f   n o t   i s i n s t a n c e ( c o n t e n t ,   s t r )   o r   n o t   c o n t e n t : 
 
                         r e t u r n   s e l f . _ j s o n ( 4 0 0 ,   { " e r r o r " :   " m i s s i n g   ' c o n t e n t ' " } ) 
 
                 i f   l e n ( c o n t e n t . e n c o d e ( " u t f - 8 " ) )   >   M A X _ B U N D L E _ B Y T E S : 
 
                         r e t u r n   s e l f . _ j s o n ( 4 1 3 ,   { " e r r o r " :   " b u n d l e   t o o   l a r g e " ,   " m a x _ b y t e s " :   M A X _ B U N D L E _ B Y T E S } ) 
 
 
 
                 t r y : 
 
                         t t l _ h o u r s   =   m a x ( 1 ,   m i n ( i n t ( b o d y . g e t ( " t t l _ h o u r s " ,   D E F A U L T _ T T L _ H O U R S ) ) ,   M A X _ T T L _ H O U R S ) ) 
 
                 e x c e p t   ( T y p e E r r o r ,   V a l u e E r r o r ) : 
 
                         t t l _ h o u r s   =   D E F A U L T _ T T L _ H O U R S 
 
 
 
                 s h a r e _ i d   =   s e c r e t s . t o k e n _ u r l s a f e ( 1 6 ) 
 
                 i f   n o t   _ s h a r e _ s e t ( s h a r e _ i d ,   c o n t e n t ,   t t l _ h o u r s   *   3 6 0 0 ) : 
 
                         r e t u r n   s e l f . _ j s o n ( 5 0 3 ,   { " e r r o r " :   " s t o r a g e   u n a v a i l a b l e ,   r e t r y   l a t e r " } ) 
 
 
 
                 h o s t   =   s e l f . h e a d e r s . g e t ( " H o s t " )   o r   " k r a i m i n d o f f i c i a l 1 . v e r c e l . a p p " 
 
                 s c h e m e   =   " h t t p "   i f   h o s t . s t a r t s w i t h ( " l o c a l h o s t " )   e l s e   " h t t p s " 
 
                 e x p i r e s _ a t   =   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   +   t i m e d e l t a ( h o u r s = t t l _ h o u r s ) ) . i s o f o r m a t ( ) 
 
                 s e l f . _ j s o n ( 2 0 0 ,   { " u r l " :   f " { s c h e m e } : / / { h o s t } / a p i / s / { s h a r e _ i d } " , 
 
                                                   " i d " :   s h a r e _ i d ,   " e x p i r e s _ a t " :   e x p i r e s _ a t } ) 
 
 
 
         d e f   _ h a n d l e _ s h a r e _ g e t ( s e l f ,   s h a r e _ i d :   s t r )   - >   N o n e : 
 
                 i f   n o t   s h a r e _ i d   o r   " / "   i n   s h a r e _ i d : 
 
                         r e t u r n   s e l f . _ m a r k d o w n ( 4 0 4 ,   " #   S h a r e   n o t   f o u n d \ n \ n I n v a l i d   s h a r e   i d . \ n " ) 
 
                 c o n t e n t   =   _ s h a r e _ g e t ( s h a r e _ i d ) 
 
                 i f   c o n t e n t   i s   N o n e : 
 
                         r e t u r n   s e l f . _ m a r k d o w n ( 4 0 4 , 
 
                                 " #   K r a i m i n d   s h a r e   e x p i r e d \ n \ n " 
 
                                 " T h i s   c o d e b a s e   s h a r e   h a s   e x p i r e d   o r   n e v e r   e x i s t e d . \ n " 
 
                                 " A s k   t h e   d e v e l o p e r   t o   r u n   ` k r a i m i n d   s h a r e `   a g a i n . \ n " ) 
 
                 
 
                 #   C h e c k   i f   t h e   c l i e n t   r e q u e s t e d   t h e   r a w   m a r k d o w n   o r   i s   a n   A I / C L I   b o t 
 
                 u s e r _ a g e n t   =   s e l f . h e a d e r s . g e t ( " U s e r - A g e n t " ,   " " ) . l o w e r ( ) 
 
                 a i _ b o t s   =   [ " c h a t g p t " ,   " g p t b o t " ,   " o a i - s e a r c h b o t " ,   " c l a u d e " ,   " a n t h r o p i c " ,   " g o o g l e " ,   " b o t " ] 
 
                 c l i _ t o o l s   =   [ " c u r l " ,   " w g e t " ,   " h t t p i e " ,   " h t t p x " ,   " p y t h o n " ,   " u r l l i b " ] 
 
                 i s _ b o t   =   a n y ( x   i n   u s e r _ a g e n t   f o r   x   i n   a i _ b o t s   +   c l i _ t o o l s ) 
 
                 i s _ r a w   =   " r a w = 1 "   i n   s e l f . p a t h   o r   " r a w = t r u e "   i n   s e l f . p a t h   o r   i s _ b o t 
 
                 
 
                 i f   i s _ r a w   o r   r e n d e r _ s h a r e _ p a g e   i s   N o n e : 
 
                         s e l f . _ m a r k d o w n ( 2 0 0 ,   c o n t e n t ) 
 
                 e l s e : 
 
                         #   E x t r a c t   p r o j e c t   n a m e   f r o m   t h e   b u n d l e   t i t l e 
 
                         p r o j e c t _ n a m e   =   " C o d e b a s e " 
 
                         f o r   l i n e   i n   c o n t e n t . s p l i t l i n e s ( ) : 
 
                                 i f   l i n e . s t a r t s w i t h ( " #   K r a i m i n d   C o d e b a s e   S h a r e       " ) : 
 
                                         p r o j e c t _ n a m e   =   l i n e [ l e n ( " #   K r a i m i n d   C o d e b a s e   S h a r e       " ) : ] . s t r i p ( ) 
 
                                         b r e a k 
 
                         h t m l _ c o n t e n t   =   r e n d e r _ s h a r e _ p a g e ( c o n t e n t ,   p r o j e c t _ n a m e ) 
 
                         s e l f . _ h t m l ( 2 0 0 ,   h t m l _ c o n t e n t ) 
 
 
 
         #         c h a t   p r o x y                                                                                                                   
 
         d e f   _ h a n d l e _ c h a t _ p r o x y ( s e l f )   - >   N o n e : 
 
                 r a w   =   s e l f . _ r e a d _ b o d y ( ) 
 
                 t r y : 
 
                         b o d y   =   j s o n . l o a d s ( r a w ) 
 
                 e x c e p t   j s o n . J S O N D e c o d e E r r o r : 
 
                         r e t u r n   s e l f . _ j s o n ( 4 0 0 ,   { " e r r o r " :   " I n v a l i d   J S O N " } ) 
 
 
 
                 i f   " m o d e l "   n o t   i n   b o d y : 
 
                         b o d y [ " m o d e l " ]   =   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " 
 
 
 
                 #   T r y   G r o q   f i r s t ,   f a l l   b a c k   t o   C e r e b r a s 
 
                 g r o q _ k e y   =   o s . g e t e n v ( " G R O Q _ A P I _ K E Y " ) 
 
                 c e r e b r a s _ k e y   =   o s . g e t e n v ( " C E R E B R A S _ A P I _ K E Y " ) 
 
 
 
                 i f   g r o q _ k e y : 
 
                         t r y : 
 
                                 r e s p   =   h t t p x . p o s t ( " h t t p s : / / a p i . g r o q . c o m / o p e n a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                         j s o n = b o d y , 
 
                                         h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { g r o q _ k e y } " ,   " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                                         t i m e o u t = 3 0 . 0 ) 
 
                                 r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                                 s e l f . s e n d _ r e s p o n s e ( 2 0 0 ) 
 
                                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - T y p e " ,   " a p p l i c a t i o n / j s o n " ) 
 
                                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - O r i g i n " ,   " * " ) 
 
                                 s e l f . e n d _ h e a d e r s ( ) 
 
                                 s e l f . w f i l e . w r i t e ( r e s p . c o n t e n t ) 
 
                                 r e t u r n 
 
                         e x c e p t   h t t p x . H T T P E r r o r : 
 
                                 p a s s     #   f a l l   t h r o u g h   t o   C e r e b r a s 
 
 
 
                 i f   c e r e b r a s _ k e y : 
 
                         c e r e b r a s _ b o d y   =   d i c t ( b o d y ) 
 
                         c e r e b r a s _ b o d y [ " m o d e l " ]   =   " l l a m a 3 . 1 - 8 b " 
 
                         t r y : 
 
                                 r e s p   =   h t t p x . p o s t ( " h t t p s : / / a p i . c e r e b r a s . a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                         j s o n = c e r e b r a s _ b o d y , 
 
                                         h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { c e r e b r a s _ k e y } " ,   " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                                         t i m e o u t = 3 0 . 0 ) 
 
                                 r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                                 s e l f . s e n d _ r e s p o n s e ( 2 0 0 ) 
 
                                 s e l f . s e n d _ h e a d e r ( " C o n t e n t - T y p e " ,   " a p p l i c a t i o n / j s o n " ) 
 
                                 s e l f . s e n d _ h e a d e r ( " A c c e s s - C o n t r o l - A l l o w - O r i g i n " ,   " * " ) 
 
                                 s e l f . e n d _ h e a d e r s ( ) 
 
                                 s e l f . w f i l e . w r i t e ( r e s p . c o n t e n t ) 
 
                                 r e t u r n 
 
                         e x c e p t   h t t p x . H T T P E r r o r : 
 
                                 p a s s 
 
 
 
                 s e l f . _ j s o n ( 5 0 3 ,   { " e r r o r " :   " N o   A I   p r o v i d e r   a v a i l a b l e .   S e t   G R O Q _ A P I _ K E Y   o r   C E R E B R A S _ A P I _ K E Y   o n   V e r c e l . " } ) 
 
 
 
 
 
 i f   _ _ n a m e _ _   = =   " _ _ m a i n _ _ " : 
 
         f r o m   h t t p . s e r v e r   i m p o r t   H T T P S e r v e r 
 
         p o r t   =   i n t ( o s . g e t e n v ( " P O R T " ,   " 8 0 0 0 " ) ) 
 
         s e r v e r   =   H T T P S e r v e r ( ( " l o c a l h o s t " ,   p o r t ) ,   h a n d l e r ) 
 
         p r i n t ( f " K r a i m i n d   p r o x y   r u n n i n g   o n   h t t p : / / l o c a l h o s t : { p o r t } " ) 
 
         p r i n t ( "     G E T     /                             s t a t u s   d a s h b o a r d " ) 
 
         p r i n t ( "     G E T     / a p i / s t a t u s         J S O N   h e a l t h   c h e c k " ) 
 
         p r i n t ( "     P O S T   / a p i                       c h a t   p r o x y   ( G r o q   - >   C e r e b r a s ) " ) 
 
         p r i n t ( "     P O S T   / a p i / s h a r e           c r e a t e   c o d e b a s e   s h a r e " ) 
 
         p r i n t ( f "     G E T     / a p i / s / < i d >       f e t c h   c o d e b a s e   s h a r e " ) 
 
         s e r v e r . s e r v e _ f o r e v e r ( ) 
 
 ` ` ` 
 
 
 
 # # #   ` a p i / r e q u i r e m e n t s . t x t ` 
 
 
 
 ` ` ` 
 
 h t t p x > = 0 . 2 5 . 0 
 
 ` ` ` 
 
 
 
 # # #   ` e x a m p l e s / s a m p l e - p y t h o n - p r o j e c t / p y p r o j e c t . t o m l ` 
 
 
 
 ` ` ` t o m l 
 
 [ p r o j e c t ] 
 
 n a m e   =   " s a m p l e - a p p " 
 
 v e r s i o n   =   " 1 . 0 . 0 " 
 
 d e s c r i p t i o n   =   " S a m p l e   p r o j e c t   f o r   K r a i m i n d   d e m o " 
 
 r e q u i r e s - p y t h o n   =   " > = 3 . 1 0 " 
 
 d e p e n d e n c i e s   =   [ 
 
         " r e q u e s t s > = 2 . 3 1 . 0 " , 
 
         " f l a s k > = 2 . 0 " , 
 
         " r i c h > = 1 3 . 0 " , 
 
 ] 
 
 ` ` ` 
 
 
 
 # # #   ` e x a m p l e s / s a m p l e - p y t h o n - p r o j e c t / s r c / a p p . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " S a m p l e   F l a s k   a p p       i n t e n t i o n a l l y   o n l y   u s e s   r e q u e s t s ,   f l a s k ,   a n d   r i c h . " " " 
 
 
 
 i m p o r t   r e q u e s t s 
 
 f r o m   f l a s k   i m p o r t   F l a s k 
 
 f r o m   r i c h . c o n s o l e   i m p o r t   C o n s o l e 
 
 
 
 a p p   =   F l a s k ( _ _ n a m e _ _ ) 
 
 c o n s o l e   =   C o n s o l e ( ) 
 
 
 
 
 
 @ a p p . r o u t e ( " / " ) 
 
 d e f   i n d e x ( )   - >   s t r : 
 
         r e s p   =   r e q u e s t s . g e t ( " h t t p s : / / h t t p b i n . o r g / g e t " ,   t i m e o u t = 5 ) 
 
         c o n s o l e . p r i n t ( f " S t a t u s :   { r e s p . s t a t u s _ c o d e } " ,   s t y l e = " b o l d   g r e e n " ) 
 
         r e t u r n   f " < h 1 > K r a i m i n d   S a m p l e   A p p < / h 1 > < p r e > { r e s p . t e x t } < / p r e > " 
 
 
 
 
 
 i f   _ _ n a m e _ _   = =   " _ _ m a i n _ _ " : 
 
         a p p . r u n ( d e b u g = T r u e ) 
 
 ` ` ` 
 
 
 
 # # #   ` p y p r o j e c t . t o m l ` 
 
 
 
 ` ` ` t o m l 
 
 [ b u i l d - s y s t e m ] 
 
 r e q u i r e s   =   [ " h a t c h l i n g " ] 
 
 b u i l d - b a c k e n d   =   " h a t c h l i n g . b u i l d " 
 
 
 
 [ p r o j e c t ] 
 
 n a m e   =   " k r a i m i n d " 
 
 v e r s i o n   =   " 0 . 2 . 2 " 
 
 d e s c r i p t i o n   =   " K r a i m i n d   b y   K r a i o n y x   A I       A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e   f o r   d e v e l o p e r s " 
 
 r e a d m e   =   " R E A D M E . m d " 
 
 r e q u i r e s - p y t h o n   =   " > = 3 . 1 0 " 
 
 l i c e n s e   =   { t e x t   =   " M I T " } 
 
 a u t h o r s   =   [ { n a m e   =   " K r a i m i n d   C o n t r i b u t o r s " ,   e m a i l   =   " h e l l o @ k r a i m i n d . d e v " } ] 
 
 k e y w o r d s   =   [ " d e p e n d e n c i e s " ,   " p y t h o n " ,   " c l i " ,   " a i " ,   " o p t i m i z a t i o n " ,   " r e m o v e " ,   " m i g r a t e " ,   " c l e a n u p " ,   " s u p p l y - c h a i n " ] 
 
 c l a s s i f i e r s   =   [ 
 
         " D e v e l o p m e n t   S t a t u s   : :   3   -   A l p h a " , 
 
         " E n v i r o n m e n t   : :   C o n s o l e " , 
 
         " I n t e n d e d   A u d i e n c e   : :   D e v e l o p e r s " , 
 
         " L i c e n s e   : :   O S I   A p p r o v e d   : :   M I T   L i c e n s e " , 
 
         " P r o g r a m m i n g   L a n g u a g e   : :   P y t h o n   : :   3 " , 
 
         " P r o g r a m m i n g   L a n g u a g e   : :   P y t h o n   : :   3 . 1 0 " , 
 
         " P r o g r a m m i n g   L a n g u a g e   : :   P y t h o n   : :   3 . 1 1 " , 
 
         " P r o g r a m m i n g   L a n g u a g e   : :   P y t h o n   : :   3 . 1 2 " , 
 
 ] 
 
 
 
 d e p e n d e n c i e s   =   [ 
 
         " t y p e r > = 0 . 9 . 0 " , 
 
         " c l i c k > = 8 . 0 . 0 , < 8 . 3 " , 
 
         " r i c h > = 1 3 . 0 . 0 " , 
 
         " h t t p x > = 0 . 2 5 . 0 " , 
 
         " p a c k a g i n g > = 2 3 . 0 " , 
 
         " t o m l i > = 2 . 0 . 0 ;   p y t h o n _ v e r s i o n   <   ' 3 . 1 1 ' " , 
 
         " p r o m p t - t o o l k i t > = 3 . 0 . 0 " , 
 
 ] 
 
 
 
 [ p r o j e c t . o p t i o n a l - d e p e n d e n c i e s ] 
 
 a i   =   [ 
 
         " o p e n a i > = 1 . 0 . 0 " , 
 
         " o l l a m a > = 0 . 1 . 0 " , 
 
 ] 
 
 d e v   =   [ 
 
         " p y t e s t > = 7 . 0 . 0 " , 
 
         " p y t e s t - c o v > = 4 . 0 . 0 " , 
 
         " p y t e s t - m o c k > = 3 . 0 . 0 " , 
 
         " m y p y > = 1 . 0 . 0 " , 
 
         " b l a c k > = 2 3 . 0 . 0 " , 
 
         " i s o r t > = 5 . 0 . 0 " , 
 
         " r e s p x > = 0 . 2 0 . 0 " , 
 
         " b u i l d > = 1 . 0 . 0 " , 
 
         " t w i n e > = 4 . 0 . 0 " , 
 
 ] 
 
 
 
 [ p r o j e c t . s c r i p t s ] 
 
 k r a i m i n d   =   " k r a i m i n d . c l i : a p p " 
 
 
 
 [ p r o j e c t . u r l s ] 
 
 H o m e p a g e   =   " h t t p s : / / g i t h u b . c o m / k r a i m i n d / k r a i m i n d " 
 
 D o c u m e n t a t i o n   =   " h t t p s : / / g i t h u b . c o m / k r a i m i n d / k r a i m i n d # r e a d m e " 
 
 R e p o s i t o r y   =   " h t t p s : / / g i t h u b . c o m / k r a i m i n d / k r a i m i n d " 
 
 I s s u e s   =   " h t t p s : / / g i t h u b . c o m / k r a i m i n d / k r a i m i n d / i s s u e s " 
 
 
 
 [ t o o l . h a t c h . b u i l d . t a r g e t s . w h e e l ] 
 
 p a c k a g e s   =   [ " s r c / k r a i m i n d " ] 
 
 
 
 [ t o o l . m y p y ] 
 
 p y t h o n _ v e r s i o n   =   " 3 . 1 0 " 
 
 w a r n _ r e t u r n _ a n y   =   t r u e 
 
 w a r n _ u n u s e d _ c o n f i g s   =   t r u e 
 
 d i s a l l o w _ u n t y p e d _ d e f s   =   t r u e 
 
 
 
 [ t o o l . p y t e s t . i n i _ o p t i o n s ] 
 
 t e s t p a t h s   =   [ " t e s t s " ] 
 
 p y t h o n _ f i l e s   =   [ " t e s t _ * . p y " ] 
 
 p y t h o n _ f u n c t i o n s   =   [ " t e s t _ * " ] 
 
 
 
 [ t o o l . b l a c k ] 
 
 l i n e - l e n g t h   =   1 0 0 
 
 t a r g e t - v e r s i o n   =   [ " p y 3 1 0 " ] 
 
 
 
 [ t o o l . i s o r t ] 
 
 p r o f i l e   =   " b l a c k " 
 
 l i n e _ l e n g t h   =   1 0 0 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " K r a i m i n d :   A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e   f o r   d e v e l o p e r s .   B y   K r a i o n y x   A I . " " " 
 
 
 
 _ _ v e r s i o n _ _   =   " 0 . 2 . 1 " 
 
 _ _ a u t h o r _ _   =   " K r a i o n y x   A I " 
 
 _ _ l i c e n s e _ _   =   " M I T " 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a i / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " O p t i o n a l   A I   e n h a n c e m e n t   l a y e r   f o r   K r a i m i n d       g r a c e f u l l y   d e g r a d e s   w i t h o u t   A P I   k e y s . " " " 
 
 
 
 f r o m   k r a i m i n d . a i . e x p l a i n e r   i m p o r t   g e n e r a t e _ e x p l a n a t i o n 
 
 
 
 _ _ a l l _ _   =   [ " g e n e r a t e _ e x p l a n a t i o n " ] 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a i / c l o u d _ l l m . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " C l o u d   L L M   i n t e g r a t i o n   s u p p o r t i n g   O p e n A I ,   G r o q ,   a n d   G e m i n i . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   o s 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   O p t i o n a l 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 f r o m   k r a i m i n d . u t i l s . c o n f i g   i m p o r t   g e t _ k e y 
 
 
 
 
 
 d e f   c h a t _ c o m p l e t i o n ( 
 
         p r o m p t :   s t r , 
 
         * , 
 
         m a x _ t o k e n s :   i n t   =   2 5 0 , 
 
         t e m p e r a t u r e :   f l o a t   =   0 . 4 , 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         " " " S e n d   a   c h a t   p r o m p t   t h r o u g h   t h e   c o n f i g u r e d   p r o v i d e r   c h a i n . 
 
 
 
         R e s o l u t i o n   o r d e r :   O P E N A I _ A P I _ K E Y       G R O Q _ A P I _ K E Y       C E R E B R A S _ A P I _ K E Y       p r o x y . 
 
         R e t u r n s   t h e   a s s i s t a n t   t e x t ,   o r   N o n e   i f   e v e r y   p r o v i d e r   f a i l e d . 
 
         " " " 
 
         m e s s a g e s :   L i s t [ D i c t [ s t r ,   s t r ] ]   =   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] 
 
 
 
         o p e n a i _ k e y   =   g e t _ k e y ( " O P E N A I _ A P I _ K E Y " ) 
 
         i f   o p e n a i _ k e y : 
 
                 t e x t   =   _ o p e n a i _ c h a t ( m e s s a g e s ,   o p e n a i _ k e y ,   m a x _ t o k e n s ,   t e m p e r a t u r e ) 
 
                 i f   t e x t : 
 
                         r e t u r n   t e x t 
 
 
 
         g r o q _ k e y   =   g e t _ k e y ( " G R O Q _ A P I _ K E Y " ) 
 
         i f   g r o q _ k e y : 
 
                 t e x t   =   _ g r o q _ c h a t ( m e s s a g e s ,   g r o q _ k e y ,   m a x _ t o k e n s ,   t e m p e r a t u r e ) 
 
                 i f   t e x t : 
 
                         r e t u r n   t e x t 
 
 
 
         c e r e b r a s _ k e y   =   g e t _ k e y ( " C E R E B R A S _ A P I _ K E Y " ) 
 
         i f   c e r e b r a s _ k e y : 
 
                 t e x t   =   _ c e r e b r a s _ c h a t ( m e s s a g e s ,   c e r e b r a s _ k e y ,   m a x _ t o k e n s ,   t e m p e r a t u r e ) 
 
                 i f   t e x t : 
 
                         r e t u r n   t e x t 
 
 
 
         r e t u r n   _ p r o x y _ c h a t ( m e s s a g e s ,   m a x _ t o k e n s ,   t e m p e r a t u r e ) 
 
 
 
 
 
 d e f   _ o p e n a i _ c h a t ( 
 
         m e s s a g e s :   L i s t [ D i c t [ s t r ,   s t r ] ] ,   a p i _ k e y :   s t r ,   m a x _ t o k e n s :   i n t ,   t e m p e r a t u r e :   f l o a t 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 " h t t p s : / / a p i . o p e n a i . c o m / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                 h e a d e r s = { 
 
                                         " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " , 
 
                                         " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " , 
 
                                 } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " g p t - 4 o - m i n i " , 
 
                                         " m e s s a g e s " :   m e s s a g e s , 
 
                                         " m a x _ t o k e n s " :   m a x _ t o k e n s , 
 
                                         " t e m p e r a t u r e " :   t e m p e r a t u r e , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ g r o q _ c h a t ( 
 
         m e s s a g e s :   L i s t [ D i c t [ s t r ,   s t r ] ] ,   a p i _ k e y :   s t r ,   m a x _ t o k e n s :   i n t ,   t e m p e r a t u r e :   f l o a t 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 " h t t p s : / / a p i . g r o q . c o m / o p e n a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                 h e a d e r s = { 
 
                                         " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " , 
 
                                         " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " , 
 
                                 } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                                         " m e s s a g e s " :   m e s s a g e s , 
 
                                         " m a x _ t o k e n s " :   m a x _ t o k e n s , 
 
                                         " t e m p e r a t u r e " :   t e m p e r a t u r e , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ c e r e b r a s _ c h a t ( 
 
         m e s s a g e s :   L i s t [ D i c t [ s t r ,   s t r ] ] ,   a p i _ k e y :   s t r ,   m a x _ t o k e n s :   i n t ,   t e m p e r a t u r e :   f l o a t 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 " h t t p s : / / a p i . c e r e b r a s . a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                 h e a d e r s = { 
 
                                         " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " , 
 
                                         " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " , 
 
                                 } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a 3 . 1 - 8 b " , 
 
                                         " m e s s a g e s " :   m e s s a g e s , 
 
                                         " m a x _ t o k e n s " :   m a x _ t o k e n s , 
 
                                         " t e m p e r a t u r e " :   t e m p e r a t u r e , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ p r o x y _ c h a t ( 
 
         m e s s a g e s :   L i s t [ D i c t [ s t r ,   s t r ] ] ,   m a x _ t o k e n s :   i n t ,   t e m p e r a t u r e :   f l o a t 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         a p i _ u r l   =   o s . g e t e n v ( " K R A I M I N D _ A P I _ U R L " ,   " h t t p s : / / k r a i m i n d . v e r c e l . a p p / a p i " ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 a p i _ u r l , 
 
                                 h e a d e r s = { " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                                         " m e s s a g e s " :   m e s s a g e s , 
 
                                         " m a x _ t o k e n s " :   m a x _ t o k e n s , 
 
                                         " t e m p e r a t u r e " :   t e m p e r a t u r e , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ b u i l d _ p r o m p t ( p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t )   - >   s t r : 
 
         g h   =   m e t a d a t a . g e t ( " g i t h u b " )   o r   { } 
 
         p y   =   m e t a d a t a . g e t ( " p y p i " )   o r   { } 
 
         r e t u r n   ( 
 
                 f " Y o u   a r e   a   s e n i o r   s o f t w a r e   e n g i n e e r   a d v i s i n g   o n   P y t h o n   p a c k a g e   s e l e c t i o n . \ n \ n " 
 
                 f " P a c k a g e :   { p a c k a g e } \ n " 
 
                 f " V e r s i o n :   { p y . g e t ( ' v e r s i o n ' ,   ' N / A ' ) } \ n " 
 
                 f " S u m m a r y :   { p y . g e t ( ' s u m m a r y ' ,   ' N / A ' ) } \ n " 
 
                 f " G i t H u b   s t a r s :   { g h . g e t ( ' s t a r s ' ,   ' N / A ' ) } \ n " 
 
                 f " L a s t   p u s h :   { g h . g e t ( ' l a s t _ p u s h ' ,   ' N / A ' ) } \ n " 
 
                 f " T r u s t   s c o r e :   { t r u s t _ s c o r e } / 1 0 0 \ n \ n " 
 
                 f " I n   4 - 6   s e n t e n c e s :   W h a t   i s   t h i s   p a c k a g e   b e s t   f o r ?   S h o u l d   a   d e v e l o p e r   u s e   i t   t o d a y   " 
 
                 f " a n d   w h y ?   A r e   t h e r e   m o d e r n   a l t e r n a t i v e s ?   B e   d i r e c t   a n d   p r a c t i c a l . " 
 
         ) 
 
 
 
 
 
 d e f   _ o p e n a i _ e x p l a i n ( 
 
         p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t ,   a p i _ k e y :   s t r 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         p r o m p t   =   _ b u i l d _ p r o m p t ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 2 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 " h t t p s : / / a p i . o p e n a i . c o m / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                 h e a d e r s = { 
 
                                         " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " , 
 
                                         " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " , 
 
                                 } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " g p t - 4 o - m i n i " , 
 
                                         " m e s s a g e s " :   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                                         " m a x _ t o k e n s " :   2 5 0 , 
 
                                         " t e m p e r a t u r e " :   0 . 4 , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ g r o q _ e x p l a i n ( 
 
         p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t ,   a p i _ k e y :   s t r 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         p r o m p t   =   _ b u i l d _ p r o m p t ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 2 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 " h t t p s : / / a p i . g r o q . c o m / o p e n a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                 h e a d e r s = { 
 
                                         " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " , 
 
                                         " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " , 
 
                                 } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                                         " m e s s a g e s " :   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                                         " m a x _ t o k e n s " :   2 5 0 , 
 
                                         " t e m p e r a t u r e " :   0 . 4 , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ g e m i n i _ e x p l a i n ( 
 
         p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t ,   a p i _ k e y :   s t r 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         p r o m p t   =   _ b u i l d _ p r o m p t ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 2 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 f " h t t p s : / / g e n e r a t i v e l a n g u a g e . g o o g l e a p i s . c o m / v 1 b e t a / m o d e l s / " 
 
                                 f " g e m i n i - 1 . 5 - f l a s h : g e n e r a t e C o n t e n t ? k e y = { a p i _ k e y } " , 
 
                                 j s o n = { " c o n t e n t s " :   [ { " p a r t s " :   [ { " t e x t " :   p r o m p t } ] } ] } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c a n d i d a t e s   =   r e s p . j s o n ( ) . g e t ( " c a n d i d a t e s " ,   [ ] ) 
 
                         i f   c a n d i d a t e s : 
 
                                 p a r t s   =   c a n d i d a t e s [ 0 ] . g e t ( " c o n t e n t " ,   { } ) . g e t ( " p a r t s " ,   [ ] ) 
 
                                 t e x t   =   " " . j o i n ( p . g e t ( " t e x t " ,   " " )   f o r   p   i n   p a r t s ) . s t r i p ( ) 
 
                                 r e t u r n   t e x t   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ p r o x y _ e x p l a i n ( 
 
         p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         p r o m p t   =   _ b u i l d _ p r o m p t ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
         a p i _ u r l   =   o s . g e t e n v ( " K R A I M I N D _ A P I _ U R L " ,   " h t t p s : / / k r a i m i n d . v e r c e l . a p p / a p i " ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 2 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 a p i _ u r l , 
 
                                 h e a d e r s = { " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                                         " m e s s a g e s " :   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                                         " m a x _ t o k e n s " :   2 5 0 , 
 
                                         " t e m p e r a t u r e " :   0 . 4 , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 d e f   c l o u d _ e x p l a i n ( 
 
         p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t ,   a p i _ k e y :   s t r 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         " " " T r y   c l o u d   p r o v i d e r s   i n   o r d e r :   O p e n A I       G r o q       G e m i n i       C e r e b r a s       p r o x y . " " " 
 
         o p e n a i _ k e y   =   g e t _ k e y ( " O P E N A I _ A P I _ K E Y " ) 
 
         g r o q _ k e y   =   g e t _ k e y ( " G R O Q _ A P I _ K E Y " ) 
 
         g e m i n i _ k e y   =   g e t _ k e y ( " G E M I N I _ A P I _ K E Y " ) 
 
         c e r e b r a s _ k e y   =   g e t _ k e y ( " C E R E B R A S _ A P I _ K E Y " ) 
 
 
 
         i f   o p e n a i _ k e y : 
 
                 r e s u l t   =   _ o p e n a i _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ,   o p e n a i _ k e y ) 
 
                 i f   r e s u l t : 
 
                         r e t u r n   r e s u l t 
 
 
 
         i f   g r o q _ k e y : 
 
                 r e s u l t   =   _ g r o q _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ,   g r o q _ k e y ) 
 
                 i f   r e s u l t : 
 
                         r e t u r n   r e s u l t 
 
 
 
         i f   g e m i n i _ k e y : 
 
                 r e s u l t   =   _ g e m i n i _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ,   g e m i n i _ k e y ) 
 
                 i f   r e s u l t : 
 
                         r e t u r n   r e s u l t 
 
 
 
         i f   c e r e b r a s _ k e y : 
 
                 p r o m p t   =   _ b u i l d _ p r o m p t ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
                 r e s u l t   =   _ c e r e b r a s _ c h a t ( [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] ,   c e r e b r a s _ k e y ,   2 5 0 ,   0 . 4 ) 
 
                 i f   r e s u l t : 
 
                         r e t u r n   r e s u l t 
 
 
 
         #   F a l l b a c k :   t r y   t h e   p a s s e d   a p i _ k e y   h e u r i s t i c a l l y 
 
         i f   a p i _ k e y   a n d   a p i _ k e y   n o t   i n   ( o p e n a i _ k e y ,   g r o q _ k e y ,   g e m i n i _ k e y ,   c e r e b r a s _ k e y ) : 
 
                 r e s u l t   =   _ o p e n a i _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ,   a p i _ k e y ) 
 
                 i f   r e s u l t : 
 
                         r e t u r n   r e s u l t 
 
 
 
         #   F i n a l   F a l l b a c k   t o   P r o x y 
 
         r e t u r n   _ p r o x y _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a i / e x p l a i n e r . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A I   e x p l a n a t i o n   o r c h e s t r a t o r       t r i e s   l o c a l       c l o u d       r u l e - b a s e d   f a l l b a c k . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   o s 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   O p t i o n a l 
 
 
 
 f r o m   r i c h . t e x t   i m p o r t   T e x t 
 
 
 
 f r o m   k r a i m i n d . u t i l s . f o r m a t t i n g   i m p o r t   s c o r e _ b a r ,   s c o r e _ c o l o r ,   s c o r e _ l a b e l 
 
 
 
 
 
 d e f   g e n e r a t e _ e x p l a n a t i o n ( 
 
         p a c k a g e :   s t r , 
 
         m e t a d a t a :   D i c t [ s t r ,   A n y ] , 
 
         t r u s t _ s c o r e :   i n t , 
 
         p o s i t i v e s :   O p t i o n a l [ L i s t [ s t r ] ]   =   N o n e , 
 
         c o n c e r n s :   O p t i o n a l [ L i s t [ s t r ] ]   =   N o n e , 
 
         u s e _ a i :   b o o l   =   T r u e , 
 
 )   - >   T e x t : 
 
         " " " G e n e r a t e   a   r i c h ,   h u m a n - r e a d a b l e   e x p l a n a t i o n   f o r   a   p a c k a g e . 
 
 
 
         A l l   c o r e   o u t p u t   i s   p r o d u c e d   w i t h o u t   a n y   A P I   k e y . 
 
         A I   c o n t e n t   i s   l a y e r e d   o n   t o p   i f   a   p r o v i d e r   i s   a v a i l a b l e . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   n a m e . 
 
                 m e t a d a t a :   D i c t   w i t h   ' g i t h u b '   a n d   ' p y p i '   k e y s . 
 
                 t r u s t _ s c o r e :   P r e - c a l c u l a t e d   0 - 1 0 0   t r u s t   s c o r e . 
 
                 p o s i t i v e s :   P o s i t i v e   s i g n a l s   f r o m   c a l c u l a t e _ t r u s t _ s c o r e ( ) . 
 
                 c o n c e r n s :   C o n c e r n s   f r o m   c a l c u l a t e _ t r u s t _ s c o r e ( ) . 
 
                 u s e _ a i :   W h e t h e r   t o   a t t e m p t   A I - g e n e r a t e d   i n s i g h t . 
 
 
 
         R e t u r n s : 
 
                 A   R i c h   T e x t   o b j e c t   r e a d y   t o   p r i n t . 
 
         " " " 
 
         g h   =   m e t a d a t a . g e t ( " g i t h u b " )   o r   { } 
 
         p y   =   m e t a d a t a . g e t ( " p y p i " )   o r   { } 
 
         p o s i t i v e s   =   p o s i t i v e s   o r   [ ] 
 
         c o n c e r n s   =   c o n c e r n s   o r   [ ] 
 
 
 
         t e x t   =   T e x t ( ) 
 
 
 
         #         H e a d e r                                                                                                                           
 
         t e x t . a p p e n d ( f " \ n { p a c k a g e } " ,   s t y l e = " b o l d   c y a n " ) 
 
         i f   p y . g e t ( " v e r s i o n " ) : 
 
                 t e x t . a p p e n d ( f "     v { p y [ ' v e r s i o n ' ] } " ,   s t y l e = " b o l d   w h i t e " ) 
 
         t e x t . a p p e n d ( " \ n " ) 
 
         i f   p y . g e t ( " s u m m a r y " ) : 
 
                 t e x t . a p p e n d ( f " { p y [ ' s u m m a r y ' ] } \ n " ,   s t y l e = " g r e y 7 0 " ) 
 
 
 
         t e x t . a p p e n d ( " \ n " ) 
 
 
 
         #         S c o r e   b a r                                                                                                                     
 
         c o l o r   =   s c o r e _ c o l o r ( t r u s t _ s c o r e ) 
 
         l a b e l   =   s c o r e _ l a b e l ( t r u s t _ s c o r e ) 
 
         t e x t . a p p e n d ( " T r u s t   S c o r e :   " ,   s t y l e = " b o l d " ) 
 
         t e x t . a p p e n d ( f " { t r u s t _ s c o r e } / 1 0 0   " ,   s t y l e = f " b o l d   { c o l o r } " ) 
 
         t e x t . a p p e n d ( s c o r e _ b a r ( t r u s t _ s c o r e ) ,   s t y l e = c o l o r ) 
 
         t e x t . a p p e n d ( f "     [ { l a b e l } ] \ n " ,   s t y l e = f " b o l d   { c o l o r } " ) 
 
 
 
         t e x t . a p p e n d ( " \ n " ) 
 
 
 
         #         G i t H u b   s t a t s                                                                                                               
 
         i f   g h : 
 
                 t e x t . a p p e n d ( " a"    G i t H u b     " ,   s t y l e = " b o l d " ) 
 
                 s t a r s   =   g h . g e t ( " s t a r s " ,   0 )   o r   0 
 
                 f o r k s   =   g h . g e t ( " f o r k s " ,   0 )   o r   0 
 
                 i s s u e s   =   g h . g e t ( " o p e n _ i s s u e s " ,   0 )   o r   0 
 
                 t e x t . a p p e n d ( f "     { s t a r s : , }   s t a r s     a" $%  { f o r k s : , }   f o r k s     a"    { i s s u e s : , }   i s s u e s \ n " ,   s t y l e = " c y a n " ) 
 
                 i f   g h . g e t ( " l a s t _ p u s h " ) : 
 
                         t e x t . a p p e n d ( f "       L a s t   p u s h :   { s t r ( g h [ ' l a s t _ p u s h ' ] ) [ : 1 0 ] } " ,   s t y l e = " g r e y 7 0 " ) 
 
                         i f   g h . g e t ( " l a n g u a g e " ) : 
 
                                 t e x t . a p p e n d ( f "           { g h [ ' l a n g u a g e ' ] } " ,   s t y l e = " g r e y 7 0 " ) 
 
                         t e x t . a p p e n d ( " \ n " ) 
 
 
 
         #         P o s i t i v e   s i g n a l s                                                                                                       
 
         i f   p o s i t i v e s : 
 
                 t e x t . a p p e n d ( " \ n     P o s i t i v e   s i g n a l s : \ n " ,   s t y l e = " b o l d   g r e e n " ) 
 
                 f o r   i t e m   i n   p o s i t i v e s : 
 
                         t e x t . a p p e n d ( f "         { i t e m } \ n " ) 
 
 
 
         #         C o n c e r n s                                                                                                                       
 
         i f   c o n c e r n s : 
 
                 t e x t . a p p e n d ( " \ n   )"U%     C o n c e r n s : \ n " ,   s t y l e = " b o l d   y e l l o w " ) 
 
                 f o r   i t e m   i n   c o n c e r n s : 
 
                         t e x t . a p p e n d ( f "         { i t e m } \ n " ) 
 
 
 
         #         A I   i n s i g h t   ( o p t i o n a l )                                                                                             
 
         i f   n o t   u s e _ a i : 
 
                 t e x t . a p p e n d ( 
 
                         " \ n a"    T i p :   S e t   O P E N A I _ A P I _ K E Y ,   G R O Q _ A P I _ K E Y ,   o r   G E M I N I _ A P I _ K E Y   " 
 
                         "     o r   r u n   ` o l l a m a   p u l l   l l a m a 3 . 2 `       f o r   A I - p o w e r e d   i n s i g h t s . \ n " , 
 
                         s t y l e = " g r e y 5 0 " , 
 
                 ) 
 
         e l s e : 
 
                 a i _ t e x t   =   _ t r y _ a i ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
                 i f   a i _ t e x t : 
 
                         t e x t . a p p e n d ( " \ n a"    A I   I n s i g h t : \ n " ,   s t y l e = " b o l d   m a g e n t a " ) 
 
                         t e x t . a p p e n d ( f " { a i _ t e x t } \ n " ,   s t y l e = " g r e y 8 5 " ) 
 
                 e l s e : 
 
                         t e x t . a p p e n d ( 
 
                                 " \ n a"    A I   P r o x y   f a i l e d .   T i p :   S e t   O P E N A I _ A P I _ K E Y ,   G R O Q _ A P I _ K E Y ,   o r   G E M I N I _ A P I _ K E Y   " 
 
                                 "     o r   r u n   ` o l l a m a   p u l l   l l a m a 3 . 2 `       f o r   p r i o r i t y   A I   i n s i g h t s . \ n " , 
 
                                 s t y l e = " g r e y 5 0 " , 
 
                         ) 
 
 
 
         r e t u r n   t e x t 
 
 
 
 
 
 d e f   _ t r y _ a i ( p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t )   - >   O p t i o n a l [ s t r ] : 
 
         " " " A t t e m p t   A I   g e n e r a t i o n   i n   p r i o r i t y   o r d e r ;   r e t u r n   N o n e   o n   a l l   f a i l u r e s . " " " 
 
 
 
         #   1 .   L o c a l   O l l a m a   ( p r i v a c y - f i r s t ) 
 
         i f   o s . g e t e n v ( " K R A I M I N D _ L O C A L _ A I " ) : 
 
                 t r y : 
 
                         f r o m   k r a i m i n d . a i . l o c a l _ l l m   i m p o r t   o l l a m a _ e x p l a i n 
 
 
 
                         r e s u l t   =   o l l a m a _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
                         i f   r e s u l t : 
 
                                 r e t u r n   r e s u l t 
 
                 e x c e p t   E x c e p t i o n : 
 
                         p a s s 
 
 
 
         #   2 .   C l o u d   p r o v i d e r s   &   P r o x y 
 
         t r y : 
 
                 f r o m   k r a i m i n d . a i . c l o u d _ l l m   i m p o r t   c l o u d _ e x p l a i n 
 
 
 
                 r e s u l t   =   c l o u d _ e x p l a i n ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ,   a p i _ k e y = " " ) 
 
                 i f   r e s u l t : 
 
                         r e t u r n   r e s u l t 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
 
 
         r e t u r n   N o n e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a i / l o c a l _ l l m . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " L o c a l   L L M   i n t e g r a t i o n   v i a   O l l a m a   H T T P   A P I . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   j s o n 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   O p t i o n a l 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 _ O L L A M A _ B A S E   =   " h t t p : / / l o c a l h o s t : 1 1 4 3 4 " 
 
 _ D E F A U L T _ M O D E L   =   " l l a m a 3 . 2 " 
 
 
 
 
 
 d e f   _ b u i l d _ p r o m p t ( p a c k a g e :   s t r ,   m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t r u s t _ s c o r e :   i n t )   - >   s t r : 
 
         g h   =   m e t a d a t a . g e t ( " g i t h u b " )   o r   { } 
 
         p y   =   m e t a d a t a . g e t ( " p y p i " )   o r   { } 
 
         s t a r s   =   g h . g e t ( " s t a r s " ,   " N / A " ) 
 
         v e r s i o n   =   p y . g e t ( " v e r s i o n " ,   " N / A " ) 
 
         s u m m a r y   =   p y . g e t ( " s u m m a r y " ,   " N / A " ) 
 
         l a s t _ p u s h   =   g h . g e t ( " l a s t _ p u s h " ,   " N / A " ) 
 
 
 
         r e t u r n   f " " " Y o u   a r e   a   s e n i o r   s o f t w a r e   e n g i n e e r   a d v i s i n g   o n   P y t h o n   p a c k a g e   s e l e c t i o n . 
 
 
 
 P a c k a g e :   { p a c k a g e } 
 
 V e r s i o n :   { v e r s i o n } 
 
 S u m m a r y :   { s u m m a r y } 
 
 G i t H u b   s t a r s :   { s t a r s } 
 
 L a s t   p u s h :   { l a s t _ p u s h } 
 
 T r u s t   s c o r e :   { t r u s t _ s c o r e } / 1 0 0 
 
 
 
 I n   3 - 5   c o n c i s e   s e n t e n c e s : 
 
 1 .   W h a t   i s   t h i s   p a c k a g e   b e s t   u s e d   f o r ? 
 
 2 .   S h o u l d   a   d e v e l o p e r   u s e   i t   t o d a y ,   a n d   w h y   ( o r   w h y   n o t ) ? 
 
 3 .   A r e   t h e r e   b e t t e r   m o d e r n   a l t e r n a t i v e s   w o r t h   c o n s i d e r i n g ? 
 
 
 
 B e   d i r e c t ,   p r a c t i c a l ,   a n d   d e v e l o p e r - f r i e n d l y .   N o   m a r k d o w n   h e a d e r s . " " " 
 
 
 
 
 
 d e f   o l l a m a _ e x p l a i n ( 
 
         p a c k a g e :   s t r , 
 
         m e t a d a t a :   D i c t [ s t r ,   A n y ] , 
 
         t r u s t _ s c o r e :   i n t , 
 
         m o d e l :   s t r   =   _ D E F A U L T _ M O D E L , 
 
         t i m e o u t :   f l o a t   =   3 0 . 0 , 
 
 )   - >   O p t i o n a l [ s t r ] : 
 
         " " " G e n e r a t e   a n   e x p l a n a t i o n   v i a   a   l o c a l l y   r u n n i n g   O l l a m a   i n s t a n c e . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   n a m e . 
 
                 m e t a d a t a :   D i c t   w i t h   ' g i t h u b '   a n d   ' p y p i '   s u b - d i c t s . 
 
                 t r u s t _ s c o r e :   P r e - c a l c u l a t e d   t r u s t   s c o r e . 
 
                 m o d e l :   O l l a m a   m o d e l   t o   u s e   ( d e f a u l t :   l l a m a 3 . 2 ) . 
 
                 t i m e o u t :   R e q u e s t   t i m e o u t   i n   s e c o n d s . 
 
 
 
         R e t u r n s : 
 
                 A I - g e n e r a t e d   e x p l a n a t i o n   s t r i n g ,   o r   N o n e   i f   O l l a m a   i s   u n a v a i l a b l e . 
 
         " " " 
 
         p r o m p t   =   _ b u i l d _ p r o m p t ( p a c k a g e ,   m e t a d a t a ,   t r u s t _ s c o r e ) 
 
 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = t i m e o u t )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 f " { _ O L L A M A _ B A S E } / a p i / g e n e r a t e " , 
 
                                 j s o n = { " m o d e l " :   m o d e l ,   " p r o m p t " :   p r o m p t ,   " s t r e a m " :   F a l s e } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         d a t a   =   r e s p . j s o n ( ) 
 
                         t e x t   =   d a t a . g e t ( " r e s p o n s e " ,   " " ) . s t r i p ( ) 
 
                         r e t u r n   t e x t   i f   t e x t   e l s e   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   N o n e 
 
 
 
 
 
 d e f   i s _ o l l a m a _ a v a i l a b l e ( m o d e l :   s t r   =   _ D E F A U L T _ M O D E L )   - >   b o o l : 
 
         " " " C h e c k   i f   O l l a m a   i s   r u n n i n g   a n d   t h e   r e q u e s t e d   m o d e l   i s   a v a i l a b l e . " " " 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . g e t ( f " { _ O L L A M A _ B A S E } / a p i / t a g s " ) 
 
                         i f   r e s p . s t a t u s _ c o d e   ! =   2 0 0 : 
 
                                 r e t u r n   F a l s e 
 
                         m o d e l s   =   [ m . g e t ( " n a m e " ,   " " )   f o r   m   i n   r e s p . j s o n ( ) . g e t ( " m o d e l s " ,   [ ] ) ] 
 
                         r e t u r n   a n y ( m o d e l   i n   m   f o r   m   i n   m o d e l s ) 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   F a l s e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a l t e r n a t i v e s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " C u r a t e d   a l t e r n a t i v e s   d a t a b a s e       a n s w e r s   K r a i m i n d ' s   c o r e   q u e s t i o n : 
 
 ' I s   t h e r e   a   b e t t e r   a l t e r n a t i v e   t o   t h i s   p a c k a g e ? ' " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   L i s t ,   O p t i o n a l ,   T y p e d D i c t 
 
 
 
 
 
 c l a s s   A l t e r n a t i v e ( T y p e d D i c t ) : 
 
         " " " A   s i n g l e   a l t e r n a t i v e   r e c o m m e n d a t i o n . " " " 
 
         n a m e :   s t r 
 
         r e a s o n :   s t r 
 
         m i g r a t i o n _ e f f o r t :   s t r     #   " l o w " ,   " m e d i u m " ,   " h i g h " 
 
 
 
 
 
 c l a s s   A l t e r n a t i v e E n t r y ( T y p e d D i c t ) : 
 
         " " " F u l l   e n t r y   f o r   a   p a c k a g e   w i t h   o n e   o r   m o r e   a l t e r n a t i v e s . " " " 
 
         r e a s o n :   s t r 
 
         s e v e r i t y :   s t r     #   " i n f o " ,   " s u g g e s t " ,   " d e p r e c a t e d " 
 
         a l t e r n a t i v e s :   L i s t [ A l t e r n a t i v e ] 
 
 
 
 
 
 #   C u r a t e d   d a t a b a s e   o f   p a c k a g e s   w i t h   b e t t e r   a l t e r n a t i v e s 
 
 #   S o u r c e s :   P y t h o n   e c o s y s t e m   b e s t   p r a c t i c e s ,   d e p r e c a t e d   p a c k a g e s ,   m o d e r n i z a t i o n   p a t t e r n s 
 
 A L T E R N A T I V E S :   D i c t [ s t r ,   A l t e r n a t i v e E n t r y ]   =   { 
 
         #         D e p r e c a t e d   /   a b a n d o n e d                                                                                               
 
         " n o s e " :   { 
 
                 " r e a s o n " :   " n o s e   i s   d e p r e c a t e d   a n d   n o   l o n g e r   m a i n t a i n e d . " , 
 
                 " s e v e r i t y " :   " d e p r e c a t e d " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " p y t e s t " ,   " r e a s o n " :   " m o d e r n ,   a c t i v e l y   m a i n t a i n e d ,   r i c h e r   p l u g i n   e c o s y s t e m " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                         { " n a m e " :   " n o s e 2 " ,   " r e a s o n " :   " s u c c e s s o r   w i t h   s i m i l a r   A P I " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
         " i m p " :   { 
 
                 " r e a s o n " :   " R e m o v e d   f r o m   s t d l i b   i n   P y t h o n   3 . 1 2 . " , 
 
                 " s e v e r i t y " :   " d e p r e c a t e d " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " i m p o r t l i b " ,   " r e a s o n " :   " m o d e r n   s t d l i b   r e p l a c e m e n t " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
         " d i s t u t i l s " :   { 
 
                 " r e a s o n " :   " R e m o v e d   f r o m   s t d l i b   i n   P y t h o n   3 . 1 2 . " , 
 
                 " s e v e r i t y " :   " d e p r e c a t e d " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " s e t u p t o o l s " ,   " r e a s o n " :   " d r o p - i n   r e p l a c e m e n t   o n   P y P I " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
         " a s y n c i o - r e d i s " :   { 
 
                 " r e a s o n " :   " U n m a i n t a i n e d   f o r   y e a r s . " , 
 
                 " s e v e r i t y " :   " d e p r e c a t e d " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " r e d i s - p y " ,   " r e a s o n " :   " o f f i c i a l   R e d i s   c l i e n t   w i t h   n a t i v e   a s y n c i o   s u p p o r t " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
         " M y S Q L d b " :   { 
 
                 " r e a s o n " :   " M y S Q L d b   i s   t h e   l e g a c y   f o r k ;   m y s q l c l i e n t   i s   i t s   m o d e r n   c o n t i n u a t i o n . " , 
 
                 " s e v e r i t y " :   " s u g g e s t " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " m y s q l c l i e n t " ,   " r e a s o n " :   " a c t i v e l y   m a i n t a i n e d   d r o p - i n   r e p l a c e m e n t " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                         { " n a m e " :   " P y M y S Q L " ,   " r e a s o n " :   " p u r e - P y t h o n   a l t e r n a t i v e   w i t h   n o   C   e x t e n s i o n   r e q u i r e d " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
 
 
         #         M o d e r n i z a t i o n   s u g g e s t i o n s                                                                                         
 
         " r e q u e s t s " :   { 
 
                 " r e a s o n " :   " r e q u e s t s   i s   r o c k - s o l i d   b u t   s y n c h r o n o u s - o n l y . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " h t t p x " ,   " r e a s o n " :   " s u p p o r t s   b o t h   s y n c   a n d   a s y n c ,   H T T P / 2 ,   a n d   m o d e r n   t y p e   h i n t s " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
         " u r l l i b 3 " :   { 
 
                 " r e a s o n " :   " L o w - l e v e l       u s u a l l y   w r a p p e d   i n   h i g h e r - l e v e l   c l i e n t s . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " r e q u e s t s " ,   " r e a s o n " :   " s i m p l e r   h i g h - l e v e l   A P I   f o r   m o s t   u s e   c a s e s " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                         { " n a m e " :   " h t t p x " ,   " r e a s o n " :   " m o d e r n   a s y n c - c a p a b l e   H T T P   c l i e n t " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
         " a i o h t t p " :   { 
 
                 " r e a s o n " :   " a i o h t t p   i s   m a t u r e   b u t   m o r e   v e r b o s e   t h a n   a l t e r n a t i v e s . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " h t t p x " ,   " r e a s o n " :   " c l e a n e r   A P I ,   d u a l   s y n c / a s y n c   s u p p o r t " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   J S O N 
 
         " s i m p l e j s o n " :   { 
 
                 " r e a s o n " :   " s i m p l e j s o n   i s   r a r e l y   n e e d e d       s t d l i b   j s o n   i s   f a s t   e n o u g h . " , 
 
                 " s e v e r i t y " :   " s u g g e s t " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " j s o n   ( s t d l i b ) " ,   " r e a s o n " :   " n o   e x t r a   d e p e n d e n c y   r e q u i r e d " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                         { " n a m e " :   " o r j s o n " ,   " r e a s o n " :   " m u c h   f a s t e r   ( R u s t - b a s e d )   f o r   J S O N - h e a v y   w o r k l o a d s " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   D a t e / t i m e 
 
         " a r r o w " :   { 
 
                 " r e a s o n " :   " a r r o w ' s   A P I   i s   l a r g e l y   s u p e r s e d e d   b y   s t d l i b   +   z o n e i n f o   ( P y t h o n   3 . 9 + ) . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " d a t e t i m e   +   z o n e i n f o   ( s t d l i b ) " ,   " r e a s o n " :   " n o   e x t r a   d e p e n d e n c y   f o r   t i m e z o n e   h a n d l i n g " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                         { " n a m e " :   " p e n d u l u m " ,   " r e a s o n " :   " r i c h e r   A P I   i f   y o u   n e e d   m o r e   t h a n   s t d l i b   o f f e r s " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   C o n f i g u r a t i o n 
 
         " c o n f i g p a r s e r " :   { 
 
                 " r e a s o n " :   " I N I   f i l e s   a r e   l i m i t i n g   c o m p a r e d   t o   T O M L . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " t o m l l i b   ( s t d l i b   3 . 1 1 + ) " ,   " r e a s o n " :   " T O M L   i s   t h e   m o d e r n   P y t h o n   s t a n d a r d   f o r   c o n f i g " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                         { " n a m e " :   " p y d a n t i c - s e t t i n g s " ,   " r e a s o n " :   " t y p e - s a f e   c o n f i g   f r o m   e n v   v a r s   +   f i l e s " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   T e s t i n g 
 
         " m o c k " :   { 
 
                 " r e a s o n " :   " E x t e r n a l   ' m o c k '   i s   t h e   b a c k p o r t       s t d l i b   u n i t t e s t . m o c k   i s   b u i l t - i n . " , 
 
                 " s e v e r i t y " :   " s u g g e s t " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " u n i t t e s t . m o c k   ( s t d l i b ) " ,   " r e a s o n " :   " n o   e x t r a   d e p e n d e n c y   o n   P y t h o n   3 . 3 + " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   W e b   s c r a p i n g 
 
         " b e a u t i f u l s o u p 4 " :   { 
 
                 " r e a s o n " :   " B S 4   i s   g r e a t   f o r   H T M L ,   b u t   s l o w   o n   l a r g e   d o c u m e n t s . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " s e l e c t o l a x " ,   " r e a s o n " :   " 1 0 - 1 0 0 x   f a s t e r   f o r   H T M L   p a r s i n g " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                         { " n a m e " :   " l x m l " ,   " r e a s o n " :   " b a t t l e - t e s t e d ,   f a s t   X M L / H T M L   p a r s i n g " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   M L 
 
         " t e n s o r f l o w " :   { 
 
                 " r e a s o n " :   " T e n s o r F l o w   i s   h e a v y       c o n s i d e r   w h e t h e r   y o u   n e e d   i t . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " p y t o r c h " ,   " r e a s o n " :   " m o r e   p y t h o n i c ,   d o m i n a n t   i n   r e s e a r c h " ,   " m i g r a t i o n _ e f f o r t " :   " h i g h " } , 
 
                         { " n a m e " :   " j a x " ,   " r e a s o n " :   " f u n c t i o n a l ,   f a s t ,   g r e a t   f o r   r e s e a r c h " ,   " m i g r a t i o n _ e f f o r t " :   " h i g h " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   A s y n c 
 
         " t r i o " :   { 
 
                 " r e a s o n " :   " E x c e l l e n t   a s y n c   l i b r a r y ,   b u t   s m a l l e r   e c o s y s t e m   t h a n   a s y n c i o . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " a n y i o " ,   " r e a s o n " :   " w o r k s   w i t h   b o t h   a s y n c i o   a n d   t r i o   b a c k e n d s " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   C L I 
 
         " a r g p a r s e " :   { 
 
                 " r e a s o n " :   " S t d l i b   a r g p a r s e   i s   f i n e   b u t   l a c k s   t y p e   h i n t s   a n d   c o l o r . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " t y p e r " ,   " r e a s o n " :   " t y p e - h i n t   b a s e d ,   b e a u t i f u l   h e l p ,   b u i l t   o n   C l i c k " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                         { " n a m e " :   " c l i c k " ,   " r e a s o n " :   " b a t t l e - t e s t e d   d e c o r a t o r - b a s e d   C L I   f r a m e w o r k " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   V a l i d a t i o n 
 
         " m a r s h m a l l o w " :   { 
 
                 " r e a s o n " :   " m a r s h m a l l o w   i s   s t a b l e   b u t   p y d a n t i c   v 2   h a s   o v e r t a k e n   i t   f o r   n e w   p r o j e c t s . " , 
 
                 " s e v e r i t y " :   " i n f o " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " p y d a n t i c " ,   " r e a s o n " :   " v 2   i s   f a s t   ( R u s t   c o r e ) ,   g r e a t   D X ,   n a t i v e   t o   F a s t A P I " ,   " m i g r a t i o n _ e f f o r t " :   " m e d i u m " } , 
 
                 ] , 
 
         } , 
 
 
 
         #   I m a g e 
 
         " P i l l o w - P I L " :   { 
 
                 " r e a s o n " :   " P i l l o w - P I L   i s   a   l e g a c y   a l i a s . " , 
 
                 " s e v e r i t y " :   " d e p r e c a t e d " , 
 
                 " a l t e r n a t i v e s " :   [ 
 
                         { " n a m e " :   " p i l l o w " ,   " r e a s o n " :   " c u r r e n t   c a n o n i c a l   f o r k " ,   " m i g r a t i o n _ e f f o r t " :   " l o w " } , 
 
                 ] , 
 
         } , 
 
 } 
 
 
 
 
 
 d e f   g e t _ a l t e r n a t i v e s ( p a c k a g e :   s t r )   - >   O p t i o n a l [ A l t e r n a t i v e E n t r y ] : 
 
         " " " L o o k   u p   a l t e r n a t i v e s   f o r   a   p a c k a g e   n a m e   ( c a s e - i n s e n s i t i v e ,   n o r m a l i z e d ) . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   n a m e   t o   l o o k   u p . 
 
 
 
         R e t u r n s : 
 
                 A l t e r n a t i v e   e n t r y   o r   N o n e   i f   n o t   i n   d a t a b a s e . 
 
         " " " 
 
         i f   n o t   p a c k a g e : 
 
                 r e t u r n   N o n e 
 
         #   T r y   e x a c t ,   l o w e r c a s e ,   a n d   h y p h e n - n o r m a l i z e d   v a r i a n t s 
 
         f o r   k e y   i n   ( p a c k a g e ,   p a c k a g e . l o w e r ( ) ,   p a c k a g e . l o w e r ( ) . r e p l a c e ( " _ " ,   " - " ) ) : 
 
                 i f   k e y   i n   A L T E R N A T I V E S : 
 
                         r e t u r n   A L T E R N A T I V E S [ k e y ] 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   h a s _ a l t e r n a t i v e s ( p a c k a g e :   s t r )   - >   b o o l : 
 
         " " " Q u i c k   c h e c k   w h e t h e r   w e   h a v e   a l t e r n a t i v e s   r e c o r d e d   f o r   t h i s   p a c k a g e . " " " 
 
         r e t u r n   g e t _ a l t e r n a t i v e s ( p a c k a g e )   i s   n o t   N o n e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a r c h i t e c t . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A I - p o w e r e d   a r c h i t e c t u r a l   c o n s t r a i n t s   &   d e p l o y m e n t   s c a n n e r . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t 
 
 
 
 f r o m   k r a i m i n d . a i . c l o u d _ l l m   i m p o r t   c h a t _ c o m p l e t i o n 
 
 f r o m   k r a i m i n d . p a r s e r   i m p o r t   g e t _ d e c l a r e d _ d e p e n d e n c i e s ,   g e t _ l o c k f i l e _ i n f o 
 
 
 
 
 
 d e f   c o l l e c t _ t e l e m e t r y ( p r o j e c t _ p a t h :   P a t h )   - >   D i c t [ s t r ,   A n y ] : 
 
         " " " C o l l e c t   h i g h - l e v e l   s i g n a l s   a b o u t   t h e   r e p o s i t o r y   s t r u c t u r e . " " " 
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         h a s _ d j a n g o   =   " d j a n g o "   i n   d e c l a r e d 
 
         h a s _ f a s t a p i   =   " f a s t a p i "   i n   d e c l a r e d 
 
         h a s _ f l a s k   =   " f l a s k "   i n   d e c l a r e d 
 
 
 
         h a s _ d o c k e r   =   ( p r o j e c t _ p a t h   /   " D o c k e r f i l e " ) . e x i s t s ( ) 
 
         h a s _ p a c k a g e _ j s o n   =   ( p r o j e c t _ p a t h   /   " p a c k a g e . j s o n " ) . e x i s t s ( ) 
 
 
 
         r e t u r n   { 
 
                 " f r a m e w o r k s " :   { 
 
                         " d j a n g o " :   h a s _ d j a n g o , 
 
                         " f a s t a p i " :   h a s _ f a s t a p i , 
 
                         " f l a s k " :   h a s _ f l a s k , 
 
                 } , 
 
                 " d e p e n d e n c i e s _ c o u n t " :   l e n ( d e c l a r e d ) , 
 
                 " d o c k e r i z e d " :   h a s _ d o c k e r , 
 
                 " h a s _ f r o n t e n d " :   h a s _ p a c k a g e _ j s o n , 
 
         } 
 
 
 
 
 
 d e f   _ b u i l d _ a r c h i t e c t _ p r o m p t ( t e l e m e t r y :   D i c t [ s t r ,   A n y ] )   - >   s t r : 
 
         f r a m e w o r k s   =   [ k   f o r   k ,   v   i n   t e l e m e t r y . g e t ( " f r a m e w o r k s " ,   { } ) . i t e m s ( )   i f   v ] 
 
         f w _ s t r   =   " ,   " . j o i n ( f r a m e w o r k s )   i f   f r a m e w o r k s   e l s e   " g e n e r i c   p y t h o n " 
 
 
 
         r e t u r n   ( 
 
                 f " Y o u   a r e   a   C l o u d   I n f r a s t r u c t u r e   A r c h i t e c t .   T h e   u s e r   w a n t s   d e p l o y m e n t   a n d   c o s t   r e c o m m e n d a t i o n s   " 
 
                 f " f o r   t h e i r   P y t h o n   p r o j e c t . \ n \ n " 
 
                 f " P r o j e c t   T e l e m e t r y : \ n " 
 
                 f " -   F r a m e w o r k s :   { f w _ s t r } \ n " 
 
                 f " -   T o t a l   D e p e n d e n c i e s :   { t e l e m e t r y . g e t ( ' d e p e n d e n c i e s _ c o u n t ' ,   0 ) } \ n " 
 
                 f " -   D o c k e r i z e d :   { t e l e m e t r y . g e t ( ' d o c k e r i z e d ' ,   F a l s e ) } \ n " 
 
                 f " -   N o d e . j s / F r o n t e n d   p r e s e n t :   { t e l e m e t r y . g e t ( ' h a s _ f r o n t e n d ' ,   F a l s e ) } \ n \ n " 
 
                 f " P l e a s e   p r o v i d e : \ n " 
 
                 f " 1 .   T o p   2   d e p l o y m e n t   p l a t f o r m   r e c o m m e n d a t i o n s   ( e . g .   A W S   A p p   R u n n e r ,   V e r c e l ,   R a i l w a y ,   R e n d e r ,   G C P   C l o u d   R u n ) . \ n " 
 
                 f " 2 .   A   r o u g h   m o n t h l y   c o s t   e s t i m a t e   ( i n   U S D )   f o r   a n   M V P   /   l o w   t r a f f i c   s e t t i n g   v s   m e d i u m   t r a f f i c . \ n " 
 
                 f " 3 .   2   k e y   p o t e n t i a l   b o t t l e n e c k s .   \ n \ n " 
 
                 f " K e e p   t h e   f o r m a t t i n g   c l e a n   u s i n g   m a r k d o w n .   M a k e   i t   c o n c i s e   b u t   h i g h l y   a c t i o n a b l e . " 
 
         ) 
 
 
 
 
 
 d e f   a n a l y z e _ d e p l o y m e n t ( p r o j e c t _ p a t h :   P a t h )   - >   s t r : 
 
         " " " A n a l y z e   t h e   p r o j e c t   a n d   r e t u r n   a r c h i t e c t   r e c o m m e n d a t i o n s . 
 
 
 
         U s e s   t h e   u n i f i e d   p r o v i d e r   c h a i n   i n   ` k r a i m i n d . a i . c l o u d _ l l m . c h a t _ c o m p l e t i o n ` : 
 
         O p e n A I       G r o q       K r a i m i n d   V e r c e l   p r o x y . 
 
         " " " 
 
         t e l e m e t r y   =   c o l l e c t _ t e l e m e t r y ( p r o j e c t _ p a t h ) 
 
         p r o m p t   =   _ b u i l d _ a r c h i t e c t _ p r o m p t ( t e l e m e t r y ) 
 
 
 
         r e s u l t   =   c h a t _ c o m p l e t i o n ( p r o m p t ,   m a x _ t o k e n s = 5 1 2 ,   t e m p e r a t u r e = 0 . 4 ) 
 
         i f   r e s u l t : 
 
                 r e t u r n   r e s u l t 
 
 
 
         r e t u r n   ( 
 
                 " F a i l e d   t o   f e t c h   a r c h i t e c t   r e c o m m e n d a t i o n s .   " 
 
                 " P l e a s e   e n s u r e   y o u   h a v e   a n   a c t i v e   i n t e r n e t   c o n n e c t i o n   o r   s e t   " 
 
                 " O P E N A I _ A P I _ K E Y   /   G R O Q _ A P I _ K E Y . " 
 
         ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / a s y n c _ c l i e n t s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A s y n c   p a r a l l e l   A P I   c l i e n t s       g i v e s   5 - 1 0 x   s p e e d u p   v s   s e q u e n t i a l   f e t c h i n g . 
 
 
 
 E a c h   c l i e n t   w r a p s   t h e   e x i s t i n g   s y n c   c l i e n t   l o g i c   w i t h   a s y n c / a w a i t   +   a s y n c i o . g a t h e r ( ) . 
 
 C a c h i n g   i s   s h a r e d   w i t h   t h e   s y n c   c l i e n t s   ( f i l e s y s t e m   c a c h e ) . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   a s y n c i o 
 
 i m p o r t   j s o n 
 
 i m p o r t   o s 
 
 i m p o r t   t i m e 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   A w a i t a b l e ,   C a l l a b l e ,   D i c t ,   L i s t ,   O p t i o n a l ,   T u p l e 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 f r o m   k r a i m i n d . g i t h u b   i m p o r t   e x t r a c t _ r e p o _ s l u g _ f r o m _ u r l 
 
 f r o m   k r a i m i n d . u t i l s . c a c h e   i m p o r t   _ c a c h e _ p a t h 
 
 f r o m   k r a i m i n d . v u l n e r a b i l i t y   i m p o r t   _ e x t r a c t _ f i x e d _ v e r s i o n s ,   _ e x t r a c t _ s e v e r i t y 
 
 
 
 _ G I T H U B _ A P I   =   " h t t p s : / / a p i . g i t h u b . c o m " 
 
 _ P Y P I _ J S O N   =   " h t t p s : / / p y p i . o r g / p y p i / { p a c k a g e } / j s o n " 
 
 _ O S V _ Q U E R Y   =   " h t t p s : / / a p i . o s v . d e v / v 1 / q u e r y " 
 
 
 
 
 
 d e f   _ g h _ h e a d e r s ( )   - >   D i c t [ s t r ,   s t r ] : 
 
         h   =   { 
 
                 " A c c e p t " :   " a p p l i c a t i o n / v n d . g i t h u b + j s o n " , 
 
                 " X - G i t H u b - A p i - V e r s i o n " :   " 2 0 2 2 - 1 1 - 2 8 " , 
 
         } 
 
         t o k e n   =   o s . g e t e n v ( " G I T H U B _ T O K E N " )   o r   o s . g e t e n v ( " G H _ T O K E N " ) 
 
         i f   t o k e n : 
 
                 h [ " A u t h o r i z a t i o n " ]   =   f " B e a r e r   { t o k e n } " 
 
         r e t u r n   h 
 
 
 
 
 
 a s y n c   d e f   _ a s y n c _ c a c h e d ( 
 
         k e y :   s t r , 
 
         f e t c h e r :   C a l l a b l e [ [ ] ,   A w a i t a b l e [ A n y ] ] , 
 
         t t l _ h o u r s :   f l o a t   =   2 4 . 0 , 
 
 )   - >   A n y : 
 
         " " " C h e c k   t h e   f i l e s y s t e m   c a c h e   s y n c h r o n o u s l y ,   t h e n   a w a i t   t h e   n e t w o r k   f e t c h   o n   m i s s . " " " 
 
         c a c h e _ f i l e   =   _ c a c h e _ p a t h ( k e y ) 
 
         i f   c a c h e _ f i l e . e x i s t s ( ) : 
 
                 t r y : 
 
                         w i t h   o p e n ( c a c h e _ f i l e ,   " r " ,   e n c o d i n g = " u t f - 8 " )   a s   f : 
 
                                 c a c h e d   =   j s o n . l o a d ( f ) 
 
                         i f   ( t i m e . t i m e ( )   -   c a c h e d [ " t i m e s t a m p " ] )   /   3 6 0 0 . 0   <   t t l _ h o u r s : 
 
                                 r e t u r n   c a c h e d [ " d a t a " ] 
 
                 e x c e p t   E x c e p t i o n : 
 
                         p a s s 
 
 
 
         r e s u l t   =   a w a i t   f e t c h e r ( ) 
 
 
 
         t r y : 
 
                 w i t h   o p e n ( c a c h e _ f i l e ,   " w " ,   e n c o d i n g = " u t f - 8 " )   a s   f : 
 
                         j s o n . d u m p ( { " t i m e s t a m p " :   t i m e . t i m e ( ) ,   " d a t a " :   r e s u l t } ,   f ) 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
 
 
         r e t u r n   r e s u l t 
 
 
 
 
 
 a s y n c   d e f   f e t c h _ p y p i _ a s y n c ( 
 
         p a c k a g e :   s t r ,   c l i e n t :   h t t p x . A s y n c C l i e n t 
 
 )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
         " " " A s y n c   P y P I   m e t a d a t a   f e t c h   w i t h   c a c h i n g . " " " 
 
         i f   n o t   p a c k a g e : 
 
                 r e t u r n   N o n e 
 
         u r l   =   _ P Y P I _ J S O N . f o r m a t ( p a c k a g e = p a c k a g e ) 
 
 
 
         a s y n c   d e f   _ d o ( )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
                 t r y : 
 
                         r e s p   =   a w a i t   c l i e n t . g e t ( u r l ,   t i m e o u t = 1 0 . 0 ) 
 
                         i f   r e s p . s t a t u s _ c o d e   = =   4 0 4 : 
 
                                 r e t u r n   N o n e 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         d a t a   =   r e s p . j s o n ( ) 
 
                 e x c e p t   E x c e p t i o n : 
 
                         r e t u r n   N o n e 
 
 
 
                 i n f o   =   d a t a . g e t ( " i n f o " )   o r   { } 
 
                 r e l e a s e s   =   d a t a . g e t ( " r e l e a s e s " )   o r   { } 
 
                 l a t e s t   =   i n f o . g e t ( " v e r s i o n " ) 
 
 
 
                 r e l e a s e _ d a t e   =   N o n e 
 
                 s i z e _ b y t e s   =   N o n e 
 
                 i f   l a t e s t   a n d   l a t e s t   i n   r e l e a s e s : 
 
                         u p l o a d s   =   r e l e a s e s [ l a t e s t ] 
 
                         i f   u p l o a d s   a n d   i s i n s t a n c e ( u p l o a d s ,   l i s t ) : 
 
                                 r e l e a s e _ d a t e   =   u p l o a d s [ 0 ] . g e t ( " u p l o a d _ t i m e " ) 
 
                                 s i z e _ b y t e s   =   s u m ( u . g e t ( " s i z e " ,   0 )   o r   0   f o r   u   i n   u p l o a d s   i f   i s i n s t a n c e ( u ,   d i c t ) ) 
 
 
 
                 p r o j e c t _ u r l s   =   i n f o . g e t ( " p r o j e c t _ u r l s " )   o r   { } 
 
                 r e p o _ u r l   =   N o n e 
 
                 f o r   _ k ,   v   i n   p r o j e c t _ u r l s . i t e m s ( ) : 
 
                         i f   v   a n d   " g i t h u b . c o m "   i n   ( v   o r   " " ) . l o w e r ( ) : 
 
                                 r e p o _ u r l   =   v 
 
                                 b r e a k 
 
                 i f   n o t   r e p o _ u r l : 
 
                         h o m e   =   i n f o . g e t ( " h o m e _ p a g e " )   o r   " " 
 
                         i f   " g i t h u b . c o m "   i n   h o m e . l o w e r ( ) : 
 
                                 r e p o _ u r l   =   h o m e 
 
 
 
                 r e t u r n   { 
 
                         " n a m e " :   i n f o . g e t ( " n a m e " ,   p a c k a g e ) , 
 
                         " v e r s i o n " :   l a t e s t , 
 
                         " s u m m a r y " :   i n f o . g e t ( " s u m m a r y " ) , 
 
                         " a u t h o r " :   i n f o . g e t ( " a u t h o r " )   o r   i n f o . g e t ( " m a i n t a i n e r " ) , 
 
                         " l i c e n s e " :   i n f o . g e t ( " l i c e n s e " ) , 
 
                         " h o m e _ p a g e " :   i n f o . g e t ( " h o m e _ p a g e " ) , 
 
                         " p r o j e c t _ u r l s " :   p r o j e c t _ u r l s , 
 
                         " r e p o _ u r l " :   r e p o _ u r l , 
 
                         " r e q u i r e s _ p y t h o n " :   i n f o . g e t ( " r e q u i r e s _ p y t h o n " ) , 
 
                         " r e l e a s e _ d a t e " :   r e l e a s e _ d a t e , 
 
                         " r e l e a s e _ s i z e _ b y t e s " :   s i z e _ b y t e s , 
 
                         " c l a s s i f i e r s " :   i n f o . g e t ( " c l a s s i f i e r s " )   o r   [ ] , 
 
                         " h a s _ s e c u r i t y _ a d v i s o r i e s " :   F a l s e , 
 
                 } 
 
 
 
         r e t u r n   a w a i t   _ a s y n c _ c a c h e d ( f " p y p i : { p a c k a g e . l o w e r ( ) } " ,   _ d o ,   t t l _ h o u r s = 2 4 . 0 ) 
 
 
 
 
 
 a s y n c   d e f   f e t c h _ g i t h u b _ a s y n c ( 
 
         r e p o _ s l u g :   s t r ,   c l i e n t :   h t t p x . A s y n c C l i e n t 
 
 )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
         " " " A s y n c   G i t H u b   r e p o   m e t a d a t a   f e t c h   w i t h   r a t e - l i m i t   a w a r e n e s s . " " " 
 
         i f   n o t   r e p o _ s l u g   o r   " / "   n o t   i n   r e p o _ s l u g : 
 
                 r e t u r n   N o n e 
 
 
 
         u r l   =   f " { _ G I T H U B _ A P I } / r e p o s / { r e p o _ s l u g } " 
 
 
 
         a s y n c   d e f   _ d o ( )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
                 t r y : 
 
                         r e s p   =   a w a i t   c l i e n t . g e t ( u r l ,   h e a d e r s = _ g h _ h e a d e r s ( ) ,   t i m e o u t = 1 0 . 0 ) 
 
                         i f   r e s p . s t a t u s _ c o d e   = =   4 0 4 : 
 
                                 r e t u r n   N o n e 
 
                         i f   r e s p . s t a t u s _ c o d e   i n   ( 4 0 3 ,   4 2 9 ) : 
 
                                 #   R a t e - l i m i t e d       r e t u r n   N o n e   ( d e g r a d e d   g r a c e f u l l y ) 
 
                                 r e t u r n   N o n e 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         d a t a   =   r e s p . j s o n ( ) 
 
                 e x c e p t   E x c e p t i o n : 
 
                         r e t u r n   N o n e 
 
 
 
                 s e c   =   d a t a . g e t ( " s e c u r i t y _ a n d _ a n a l y s i s " )   o r   { } 
 
                 h a s _ s e c u r i t y _ p o l i c y   =   ( 
 
                         i s i n s t a n c e ( s e c ,   d i c t ) 
 
                         a n d   i s i n s t a n c e ( s e c . g e t ( " s e c r e t _ s c a n n i n g " ) ,   d i c t ) 
 
                         a n d   s e c [ " s e c r e t _ s c a n n i n g " ] . g e t ( " s t a t u s " )   = =   " e n a b l e d " 
 
                 ) 
 
 
 
                 r e t u r n   { 
 
                         " f u l l _ n a m e " :   d a t a . g e t ( " f u l l _ n a m e " ) , 
 
                         " h t m l _ u r l " :   d a t a . g e t ( " h t m l _ u r l " ) , 
 
                         " d e s c r i p t i o n " :   d a t a . g e t ( " d e s c r i p t i o n " ) , 
 
                         " s t a r s " :   d a t a . g e t ( " s t a r g a z e r s _ c o u n t " ,   0 ) , 
 
                         " f o r k s " :   d a t a . g e t ( " f o r k s _ c o u n t " ,   0 ) , 
 
                         " o p e n _ i s s u e s " :   d a t a . g e t ( " o p e n _ i s s u e s _ c o u n t " ,   0 ) , 
 
                         " l a s t _ p u s h " :   d a t a . g e t ( " p u s h e d _ a t " ) , 
 
                         " c r e a t e d _ a t " :   d a t a . g e t ( " c r e a t e d _ a t " ) , 
 
                         " u p d a t e d _ a t " :   d a t a . g e t ( " u p d a t e d _ a t " ) , 
 
                         " l a n g u a g e " :   d a t a . g e t ( " l a n g u a g e " ) , 
 
                         " h o m e p a g e " :   d a t a . g e t ( " h o m e p a g e " ) , 
 
                         " h a s _ s e c u r i t y _ p o l i c y " :   h a s _ s e c u r i t y _ p o l i c y , 
 
                         " a r c h i v e d " :   d a t a . g e t ( " a r c h i v e d " ,   F a l s e ) , 
 
                         " d i s a b l e d " :   d a t a . g e t ( " d i s a b l e d " ,   F a l s e ) , 
 
                 } 
 
 
 
         r e t u r n   a w a i t   _ a s y n c _ c a c h e d ( f " g i t h u b : { r e p o _ s l u g } " ,   _ d o ,   t t l _ h o u r s = 2 4 . 0 ) 
 
 
 
 
 
 a s y n c   d e f   f e t c h _ o s v _ a s y n c ( 
 
         p a c k a g e :   s t r ,   v e r s i o n :   O p t i o n a l [ s t r ] ,   c l i e n t :   h t t p x . A s y n c C l i e n t 
 
 )   - >   L i s t [ D i c t [ s t r ,   A n y ] ] : 
 
         " " " A s y n c   O S V   v u l n e r a b i l i t y   q u e r y   w i t h   c a c h i n g . " " " 
 
         i f   n o t   p a c k a g e : 
 
                 r e t u r n   [ ] 
 
 
 
         p a y l o a d :   D i c t [ s t r ,   A n y ]   =   { " p a c k a g e " :   { " n a m e " :   p a c k a g e ,   " e c o s y s t e m " :   " P y P I " } } 
 
         i f   v e r s i o n : 
 
                 p a y l o a d [ " v e r s i o n " ]   =   v e r s i o n 
 
 
 
         c a c h e _ k e y   =   f " o s v : P y P I : { p a c k a g e } : { v e r s i o n   o r   ' a l l ' } " 
 
 
 
         a s y n c   d e f   _ d o ( )   - >   L i s t [ D i c t [ s t r ,   A n y ] ] : 
 
                 t r y : 
 
                         r e s p   =   a w a i t   c l i e n t . p o s t ( _ O S V _ Q U E R Y ,   j s o n = p a y l o a d ,   t i m e o u t = 1 0 . 0 ) 
 
                         i f   r e s p . s t a t u s _ c o d e   ! =   2 0 0 : 
 
                                 r e t u r n   [ ] 
 
                         d a t a   =   r e s p . j s o n ( ) 
 
                 e x c e p t   E x c e p t i o n : 
 
                         r e t u r n   [ ] 
 
 
 
                 f r o m   k r a i m i n d . v u l n e r a b i l i t y   i m p o r t   _ e x t r a c t _ f i x e d _ v e r s i o n s ,   _ e x t r a c t _ s e v e r i t y 
 
 
 
                 v u l n s :   L i s t [ D i c t [ s t r ,   A n y ] ]   =   [ ] 
 
                 f o r   v   i n   d a t a . g e t ( " v u l n s " )   o r   [ ] : 
 
                         v u l n s . a p p e n d ( 
 
                                 { 
 
                                         " i d " :   v . g e t ( " i d " ) , 
 
                                         " s u m m a r y " :   v . g e t ( " s u m m a r y " )   o r   ( v . g e t ( " d e t a i l s " )   o r   " " ) [ : 2 0 0 ] , 
 
                                         " s e v e r i t y " :   _ e x t r a c t _ s e v e r i t y ( v ) , 
 
                                         " f i x e d _ v e r s i o n s " :   _ e x t r a c t _ f i x e d _ v e r s i o n s ( v ) , 
 
                                         " a l i a s e s " :   v . g e t ( " a l i a s e s " ,   [ ] ) , 
 
                                         " p u b l i s h e d " :   v . g e t ( " p u b l i s h e d " ) , 
 
                                 } 
 
                         ) 
 
                 r e t u r n   v u l n s 
 
 
 
         r e s u l t   =   a w a i t   _ a s y n c _ c a c h e d ( c a c h e _ k e y ,   _ d o ,   t t l _ h o u r s = 1 2 . 0 ) 
 
         r e t u r n   r e s u l t   i f   i s i n s t a n c e ( r e s u l t ,   l i s t )   e l s e   [ ] 
 
 
 
 
 
 a s y n c   d e f   _ n o n e _ c o r o ( )   - >   N o n e : 
 
         " " " S e n t i n e l   c o r o u t i n e   r e t u r n i n g   N o n e       u s e d   w h e n   a   f e t c h   i s   n o t   a p p l i c a b l e . " " " 
 
         r e t u r n   N o n e 
 
 
 
 
 
 a s y n c   d e f   f e t c h _ f u l l _ i n t e l l i g e n c e ( 
 
         p a c k a g e :   s t r ,   c l i e n t :   h t t p x . A s y n c C l i e n t 
 
 )   - >   T u p l e [ s t r ,   D i c t [ s t r ,   A n y ] ] : 
 
         " " " F e t c h   a l l   i n t e l   f o r   a   s i n g l e   p a c k a g e   ( P y P I   +   G i t H u b   +   O S V )   c o n c u r r e n t l y . 
 
 
 
         R e t u r n s : 
 
                 ( p a c k a g e _ n a m e ,   i n t e l l i g e n c e _ d i c t )   w h e r e   t h e   d i c t   c o n t a i n s : 
 
                         ' p y p i ' ,   ' g i t h u b ' ,   ' v u l n e r a b i l i t i e s ' 
 
         " " " 
 
         p y p i   =   a w a i t   f e t c h _ p y p i _ a s y n c ( p a c k a g e ,   c l i e n t ) 
 
         p y p i   =   p y p i   o r   { } 
 
 
 
         r e p o _ u r l   =   p y p i . g e t ( " r e p o _ u r l " )   o r   p y p i . g e t ( " h o m e _ p a g e " ) 
 
         s l u g   =   e x t r a c t _ r e p o _ s l u g _ f r o m _ u r l ( r e p o _ u r l ) 
 
 
 
         #   G i t H u b   +   O S V   i n   p a r a l l e l 
 
         g h _ t a s k   =   f e t c h _ g i t h u b _ a s y n c ( s l u g ,   c l i e n t )   i f   s l u g   e l s e   _ n o n e _ c o r o ( ) 
 
         v u l n _ t a s k   =   f e t c h _ o s v _ a s y n c ( p a c k a g e ,   p y p i . g e t ( " v e r s i o n " ) ,   c l i e n t ) 
 
 
 
         g h ,   v u l n s   =   a w a i t   a s y n c i o . g a t h e r ( g h _ t a s k ,   v u l n _ t a s k ) 
 
         g h   =   g h   o r   { } 
 
 
 
         r e t u r n   p a c k a g e ,   { 
 
                 " p y p i " :   p y p i , 
 
                 " g i t h u b " :   g h , 
 
                 " v u l n e r a b i l i t i e s " :   v u l n s , 
 
         } 
 
 
 
 
 
 a s y n c   d e f   f e t c h _ a l l _ p a c k a g e s ( 
 
         p a c k a g e s :   L i s t [ s t r ] , 
 
         m a x _ c o n c u r r e n t :   i n t   =   1 0 , 
 
         p r o g r e s s _ c a l l b a c k :   O p t i o n a l [ C a l l a b l e [ [ s t r ] ,   N o n e ] ]   =   N o n e , 
 
 )   - >   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] : 
 
         " " " F e t c h   i n t e l l i g e n c e   f o r   a l l   p a c k a g e s   i n   p a r a l l e l . 
 
 
 
         A r g s : 
 
                 p a c k a g e s :   L i s t   o f   p a c k a g e   n a m e s . 
 
                 m a x _ c o n c u r r e n t :   M a x   s i m u l t a n e o u s   H T T P   c o n n e c t i o n s . 
 
                 p r o g r e s s _ c a l l b a c k :   O p t i o n a l   c a l l b a c k   i n v o k e d   w i t h   e a c h   c o m p l e t e d   p a c k a g e   n a m e . 
 
 
 
         R e t u r n s : 
 
                 D i c t   m a p p i n g   p a c k a g e   n a m e       i n t e l l i g e n c e   d i c t . 
 
         " " " 
 
         i f   n o t   p a c k a g e s : 
 
                 r e t u r n   { } 
 
 
 
         r e s u l t s :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ]   =   { } 
 
         s e m a p h o r e   =   a s y n c i o . S e m a p h o r e ( m a x _ c o n c u r r e n t ) 
 
 
 
         l i m i t s   =   h t t p x . L i m i t s ( m a x _ c o n n e c t i o n s = m a x _ c o n c u r r e n t ,   m a x _ k e e p a l i v e _ c o n n e c t i o n s = m a x _ c o n c u r r e n t ) 
 
         a s y n c   w i t h   h t t p x . A s y n c C l i e n t ( f o l l o w _ r e d i r e c t s = T r u e ,   l i m i t s = l i m i t s )   a s   c l i e n t : 
 
 
 
                 a s y n c   d e f   _ b o u n d e d _ f e t c h ( p k g :   s t r )   - >   T u p l e [ s t r ,   D i c t [ s t r ,   A n y ] ] : 
 
                         a s y n c   w i t h   s e m a p h o r e : 
 
                                 r e s u l t   =   a w a i t   f e t c h _ f u l l _ i n t e l l i g e n c e ( p k g ,   c l i e n t ) 
 
                                 i f   p r o g r e s s _ c a l l b a c k : 
 
                                         p r o g r e s s _ c a l l b a c k ( p k g ) 
 
                                 r e t u r n   r e s u l t 
 
 
 
                 c o r o s   =   [ _ b o u n d e d _ f e t c h ( p )   f o r   p   i n   p a c k a g e s ] 
 
                 c o m p l e t e d   =   a w a i t   a s y n c i o . g a t h e r ( * c o r o s ,   r e t u r n _ e x c e p t i o n s = T r u e ) 
 
 
 
                 f o r   o u t c o m e   i n   c o m p l e t e d : 
 
                         i f   i s i n s t a n c e ( o u t c o m e ,   E x c e p t i o n ) : 
 
                                 c o n t i n u e 
 
                         p k g ,   i n t e l   =   o u t c o m e     #   t y p e :   i g n o r e [ m i s c ] 
 
                         r e s u l t s [ p k g ]   =   i n t e l 
 
 
 
         r e t u r n   r e s u l t s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / b i s e c t . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " E m p i r i c a l   b i s e c t i o n - b a s e d   d e t e c t i o n :   u n i n s t a l l   e a c h   c a n d i d a t e ,   r u n   t e s t s ,   r e s t o r e . 
 
 
 
 T h e   " I   d o n ' t   t r u s t   s t a t i c   a n a l y s i s "   p o w e r - u s e r   m o d e .   F o r   e a c h   c a n d i d a t e   p a c k a g e : 
 
     1 .   S n a p s h o t   v e n v . 
 
     2 .   p i p   u n i n s t a l l   < c a n d i d a t e > . 
 
     3 .   R u n   t e s t   c o m m a n d . 
 
     4 .   R e c o r d :   p a s s e d   ( g e n u i n e l y   u n u s e d )   o r   f a i l e d   ( u s e d ) . 
 
     5 .   R e s t o r e   s n a p s h o t   ( A L W A Y S ) . 
 
 
 
 S l o w   ( o n e   t e s t   r u n   p e r   c a n d i d a t e )   b u t   g i v e s   g r o u n d - t r u t h   a n s w e r s . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   s h l e x 
 
 i m p o r t   s u b p r o c e s s 
 
 i m p o r t   s y s 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t ,   O p t i o n a l 
 
 
 
 f r o m   k r a i m i n d . r e m o v e . r o l l b a c k   i m p o r t   r e s t o r e _ s n a p s h o t 
 
 f r o m   k r a i m i n d . r e m o v e . s n a p s h o t   i m p o r t   S n a p s h o t ,   c r e a t e _ s n a p s h o t 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   B i s e c t F i n d i n g : 
 
         " " " P e r - c a n d i d a t e   b i s e c t i o n   f i n d i n g . " " " 
 
 
 
         p a c k a g e :   s t r 
 
         t e s t s _ p a s s e d :   b o o l 
 
         d u r a t i o n _ s e c o n d s :   f l o a t 
 
         t e s t _ o u t p u t :   s t r   =   " " 
 
 
 
         @ p r o p e r t y 
 
         d e f   s a f e _ t o _ r e m o v e ( s e l f )   - >   b o o l : 
 
                 r e t u r n   s e l f . t e s t s _ p a s s e d 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   B i s e c t R e p o r t : 
 
         " " " F u l l   b i s e c t i o n   r e p o r t . " " " 
 
 
 
         c a n d i d a t e s :   L i s t [ s t r ] 
 
         f i n d i n g s :   L i s t [ B i s e c t F i n d i n g ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
         a b o r t e d :   b o o l   =   F a l s e 
 
         e r r o r :   O p t i o n a l [ s t r ]   =   N o n e 
 
 
 
         @ p r o p e r t y 
 
         d e f   s a f e _ p a c k a g e s ( s e l f )   - >   L i s t [ s t r ] : 
 
                 r e t u r n   [ f . p a c k a g e   f o r   f   i n   s e l f . f i n d i n g s   i f   f . s a f e _ t o _ r e m o v e ] 
 
 
 
         @ p r o p e r t y 
 
         d e f   u s e d _ p a c k a g e s ( s e l f )   - >   L i s t [ s t r ] : 
 
                 r e t u r n   [ f . p a c k a g e   f o r   f   i n   s e l f . f i n d i n g s   i f   n o t   f . s a f e _ t o _ r e m o v e ] 
 
 
 
 
 
 d e f   _ r u n _ t e s t _ c m d ( p r o j e c t _ p a t h :   P a t h ,   t e s t _ c m d :   L i s t [ s t r ] ,   t i m e o u t :   f l o a t   =   6 0 0 . 0 )   - >   t u p l e [ b o o l ,   s t r ,   f l o a t ] : 
 
         " " " R u n   a   t e s t   c o m m a n d   i n   t h e   p r o j e c t ;   r e t u r n   ( p a s s e d ,   o u t p u t ,   s e c o n d s _ e l a p s e d ) . " " " 
 
         i m p o r t   t i m e 
 
 
 
         s t a r t   =   t i m e . t i m e ( ) 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         t e s t _ c m d , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = t i m e o u t , 
 
                 ) 
 
         e x c e p t   s u b p r o c e s s . T i m e o u t E x p i r e d : 
 
                 r e t u r n   F a l s e ,   " ( t e s t   c o m m a n d   t i m e d   o u t ) " ,   t i m e . t i m e ( )   -   s t a r t 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r )   a s   e : 
 
                 r e t u r n   F a l s e ,   f " ( e r r o r :   { e } ) " ,   t i m e . t i m e ( )   -   s t a r t 
 
 
 
         e l a p s e d   =   t i m e . t i m e ( )   -   s t a r t 
 
         o u t p u t   =   ( r e s u l t . s t d o u t   o r   " " )   +   ( r e s u l t . s t d e r r   o r   " " ) 
 
         r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 ,   o u t p u t ,   e l a p s e d 
 
 
 
 
 
 d e f   _ u n i n s t a l l _ o n e ( p a c k a g e :   s t r )   - >   b o o l : 
 
         " " " U n i n s t a l l   a   s i n g l e   p a c k a g e   v i a   p i p . " " " 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ s y s . e x e c u t a b l e ,   " - m " ,   " p i p " ,   " u n i n s t a l l " ,   " - y " ,   p a c k a g e ] , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 1 2 0 . 0 , 
 
                 ) 
 
                 r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ) : 
 
                 r e t u r n   F a l s e 
 
 
 
 
 
 d e f   b i s e c t _ p a c k a g e s ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         c a n d i d a t e s :   L i s t [ s t r ] , 
 
         t e s t _ c m d :   O p t i o n a l [ s t r ]   =   N o n e , 
 
         t i m e o u t :   f l o a t   =   6 0 0 . 0 , 
 
         o n _ p r o g r e s s :   O p t i o n a l [ c a l l a b l e ]   =   N o n e , 
 
 )   - >   B i s e c t R e p o r t : 
 
         " " " B i s e c t   e a c h   c a n d i d a t e :   u n i n s t a l l ,   t e s t ,   r e s t o r e . 
 
 
 
         A r g s : 
 
                 p r o j e c t _ p a t h :   P r o j e c t   r o o t . 
 
                 c a n d i d a t e s :   P a c k a g e   n a m e s   t o   t e s t   f o r   g e n u i n e   u n u s e d - n e s s . 
 
                 t e s t _ c m d :   S h e l l   c o m m a n d   ( s t r i n g )   t o   r u n   a s   t h e   t e s t   s u i t e .   D e f a u l t s   t o   " p y t e s t   - x " . 
 
                 t i m e o u t :   P e r - t e s t - r u n   t i m e o u t   i n   s e c o n d s . 
 
                 o n _ p r o g r e s s :   O p t i o n a l   c a l l b a c k   i n v o k e d   w i t h   t h e   p a c k a g e   n a m e   a f t e r   e a c h   t e s t . 
 
 
 
         R e t u r n s : 
 
                 B i s e c t R e p o r t . 
 
         " " " 
 
         c m d _ s t r   =   t e s t _ c m d   o r   " p y t e s t   - x   - - n o - h e a d e r   - q " 
 
         c m d _ l i s t   =   s h l e x . s p l i t ( c m d _ s t r ) 
 
 
 
         r e p o r t   =   B i s e c t R e p o r t ( c a n d i d a t e s = l i s t ( c a n d i d a t e s ) ) 
 
 
 
         #   S n a p s h o t   O N C E   f o r   t h e   w h o l e   b i s e c t i o n       r e s t o r e d   a f t e r   e v e r y   c a n d i d a t e . 
 
         b a s e l i n e _ s n a p s h o t :   O p t i o n a l [ S n a p s h o t ]   =   c r e a t e _ s n a p s h o t ( l a b e l = " b i s e c t - b a s e l i n e " ) 
 
         i f   b a s e l i n e _ s n a p s h o t   i s   N o n e : 
 
                 r e p o r t . a b o r t e d   =   T r u e 
 
                 r e p o r t . e r r o r   =   " F a i l e d   t o   c r e a t e   b a s e l i n e   s n a p s h o t       a b o r t i n g " 
 
                 r e t u r n   r e p o r t 
 
 
 
         #   V e r i f y   b a s e l i n e   p a s s e s 
 
         b a s e l i n e _ o k ,   _ b a s e l i n e _ o u t p u t ,   _   =   _ r u n _ t e s t _ c m d ( p r o j e c t _ p a t h ,   c m d _ l i s t ,   t i m e o u t = t i m e o u t ) 
 
         i f   n o t   b a s e l i n e _ o k : 
 
                 r e p o r t . a b o r t e d   =   T r u e 
 
                 r e p o r t . e r r o r   =   ( 
 
                         " B a s e l i n e   t e s t   r u n   f a i l e d   B E F O R E   a n y   u n i n s t a l l       " 
 
                         " f i x   y o u r   t e s t   s u i t e   f i r s t ,   t h e n   r e - r u n   b i s e c t . " 
 
                 ) 
 
                 r e t u r n   r e p o r t 
 
 
 
         f o r   p k g   i n   c a n d i d a t e s : 
 
                 i f   n o t   _ u n i n s t a l l _ o n e ( p k g ) : 
 
                         #   C o u l d n ' t   u n i n s t a l l   ( l i k e l y   n o t   i n s t a l l e d )       r e c o r d   a s   s a f e - t o - r e m o v e 
 
                         r e p o r t . f i n d i n g s . a p p e n d ( 
 
                                 B i s e c t F i n d i n g ( 
 
                                         p a c k a g e = p k g , 
 
                                         t e s t s _ p a s s e d = T r u e , 
 
                                         d u r a t i o n _ s e c o n d s = 0 . 0 , 
 
                                         t e s t _ o u t p u t = " ( p a c k a g e   n o t   i n s t a l l e d       a l r e a d y   a b s e n t ) " , 
 
                                 ) 
 
                         ) 
 
                         i f   o n _ p r o g r e s s : 
 
                                 o n _ p r o g r e s s ( p k g ) 
 
                         c o n t i n u e 
 
 
 
                 p a s s e d ,   o u t p u t ,   e l a p s e d   =   _ r u n _ t e s t _ c m d ( p r o j e c t _ p a t h ,   c m d _ l i s t ,   t i m e o u t = t i m e o u t ) 
 
                 r e p o r t . f i n d i n g s . a p p e n d ( 
 
                         B i s e c t F i n d i n g ( 
 
                                 p a c k a g e = p k g , 
 
                                 t e s t s _ p a s s e d = p a s s e d , 
 
                                 d u r a t i o n _ s e c o n d s = e l a p s e d , 
 
                                 t e s t _ o u t p u t = o u t p u t [ : 5 0 0 ] , 
 
                         ) 
 
                 ) 
 
 
 
                 #   A L W A Y S   r e s t o r e       b i s e c t   m u s t   b e   n o n - d e s t r u c t i v e 
 
                 r e s t o r e _ s n a p s h o t ( b a s e l i n e _ s n a p s h o t ) 
 
 
 
                 i f   o n _ p r o g r e s s : 
 
                         o n _ p r o g r e s s ( p k g ) 
 
 
 
         r e t u r n   r e p o r t 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / c l i . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " K r a i m i n d   C L I       A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   a s y n c i o 
 
 i m p o r t   j s o n   a s   j s o n _ l i b 
 
 i m p o r t   s y s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   O p t i o n a l 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 i m p o r t   t y p e r 
 
 f r o m   r i c h . c o n s o l e   i m p o r t   C o n s o l e 
 
 f r o m   r i c h . p a n e l   i m p o r t   P a n e l 
 
 f r o m   r i c h . p r o g r e s s   i m p o r t   ( 
 
         B a r C o l u m n , 
 
         M o f N C o m p l e t e C o l u m n , 
 
         P r o g r e s s , 
 
         S p i n n e r C o l u m n , 
 
         T a s k P r o g r e s s C o l u m n , 
 
         T e x t C o l u m n , 
 
         T i m e E l a p s e d C o l u m n , 
 
 ) 
 
 f r o m   r i c h . t e x t   i m p o r t   T e x t 
 
 
 
 #   E n a b l e   U T F - 8   m o d e   o n   W i n d o w s   s o   e m o j i / U n i c o d e   c h a r a c t e r s   r e n d e r   c o r r e c t l y 
 
 i f   s y s . p l a t f o r m   = =   " w i n 3 2 " : 
 
         i m p o r t   o s 
 
 
 
         o s . e n v i r o n . s e t d e f a u l t ( " P Y T H O N U T F 8 " ,   " 1 " ) 
 
         i f   h a s a t t r ( s y s . s t d o u t ,   " r e c o n f i g u r e " ) : 
 
                 t r y : 
 
                         s y s . s t d o u t . r e c o n f i g u r e ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " r e p l a c e " )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
                 e x c e p t   E x c e p t i o n : 
 
                         p a s s 
 
         i f   h a s a t t r ( s y s . s t d e r r ,   " r e c o n f i g u r e " ) : 
 
                 t r y : 
 
                         s y s . s t d e r r . r e c o n f i g u r e ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " r e p l a c e " )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
                 e x c e p t   E x c e p t i o n : 
 
                         p a s s 
 
 
 
 f r o m   k r a i m i n d   i m p o r t   _ _ v e r s i o n _ _ 
 
 f r o m   k r a i m i n d . a i . e x p l a i n e r   i m p o r t   g e n e r a t e _ e x p l a n a t i o n 
 
 f r o m   k r a i m i n d . a l t e r n a t i v e s   i m p o r t   g e t _ a l t e r n a t i v e s 
 
 f r o m   k r a i m i n d . a r c h i t e c t   i m p o r t   a n a l y z e _ d e p l o y m e n t 
 
 f r o m   k r a i m i n d . a s y n c _ c l i e n t s   i m p o r t   f e t c h _ a l l _ p a c k a g e s ,   f e t c h _ f u l l _ i n t e l l i g e n c e 
 
 f r o m   k r a i m i n d . b i s e c t   i m p o r t   b i s e c t _ p a c k a g e s 
 
 f r o m   k r a i m i n d . c o s t   i m p o r t   c o m p u t e _ c o s t _ r e p o r t ,   f o r m a t _ c o s t _ r e p o r t 
 
 f r o m   k r a i m i n d . d e t e c t i o n   i m p o r t   s c o r e _ a l l _ p a c k a g e s 
 
 f r o m   k r a i m i n d . m i g r a t e   i m p o r t   ( 
 
         a p p l y _ m i g r a t i o n , 
 
         g e t _ r e c i p e , 
 
         p r e v i e w _ m i g r a t i o n , 
 
 ) 
 
 f r o m   k r a i m i n d . m i g r a t e . a i _ r e w r i t e r   i m p o r t   g e n e r a t e _ a i _ r e c i p e 
 
 f r o m   k r a i m i n d . m i g r a t e . d i f f _ p r e v i e w   i m p o r t   r e n d e r _ m i g r a t i o n _ p r e v i e w 
 
 f r o m   k r a i m i n d . p a r s e r   i m p o r t   ( 
 
         d e t e c t _ l o c k f i l e , 
 
         g e t _ d e c l a r e d _ d e p e n d e n c i e s , 
 
         g e t _ l o c k f i l e _ i n f o , 
 
         m a p _ i m p o r t s _ t o _ p a c k a g e s , 
 
         s c a n _ p r o j e c t _ i m p o r t s , 
 
 ) 
 
 f r o m   k r a i m i n d . r e m o v e   i m p o r t   ( 
 
         e x e c u t e _ r e m o v a l , 
 
         l i s t _ s n a p s h o t s , 
 
         p l a n _ r e m o v a l , 
 
         r e s t o r e _ s n a p s h o t , 
 
 ) 
 
 f r o m   k r a i m i n d . h a n d o f f   i m p o r t   ( 
 
         b u i l d _ h a n d o f f _ p r o m p t , 
 
         c o p y _ t o _ c l i p b o a r d , 
 
         g a t h e r _ g i t _ c o n t e x t , 
 
 ) 
 
 f r o m   k r a i m i n d . s h a r e   i m p o r t   ( 
 
         E x c l u d e d F i l e , 
 
         S h a r e U p l o a d E r r o r , 
 
         b u i l d _ b u n d l e , 
 
         u p l o a d _ b u n d l e , 
 
 ) 
 
 f r o m   k r a i m i n d . s u p p l y _ c h a i n   i m p o r t   a s s e s s _ a l l 
 
 f r o m   k r a i m i n d . t r u s t   i m p o r t   c a l c u l a t e _ t r u s t _ s c o r e 
 
 f r o m   k r a i m i n d . u t i l s . c a c h e   i m p o r t   c a c h e _ i n f o ,   c l e a r _ c a c h e 
 
 f r o m   k r a i m i n d . u t i l s . c o n f i g   i m p o r t   ( 
 
         K N O W N _ K E Y S , 
 
         c o n f i g _ p a t h , 
 
         g e t _ k e y , 
 
         l i s t _ k e y s , 
 
         s e t _ k e y , 
 
         u n s e t _ k e y , 
 
 ) 
 
 f r o m   k r a i m i n d . u t i l s . f o r m a t t i n g   i m p o r t   ( 
 
         b a n n e r , 
 
         f o r m a t _ a l t e r n a t i v e s , 
 
         f o r m a t _ c o m p a r e , 
 
         f o r m a t _ h e a l t h _ s u m m a r y , 
 
         f o r m a t _ p a c k a g e _ d e t a i l , 
 
         f o r m a t _ s i z e , 
 
         f o r m a t _ t r u s t _ r e p o r t , 
 
         f o r m a t _ u n u s e d _ d e p s , 
 
         f o r m a t _ v u l n e r a b i l i t i e s , 
 
         s c o r e _ c o l o r , 
 
 ) 
 
 f r o m   k r a i m i n d . w i z a r d   i m p o r t   r u n _ w i z a r d 
 
 
 
 a p p   =   t y p e r . T y p e r ( 
 
         h e l p = " K r a i m i n d :   A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e   f o r   d e v e l o p e r s " , 
 
         a d d _ c o m p l e t i o n = F a l s e , 
 
         i n v o k e _ w i t h o u t _ c o m m a n d = T r u e , 
 
         r i c h _ m a r k u p _ m o d e = " r i c h " , 
 
 ) 
 
 
 
 #   S u b c o m m a n d   f o r   c a c h e   m a n a g e m e n t 
 
 c a c h e _ a p p   =   t y p e r . T y p e r ( 
 
         h e l p = " M a n a g e   K r a i m i n d ' s   l o c a l   A P I   c a c h e . " , 
 
         n o _ a r g s _ i s _ h e l p = T r u e , 
 
 ) 
 
 a p p . a d d _ t y p e r ( c a c h e _ a p p ,   n a m e = " c a c h e " ) 
 
 
 
 #   S u b c o m m a n d   f o r   c o n f i g   /   A P I   k e y   m a n a g e m e n t 
 
 c o n f i g _ a p p   =   t y p e r . T y p e r ( 
 
         h e l p = " S e t   a n d   m a n a g e   A P I   k e y s   f o r   K r a i m i n d   A I   f e a t u r e s . " , 
 
         n o _ a r g s _ i s _ h e l p = T r u e , 
 
 ) 
 
 a p p . a d d _ t y p e r ( c o n f i g _ a p p ,   n a m e = " c o n f i g " ) 
 
 
 
 c o n s o l e   =   C o n s o l e ( h i g h l i g h t = F a l s e ) 
 
 
 
 
 
 d e f   _ v e r s i o n _ c a l l b a c k ( v a l u e :   b o o l )   - >   N o n e : 
 
         i f   v a l u e : 
 
                 c o n s o l e . p r i n t ( f " K r a i m i n d   { _ _ v e r s i o n _ _ } " ) 
 
                 r a i s e   t y p e r . E x i t ( ) 
 
 
 
 
 
 @ a p p . c a l l b a c k ( i n v o k e _ w i t h o u t _ c o m m a n d = T r u e ) 
 
 d e f   m a i n ( 
 
         c t x :   t y p e r . C o n t e x t , 
 
         v e r s i o n :   b o o l   =   t y p e r . O p t i o n ( 
 
                 F a l s e , 
 
                 " - - v e r s i o n " , 
 
                 " - V " , 
 
                 h e l p = " S h o w   v e r s i o n   a n d   e x i t . " , 
 
                 c a l l b a c k = _ v e r s i o n _ c a l l b a c k , 
 
                 i s _ e a g e r = T r u e , 
 
         ) , 
 
 )   - >   N o n e : 
 
         " " " K r a i m i n d :   A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e   f o r   d e v e l o p e r s . " " " 
 
         i f   c t x . i n v o k e d _ s u b c o m m a n d   i s   N o n e : 
 
                 f r o m   k r a i m i n d . r e p l   i m p o r t   s t a r t _ i n t e r a c t i v e _ r e p l 
 
                 s t a r t _ i n t e r a c t i v e _ r e p l ( ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   H e l p e r :   b u i l d   p e r - p a c k a g e   r e p o r t   f r o m   r a w   i n t e l l i g e n c e 
 
 #                                                                                                                                                               
 
 
 
 d e f   _ b u i l d _ r e p o r t ( p k g :   s t r ,   i n t e l :   D i c t [ s t r ,   A n y ] ,   u n u s e d :   b o o l   =   F a l s e )   - >   D i c t [ s t r ,   A n y ] : 
 
         " " " C o n v e r t   r a w   i n t e l l i g e n c e   d i c t   i n t o   a   f u l l   r e p o r t   w i t h   t r u s t   s c o r e . " " " 
 
         p y p i   =   i n t e l . g e t ( " p y p i " )   o r   { } 
 
         g h   =   i n t e l . g e t ( " g i t h u b " )   o r   { } 
 
         v u l n s   =   i n t e l . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] 
 
         s c o r e ,   p o s i t i v e s ,   c o n c e r n s   =   c a l c u l a t e _ t r u s t _ s c o r e ( g h ,   p y p i ,   v u l n s ) 
 
         r e t u r n   { 
 
                 " s c o r e " :   s c o r e , 
 
                 " p o s i t i v e s " :   p o s i t i v e s , 
 
                 " c o n c e r n s " :   c o n c e r n s , 
 
                 " g i t h u b " :   g h , 
 
                 " p y p i " :   p y p i , 
 
                 " v u l n e r a b i l i t i e s " :   v u l n s , 
 
                 " u n u s e d " :   u n u s e d , 
 
         } 
 
 
 
 
 
 d e f   _ f e t c h _ w i t h _ p r o g r e s s ( 
 
         p k g _ l i s t :   l i s t [ s t r ] , 
 
         c o n c u r r e n c y :   i n t , 
 
         s h o w _ p r o g r e s s :   b o o l , 
 
 )   - >   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] : 
 
         " " " R u n   f e t c h _ a l l _ p a c k a g e s       w i t h   a   l i v e   p r o g r e s s   b a r   w h e n   s h o w _ p r o g r e s s   i s   T r u e . " " " 
 
         i f   n o t   s h o w _ p r o g r e s s : 
 
                 r e t u r n   a s y n c i o . r u n ( f e t c h _ a l l _ p a c k a g e s ( p k g _ l i s t ,   m a x _ c o n c u r r e n t = c o n c u r r e n c y ) ) 
 
 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] F e t c h i n g   i n t e l l i g e n c e . . . [ / ] " ) , 
 
                 B a r C o l u m n ( b a r _ w i d t h = 4 0 ) , 
 
                 M o f N C o m p l e t e C o l u m n ( ) , 
 
                 T a s k P r o g r e s s C o l u m n ( ) , 
 
                 T i m e E l a p s e d C o l u m n ( ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p : 
 
                 t a s k _ i d   =   p . a d d _ t a s k ( " f e t c h " ,   t o t a l = l e n ( p k g _ l i s t ) ) 
 
 
 
                 d e f   _ o n _ d o n e ( _ p k g :   s t r )   - >   N o n e : 
 
                         p . a d v a n c e ( t a s k _ i d ,   1 ) 
 
 
 
                 r e t u r n   a s y n c i o . r u n ( 
 
                         f e t c h _ a l l _ p a c k a g e s ( p k g _ l i s t ,   m a x _ c o n c u r r e n t = c o n c u r r e n c y ,   p r o g r e s s _ c a l l b a c k = _ o n _ d o n e ) 
 
                 ) 
 
 
 
 
 
 d e f   _ s e r i a l i z e _ r e p o r t ( r e p o r t :   D i c t [ s t r ,   A n y ] )   - >   D i c t [ s t r ,   A n y ] : 
 
         " " " S t r i p   d o w n   r e p o r t   f o r   J S O N   o u t p u t   ( l i g h t e r ,   n o   R i c h   o b j e c t s ) . " " " 
 
         p y p i   =   r e p o r t . g e t ( " p y p i " )   o r   { } 
 
         g h   =   r e p o r t . g e t ( " g i t h u b " )   o r   { } 
 
         r e t u r n   { 
 
                 " s c o r e " :   r e p o r t . g e t ( " s c o r e " ) , 
 
                 " p o s i t i v e s " :   r e p o r t . g e t ( " p o s i t i v e s " ,   [ ] ) , 
 
                 " c o n c e r n s " :   r e p o r t . g e t ( " c o n c e r n s " ,   [ ] ) , 
 
                 " u n u s e d " :   r e p o r t . g e t ( " u n u s e d " ,   F a l s e ) , 
 
                 " v e r s i o n " :   p y p i . g e t ( " v e r s i o n " ) , 
 
                 " s u m m a r y " :   p y p i . g e t ( " s u m m a r y " ) , 
 
                 " l i c e n s e " :   p y p i . g e t ( " l i c e n s e " ) , 
 
                 " r e p o _ u r l " :   p y p i . g e t ( " r e p o _ u r l " ) , 
 
                 " r e l e a s e _ s i z e _ b y t e s " :   p y p i . g e t ( " r e l e a s e _ s i z e _ b y t e s " ) , 
 
                 " g i t h u b " :   { 
 
                         " s t a r s " :   g h . g e t ( " s t a r s " ) , 
 
                         " f o r k s " :   g h . g e t ( " f o r k s " ) , 
 
                         " o p e n _ i s s u e s " :   g h . g e t ( " o p e n _ i s s u e s " ) , 
 
                         " l a s t _ p u s h " :   g h . g e t ( " l a s t _ p u s h " ) , 
 
                         " a r c h i v e d " :   g h . g e t ( " a r c h i v e d " ) , 
 
                 }   i f   g h   e l s e   N o n e , 
 
                 " v u l n e r a b i l i t i e s " :   [ 
 
                         { 
 
                                 " i d " :   v . g e t ( " i d " ) , 
 
                                 " s e v e r i t y " :   v . g e t ( " s e v e r i t y " ) , 
 
                                 " s u m m a r y " :   v . g e t ( " s u m m a r y " ) , 
 
                                 " f i x e d _ v e r s i o n s " :   v . g e t ( " f i x e d _ v e r s i o n s " ) , 
 
                         } 
 
                         f o r   v   i n   ( r e p o r t . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] ) 
 
                 ] , 
 
         } 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   h e l l o 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   h e l l o ( )   - >   N o n e : 
 
         " " " V e r i f y   y o u r   K r a i m i n d   i n s t a l l a t i o n   i s   w o r k i n g   c o r r e c t l y . " " " 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l . f i t ( 
 
                         f " [ b o l d   g r e e n ]     K r a i m i n d   v { _ _ v e r s i o n _ _ } [ / ]   i s   i n s t a l l e d   a n d   r e a d y ! \ n \ n " 
 
                         " [ c y a n ] Q u i c k   s t a r t : [ / ] \ n " 
 
                         "     [ b o l d ] k r a i m i n d   a n a l y z e [ / ]                             a n a l y z e   c u r r e n t   p r o j e c t \ n " 
 
                         "     [ b o l d ] k r a i m i n d   a n a l y z e   . / p a t h [ / ]               a n a l y z e   a   s p e c i f i c   p r o j e c t \ n " 
 
                         "     [ b o l d ] k r a i m i n d   e x p l a i n   r e q u e s t s [ / ]           i n s p e c t   a   p a c k a g e \ n " 
 
                         "     [ b o l d ] k r a i m i n d   c o m p a r e   a   b [ / ]                     c o m p a r e   t w o   p a c k a g e s \ n " 
 
                         "     [ b o l d ] k r a i m i n d   d o c t o r [ / ]                               f u l l   h e a l t h   r e p o r t \ n " 
 
                         "     [ b o l d ] k r a i m i n d   c a c h e   i n f o [ / ]                       c a c h e   s t a t s \ n " 
 
                         "     [ b o l d ] k r a i m i n d   - - h e l p [ / ]                               a l l   c o m m a n d s \ n \ n " 
 
                         " [ g r e y 5 0 ] P o w e r - u s e r   f l a g s : [ / ] \ n " 
 
                         "     [ b o l d ] - - f o r m a t   j s o n [ / ]       m a c h i n e - r e a d a b l e   o u t p u t   f o r   C I / C D \ n " 
 
                         "     [ b o l d ] - - n o - a i [ / ]                   d i s a b l e   A I   i n s i g h t s \ n \ n " 
 
                         " [ g r e y 5 0 ] O p t i o n a l   A I : [ / ] \ n " 
 
                         "     e x p o r t   O P E N A I _ A P I _ K E Y = . . .           c l o u d   A I   i n s i g h t s \ n " 
 
                         "     e x p o r t   G R O Q _ A P I _ K E Y = . . .               f a s t   f r e e   A I   i n s i g h t s \ n " 
 
                         "     o l l a m a   p u l l   l l a m a 3 . 2                     l o c a l   p r i v a t e   A I " , 
 
                         t i t l e = " [ b o l d   c y a n ] K r a i m i n d [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e e n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   a n a l y z e 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   a n a l y z e ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P a t h   t o   p r o j e c t   d i r e c t o r y   t o   a n a l y z e . " ) , 
 
         f o r m a t :   s t r   =   t y p e r . O p t i o n ( " t e x t " ,   " - - f o r m a t " ,   " - f " ,   h e l p = " O u t p u t   f o r m a t :   t e x t   o r   j s o n . " ) , 
 
         n o _ a i :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - n o - a i " ,   h e l p = " D i s a b l e   A I   e x p l a n a t i o n s . " ) , 
 
         c o n c u r r e n c y :   i n t   =   t y p e r . O p t i o n ( 1 0 ,   " - - c o n c u r r e n c y " ,   " - c " ,   h e l p = " M a x   p a r a l l e l   A P I   r e q u e s t s . " ) , 
 
 )   - >   N o n e : 
 
         " " " A n a l y z e   p r o j e c t   d e p e n d e n c i e s       u n u s e d ,   t r u s t   s c o r e s ,   C V E s ,   a l t e r n a t i v e s . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( )   o r   n o t   p r o j e c t _ p a t h . i s _ d i r ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         i s _ j s o n   =   f o r m a t . l o w e r ( )   = =   " j s o n " 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
                 c o n s o l e . p r i n t ( ) 
 
                 c o n s o l e . p r i n t ( f " [ b o l d ] a"    A n a l y z i n g [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         #         S t e p   1 :   P a r s e   m a n i f e s t s   +   l o c k f i l e                                                                   
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         l o c k f i l e _ p a t h   =   d e t e c t _ l o c k f i l e ( p r o j e c t _ p a t h ) 
 
 
 
         #   I f   a   l o c k f i l e   e x i s t s ,   p r e f e r   i t s   c o m p l e t e   d e p   l i s t   ( c a t c h e s   t r a n s i t i v e   d e p s   t o o ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         i f   n o t   d e c l a r e d : 
 
                 i f   i s _ j s o n : 
 
                         p r i n t ( j s o n _ l i b . d u m p s ( { " e r r o r " :   " n o _ m a n i f e s t s " ,   " p a t h " :   s t r ( p r o j e c t _ p a t h ) } ) ) 
 
                 e l s e : 
 
                         c o n s o l e . p r i n t ( 
 
                                 P a n e l ( 
 
                                         " [ y e l l o w ] N o   d e p e n d e n c y   m a n i f e s t s   f o u n d . [ / ] \ n \ n " 
 
                                         " K r a i m i n d   l o o k s   f o r :   [ b o l d ] r e q u i r e m e n t s . t x t [ / ] ,   [ b o l d ] p y p r o j e c t . t o m l [ / ] ,   " 
 
                                         " [ b o l d ] p a c k a g e . j s o n [ / ] ,   [ b o l d ] p o e t r y . l o c k [ / ] ,   [ b o l d ] P i p f i l e . l o c k [ / ] ,   [ b o l d ] u v . l o c k [ / ] " , 
 
                                         t i t l e = " [ b o l d   y e l l o w ]     N o t h i n g   t o   a n a l y z e [ / ] " , 
 
                                         b o r d e r _ s t y l e = " y e l l o w " , 
 
                                 ) 
 
                         ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   F o u n d   [ b o l d ] { l e n ( d e c l a r e d ) } [ / ]   d e c l a r e d   d e p e n d e n c i e s " ) 
 
                 i f   l o c k f i l e _ p a t h : 
 
                         c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   L o c k f i l e   d e t e c t e d :   [ c y a n ] { l o c k f i l e _ p a t h . n a m e } [ / ] " ) 
 
 
 
         #         S t e p   2 :   A S T   i m p o r t   s c a n                                                                                         
 
         r a w _ i m p o r t s   =   s c a n _ p r o j e c t _ i m p o r t s ( p r o j e c t _ p a t h ) 
 
         u s e d _ p a c k a g e s   =   m a p _ i m p o r t s _ t o _ p a c k a g e s ( r a w _ i m p o r t s ) 
 
         u n u s e d   =   d e c l a r e d   -   u s e d _ p a c k a g e s 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   D e t e c t e d   [ b o l d ] { l e n ( r a w _ i m p o r t s ) } [ / ]   u n i q u e   i m p o r t s   i n   s o u r c e " ) 
 
 
 
         #         S t e p   3 :   P a r a l l e l   i n t e l l i g e n c e   f e t c h                                                                 
 
         p k g _ l i s t   =   s o r t e d ( d e c l a r e d ) 
 
 
 
         i n t e l _ m a p   =   _ f e t c h _ w i t h _ p r o g r e s s ( p k g _ l i s t ,   c o n c u r r e n c y ,   s h o w _ p r o g r e s s = n o t   i s _ j s o n ) 
 
 
 
         r e p o r t s :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ]   =   { } 
 
         f o r   p k g   i n   p k g _ l i s t : 
 
                 i n t e l   =   i n t e l _ m a p . g e t ( p k g ,   { } ) 
 
                 r e p o r t s [ p k g ]   =   _ b u i l d _ r e p o r t ( p k g ,   i n t e l ,   u n u s e d = p k g   i n   u n u s e d ) 
 
 
 
         #         J S O N   o u t p u t                                                                                                                 
 
         i f   i s _ j s o n : 
 
                 o u t p u t   =   { 
 
                         " p r o j e c t " :   s t r ( p r o j e c t _ p a t h ) , 
 
                         " s u m m a r y " :   { 
 
                                 " t o t a l _ d e p e n d e n c i e s " :   l e n ( d e c l a r e d ) , 
 
                                 " u n u s e d _ c o u n t " :   l e n ( u n u s e d ) , 
 
                                 " u s e d _ c o u n t " :   l e n ( d e c l a r e d )   -   l e n ( u n u s e d ) , 
 
                                 " a v e r a g e _ t r u s t _ s c o r e " :   ( 
 
                                         s u m ( r [ " s c o r e " ]   f o r   r   i n   r e p o r t s . v a l u e s ( ) )   /   l e n ( r e p o r t s )   i f   r e p o r t s   e l s e   0 
 
                                 ) , 
 
                         } , 
 
                         " u n u s e d _ d e p e n d e n c i e s " :   s o r t e d ( u n u s e d ) , 
 
                         " r e p o r t s " :   { p k g :   _ s e r i a l i z e _ r e p o r t ( r )   f o r   p k g ,   r   i n   r e p o r t s . i t e m s ( ) } , 
 
                 } 
 
                 p r i n t ( j s o n _ l i b . d u m p s ( o u t p u t ,   i n d e n t = 2 ,   d e f a u l t = s t r ) ) 
 
                 r e t u r n 
 
 
 
         #         T e x t   o u t p u t                                                                                                                 
 
         c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   I n t e l l i g e n c e   g a t h e r e d   f o r   [ b o l d ] { l e n ( r e p o r t s ) } [ / ]   p a c k a g e s \ n " ) 
 
 
 
         c o n s o l e . p r i n t ( f o r m a t _ u n u s e d _ d e p s ( u n u s e d ,   r e p o r t s ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f o r m a t _ t r u s t _ r e p o r t ( r e p o r t s ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
 
 
         #   V u l n e r a b i l i t i e s   s u m m a r y 
 
         p k g s _ w i t h _ v u l n s   =   [ ( p k g ,   r )   f o r   p k g ,   r   i n   r e p o r t s . i t e m s ( )   i f   r . g e t ( " v u l n e r a b i l i t i e s " ) ] 
 
         i f   p k g s _ w i t h _ v u l n s : 
 
                 v u l n _ t e x t   =   T e x t ( ) 
 
                 v u l n _ t e x t . a p p e n d ( f " F o u n d   v u l n e r a b i l i t i e s   i n   { l e n ( p k g s _ w i t h _ v u l n s ) }   p a c k a g e ( s ) : \ n \ n " ,   s t y l e = " b o l d   r e d " ) 
 
                 f o r   p k g ,   r   i n   p k g s _ w i t h _ v u l n s [ : 5 ] : 
 
                         c o u n t   =   l e n ( r [ " v u l n e r a b i l i t i e s " ] ) 
 
                         h i g h e s t   =   m a x ( 
 
                                 ( v . g e t ( " s e v e r i t y " ,   " U N K N O W N " )   f o r   v   i n   r [ " v u l n e r a b i l i t i e s " ] ) , 
 
                                 d e f a u l t = " U N K N O W N " , 
 
                         ) 
 
                         v u l n _ t e x t . a p p e n d ( f "         { p k g } " ,   s t y l e = " b o l d " ) 
 
                         v u l n _ t e x t . a p p e n d ( f "       { c o u n t }   v u l n e r a b i l i t y { ' i e s '   i f   c o u n t   >   1   e l s e   ' y ' }   " ,   s t y l e = " g r e y 7 0 " ) 
 
                         v u l n _ t e x t . a p p e n d ( f " ( { h i g h e s t } ) \ n " ,   s t y l e = " r e d " ) 
 
                 v u l n _ t e x t . a p p e n d ( 
 
                         f " \ n R u n   [ b o l d ] k r a i m i n d   e x p l a i n   < p a c k a g e > [ / ]   f o r   d e t a i l s   o n   e a c h . " , 
 
                         s t y l e = " g r e y 5 0 " , 
 
                 ) 
 
                 c o n s o l e . p r i n t ( 
 
                         P a n e l ( 
 
                                 v u l n _ t e x t , 
 
                                 t i t l e = " [ b o l d   r e d ] a"    S e c u r i t y   A l e r t s [ / ] " , 
 
                                 b o r d e r _ s t y l e = " r e d " , 
 
                                 p a d d i n g = ( 1 ,   2 ) , 
 
                         ) 
 
                 ) 
 
                 c o n s o l e . p r i n t ( ) 
 
 
 
         #   A l t e r n a t i v e s   s u g g e s t i o n s 
 
         a l t _ s u g g e s t i o n s   =   [ ] 
 
         f o r   p k g   i n   d e c l a r e d : 
 
                 e n t r y   =   g e t _ a l t e r n a t i v e s ( p k g ) 
 
                 i f   e n t r y : 
 
                         a l t _ s u g g e s t i o n s . a p p e n d ( ( p k g ,   e n t r y ) ) 
 
 
 
         i f   a l t _ s u g g e s t i o n s : 
 
                 a l t _ t e x t   =   T e x t ( ) 
 
                 f o r   p k g ,   e n t r y   i n   a l t _ s u g g e s t i o n s [ : 5 ] : 
 
                         s e v e r i t y   =   e n t r y . g e t ( " s e v e r i t y " ,   " i n f o " ) 
 
                         e m o j i   =   { " d e p r e c a t e d " :   "   " ,   " s u g g e s t " :   " a"  " ,   " i n f o " :   " a"  " } . g e t ( s e v e r i t y ,   " a"  " ) 
 
                         a l t _ t e x t . a p p e n d ( f "     { e m o j i }   " ,   s t y l e = " b o l d " ) 
 
                         a l t _ t e x t . a p p e n d ( f " { p k g } " ,   s t y l e = " b o l d   c y a n " ) 
 
                         a l t _ t e x t . a p p e n d ( f "       " ,   s t y l e = " g r e y 5 0 " ) 
 
                         a l t s   =   " ,   " . j o i n ( a [ " n a m e " ]   f o r   a   i n   e n t r y [ " a l t e r n a t i v e s " ] [ : 2 ] ) 
 
                         a l t _ t e x t . a p p e n d ( f " { a l t s } \ n " ,   s t y l e = " g r e e n " ) 
 
                 a l t _ t e x t . a p p e n d ( 
 
                         f " \ n R u n   [ b o l d ] k r a i m i n d   e x p l a i n   < p a c k a g e > [ / ]   f o r   f u l l   a l t e r n a t i v e s . " , 
 
                         s t y l e = " g r e y 5 0 " , 
 
                 ) 
 
                 c o n s o l e . p r i n t ( 
 
                         P a n e l ( 
 
                                 a l t _ t e x t , 
 
                                 t i t l e = " [ b o l d ] a"    M i g r a t i o n   O p p o r t u n i t i e s [ / ] " , 
 
                                 b o r d e r _ s t y l e = " c y a n " , 
 
                                 p a d d i n g = ( 1 ,   2 ) , 
 
                         ) 
 
                 ) 
 
                 c o n s o l e . p r i n t ( ) 
 
 
 
         #   R e c o m m e n d a t i o n s 
 
         l o w _ t r u s t   =   [ p   f o r   p ,   r   i n   r e p o r t s . i t e m s ( )   i f   r [ " s c o r e " ]   <   5 0 ] 
 
         t i p s   =   [ ] 
 
         i f   u n u s e d : 
 
                 p k g _ l i s t _ s t r   =   "   " . j o i n ( s o r t e d ( u n u s e d ) ) 
 
                 t i p s . a p p e n d ( f "     R e m o v e   u n u s e d :   [ b o l d ] p i p   u n i n s t a l l   { p k g _ l i s t _ s t r } [ / ] " ) 
 
         i f   l o w _ t r u s t : 
 
                 t i p s . a p p e n d ( f "     R e v i e w   l o w - t r u s t   p a c k a g e s :   [ b o l d ] { ' ,   ' . j o i n ( s o r t e d ( l o w _ t r u s t ) ) } [ / ] " ) 
 
         i f   p k g s _ w i t h _ v u l n s : 
 
                 t i p s . a p p e n d ( f "     P a t c h   v u l n e r a b i l i t i e s :   [ b o l d ] k r a i m i n d   e x p l a i n   < p a c k a g e > [ / ] " ) 
 
         t i p s . a p p e n d ( "     C o m p a r e   o p t i o n s :   [ b o l d ] k r a i m i n d   c o m p a r e   p k g - a   p k g - b [ / ] " ) 
 
         t i p s . a p p e n d ( "     M a c h i n e - r e a d a b l e   o u t p u t :   [ b o l d ] k r a i m i n d   a n a l y z e   - - f o r m a t   j s o n [ / ] " ) 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         " \ n " . j o i n ( t i p s ) , 
 
                         t i t l e = " [ b o l d ] a"    R e c o m m e n d a t i o n s [ / ] " , 
 
                         b o r d e r _ s t y l e = " b l u e " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   e x p l a i n 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   e x p l a i n ( 
 
         p a c k a g e :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " P a c k a g e   n a m e   t o   e x p l a i n   ( e . g .   ' r e q u e s t s ' ) . " ) , 
 
         n o _ a i :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - n o - a i " ,   h e l p = " D i s a b l e   A I - g e n e r a t e d   i n s i g h t s . " ) , 
 
 )   - >   N o n e : 
 
         " " " G e t   a n   i n t e l l i g e n t   e x p l a n a t i o n ,   t r u s t   r e p o r t ,   C V E s ,   a n d   a l t e r n a t i v e s   f o r   a   p a c k a g e . " " " 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"    I n s p e c t i n g [ / ]   [ c y a n ] { p a c k a g e } [ / ]   \ n " ) 
 
 
 
         a s y n c   d e f   _ d o _ f e t c h ( )   - >   D i c t [ s t r ,   A n y ] : 
 
                 a s y n c   w i t h   h t t p x . A s y n c C l i e n t ( f o l l o w _ r e d i r e c t s = T r u e )   a s   c l i e n t : 
 
                         _ ,   i n t e l   =   a w a i t   f e t c h _ f u l l _ i n t e l l i g e n c e ( p a c k a g e ,   c l i e n t ) 
 
                         r e t u r n   i n t e l 
 
 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] F e t c h i n g   P y P I   +   G i t H u b   +   O S V   [ / ] " ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p : 
 
                 p . a d d _ t a s k ( " f e t c h " ,   t o t a l = N o n e ) 
 
                 i n t e l   =   a s y n c i o . r u n ( _ d o _ f e t c h ( ) ) 
 
 
 
         p y p i   =   i n t e l . g e t ( " p y p i " )   o r   { } 
 
         g h   =   i n t e l . g e t ( " g i t h u b " )   o r   { } 
 
         v u l n s   =   i n t e l . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] 
 
 
 
         i f   n o t   p y p i   a n d   n o t   g h : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   C o u l d   n o t   f i n d   m e t a d a t a   f o r   ' { p a c k a g e } ' . " ) 
 
                 c o n s o l e . p r i n t ( "         C h e c k   t h e   p a c k a g e   n a m e   s p e l l i n g " ) 
 
                 c o n s o l e . p r i n t ( "         T h e   p a c k a g e   m a y   n o t   e x i s t   o n   P y P I " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         s c o r e ,   p o s i t i v e s ,   c o n c e r n s   =   c a l c u l a t e _ t r u s t _ s c o r e ( g h ,   p y p i ,   v u l n s ) 
 
         m e t a d a t a   =   { " g i t h u b " :   g h ,   " p y p i " :   p y p i } 
 
 
 
         #   D e t a i l e d   i n f o   p a n e l 
 
         c o n s o l e . p r i n t ( f o r m a t _ p a c k a g e _ d e t a i l ( p a c k a g e ,   s c o r e ,   p o s i t i v e s ,   c o n c e r n s ,   p y p i ,   g h ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
 
 
         #   V u l n e r a b i l i t i e s 
 
         v u l n _ p a n e l   =   f o r m a t _ v u l n e r a b i l i t i e s ( v u l n s ) 
 
         i f   v u l n _ p a n e l : 
 
                 c o n s o l e . p r i n t ( v u l n _ p a n e l ) 
 
                 c o n s o l e . p r i n t ( ) 
 
 
 
         #   A l t e r n a t i v e s 
 
         a l t _ e n t r y   =   g e t _ a l t e r n a t i v e s ( p a c k a g e ) 
 
         i f   a l t _ e n t r y : 
 
                 a l t _ p a n e l   =   f o r m a t _ a l t e r n a t i v e s ( p a c k a g e ,   a l t _ e n t r y ) 
 
                 i f   a l t _ p a n e l : 
 
                         c o n s o l e . p r i n t ( a l t _ p a n e l ) 
 
                         c o n s o l e . p r i n t ( ) 
 
 
 
         #   A I   /   r u l e - b a s e d   e x p l a n a t i o n 
 
         e x p l a n a t i o n   =   g e n e r a t e _ e x p l a n a t i o n ( 
 
                 p a c k a g e = p a c k a g e , 
 
                 m e t a d a t a = m e t a d a t a , 
 
                 t r u s t _ s c o r e = s c o r e , 
 
                 p o s i t i v e s = p o s i t i v e s , 
 
                 c o n c e r n s = c o n c e r n s , 
 
                 u s e _ a i = n o t   n o _ a i , 
 
         ) 
 
         c o l o r   =   s c o r e _ c o l o r ( s c o r e ) 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         e x p l a n a t i o n , 
 
                         t i t l e = f " [ b o l d ] a"    P a c k a g e   A n a l y s i s :   { p a c k a g e } [ / ] " , 
 
                         b o r d e r _ s t y l e = c o l o r , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   c o m p a r e 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   c o m p a r e ( 
 
         p a c k a g e _ a :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " F i r s t   p a c k a g e . " ) , 
 
         p a c k a g e _ b :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " S e c o n d   p a c k a g e . " ) , 
 
         f o r m a t :   s t r   =   t y p e r . O p t i o n ( " t e x t " ,   " - - f o r m a t " ,   " - f " ,   h e l p = " O u t p u t   f o r m a t :   t e x t   o r   j s o n . " ) , 
 
 )   - >   N o n e : 
 
         " " " S i d e - b y - s i d e   c o m p a r i s o n   o f   t w o   p a c k a g e s       t r u s t ,   s t a t s ,   C V E s ,   l i c e n s e . " " " 
 
 
 
         i s _ j s o n   =   f o r m a t . l o w e r ( )   = =   " j s o n " 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
                 c o n s o l e . p r i n t ( ) 
 
                 c o n s o l e . p r i n t ( f " [ b o l d ]   )"U%     C o m p a r i n g [ / ]   [ c y a n ] { p a c k a g e _ a } [ / ]   [ b o l d ] v s [ / ]   [ m a g e n t a ] { p a c k a g e _ b } [ / ] \ n " ) 
 
 
 
         i n t e l   =   a s y n c i o . r u n ( f e t c h _ a l l _ p a c k a g e s ( [ p a c k a g e _ a ,   p a c k a g e _ b ] ,   m a x _ c o n c u r r e n t = 2 ) ) 
 
 
 
         i n t e l _ a   =   i n t e l . g e t ( p a c k a g e _ a ,   { } ) 
 
         i n t e l _ b   =   i n t e l . g e t ( p a c k a g e _ b ,   { } ) 
 
 
 
         i f   n o t   i n t e l _ a . g e t ( " p y p i " )   a n d   n o t   i n t e l _ b . g e t ( " p y p i " ) : 
 
                 i f   i s _ j s o n : 
 
                         p r i n t ( j s o n _ l i b . d u m p s ( { " e r r o r " :   " b o t h _ p a c k a g e s _ n o t _ f o u n d " } ) ) 
 
                 e l s e : 
 
                         c o n s o l e . p r i n t ( " [ b o l d   r e d ]   [ / ]   C o u l d   n o t   f i n d   m e t a d a t a   f o r   e i t h e r   p a c k a g e . " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         r e p o r t _ a   =   _ b u i l d _ r e p o r t ( p a c k a g e _ a ,   i n t e l _ a ) 
 
         r e p o r t _ b   =   _ b u i l d _ r e p o r t ( p a c k a g e _ b ,   i n t e l _ b ) 
 
 
 
         i f   i s _ j s o n : 
 
                 o u t p u t   =   { 
 
                         p a c k a g e _ a :   _ s e r i a l i z e _ r e p o r t ( r e p o r t _ a ) , 
 
                         p a c k a g e _ b :   _ s e r i a l i z e _ r e p o r t ( r e p o r t _ b ) , 
 
                 } 
 
                 p r i n t ( j s o n _ l i b . d u m p s ( o u t p u t ,   i n d e n t = 2 ,   d e f a u l t = s t r ) ) 
 
                 r e t u r n 
 
 
 
         c o n s o l e . p r i n t ( f o r m a t _ c o m p a r e ( p a c k a g e _ a ,   r e p o r t _ a ,   p a c k a g e _ b ,   r e p o r t _ b ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
 
 
         #   V e r d i c t 
 
         s c o r e _ a   =   r e p o r t _ a [ " s c o r e " ] 
 
         s c o r e _ b   =   r e p o r t _ b [ " s c o r e " ] 
 
         i f   s c o r e _ a   >   s c o r e _ b : 
 
                 w i n n e r   =   p a c k a g e _ a 
 
                 d e l t a   =   s c o r e _ a   -   s c o r e _ b 
 
         e l i f   s c o r e _ b   >   s c o r e _ a : 
 
                 w i n n e r   =   p a c k a g e _ b 
 
                 d e l t a   =   s c o r e _ b   -   s c o r e _ a 
 
         e l s e : 
 
                 w i n n e r   =   N o n e 
 
                 d e l t a   =   0 
 
 
 
         v e r d i c t   =   T e x t ( ) 
 
         i f   w i n n e r : 
 
                 c o l o r   =   " c y a n "   i f   w i n n e r   = =   p a c k a g e _ a   e l s e   " m a g e n t a " 
 
                 v e r d i c t . a p p e n d ( f " a"    " ,   s t y l e = " b o l d " ) 
 
                 v e r d i c t . a p p e n d ( f " { w i n n e r } " ,   s t y l e = f " b o l d   { c o l o r } " ) 
 
                 v e r d i c t . a p p e n d ( f "   l e a d s   b y   " ,   s t y l e = " g r e y 7 0 " ) 
 
                 v e r d i c t . a p p e n d ( f " { d e l t a }   p o i n t s " ,   s t y l e = " b o l d " ) 
 
         e l s e : 
 
                 v e r d i c t . a p p e n d ( "   )"U%     B o t h   p a c k a g e s   a r e   e q u a l l y   t r u s t e d . " ,   s t y l e = " b o l d " ) 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         v e r d i c t , 
 
                         t i t l e = " [ b o l d ] V e r d i c t [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e e n "   i f   w i n n e r   e l s e   " g r e y 5 0 " , 
 
                         p a d d i n g = ( 0 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   d o c t o r 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   d o c t o r ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P a t h   t o   p r o j e c t   d i r e c t o r y . " ) , 
 
         f o r m a t :   s t r   =   t y p e r . O p t i o n ( " t e x t " ,   " - - f o r m a t " ,   " - f " ,   h e l p = " O u t p u t   f o r m a t :   t e x t   o r   j s o n . " ) , 
 
         c o n c u r r e n c y :   i n t   =   t y p e r . O p t i o n ( 1 0 ,   " - - c o n c u r r e n c y " ,   " - c " ,   h e l p = " M a x   p a r a l l e l   A P I   r e q u e s t s . " ) , 
 
 )   - >   N o n e : 
 
         " " " R u n   a   f u l l   d e p e n d e n c y   h e a l t h   c h e c k   a n d   p r i n t   a n   a g g r e g a t e   s u m m a r y . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( )   o r   n o t   p r o j e c t _ p a t h . i s _ d i r ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         i s _ j s o n   =   f o r m a t . l o w e r ( )   = =   " j s o n " 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
                 c o n s o l e . p r i n t ( ) 
 
                 c o n s o l e . p r i n t ( f " [ b o l d ] a"#Q%  R u n n i n g   h e a l t h   c h e c k   o n [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         i f   n o t   d e c l a r e d : 
 
                 i f   i s _ j s o n : 
 
                         p r i n t ( j s o n _ l i b . d u m p s ( { " e r r o r " :   " n o _ m a n i f e s t s " } ) ) 
 
                 e l s e : 
 
                         c o n s o l e . p r i n t ( " [ y e l l o w ]     N o   d e p e n d e n c y   m a n i f e s t s   f o u n d   i n   t h i s   d i r e c t o r y . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         r a w _ i m p o r t s   =   s c a n _ p r o j e c t _ i m p o r t s ( p r o j e c t _ p a t h ) 
 
         u s e d _ p a c k a g e s   =   m a p _ i m p o r t s _ t o _ p a c k a g e s ( r a w _ i m p o r t s ) 
 
         u n u s e d   =   d e c l a r e d   -   u s e d _ p a c k a g e s 
 
 
 
         p k g _ l i s t   =   s o r t e d ( d e c l a r e d ) 
 
 
 
         i n t e l _ m a p   =   _ f e t c h _ w i t h _ p r o g r e s s ( p k g _ l i s t ,   c o n c u r r e n c y ,   s h o w _ p r o g r e s s = n o t   i s _ j s o n ) 
 
 
 
         r e p o r t s   =   { p k g :   _ b u i l d _ r e p o r t ( p k g ,   i n t e l _ m a p . g e t ( p k g ,   { } ) ,   u n u s e d = p k g   i n   u n u s e d )   f o r   p k g   i n   p k g _ l i s t } 
 
 
 
         i f   i s _ j s o n : 
 
                 t o t a l _ v u l n s   =   s u m ( l e n ( r . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] )   f o r   r   i n   r e p o r t s . v a l u e s ( ) ) 
 
                 o u t p u t   =   { 
 
                         " p r o j e c t " :   s t r ( p r o j e c t _ p a t h ) , 
 
                         " h e a l t h " :   { 
 
                                 " t o t a l _ d e p e n d e n c i e s " :   l e n ( d e c l a r e d ) , 
 
                                 " u n u s e d _ c o u n t " :   l e n ( u n u s e d ) , 
 
                                 " a v e r a g e _ t r u s t _ s c o r e " :   ( 
 
                                         s u m ( r [ " s c o r e " ]   f o r   r   i n   r e p o r t s . v a l u e s ( ) )   /   l e n ( r e p o r t s )   i f   r e p o r t s   e l s e   0 
 
                                 ) , 
 
                                 " t o t a l _ v u l n e r a b i l i t i e s " :   t o t a l _ v u l n s , 
 
                         } , 
 
                         " r e p o r t s " :   { p k g :   _ s e r i a l i z e _ r e p o r t ( r )   f o r   p k g ,   r   i n   r e p o r t s . i t e m s ( ) } , 
 
                 } 
 
                 p r i n t ( j s o n _ l i b . d u m p s ( o u t p u t ,   i n d e n t = 2 ,   d e f a u l t = s t r ) ) 
 
                 r e t u r n 
 
 
 
         c o n s o l e . p r i n t ( f o r m a t _ h e a l t h _ s u m m a r y ( d e c l a r e d ,   u n u s e d ,   r e p o r t s ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f o r m a t _ t r u s t _ r e p o r t ( r e p o r t s ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
 
 
         #   S c o r e   L e g e n d 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         " [ g r e e n ] 9 0 - 1 0 0 [ / ]   E x c e l l e n t           " 
 
                         " [ y e l l o w ] 7 0 - 8 9 [ / ]   G o o d           " 
 
                         " [ o r a n g e 1 ] 5 0 - 6 9 [ / ]   N e e d s   A t t e n t i o n           " 
 
                         " [ r e d ] 0 - 4 9 [ / ]   C r i t i c a l " , 
 
                         t i t l e = " [ b o l d ] a"    S c o r e   L e g e n d [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e y 5 0 " , 
 
                         p a d d i n g = ( 0 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   c a c h e   s u b c o m m a n d s 
 
 #                                                                                                                                                               
 
 
 
 @ c a c h e _ a p p . c o m m a n d ( " i n f o " ) 
 
 d e f   c a c h e _ i n f o _ c m d ( )   - >   N o n e : 
 
         " " " S h o w   c a c h e   l o c a t i o n ,   e n t r y   c o u n t ,   a n d   t o t a l   s i z e . " " " 
 
         i n f o   =   c a c h e _ i n f o ( ) 
 
         t e x t   =   T e x t ( ) 
 
         t e x t . a p p e n d ( " a"    P a t h :         " ,   s t y l e = " b o l d " ) 
 
         t e x t . a p p e n d ( f " { i n f o [ ' p a t h ' ] } \ n " ,   s t y l e = " c y a n " ) 
 
         t e x t . a p p e n d ( " a"    E n t r i e s :   " ,   s t y l e = " b o l d " ) 
 
         t e x t . a p p e n d ( f " { i n f o [ ' e n t r i e s ' ] : , } \ n " ,   s t y l e = " c y a n " ) 
 
         t e x t . a p p e n d ( " a" [%  S i z e :         " ,   s t y l e = " b o l d " ) 
 
         t e x t . a p p e n d ( f " { f o r m a t _ s i z e ( i n f o [ ' t o t a l _ b y t e s ' ] ) } " ,   s t y l e = " c y a n " ) 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         t e x t , 
 
                         t i t l e = " [ b o l d ] K r a i m i n d   C a c h e [ / ] " , 
 
                         b o r d e r _ s t y l e = " c y a n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 @ c a c h e _ a p p . c o m m a n d ( " c l e a r " ) 
 
 d e f   c a c h e _ c l e a r _ c m d ( 
 
         y e s :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - y e s " ,   " - y " ,   h e l p = " S k i p   c o n f i r m a t i o n   p r o m p t . " ) , 
 
 )   - >   N o n e : 
 
         " " " D e l e t e   a l l   c a c h e d   A P I   r e s p o n s e s . " " " 
 
         i n f o   =   c a c h e _ i n f o ( ) 
 
         i f   i n f o [ " e n t r i e s " ]   = =   0 : 
 
                 c o n s o l e . p r i n t ( " [ g r e y 5 0 ] C a c h e   i s   a l r e a d y   e m p t y . [ / ] " ) 
 
                 r e t u r n 
 
 
 
         i f   n o t   y e s : 
 
                 c o n s o l e . p r i n t ( 
 
                         f " T h i s   w i l l   d e l e t e   [ b o l d ] { i n f o [ ' e n t r i e s ' ] } [ / ]   c a c h e   e n t r i e s   " 
 
                         f " ( { f o r m a t _ s i z e ( i n f o [ ' t o t a l _ b y t e s ' ] ) } ) . " 
 
                 ) 
 
                 c o n f i r m   =   t y p e r . c o n f i r m ( " C o n t i n u e ? " ,   d e f a u l t = F a l s e ) 
 
                 i f   n o t   c o n f i r m : 
 
                         c o n s o l e . p r i n t ( " [ g r e y 5 0 ] A b o r t e d . [ / ] " ) 
 
                         r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         d e l e t e d   =   c l e a r _ c a c h e ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d   g r e e n ]   [ / ]   C l e a r e d   [ b o l d ] { d e l e t e d } [ / ]   c a c h e   e n t r i e s . " ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   c o n f i g   s u b c o m m a n d s       A P I   k e y   m a n a g e m e n t 
 
 #                                                                                                                                                               
 
 
 
 @ c o n f i g _ a p p . c o m m a n d ( " s e t " ) 
 
 d e f   c o n f i g _ s e t ( 
 
         k e y :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " C o n f i g   k e y   ( e . g .   G R O Q _ A P I _ K E Y ) . " ) , 
 
         v a l u e :   s t r   =   t y p e r . A r g u m e n t ( d e f a u l t = " " ,   h e l p = " V a l u e   t o   s t o r e .   O m i t   t o   b e   p r o m p t e d   s e c u r e l y . " ) , 
 
 )   - >   N o n e : 
 
         " " " S t o r e   a n   A P I   k e y   o r   c o n f i g   v a l u e   p e r s i s t e n t l y . " " " 
 
         k e y   =   k e y . u p p e r ( ) 
 
         i f   k e y   n o t   i n   K N O W N _ K E Y S : 
 
                 c o n s o l e . p r i n t ( 
 
                         f " [ y e l l o w ]     U n k n o w n   k e y : [ / ]   [ b o l d ] { k e y } [ / ] \ n " 
 
                         f " [ g r e y 5 0 ] K n o w n   k e y s :   { ' ,   ' . j o i n ( s o r t e d ( K N O W N _ K E Y S ) ) } [ / ] " 
 
                 ) 
 
                 i f   n o t   t y p e r . c o n f i r m ( " S t o r e   a n y w a y ? " ,   d e f a u l t = F a l s e ) : 
 
                         r a i s e   t y p e r . E x i t ( 0 ) 
 
         i f   n o t   v a l u e : 
 
                 v a l u e   =   t y p e r . p r o m p t ( f " E n t e r   v a l u e   f o r   { k e y } " ) 
 
         i f   n o t   v a l u e : 
 
                 c o n s o l e . p r i n t ( " [ r e d ]     N o   v a l u e   p r o v i d e d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
         s e t _ k e y ( k e y ,   v a l u e ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d   g r e e n ]   [ / ]   S a v e d   [ b o l d ] { k e y } [ / ]       [ c y a n ] { c o n f i g _ p a t h ( ) } [ / ] " ) 
 
 
 
 
 
 @ c o n f i g _ a p p . c o m m a n d ( " g e t " ) 
 
 d e f   c o n f i g _ g e t ( 
 
         k e y :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " C o n f i g   k e y   t o   r e a d . " ) , 
 
 )   - >   N o n e : 
 
         " " " S h o w   t h e   c u r r e n t   v a l u e   o f   a   c o n f i g   k e y   ( m a s k e d ) . " " " 
 
         k e y   =   k e y . u p p e r ( ) 
 
         v a l   =   g e t _ k e y ( k e y ) 
 
         i f   v a l   i s   N o n e : 
 
                 c o n s o l e . p r i n t ( f " [ g r e y 5 0 ] { k e y }   i s   n o t   s e t . [ / ] " ) 
 
         e l s e : 
 
                 m a s k e d   =   v a l [ : 6 ]   +   " . . . "   +   v a l [ - 3 : ]   i f   l e n ( v a l )   >   1 2   e l s e   " * * * " 
 
                 s o u r c e   =   " e n v "   i f   _ _ i m p o r t _ _ ( " o s " ) . g e t e n v ( k e y )   e l s e   " c o n f i g " 
 
                 c o n s o l e . p r i n t ( f " [ b o l d ] { k e y } [ / ]   =   [ c y a n ] { m a s k e d } [ / ]   [ g r e y 5 0 ] ( f r o m   { s o u r c e } ) [ / ] " ) 
 
 
 
 
 
 @ c o n f i g _ a p p . c o m m a n d ( " l i s t " ) 
 
 d e f   c o n f i g _ l i s t ( )   - >   N o n e : 
 
         " " " L i s t   a l l   s t o r e d   c o n f i g   k e y s   ( v a l u e s   m a s k e d ) . " " " 
 
         s t o r e d   =   l i s t _ k e y s ( ) 
 
         i f   n o t   s t o r e d : 
 
                 c o n s o l e . p r i n t ( 
 
                         f " [ g r e y 5 0 ] N o   k e y s   s t o r e d .   U s e   [ b o l d ] k r a i m i n d   c o n f i g   s e t   G R O Q _ A P I _ K E Y   g s k _ . . . [ / ] [ / ] \ n " 
 
                         f " [ g r e y 5 0 ] C o n f i g   f i l e :   { c o n f i g _ p a t h ( ) } [ / ] " 
 
                 ) 
 
                 r e t u r n 
 
         t e x t   =   T e x t ( ) 
 
         t e x t . a p p e n d ( f " C o n f i g   f i l e :   { c o n f i g _ p a t h ( ) } \ n \ n " ,   s t y l e = " g r e y 5 0 " ) 
 
         f o r   k ,   v   i n   s o r t e d ( s t o r e d . i t e m s ( ) ) : 
 
                 m a s k e d   =   v [ : 6 ]   +   " . . . "   +   v [ - 3 : ]   i f   l e n ( v )   >   1 2   e l s e   " * * * " 
 
                 e n v _ o v e r r i d e   =   _ _ i m p o r t _ _ ( " o s " ) . g e t e n v ( k ) 
 
                 n o t e   =   "     [ g r e y 5 0 ] ( o v e r r i d d e n   b y   e n v   v a r ) [ / ] "   i f   e n v _ o v e r r i d e   e l s e   " " 
 
                 t e x t . a p p e n d ( f "     { k } " ,   s t y l e = " b o l d " ) 
 
                 t e x t . a p p e n d ( f "   =   { m a s k e d } { n o t e } \ n " ,   s t y l e = " c y a n " ) 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( t e x t ,   t i t l e = " [ b o l d ] K r a i m i n d   C o n f i g [ / ] " ,   b o r d e r _ s t y l e = " c y a n " ,   p a d d i n g = ( 1 ,   2 ) ) 
 
         ) 
 
 
 
 
 
 @ c o n f i g _ a p p . c o m m a n d ( " u n s e t " ) 
 
 d e f   c o n f i g _ u n s e t ( 
 
         k e y :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " C o n f i g   k e y   t o   r e m o v e . " ) , 
 
 )   - >   N o n e : 
 
         " " " R e m o v e   a   s t o r e d   c o n f i g   k e y . " " " 
 
         k e y   =   k e y . u p p e r ( ) 
 
         r e m o v e d   =   u n s e t _ k e y ( k e y ) 
 
         i f   r e m o v e d : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   g r e e n ]   [ / ]   R e m o v e d   [ b o l d ] { k e y } [ / ]   f r o m   c o n f i g . " ) 
 
         e l s e : 
 
                 c o n s o l e . p r i n t ( f " [ g r e y 5 0 ] { k e y }   w a s   n o t   i n   c o n f i g . [ / ] " ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   r e m o v e       a t o m i c   s a f e - r e m o v e   w i t h   r o l l b a c k   ( F 1 ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   r e m o v e ( 
 
         p a c k a g e :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " P a c k a g e   t o   r e m o v e . " ) , 
 
         y e s :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - y e s " ,   " - y " ,   h e l p = " S k i p   c o n f i r m a t i o n   p r o m p t . " ) , 
 
         n o _ t e s t :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - n o - t e s t " ,   h e l p = " S k i p   p o s t - r e m o v a l   t e s t   r u n . " ) , 
 
         d r y _ r u n :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - d r y - r u n " ,   h e l p = " S h o w   p l a n ,   d o n ' t   e x e c u t e . " ) , 
 
         f o r c e :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - f o r c e " ,   h e l p = " B y p a s s   c o n f i d e n c e   t h r e s h o l d . " ) , 
 
         m i n _ c o n f i d e n c e :   i n t   =   t y p e r . O p t i o n ( 7 0 ,   " - - m i n - c o n f i d e n c e " ,   h e l p = " R e q u i r e d   c o n f i d e n c e   t o   p r o c e e d . " ) , 
 
         t e s t _ c m d :   s t r   =   t y p e r . O p t i o n ( " " ,   " - - t e s t - c m d " ,   h e l p = " O v e r r i d e   t e s t   c o m m a n d   ( d e f a u l t :   p y t e s t   o n   t e s t s   t h a t   i m p o r t   t a r g e t ) . " ) , 
 
         p a t h :   s t r   =   t y p e r . O p t i o n ( " . " ,   " - - p a t h " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
 )   - >   N o n e : 
 
         " " " A t o m i c a l l y   r e m o v e   a   p a c k a g e       s n a p s h o t       u n i n s t a l l       t e s t       r o l l b a c k   o n   f a i l u r e . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"      R e m o v i n g [ / ]   [ c y a n ] { p a c k a g e } [ / ] \ n " ) 
 
 
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         #   C o n f i d e n c e   g a t e   ( u n l e s s   - - f o r c e ) 
 
         i f   n o t   f o r c e : 
 
                 s c o r e d   =   s c o r e _ a l l _ p a c k a g e s ( p r o j e c t _ p a t h ,   { p a c k a g e }   |   d e c l a r e d ) 
 
                 r c   =   s c o r e d . g e t ( p a c k a g e ) 
 
                 i f   r c   i s   N o n e   o r   r c . c o n f i d e n c e   <   m i n _ c o n f i d e n c e : 
 
                         a c t u a l   =   r c . c o n f i d e n c e   i f   r c   e l s e   0 
 
                         c o n s o l e . p r i n t ( 
 
                                 P a n e l ( 
 
                                         f " [ b o l d   r e d ]     C o n f i d e n c e   t o o   l o w :   { a c t u a l } / 1 0 0   ( r e q u i r e d :   { m i n _ c o n f i d e n c e } ) [ / ] \ n \ n " 
 
                                         +   ( ( " \ n " . j o i n ( f "         { c } "   f o r   c   i n   r c . c o n c e r n s )   +   " \ n \ n " )   i f   r c   e l s e   " " ) 
 
                                         +   " [ g r e y 7 0 ] R e - r u n   w i t h   [ b o l d ] - - f o r c e [ / ]   t o   o v e r r i d e ,   o r   l o w e r   [ b o l d ] - - m i n - c o n f i d e n c e [ / ] . [ / ] " , 
 
                                         t i t l e = " [ b o l d   r e d ] R e m o v a l   b l o c k e d [ / ] " , 
 
                                         b o r d e r _ s t y l e = " r e d " , 
 
                                         p a d d i n g = ( 1 ,   2 ) , 
 
                                 ) 
 
                         ) 
 
                         r a i s e   t y p e r . E x i t ( 1 ) 
 
                 c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   C o n f i d e n c e :   [ b o l d ] { r c . c o n f i d e n c e } / 1 0 0 [ / ]   ( { r c . l a b e l } ) " ) 
 
 
 
         p l a n   =   p l a n _ r e m o v a l ( p r o j e c t _ p a t h ,   p a c k a g e ,   d e c l a r e d ,   s k i p _ t e s t _ s e l e c t i o n = n o _ t e s t ) 
 
 
 
         c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   P a c k a g e   m a n a g e r :   [ b o l d ] { p l a n . p a c k a g e _ m a n a g e r . v a l u e } [ / ] " ) 
 
         i f   p l a n . o r p h a n s : 
 
                 c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   T r a n s i t i v e   o r p h a n s :   [ b o l d ] { l e n ( p l a n . o r p h a n s ) } [ / ] " ) 
 
                 f o r   o   i n   p l a n . o r p h a n s [ : 1 0 ] : 
 
                         c o n s o l e . p r i n t ( f "                 { o } " ) 
 
         i f   p l a n . t e s t _ f i l e s   a n d   n o t   n o _ t e s t : 
 
                 c o n s o l e . p r i n t ( f "     [ g r e e n ]   [ / ]   T e s t   f i l e s   t o   v e r i f y :   [ b o l d ] { l e n ( p l a n . t e s t _ f i l e s ) } [ / ] " ) 
 
 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         f " [ b o l d ] W i l l   u n i n s t a l l : [ / ] \ n " 
 
                         +   " \ n " . j o i n ( f "         { p } "   f o r   p   i n   p l a n . a l l _ p a c k a g e s ) , 
 
                         b o r d e r _ s t y l e = " c y a n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
         i f   d r y _ r u n : 
 
                 c o n s o l e . p r i n t ( " \ n [ g r e y 7 0 ] ( - - d r y - r u n       n o t h i n g   c h a n g e d ) [ / ] " ) 
 
                 r e t u r n 
 
 
 
         i f   n o t   y e s : 
 
                 c o n f i r m   =   t y p e r . c o n f i r m ( " \ n P r o c e e d ? " ,   d e f a u l t = F a l s e ) 
 
                 i f   n o t   c o n f i r m : 
 
                         c o n s o l e . p r i n t ( " [ g r e y 5 0 ] A b o r t e d . [ / ] " ) 
 
                         r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         t e s t _ c m d _ l i s t   =   t e s t _ c m d . s p l i t ( )   i f   t e s t _ c m d   e l s e   N o n e 
 
         r e s u l t   =   e x e c u t e _ r e m o v a l ( 
 
                 p r o j e c t _ p a t h , 
 
                 p l a n , 
 
                 r u n _ t e s t s = n o t   n o _ t e s t , 
 
                 d r y _ r u n = F a l s e , 
 
                 t e s t _ c m d = t e s t _ c m d _ l i s t , 
 
         ) 
 
 
 
         i f   r e s u l t . s u c c e s s : 
 
                 m s g   =   f " [ b o l d   g r e e n ]     R e m o v e d   { l e n ( r e s u l t . u n i n s t a l l e d ) }   p a c k a g e ( s ) . [ / ] " 
 
                 i f   r e s u l t . s n a p s h o t : 
 
                         m s g   + =   f " \ n [ g r e y 7 0 ] S n a p s h o t :   { r e s u l t . s n a p s h o t . p a t h } [ / ] " 
 
                         m s g   + =   f " \ n [ g r e y 7 0 ] R o l l b a c k :   [ b o l d ] k r a i m i n d   r o l l b a c k   { r e s u l t . s n a p s h o t . p a t h . n a m e } [ / ] [ / ] " 
 
                 c o n s o l e . p r i n t ( P a n e l ( m s g ,   b o r d e r _ s t y l e = " g r e e n " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
         e l s e : 
 
                 m s g   =   f " [ b o l d   r e d ]     { r e s u l t . e r r o r   o r   ' U n k n o w n   f a i l u r e ' } [ / ] " 
 
                 i f   r e s u l t . r o l l e d _ b a c k : 
 
                         m s g   + =   " \ n [ g r e e n ] V e n v   r e s t o r e d   f r o m   s n a p s h o t . [ / ] " 
 
                 c o n s o l e . p r i n t ( P a n e l ( m s g ,   b o r d e r _ s t y l e = " r e d " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   c l e a n       i n t e r a c t i v e   s p r i n g - c l e a n i n g   w i z a r d   ( F 4 ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   c l e a n ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
         m i n _ c o n f i d e n c e :   i n t   =   t y p e r . O p t i o n ( 7 0 ,   " - - m i n - c o n f i d e n c e " ,   h e l p = " M i n i m u m   c o n f i d e n c e   t o   s h o w   a   c a n d i d a t e . " ) , 
 
         u n u s e d _ o n l y :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - u n u s e d - o n l y " ,   h e l p = " S k i p   a l t e r n a t i v e s   s u g g e s t i o n s . " ) , 
 
         y e s :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - y e s " ,   " - y " ,   h e l p = " A c c e p t   a l l   c a n d i d a t e s   w i t h o u t   p r o m p t i n g   ( C I   m o d e ) . " ) , 
 
 )   - >   N o n e : 
 
         " " " I n t e r a c t i v e   c l e a n u p   w i z a r d       w a l k s   c a n d i d a t e s   o n e - b y - o n e   w i t h   s n a p s h o t - b a c k e d   b a t c h   r e m o v a l . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
 
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         i f   n o t   d e c l a r e d : 
 
                 c o n s o l e . p r i n t ( " [ y e l l o w ]     N o   d e p e n d e n c i e s   f o u n d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         r e s u l t   =   r u n _ w i z a r d ( 
 
                 p r o j e c t _ p a t h , 
 
                 d e c l a r e d , 
 
                 m i n _ c o n f i d e n c e = m i n _ c o n f i d e n c e , 
 
                 i n c l u d e _ a l t e r n a t i v e s = n o t   u n u s e d _ o n l y , 
 
                 c o n s o l e = c o n s o l e , 
 
                 a u t o _ y e s = y e s , 
 
         ) 
 
 
 
         i f   r e s u l t . e r r o r : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]     { r e s u l t . e r r o r } [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
         i f   r e s u l t . c a n c e l l e d   a n d   n o t   r e s u l t . a c c e p t e d : 
 
                 c o n s o l e . p r i n t ( " [ g r e y 5 0 ] W i z a r d   c a n c e l l e d       n o t h i n g   c h a n g e d . [ / ] " ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   m i g r a t e       A I - p o w e r e d   A S T   c o d e m o d   ( F 3 ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   m i g r a t e ( 
 
         s o u r c e :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " P a c k a g e   t o   m i g r a t e   F R O M . " ) , 
 
         t a r g e t :   s t r   =   t y p e r . A r g u m e n t ( . . . ,   h e l p = " P a c k a g e   t o   m i g r a t e   T O . " ) , 
 
         p a t h :   s t r   =   t y p e r . O p t i o n ( " . " ,   " - - p a t h " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
         d r y _ r u n :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - d r y - r u n " ,   h e l p = " P r e v i e w   o n l y       d o   n o t   w r i t e   c h a n g e s . " ) , 
 
         u s e _ a i :   b o o l   =   t y p e r . O p t i o n ( T r u e ,   " - - a i / - - n o - a i " ,   h e l p = " U s e   A I   f a l l b a c k   i f   n o   r e c i p e   e x i s t s . " ) , 
 
         y e s :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - y e s " ,   " - y " ,   h e l p = " S k i p   c o n f i r m a t i o n   p r o m p t . " ) , 
 
 )   - >   N o n e : 
 
         " " " R e w r i t e   a l l   i m p o r t s   +   c a l l   s i t e s :   s o u r c e   p a c k a g e       t a r g e t   p a c k a g e . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"    M i g r a t i n g [ / ]   [ r e d ] { s o u r c e } [ / ]       [ g r e e n ] { t a r g e t } [ / ] \ n " ) 
 
 
 
         r e c i p e   =   g e t _ r e c i p e ( s o u r c e ,   t a r g e t ) 
 
         i f   r e c i p e   i s   N o n e : 
 
                 i f   u s e _ a i : 
 
                         c o n s o l e . p r i n t ( " [ g r e y 7 0 ] N o   b u i l t - i n   r e c i p e       a s k i n g   A I   t o   g e n e r a t e   o n e   [ / ] " ) 
 
                         r e c i p e   =   g e n e r a t e _ a i _ r e c i p e ( s o u r c e ,   t a r g e t ) 
 
                 i f   r e c i p e   i s   N o n e : 
 
                         c o n s o l e . p r i n t ( 
 
                                 P a n e l ( 
 
                                         f " [ y e l l o w ] N o   r e c i p e   f o u n d   f o r   { s o u r c e }       { t a r g e t } . [ / ] \ n \ n " 
 
                                         " [ g r e y 7 0 ] E i t h e r   s e t   O P E N A I _ A P I _ K E Y   /   G R O Q _ A P I _ K E Y   /   K R A I M I N D _ L O C A L _ A I = 1   " 
 
                                         " t o   e n a b l e   A I   f a l l b a c k ,   o r   c o n t r i b u t e   a   r e c i p e   t o   " 
 
                                         " [ b o l d ] s r c / k r a i m i n d / m i g r a t e / r e c i p e s . p y [ / ] . [ / ] " , 
 
                                         b o r d e r _ s t y l e = " y e l l o w " , 
 
                                 ) 
 
                         ) 
 
                         r a i s e   t y p e r . E x i t ( 1 ) 
 
                 c o n s o l e . p r i n t ( "     [ g r e e n ]   [ / ]   A I   g e n e r a t e d   a   d r a f t   r e c i p e       r e v i e w   c a r e f u l l y . " ) 
 
         e l s e : 
 
                 c o n s o l e . p r i n t ( "     [ g r e e n ]   [ / ]   U s i n g   b u i l t - i n   r e c i p e . " ) 
 
 
 
         p r e v i e w   =   p r e v i e w _ m i g r a t i o n ( p r o j e c t _ p a t h ,   r e c i p e ) 
 
         r e n d e r _ m i g r a t i o n _ p r e v i e w ( p r e v i e w ,   c o n s o l e ) 
 
 
 
         i f   p r e v i e w . f i l e s _ c h a n g e d   = =   0 : 
 
                 c o n s o l e . p r i n t ( " \ n [ y e l l o w ] N o t h i n g   t o   m i g r a t e . [ / ] " ) 
 
                 r e t u r n 
 
 
 
         i f   d r y _ r u n : 
 
                 c o n s o l e . p r i n t ( " \ n [ g r e y 7 0 ] ( - - d r y - r u n       n o   f i l e s   w r i t t e n ) [ / ] " ) 
 
                 r e t u r n 
 
 
 
         i f   n o t   y e s : 
 
                 p r o c e e d   =   t y p e r . c o n f i r m ( f " \ n A p p l y   c h a n g e s   t o   { p r e v i e w . f i l e s _ c h a n g e d }   f i l e ( s ) ? " ,   d e f a u l t = F a l s e ) 
 
                 i f   n o t   p r o c e e d : 
 
                         c o n s o l e . p r i n t ( " [ g r e y 5 0 ] A b o r t e d . [ / ] " ) 
 
                         r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         f i n a l   =   a p p l y _ m i g r a t i o n ( p r o j e c t _ p a t h ,   r e c i p e ) 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         f " [ b o l d   g r e e n ]     M i g r a t e d   { f i n a l . f i l e s _ c h a n g e d }   f i l e ( s )       { f i n a l . t o t a l _ r e p l a c e m e n t s }   r e p l a c e m e n t ( s ) . [ / ] \ n " 
 
                         f " [ g r e y 7 0 ] N e x t :   r u n   y o u r   t e s t s ,   t h e n   [ b o l d ] k r a i m i n d   r e m o v e   { s o u r c e } [ / ] [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e e n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   a r c h i t e c t       d e p l o y m e n t   i n f r a s t r u c t u r e   A I   r e c o m m e n d a t i o n s 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   a r c h i t e c t ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h   t o   a n a l y z e . " ) , 
 
 )   - >   N o n e : 
 
         " " " A n a l y z e   t h e   w o r k s p a c e   a n d   s u g g e s t   o p t i m a l   d e p l o y m e n t   m o d e l s   v i a   A I . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"  )"U%   A r c h i t e c t i n g   d e p l o y m e n t   f o r [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] A n a l y z i n g   p r o j e c t   l a y o u t   &   c o n s u l t i n g   A I . . . [ / ] " ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p r o g r e s s : 
 
                 p r o g r e s s . a d d _ t a s k ( " a r c h i t e c t " ,   t o t a l = N o n e ) 
 
                 r e c o m m e n d a t i o n   =   a n a l y z e _ d e p l o y m e n t ( p r o j e c t _ p a t h ) 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         r e c o m m e n d a t i o n , 
 
                         t i t l e = " [ b o l d ]   )"U%   D e p l o y m e n t   R e c o m m e n d a t i o n s [ / ] " , 
 
                         b o r d e r _ s t y l e = " c y a n " , 
 
                         p a d d i n g = ( 1 ,   2 ) 
 
                 ) 
 
         ) 
 
 
 
 #                                                                                                                                                               
 
 #   s h a r e       b u n d l e   c o d e b a s e   i n t o   a   l i n k   a n y   w e b   A I   c a n   r e a d 
 
 #                                                                                                                                                               
 
 
 
 
 
 d e f   _ p a r s e _ s i n c e ( v a l u e :   s t r ) : 
 
         i m p o r t   r e 
 
         f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e d e l t a ,   t i m e z o n e 
 
 
 
         m   =   r e . f u l l m a t c h ( r " ( \ d + ) d " ,   v a l u e . s t r i p ( ) ) 
 
         i f   m : 
 
                 r e t u r n   d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   t i m e d e l t a ( d a y s = i n t ( m . g r o u p ( 1 ) ) ) 
 
         t r y : 
 
                 d t   =   d a t e t i m e . f r o m i s o f o r m a t ( v a l u e ) 
 
                 r e t u r n   d t   i f   d t . t z i n f o   e l s e   d t . r e p l a c e ( t z i n f o = t i m e z o n e . u t c ) 
 
         e x c e p t   V a l u e E r r o r : 
 
                 r a i s e   t y p e r . B a d P a r a m e t e r ( 
 
                         f " C a n n o t   p a r s e   - - s i n c e   v a l u e :   { v a l u e ! r } .   U s e   e . g .   ' 7 d '   o r   ' 2 0 2 5 - 0 5 - 2 0 ' . " 
 
                 ) 
 
 
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   s h a r e ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h   t o   b u n d l e . " ) , 
 
         f u l l :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - f u l l " ,   h e l p = " I n c l u d e   a l l   f i l e s   ( d e f a u l t :   s m a r t   s u b s e t ,   ~ 3 0 0   K B   c a p ) . " ) , 
 
         s i n c e _ s t r :   O p t i o n a l [ s t r ]   =   t y p e r . O p t i o n ( N o n e ,   " - - s i n c e " ,   h e l p = " O n l y   i n c l u d e   f i l e s   m o d i f i e d   a f t e r   t h i s   d a t e / d u r a t i o n .   E x a m p l e s :   ' 7 d ' ,   ' 2 0 2 5 - 0 5 - 2 0 ' . " ) , 
 
         f i l e :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - f i l e " ,   h e l p = " W r i t e   b u n d l e   l o c a l l y   i n s t e a d   o f   u p l o a d i n g . " ) , 
 
         o u t p u t :   s t r   =   t y p e r . O p t i o n ( " k r a i m i n d - b u n d l e . m d " ,   " - - o u t p u t " ,   " - o " ,   h e l p = " O u t p u t   p a t h   w h e n   u s i n g   - - f i l e . " ) , 
 
         t t l _ h o u r s :   i n t   =   t y p e r . O p t i o n ( 2 4 ,   " - - t t l " ,   h e l p = " H o u r s   u n t i l   t h e   s h a r e   l i n k   e x p i r e s   ( 1 - 7 2 ) . " ) , 
 
 )   - >   N o n e : 
 
         " " " B u n d l e   y o u r   c o d e b a s e   i n t o   a   l i n k   t h a t   a n y   w e b   A I   ( C l a u d e . a i ,   C h a t G P T ,   G e m i n i )   c a n   r e a d . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( )   o r   n o t   p r o j e c t _ p a t h . i s _ d i r ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         s i n c e   =   _ p a r s e _ s i n c e ( s i n c e _ s t r )   i f   s i n c e _ s t r   e l s e   N o n e 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"    B u n d l i n g [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] W a l k i n g   p r o j e c t   &   b u i l d i n g   b u n d l e . . . [ / ] " ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p r o g r e s s : 
 
                 p r o g r e s s . a d d _ t a s k ( " s h a r e " ,   t o t a l = N o n e ) 
 
                 b u n d l e   =   b u i l d _ b u n d l e ( p r o j e c t _ p a t h ,   f u l l = f u l l ,   s i n c e = s i n c e ) 
 
 
 
         i f   b u n d l e . f i l e _ c o u n t   = =   0 : 
 
                 c o n s o l e . p r i n t ( " [ b o l d   y e l l o w ]     N o   s h a r e a b l e   f i l e s   f o u n d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         s i z e _ k b   =   b u n d l e . t o t a l _ b y t e s   / /   1 0 2 4 
 
         c o n s o l e . p r i n t ( 
 
                 f "     [ g r e e n ]   [ / ]   B u n d l e d   [ b o l d ] { b u n d l e . f i l e _ c o u n t } [ / ]   f i l e s   " 
 
                 f " ( [ b o l d ] { s i z e _ k b }   K B [ / ] ,   m o d e = [ b o l d ] { ' f u l l '   i f   f u l l   e l s e   ' s m a r t ' } [ / ] ) " 
 
         ) 
 
 
 
         i f   f u l l   a n d   b u n d l e . t o t a l _ b y t e s   >   5 0 0   *   1 0 2 4 : 
 
                 c o n s o l e . p r i n t ( 
 
                         "     [ y e l l o w ]   [ / ]   B u n d l e   i s   l a r g e       s o m e   w e b   A I s   m a y   t r u n c a t e .   " 
 
                         " C o n s i d e r   d r o p p i n g   [ b o l d ] - - f u l l [ / ] . " 
 
                 ) 
 
 
 
         i f   n o t   f u l l   a n d   b u n d l e . e x c l u d e d _ f i l e s : 
 
                 c o n s o l e . p r i n t ( 
 
                         f "     [ y e l l o w ]   [ / ]   [ b o l d ] { l e n ( b u n d l e . e x c l u d e d _ f i l e s ) } [ / ]   f i l e ( s )   e x c l u d e d   b y   s m a r t   c a p   " 
 
                         f " ( u s e   [ b o l d ] - - f u l l [ / ]   o r   [ b o l d ] - - s i n c e [ / ]   t o   n a r r o w   s c o p e ) : " 
 
                 ) 
 
                 f o r   e x c   i n   b u n d l e . e x c l u d e d _ f i l e s [ : 1 0 ] : 
 
                         c o n s o l e . p r i n t ( f "         [ g r e y 5 0 ] { e x c . r e l } [ / ]     ( { e x c . s i z e _ k b }   K B ) " ) 
 
                 i f   l e n ( b u n d l e . e x c l u d e d _ f i l e s )   >   1 0 : 
 
                         c o n s o l e . p r i n t ( f "         [ g r e y 5 0 ] . . .   a n d   { l e n ( b u n d l e . e x c l u d e d _ f i l e s )   -   1 0 }   m o r e [ / ] " ) 
 
 
 
         o u t p u t _ p a t h   =   P a t h ( o u t p u t ) . r e s o l v e ( ) 
 
 
 
         d e f   _ w r i t e _ l o c a l ( r e a s o n :   s t r   |   N o n e   =   N o n e )   - >   N o n e : 
 
                 o u t p u t _ p a t h . w r i t e _ t e x t ( b u n d l e . c o n t e n t ,   e n c o d i n g = " u t f - 8 " ) 
 
                 i f   r e a s o n : 
 
                         c o n s o l e . p r i n t ( f "     [ y e l l o w ]     { r e a s o n } [ / ] " ) 
 
                 c o n s o l e . p r i n t ( 
 
                         P a n e l ( 
 
                                 f " [ b o l d   g r e e n ]     W r o t e   b u n d l e : [ / ]   [ c y a n ] { o u t p u t _ p a t h } [ / ] \ n " 
 
                                 f " [ g r e y 7 0 ] D r a g   t h i s   f i l e   i n t o   C h a t G P T   ( P l u s ) ,   C l a u d e . a i ,   o r   G e m i n i . [ / ] " , 
 
                                 t i t l e = " [ b o l d ] a"    L o c a l   b u n d l e [ / ] " , 
 
                                 b o r d e r _ s t y l e = " g r e e n " , 
 
                                 p a d d i n g = ( 1 ,   2 ) , 
 
                         ) 
 
                 ) 
 
 
 
         i f   f i l e : 
 
                 _ w r i t e _ l o c a l ( ) 
 
         e l s e : 
 
                 w i t h   P r o g r e s s ( 
 
                         S p i n n e r C o l u m n ( ) , 
 
                         T e x t C o l u m n ( " [ c y a n ] U p l o a d i n g   t o   K r a i m i n d   s h a r e   e n d p o i n t . . . [ / ] " ) , 
 
                         c o n s o l e = c o n s o l e , 
 
                         t r a n s i e n t = T r u e , 
 
                 )   a s   p r o g r e s s : 
 
                         p r o g r e s s . a d d _ t a s k ( " u p l o a d " ,   t o t a l = N o n e ) 
 
                         t r y : 
 
                                 r e s u l t   =   u p l o a d _ b u n d l e ( b u n d l e . c o n t e n t ,   t t l _ h o u r s = t t l _ h o u r s ) 
 
                         e x c e p t   S h a r e U p l o a d E r r o r   a s   e x c : 
 
                                 _ w r i t e _ l o c a l ( r e a s o n = f " U p l o a d   f a i l e d   ( { e x c } ) .   W r o t e   l o c a l   b u n d l e   i n s t e a d . " ) 
 
                                 r e t u r n 
 
 
 
                 e x p i r e s _ l i n e   =   ( 
 
                         f " \ n [ g r e y 7 0 ] E x p i r e s : [ / ]   [ b o l d ] { r e s u l t . e x p i r e s _ a t } [ / ] "   i f   r e s u l t . e x p i r e s _ a t   e l s e   " " 
 
                 ) 
 
                 c o n s o l e . p r i n t ( 
 
                         P a n e l ( 
 
                                 f " [ b o l d   c y a n ] { r e s u l t . u r l } [ / ] \ n \ n " 
 
                                 f " [ g r e y 7 0 ] P a s t e   t h i s   U R L   i n t o   C h a t G P T   ( b r o w s i n g ) ,   C l a u d e . a i ,   G e m i n i , \ n " 
 
                                 f " t h e n   a s k   a b o u t   t h e   c o d e b a s e .   T h e   A I   w i l l   f e t c h   a n d   r e a d   a l l   f i l e s . [ / ] " 
 
                                 f " { e x p i r e s _ l i n e } " , 
 
                                 t i t l e = " [ b o l d ] a"    S h a r e   l i n k [ / ] " , 
 
                                 b o r d e r _ s t y l e = " c y a n " , 
 
                                 p a d d i n g = ( 1 ,   2 ) , 
 
                         ) 
 
                 ) 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 " \ n [ g r e y 5 0 ] E x c l u d e d   b y   d e f a u l t :   . e n v ,   * . k e y ,   * . p e m ,   l o c k   f i l e s ,   b i n a r i e s . \ n " 
 
                 " A d d   a   [ b o l d ] . k r a i m i n d i g n o r e [ / ]   t o   e x c l u d e   m o r e   p a t h s . [ / ] " 
 
         ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   h a n d o f f       g e n e r a t e   a   b r o w s e r - A I   c o n t e x t   h a n d o f f   p r o m p t 
 
 #                                                                                                                                                               
 
 
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   h a n d o f f ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
         q u e s t i o n :   O p t i o n a l [ s t r ]   =   t y p e r . O p t i o n ( 
 
                 N o n e ,   " - - q u e s t i o n " ,   " - q " ,   h e l p = " T h e   q u e s t i o n   y o u   w e r e   a b o u t   t o   a s k   t h e   A I . " 
 
         ) , 
 
         f u l l :   b o o l   =   t y p e r . O p t i o n ( 
 
                 F a l s e ,   " - - f u l l " ,   h e l p = " I n c l u d e   a l l   f i l e s   i n   t h e   s h a r e   ( d e f a u l t :   s m a r t   3 0 0   K B ) . " 
 
         ) , 
 
         s i n c e _ s t r :   O p t i o n a l [ s t r ]   =   t y p e r . O p t i o n ( 
 
                 N o n e ,   " - - s i n c e " ,   h e l p = " O n l y   i n c l u d e   f i l e s   m o d i f i e d   s i n c e   ( e . g .   ' 7 d ' ,   ' 2 0 2 5 - 0 5 - 2 0 ' ) . " 
 
         ) , 
 
         n o _ c l i p b o a r d :   b o o l   =   t y p e r . O p t i o n ( 
 
                 F a l s e ,   " - - n o - c l i p b o a r d " ,   h e l p = " P r i n t   p r o m p t   w i t h o u t   c o p y i n g   t o   c l i p b o a r d . " 
 
         ) , 
 
         t t l _ h o u r s :   i n t   =   t y p e r . O p t i o n ( 2 4 ,   " - - t t l " ,   h e l p = " S h a r e   l i n k   T T L   i n   h o u r s   ( 1 - 7 2 ) . " ) , 
 
 )   - >   N o n e : 
 
         " " " B u n d l e   y o u r   c o d e b a s e   a n d   g e n e r a t e   a   r e a d y - t o - p a s t e   p r o m p t   f o r   C h a t G P T ,   C l a u d e . a i ,   o r   G e m i n i . 
 
 
 
         U s e   t h i s   w h e n   y o u   r u n   o u t   o f   c r e d i t s   i n   V S C o d e   a n d   w a n t   t o   c o n t i n u e   i n   a   b r o w s e r   A I . 
 
         O n e   c o m m a n d   c a p t u r e s   y o u r   c o d e b a s e ,   g i t   c o n t e x t ,   a n d   q u e s t i o n       c o p i e d   t o   c l i p b o a r d . 
 
         " " " 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( )   o r   n o t   p r o j e c t _ p a t h . i s _ d i r ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         s i n c e   =   _ p a r s e _ s i n c e ( s i n c e _ s t r )   i f   s i n c e _ s t r   e l s e   N o n e 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"    G e n e r a t i n g   h a n d o f f   f o r [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] W a l k i n g   p r o j e c t   &   b u i l d i n g   b u n d l e . . . [ / ] " ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p r o g r e s s : 
 
                 p r o g r e s s . a d d _ t a s k ( " b u n d l e " ,   t o t a l = N o n e ) 
 
                 b u n d l e   =   b u i l d _ b u n d l e ( p r o j e c t _ p a t h ,   f u l l = f u l l ,   s i n c e = s i n c e ) 
 
 
 
         i f   b u n d l e . f i l e _ c o u n t   = =   0 : 
 
                 c o n s o l e . p r i n t ( " [ b o l d   y e l l o w ]     N o   s h a r e a b l e   f i l e s   f o u n d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         s i z e _ k b   =   b u n d l e . t o t a l _ b y t e s   / /   1 0 2 4 
 
         c o n s o l e . p r i n t ( 
 
                 f "     [ g r e e n ]   [ / ]   B u n d l e d   [ b o l d ] { b u n d l e . f i l e _ c o u n t } [ / ]   f i l e s   " 
 
                 f " ( [ b o l d ] { s i z e _ k b }   K B [ / ] ,   m o d e = [ b o l d ] { ' f u l l '   i f   f u l l   e l s e   ' s m a r t ' } [ / ] ) " 
 
         ) 
 
 
 
         s h a r e _ u r l :   s t r 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] U p l o a d i n g   t o   K r a i m i n d   s h a r e   e n d p o i n t . . . [ / ] " ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p r o g r e s s : 
 
                 p r o g r e s s . a d d _ t a s k ( " u p l o a d " ,   t o t a l = N o n e ) 
 
                 t r y : 
 
                         r e s u l t   =   u p l o a d _ b u n d l e ( b u n d l e . c o n t e n t ,   t t l _ h o u r s = t t l _ h o u r s ) 
 
                         s h a r e _ u r l   =   r e s u l t . u r l 
 
                         e x p i r e s _ a t   =   r e s u l t . e x p i r e s _ a t 
 
                 e x c e p t   S h a r e U p l o a d E r r o r   a s   e x c : 
 
                         l o c a l _ p a t h   =   p r o j e c t _ p a t h   /   " k r a i m i n d - h a n d o f f - b u n d l e . m d " 
 
                         l o c a l _ p a t h . w r i t e _ t e x t ( b u n d l e . c o n t e n t ,   e n c o d i n g = " u t f - 8 " ) 
 
                         c o n s o l e . p r i n t ( f "     [ y e l l o w ]     U p l o a d   f a i l e d   ( { e x c } ) .   B u n d l e   s a v e d   l o c a l l y : [ / ]   [ c y a n ] { l o c a l _ p a t h } [ / ] " ) 
 
                         s h a r e _ u r l   =   f " f i l e : / / { l o c a l _ p a t h } " 
 
                         e x p i r e s _ a t   =   N o n e 
 
 
 
         g i t _ c t x   =   g a t h e r _ g i t _ c o n t e x t ( p r o j e c t _ p a t h ) 
 
         p r o m p t _ t e x t   =   b u i l d _ h a n d o f f _ p r o m p t ( 
 
                 s h a r e _ u r l , 
 
                 g i t _ c t x , 
 
                 q u e s t i o n , 
 
                 s i n c e _ s t r , 
 
                 p r o j e c t _ n a m e = p r o j e c t _ p a t h . n a m e , 
 
                 f i l e _ c o u n t = b u n d l e . f i l e _ c o u n t , 
 
         ) 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         p r o m p t _ t e x t , 
 
                         t i t l e = " [ b o l d ] a"    H a n d o f f   P r o m p t [ / ] " , 
 
                         b o r d e r _ s t y l e = " c y a n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
         i f   n o t   n o _ c l i p b o a r d : 
 
                 c o p i e d   =   c o p y _ t o _ c l i p b o a r d ( p r o m p t _ t e x t ) 
 
                 i f   c o p i e d : 
 
                         c o n s o l e . p r i n t ( "     [ b o l d   g r e e n ]     C o p i e d   t o   c l i p b o a r d . [ / ]   P a s t e   i n t o   C h a t G P T ,   C l a u d e . a i ,   o r   G e m i n i . " ) 
 
                 e l s e : 
 
                         c o n s o l e . p r i n t ( "     [ y e l l o w ]     C l i p b o a r d   u n a v a i l a b l e       c o p y   t h e   p r o m p t   a b o v e   m a n u a l l y . [ / ] " ) 
 
         e l s e : 
 
                 c o n s o l e . p r i n t ( "     [ g r e y 5 0 ] ( - - n o - c l i p b o a r d :   c o p y   t h e   p r o m p t   a b o v e   m a n u a l l y . ) [ / ] " ) 
 
 
 
         i f   e x p i r e s _ a t : 
 
                 c o n s o l e . p r i n t ( f " \ n     [ g r e y 7 0 ] S h a r e   l i n k   e x p i r e s : [ / ]   [ b o l d ] { e x p i r e s _ a t } [ / ] " ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   c o s t       c a r b o n   /   C I - c o s t   t r a c k e r   ( F 5 ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   c o s t ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
         c i _ r u n s :   i n t   =   t y p e r . O p t i o n ( 0 ,   " - - c i - r u n s " ,   h e l p = " C I   r u n s   p e r   m o n t h   ( d e f a u l t :   2 0 0   o r   $ K R A I M I N D _ C I _ R U N S ) . " ) , 
 
         c o n c u r r e n c y :   i n t   =   t y p e r . O p t i o n ( 1 0 ,   " - - c o n c u r r e n c y " ,   " - c " ,   h e l p = " M a x   p a r a l l e l   A P I   r e q u e s t s . " ) , 
 
         f o r m a t :   s t r   =   t y p e r . O p t i o n ( " t e x t " ,   " - - f o r m a t " ,   " - f " ,   h e l p = " O u t p u t   f o r m a t :   t e x t   o r   j s o n . " ) , 
 
 )   - >   N o n e : 
 
         " " " E s t i m a t e   d e p e n d e n c y   c o s t :   i n s t a l l   s i z e ,   C I   t i m e ,   C O     f o o t p r i n t . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         i s _ j s o n   =   f o r m a t . l o w e r ( )   = =   " j s o n " 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
                 c o n s o l e . p r i n t ( ) 
 
                 c o n s o l e . p r i n t ( f " [ b o l d ] a" %  C o s t   a n a l y s i s [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         i f   n o t   d e c l a r e d : 
 
                 c o n s o l e . p r i n t ( " [ y e l l o w ]     N o   d e p e n d e n c i e s   f o u n d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         p k g _ l i s t   =   s o r t e d ( d e c l a r e d ) 
 
         i n t e l _ m a p   =   _ f e t c h _ w i t h _ p r o g r e s s ( p k g _ l i s t ,   c o n c u r r e n c y ,   s h o w _ p r o g r e s s = n o t   i s _ j s o n ) 
 
 
 
         s c o r e d   =   s c o r e _ a l l _ p a c k a g e s ( p r o j e c t _ p a t h ,   d e c l a r e d ) 
 
         u n u s e d   =   { p   f o r   p ,   r c   i n   s c o r e d . i t e m s ( )   i f   r c . i s _ l i k e l y _ u n u s e d } 
 
 
 
         r e p o r t   =   c o m p u t e _ c o s t _ r e p o r t ( 
 
                 i n t e l _ m a p , 
 
                 u n u s e d , 
 
                 c i _ r u n s _ p e r _ m o n t h = c i _ r u n s   i f   c i _ r u n s   >   0   e l s e   N o n e , 
 
         ) 
 
 
 
         i f   i s _ j s o n : 
 
                 o u t   =   { 
 
                         " c i _ r u n s _ p e r _ m o n t h " :   r e p o r t . c i _ r u n s _ p e r _ m o n t h , 
 
                         " t o t a l _ s i z e _ m b " :   r e p o r t . t o t a l _ s i z e _ m b , 
 
                         " u n u s e d _ s i z e _ m b " :   r e p o r t . u n u s e d _ s i z e _ m b , 
 
                         " m o n t h l y _ c i _ s e c o n d s _ t o t a l " :   r e p o r t . m o n t h l y _ c i _ s e c o n d s _ t o t a l , 
 
                         " m o n t h l y _ c i _ s e c o n d s _ u n u s e d " :   r e p o r t . m o n t h l y _ c i _ s e c o n d s _ u n u s e d , 
 
                         " m o n t h l y _ c o 2 _ g r a m s _ t o t a l " :   r e p o r t . m o n t h l y _ c o 2 _ g r a m s _ t o t a l , 
 
                         " m o n t h l y _ c o 2 _ g r a m s _ u n u s e d " :   r e p o r t . m o n t h l y _ c o 2 _ g r a m s _ u n u s e d , 
 
                         " y e a r l y _ s e c o n d s _ s a v e d " :   r e p o r t . y e a r l y _ s e c o n d s _ s a v e d , 
 
                         " y e a r l y _ c o 2 _ g r a m s _ s a v e d " :   r e p o r t . y e a r l y _ c o 2 _ g r a m s _ s a v e d , 
 
                         " t o p _ p a c k a g e s _ b y _ s i z e " :   [ 
 
                                 { " p a c k a g e " :   b . p a c k a g e ,   " s i z e _ m b " :   b . s i z e _ m b } 
 
                                 f o r   b   i n   r e p o r t . b r e a k d o w n s [ : 1 0 ] 
 
                         ] , 
 
                 } 
 
                 p r i n t ( j s o n _ l i b . d u m p s ( o u t ,   i n d e n t = 2 ) ) 
 
                 r e t u r n 
 
 
 
         c o n s o l e . p r i n t ( 
 
                 P a n e l ( 
 
                         f o r m a t _ c o s t _ r e p o r t ( r e p o r t ) , 
 
                         t i t l e = " [ b o l d ] a" %  D e p e n d e n c y   C o s t   R e p o r t [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e e n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
         ) 
 
 
 
         i f   r e p o r t . b r e a k d o w n s : 
 
                 t o p   =   r e p o r t . b r e a k d o w n s [ : 1 0 ] 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( " T o p   1 0   p a c k a g e s   b y   i n s t a l l   s i z e : \ n \ n " ,   s t y l e = " b o l d " ) 
 
                 f o r   b   i n   t o p : 
 
                         u n u s e d _ m a r k e r   =   "     [ u n u s e d ] "   i f   b . p a c k a g e   i n   u n u s e d   e l s e   " " 
 
                         t e x t . a p p e n d ( f "     { b . p a c k a g e : 2 5 s } " ,   s t y l e = " c y a n " ) 
 
                         t e x t . a p p e n d ( f " { b . s i z e _ m b : 6 . 1 f }   M B " ,   s t y l e = " b o l d " ) 
 
                         t e x t . a p p e n d ( f " { u n u s e d _ m a r k e r } \ n " ,   s t y l e = " r e d "   i f   u n u s e d _ m a r k e r   e l s e   " " ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( t e x t ,   b o r d e r _ s t y l e = " g r e y 5 0 " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   b i s e c t       e m p i r i c a l   r e m o v a l - s a f e t y   d e t e c t i o n   ( F 6 ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   b i s e c t ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
         c a n d i d a t e s :   s t r   =   t y p e r . O p t i o n ( " " ,   " - - c a n d i d a t e s " ,   h e l p = " C o m m a - s e p a r a t e d   p a c k a g e   n a m e s .   D e f a u l t s   t o   A S T - d e t e c t e d   u n u s e d . " ) , 
 
         t e s t _ c m d :   s t r   =   t y p e r . O p t i o n ( " " ,   " - - t e s t - c m d " ,   h e l p = " T e s t   c o m m a n d   t o   r u n .   D e f a u l t :   p y t e s t   - x . " ) , 
 
         t i m e o u t :   i n t   =   t y p e r . O p t i o n ( 6 0 0 ,   " - - t i m e o u t " ,   h e l p = " P e r - t e s t   t i m e o u t   i n   s e c o n d s . " ) , 
 
 )   - >   N o n e : 
 
         " " " E m p i r i c a l l y   t e s t   w h i c h   p a c k a g e s   a r e   s a f e   t o   r e m o v e   b y   u n i n s t a l l i n g   o n e - b y - o n e . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
         c o n s o l e . p r i n t ( ) 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] a"    B i s e c t i n g [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         i f   c a n d i d a t e s : 
 
                 c a n d i d a t e _ l i s t   =   [ c . s t r i p ( )   f o r   c   i n   c a n d i d a t e s . s p l i t ( " , " )   i f   c . s t r i p ( ) ] 
 
         e l s e : 
 
                 d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
                 l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
                 i f   l o c k e d : 
 
                         d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
                 s c o r e d   =   s c o r e _ a l l _ p a c k a g e s ( p r o j e c t _ p a t h ,   d e c l a r e d ) 
 
                 c a n d i d a t e _ l i s t   =   s o r t e d ( [ 
 
                         p   f o r   p ,   r c   i n   s c o r e d . i t e m s ( ) 
 
                         i f   r c . c o n f i d e n c e   > =   5 0   a n d   n o t   r c . i s _ d e f i n i t e l y _ u s e d 
 
                 ] ) 
 
 
 
         i f   n o t   c a n d i d a t e _ l i s t : 
 
                 c o n s o l e . p r i n t ( " [ y e l l o w ] N o   b i s e c t i o n   c a n d i d a t e s . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         c o n s o l e . p r i n t ( f "     [ b o l d ] { l e n ( c a n d i d a t e _ l i s t ) } [ / ]   c a n d i d a t e ( s ) :   { ' ,   ' . j o i n ( c a n d i d a t e _ l i s t ) } \ n " ) 
 
         c o n s o l e . p r i n t ( 
 
                 " [ g r e y 7 0 ] T h i s   w i l l   u n i n s t a l l   e a c h   c a n d i d a t e   o n e - b y - o n e   a n d   r e - r u n   y o u r   t e s t s . \ n " 
 
                 " E a c h   i t e r a t i o n   i s   r o l l e d   b a c k .   E x p e c t   s e v e r a l   m i n u t e s   p e r   c a n d i d a t e . [ / ] \ n " 
 
         ) 
 
 
 
         c o n f i r m   =   t y p e r . c o n f i r m ( " P r o c e e d ? " ,   d e f a u l t = F a l s e ) 
 
         i f   n o t   c o n f i r m : 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         w i t h   P r o g r e s s ( 
 
                 S p i n n e r C o l u m n ( ) , 
 
                 T e x t C o l u m n ( " [ c y a n ] B i s e c t i n g . . . [ / ] " ) , 
 
                 B a r C o l u m n ( b a r _ w i d t h = 4 0 ) , 
 
                 M o f N C o m p l e t e C o l u m n ( ) , 
 
                 T i m e E l a p s e d C o l u m n ( ) , 
 
                 c o n s o l e = c o n s o l e , 
 
                 t r a n s i e n t = T r u e , 
 
         )   a s   p : 
 
                 t a s k _ i d   =   p . a d d _ t a s k ( " b i s e c t " ,   t o t a l = l e n ( c a n d i d a t e _ l i s t ) ) 
 
 
 
                 d e f   _ p r o g r e s s ( _ p k g :   s t r )   - >   N o n e : 
 
                         p . a d v a n c e ( t a s k _ i d ,   1 ) 
 
 
 
                 r e p o r t   =   b i s e c t _ p a c k a g e s ( 
 
                         p r o j e c t _ p a t h , 
 
                         c a n d i d a t e _ l i s t , 
 
                         t e s t _ c m d = t e s t _ c m d   o r   N o n e , 
 
                         t i m e o u t = f l o a t ( t i m e o u t ) , 
 
                         o n _ p r o g r e s s = _ p r o g r e s s , 
 
                 ) 
 
 
 
         i f   r e p o r t . a b o r t e d : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]     B i s e c t i o n   a b o r t e d :   { r e p o r t . e r r o r } [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         s a f e   =   r e p o r t . s a f e _ p a c k a g e s 
 
         u s e d   =   r e p o r t . u s e d _ p a c k a g e s 
 
 
 
         i f   s a f e : 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( "     C o n f i r m e d   s a f e   t o   r e m o v e : \ n " ,   s t y l e = " b o l d   g r e e n " ) 
 
                 f o r   p _ n a m e   i n   s a f e : 
 
                         t e x t . a p p e n d ( f "         { p _ n a m e } \ n " ,   s t y l e = " g r e e n " ) 
 
                 t e x t . a p p e n d ( 
 
                         f " \ n R u n :   [ b o l d ] k r a i m i n d   r e m o v e   < p a c k a g e > [ / ]   f o r   e a c h . \ n " , 
 
                         s t y l e = " g r e y 7 0 " , 
 
                 ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( t e x t ,   b o r d e r _ s t y l e = " g r e e n " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
 
 
         i f   u s e d : 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( "     I n   a c t i v e   u s e   ( t e s t   f a i l u r e s   d e t e c t e d ) : \ n " ,   s t y l e = " b o l d   y e l l o w " ) 
 
                 f o r   p _ n a m e   i n   u s e d : 
 
                         t e x t . a p p e n d ( f "         { p _ n a m e } \ n " ,   s t y l e = " y e l l o w " ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( t e x t ,   b o r d e r _ s t y l e = " y e l l o w " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   r o l l b a c k       r e s t o r e   f r o m   a   s n a p s h o t   ( c o m p a n i o n   t o   r e m o v e ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   r o l l b a c k ( 
 
         s n a p s h o t _ n a m e :   s t r   =   t y p e r . A r g u m e n t ( " " ,   h e l p = " S n a p s h o t   f i l e n a m e   ( d e f a u l t :   l a t e s t ) . " ) , 
 
         l i s t _ o n l y :   b o o l   =   t y p e r . O p t i o n ( F a l s e ,   " - - l i s t " ,   h e l p = " L i s t   a v a i l a b l e   s n a p s h o t s   o n l y . " ) , 
 
 )   - >   N o n e : 
 
         " " " R e s t o r e   t h e   v e n v   f r o m   a   K r a i m i n d   s n a p s h o t . " " " 
 
 
 
         s n a p s h o t s   =   l i s t _ s n a p s h o t s ( ) 
 
         i f   l i s t _ o n l y   o r   n o t   s n a p s h o t s : 
 
                 i f   n o t   s n a p s h o t s : 
 
                         c o n s o l e . p r i n t ( " [ g r e y 5 0 ] N o   s n a p s h o t s   a v a i l a b l e . [ / ] " ) 
 
                         r e t u r n 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( " A v a i l a b l e   s n a p s h o t s : \ n \ n " ,   s t y l e = " b o l d " ) 
 
                 f o r   s   i n   s n a p s h o t s [ : 2 0 ] : 
 
                         t e x t . a p p e n d ( f "         { s . p a t h . n a m e } " ,   s t y l e = " c y a n " ) 
 
                         t e x t . a p p e n d ( f "       ( { s . p a c k a g e _ c o u n t }   p a c k a g e s ,   { s . a g e _ h o u r s : . 1 f } h   o l d ) \ n " ,   s t y l e = " g r e y 7 0 " ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( t e x t ,   b o r d e r _ s t y l e = " c y a n " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
                 r e t u r n 
 
 
 
         t a r g e t   =   s n a p s h o t s [ 0 ]   i f   n o t   s n a p s h o t _ n a m e   e l s e   n e x t ( 
 
                 ( s   f o r   s   i n   s n a p s h o t s   i f   s . p a t h . n a m e   = =   s n a p s h o t _ n a m e   o r   s t r ( s . p a t h )   = =   s n a p s h o t _ n a m e ) , 
 
                 N o n e , 
 
         ) 
 
         i f   t a r g e t   i s   N o n e : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]     S n a p s h o t   n o t   f o u n d :   { s n a p s h o t _ n a m e } [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         c o n s o l e . p r i n t ( f " [ b o l d ] R e s t o r i n g   f r o m : [ / ]   { t a r g e t . p a t h } " ) 
 
         o k   =   r e s t o r e _ s n a p s h o t ( t a r g e t ) 
 
         i f   o k : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   g r e e n ]     R e s t o r e d   { t a r g e t . p a c k a g e _ c o u n t }   p a c k a g e s . [ / ] " ) 
 
         e l s e : 
 
                 c o n s o l e . p r i n t ( " [ b o l d   r e d ]     R o l l b a c k   f a i l e d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
 
 
 #                                                                                                                                                               
 
 #   r i s k       s u p p l y - c h a i n   u r g e n c y   c h e c k   ( F 7       s t a n d a l o n e   s u r f a c e ) 
 
 #                                                                                                                                                               
 
 
 
 @ a p p . c o m m a n d ( ) 
 
 d e f   r i s k ( 
 
         p a t h :   s t r   =   t y p e r . A r g u m e n t ( " . " ,   h e l p = " P r o j e c t   p a t h . " ) , 
 
         c o n c u r r e n c y :   i n t   =   t y p e r . O p t i o n ( 1 0 ,   " - - c o n c u r r e n c y " ,   " - c " ) , 
 
         f o r m a t :   s t r   =   t y p e r . O p t i o n ( " t e x t " ,   " - - f o r m a t " ,   " - f " ) , 
 
 )   - >   N o n e : 
 
         " " " S u r f a c e   s u p p l y - c h a i n   r i s k   f l a g s :   t y p o s q u a t s ,   r e c e n t   C V E s ,   a r c h i v e d   r e p o s ,   f r e s h   r e l e a s e s . " " " 
 
 
 
         p r o j e c t _ p a t h   =   P a t h ( p a t h ) . r e s o l v e ( ) 
 
         i f   n o t   p r o j e c t _ p a t h . e x i s t s ( ) : 
 
                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ]   [ / ]   P a t h   n o t   f o u n d :   { p r o j e c t _ p a t h } " ) 
 
                 r a i s e   t y p e r . E x i t ( 1 ) 
 
 
 
         i s _ j s o n   =   f o r m a t . l o w e r ( )   = =   " j s o n " 
 
 
 
         i f   n o t   i s _ j s o n : 
 
                 c o n s o l e . p r i n t ( b a n n e r ( ) ) 
 
                 c o n s o l e . p r i n t ( ) 
 
                 c o n s o l e . p r i n t ( f " [ b o l d ] a"      S u p p l y - c h a i n   r i s k   s c a n [ / ]   [ c y a n ] { p r o j e c t _ p a t h } [ / ] \ n " ) 
 
 
 
         d e c l a r e d   =   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h ) 
 
         l o c k e d   =   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h ) 
 
         i f   l o c k e d : 
 
                 d e c l a r e d   =   d e c l a r e d   |   s e t ( l o c k e d . k e y s ( ) ) 
 
 
 
         i f   n o t   d e c l a r e d : 
 
                 c o n s o l e . p r i n t ( " [ y e l l o w ]     N o   d e p e n d e n c i e s   f o u n d . [ / ] " ) 
 
                 r a i s e   t y p e r . E x i t ( 0 ) 
 
 
 
         i n t e l _ m a p   =   _ f e t c h _ w i t h _ p r o g r e s s ( s o r t e d ( d e c l a r e d ) ,   c o n c u r r e n c y ,   s h o w _ p r o g r e s s = n o t   i s _ j s o n ) 
 
         a s s e s s m e n t s   =   a s s e s s _ a l l ( i n t e l _ m a p ) 
 
 
 
         f l a g g e d   =   [ a   f o r   a   i n   a s s e s s m e n t s . v a l u e s ( )   i f   a . h a s _ a n y _ f l a g ] 
 
 
 
         i f   i s _ j s o n : 
 
                 o u t   =   { 
 
                         " f l a g g e d _ c o u n t " :   l e n ( f l a g g e d ) , 
 
                         " p a c k a g e s " :   [ 
 
                                 { 
 
                                         " p a c k a g e " :   a . p a c k a g e , 
 
                                         " u r g e n t " :   a . h a s _ u r g e n t _ f l a g , 
 
                                         " f l a g s " :   [ 
 
                                                 { " c o d e " :   f . c o d e ,   " s e v e r i t y " :   f . s e v e r i t y ,   " m e s s a g e " :   f . m e s s a g e } 
 
                                                 f o r   f   i n   a . f l a g s 
 
                                         ] , 
 
                                 } 
 
                                 f o r   a   i n   f l a g g e d 
 
                         ] , 
 
                 } 
 
                 p r i n t ( j s o n _ l i b . d u m p s ( o u t ,   i n d e n t = 2 ) ) 
 
                 r e t u r n 
 
 
 
         i f   n o t   f l a g g e d : 
 
                 c o n s o l e . p r i n t ( 
 
                         P a n e l ( 
 
                                 " [ g r e e n ]     N o   s u p p l y - c h a i n   r i s k   s i g n a l s   d e t e c t e d . [ / ] " , 
 
                                 b o r d e r _ s t y l e = " g r e e n " , 
 
                                 p a d d i n g = ( 1 ,   2 ) , 
 
                         ) 
 
                 ) 
 
                 r e t u r n 
 
 
 
         u r g e n t   =   [ a   f o r   a   i n   f l a g g e d   i f   a . h a s _ u r g e n t _ f l a g ] 
 
         o t h e r   =   [ a   f o r   a   i n   f l a g g e d   i f   n o t   a . h a s _ u r g e n t _ f l a g ] 
 
 
 
         i f   u r g e n t : 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( f " { l e n ( u r g e n t ) }   U R G E N T   i s s u e ( s ) : \ n \ n " ,   s t y l e = " b o l d   r e d " ) 
 
                 f o r   a   i n   u r g e n t : 
 
                         t e x t . a p p e n d ( f "         { a . p a c k a g e } \ n " ,   s t y l e = " b o l d   r e d " ) 
 
                         f o r   f   i n   a . f l a g s : 
 
                                 t e x t . a p p e n d ( f "             [ { f . s e v e r i t y } ]   { f . m e s s a g e } \ n " ,   s t y l e = " r e d " ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( t e x t ,   t i t l e = " [ b o l d   r e d ] a"    U r g e n t [ / ] " ,   b o r d e r _ s t y l e = " r e d " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
 
 
         i f   o t h e r : 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( f " { l e n ( o t h e r ) }   a d v i s o r y   i s s u e ( s ) : \ n \ n " ,   s t y l e = " b o l d   y e l l o w " ) 
 
                 f o r   a   i n   o t h e r : 
 
                         t e x t . a p p e n d ( f "         { a . p a c k a g e } \ n " ,   s t y l e = " y e l l o w " ) 
 
                         f o r   f   i n   a . f l a g s : 
 
                                 t e x t . a p p e n d ( f "             [ { f . s e v e r i t y } ]   { f . m e s s a g e } \ n " ,   s t y l e = " g r e y 7 0 " ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( t e x t ,   t i t l e = " [ b o l d ] A d v i s o r i e s [ / ] " ,   b o r d e r _ s t y l e = " y e l l o w " ,   p a d d i n g = ( 1 ,   2 ) ) ) 
 
 
 
 
 
 i f   _ _ n a m e _ _   = =   " _ _ m a i n _ _ " : 
 
         a p p ( ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / c o s t . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " D e p e n d e n c y   c a r b o n   /   C I - c o s t   t r a c k e r . 
 
 
 
 E s t i m a t e s   t h e   c o s t   o f   c a r r y i n g   u n u s e d   o r   o v e r s i z e d   d e p e n d e n c i e s   t h r o u g h   C I . 
 
 N u m b e r s   a r e   t r a n s p a r e n t   e s t i m a t e s       e v e r y   p a r a m e t e r   i s   a u d i t a b l e . 
 
 
 
 D e f a u l t s   a r e   c o n s e r v a t i v e : 
 
     d o w n l o a d _ s p e e d _ m b p s     =   1 0 0     ( t y p i c a l   C I   r u n n e r ) 
 
     i n s t a l l _ o v e r h e a d _ p c t   =   3 0       ( w h e e l   e x t r a c t i o n ,   b y t e - c o m p i l e ,   e t c . ) 
 
     c i _ r u n s _ p e r _ m o n t h         =   2 0 0     ( e n v   o v e r r i d e :   K R A I M I N D _ C I _ R U N S ) 
 
     r u n n e r _ c o 2 _ g _ p e r _ s e c   =   0 . 0 1 2     ( t y p i c a l   x 8 6   C I   m i n u t e       0 . 7 g   C O   ) 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   o s 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   O p t i o n a l ,   S e t 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   C o s t B r e a k d o w n : 
 
         " " " C o s t   b r e a k d o w n   f o r   a   s i n g l e   p a c k a g e . " " " 
 
 
 
         p a c k a g e :   s t r 
 
         s i z e _ m b :   f l o a t 
 
         s e c o n d s _ p e r _ i n s t a l l :   f l o a t 
 
         m o n t h l y _ c i _ s e c o n d s :   f l o a t 
 
         m o n t h l y _ c o 2 _ g r a m s :   f l o a t 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   C o s t R e p o r t : 
 
         " " " F u l l   p r o j e c t - l e v e l   c o s t   a n a l y s i s . " " " 
 
 
 
         t o t a l _ s i z e _ m b :   f l o a t 
 
         u n u s e d _ s i z e _ m b :   f l o a t 
 
         m o n t h l y _ c i _ s e c o n d s _ t o t a l :   f l o a t 
 
         m o n t h l y _ c i _ s e c o n d s _ u n u s e d :   f l o a t 
 
         m o n t h l y _ c o 2 _ g r a m s _ t o t a l :   f l o a t 
 
         m o n t h l y _ c o 2 _ g r a m s _ u n u s e d :   f l o a t 
 
         c i _ r u n s _ p e r _ m o n t h :   i n t 
 
         y e a r l y _ s e c o n d s _ s a v e d :   f l o a t 
 
         y e a r l y _ c o 2 _ g r a m s _ s a v e d :   f l o a t 
 
         b r e a k d o w n s :   L i s t [ C o s t B r e a k d o w n ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
 
 
 
 
 d e f   _ d e f a u l t _ c i _ r u n s ( )   - >   i n t : 
 
         r a w   =   o s . g e t e n v ( " K R A I M I N D _ C I _ R U N S " ) 
 
         i f   r a w   a n d   r a w . i s d i g i t ( ) : 
 
                 r e t u r n   i n t ( r a w ) 
 
         r e t u r n   2 0 0 
 
 
 
 
 
 d e f   e s t i m a t e _ i n s t a l l _ s e c o n d s ( s i z e _ b y t e s :   i n t ,   d o w n l o a d _ s p e e d _ m b p s :   f l o a t   =   1 0 0 . 0 )   - >   f l o a t : 
 
         " " " E s t i m a t e   s e c o n d s   t o   d o w n l o a d   +   i n s t a l l   a   w h e e l   o f   t h e   g i v e n   s i z e . 
 
 
 
         F o r m u l a :   d o w n l o a d _ t i m e   +   3 0 %   i n s t a l l   o v e r h e a d . 
 
         " " " 
 
         i f   s i z e _ b y t e s   < =   0 : 
 
                 r e t u r n   0 . 0 
 
         b i t s   =   s i z e _ b y t e s   *   8 
 
         d o w n l o a d _ s e c o n d s   =   b i t s   /   ( d o w n l o a d _ s p e e d _ m b p s   *   1 _ 0 0 0 _ 0 0 0 ) 
 
         r e t u r n   d o w n l o a d _ s e c o n d s   *   1 . 3 
 
 
 
 
 
 d e f   c o m p u t e _ c o s t _ r e p o r t ( 
 
         i n t e l _ m a p :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] , 
 
         u n u s e d :   S e t [ s t r ] , 
 
         c i _ r u n s _ p e r _ m o n t h :   O p t i o n a l [ i n t ]   =   N o n e , 
 
         d o w n l o a d _ s p e e d _ m b p s :   f l o a t   =   1 0 0 . 0 , 
 
         r u n n e r _ c o 2 _ g _ p e r _ s e c :   f l o a t   =   0 . 0 1 2 , 
 
 )   - >   C o s t R e p o r t : 
 
         " " " C o m p u t e   a   p r o j e c t - w i d e   c o s t   r e p o r t   f r o m   i n t e l l i g e n c e   d a t a   +   u n u s e d   s e t . 
 
 
 
         A r g s : 
 
                 i n t e l _ m a p :   O u t p u t   o f   ` f e t c h _ a l l _ p a c k a g e s `       n e e d s   ` p y p i . r e l e a s e _ s i z e _ b y t e s `   p e r   p a c k a g e . 
 
                 u n u s e d :   S e t   o f   p a c k a g e s   f l a g g e d   a s   u n u s e d . 
 
                 c i _ r u n s _ p e r _ m o n t h :   C I   b u i l d s   p e r   m o n t h .   D e f a u l t s   t o   K R A I M I N D _ C I _ R U N S   e n v   o r   2 0 0 . 
 
                 d o w n l o a d _ s p e e d _ m b p s :   A s s u m e d   C I   r u n n e r   n e t w o r k   s p e e d . 
 
                 r u n n e r _ c o 2 _ g _ p e r _ s e c :   R u n n e r   e n e r g y   C O     p e r   s e c o n d . 
 
 
 
         R e t u r n s : 
 
                 C o s t R e p o r t . 
 
         " " " 
 
         c i _ r u n s   =   c i _ r u n s _ p e r _ m o n t h   i f   c i _ r u n s _ p e r _ m o n t h   i s   n o t   N o n e   e l s e   _ d e f a u l t _ c i _ r u n s ( ) 
 
 
 
         b r e a k d o w n s :   L i s t [ C o s t B r e a k d o w n ]   =   [ ] 
 
         t o t a l _ s i z e _ m b   =   0 . 0 
 
         u n u s e d _ s i z e _ m b   =   0 . 0 
 
         m o n t h l y _ t o t a l _ s e c o n d s   =   0 . 0 
 
         m o n t h l y _ u n u s e d _ s e c o n d s   =   0 . 0 
 
         m o n t h l y _ t o t a l _ c o 2   =   0 . 0 
 
         m o n t h l y _ u n u s e d _ c o 2   =   0 . 0 
 
 
 
         f o r   p k g ,   i n t e l   i n   i n t e l _ m a p . i t e m s ( ) : 
 
                 p y p i   =   i n t e l . g e t ( " p y p i " )   o r   { } 
 
                 s i z e _ b y t e s   =   p y p i . g e t ( " r e l e a s e _ s i z e _ b y t e s " )   o r   0 
 
                 s i z e _ m b   =   s i z e _ b y t e s   /   ( 1 0 2 4   *   1 0 2 4 ) 
 
                 s e c o n d s _ p e r _ i n s t a l l   =   e s t i m a t e _ i n s t a l l _ s e c o n d s ( s i z e _ b y t e s ,   d o w n l o a d _ s p e e d _ m b p s ) 
 
                 m o n t h l y _ s e c o n d s   =   s e c o n d s _ p e r _ i n s t a l l   *   c i _ r u n s 
 
                 m o n t h l y _ c o 2   =   m o n t h l y _ s e c o n d s   *   r u n n e r _ c o 2 _ g _ p e r _ s e c 
 
 
 
                 b r e a k d o w n s . a p p e n d ( 
 
                         C o s t B r e a k d o w n ( 
 
                                 p a c k a g e = p k g , 
 
                                 s i z e _ m b = s i z e _ m b , 
 
                                 s e c o n d s _ p e r _ i n s t a l l = s e c o n d s _ p e r _ i n s t a l l , 
 
                                 m o n t h l y _ c i _ s e c o n d s = m o n t h l y _ s e c o n d s , 
 
                                 m o n t h l y _ c o 2 _ g r a m s = m o n t h l y _ c o 2 , 
 
                         ) 
 
                 ) 
 
 
 
                 t o t a l _ s i z e _ m b   + =   s i z e _ m b 
 
                 m o n t h l y _ t o t a l _ s e c o n d s   + =   m o n t h l y _ s e c o n d s 
 
                 m o n t h l y _ t o t a l _ c o 2   + =   m o n t h l y _ c o 2 
 
 
 
                 i f   p k g   i n   u n u s e d : 
 
                         u n u s e d _ s i z e _ m b   + =   s i z e _ m b 
 
                         m o n t h l y _ u n u s e d _ s e c o n d s   + =   m o n t h l y _ s e c o n d s 
 
                         m o n t h l y _ u n u s e d _ c o 2   + =   m o n t h l y _ c o 2 
 
 
 
         b r e a k d o w n s . s o r t ( k e y = l a m b d a   b :   b . s i z e _ m b ,   r e v e r s e = T r u e ) 
 
 
 
         r e t u r n   C o s t R e p o r t ( 
 
                 t o t a l _ s i z e _ m b = t o t a l _ s i z e _ m b , 
 
                 u n u s e d _ s i z e _ m b = u n u s e d _ s i z e _ m b , 
 
                 m o n t h l y _ c i _ s e c o n d s _ t o t a l = m o n t h l y _ t o t a l _ s e c o n d s , 
 
                 m o n t h l y _ c i _ s e c o n d s _ u n u s e d = m o n t h l y _ u n u s e d _ s e c o n d s , 
 
                 m o n t h l y _ c o 2 _ g r a m s _ t o t a l = m o n t h l y _ t o t a l _ c o 2 , 
 
                 m o n t h l y _ c o 2 _ g r a m s _ u n u s e d = m o n t h l y _ u n u s e d _ c o 2 , 
 
                 c i _ r u n s _ p e r _ m o n t h = c i _ r u n s , 
 
                 y e a r l y _ s e c o n d s _ s a v e d = m o n t h l y _ u n u s e d _ s e c o n d s   *   1 2 , 
 
                 y e a r l y _ c o 2 _ g r a m s _ s a v e d = m o n t h l y _ u n u s e d _ c o 2   *   1 2 , 
 
                 b r e a k d o w n s = b r e a k d o w n s , 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ c o s t _ r e p o r t ( r e p o r t :   C o s t R e p o r t )   - >   s t r : 
 
         " " " B u i l d   a   p l a i n - t e x t   s u m m a r y   s t r i n g   f o r   t h e   c o s t   r e p o r t . " " " 
 
         l i n e s   =   [ ] 
 
         l i n e s . a p p e n d ( f " T o t a l   i n s t a l l   s i z e :               { r e p o r t . t o t a l _ s i z e _ m b : . 1 f }   M B " ) 
 
         l i n e s . a p p e n d ( f " U n u s e d   i n s t a l l   s i z e :             { r e p o r t . u n u s e d _ s i z e _ m b : . 1 f }   M B " ) 
 
         l i n e s . a p p e n d ( f " C I   r u n s / m o n t h   a s s u m e d :         { r e p o r t . c i _ r u n s _ p e r _ m o n t h } " ) 
 
         l i n e s . a p p e n d ( " " ) 
 
         l i n e s . a p p e n d ( f " M o n t h l y   C I   t i m e   ( t o t a l ) :     { r e p o r t . m o n t h l y _ c i _ s e c o n d s _ t o t a l   /   6 0 : . 1 f }   m i n " ) 
 
         l i n e s . a p p e n d ( f " M o n t h l y   C I   t i m e   ( u n u s e d ) :   { r e p o r t . m o n t h l y _ c i _ s e c o n d s _ u n u s e d   /   6 0 : . 1 f }   m i n " ) 
 
         l i n e s . a p p e n d ( f " M o n t h l y   C O     ( t o t a l ) :             { r e p o r t . m o n t h l y _ c o 2 _ g r a m s _ t o t a l : . 1 f }   g " ) 
 
         l i n e s . a p p e n d ( f " M o n t h l y   C O     ( u n u s e d ) :           { r e p o r t . m o n t h l y _ c o 2 _ g r a m s _ u n u s e d : . 1 f }   g " ) 
 
         l i n e s . a p p e n d ( " " ) 
 
         l i n e s . a p p e n d ( f " Y e a r l y   s a v i n g s   i f   u n u s e d   r e m o v e d : " ) 
 
         l i n e s . a p p e n d ( f "      %  { r e p o r t . y e a r l y _ s e c o n d s _ s a v e d   /   6 0 : . 1 f }   C I - m i n u t e s " ) 
 
         l i n e s . a p p e n d ( f "     a" %  { r e p o r t . y e a r l y _ c o 2 _ g r a m s _ s a v e d : . 1 f }   g   C O   " ) 
 
         r e t u r n   " \ n " . j o i n ( l i n e s ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / d e t e c t i o n / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " C o n f i d e n c e - s c o r e d   u n u s e d   d e p e n d e n c y   d e t e c t i o n . 
 
 
 
 C o m b i n e s   m u l t i p l e   s i g n a l s   ( A S T ,   s t r i n g - s e a r c h ,   e n t r y - p o i n t s ,   g i t   h i s t o r y , 
 
 o p t i o n a l   e x t r a s )   i n t o   a   0 - 1 0 0   c o n f i d e n c e   s c o r e   i n d i c a t i n g   h o w   s a f e   i t   i s   t o 
 
 r e m o v e   a   d e c l a r e d   d e p e n d e n c y . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   k r a i m i n d . d e t e c t i o n . c o n f i d e n c e   i m p o r t   ( 
 
         D e t e c t i o n S i g n a l s , 
 
         R e m o v a l C o n f i d e n c e , 
 
         s c o r e _ r e m o v a l _ c o n f i d e n c e , 
 
         s c o r e _ a l l _ p a c k a g e s , 
 
 ) 
 
 
 
 _ _ a l l _ _   =   [ 
 
         " D e t e c t i o n S i g n a l s " , 
 
         " R e m o v a l C o n f i d e n c e " , 
 
         " s c o r e _ r e m o v a l _ c o n f i d e n c e " , 
 
         " s c o r e _ a l l _ p a c k a g e s " , 
 
 ] 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / d e t e c t i o n / a s t _ s i g n a l s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A S T - b a s e d   s i g n a l :   d o e s   a n y   s o u r c e   f i l e   i m p o r t   t h i s   p a c k a g e ? " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   S e t 
 
 
 
 f r o m   k r a i m i n d . p a r s e r . a s t _ s c a n n e r   i m p o r t   s c a n _ p r o j e c t _ i m p o r t s 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   I M P O R T _ T O _ P A C K A G E ,   n o r m a l i z e _ p a c k a g e _ n a m e 
 
 
 
 
 
 d e f   b u i l d _ i m p o r t _ i n d e x ( p r o j e c t _ p a t h :   P a t h )   - >   S e t [ s t r ] : 
 
         " " " R e t u r n   t h e   s e t   o f   c a n o n i c a l   P y P I   p a c k a g e   n a m e s   i m p o r t e d   a n y w h e r e   i n   t h e   p r o j e c t . 
 
 
 
         W r a p s   ` s c a n _ p r o j e c t _ i m p o r t s `   +   ` m a p _ i m p o r t s _ t o _ p a c k a g e s `   b u t   e x p o s e s   t h e   r a w 
 
         s e t   s o   t h e   c o n f i d e n c e   l a y e r   c a n   a s k :   " i s   X   i n   h e r e ? " . 
 
         " " " 
 
         r a w   =   s c a n _ p r o j e c t _ i m p o r t s ( p r o j e c t _ p a t h ) 
 
         p k g s :   S e t [ s t r ]   =   s e t ( ) 
 
         f o r   i m p   i n   r a w : 
 
                 c a n o n i c a l   =   I M P O R T _ T O _ P A C K A G E . g e t ( i m p ,   i m p ) 
 
                 p k g s . a d d ( n o r m a l i z e _ p a c k a g e _ n a m e ( c a n o n i c a l ) ) 
 
         r e t u r n   p k g s 
 
 
 
 
 
 d e f   a s t _ i m p o r t e d ( p a c k a g e :   s t r ,   i m p o r t _ i n d e x :   S e t [ s t r ] )   - >   b o o l : 
 
         " " " T r u e   i f   ` p a c k a g e `   ( n o r m a l i z e d )   i s   i n   t h e   A S T - s c a n n e d   i m p o r t   i n d e x . " " " 
 
         r e t u r n   n o r m a l i z e _ p a c k a g e _ n a m e ( p a c k a g e )   i n   i m p o r t _ i n d e x 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / d e t e c t i o n / c o n f i d e n c e . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " C o n f i d e n c e   s c o r e r :   c o m b i n e s   a l l   d e t e c t i o n   s i g n a l s   i n t o   a   0 - 1 0 0   r e m o v a l   c o n f i d e n c e . 
 
 
 
 H i g h e r   c o n f i d e n c e   =   s a f e r   t o   r e m o v e . 
 
 
 
 A l g o r i t h m   ( m i r r o r s   t r u s t . p y ' s   t r a n s p a r e n t   r u l e - b a s e d   a p p r o a c h ) : 
 
     -   A S T   s c a n :   0   i m p o r t s               + 4 0 
 
     -   S t r i n g   s e a r c h :   0   h i t s           + 2 5 
 
     -   N o   p l u g i n   e n t r y - p o i n t s         + 1 5 
 
     -   G i t :   n o   t o u c h   i n   3 6 5 d           + 1 0 
 
     -   N o t   i n   o p t i o n a l   e x t r a s         + 1 0 
 
     -   T o t a l   c l a m p e d   t o   [ 0 ,   1 0 0 ] 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   L i s t ,   O p t i o n a l ,   S e t 
 
 
 
 f r o m   k r a i m i n d . d e t e c t i o n . a s t _ s i g n a l s   i m p o r t   a s t _ i m p o r t e d ,   b u i l d _ i m p o r t _ i n d e x 
 
 f r o m   k r a i m i n d . d e t e c t i o n . e n t r y _ p o i n t s   i m p o r t   h a s _ p l u g i n _ e n t r y _ p o i n t s 
 
 f r o m   k r a i m i n d . d e t e c t i o n . g i t _ s i g n a l s   i m p o r t   d a y s _ s i n c e _ g r e p _ t o u c h e d 
 
 f r o m   k r a i m i n d . d e t e c t i o n . s t r i n g _ s i g n a l s   i m p o r t   s c a n _ s t r i n g _ o c c u r r e n c e s 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   D e t e c t i o n S i g n a l s : 
 
         " " " R a w   p e r - p a c k a g e   s i g n a l   v a l u e s       f e e d s   t h e   c o n f i d e n c e   f o r m u l a . " " " 
 
 
 
         a s t _ i m p o r t e d :   b o o l 
 
         s t r i n g _ o c c u r r e n c e s :   i n t 
 
         h a s _ e n t r y _ p o i n t s :   b o o l 
 
         d a y s _ s i n c e _ g i t _ t o u c h :   O p t i o n a l [ i n t ] 
 
         i s _ o p t i o n a l _ e x t r a :   b o o l 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   R e m o v a l C o n f i d e n c e : 
 
         " " " P e r - p a c k a g e   r e m o v a l   c o n f i d e n c e   +   r a t i o n a l e . " " " 
 
 
 
         p a c k a g e :   s t r 
 
         c o n f i d e n c e :   i n t 
 
         l a b e l :   s t r 
 
         p o s i t i v e s :   L i s t [ s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
         c o n c e r n s :   L i s t [ s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
         s i g n a l s :   O p t i o n a l [ D e t e c t i o n S i g n a l s ]   =   N o n e 
 
 
 
         @ p r o p e r t y 
 
         d e f   i s _ l i k e l y _ u n u s e d ( s e l f )   - >   b o o l : 
 
                 " " " C o n s e r v a t i v e   t h r e s h o l d :   7 0 +   c o n f i d e n c e       s a f e   t o   s u g g e s t   r e m o v a l . " " " 
 
                 r e t u r n   s e l f . c o n f i d e n c e   > =   7 0 
 
 
 
         @ p r o p e r t y 
 
         d e f   i s _ d e f i n i t e l y _ u s e d ( s e l f )   - >   b o o l : 
 
                 " " " L o w   c o n f i d e n c e   ( <   3 0 )       c l e a r l y   u s e d ;   d o n ' t   s u g g e s t   r e m o v a l . " " " 
 
                 r e t u r n   s e l f . c o n f i d e n c e   <   3 0 
 
 
 
 
 
 d e f   c o n f i d e n c e _ l a b e l ( s c o r e :   i n t )   - >   s t r : 
 
         " " " H u m a n - r e a d a b l e   l a b e l   f o r   a   c o n f i d e n c e   s c o r e . " " " 
 
         i f   s c o r e   > =   9 0 : 
 
                 r e t u r n   " V e r y   H i g h " 
 
         i f   s c o r e   > =   7 0 : 
 
                 r e t u r n   " H i g h " 
 
         i f   s c o r e   > =   5 0 : 
 
                 r e t u r n   " M o d e r a t e " 
 
         i f   s c o r e   > =   3 0 : 
 
                 r e t u r n   " L o w " 
 
         r e t u r n   " V e r y   L o w " 
 
 
 
 
 
 d e f   s c o r e _ r e m o v a l _ c o n f i d e n c e ( 
 
         p a c k a g e :   s t r , 
 
         s i g n a l s :   D e t e c t i o n S i g n a l s , 
 
 )   - >   R e m o v a l C o n f i d e n c e : 
 
         " " " C o m p u t e   a   0 - 1 0 0   c o n f i d e n c e   s c o r e   t h a t   ` p a c k a g e `   i s   s a f e   t o   r e m o v e . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   n a m e   b e i n g   e v a l u a t e d . 
 
                 s i g n a l s :   P r e - c o m p u t e d   s i g n a l   v a l u e s . 
 
 
 
         R e t u r n s : 
 
                 R e m o v a l C o n f i d e n c e   w i t h   s c o r e ,   l a b e l ,   a n d   h u m a n - r e a d a b l e   r a t i o n a l e . 
 
         " " " 
 
         s c o r e   =   0 
 
         p o s i t i v e s :   L i s t [ s t r ]   =   [ ] 
 
         c o n c e r n s :   L i s t [ s t r ]   =   [ ] 
 
 
 
         #         A S T   s i g n a l   ( 4 0   p o i n t s )                                                                                             
 
         i f   n o t   s i g n a l s . a s t _ i m p o r t e d : 
 
                 s c o r e   + =   4 0 
 
                 p o s i t i v e s . a p p e n d ( " N o   ` i m p o r t `   s t a t e m e n t s   f o u n d   i n   a n y   . p y   f i l e " ) 
 
         e l s e : 
 
                 c o n c e r n s . a p p e n d ( " I m p o r t e d   b y   s o u r c e   c o d e   ( A S T   s c a n ) " ) 
 
 
 
         #         S t r i n g - s e a r c h   s i g n a l   ( 2 5   p o i n t s )                                                                         
 
         i f   s i g n a l s . s t r i n g _ o c c u r r e n c e s   = =   0 : 
 
                 s c o r e   + =   2 5 
 
                 p o s i t i v e s . a p p e n d ( " N o   q u o t e d   s t r i n g   r e f e r e n c e s   ( n o   d y n a m i c   i m p o r t s ) " ) 
 
         e l i f   s i g n a l s . s t r i n g _ o c c u r r e n c e s   < =   2 : 
 
                 s c o r e   + =   1 0 
 
                 c o n c e r n s . a p p e n d ( 
 
                         f " F o u n d   { s i g n a l s . s t r i n g _ o c c u r r e n c e s }   s t r i n g   o c c u r r e n c e ( s )       p o s s i b l e   d y n a m i c   i m p o r t " 
 
                 ) 
 
         e l s e : 
 
                 c o n c e r n s . a p p e n d ( 
 
                         f " F o u n d   { s i g n a l s . s t r i n g _ o c c u r r e n c e s }   s t r i n g   r e f e r e n c e s       l i k e l y   l o a d e d   d y n a m i c a l l y " 
 
                 ) 
 
 
 
         #         E n t r y - p o i n t s   s i g n a l   ( 1 5   p o i n t s )                                                                           
 
         i f   n o t   s i g n a l s . h a s _ e n t r y _ p o i n t s : 
 
                 s c o r e   + =   1 5 
 
                 p o s i t i v e s . a p p e n d ( " N o   p l u g i n   e n t r y - p o i n t s   ( n o t   l o a d e d   i n d i r e c t l y   b y   o t h e r   t o o l s ) " ) 
 
         e l s e : 
 
                 c o n c e r n s . a p p e n d ( " R e g i s t e r s   p l u g i n   e n t r y - p o i n t s       m a y   b e   l o a d e d   i n d i r e c t l y " ) 
 
 
 
         #         G i t   s i g n a l   ( 1 0   p o i n t s )                                                                                             
 
         i f   s i g n a l s . d a y s _ s i n c e _ g i t _ t o u c h   i s   N o n e : 
 
                 #   N o   g i t   o r   n o   i n f o       n e u t r a l 
 
                 p a s s 
 
         e l i f   s i g n a l s . d a y s _ s i n c e _ g i t _ t o u c h   >   3 6 5 : 
 
                 s c o r e   + =   1 0 
 
                 p o s i t i v e s . a p p e n d ( 
 
                         f " N o   f i l e   r e f e r e n c i n g   t h i s   p a c k a g e   t o u c h e d   i n   { s i g n a l s . d a y s _ s i n c e _ g i t _ t o u c h }   d a y s " 
 
                 ) 
 
         e l i f   s i g n a l s . d a y s _ s i n c e _ g i t _ t o u c h   <   3 0 : 
 
                 c o n c e r n s . a p p e n d ( 
 
                         f " R e c e n t l y   t o u c h e d   ( { s i g n a l s . d a y s _ s i n c e _ g i t _ t o u c h }   d a y s   a g o )       s t i l l   i n   a c t i v e   u s e ? " 
 
                 ) 
 
 
 
         #         O p t i o n a l - e x t r a s   s i g n a l   ( 1 0   p o i n t s )                                                                     
 
         i f   n o t   s i g n a l s . i s _ o p t i o n a l _ e x t r a : 
 
                 s c o r e   + =   1 0 
 
         e l s e : 
 
                 c o n c e r n s . a p p e n d ( " D e c l a r e d   a s   a n   o p t i o n a l   e x t r a       m a y   b e   n e e d e d   f o r   o p t - i n   f e a t u r e s " ) 
 
 
 
         s c o r e   =   m a x ( 0 ,   m i n ( 1 0 0 ,   s c o r e ) ) 
 
 
 
         r e t u r n   R e m o v a l C o n f i d e n c e ( 
 
                 p a c k a g e = p a c k a g e , 
 
                 c o n f i d e n c e = s c o r e , 
 
                 l a b e l = c o n f i d e n c e _ l a b e l ( s c o r e ) , 
 
                 p o s i t i v e s = p o s i t i v e s , 
 
                 c o n c e r n s = c o n c e r n s , 
 
                 s i g n a l s = s i g n a l s , 
 
         ) 
 
 
 
 
 
 d e f   s c o r e _ a l l _ p a c k a g e s ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         d e c l a r e d _ p a c k a g e s :   S e t [ s t r ] , 
 
         o p t i o n a l _ e x t r a s :   O p t i o n a l [ S e t [ s t r ] ]   =   N o n e , 
 
 )   - >   D i c t [ s t r ,   R e m o v a l C o n f i d e n c e ] : 
 
         " " " S c o r e   e v e r y   d e c l a r e d   p a c k a g e   f o r   r e m o v a l   c o n f i d e n c e . 
 
 
 
         P e r f o r m s   o n e   p r o j e c t - w i d e   A S T   s c a n   a n d   o n e   p r o j e c t - w i d e   s t r i n g   s c a n , 
 
         t h e n   p e r - p a c k a g e   e n t r y - p o i n t   a n d   g i t   l o o k u p s . 
 
 
 
         A r g s : 
 
                 p r o j e c t _ p a t h :   P r o j e c t   r o o t . 
 
                 d e c l a r e d _ p a c k a g e s :   A l l   d e c l a r e d   p a c k a g e   n a m e s   ( n o r m a l i z e d ) . 
 
                 o p t i o n a l _ e x t r a s :   S u b s e t   d e c l a r e d   a s   o p t i o n a l   e x t r a s   ( t r e a t e d   a s   l o w e r   c o n f i d e n c e ) . 
 
 
 
         R e t u r n s : 
 
                 M a p p i n g   p a c k a g e   n a m e       R e m o v a l C o n f i d e n c e . 
 
         " " " 
 
         o p t i o n a l _ e x t r a s   =   o p t i o n a l _ e x t r a s   o r   s e t ( ) 
 
 
 
         i m p o r t _ i n d e x   =   b u i l d _ i m p o r t _ i n d e x ( p r o j e c t _ p a t h ) 
 
         s t r i n g _ c o u n t s   =   s c a n _ s t r i n g _ o c c u r r e n c e s ( p r o j e c t _ p a t h ,   d e c l a r e d _ p a c k a g e s ) 
 
 
 
         r e s u l t s :   D i c t [ s t r ,   R e m o v a l C o n f i d e n c e ]   =   { } 
 
         f o r   p k g   i n   d e c l a r e d _ p a c k a g e s : 
 
                 s i g n a l s   =   D e t e c t i o n S i g n a l s ( 
 
                         a s t _ i m p o r t e d = a s t _ i m p o r t e d ( p k g ,   i m p o r t _ i n d e x ) , 
 
                         s t r i n g _ o c c u r r e n c e s = s t r i n g _ c o u n t s . g e t ( p k g ,   0 ) , 
 
                         h a s _ e n t r y _ p o i n t s = h a s _ p l u g i n _ e n t r y _ p o i n t s ( p k g ) , 
 
                         d a y s _ s i n c e _ g i t _ t o u c h = d a y s _ s i n c e _ g r e p _ t o u c h e d ( p r o j e c t _ p a t h ,   p k g ) , 
 
                         i s _ o p t i o n a l _ e x t r a = p k g   i n   o p t i o n a l _ e x t r a s , 
 
                 ) 
 
                 r e s u l t s [ p k g ]   =   s c o r e _ r e m o v a l _ c o n f i d e n c e ( p k g ,   s i g n a l s ) 
 
 
 
         r e t u r n   r e s u l t s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / d e t e c t i o n / e n t r y _ p o i n t s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " E n t r y - p o i n t   r e v e r s e   s i g n a l :   d o e s   t h i s   p a c k a g e   p r o v i d e   e n t r y _ p o i n t s   /   p l u g i n s ? 
 
 
 
 I f   a   p a c k a g e   r e g i s t e r s   e n t r y _ p o i n t s   ( e . g .   p y t e s t   p l u g i n s ,   s e t u p t o o l s   c o n s o l e _ s c r i p t s , 
 
 f l a k e 8   e x t e n s i o n s ) ,   i t   m a y   b e   l o a d e d   i n d i r e c t l y   e v e n   w h e n   n o   s o u r c e   c o d e   i m p o r t s   i t . 
 
 
 
 T h i s   m o d u l e   q u e r i e s   t h e   i n s t a l l e d   p a c k a g e ' s   m e t a d a t a   v i a   i m p o r t l i b . m e t a d a t a   t o 
 
 d e t e r m i n e   w h e t h e r   r e m o v i n g   i t   w o u l d   b r e a k   a   p l u g i n   c o n t r a c t . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   S e t 
 
 
 
 
 
 d e f   g e t _ e n t r y _ p o i n t _ g r o u p s ( p a c k a g e :   s t r )   - >   L i s t [ s t r ] : 
 
         " " " R e t u r n   t h e   e n t r y - p o i n t   g r o u p   n a m e s   e x p o s e d   b y   ` p a c k a g e `   ( i f   i n s t a l l e d ) . 
 
 
 
         R e t u r n s   a n   e m p t y   l i s t   i f   t h e   p a c k a g e   i s   n o t   i n s t a l l e d   o r   h a s   n o   e n t r y   p o i n t s . 
 
 
 
         E x a m p l e :   p y t e s t   p l u g i n s   e x p o s e   g r o u p   " p y t e s t 1 1 " ;   f l a k e 8   p l u g i n s   e x p o s e 
 
         " f l a k e 8 . e x t e n s i o n " ;   c o n s o l e   s c r i p t s   u s e   " c o n s o l e _ s c r i p t s " . 
 
         " " " 
 
         t r y : 
 
                 f r o m   i m p o r t l i b . m e t a d a t a   i m p o r t   e n t r y _ p o i n t s ,   P a c k a g e N o t F o u n d E r r o r ,   d i s t r i b u t i o n 
 
         e x c e p t   I m p o r t E r r o r : 
 
                 r e t u r n   [ ] 
 
 
 
         t r y : 
 
                 d i s t   =   d i s t r i b u t i o n ( p a c k a g e ) 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   [ ] 
 
 
 
         t r y : 
 
                 e p s   =   d i s t . e n t r y _ p o i n t s 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   [ ] 
 
 
 
         g r o u p s :   S e t [ s t r ]   =   s e t ( ) 
 
         f o r   e p   i n   e p s : 
 
                 g r o u p   =   g e t a t t r ( e p ,   " g r o u p " ,   N o n e ) 
 
                 i f   g r o u p : 
 
                         g r o u p s . a d d ( g r o u p ) 
 
         r e t u r n   s o r t e d ( g r o u p s ) 
 
 
 
 
 
 d e f   h a s _ p l u g i n _ e n t r y _ p o i n t s ( p a c k a g e :   s t r )   - >   b o o l : 
 
         " " " T r u e   i f   ` p a c k a g e `   e x p o s e s   p l u g i n - s t y l e   e n t r y _ p o i n t s   ( n o t   j u s t   c o n s o l e _ s c r i p t s ) . 
 
 
 
         C o n s o l e   s c r i p t s   a r e   u s e r - f a c i n g   C L I s ;   t h e i r   a b s e n c e   a f t e r   r e m o v a l   i s 
 
         e x p e c t e d   a n d   n o t   a   " h i d d e n   d e p e n d e n c y " .   P l u g i n   g r o u p s   ( p y t e s t 1 1 ,   f l a k e 8 . e x t e n s i o n , 
 
         e t c . )   i n d i c a t e   t h e   p a c k a g e   i s   l o a d e d   i n d i r e c t l y   b y   a n o t h e r   t o o l . 
 
         " " " 
 
         g r o u p s   =   g e t _ e n t r y _ p o i n t _ g r o u p s ( p a c k a g e ) 
 
         p l u g i n _ g r o u p s   =   { g   f o r   g   i n   g r o u p s   i f   g   ! =   " c o n s o l e _ s c r i p t s " } 
 
         r e t u r n   l e n ( p l u g i n _ g r o u p s )   >   0 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / d e t e c t i o n / g i t _ s i g n a l s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " G i t   s i g n a l :   w h e n   w a s   a   f i l e   r e f e r e n c i n g   t h i s   p a c k a g e   l a s t   t o u c h e d ? 
 
 
 
 A   p a c k a g e   w h o s e   l a s t   t o u c h   i n   g i t   h i s t o r y   w a s   1 8 +   m o n t h s   a g o   i s   a   s t r o n g e r 
 
 r e m o v a l   c a n d i d a t e   t h a n   o n e   r e f e r e n c e d   i n   a   f i l e   t o u c h e d   t h i s   w e e k . 
 
 
 
 U s e s   s u b p r o c e s s   t o   c a l l   ` g i t   l o g `   d i r e c t l y       n o   e x t r a   d e p e n d e n c y   r e q u i r e d . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   s u b p r o c e s s 
 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e z o n e 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   O p t i o n a l 
 
 
 
 
 
 d e f   _ i s _ g i t _ r e p o ( p r o j e c t _ p a t h :   P a t h )   - >   b o o l : 
 
         " " " T r u e   i f   ` p r o j e c t _ p a t h `   i s   i n s i d e   a   g i t   w o r k i n g   t r e e . " " " 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ " g i t " ,   " r e v - p a r s e " ,   " - - i s - i n s i d e - w o r k - t r e e " ] , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 5 . 0 , 
 
                 ) 
 
                 r e t u r n   r e s u l t . r e t u r n c o d e   = =   0   a n d   r e s u l t . s t d o u t . s t r i p ( )   = =   " t r u e " 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   F a l s e 
 
 
 
 
 
 d e f   d a y s _ s i n c e _ a n y _ t o u c h ( p r o j e c t _ p a t h :   P a t h )   - >   O p t i o n a l [ i n t ] : 
 
         " " " R e t u r n   t h e   n u m b e r   o f   d a y s   s i n c e   t h e   m o s t   r e c e n t   c o m m i t   i n   t h i s   r e p o . 
 
 
 
         N o n e   i f   n o t   a   g i t   r e p o   o r   g i t   u n a v a i l a b l e . 
 
         " " " 
 
         i f   n o t   _ i s _ g i t _ r e p o ( p r o j e c t _ p a t h ) : 
 
                 r e t u r n   N o n e 
 
 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ " g i t " ,   " l o g " ,   " - 1 " ,   " - - f o r m a t = % c I " ] , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 5 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   N o n e 
 
 
 
         i f   r e s u l t . r e t u r n c o d e   ! =   0   o r   n o t   r e s u l t . s t d o u t . s t r i p ( ) : 
 
                 r e t u r n   N o n e 
 
 
 
         t r y : 
 
                 l a s t   =   d a t e t i m e . f r o m i s o f o r m a t ( r e s u l t . s t d o u t . s t r i p ( ) . r e p l a c e ( " Z " ,   " + 0 0 : 0 0 " ) ) 
 
         e x c e p t   V a l u e E r r o r : 
 
                 r e t u r n   N o n e 
 
 
 
         d e l t a   =   d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   l a s t 
 
         r e t u r n   d e l t a . d a y s 
 
 
 
 
 
 d e f   d a y s _ s i n c e _ g r e p _ t o u c h e d ( p r o j e c t _ p a t h :   P a t h ,   s e a r c h _ t e r m :   s t r )   - >   O p t i o n a l [ i n t ] : 
 
         " " " D a y s   s i n c e   a n y   f i l e   * c o n t a i n i n g *   ` s e a r c h _ t e r m `   w a s   l a s t   m o d i f i e d   i n   g i t . 
 
 
 
         U s e s   ` g i t   l o g   - S `   ( p i c k a x e )   w h i c h   f i n d s   c o m m i t s   t h a t   a d d e d   o r   r e m o v e d   l i n e s 
 
         m a t c h i n g   t h e   t e r m .   F a l l s   b a c k   t o   N o n e   o n   a n y   f a i l u r e . 
 
         " " " 
 
         i f   n o t   _ i s _ g i t _ r e p o ( p r o j e c t _ p a t h ) : 
 
                 r e t u r n   N o n e 
 
         i f   n o t   s e a r c h _ t e r m : 
 
                 r e t u r n   N o n e 
 
 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ " g i t " ,   " l o g " ,   " - 1 " ,   " - - f o r m a t = % c I " ,   " - S " ,   s e a r c h _ t e r m ,   " - - a l l " ] , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 1 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   N o n e 
 
 
 
         i f   r e s u l t . r e t u r n c o d e   ! =   0   o r   n o t   r e s u l t . s t d o u t . s t r i p ( ) : 
 
                 r e t u r n   N o n e 
 
 
 
         t r y : 
 
                 l a s t   =   d a t e t i m e . f r o m i s o f o r m a t ( r e s u l t . s t d o u t . s t r i p ( ) . r e p l a c e ( " Z " ,   " + 0 0 : 0 0 " ) ) 
 
         e x c e p t   V a l u e E r r o r : 
 
                 r e t u r n   N o n e 
 
 
 
         d e l t a   =   d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   l a s t 
 
         r e t u r n   d e l t a . d a y s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / d e t e c t i o n / s t r i n g _ s i g n a l s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " S t r i n g - s e a r c h   s i g n a l :   c a t c h e s   d y n a m i c   i m p o r t s   l i k e   ` i m p o r t l i b . i m p o r t _ m o d u l e ( " f l a s k " ) ` . 
 
 
 
 A S T   s c a n n i n g   m i s s e s   ` _ _ i m p o r t _ _ ( " x " ) ` ,   ` i m p o r t l i b . i m p o r t _ m o d u l e ( " x " ) ` , 
 
 p l u g i n   d i s c o v e r y ,   c o n f i g - d r i v e n   i m p o r t s ,   a n d   s t r i n g - b a s e d   r e f e r e n c e s . 
 
 T h i s   m o d u l e   g r e p s   s o u r c e   f i l e s   f o r   l i t e r a l   p a c k a g e - n a m e   o c c u r r e n c e s . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   r e 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   S e t 
 
 
 
 f r o m   k r a i m i n d . p a r s e r . a s t _ s c a n n e r   i m p o r t   S K I P _ D I R S 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   I M P O R T _ T O _ P A C K A G E ,   n o r m a l i z e _ p a c k a g e _ n a m e 
 
 
 
 
 
 d e f   _ c a n d i d a t e _ s t r i n g s ( p a c k a g e :   s t r )   - >   S e t [ s t r ] : 
 
         " " " R e t u r n   t h e   s e t   o f   i d e n t i f i e r s   t h a t   c o u l d   r e f e r   t o   ` p a c k a g e `   i n   s o u r c e . 
 
 
 
         I n c l u d e s   t h e   p a c k a g e   n a m e   i t s e l f ,   i t s   u n d e r s c o r e   v a r i a n t ,   a n d   t h e 
 
         c a n o n i c a l   i m p o r t   n a m e   w h e n   d i f f e r e n t   ( e . g .   P I L       p i l l o w ,   s k l e a r n       s c i k i t - l e a r n ) . 
 
         " " " 
 
         o u t :   S e t [ s t r ]   =   s e t ( ) 
 
         p k g   =   n o r m a l i z e _ p a c k a g e _ n a m e ( p a c k a g e ) 
 
         o u t . a d d ( p k g ) 
 
         o u t . a d d ( p k g . r e p l a c e ( " - " ,   " _ " ) ) 
 
         o u t . a d d ( p k g . r e p l a c e ( " _ " ,   " - " ) ) 
 
 
 
         #   R e v e r s e - l o o k u p :   w h i c h   i m p o r t   n a m e s   m a p   t o   t h i s   p a c k a g e ? 
 
         f o r   i m p _ n a m e ,   c a n o n i c a l   i n   I M P O R T _ T O _ P A C K A G E . i t e m s ( ) : 
 
                 i f   n o r m a l i z e _ p a c k a g e _ n a m e ( c a n o n i c a l )   = =   p k g : 
 
                         o u t . a d d ( i m p _ n a m e ) 
 
                         o u t . a d d ( i m p _ n a m e . r e p l a c e ( " _ " ,   " - " ) ) 
 
         r e t u r n   { s   f o r   s   i n   o u t   i f   s } 
 
 
 
 
 
 d e f   s c a n _ s t r i n g _ o c c u r r e n c e s ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         p a c k a g e s :   S e t [ s t r ] , 
 
 )   - >   D i c t [ s t r ,   i n t ] : 
 
         " " " F o r   e a c h   p a c k a g e ,   c o u n t   s o u r c e   f i l e s   t h a t   c o n t a i n   i t s   n a m e   a s   a   q u o t e d   s t r i n g . 
 
 
 
         O n l y   c o u n t s   o c c u r r e n c e s   i n s i d e   s t r i n g   l i t e r a l s   ( h e u r i s t i c :   s u r r o u n d e d   b y 
 
         s i n g l e   o r   d o u b l e   q u o t e s )   t o   r e d u c e   f a l s e   p o s i t i v e s   f r o m   c o m m e n t s   /   v a r i a b l e   n a m e s . 
 
 
 
         R e t u r n s : 
 
                 M a p p i n g   p a c k a g e       n u m b e r   o f   s o u r c e   f i l e s   w i t h   a t   l e a s t   o n e   s t r i n g   o c c u r r e n c e . 
 
         " " " 
 
         i f   n o t   p a c k a g e s : 
 
                 r e t u r n   { } 
 
 
 
         c a n d i d a t e s :   D i c t [ s t r ,   S e t [ s t r ] ]   =   { p k g :   _ c a n d i d a t e _ s t r i n g s ( p k g )   f o r   p k g   i n   p a c k a g e s } 
 
 
 
         c o u n t s :   D i c t [ s t r ,   i n t ]   =   { p k g :   0   f o r   p k g   i n   p a c k a g e s } 
 
 
 
         p a t t e r n s :   D i c t [ s t r ,   r e . P a t t e r n [ s t r ] ]   =   { } 
 
         f o r   p k g ,   n a m e s   i n   c a n d i d a t e s . i t e m s ( ) : 
 
                 i f   n o t   n a m e s : 
 
                         c o n t i n u e 
 
                 e s c a p e d   =   " | " . j o i n ( r e . e s c a p e ( n )   f o r   n   i n   s o r t e d ( n a m e s ,   k e y = l e n ,   r e v e r s e = T r u e ) ) 
 
                 p a t t e r n s [ p k g ]   =   r e . c o m p i l e ( r f " " " [ ' " ] ( { e s c a p e d } ) [ ' " ] " " " ) 
 
 
 
         f o r   p y _ f i l e   i n   p r o j e c t _ p a t h . r g l o b ( " * . p y " ) : 
 
                 i f   a n y ( p a r t   i n   S K I P _ D I R S   f o r   p a r t   i n   p y _ f i l e . p a r t s ) : 
 
                         c o n t i n u e 
 
                 t r y : 
 
                         s o u r c e   =   p y _ f i l e . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
                 e x c e p t   ( O S E r r o r ,   P e r m i s s i o n E r r o r ) : 
 
                         c o n t i n u e 
 
 
 
                 f o r   p k g ,   p a t t e r n   i n   p a t t e r n s . i t e m s ( ) : 
 
                         i f   p a t t e r n . s e a r c h ( s o u r c e ) : 
 
                                 c o u n t s [ p k g ]   + =   1 
 
 
 
         r e t u r n   c o u n t s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / g i t h u b . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " F e t c h   r e p o s i t o r y   m e t a d a t a   f r o m   G i t H u b ' s   p u b l i c   R E S T   A P I . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   o s 
 
 i m p o r t   t i m e 
 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e d e l t a ,   t i m e z o n e 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   O p t i o n a l 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 f r o m   k r a i m i n d . u t i l s . c a c h e   i m p o r t   c a c h e d _ r e q u e s t 
 
 
 
 _ G I T H U B _ A P I   =   " h t t p s : / / a p i . g i t h u b . c o m " 
 
 
 
 
 
 d e f   _ h e a d e r s ( )   - >   D i c t [ s t r ,   s t r ] : 
 
         h :   D i c t [ s t r ,   s t r ]   =   { 
 
                 " A c c e p t " :   " a p p l i c a t i o n / v n d . g i t h u b + j s o n " , 
 
                 " X - G i t H u b - A p i - V e r s i o n " :   " 2 0 2 2 - 1 1 - 2 8 " , 
 
         } 
 
         t o k e n   =   o s . g e t e n v ( " G I T H U B _ T O K E N " )   o r   o s . g e t e n v ( " G H _ T O K E N " ) 
 
         i f   t o k e n : 
 
                 h [ " A u t h o r i z a t i o n " ]   =   f " B e a r e r   { t o k e n } " 
 
         r e t u r n   h 
 
 
 
 
 
 d e f   e x t r a c t _ r e p o _ s l u g _ f r o m _ u r l ( u r l :   O p t i o n a l [ s t r ] )   - >   O p t i o n a l [ s t r ] : 
 
         " " " E x t r a c t   ' o w n e r / r e p o '   f r o m   a   G i t H u b   U R L   ( h t t p s   o r   g i t @   f o r m ) . " " " 
 
         i f   n o t   u r l : 
 
                 r e t u r n   N o n e 
 
         u r l   =   u r l . s t r i p ( ) . r s t r i p ( " / " ) . r s t r i p ( " . g i t " ) 
 
         i f   " g i t h u b . c o m "   n o t   i n   u r l . l o w e r ( ) : 
 
                 r e t u r n   N o n e 
 
         #   h t t p s : / / g i t h u b . c o m / o w n e r / r e p o 
 
         i f   u r l . s t a r t s w i t h ( " h t t p s : / / " ) : 
 
                 p a r t s   =   u r l . r e p l a c e ( " h t t p s : / / g i t h u b . c o m / " ,   " " ) . s p l i t ( " / " ) 
 
                 i f   l e n ( p a r t s )   > =   2 : 
 
                         r e t u r n   f " { p a r t s [ 0 ] } / { p a r t s [ 1 ] } " 
 
         #   g i t @ g i t h u b . c o m : o w n e r / r e p o 
 
         i f   u r l . s t a r t s w i t h ( " g i t @ g i t h u b . c o m : " ) : 
 
                 p a r t s   =   u r l . r e p l a c e ( " g i t @ g i t h u b . c o m : " ,   " " ) . s p l i t ( " / " ) 
 
                 i f   l e n ( p a r t s )   > =   2 : 
 
                         r e t u r n   f " { p a r t s [ 0 ] } / { p a r t s [ 1 ] } " 
 
         #   b a r e   p a t h - s t y l e   m a t c h 
 
         f o r   p r e f i x   i n   ( " g i t h u b . c o m / " , ) : 
 
                 i f   p r e f i x   i n   u r l : 
 
                         a f t e r   =   u r l . s p l i t ( p r e f i x ,   1 ) [ 1 ] 
 
                         p a r t s   =   a f t e r . s p l i t ( " / " ) 
 
                         i f   l e n ( p a r t s )   > =   2 : 
 
                                 r e t u r n   f " { p a r t s [ 0 ] } / { p a r t s [ 1 ] } " 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   f e t c h _ r e p o _ m e t a d a t a ( 
 
         r e p o _ s l u g :   s t r , 
 
         u s e _ c a c h e :   b o o l   =   T r u e , 
 
 )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
         " " " F e t c h   p u b l i c   r e p o s i t o r y   m e t a d a t a   f r o m   t h e   G i t H u b   A P I . 
 
 
 
         H a n d l e s   r a t e   l i m i t i n g   a n d   n o n - e x i s t e n t   r e p o s   g r a c e f u l l y . 
 
 
 
         A r g s : 
 
                 r e p o _ s l u g :   ' o w n e r / r e p o '   s t r i n g   ( e . g .   ' p s f / r e q u e s t s ' ) . 
 
                 u s e _ c a c h e :   U s e   l o c a l   2 4 h   c a c h e   ( d e f a u l t   T r u e ) . 
 
 
 
         R e t u r n s : 
 
                 D i c t   o f   r e p o   m e t a d a t a ,   o r   N o n e   i f   n o t   f o u n d   /   r a t e - l i m i t e d   /   e r r o r . 
 
         " " " 
 
         i f   n o t   r e p o _ s l u g   o r   " / "   n o t   i n   r e p o _ s l u g : 
 
                 r e t u r n   N o n e 
 
 
 
         u r l   =   f " { _ G I T H U B _ A P I } / r e p o s / { r e p o _ s l u g } " 
 
 
 
         d e f   _ f e t c h ( r e t r y :   b o o l   =   T r u e )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
                 t r y : 
 
                         w i t h   h t t p x . C l i e n t ( t i m e o u t = 1 0 . 0 ,   f o l l o w _ r e d i r e c t s = T r u e )   a s   c l i e n t : 
 
                                 r e s p   =   c l i e n t . g e t ( u r l ,   h e a d e r s = _ h e a d e r s ( ) ) 
 
 
 
                                 i f   r e s p . s t a t u s _ c o d e   = =   4 0 4 : 
 
                                         r e t u r n   N o n e 
 
 
 
                                 i f   r e s p . s t a t u s _ c o d e   i n   ( 4 0 3 ,   4 2 9 ) : 
 
                                         #   R a t e   l i m i t   h i t 
 
                                         i f   r e t r y : 
 
                                                 r e s e t   =   r e s p . h e a d e r s . g e t ( " X - R a t e L i m i t - R e s e t " ) 
 
                                                 i f   r e s e t : 
 
                                                         w a i t   =   i n t ( r e s e t )   -   i n t ( t i m e . t i m e ( ) )   +   1 
 
                                                         i f   0   <   w a i t   < =   5 : 
 
                                                                 t i m e . s l e e p ( w a i t ) 
 
                                                                 r e t u r n   _ f e t c h ( r e t r y = F a l s e ) 
 
                                         r e t u r n   N o n e 
 
 
 
                                 r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                                 d a t a   =   r e s p . j s o n ( ) 
 
                 e x c e p t   E x c e p t i o n : 
 
                         r e t u r n   N o n e 
 
 
 
                 #   E x t r a c t   s e c u r i t y _ a n d _ a n a l y s i s   s a f e l y 
 
                 s e c   =   d a t a . g e t ( " s e c u r i t y _ a n d _ a n a l y s i s " )   o r   { } 
 
                 h a s _ s e c u r i t y _ p o l i c y   =   ( 
 
                         i s i n s t a n c e ( s e c ,   d i c t ) 
 
                         a n d   i s i n s t a n c e ( s e c . g e t ( " s e c r e t _ s c a n n i n g " ) ,   d i c t ) 
 
                         a n d   s e c [ " s e c r e t _ s c a n n i n g " ] . g e t ( " s t a t u s " )   = =   " e n a b l e d " 
 
                 ) 
 
 
 
                 r e t u r n   { 
 
                         " f u l l _ n a m e " :   d a t a . g e t ( " f u l l _ n a m e " ) , 
 
                         " h t m l _ u r l " :   d a t a . g e t ( " h t m l _ u r l " ) , 
 
                         " d e s c r i p t i o n " :   d a t a . g e t ( " d e s c r i p t i o n " ) , 
 
                         " s t a r s " :   d a t a . g e t ( " s t a r g a z e r s _ c o u n t " ,   0 ) , 
 
                         " f o r k s " :   d a t a . g e t ( " f o r k s _ c o u n t " ,   0 ) , 
 
                         " o p e n _ i s s u e s " :   d a t a . g e t ( " o p e n _ i s s u e s _ c o u n t " ,   0 ) , 
 
                         " l a s t _ p u s h " :   d a t a . g e t ( " p u s h e d _ a t " ) , 
 
                         " c r e a t e d _ a t " :   d a t a . g e t ( " c r e a t e d _ a t " ) , 
 
                         " u p d a t e d _ a t " :   d a t a . g e t ( " u p d a t e d _ a t " ) , 
 
                         " l a n g u a g e " :   d a t a . g e t ( " l a n g u a g e " ) , 
 
                         " h o m e p a g e " :   d a t a . g e t ( " h o m e p a g e " ) , 
 
                         " h a s _ s e c u r i t y _ p o l i c y " :   h a s _ s e c u r i t y _ p o l i c y , 
 
                         " a r c h i v e d " :   d a t a . g e t ( " a r c h i v e d " ,   F a l s e ) , 
 
                         " d i s a b l e d " :   d a t a . g e t ( " d i s a b l e d " ,   F a l s e ) , 
 
                 } 
 
 
 
         i f   u s e _ c a c h e : 
 
                 r e t u r n   c a c h e d _ r e q u e s t ( f " g i t h u b : { r e p o _ s l u g } " ,   _ f e t c h ,   t t l _ h o u r s = 2 4 ) 
 
         r e t u r n   _ f e t c h ( ) 
 
 
 
 
 
 d e f   i s _ r e p o _ a c t i v e ( m e t a d a t a :   D i c t [ s t r ,   A n y ] ,   t h r e s h o l d _ d a y s :   i n t   =   3 6 5 )   - >   b o o l : 
 
         " " " R e t u r n   T r u e   i f   t h e   r e p o ' s   l a s t   p u s h   i s   w i t h i n   t h r e s h o l d _ d a y s . " " " 
 
         t r y : 
 
                 r a w   =   m e t a d a t a . g e t ( " l a s t _ p u s h " ) 
 
                 i f   n o t   r a w : 
 
                         r e t u r n   F a l s e 
 
                 l a s t   =   d a t e t i m e . f r o m i s o f o r m a t ( r a w . r e p l a c e ( " Z " ,   " + 0 0 : 0 0 " ) ) 
 
                 r e t u r n   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   l a s t )   <   t i m e d e l t a ( d a y s = t h r e s h o l d _ d a y s ) 
 
         e x c e p t   ( V a l u e E r r o r ,   T y p e E r r o r ) : 
 
                 r e t u r n   F a l s e 
 
 
 
 
 
 d e f   d a y s _ s i n c e _ l a s t _ p u s h ( m e t a d a t a :   D i c t [ s t r ,   A n y ] )   - >   O p t i o n a l [ i n t ] : 
 
         " " " R e t u r n   n u m b e r   o f   d a y s   s i n c e   l a s t   p u s h ,   o r   N o n e   i f   u n k n o w n . " " " 
 
         t r y : 
 
                 r a w   =   m e t a d a t a . g e t ( " l a s t _ p u s h " ) 
 
                 i f   n o t   r a w : 
 
                         r e t u r n   N o n e 
 
                 l a s t   =   d a t e t i m e . f r o m i s o f o r m a t ( r a w . r e p l a c e ( " Z " ,   " + 0 0 : 0 0 " ) ) 
 
                 d e l t a   =   d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   l a s t 
 
                 r e t u r n   d e l t a . d a y s 
 
         e x c e p t   ( V a l u e E r r o r ,   T y p e E r r o r ) : 
 
                 r e t u r n   N o n e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / h a n d o f f . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " C o n t e x t   h a n d o f f       b u n d l e   +   s h a r e   a   c o d e b a s e   a n d   p r o d u c e   a   r e a d y - t o - p a s t e   p r o m p t 
 
 f o r   C h a t G P T ,   C l a u d e . a i ,   o r   G e m i n i   w h e n   s w i t c h i n g   f r o m   a   V S C o d e   A I   c o d i n g   t o o l . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   p l a t f o r m 
 
 i m p o r t   s u b p r o c e s s 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t ,   O p t i o n a l ,   T u p l e 
 
 
 
 f r o m   k r a i m i n d . s h a r e   i m p o r t   b u i l d _ a i _ h a n d s h a k e 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   G i t C o n t e x t : 
 
         b r a n c h :   s t r 
 
         m o d i f i e d _ f i l e s :   L i s t [ T u p l e [ s t r ,   s t r ] ]     #   ( s t a t u s _ c o d e ,   r e l _ p a t h ) 
 
         r e c e n t _ c o m m i t s :   L i s t [ s t r ]                             #   o n e l i n e   l o g   s t r i n g s ,   u p   t o   5 
 
         h a s _ u n c o m m i t t e d :   b o o l 
 
 
 
 
 
 d e f   _ g i t ( r o o t :   P a t h ,   * a r g s :   s t r )   - >   s t r : 
 
         " " " R u n   a   g i t   s u b c o m m a n d   u n d e r   ` r o o t ` ;   r e t u r n   s t d o u t   o r   ' '   o n   a n y   f a i l u r e . " " " 
 
         t r y : 
 
                 r   =   s u b p r o c e s s . r u n ( 
 
                         [ " g i t " ,   * a r g s ] , 
 
                         c w d = r o o t , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 5 . 0 , 
 
                 ) 
 
                 r e t u r n   r . s t d o u t . r s t r i p ( )   i f   r . r e t u r n c o d e   = =   0   e l s e   " " 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   " " 
 
 
 
 
 
 d e f   g a t h e r _ g i t _ c o n t e x t ( r o o t :   P a t h )   - >   G i t C o n t e x t : 
 
         " " " C o l l e c t   b r a n c h ,   m o d i f i e d   f i l e s ,   a n d   r e c e n t   c o m m i t s   f r o m   t h e   r e p o   a t   ` r o o t ` . 
 
 
 
         R e t u r n s   a n   e m p t y   G i t C o n t e x t   i f   t h e   d i r e c t o r y   i s   n o t   a   g i t   r e p o   o r   g i t   i s   a b s e n t . 
 
         " " " 
 
         b r a n c h   =   _ g i t ( r o o t ,   " r e v - p a r s e " ,   " - - a b b r e v - r e f " ,   " H E A D " ) . s t r i p ( ) 
 
         s t a t u s _ o u t   =   _ g i t ( r o o t ,   " s t a t u s " ,   " - - s h o r t " ) 
 
         m o d i f i e d   =   [ 
 
                 ( l i n e [ : 2 ] . s t r i p ( ) ,   l i n e [ 3 : ] ) 
 
                 f o r   l i n e   i n   s t a t u s _ o u t . s p l i t l i n e s ( ) 
 
                 i f   l i n e . s t r i p ( ) 
 
         ] 
 
         l o g _ o u t   =   _ g i t ( r o o t ,   " l o g " ,   " - - o n e l i n e " ,   " - 5 " ) 
 
         r e c e n t   =   [ l n . s t r i p ( )   f o r   l n   i n   l o g _ o u t . s p l i t l i n e s ( )   i f   l n . s t r i p ( ) ] 
 
         r e t u r n   G i t C o n t e x t ( 
 
                 b r a n c h = b r a n c h   o r   " u n k n o w n " , 
 
                 m o d i f i e d _ f i l e s = m o d i f i e d , 
 
                 r e c e n t _ c o m m i t s = r e c e n t , 
 
                 h a s _ u n c o m m i t t e d = b o o l ( m o d i f i e d ) , 
 
         ) 
 
 
 
 
 
 d e f   b u i l d _ h a n d o f f _ p r o m p t ( 
 
         s h a r e _ u r l :   s t r , 
 
         g i t _ c t x :   G i t C o n t e x t , 
 
         q u e s t i o n :   O p t i o n a l [ s t r ] , 
 
         s i n c e :   O p t i o n a l [ s t r ] , 
 
         p r o j e c t _ n a m e :   s t r , 
 
         f i l e _ c o u n t :   i n t , 
 
 )   - >   s t r : 
 
         " " " A s s e m b l e   t h e   r e a d y - t o - p a s t e   h a n d o f f   p r o m p t   f o r   t h e   b r o w s e r   A I . " " " 
 
         b r a n c h   =   g i t _ c t x . b r a n c h   i f   g i t _ c t x . b r a n c h   ! =   " u n k n o w n "   e l s e   N o n e 
 
         l i n e s :   L i s t [ s t r ]   =   [ 
 
                 b u i l d _ a i _ h a n d s h a k e ( p r o j e c t _ n a m e ,   f i l e _ c o u n t ,   b r a n c h ) , 
 
                 " I   w a s   u s i n g   a n   A I   c o d i n g   a s s i s t a n t   i n   V S C o d e   a n d   h i t   a   c r e d i t   l i m i t .   " 
 
                 " H e r e   i s   m y   f u l l   c o d e b a s e   c o n t e x t   s o   y o u   c a n   h e l p   m e   c o n t i n u e . " , 
 
                 " " , 
 
                 " # #   C o d e b a s e " , 
 
                 s h a r e _ u r l , 
 
                 " " , 
 
                 " F e t c h   t h i s   U R L   a n d   r e a d   i t       i t   r e t u r n s   t h e   f u l l   s o u r c e   o f   t h e   p r o j e c t   a s   m a r k d o w n . " , 
 
         ] 
 
 
 
         h a s _ g i t   =   g i t _ c t x . b r a n c h   ! =   " u n k n o w n "   o r   b o o l ( g i t _ c t x . r e c e n t _ c o m m i t s ) 
 
         i f   h a s _ g i t : 
 
                 l i n e s   + =   [ " " ,   " # #   W h e r e   I   w a s " ,   f " B r a n c h :   { g i t _ c t x . b r a n c h } " ] 
 
                 i f   s i n c e : 
 
                         l i n e s . a p p e n d ( f " O n l y   f i l e s   m o d i f i e d   s i n c e :   { s i n c e } " ) 
 
                 i f   g i t _ c t x . r e c e n t _ c o m m i t s : 
 
                         l i n e s . a p p e n d ( " R e c e n t   w o r k : " ) 
 
                         f o r   c o m m i t   i n   g i t _ c t x . r e c e n t _ c o m m i t s : 
 
                                 l i n e s . a p p e n d ( f "     -   { c o m m i t } " ) 
 
 
 
         i f   g i t _ c t x . h a s _ u n c o m m i t t e d : 
 
                 l i n e s   + =   [ " " ,   " # #   F i l e s   w i t h   u n c o m m i t t e d   c h a n g e s " ] 
 
                 f o r   s t a t u s _ c o d e ,   p a t h   i n   g i t _ c t x . m o d i f i e d _ f i l e s : 
 
                         l i n e s . a p p e n d ( f "     { s t a t u s _ c o d e }     { p a t h } " ) 
 
 
 
         i f   q u e s t i o n : 
 
                 l i n e s   + =   [ " " ,   " # #   W h a t   I   w a s   a b o u t   t o   a s k   ( a f t e r   y o u   c o n f i r m ) " ,   q u e s t i o n ] 
 
 
 
         r e t u r n   " \ n " . j o i n ( l i n e s ) 
 
 
 
 
 
 d e f   c o p y _ t o _ c l i p b o a r d ( t e x t :   s t r )   - >   b o o l : 
 
         " " " C o p y   ` t e x t `   t o   t h e   s y s t e m   c l i p b o a r d .   R e t u r n s   F a l s e   i f   u n a v a i l a b l e . " " " 
 
         t r y : 
 
                 s y s t e m   =   p l a t f o r m . s y s t e m ( ) 
 
                 i f   s y s t e m   = =   " W i n d o w s " : 
 
                         s u b p r o c e s s . r u n ( [ " c l i p " ] ,   i n p u t = t e x t . e n c o d e ( " u t f - 8 " ) ,   c h e c k = T r u e ) 
 
                 e l i f   s y s t e m   = =   " D a r w i n " : 
 
                         s u b p r o c e s s . r u n ( [ " p b c o p y " ] ,   i n p u t = t e x t . e n c o d e ( " u t f - 8 " ) ,   c h e c k = T r u e ) 
 
                 e l s e : 
 
                         s u b p r o c e s s . r u n ( 
 
                                 [ " x c l i p " ,   " - s e l e c t i o n " ,   " c l i p b o a r d " ] , 
 
                                 i n p u t = t e x t . e n c o d e ( " u t f - 8 " ) , 
 
                                 c h e c k = T r u e , 
 
                         ) 
 
                 r e t u r n   T r u e 
 
         e x c e p t   ( s u b p r o c e s s . C a l l e d P r o c e s s E r r o r ,   F i l e N o t F o u n d E r r o r ) : 
 
                 r e t u r n   F a l s e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / m i g r a t e / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A I - p o w e r e d   A S T   c o d e m o d   f o r   m i g r a t i n g   b e t w e e n   p a c k a g e s . 
 
 
 
 T w o - t i e r   a p p r o a c h : 
 
     1 .   R e c i p e   t i e r       h a n d - w r i t t e n   l i b c s t   c o d e m o d s   f o r   k n o w n   p a i r s   ( r e q u e s t s   h t t p x ,   e t c . ) 
 
     2 .   A I   t i e r       f o r   u n k n o w n   p a i r s ,   a s k s   t h e   c o n f i g u r e d   A I   p r o v i d e r   t o   r e w r i t e   c a l l   s i t e s 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   k r a i m i n d . m i g r a t e . a s t _ r e w r i t e r   i m p o r t   ( 
 
         M i g r a t i o n R e s u l t , 
 
         a p p l y _ m i g r a t i o n , 
 
         p r e v i e w _ m i g r a t i o n , 
 
 ) 
 
 f r o m   k r a i m i n d . m i g r a t e . r e c i p e s   i m p o r t   ( 
 
         R e c i p e , 
 
         g e t _ r e c i p e , 
 
         l i s t _ r e c i p e s , 
 
 ) 
 
 
 
 _ _ a l l _ _   =   [ 
 
         " M i g r a t i o n R e s u l t " , 
 
         " R e c i p e " , 
 
         " a p p l y _ m i g r a t i o n " , 
 
         " g e t _ r e c i p e " , 
 
         " l i s t _ r e c i p e s " , 
 
         " p r e v i e w _ m i g r a t i o n " , 
 
 ] 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / m i g r a t e / a i _ r e w r i t e r . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A I   f a l l b a c k   f o r   u n k n o w n   m i g r a t i o n   p a i r s . 
 
 
 
 W h e n   n o   R e c i p e   e x i s t s   f o r   s o u r c e   t a r g e t ,   a s k   t h e   c o n f i g u r e d   A I   p r o v i d e r   t o 
 
 s u g g e s t   a   m i g r a t i o n   p l a n .   T h e   A I   g e n e r a t e s   a   R e c i p e - l i k e   d i c t   t h a t   t h e 
 
 d e t e r m i n i s t i c   r e w r i t e r   t h e n   a p p l i e s . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   j s o n 
 
 i m p o r t   o s 
 
 f r o m   t y p i n g   i m p o r t   O p t i o n a l 
 
 
 
 f r o m   k r a i m i n d . m i g r a t e . r e c i p e s   i m p o r t   R e c i p e 
 
 f r o m   k r a i m i n d . u t i l s . c o n f i g   i m p o r t   g e t _ k e y 
 
 
 
 
 
 _ P R O M P T _ T E M P L A T E   =   " " " Y o u   a r e   a   P y t h o n   m i g r a t i o n   e x p e r t . 
 
 G e n e r a t e   a   J S O N   m i g r a t i o n   r e c i p e   f o r   s w i t c h i n g   f r o m   ` { s o u r c e } `   t o   ` { t a r g e t } ` . 
 
 
 
 R e q u i r e d   f o r m a t   ( r e t u r n   O N L Y   t h e   J S O N ,   n o   m a r k d o w n   f e n c e s ) : 
 
 { { 
 
     " i m p o r t _ r e w r i t e s " :   { { " < o l d _ i m p o r t > " :   " < n e w _ i m p o r t > " } } , 
 
     " s y m b o l _ r e w r i t e s " :   { { " < o l d . d o t t e d . p a t h > " :   " < n e w . d o t t e d . p a t h > " } } , 
 
     " n o t e s " :   [ " s h o r t   n o t e   1 " ,   " s h o r t   n o t e   2 " ] 
 
 } } 
 
 
 
 R u l e s : 
 
 -   K e y s   i n   s y m b o l _ r e w r i t e s   m u s t   b e   e x a c t ,   f u l l y - q u a l i f i e d   d o t t e d   p a t h s . 
 
 -   E a c h   n o t e   s h o u l d   d e s c r i b e   a   b e h a v i o r a l   d i f f e r e n c e   t h e   u s e r   m u s t   c h e c k   m a n u a l l y . 
 
 -   K e e p   n o t e s   u n d e r   1 2   w o r d s   e a c h . 
 
 -   R e t u r n   s t r i c t   J S O N   o n l y . 
 
 " " " 
 
 
 
 
 
 d e f   _ t r y _ o p e n a i ( p r o m p t :   s t r )   - >   O p t i o n a l [ s t r ] : 
 
         a p i _ k e y   =   g e t _ k e y ( " O P E N A I _ A P I _ K E Y " ) 
 
         i f   n o t   a p i _ k e y : 
 
                 r e t u r n   N o n e 
 
         t r y : 
 
                 f r o m   o p e n a i   i m p o r t   O p e n A I 
 
 
 
                 c l i e n t   =   O p e n A I ( a p i _ k e y = a p i _ k e y ) 
 
                 r e s p o n s e   =   c l i e n t . c h a t . c o m p l e t i o n s . c r e a t e ( 
 
                         m o d e l = " g p t - 4 o - m i n i " , 
 
                         m e s s a g e s = [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                         t e m p e r a t u r e = 0 . 2 , 
 
                         m a x _ t o k e n s = 6 0 0 , 
 
                 ) 
 
                 r e t u r n   r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e . c o n t e n t 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ t r y _ g r o q ( p r o m p t :   s t r )   - >   O p t i o n a l [ s t r ] : 
 
         a p i _ k e y   =   g e t _ k e y ( " G R O Q _ A P I _ K E Y " ) 
 
         i f   n o t   a p i _ k e y : 
 
                 r e t u r n   N o n e 
 
         t r y : 
 
                 f r o m   o p e n a i   i m p o r t   O p e n A I 
 
 
 
                 c l i e n t   =   O p e n A I ( a p i _ k e y = a p i _ k e y ,   b a s e _ u r l = " h t t p s : / / a p i . g r o q . c o m / o p e n a i / v 1 " ) 
 
                 r e s p o n s e   =   c l i e n t . c h a t . c o m p l e t i o n s . c r e a t e ( 
 
                         m o d e l = " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                         m e s s a g e s = [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                         t e m p e r a t u r e = 0 . 2 , 
 
                         m a x _ t o k e n s = 6 0 0 , 
 
                 ) 
 
                 r e t u r n   r e s p o n s e . c h o i c e s [ 0 ] . m e s s a g e . c o n t e n t 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ t r y _ o l l a m a ( p r o m p t :   s t r )   - >   O p t i o n a l [ s t r ] : 
 
         i f   n o t   o s . g e t e n v ( " K R A I M I N D _ L O C A L _ A I " ) : 
 
                 r e t u r n   N o n e 
 
         t r y : 
 
                 i m p o r t   o l l a m a 
 
 
 
                 r e s p o n s e   =   o l l a m a . c h a t ( 
 
                         m o d e l = " l l a m a 3 . 2 " , 
 
                         m e s s a g e s = [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                         o p t i o n s = { " t e m p e r a t u r e " :   0 . 2 } , 
 
                 ) 
 
                 r e t u r n   r e s p o n s e . g e t ( " m e s s a g e " ,   { } ) . g e t ( " c o n t e n t " ) 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ t r y _ c e r e b r a s ( p r o m p t :   s t r )   - >   O p t i o n a l [ s t r ] : 
 
         a p i _ k e y   =   g e t _ k e y ( " C E R E B R A S _ A P I _ K E Y " ) 
 
         i f   n o t   a p i _ k e y : 
 
                 r e t u r n   N o n e 
 
         t r y : 
 
                 i m p o r t   h t t p x 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 " h t t p s : / / a p i . c e r e b r a s . a i / v 1 / c h a t / c o m p l e t i o n s " , 
 
                                 h e a d e r s = { " A u t h o r i z a t i o n " :   f " B e a r e r   { a p i _ k e y } " ,   " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a 3 . 1 - 8 b " , 
 
                                         " m e s s a g e s " :   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                                         " t e m p e r a t u r e " :   0 . 2 , 
 
                                         " m a x _ t o k e n s " :   6 0 0 , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] 
 
         e x c e p t   E x c e p t i o n : 
 
                 r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ t r y _ p r o x y ( p r o m p t :   s t r )   - >   O p t i o n a l [ s t r ] : 
 
         i m p o r t   h t t p x 
 
         a p i _ u r l   =   o s . g e t e n v ( " K R A I M I N D _ A P I _ U R L " ,   " h t t p s : / / k r a i m i n d . v e r c e l . a p p / a p i " ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 3 0 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 a p i _ u r l , 
 
                                 h e a d e r s = { " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                                 j s o n = { 
 
                                         " m o d e l " :   " l l a m a - 3 . 3 - 7 0 b - v e r s a t i l e " , 
 
                                         " m e s s a g e s " :   [ { " r o l e " :   " u s e r " ,   " c o n t e n t " :   p r o m p t } ] , 
 
                                         " m a x _ t o k e n s " :   6 0 0 , 
 
                                         " t e m p e r a t u r e " :   0 . 2 , 
 
                                 } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         c h o i c e s   =   r e s p . j s o n ( ) . g e t ( " c h o i c e s " ,   [ ] ) 
 
                         i f   c h o i c e s : 
 
                                 r e t u r n   c h o i c e s [ 0 ] [ " m e s s a g e " ] [ " c o n t e n t " ] . s t r i p ( )   o r   N o n e 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 
 
 d e f   g e n e r a t e _ a i _ r e c i p e ( s o u r c e :   s t r ,   t a r g e t :   s t r )   - >   O p t i o n a l [ R e c i p e ] : 
 
         " " " A s k   A I   t o   d r a f t   a   m i g r a t i o n   r e c i p e   f o r   ` s o u r c e `       ` t a r g e t ` . 
 
 
 
         T r i e s :   l o c a l   O l l a m a       O p e n A I       G r o q       F a l l b a c k   p r o x y .   R e t u r n s   N o n e   o n   a l l   f a i l u r e s . 
 
         " " " 
 
         p r o m p t   =   _ P R O M P T _ T E M P L A T E . f o r m a t ( s o u r c e = s o u r c e ,   t a r g e t = t a r g e t ) 
 
 
 
         r a w :   O p t i o n a l [ s t r ]   =   N o n e 
 
         f o r   f n   i n   ( _ t r y _ o l l a m a ,   _ t r y _ o p e n a i ,   _ t r y _ g r o q ,   _ t r y _ c e r e b r a s ,   _ t r y _ p r o x y ) : 
 
                 r a w   =   f n ( p r o m p t ) 
 
                 i f   r a w : 
 
                         b r e a k 
 
 
 
         i f   n o t   r a w : 
 
                 r e t u r n   N o n e 
 
 
 
         #   S t r i p   m a r k d o w n   f e n c e s   i f   t h e   m o d e l   a d d e d   a n y 
 
         c l e a n e d   =   r a w . s t r i p ( ) 
 
         i f   c l e a n e d . s t a r t s w i t h ( " ` ` ` " ) : 
 
                 c l e a n e d   =   " \ n " . j o i n ( l i n e   f o r   l i n e   i n   c l e a n e d . s p l i t l i n e s ( )   i f   n o t   l i n e . s t r i p ( ) . s t a r t s w i t h ( " ` ` ` " ) ) 
 
 
 
         t r y : 
 
                 d a t a   =   j s o n . l o a d s ( c l e a n e d ) 
 
         e x c e p t   j s o n . J S O N D e c o d e E r r o r : 
 
                 r e t u r n   N o n e 
 
 
 
         r e t u r n   R e c i p e ( 
 
                 s o u r c e = s o u r c e , 
 
                 t a r g e t = t a r g e t , 
 
                 i m p o r t _ r e w r i t e s = d i c t ( d a t a . g e t ( " i m p o r t _ r e w r i t e s " )   o r   { } ) , 
 
                 s y m b o l _ r e w r i t e s = d i c t ( d a t a . g e t ( " s y m b o l _ r e w r i t e s " )   o r   { } ) , 
 
                 n o t e s = l i s t ( d a t a . g e t ( " n o t e s " )   o r   [ ] ) , 
 
                 m a n u a l _ r e v i e w _ n e e d e d = T r u e , 
 
         ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / m i g r a t e / a s t _ r e w r i t e r . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A S T - a w a r e   c o d e m o d   t h a t   a p p l i e s   a   R e c i p e   t o   a l l   . p y   f i l e s   i n   a   p r o j e c t . 
 
 
 
 F o r   t h e   v 1   i m p l e m e n t a t i o n   w e   u s e   P y t h o n ' s   s t d l i b   ` a s t `   f o r   a n a l y s i s   a n d   a 
 
 c a r e f u l   r e g e x - b a s e d   r e w r i t e   f o r   t e x t   s u b s t i t u t i o n .   T h i s   p r e s e r v e s   f o r m a t t i n g 
 
 a n d   c o m m e n t s   ( u n l i k e   ` a s t . u n p a r s e ` )   w h i l e   s t i l l   b e i n g   d e t e r m i n i s t i c . 
 
 
 
 A   f u t u r e   v 2   s h o u l d   s w a p   t h e   r e w r i t e r   f o r   ` l i b c s t `   f o r   f u l l   r o u n d - t r i p   s a f e t y . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   a s t 
 
 i m p o r t   r e 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   L i s t ,   O p t i o n a l ,   S e t ,   T u p l e 
 
 
 
 f r o m   k r a i m i n d . m i g r a t e . r e c i p e s   i m p o r t   R e c i p e 
 
 f r o m   k r a i m i n d . p a r s e r . a s t _ s c a n n e r   i m p o r t   S K I P _ D I R S 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   F i l e M i g r a t i o n : 
 
         " " " P e r - f i l e   m i g r a t i o n   o u t c o m e . " " " 
 
 
 
         p a t h :   P a t h 
 
         o r i g i n a l :   s t r 
 
         r e w r i t t e n :   s t r 
 
         c h a n g e s :   i n t 
 
 
 
         @ p r o p e r t y 
 
         d e f   c h a n g e d ( s e l f )   - >   b o o l : 
 
                 r e t u r n   s e l f . c h a n g e s   >   0   a n d   s e l f . o r i g i n a l   ! =   s e l f . r e w r i t t e n 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   M i g r a t i o n R e s u l t : 
 
         " " " A g g r e g a t e   r e s u l t   o v e r   a   p r o j e c t . " " " 
 
 
 
         r e c i p e :   R e c i p e 
 
         f i l e s _ s c a n n e d :   i n t 
 
         f i l e s _ c h a n g e d :   i n t 
 
         t o t a l _ r e p l a c e m e n t s :   i n t 
 
         f i l e _ r e s u l t s :   L i s t [ F i l e M i g r a t i o n ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
         n o t e s :   L i s t [ s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
 
 
 
 
 d e f   _ f i l e _ i m p o r t s _ s o u r c e ( f i l e _ p a t h :   P a t h ,   s o u r c e :   s t r )   - >   b o o l : 
 
         " " " C h e c k   w h e t h e r   a   f i l e   i m p o r t s   t h e   ` s o u r c e `   p a c k a g e   ( t o p - l e v e l ) . " " " 
 
         t r y : 
 
                 t e x t   =   f i l e _ p a t h . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
                 t r e e   =   a s t . p a r s e ( t e x t ,   f i l e n a m e = s t r ( f i l e _ p a t h ) ) 
 
         e x c e p t   ( S y n t a x E r r o r ,   U n i c o d e D e c o d e E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   F a l s e 
 
 
 
         f o r   n o d e   i n   a s t . w a l k ( t r e e ) : 
 
                 i f   i s i n s t a n c e ( n o d e ,   a s t . I m p o r t ) : 
 
                         f o r   a l i a s   i n   n o d e . n a m e s : 
 
                                 i f   a l i a s . n a m e . s p l i t ( " . " ) [ 0 ]   = =   s o u r c e : 
 
                                         r e t u r n   T r u e 
 
                 e l i f   i s i n s t a n c e ( n o d e ,   a s t . I m p o r t F r o m ) : 
 
                         i f   n o d e . m o d u l e   a n d   n o d e . m o d u l e . s p l i t ( " . " ) [ 0 ]   = =   s o u r c e : 
 
                                 r e t u r n   T r u e 
 
         r e t u r n   F a l s e 
 
 
 
 
 
 d e f   _ r e w r i t e _ t e x t ( t e x t :   s t r ,   r e c i p e :   R e c i p e )   - >   T u p l e [ s t r ,   i n t ] : 
 
         " " " A p p l y   a l l   r e w r i t e s   i n   ` r e c i p e `   t o   ` t e x t ` .   R e t u r n s   ( n e w _ t e x t ,   c o u n t ) . " " " 
 
         c o u n t   =   0 
 
 
 
         #   1 .   I m p o r t   s t a t e m e n t s :   ` i m p o r t   X `   /   ` i m p o r t   X   a s   Y `   /   ` f r o m   X   i m p o r t   . . . ` 
 
         f o r   o l d ,   n e w   i n   r e c i p e . i m p o r t _ r e w r i t e s . i t e m s ( ) : 
 
                 #   ` i m p o r t   o l d `       ` i m p o r t   n e w ` 
 
                 p a t t e r n   =   r e . c o m p i l e ( r f " \ b i m p o r t \ s + { r e . e s c a p e ( o l d ) } \ b " ) 
 
                 n e w _ t e x t ,   n   =   p a t t e r n . s u b n ( f " i m p o r t   { n e w } " ,   t e x t ) 
 
                 c o u n t   + =   n 
 
                 t e x t   =   n e w _ t e x t 
 
 
 
                 #   ` f r o m   o l d . x   i m p o r t   y `       ` f r o m   n e w . x   i m p o r t   y ` 
 
                 p a t t e r n   =   r e . c o m p i l e ( r f " \ b f r o m \ s + { r e . e s c a p e ( o l d ) } ( \ b | \ . ) " ) 
 
                 n e w _ t e x t ,   n   =   p a t t e r n . s u b n ( r f " f r o m   { n e w } \ 1 " ,   t e x t ) 
 
                 c o u n t   + =   n 
 
                 t e x t   =   n e w _ t e x t 
 
 
 
         #   2 .   S y m b o l   r e w r i t e s :   d o t t e d - p a t h s   l i k e   ` r e q u e s t s . g e t `       ` h t t p x . g e t ` 
 
         #   A p p l y   l o n g e r   k e y s   f i r s t   s o   e . g .   r e q u e s t s . e x c e p t i o n s . H T T P E r r o r   b e a t s   r e q u e s t s . g e t 
 
         f o r   o l d ,   n e w   i n   s o r t e d ( r e c i p e . s y m b o l _ r e w r i t e s . i t e m s ( ) ,   k e y = l a m b d a   k v :   l e n ( k v [ 0 ] ) ,   r e v e r s e = T r u e ) : 
 
                 #   E s c a p e   d o t s ;   r e q u i r e   w o r d   b o u n d a r y   b e f o r e ,   a n d   ( l o o k a h e a d )   n o n - i d e n t i f i e r   a f t e r 
 
                 p a t t e r n   =   r e . c o m p i l e ( r f " ( ? < ! [ A - Z a - z 0 - 9 _ ] ) { r e . e s c a p e ( o l d ) } ( ? ! [ A - Z a - z 0 - 9 _ ] ) " ) 
 
                 n e w _ t e x t ,   n   =   p a t t e r n . s u b n ( n e w ,   t e x t ) 
 
                 c o u n t   + =   n 
 
                 t e x t   =   n e w _ t e x t 
 
 
 
         r e t u r n   t e x t ,   c o u n t 
 
 
 
 
 
 d e f   p r e v i e w _ m i g r a t i o n ( p r o j e c t _ p a t h :   P a t h ,   r e c i p e :   R e c i p e )   - >   M i g r a t i o n R e s u l t : 
 
         " " " C o m p u t e   m i g r a t i o n   c h a n g e s   w i t h o u t   w r i t i n g   a n y t h i n g   t o   d i s k . " " " 
 
         r e s u l t   =   M i g r a t i o n R e s u l t ( 
 
                 r e c i p e = r e c i p e , 
 
                 f i l e s _ s c a n n e d = 0 , 
 
                 f i l e s _ c h a n g e d = 0 , 
 
                 t o t a l _ r e p l a c e m e n t s = 0 , 
 
                 n o t e s = l i s t ( r e c i p e . n o t e s ) , 
 
         ) 
 
 
 
         f o r   p y _ f i l e   i n   p r o j e c t _ p a t h . r g l o b ( " * . p y " ) : 
 
                 i f   a n y ( p a r t   i n   S K I P _ D I R S   f o r   p a r t   i n   p y _ f i l e . p a r t s ) : 
 
                         c o n t i n u e 
 
                 r e s u l t . f i l e s _ s c a n n e d   + =   1 
 
 
 
                 i f   n o t   _ f i l e _ i m p o r t s _ s o u r c e ( p y _ f i l e ,   r e c i p e . s o u r c e ) : 
 
                         c o n t i n u e 
 
 
 
                 t r y : 
 
                         o r i g i n a l   =   p y _ f i l e . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ) 
 
                 e x c e p t   ( O S E r r o r ,   U n i c o d e D e c o d e E r r o r ) : 
 
                         c o n t i n u e 
 
 
 
                 r e w r i t t e n ,   n   =   _ r e w r i t e _ t e x t ( o r i g i n a l ,   r e c i p e ) 
 
                 f m   =   F i l e M i g r a t i o n ( p a t h = p y _ f i l e ,   o r i g i n a l = o r i g i n a l ,   r e w r i t t e n = r e w r i t t e n ,   c h a n g e s = n ) 
 
                 i f   f m . c h a n g e d : 
 
                         r e s u l t . f i l e _ r e s u l t s . a p p e n d ( f m ) 
 
                         r e s u l t . f i l e s _ c h a n g e d   + =   1 
 
                         r e s u l t . t o t a l _ r e p l a c e m e n t s   + =   n 
 
 
 
         r e t u r n   r e s u l t 
 
 
 
 
 
 d e f   a p p l y _ m i g r a t i o n ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         r e c i p e :   R e c i p e , 
 
         c o n f i r m _ p e r _ f i l e :   b o o l   =   F a l s e , 
 
         f i l e _ f i l t e r :   O p t i o n a l [ S e t [ P a t h ] ]   =   N o n e , 
 
 )   - >   M i g r a t i o n R e s u l t : 
 
         " " " A p p l y   a   r e c i p e   t o   a l l   f i l e s   ( o r   a   f i l t e r e d   s u b s e t )   a n d   w r i t e   c h a n g e s   t o   d i s k . 
 
 
 
         A r g s : 
 
                 p r o j e c t _ p a t h :   P r o j e c t   r o o t . 
 
                 r e c i p e :   M i g r a t i o n   r e c i p e . 
 
                 c o n f i r m _ p e r _ f i l e :   I f   T r u e ,   t h e   c a l l e r   i s   e x p e c t e d   t o   h a v e   a l r e a d y   f i l t e r e d   f i l e _ f i l t e r . 
 
                 f i l e _ f i l t e r :   O p t i o n a l   s e t   o f   p a t h s   t o   l i m i t   c h a n g e s   t o . 
 
 
 
         R e t u r n s : 
 
                 M i g r a t i o n R e s u l t   w i t h   a l l   p e r - f i l e   c h a n g e s . 
 
         " " " 
 
         p r e v i e w   =   p r e v i e w _ m i g r a t i o n ( p r o j e c t _ p a t h ,   r e c i p e ) 
 
 
 
         f o r   f m   i n   p r e v i e w . f i l e _ r e s u l t s : 
 
                 i f   f i l e _ f i l t e r   i s   n o t   N o n e   a n d   f m . p a t h   n o t   i n   f i l e _ f i l t e r : 
 
                         c o n t i n u e 
 
                 t r y : 
 
                         f m . p a t h . w r i t e _ t e x t ( f m . r e w r i t t e n ,   e n c o d i n g = " u t f - 8 " ) 
 
                 e x c e p t   O S E r r o r   a s   e : 
 
                         p r e v i e w . n o t e s . a p p e n d ( f " F a i l e d   t o   w r i t e   { f m . p a t h } :   { e } " ) 
 
 
 
         r e t u r n   p r e v i e w 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / m i g r a t e / d i f f _ p r e v i e w . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " R i c h - f o r m a t t e d   d i f f   p r e v i e w   f o r   m i g r a t i o n s . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   d i f f l i b 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t 
 
 
 
 f r o m   r i c h . c o n s o l e   i m p o r t   C o n s o l e 
 
 f r o m   r i c h . p a n e l   i m p o r t   P a n e l 
 
 f r o m   r i c h . s y n t a x   i m p o r t   S y n t a x 
 
 f r o m   r i c h . t e x t   i m p o r t   T e x t 
 
 
 
 f r o m   k r a i m i n d . m i g r a t e . a s t _ r e w r i t e r   i m p o r t   F i l e M i g r a t i o n ,   M i g r a t i o n R e s u l t 
 
 
 
 
 
 d e f   _ u n i f i e d _ d i f f ( f i l e _ m i g r a t i o n :   F i l e M i g r a t i o n ,   c o n t e x t _ l i n e s :   i n t   =   3 )   - >   s t r : 
 
         " " " G e n e r a t e   a   u n i f i e d   d i f f   f o r   a   s i n g l e   F i l e M i g r a t i o n . " " " 
 
         d i f f   =   d i f f l i b . u n i f i e d _ d i f f ( 
 
                 f i l e _ m i g r a t i o n . o r i g i n a l . s p l i t l i n e s ( k e e p e n d s = T r u e ) , 
 
                 f i l e _ m i g r a t i o n . r e w r i t t e n . s p l i t l i n e s ( k e e p e n d s = T r u e ) , 
 
                 f r o m f i l e = s t r ( f i l e _ m i g r a t i o n . p a t h ) , 
 
                 t o f i l e = s t r ( f i l e _ m i g r a t i o n . p a t h )   +   "   ( a f t e r ) " , 
 
                 n = c o n t e x t _ l i n e s , 
 
         ) 
 
         r e t u r n   " " . j o i n ( d i f f ) 
 
 
 
 
 
 d e f   r e n d e r _ m i g r a t i o n _ p r e v i e w ( 
 
         r e s u l t :   M i g r a t i o n R e s u l t , 
 
         c o n s o l e :   C o n s o l e , 
 
         m a x _ f i l e s :   i n t   =   2 0 , 
 
 )   - >   N o n e : 
 
         " " " P r e t t y - p r i n t   a   M i g r a t i o n R e s u l t   t o   t h e   c o n s o l e . " " " 
 
         h e a d e r   =   T e x t ( ) 
 
         h e a d e r . a p p e n d ( f " M i g r a t i o n :   " ,   s t y l e = " b o l d " ) 
 
         h e a d e r . a p p e n d ( f " { r e s u l t . r e c i p e . s o u r c e } " ,   s t y l e = " b o l d   r e d " ) 
 
         h e a d e r . a p p e n d ( "       " ,   s t y l e = " g r e y 5 0 " ) 
 
         h e a d e r . a p p e n d ( f " { r e s u l t . r e c i p e . t a r g e t } \ n \ n " ,   s t y l e = " b o l d   g r e e n " ) 
 
         h e a d e r . a p p e n d ( f " F i l e s   s c a n n e d :   " ,   s t y l e = " g r e y 7 0 " ) 
 
         h e a d e r . a p p e n d ( f " { r e s u l t . f i l e s _ s c a n n e d } \ n " ) 
 
         h e a d e r . a p p e n d ( f " F i l e s   c h a n g e d :   " ,   s t y l e = " g r e y 7 0 " ) 
 
         h e a d e r . a p p e n d ( f " { r e s u l t . f i l e s _ c h a n g e d } \ n " ,   s t y l e = " b o l d " ) 
 
         h e a d e r . a p p e n d ( f " R e p l a c e m e n t s :     " ,   s t y l e = " g r e y 7 0 " ) 
 
         h e a d e r . a p p e n d ( f " { r e s u l t . t o t a l _ r e p l a c e m e n t s } \ n " ,   s t y l e = " b o l d " ) 
 
 
 
         c o n s o l e . p r i n t ( P a n e l ( h e a d e r ,   t i t l e = " [ b o l d ] M i g r a t i o n   P l a n [ / ] " ,   b o r d e r _ s t y l e = " c y a n " ) ) 
 
 
 
         i f   n o t   r e s u l t . f i l e _ r e s u l t s : 
 
                 c o n s o l e . p r i n t ( " [ y e l l o w ] N o   m a t c h i n g   i m p o r t s   f o u n d       n o t h i n g   t o   m i g r a t e . [ / ] " ) 
 
                 r e t u r n 
 
 
 
         f o r   f m   i n   r e s u l t . f i l e _ r e s u l t s [ : m a x _ f i l e s ] : 
 
                 d i f f _ t e x t   =   _ u n i f i e d _ d i f f ( f m ) 
 
                 i f   n o t   d i f f _ t e x t . s t r i p ( ) : 
 
                         c o n t i n u e 
 
                 c o n s o l e . p r i n t ( 
 
                         P a n e l ( 
 
                                 S y n t a x ( d i f f _ t e x t ,   " d i f f " ,   t h e m e = " a n s i _ d a r k " ,   l i n e _ n u m b e r s = F a l s e ) , 
 
                                 t i t l e = f " [ b o l d ] { f m . p a t h } [ / ]       [ g r e y 7 0 ] ( { f m . c h a n g e s }   c h a n g e { ' s '   i f   f m . c h a n g e s   ! =   1   e l s e   ' ' } ) [ / ] " , 
 
                                 b o r d e r _ s t y l e = " b l u e " , 
 
                         ) 
 
                 ) 
 
 
 
         i f   l e n ( r e s u l t . f i l e _ r e s u l t s )   >   m a x _ f i l e s : 
 
                 c o n s o l e . p r i n t ( 
 
                         f " [ g r e y 5 0 ] . . .   a n d   { l e n ( r e s u l t . f i l e _ r e s u l t s )   -   m a x _ f i l e s }   m o r e   f i l e ( s ) [ / ] " 
 
                 ) 
 
 
 
         i f   r e s u l t . r e c i p e . m a n u a l _ r e v i e w _ n e e d e d   o r   r e s u l t . n o t e s : 
 
                 n o t e s _ t e x t   =   T e x t ( ) 
 
                 i f   r e s u l t . r e c i p e . m a n u a l _ r e v i e w _ n e e d e d : 
 
                         n o t e s _ t e x t . a p p e n d ( "     M a n u a l   r e v i e w   r e c o m m e n d e d \ n \ n " ,   s t y l e = " b o l d   y e l l o w " ) 
 
                 f o r   n o t e   i n   r e s u l t . n o t e s : 
 
                         n o t e s _ t e x t . a p p e n d ( f "         { n o t e } \ n " ,   s t y l e = " y e l l o w " ) 
 
                 c o n s o l e . p r i n t ( P a n e l ( n o t e s _ t e x t ,   t i t l e = " [ b o l d ] N o t e s [ / ] " ,   b o r d e r _ s t y l e = " y e l l o w " ) ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / m i g r a t e / r e c i p e s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " H a n d - c u r a t e d   m i g r a t i o n   r e c i p e s       d e t e r m i n i s t i c ,   f a s t ,   f r e e . 
 
 
 
 E a c h   r e c i p e   d e s c r i b e s   h o w   t o   m i g r a t e   f r o m   o n e   p a c k a g e   t o   a n o t h e r : 
 
     -   I m p o r t   r e w r i t e s   ( r e p l a c e   ` i m p o r t   r e q u e s t s `   w i t h   ` i m p o r t   h t t p x ` ) 
 
     -   S y m b o l   r e w r i t e s   ( r e p l a c e   ` r e q u e s t s . g e t ( . . . ) `   w i t h   ` h t t p x . g e t ( . . . ) ` ) 
 
     -   N o t e s   a b o u t   b e h a v i o r   d i f f e r e n c e s   t h e   u s e r   m u s t   r e v i e w   m a n u a l l y 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   L i s t ,   O p t i o n a l 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   R e c i p e : 
 
         " " " A   s i n g l e   m i g r a t i o n   r e c i p e . " " " 
 
 
 
         s o u r c e :   s t r 
 
         t a r g e t :   s t r 
 
         i m p o r t _ r e w r i t e s :   D i c t [ s t r ,   s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = d i c t ) 
 
         s y m b o l _ r e w r i t e s :   D i c t [ s t r ,   s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = d i c t ) 
 
         n o t e s :   L i s t [ s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
         m a n u a l _ r e v i e w _ n e e d e d :   b o o l   =   F a l s e 
 
 
 
 
 
 R E C I P E S :   D i c t [ s t r ,   R e c i p e ]   =   { 
 
         " r e q u e s t s - > h t t p x " :   R e c i p e ( 
 
                 s o u r c e = " r e q u e s t s " , 
 
                 t a r g e t = " h t t p x " , 
 
                 i m p o r t _ r e w r i t e s = { 
 
                         " r e q u e s t s " :   " h t t p x " , 
 
                 } , 
 
                 s y m b o l _ r e w r i t e s = { 
 
                         " r e q u e s t s . g e t " :   " h t t p x . g e t " , 
 
                         " r e q u e s t s . p o s t " :   " h t t p x . p o s t " , 
 
                         " r e q u e s t s . p u t " :   " h t t p x . p u t " , 
 
                         " r e q u e s t s . d e l e t e " :   " h t t p x . d e l e t e " , 
 
                         " r e q u e s t s . p a t c h " :   " h t t p x . p a t c h " , 
 
                         " r e q u e s t s . h e a d " :   " h t t p x . h e a d " , 
 
                         " r e q u e s t s . S e s s i o n " :   " h t t p x . C l i e n t " , 
 
                         " r e q u e s t s . e x c e p t i o n s . R e q u e s t E x c e p t i o n " :   " h t t p x . H T T P E r r o r " , 
 
                         " r e q u e s t s . e x c e p t i o n s . H T T P E r r o r " :   " h t t p x . H T T P S t a t u s E r r o r " , 
 
                         " r e q u e s t s . e x c e p t i o n s . T i m e o u t " :   " h t t p x . T i m e o u t E x c e p t i o n " , 
 
                         " r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r " :   " h t t p x . C o n n e c t E r r o r " , 
 
                 } , 
 
                 n o t e s = [ 
 
                         " h t t p x   r a i s e s   o n   n o n - 2 x x   o n l y   w h e n   y o u   c a l l   r e s p o n s e . r a i s e _ f o r _ s t a t u s ( )       s a m e   a s   r e q u e s t s . " , 
 
                         " S e s s i o n       C l i e n t :   u s e   a s   a   c o n t e x t   m a n a g e r   ( ` w i t h   h t t p x . C l i e n t ( )   a s   c : ` ) . " , 
 
                         " S o m e   r e q u e s t s - o n l y   k w a r g s   ( e . g .   ` j s o n = ` )   w o r k   i d e n t i c a l l y ;   v e r i f y   i n   y o u r   t e s t   s u i t e . " , 
 
                 ] , 
 
         ) , 
 
         " m o c k - > u n i t t e s t . m o c k " :   R e c i p e ( 
 
                 s o u r c e = " m o c k " , 
 
                 t a r g e t = " u n i t t e s t . m o c k " , 
 
                 i m p o r t _ r e w r i t e s = { 
 
                         " m o c k " :   " u n i t t e s t . m o c k " , 
 
                 } , 
 
                 n o t e s = [ 
 
                         " s t d l i b   u n i t t e s t . m o c k   i s   A P I - c o m p a t i b l e   w i t h   t h e   e x t e r n a l   ` m o c k `   p a c k a g e   o n   P y t h o n   3 . 3 + . " , 
 
                         " A f t e r   m i g r a t i o n ,   ` p i p   u n i n s t a l l   m o c k `   c a n   b e   r u n   s a f e l y . " , 
 
                 ] , 
 
         ) , 
 
         " s i m p l e j s o n - > j s o n " :   R e c i p e ( 
 
                 s o u r c e = " s i m p l e j s o n " , 
 
                 t a r g e t = " j s o n " , 
 
                 i m p o r t _ r e w r i t e s = { 
 
                         " s i m p l e j s o n " :   " j s o n " , 
 
                 } , 
 
                 n o t e s = [ 
 
                         " s i m p l e j s o n   h a s   s l i g h t l y   d i f f e r e n t   ` f o r _ j s o n `   a n d   ` t u p l e _ a s _ a r r a y `   d e f a u l t s       v e r i f y   e d g e   c a s e s . " , 
 
                         " F o r   h i g h e r   p e r f o r m a n c e   c o n s i d e r   ` o r j s o n `   i n s t e a d   o f   s t d l i b   j s o n . " , 
 
                 ] , 
 
                 m a n u a l _ r e v i e w _ n e e d e d = T r u e , 
 
         ) , 
 
         " n o s e - > p y t e s t " :   R e c i p e ( 
 
                 s o u r c e = " n o s e " , 
 
                 t a r g e t = " p y t e s t " , 
 
                 i m p o r t _ r e w r i t e s = { 
 
                         " n o s e . t o o l s " :   " p y t e s t " , 
 
                 } , 
 
                 s y m b o l _ r e w r i t e s = { 
 
                         " n o s e . t o o l s . a s s e r t _ e q u a l " :   " a s s e r t " , 
 
                         " n o s e . t o o l s . a s s e r t _ t r u e " :   " a s s e r t " , 
 
                         " n o s e . t o o l s . a s s e r t _ f a l s e " :   " a s s e r t   n o t " , 
 
                         " n o s e . t o o l s . a s s e r t _ r a i s e s " :   " p y t e s t . r a i s e s " , 
 
                 } , 
 
                 n o t e s = [ 
 
                         " n o s e . t o o l s . a s s e r t _ *   h e l p e r s   m a p   t o   p l a i n   ` a s s e r t `   s t a t e m e n t s   i n   p y t e s t . " , 
 
                         " T e s t   d i s c o v e r y :   p y t e s t   u s e s   ` t e s t _ * . p y `   /   ` * _ t e s t . p y `   ( v s   n o s e ' s   ` * _ t e s t ` ) . " , 
 
                         " n o s e   @ w i t h _ s e t u p   d e c o r a t o r       p y t e s t   f i x t u r e s . " , 
 
                 ] , 
 
                 m a n u a l _ r e v i e w _ n e e d e d = T r u e , 
 
         ) , 
 
         " a r r o w - > d a t e t i m e " :   R e c i p e ( 
 
                 s o u r c e = " a r r o w " , 
 
                 t a r g e t = " d a t e t i m e " , 
 
                 i m p o r t _ r e w r i t e s = { 
 
                         " a r r o w " :   " d a t e t i m e " , 
 
                 } , 
 
                 n o t e s = [ 
 
                         " a r r o w . n o w ( )       d a t e t i m e . d a t e t i m e . n o w ( z o n e i n f o . Z o n e I n f o ( ' U T C ' ) ) . " , 
 
                         " a r r o w . g e t ( s t r i n g )       d a t e t i m e . d a t e t i m e . f r o m i s o f o r m a t ( s t r i n g )   ( P y t h o n   3 . 1 1 + ) . " , 
 
                         " T h i s   i s   a   s i g n i f i c a n t   A P I   s h i f t       m a n u a l   r e v i e w   r e q u i r e d . " , 
 
                 ] , 
 
                 m a n u a l _ r e v i e w _ n e e d e d = T r u e , 
 
         ) , 
 
 } 
 
 
 
 
 
 d e f   _ r e c i p e _ k e y ( s o u r c e :   s t r ,   t a r g e t :   s t r )   - >   s t r : 
 
         r e t u r n   f " { s o u r c e . l o w e r ( ) } - > { t a r g e t . l o w e r ( ) } " 
 
 
 
 
 
 d e f   g e t _ r e c i p e ( s o u r c e :   s t r ,   t a r g e t :   s t r )   - >   O p t i o n a l [ R e c i p e ] : 
 
         " " " L o o k   u p   a   r e c i p e   f o r   m i g r a t i n g   ` s o u r c e `       ` t a r g e t ` . " " " 
 
         r e t u r n   R E C I P E S . g e t ( _ r e c i p e _ k e y ( s o u r c e ,   t a r g e t ) ) 
 
 
 
 
 
 d e f   l i s t _ r e c i p e s ( )   - >   L i s t [ R e c i p e ] : 
 
         " " " A l l   a v a i l a b l e   r e c i p e s . " " " 
 
         r e t u r n   l i s t ( R E C I P E S . v a l u e s ( ) ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p a r s e r / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " D e p e n d e n c y   p a r s e r s   f o r   P y t h o n   ( a n d   b a s i c   N o d e )   p r o j e c t s . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   S e t 
 
 
 
 f r o m   k r a i m i n d . p a r s e r . a s t _ s c a n n e r   i m p o r t   ( 
 
         e x t r a c t _ i m p o r t s _ f r o m _ f i l e , 
 
         m a p _ i m p o r t s _ t o _ p a c k a g e s , 
 
         s c a n _ p r o j e c t _ i m p o r t s , 
 
 ) 
 
 f r o m   k r a i m i n d . p a r s e r . l o c k f i l e   i m p o r t   d e t e c t _ l o c k f i l e ,   g e t _ l o c k f i l e _ i n f o 
 
 f r o m   k r a i m i n d . p a r s e r . p a c k a g e _ j s o n   i m p o r t   p a r s e _ p a c k a g e _ j s o n 
 
 f r o m   k r a i m i n d . p a r s e r . p y p r o j e c t   i m p o r t   p a r s e _ p y p r o j e c t _ t o m l 
 
 f r o m   k r a i m i n d . p a r s e r . r e q u i r e m e n t s   i m p o r t   p a r s e _ r e q u i r e m e n t s _ t x t 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   n o r m a l i z e _ p a c k a g e _ n a m e 
 
 
 
 
 
 d e f   g e t _ d e c l a r e d _ d e p e n d e n c i e s ( p r o j e c t _ p a t h :   P a t h )   - >   S e t [ s t r ] : 
 
         " " " A g g r e g a t e   d e c l a r e d   d e p e n d e n c i e s   f r o m   a l l   m a n i f e s t   f i l e s   i n   a   p r o j e c t . 
 
 
 
         T r i e s   ( i n   o r d e r ,   m e r g i n g   r e s u l t s ) : 
 
                 r e q u i r e m e n t s . t x t   ( a n d   a n y   - r   r e f e r e n c e d   f i l e s ) 
 
                 p y p r o j e c t . t o m l   [ p r o j e c t . d e p e n d e n c i e s ] 
 
                 p a c k a g e . j s o n   ( d e p e n d e n c i e s   +   d e v D e p e n d e n c i e s ) 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   n o r m a l i z e d   ( l o w e r c a s e ,   h y p h e n a t e d )   p a c k a g e   n a m e s . 
 
         " " " 
 
         d e p s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         r e q u i r e m e n t s _ f i l e   =   p r o j e c t _ p a t h   /   " r e q u i r e m e n t s . t x t " 
 
         i f   r e q u i r e m e n t s _ f i l e . e x i s t s ( ) : 
 
                 d e p s . u p d a t e ( p a r s e _ r e q u i r e m e n t s _ t x t ( r e q u i r e m e n t s _ f i l e ) ) 
 
 
 
         #   A l s o   l o o k   f o r   c o m m o n   a l t e r n a t i v e   n a m e s 
 
         f o r   a l t _ n a m e   i n   ( " r e q u i r e m e n t s - d e v . t x t " ,   " r e q u i r e m e n t s - p r o d . t x t " ,   " d e v - r e q u i r e m e n t s . t x t " ) : 
 
                 a l t _ f i l e   =   p r o j e c t _ p a t h   /   a l t _ n a m e 
 
                 i f   a l t _ f i l e . e x i s t s ( ) : 
 
                         d e p s . u p d a t e ( p a r s e _ r e q u i r e m e n t s _ t x t ( a l t _ f i l e ) ) 
 
 
 
         p y p r o j e c t _ f i l e   =   p r o j e c t _ p a t h   /   " p y p r o j e c t . t o m l " 
 
         i f   p y p r o j e c t _ f i l e . e x i s t s ( ) : 
 
                 d e p s . u p d a t e ( p a r s e _ p y p r o j e c t _ t o m l ( p y p r o j e c t _ f i l e ) ) 
 
 
 
         p a c k a g e _ j s o n _ f i l e   =   p r o j e c t _ p a t h   /   " p a c k a g e . j s o n " 
 
         i f   p a c k a g e _ j s o n _ f i l e . e x i s t s ( ) : 
 
                 d e p s . u p d a t e ( p a r s e _ p a c k a g e _ j s o n ( p a c k a g e _ j s o n _ f i l e ) ) 
 
 
 
         r e t u r n   { n o r m a l i z e _ p a c k a g e _ n a m e ( d )   f o r   d   i n   d e p s   i f   d } 
 
 
 
 
 
 _ _ a l l _ _   =   [ 
 
         " g e t _ d e c l a r e d _ d e p e n d e n c i e s " , 
 
         " e x t r a c t _ i m p o r t s _ f r o m _ f i l e " , 
 
         " s c a n _ p r o j e c t _ i m p o r t s " , 
 
         " m a p _ i m p o r t s _ t o _ p a c k a g e s " , 
 
         " p a r s e _ r e q u i r e m e n t s _ t x t " , 
 
         " p a r s e _ p y p r o j e c t _ t o m l " , 
 
         " p a r s e _ p a c k a g e _ j s o n " , 
 
         " g e t _ l o c k f i l e _ i n f o " , 
 
         " d e t e c t _ l o c k f i l e " , 
 
 ] 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p a r s e r / a s t _ s c a n n e r . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " E x t r a c t   P y t h o n   i m p o r t s   f r o m   s o u r c e   f i l e s   u s i n g   A S T   p a r s i n g . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   a s t 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   S e t 
 
 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   ( 
 
         I G N O R E _ I M P O R T S , 
 
         I M P O R T _ T O _ P A C K A G E , 
 
         n o r m a l i z e _ p a c k a g e _ n a m e , 
 
 ) 
 
 
 
 #   D i r e c t o r i e s   t o   s k i p   w h e n   s c a n n i n g   a   p r o j e c t 
 
 S K I P _ D I R S :   S e t [ s t r ]   =   { 
 
         " v e n v " , 
 
         " . v e n v " , 
 
         " e n v " , 
 
         " . e n v " , 
 
         " _ _ p y c a c h e _ _ " , 
 
         " . p y t e s t _ c a c h e " , 
 
         " . m y p y _ c a c h e " , 
 
         " n o d e _ m o d u l e s " , 
 
         " . g i t " , 
 
         " . t o x " , 
 
         " . e g g s " , 
 
         " b u i l d " , 
 
         " d i s t " , 
 
         " . n o x " , 
 
         " s i t e - p a c k a g e s " , 
 
 } 
 
 
 
 
 
 d e f   e x t r a c t _ i m p o r t s _ f r o m _ f i l e ( f i l e _ p a t h :   P a t h )   - >   S e t [ s t r ] : 
 
         " " " E x t r a c t   t o p - l e v e l   i m p o r t e d   m o d u l e   n a m e s   f r o m   a   s i n g l e   . p y   f i l e . 
 
 
 
         A r g s : 
 
                 f i l e _ p a t h :   P a t h   t o   a   P y t h o n   s o u r c e   f i l e . 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   t o p - l e v e l   m o d u l e   n a m e s   ( e . g .   " r e q u e s t s "   f r o m   " i m p o r t   r e q u e s t s . a u t h " ) . 
 
         " " " 
 
         i m p o r t s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         t r y : 
 
                 s o u r c e   =   f i l e _ p a t h . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
                 t r e e   =   a s t . p a r s e ( s o u r c e ,   f i l e n a m e = s t r ( f i l e _ p a t h ) ) 
 
         e x c e p t   ( S y n t a x E r r o r ,   U n i c o d e D e c o d e E r r o r ,   P e r m i s s i o n E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   i m p o r t s 
 
 
 
         f o r   n o d e   i n   a s t . w a l k ( t r e e ) : 
 
                 i f   i s i n s t a n c e ( n o d e ,   a s t . I m p o r t ) : 
 
                         f o r   a l i a s   i n   n o d e . n a m e s : 
 
                                 t o p   =   a l i a s . n a m e . s p l i t ( " . " ) [ 0 ] 
 
                                 i f   t o p : 
 
                                         i m p o r t s . a d d ( t o p ) 
 
                 e l i f   i s i n s t a n c e ( n o d e ,   a s t . I m p o r t F r o m ) : 
 
                         i f   n o d e . m o d u l e   a n d   n o d e . l e v e l   = =   0 : 
 
                                 #   A b s o l u t e   i m p o r t       t a k e   t o p - l e v e l   m o d u l e 
 
                                 t o p   =   n o d e . m o d u l e . s p l i t ( " . " ) [ 0 ] 
 
                                 i f   t o p : 
 
                                         i m p o r t s . a d d ( t o p ) 
 
                         #   R e l a t i v e   i m p o r t s   ( n o d e . l e v e l   >   0 )   a r e   i n t r a - p a c k a g e       s k i p 
 
 
 
         r e t u r n   i m p o r t s 
 
 
 
 
 
 d e f   s c a n _ p r o j e c t _ i m p o r t s ( r o o t _ p a t h :   P a t h )   - >   S e t [ s t r ] : 
 
         " " " R e c u r s i v e l y   s c a n   a l l   . p y   f i l e s   i n   a   p r o j e c t   d i r e c t o r y   f o r   i m p o r t s . 
 
 
 
         S k i p s   v i r t u a l   e n v s ,   b u i l d   d i r s ,   c a c h e s ,   a n d   . g i t . 
 
 
 
         A r g s : 
 
                 r o o t _ p a t h :   R o o t   d i r e c t o r y   t o   s c a n . 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   a l l   u n i q u e   t o p - l e v e l   i m p o r t   n a m e s   f o u n d   a c r o s s   t h e   p r o j e c t . 
 
         " " " 
 
         a l l _ i m p o r t s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         f o r   p y _ f i l e   i n   r o o t _ p a t h . r g l o b ( " * . p y " ) : 
 
                 #   S k i p   f i l e s   i n s i d e   a n y   i g n o r e d   d i r e c t o r y 
 
                 p a r t s   =   s e t ( p y _ f i l e . p a r t s ) 
 
                 i f   p a r t s   &   S K I P _ D I R S : 
 
                         c o n t i n u e 
 
                 #   A l s o   c h e c k   p a r e n t   d i r e c t o r y   n a m e s   a l o n g   t h e   p a t h 
 
                 i f   a n y ( p a r t   i n   S K I P _ D I R S   f o r   p a r t   i n   p y _ f i l e . r e l a t i v e _ t o ( r o o t _ p a t h ) . p a r t s ) : 
 
                         c o n t i n u e 
 
 
 
                 a l l _ i m p o r t s . u p d a t e ( e x t r a c t _ i m p o r t s _ f r o m _ f i l e ( p y _ f i l e ) ) 
 
 
 
         r e t u r n   a l l _ i m p o r t s 
 
 
 
 
 
 d e f   m a p _ i m p o r t s _ t o _ p a c k a g e s ( i m p o r t s :   S e t [ s t r ] )   - >   S e t [ s t r ] : 
 
         " " " M a p   r a w   i m p o r t   n a m e s   t o   c a n o n i c a l   P y P I   p a c k a g e   n a m e s . 
 
 
 
         U s e s   t h e   I M P O R T _ T O _ P A C K A G E   m a p p i n g   a n d   f i l t e r s   o u t   s t d l i b   m o d u l e s . 
 
 
 
         A r g s : 
 
                 i m p o r t s :   S e t   o f   t o p - l e v e l   i m p o r t   n a m e s . 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   P y P I   p a c k a g e   n a m e s   ( n o r m a l i z e d ,   s t d l i b   r e m o v e d ) . 
 
         " " " 
 
         p a c k a g e s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         f o r   i m p   i n   i m p o r t s : 
 
                 i f   i m p   i n   I G N O R E _ I M P O R T S : 
 
                         c o n t i n u e 
 
                 c a n o n i c a l   =   I M P O R T _ T O _ P A C K A G E . g e t ( i m p ,   i m p ) 
 
                 p a c k a g e s . a d d ( n o r m a l i z e _ p a c k a g e _ n a m e ( c a n o n i c a l ) ) 
 
 
 
         r e t u r n   p a c k a g e s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p a r s e r / l o c k f i l e . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " P a r s e r s   f o r   l o c k f i l e s :   p o e t r y . l o c k ,   P i p f i l e . l o c k ,   u v . l o c k . 
 
 
 
 L o c k f i l e s   g i v e   u s   e x a c t   i n s t a l l e d   v e r s i o n s ,   w h i c h   i s   m o r e   a c c u r a t e   t h a n 
 
 p a r s i n g   r e q u i r e m e n t s . t x t   ( w h i c h   o f t e n   o n l y   s p e c i f i e s   m i n   v e r s i o n ) . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   j s o n 
 
 i m p o r t   s y s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   S e t 
 
 
 
 i f   s y s . v e r s i o n _ i n f o   > =   ( 3 ,   1 1 ) : 
 
         i m p o r t   t o m l l i b     #   t y p e :   i g n o r e [ i m p o r t - n o t - f o u n d ] 
 
 e l s e :     #   p r a g m a :   n o   c o v e r 
 
         t r y : 
 
                 i m p o r t   t o m l i   a s   t o m l l i b     #   t y p e :   i g n o r e [ i m p o r t - n o t - f o u n d , n o - r e d e f ] 
 
         e x c e p t   I m p o r t E r r o r : 
 
                 t o m l l i b   =   N o n e     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
 
 
 
 
 d e f   p a r s e _ p o e t r y _ l o c k ( f i l e _ p a t h :   P a t h )   - >   D i c t [ s t r ,   s t r ] : 
 
         " " " P a r s e   p o e t r y . l o c k       T O M L   f o r m a t   w i t h   [ [ p a c k a g e ] ]   e n t r i e s . 
 
 
 
         R e t u r n s : 
 
                 D i c t   o f   { p a c k a g e _ n a m e :   l o c k e d _ v e r s i o n } . 
 
         " " " 
 
         r e s u l t :   D i c t [ s t r ,   s t r ]   =   { } 
 
         i f   t o m l l i b   i s   N o n e   o r   n o t   f i l e _ p a t h . e x i s t s ( ) : 
 
                 r e t u r n   r e s u l t 
 
 
 
         t r y : 
 
                 w i t h   o p e n ( f i l e _ p a t h ,   " r b " )   a s   f : 
 
                         d a t a   =   t o m l l i b . l o a d ( f ) 
 
         e x c e p t   ( O S E r r o r ,   V a l u e E r r o r ) : 
 
                 r e t u r n   r e s u l t 
 
 
 
         f o r   p k g   i n   d a t a . g e t ( " p a c k a g e " ,   [ ] )   o r   [ ] : 
 
                 n a m e   =   p k g . g e t ( " n a m e " ) 
 
                 v e r s i o n   =   p k g . g e t ( " v e r s i o n " ,   " u n k n o w n " ) 
 
                 i f   n a m e : 
 
                         r e s u l t [ s t r ( n a m e ) . l o w e r ( ) ]   =   s t r ( v e r s i o n ) 
 
 
 
         r e t u r n   r e s u l t 
 
 
 
 
 
 d e f   p a r s e _ p i p f i l e _ l o c k ( f i l e _ p a t h :   P a t h )   - >   D i c t [ s t r ,   s t r ] : 
 
         " " " P a r s e   P i p f i l e . l o c k       J S O N   w i t h   ' d e f a u l t '   a n d   ' d e v e l o p '   s e c t i o n s . 
 
 
 
         R e t u r n s : 
 
                 D i c t   o f   { p a c k a g e _ n a m e :   l o c k e d _ v e r s i o n } . 
 
         " " " 
 
         r e s u l t :   D i c t [ s t r ,   s t r ]   =   { } 
 
         i f   n o t   f i l e _ p a t h . e x i s t s ( ) : 
 
                 r e t u r n   r e s u l t 
 
 
 
         t r y : 
 
                 t e x t   =   f i l e _ p a t h . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
                 d a t a   =   j s o n . l o a d s ( t e x t ) 
 
         e x c e p t   ( O S E r r o r ,   j s o n . J S O N D e c o d e E r r o r ) : 
 
                 r e t u r n   r e s u l t 
 
 
 
         f o r   s e c t i o n   i n   ( " d e f a u l t " ,   " d e v e l o p " ) : 
 
                 s e c t i o n _ d a t a   =   d a t a . g e t ( s e c t i o n )   o r   { } 
 
                 i f   n o t   i s i n s t a n c e ( s e c t i o n _ d a t a ,   d i c t ) : 
 
                         c o n t i n u e 
 
                 f o r   n a m e ,   i n f o   i n   s e c t i o n _ d a t a . i t e m s ( ) : 
 
                         v e r s i o n   =   " " 
 
                         i f   i s i n s t a n c e ( i n f o ,   d i c t ) : 
 
                                 v e r s i o n _ s t r   =   i n f o . g e t ( " v e r s i o n " )   o r   " " 
 
                                 #   S t r i p   l e a d i n g   " = = "   i f   p r e s e n t 
 
                                 v e r s i o n   =   v e r s i o n _ s t r . l s t r i p ( " = " ) . s t r i p ( )   i f   v e r s i o n _ s t r   e l s e   " " 
 
                         r e s u l t [ s t r ( n a m e ) . l o w e r ( ) ]   =   v e r s i o n   o r   " u n k n o w n " 
 
 
 
         r e t u r n   r e s u l t 
 
 
 
 
 
 d e f   p a r s e _ u v _ l o c k ( f i l e _ p a t h :   P a t h )   - >   D i c t [ s t r ,   s t r ] : 
 
         " " " P a r s e   u v . l o c k       T O M L   w i t h   [ [ p a c k a g e ] ]   e n t r i e s   ( s i m i l a r   t o   p o e t r y ) . 
 
 
 
         R e t u r n s : 
 
                 D i c t   o f   { p a c k a g e _ n a m e :   l o c k e d _ v e r s i o n } . 
 
         " " " 
 
         r e t u r n   p a r s e _ p o e t r y _ l o c k ( f i l e _ p a t h )     #   u v . l o c k   u s e s   t h e   s a m e   s c h e m a 
 
 
 
 
 
 d e f   g e t _ l o c k f i l e _ i n f o ( p r o j e c t _ p a t h :   P a t h )   - >   D i c t [ s t r ,   s t r ] : 
 
         " " " A g g r e g a t e   l o c k f i l e   d a t a   f r o m   a n y   o f   t h e   s u p p o r t e d   l o c k f i l e s . 
 
 
 
         P r i o r i t y   o r d e r   ( f i r s t   f o u n d   w i n s ) : 
 
                 1 .   p o e t r y . l o c k 
 
                 2 .   u v . l o c k 
 
                 3 .   P i p f i l e . l o c k 
 
 
 
         R e t u r n s : 
 
                 D i c t   m a p p i n g   l o w e r c a s e   p a c k a g e   n a m e s   t o   l o c k e d   v e r s i o n s . 
 
         " " " 
 
         p o e t r y   =   p r o j e c t _ p a t h   /   " p o e t r y . l o c k " 
 
         i f   p o e t r y . e x i s t s ( ) : 
 
                 r e t u r n   p a r s e _ p o e t r y _ l o c k ( p o e t r y ) 
 
 
 
         u v   =   p r o j e c t _ p a t h   /   " u v . l o c k " 
 
         i f   u v . e x i s t s ( ) : 
 
                 r e t u r n   p a r s e _ u v _ l o c k ( u v ) 
 
 
 
         p i p f i l e   =   p r o j e c t _ p a t h   /   " P i p f i l e . l o c k " 
 
         i f   p i p f i l e . e x i s t s ( ) : 
 
                 r e t u r n   p a r s e _ p i p f i l e _ l o c k ( p i p f i l e ) 
 
 
 
         r e t u r n   { } 
 
 
 
 
 
 d e f   d e t e c t _ l o c k f i l e ( p r o j e c t _ p a t h :   P a t h )   - >   P a t h   |   N o n e : 
 
         " " " R e t u r n   t h e   p a t h   t o   t h e   f i r s t   l o c k f i l e   f o u n d ,   o r   N o n e . " " " 
 
         f o r   n a m e   i n   ( " p o e t r y . l o c k " ,   " u v . l o c k " ,   " P i p f i l e . l o c k " ) : 
 
                 c a n d i d a t e   =   p r o j e c t _ p a t h   /   n a m e 
 
                 i f   c a n d i d a t e . e x i s t s ( ) : 
 
                         r e t u r n   c a n d i d a t e 
 
         r e t u r n   N o n e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p a r s e r / p a c k a g e _ j s o n . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " P a r s e   d e p e n d e n c i e s   f r o m   p a c k a g e . j s o n   ( N o d e . j s   p r o j e c t s ) . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   j s o n 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   S e t 
 
 
 
 
 
 d e f   p a r s e _ p a c k a g e _ j s o n ( f i l e _ p a t h :   P a t h )   - >   S e t [ s t r ] : 
 
         " " " E x t r a c t   d e p e n d e n c y   n a m e s   f r o m   p a c k a g e . j s o n . 
 
 
 
         R e a d s   b o t h   ` d e p e n d e n c i e s `   a n d   ` d e v D e p e n d e n c i e s ` . 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   p a c k a g e   n a m e s   ( r a w   s t r i n g s   f r o m   p a c k a g e . j s o n ) . 
 
         " " " 
 
         d e p s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         i f   n o t   f i l e _ p a t h . e x i s t s ( ) : 
 
                 r e t u r n   d e p s 
 
 
 
         t r y : 
 
                 t e x t   =   f i l e _ p a t h . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
                 d a t a   =   j s o n . l o a d s ( t e x t ) 
 
         e x c e p t   ( O S E r r o r ,   j s o n . J S O N D e c o d e E r r o r ) : 
 
                 r e t u r n   d e p s 
 
 
 
         f o r   s e c t i o n   i n   ( " d e p e n d e n c i e s " ,   " d e v D e p e n d e n c i e s " ,   " p e e r D e p e n d e n c i e s " ) : 
 
                 s e c t i o n _ d a t a   =   d a t a . g e t ( s e c t i o n )   o r   { } 
 
                 i f   i s i n s t a n c e ( s e c t i o n _ d a t a ,   d i c t ) : 
 
                         f o r   p k g _ n a m e   i n   s e c t i o n _ d a t a : 
 
                                 i f   p k g _ n a m e   a n d   i s i n s t a n c e ( p k g _ n a m e ,   s t r ) : 
 
                                         d e p s . a d d ( p k g _ n a m e . s t r i p ( ) ) 
 
 
 
         r e t u r n   d e p s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p a r s e r / p y p r o j e c t . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " P a r s e   [ p r o j e c t . d e p e n d e n c i e s ]   f r o m   p y p r o j e c t . t o m l   ( P E P   6 2 1 ) . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   r e 
 
 i m p o r t   s y s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   S e t 
 
 
 
 i f   s y s . v e r s i o n _ i n f o   > =   ( 3 ,   1 1 ) : 
 
         i m p o r t   t o m l l i b     #   t y p e :   i g n o r e [ i m p o r t - n o t - f o u n d ] 
 
 e l s e :     #   p r a g m a :   n o   c o v e r 
 
         t r y : 
 
                 i m p o r t   t o m l i   a s   t o m l l i b     #   t y p e :   i g n o r e [ i m p o r t - n o t - f o u n d , n o - r e d e f ] 
 
         e x c e p t   I m p o r t E r r o r : 
 
                 t o m l l i b   =   N o n e     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
 
 
 _ R E Q _ N A M E _ R E   =   r e . c o m p i l e ( r " ^ ( [ A - Z a - z 0 - 9 _ ] [ A - Z a - z 0 - 9 _ . \ - ] * ) " ) 
 
 
 
 
 
 d e f   _ e x t r a c t _ n a m e _ f r o m _ s p e c ( s p e c :   s t r )   - >   s t r   |   N o n e : 
 
         " " " E x t r a c t   p a c k a g e   n a m e   f r o m   a   P E P   5 0 8   s p e c   s t r i n g . " " " 
 
         s p e c   =   s p e c . s t r i p ( ) 
 
         i f   n o t   s p e c : 
 
                 r e t u r n   N o n e 
 
         m a t c h   =   _ R E Q _ N A M E _ R E . m a t c h ( s p e c ) 
 
         r e t u r n   m a t c h . g r o u p ( 1 )   i f   m a t c h   e l s e   N o n e 
 
 
 
 
 
 d e f   p a r s e _ p y p r o j e c t _ t o m l ( f i l e _ p a t h :   P a t h )   - >   S e t [ s t r ] : 
 
         " " " P a r s e   [ p r o j e c t . d e p e n d e n c i e s ]   a n d   [ p r o j e c t . o p t i o n a l - d e p e n d e n c i e s ]   f r o m   p y p r o j e c t . t o m l . 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   p a c k a g e   n a m e s   ( r a w ,   n o t   n o r m a l i z e d ) . 
 
         " " " 
 
         d e p s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         i f   t o m l l i b   i s   N o n e : 
 
                 r e t u r n   d e p s 
 
         i f   n o t   f i l e _ p a t h . e x i s t s ( ) : 
 
                 r e t u r n   d e p s 
 
 
 
         t r y : 
 
                 w i t h   o p e n ( f i l e _ p a t h ,   " r b " )   a s   f : 
 
                         d a t a :   D i c t [ s t r ,   A n y ]   =   t o m l l i b . l o a d ( f ) 
 
         e x c e p t   ( O S E r r o r ,   V a l u e E r r o r ) : 
 
                 r e t u r n   d e p s 
 
 
 
         p r o j e c t   =   d a t a . g e t ( " p r o j e c t " ,   { } ) 
 
         i f   n o t   i s i n s t a n c e ( p r o j e c t ,   d i c t ) : 
 
                 r e t u r n   d e p s 
 
 
 
         #   M a i n   r u n t i m e   d e p e n d e n c i e s 
 
         f o r   s p e c   i n   p r o j e c t . g e t ( " d e p e n d e n c i e s " ,   [ ] )   o r   [ ] : 
 
                 i f   i s i n s t a n c e ( s p e c ,   s t r ) : 
 
                         n a m e   =   _ e x t r a c t _ n a m e _ f r o m _ s p e c ( s p e c ) 
 
                         i f   n a m e : 
 
                                 d e p s . a d d ( n a m e ) 
 
 
 
         #   O p t i o n a l / e x t r a   d e p e n d e n c i e s 
 
         o p t i o n a l   =   p r o j e c t . g e t ( " o p t i o n a l - d e p e n d e n c i e s " ,   { } ) 
 
         i f   i s i n s t a n c e ( o p t i o n a l ,   d i c t ) : 
 
                 f o r   _ e x t r a ,   s p e c s   i n   o p t i o n a l . i t e m s ( ) : 
 
                         f o r   s p e c   i n   s p e c s   o r   [ ] : 
 
                                 i f   i s i n s t a n c e ( s p e c ,   s t r ) : 
 
                                         n a m e   =   _ e x t r a c t _ n a m e _ f r o m _ s p e c ( s p e c ) 
 
                                         i f   n a m e : 
 
                                                 d e p s . a d d ( n a m e ) 
 
 
 
         #   P o e t r y - s t y l e   f a l l b a c k :   [ t o o l . p o e t r y . d e p e n d e n c i e s ] 
 
         p o e t r y   =   d a t a . g e t ( " t o o l " ,   { } ) . g e t ( " p o e t r y " ,   { } )   i f   i s i n s t a n c e ( d a t a . g e t ( " t o o l " ) ,   d i c t )   e l s e   { } 
 
         i f   i s i n s t a n c e ( p o e t r y ,   d i c t ) : 
 
                 f o r   n a m e   i n   ( p o e t r y . g e t ( " d e p e n d e n c i e s " )   o r   { } ) : 
 
                         i f   n a m e   a n d   n a m e . l o w e r ( )   ! =   " p y t h o n " : 
 
                                 d e p s . a d d ( n a m e ) 
 
                 f o r   n a m e   i n   ( p o e t r y . g e t ( " d e v - d e p e n d e n c i e s " )   o r   { } ) : 
 
                         i f   n a m e   a n d   n a m e . l o w e r ( )   ! =   " p y t h o n " : 
 
                                 d e p s . a d d ( n a m e ) 
 
 
 
         r e t u r n   d e p s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p a r s e r / r e q u i r e m e n t s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " P a r s e   r e q u i r e m e n t s . t x t   f i l e s   w i t h   f u l l   P E P   5 0 8   /   p i p   s y n t a x   s u p p o r t . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   r e 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   S e t 
 
 
 
 #   S t r i p   t r a i l i n g   v e r s i o n   s p e c i f i e r s ,   e x t r a s ,   e n v i r o n m e n t   m a r k e r s 
 
 _ R E Q _ N A M E _ R E   =   r e . c o m p i l e ( r " ^ ( [ A - Z a - z 0 - 9 _ ] [ A - Z a - z 0 - 9 _ . \ - ] * ) " ) 
 
 _ E G G _ R E   =   r e . c o m p i l e ( r " # e g g = ( [ A - Z a - z 0 - 9 _ ] [ A - Z a - z 0 - 9 _ . \ - ] * ) " ) 
 
 
 
 #   L i n e s   s t a r t i n g   w i t h   t h e s e   f l a g s   a r e   n o t   p a c k a g e s   t h e m s e l v e s 
 
 _ P I P _ F L A G S   =   ( 
 
         " - i " ,   " - - i n d e x - u r l " , 
 
         " - - e x t r a - i n d e x - u r l " , 
 
         " - - t r u s t e d - h o s t " , 
 
         " - - f i n d - l i n k s " ,   " - f " , 
 
         " - - n o - i n d e x " , 
 
         " - - p r e " , 
 
         " - - n o - b i n a r y " ,   " - - o n l y - b i n a r y " , 
 
         " - - r e q u i r e - h a s h e s " , 
 
         " - c " ,   " - - c o n s t r a i n t " , 
 
 ) 
 
 
 
 
 
 d e f   _ e x t r a c t _ n a m e _ f r o m _ l i n e ( l i n e :   s t r )   - >   s t r   |   N o n e : 
 
         " " " P u l l   t h e   b a r e   p a c k a g e   n a m e   o u t   o f   a   r e q u i r e m e n t s . t x t   l i n e . " " " 
 
         l i n e   =   l i n e . s t r i p ( ) 
 
         i f   n o t   l i n e : 
 
                 r e t u r n   N o n e 
 
 
 
         #   D i r e c t   U R L   w i t h   # e g g = n a m e   ( e . g . ,   - e   g i t + h t t p s : / / . . . # e g g = m y p a c k a g e ) 
 
         e g g _ m a t c h   =   _ E G G _ R E . s e a r c h ( l i n e ) 
 
         i f   e g g _ m a t c h : 
 
                 r e t u r n   e g g _ m a t c h . g r o u p ( 1 ) 
 
 
 
         #   P E P   5 0 8   d i r e c t   r e f e r e n c e :   " n a m e   @   u r l " 
 
         i f   " @ "   i n   l i n e   a n d   n o t   l i n e . s t a r t s w i t h ( " g i t + " ) : 
 
                 h e a d   =   l i n e . s p l i t ( " @ " ,   1 ) [ 0 ] . s t r i p ( ) 
 
                 m a t c h   =   _ R E Q _ N A M E _ R E . m a t c h ( h e a d ) 
 
                 i f   m a t c h : 
 
                         r e t u r n   m a t c h . g r o u p ( 1 ) 
 
 
 
         #   S t a n d a r d   p a c k a g e   s p e c :   " n a m e [ e x t r a ] > = v e r s i o n ;   m a r k e r " 
 
         m a t c h   =   _ R E Q _ N A M E _ R E . m a t c h ( l i n e ) 
 
         i f   m a t c h : 
 
                 r e t u r n   m a t c h . g r o u p ( 1 ) 
 
 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   p a r s e _ r e q u i r e m e n t s _ t x t ( f i l e _ p a t h :   P a t h ,   _ s e e n :   S e t [ P a t h ]   |   N o n e   =   N o n e )   - >   S e t [ s t r ] : 
 
         " " " P a r s e   a   r e q u i r e m e n t s . t x t   f i l e   r e c u r s i v e l y   ( h a n d l e s   - r / - c   i n c l u d e s ) . 
 
 
 
         A r g s : 
 
                 f i l e _ p a t h :   P a t h   t o   t h e   r e q u i r e m e n t s . t x t   f i l e . 
 
                 _ s e e n :   I n t e r n a l   t r a c k i n g   s e t   t o   p r e v e n t   i n f i n i t e   r e c u r s i o n . 
 
 
 
         R e t u r n s : 
 
                 S e t   o f   p a c k a g e   n a m e s   ( r a w ,   n o t   y e t   n o r m a l i z e d ) . 
 
         " " " 
 
         _ s e e n   =   _ s e e n   o r   s e t ( ) 
 
         f i l e _ p a t h   =   f i l e _ p a t h . r e s o l v e ( ) 
 
         i f   f i l e _ p a t h   i n   _ s e e n : 
 
                 r e t u r n   s e t ( ) 
 
         _ s e e n . a d d ( f i l e _ p a t h ) 
 
 
 
         d e p s :   S e t [ s t r ]   =   s e t ( ) 
 
 
 
         i f   n o t   f i l e _ p a t h . e x i s t s ( ) : 
 
                 r e t u r n   d e p s 
 
 
 
         t r y : 
 
                 t e x t   =   f i l e _ p a t h . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
         e x c e p t   O S E r r o r : 
 
                 r e t u r n   d e p s 
 
 
 
         f o r   r a w _ l i n e   i n   t e x t . s p l i t l i n e s ( ) : 
 
                 #   S t r i p   i n l i n e   c o m m e n t s   o n l y   w h e r e   ' # '   i s   p r e c e d e d   b y   w h i t e s p a c e , 
 
                 #   s o   w e   d o n ' t   s t r i p   # e g g = n a m e   f r o m   g i t   V C S   U R L s 
 
                 r a w _ l i n e   =   r e . s u b ( r ' \ s + # . * $ ' ,   ' ' ,   r a w _ l i n e ) 
 
                 l i n e   =   r a w _ l i n e . s t r i p ( ) 
 
                 i f   n o t   l i n e : 
 
                         c o n t i n u e 
 
 
 
                 #   R e c u r s i v e   i n c l u d e s 
 
                 i f   l i n e . s t a r t s w i t h ( " - r   " )   o r   l i n e . s t a r t s w i t h ( " - - r e q u i r e m e n t   " ) : 
 
                         i n c l u d e d   =   l i n e . s p l i t ( m a x s p l i t = 1 ) [ 1 ] . s t r i p ( ) 
 
                         i n c l u d e d _ p a t h   =   ( f i l e _ p a t h . p a r e n t   /   i n c l u d e d ) . r e s o l v e ( ) 
 
                         d e p s . u p d a t e ( p a r s e _ r e q u i r e m e n t s _ t x t ( i n c l u d e d _ p a t h ,   _ s e e n ) ) 
 
                         c o n t i n u e 
 
                 i f   l i n e . s t a r t s w i t h ( " - c   " )   o r   l i n e . s t a r t s w i t h ( " - - c o n s t r a i n t   " ) : 
 
                         i n c l u d e d   =   l i n e . s p l i t ( m a x s p l i t = 1 ) [ 1 ] . s t r i p ( ) 
 
                         i n c l u d e d _ p a t h   =   ( f i l e _ p a t h . p a r e n t   /   i n c l u d e d ) . r e s o l v e ( ) 
 
                         d e p s . u p d a t e ( p a r s e _ r e q u i r e m e n t s _ t x t ( i n c l u d e d _ p a t h ,   _ s e e n ) ) 
 
                         c o n t i n u e 
 
 
 
                 #   S k i p   p i p   f l a g s   /   o p t i o n s 
 
                 i f   a n y ( l i n e . s t a r t s w i t h ( f l a g   +   "   " )   o r   l i n e   = =   f l a g   f o r   f l a g   i n   _ P I P _ F L A G S ) : 
 
                         c o n t i n u e 
 
                 i f   l i n e . s t a r t s w i t h ( " - - h a s h " ) : 
 
                         c o n t i n u e 
 
 
 
                 #   E d i t a b l e   i n s t a l l s :   " - e   . . . "       k e e p   p a r s i n g   t h e   U R L / p a t h   p a r t 
 
                 i f   l i n e . s t a r t s w i t h ( " - e   " )   o r   l i n e . s t a r t s w i t h ( " - - e d i t a b l e   " ) : 
 
                         l i n e   =   l i n e . s p l i t ( m a x s p l i t = 1 ) [ 1 ] . s t r i p ( ) 
 
 
 
                 n a m e   =   _ e x t r a c t _ n a m e _ f r o m _ l i n e ( l i n e ) 
 
                 i f   n a m e : 
 
                         d e p s . a d d ( n a m e ) 
 
 
 
         r e t u r n   d e p s 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / p y p i . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " F e t c h   p a c k a g e   m e t a d a t a   f r o m   P y P I ' s   p u b l i c   J S O N   A P I   ( n o   a u t h   r e q u i r e d ) . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   t i m e 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   O p t i o n a l 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 f r o m   k r a i m i n d . u t i l s . c a c h e   i m p o r t   c a c h e d _ r e q u e s t 
 
 
 
 _ P Y P I _ J S O N   =   " h t t p s : / / p y p i . o r g / p y p i / { p a c k a g e } / j s o n " 
 
 _ P Y P I S T A T S   =   " h t t p s : / / p y p i s t a t s . o r g / a p i / p a c k a g e s / { p a c k a g e } / r e c e n t " 
 
 
 
 
 
 d e f   _ g i t h u b _ u r l _ f r o m _ p r o j e c t _ u r l s ( p r o j e c t _ u r l s :   D i c t [ s t r ,   s t r ] )   - >   O p t i o n a l [ s t r ] : 
 
         f o r   _ k e y ,   v a l u e   i n   p r o j e c t _ u r l s . i t e m s ( ) : 
 
                 i f   v a l u e   a n d   " g i t h u b . c o m "   i n   v a l u e . l o w e r ( ) : 
 
                         r e t u r n   v a l u e 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   f e t c h _ p a c k a g e _ m e t a d a t a ( p a c k a g e :   s t r ,   u s e _ c a c h e :   b o o l   =   T r u e )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
         " " " F e t c h   m e t a d a t a   f o r   a   P y P I   p a c k a g e . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   n a m e   ( e . g .   " r e q u e s t s " ) . 
 
                 u s e _ c a c h e :   U s e   l o c a l   2 4 h   c a c h e   ( d e f a u l t   T r u e ) . 
 
 
 
         R e t u r n s : 
 
                 D i c t   o f   p a c k a g e   m e t a d a t a ,   o r   N o n e   i f   n o t   f o u n d   /   n e t w o r k   e r r o r . 
 
         " " " 
 
         i f   n o t   p a c k a g e : 
 
                 r e t u r n   N o n e 
 
 
 
         u r l   =   _ P Y P I _ J S O N . f o r m a t ( p a c k a g e = p a c k a g e ) 
 
 
 
         d e f   _ f e t c h ( )   - >   O p t i o n a l [ D i c t [ s t r ,   A n y ] ] : 
 
                 t r y : 
 
                         w i t h   h t t p x . C l i e n t ( t i m e o u t = 1 0 . 0 ,   f o l l o w _ r e d i r e c t s = T r u e )   a s   c l i e n t : 
 
                                 r e s p   =   c l i e n t . g e t ( u r l ) 
 
                                 i f   r e s p . s t a t u s _ c o d e   = =   4 0 4 : 
 
                                         r e t u r n   N o n e 
 
                                 r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                                 d a t a   =   r e s p . j s o n ( ) 
 
                 e x c e p t   E x c e p t i o n : 
 
                         r e t u r n   N o n e 
 
 
 
                 i n f o   =   d a t a . g e t ( " i n f o " )   o r   { } 
 
                 r e l e a s e s   =   d a t a . g e t ( " r e l e a s e s " )   o r   { } 
 
                 l a t e s t   =   i n f o . g e t ( " v e r s i o n " ) 
 
 
 
                 r e l e a s e _ d a t e :   O p t i o n a l [ s t r ]   =   N o n e 
 
                 i f   l a t e s t   a n d   l a t e s t   i n   r e l e a s e s : 
 
                         u p l o a d s   =   r e l e a s e s [ l a t e s t ] 
 
                         i f   u p l o a d s   a n d   i s i n s t a n c e ( u p l o a d s ,   l i s t ) : 
 
                                 r e l e a s e _ d a t e   =   u p l o a d s [ 0 ] . g e t ( " u p l o a d _ t i m e " ) 
 
 
 
                 p r o j e c t _ u r l s   =   i n f o . g e t ( " p r o j e c t _ u r l s " )   o r   { } 
 
                 r e p o _ u r l   =   _ g i t h u b _ u r l _ f r o m _ p r o j e c t _ u r l s ( p r o j e c t _ u r l s ) 
 
                 i f   n o t   r e p o _ u r l : 
 
                         h o m e   =   i n f o . g e t ( " h o m e _ p a g e " )   o r   " " 
 
                         i f   " g i t h u b . c o m "   i n   h o m e . l o w e r ( ) : 
 
                                 r e p o _ u r l   =   h o m e 
 
 
 
                 r e t u r n   { 
 
                         " n a m e " :   i n f o . g e t ( " n a m e " ,   p a c k a g e ) , 
 
                         " v e r s i o n " :   l a t e s t , 
 
                         " s u m m a r y " :   i n f o . g e t ( " s u m m a r y " ) , 
 
                         " a u t h o r " :   i n f o . g e t ( " a u t h o r " )   o r   i n f o . g e t ( " m a i n t a i n e r " ) , 
 
                         " a u t h o r _ e m a i l " :   i n f o . g e t ( " a u t h o r _ e m a i l " ) , 
 
                         " l i c e n s e " :   i n f o . g e t ( " l i c e n s e " ) , 
 
                         " h o m e _ p a g e " :   i n f o . g e t ( " h o m e _ p a g e " ) , 
 
                         " p r o j e c t _ u r l s " :   p r o j e c t _ u r l s , 
 
                         " r e p o _ u r l " :   r e p o _ u r l , 
 
                         " r e q u i r e s _ p y t h o n " :   i n f o . g e t ( " r e q u i r e s _ p y t h o n " ) , 
 
                         " r e l e a s e _ d a t e " :   r e l e a s e _ d a t e , 
 
                         " c l a s s i f i e r s " :   i n f o . g e t ( " c l a s s i f i e r s " )   o r   [ ] , 
 
                         " h a s _ s e c u r i t y _ a d v i s o r i e s " :   F a l s e ,     #   P y P I   J S O N   A P I   d o e s n ' t   e x p o s e   t h i s   d i r e c t l y 
 
                 } 
 
 
 
         i f   u s e _ c a c h e : 
 
                 r e t u r n   c a c h e d _ r e q u e s t ( f " p y p i : { p a c k a g e . l o w e r ( ) } " ,   _ f e t c h ,   t t l _ h o u r s = 2 4 ) 
 
         r e t u r n   _ f e t c h ( ) 
 
 
 
 
 
 d e f   g e t _ p a c k a g e _ d o w n l o a d s ( p a c k a g e :   s t r ,   p e r i o d :   s t r   =   " m o n t h " )   - >   O p t i o n a l [ i n t ] : 
 
         " " " F e t c h   r e c e n t   d o w n l o a d   c o u n t   f r o m   p y p i s t a t s . o r g   ( b e s t - e f f o r t ,   n o n - c r i t i c a l ) . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   n a m e . 
 
                 p e r i o d :   " d a y " ,   " w e e k " ,   o r   " m o n t h " . 
 
 
 
         R e t u r n s : 
 
                 D o w n l o a d   c o u n t   o r   N o n e   i f   u n a v a i l a b l e . 
 
         " " " 
 
         u r l   =   _ P Y P I S T A T S . f o r m a t ( p a c k a g e = p a c k a g e . l o w e r ( ) ) 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = 5 . 0 )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . g e t ( u r l ) 
 
                         i f   r e s p . s t a t u s _ c o d e   = =   2 0 0 : 
 
                                 d a t a   =   r e s p . j s o n ( ) 
 
                                 r e t u r n   d a t a . g e t ( " d a t a " ,   { } ) . g e t ( f " l a s t _ { p e r i o d } " ) 
 
         e x c e p t   E x c e p t i o n : 
 
                 p a s s 
 
         r e t u r n   N o n e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e m o v e / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " A t o m i c   s a f e - r e m o v e :   s n a p s h o t       u n i n s t a l l       t e s t       r o l l b a c k   o n   f a i l u r e . 
 
 
 
 T h i s   i s   K r a i m i n d ' s   u n i q u e   v a l u e - a d d       n o   o t h e r   P y t h o n   t o o l   c o m b i n e s   A S T 
 
 v e r i f i c a t i o n ,   s n a p s h o t - b a c k e d   u n i n s t a l l ,   t r a n s i t i v e   c l e a n u p ,   t e s t - a w a r e 
 
 r o l l b a c k ,   a n d   c o n f i d e n c e - s c o r e d   g a t i n g   i n   a   s i n g l e   c o m m a n d . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   k r a i m i n d . r e m o v e . e x e c u t o r   i m p o r t   ( 
 
         P a c k a g e M a n a g e r , 
 
         R e m o v a l P l a n , 
 
         R e m o v a l R e s u l t , 
 
         d e t e c t _ p a c k a g e _ m a n a g e r , 
 
         e x e c u t e _ r e m o v a l , 
 
         p l a n _ r e m o v a l , 
 
 ) 
 
 f r o m   k r a i m i n d . r e m o v e . r o l l b a c k   i m p o r t   r e s t o r e _ s n a p s h o t 
 
 f r o m   k r a i m i n d . r e m o v e . s n a p s h o t   i m p o r t   ( 
 
         S N A P S H O T S _ D I R , 
 
         c r e a t e _ s n a p s h o t , 
 
         l i s t _ s n a p s h o t s , 
 
 ) 
 
 f r o m   k r a i m i n d . r e m o v e . t e s t _ s e l e c t o r   i m p o r t   f i n d _ t e s t s _ i m p o r t i n g 
 
 f r o m   k r a i m i n d . r e m o v e . t r a n s i t i v e   i m p o r t   f i n d _ o r p h a n s 
 
 
 
 _ _ a l l _ _   =   [ 
 
         " P a c k a g e M a n a g e r " , 
 
         " R e m o v a l P l a n " , 
 
         " R e m o v a l R e s u l t " , 
 
         " S N A P S H O T S _ D I R " , 
 
         " c r e a t e _ s n a p s h o t " , 
 
         " d e t e c t _ p a c k a g e _ m a n a g e r " , 
 
         " e x e c u t e _ r e m o v a l " , 
 
         " f i n d _ o r p h a n s " , 
 
         " f i n d _ t e s t s _ i m p o r t i n g " , 
 
         " l i s t _ s n a p s h o t s " , 
 
         " p l a n _ r e m o v a l " , 
 
         " r e s t o r e _ s n a p s h o t " , 
 
 ] 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e m o v e / e x e c u t o r . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " R e m o v a l   e x e c u t o r :   d e t e c t s   p a c k a g e   m a n a g e r ,   b u i l d s   p l a n ,   r u n s   t h e   p i p e l i n e . 
 
 
 
 P i p e l i n e : 
 
     1 .   D e t e c t   p a c k a g e   m a n a g e r   ( p o e t r y   /   u v   /   p i p ) . 
 
     2 .   B u i l d   R e m o v a l P l a n   ( t a r g e t   +   t r a n s i t i v e   o r p h a n s ) . 
 
     3 .   S n a p s h o t   v e n v . 
 
     4 .   U n i n s t a l l . 
 
     5 .   R u n   t a r g e t e d   t e s t s   ( o p t i o n a l ) . 
 
     6 .   R o l l   b a c k   s n a p s h o t   i f   t e s t s   f a i l . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   s h u t i l 
 
 i m p o r t   s u b p r o c e s s 
 
 i m p o r t   s y s 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   e n u m   i m p o r t   E n u m 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t ,   O p t i o n a l ,   S e t 
 
 
 
 f r o m   k r a i m i n d . r e m o v e . s n a p s h o t   i m p o r t   S n a p s h o t ,   c r e a t e _ s n a p s h o t 
 
 f r o m   k r a i m i n d . r e m o v e . t e s t _ s e l e c t o r   i m p o r t   f i n d _ t e s t s _ i m p o r t i n g 
 
 f r o m   k r a i m i n d . r e m o v e . t r a n s i t i v e   i m p o r t   f i n d _ o r p h a n s 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   n o r m a l i z e _ p a c k a g e _ n a m e 
 
 
 
 
 
 c l a s s   P a c k a g e M a n a g e r ( s t r ,   E n u m ) : 
 
         " " " S u p p o r t e d   P y t h o n   p a c k a g e   m a n a g e r s . " " " 
 
 
 
         P I P   =   " p i p " 
 
         P O E T R Y   =   " p o e t r y " 
 
         U V   =   " u v " 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   R e m o v a l P l a n : 
 
         " " " T h e   p l a n :   w h a t   w i l l   b e   u n i n s t a l l e d   a n d   w h i c h   t e s t s   w i l l   b e   c h e c k e d . " " " 
 
 
 
         t a r g e t :   s t r 
 
         p a c k a g e _ m a n a g e r :   P a c k a g e M a n a g e r 
 
         o r p h a n s :   L i s t [ s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
         t e s t _ f i l e s :   L i s t [ P a t h ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
 
 
         @ p r o p e r t y 
 
         d e f   a l l _ p a c k a g e s ( s e l f )   - >   L i s t [ s t r ] : 
 
                 " " " E v e r y   p a c k a g e   t h i s   p l a n   w i l l   u n i n s t a l l . " " " 
 
                 r e t u r n   [ s e l f . t a r g e t ]   +   l i s t ( s e l f . o r p h a n s ) 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   R e m o v a l R e s u l t : 
 
         " " " O u t c o m e   o f   a   r e m o v a l   a t t e m p t . " " " 
 
 
 
         s u c c e s s :   b o o l 
 
         p l a n :   R e m o v a l P l a n 
 
         s n a p s h o t :   O p t i o n a l [ S n a p s h o t ] 
 
         e r r o r :   O p t i o n a l [ s t r ]   =   N o n e 
 
         t e s t s _ p a s s e d :   O p t i o n a l [ b o o l ]   =   N o n e 
 
         r o l l e d _ b a c k :   b o o l   =   F a l s e 
 
         u n i n s t a l l e d :   L i s t [ s t r ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
 
 
 
 
 d e f   d e t e c t _ p a c k a g e _ m a n a g e r ( p r o j e c t _ p a t h :   P a t h )   - >   P a c k a g e M a n a g e r : 
 
         " " " R e t u r n   t h e   p a c k a g e   m a n a g e r   b e i n g   u s e d   i n   t h i s   p r o j e c t . 
 
 
 
         P r i o r i t y :   u v . l o c k       p o e t r y . l o c k       p i p   ( d e f a u l t ) . 
 
         " " " 
 
         i f   ( p r o j e c t _ p a t h   /   " u v . l o c k " ) . e x i s t s ( )   a n d   s h u t i l . w h i c h ( " u v " ) : 
 
                 r e t u r n   P a c k a g e M a n a g e r . U V 
 
         i f   ( p r o j e c t _ p a t h   /   " p o e t r y . l o c k " ) . e x i s t s ( )   a n d   s h u t i l . w h i c h ( " p o e t r y " ) : 
 
                 r e t u r n   P a c k a g e M a n a g e r . P O E T R Y 
 
         r e t u r n   P a c k a g e M a n a g e r . P I P 
 
 
 
 
 
 d e f   p l a n _ r e m o v a l ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         t a r g e t :   s t r , 
 
         d e c l a r e d :   S e t [ s t r ] , 
 
         s k i p _ t e s t _ s e l e c t i o n :   b o o l   =   F a l s e , 
 
 )   - >   R e m o v a l P l a n : 
 
         " " " B u i l d   a   r e m o v a l   p l a n :   p a c k a g e   m a n a g e r ,   o r p h a n s ,   t e s t   f i l e s . 
 
 
 
         A r g s : 
 
                 p r o j e c t _ p a t h :   P r o j e c t   r o o t . 
 
                 t a r g e t :   P a c k a g e   t o   r e m o v e . 
 
                 d e c l a r e d :   A l l   d e c l a r e d   d e p s   ( n o r m a l i z e d )       u s e d   t o   i d e n t i f y   o r p h a n s . 
 
                 s k i p _ t e s t _ s e l e c t i o n :   I f   T r u e ,   d o n ' t   s c a n   f o r   t e s t   f i l e s . 
 
 
 
         R e t u r n s : 
 
                 R e m o v a l P l a n   r e a d y   f o r   e x e c u t e _ r e m o v a l ( ) . 
 
         " " " 
 
         t a r g e t   =   n o r m a l i z e _ p a c k a g e _ n a m e ( t a r g e t ) 
 
         p m   =   d e t e c t _ p a c k a g e _ m a n a g e r ( p r o j e c t _ p a t h ) 
 
         o r p h a n s   =   f i n d _ o r p h a n s ( t a r g e t ,   d e c l a r e d ) 
 
         t e s t _ f i l e s :   L i s t [ P a t h ]   =   [ ] 
 
         i f   n o t   s k i p _ t e s t _ s e l e c t i o n : 
 
                 t e s t _ f i l e s   =   f i n d _ t e s t s _ i m p o r t i n g ( p r o j e c t _ p a t h ,   t a r g e t ) 
 
         r e t u r n   R e m o v a l P l a n ( 
 
                 t a r g e t = t a r g e t , 
 
                 p a c k a g e _ m a n a g e r = p m , 
 
                 o r p h a n s = o r p h a n s , 
 
                 t e s t _ f i l e s = t e s t _ f i l e s , 
 
         ) 
 
 
 
 
 
 d e f   _ u n i n s t a l l _ p i p ( p a c k a g e s :   L i s t [ s t r ] )   - >   t u p l e [ b o o l ,   s t r ] : 
 
         " " " U n i n s t a l l   p a c k a g e s   v i a   p i p ;   r e t u r n   ( s u c c e s s ,   o u t p u t ) . " " " 
 
         i f   n o t   p a c k a g e s : 
 
                 r e t u r n   T r u e ,   " " 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ s y s . e x e c u t a b l e ,   " - m " ,   " p i p " ,   " u n i n s t a l l " ,   " - y " ,   * p a c k a g e s ] , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 1 2 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r )   a s   e : 
 
                 r e t u r n   F a l s e ,   s t r ( e ) 
 
         r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 ,   r e s u l t . s t d o u t   +   r e s u l t . s t d e r r 
 
 
 
 
 
 d e f   _ u n i n s t a l l _ p o e t r y ( p r o j e c t _ p a t h :   P a t h ,   p a c k a g e s :   L i s t [ s t r ] )   - >   t u p l e [ b o o l ,   s t r ] : 
 
         " " " R e m o v e   p a c k a g e s   v i a   ` p o e t r y   r e m o v e ` ;   l e t   p o e t r y   h a n d l e   t r a n s i t i v e   c l e a n u p . " " " 
 
         i f   n o t   p a c k a g e s : 
 
                 r e t u r n   T r u e ,   " " 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ " p o e t r y " ,   " r e m o v e " ,   * p a c k a g e s ] , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 3 0 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r )   a s   e : 
 
                 r e t u r n   F a l s e ,   s t r ( e ) 
 
         r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 ,   r e s u l t . s t d o u t   +   r e s u l t . s t d e r r 
 
 
 
 
 
 d e f   _ u n i n s t a l l _ u v ( p r o j e c t _ p a t h :   P a t h ,   p a c k a g e s :   L i s t [ s t r ] )   - >   t u p l e [ b o o l ,   s t r ] : 
 
         " " " R e m o v e   p a c k a g e s   v i a   ` u v   r e m o v e ` . " " " 
 
         i f   n o t   p a c k a g e s : 
 
                 r e t u r n   T r u e ,   " " 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ " u v " ,   " r e m o v e " ,   * p a c k a g e s ] , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 3 0 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r )   a s   e : 
 
                 r e t u r n   F a l s e ,   s t r ( e ) 
 
         r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 ,   r e s u l t . s t d o u t   +   r e s u l t . s t d e r r 
 
 
 
 
 
 d e f   _ r u n _ t a r g e t e d _ t e s t s ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         t e s t _ f i l e s :   L i s t [ P a t h ] , 
 
         t e s t _ c m d :   O p t i o n a l [ L i s t [ s t r ] ]   =   N o n e , 
 
 )   - >   t u p l e [ b o o l ,   s t r ] : 
 
         " " " R u n   p y t e s t   o n   t h e   g i v e n   t e s t   f i l e s   ( o r   t h e   u s e r - p r o v i d e d   t e s t   c o m m a n d ) . " " " 
 
         i f   t e s t _ c m d : 
 
                 c m d   =   t e s t _ c m d 
 
         e l i f   t e s t _ f i l e s : 
 
                 c m d   =   [ " p y t e s t " ,   " - x " ,   " - - n o - h e a d e r " ,   " - q " ,   * [ s t r ( p )   f o r   p   i n   t e s t _ f i l e s ] ] 
 
         e l s e : 
 
                 r e t u r n   T r u e ,   " ( n o   t a r g e t e d   t e s t s   f o u n d ) " 
 
 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         c m d , 
 
                         c w d = p r o j e c t _ p a t h , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 6 0 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r )   a s   e : 
 
                 #   p y t e s t   n o t   i n s t a l l e d       t r e a t   a s   p a s s   ( c a n ' t   v e r i f y ,   d o n ' t   r o l l   b a c k ) 
 
                 r e t u r n   T r u e ,   f " ( t e s t   r u n n e r   u n a v a i l a b l e :   { e } ) " 
 
         r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 ,   r e s u l t . s t d o u t   +   r e s u l t . s t d e r r 
 
 
 
 
 
 d e f   e x e c u t e _ r e m o v a l ( 
 
         p r o j e c t _ p a t h :   P a t h , 
 
         p l a n :   R e m o v a l P l a n , 
 
         r u n _ t e s t s :   b o o l   =   T r u e , 
 
         d r y _ r u n :   b o o l   =   F a l s e , 
 
         t e s t _ c m d :   O p t i o n a l [ L i s t [ s t r ] ]   =   N o n e , 
 
 )   - >   R e m o v a l R e s u l t : 
 
         " " " E x e c u t e   a   r e m o v a l   p l a n   w i t h   s n a p s h o t   +   r o l l b a c k   s a f e t y . 
 
 
 
         A r g s : 
 
                 p r o j e c t _ p a t h :   P r o j e c t   r o o t . 
 
                 p l a n :   R e m o v a l P l a n   f r o m   p l a n _ r e m o v a l ( ) . 
 
                 r u n _ t e s t s :   W h e t h e r   t o   r u n   t a r g e t e d   t e s t s   a f t e r   u n i n s t a l l . 
 
                 d r y _ r u n :   I f   T r u e ,   o n l y   r e p o r t   w h a t   w o u l d   b e   d o n e . 
 
                 t e s t _ c m d :   O p t i o n a l   o v e r r i d e   t e s t   c o m m a n d   ( l i s t   o f   a r g s ) . 
 
 
 
         R e t u r n s : 
 
                 R e m o v a l R e s u l t   d e s c r i b i n g   t h e   o u t c o m e . 
 
         " " " 
 
         i f   d r y _ r u n : 
 
                 r e t u r n   R e m o v a l R e s u l t ( 
 
                         s u c c e s s = T r u e , 
 
                         p l a n = p l a n , 
 
                         s n a p s h o t = N o n e , 
 
                         u n i n s t a l l e d = [ ] , 
 
                 ) 
 
 
 
         s n a p s h o t   =   c r e a t e _ s n a p s h o t ( l a b e l = f " r e m o v e - { p l a n . t a r g e t } " ) 
 
         i f   s n a p s h o t   i s   N o n e : 
 
                 r e t u r n   R e m o v a l R e s u l t ( 
 
                         s u c c e s s = F a l s e , 
 
                         p l a n = p l a n , 
 
                         s n a p s h o t = N o n e , 
 
                         e r r o r = " F a i l e d   t o   c r e a t e   v e n v   s n a p s h o t       a b o r t i n g   f o r   s a f e t y " , 
 
                 ) 
 
 
 
         i f   p l a n . p a c k a g e _ m a n a g e r   = =   P a c k a g e M a n a g e r . P O E T R Y : 
 
                 o k ,   o u t p u t   =   _ u n i n s t a l l _ p o e t r y ( p r o j e c t _ p a t h ,   [ p l a n . t a r g e t ] ) 
 
         e l i f   p l a n . p a c k a g e _ m a n a g e r   = =   P a c k a g e M a n a g e r . U V : 
 
                 o k ,   o u t p u t   =   _ u n i n s t a l l _ u v ( p r o j e c t _ p a t h ,   [ p l a n . t a r g e t ] ) 
 
         e l s e : 
 
                 o k ,   o u t p u t   =   _ u n i n s t a l l _ p i p ( p l a n . a l l _ p a c k a g e s ) 
 
 
 
         i f   n o t   o k : 
 
                 r e t u r n   R e m o v a l R e s u l t ( 
 
                         s u c c e s s = F a l s e , 
 
                         p l a n = p l a n , 
 
                         s n a p s h o t = s n a p s h o t , 
 
                         e r r o r = f " U n i n s t a l l   f a i l e d : \ n { o u t p u t } " , 
 
                         u n i n s t a l l e d = [ ] , 
 
                 ) 
 
 
 
         u n i n s t a l l e d   =   l i s t ( p l a n . a l l _ p a c k a g e s ) 
 
 
 
         i f   n o t   r u n _ t e s t s : 
 
                 r e t u r n   R e m o v a l R e s u l t ( 
 
                         s u c c e s s = T r u e , 
 
                         p l a n = p l a n , 
 
                         s n a p s h o t = s n a p s h o t , 
 
                         u n i n s t a l l e d = u n i n s t a l l e d , 
 
                         t e s t s _ p a s s e d = N o n e , 
 
                 ) 
 
 
 
         t e s t s _ o k ,   t e s t _ o u t p u t   =   _ r u n _ t a r g e t e d _ t e s t s ( p r o j e c t _ p a t h ,   p l a n . t e s t _ f i l e s ,   t e s t _ c m d = t e s t _ c m d ) 
 
 
 
         i f   t e s t s _ o k : 
 
                 r e t u r n   R e m o v a l R e s u l t ( 
 
                         s u c c e s s = T r u e , 
 
                         p l a n = p l a n , 
 
                         s n a p s h o t = s n a p s h o t , 
 
                         u n i n s t a l l e d = u n i n s t a l l e d , 
 
                         t e s t s _ p a s s e d = T r u e , 
 
                 ) 
 
 
 
         #   T e s t s   f a i l e d       r o l l   b a c k 
 
         f r o m   k r a i m i n d . r e m o v e . r o l l b a c k   i m p o r t   r e s t o r e _ s n a p s h o t 
 
 
 
         r o l l b a c k _ o k   =   r e s t o r e _ s n a p s h o t ( s n a p s h o t ) 
 
         r e t u r n   R e m o v a l R e s u l t ( 
 
                 s u c c e s s = F a l s e , 
 
                 p l a n = p l a n , 
 
                 s n a p s h o t = s n a p s h o t , 
 
                 u n i n s t a l l e d = u n i n s t a l l e d , 
 
                 t e s t s _ p a s s e d = F a l s e , 
 
                 r o l l e d _ b a c k = r o l l b a c k _ o k , 
 
                 e r r o r = f " T e s t s   f a i l e d   a f t e r   r e m o v a l       { ' r o l l e d   b a c k '   i f   r o l l b a c k _ o k   e l s e   ' R O L L B A C K   F A I L E D ' } \ n { t e s t _ o u t p u t [ : 1 0 0 0 ] } " , 
 
         ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e m o v e / r o l l b a c k . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " R e s t o r e   a   v e n v   s n a p s h o t   v i a   ` p i p   i n s t a l l   - r   < s n a p s h o t . t x t > ` . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   s u b p r o c e s s 
 
 i m p o r t   s y s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   U n i o n 
 
 
 
 f r o m   k r a i m i n d . r e m o v e . s n a p s h o t   i m p o r t   S n a p s h o t 
 
 
 
 
 
 d e f   r e s t o r e _ s n a p s h o t ( s n a p s h o t :   U n i o n [ S n a p s h o t ,   P a t h ,   s t r ] )   - >   b o o l : 
 
         " " " R e s t o r e   t h e   v e n v   t o   t h e   s t a t e   c a p t u r e d   b y   ` s n a p s h o t ` . 
 
 
 
         C a l l s   ` p i p   i n s t a l l   - - f o r c e - r e i n s t a l l   - r   < s n a p s h o t . t x t > `   t o   b r i n g   t h e 
 
         e n v i r o n m e n t   b a c k   t o   t h e   s n a p s h o t t e d   s t a t e   ( r e - i n s t a l l s   t h e   t a r g e t , 
 
         r e - i n s t a l l s   a n y   t r a n s i t i v e   d e p s   t h a t   w e r e   r e m o v e d ) . 
 
 
 
         R e t u r n s : 
 
                 T r u e   o n   s u c c e s s ,   F a l s e   o t h e r w i s e . 
 
         " " " 
 
         i f   i s i n s t a n c e ( s n a p s h o t ,   S n a p s h o t ) : 
 
                 p a t h   =   s n a p s h o t . p a t h 
 
         e l i f   i s i n s t a n c e ( s n a p s h o t ,   s t r ) : 
 
                 p a t h   =   P a t h ( s n a p s h o t ) 
 
         e l s e : 
 
                 p a t h   =   s n a p s h o t 
 
 
 
         i f   n o t   p a t h . e x i s t s ( ) : 
 
                 r e t u r n   F a l s e 
 
 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ s y s . e x e c u t a b l e ,   " - m " ,   " p i p " ,   " i n s t a l l " ,   " - r " ,   s t r ( p a t h ) ,   " - - q u i e t " ] , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 6 0 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ) : 
 
                 r e t u r n   F a l s e 
 
 
 
         r e t u r n   r e s u l t . r e t u r n c o d e   = =   0 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e m o v e / s n a p s h o t . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " V e n v   s n a p s h o t   v i a   ` p i p   f r e e z e `       t h e   s a f e t y   n e t   f o r   a t o m i c   r e m o v a l . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   s u b p r o c e s s 
 
 i m p o r t   s y s 
 
 i m p o r t   t i m e 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t ,   O p t i o n a l 
 
 
 
 S N A P S H O T S _ D I R   =   P a t h . h o m e ( )   /   " . k r a i m i n d "   /   " s n a p s h o t s " 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   S n a p s h o t : 
 
         " " " R e p r e s e n t s   a   f r o z e n   v e n v   s t a t e   a t   a   p o i n t   i n   t i m e . " " " 
 
 
 
         p a t h :   P a t h 
 
         t i m e s t a m p :   f l o a t 
 
         p a c k a g e _ c o u n t :   i n t 
 
 
 
         @ p r o p e r t y 
 
         d e f   a g e _ h o u r s ( s e l f )   - >   f l o a t : 
 
                 r e t u r n   ( t i m e . t i m e ( )   -   s e l f . t i m e s t a m p )   /   3 6 0 0 . 0 
 
 
 
 
 
 d e f   _ e n s u r e _ s n a p s h o t s _ d i r ( )   - >   P a t h : 
 
         S N A P S H O T S _ D I R . m k d i r ( p a r e n t s = T r u e ,   e x i s t _ o k = T r u e ) 
 
         r e t u r n   S N A P S H O T S _ D I R 
 
 
 
 
 
 d e f   c r e a t e _ s n a p s h o t ( l a b e l :   s t r   =   " r e m o v e " )   - >   O p t i o n a l [ S n a p s h o t ] : 
 
         " " " C a p t u r e   t h e   c u r r e n t   v e n v   s t a t e   v i a   ` p i p   f r e e z e `   a n d   w r i t e   i t   t o   d i s k . 
 
 
 
         A r g s : 
 
                 l a b e l :   H u m a n - r e a d a b l e   t a g   ( e . g .   " r e m o v e " ,   " c l e a n " ,   " b i s e c t " ) . 
 
 
 
         R e t u r n s : 
 
                 S n a p s h o t   o b j e c t   o n   s u c c e s s ;   N o n e   i f   p i p   f r e e z e   f a i l e d . 
 
         " " " 
 
         s n a p s h o t s _ d i r   =   _ e n s u r e _ s n a p s h o t s _ d i r ( ) 
 
         t i m e s t a m p   =   t i m e . t i m e ( ) 
 
         t s _ s t r   =   t i m e . s t r f t i m e ( " % Y % m % d - % H % M % S " ,   t i m e . l o c a l t i m e ( t i m e s t a m p ) ) 
 
         s n a p s h o t _ p a t h   =   s n a p s h o t s _ d i r   /   f " { t s _ s t r } - { l a b e l } . t x t " 
 
 
 
         t r y : 
 
                 r e s u l t   =   s u b p r o c e s s . r u n ( 
 
                         [ s y s . e x e c u t a b l e ,   " - m " ,   " p i p " ,   " f r e e z e " ,   " - - a l l " ] , 
 
                         c a p t u r e _ o u t p u t = T r u e , 
 
                         t e x t = T r u e , 
 
                         t i m e o u t = 3 0 . 0 , 
 
                 ) 
 
         e x c e p t   ( F i l e N o t F o u n d E r r o r ,   s u b p r o c e s s . S u b p r o c e s s E r r o r ) : 
 
                 r e t u r n   N o n e 
 
 
 
         i f   r e s u l t . r e t u r n c o d e   ! =   0 : 
 
                 r e t u r n   N o n e 
 
 
 
         c o n t e n t   =   r e s u l t . s t d o u t 
 
         s n a p s h o t _ p a t h . w r i t e _ t e x t ( c o n t e n t ,   e n c o d i n g = " u t f - 8 " ) 
 
         p a c k a g e _ c o u n t   =   s u m ( 1   f o r   l i n e   i n   c o n t e n t . s p l i t l i n e s ( )   i f   l i n e . s t r i p ( )   a n d   n o t   l i n e . s t a r t s w i t h ( " # " ) ) 
 
 
 
         r e t u r n   S n a p s h o t ( p a t h = s n a p s h o t _ p a t h ,   t i m e s t a m p = t i m e s t a m p ,   p a c k a g e _ c o u n t = p a c k a g e _ c o u n t ) 
 
 
 
 
 
 d e f   l i s t _ s n a p s h o t s ( m a x _ a g e _ d a y s :   f l o a t   =   3 0 . 0 )   - >   L i s t [ S n a p s h o t ] : 
 
         " " " R e t u r n   a l l   s n a p s h o t   f i l e s   n e w e r   t h a n   ` m a x _ a g e _ d a y s ` ,   n e w e s t   f i r s t . " " " 
 
         s n a p s h o t s _ d i r   =   _ e n s u r e _ s n a p s h o t s _ d i r ( ) 
 
         o u t :   L i s t [ S n a p s h o t ]   =   [ ] 
 
         c u t o f f   =   t i m e . t i m e ( )   -   m a x _ a g e _ d a y s   *   8 6 4 0 0 . 0 
 
         f o r   p a t h   i n   s n a p s h o t s _ d i r . g l o b ( " * . t x t " ) : 
 
                 t r y : 
 
                         s t a t   =   p a t h . s t a t ( ) 
 
                 e x c e p t   O S E r r o r : 
 
                         c o n t i n u e 
 
                 i f   s t a t . s t _ m t i m e   <   c u t o f f : 
 
                         c o n t i n u e 
 
                 l i n e _ c o u n t   =   0 
 
                 t r y : 
 
                         w i t h   p a t h . o p e n ( " r " ,   e n c o d i n g = " u t f - 8 " )   a s   f : 
 
                                 f o r   l i n e   i n   f : 
 
                                         i f   l i n e . s t r i p ( )   a n d   n o t   l i n e . s t a r t s w i t h ( " # " ) : 
 
                                                 l i n e _ c o u n t   + =   1 
 
                 e x c e p t   O S E r r o r : 
 
                         p a s s 
 
                 o u t . a p p e n d ( S n a p s h o t ( p a t h = p a t h ,   t i m e s t a m p = s t a t . s t _ m t i m e ,   p a c k a g e _ c o u n t = l i n e _ c o u n t ) ) 
 
         r e t u r n   s o r t e d ( o u t ,   k e y = l a m b d a   s :   s . t i m e s t a m p ,   r e v e r s e = T r u e ) 
 
 
 
 
 
 d e f   c l e a n u p _ o l d _ s n a p s h o t s ( m a x _ a g e _ d a y s :   f l o a t   =   7 . 0 )   - >   i n t : 
 
         " " " D e l e t e   s n a p s h o t s   o l d e r   t h a n   ` m a x _ a g e _ d a y s ` .   R e t u r n s   c o u n t   d e l e t e d . " " " 
 
         s n a p s h o t s _ d i r   =   _ e n s u r e _ s n a p s h o t s _ d i r ( ) 
 
         c u t o f f   =   t i m e . t i m e ( )   -   m a x _ a g e _ d a y s   *   8 6 4 0 0 . 0 
 
         d e l e t e d   =   0 
 
         f o r   p a t h   i n   s n a p s h o t s _ d i r . g l o b ( " * . t x t " ) : 
 
                 t r y : 
 
                         i f   p a t h . s t a t ( ) . s t _ m t i m e   <   c u t o f f : 
 
                                 p a t h . u n l i n k ( ) 
 
                                 d e l e t e d   + =   1 
 
                 e x c e p t   O S E r r o r : 
 
                         c o n t i n u e 
 
         r e t u r n   d e l e t e d 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e m o v e / t e s t _ s e l e c t o r . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " F i n d   t e s t   f i l e s   t h a t   i m p o r t   a   g i v e n   p a c k a g e       f o r   t a r g e t e d   r e - r u n   a f t e r   r e m o v a l . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t ,   S e t 
 
 
 
 f r o m   k r a i m i n d . p a r s e r . a s t _ s c a n n e r   i m p o r t   S K I P _ D I R S ,   e x t r a c t _ i m p o r t s _ f r o m _ f i l e 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   I M P O R T _ T O _ P A C K A G E ,   n o r m a l i z e _ p a c k a g e _ n a m e 
 
 
 
 
 
 d e f   _ i s _ t e s t _ f i l e ( p a t h :   P a t h )   - >   b o o l : 
 
         " " " H e u r i s t i c :   t e s t s   l i v e   i n   t e s t s /   o r   t e s t _ /   d i r e c t o r i e s   o r   m a t c h   t e s t _ * . p y   /   * _ t e s t . p y . " " " 
 
         n a m e   =   p a t h . n a m e 
 
         i f   n a m e . s t a r t s w i t h ( " t e s t _ " )   o r   n a m e . e n d s w i t h ( " _ t e s t . p y " ) : 
 
                 r e t u r n   T r u e 
 
         p a r t s   =   { p . l o w e r ( )   f o r   p   i n   p a t h . p a r t s } 
 
         r e t u r n   " t e s t s "   i n   p a r t s   o r   " t e s t "   i n   p a r t s 
 
 
 
 
 
 d e f   _ i m p o r t _ n a m e s _ f o r _ p a c k a g e ( p a c k a g e :   s t r )   - >   S e t [ s t r ] : 
 
         " " " R e t u r n   a l l   i m p o r t   n a m e s   t h a t   m a p   t o   t h i s   p a c k a g e   ( r e v e r s e   o f   I M P O R T _ T O _ P A C K A G E ) . " " " 
 
         p k g   =   n o r m a l i z e _ p a c k a g e _ n a m e ( p a c k a g e ) 
 
         n a m e s :   S e t [ s t r ]   =   { p k g ,   p k g . r e p l a c e ( " - " ,   " _ " ) } 
 
         f o r   i m p _ n a m e ,   c a n o n i c a l   i n   I M P O R T _ T O _ P A C K A G E . i t e m s ( ) : 
 
                 i f   n o r m a l i z e _ p a c k a g e _ n a m e ( c a n o n i c a l )   = =   p k g : 
 
                         n a m e s . a d d ( i m p _ n a m e ) 
 
         r e t u r n   n a m e s 
 
 
 
 
 
 d e f   f i n d _ t e s t s _ i m p o r t i n g ( p r o j e c t _ p a t h :   P a t h ,   p a c k a g e :   s t r )   - >   L i s t [ P a t h ] : 
 
         " " " R e t u r n   a l l   t e s t   f i l e s   t h a t   i m p o r t   ` p a c k a g e `   ( d i r e c t l y   o r   v i a   m a p p e d   n a m e ) . 
 
 
 
         A r g s : 
 
                 p r o j e c t _ p a t h :   P r o j e c t   r o o t . 
 
                 p a c k a g e :   P a c k a g e   n a m e   t o   s e a r c h   f o r . 
 
 
 
         R e t u r n s : 
 
                 S o r t e d   l i s t   o f   t e s t   f i l e   p a t h s . 
 
         " " " 
 
         c a n d i d a t e _ n a m e s   =   _ i m p o r t _ n a m e s _ f o r _ p a c k a g e ( p a c k a g e ) 
 
         h i t s :   L i s t [ P a t h ]   =   [ ] 
 
 
 
         f o r   p y _ f i l e   i n   p r o j e c t _ p a t h . r g l o b ( " * . p y " ) : 
 
                 i f   a n y ( p a r t   i n   S K I P _ D I R S   f o r   p a r t   i n   p y _ f i l e . p a r t s ) : 
 
                         c o n t i n u e 
 
                 i f   n o t   _ i s _ t e s t _ f i l e ( p y _ f i l e ) : 
 
                         c o n t i n u e 
 
                 i m p o r t s   =   e x t r a c t _ i m p o r t s _ f r o m _ f i l e ( p y _ f i l e ) 
 
                 i f   i m p o r t s   &   c a n d i d a t e _ n a m e s : 
 
                         h i t s . a p p e n d ( p y _ f i l e ) 
 
 
 
         r e t u r n   s o r t e d ( h i t s ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e m o v e / t r a n s i t i v e . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " F i n d   t r a n s i t i v e   d e p s   t h a t   b e c o m e   o r p h a n e d   w h e n   a   p a c k a g e   i s   r e m o v e d . 
 
 
 
 U s e s   ` i m p o r t l i b . m e t a d a t a `   t o   w a l k   t h e   i n s t a l l e d   d e p e n d e n c y   g r a p h .   W h e n   p a c k a g e   X 
 
 i s   r e m o v e d ,   a n y   d e p e n d e n c y   Y   i s   a n   o r p h a n   i f   n o   * o t h e r *   i n s t a l l e d   p a c k a g e 
 
 r e q u i r e s   Y   ( a n d   Y   i s   n o t   a   d e c l a r e d   d i r e c t   d e p e n d e n c y ) . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   L i s t ,   S e t 
 
 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   n o r m a l i z e _ p a c k a g e _ n a m e 
 
 
 
 
 
 d e f   _ i n s t a l l e d _ d i s t r i b u t i o n s ( )   - >   D i c t [ s t r ,   L i s t [ s t r ] ] : 
 
         " " " R e t u r n   m a p p i n g   i n s t a l l e d - p a c k a g e       l i s t   o f   i t s   d i r e c t   r e q u i r e m e n t s   ( n o r m a l i z e d ) . " " " 
 
         t r y : 
 
                 f r o m   i m p o r t l i b . m e t a d a t a   i m p o r t   d i s t r i b u t i o n s 
 
         e x c e p t   I m p o r t E r r o r : 
 
                 r e t u r n   { } 
 
 
 
         o u t :   D i c t [ s t r ,   L i s t [ s t r ] ]   =   { } 
 
         f o r   d i s t   i n   d i s t r i b u t i o n s ( ) : 
 
                 t r y : 
 
                         n a m e   =   n o r m a l i z e _ p a c k a g e _ n a m e ( d i s t . m e t a d a t a [ " N a m e " ] ) 
 
                 e x c e p t   ( K e y E r r o r ,   A t t r i b u t e E r r o r ,   T y p e E r r o r ) : 
 
                         c o n t i n u e 
 
                 r e q u i r e s   =   d i s t . r e q u i r e s   o r   [ ] 
 
                 d e p s :   L i s t [ s t r ]   =   [ ] 
 
                 f o r   r e q _ s t r   i n   r e q u i r e s : 
 
                         #   S t r i p   e x t r a s   m a r k e r s   a n d   v e r s i o n   s p e c i f i e r s 
 
                         #   E x a m p l e :   " c l i c k   ( > = 7 . 0 ) ;   p y t h o n _ v e r s i o n < ' 3 . 8 ' "       " c l i c k " 
 
                         h e a d   =   r e q _ s t r . s p l i t ( " ; " ) [ 0 ] . s t r i p ( ) 
 
                         h e a d   =   h e a d . s p l i t ( " [ " ) [ 0 ] . s t r i p ( ) 
 
                         f o r   s e p   i n   ( " = = " ,   " > = " ,   " < = " ,   " ~ = " ,   " ! = " ,   " > " ,   " < " ,   "   " ) : 
 
                                 i f   s e p   i n   h e a d : 
 
                                         h e a d   =   h e a d . s p l i t ( s e p ) [ 0 ] . s t r i p ( ) 
 
                                         b r e a k 
 
                         i f   h e a d : 
 
                                 d e p s . a p p e n d ( n o r m a l i z e _ p a c k a g e _ n a m e ( h e a d ) ) 
 
                 o u t [ n a m e ]   =   d e p s 
 
         r e t u r n   o u t 
 
 
 
 
 
 d e f   f i n d _ o r p h a n s ( 
 
         p a c k a g e :   s t r , 
 
         d e c l a r e d :   S e t [ s t r ] , 
 
         g r a p h :   D i c t [ s t r ,   L i s t [ s t r ] ]   |   N o n e   =   N o n e , 
 
 )   - >   L i s t [ s t r ] : 
 
         " " " F i n d   p a c k a g e s   t h a t   w o u l d   b e c o m e   o r p h a n s   i f   ` p a c k a g e `   i s   r e m o v e d . 
 
 
 
         A   p a c k a g e   Y   i s   a n   o r p h a n   i f : 
 
             1 .   I t   i s   a   t r a n s i t i v e   d e p e n d e n c y   o f   ` p a c k a g e `   ( d i r e c t l y   o r   r e c u r s i v e l y ) ,   A N D 
 
             2 .   I t   i s   n o t   a   d e c l a r e d   d i r e c t   d e p e n d e n c y ,   A N D 
 
             3 .   N o   o t h e r   i n s t a l l e d   p a c k a g e   ( e x c l u d i n g   ` p a c k a g e `   a n d   t h e   o r p h a n   c h a i n )   r e q u i r e s   i t . 
 
 
 
         A r g s : 
 
                 p a c k a g e :   P a c k a g e   b e i n g   r e m o v e d . 
 
                 d e c l a r e d :   S e t   o f   d e c l a r e d   d i r e c t   d e p e n d e n c i e s   ( n o r m a l i z e d ) . 
 
                 g r a p h :   O p t i o n a l   p r e - b u i l t   i n s t a l l   g r a p h   ( f o r   t e s t i n g ) .   D e f a u l t s   t o   l i v e   ` i m p o r t l i b . m e t a d a t a ` . 
 
 
 
         R e t u r n s : 
 
                 S o r t e d   l i s t   o f   o r p h a n e d   p a c k a g e   n a m e s . 
 
         " " " 
 
         i f   g r a p h   i s   N o n e : 
 
                 g r a p h   =   _ i n s t a l l e d _ d i s t r i b u t i o n s ( ) 
 
 
 
         p a c k a g e   =   n o r m a l i z e _ p a c k a g e _ n a m e ( p a c k a g e ) 
 
         d e c l a r e d   =   { n o r m a l i z e _ p a c k a g e _ n a m e ( d )   f o r   d   i n   d e c l a r e d } 
 
 
 
         i f   p a c k a g e   n o t   i n   g r a p h : 
 
                 r e t u r n   [ ] 
 
 
 
         #   W a l k   t r a n s i t i v e   d e p s   s t a r t i n g   f r o m   ` p a c k a g e ` 
 
         t r a n s i t i v e :   S e t [ s t r ]   =   s e t ( ) 
 
         s t a c k   =   [ p a c k a g e ] 
 
         v i s i t e d :   S e t [ s t r ]   =   s e t ( ) 
 
         w h i l e   s t a c k : 
 
                 c u r   =   s t a c k . p o p ( ) 
 
                 i f   c u r   i n   v i s i t e d : 
 
                         c o n t i n u e 
 
                 v i s i t e d . a d d ( c u r ) 
 
                 f o r   d e p   i n   g r a p h . g e t ( c u r ,   [ ] ) : 
 
                         i f   d e p   n o t   i n   t r a n s i t i v e   a n d   d e p   ! =   p a c k a g e : 
 
                                 t r a n s i t i v e . a d d ( d e p ) 
 
                                 s t a c k . a p p e n d ( d e p ) 
 
 
 
         #   F o r   e a c h   c a n d i d a t e ,   c h e c k   i f   a n y   o t h e r   i n s t a l l e d   p a c k a g e   s t i l l   r e q u i r e s   i t 
 
         o r p h a n s :   L i s t [ s t r ]   =   [ ] 
 
         f o r   c a n d i d a t e   i n   t r a n s i t i v e : 
 
                 i f   c a n d i d a t e   i n   d e c l a r e d   a n d   c a n d i d a t e   ! =   p a c k a g e : 
 
                         #   D e c l a r e d   i n d e p e n d e n t l y       k e e p   i t 
 
                         c o n t i n u e 
 
                 s t i l l _ n e e d e d   =   F a l s e 
 
                 f o r   o w n e r ,   d e p s   i n   g r a p h . i t e m s ( ) : 
 
                         i f   o w n e r   = =   p a c k a g e : 
 
                                 c o n t i n u e 
 
                         i f   o w n e r   i n   t r a n s i t i v e   a n d   o w n e r   n o t   i n   d e c l a r e d : 
 
                                 #   O w n e r   i s   i t s e l f   a   s o o n - t o - b e - o r p h a n       d o n ' t   c o u n t   i t s   r e q u i r e m e n t s 
 
                                 c o n t i n u e 
 
                         i f   c a n d i d a t e   i n   d e p s : 
 
                                 s t i l l _ n e e d e d   =   T r u e 
 
                                 b r e a k 
 
                 i f   n o t   s t i l l _ n e e d e d : 
 
                         o r p h a n s . a p p e n d ( c a n d i d a t e ) 
 
 
 
         r e t u r n   s o r t e d ( o r p h a n s ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / r e p l . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   o s 
 
 i m p o r t   s h l e x 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   L i s t 
 
 
 
 f r o m   p r o m p t _ t o o l k i t   i m p o r t   P r o m p t S e s s i o n 
 
 f r o m   p r o m p t _ t o o l k i t . a u t o _ s u g g e s t   i m p o r t   A u t o S u g g e s t F r o m H i s t o r y 
 
 f r o m   p r o m p t _ t o o l k i t . c o m p l e t i o n   i m p o r t   W o r d C o m p l e t e r 
 
 f r o m   p r o m p t _ t o o l k i t . f o r m a t t e d _ t e x t   i m p o r t   H T M L 
 
 f r o m   p r o m p t _ t o o l k i t . h i s t o r y   i m p o r t   F i l e H i s t o r y 
 
 f r o m   p r o m p t _ t o o l k i t . s t y l e s   i m p o r t   S t y l e 
 
 f r o m   r i c h . c o n s o l e   i m p o r t   C o n s o l e 
 
 
 
 f r o m   k r a i m i n d . u t i l s . f o r m a t t i n g   i m p o r t   b a n n e r ,   p r i n t _ a n i m a t e d _ b a n n e r 
 
 
 
 c o n s o l e   =   C o n s o l e ( ) 
 
 
 
 #   B a s i c   s t y l e   f o r   t h e   p r o m p t   ( s i m i l a r   t o   C l a u d e ' s   s l e e k   U I ) 
 
 s t y l e   =   S t y l e . f r o m _ d i c t ( { 
 
         " p r o m p t " :   " a n s i c y a n   b o l d " , 
 
         " a r r o w " :   " a n s i g r e e n   b o l d " , 
 
         " b o t t o m - t o o l b a r " :   " b g : # 2 2 2 2 2 2   # c c c c c c " , 
 
 } ) 
 
 
 
 #   P r e d e f i n e d   c o m m a n d s   f o r   a u t o c o m p l e t i o n 
 
 C O M M A N D S   =   [ 
 
         " h e l l o " , 
 
         " a n a l y z e " , 
 
         " e x p l a i n " , 
 
         " d o c t o r " , 
 
         " c o m p a r e " , 
 
         " r e m o v e " , 
 
         " c a c h e   i n f o " , 
 
         " c a c h e   c l e a r " , 
 
         " w i z a r d " , 
 
         " a r c h i t e c t " , 
 
         " e x i t " , 
 
         " q u i t " , 
 
         " h e l p " 
 
 ] 
 
 
 
 d e f   b o t t o m _ t o o l b a r ( ) : 
 
         r e t u r n   H T M L ( '   < b > [ K r a i m i n d   S h e l l ] < / b >   |   P r e s s   < b > C t r l + D < / b >   t o   e x i t   |   T y p e   < b > h e l p < / b >   f o r   c o m m a n d s . ' ) 
 
 
 
 d e f   s t a r t _ i n t e r a c t i v e _ r e p l ( )   - >   N o n e : 
 
         " " " 
 
         S t a r t   a   r i c h   i n t e r a c t i v e   R E P L   s i m i l a r   t o   C l a u d e   C o d e   C L I . 
 
         " " " 
 
         f r o m   k r a i m i n d . c l i   i m p o r t   a p p 
 
         f r o m   c l i c k . e x c e p t i o n s   i m p o r t   E x i t 
 
 
 
         p r i n t _ a n i m a t e d _ b a n n e r ( c o n s o l e ) 
 
         c o n s o l e . p r i n t ( " [ g r e y 5 0 ] E x p e r i e n c e   A I - n a t i v e   d e p e n d e n c y   i n t e l l i g e n c e   i n t e r a c t i v e l y . [ / g r e y 5 0 ] \ n " ) 
 
         
 
         #   C o n f i g u r e   h i s t o r y   f i l e 
 
         h i s t o r y _ f i l e   =   P a t h ( o s . p a t h . e x p a n d u s e r ( " ~ " ) )   /   " . k r a i m i n d _ h i s t o r y " 
 
         
 
         c o m p l e t e r   =   W o r d C o m p l e t e r ( C O M M A N D S ,   i g n o r e _ c a s e = T r u e ) 
 
         s e s s i o n   =   P r o m p t S e s s i o n ( 
 
                 h i s t o r y = F i l e H i s t o r y ( s t r ( h i s t o r y _ f i l e ) ) , 
 
                 a u t o _ s u g g e s t = A u t o S u g g e s t F r o m H i s t o r y ( ) , 
 
                 c o m p l e t e r = c o m p l e t e r , 
 
                 s t y l e = s t y l e , 
 
                 b o t t o m _ t o o l b a r = b o t t o m _ t o o l b a r 
 
         ) 
 
 
 
         w h i l e   T r u e : 
 
                 t r y : 
 
                         #   W e   u s e   p r o m p t _ t o o l k i t   f o r   t h e   i n p u t   l i n e 
 
                         t e x t   =   s e s s i o n . p r o m p t ( [ 
 
                                 ( " c l a s s : p r o m p t " ,   " k r a i m i n d   " ) , 
 
                                 ( " c l a s s : a r r o w " ,   " >   " ) , 
 
                         ] ) 
 
                         t e x t   =   t e x t . s t r i p ( ) 
 
                         
 
                         i f   n o t   t e x t : 
 
                                 c o n t i n u e 
 
                                 
 
                         i f   t e x t . l o w e r ( )   i n   ( " e x i t " ,   " q u i t " ,   " q " ) : 
 
                                 c o n s o l e . p r i n t ( " [ g r e y 5 0 ] G o o d b y e ! [ / g r e y 5 0 ] " ) 
 
                                 b r e a k 
 
                                 
 
                         i f   t e x t . l o w e r ( )   i n   ( " h e l p " ,   " ? " ) : 
 
                                 t r y : 
 
                                         a p p ( [ " - - h e l p " ] ,   s t a n d a l o n e _ m o d e = F a l s e ) 
 
                                 e x c e p t   E x i t : 
 
                                         p a s s 
 
                                 c o n t i n u e 
 
 
 
                         a r g s   =   s h l e x . s p l i t ( t e x t ) 
 
                         
 
                         t r y : 
 
                                 #   C a p t u r e   s t a n d a r d   t y p e r   e x i t s   g r a c e f u l l y   i n   t h e   l o o p 
 
                                 a p p ( a r g s ,   s t a n d a l o n e _ m o d e = F a l s e ) 
 
                         e x c e p t   E x i t   a s   e : 
 
                                 p a s s 
 
                         e x c e p t   S y s t e m E x i t   a s   e : 
 
                                 p a s s 
 
                         e x c e p t   E x c e p t i o n   a s   e : 
 
                                 c o n s o l e . p r i n t ( f " [ b o l d   r e d ] E r r o r : [ / b o l d   r e d ]   { e } " ) 
 
 
 
                 e x c e p t   K e y b o a r d I n t e r r u p t : 
 
                         c o n t i n u e 
 
                 e x c e p t   E O F E r r o r : 
 
                         c o n s o l e . p r i n t ( " [ g r e y 5 0 ] G o o d b y e ! [ / g r e y 5 0 ] " ) 
 
                         b r e a k 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / s h a r e . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " B u n d l e   a   p r o j e c t   i n t o   a   s i n g l e   m a r k d o w n   b l o b   a n d   s h a r e   i t   v i a   t h e   K r a i m i n d   p r o x y . 
 
 
 
 T h e   o u t p u t   U R L   c a n   b e   p a s t e d   i n t o   a n y   b r o w s i n g - c a p a b l e   w e b   A I   ( C l a u d e . a i ,   C h a t G P T 
 
 P l u s ,   G e m i n i )       t h e   A I   f e t c h e s   i t   a n d   r e a d s   t h e   c o d e b a s e   t o   a n s w e r   q u e s t i o n s . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   f n m a t c h 
 
 i m p o r t   o s 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e d e l t a ,   t i m e z o n e 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   I t e r a b l e ,   L i s t ,   O p t i o n a l ,   T u p l e 
 
 
 
 t r y : 
 
         i m p o r t   p a t h s p e c   a s   _ p a t h s p e c 
 
         _ H A S _ P A T H S P E C   =   T r u e 
 
 e x c e p t   I m p o r t E r r o r : 
 
         _ p a t h s p e c   =   N o n e     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         _ H A S _ P A T H S P E C   =   F a l s e 
 
 
 
 i m p o r t   h t t p x 
 
 
 
 f r o m   k r a i m i n d . p a r s e r . a s t _ s c a n n e r   i m p o r t   S K I P _ D I R S 
 
 
 
 #   F i l e   e x t e n s i o n s   w e   t r e a t   a s   r e a d a b l e   s o u r c e / c o n f i g   t e x t . 
 
 I N C L U D E _ E X T S   =   { 
 
         " . p y " ,   " . j s " ,   " . t s " ,   " . t s x " ,   " . j s x " ,   " . v u e " ,   " . s v e l t e " , 
 
         " . m d " ,   " . r s t " ,   " . t x t " , 
 
         " . t o m l " ,   " . y m l " ,   " . y a m l " ,   " . j s o n " ,   " . c f g " ,   " . i n i " , 
 
         " . h t m l " ,   " . c s s " ,   " . s c s s " , 
 
         " . s h " ,   " . p s 1 " , 
 
 } 
 
 
 
 #   F i l e s   w i t h o u t   a n   e x t e n s i o n   w e   s t i l l   w a n t   t o   i n c l u d e . 
 
 I N C L U D E _ N A M E S   =   { 
 
         " D o c k e r f i l e " ,   " M a k e f i l e " ,   " P r o c f i l e " , 
 
         " . g i t i g n o r e " ,   " . d o c k e r i g n o r e " ,   " . e n v . e x a m p l e " , 
 
 } 
 
 
 
 #   L o c k   f i l e s       e x c l u d e d   u n l e s s   - - f u l l . 
 
 L O C K F I L E S   =   { 
 
         " p o e t r y . l o c k " ,   " p a c k a g e - l o c k . j s o n " ,   " y a r n . l o c k " , 
 
         " p n p m - l o c k . y a m l " ,   " u v . l o c k " ,   " P i p f i l e . l o c k " ,   " c o m p o s e r . l o c k " , 
 
 } 
 
 
 
 #   H a r d - b l o c k   p a t t e r n s       n e v e r   s h a r e   t h e s e ,   e v e n   i n   - - f u l l . 
 
 S E C R E T _ P A T T E R N S   =   [ 
 
         " . e n v " ,   " . e n v . l o c a l " ,   " . e n v . p r o d u c t i o n " ,   " . e n v . d e v e l o p m e n t " , 
 
         " * . k e y " ,   " * . p e m " ,   " * . p 1 2 " ,   " * . c r t " ,   " * . p f x " , 
 
         " i d _ r s a " ,   " i d _ r s a . * " ,   " i d _ e d 2 5 5 1 9 " ,   " i d _ e d 2 5 5 1 9 . * " , 
 
         " * c r e d e n t i a l * " ,   " * s e c r e t * " ,   " * p a s s w o r d * " , 
 
 ] 
 
 
 
 #   E n t r y - p o i n t   f i l e n a m e s   p r i o r i t i z e d   i n   s m a r t   m o d e . 
 
 E N T R Y _ P O I N T S   =   { 
 
         " m a i n . p y " ,   " a p p . p y " ,   " c l i . p y " ,   " _ _ m a i n _ _ . p y " , 
 
         " i n d e x . t s " ,   " i n d e x . j s " ,   " m a i n . t s " ,   " m a i n . j s " , 
 
         " s e r v e r . t s " ,   " s e r v e r . j s " , 
 
 } 
 
 
 
 M A X _ F I L E _ S I Z E   =   1 0 0   *   1 0 2 4                     #   f i l e s   a b o v e   t h i s   a r e   t r u n c a t e d ,   n o t   s k i p p e d 
 
 F I L E _ T R U N C A T E _ A T   =   5 0   *   1 0 2 4                 #   t r u n c a t e d   f i l e s   s h o w   f i r s t   5 0   K B   +   m a r k e r 
 
 S M A R T _ B U N D L E _ C A P   =   3 0 0   *   1 0 2 4               #   3 0 0   K B   t o t a l   f o r   s m a r t   m o d e 
 
 F U L L _ W A R N _ T H R E S H O L D   =   5 0 0   *   1 0 2 4         #   w a r n   u s e r   a b o v e   t h i s   i n   f u l l   m o d e 
 
 R E C E N C Y _ D A Y S   =   7                                         #   f i l e s   m o d i f i e d   w i t h i n   t h i s   w i n d o w   g e t   a   p r i o r i t y   b o o s t 
 
 
 
 
 
 c l a s s   S h a r e U p l o a d E r r o r ( R u n t i m e E r r o r ) : 
 
         " " " R a i s e d   w h e n   t h e   b u n d l e   c o u l d   n o t   b e   u p l o a d e d   t o   t h e   s h a r e   A P I . " " " 
 
 
 
 
 
 d e f   b u i l d _ a i _ h a n d s h a k e ( 
 
         p r o j e c t _ n a m e :   s t r ,   f i l e _ c o u n t :   i n t ,   b r a n c h :   O p t i o n a l [ s t r ]   =   N o n e 
 
 )   - >   s t r : 
 
         " " " A I - d i r e c t e d   p r e a m b l e   t h a t   m a k e s   a   b r o w s e r   A I   a c k n o w l e d g e   t h e   c o n n e c t i o n . 
 
 
 
         R e t u r n e d   m a r k d o w n   i s   m e a n t   t o   s i t   a t   t h e   v e r y   t o p   o f   w h a t e v e r   t h e   m o d e l   r e a d s 
 
         ( t h e   s h a r e   b u n d l e ,   o r   t h e   h a n d o f f   p r o m p t ) .   I t   i n s t r u c t s   t h e   A I   t o   c o n f i r m   w i t h 
 
         a   ' C o n n e c t e d   t o   k r a i m i n d '   l i n e ,   s u m m a r i z e   t h e   p r o j e c t ,   a n d   t r e a t   t h e   c o d e b a s e 
 
         a s   s h a r e d   c o n t e x t   f o r   t h e   r e s t   o f   t h e   c o n v e r s a t i o n .   T h e   i n t e r p o l a t e d   n a m e   / 
 
         f i l e   c o u n t   /   b r a n c h   m a k e   t h e   c o n f i r m a t i o n   s p e c i f i c       t h e   A I   c a n   o n l y   p r o d u c e 
 
         i t   i f   i t   a c t u a l l y   r e a d   t h e   c o d e . 
 
         " " " 
 
         b r a n c h _ c l a u s e   =   f "   ,%V%  b r a n c h   { b r a n c h } "   i f   b r a n c h   e l s e   " " 
 
         c o n f i r m   =   f "     C o n n e c t e d   t o   k r a i m i n d       { p r o j e c t _ n a m e }   ,%V%  { f i l e _ c o u n t }   f i l e s { b r a n c h _ c l a u s e } " 
 
         r e t u r n   ( 
 
                 " < ! - -   K R A I M I N D   H A N D O F F   - - > \ n " 
 
                 " #   a"    K r a i m i n d   h a n d o f f       i n s t r u c t i o n s   f o r   t h e   A I   ( r e a d   t h i s   f i r s t ) \ n \ n " 
 
                 f " Y o u   h a v e   b e e n   c o n n e c t e d   t o   a   l i v e   c o d e b a s e   t h r o u g h   * * K r a i m i n d * * ,   a   d e v e l o p e r   " 
 
                 f " h a n d - o f f   t o o l .   T h e   c o m p l e t e   s o u r c e   o f   t h e   p r o j e c t   * * ` { p r o j e c t _ n a m e } ` * *   " 
 
                 f " ( { f i l e _ c o u n t }   f i l e s )   f o l l o w s   b e l o w . \ n \ n " 
 
                 " * * F i r s t ,   c o n f i r m   t h e   c o n n e c t i o n . * *   B e g i n   y o u r   v e r y   f i r s t   r e p l y   w i t h   e x a c t l y   t h i s   l i n e : \ n \ n " 
 
                 f " >   { c o n f i r m } \ n \ n " 
 
                 " T h e n   a d d   a   o n e - s e n t e n c e   s u m m a r y   o f   w h a t   t h i s   p r o j e c t   d o e s ,   a n d   a s k   t h e   d e v e l o p e r   " 
 
                 " w h a t   t h e y ' d   l i k e   t o   w o r k   o n .   F o r   t h e   r e s t   o f   t h e   c o n v e r s a t i o n ,   t r e a t   t h e   c o d e   b e l o w   " 
 
                 " a s   o u r   s h a r e d   w o r k i n g   c o n t e x t       a n s w e r   f o l l o w - u p   q u e s t i o n s   d i r e c t l y   f r o m   t h e s e   f i l e s   " 
 
                 " w i t h o u t   a s k i n g   m e   t o   p a s t e   t h e m   a g a i n . \ n \ n " 
 
                 " - - - \ n " 
 
         ) 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   E x c l u d e d F i l e : 
 
         r e l :   s t r 
 
         s i z e _ k b :   i n t 
 
         r e a s o n :   s t r     #   " c a p "   |   " s i z e _ l i m i t " 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   S h a r e d B u n d l e : 
 
         c o n t e n t :   s t r 
 
         f i l e _ c o u n t :   i n t 
 
         t o t a l _ b y t e s :   i n t 
 
         e x c l u d e d _ f i l e s :   L i s t [ " E x c l u d e d F i l e " ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   S h a r e R e s u l t : 
 
         u r l :   s t r 
 
         e x p i r e s _ a t :   O p t i o n a l [ s t r ] 
 
 
 
 
 
 d e f   _ i s _ s e c r e t ( n a m e :   s t r )   - >   b o o l : 
 
         i f   n a m e   = =   " . e n v . e x a m p l e " : 
 
                 r e t u r n   F a l s e 
 
         l o w e r   =   n a m e . l o w e r ( ) 
 
         r e t u r n   a n y ( f n m a t c h . f n m a t c h c a s e ( l o w e r ,   p a t . l o w e r ( ) )   f o r   p a t   i n   S E C R E T _ P A T T E R N S ) 
 
 
 
 
 
 d e f   _ s h o u l d _ i n c l u d e ( p a t h :   P a t h ,   * ,   f u l l :   b o o l )   - >   b o o l : 
 
         n a m e   =   p a t h . n a m e 
 
         i f   _ i s _ s e c r e t ( n a m e ) : 
 
                 r e t u r n   F a l s e 
 
         i f   n a m e   i n   L O C K F I L E S : 
 
                 r e t u r n   f u l l 
 
         i f   n a m e   i n   I N C L U D E _ N A M E S : 
 
                 r e t u r n   T r u e 
 
         r e t u r n   p a t h . s u f f i x . l o w e r ( )   i n   I N C L U D E _ E X T S 
 
 
 
 
 
 d e f   _ r e a d _ k r a i m i n d i g n o r e ( r o o t :   P a t h )   - >   L i s t [ s t r ] : 
 
         f   =   r o o t   /   " . k r a i m i n d i g n o r e " 
 
         i f   n o t   f . e x i s t s ( ) : 
 
                 r e t u r n   [ ] 
 
         p a t t e r n s :   L i s t [ s t r ]   =   [ ] 
 
         f o r   l i n e   i n   f . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) . s p l i t l i n e s ( ) : 
 
                 l i n e   =   l i n e . s t r i p ( ) 
 
                 i f   l i n e   a n d   n o t   l i n e . s t a r t s w i t h ( " # " ) : 
 
                         p a t t e r n s . a p p e n d ( l i n e ) 
 
         r e t u r n   p a t t e r n s 
 
 
 
 
 
 d e f   _ l o a d _ g i t i g n o r e _ s p e c ( r o o t :   P a t h )   - >   O p t i o n a l [ o b j e c t ] : 
 
         i f   n o t   _ H A S _ P A T H S P E C : 
 
                 r e t u r n   N o n e 
 
         g i t i g n o r e   =   r o o t   /   " . g i t i g n o r e " 
 
         i f   n o t   g i t i g n o r e . e x i s t s ( ) : 
 
                 r e t u r n   N o n e 
 
         p a t t e r n s   =   [ 
 
                 l n . s t r i p ( ) 
 
                 f o r   l n   i n   g i t i g n o r e . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ,   e r r o r s = " i g n o r e " ) . s p l i t l i n e s ( ) 
 
                 i f   l n . s t r i p ( )   a n d   n o t   l n . s t r i p ( ) . s t a r t s w i t h ( " # " ) 
 
         ] 
 
         r e t u r n   _ p a t h s p e c . P a t h S p e c . f r o m _ l i n e s ( " g i t i g n o r e " ,   p a t t e r n s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
 
 
 
 
 d e f   _ r e a d _ f i l e _ w i t h _ t r u n c a t i o n ( f p a t h :   P a t h )   - >   T u p l e [ s t r ,   b o o l ] : 
 
         " " " R e a d   a   f i l e ,   t r u n c a t i n g   t o   F I L E _ T R U N C A T E _ A T   b y t e s   i f   i t   e x c e e d s   M A X _ F I L E _ S I Z E . " " " 
 
         t r y : 
 
                 r a w   =   f p a t h . r e a d _ b y t e s ( ) 
 
         e x c e p t   O S E r r o r : 
 
                 r e t u r n   " " ,   F a l s e 
 
         t o t a l   =   l e n ( r a w ) 
 
         i f   t o t a l   >   M A X _ F I L E _ S I Z E : 
 
                 t e x t   =   r a w [ : F I L E _ T R U N C A T E _ A T ] . d e c o d e ( " u t f - 8 " ,   e r r o r s = " i g n o r e " ) 
 
                 m a r k e r   =   f " \ n \ n [ t r u n c a t e d       s h o w i n g   f i r s t   { F I L E _ T R U N C A T E _ A T   / /   1 0 2 4 }   K B   o f   { t o t a l   / /   1 0 2 4 }   K B   t o t a l ] " 
 
                 r e t u r n   t e x t   +   m a r k e r ,   T r u e 
 
         t r y : 
 
                 r e t u r n   r a w . d e c o d e ( " u t f - 8 " ) ,   F a l s e 
 
         e x c e p t   U n i c o d e D e c o d e E r r o r : 
 
                 r e t u r n   r a w . d e c o d e ( " u t f - 8 " ,   e r r o r s = " i g n o r e " ) ,   F a l s e 
 
 
 
 
 
 d e f   _ m a t c h e s _ i g n o r e ( r e l :   P a t h ,   p a t t e r n s :   I t e r a b l e [ s t r ] )   - >   b o o l : 
 
         r e l _ s t r   =   r e l . a s _ p o s i x ( ) 
 
         r e t u r n   a n y ( 
 
                 f n m a t c h . f n m a t c h c a s e ( r e l _ s t r ,   p a t )   o r   f n m a t c h . f n m a t c h c a s e ( r e l . n a m e ,   p a t ) 
 
                 f o r   p a t   i n   p a t t e r n s 
 
         ) 
 
 
 
 
 
 d e f   w a l k _ p r o j e c t ( 
 
         r o o t :   P a t h , 
 
         * , 
 
         f u l l :   b o o l   =   F a l s e , 
 
         s i n c e :   O p t i o n a l [ d a t e t i m e ]   =   N o n e , 
 
 )   - >   L i s t [ T u p l e [ P a t h ,   s t r ] ] : 
 
         " " " W a l k   ` r o o t ` ,   r e t u r n i n g   ( r e l a t i v e _ p a t h ,   c o n t e n t s )   f o r   e a c h   i n c l u d e d   f i l e . " " " 
 
         e x t r a _ i g n o r e   =   _ r e a d _ k r a i m i n d i g n o r e ( r o o t ) 
 
         g i t i g n o r e _ s p e c   =   _ l o a d _ g i t i g n o r e _ s p e c ( r o o t ) 
 
         r e s u l t s :   L i s t [ T u p l e [ P a t h ,   s t r ] ]   =   [ ] 
 
 
 
         k e e p _ h i d d e n   =   { " . g i t h u b " } 
 
 
 
         f o r   d i r p a t h ,   d i r n a m e s ,   f i l e n a m e s   i n   o s . w a l k ( r o o t ) : 
 
                 d i r n a m e s [ : ]   =   [ 
 
                         d   f o r   d   i n   d i r n a m e s 
 
                         i f   d   n o t   i n   S K I P _ D I R S   a n d   ( n o t   d . s t a r t s w i t h ( " . " )   o r   d   i n   k e e p _ h i d d e n ) 
 
                 ] 
 
 
 
                 f o r   f n a m e   i n   f i l e n a m e s : 
 
                         f p a t h   =   P a t h ( d i r p a t h )   /   f n a m e 
 
                         r e l   =   f p a t h . r e l a t i v e _ t o ( r o o t ) 
 
 
 
                         i f   _ m a t c h e s _ i g n o r e ( r e l ,   e x t r a _ i g n o r e ) : 
 
                                 c o n t i n u e 
 
                         i f   g i t i g n o r e _ s p e c   i s   n o t   N o n e   a n d   g i t i g n o r e _ s p e c . m a t c h _ f i l e ( r e l . a s _ p o s i x ( ) ) :     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
                                 c o n t i n u e 
 
                         i f   n o t   _ s h o u l d _ i n c l u d e ( f p a t h ,   f u l l = f u l l ) : 
 
                                 c o n t i n u e 
 
                         t r y : 
 
                                 s t a t   =   f p a t h . s t a t ( ) 
 
                         e x c e p t   O S E r r o r : 
 
                                 c o n t i n u e 
 
                         i f   s i n c e   i s   n o t   N o n e : 
 
                                 m t i m e   =   d a t e t i m e . f r o m t i m e s t a m p ( s t a t . s t _ m t i m e ,   t z = t i m e z o n e . u t c ) 
 
                                 i f   m t i m e   <   s i n c e : 
 
                                         c o n t i n u e 
 
                         t e x t ,   _ t r u n c a t e d   =   _ r e a d _ f i l e _ w i t h _ t r u n c a t i o n ( f p a t h ) 
 
                         i f   n o t   t e x t : 
 
                                 c o n t i n u e 
 
                         r e s u l t s . a p p e n d ( ( r e l ,   t e x t ) ) 
 
 
 
         r e s u l t s . s o r t ( k e y = l a m b d a   t :   t [ 0 ] . a s _ p o s i x ( ) ) 
 
         r e t u r n   r e s u l t s 
 
 
 
 
 
 d e f   _ p r i o r i t y ( r e l :   P a t h )   - >   i n t : 
 
         " " " L o w e r   =   h i g h e r   p r i o r i t y .   U s e d   f o r   s m a r t - m o d e   t r i m m i n g . " " " 
 
         n a m e   =   r e l . n a m e . l o w e r ( ) 
 
         p a r t s   =   r e l . p a r t s 
 
         i f   n a m e   i n   { " r e a d m e . m d " ,   " r e a d m e . r s t " ,   " r e a d m e . t x t " }   a n d   l e n ( p a r t s )   = =   1 : 
 
                 r e t u r n   0 
 
         i f   n a m e   i n   { " p y p r o j e c t . t o m l " ,   " p a c k a g e . j s o n " ,   " r e q u i r e m e n t s . t x t " ,   " g o . m o d " ,   " c a r g o . t o m l " }   a n d   l e n ( p a r t s )   = =   1 : 
 
                 r e t u r n   1 
 
         i f   n a m e   i n   E N T R Y _ P O I N T S : 
 
                 r e t u r n   2 
 
         i f   r e l . s u f f i x . l o w e r ( )   i n   { " . p y " ,   " . t s " ,   " . t s x " ,   " . j s " ,   " . j s x " } : 
 
                 r e t u r n   3 
 
         r e t u r n   4 
 
 
 
 
 
 d e f   _ p r i o r i t y _ w i t h _ r e c e n c y ( 
 
         r e l :   P a t h ,   r o o t :   P a t h ,   n o w :   d a t e t i m e ,   r e c e n c y _ d a y s :   i n t 
 
 )   - >   T u p l e [ f l o a t ,   s t r ] : 
 
         " " " R e t u r n   ( f l o a t _ p r i o r i t y ,   p o s i x _ n a m e )   s o r t   k e y . 
 
 
 
         F i l e s   m o d i f i e d   w i t h i n   r e c e n c y _ d a y s   g e t   t h e i r   b a s e   p r i o r i t y   r e d u c e d   b y   0 . 5 , 
 
         f l o a t i n g   t h e m   a h e a d   o f   s a m e - p r i o r i t y   s t a l e   f i l e s . 
 
         " " " 
 
         b a s e   =   f l o a t ( _ p r i o r i t y ( r e l ) ) 
 
         t r y : 
 
                 m t i m e   =   d a t e t i m e . f r o m t i m e s t a m p ( ( r o o t   /   r e l ) . s t a t ( ) . s t _ m t i m e ,   t z = t i m e z o n e . u t c ) 
 
                 i f   ( n o w   -   m t i m e )   < =   t i m e d e l t a ( d a y s = r e c e n c y _ d a y s ) : 
 
                         b a s e   - =   0 . 5 
 
         e x c e p t   O S E r r o r : 
 
                 p a s s 
 
         r e t u r n   ( b a s e ,   r e l . a s _ p o s i x ( ) ) 
 
 
 
 
 
 d e f   _ e x t _ t o _ l a n g ( s u f f i x :   s t r )   - >   s t r : 
 
         r e t u r n   { 
 
                 " . p y " :   " p y t h o n " ,   " . j s " :   " j a v a s c r i p t " ,   " . t s " :   " t y p e s c r i p t " , 
 
                 " . t s x " :   " t s x " ,   " . j s x " :   " j s x " ,   " . v u e " :   " v u e " ,   " . s v e l t e " :   " s v e l t e " , 
 
                 " . m d " :   " m a r k d o w n " ,   " . r s t " :   " r s t " , 
 
                 " . t o m l " :   " t o m l " ,   " . y m l " :   " y a m l " ,   " . y a m l " :   " y a m l " ,   " . j s o n " :   " j s o n " , 
 
                 " . h t m l " :   " h t m l " ,   " . c s s " :   " c s s " ,   " . s c s s " :   " s c s s " , 
 
                 " . s h " :   " b a s h " ,   " . p s 1 " :   " p o w e r s h e l l " , 
 
         } . g e t ( s u f f i x . l o w e r ( ) ,   " " ) 
 
 
 
 
 
 d e f   _ b u i l d _ t r e e ( f i l e s :   L i s t [ T u p l e [ P a t h ,   s t r ] ] )   - >   s t r : 
 
         l i n e s :   L i s t [ s t r ]   =   [ ] 
 
         p r e v _ p a r t s :   T u p l e [ s t r ,   . . . ]   =   ( ) 
 
         f o r   r e l ,   _   i n   f i l e s : 
 
                 p a r t s   =   r e l . p a r t s 
 
                 f o r   d e p t h ,   p a r t   i n   e n u m e r a t e ( p a r t s ) : 
 
                         i f   d e p t h   > =   l e n ( p r e v _ p a r t s )   o r   p r e v _ p a r t s [ d e p t h ]   ! =   p a r t : 
 
                                 l i n e s . a p p e n d ( "     "   *   d e p t h   +   ( " -   "   i f   d e p t h   <   l e n ( p a r t s )   -   1   e l s e   "     " )   +   p a r t ) 
 
                 p r e v _ p a r t s   =   p a r t s 
 
         r e t u r n   " \ n " . j o i n ( l i n e s ) 
 
 
 
 
 
 d e f   b u i l d _ b u n d l e ( 
 
         r o o t :   P a t h , 
 
         * , 
 
         f u l l :   b o o l   =   F a l s e , 
 
         s i n c e :   O p t i o n a l [ d a t e t i m e ]   =   N o n e , 
 
         r e c e n c y _ d a y s :   i n t   =   R E C E N C Y _ D A Y S , 
 
 )   - >   S h a r e d B u n d l e : 
 
         " " " W a l k   +   s e r i a l i z e   t h e   p r o j e c t   i n t o   a   s i n g l e   m a r k d o w n   d o c u m e n t . " " " 
 
         f i l e s   =   w a l k _ p r o j e c t ( r o o t ,   f u l l = f u l l ,   s i n c e = s i n c e ) 
 
 
 
         e x c l u d e d :   L i s t [ E x c l u d e d F i l e ]   =   [ ] 
 
 
 
         i f   n o t   f u l l : 
 
                 n o w   =   d a t e t i m e . n o w ( t i m e z o n e . u t c ) 
 
                 f i l e s . s o r t ( k e y = l a m b d a   t :   _ p r i o r i t y _ w i t h _ r e c e n c y ( t [ 0 ] ,   r o o t ,   n o w ,   r e c e n c y _ d a y s ) ) 
 
                 k e p t :   L i s t [ T u p l e [ P a t h ,   s t r ] ]   =   [ ] 
 
                 r u n n i n g   =   0 
 
                 f o r   r e l ,   t e x t   i n   f i l e s : 
 
                         c h u n k _ s i z e   =   l e n ( t e x t . e n c o d e ( " u t f - 8 " ) ) 
 
                         i f   r u n n i n g   +   c h u n k _ s i z e   < =   S M A R T _ B U N D L E _ C A P : 
 
                                 k e p t . a p p e n d ( ( r e l ,   t e x t ) ) 
 
                                 r u n n i n g   + =   c h u n k _ s i z e 
 
                         e l s e : 
 
                                 e x c l u d e d . a p p e n d ( E x c l u d e d F i l e ( 
 
                                         r e l = r e l . a s _ p o s i x ( ) , 
 
                                         s i z e _ k b = c h u n k _ s i z e   / /   1 0 2 4 , 
 
                                         r e a s o n = " c a p " , 
 
                                 ) ) 
 
                 f i l e s   =   s o r t e d ( k e p t ,   k e y = l a m b d a   t :   t [ 0 ] . a s _ p o s i x ( ) ) 
 
 
 
         p r o j e c t _ n a m e   =   r o o t . r e s o l v e ( ) . n a m e 
 
         t o t a l _ b y t e s   =   s u m ( l e n ( t . e n c o d e ( " u t f - 8 " ) )   f o r   _ ,   t   i n   f i l e s ) 
 
         t i m e s t a m p   =   d a t e t i m e . n o w ( t i m e z o n e . u t c ) . s t r f t i m e ( " % Y - % m - % d   % H : % M   U T C " ) 
 
 
 
         p a r t s :   L i s t [ s t r ]   =   [ ] 
 
         p a r t s . a p p e n d ( b u i l d _ a i _ h a n d s h a k e ( p r o j e c t _ n a m e ,   l e n ( f i l e s ) ) ) 
 
         p a r t s . a p p e n d ( f " #   K r a i m i n d   C o d e b a s e   S h a r e       { p r o j e c t _ n a m e } \ n " ) 
 
         p a r t s . a p p e n d ( 
 
                 f " G e n e r a t e d :   { t i m e s t a m p }           F i l e s :   { l e n ( f i l e s ) }           S i z e :   { t o t a l _ b y t e s   / /   1 0 2 4 }   K B \ n " 
 
         ) 
 
         p a r t s . a p p e n d ( " # #   F i l e   t r e e \ n " ) 
 
         p a r t s . a p p e n d ( " ` ` ` \ n "   +   _ b u i l d _ t r e e ( f i l e s )   +   " \ n ` ` ` \ n " ) 
 
         p a r t s . a p p e n d ( " # #   F i l e s \ n " ) 
 
         f o r   r e l ,   t e x t   i n   f i l e s : 
 
                 l a n g   =   _ e x t _ t o _ l a n g ( r e l . s u f f i x ) 
 
                 p a r t s . a p p e n d ( f " # # #   ` { r e l . a s _ p o s i x ( ) } ` \ n " ) 
 
                 p a r t s . a p p e n d ( f " ` ` ` { l a n g } \ n { t e x t . r s t r i p ( ) } \ n ` ` ` \ n " ) 
 
 
 
         c o n t e n t   =   " \ n " . j o i n ( p a r t s ) 
 
         r e t u r n   S h a r e d B u n d l e ( 
 
                 c o n t e n t = c o n t e n t , 
 
                 f i l e _ c o u n t = l e n ( f i l e s ) , 
 
                 t o t a l _ b y t e s = l e n ( c o n t e n t . e n c o d e ( " u t f - 8 " ) ) , 
 
                 e x c l u d e d _ f i l e s = e x c l u d e d , 
 
         ) 
 
 
 
 
 
 d e f   u p l o a d _ b u n d l e ( 
 
         c o n t e n t :   s t r , 
 
         * , 
 
         t t l _ h o u r s :   i n t   =   2 4 , 
 
         a p i _ u r l :   O p t i o n a l [ s t r ]   =   N o n e , 
 
         t i m e o u t :   f l o a t   =   3 0 . 0 , 
 
 )   - >   S h a r e R e s u l t : 
 
         " " " P O S T   t h e   b u n d l e   t o   t h e   K r a i m i n d   s h a r e   e n d p o i n t ,   r e t u r n   t h e   p u b l i c   U R L . " " " 
 
         #   H o s t   i s   f u l l y   c o n f i g u r a b l e   v i a   K R A I M I N D _ A P I _ U R L .   T h e   r e t u r n e d   s h a r e   l i n k   u s e s 
 
         #   w h a t e v e r   h o s t   t h i s   P O S T   h i t s   ( a p i / i n d e x . p y   d e r i v e s   i t   f r o m   t h e   r e q u e s t   H o s t ) ,   s o 
 
         #   t o   d r o p   t h e   * . v e r c e l . a p p   d o m a i n :   r e g i s t e r   a   f r e e   s u b d o m a i n   ( e . g .   k r a i m i n d . i s - a . d e v ) , 
 
         #   a d d   i t   a s   a   c u s t o m   d o m a i n   i n   V e r c e l ,   t h e n   s e t   K R A I M I N D _ A P I _ U R L   t o   i t . 
 
         b a s e   =   a p i _ u r l   o r   o s . g e t e n v ( " K R A I M I N D _ A P I _ U R L " ,   " h t t p s : / / k r a i m i n d o f f i c i a l 1 . v e r c e l . a p p / a p i " ) 
 
         e n d p o i n t   =   b a s e . r s t r i p ( " / " )   +   " / s h a r e " 
 
 
 
         t r y : 
 
                 w i t h   h t t p x . C l i e n t ( t i m e o u t = t i m e o u t )   a s   c l i e n t : 
 
                         r e s p   =   c l i e n t . p o s t ( 
 
                                 e n d p o i n t , 
 
                                 j s o n = { " c o n t e n t " :   c o n t e n t ,   " t t l _ h o u r s " :   t t l _ h o u r s } , 
 
                                 h e a d e r s = { " C o n t e n t - T y p e " :   " a p p l i c a t i o n / j s o n " } , 
 
                         ) 
 
                         r e s p . r a i s e _ f o r _ s t a t u s ( ) 
 
                         d a t a   =   r e s p . j s o n ( ) 
 
         e x c e p t   h t t p x . H T T P E r r o r   a s   e x c : 
 
                 r a i s e   S h a r e U p l o a d E r r o r ( s t r ( e x c ) )   f r o m   e x c 
 
         e x c e p t   V a l u e E r r o r   a s   e x c : 
 
                 r a i s e   S h a r e U p l o a d E r r o r ( f " i n v a l i d   J S O N   r e s p o n s e :   { e x c } " )   f r o m   e x c 
 
 
 
         u r l   =   d a t a . g e t ( " u r l " ) 
 
         i f   n o t   u r l : 
 
                 r a i s e   S h a r e U p l o a d E r r o r ( f " s e r v e r   r e t u r n e d   n o   U R L :   { d a t a ! r } " ) 
 
         r e t u r n   S h a r e R e s u l t ( u r l = u r l ,   e x p i r e s _ a t = d a t a . g e t ( " e x p i r e s _ a t " ) ) 
 
 
 
 
 
 d e f   r e n d e r _ s h a r e _ p a g e ( c o n t e n t :   s t r ,   p r o j e c t _ n a m e :   s t r )   - >   s t r : 
 
         " " " W r a p   t h e   m a r k d o w n   c o d e b a s e   s h a r e   b u n d l e   i n   a   p r e m i u m   H T M L   d o c u m e n t   f o r   b r o w s e r   v i e w i n g . 
 
 
 
         M a i n t a i n s   a   r a w   ` < p r e > `   t a g   o f   t h e   m a r k d o w n   c o n t e n t s   s o   t h a t   A I   c r a w l e r s   c a n   r e a d   i t 
 
         d i r e c t l y   w i t h o u t   e x e c u t i n g   J S ,   w h i l e   r e n d e r i n g   a   b e a u t i f u l ,   i n t e r a c t i v e   f i l e   t r e e 
 
         a n d   c o d e   v i e w e r   f o r   d e v e l o p e r s   u s i n g   a   b r o w s e r . 
 
         " " " 
 
         i m p o r t   h t m l 
 
         e s c a p e d _ c o n t e n t   =   h t m l . e s c a p e ( c o n t e n t ) 
 
 
 
         t e m p l a t e   =   " " " < ! d o c t y p e   h t m l > 
 
 < h t m l   l a n g = " e n " > 
 
 < h e a d > 
 
     < m e t a   c h a r s e t = " U T F - 8 " > 
 
     < m e t a   n a m e = " v i e w p o r t "   c o n t e n t = " w i d t h = d e v i c e - w i d t h ,   i n i t i a l - s c a l e = 1 . 0 " > 
 
     < t i t l e > K r a i m i n d   S h a r e       { { P R O J E C T _ N A M E } } < / t i t l e > 
 
     < l i n k   r e l = " p r e c o n n e c t "   h r e f = " h t t p s : / / f o n t s . g o o g l e a p i s . c o m " > 
 
     < l i n k   r e l = " p r e c o n n e c t "   h r e f = " h t t p s : / / f o n t s . g s t a t i c . c o m "   c r o s s o r i g i n > 
 
     < l i n k   h r e f = " h t t p s : / / f o n t s . g o o g l e a p i s . c o m / c s s 2 ? f a m i l y = J e t B r a i n s + M o n o : w g h t @ 4 0 0 ; 5 0 0 ; 7 0 0 & f a m i l y = O u t f i t : w g h t @ 4 0 0 ; 5 0 0 ; 6 0 0 ; 7 0 0 & d i s p l a y = s w a p "   r e l = " s t y l e s h e e t " > 
 
     < l i n k   h r e f = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / t h e m e s / p r i s m - t o m o r r o w . m i n . c s s "   r e l = " s t y l e s h e e t "   / > 
 
     < s t y l e > 
 
         : r o o t   { 
 
             - - b g - d a r k :   # 0 7 0 7 0 9 ; 
 
             - - b g - p a n e l :   # 0 d 0 d 1 2 ; 
 
             - - b g - c a r d :   # 1 2 1 2 1 a ; 
 
             - - b o r d e r :   # 1 f 1 f 2 e ; 
 
             - - b o r d e r - f o c u s :   # 0 0 f 0 f f ; 
 
             - - t e x t :   # e 2 e 2 e 9 ; 
 
             - - t e x t - m u t e d :   # 7 8 7 8 8 a ; 
 
             - - p r i m a r y :   # 0 0 f 0 f f ; 
 
             - - s e c o n d a r y :   # b d 0 0 f f ; 
 
             - - p r i m a r y - g l o w :   r g b a ( 0 ,   2 4 0 ,   2 5 5 ,   0 . 1 5 ) ; 
 
             - - s e c o n d a r y - g l o w :   r g b a ( 1 8 9 ,   0 ,   2 5 5 ,   0 . 1 5 ) ; 
 
             - - s u c c e s s :   # 1 0 b 9 8 1 ; 
 
         } 
 
 
 
         *   {   b o x - s i z i n g :   b o r d e r - b o x ;   m a r g i n :   0 ;   p a d d i n g :   0 ;   } 
 
 
 
         b o d y   { 
 
             f o n t - f a m i l y :   ' O u t f i t ' ,   s a n s - s e r i f ; 
 
             b a c k g r o u n d - c o l o r :   v a r ( - - b g - d a r k ) ; 
 
             c o l o r :   v a r ( - - t e x t ) ; 
 
             m i n - h e i g h t :   1 0 0 v h ; 
 
             d i s p l a y :   f l e x ; 
 
             f l e x - d i r e c t i o n :   c o l u m n ; 
 
             o v e r f l o w - x :   h i d d e n ; 
 
         } 
 
 
 
         h e a d e r   { 
 
             b a c k g r o u n d :   v a r ( - - b g - p a n e l ) ; 
 
             b o r d e r - b o t t o m :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
             p a d d i n g :   1 4 p x   2 4 p x ; 
 
             d i s p l a y :   f l e x ; 
 
             j u s t i f y - c o n t e n t :   s p a c e - b e t w e e n ; 
 
             a l i g n - i t e m s :   c e n t e r ; 
 
             p o s i t i o n :   s t i c k y ; 
 
             t o p :   0 ; 
 
             z - i n d e x :   1 0 ; 
 
         } 
 
 
 
         . l o g o - c o n t a i n e r   { 
 
             d i s p l a y :   f l e x ; 
 
             a l i g n - i t e m s :   c e n t e r ; 
 
             g a p :   1 2 p x ; 
 
         } 
 
 
 
         . l o g o   { 
 
             f o n t - s i z e :   2 2 p x ; 
 
             f o n t - w e i g h t :   7 0 0 ; 
 
             b a c k g r o u n d :   l i n e a r - g r a d i e n t ( 1 3 5 d e g ,   v a r ( - - p r i m a r y ) ,   v a r ( - - s e c o n d a r y ) ) ; 
 
             - w e b k i t - b a c k g r o u n d - c l i p :   t e x t ; 
 
             - w e b k i t - t e x t - f i l l - c o l o r :   t r a n s p a r e n t ; 
 
             l e t t e r - s p a c i n g :   1 p x ; 
 
         } 
 
 
 
         . b a d g e   { 
 
             b a c k g r o u n d :   v a r ( - - b o r d e r ) ; 
 
             p a d d i n g :   4 p x   1 0 p x ; 
 
             b o r d e r - r a d i u s :   1 2 p x ; 
 
             f o n t - s i z e :   1 1 p x ; 
 
             f o n t - w e i g h t :   5 0 0 ; 
 
             c o l o r :   v a r ( - - t e x t - m u t e d ) ; 
 
         } 
 
 
 
         . a c t i o n s   { 
 
             d i s p l a y :   f l e x ; 
 
             g a p :   1 2 p x ; 
 
         } 
 
 
 
         . b t n   { 
 
             b a c k g r o u n d :   l i n e a r - g r a d i e n t ( 1 3 5 d e g ,   v a r ( - - p r i m a r y ) ,   v a r ( - - s e c o n d a r y ) ) ; 
 
             b o r d e r :   n o n e ; 
 
             c o l o r :   # 0 0 0 ; 
 
             f o n t - w e i g h t :   6 0 0 ; 
 
             p a d d i n g :   8 p x   1 6 p x ; 
 
             b o r d e r - r a d i u s :   6 p x ; 
 
             c u r s o r :   p o i n t e r ; 
 
             f o n t - f a m i l y :   i n h e r i t ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             t r a n s i t i o n :   a l l   0 . 2 s   e a s e ; 
 
             b o x - s h a d o w :   0   0   1 2 p x   r g b a ( 0 ,   2 4 0 ,   2 5 5 ,   0 . 2 ) ; 
 
         } 
 
 
 
         . b t n : h o v e r   { 
 
             t r a n s f o r m :   t r a n s l a t e Y ( - 1 p x ) ; 
 
             b o x - s h a d o w :   0   0   1 6 p x   r g b a ( 0 ,   2 4 0 ,   2 5 5 ,   0 . 4 ) ; 
 
         } 
 
 
 
         . b t n - s e c o n d a r y   { 
 
             b a c k g r o u n d :   v a r ( - - b o r d e r ) ; 
 
             c o l o r :   v a r ( - - t e x t ) ; 
 
             b o x - s h a d o w :   n o n e ; 
 
             b o r d e r :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
         } 
 
 
 
         . b t n - s e c o n d a r y : h o v e r   { 
 
             b a c k g r o u n d :   v a r ( - - b g - c a r d ) ; 
 
             b o r d e r - c o l o r :   v a r ( - - p r i m a r y ) ; 
 
             b o x - s h a d o w :   0   0   1 0 p x   v a r ( - - p r i m a r y - g l o w ) ; 
 
         } 
 
 
 
         . m a i n - c o n t a i n e r   { 
 
             d i s p l a y :   f l e x ; 
 
             f l e x :   1 ; 
 
             h e i g h t :   c a l c ( 1 0 0 v h   -   5 9 p x ) ; 
 
             o v e r f l o w :   h i d d e n ; 
 
         } 
 
 
 
         . s i d e b a r   { 
 
             w i d t h :   3 0 0 p x ; 
 
             b a c k g r o u n d :   v a r ( - - b g - p a n e l ) ; 
 
             b o r d e r - r i g h t :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
             d i s p l a y :   f l e x ; 
 
             f l e x - d i r e c t i o n :   c o l u m n ; 
 
             f l e x - s h r i n k :   0 ; 
 
         } 
 
 
 
         . s e a r c h - b o x   { 
 
             p a d d i n g :   1 2 p x ; 
 
             b o r d e r - b o t t o m :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
         } 
 
 
 
         . s e a r c h - i n p u t   { 
 
             w i d t h :   1 0 0 % ; 
 
             b a c k g r o u n d :   v a r ( - - b g - d a r k ) ; 
 
             b o r d e r :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
             p a d d i n g :   8 p x   1 2 p x ; 
 
             b o r d e r - r a d i u s :   6 p x ; 
 
             c o l o r :   v a r ( - - t e x t ) ; 
 
             f o n t - f a m i l y :   i n h e r i t ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             o u t l i n e :   n o n e ; 
 
             t r a n s i t i o n :   b o r d e r - c o l o r   0 . 2 s ; 
 
         } 
 
 
 
         . s e a r c h - i n p u t : f o c u s   { 
 
             b o r d e r - c o l o r :   v a r ( - - b o r d e r - f o c u s ) ; 
 
         } 
 
 
 
         . t r e e - c o n t a i n e r   { 
 
             f l e x :   1 ; 
 
             o v e r f l o w - y :   a u t o ; 
 
             p a d d i n g :   1 2 p x   6 p x ; 
 
         } 
 
 
 
         . t r e e - i t e m   { 
 
             d i s p l a y :   f l e x ; 
 
             a l i g n - i t e m s :   c e n t e r ; 
 
             g a p :   8 p x ; 
 
             p a d d i n g :   6 p x   1 0 p x ; 
 
             b o r d e r - r a d i u s :   4 p x ; 
 
             c u r s o r :   p o i n t e r ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             c o l o r :   v a r ( - - t e x t - m u t e d ) ; 
 
             t r a n s i t i o n :   a l l   0 . 1 5 s   e a s e ; 
 
             w h i t e - s p a c e :   n o w r a p ; 
 
             o v e r f l o w :   h i d d e n ; 
 
             t e x t - o v e r f l o w :   e l l i p s i s ; 
 
         } 
 
 
 
         . t r e e - i t e m : h o v e r   { 
 
             b a c k g r o u n d :   v a r ( - - b g - c a r d ) ; 
 
             c o l o r :   v a r ( - - t e x t ) ; 
 
         } 
 
 
 
         . t r e e - i t e m . a c t i v e   { 
 
             b a c k g r o u n d :   v a r ( - - p r i m a r y - g l o w ) ; 
 
             c o l o r :   v a r ( - - p r i m a r y ) ; 
 
             f o n t - w e i g h t :   5 0 0 ; 
 
         } 
 
 
 
         . c o n t e n t - a r e a   { 
 
             f l e x :   1 ; 
 
             d i s p l a y :   f l e x ; 
 
             f l e x - d i r e c t i o n :   c o l u m n ; 
 
             b a c k g r o u n d :   v a r ( - - b g - d a r k ) ; 
 
             o v e r f l o w :   h i d d e n ; 
 
         } 
 
 
 
         . t a b - b a r   { 
 
             b a c k g r o u n d :   v a r ( - - b g - p a n e l ) ; 
 
             b o r d e r - b o t t o m :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
             d i s p l a y :   f l e x ; 
 
             p a d d i n g :   0   1 6 p x ; 
 
         } 
 
 
 
         . t a b   { 
 
             p a d d i n g :   1 4 p x   2 0 p x ; 
 
             b o r d e r - b o t t o m :   2 p x   s o l i d   t r a n s p a r e n t ; 
 
             c u r s o r :   p o i n t e r ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             f o n t - w e i g h t :   5 0 0 ; 
 
             c o l o r :   v a r ( - - t e x t - m u t e d ) ; 
 
             t r a n s i t i o n :   a l l   0 . 2 s   e a s e ; 
 
         } 
 
 
 
         . t a b . a c t i v e   { 
 
             c o l o r :   v a r ( - - p r i m a r y ) ; 
 
             b o r d e r - c o l o r :   v a r ( - - p r i m a r y ) ; 
 
         } 
 
 
 
         . v i e w e r   { 
 
             f l e x :   1 ; 
 
             o v e r f l o w :   a u t o ; 
 
             p a d d i n g :   2 0 p x ; 
 
             p o s i t i o n :   r e l a t i v e ; 
 
         } 
 
 
 
         p r e . c o d e - b l o c k   { 
 
             b a c k g r o u n d :   v a r ( - - b g - c a r d )   ! i m p o r t a n t ; 
 
             b o r d e r :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
             b o r d e r - r a d i u s :   6 p x ; 
 
             p a d d i n g :   1 6 p x ; 
 
             f o n t - f a m i l y :   ' J e t B r a i n s   M o n o ' ,   m o n o s p a c e ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             l i n e - h e i g h t :   1 . 6 ; 
 
             m a r g i n :   0 ; 
 
         } 
 
 
 
         . i n s t r u c t i o n - c a r d   { 
 
             b a c k g r o u n d :   v a r ( - - b g - c a r d ) ; 
 
             b o r d e r :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 
             b o r d e r - r a d i u s :   6 p x ; 
 
             p a d d i n g :   2 4 p x ; 
 
             m a x - w i d t h :   8 0 0 p x ; 
 
             m a r g i n :   0   a u t o ; 
 
         } 
 
 
 
         . i n s t r u c t i o n - c a r d   h 2   { 
 
             m a r g i n - b o t t o m :   1 6 p x ; 
 
             c o l o r :   v a r ( - - p r i m a r y ) ; 
 
             f o n t - s i z e :   1 8 p x ; 
 
         } 
 
 
 
         . i n s t r u c t i o n - c a r d   p   { 
 
             m a r g i n - b o t t o m :   1 2 p x ; 
 
             l i n e - h e i g h t :   1 . 6 ; 
 
             f o n t - s i z e :   1 4 p x ; 
 
             c o l o r :   v a r ( - - t e x t ) ; 
 
         } 
 
 
 
         . i n s t r u c t i o n - c a r d   c o d e   { 
 
             b a c k g r o u n d :   v a r ( - - b g - p a n e l ) ; 
 
             p a d d i n g :   2 p x   6 p x ; 
 
             b o r d e r - r a d i u s :   4 p x ; 
 
             f o n t - f a m i l y :   ' J e t B r a i n s   M o n o ' ,   m o n o s p a c e ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             c o l o r :   v a r ( - - s e c o n d a r y ) ; 
 
         } 
 
 
 
         . i n s t r u c t i o n - c a r d   b l o c k q u o t e   { 
 
             b o r d e r - l e f t :   3 p x   s o l i d   v a r ( - - p r i m a r y ) ; 
 
             p a d d i n g - l e f t :   1 2 p x ; 
 
             m a r g i n :   1 6 p x   0 ; 
 
             f o n t - s t y l e :   i t a l i c ; 
 
             c o l o r :   v a r ( - - t e x t - m u t e d ) ; 
 
         } 
 
 
 
         # r a w - m a r k d o w n   { 
 
             b a c k g r o u n d :   # 0 0 0 ; 
 
             c o l o r :   # f f f ; 
 
             p a d d i n g :   2 0 p x ; 
 
             f o n t - f a m i l y :   m o n o s p a c e ; 
 
             w h i t e - s p a c e :   p r e - w r a p ; 
 
             f o n t - s i z e :   1 2 p x ; 
 
         } 
 
 
 
         . n o t i f i c a t i o n   { 
 
             p o s i t i o n :   f i x e d ; 
 
             b o t t o m :   2 0 p x ; 
 
             r i g h t :   2 0 p x ; 
 
             b a c k g r o u n d :   v a r ( - - s u c c e s s ) ; 
 
             c o l o r :   # 0 0 0 ; 
 
             p a d d i n g :   1 0 p x   2 0 p x ; 
 
             b o r d e r - r a d i u s :   4 p x ; 
 
             f o n t - s i z e :   1 3 p x ; 
 
             f o n t - w e i g h t :   6 0 0 ; 
 
             o p a c i t y :   0 ; 
 
             t r a n s f o r m :   t r a n s l a t e Y ( 1 0 p x ) ; 
 
             t r a n s i t i o n :   a l l   0 . 3 s   e a s e ; 
 
             z - i n d e x :   1 0 0 ; 
 
         } 
 
 
 
         . n o t i f i c a t i o n . s h o w   { 
 
             o p a c i t y :   1 ; 
 
             t r a n s f o r m :   t r a n s l a t e Y ( 0 ) ; 
 
         } 
 
     < / s t y l e > 
 
 < / h e a d > 
 
 < b o d y > 
 
 
 
     < ! - -   R a w   m a r k d o w n   f a l l b a c k   f o r   A I   c r a w l e r s   - - > 
 
     < p r e   i d = " r a w - m a r k d o w n " > { { C O N T E N T } } < / p r e > 
 
 
 
     < ! - -   I n t e r a c t i v e   e l e m e n t s   f o r   h u m a n   b r o w s e r s ,   r e n d e r e d   b y   J S   - - > 
 
     < d i v   i d = " i n t e r a c t i v e - u i "   s t y l e = " d i s p l a y :   n o n e ;   f l e x - d i r e c t i o n :   c o l u m n ;   f l e x :   1 ; " > 
 
         < h e a d e r > 
 
             < d i v   c l a s s = " l o g o - c o n t a i n e r " > 
 
                 < s p a n   c l a s s = " l o g o " > K R A I M I N D < / s p a n > 
 
                 < s p a n   c l a s s = " b a d g e " > C o d e b a s e   S h a r e       { { P R O J E C T _ N A M E } } < / s p a n > 
 
             < / d i v > 
 
             < d i v   c l a s s = " a c t i o n s " > 
 
                 < b u t t o n   c l a s s = " b t n   b t n - s e c o n d a r y "   o n c l i c k = " c o p y P r o m p t ( ) " > C o p y   H a n d o f f   P r o m p t < / b u t t o n > 
 
                 < b u t t o n   c l a s s = " b t n "   o n c l i c k = " c o p y R a w M a r k d o w n ( ) " > C o p y   R a w   M a r k d o w n < / b u t t o n > 
 
             < / d i v > 
 
         < / h e a d e r > 
 
 
 
         < d i v   c l a s s = " m a i n - c o n t a i n e r " > 
 
             < d i v   c l a s s = " s i d e b a r " > 
 
                 < d i v   c l a s s = " s e a r c h - b o x " > 
 
                     < i n p u t   t y p e = " t e x t "   i d = " s e a r c h "   c l a s s = " s e a r c h - i n p u t "   p l a c e h o l d e r = " S e a r c h   f i l e s . . . "   o n i n p u t = " f i l t e r F i l e s ( ) " > 
 
                 < / d i v > 
 
                 < d i v   c l a s s = " t r e e - c o n t a i n e r "   i d = " f i l e - l i s t " > 
 
                     < ! - -   P o p u l a t e d   b y   J S   - - > 
 
                 < / d i v > 
 
             < / d i v > 
 
 
 
             < d i v   c l a s s = " c o n t e n t - a r e a " > 
 
                 < d i v   c l a s s = " t a b - b a r " > 
 
                     < d i v   c l a s s = " t a b   a c t i v e "   i d = " t a b - e x p l o r e r "   o n c l i c k = " s w i t c h T a b ( ' e x p l o r e r ' ) " > C o d e   E x p l o r e r < / d i v > 
 
                     < d i v   c l a s s = " t a b "   i d = " t a b - i n s t r u c t i o n s "   o n c l i c k = " s w i t c h T a b ( ' i n s t r u c t i o n s ' ) " > H a n d o f f   I n s t r u c t i o n s < / d i v > 
 
                 < / d i v > 
 
 
 
                 < d i v   c l a s s = " v i e w e r "   i d = " e x p l o r e r - v i e w " > 
 
                     < p r e   c l a s s = " c o d e - b l o c k " > < c o d e   c l a s s = " l a n g u a g e - p y t h o n "   i d = " c o d e - v i e w e r " > #   S e l e c t   a   f i l e   t o   v i e w   i t s   c o n t e n t < / c o d e > < / p r e > 
 
                 < / d i v > 
 
 
 
                 < d i v   c l a s s = " v i e w e r "   i d = " i n s t r u c t i o n s - v i e w "   s t y l e = " d i s p l a y :   n o n e ; " > 
 
                     < d i v   c l a s s = " i n s t r u c t i o n - c a r d " > 
 
                         < h 2 > a"    K r a i m i n d   H a n d o f f   P r e a m b l e < / h 2 > 
 
                         < p > T h i s   c o d e b a s e   s h a r e   s t a r t s   w i t h   a   h a n d s h a k e   p r e a m b l e   t h a t   t e l l s   a n y   w e b - b r o w s i n g   A I   ( C h a t G P T ,   C l a u d e ,   G e m i n i )   h o w   t o   h a n d l e   t h e   c o d e . < / p > 
 
                         < p > W h e n   y o u   p a s t e   t h e   l i n k   i n t o   t h e   c h a t ,   y o u   s h o u l d   i n s t r u c t   t h e   A I   a s   f o l l o w s : < / p > 
 
                         < b l o c k q u o t e > 
 
                             " F e t c h   t h i s   U R L   a n d   r e a d   i t       i t   r e t u r n s   t h e   f u l l   s o u r c e   o f   t h e   p r o j e c t   a s   m a r k d o w n .   W a i t   f o r   m e   t o   a s k   q u e s t i o n s   o n c e   c o n n e c t e d . " 
 
                         < / b l o c k q u o t e > 
 
                         < p > T h e   A I   w i l l   r e a d   t h e   i n s t r u c t i o n s   a n d   r e s p o n d   w i t h   a   c o n f i r m a t i o n   l i n e : < / p > 
 
                         < b l o c k q u o t e > 
 
                             & g t ;       C o n n e c t e d   t o   k r a i m i n d       { { P R O J E C T _ N A M E } }   ,%V%  [ X ]   f i l e s 
 
                         < / b l o c k q u o t e > 
 
                     < / d i v > 
 
                 < / d i v > 
 
             < / d i v > 
 
         < / d i v > 
 
     < / d i v > 
 
 
 
     < d i v   i d = " t o a s t "   c l a s s = " n o t i f i c a t i o n " > C o p i e d   t o   c l i p b o a r d ! < / d i v > 
 
 
 
     < ! - -   J a v a S c r i p t   l o g i c   t o   p a r s e   m a r k d o w n   a n d   m a k e   U I   i n t e r a c t i v e   - - > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / p r i s m . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - p y t h o n . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - j a v a s c r i p t . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - t y p e s c r i p t . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - b a s h . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - j s o n . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - y a m l . m i n . j s " > < / s c r i p t > 
 
     < s c r i p t   s r c = " h t t p s : / / c d n j s . c l o u d f l a r e . c o m / a j a x / l i b s / p r i s m / 1 . 2 9 . 0 / c o m p o n e n t s / p r i s m - m a r k d o w n . m i n . j s " > < / s c r i p t > 
 
 
 
     < s c r i p t > 
 
         / /   G l o b a l   s t a t e 
 
         l e t   f i l e s   =   [ ] ; 
 
         l e t   a c t i v e F i l e   =   n u l l ; 
 
 
 
         / /   S h o w   i n t e r a c t i v e   U I   &   H i d e   r a w   m a r k d o w n 
 
         d o c u m e n t . a d d E v e n t L i s t e n e r ( " D O M C o n t e n t L o a d e d " ,   ( )   = >   { 
 
             c o n s t   r a w T e x t   =   d o c u m e n t . g e t E l e m e n t B y I d ( " r a w - m a r k d o w n " ) . t e x t C o n t e n t ; 
 
             d o c u m e n t . g e t E l e m e n t B y I d ( " r a w - m a r k d o w n " ) . s t y l e . d i s p l a y   =   " n o n e " ; 
 
             d o c u m e n t . g e t E l e m e n t B y I d ( " i n t e r a c t i v e - u i " ) . s t y l e . d i s p l a y   =   " f l e x " ; 
 
 
 
             / /   P a r s e   m a r k d o w n   t o   e x t r a c t   f i l e s 
 
             / /   P a t t e r n   m a t c h e s :   # # #   ` p a t h / t o / f i l e `   f o l l o w e d   b y   f i l e   c o n t e n t s   c o d e   b l o c k 
 
             c o n s t   r e g e x   =   / # # #   ` ( [ ^ ` ] + ) ` \ \ s * ` ` ` ( [ a - z A - Z 0 - 9 _ - ] * ) \ \ r ? \ \ n ( [ \ \ s \ \ S ] * ? ) \ \ r ? \ \ n ` ` ` / g ; 
 
             l e t   m a t c h ; 
 
             w h i l e   ( ( m a t c h   =   r e g e x . e x e c ( r a w T e x t ) )   ! = =   n u l l )   { 
 
                 f i l e s . p u s h ( { 
 
                     p a t h :   m a t c h [ 1 ] , 
 
                     l a n g :   m a t c h [ 2 ]   | |   " p l a i n t e x t " , 
 
                     c o n t e n t :   m a t c h [ 3 ] 
 
                 } ) ; 
 
             } 
 
 
 
             / /   R e n d e r   f i l e   l i s t 
 
             r e n d e r F i l e L i s t ( f i l e s ) ; 
 
 
 
             / /   S e l e c t   f i r s t   f i l e   b y   d e f a u l t   i f   a v a i l a b l e 
 
             i f   ( f i l e s . l e n g t h   >   0 )   { 
 
                 s e l e c t F i l e ( f i l e s [ 0 ] . p a t h ) ; 
 
             } 
 
         } ) ; 
 
 
 
         f u n c t i o n   r e n d e r F i l e L i s t ( f i l e L i s t )   { 
 
             c o n s t   l i s t E l   =   d o c u m e n t . g e t E l e m e n t B y I d ( " f i l e - l i s t " ) ; 
 
             l i s t E l . i n n e r H T M L   =   " " ; 
 
 
 
             i f   ( f i l e L i s t . l e n g t h   = = =   0 )   { 
 
                 l i s t E l . i n n e r H T M L   =   ' < d i v   s t y l e = " p a d d i n g :   1 0 p x ;   c o l o r :   v a r ( - - t e x t - m u t e d ) ; " > N o   f i l e s   f o u n d < / d i v > ' ; 
 
                 r e t u r n ; 
 
             } 
 
 
 
             f i l e L i s t . f o r E a c h ( f i l e   = >   { 
 
                 c o n s t   i t e m   =   d o c u m e n t . c r e a t e E l e m e n t ( " d i v " ) ; 
 
                 i t e m . c l a s s N a m e   =   " t r e e - i t e m " ; 
 
                 i f   ( a c t i v e F i l e   & &   a c t i v e F i l e . p a t h   = = =   f i l e . p a t h )   { 
 
                     i t e m . c l a s s N a m e   + =   "   a c t i v e " ; 
 
                 } 
 
                 i t e m . t e x t C o n t e n t   =   f i l e . p a t h ; 
 
                 i t e m . o n c l i c k   =   ( )   = >   s e l e c t F i l e ( f i l e . p a t h ) ; 
 
                 l i s t E l . a p p e n d C h i l d ( i t e m ) ; 
 
             } ) ; 
 
         } 
 
 
 
         f u n c t i o n   s e l e c t F i l e ( p a t h )   { 
 
             c o n s t   f i l e   =   f i l e s . f i n d ( f   = >   f . p a t h   = = =   p a t h ) ; 
 
             i f   ( ! f i l e )   r e t u r n ; 
 
 
 
             a c t i v e F i l e   =   f i l e ; 
 
 
 
             / /   U p d a t e   a c t i v e   l i s t   i t e m 
 
             c o n s t   i t e m s   =   d o c u m e n t . q u e r y S e l e c t o r A l l ( " . t r e e - i t e m " ) ; 
 
             i t e m s . f o r E a c h ( i t e m   = >   { 
 
                 i f   ( i t e m . t e x t C o n t e n t   = = =   p a t h )   { 
 
                     i t e m . c l a s s L i s t . a d d ( " a c t i v e " ) ; 
 
                 }   e l s e   { 
 
                     i t e m . c l a s s L i s t . r e m o v e ( " a c t i v e " ) ; 
 
                 } 
 
             } ) ; 
 
 
 
             / /   R e n d e r   c o d e 
 
             c o n s t   v i e w e r   =   d o c u m e n t . g e t E l e m e n t B y I d ( " c o d e - v i e w e r " ) ; 
 
             v i e w e r . t e x t C o n t e n t   =   f i l e . c o n t e n t ; 
 
             v i e w e r . c l a s s N a m e   =   " l a n g u a g e - "   +   f i l e . l a n g ; 
 
 
 
             / /   R e - t r i g g e r   P r i s m   s y n t a x   h i g h l i g h t i n g 
 
             P r i s m . h i g h l i g h t E l e m e n t ( v i e w e r ) ; 
 
         } 
 
 
 
         f u n c t i o n   f i l t e r F i l e s ( )   { 
 
             c o n s t   q u e r y   =   d o c u m e n t . g e t E l e m e n t B y I d ( " s e a r c h " ) . v a l u e . t o L o w e r C a s e ( ) ; 
 
             c o n s t   f i l t e r e d   =   f i l e s . f i l t e r ( f   = >   f . p a t h . t o L o w e r C a s e ( ) . i n c l u d e s ( q u e r y ) ) ; 
 
             r e n d e r F i l e L i s t ( f i l t e r e d ) ; 
 
         } 
 
 
 
         f u n c t i o n   s h o w T o a s t ( m s g )   { 
 
             c o n s t   t o a s t   =   d o c u m e n t . g e t E l e m e n t B y I d ( " t o a s t " ) ; 
 
             t o a s t . t e x t C o n t e n t   =   m s g ; 
 
             t o a s t . c l a s s L i s t . a d d ( " s h o w " ) ; 
 
             s e t T i m e o u t ( ( )   = >   t o a s t . c l a s s L i s t . r e m o v e ( " s h o w " ) ,   2 0 0 0 ) ; 
 
         } 
 
 
 
         f u n c t i o n   c o p y P r o m p t ( )   { 
 
             c o n s t   p r o j e c t   =   " { { P R O J E C T _ N A M E } } " ; 
 
             c o n s t   f i l e s C o u n t   =   f i l e s . l e n g t h ; 
 
             c o n s t   c o n f i r m T e x t   =   `     C o n n e c t e d   t o   k r a i m i n d       $ { p r o j e c t }   ,%V%  $ { f i l e s C o u n t }   f i l e s ` ; 
 
             c o n s t   p r o m p t   =   ` < ! - -   K R A I M I N D   H A N D O F F   - - > 
 
 #   a"    K r a i m i n d   h a n d o f f       i n s t r u c t i o n s   f o r   t h e   A I   ( r e a d   t h i s   f i r s t ) 
 
 
 
 Y o u   h a v e   b e e n   c o n n e c t e d   t o   a   l i v e   c o d e b a s e   t h r o u g h   * * K r a i m i n d * * ,   a   d e v e l o p e r   h a n d - o f f   t o o l .   T h e   c o m p l e t e   s o u r c e   o f   t h e   p r o j e c t   * * \ \ \ ` $ { p r o j e c t } \ \ \ ` * *   ( \ $ { f i l e s C o u n t }   f i l e s )   f o l l o w s   b e l o w . 
 
 
 
 * * F i r s t ,   c o n f i r m   t h e   c o n n e c t i o n . * *   B e g i n   y o u r   v e r y   f i r s t   r e p l y   w i t h   e x a c t l y   t h i s   l i n e : 
 
 
 
 >   \ $ { c o n f i r m T e x t } 
 
 
 
 T h e n   a d d   a   o n e - s e n t e n c e   s u m m a r y   o f   w h a t   t h i s   p r o j e c t   d o e s ,   a n d   a s k   t h e   d e v e l o p e r   w h a t   t h e y ' d   l i k e   t o   w o r k   o n .   F o r   t h e   r e s t   o f   t h e   c o n v e r s a t i o n ,   t r e a t   t h e   c o d e   b e l o w   a s   o u r   s h a r e d   w o r k i n g   c o n t e x t       a n s w e r   f o l l o w - u p   q u e s t i o n s   d i r e c t l y   f r o m   t h e s e   f i l e s   w i t h o u t   a s k i n g   m e   t o   p a s t e   t h e m   a g a i n . 
 
 
 
 - - - 
 
 I   w a s   u s i n g   a n   A I   c o d i n g   a s s i s t a n t   i n   V S C o d e   a n d   h i t   a   c r e d i t   l i m i t .   H e r e   i s   m y   f u l l   c o d e b a s e   c o n t e x t   s o   y o u   c a n   h e l p   m e   c o n t i n u e . 
 
 
 
 # #   C o d e b a s e 
 
 \ $ { w i n d o w . l o c a t i o n . h r e f } ` ; 
 
 
 
             n a v i g a t o r . c l i p b o a r d . w r i t e T e x t ( p r o m p t ) . t h e n ( ( )   = >   { 
 
                 s h o w T o a s t ( " H a n d o f f   p r o m p t   c o p i e d ! " ) ; 
 
             } ) ; 
 
         } 
 
 
 
         f u n c t i o n   c o p y R a w M a r k d o w n ( )   { 
 
             c o n s t   r a w T e x t   =   d o c u m e n t . g e t E l e m e n t B y I d ( " r a w - m a r k d o w n " ) . t e x t C o n t e n t ; 
 
             n a v i g a t o r . c l i p b o a r d . w r i t e T e x t ( r a w T e x t ) . t h e n ( ( )   = >   { 
 
                 s h o w T o a s t ( " R a w   m a r k d o w n   c o d e b a s e   c o p i e d ! " ) ; 
 
             } ) ; 
 
         } 
 
     < / s c r i p t > 
 
 < / b o d y > 
 
 < / h t m l > " " " 
 
 
 
         r e t u r n   t e m p l a t e . r e p l a c e ( " { { C O N T E N T } } " ,   e s c a p e d _ c o n t e n t ) . r e p l a c e ( " { { P R O J E C T _ N A M E } } " ,   p r o j e c t _ n a m e ) 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / s u p p l y _ c h a i n . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " S u p p l y - c h a i n   u r g e n c y   s i g n a l s . 
 
 
 
 F l a g s   p a c k a g e s   w i t h   r e c e n t ,   s u s p i c i o u s   c h a n g e s   t h a t   w a r r a n t   i m m e d i a t e   r e v i e w : 
 
         Y a n k e d   f r o m   P y P I   i n   t h e   l a s t   3 0   d a y s 
 
         M a i n t a i n e r / o w n e r   c h a n g e d   r e c e n t l y   ( h e u r i s t i c ) 
 
         C V E   p u b l i s h e d   i n   t h e   l a s t   7   d a y s 
 
         T y p o s q u a t   s u s p e c t   ( L e v e n s h t e i n   d i s t a n c e       2   f r o m   a   t o p   p a c k a g e ) 
 
 
 
 E a c h   s i g n a l   r a i s e s   a n   " u r g e n c y "   f l a g   a t t a c h e d   t o   t h e   p a c k a g e ;   s u r f a c e d   i n 
 
 a n a l y z e   /   c l e a n   o u t p u t   a s   a   r e d   b a n n e r . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   d a t a c l a s s e s   i m p o r t   d a t a c l a s s ,   f i e l d 
 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e z o n e 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   O p t i o n a l ,   S e t 
 
 
 
 
 
 #   H a n d - p i c k e d   t o p - 1 0 0   P y P I   p a c k a g e s       t y p o s q u a t   r e f e r e n c e   s e t . 
 
 #   S o u r c e :   p y p i . o r g / s t a t s ,   d e l i b e r a t e l y   s m a l l   t o   k e e p   d i s t a n c e   c h e c k s   c h e a p . 
 
 T O P _ P A C K A G E S :   S e t [ s t r ]   =   { 
 
         " r e q u e s t s " ,   " u r l l i b 3 " ,   " b o t o 3 " ,   " b o t o c o r e " ,   " s e t u p t o o l s " ,   " p i p " ,   " c e r t i f i " , 
 
         " c h a r s e t - n o r m a l i z e r " ,   " i d n a " ,   " w h e e l " ,   " p y t h o n - d a t e u t i l " ,   " s i x " ,   " p y y a m l " , 
 
         " n u m p y " ,   " p a n d a s " ,   " c l i c k " ,   " j i n j a 2 " ,   " m a r k u p s a f e " ,   " c r y p t o g r a p h y " ,   " c f f i " , 
 
         " p y c p a r s e r " ,   " t y p i n g - e x t e n s i o n s " ,   " p a c k a g i n g " ,   " r i c h " ,   " h t t p x " ,   " f a s t a p i " , 
 
         " p y d a n t i c " ,   " s q l a l c h e m y " ,   " f l a s k " ,   " d j a n g o " ,   " p y t e s t " ,   " t o x " ,   " b l a c k " , 
 
         " i s o r t " ,   " m y p y " ,   " r u f f " ,   " p y l i n t " ,   " c o v e r a g e " ,   " t o r n a d o " ,   " c e l e r y " ,   " r e d i s " , 
 
         " p s y c o p g 2 " ,   " p y m o n g o " ,   " a i o h t t p " ,   " s t a r l e t t e " ,   " u v i c o r n " ,   " g u n i c o r n " , 
 
         " m a t p l o t l i b " ,   " s c i p y " ,   " s c i k i t - l e a r n " ,   " t e n s o r f l o w " ,   " t o r c h " ,   " p i l l o w " , 
 
         " l x m l " ,   " b e a u t i f u l s o u p 4 " ,   " s e l e n i u m " ,   " p l a y w r i g h t " ,   " o p e n a i " ,   " a n t h r o p i c " , 
 
         " g o o g l e - a p i - p y t h o n - c l i e n t " ,   " p r o t o b u f " ,   " g r p c i o " ,   " m s g p a c k " ,   " o r j s o n " , 
 
         " t q d m " ,   " a t t r s " ,   " w r a p t " ,   " d e c o r a t o r " ,   " m o r e - i t e r t o o l s " ,   " p l u g g y " , 
 
         " i n i c o n f i g " ,   " f i l e l o c k " ,   " p l a t f o r m d i r s " ,   " v i r t u a l e n v " ,   " d o c k e r " ,   " k u b e r n e t e s " , 
 
         " a n s i b l e " ,   " p a r a m i k o " ,   " f a b r i c " ,   " i n v o k e " ,   " s t r u c t l o g " ,   " l o g u r u " ,   " s e n t r y - s d k " , 
 
         " n e w r e l i c " ,   " d d t r a c e " ,   " p r o m e t h e u s - c l i e n t " ,   " s t a t s d " ,   " e l a s t i c s e a r c h " , 
 
         " k a f k a - p y t h o n " ,   " p i k a " ,   " w e b s o c k e t s " ,   " a s y n c p g " ,   " a i o m y s q l " ,   " a i o r e d i s " , 
 
         " h t t p t o o l s " ,   " h 1 1 " ,   " a n y i o " ,   " t r i o " ,   " s n i f f i o " ,   " e x c e p t i o n g r o u p " , 
 
 } 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   U r g e n c y F l a g : 
 
         " " " S i n g l e   s u p p l y - c h a i n   u r g e n c y   s i g n a l . " " " 
 
 
 
         c o d e :   s t r                 #   " t y p o s q u a t " ,   " y a n k e d - r e c e n t " ,   " c v e - r e c e n t " ,   " n e w - m a i n t a i n e r " 
 
         s e v e r i t y :   s t r         #   " h i g h " ,   " m e d i u m " ,   " l o w " 
 
         m e s s a g e :   s t r 
 
 
 
 
 
 @ d a t a c l a s s 
 
 c l a s s   S u p p l y C h a i n A s s e s s m e n t : 
 
         " " " P e r - p a c k a g e   s u p p l y - c h a i n   r i s k . " " " 
 
 
 
         p a c k a g e :   s t r 
 
         f l a g s :   L i s t [ U r g e n c y F l a g ]   =   f i e l d ( d e f a u l t _ f a c t o r y = l i s t ) 
 
 
 
         @ p r o p e r t y 
 
         d e f   h a s _ u r g e n t _ f l a g ( s e l f )   - >   b o o l : 
 
                 r e t u r n   a n y ( f . s e v e r i t y   = =   " h i g h "   f o r   f   i n   s e l f . f l a g s ) 
 
 
 
         @ p r o p e r t y 
 
         d e f   h a s _ a n y _ f l a g ( s e l f )   - >   b o o l : 
 
                 r e t u r n   b o o l ( s e l f . f l a g s ) 
 
 
 
 
 
 d e f   _ l e v e n s h t e i n ( a :   s t r ,   b :   s t r )   - >   i n t : 
 
         " " " S i m p l e   L e v e n s h t e i n   d i s t a n c e   ( s m a l l   s t r i n g s ,   n o   o p t i m i z a t i o n   n e e d e d ) . " " " 
 
         i f   a   = =   b : 
 
                 r e t u r n   0 
 
         i f   l e n ( a )   <   l e n ( b ) : 
 
                 a ,   b   =   b ,   a 
 
         i f   n o t   b : 
 
                 r e t u r n   l e n ( a ) 
 
 
 
         p r e v   =   l i s t ( r a n g e ( l e n ( b )   +   1 ) ) 
 
         f o r   i ,   c a   i n   e n u m e r a t e ( a ,   s t a r t = 1 ) : 
 
                 c u r   =   [ i ] 
 
                 f o r   j ,   c b   i n   e n u m e r a t e ( b ,   s t a r t = 1 ) : 
 
                         i n s   =   c u r [ j   -   1 ]   +   1 
 
                         d e l e   =   p r e v [ j ]   +   1 
 
                         s u b   =   p r e v [ j   -   1 ]   +   ( c a   ! =   c b ) 
 
                         c u r . a p p e n d ( m i n ( i n s ,   d e l e ,   s u b ) ) 
 
                 p r e v   =   c u r 
 
         r e t u r n   p r e v [ - 1 ] 
 
 
 
 
 
 d e f   c h e c k _ t y p o s q u a t ( p a c k a g e :   s t r )   - >   O p t i o n a l [ U r g e n c y F l a g ] : 
 
         " " " F l a g   i f   ` p a c k a g e `   i s   d i s t a n c e       2   f r o m   a   t o p   p a c k a g e   ( b u t   n o t   t h e   t o p   p a c k a g e   i t s e l f ) . " " " 
 
         p k g   =   p a c k a g e . l o w e r ( ) 
 
         i f   p k g   i n   T O P _ P A C K A G E S : 
 
                 r e t u r n   N o n e 
 
         f o r   t o p   i n   T O P _ P A C K A G E S : 
 
                 d   =   _ l e v e n s h t e i n ( p k g ,   t o p ) 
 
                 i f   d   = =   0 : 
 
                         r e t u r n   N o n e 
 
                 i f   d   < =   2   a n d   a b s ( l e n ( p k g )   -   l e n ( t o p ) )   < =   2 : 
 
                         r e t u r n   U r g e n c y F l a g ( 
 
                                 c o d e = " t y p o s q u a t " , 
 
                                 s e v e r i t y = " h i g h " , 
 
                                 m e s s a g e = f " N a m e   i s   { d }   c h a r ( s )   f r o m   p o p u l a r   p a c k a g e   ' { t o p } '       p o s s i b l e   t y p o s q u a t " , 
 
                         ) 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   _ p a r s e _ i s o ( d a t e _ s t r :   O p t i o n a l [ s t r ] )   - >   O p t i o n a l [ d a t e t i m e ] : 
 
         i f   n o t   d a t e _ s t r : 
 
                 r e t u r n   N o n e 
 
         t r y : 
 
                 r e t u r n   d a t e t i m e . f r o m i s o f o r m a t ( d a t e _ s t r . r e p l a c e ( " Z " ,   " + 0 0 : 0 0 " ) ) 
 
         e x c e p t   ( V a l u e E r r o r ,   A t t r i b u t e E r r o r ) : 
 
                 r e t u r n   N o n e 
 
 
 
 
 
 d e f   c h e c k _ r e c e n t _ c v e ( v u l n e r a b i l i t i e s :   L i s t [ D i c t [ s t r ,   A n y ] ] ,   d a y s :   i n t   =   7 )   - >   O p t i o n a l [ U r g e n c y F l a g ] : 
 
         " " " F l a g   i f   a n y   v u l n e r a b i l i t y   w a s   p u b l i s h e d   i n   t h e   l a s t   ` d a y s `   d a y s . " " " 
 
         i f   n o t   v u l n e r a b i l i t i e s : 
 
                 r e t u r n   N o n e 
 
         c u t o f f _ d a y s   =   d a y s 
 
         n o w   =   d a t e t i m e . n o w ( t i m e z o n e . u t c ) 
 
         f o r   v   i n   v u l n e r a b i l i t i e s : 
 
                 p u b l i s h e d   =   _ p a r s e _ i s o ( v . g e t ( " p u b l i s h e d " ) ) 
 
                 i f   n o t   p u b l i s h e d : 
 
                         c o n t i n u e 
 
                 a g e _ d a y s   =   ( n o w   -   p u b l i s h e d ) . d a y s 
 
                 i f   0   < =   a g e _ d a y s   < =   c u t o f f _ d a y s : 
 
                         r e t u r n   U r g e n c y F l a g ( 
 
                                 c o d e = " c v e - r e c e n t " , 
 
                                 s e v e r i t y = " h i g h " , 
 
                                 m e s s a g e = f " C V E   p u b l i s h e d   { a g e _ d a y s } d   a g o :   { v . g e t ( ' i d ' ,   ' u n k n o w n ' ) } " , 
 
                         ) 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   c h e c k _ r e p o _ a r c h i v e d _ r e c e n t l y ( g i t h u b :   D i c t [ s t r ,   A n y ] ,   d a y s :   i n t   =   9 0 )   - >   O p t i o n a l [ U r g e n c y F l a g ] : 
 
         " " " F l a g   i f   t h e   G i t H u b   r e p o   i s   a r c h i v e d   a n d   w a s   u p d a t e d   w i t h i n   t h e   l a s t   ` d a y s `   d a y s . " " " 
 
         i f   n o t   g i t h u b . g e t ( " a r c h i v e d " ) : 
 
                 r e t u r n   N o n e 
 
         u p d a t e d   =   _ p a r s e _ i s o ( g i t h u b . g e t ( " u p d a t e d _ a t " ) ) 
 
         i f   n o t   u p d a t e d : 
 
                 r e t u r n   U r g e n c y F l a g ( 
 
                         c o d e = " a r c h i v e d " , 
 
                         s e v e r i t y = " m e d i u m " , 
 
                         m e s s a g e = " G i t H u b   r e p o   i s   a r c h i v e d       u n m a i n t a i n e d " , 
 
                 ) 
 
         a g e   =   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   u p d a t e d ) . d a y s 
 
         s e v e r i t y   =   " h i g h "   i f   a g e   < =   d a y s   e l s e   " m e d i u m " 
 
         r e t u r n   U r g e n c y F l a g ( 
 
                 c o d e = " a r c h i v e d " , 
 
                 s e v e r i t y = s e v e r i t y , 
 
                 m e s s a g e = f " G i t H u b   r e p o   a r c h i v e d   ( l a s t   u p d a t e d   { a g e } d   a g o ) " , 
 
         ) 
 
 
 
 
 
 d e f   c h e c k _ n e w _ p a c k a g e ( p y p i :   D i c t [ s t r ,   A n y ] ,   d a y s :   i n t   =   3 0 )   - >   O p t i o n a l [ U r g e n c y F l a g ] : 
 
         " " " F l a g   i f   t h e   l a t e s t   r e l e a s e   w a s   p u b l i s h e d   i n   t h e   l a s t   ` d a y s `   d a y s   A N D   t h e   p a c k a g e   i s   n e w . 
 
 
 
         H e u r i s t i c :   a   b r a n d - n e w   p a c k a g e   w i t h   a   s i n g l e   r e c e n t   r e l e a s e   i s   h i g h e r   r i s k 
 
         t h a n   a n   e s t a b l i s h e d   p a c k a g e   w i t h   a   r e c e n t   r e l e a s e . 
 
         " " " 
 
         r e l e a s e _ d a t e   =   _ p a r s e _ i s o ( p y p i . g e t ( " r e l e a s e _ d a t e " ) ) 
 
         i f   n o t   r e l e a s e _ d a t e : 
 
                 r e t u r n   N o n e 
 
         a g e   =   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   r e l e a s e _ d a t e ) . d a y s 
 
         i f   0   < =   a g e   < =   d a y s : 
 
                 r e t u r n   U r g e n c y F l a g ( 
 
                         c o d e = " r e c e n t - r e l e a s e " , 
 
                         s e v e r i t y = " l o w " , 
 
                         m e s s a g e = f " L a t e s t   r e l e a s e   i s   o n l y   { a g e } d   o l d       i n v e s t i g a t e   b e f o r e   u p g r a d i n g   b l i n d l y " , 
 
                 ) 
 
         r e t u r n   N o n e 
 
 
 
 
 
 d e f   a s s e s s _ s u p p l y _ c h a i n ( 
 
         p a c k a g e :   s t r , 
 
         p y p i :   D i c t [ s t r ,   A n y ] , 
 
         g i t h u b :   D i c t [ s t r ,   A n y ] , 
 
         v u l n e r a b i l i t i e s :   L i s t [ D i c t [ s t r ,   A n y ] ] , 
 
 )   - >   S u p p l y C h a i n A s s e s s m e n t : 
 
         " " " R u n   a l l   s u p p l y - c h a i n   c h e c k s   a n d   r e t u r n   t h e   a g g r e g a t e   a s s e s s m e n t . " " " 
 
         f l a g s :   L i s t [ U r g e n c y F l a g ]   =   [ ] 
 
 
 
         f o r   c h e c k   i n   ( 
 
                 c h e c k _ t y p o s q u a t ( p a c k a g e ) , 
 
                 c h e c k _ r e c e n t _ c v e ( v u l n e r a b i l i t i e s ) , 
 
                 c h e c k _ r e p o _ a r c h i v e d _ r e c e n t l y ( g i t h u b   o r   { } ) , 
 
                 c h e c k _ n e w _ p a c k a g e ( p y p i   o r   { } ) , 
 
         ) : 
 
                 i f   c h e c k : 
 
                         f l a g s . a p p e n d ( c h e c k ) 
 
 
 
         r e t u r n   S u p p l y C h a i n A s s e s s m e n t ( p a c k a g e = p a c k a g e ,   f l a g s = f l a g s ) 
 
 
 
 
 
 d e f   a s s e s s _ a l l ( 
 
         i n t e l _ m a p :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] , 
 
 )   - >   D i c t [ s t r ,   S u p p l y C h a i n A s s e s s m e n t ] : 
 
         " " " A s s e s s   e v e r y   p a c k a g e   i n   a n   i n t e l l i g e n c e   m a p . " " " 
 
         o u t :   D i c t [ s t r ,   S u p p l y C h a i n A s s e s s m e n t ]   =   { } 
 
         f o r   p k g ,   i n t e l   i n   i n t e l _ m a p . i t e m s ( ) : 
 
                 o u t [ p k g ]   =   a s s e s s _ s u p p l y _ c h a i n ( 
 
                         p k g , 
 
                         i n t e l . g e t ( " p y p i " )   o r   { } , 
 
                         i n t e l . g e t ( " g i t h u b " )   o r   { } , 
 
                         i n t e l . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] , 
 
                 ) 
 
         r e t u r n   o u t 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / t r u s t . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " R u l e - b a s e d   t r u s t   s c o r e   e n g i n e       t r a n s p a r e n t ,   a u d i t a b l e ,   n o   b l a c k - b o x   M L . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   O p t i o n a l ,   T u p l e 
 
 
 
 f r o m   k r a i m i n d . g i t h u b   i m p o r t   d a y s _ s i n c e _ l a s t _ p u s h ,   i s _ r e p o _ a c t i v e 
 
 f r o m   k r a i m i n d . v u l n e r a b i l i t y   i m p o r t   s e v e r i t y _ s c o r e _ i m p a c t ,   s u m m a r i z e _ v u l n e r a b i l i t i e s 
 
 
 
 
 
 d e f   c a l c u l a t e _ t r u s t _ s c o r e ( 
 
         g i t h u b :   D i c t [ s t r ,   A n y ] , 
 
         p y p i :   D i c t [ s t r ,   A n y ] , 
 
         v u l n e r a b i l i t i e s :   O p t i o n a l [ L i s t [ D i c t [ s t r ,   A n y ] ] ]   =   N o n e , 
 
 )   - >   T u p l e [ i n t ,   L i s t [ s t r ] ,   L i s t [ s t r ] ] : 
 
         " " " C a l c u l a t e   a   0 - 1 0 0   t r u s t   s c o r e   w i t h   f u l l   r a t i o n a l e . 
 
 
 
         T h e   a l g o r i t h m   i s   d e t e r m i n i s t i c   a n d   r u l e - b a s e d       e v e r y   p o i n t   d e l t a   i s 
 
         t r a c e d   t o   a   s p e c i f i c   s i g n a l   s o   u s e r s   c a n   a u d i t   t h e   r e s u l t . 
 
 
 
         A r g s : 
 
                 g i t h u b :   M e t a d a t a   d i c t   f r o m   f e t c h _ r e p o _ m e t a d a t a ( )   ( m a y   b e   e m p t y ) . 
 
                 p y p i :       M e t a d a t a   d i c t   f r o m   f e t c h _ p a c k a g e _ m e t a d a t a ( )   ( m a y   b e   e m p t y ) . 
 
 
 
         R e t u r n s : 
 
                 ( s c o r e ,   p o s i t i v e s ,   c o n c e r n s )   w h e r e   p o s i t i v e s / c o n c e r n s   a r e   h u m a n - r e a d a b l e   s t r i n g s . 
 
         " " " 
 
         g i t h u b   =   g i t h u b   o r   { } 
 
         p y p i   =   p y p i   o r   { } 
 
 
 
         s c o r e   =   5 0 
 
         p o s i t i v e s :   L i s t [ s t r ]   =   [ ] 
 
         c o n c e r n s :   L i s t [ s t r ]   =   [ ] 
 
 
 
         #         G i t H u b   s i g n a l s                                                                                                             
 
 
 
         s t a r s :   i n t   =   g i t h u b . g e t ( " s t a r s " ,   0 )   o r   0 
 
         i f   s t a r s   >   1 0 _ 0 0 0 : 
 
                 s c o r e   + =   1 5 
 
                 p o s i t i v e s . a p p e n d ( f " E x c e p t i o n a l   a d o p t i o n   ( { s t a r s : , }   G i t H u b   s t a r s ) " ) 
 
         e l i f   s t a r s   >   1 _ 0 0 0 : 
 
                 s c o r e   + =   1 5 
 
                 p o s i t i v e s . a p p e n d ( f " S t r o n g   a d o p t i o n   ( { s t a r s : , }   G i t H u b   s t a r s ) " ) 
 
         e l i f   s t a r s   >   1 0 0 : 
 
                 s c o r e   + =   1 0 
 
                 p o s i t i v e s . a p p e n d ( f " G o o d   a d o p t i o n   ( { s t a r s : , }   G i t H u b   s t a r s ) " ) 
 
         e l i f   s t a r s   <   5 0   a n d   g i t h u b : 
 
                 s c o r e   - =   1 0 
 
                 c o n c e r n s . a p p e n d ( f " L o w   c o m m u n i t y   a d o p t i o n   ( { s t a r s }   s t a r s ) " ) 
 
 
 
         f o r k s :   i n t   =   g i t h u b . g e t ( " f o r k s " ,   0 )   o r   0 
 
         i f   f o r k s   >   1 _ 0 0 0 : 
 
                 s c o r e   + =   5 
 
                 p o s i t i v e s . a p p e n d ( f " H i g h   d e v e l o p e r   i n t e r e s t   ( { f o r k s : , }   f o r k s ) " ) 
 
 
 
         #   M a i n t e n a n c e   a c t i v i t y 
 
         i f   g i t h u b : 
 
                 i f   i s _ r e p o _ a c t i v e ( g i t h u b ,   t h r e s h o l d _ d a y s = 9 0 ) : 
 
                         s c o r e   + =   1 5 
 
                         d   =   d a y s _ s i n c e _ l a s t _ p u s h ( g i t h u b ) 
 
                         d a y s _ s t r   =   f " { d } d   a g o "   i f   d   i s   n o t   N o n e   e l s e   " r e c e n t l y " 
 
                         p o s i t i v e s . a p p e n d ( f " A c t i v e   m a i n t e n a n c e   ( l a s t   c o m m i t   { d a y s _ s t r } ) " ) 
 
                 e l i f   i s _ r e p o _ a c t i v e ( g i t h u b ,   t h r e s h o l d _ d a y s = 3 6 5 ) : 
 
                         s c o r e   + =   5 
 
                         p o s i t i v e s . a p p e n d ( " M o d e r a t e   m a i n t e n a n c e   a c t i v i t y " ) 
 
                 e l s e : 
 
                         s c o r e   - =   2 0 
 
                         d   =   d a y s _ s i n c e _ l a s t _ p u s h ( g i t h u b ) 
 
                         d a y s _ s t r   =   f " { d }   d a y s "   i f   d   i s   n o t   N o n e   e l s e   " o v e r   a   y e a r " 
 
                         c o n c e r n s . a p p e n d ( f " N o   r e c e n t   c o m m i t s       p o s s i b l e   a b a n d o n m e n t   ( { d a y s _ s t r }   s i n c e   l a s t   p u s h ) " ) 
 
 
 
         o p e n _ i s s u e s :   i n t   =   g i t h u b . g e t ( " o p e n _ i s s u e s " ,   0 )   o r   0 
 
         i f   o p e n _ i s s u e s   >   5 0 0 : 
 
                 s c o r e   - =   1 5 
 
                 c o n c e r n s . a p p e n d ( f " H i g h   i s s u e   b a c k l o g   ( { o p e n _ i s s u e s : , }   o p e n   i s s u e s ) " ) 
 
         e l i f   o p e n _ i s s u e s   <   5 0   a n d   g i t h u b : 
 
                 s c o r e   + =   5 
 
                 p o s i t i v e s . a p p e n d ( " W e l l - m a n a g e d   i s s u e   q u e u e " ) 
 
 
 
         i f   g i t h u b . g e t ( " h a s _ s e c u r i t y _ p o l i c y " ) : 
 
                 s c o r e   + =   1 0 
 
                 p o s i t i v e s . a p p e n d ( " S e c u r i t y   p o l i c y   e n a b l e d " ) 
 
 
 
         i f   g i t h u b . g e t ( " a r c h i v e d " ) : 
 
                 s c o r e   - =   2 5 
 
                 c o n c e r n s . a p p e n d ( " R e p o s i t o r y   i s   a r c h i v e d   ( n o   l o n g e r   m a i n t a i n e d ) " ) 
 
 
 
         #         P y P I   s i g n a l s                                                                                                                 
 
 
 
         i f   p y p i . g e t ( " v e r s i o n " ) : 
 
                 s c o r e   + =   5 
 
                 p o s i t i v e s . a p p e n d ( f " A c t i v e l y   p u b l i s h e d   o n   P y P I   ( v { p y p i [ ' v e r s i o n ' ] } ) " ) 
 
 
 
         i f   p y p i . g e t ( " h a s _ s e c u r i t y _ a d v i s o r i e s " ) : 
 
                 s c o r e   - =   1 0 
 
                 c o n c e r n s . a p p e n d ( " K n o w n   s e c u r i t y   a d v i s o r i e s   o n   r e c o r d " ) 
 
 
 
         r e q _ p y t h o n   =   p y p i . g e t ( " r e q u i r e s _ p y t h o n " )   o r   " " 
 
         i f   " 3 . 1 "   i n   r e q _ p y t h o n   o r   " 3 . 2 "   i n   r e q _ p y t h o n : 
 
                 s c o r e   + =   5 
 
                 p o s i t i v e s . a p p e n d ( " M o d e r n   P y t h o n   v e r s i o n   s u p p o r t " ) 
 
 
 
         #         V u l n e r a b i l i t y   s i g n a l s   ( O S V . d e v )                                                                         
 
         i f   v u l n e r a b i l i t i e s : 
 
                 s u m m a r y   =   s u m m a r i z e _ v u l n e r a b i l i t i e s ( v u l n e r a b i l i t i e s ) 
 
                 c o u n t   =   s u m m a r y [ " c o u n t " ] 
 
                 h i g h e s t   =   s u m m a r y . g e t ( " h i g h e s t _ s e v e r i t y " )   o r   " U N K N O W N " 
 
 
 
                 #   A p p l y   p e n a l t y   f o r   h i g h e s t   s e v e r i t y 
 
                 s c o r e   + =   s e v e r i t y _ s c o r e _ i m p a c t ( h i g h e s t ) 
 
 
 
                 #   A d d i t i o n a l   p e n a l t y   i f   m a n y   v u l n s   a t   o n c e 
 
                 i f   c o u n t   >   5 : 
 
                         s c o r e   - =   5 
 
 
 
                 i f   c o u n t   = =   1 : 
 
                         c o n c e r n s . a p p e n d ( f " 1   k n o w n   v u l n e r a b i l i t y   ( { h i g h e s t . l o w e r ( ) }   s e v e r i t y ) " ) 
 
                 e l s e : 
 
                         c o n c e r n s . a p p e n d ( 
 
                                 f " { c o u n t }   k n o w n   v u l n e r a b i l i t i e s   ( h i g h e s t :   { h i g h e s t . l o w e r ( ) } ) " 
 
                         ) 
 
 
 
         #         C l a m p                                                                                                                               
 
         s c o r e   =   m a x ( 0 ,   m i n ( 1 0 0 ,   s c o r e ) ) 
 
 
 
         r e t u r n   s c o r e ,   p o s i t i v e s ,   c o n c e r n s 
 
 
 
 
 
 d e f   g e t _ t r u s t _ l a b e l ( s c o r e :   i n t )   - >   s t r : 
 
         " " " C o n v e r t   n u m e r i c   s c o r e   t o   a   h u m a n - r e a d a b l e   l a b e l . " " " 
 
         i f   s c o r e   > =   9 0 : 
 
                 r e t u r n   " E x c e l l e n t " 
 
         i f   s c o r e   > =   7 5 : 
 
                 r e t u r n   " G o o d " 
 
         i f   s c o r e   > =   6 0 : 
 
                 r e t u r n   " A c c e p t a b l e " 
 
         i f   s c o r e   > =   4 0 : 
 
                 r e t u r n   " C a u t i o n " 
 
         r e t u r n   " H i g h   R i s k " 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / u t i l s / _ _ i n i t _ _ . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " U t i l i t y   h e l p e r s :   c a c h i n g ,   f o r m a t t i n g ,   i m p o r t - t o - p a c k a g e   m a p p i n g s . " " " 
 
 
 
 f r o m   k r a i m i n d . u t i l s . m a p p i n g s   i m p o r t   I M P O R T _ T O _ P A C K A G E ,   I G N O R E _ I M P O R T S 
 
 
 
 _ _ a l l _ _   =   [ " I M P O R T _ T O _ P A C K A G E " ,   " I G N O R E _ I M P O R T S " ] 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / u t i l s / c a c h e . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " S i m p l e   f i l e s y s t e m - b a s e d   c a c h i n g   f o r   A P I   r e s p o n s e s . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   h a s h l i b 
 
 i m p o r t   j s o n 
 
 i m p o r t   t i m e 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   C a l l a b l e ,   D i c t ,   O p t i o n a l 
 
 
 
 C A C H E _ D I R   =   P a t h . h o m e ( )   /   " . k r a i m i n d "   /   " c a c h e " 
 
 
 
 
 
 d e f   _ e n s u r e _ c a c h e _ d i r ( )   - >   P a t h : 
 
         " " " C r e a t e   c a c h e   d i r e c t o r y   i f   i t   d o e s n ' t   e x i s t ;   r e t u r n   i t s   p a t h . " " " 
 
         C A C H E _ D I R . m k d i r ( p a r e n t s = T r u e ,   e x i s t _ o k = T r u e ) 
 
         r e t u r n   C A C H E _ D I R 
 
 
 
 
 
 d e f   _ c a c h e _ p a t h ( k e y :   s t r )   - >   P a t h : 
 
         " " " G e n e r a t e   a   d e t e r m i n i s t i c   c a c h e   f i l e   p a t h   f o r   a   g i v e n   k e y . " " " 
 
         c a c h e _ d i r   =   _ e n s u r e _ c a c h e _ d i r ( ) 
 
         d i g e s t   =   h a s h l i b . s h a 2 5 6 ( k e y . e n c o d e ( " u t f - 8 " ) ) . h e x d i g e s t ( ) [ : 1 6 ] 
 
         s a f e _ p r e f i x   =   " " . j o i n ( c   i f   c . i s a l n u m ( )   e l s e   " _ "   f o r   c   i n   k e y ) [ : 3 2 ] 
 
         r e t u r n   c a c h e _ d i r   /   f " { s a f e _ p r e f i x } _ { d i g e s t } . j s o n " 
 
 
 
 
 
 d e f   c a c h e d _ r e q u e s t ( 
 
         k e y :   s t r , 
 
         f e t c h _ f u n c :   C a l l a b l e [ [ ] ,   A n y ] , 
 
         t t l _ h o u r s :   f l o a t   =   2 4 . 0 , 
 
 )   - >   A n y : 
 
         " " " E x e c u t e   f e t c h _ f u n c   w i t h   f i l e s y s t e m   c a c h i n g . 
 
 
 
         A r g s : 
 
                 k e y :   U n i q u e   c a c h e   k e y   ( e . g . ,   " g i t h u b : p s f / r e q u e s t s " ) . 
 
                 f e t c h _ f u n c :   Z e r o - a r g   f u n c t i o n   t h a t   f e t c h e s   f r e s h   d a t a . 
 
                 t t l _ h o u r s :   T i m e - t o - l i v e   i n   h o u r s .   D e f a u l t   2 4 h . 
 
 
 
         R e t u r n s : 
 
                 C a c h e d   o r   f r e s h   r e s u l t   f r o m   f e t c h _ f u n c . 
 
         " " " 
 
         c a c h e _ f i l e   =   _ c a c h e _ p a t h ( k e y ) 
 
 
 
         i f   c a c h e _ f i l e . e x i s t s ( ) : 
 
                 t r y : 
 
                         w i t h   o p e n ( c a c h e _ f i l e ,   " r " ,   e n c o d i n g = " u t f - 8 " )   a s   f : 
 
                                 c a c h e d   =   j s o n . l o a d ( f ) 
 
                         a g e _ h o u r s   =   ( t i m e . t i m e ( )   -   c a c h e d [ " t i m e s t a m p " ] )   /   3 6 0 0 . 0 
 
                         i f   a g e _ h o u r s   <   t t l _ h o u r s : 
 
                                 r e t u r n   c a c h e d [ " d a t a " ] 
 
                 e x c e p t   ( j s o n . J S O N D e c o d e E r r o r ,   K e y E r r o r ,   O S E r r o r ,   T y p e E r r o r ) : 
 
                         #   C a c h e   c o r r u p t e d   o r   u n r e a d a b l e       f a l l   t h r o u g h   t o   f r e s h   f e t c h 
 
                         p a s s 
 
 
 
         r e s u l t   =   f e t c h _ f u n c ( ) 
 
 
 
         t r y : 
 
                 w i t h   o p e n ( c a c h e _ f i l e ,   " w " ,   e n c o d i n g = " u t f - 8 " )   a s   f : 
 
                         j s o n . d u m p ( { " t i m e s t a m p " :   t i m e . t i m e ( ) ,   " d a t a " :   r e s u l t } ,   f ) 
 
         e x c e p t   ( O S E r r o r ,   T y p e E r r o r ) : 
 
                 #   R e s u l t   n o t   J S O N - s e r i a l i z a b l e   o r   c a c h e   w r i t e   f a i l e d       n o n - c r i t i c a l 
 
                 p a s s 
 
 
 
         r e t u r n   r e s u l t 
 
 
 
 
 
 d e f   c l e a r _ c a c h e ( )   - >   i n t : 
 
         " " " C l e a r   a l l   c a c h e d   d a t a .   R e t u r n s   n u m b e r   o f   f i l e s   d e l e t e d . " " " 
 
         c a c h e _ d i r   =   _ e n s u r e _ c a c h e _ d i r ( ) 
 
         c o u n t   =   0 
 
         f o r   c a c h e _ f i l e   i n   c a c h e _ d i r . g l o b ( " * . j s o n " ) : 
 
                 t r y : 
 
                         c a c h e _ f i l e . u n l i n k ( ) 
 
                         c o u n t   + =   1 
 
                 e x c e p t   O S E r r o r : 
 
                         p a s s 
 
         r e t u r n   c o u n t 
 
 
 
 
 
 d e f   c a c h e _ i n f o ( )   - >   D i c t [ s t r ,   A n y ] : 
 
         " " " R e t u r n   d i a g n o s t i c   i n f o   a b o u t   t h e   c a c h e . " " " 
 
         c a c h e _ d i r   =   _ e n s u r e _ c a c h e _ d i r ( ) 
 
         f i l e s   =   l i s t ( c a c h e _ d i r . g l o b ( " * . j s o n " ) ) 
 
         t o t a l _ s i z e   =   s u m ( f . s t a t ( ) . s t _ s i z e   f o r   f   i n   f i l e s   i f   f . e x i s t s ( ) ) 
 
         r e t u r n   { 
 
                 " p a t h " :   s t r ( c a c h e _ d i r ) , 
 
                 " e n t r i e s " :   l e n ( f i l e s ) , 
 
                 " t o t a l _ b y t e s " :   t o t a l _ s i z e , 
 
         } 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / u t i l s / c o n f i g . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " P e r s i s t e n t   u s e r   c o n f i g   s t o r e d   a t   ~ / . k r a i m i n d / c o n f i g . j s o n . 
 
 
 
 P r i o r i t y   f o r   a l l   A P I   k e y s :   e n v i r o n m e n t   v a r i a b l e   >   k r a i m i n d   c o n f i g   >   u n s e t . 
 
 " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   j s o n 
 
 i m p o r t   o s 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   O p t i o n a l 
 
 
 
 C O N F I G _ F I L E   =   P a t h . h o m e ( )   /   " . k r a i m i n d "   /   " c o n f i g . j s o n " 
 
 
 
 K N O W N _ K E Y S   =   { 
 
         " G R O Q _ A P I _ K E Y " , 
 
         " O P E N A I _ A P I _ K E Y " , 
 
         " G E M I N I _ A P I _ K E Y " , 
 
         " C E R E B R A S _ A P I _ K E Y " , 
 
         " K R A I M I N D _ A P I _ U R L " , 
 
 } 
 
 
 
 
 
 d e f   _ l o a d ( )   - >   D i c t [ s t r ,   s t r ] : 
 
         i f   n o t   C O N F I G _ F I L E . e x i s t s ( ) : 
 
                 r e t u r n   { } 
 
         t r y : 
 
                 r e t u r n   j s o n . l o a d s ( C O N F I G _ F I L E . r e a d _ t e x t ( e n c o d i n g = " u t f - 8 " ) ) 
 
         e x c e p t   ( j s o n . J S O N D e c o d e E r r o r ,   O S E r r o r ) : 
 
                 r e t u r n   { } 
 
 
 
 
 
 d e f   _ s a v e ( d a t a :   D i c t [ s t r ,   s t r ] )   - >   N o n e : 
 
         C O N F I G _ F I L E . p a r e n t . m k d i r ( p a r e n t s = T r u e ,   e x i s t _ o k = T r u e ) 
 
         C O N F I G _ F I L E . w r i t e _ t e x t ( j s o n . d u m p s ( d a t a ,   i n d e n t = 2 ) ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
 
 
 d e f   g e t _ k e y ( n a m e :   s t r )   - >   O p t i o n a l [ s t r ] : 
 
         " " " R e t u r n   t h e   v a l u e   f o r   ` n a m e ` ,   c h e c k i n g   e n v   v a r   f i r s t   t h e n   c o n f i g   f i l e . " " " 
 
         e n v _ v a l   =   o s . g e t e n v ( n a m e ) 
 
         i f   e n v _ v a l : 
 
                 r e t u r n   e n v _ v a l 
 
         r e t u r n   _ l o a d ( ) . g e t ( n a m e ) 
 
 
 
 
 
 d e f   s e t _ k e y ( n a m e :   s t r ,   v a l u e :   s t r )   - >   N o n e : 
 
         d a t a   =   _ l o a d ( ) 
 
         d a t a [ n a m e ]   =   v a l u e 
 
         _ s a v e ( d a t a ) 
 
 
 
 
 
 d e f   u n s e t _ k e y ( n a m e :   s t r )   - >   b o o l : 
 
         " " " R e m o v e   a   k e y   f r o m   c o n f i g .   R e t u r n s   T r u e   i f   i t   e x i s t e d . " " " 
 
         d a t a   =   _ l o a d ( ) 
 
         i f   n a m e   n o t   i n   d a t a : 
 
                 r e t u r n   F a l s e 
 
         d e l   d a t a [ n a m e ] 
 
         _ s a v e ( d a t a ) 
 
         r e t u r n   T r u e 
 
 
 
 
 
 d e f   l i s t _ k e y s ( )   - >   D i c t [ s t r ,   s t r ] : 
 
         " " " R e t u r n   a l l   s t o r e d   c o n f i g   k e y s   ( v a l u e s   m a s k e d ) . " " " 
 
         r e t u r n   _ l o a d ( ) 
 
 
 
 
 
 d e f   c o n f i g _ p a t h ( )   - >   P a t h : 
 
         r e t u r n   C O N F I G _ F I L E 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / u t i l s / f o r m a t t i n g . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " R i c h   c o n s o l e   f o r m a t t i n g   h e l p e r s   f o r   c o n s i s t e n t   t e r m i n a l   U I . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 f r o m   t y p i n g   i m p o r t   A n y ,   D i c t ,   L i s t ,   O p t i o n a l ,   S e t 
 
 
 
 f r o m   r i c h . c o n s o l e   i m p o r t   G r o u p 
 
 f r o m   r i c h . p a n e l   i m p o r t   P a n e l 
 
 f r o m   r i c h . t a b l e   i m p o r t   T a b l e 
 
 f r o m   r i c h . t e x t   i m p o r t   T e x t 
 
 
 
 #   C o l o r / s t y l e   s y s t e m   u s e d   t h r o u g h o u t   K r a i m i n d 
 
 S T Y L E S   =   { 
 
         " s u c c e s s " :   " b o l d   g r e e n " , 
 
         " w a r n i n g " :   " b o l d   y e l l o w " , 
 
         " e r r o r " :   " b o l d   r e d " , 
 
         " i n f o " :   " b o l d   b l u e " , 
 
         " m u t e d " :   " g r e y 5 0 " , 
 
         " p a c k a g e " :   " b o l d   c y a n " , 
 
         " s c o r e _ h i g h " :   " g r e e n " , 
 
         " s c o r e _ m e d " :   " y e l l o w " , 
 
         " s c o r e _ l o w " :   " r e d " , 
 
         " h e a d e r " :   " b o l d   m a g e n t a " , 
 
         " a c c e n t " :   " b o l d   c y a n " , 
 
 } 
 
 
 
 
 
 d e f   s c o r e _ c o l o r ( s c o r e :   i n t )   - >   s t r : 
 
         " " " R e t u r n   t h e   R i c h   c o l o r   n a m e   a p p r o p r i a t e   f o r   a   t r u s t   s c o r e . " " " 
 
         i f   s c o r e   > =   7 5 : 
 
                 r e t u r n   " g r e e n " 
 
         i f   s c o r e   > =   5 0 : 
 
                 r e t u r n   " y e l l o w " 
 
         r e t u r n   " r e d " 
 
 
 
 
 
 d e f   s c o r e _ l a b e l ( s c o r e :   i n t )   - >   s t r : 
 
         " " " H u m a n - r e a d a b l e   l a b e l   f o r   a   t r u s t   s c o r e . " " " 
 
         i f   s c o r e   > =   9 0 : 
 
                 r e t u r n   " E x c e l l e n t " 
 
         i f   s c o r e   > =   7 5 : 
 
                 r e t u r n   " G o o d " 
 
         i f   s c o r e   > =   6 0 : 
 
                 r e t u r n   " A c c e p t a b l e " 
 
         i f   s c o r e   > =   4 0 : 
 
                 r e t u r n   " C a u t i o n " 
 
         r e t u r n   " H i g h   R i s k " 
 
 
 
 
 
 d e f   s c o r e _ b a r ( s c o r e :   i n t ,   w i d t h :   i n t   =   2 0 )   - >   s t r : 
 
         " " " G e n e r a t e   a   u n i c o d e   p r o g r e s s   b a r   f o r   a   0 - 1 0 0   s c o r e . " " " 
 
         s c o r e   =   m a x ( 0 ,   m i n ( 1 0 0 ,   s c o r e ) ) 
 
         f i l l e d   =   i n t ( r o u n d ( ( s c o r e   /   1 0 0 . 0 )   *   w i d t h ) ) 
 
         e m p t y   =   w i d t h   -   f i l l e d 
 
         r e t u r n   "   "   *   f i l l e d   +   "   "   *   e m p t y 
 
 
 
 
 
 d e f   f o r m a t _ s c o r e _ l i n e ( s c o r e :   i n t )   - >   T e x t : 
 
         " " " R e n d e r   a   c o l o r f u l   o n e - l i n e   s c o r e   w i t h   b a r   a n d   l a b e l . " " " 
 
         c o l o r   =   s c o r e _ c o l o r ( s c o r e ) 
 
         l a b e l   =   s c o r e _ l a b e l ( s c o r e ) 
 
         t e x t   =   T e x t ( ) 
 
         t e x t . a p p e n d ( " T r u s t   S c o r e :   " ,   s t y l e = " b o l d " ) 
 
         t e x t . a p p e n d ( f " { s c o r e } / 1 0 0   " ,   s t y l e = f " b o l d   { c o l o r } " ) 
 
         t e x t . a p p e n d ( s c o r e _ b a r ( s c o r e ) ,   s t y l e = c o l o r ) 
 
         t e x t . a p p e n d ( f "     [ { l a b e l } ] " ,   s t y l e = f " b o l d   { c o l o r } " ) 
 
         r e t u r n   t e x t 
 
 
 
 
 
 d e f   f o r m a t _ u n u s e d _ d e p s ( u n u s e d :   S e t [ s t r ] ,   r e p o r t s :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] )   - >   P a n e l : 
 
         " " " F o r m a t   a   p a n e l   s u m m a r i z i n g   u n u s e d   d e p e n d e n c i e s   w i t h   q u i c k - f i x   h i n t . " " " 
 
         i f   n o t   u n u s e d : 
 
                 r e t u r n   P a n e l ( 
 
                         T e x t ( "     N o   u n u s e d   d e p e n d e n c i e s   d e t e c t e d ! " ,   s t y l e = S T Y L E S [ " s u c c e s s " ] ) , 
 
                         t i t l e = " [ b o l d ] U n u s e d   D e p e n d e n c i e s [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e e n " , 
 
                         p a d d i n g = ( 1 ,   2 ) , 
 
                 ) 
 
 
 
         b o d y   =   T e x t ( ) 
 
         b o d y . a p p e n d ( " a"    U n u s e d   d e p e n d e n c i e s   f o u n d : \ n \ n " ,   s t y l e = " b o l d   y e l l o w " ) 
 
         f o r   p k g   i n   s o r t e d ( u n u s e d ) : 
 
                 b o d y . a p p e n d ( "         " ,   s t y l e = " y e l l o w " ) 
 
                 b o d y . a p p e n d ( f " { p k g } " ,   s t y l e = S T Y L E S [ " p a c k a g e " ] ) 
 
                 i n f o   =   r e p o r t s . g e t ( p k g ,   { } )   i f   r e p o r t s   e l s e   { } 
 
                 p y p i   =   ( i n f o . g e t ( " p y p i " )   o r   { } )   i f   i n f o   e l s e   { } 
 
                 s u m m a r y   =   p y p i . g e t ( " s u m m a r y " )   i f   p y p i   e l s e   N o n e 
 
                 i f   s u m m a r y : 
 
                         s h o r t   =   s u m m a r y [ : 6 0 ]   +   ( "   "   i f   l e n ( s u m m a r y )   >   6 0   e l s e   " " ) 
 
                         b o d y . a p p e n d ( f "         { s h o r t } " ,   s t y l e = " g r e y 5 0 " ) 
 
                 b o d y . a p p e n d ( " \ n " ) 
 
 
 
         b o d y . a p p e n d ( " \ n a"    Q u i c k   f i x : \ n " ,   s t y l e = " b o l d   c y a n " ) 
 
         p k g _ l i s t   =   "   " . j o i n ( s o r t e d ( u n u s e d ) ) 
 
         b o d y . a p p e n d ( f "     p i p   u n i n s t a l l   { p k g _ l i s t } \ n " ,   s t y l e = " b o l d " ) 
 
 
 
         r e t u r n   P a n e l ( 
 
                 b o d y , 
 
                 t i t l e = " [ b o l d ] a" c%  U n u s e d   D e p e n d e n c i e s [ / ] " , 
 
                 b o r d e r _ s t y l e = " y e l l o w " , 
 
                 p a d d i n g = ( 1 ,   2 ) , 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ t r u s t _ r e p o r t ( r e p o r t s :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] )   - >   P a n e l : 
 
         " " " F o r m a t   a   R i c h   T a b l e   s u m m a r i z i n g   t r u s t   s c o r e s   f o r   a l l   d e p e n d e n c i e s . " " " 
 
         i f   n o t   r e p o r t s : 
 
                 r e t u r n   P a n e l ( 
 
                         T e x t ( " N o   d e p e n d e n c i e s   a n a l y z e d . " ,   s t y l e = S T Y L E S [ " m u t e d " ] ) , 
 
                         t i t l e = " [ b o l d ] T r u s t   R e p o r t [ / ] " , 
 
                         b o r d e r _ s t y l e = " g r e y 5 0 " , 
 
                 ) 
 
 
 
         t a b l e   =   T a b l e ( 
 
                 s h o w _ h e a d e r = T r u e , 
 
                 h e a d e r _ s t y l e = " b o l d   m a g e n t a " , 
 
                 b o r d e r _ s t y l e = " c y a n " , 
 
                 e x p a n d = T r u e , 
 
                 p a d d i n g = ( 0 ,   1 ) , 
 
         ) 
 
         t a b l e . a d d _ c o l u m n ( " P a c k a g e " ,   s t y l e = " b o l d   c y a n " ,   n o _ w r a p = T r u e ) 
 
         t a b l e . a d d _ c o l u m n ( " S c o r e " ,   j u s t i f y = " c e n t e r " ,   n o _ w r a p = T r u e ) 
 
         t a b l e . a d d _ c o l u m n ( " B a r " ,   j u s t i f y = " l e f t " ,   n o _ w r a p = T r u e ) 
 
         t a b l e . a d d _ c o l u m n ( " L a b e l " ,   j u s t i f y = " l e f t " ,   n o _ w r a p = T r u e ) 
 
         t a b l e . a d d _ c o l u m n ( " T o p   S i g n a l " ,   s t y l e = " g r e y 7 0 " ,   o v e r f l o w = " f o l d " ) 
 
 
 
         f o r   p k g   i n   s o r t e d ( r e p o r t s . k e y s ( ) ) : 
 
                 r e p o r t   =   r e p o r t s [ p k g ] 
 
                 s c o r e   =   r e p o r t . g e t ( " s c o r e " ,   0 ) 
 
                 p o s i t i v e s   =   r e p o r t . g e t ( " p o s i t i v e s " )   o r   [ ] 
 
                 c o n c e r n s   =   r e p o r t . g e t ( " c o n c e r n s " )   o r   [ ] 
 
                 s i g n a l   =   " " 
 
                 i f   s c o r e   > =   6 0   a n d   p o s i t i v e s : 
 
                         s i g n a l   =   p o s i t i v e s [ 0 ] 
 
                 e l i f   c o n c e r n s : 
 
                         s i g n a l   =   c o n c e r n s [ 0 ] 
 
                 e l i f   p o s i t i v e s : 
 
                         s i g n a l   =   p o s i t i v e s [ 0 ] 
 
 
 
                 c o l o r   =   s c o r e _ c o l o r ( s c o r e ) 
 
                 t a b l e . a d d _ r o w ( 
 
                         p k g , 
 
                         T e x t ( f " { s c o r e } / 1 0 0 " ,   s t y l e = f " b o l d   { c o l o r } " ) , 
 
                         T e x t ( s c o r e _ b a r ( s c o r e ,   w i d t h = 1 4 ) ,   s t y l e = c o l o r ) , 
 
                         T e x t ( s c o r e _ l a b e l ( s c o r e ) ,   s t y l e = c o l o r ) , 
 
                         s i g n a l , 
 
                 ) 
 
 
 
         r e t u r n   P a n e l ( 
 
                 t a b l e , 
 
                 t i t l e = " [ b o l d ] a"  )"U%     T r u s t   R e p o r t [ / ] " , 
 
                 b o r d e r _ s t y l e = " c y a n " , 
 
                 p a d d i n g = ( 1 ,   1 ) , 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ p a c k a g e _ d e t a i l ( 
 
         p a c k a g e :   s t r , 
 
         s c o r e :   i n t , 
 
         p o s i t i v e s :   L i s t [ s t r ] , 
 
         c o n c e r n s :   L i s t [ s t r ] , 
 
         p y p i :   D i c t [ s t r ,   A n y ] , 
 
         g i t h u b :   D i c t [ s t r ,   A n y ] , 
 
 )   - >   P a n e l : 
 
         " " " F o r m a t   d e t a i l e d   r e p o r t   f o r   a   s i n g l e   p a c k a g e . " " " 
 
         p y p i   =   p y p i   o r   { } 
 
         g i t h u b   =   g i t h u b   o r   { } 
 
 
 
         p a r t s :   L i s t [ A n y ]   =   [ ] 
 
 
 
         #   H e a d e r   l i n e :   p a c k a g e   +   v e r s i o n   +   s c o r e 
 
         h e a d e r   =   T e x t ( ) 
 
         h e a d e r . a p p e n d ( f " { p a c k a g e } " ,   s t y l e = S T Y L E S [ " p a c k a g e " ] ) 
 
         i f   p y p i . g e t ( " v e r s i o n " ) : 
 
                 h e a d e r . a p p e n d ( f "     v { p y p i [ ' v e r s i o n ' ] } " ,   s t y l e = " b o l d   w h i t e " ) 
 
         i f   p y p i . g e t ( " s u m m a r y " ) : 
 
                 h e a d e r . a p p e n d ( f " \ n { p y p i [ ' s u m m a r y ' ] } " ,   s t y l e = " g r e y 7 0 " ) 
 
         p a r t s . a p p e n d ( h e a d e r ) 
 
 
 
         p a r t s . a p p e n d ( T e x t ( " " ) ) 
 
         p a r t s . a p p e n d ( f o r m a t _ s c o r e _ l i n e ( s c o r e ) ) 
 
 
 
         #   M e t a d a t a   t a b l e 
 
         m e t a   =   T a b l e . g r i d ( p a d d i n g = ( 0 ,   2 ) ) 
 
         m e t a . a d d _ c o l u m n ( s t y l e = " b o l d " ) 
 
         m e t a . a d d _ c o l u m n ( ) 
 
         i f   g i t h u b . g e t ( " s t a r s " )   i s   n o t   N o n e : 
 
                 m e t a . a d d _ r o w ( "     S t a r s : " ,   f " { g i t h u b . g e t ( ' s t a r s ' ,   0 ) : , } " ) 
 
         i f   g i t h u b . g e t ( " f o r k s " )   i s   n o t   N o n e : 
 
                 m e t a . a d d _ r o w ( " a" $%  F o r k s : " ,   f " { g i t h u b . g e t ( ' f o r k s ' ,   0 ) : , } " ) 
 
         i f   g i t h u b . g e t ( " o p e n _ i s s u e s " )   i s   n o t   N o n e : 
 
                 m e t a . a d d _ r o w ( " a"    O p e n   i s s u e s : " ,   f " { g i t h u b . g e t ( ' o p e n _ i s s u e s ' ,   0 ) : , } " ) 
 
         i f   g i t h u b . g e t ( " l a n g u a g e " ) : 
 
                 m e t a . a d d _ r o w ( " a" W%  L a n g u a g e : " ,   s t r ( g i t h u b . g e t ( " l a n g u a g e " ) ) ) 
 
         i f   p y p i . g e t ( " l i c e n s e " ) : 
 
                 m e t a . a d d _ r o w ( " a"    L i c e n s e : " ,   s t r ( p y p i . g e t ( " l i c e n s e " ) ) [ : 5 0 ] ) 
 
         i f   p y p i . g e t ( " r e q u i r e s _ p y t h o n " ) : 
 
                 m e t a . a d d _ r o w ( " a"    P y t h o n : " ,   s t r ( p y p i . g e t ( " r e q u i r e s _ p y t h o n " ) ) ) 
 
         i f   g i t h u b . g e t ( " l a s t _ p u s h " ) : 
 
                 m e t a . a d d _ r o w ( " a"    L a s t   p u s h : " ,   s t r ( g i t h u b . g e t ( " l a s t _ p u s h " ,   " " ) ) [ : 1 0 ] ) 
 
         i f   g i t h u b . g e t ( " h t m l _ u r l " ) : 
 
                 m e t a . a d d _ r o w ( " a"    R e p o : " ,   s t r ( g i t h u b . g e t ( " h t m l _ u r l " ) ) ) 
 
 
 
         p a r t s . a p p e n d ( T e x t ( " " ) ) 
 
         p a r t s . a p p e n d ( m e t a ) 
 
 
 
         #   P o s i t i v e s 
 
         i f   p o s i t i v e s : 
 
                 p a r t s . a p p e n d ( T e x t ( " " ) ) 
 
                 p o s _ t e x t   =   T e x t ( ) 
 
                 p o s _ t e x t . a p p e n d ( "     P o s i t i v e   s i g n a l s : \ n " ,   s t y l e = S T Y L E S [ " s u c c e s s " ] ) 
 
                 f o r   i t e m   i n   p o s i t i v e s : 
 
                         p o s _ t e x t . a p p e n d ( f "         { i t e m } \ n " ) 
 
                 p a r t s . a p p e n d ( p o s _ t e x t ) 
 
 
 
         #   C o n c e r n s 
 
         i f   c o n c e r n s : 
 
                 c o n _ t e x t   =   T e x t ( ) 
 
                 c o n _ t e x t . a p p e n d ( "   )"U%     C o n c e r n s : \ n " ,   s t y l e = S T Y L E S [ " w a r n i n g " ] ) 
 
                 f o r   i t e m   i n   c o n c e r n s : 
 
                         c o n _ t e x t . a p p e n d ( f "         { i t e m } \ n " ) 
 
                 p a r t s . a p p e n d ( c o n _ t e x t ) 
 
 
 
         c o l o r   =   s c o r e _ c o l o r ( s c o r e ) 
 
         r e t u r n   P a n e l ( 
 
                 G r o u p ( * p a r t s ) , 
 
                 t i t l e = f " [ b o l d ] a"    { p a c k a g e } [ / ] " , 
 
                 b o r d e r _ s t y l e = c o l o r , 
 
                 p a d d i n g = ( 1 ,   2 ) , 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ h e a l t h _ s u m m a r y ( 
 
         d e c l a r e d :   S e t [ s t r ] , 
 
         u n u s e d :   S e t [ s t r ] , 
 
         r e p o r t s :   D i c t [ s t r ,   D i c t [ s t r ,   A n y ] ] , 
 
 )   - >   P a n e l : 
 
         " " " A g g r e g a t e   h e a l t h   s u m m a r y   p a n e l   f o r   t h e   d o c t o r   c o m m a n d . " " " 
 
         t o t a l   =   l e n ( d e c l a r e d ) 
 
         u s e d   =   t o t a l   -   l e n ( u n u s e d ) 
 
         i f   r e p o r t s : 
 
                 a v g _ s c o r e   =   s u m ( r . g e t ( " s c o r e " ,   0 )   f o r   r   i n   r e p o r t s . v a l u e s ( ) )   /   m a x ( l e n ( r e p o r t s ) ,   1 ) 
 
         e l s e : 
 
                 a v g _ s c o r e   =   0 . 0 
 
 
 
         l o w   =   s u m ( 1   f o r   r   i n   r e p o r t s . v a l u e s ( )   i f   r . g e t ( " s c o r e " ,   0 )   <   5 0 ) 
 
         m e d   =   s u m ( 1   f o r   r   i n   r e p o r t s . v a l u e s ( )   i f   5 0   < =   r . g e t ( " s c o r e " ,   0 )   <   7 5 ) 
 
         h i g h   =   s u m ( 1   f o r   r   i n   r e p o r t s . v a l u e s ( )   i f   r . g e t ( " s c o r e " ,   0 )   > =   7 5 ) 
 
 
 
         s u m m a r y   =   T a b l e . g r i d ( p a d d i n g = ( 0 ,   2 ) ) 
 
         s u m m a r y . a d d _ c o l u m n ( s t y l e = " b o l d " ) 
 
         s u m m a r y . a d d _ c o l u m n ( ) 
 
         s u m m a r y . a d d _ r o w ( " a"    T o t a l   d e p e n d e n c i e s : " ,   f " { t o t a l } " ) 
 
         s u m m a r y . a d d _ r o w ( "     I n   u s e : " ,   f " [ g r e e n ] { u s e d } [ / ] " ) 
 
         s u m m a r y . a d d _ r o w ( " a" c%  U n u s e d : " ,   f " [ y e l l o w ] { l e n ( u n u s e d ) } [ / ] "   i f   u n u s e d   e l s e   " [ g r e e n ] 0 [ / ] " ) 
 
         s u m m a r y . a d d _ r o w ( " a"    A v e r a g e   t r u s t : " ,   f " [ { s c o r e _ c o l o r ( i n t ( a v g _ s c o r e ) ) } ] { a v g _ s c o r e : . 1 f } / 1 0 0 [ / ] " ) 
 
         s u m m a r y . a d d _ r o w ( " a"   H i g h - t r u s t : " ,   f " { h i g h } " ) 
 
         s u m m a r y . a d d _ r o w ( " a"   M e d i u m - t r u s t : " ,   f " { m e d } " ) 
 
         s u m m a r y . a d d _ r o w ( " a" $%  L o w - t r u s t : " ,   f " { l o w } " ) 
 
 
 
         c o l o r   =   s c o r e _ c o l o r ( i n t ( a v g _ s c o r e ) ) 
 
         r e t u r n   P a n e l ( 
 
                 s u m m a r y , 
 
                 t i t l e = " [ b o l d ] a"#Q%  P r o j e c t   H e a l t h [ / ] " , 
 
                 b o r d e r _ s t y l e = c o l o r , 
 
                 p a d d i n g = ( 1 ,   2 ) , 
 
         ) 
 
 
 
 
 
 d e f   p r i n t _ a n i m a t e d _ b a n n e r ( c o n s o l e )   - >   N o n e : 
 
         " " " P r i n t   a n   a n i m a t e d   w e l c o m e   b a n n e r   w i t h   a   b l i n k i n g   a g e n t . " " " 
 
         f r o m   r i c h . l i v e   i m p o r t   L i v e 
 
         i m p o r t   t i m e 
 
 
 
         d e f   g e t _ p a n e l ( e y e s :   s t r )   - >   P a n e l : 
 
                 a r t   =   f " " "                 W e l c o m e   b a c k . 
 
 
 
                                                         
 
                                               (   { e y e s }   ) 
 
                                                  %      
 
                                              %         %
 
                                                %   %
 
 
 
                                   B u i l d   a n y t h i n g " " " 
 
                 
 
                 t e x t   =   T e x t ( ) 
 
                 t e x t . a p p e n d ( a r t ,   s t y l e = " b o l d   c y a n " ) 
 
                 
 
                 r e t u r n   P a n e l ( 
 
                         t e x t ,   
 
                         t i t l e = " [ b o l d   c y a n ] K r a i M i n d [ / b o l d   c y a n ]   b y   [ b o l d   m a g e n t a ] K r a i o n y x   A I [ / b o l d   m a g e n t a ]       U n d e r s t a n d .   O p t i m i z e .   T r u s t . " ,   
 
                         s u b t i t l e = " C o p y r i g h t   K r a i o n y x   A I " , 
 
                         s u b t i t l e _ a l i g n = " r i g h t " , 
 
                         b o r d e r _ s t y l e = " c y a n " ,   
 
                         p a d d i n g = ( 1 ,   2 ) 
 
                 ) 
 
 
 
         w i t h   L i v e ( g e t _ p a n e l ( "     " ) ,   c o n s o l e = c o n s o l e ,   r e f r e s h _ p e r _ s e c o n d = 1 0 ,   t r a n s i e n t = F a l s e )   a s   l i v e : 
 
                 t i m e . s l e e p ( 0 . 5 ) 
 
                 
 
                 #   B l i n k   1 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 1 5 ) 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 8 ) 
 
                 
 
                 #   B l i n k   2   ( q u i c k   d o u b l e   b l i n k ) 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 1 ) 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 1 ) 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 1 ) 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 1 . 2 ) 
 
                 
 
                 #   B l i n k   3 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 2 ) 
 
                 l i v e . u p d a t e ( g e t _ p a n e l ( "     " ) ) 
 
                 t i m e . s l e e p ( 0 . 4 ) 
 
 
 
 d e f   b a n n e r ( )   - >   P a n e l : 
 
         " " " W e l c o m e   b a n n e r   p a n e l . " " " 
 
         #   B u i l d   t h e   r e q u i r e d   A S C I I   a r t   a n d   f o r m a t t i n g 
 
         a r t   =   " " "                 W e l c o m e   b a c k . 
 
 
 
                                                         
 
                                               (         ) 
 
                                                  %      
 
                                              %         %
 
                                                %   %
 
 
 
                                   B u i l d   a n y t h i n g " " " 
 
         
 
         t e x t   =   T e x t ( ) 
 
         t e x t . a p p e n d ( a r t ,   s t y l e = " b o l d   c y a n " ) 
 
         
 
         r e t u r n   P a n e l ( 
 
                 t e x t ,   
 
                 t i t l e = " [ b o l d   c y a n ] K r a i M i n d [ / b o l d   c y a n ]   b y   [ b o l d   m a g e n t a ] K r a i o n y x   A I [ / b o l d   m a g e n t a ]       U n d e r s t a n d .   O p t i m i z e .   T r u s t . " ,   
 
                 s u b t i t l e = " C o p y r i g h t   K r a i o n y x   A I " , 
 
                 s u b t i t l e _ a l i g n = " r i g h t " , 
 
                 b o r d e r _ s t y l e = " c y a n " ,   
 
                 p a d d i n g = ( 1 ,   2 ) 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ s i z e ( n u m _ b y t e s :   i n t )   - >   s t r : 
 
         " " " H u m a n - r e a d a b l e   f i l e   s i z e . " " " 
 
         i f   n u m _ b y t e s   < =   0 : 
 
                 r e t u r n   "   " 
 
         u n i t s   =   [ " B " ,   " K B " ,   " M B " ,   " G B " ] 
 
         s i z e   =   f l o a t ( n u m _ b y t e s ) 
 
         f o r   u n i t   i n   u n i t s : 
 
                 i f   s i z e   <   1 0 2 4 . 0   o r   u n i t   = =   u n i t s [ - 1 ] : 
 
                         r e t u r n   f " { s i z e : . 1 f }   { u n i t } "   i f   u n i t   ! =   " B "   e l s e   f " { i n t ( s i z e ) }   { u n i t } " 
 
                 s i z e   / =   1 0 2 4 . 0 
 
         r e t u r n   "   "     #   u n r e a c h a b l e   b u t   s a t i s f i e s   t y p e   c h e c k e r 
 
 
 
 
 
 d e f   f o r m a t _ v u l n e r a b i l i t i e s ( v u l n s :   L i s t [ D i c t [ s t r ,   A n y ] ] )   - >   O p t i o n a l [ P a n e l ] : 
 
         " " " F o r m a t   a   v u l n e r a b i l i t y   l i s t   a s   a   p a n e l ;   N o n e   i f   n o   v u l n s . " " " 
 
         i f   n o t   v u l n s : 
 
                 r e t u r n   N o n e 
 
 
 
         s e v _ s t y l e s   =   { 
 
                 " C R I T I C A L " :   " b o l d   r e d " , 
 
                 " H I G H " :   " r e d " , 
 
                 " M E D I U M " :   " y e l l o w " , 
 
                 " L O W " :   " b l u e " , 
 
                 " U N K N O W N " :   " g r e y 5 0 " , 
 
         } 
 
 
 
         b o d y   =   T e x t ( ) 
 
         f o r   v   i n   v u l n s [ : 8 ] :     #   c a p   a t   8   f o r   d i s p l a y 
 
                 s e v   =   ( v . g e t ( " s e v e r i t y " )   o r   " U N K N O W N " ) . u p p e r ( ) 
 
                 s t y l e   =   s e v _ s t y l e s . g e t ( s e v ,   " g r e y 5 0 " ) 
 
                 b o d y . a p p e n d ( f "         { s e v : 8 s }   " ,   s t y l e = s t y l e ) 
 
                 b o d y . a p p e n d ( f " { v . g e t ( ' i d ' ,   ' u n k n o w n ' ) } " ,   s t y l e = " b o l d " ) 
 
                 s u m m a r y   =   v . g e t ( " s u m m a r y " )   o r   " " 
 
                 i f   s u m m a r y : 
 
                         s h o r t   =   s u m m a r y [ : 8 0 ]   +   ( "   "   i f   l e n ( s u m m a r y )   >   8 0   e l s e   " " ) 
 
                         b o d y . a p p e n d ( f " \ n         { s h o r t } " ,   s t y l e = " g r e y 7 0 " ) 
 
                 f i x e d   =   v . g e t ( " f i x e d _ v e r s i o n s " )   o r   [ ] 
 
                 i f   f i x e d : 
 
                         b o d y . a p p e n d ( f " \ n         F i x e d   i n :   { ' ,   ' . j o i n ( f i x e d [ : 3 ] ) } " ,   s t y l e = " c y a n " ) 
 
                 b o d y . a p p e n d ( " \ n \ n " ) 
 
 
 
         i f   l e n ( v u l n s )   >   8 : 
 
                 b o d y . a p p e n d ( f "       a n d   { l e n ( v u l n s )   -   8 }   m o r e . \ n " ,   s t y l e = " g r e y 5 0 " ) 
 
 
 
         r e t u r n   P a n e l ( 
 
                 b o d y , 
 
                 t i t l e = f " [ b o l d   r e d ] a"    V u l n e r a b i l i t i e s   ( { l e n ( v u l n s ) } ) [ / ] " , 
 
                 b o r d e r _ s t y l e = " r e d " , 
 
                 p a d d i n g = ( 1 ,   2 ) , 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ a l t e r n a t i v e s ( p a c k a g e :   s t r ,   e n t r y :   D i c t [ s t r ,   A n y ] )   - >   O p t i o n a l [ P a n e l ] : 
 
         " " " F o r m a t   a n   a l t e r n a t i v e s   r e c o m m e n d a t i o n   a s   a   p a n e l . " " " 
 
         i f   n o t   e n t r y : 
 
                 r e t u r n   N o n e 
 
 
 
         s e v e r i t y _ c o l o r   =   { 
 
                 " d e p r e c a t e d " :   " r e d " , 
 
                 " s u g g e s t " :   " y e l l o w " , 
 
                 " i n f o " :   " b l u e " , 
 
         } . g e t ( e n t r y . g e t ( " s e v e r i t y " ,   " i n f o " ) ,   " b l u e " ) 
 
 
 
         s e v e r i t y _ e m o j i   =   { 
 
                 " d e p r e c a t e d " :   "   " , 
 
                 " s u g g e s t " :   " a"  " , 
 
                 " i n f o " :   " a"  " , 
 
         } . g e t ( e n t r y . g e t ( " s e v e r i t y " ,   " i n f o " ) ,   " a"  " ) 
 
 
 
         b o d y   =   T e x t ( ) 
 
         b o d y . a p p e n d ( f " { e n t r y . g e t ( ' r e a s o n ' ,   ' ' ) } \ n \ n " ,   s t y l e = " b o l d " ) 
 
         b o d y . a p p e n d ( " C o n s i d e r : \ n " ,   s t y l e = " b o l d   c y a n " ) 
 
         f o r   a l t   i n   e n t r y . g e t ( " a l t e r n a t i v e s " ,   [ ] ) : 
 
                 e f f o r t   =   a l t . g e t ( " m i g r a t i o n _ e f f o r t " ,   " u n k n o w n " ) 
 
                 e f f o r t _ s t y l e   =   { " l o w " :   " g r e e n " ,   " m e d i u m " :   " y e l l o w " ,   " h i g h " :   " r e d " } . g e t ( e f f o r t ,   " g r e y 5 0 " ) 
 
                 b o d y . a p p e n d ( f "         " ,   s t y l e = " c y a n " ) 
 
                 b o d y . a p p e n d ( f " { a l t [ ' n a m e ' ] } " ,   s t y l e = " b o l d   c y a n " ) 
 
                 b o d y . a p p e n d ( f "     [ { e f f o r t }   e f f o r t ] \ n " ,   s t y l e = e f f o r t _ s t y l e ) 
 
                 b o d y . a p p e n d ( f "           { a l t . g e t ( ' r e a s o n ' ,   ' ' ) } \ n " ,   s t y l e = " g r e y 7 0 " ) 
 
 
 
         r e t u r n   P a n e l ( 
 
                 b o d y , 
 
                 t i t l e = f " [ b o l d ] { s e v e r i t y _ e m o j i }   A l t e r n a t i v e s   f o r   { p a c k a g e } [ / ] " , 
 
                 b o r d e r _ s t y l e = s e v e r i t y _ c o l o r , 
 
                 p a d d i n g = ( 1 ,   2 ) , 
 
         ) 
 
 
 
 
 
 d e f   f o r m a t _ c o m p a r e ( p k g _ a :   s t r ,   r e p o r t _ a :   D i c t [ s t r ,   A n y ] ,   p k g _ b :   s t r ,   r e p o r t _ b :   D i c t [ s t r ,   A n y ] )   - >   T a b l e : 
 
         " " " S i d e - b y - s i d e   c o m p a r i s o n   t a b l e   f o r   t w o   p a c k a g e s . " " " 
 
         p a   =   r e p o r t _ a . g e t ( " p y p i " )   o r   { } 
 
         p b   =   r e p o r t _ b . g e t ( " p y p i " )   o r   { } 
 
         g a   =   r e p o r t _ a . g e t ( " g i t h u b " )   o r   { } 
 
         g b   =   r e p o r t _ b . g e t ( " g i t h u b " )   o r   { } 
 
 
 
         t a b l e   =   T a b l e ( 
 
                 t i t l e = f " [ b o l d   c y a n ] { p k g _ a } [ / ]     v s     [ b o l d   m a g e n t a ] { p k g _ b } [ / ] " , 
 
                 s h o w _ h e a d e r = T r u e , 
 
                 h e a d e r _ s t y l e = " b o l d " , 
 
                 b o r d e r _ s t y l e = " c y a n " , 
 
                 e x p a n d = T r u e , 
 
         ) 
 
         t a b l e . a d d _ c o l u m n ( " M e t r i c " ,   s t y l e = " b o l d " ,   n o _ w r a p = T r u e ) 
 
         t a b l e . a d d _ c o l u m n ( p k g _ a ,   s t y l e = " c y a n " ,   j u s t i f y = " r i g h t " ) 
 
         t a b l e . a d d _ c o l u m n ( p k g _ b ,   s t y l e = " m a g e n t a " ,   j u s t i f y = " r i g h t " ) 
 
 
 
         s c o r e _ a   =   r e p o r t _ a . g e t ( " s c o r e " ,   0 ) 
 
         s c o r e _ b   =   r e p o r t _ b . g e t ( " s c o r e " ,   0 ) 
 
 
 
         t a b l e . a d d _ r o w ( 
 
                 " T r u s t   S c o r e " , 
 
                 T e x t ( f " { s c o r e _ a } / 1 0 0 " ,   s t y l e = f " b o l d   { s c o r e _ c o l o r ( s c o r e _ a ) } " ) , 
 
                 T e x t ( f " { s c o r e _ b } / 1 0 0 " ,   s t y l e = f " b o l d   { s c o r e _ c o l o r ( s c o r e _ b ) } " ) , 
 
         ) 
 
         t a b l e . a d d _ r o w ( " L a t e s t   V e r s i o n " ,   s t r ( p a . g e t ( " v e r s i o n " ,   "   " ) ) ,   s t r ( p b . g e t ( " v e r s i o n " ,   "   " ) ) ) 
 
         t a b l e . a d d _ r o w ( 
 
                 " G i t H u b   S t a r s " , 
 
                 f " { g a . g e t ( ' s t a r s ' ,   0 ) : , } "   i f   g a . g e t ( " s t a r s " )   e l s e   "   " , 
 
                 f " { g b . g e t ( ' s t a r s ' ,   0 ) : , } "   i f   g b . g e t ( " s t a r s " )   e l s e   "   " , 
 
         ) 
 
         t a b l e . a d d _ r o w ( 
 
                 " F o r k s " , 
 
                 f " { g a . g e t ( ' f o r k s ' ,   0 ) : , } "   i f   g a . g e t ( " f o r k s " )   e l s e   "   " , 
 
                 f " { g b . g e t ( ' f o r k s ' ,   0 ) : , } "   i f   g b . g e t ( " f o r k s " )   e l s e   "   " , 
 
         ) 
 
         t a b l e . a d d _ r o w ( 
 
                 " O p e n   I s s u e s " , 
 
                 f " { g a . g e t ( ' o p e n _ i s s u e s ' ,   0 ) : , } "   i f   g a . g e t ( " o p e n _ i s s u e s " )   i s   n o t   N o n e   e l s e   "   " , 
 
                 f " { g b . g e t ( ' o p e n _ i s s u e s ' ,   0 ) : , } "   i f   g b . g e t ( " o p e n _ i s s u e s " )   i s   n o t   N o n e   e l s e   "   " , 
 
         ) 
 
         t a b l e . a d d _ r o w ( 
 
                 " L a s t   P u s h " , 
 
                 s t r ( g a . g e t ( " l a s t _ p u s h " ,   "   " ) ) [ : 1 0 ] , 
 
                 s t r ( g b . g e t ( " l a s t _ p u s h " ,   "   " ) ) [ : 1 0 ] , 
 
         ) 
 
         t a b l e . a d d _ r o w ( " L i c e n s e " ,   s t r ( p a . g e t ( " l i c e n s e " ,   "   " ) ) [ : 3 0 ] ,   s t r ( p b . g e t ( " l i c e n s e " ,   "   " ) ) [ : 3 0 ] ) 
 
         t a b l e . a d d _ r o w ( " P y t h o n " ,   s t r ( p a . g e t ( " r e q u i r e s _ p y t h o n " ,   "   " ) ) ,   s t r ( p b . g e t ( " r e q u i r e s _ p y t h o n " ,   "   " ) ) ) 
 
 
 
         s i z e _ a   =   p a . g e t ( " r e l e a s e _ s i z e _ b y t e s " ) 
 
         s i z e _ b   =   p b . g e t ( " r e l e a s e _ s i z e _ b y t e s " ) 
 
         t a b l e . a d d _ r o w ( 
 
                 " R e l e a s e   S i z e " , 
 
                 f o r m a t _ s i z e ( s i z e _ a )   i f   s i z e _ a   e l s e   "   " , 
 
                 f o r m a t _ s i z e ( s i z e _ b )   i f   s i z e _ b   e l s e   "   " , 
 
         ) 
 
 
 
         v u l n s _ a   =   l e n ( r e p o r t _ a . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] ) 
 
         v u l n s _ b   =   l e n ( r e p o r t _ b . g e t ( " v u l n e r a b i l i t i e s " )   o r   [ ] ) 
 
         t a b l e . a d d _ r o w ( 
 
                 " K n o w n   C V E s " , 
 
                 T e x t ( s t r ( v u l n s _ a ) ,   s t y l e = " r e d "   i f   v u l n s _ a   e l s e   " g r e e n " ) , 
 
                 T e x t ( s t r ( v u l n s _ b ) ,   s t y l e = " r e d "   i f   v u l n s _ b   e l s e   " g r e e n " ) , 
 
         ) 
 
 
 
         r e t u r n   t a b l e 
 
 ` ` ` 
 
 
 
 # # #   ` s r c / k r a i m i n d / u t i l s / m a p p i n g s . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " M a p p i n g   o f   P y t h o n   i m p o r t   n a m e s   t o   c a n o n i c a l   P y P I   p a c k a g e   n a m e s . " " " 
 
 
 
 f r o m   t y p i n g   i m p o r t   D i c t ,   S e t 
 
 
 
 #   S t a n d a r d   l i b r a r y   m o d u l e s       t h e s e   d o n ' t   m a p   t o   P y P I   p a c k a g e s 
 
 S T D L I B _ M O D U L E S :   S e t [ s t r ]   =   { 
 
         " a b c " ,   " a r g p a r s e " ,   " a s t " ,   " a s y n c i o " ,   " b a s e 6 4 " ,   " b i n a s c i i " ,   " b i s e c t " ,   " b u i l t i n s " , 
 
         " c a l e n d a r " ,   " c m a t h " ,   " c o l l e c t i o n s " ,   " c o n c u r r e n t " ,   " c o n f i g p a r s e r " ,   " c o n t e x t l i b " , 
 
         " c o n t e x t v a r s " ,   " c o p y " ,   " c s v " ,   " c t y p e s " ,   " d a t a c l a s s e s " ,   " d a t e t i m e " ,   " d e c i m a l " , 
 
         " d i f f l i b " ,   " d i s " ,   " d o c t e s t " ,   " e m a i l " ,   " e n c o d i n g s " ,   " e n u m " ,   " e r r n o " ,   " f a u l t h a n d l e r " , 
 
         " f c n t l " ,   " f i l e c m p " ,   " f i l e i n p u t " ,   " f n m a t c h " ,   " f r a c t i o n s " ,   " f t p l i b " ,   " f u n c t o o l s " , 
 
         " g c " ,   " g e t o p t " ,   " g e t p a s s " ,   " g e t t e x t " ,   " g l o b " ,   " g r a p h l i b " ,   " g z i p " ,   " h a s h l i b " , 
 
         " h e a p q " ,   " h m a c " ,   " h t m l " ,   " h t t p " ,   " i m a p l i b " ,   " i m p o r t l i b " ,   " i n s p e c t " ,   " i o " , 
 
         " i p a d d r e s s " ,   " i t e r t o o l s " ,   " j s o n " ,   " k e y w o r d " ,   " l i n e c a c h e " ,   " l o c a l e " ,   " l o g g i n g " , 
 
         " l z m a " ,   " m a i l b o x " ,   " m a t h " ,   " m i m e t y p e s " ,   " m m a p " ,   " m u l t i p r o c e s s i n g " ,   " n e t r c " , 
 
         " n u m b e r s " ,   " o p e r a t o r " ,   " o s " ,   " p a t h l i b " ,   " p i c k l e " ,   " p k g u t i l " ,   " p l a t f o r m " , 
 
         " p l i s t l i b " ,   " p o p l i b " ,   " p o s i x p a t h " ,   " p p r i n t " ,   " p r o f i l e " ,   " p s t a t s " ,   " p t y " , 
 
         " p w d " ,   " p y _ c o m p i l e " ,   " q u e u e " ,   " q u o p r i " ,   " r a n d o m " ,   " r e " ,   " r e a d l i n e " ,   " r e p r l i b " , 
 
         " r e s o u r c e " ,   " s e c r e t s " ,   " s e l e c t " ,   " s e l e c t o r s " ,   " s h e l v e " ,   " s h l e x " ,   " s h u t i l " , 
 
         " s i g n a l " ,   " s i t e " ,   " s m t p l i b " ,   " s o c k e t " ,   " s o c k e t s e r v e r " ,   " s q l i t e 3 " ,   " s s l " , 
 
         " s t a t " ,   " s t a t i s t i c s " ,   " s t r i n g " ,   " s t r i n g p r e p " ,   " s t r u c t " ,   " s u b p r o c e s s " ,   " s y m t a b l e " , 
 
         " s y s " ,   " s y s c o n f i g " ,   " s y s l o g " ,   " t a r f i l e " ,   " t e m p f i l e " ,   " t e r m i o s " ,   " t e x t w r a p " , 
 
         " t h r e a d i n g " ,   " t i m e " ,   " t i m e i t " ,   " t k i n t e r " ,   " t o k e n " ,   " t o k e n i z e " ,   " t o m l l i b " , 
 
         " t r a c e " ,   " t r a c e b a c k " ,   " t r a c e m a l l o c " ,   " t t y " ,   " t y p e s " ,   " t y p i n g " ,   " u n i c o d e d a t a " , 
 
         " u n i t t e s t " ,   " u r l l i b " ,   " u u " ,   " u u i d " ,   " v e n v " ,   " w a r n i n g s " ,   " w a v e " ,   " w e a k r e f " , 
 
         " w e b b r o w s e r " ,   " w s g i r e f " ,   " x m l " ,   " x m l r p c " ,   " z i p a p p " ,   " z i p f i l e " ,   " z i p i m p o r t " , 
 
         " z l i b " ,   " z o n e i n f o " ,   " _ _ f u t u r e _ _ " , 
 
 } 
 
 
 
 #   M a p p i n g :   P y t h o n   i m p o r t   n a m e       c a n o n i c a l   P y P I   p a c k a g e   n a m e 
 
 #   E x t e n d   t h i s   a s   n e w   a l i a s e s   a r e   d i s c o v e r e d 
 
 I M P O R T _ T O _ P A C K A G E :   D i c t [ s t r ,   s t r ]   =   { 
 
         #   C o m p u t e r   v i s i o n   &   i m a g e s 
 
         " c v 2 " :   " o p e n c v - p y t h o n " , 
 
         " c v " :   " o p e n c v - p y t h o n " , 
 
         " P I L " :   " p i l l o w " , 
 
         " s k i m a g e " :   " s c i k i t - i m a g e " , 
 
 
 
         #   M a c h i n e   l e a r n i n g 
 
         " s k l e a r n " :   " s c i k i t - l e a r n " , 
 
         " t e n s o r f l o w " :   " t e n s o r f l o w " , 
 
         " t o r c h " :   " t o r c h " , 
 
         " t o r c h v i s i o n " :   " t o r c h v i s i o n " , 
 
         " t r a n s f o r m e r s " :   " t r a n s f o r m e r s " , 
 
 
 
         #   W e b   p a r s i n g 
 
         " b s 4 " :   " b e a u t i f u l s o u p 4 " , 
 
         " l x m l " :   " l x m l " , 
 
 
 
         #   H a r d w a r e   /   s e r i a l 
 
         " s e r i a l " :   " p y s e r i a l " , 
 
 
 
         #   C o n f i g   &   d a t a 
 
         " y a m l " :   " p y y a m l " , 
 
         " t o m l " :   " t o m l " , 
 
         " d o t e n v " :   " p y t h o n - d o t e n v " , 
 
 
 
         #   A u t h   /   c r y p t o 
 
         " j w t " :   " p y j w t " , 
 
         " C r y p t o " :   " p y c r y p t o d o m e " , 
 
         " O p e n S S L " :   " p y o p e n s s l " , 
 
 
 
         #   D a t e / t i m e 
 
         " d a t e u t i l " :   " p y t h o n - d a t e u t i l " , 
 
 
 
         #   D a t a b a s e 
 
         " M y S Q L d b " :   " m y s q l c l i e n t " , 
 
         " p s y c o p g 2 " :   " p s y c o p g 2 - b i n a r y " , 
 
         " r e d i s " :   " r e d i s " , 
 
 
 
         #   M i s c 
 
         " p k g _ r e s o u r c e s " :   " s e t u p t o o l s " , 
 
         " s i x " :   " s i x " , 
 
         " m a g i c " :   " p y t h o n - m a g i c " , 
 
         " L e v e n s h t e i n " :   " p y t h o n - L e v e n s h t e i n " , 
 
         " g o o g l e " :   " g o o g l e - a p i - p y t h o n - c l i e n t " , 
 
         " g o o g l e a p i c l i e n t " :   " g o o g l e - a p i - p y t h o n - c l i e n t " , 
 
         " a b s l " :   " a b s l - p y " , 
 
         " _ p y t e s t " :   " p y t e s t " , 
 
         " I P y t h o n " :   " i p y t h o n " , 
 
         " w i n 3 2 a p i " :   " p y w i n 3 2 " , 
 
         " w i n 3 2 c o m " :   " p y w i n 3 2 " , 
 
         " w i n 3 2 c o n " :   " p y w i n 3 2 " , 
 
         " p y t h o n c o m " :   " p y w i n 3 2 " , 
 
 } 
 
 
 
 #   I m p o r t s   w e   i g n o r e   e n t i r e l y   ( s t d l i b   m a r k e r s ,   i n t e r n a l ) 
 
 I G N O R E _ I M P O R T S :   S e t [ s t r ]   =   S T D L I B _ M O D U L E S   |   { " _ _ f u t u r e _ _ " ,   " b u i l t i n s " ,   " s t d l i b " } 
 
 
 
 
 
 d e f   n o r m a l i z e _ p a c k a g e _ n a m e ( n a m e :   s t r )   - >   s t r : 
 
         " " " N o r m a l i z e   a   p a c k a g e   n a m e   f o r   c o m p a r i s o n :   l o w e r c a s e ,   r e p l a c e   _ / .   w i t h   - . " " " 
 
         r e t u r n   n a m e . l o w e r ( ) . r e p l a c e ( " _ " ,   " - " ) . r e p l a c e ( " . " ,   " - " ) . s t r i p ( ) 
 
 ` ` ` 
 
 
 
 # # #   ` t e s t s / t e s t _ s h a r e . p y ` 
 
 
 
 ` ` ` p y t h o n 
 
 " " " T e s t s   f o r   t h e   k r a i m i n d . s h a r e   m o d u l e . " " " 
 
 
 
 f r o m   _ _ f u t u r e _ _   i m p o r t   a n n o t a t i o n s 
 
 
 
 i m p o r t   o s 
 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e d e l t a ,   t i m e z o n e 
 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 
 
 i m p o r t   p y t e s t 
 
 
 
 f r o m   k r a i m i n d . s h a r e   i m p o r t   ( 
 
         E x c l u d e d F i l e , 
 
         L O C K F I L E S , 
 
         R E C E N C Y _ D A Y S , 
 
         S M A R T _ B U N D L E _ C A P , 
 
         b u i l d _ b u n d l e , 
 
         r e n d e r _ s h a r e _ p a g e , 
 
         w a l k _ p r o j e c t , 
 
 ) 
 
 
 
 
 
 @ p y t e s t . f i x t u r e 
 
 d e f   s h a r e _ p r o j e c t ( t m p _ p a t h :   P a t h )   - >   P a t h : 
 
         " " " P r o j e c t   w i t h   s e c r e t s ,   l o c k f i l e s ,   s o u r c e ,   R E A D M E ,   a n d   a   s k i p p e d   d i r . " " " 
 
         ( t m p _ p a t h   /   " R E A D M E . m d " ) . w r i t e _ t e x t ( " #   M y   A p p \ n F l a s k   d e m o . \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " p y p r o j e c t . t o m l " ) . w r i t e _ t e x t ( " [ p r o j e c t ] \ n n a m e = ' d e m o ' \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " a p p . p y " ) . w r i t e _ t e x t ( " f r o m   f l a s k   i m p o r t   F l a s k \ n a p p   =   F l a s k ( _ _ n a m e _ _ ) \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
         #   S e c r e t s       m u s t   a l w a y s   b e   e x c l u d e d . 
 
         ( t m p _ p a t h   /   " . e n v " ) . w r i t e _ t e x t ( " S E C R E T = h u n t e r 2 \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " i d _ r s a " ) . w r i t e _ t e x t ( " - - - - - B E G I N   P R I V A T E   K E Y - - - - - \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " s e r v i c e . k e y " ) . w r i t e _ t e x t ( " x x x \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " . e n v . e x a m p l e " ) . w r i t e _ t e x t ( " S E C R E T = c h a n g e m e \ n " ,   e n c o d i n g = " u t f - 8 " )     #   a l l o w e d 
 
 
 
         #   L o c k f i l e       o n l y   i n c l u d e d   w i t h   - - f u l l . 
 
         ( t m p _ p a t h   /   " p o e t r y . l o c k " ) . w r i t e _ t e x t ( " [ [ p a c k a g e ] ] \ n n a m e   =   ' x ' \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
         #   S k i p p e d   d i r s . 
 
         v e n v   =   t m p _ p a t h   /   " . v e n v " 
 
         v e n v . m k d i r ( ) 
 
         ( v e n v   /   " s h o u l d _ n o t _ a p p e a r . p y " ) . w r i t e _ t e x t ( " #   s k i p   m e \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
         n o d e   =   t m p _ p a t h   /   " n o d e _ m o d u l e s " 
 
         n o d e . m k d i r ( ) 
 
         ( n o d e   /   " l i b . j s " ) . w r i t e _ t e x t ( " / /   s k i p   m e \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
         r e t u r n   t m p _ p a t h 
 
 
 
 
 
 d e f   _ r e l _ n a m e s ( f i l e s :   l i s t )   - >   s e t [ s t r ] : 
 
         r e t u r n   { p . a s _ p o s i x ( )   f o r   p ,   _   i n   f i l e s } 
 
 
 
 
 
 d e f   t e s t _ w a l k _ e x c l u d e s _ s e c r e t s ( s h a r e _ p r o j e c t :   P a t h )   - >   N o n e : 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( s h a r e _ p r o j e c t ,   f u l l = F a l s e ) ) 
 
         a s s e r t   " . e n v "   n o t   i n   n a m e s 
 
         a s s e r t   " i d _ r s a "   n o t   i n   n a m e s 
 
         a s s e r t   " s e r v i c e . k e y "   n o t   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ w a l k _ a l l o w s _ e n v _ e x a m p l e ( s h a r e _ p r o j e c t :   P a t h )   - >   N o n e : 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( s h a r e _ p r o j e c t ,   f u l l = F a l s e ) ) 
 
         a s s e r t   " . e n v . e x a m p l e "   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ w a l k _ e x c l u d e s _ s k i p _ d i r s ( s h a r e _ p r o j e c t :   P a t h )   - >   N o n e : 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( s h a r e _ p r o j e c t ,   f u l l = F a l s e ) ) 
 
         a s s e r t   n o t   a n y ( n . s t a r t s w i t h ( " . v e n v / " )   f o r   n   i n   n a m e s ) 
 
         a s s e r t   n o t   a n y ( n . s t a r t s w i t h ( " n o d e _ m o d u l e s / " )   f o r   n   i n   n a m e s ) 
 
 
 
 
 
 d e f   t e s t _ l o c k f i l e _ e x c l u d e d _ i n _ s m a r t _ m o d e ( s h a r e _ p r o j e c t :   P a t h )   - >   N o n e : 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( s h a r e _ p r o j e c t ,   f u l l = F a l s e ) ) 
 
         a s s e r t   " p o e t r y . l o c k "   n o t   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ l o c k f i l e _ i n c l u d e d _ w i t h _ f u l l ( s h a r e _ p r o j e c t :   P a t h )   - >   N o n e : 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( s h a r e _ p r o j e c t ,   f u l l = T r u e ) ) 
 
         a s s e r t   " p o e t r y . l o c k "   i n   n a m e s 
 
         a s s e r t   " p o e t r y . l o c k "   i n   L O C K F I L E S     #   s a n i t y 
 
 
 
 
 
 d e f   t e s t _ k r a i m i n d i g n o r e _ r e s p e c t e d ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         ( t m p _ p a t h   /   " k e e p . p y " ) . w r i t e _ t e x t ( " #   y e s \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " d r o p . p y " ) . w r i t e _ t e x t ( " #   n o \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " . k r a i m i n d i g n o r e " ) . w r i t e _ t e x t ( " d r o p . p y \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( t m p _ p a t h ,   f u l l = F a l s e ) ) 
 
         a s s e r t   " k e e p . p y "   i n   n a m e s 
 
         a s s e r t   " d r o p . p y "   n o t   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ r e n d e r _ s h a r e _ p a g e _ w r a p s _ m a r k d o w n _ f o r _ b r o w s e r s ( )   - >   N o n e : 
 
         h t m l   =   r e n d e r _ s h a r e _ p a g e ( " #   D e m o \ n \ n H e l l o   f r o m   K r a i m i n d " ,   " d e m o " ) 
 
 
 
         a s s e r t   " < ! d o c t y p e   h t m l "   i n   h t m l . l o w e r ( ) 
 
         a s s e r t   " k r a i m i n d   s h a r e "   i n   h t m l . l o w e r ( ) 
 
         a s s e r t   " #   D e m o "   i n   h t m l 
 
         a s s e r t   " H e l l o   f r o m   K r a i m i n d "   i n   h t m l 
 
 
 
 
 
 d e f   t e s t _ b u i l d _ b u n d l e _ h a s _ t r e e _ a n d _ f i l e s ( s h a r e _ p r o j e c t :   P a t h )   - >   N o n e : 
 
         b u n d l e   =   b u i l d _ b u n d l e ( s h a r e _ p r o j e c t ,   f u l l = F a l s e ) 
 
         a s s e r t   b u n d l e . f i l e _ c o u n t   > =   3 
 
         a s s e r t   " #   K r a i m i n d   C o d e b a s e   S h a r e "   i n   b u n d l e . c o n t e n t 
 
         a s s e r t   " # #   F i l e   t r e e "   i n   b u n d l e . c o n t e n t 
 
         a s s e r t   " # #   F i l e s "   i n   b u n d l e . c o n t e n t 
 
         a s s e r t   " a p p . p y "   i n   b u n d l e . c o n t e n t 
 
         a s s e r t   " f r o m   f l a s k   i m p o r t   F l a s k "   i n   b u n d l e . c o n t e n t 
 
         #   R E A D M E   l i s t e d   s i n c e   i t ' s   p r i o r i t i z e d 
 
         a s s e r t   " R E A D M E . m d "   i n   b u n d l e . c o n t e n t 
 
         #   A I   h a n d s h a k e   p r e a m b l e   s i t s   a t   t h e   v e r y   t o p ,   w i t h   a n   i n t e r p o l a t e d   c o n f i r m   l i n e . 
 
         a s s e r t   b u n d l e . c o n t e n t . s t a r t s w i t h ( " < ! - -   K R A I M I N D   H A N D O F F   - - > " ) 
 
         a s s e r t   f "     C o n n e c t e d   t o   k r a i m i n d       { s h a r e _ p r o j e c t . n a m e }   ,%V%  { b u n d l e . f i l e _ c o u n t }   f i l e s "   i n   b u n d l e . c o n t e n t 
 
 
 
 
 
 d e f   t e s t _ s m a r t _ m o d e _ c a p s _ t o t a l _ b y t e s ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         #   C r e a t e   m a n y   f i l e s   l a r g e   e n o u g h   t o   b l o w   t h e   c a p . 
 
         c h u n k   =   " x "   *   2 0 _ 0 0 0 
 
         f o r   i   i n   r a n g e ( 2 0 ) : 
 
                 ( t m p _ p a t h   /   f " f { i : 0 2 d } . p y " ) . w r i t e _ t e x t ( c h u n k ,   e n c o d i n g = " u t f - 8 " ) 
 
 
 
         b u n d l e   =   b u i l d _ b u n d l e ( t m p _ p a t h ,   f u l l = F a l s e ) 
 
         #   C o n t e n t   i n c l u d e s   m a r k d o w n   o v e r h e a d ;   t h e   * r a w   i n c l u d e d   f i l e s *   s h o u l d   f i t   c a p . 
 
         a s s e r t   b u n d l e . t o t a l _ b y t e s   < =   S M A R T _ B U N D L E _ C A P   *   3     #   g e n e r o u s :   i n c l u d e s   m a r k d o w n   w r a p p e r 
 
         a s s e r t   b u n d l e . f i l e _ c o u n t   <   2 0     #   s o m e   f i l e s   d r o p p e d 
 
 
 
 
 
 d e f   t e s t _ f u l l _ m o d e _ i n c l u d e s _ e v e r y t h i n g ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         f o r   i   i n   r a n g e ( 5 ) : 
 
                 ( t m p _ p a t h   /   f " f { i } . p y " ) . w r i t e _ t e x t ( f " #   f i l e   { i } \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         b u n d l e   =   b u i l d _ b u n d l e ( t m p _ p a t h ,   f u l l = T r u e ) 
 
         a s s e r t   b u n d l e . f i l e _ c o u n t   = =   5 
 
 
 
 
 
 d e f   t e s t _ l a r g e _ f i l e _ t r u n c a t e d ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         h u g e   =   " y "   *   ( 2 0 0   *   1 0 2 4 )     #   2 0 0   K B       o v e r   p e r - f i l e   c a p 
 
         ( t m p _ p a t h   /   " h u g e . p y " ) . w r i t e _ t e x t ( h u g e ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " s m a l l . p y " ) . w r i t e _ t e x t ( " o k \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         f i l e s   =   w a l k _ p r o j e c t ( t m p _ p a t h ,   f u l l = F a l s e ) 
 
         n a m e s   =   _ r e l _ n a m e s ( f i l e s ) 
 
         a s s e r t   " s m a l l . p y "   i n   n a m e s 
 
         a s s e r t   " h u g e . p y "   i n   n a m e s     #   n o w   i n c l u d e d   b u t   t r u n c a t e d 
 
         t e x t s   =   { p . a s _ p o s i x ( ) :   t   f o r   p ,   t   i n   f i l e s } 
 
         a s s e r t   " [ t r u n c a t e d "   i n   t e x t s [ " h u g e . p y " ] 
 
         a s s e r t   l e n ( t e x t s [ " h u g e . p y " ] . e n c o d e ( " u t f - 8 " ) )   <   2 0 0   *   1 0 2 4 
 
 
 
 
 
 d e f   t e s t _ s m a r t _ m o d e _ b i n _ p a c k i n g ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         #   1 5 0   K B   f i l e   +   t e n   1   K B   f i l e s   =   ~ 1 6 0   K B   <   3 0 0   K B   c a p       a l l   s h o u l d   b e   i n c l u d e d . 
 
         ( t m p _ p a t h   /   " a a a _ l a r g e . p y " ) . w r i t e _ t e x t ( " x "   *   ( 1 5 0   *   1 0 2 4 ) ,   e n c o d i n g = " u t f - 8 " ) 
 
         f o r   i   i n   r a n g e ( 1 0 ) : 
 
                 ( t m p _ p a t h   /   f " s m a l l _ { i : 0 2 d } . p y " ) . w r i t e _ t e x t ( " x "   *   1 0 2 4 ,   e n c o d i n g = " u t f - 8 " ) 
 
         b u n d l e   =   b u i l d _ b u n d l e ( t m p _ p a t h ,   f u l l = F a l s e ) 
 
         a s s e r t   b u n d l e . f i l e _ c o u n t   = =   1 1 
 
 
 
 
 
 d e f   t e s t _ e x c l u d e d _ f i l e s _ r e p o r t e d _ i n _ s m a r t _ m o d e ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         c h u n k   =   " x "   *   2 5 _ 0 0 0     #   2 5   K B   e a c h       2 0   f i l e s   =   5 0 0   K B   > >   3 0 0   K B   c a p 
 
         f o r   i   i n   r a n g e ( 2 0 ) : 
 
                 ( t m p _ p a t h   /   f " f { i : 0 2 d } . p y " ) . w r i t e _ t e x t ( c h u n k ,   e n c o d i n g = " u t f - 8 " ) 
 
         b u n d l e   =   b u i l d _ b u n d l e ( t m p _ p a t h ,   f u l l = F a l s e ) 
 
         a s s e r t   b u n d l e . f i l e _ c o u n t   <   2 0 
 
         a s s e r t   l e n ( b u n d l e . e x c l u d e d _ f i l e s )   >   0 
 
         f o r   e x c   i n   b u n d l e . e x c l u d e d _ f i l e s : 
 
                 a s s e r t   i s i n s t a n c e ( e x c ,   E x c l u d e d F i l e ) 
 
                 a s s e r t   e x c . r e a s o n   = =   " c a p " 
 
                 a s s e r t   e x c . s i z e _ k b   >   0 
 
 
 
 
 
 d e f   t e s t _ e x c l u d e d _ f i l e s _ e m p t y _ i n _ f u l l _ m o d e ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         f o r   i   i n   r a n g e ( 3 ) : 
 
                 ( t m p _ p a t h   /   f " f { i } . p y " ) . w r i t e _ t e x t ( " #   o k \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         b u n d l e   =   b u i l d _ b u n d l e ( t m p _ p a t h ,   f u l l = T r u e ) 
 
         a s s e r t   b u n d l e . e x c l u d e d _ f i l e s   = =   [ ] 
 
 
 
 
 
 d e f   t e s t _ r e c e n c y _ b o o s t _ p r e f e r s _ r e c e n t _ f i l e s ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         o l d _ f i l e   =   t m p _ p a t h   /   " a a a _ o l d . p y " 
 
         n e w _ f i l e   =   t m p _ p a t h   /   " b b b _ n e w . p y " 
 
         f i l l e r   =   t m p _ p a t h   /   " z z z _ f i l l . p y " 
 
         o l d _ f i l e . w r i t e _ t e x t ( " #   o l d \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         n e w _ f i l e . w r i t e _ t e x t ( " #   n e w \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         #   F i l l e r   f i l e   t a k e s   u p   n e a r l y   t h e   w h o l e   c a p   s o   o n l y   o n e   s m a l l   f i l e   f i t s   a l o n g s i d e   i t . 
 
         f i l l e r . w r i t e _ t e x t ( " x "   *   ( S M A R T _ B U N D L E _ C A P   -   5 0 0 ) ,   e n c o d i n g = " u t f - 8 " ) 
 
         #   A g e   o l d _ f i l e   t o   3 0   d a y s   a g o . 
 
         o l d _ m t i m e   =   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   t i m e d e l t a ( d a y s = 3 0 ) ) . t i m e s t a m p ( ) 
 
         o s . u t i m e ( o l d _ f i l e ,   ( o l d _ m t i m e ,   o l d _ m t i m e ) ) 
 
         b u n d l e   =   b u i l d _ b u n d l e ( t m p _ p a t h ,   f u l l = F a l s e ) 
 
         #   b b b _ n e w . p y   i s   r e c e n t   s o   g e t s   p r i o r i t y   b o o s t       s h o u l d   b e   i n c l u d e d   o v e r   a a a _ o l d . p y . 
 
         a s s e r t   " b b b _ n e w . p y "   i n   b u n d l e . c o n t e n t 
 
 
 
 
 
 d e f   t e s t _ g i t i g n o r e _ e x c l u d e s _ m a t c h i n g _ f i l e s ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         p y t e s t . i m p o r t o r s k i p ( " p a t h s p e c " ) 
 
         ( t m p _ p a t h   /   " k e e p . p y " ) . w r i t e _ t e x t ( " #   k e e p \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " d r o p . p y " ) . w r i t e _ t e x t ( " #   d r o p \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         ( t m p _ p a t h   /   " . g i t i g n o r e " ) . w r i t e _ t e x t ( " d r o p . p y \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( t m p _ p a t h ,   f u l l = F a l s e ) ) 
 
         a s s e r t   " k e e p . p y "   i n   n a m e s 
 
         a s s e r t   " d r o p . p y "   n o t   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ g i t i g n o r e _ a b s e n t _ d o e s _ n o t _ e r r o r ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         ( t m p _ p a t h   /   " k e e p . p y " ) . w r i t e _ t e x t ( " #   k e e p \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( t m p _ p a t h ,   f u l l = F a l s e ) ) 
 
         a s s e r t   " k e e p . p y "   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ s i n c e _ f i l t e r _ e x c l u d e s _ o l d _ f i l e s ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         o l d _ f i l e   =   t m p _ p a t h   /   " o l d . p y " 
 
         n e w _ f i l e   =   t m p _ p a t h   /   " n e w . p y " 
 
         o l d _ f i l e . w r i t e _ t e x t ( " #   o l d \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         n e w _ f i l e . w r i t e _ t e x t ( " #   n e w \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         o l d _ m t i m e   =   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   t i m e d e l t a ( d a y s = 3 0 ) ) . t i m e s t a m p ( ) 
 
         o s . u t i m e ( o l d _ f i l e ,   ( o l d _ m t i m e ,   o l d _ m t i m e ) ) 
 
         s i n c e   =   d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   t i m e d e l t a ( d a y s = 7 ) 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( t m p _ p a t h ,   f u l l = F a l s e ,   s i n c e = s i n c e ) ) 
 
         a s s e r t   " n e w . p y "   i n   n a m e s 
 
         a s s e r t   " o l d . p y "   n o t   i n   n a m e s 
 
 
 
 
 
 d e f   t e s t _ s i n c e _ n o n e _ i n c l u d e s _ a l l _ a g e s ( t m p _ p a t h :   P a t h )   - >   N o n e : 
 
         o l d _ f i l e   =   t m p _ p a t h   /   " o l d . p y " 
 
         o l d _ f i l e . w r i t e _ t e x t ( " #   o l d \ n " ,   e n c o d i n g = " u t f - 8 " ) 
 
         o l d _ m t i m e   =   ( d a t e t i m e . n o w ( t i m e z o n e . u t c )   -   t i m e d e l t a ( d a y s = 3 6 5 ) ) . t i m e s t a m p ( ) 
 
         o s . u t i m e ( o l d _ f i l e ,   ( o l d _ m t i m e ,   o l d _ m t i m e ) ) 
 
         n a m e s   =   _ r e l _ n a m e s ( w a l k _ p r o j e c t ( t m p _ p a t h ,   f u l l = F a l s e ,   s i n c e = N o n e ) ) 
 
         a s s e r t   " o l d . p y "   i n   n a m e s 
 
 ` ` ` 
 
 