icoa-cli 2.19.608 → 2.19.609

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (function(j,q){const a4=a0q,v=j();while(!![]){try{const z=-parseInt(a4(0x21b))/(-0xc1b+0x67+-0x1*-0xbb5)+-parseInt(a4(0x18a))/(-0x1*-0x2371+0x60b+-0x2*0x14bd)*(parseInt(a4(0x196))/(-0x2*-0x22d+0x175a+0x33*-0x8b))+-parseInt(a4(0x151))/(0xede+-0x60a+0x178*-0x6)*(parseInt(a4(0x278))/(0x28f+0x233b+-0x25c5))+parseInt(a4(0x23d))/(-0x3b2+-0x1a13+0x1dcb)+parseInt(a4(0x171))/(-0x2*0xbc5+0x1*0x1ced+-0x55c)*(parseInt(a4(0x259))/(-0x85*0x2b+0x1a73+0x3*-0x15c))+parseInt(a4(0x16c))/(0xbdf+0x1*-0x14c2+-0x8ec*-0x1)+parseInt(a4(0x236))/(-0x9e2+-0x603+0xfef);if(z===q)break;else v['push'](v['shift']());}catch(B){v['push'](v['shift']());}}}(a0j,0xb1f0f+-0x34705+0x5073a));import a0z from'chalk';import{createChatSession as a0B}from'../lib/gemini.js';import{addTokenUsage as a0D}from'../lib/budget.js';import{getConfig as a0E,isConnected as a0F}from'../lib/config.js';import{logCommand as a0G,logSubmission as a0H}from'../lib/logger.js';import{printMarkdown as a0I,printError as a0J}from'../lib/ui.js';import{t as a0K}from'../lib/i18n.js';import{httpFetch as a0L}from'../lib/http.js';const r=j=>new Promise(q=>setTimeout(q,j));let u=!(0x1d98+-0x1fad+0x216),h=null,y=-0x240c*-0x1+0x2674*0x1+0x10*-0x4a8,d=0xc5c+-0x149d+0x841,m=!(-0x29*-0xed+-0x2412+0xa1*-0x3),f=!(0xde3*-0x2+0x17*0x38+0x16bf),p=!(0xb*0x2b3+-0x1+0x3*-0x9e5);const w=-0x48be+0x21ed+0x8879,b=0xb26f7+0x1*0x5df7c+0x2b*-0x36d9;let $=null,A=null;function a0q(a,b){a=a-(0x14be+-0x1026+0x1*-0x355);const c=a0j();let d=c[a];if(a0q['tNGIRW']===undefined){var e=function(i){const j='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let l='',m='';for(let n=-0x120b*-0x2+0x1e83+-0x4299,o,p,q=0xe*-0x14d+0x240c+0x11d6*-0x1;p=i['charAt'](q++);~p&&(o=n%(-0x5f*-0x39+0x9f9+-0x1f1c)?o*(-0xf64+-0x29*-0xed+-0x1651)+p:p,n++%(0x3c0+0x13*0x18d+0x3*-0xb11))?l+=String['fromCharCode'](-0x1*-0xfaf+0x1*-0xd13+-0x19d&o>>(-(0x14dd+-0x4cc*-0x2+-0x1e73)*n&-0x7*0x544+0x1*0x1be2+0x12*0x80)):0x1d*0x7f+0x19*0x4e+-0x1601){p=j['indexOf'](p);}for(let r=0x2390+-0x3*-0x9a4+-0x1*0x407c,s=l['length'];r<s;r++){m+='%'+('00'+l['charCodeAt'](r)['toString'](-0x11d4+0x605+-0x3*-0x3f5))['slice'](-(0x22*0xc5+-0x2f*-0x7f+-0x55*0x95));}return decodeURIComponent(m);};a0q['tRLntF']=e,a0q['iKOeui']={},a0q['tNGIRW']=!![];}const f=c[-0x1be7+0x678+0x156f],g=a+f,h=a0q['iKOeui'][g];return!h?(d=a0q['tRLntF'](d),a0q['iKOeui'][g]=d):d=h,d;}export function isChatActive(){return u;}function x(){const a5=a0q,j=$?w:A?d||b:0x1d*0x7f+0x19*0x4e+-0x279,q=y,v=Math[a5(0x25b)](Math['round'](q/j*(0x2390+-0x3*-0x9a4+-0x1*0x4018)),-0x11d4+0x605+-0x9*-0x15b),z=Math[a5(0x188)](v/(0x22*0xc5+-0x2f*-0x7f+-0x47*0xb1)*(-0x1be7+0x678+0x1583)),B=0x246a+0x4a5+-0x28fb-z,D=v>-0x1*0x1327+-0x1fba+0x3331?a0z[a5(0x21a)]:v>-0x2450+0x89*-0x2b+0x3b85?a0z[a5(0x243)]:a0z['green'],E=$?a5(0x1ba):A?a5(0x283):a5(0x172);!A||m?!A||f?console[a5(0x280)](a0z['gray']('\x20\x20'+E+':\x20')+D('█'[a5(0x20f)](z))+a0z[a5(0x28c)]('░'['repeat'](B))+a0z[a5(0x28c)]('\x20'+q+'/'+j+'\x20('+v+'%)')):console[a5(0x280)](a0z[a5(0x28c)](a5(0x289))+a0z[a5(0x243)]('syncing…')+a0z[a5(0x28c)](a5(0x14a))):console['log'](a0z['gray'](a5(0x289))+a0z['yellow'](a5(0x195))+a0z[a5(0x28c)](a5(0x19a)));}export async function handleChatMessage(z){const a6=a0q;if(!h)return a6(0x198);if(a0G(a6(0x232)+z),$)return k(z);if(A)return async function(G){const a7=a6;if(!A||!h)return a7(0x198);const H=G[a7(0x1f5)](),I=H['toLowerCase'](),J=H[a7(0x274)](/^submit\s+(.+)/i);if(J){let K=J[0x30b+-0x2*0xd33+0x175c]['trim']();if(/^submit\s+/i['test'](K)&&(K=K[a7(0x22f)](/^submit\s+/i,'')[a7(0x1f5)]()),K=K[a7(0x22f)](/^["'`]+|["'`]+$/g,'')['trim'](),!K)return console[a7(0x280)](),console[a7(0x280)](a0z[a7(0x28c)](a7(0x28b))+a0z[a7(0x167)]('submit\x20<flag>')),console[a7(0x280)](),a7(0x225);const L=A[a7(0x1f8)];if(!L)return console[a7(0x280)](),console['log'](a0z['yellow'](a7(0x279))+a0z[a7(0x167)](a7(0x1c0))),console['log'](),a7(0x225);a0H(L,K);const M=a0E();try{const {CTFdClient:N}=await import(a7(0x219)),O=M[a7(0x1e6)]||'',P=M['token']&&!M['token'][a7(0x237)](a7(0x1b5))?M['token']:'',Q=new N(M[a7(0x144)],P,O||M[a7(0x26e)]),R=await Q[a7(0x212)](L,K);switch(console[a7(0x280)](),R[a7(0x285)]){case a7(0x1d7):console[a7(0x280)](a0z[a7(0x1af)][a7(0x208)]('\x20\x20🎉\x20Correct!\x20')+a0z[a7(0x167)](R['message']||''));break;case a7(0x1eb):console[a7(0x280)](a0z[a7(0x21a)]('\x20\x20✗\x20Incorrect.\x20')+a0z[a7(0x28c)](R[a7(0x25d)]||''));break;case a7(0x23c):console['log'](a0z[a7(0x243)](a7(0x24d)));break;case a7(0x180):console[a7(0x280)](a0z[a7(0x243)](a7(0x248)));break;case'ratelimited':console[a7(0x280)](a0z[a7(0x243)](a7(0x14e)));break;default:console[a7(0x280)](a0z[a7(0x28c)]('\x20\x20'+(R['message']||a7(0x17c))));}console[a7(0x280)]();const {postIntegritySnapshot:S}=await import('../lib/integrity-snapshot.js');await S();}catch(T){console['log'](),console[a7(0x280)](a0z[a7(0x21a)](a7(0x220)+(T['message']?.[a7(0x256)]('\x0a')[0x1c2a+-0x6c5*0x2+-0x138*0xc]||'unknown\x20error'))),console[a7(0x280)]();}return a7(0x225);}if(G['startsWith']('!')){const U=G[a7(0x239)](0x7*0x38b+0x1a0f+-0x115*0x2f)['trim']();if(!U)return'continue';try{const V={};V[a7(0x1ff)]=a7(0x149),V['timeout']=0x2710;const {execSync:W}=await import(a7(0x1f7)),X=W(U,V)[a7(0x1f5)]();console[a7(0x280)](),console['log'](a0z[a7(0x28c)](a7(0x26f))+a0z[a7(0x167)](U)),console['log'](a0z[a7(0x167)]('\x20\x20'+X['split']('\x0a')[a7(0x179)](a7(0x1e4)))),console[a7(0x280)]();}catch(Y){console[a7(0x280)](),console[a7(0x280)](a0z[a7(0x21a)](a7(0x1a7)+(Y['message']?.[a7(0x256)]('\x0a')[-0x9d*-0x1+0x1d4a+-0x1de7]||'Command\x20failed'))),console[a7(0x280)]();}return'continue';}if('exit'===I||'back'===I||'quit'===I){const Z=A[a7(0x150)];return u=!(0x2f2*0x2+-0x1778+-0x7*-0x283),h=null,A=null,console[a7(0x280)](),console[a7(0x280)](a0z['gray'](a7(0x152)+Z+'\x22.')),console['log'](a0z[a7(0x28c)](a7(0x1ec))+a0z['white']('open\x20<id>')+a0z[a7(0x28c)](a7(0x24b))+a0z[a7(0x167)](a7(0x1ad))),console[a7(0x280)](),'exit';}console[a7(0x280)](a0z[a7(0x28c)]('\x20\x20'+a0K(a7(0x271))));try{const a0=await h['sendMessage'](G);process[a7(0x1d3)][a7(0x1d9)](a7(0x18c)),a0D(a0['tokensUsed']),a7(0x1db)==typeof a0[a7(0x169)]?(y=a0[a7(0x169)],m=!(0x1*0xf19+-0x14*-0x94+-0x1aa9),f=!(-0x1f30+-0xd*0x1d+-0x9*-0x3a1),a7(0x1db)==typeof a0[a7(0x207)]&&(d=a0['accountCap'])):(y+=a0[a7(0x211)],f=!(0x158a+0xae5+-0x206f)),console[a7(0x280)](),a0I(a0['text']),x(),console[a7(0x280)](a0z[a7(0x28c)]('\x20\x20exit\x20to\x20leave\x20chat\x20·\x20submit\x20<flag>\x20to\x20score')),console['log']();}catch(a1){process[a7(0x1d3)][a7(0x1d9)]('\x1b[1A\x1b[2K'),a0J(a7(0x186)+a1[a7(0x25d)]),console['log']();}return a7(0x225);}(z);const B=z['trim']()[a6(0x162)]()[a6(0x274)](/^hint\s+([abc])$/);if(B)return function(G){const a8=a6,H=a0K('a'===G?a8(0x20b):'b'===G?a8(0x155):a8(0x21c)),I=a0K('a'===G?'ai4ctfHintABody':'b'===G?a8(0x17a):'ai4ctfHintCBody'),J=a8(0x153)+G[a8(0x276)](),K='a'===G?a0z[a8(0x1af)]:'b'===G?a0z[a8(0x243)]:a0z['red'];console[a8(0x280)](),console[a8(0x280)](K[a8(0x208)](a8(0x224)+J+'\x20\x20')+a0z[a8(0x28c)](H)),console[a8(0x280)]();for(const L of I[a8(0x256)]('\x0a'))''===L?console[a8(0x280)]():console[a8(0x280)](a0z[a8(0x167)](a8(0x158)+L));console[a8(0x280)](),'a'===G?(console[a8(0x280)](a0z[a8(0x28c)](a8(0x158)+a0K('ai4ctfHintNextA')+'\x20')+a0z[a8(0x1bd)](a8(0x292))),console[a8(0x280)]()):'b'===G&&(console[a8(0x280)](a0z[a8(0x28c)](a8(0x158)+a0K('ai4ctfHintNextB')+'\x20')+a0z['cyan'](a8(0x1a5))),console['log']());}(B[-0x2c5+-0x20c0+0x2386*0x1]),a6(0x225);const D=z['match'](/^submit\s+(.+)/i);if(D){let G=D[-0x6b*-0x4+-0x1de2+-0x1*-0x1c37]['trim']();if(/^submit\s+/i[a6(0x15c)](G)&&(G=G[a6(0x22f)](/^submit\s+/i,'')['trim']()),G=G[a6(0x22f)](/^["'`]+|["'`]+$/g,'')[a6(0x1f5)](),a6(0x1d4)===G){console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x1af)]['bold']('\x20\x20════════════════════════════════════')),console[a6(0x280)](a0z[a6(0x1af)]['bold']('\x20\x20'+a0K(a6(0x202)))),console[a6(0x280)](a0z[a6(0x1af)][a6(0x208)]('\x20\x20════════════════════════════════════')),console['log'](),console[a6(0x280)](a0z[a6(0x167)]('\x20\x20'+a0K(a6(0x187)))),console[a6(0x280)](a0z[a6(0x28c)]('\x20\x20'+a0K(a6(0x146)))),console[a6(0x280)](),x(),u=!(-0x1*0x1327+0x695*0x1+0xc93),h=null,fetch(a6(0x26b),{'method':'POST','headers':{'Content-Type':a6(0x1fe)},'body':JSON[a6(0x24f)]({'type':a6(0x1ad),'solved':!(-0xb68+0x27*-0x71+0x1c9f*0x1),'tokensUsed':y,'timestamp':new Date()['toISOString']()}),'signal':AbortSignal[a6(0x267)](-0x1*0x254f+-0x1532+0x4e09)})[a6(0x174)](()=>{}),await r(-0x217e*0x1+-0x23*0xc0+0x3*0x15de),console['log'](),console['log'](a0z[a6(0x1bd)]('\x20\x20─────────────────────────────────────────────')),console[a6(0x280)](a0z['bold'][a6(0x167)]('\x20\x20'+a0K(a6(0x1be)))),console[a6(0x280)](a0z[a6(0x1bd)](a6(0x28a))),console[a6(0x280)]();const H=a0K(a6(0x229)),I=a0K(a6(0x1cc));console[a6(0x280)](a0z[a6(0x167)](a6(0x1a9)+H+'\x20')+a0z[a6(0x28c)](I['split']('\x0a')[0x43*0x71+-0x584*0x1+-0x180f]||''));for(const M of I[a6(0x256)]('\x0a')[a6(0x239)](0x1*0x526+0x1494+0x893*-0x3))M[a6(0x1f5)]()&&console[a6(0x280)](a0z[a6(0x28c)](a6(0x1ef)+M[a6(0x22f)](/\{thinking\}/g,a6(0x27f))));console[a6(0x280)](),console[a6(0x280)](a0z['white'](a6(0x16b)+a0K(a6(0x177))+'\x20')+a0z[a6(0x28c)](a0K(a6(0x1dc)))),console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x1bd)](a6(0x1e1))),console[a6(0x280)](),await r(0xf9b+0x77c+-0xf47),console[a6(0x280)](a0z['cyan']('\x20\x20─────────────────────────────────────────────')),console[a6(0x280)](a0z[a6(0x208)][a6(0x167)]('\x20\x20'+a0K(a6(0x18b)))),console[a6(0x280)](a0z[a6(0x1bd)](a6(0x28a))),console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x243)](a6(0x22e))+a0z[a6(0x167)](a0K(a6(0x18e))[a6(0x22c)](-0x4*-0x431+-0x236f+0x12c5))+a0z[a6(0x28c)](a0K(a6(0x22b)))),console['log'](a0z[a6(0x243)](a6(0x17d))+a0z[a6(0x167)](a0K(a6(0x1d5))['padEnd'](0x1917+-0x3bc+-0x1541))+a0z[a6(0x28c)](a0K(a6(0x1e5)))),console[a6(0x280)](a0z['yellow'](a6(0x26a))+a0z[a6(0x167)](a0K(a6(0x1c7))['padEnd'](-0x1fff+-0x1*0x23f9+0x2*0x2209))+a0z['gray'](a0K(a6(0x294)))),console['log']();for(const N of a0K(a6(0x1e8))[a6(0x256)]('\x0a'))console[a6(0x280)](a0z[a6(0x28c)](a6(0x158)+N));console[a6(0x280)](),await r(-0x350*-0x6+0x469*-0x1+0x7a7*-0x1),console[a6(0x280)](a0z[a6(0x1bd)](a6(0x28a))),console[a6(0x280)](a0z[a6(0x208)][a6(0x167)]('\x20\x20'+a0K(a6(0x253))+'\x20')+a0z[a6(0x21a)][a6(0x208)](a6(0x1fb))+a0z[a6(0x167)]('\x20—\x20'+a0K(a6(0x210)))),console['log'](a0z['cyan']('\x20\x20─────────────────────────────────────────────')),console[a6(0x280)]();const J=a0K(a6(0x17f)),K=a0K(a6(0x16a)),L=J[a6(0x256)]('\x0a');if(L[0xb3e+-0x9*0x376+0x1c*0xb6]){const [O,P]=L[-0x6ba+0x1a96+-0x13dc][a6(0x256)](a6(0x1a2));console[a6(0x280)](a0z[a6(0x167)]('\x20\x20\x20\x20'+(O||''))+a0z[a6(0x208)][a6(0x167)](K)+a0z[a6(0x167)](P||''));}for(const Q of L[a6(0x239)](-0x7*-0xba+-0x241a+0x1f05))Q[a6(0x1f5)]()&&console[a6(0x280)](a0z[a6(0x167)](a6(0x158)+Q));return console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x28c)]('\x20\x20\x20\x20'+a0K(a6(0x26c))+'\x20')+a0z[a6(0x208)]['red'](a6(0x1fb))),console[a6(0x280)](),a6(0x198);}return console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x21a)]('\x20\x20'+a0K(a6(0x262)))),console['log'](a0z[a6(0x28c)]('\x20\x20'+a0K('ai4ctfFlagHint'))),console[a6(0x280)](),a6(0x225);}if(z[a6(0x1bc)]('!')){const R=z[a6(0x239)](-0x127e+0x1*-0x999+0x1d*0xf8)[a6(0x1f5)]();if(!R)return a6(0x225);try{const S={};S[a6(0x1ff)]='utf-8',S[a6(0x267)]=0x2710;const {execSync:T}=await import(a6(0x1f7)),U=T(R,S)[a6(0x1f5)]();console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x28c)](a6(0x26f))+a0z[a6(0x167)](R)),console[a6(0x280)](a0z[a6(0x167)]('\x20\x20'+U['split']('\x0a')[a6(0x179)]('\x0a\x20\x20'))),console[a6(0x280)](),console['log'](a0z[a6(0x28c)]('\x20\x20'+a0K('ai4ctfFoundFlag'))),console[a6(0x280)]();}catch(V){console['log'](),console[a6(0x280)](a0z[a6(0x21a)](a6(0x1a7)+(V[a6(0x25d)]?.[a6(0x256)]('\x0a')[-0x79f+-0x2531*-0x1+0x5ea*-0x5]||'Command\x20failed'))),console['log']();}return a6(0x225);}const E={};E[a6(0x216)]='application/json';if('exit'===z||'back'===z||'quit'===z||a6(0x1ac)===z)return u=!(0x13ad+0x2*0xb97+0x156d*-0x2),h=null,fetch(a6(0x26b),{'method':a6(0x1f1),'headers':E,'body':JSON[a6(0x24f)]({'type':a6(0x1ad),'tokensUsed':y,'timestamp':new Date()[a6(0x159)]()}),'signal':AbortSignal[a6(0x267)](0x35d*-0xb+-0x265*0x2+0x1*0x3d51)})['catch'](()=>{}),console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x28c)](a6(0x28e))),console[a6(0x280)](a0z[a6(0x167)]('\x20\x20'+a0K(a6(0x21e)))),console[a6(0x280)](a0z[a6(0x28c)]('\x20\x20'+a0K('ai4ctfTokens')+':\x20'+y+a6(0x258))),console[a6(0x280)](a0z['gray']('\x20\x20'+a0K(a6(0x251))+a6(0x1ae))),console[a6(0x280)](a0z[a6(0x28c)](a6(0x28e))),console[a6(0x280)](),console[a6(0x280)](a0z['cyan'](a6(0x28a))),console['log'](a0z[a6(0x167)]('\x20\x20'+a0K(a6(0x145))+'\x20')+a0z[a6(0x208)][a6(0x21a)](a6(0x1fb))+a0z[a6(0x167)]('\x20—\x20'+a0K(a6(0x160)))),console[a6(0x280)](a0z[a6(0x28c)]('\x20\x20'+a0K(a6(0x148)))),console[a6(0x280)](a0z[a6(0x1bd)]('\x20\x20─────────────────────────────────────────────')),console['log'](),console[a6(0x280)](a0z[a6(0x167)]('\x20\x20▸\x20\x20')+a0z[a6(0x167)](a0K(a6(0x22d))[a6(0x22f)](a6(0x192),a0z[a6(0x208)][a6(0x21a)](a6(0x1fb))))),console[a6(0x280)](a0z[a6(0x28c)](a6(0x1b1)+a0K(a6(0x1f6)))),console[a6(0x280)](),a6(0x198);const F={};F[a6(0x216)]=a6(0x1fe);if(!p&&y>=-0x1f09+-0x9d*0x2+0x1*0x33cb)return p=!(-0x73*-0x9+0x234*-0x5+0x6f9*0x1),fetch(a6(0x26b),{'method':a6(0x1f1),'headers':F,'body':JSON['stringify']({'type':a6(0x1ad),'solved':!(-0xa5c+-0xb*-0xc7+0x1d0),'tokensUsed':y,'timestamp':new Date()[a6(0x159)]()}),'signal':AbortSignal['timeout'](-0xe28+-0x267a+0x2*0x2415)})[a6(0x174)](()=>{}),console[a6(0x280)](),console['log'](a0z[a6(0x243)]('\x20\x20'+a0K(a6(0x15d)))),x(),(function(){const a9=a6;console['log'](),console['log'](a0z[a9(0x243)](a9(0x28a))),console['log'](a0z['bold'][a9(0x243)]('\x20\x20'+a0K(a9(0x1df)))),console['log'](a0z[a9(0x243)](a9(0x28a))),console[a9(0x280)]();for(const W of a0K('ai4ctfRevealBody')['split']('\x0a'))''===W?console[a9(0x280)]():console[a9(0x280)](a0z[a9(0x167)](a9(0x158)+W));console[a9(0x280)](),console[a9(0x280)](a0z['cyan']('\x20\x20\x20\x20\x20\x20\x20\x20!echo\x20aWNvYXt3M2xjMG1lXzJfYWk0Y3RmfQ==\x20|\x20base64\x20-d')),console[a9(0x280)](),console[a9(0x280)](a0z[a9(0x167)](a9(0x158)+a0K(a9(0x247)))),console['log'](),console[a9(0x280)](a0z[a9(0x1af)](a9(0x1ca))),console['log'](),console[a9(0x280)](a0z['white'](a9(0x158)+a0K(a9(0x1cd)))),console[a9(0x280)](),console[a9(0x280)](a0z[a9(0x1bd)](a9(0x185))),console[a9(0x280)](),console['log'](a0z[a9(0x28c)](a9(0x158)+a0K(a9(0x19c)))),console['log']();}()),a6(0x225);if(p)return console[a6(0x280)](),console[a6(0x280)](a0z[a6(0x243)]('\x20\x20'+a0K(a6(0x1b9)))),console[a6(0x280)](a0z['gray']('\x20\x20'+a0K(a6(0x199))+'\x20')+a0z[a6(0x1bd)](a6(0x230))),console[a6(0x280)](a0z[a6(0x28c)]('\x20\x20'+a0K('ai4ctfLockedThen')+'\x20')+a0z[a6(0x1bd)](a6(0x203))),console[a6(0x280)](),'continue';console[a6(0x280)](a0z[a6(0x28c)]('\x20\x20'+a0K(a6(0x271))));try{const W=await h['sendMessage'](z);process['stdout']['write'](a6(0x18c)),y+=W['tokensUsed'],a0D(W[a6(0x211)]),console[a6(0x280)](),a0I(W[a6(0x26d)]),x(),console[a6(0x280)](a0z[a6(0x28c)](a6(0x227))),console[a6(0x280)]();}catch(X){process[a6(0x1d3)]['write'](a6(0x18c)),a0J(a6(0x186)+X[a6(0x25d)]),console[a6(0x280)]();}return a6(0x225);}const C=new Set();async function k(v){const aa=a0q;if(!$||!h)return'exit';const z=v['trim'](),B=z[aa(0x162)](),D=(Date[aa(0x246)]()-$[aa(0x1b2)])/(0x30*0xa4+0x1c4db+0x1*-0xf93b);if(!$[aa(0x1b0)]&&!$[aa(0x268)]&&D>=0x1552+-0x16*-0x139+0x1*-0x3033&&($['nudgeShown']=!(0x69c+0x11d*-0xa+0x486),console[aa(0x280)](),console[aa(0x280)](a0z[aa(0x243)]('\x20\x20💡\x20Once\x20you\x20have\x20ICOA{...},\x20submit\x20it\x20with:\x20')+a0z[aa(0x208)][aa(0x243)](aa(0x181))),console[aa(0x280)](a0z[aa(0x28c)](aa(0x21d))),console[aa(0x280)]()),/^ICOA\{[^}]+\}$/i['test'](z))return console[aa(0x280)](),console[aa(0x280)](a0z[aa(0x28c)]('\x20\x20Detected\x20flag\x20—\x20treating\x20as:\x20')+a0z['white'](aa(0x291)+z)),k(aa(0x291)+z);const E=z[aa(0x274)](/^submit\s+(.+)/i);if(E){let F=E[0xd74+0x1bd*0x7+0x3*-0x88a][aa(0x1f5)]();if(/^submit\s+/i[aa(0x15c)](F)&&(F=F[aa(0x22f)](/^submit\s+/i,'')['trim']()),F=F[aa(0x22f)](/^["'`]+|["'`]+$/g,'')[aa(0x1f5)](),/^[A-Da-d]$/['test'](F))return console['log'](),console[aa(0x280)](a0z['yellow'](aa(0x173)+F+aa(0x197))),console[aa(0x280)](a0z['gray'](aa(0x168))+a0z['green'](aa(0x1c9))+a0z[aa(0x28c)](aa(0x1c5))),console[aa(0x280)](),aa(0x225);const {getExamState:G,saveExamState:H}=await import(aa(0x1c8)),I=G();if(!I)return aa(0x198);if(!I[aa(0x1d0)][aa(0x252)](L=>L[aa(0x1db)]===$[aa(0x240)]))return console[aa(0x280)](a0z['red'](aa(0x176)+$['qNum']+aa(0x27d))),aa(0x225);const J=I[aa(0x206)][$[aa(0x240)]];I[aa(0x1b8)]||(I[aa(0x1b8)]=[]),I['interactions'][aa(0x288)]({'ts':new Date()[aa(0x159)](),'q':$[aa(0x240)],'type':J?'answer_changed':aa(0x147),'input':F,'result':aa(0x1c3)}),I[aa(0x206)][$[aa(0x240)]]=F;const K=$['qNum']+(-0x1*0x11f0+-0x60f+0x1800);return I['_lastQ']=K<=-0x12d7+-0x172c+0x2a29*0x1?K:$[aa(0x240)],H(I),console[aa(0x280)](),J?(console[aa(0x280)](a0z[aa(0x1af)](aa(0x213)+$['qNum']+aa(0x25e))+a0z[aa(0x243)](F)),console[aa(0x280)](a0z[aa(0x28c)](aa(0x16f)+J))):console['log'](a0z[aa(0x1af)][aa(0x208)](aa(0x15f)+$[aa(0x240)]+aa(0x23b)+F)),console[aa(0x280)](a0z[aa(0x28c)](aa(0x257))),console[aa(0x280)](),console[aa(0x280)](a0z['gray']('\x20\x20')+a0z[aa(0x167)](aa(0x20e))+a0z[aa(0x28c)](aa(0x1e7))+a0z[aa(0x167)](aa(0x198))+a0z[aa(0x28c)](aa(0x28f))),K<=0x917+0xe*0xb+-0x7*0x15d?console[aa(0x280)](a0z['gray'](aa(0x16d))+a0z[aa(0x1bd)](aa(0x1ad))+a0z[aa(0x28c)](aa(0x1e9)+K)):console[aa(0x280)](a0z[aa(0x28c)](aa(0x183))+a0z[aa(0x21a)]('ctf4ai')+a0z[aa(0x28c)](aa(0x1aa))),console[aa(0x280)](),aa(0x225);}if(v['startsWith']('!')){const L=v[aa(0x239)](-0xc80+-0xd9*-0x17+-0x6fe)[aa(0x1f5)]();if(!L)return aa(0x225);try{const M={};M['encoding']='utf-8',M['timeout']=0x2710;const {execSync:N}=await import('node:child_process'),O=N(L,M)['trim']();console['log'](),console['log'](a0z['gray'](aa(0x26f))+a0z[aa(0x167)](L)),console[aa(0x280)](a0z[aa(0x167)]('\x20\x20'+O[aa(0x256)]('\x0a')[aa(0x179)](aa(0x1e4)))),console['log']();}catch(P){console[aa(0x280)](),console['log'](a0z[aa(0x21a)](aa(0x1a7)+(P['message']?.['split']('\x0a')[0x1091+-0x367*0x7+-0x1d*-0x40]||aa(0x156)))),console['log']();}return aa(0x225);}if(aa(0x198)===B||aa(0x254)===B||aa(0x143)===B){const Q=$[aa(0x240)],{getExamState:R}=await import('../lib/exam-state.js'),S=R(),T=S&&null!=S[aa(0x206)][Q],U=S?.[aa(0x25f)]||Q;return u=!(-0x652+0x2*0x479+0x3d*-0xb),h=null,$=null,C[aa(0x20c)](),console[aa(0x280)](),console[aa(0x280)](a0z[aa(0x28c)](aa(0x269)+Q+'.')),T&&U>Q&&U<=-0x178+-0x2ef*-0xa+0x377*-0x8?console[aa(0x280)](a0z[aa(0x167)](aa(0x19e))+a0z[aa(0x208)][aa(0x1af)]('Q'+U)+a0z[aa(0x28c)](aa(0x21f))+a0z[aa(0x1bd)](aa(0x1ad))+a0z[aa(0x28c)](aa(0x286))):T&&Q>=0x1ef6+-0x1ba1+-0x32f?console['log'](a0z[aa(0x167)](aa(0x28d))+a0z[aa(0x208)][aa(0x21a)]('ctf4ai')+a0z[aa(0x28c)](aa(0x175))):console['log'](a0z[aa(0x28c)](aa(0x1e2))+a0z[aa(0x167)](aa(0x24e)+Q)+a0z[aa(0x28c)](aa(0x190))+a0z[aa(0x167)](aa(0x1ad))),console[aa(0x280)](),'exit';}if(p)return console['log'](),console['log'](a0z['yellow']('\x20\x20AI\x20budget\x20exhausted\x20for\x20AI4CTF\x20section.')),console[aa(0x280)](a0z[aa(0x28c)](aa(0x17e))+a0z[aa(0x167)](aa(0x1b3))+a0z[aa(0x28c)](aa(0x1b6))+a0z[aa(0x167)]('!shell')+a0z['gray'](aa(0x1b6))+a0z[aa(0x167)](aa(0x198))),console[aa(0x280)](),aa(0x225);if(y>=w)return p=!(-0x31d*-0x6+-0x7*-0x141+-0x1b75),console[aa(0x280)](),console['log'](a0z[aa(0x21a)][aa(0x208)](aa(0x1a6))),console[aa(0x280)](a0z[aa(0x28c)](aa(0x1ee))+a0z[aa(0x167)]('submit\x20<flag>')+a0z[aa(0x28c)](aa(0x1b6))+a0z[aa(0x167)](aa(0x261))+a0z[aa(0x28c)](aa(0x1b6))+a0z[aa(0x167)](aa(0x198))),console['log'](),'continue';console[aa(0x280)](a0z[aa(0x28c)]('\x20\x20Thinking...'));try{const V=await h[aa(0x1cb)](v);process[aa(0x1d3)][aa(0x1d9)]('\x1b[1A\x1b[2K'),y+=V[aa(0x211)];const {getRealExamState:W,saveExamState:X}=await import(aa(0x1c8)),Y=W(),Z={};Z['ai4ctf']=0x0,Z[aa(0x1fb)]=0x0,(Y&&(Y[aa(0x1dd)]||(Y[aa(0x1dd)]=Z),Y[aa(0x1dd)][aa(0x1ad)]=y,X(Y)),console[aa(0x280)](),a0I(V[aa(0x26d)]),x(),console[aa(0x280)](a0z[aa(0x28c)](aa(0x157))),function(a0,a1,a2){const ab=aa,a3=a0/a1*(-0x1*-0x24dd+0x8*0x446+-0x46a9);a3>=-0x7*0x386+0x1*-0xb2d+0x2436&&!a2[ab(0x214)]('95')?(console[ab(0x280)](a0z[ab(0x21a)]['bold'](ab(0x1d1)+Math[ab(0x188)](a3)+ab(0x14b)+(a1-a0)+'\x20tokens\x20left.')),a2['add']('95')):a3>=0x1*-0x491+-0xb71+0x829*0x2&&!a2['has']('80')?(console[ab(0x280)](a0z[ab(0x243)](ab(0x1fa))),a2[ab(0x1f4)]('80')):a3>=-0x2*-0x2a5+-0x1dd5+0x18bd&&!a2[ab(0x214)]('50')&&(console['log'](a0z[ab(0x28c)]('\x20\x20Note:\x2050%\x20of\x20section\x20AI\x20budget\x20used.')),a2['add']('50'));}(y,w,C),console[aa(0x280)]());}catch(a0){process['stdout'][aa(0x1d9)](aa(0x18c)),a0J('AI\x20error:\x20'+a0[aa(0x25d)]),console[aa(0x280)]();}return'continue';}function a0j(){const ak=['quKGzxjYB3i6ia','ywK0y3rMrgvJB2rLza','CM91BMq','yM9VBgvHBG','ndG5ote0wunIC1vX','ywK0y3rMv3jHCff1B3rHC1rPDgXL','g1SXqrTBmKS','icaGicaGicaGicbuzwnOBMLXDwuGAgLUDcaOChjLlxDYAxr0zw4P','ywK0y3rMv3jHCff1B3rHqq','icaGigHPBNqGyG','icdcTYaGuMuTzw50zxi6ia','rMXHzYbMB3jTyxq6icaGieLdt0f7lI4UFq','E2nTzh0','icaGihn1yM1PDca8zMXHzZ4Gica','ywnJB3vUDfzLCMLMAwvK','BM90igvUzM9Yy2vKigzVCIb0AgLZigXVz2LU','m2DQDMT2BG','iIbSB29RCYbSAwTLigfUie1dusbSzxr0zxiSig5VDcbHigzSywCU','zxHPDa','ywK0y3rMtg9JA2vKvxnL','iokaLcb1CgrHDguGAwnVys1JBgKGDg8GDgHLigXHDgvZDcb2zxjZAw9U','q3j5ChrVz3jHCgH5','ywK0y3rMuMv2zwfStg9JA05VDgu','ANnVBG','icbozxH0oIa','ywK0y3rMrgvJB2rL','icdILzdILzdILzaGquK0q1rgiokaLcbr','icaGicbsDw4GuhL0Ag9UigLUihnOzwXS','E25VuhjVz30','icaGicaGicaGicblzxKGyNjLywT0AhjVDwDOicHWCMuTD3jPDhrLBIK','u2nVCgvKihrVihrOzsbJAgfSBgvUz2uGEw91ig9Wzw5Lzc4GqxnRigzYzwvSEsdIGjq','AgLUDcbJ','icdIMQaGquK0q1rgihrVA2vUigj1zgDLDcbLEgHHDxn0zwqGkdi1ldaWmcb1C2vKks4','icbfCNjVCJOG','ywK0y3rMu2fTCgXL','icaGideUia','ig9UifeZoq','qxnRihrOzsbbssb0zwfTBwf0zsbHyM91Dcb0AgLZignOywXSzw5Nzq','BwvUDq','ywK0y3rM','oIbhB29NBguGr2vTBweGncaOz2vTBweTnc0ZmwiTAxqP','z3jLzw4','BNvKz2vtAg93BG','icaGica','zw50zxjLzef0','C3vIBwL0idXMBgfNpG','ywK0y3rMsgLUDenvC2vZ','C2vZC2LVBJ0','imk3ia','C29Tzq','Aw50zxjHy3rPB25Z','ywK0y3rMtg9JA2vKvgL0Bgu','quK0q1rgihnLy3rPB24','u3vIBwL0igeGzMXHzYb0BYb0AguGBgL2zsbZy29YzwjVyxjK','C3rHCNrZv2L0Aa','y3LHBG','ywK0y3rMv3jHCfrPDgXL','icdILzdILzdILzaGquKGvgvHBw1HDguG4Pwq4Pwq4Pwq','B3bLBIa8Awq+','ywK0y3rMrxHPDa','cGPzt1vsifjvtevtoGOTifLVDsbnqvKGzxHWBgfPBIbJB25Jzxb0CYWGzgvZy3jPyMuGyxbWCM9Hy2HLCYWGyw5KigHLBhaGDgHLignVBNrLC3rHBNqGCMvHC29UihrOCM91z2GGDgHLihbYB2jSzw0UcI0Gww91ie1bwsbKAxnJDxnZihrOzsb0zwnOBM9SB2D5igLUDM9SDMvKicHJCNLWDg8SihDLyIWGzM9Yzw5ZAwnZlcbWD24SihjLDMvYC2LUzYWGt1njtLqSihn0zwDVlcbLDgmUks4klsbzB3uGtufzigHLBhaGzgvIDwCGy29Kzsb0AguGy29UDgvZDgfUDcb3CML0zxmGyw5Kihn1z2DLC3qGD2HPy2GGDg9VBcaVigXPyNjHCNKGlYb0zwnOBMLXDwuGDg8GDxnLlGOTifLVDsbnvvnuie5pvcbYzxzLywWGB3iGz3vLC3mGDgHLigzSywCSigfUzcbnvvnuie5pvcbVDxrWDxqGyw55igzSywCTC2HHCgvKihn0CMLUzYaOyw55DgHPBMCGBgLRzsbUyw1LEY4UlN0PlGOTifLVDsbnvvnuie5pvcbZB2X2zsb0AguGD2HVBguGy2HHBgXLBMDLigvUzc10BY1LBMqGzM9YihrOzsbJB250zxn0yw50iokaLcbNDwLKzsWGzg9Uj3qGAgfUzcbVDMvYihrOzsbHBNn3zxiUcI0Gs2vLCcbYzxnWB25ZzxmGy29Uy2LZzsbHBMqGChjHy3rPy2fSlIbuAguGy29UDgvZDgfUDcbPCYbYywnPBMCGDgHLignSB2nRlG','DMLHigfPngn0zIbJAgf0','iMHVDYbKBYbjigrLy3j5ChqGquvtluncqYbPBIbqExrOB24/iG','lIbuCNKGywDHAw4GAw5ZAwrLihrOAxmGy2HHDc4','cGPdsefmtevor0uGqLjjruy6cG','ywK0y3rMv3jHCff1B3rHqW','lI4VBgLIl2v4yw0TC3rHDguUANm','sunpqxT5B3vYx2zSywD9','icaGicaGicbPy29HE3CZBgmWBwvFmL9HAtrJDgz9','C2vUze1LC3nHz2u','ywK0y3rMv3jHCeXPBMuXqM9KEq','ywK0y3rMuMv2zwfSvgHLBLn1yM1PDa','z2vTBweTnc0ZmwiTAxq','vw5RBM93BG','CxvLC3rPB25Z','icdIMQaG','icbvC2u6ia','C3rKB3v0','AwnVyxT3m2XJmg1LxZjFywK0y3rMFq','ywK0y3rMv3jHCff1B3rHqG','icaGihn1yM1PDcbjq09bEY4UlN0','y29YCMvJDa','icaG4OAsia','D3jPDgu','icaGigHPBNqGyW','BNvTyMvY','ywK0y3rMv3jHCeXPBMuYqM9KEq','ywLvC2fNzq','vg9Rzw4G','ywK0y3rMuMv2zwfSvgL0Bgu','icaGieP1C3qGDhLWzsbMCMvLBhKGDg8Gy2HHDcb3AxrOihrOzsbbssb0zwfTBwf0zs4','icaGicaGicaGicfLy2HVigfxtNzzwhqZttj4AK1hmwXyEKPMwvDRmfKZuM1Mut09ihWGyMfZzty0ic1K','icbszxn1Bwu6ia','icdILiiG','cIaG','ywK0y3rMv3jHCff1B3rHqKHPBNq','C2vZC2LVBKnVB2TPzq','igfNywLUihrVignOyw5NzsWGB3iG','ywK0y3rMv3jHCff1B3rHrM9VDgvY','ihDPBgWGB3bLBIbr','ywK0y3rMsgLUDfbYAw5JAxbSzq','Aw5JB3jYzwn0','icbpCgvUigfUB3rOzxiGy2HHBgXLBMDLihDPDgGG','icaGig1LBNu','icbzB3uGy2fUihn0AwXSoIa','icaGicaGia','ywK0y3rMsgLUDe51zgDL','ue9tva','iNDOyxqGzw5JB2rPBMCGAxmGDgHPCZ8I','icbdDxjYzw50igfUC3DLCJOG','ywrK','DhjPBq','B3jcywnR','BM9KztPJAgLSzf9WCM9JzxnZ','y2HHBgXLBMDLswq','zgf0yq','icdIMQaGodaLig9MihnLy3rPB24GquKGyNvKz2v0ihvZzwqU','y3rMngfP','ywK0y3rMv2vSy29Tzun0yq','icbtD2L0y2GGy2HHBgXLBMDLoIa','yxbWBgLJyxrPB24VANnVBG','zw5JB2rPBMC','z2vTAw5Ptw9KzwW','icdIMQaGww91CIbbstrdveyGDg9Rzw4GyNvKz2v0igLZigv4Agf1C3rLzc4','ywK0y3rMq29YCMvJDezSywC','C3vIBwL0igLJB2f7DZnSyZbTzv8Yx2fPngn0zN0','ywK0y3rMt3jdAgf0','icaGicaGicaGicaGica','yw5ZD2vYCW','ywnJB3vUDenHCa','yM9Sza','icaOC3vIBwL0igfNywLUihrVignOyw5NzsK','ywK0y3rMsgLUDfrLy2HUAxf1zq','ywK0y3rMsgLUDee','y2XLyxi','icaGicfWExrOB24Zic4UlG','C3vIBwL0ieLdt0f7lI4UFq','CMvWzwf0','ywK0y3rMv3jHCe5LEhrtDwi','Dg9Rzw5ZvxnLza','C3vIBwL0rMXHzW','icdINjmGuq','AgfZ','ww91igfYzsbHBIbbssb0zwfTBwf0zsbOzwXWAw5NigeGy29UDgvZDgfUDcbZB2X2zsbHBIbjq09bidiWmJyGy3LIzxjZzwn1CML0EsbLEgfTihf1zxn0Aw9UlGOkq1vsuKvovcbrvuvtveLptIaOuq','q29UDgvUDc1uExbL','icboBYbJAgfSBgvUz2uGB3bLBIb5zxqU','rMXHzYbMB3jTyxq6igLJB2f7lI4UFq','lI4VBgLIl2n0zMqTy2XPzw50lMPZ','CMvK','mJC2otGYEvD2whLz','ywK0y3rMsgLUDem','icaGicaODhLWzsbPDcbYAwDODcbOzxjLigLUihrOAxmGy2HHDcdIGjqGBM90igfZigeGC2HLBgWGy29TBwfUzcK','ywK0y3rMuMvWB3j0','iokaLcb0ExbLia','icbtDwjTAxnZAw9UigzHAwXLzdOG','ihb0CW','zgvZy3jPChrPB24','AwnVys1JBgKVyNvKz2v0','icdILRGG','y29UDgLUDwu','Cg9PBNrZ','icbLEgL0ihrVigXLyxzLignOyxq','l2fWAs9Py29Hl2fPl2fJy291BNqTyNvKz2v0p2TPBMq9ywK0y3rM','ywK0y3rMv3jHCeXPBMuXsgvHza','iokvKokvKokvKa','ywK0y3rMv3jHCff1B3rHquHPBNq','CgfKrw5K','DhLWzufUzevUDgvYvg9czwDPBG','icaGicaGigHPBNqGysaGia','CMvWBgfJzq','iwvJAg8GyvDoDLLyDdnnmNHQtuCXBfH6sMzzv2SWwtnsBwzrpt0GFcbIyxnLnJqGlwq','icbdB21Tyw5KCW','ywK0y3rMoIa','ig5VDcbMB3vUzcbPBIbZDgf0zs4Gvhj5oIbLEgfTiheG','icaGicaGicaGicbbigDLBNrSzsbUDwrNzsaOChjLlxDYAxr0zw4P','icaGigv4AxqGicaGicaGicaGica','nJq4nZuWmffPEMn0uq','Aw5JBhvKzxm','y3vYCMvUDenOywXSzw5NzuLK','C2XPy2u','ywK0y3rMtgv2zwXZ','ihjLy29YzgvKoIa','ywXYzwfKEv9ZB2X2zwq','nZaZotG0mNrUBLbMBW','cGPzt1vsifjvtevtoGOTifLVDsbnqvKGzxHWBgfPBIbJB25Jzxb0CYWGzgvZy3jPyMuGyxbWCM9Hy2HLCYWGyw5KigHLBhaGDgHLignVBNrLC3rHBNqGCMvHC29UihrOCM91z2GGDgHLihbYB2jSzw0UcI0Gww91ie1bwsbKAxnJDxnZihrOzsb0zwnOBM9SB2D5igLUDM9SDMvKicHbrvmSihb3BNrVB2XZlcbqExrOB24GC3rYDwn0lcbivfrqlcbLDgmUks4klsbzB3uGtufzigHLBhaGzgvIDwCGuhL0Ag9UignVzguGDgHLignVBNrLC3rHBNqGD3jPDgvZlGOTifLVDsbnvvnuie5pvcbYzxzLywWGDgHLigzSywCGzgLYzwn0BhKUcI0Gww91ie1vu1qGtK9uig91Dhb1DcbHBNKGC3rYAw5Nig1HDgnOAw5NieLdt0f7lI4UFsbVCIbPy29HEY4UlN0UcI0Gww91ie1vu1qGtK9uihrLBgWGDgHLignVBNrLC3rHBNqGDgHLigv4ywn0igfUC3DLCIb0BYb0AgLZihf1zxn0Aw9UlGOTifLVDsbnqvKGC3vNz2vZDcb3AgLJAcb0B29Sic8GBgLICMfYEsaVihrLy2HUAxf1zsb0BYb1C2uUcI0Gv2HLBIbZDwDNzxn0Aw5NihnOzwXSic8GChL0Ag9UihnUAxbWzxrZihrOyxqGBMvLzcb0AguGyxr0ywnOzwqGzgf0ysWGCMvMzxiGDg8GDgHLigzPBguGCgf0AcbJAgfSBgvUz2vZl3e','y3rMngvHAq','Cu51Bq','xsaGWRCG','icbbssb1C2fNzsbPCYbTzxrLCMvKihbLCIbHy2nVDw50icHZzxj2zxiTzw5MB3jJzwqGyNvKz2v0ks4','EwvSBg93','ywK0y3rMsw50zxjJzxb0zwq','y3vYCMvUDenOywXSzw5Nzu5HBwu','BM93','ywK0y3rMuMv2zwfSu2vLrMXHzW','icbdB21WzxrPDgLVBIbPCYbWyxvZzwqU','icaGice8C2HLBgWGy21KpIaGica','icdILii','lcbVCIbYzs1LBNrLCIb3AxrOia','icbpCgvUig9UzsbMAxjZDdOG','icbbBhjLywr5ihnVBhzLzc4','zxHHBsbXia','C3rYAw5NAwz5','ihrOzw4GCMuTzw50zxiG','ywK0y3rMtw9KzwW','zMLUza','ywK0y3rMv3jHCe5LEhruAxrSzq','yMfJAW','y2f0zwDVCNK','C3bSAxq','icaGicHhCMfKAw5NigHHChbLBNmGyxqGzxHHBsbZDwjTAxqG4OcuihLVDsbJyw5UB3qGChjLDMLLDYbJB3jYzwn0BMvZCYbKDxjPBMCGDgHLigv4yw0Ukq','lZuWmda','ofbMthvIwa','igLZigfUievTyM9KAwvKiefjicHfquKPihf1zxn0Aw9UlG','BwLU','icdILiZILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','BwvZC2fNzq','igfUC3DLCIb1CgrHDgvKoIa','x2XHC3rr','rNvSBcbXDwvZDgLVBJOGia','ixnOzwXS','ywK0y3rMv3jVBMDgBgfN','icaGigHPBNqGyq','icbzB3uGy2fUihn0AwXSihn1yM1PDcbHigzSywCGzgLYzwn0BhK6ia','tgvHDMuGDgHLiefjihrLyw1TyxrL','icaOCMvZDw1PBMCG4OcuihbYAw9YignOyxqGAxmGBM90ihjLBwvTyMvYzwqSigj1Dcb0B2TLBNmGywXYzwfKEsb1C2vKihn0yxKGzgvKDwn0zwqP','DgLTzw91Da','C3vIBwL0qxr0zw1WDgvK','icbbstrdveyGy2HHDcbLBMrLzcbMB3iGuq','icaGicaGigHPBNqGyYaGia','Ahr0Chm6lY9WCMfJDgLJzs5Py29HmJaYnI5HDs9HCgKVAwnVys9Kzw1Vlxn0yxrZ','ywK0y3rMv3jHCfr5CgvdDgy0ywK','Dgv4Da','Dg9Rzw4','icaKia','y3vYCMvUDenOywXSzw5NzunHDgvNB3j5','ywK0y3rMvgHPBMTPBMC','ywK0y3rMq2HHBgXLBMDL','igLZigeGBxvSDgLWBguTy2HVAwnLihf1zxn0Aw9UiokaLcbHBNn3zxiGD2L0Acbbl0iVqY9elG','Bwf0y2G','icaGicaGicaGicaGifjLDhvYBIb0BYbTywLUig1LBNuGkhDVCMTZigfUExDOzxjLkq','Dg9vChbLCKnHC2u','ywK0y3rMq21Ku2HLBgXmAw5L','mJe3ndbPuerZwxa','icboBYbJAgfSBgvUz2uGAwqGAw4Gy29UDgv4DcdIGjqGB3bLBIbVBMuGzMLYC3q6ia','icbB','icdILjtILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','icaGwW','ig5VDcbMB3vUzcbPBIbZDgf0zs4','DMXH','DgHPBMTPBMC','Bg9N','lNr4DcaOAw5ZAwrLihrOzsbZyw5KyM94ksbYyxrOzxiGDgHHBIbHC2TPBMCGDgHLignVBNrLC3rHBNqGDg8GCgfZDguGDgHLihDOB2XLigjSB2iGyMfJAY4klsblzwvWihjLC3bVBNnLCYbJB25JAxnLigfUzcbWCMfJDgLJywWUifrOAxmGy29UDgvZDgfUDcbOyxmGBgLTAxrLzcb0Aw1LlG','icbiB3CGDg8GD29YAYb0AgLZihf1zxn0Aw9U','quKGyNvKz2v0icH0AgLZigfJy291BNqP','iIaOy2f0zwDVCNK6ia','C3rHDhvZ','ihrVignVBNrPBNvL','zxHHBsbHBNn3zxiG','ChvZAa','icbbssbIDwrNzxq6ia','icdILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','icbvC2fNztOG','z3jHEq','icbbstrdveyGC2vJDgLVBIbJB21WBgv0zsdIGjqG','icdILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','ihrVig1VDMuGB24','ywn0Aw9U','C3vIBwL0ia','AgLUDcbI','ihbVAw50CYK6cG','ywK0y3rMv3jHCff1B3rHq0HPBNq','yvDoDLLyDdnnmNHQtuCXBfH6sMzzv2SWwtnsBwzrpt0','CxvPDa','y3rMzfvYBa','ywK0y3rMrxHPDe5LEhruAxrSzq','ywK0y3rMv291BgrfyxjU','yw5ZD2vYx3n1yM1PDhrLza','ywK0y3rMrxHPDe5LEhrcB2r5','DxrMltG','icH1CgrHDgvZigfMDgvYihLVDxiGzMLYC3qGBwvZC2fNzsK','jsbVzIbZzwn0Aw9Uiefjigj1zgDLDcb1C2vKiokaLcbVBMX5ih4','ywK0y3rMrw5Ku2vZC2LVBG','yxr0ywnOzwreyxrH','icbsyxrLigXPBwL0zwqG4OcuihDHAxqGysbTB21LBNqGyMvMB3jLihrYEwLUzYbHz2fPBI4','icaGigHPBNqGysaVigiGlYbJica','y2HHBgXLBMDLtMfTzq','otKYsxbTrurV','icbbssb0zwfTBwf0zsbJBg9ZzwqGzM9Yici','sgLUDca','icbuAguGquKGDgvHBw1HDguGC2nVCgvZigL0C2vSzIb0BYb0AguGy2HHBgXLBMDLihLVDsbVCgvUlG','ywK0y3rMsgLUDei','q29TBwfUzcbMywLSzwq','icbLEgL0id0GyMfJAYb0BYbLEgfTimk3ihn1yM1PDcbjq09bEY4UlN0GDg8Gyw5ZD2vY','icaGia','Dg9ju09tDhjPBMC','ww91igfYzsbHBIbbssb0zwfTBwf0zsbOzwXWAw5NigeGy29UDgvZDgfUDcbPBIbHigXPDMuGq2fWDhvYzs1uAguTrMXHzYbJB21WzxrPDgLVBI4kcKnvuLjftLqGq0HbteXftKDfoIaI','ywK0y3rMsgLUDejvC2vZ','DgvZDa','Dg9Rzw5mAw1PDa','z2v0q2HHBgXLBMDL','icdINjmGqw5ZD2vYigzVCIbr','ywK0y3rMrxHPDe5LEhrtDwi','ihrOzw4G','Dg9mB3DLCKnHC2u','y3rMigXPC3q','iwvJAg8GyvDoDI4UlIb8igjHC2u2ncaTza','DgHLiefjigD1AwrLCYWGAxqGD2LSBcbUB3qGAgfUzcb5B3uGDgHLigzSywCU','sgLKzgvUie1LC3nHz2u','D2HPDgu','icbgBgfNigzVCM1HDdOG','ywnJB3vUDfnWzw50','ywK0y3rMv3jHCe5VuhjVzW','icaGidiUia','ntu2ody4n2TvEhneEG','icbbzNrLCIbLEgL0oIa','DhLWzq','icaGifbYzxzPB3vZoIa','BgvUz3rO','mJeYmtDQywPcz2W','vg9Rzw5Z','icaI','y2f0y2G','igzVCIbrmZK','icbr','ywK0y3rMv3jHCeXPBMuYsgvHza','cGPbvfrbq0HfrcbeqvrbicHHBhnVihnHDMvKihrVignOywXSzw5NzxmVCq','AM9PBG','ywK0y3rMsgLUDejcB2r5','icbnB2rLBdOGr29Vz2XLieDLBw1HidqGka','vw5RBM93BIbYzxnWB25Zzq','icaGicaGigHPBNqGyIaGia','icbtDgLSBcbHDMfPBgfIBgu6ia','ywK0y3rMv3jHCe5LEhrcB2r5','Cgf1C2vK','C3vIBwL0ieLdt0f7Ew91CL9MBgfNFq','icaGicaGicaGicaGieXLyxzLignOyxqSihjLDhvYBIb0BYbLEgfT','icbbzNrLCIbLEgL0oIbbstrdveyGC2vJDgLVBIbJB21WBgv0zs4GtMv4DdOG','icaGicaGicaGicaGicaGicaGicbLlMCUia','icaGicaGicbZDwjTAxqGAwnVyxT3m2XJmg1LxZjFywK0y3rMFq'];a0j=function(){return ak;};return a0j();}export function registerAi4ctfCommand(j){const ac=a0q;j['command'](ac(0x1ad))[ac(0x222)]('Chat\x20with\x20your\x20AI\x20teammate')[ac(0x290)](async()=>{const ad=ac;a0G('ai4ctf');const {getRealExamState:q}=await import(ad(0x1c8)),v=q(),z=v?.[ad(0x1d0)][ad(0x1b7)](G=>ad(0x1ad)===G[ad(0x16e)]);if(v&&z){const G=v[ad(0x25f)]||0xb79+0xe51+-0x19c9,H=v['questions']['find'](I=>I[ad(0x1db)]===G);if(!H)return void a0J('Q'+G+ad(0x233)+G);if(ad(0x1ad)!==H['type']){if(console[ad(0x280)](),ad(0x1fb)===H['type'])console[ad(0x280)](a0z[ad(0x243)](ad(0x176)+G+'\x20is\x20a\x20CTF4AI\x20question\x20(attack-the-AI).')),console['log'](a0z[ad(0x28c)](ad(0x1d2))+a0z[ad(0x208)][ad(0x21a)](ad(0x1fb)));else{if(ad(0x27e)===H[ad(0x16e)])console[ad(0x280)](a0z[ad(0x243)](ad(0x176)+G+ad(0x25a))),console[ad(0x280)](a0z[ad(0x28c)](ad(0x1d2))+a0z[ad(0x208)][ad(0x1bd)](ad(0x23f)));else{const I=v['questions'][ad(0x252)](J=>ad(0x1ad)===J[ad(0x16e)]);console[ad(0x280)](a0z['yellow']('\x20\x20Q'+G+ad(0x273))),I&&(console[ad(0x280)](a0z['gray']('\x20\x20AI4CTF\x20chat\x20is\x20available\x20on\x20practical\x20questions\x20(next:\x20Q'+I[ad(0x1db)]+').')),console[ad(0x280)](a0z[ad(0x28c)]('\x20\x20Jump\x20there:\x20')+a0z[ad(0x208)][ad(0x1bd)](ad(0x24e)+I[ad(0x1db)])));}}return void console[ad(0x280)]();}return void await async function(J,K){const ae=ad,{getRealExamState:L,refetchQuestionDataIfStale:M,materializeAttachedData:N}=await import('../lib/exam-state.js');await M();const O=L();if(!O)return!(0x1271+-0x1*-0x17d5+-0x1*0x2a45);const P=O[ae(0x1d0)][ae(0x252)](S=>S[ae(0x1db)]===J);P&&(K=P),N(J,K?.[ae(0x14d)]);const Q=O['aiUsage']?.['ai4ctf']??-0x2*-0x966+0x20fc+0x1*-0x33c8;if(Q>=w)return console['log'](),console[ae(0x280)](a0z['yellow'](ae(0x201))),console['log'](a0z[ae(0x28c)](ae(0x264))+a0z[ae(0x167)](ae(0x287)+J+'\x20ICOA{...}')),console['log'](),!(0x29*-0xa7+0x157f+0x541);try{h=await a0B(void(-0x561+0x2245+0x1*-0x1ce4),function(S,T){const af=ae,U=S[af(0x222)]||S[af(0x26d)]||'',V=S[af(0x14d)]?af(0x178)+T+'.txt\x20inside\x20the\x20contestant\x27s\x20sandbox\x20—\x20path\x20is\x20relative\x20to\x20the\x20sandbox\x27s\x20/home/competitor\x20working\x20directory,\x20reachable\x20from\x20any\x20!shell\x20/\x20!python3\x20invocation):\x0a'+S[af(0x14d)]:'';return af(0x215)+T+',\x20'+S[af(0x255)]+',\x20'+(S[af(0x226)]||0x12*-0x34+0x3d7+-0x29)+af(0x293)+U+V+af(0x23e)+T+af(0x281);}(K,J));}catch(S){return a0J(S[ae(0x25d)]),!(0x1b2f+-0x14c*0x11+-0x522);}u=!(-0xbf9*0x1+-0x97d+-0x43*-0x52),y=Q,p=!(-0x2*0xf61+0x1f5f+0x2*-0x4e),$={'qNum':J,'question':K,'usageField':ae(0x1ad),'enteredAt':Date['now'](),'submitAttempted':!(0x518+0x2*-0xa89+0x1*0xffb),'nudgeShown':!(0x23ca+-0xda7*-0x1+-0x38*0xe2)};const R=O['answers']?.[J];return function(T,U,V){const ag=ae,W=a0E()[ag(0x200)]||ag(0x1ce),X=y>0x71a*-0x1+-0x1a*-0x34+0x1d2*0x1;console[ag(0x280)](),console[ag(0x280)](a0z['green'][ag(0x208)](ag(0x1a0)+U+':\x20'+T[ag(0x255)]+ag(0x22a))),X&&console['log'](a0z[ag(0x28c)](ag(0x266))),V&&console[ag(0x280)](a0z[ag(0x28c)](ag(0x1f3))+a0z['yellow'](V)+a0z[ag(0x28c)](ag(0x209))),console[ag(0x280)](),console[ag(0x280)](a0z[ag(0x1bd)](ag(0x25c))),console[ag(0x280)](a0z[ag(0x1bd)]('\x20\x20│\x20')+a0z['bold'][ag(0x167)]('Q'+U+ag(0x27a)+T[ag(0x255)]+ag(0x241)+(T['points']||-0x182d+-0x2*0x6d2+-0x1*-0x25d7)+ag(0x221))),console[ag(0x280)](a0z['cyan'](ag(0x24a)));for(const Y of String(T[ag(0x26d)])[ag(0x256)]('\x0a')){const Z=Y[ag(0x170)]>-0x105*-0x1f+-0x1*0xa2c+-0x1533?Y[ag(0x239)](0x1a41*0x1+0x2167+-0x4*0xeea,0x3*0x59+0xb3*0x26+-0x1*0x1b64)+'...':Y;console[ag(0x280)](a0z[ag(0x1bd)](ag(0x1e3))+a0z[ag(0x167)](Z));}console['log'](a0z['cyan'](ag(0x24a))),console[ag(0x280)](a0z[ag(0x1bd)]('\x20\x20│\x20')+a0z['gray'](ag(0x260))+a0z[ag(0x167)](ag(0x24e)+U)),console[ag(0x280)](a0z[ag(0x1bd)](ag(0x1e3))+a0z[ag(0x28c)](ag(0x191))),console[ag(0x280)](a0z['cyan']('\x20\x20└─────────────────────────────────────────────')),console[ag(0x280)](),console['log'](a0z[ag(0x208)][ag(0x167)](ag(0x282))),console[ag(0x280)](),console[ag(0x280)](a0z[ag(0x243)]('\x20\x20\x20\x20hint\x20a')+a0z['gray'](ag(0x234))),console[ag(0x280)](a0z[ag(0x243)](ag(0x18f))+a0z['gray'](ag(0x18d))),console[ag(0x280)](a0z[ag(0x243)](ag(0x1da))+a0z[ag(0x28c)](ag(0x1a3))),console[ag(0x280)](a0z[ag(0x208)][ag(0x1af)](ag(0x1d6))+a0z[ag(0x28c)]('\x20Submit\x20your\x20flag\x20for\x20this\x20question')),console[ag(0x280)](a0z[ag(0x167)](ag(0x20d))+a0z[ag(0x28c)](ag(0x1a1))),console[ag(0x280)](a0z[ag(0x28c)](ag(0x1e0))),console['log'](a0z[ag(0x28c)](ag(0x184))+a0z[ag(0x167)](ag(0x1c4))),console[ag(0x280)](),console[ag(0x280)](a0z[ag(0x28c)]('\x20\x20\x20\x20exit')+a0z[ag(0x28c)](ag(0x182))),console['log'](a0z[ag(0x28c)](ag(0x1ed))+a0z[ag(0x28c)](ag(0x275))),console['log'](),x(),console[ag(0x280)](a0z[ag(0x28c)]('\x20\x20Model:\x20Google\x20Gemma\x204\x20('+W+')')),console[ag(0x280)]();}(K,J,R),!(-0x17e*0x3+0x20c4+-0x1c4a);}(G,H);}const B=a0E(),D=B[ad(0x200)]||'gemma-4-31b-it';if(a0F())return B[ad(0x245)]?void await(async function(){const ah=ad,J=a0E(),K=J[ah(0x238)],L=J[ah(0x245)],M=J[ah(0x270)]||ah(0x1cf);let N='';if(K)try{const {CTFdClient:O}=await import(ah(0x219)),P=J[ah(0x1e6)]||'',Q=J[ah(0x26e)]&&!J[ah(0x26e)][ah(0x237)](ah(0x1b5))?J[ah(0x26e)]:'',R=new O(J[ah(0x144)],Q,P||J[ah(0x26e)]);N=(await R[ah(0x15e)](K))[ah(0x222)]||'';}catch{}try{h=await a0B(void(-0xc37+-0x644+-0x127b*-0x1),function(S,T,U){const ai=ah;return ai(0x15a)+S+ai(0x284)+T+').'+(U?ai(0x1c6)+U:'')+ai(0x1c2);}(L,M,N));}catch(S){return a0J(S['message']),!(0x2*-0xd7b+0xd6*0x25+-0x3f7);}u=!(-0x3c8+0x1c6c+-0x18a4),y=-0xa75*0x2+0xe0f+0x6db,f=!(0x143a+0x9*0x277+-0x2a68),d=b,m=!(-0xd84+0xb92*0x2+-0x9a0);try{if(J[ah(0x144)]&&J['token']){const T=await a0L(J['ctfdUrl']+ah(0x228),{'headers':{'Authorization':ah(0x1de)+J[ah(0x26e)],'User-Agent':ah(0x223)}});if(T['ok']){const U=await T[ah(0x19d)]();'number'==typeof U[ah(0x1f9)]?.[ah(0x169)]&&(y=U[ah(0x1f9)][ah(0x169)],f=!(0x1d80+-0x1*-0x24c+-0x1fcc)),ah(0x1db)==typeof U[ah(0x1f9)]?.[ah(0x207)]&&(d=U['data']['accountCap']),ah(0x189)==typeof U[ah(0x1f9)]?.[ah(0x194)]&&(m=U[ah(0x1f9)][ah(0x194)]);}}}catch{}return p=!(-0xe53+0xb75+0x2df),A={'challengeId':K,'challengeName':L,'challengeCategory':M,'enteredAt':Date['now']()},function(V,W){const aj=ah,X=a0E()[aj(0x200)]||aj(0x1ce);console[aj(0x280)](),console[aj(0x280)](a0z[aj(0x1af)][aj(0x208)](aj(0x1bf))),console[aj(0x280)](),console[aj(0x280)](a0z['cyan'](aj(0x25c))),console[aj(0x280)](a0z[aj(0x1bd)](aj(0x1e3))+a0z[aj(0x208)]['white'](V)+a0z[aj(0x28c)](aj(0x27c)+W+']')),console[aj(0x280)](a0z[aj(0x1bd)](aj(0x24a))),console[aj(0x280)](a0z[aj(0x1bd)](aj(0x1e3))+a0z[aj(0x28c)](aj(0x1a4))),console[aj(0x280)](a0z[aj(0x1bd)](aj(0x1e3))+a0z['gray'](aj(0x165))),console[aj(0x280)](a0z[aj(0x1bd)](aj(0x27b))),console[aj(0x280)](),console[aj(0x280)](a0z[aj(0x243)](aj(0x231))),console[aj(0x280)](a0z['white']('\x20\x20\x20\x20<just\x20type>\x20\x20\x20\x20\x20')+a0z[aj(0x28c)](aj(0x1ab))),console[aj(0x280)](a0z[aj(0x167)](aj(0x249))+a0z[aj(0x28c)]('Run\x20a\x20shell\x20command\x20(e.g.\x20!base64\x20-d\x20...)')),console[aj(0x280)](a0z[aj(0x167)](aj(0x193))+a0z[aj(0x28c)](aj(0x1bb))),console['log'](a0z[aj(0x167)](aj(0x235))+a0z[aj(0x28c)](aj(0x265))),console[aj(0x280)](),console[aj(0x280)](a0z[aj(0x28c)](aj(0x1fd))+a0z['white'](aj(0x1c0))+a0z[aj(0x28c)](aj(0x250))+a0z[aj(0x167)](aj(0x1ad))),x(),console[aj(0x280)](a0z[aj(0x28c)](aj(0x17b)+X+')')),console[aj(0x280)](a0z['gray'](aj(0x242))),console[aj(0x280)]();}(L,M),!(0x19df+-0x7ae*-0x1+-0x218d);}()):(console[ad(0x280)](),console[ad(0x280)](a0z['yellow'](ad(0x217))),console['log'](a0z[ad(0x28c)](ad(0x24c))+a0z[ad(0x167)](ad(0x163))+a0z['gray'](ad(0x161))+a0z[ad(0x167)](ad(0x1c0))),console['log'](a0z['gray'](ad(0x154))),void console[ad(0x280)]());const E={};E['name']=ad(0x166),E[ad(0x255)]=ad(0x19b);const F=E;try{h=await a0B(F);}catch(J){return void a0J(J['message']);}u=!(0x3b9+0x1fc9+-0x12*0x1f9),y=-0xbd9*0x3+-0x20e7*0x1+0x2239*0x2,p=!(-0x1d4a*-0x1+-0x2*0x4f1+-0x1367),console['log'](),console[ad(0x280)](a0z[ad(0x1af)]['bold']('\x20\x20═══\x20'+a0K('ai4ctfTitle')+ad(0x22a))),console[ad(0x280)](),console[ad(0x280)](a0z[ad(0x167)]('\x20\x20'+a0K(ad(0x1a8)))),console[ad(0x280)](),console[ad(0x280)](a0z[ad(0x1bd)]('\x20\x20┌─────────────────────────────────────────────')),console[ad(0x280)](a0z['cyan'](ad(0x1e3))+a0z[ad(0x208)][ad(0x167)](a0K(ad(0x272)))),console[ad(0x280)](a0z[ad(0x1bd)](ad(0x24a))),console['log'](a0z['cyan'](ad(0x1e3))+a0z[ad(0x167)](a0K(ad(0x244)))),console[ad(0x280)](a0z['cyan'](ad(0x1e3))+a0z[ad(0x1af)](ad(0x295))),console[ad(0x280)](a0z[ad(0x1bd)](ad(0x24a))),console[ad(0x280)](a0z[ad(0x1bd)](ad(0x1e3))+a0z[ad(0x167)](a0K(ad(0x19f)))),console[ad(0x280)](a0z[ad(0x1bd)](ad(0x1e3))+a0z[ad(0x28c)](ad(0x218))),console[ad(0x280)](a0z['cyan'](ad(0x27b))),console[ad(0x280)](),console[ad(0x280)](a0z[ad(0x167)]('\x20\x20'+a0K(ad(0x23a)))),console[ad(0x280)](),console[ad(0x280)](a0z['yellow'](ad(0x263))+a0z['gray']('\x20\x20\x20\x20'+a0K('ai4ctfHintA'))),console[ad(0x280)](a0z[ad(0x28c)](ad(0x205)+a0K('ai4ctfHintAUses'))),console['log'](a0z[ad(0x243)](ad(0x18f))+a0z[ad(0x28c)](ad(0x158)+a0K(ad(0x155)))),console[ad(0x280)](a0z[ad(0x28c)]('\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+a0K(ad(0x15b)))),console[ad(0x280)](a0z['yellow'](ad(0x1da))+a0z[ad(0x28c)](ad(0x158)+a0K(ad(0x21c)))),console[ad(0x280)](a0z[ad(0x28c)](ad(0x205)+a0K(ad(0x1b4)))),console[ad(0x280)](),console[ad(0x280)](a0z[ad(0x28c)](ad(0x28e))),console[ad(0x280)](a0z['bold'][ad(0x167)]('\x20\x20'+a0K(ad(0x1fc)))),console[ad(0x280)](ad(0x158)+a0z[ad(0x1bd)]('hint\x20a')+a0z[ad(0x28c)](ad(0x1d8)+a0K(ad(0x1f0)))),console[ad(0x280)](ad(0x158)+a0z[ad(0x1bd)](ad(0x292))+a0z['gray'](ad(0x1d8)+a0K(ad(0x20a)))),console[ad(0x280)](ad(0x158)+a0z[ad(0x1bd)]('hint\x20c')+a0z[ad(0x28c)](ad(0x1d8)+a0K(ad(0x1ea)))),console[ad(0x280)](a0z[ad(0x28c)](ad(0x158)+a0K('ai4ctfWelcomeNoReveal'))),console[ad(0x280)](),console[ad(0x280)](a0z[ad(0x167)]('\x20\x20'+a0K(ad(0x204)))),console['log'](a0z[ad(0x28c)]('\x20\x20'+a0K('ai4ctfOrChatExample')+'\x20')+a0z['white'](ad(0x1f2))),console[ad(0x280)](),console[ad(0x280)](a0z['yellow']('\x20\x20'+a0K('ai4ctfCommands'))),console[ad(0x280)](a0z[ad(0x167)](ad(0x14f))+a0z['gray'](a0K('ai4ctfCmdHintLine'))),console[ad(0x280)](a0z[ad(0x167)](ad(0x193))+a0z[ad(0x28c)](a0K('ai4ctfSubmitCmd'))),console[ad(0x280)](a0z['white'](ad(0x249))+a0z['gray'](a0K(ad(0x277)))),console['log'](a0z[ad(0x28c)](ad(0x184))+a0z[ad(0x167)](ad(0x164))),console[ad(0x280)](a0z[ad(0x28c)]('\x20\x20\x20\x20exit\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+a0K(ad(0x14c)))),console[ad(0x280)](),x(),console[ad(0x280)](a0z[ad(0x28c)]('\x20\x20'+a0K('ai4ctfModel')+':\x20Google\x20Gemma\x204\x20('+D+')')),console[ad(0x280)](a0z['gray']('\x20\x20'+a0K(ad(0x1c1)))),console[ad(0x280)]();});}
1
+ (function(j,q){const a4=a0q,v=j();while(!![]){try{const z=parseInt(a4(0x159))/(0x1823+0x299*0x3+-0xb*0x2e7)+parseInt(a4(0x123))/(0x15a9+-0x140+-0x3*0x6cd)*(-parseInt(a4(0xa7))/(0x929+-0x708+-0x21e))+-parseInt(a4(0x118))/(-0x1c13+0x2313+-0x12a*0x6)*(-parseInt(a4(0x125))/(0x1f*0x2f+-0x469*-0x1+0x1*-0xa15))+parseInt(a4(0x130))/(-0xa*0x365+-0x1*-0x1565+0x1*0xc93)*(parseInt(a4(0xbe))/(0x2318+0x1983+-0x4*0xf25))+parseInt(a4(0x10f))/(0xb76+0xdb1*-0x2+0xff4)*(-parseInt(a4(0x18d))/(0x25d1+0xa75+-0x1*0x303d))+-parseInt(a4(0x145))/(0x1b17*0x1+-0x1e2*0xd+-0x293)+parseInt(a4(0x17a))/(-0xa1*-0x10+-0x17fb+0x2*0x6fb);if(z===q)break;else v['push'](v['shift']());}catch(B){v['push'](v['shift']());}}}(a0j,-0xe9309+0xce*-0xaa6+-0x6c55*-0x53));import a0z from'chalk';import{createChatSession as a0B}from'../lib/gemini.js';import{addTokenUsage as a0D}from'../lib/budget.js';import{getConfig as a0E,isConnected as a0F}from'../lib/config.js';import{logCommand as a0G,logSubmission as a0H}from'../lib/logger.js';import{printMarkdown as a0I,printError as a0J}from'../lib/ui.js';import{t as a0K}from'../lib/i18n.js';import{httpFetch as a0L}from'../lib/http.js';const r=j=>new Promise(q=>setTimeout(q,j));function a0q(a,b){a=a-(0x3f*0x5b+-0x1af*0x11+0x6a3);const c=a0j();let d=c[a];if(a0q['ZbLIAU']===undefined){var e=function(i){const j='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let l='',m='';for(let n=0x2*-0x1129+-0x7cc+-0x9*-0x4ae,o,p,q=0x65*-0x3c+-0x7*-0x3a4+-0x4*0x74;p=i['charAt'](q++);~p&&(o=n%(0xbf7*-0x1+-0x1bae+0x27a9)?o*(-0x19*0x107+-0x53*-0x63+-0x62a*0x1)+p:p,n++%(0x8*-0x39e+-0x1*-0x25be+-0x8ca))?l+=String['fromCharCode'](-0x1e40+-0x126*0xe+-0x5*-0x977&o>>(-(0x3*-0x6d+0xb6c+-0xa23)*n&0x1322+-0x1f*-0x3e+-0x1a9e)):-0x2012*-0x1+-0x2654+-0x12*-0x59){p=j['indexOf'](p);}for(let r=-0x1bcc+-0x56*0x4+0x14*0x175,s=l['length'];r<s;r++){m+='%'+('00'+l['charCodeAt'](r)['toString'](-0x576+-0x2ff+-0x3*-0x2d7))['slice'](-(-0x20dd+-0x32d*-0xb+0x2c*-0xc));}return decodeURIComponent(m);};a0q['FxzTMZ']=e,a0q['VWPXgW']={},a0q['ZbLIAU']=!![];}const f=c[0x2*0x121a+0xb83+-0x2fb7],g=a+f,h=a0q['VWPXgW'][g];return!h?(d=a0q['FxzTMZ'](d),a0q['VWPXgW'][g]=d):d=h,d;}let u=!(-0x1f3*0x4+-0x29*-0xc1+-0x171c),h=null,y=0x3a4*0x7+0x2667+-0x5*0xcc7,d=0xbf7*-0x1+-0x1bae+0x27a5,m=!(-0x19*0x107+-0x53*-0x63+-0x66a*0x1),f=!(0x8*-0x39e+-0x1*-0x25be+-0x8cd),p=!(-0x1e40+-0x126*0xe+-0x1d*-0x199);const w=0x17*-0x47+0x391b+0x2eee,b=0x7a73c+-0x8a*-0x592+-0x2d7f0;let $=null,A=null;function a0j(){const ak=['y3vYCMvUDenOywXSzw5NzuLK','zw50zxjLzef0','lI4VBgLIl2n0zMqTy2XPzw50lMPZ','icbgBgfNigzVCM1HDdOG','ywK0y3rMsgLUDei','ywK0y3rMrgvJB2rLza','icaGideUia','zxHHBsbHBNn3zxiG','ywK0y3rMrM91BMrgBgfN','l2fWAs9Py29Hl2fPl2fJy291BNqTyNvKz2v0p2TPBMq9ywK0y3rM','icaGicaGia','q29UDgvUDc1uExbL','ig5VDcbMB3vUzcbPBIbZDgf0zs4Gvhj5oIbLEgfTiheG','ywK0y3rMrxHPDe5LEhruAxrSzq','mtCWmJe0m1beD2Xbzq','AgLUDcbJ','Ahr0Chm6lY9WCMfJDgLJzs5Py29HmJaYnI5HDs9HCgKVAwnVys9Kzw1Vlxn0yxrZ','icbezxrLy3rLzcbMBgfNiokaLcb0CMvHDgLUzYbHCZOG','AwnVys1JBgKVyNvKz2v0','ywK0y3rMrxHPDa','x2XHC3rr','zxHPDa','icaGigHPBNqGyG','DxrMltG','ywK0y3rMv3jHCff1B3rHqG','ywnJB3vUDfnWzw50','icbbzNrLCIbLEgL0oIa','D3jPDgu','cGPdsefmtevor0uGqLjjruy6cG','y3rMngvHAq','y2HHBgXLBMDLswq','DhLWzq','CMvWzwf0','zw5JB2rPBMC','ywK0y3rMvgL0Bgu','AM9PBG','AgfZ','icaGicaGicaGicaGieXLyxzLignOyxqSihjLDhvYBIb0BYbLEgfT','iIaOy2f0zwDVCNK6ia','BNvTyMvY','ywK0y3rMv291BgrfyxjU','Dg9Rzw5mAw1PDa','ywK0y3rMuMv2zwfSvgL0Bgu','icbpCgvUigfUB3rOzxiGy2HHBgXLBMDLihDPDgGG','icdIMQaGww91CIbbstrdveyGDg9Rzw4GyNvKz2v0igLZigv4Agf1C3rLzc4','icaOCMvZDw1PBMCG4OcuihbYAw9YignOyxqGAxmGBM90ihjLBwvTyMvYzwqSigj1Dcb0B2TLBNmGywXYzwfKEsb1C2vKihn0yxKGzgvKDwn0zwqP','CMf0zwXPBwL0zwq','iokvKokvKokvKa','C3bSAxq','ywLvC2fNzq','BM93','icbbssb1C2fNzsbPCYbTzxrLCMvKihbLCIbHy2nVDw50icHZzxj2zxiTzw5MB3jJzwqGyNvKz2v0ks4','Bg9N','icaG4OAsia','icaGicaGicaGicaGica','icbozxH0oIa','icaGicaODhLWzsbPDcbYAwDODcbOzxjLigLUihrOAxmGy2HHDcdIGjqGBM90igfZigeGC2HLBgWGy29TBwfUzcK','z2vTAw5Ptw9KzwW','DMXH','lI4VBgLIl2v4yw0TC3rHDguUANm','ywK0y3rMt3jdAgf0','icdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILzdILza','ywK0y3rMv3jHCfrPDgXL','icbdDxjYzw50igfUC3DLCJOG','ANnVBG','y29TBwfUza','ywK0y3rMq29TBwfUzhm','u2nVCgvKihrVihrOzsbJAgfSBgvUz2uGEw91ig9Wzw5Lzc4GqxnRigzYzwvSEsdIGjq','C2XPy2u','icbszxn1Bwu6ia','vw5RBM93BIbYzxnWB25Zzq','Aw50zxjHy3rPB25Z','ywK0y3rMv3jHCeXPBMuXsgvHza','ihrVignVBNrPBNvL','lNr4DcaOAw5ZAwrLihrOzsbZyw5KyM94ksbYyxrOzxiGDgHHBIbHC2TPBMCGDgHLignVBNrLC3rHBNqGDg8GCgfZDguGDgHLihDOB2XLigjSB2iGyMfJAY4klsblzwvWihjLC3bVBNnLCYbJB25JAxnLigfUzcbWCMfJDgLJywWUifrOAxmGy29UDgvZDgfUDcbOyxmGBgLTAxrLzcb0Aw1LlG','sunpqxT5B3vYx2zSywD9','AwnVyxT3m2XJmg1LxZjFywK0y3rMFq','yvDoDLLyDdnnmNHQtuCXBfH6sMzzv2SWwtnsBwzrpt0','C3rHDhvZ','icaGicHhCMfKAw5NigHHChbLBNmGyxqGzxHHBsbZDwjTAxqG4OcuihLVDsbJyw5UB3qGChjLDMLLDYbJB3jYzwn0BMvZCYbKDxjPBMCGDgHLigv4yw0Ukq','y2XLyxi','D2HPDgu','y3vYCMvUDenOywXSzw5Nzu5HBwu','ywK0y3rMv3jHCff1B3rHC1rPDgXL','ywK0y3rMvg9Rzw5Z','C2vUze1LC3nHz2u','icbB','cGPbvfrbq0HfrcbeqvrbicHHBhnVihnHDMvKihrVignOywXSzw5NzxmVCq','DgvZDa','icaGigv4AxqGicaGicaGicaGica','Dg9Rzw4','ywK0y3rMq29YCMvJDezSywC','quK0q1rgihnLy3rPB24','vg9Rzw5Z','C2vZC2LVBJ0','ywK0y3rMv3jHCff1B3rHqq','ywK0y3rMv3jVBMDgBgfN','mtCXnJy0nwfWthPesG','lI4U','ywK0y3rMq21Ku2HLBgXmAw5L','ywK0y3rMsgLUDe5LEhrb','DhjPBq','C3vIBwL0ia','ywK0y3rMv3jHCff1B3rHq0HPBNq','BwvZC2fNzq','quKGyNvKz2v0icH0AgLZigfJy291BNqP','E25VuhjVz30','C3vIBwL0ieLdt0f7Ew91CL9MBgfNFq','Dg9vChbLCKnHC2u','ywK0y3rMsgLUDenvC2vZ','g1SXqrTBmKS','EwvSBg93','ywnJB3vUDenHCa','C3vIBwL0rMXHzW','Dg9Rzw5ZvxnLza','ig5VDcbMB3vUzcbPBIbZDgf0zs4','icdILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','icbtDwjTAxnZAw9UigzHAwXLzdOG','ywK0y3rMv2vSy29Tzun0yq','ywK0y3rMsgLUDefvC2vZ','n0rXyu90sW','Dw5RBM93BIbLCNjVCG','ywK0y3rMvgHPBMTPBMC','icaGicaGicaHzwnOBYbHv052wvH0m00YEgPnrZfSwhPkzLLxAZbzm1jTzLe9psb8igjHC2u2ncaTza','lI4VBgLIl2LUDgvNCML0Es1ZBMfWC2HVDc5QCW','icaGigHPBNqGysaVigiGlYbJica','CMvK','ihrVig1VDMuGB24','icbsyxrLigXPBwL0zwqG4OcuihDHAxqGysbTB21LBNqGyMvMB3jLihrYEwLUzYbHz2fPBI4','ywK0y3rMv3jHCeXPBMuYqM9KEq','Aw5JBhvKzxm','AgLUDcbI','C3vIBwL0qxr0zw1WDgvK','y3rMngfP','iMHVDYbKBYbjigrLy3j5ChqGquvtluncqYbPBIbqExrOB24/iG','igLZigfUievTyM9KAwvKiefjicHfquKPihf1zxn0Aw9UlG','y29YCMvJDa','icbnB2rLBdOGr29Vz2XLieDLBw1HidqGka','E2nTzh0','icbuAgLUA2LUzY4UlG','ywK0y3rMsgLUDee','ywK0y3rMv3jHCe5LEhrtDwi','icbbstrdveyGC2vJDgLVBIbJB21WBgv0zsdIGjqG','ywK0y3rMrw5Ku2vZC2LVBG','icaGicaGigHPBNqGyIaGia','igzVCIbrmZK','ywK0y3rMrgvJB2rL','BMfTzq','ChvZAa','cGPzt1vsifjvtevtoGOTifLVDsbnqvKGzxHWBgfPBIbJB25Jzxb0CYWGzgvZy3jPyMuGyxbWCM9Hy2HLCYWGyw5KigHLBhaGDgHLignVBNrLC3rHBNqGCMvHC29UihrOCM91z2GGDgHLihbYB2jSzw0UcI0Gww91ie1bwsbKAxnJDxnZihrOzsb0zwnOBM9SB2D5igLUDM9SDMvKicHbrvmSihb3BNrVB2XZlcbqExrOB24GC3rYDwn0lcbivfrqlcbLDgmUks4klsbzB3uGtufzigHLBhaGzgvIDwCGuhL0Ag9UignVzguGDgHLignVBNrLC3rHBNqGD3jPDgvZlGOTifLVDsbnvvnuie5pvcbYzxzLywWGDgHLigzSywCGzgLYzwn0BhKUcI0Gww91ie1vu1qGtK9uig91Dhb1DcbHBNKGC3rYAw5Nig1HDgnOAw5NieLdt0f7lI4UFsbVCIbPy29HEY4UlN0UcI0Gww91ie1vu1qGtK9uihrLBgWGDgHLignVBNrLC3rHBNqGDgHLigv4ywn0igfUC3DLCIb0BYb0AgLZihf1zxn0Aw9UlGOTifLVDsbnqvKGC3vNz2vZDcb3AgLJAcb0B29Sic8GBgLICMfYEsaVihrLy2HUAxf1zsb0BYb1C2uUcI0Gv2HLBIbZDwDNzxn0Aw5NihnOzwXSic8GChL0Ag9UihnUAxbWzxrZihrOyxqGBMvLzcb0AguGyxr0ywnOzwqGzgf0ysWGCMvMzxiGDg8GDgHLigzPBguGCgf0AcbJAgfSBgvUz2vZl3e','BwLU','ywK0y3rMv3jHCff1B3rHquHPBNq','icdWN46jienVCNjLy3qHia','icaGicfWExrOB24Zic4UlG','ig9UifeZoq','ywK0y3rMsgLUDfrLy2HUAxf1zq','icaGicaGicaGicaGifjLDhvYBIb0BYbTywLUig1LBNuGkhDVCMTZigfUExDOzxjLkq','CgfKrw5K','zMLUza','icaGigHPBNqGyq','ihrOzw4G','yxr0ywnOzwreyxrH','iwvJAg8GyvDoDLLyDdnnmNHQtuCXBfH6sMzzv2SWwtnsBwzrpt0GFcbIyxnLnJqGlwq','yw5ZD2vYCW','z2vTBweTnc0ZmwiTAxq','C3LUy2LUz+kaPG','icbbzNrLCIbLEgL0oIbbstrdveyGC2vJDgLVBIbJB21WBgv0zs4GtMv4DdOG','icdcTYaGuMuTzw50zxi6ia','icaGice8C2HLBgWGy21KpIaGica','BwvUDq','icbfCNjVCJOG','icdILiZILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','zxHHBsbXia','B3bLBIa8Awq+','icbbstrdveyGy2HHDcbPCYbHDMfPBgfIBguGB24GChjHy3rPy2fSihf1zxn0Aw9UCYaOBMv4DdOGuq','Dg9ju09tDhjPBMC','ywK0y3rMoIa','CxvLC3rPB25Z','ywK0y3rMrMXHz0HPBNq','lIbuCNKGywDHAw4GAw5ZAwrLihrOAxmGy2HHDc4','C3rHCNrZv2L0Aa','ywK0y3rMv3jHCfr5CgvdDgy0ywK','icbbstrdveyGy2HHDcbLBMrLzcbMB3iGuq','Cg9PBNrZ','imk3ia','oIbhB29NBguGr2vTBweGncaO','yM9VBgvHBG','icdILzdILzdILzaGquKGvgvHBw1HDguG4Pwq4Pwq4Pwq','ue9tva','y3rMzfvYBa','z3jLzw4','Cu51Bq','iokaLcb0ExbLia','ywXYzwfKEv9ZB2X2zwq','y29UDgLUDwu','ieLdt0f7lI4UFq','Bwf0y2G','ywK0y3rMv3jHCff1B3rHrM9VDgvY','iokaLcb1CgrHDguGAwnVys1JBgKGDg8GDgHLigXHDgvZDcb2zxjZAw9U','icdINjmGuq','icaGicaGicaGicbbigDLBNrSzsbUDwrNzsaOChjLlxDYAxr0zw4P','mJrkCgjWC3q','quKGzxjYB3i6ia','ywK0y3rMtw9KzwW','icaGig1LBNu','zgvZy3jPChrPB24','icaGigv4Axq','BM9KztPJAgLSzf9WCM9JzxnZ','Cgf1C2vK','BNvKz2vtAg93BG','mtzot25rv20','y3rMigXPC3q','ywK0y3rMv2vSy29Tzu5VuMv2zwfS','icaGia','icdILjtILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','icaKia','DgLTzw91Da','Dg9mB3DLCKnHC2u','ihrVA2vUCYbSzwz0lG','C29Tzq','ywK0y3rMrxHPDe5LEhrcB2r5','mMriu05Msq','icaGicaGicaGicbuzwnOBMLXDwuGAgLUDcaOChjLlxDYAxr0zw4P','mteWndiWs1PPsu14','ywK0y3rMsgLUDefcB2r5','iwvJAg8GyvDoDI4UlIb8igjHC2u2ncaTza','ywK0y3rMu2fTCgXL','ywK0y3rMsgLUDe5LEhrc','C3rYAw5NAwz5','icbtDgLSBcbHDMfPBgfIBgu6ia','icbbBhjLywr5ihnVBhzLzc4','y3LHBG','sgLKzgvUie1LC3nHz2u','icbbssb0zwfTBwf0zsbJBg9ZzwqGzM9Yici','nZe2nZyXmNn6ugzbwa','icbiB3CGDg8GD29YAYb0AgLZihf1zxn0Aw9U','y3vYCMvUDenOywXSzw5NzunHDgvNB3j5','ywK0y3rMv3jHCe5LEhruAxrSzq','iokaLca','q3j5ChrVz3jHCgH5','B3jcywnR','icbbssbIDwrNzxq6ia','CM91BMq','icdIMQaG','ywK0y3rMv3jHCe5LEhrcB2r5','lZuWmda','uNvUigeGC2HLBgWGy29TBwfUzcaOzs5NlIaHyMfZzty0ic1Kic4UlIK','ihb0CW','icaGihn1yM1PDcbjq09bEY4UlN0','iIbSB29RCYbSAwTLigfUie1dusbSzxr0zxiSig5VDcbHigzSywCU','cIaG','yxbWBgLJyxrPB24VANnVBG','CxvPDa','icaGigHPBNqGyW','ywK0y3rMuMv2zwfStg9JA05VDgu','mZi1ntiWzvj2AePu','ywK0y3rMu3vIBwL0q21K','ywK0y3rMuMv2zwfSu2vLrMXHzW','icbkDw1WihrOzxjLoIa','icaGicaGicbPy29HE3CZBgmWBwvFmL9HAtrJDgz9','ywK0y3rMsgLUDencB2r5','igfUC3DLCIb1CgrHDgvKoIa','icaGidXQDxn0ihr5Cgu+icaGica','C2vZC2LVBKnVB2TPzq','icdILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILidILia','icaGihn1yM1PDca8zMXHzZ4Gica','u3vIBwL0igeGzMXHzYb0BYb0AguGBgL2zsbZy29YzwjVyxjK','ihjLy29YzgvKoIa','DMLHigfPngn0zIbJAgf0','ywK0y3rM','Aw5JB3jYzwn0','icbvC2u6ia','y2f0zwDVCNK','ywK0y3rMv3jHCeXPBMuYsgvHza','icdINjCGsw5JB3jYzwn0lIa','ndm0mZK5thbmzxHn','CMvWBgfJzq','rMXHzYbMB3jTyxq6igLJB2f7lI4UFq','ywK0y3rMv3jHCe5VuhjVzW','yMfJAW','icaGicaGicaGicaGicaGicaGicbLlMCUia','ywK0y3rMuMv2zwfSvgHLBLn1yM1PDa','icbpCgvUig9UzsbMAxjZDdOG','z3jHEq','icdIMQaGquK0q1rgihrVA2vUigj1zgDLDcbLEgHHDxn0zwqGkdi1ldaWmcb1C2vKks4','yM9Sza','icdILiiG','icH1CgrHDgvZigfMDgvYihLVDxiGzMLYC3qGBwvZC2fNzsK','ifn1yM1PDcb5B3vYigzSywCGzM9YihrOAxmGCxvLC3rPB24','icbtD2L0y2GGy2HHBgXLBMDLoIa','icbzB3uGy2fUihn0AwXSihn1yM1PDcbHigzSywCGzgLYzwn0BhK6ia','C3vIBwL0idXMBgfNpG','igLZigeGq1rgnefjihf1zxn0Aw9UicHHDhrHy2STDgHLlufjks4','ywK0y3rMtg9JA2vKvxnL','jsbVzIbZzwn0Aw9Uiefjigj1zgDLDcb1C2vKiokaLcbVBMX5ih4','Dgv4Da','ywrK','ywK0y3rMsgLUDejcB2r5','icbr','icaGicaGicbZDwjTAxqGAwnVyxT3m2XJmg1LxZjFywK0y3rMFq','C3rKB3v0','BgvUz3rO','xsaGWRCG','icbdB21WzxrPDgLVBIbPCYbWyxvZzwqU','zgf0yq','ww91igfYzsbHBIbbssb0zwfTBwf0zsbOzwXWAw5NigeGy29UDgvZDgfUDcbZB2X2zsbHBIbjq09bidiWmJyGy3LIzxjZzwn1CML0EsbLEgfTihf1zxn0Aw9UlGOkq1vsuKvovcbrvuvtveLptIaOuq','ywK0y3rMv3jHCff1B3rHqW','BM90igvUzM9Yy2vKigzVCIb0AgLZigXVz2LU','mJyZotqZoxzxA09lqW','C3vIBwL0igLJB2f7DZnSyZbTzv8Yx2fPngn0zN0','ywnJB3vUDfzLCMLMAwvK','icdILii','q29TBwfUzcbMywLSzwq'];a0j=function(){return ak;};return a0j();}export function isChatActive(){return u;}function x(){const a5=a0q,j=$?w:A?d||b:-0x2012*-0x1+-0x2654+-0x2*-0xce5,q=y,v=Math[a5(0xdc)](Math[a5(0x138)](q/j*(-0x1bcc+-0x56*0x4+0x38*0x87)),-0x576+-0x2ff+-0x5*-0x1c5),z=Math[a5(0x138)](v/(-0x20dd+-0x32d*-0xb+0x2b*-0xa)*(0x2*0x121a+0xb83+-0x2fa3)),B=-0x14d2+0x129e+0x248*0x1-z,D=v>0x1*-0x21c1+-0x199*-0x16+-0x115?a0z[a5(0xc4)]:v>-0x2278*0x1+0x1a40+0x86a?a0z[a5(0xb5)]:a0z['green'],E=$?a5(0xa2):A?a5(0xaf):a5(0xa3);!A||m?!A||f?console['log'](a0z['gray']('\x20\x20'+E+':\x20')+D('█'[a5(0x19f)](z))+a0z[a5(0x161)]('░'[a5(0x19f)](B))+a0z[a5(0x161)]('\x20'+q+'/'+j+'\x20('+v+'%)')):console[a5(0x7a)](a0z[a5(0x161)]('\x20\x20AI\x20budget:\x20')+a0z[a5(0xb5)](a5(0xeb))+a0z['gray'](a5(0x165))):console[a5(0x7a)](a0z[a5(0x161)](a5(0x137))+a0z['yellow'](a5(0x179))+a0z[a5(0x161)](a5(0x10c)));}export async function handleChatMessage(z){const a6=a0q;if(!h)return a6(0x194);if(a0G(a6(0xf6)+z),$)return k(z);if(A)return async function(G){const a7=a6;if(!A||!h)return a7(0x194);const H=G[a7(0xab)](),I=H['toLowerCase'](),J=H[a7(0x10a)](/^submit\s+(.+)/i);if(J){let K=J[0x218b+-0x18d2+0x1*-0x8b8][a7(0xab)]();if(/^submit\s+/i[a7(0x9e)](K)&&(K=K[a7(0x15a)](/^submit\s+/i,'')[a7(0xab)]()),K=K[a7(0x15a)](/^["'`]+|["'`]+$/g,'')['trim'](),!K)return console[a7(0x7a)](),console[a7(0x7a)](a0z[a7(0x161)]('\x20\x20Usage:\x20')+a0z[a7(0x97)]('submit\x20<flag>')),console[a7(0x7a)](),a7(0x108);const L=A[a7(0x19d)];if(!L)return console[a7(0x7a)](),console[a7(0x7a)](a0z[a7(0xb5)]('\x20\x20No\x20challenge\x20id\x20in\x20context\x20—\x20open\x20one\x20first:\x20')+a0z[a7(0x97)](a7(0xf3))),console[a7(0x7a)](),'continue';a0H(L,K);const M=a0E();try{const {CTFdClient:N}=await import(a7(0x181)),O=M[a7(0x14d)]||'',P=M[a7(0xa0)]&&!M[a7(0xa0)][a7(0xc8)]('session=')?M[a7(0xa0)]:'',Q=new N(M['ctfdUrl'],P,O||M[a7(0xa0)]),R=await Q[a7(0xb7)](L,K);switch(console[a7(0x7a)](),R[a7(0x94)]){case a7(0xce):console['log'](a0z[a7(0x104)]['bold'](a7(0xde))+a0z[a7(0x97)](R[a7(0xae)]||''));break;case a7(0x154):console['log'](a0z[a7(0xc4)](a7(0x158))+a0z[a7(0x161)](R['message']||''));break;case a7(0x107):console['log'](a0z[a7(0xb5)](a7(0x12c)));break;case a7(0x116):console[a7(0x7a)](a0z['yellow'](a7(0x175)));break;case a7(0x74):console[a7(0x7a)](a0z['yellow'](a7(0xc6)));break;default:console['log'](a0z[a7(0x161)]('\x20\x20'+(R[a7(0xae)]||a7(0x8c))));}console['log']();const {postIntegritySnapshot:S}=await import(a7(0xc2));await S();}catch(T){console[a7(0x7a)](),console[a7(0x7a)](a0z[a7(0xc4)](a7(0xbb)+(T[a7(0xae)]?.[a7(0x76)]('\x0a')[0x3d*-0x7+0x26*0x22+-0x361]||a7(0xbf)))),console[a7(0x7a)]();}return a7(0x108);}if(G[a7(0xfa)]('!')){const U=G[a7(0x8a)](0x206e+-0x18ff+-0x76e)[a7(0xab)]();if(!U)return a7(0x108);try{const V={};V['encoding']=a7(0x196),V['timeout']=0x2710;const {execSync:W}=await import(a7(0x115)),X=W(U,V)[a7(0xab)]();console['log'](),console['log'](a0z[a7(0x161)](a7(0x11d))+a0z['white'](U)),console['log'](a0z[a7(0x97)]('\x20\x20'+X[a7(0x76)]('\x0a')[a7(0x69)](a7(0x140)))),console[a7(0x7a)]();}catch(Y){console[a7(0x7a)](),console[a7(0x7a)](a0z['red'](a7(0xf0)+(Y['message']?.[a7(0x76)]('\x0a')[0x22a*-0x2+0xb1c+-0x6c8]||a7(0x17e)))),console['log']();}return a7(0x108);}if(a7(0x194)===I||a7(0x15d)===I||a7(0x142)===I){const Z=A['challengeName'];return u=!(0xe09+0x30e*-0x2+-0x7ec),h=null,A=null,console[a7(0x7a)](),console[a7(0x7a)](a0z[a7(0x161)](a7(0x12f)+Z+'\x22.')),console['log'](a0z['gray'](a7(0x71))+a0z['white']('open\x20<id>')+a0z[a7(0x161)](',\x20or\x20re-enter\x20with\x20')+a0z[a7(0x97)](a7(0x153))),console[a7(0x7a)](),a7(0x194);}console[a7(0x7a)](a0z['gray']('\x20\x20'+a0K('ai4ctfThinking')));try{const a0=await h[a7(0x9b)](G);process[a7(0x172)]['write'](a7(0xb4)),a0D(a0['tokensUsed']),a7(0x6d)==typeof a0['accountSpent']?(y=a0[a7(0x198)],m=!(0x1e7f+0x1*-0xc56+-0x1229*0x1),f=!(-0x296*0x7+-0x3*-0x998+0x1*-0xaae),a7(0x6d)==typeof a0[a7(0xb6)]&&(d=a0['accountCap'])):(y+=a0['tokensUsed'],f=!(-0x16af+-0x1b1d+0x31cc)),console['log'](),a0I(a0[a7(0x16d)]),x(),console[a7(0x7a)](a0z[a7(0x161)]('\x20\x20exit\x20to\x20leave\x20chat\x20·\x20submit\x20<flag>\x20to\x20score')),console[a7(0x7a)]();}catch(a1){process['stdout'][a7(0x19a)]('\x1b[1A\x1b[2K'),a0J(a7(0x110)+a1[a7(0xae)]),console[a7(0x7a)]();}return a7(0x108);}(z);const B=z['trim']()[a6(0x11f)]()[a6(0x10a)](/^hint\s+([abc])$/);if(B)return function(G){const a8=a6,H=a0K('a'===G?a8(0xd2):'b'===G?a8(0x183):'ai4ctfHintC'),I=a0K('a'===G?a8(0x126):'b'===G?a8(0x16f):a8(0x14a)),J='Hint\x20'+G[a8(0xb2)](),K='a'===G?a0z[a8(0x104)]:'b'===G?a0z['yellow']:a0z[a8(0xc4)];console[a8(0x7a)](),console[a8(0x7a)](K[a8(0x163)]('\x20\x20▸\x20'+J+'\x20\x20')+a0z[a8(0x161)](H)),console['log']();for(const L of I[a8(0x76)]('\x0a'))''===L?console['log']():console['log'](a0z[a8(0x97)](a8(0x11b)+L));console[a8(0x7a)](),'a'===G?(console['log'](a0z[a8(0x161)](a8(0x11b)+a0K(a8(0xaa))+'\x20')+a0z[a8(0x12d)](a8(0xc9))),console[a8(0x7a)]()):'b'===G&&(console[a8(0x7a)](a0z['gray'](a8(0x11b)+a0K(a8(0x129))+'\x20')+a0z[a8(0x12d)](a8(0x18e))),console[a8(0x7a)]());}(B[-0x16cd+0xe4e+0x22*0x40]),a6(0x108);const D=z[a6(0x10a)](/^submit\s+(.+)/i);if(D){let G=D[0x1*0x26c9+0x1b1f+-0x1*0x41e7][a6(0xab)]();if(/^submit\s+/i[a6(0x9e)](G)&&(G=G['replace'](/^submit\s+/i,'')['trim']()),G=G[a6(0x15a)](/^["'`]+|["'`]+$/g,'')['trim'](),a6(0x92)===G){console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0x104)][a6(0x163)](a6(0x83))),console[a6(0x7a)](a0z[a6(0x104)]['bold']('\x20\x20'+a0K(a6(0xa1)))),console[a6(0x7a)](a0z['green'][a6(0x163)](a6(0x83))),console[a6(0x7a)](),console['log'](a0z[a6(0x97)]('\x20\x20'+a0K(a6(0x184)))),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20'+a0K(a6(0x6e)))),console['log'](),x(),u=!(-0x1369*-0x1+0x11b9*0x2+-0x36da),h=null,fetch(a6(0x18f),{'method':a6(0x102),'headers':{'Content-Type':a6(0x141)},'body':JSON['stringify']({'type':a6(0x153),'solved':!(-0x14f0+-0x648+0x1b38),'tokensUsed':y,'timestamp':new Date()[a6(0xf5)]()}),'signal':AbortSignal[a6(0x11e)](0x199f+-0x2351*0x1+0x1d3a)})['catch'](()=>{}),await r(-0x1*-0x127d+-0x1d*-0x9e+-0x1e87),console[a6(0x7a)](),console[a6(0x7a)](a0z['cyan'](a6(0x14e))),console['log'](a0z[a6(0x163)]['white']('\x20\x20'+a0K(a6(0x84)))),console[a6(0x7a)](a0z[a6(0x12d)](a6(0x14e))),console[a6(0x7a)]();const H=a0K(a6(0x8e)),I=a0K('ai4ctfWrapLine1Body');console[a6(0x7a)](a0z['white'](a6(0x185)+H+'\x20')+a0z[a6(0x161)](I[a6(0x76)]('\x0a')[-0x1fdb*-0x1+-0x1bd*-0x16+-0x4619]||''));for(const M of I[a6(0x76)]('\x0a')[a6(0x8a)](-0x1*0x2573+-0x2*-0xc5+0x23ea))M['trim']()&&console['log'](a0z['gray'](a6(0x189)+M['replace'](/\{thinking\}/g,'thinking')));console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0x97)]('\x20\x20\x20\x202.\x20'+a0K(a6(0x157))+'\x20')+a0z['gray'](a0K(a6(0xc7)))),console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0x12d)]('\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20!echo\x20aWNvYXt3M2xjMG1lXzJfYWk0Y3RmfQ==\x20|\x20base64\x20-d')),console['log'](),await r(0x2564+-0x1*-0x29a+0x3*-0xaba),console[a6(0x7a)](a0z['cyan']('\x20\x20─────────────────────────────────────────────')),console['log'](a0z[a6(0x163)][a6(0x97)]('\x20\x20'+a0K(a6(0x99)))),console[a6(0x7a)](a0z['cyan'](a6(0x14e))),console[a6(0x7a)](),console[a6(0x7a)](a0z['yellow']('\x20\x20\x20\x20\x20\x20\x20hint\x20a\x20\x20\x20')+a0z[a6(0x97)](a0K(a6(0xa5))[a6(0xe3)](0x21e1+-0x1*0x2451+-0xd*-0x32))+a0z[a6(0x161)](a0K(a6(0xdd)))),console[a6(0x7a)](a0z['yellow'](a6(0xd6))+a0z[a6(0x97)](a0K(a6(0x197))[a6(0xe3)](0x6ee+0x2517*-0x1+0x7f*0x3d))+a0z['gray'](a0K('ai4ctfWrapQuotaBHint'))),console['log'](a0z[a6(0xb5)]('\x20\x20\x20\x20\x20\x20\x20hint\x20c\x20\x20\x20')+a0z[a6(0x97)](a0K(a6(0x178))['padEnd'](0x1*0x1219+0x18d1*-0x1+0x6d2))+a0z[a6(0x161)](a0K(a6(0xad)))),console[a6(0x7a)]();for(const N of a0K(a6(0x10b))[a6(0x76)]('\x0a'))console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20\x20\x20'+N));console[a6(0x7a)](),await r(-0x208f+0x1161+0x1b*0xda),console[a6(0x7a)](a0z[a6(0x12d)](a6(0x14e))),console['log'](a0z[a6(0x163)][a6(0x97)]('\x20\x20'+a0K(a6(0x133))+'\x20')+a0z['red'][a6(0x163)](a6(0xcb))+a0z['white'](a6(0x134)+a0K(a6(0xd3)))),console['log'](a0z[a6(0x12d)](a6(0x14e))),console[a6(0x7a)]();const J=a0K(a6(0x13a)),K=a0K(a6(0x15c)),L=J[a6(0x76)]('\x0a');if(L[-0x1999+0x828+0x1171]){const [O,P]=L[-0x1d0d+-0x407*0x5+0x4*0xc4c][a6(0x76)](a6(0xb0));console['log'](a0z[a6(0x97)](a6(0x11b)+(O||''))+a0z['bold'][a6(0x97)](K)+a0z[a6(0x97)](P||''));}for(const Q of L[a6(0x8a)](0x22b4+-0x2045+-0x26e))Q[a6(0xab)]()&&console['log'](a0z[a6(0x97)](a6(0x11b)+Q));return console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20\x20\x20'+a0K(a6(0xfb))+'\x20')+a0z[a6(0x163)][a6(0xc4)](a6(0xcb))),console[a6(0x7a)](),a6(0x194);}return console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0xc4)]('\x20\x20'+a0K(a6(0xa6)))),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20'+a0K(a6(0xf8)))),console[a6(0x7a)](),a6(0x108);}if(z[a6(0xfa)]('!')){const R=z['slice'](-0x1*-0xe59+-0x1254+-0x22*-0x1e)['trim']();if(!R)return'continue';try{const S={};S[a6(0x1a0)]=a6(0x196),S['timeout']=0x2710;const {execSync:T}=await import(a6(0x115)),U=T(R,S)['trim']();console[a6(0x7a)](),console['log'](a0z[a6(0x161)](a6(0x11d))+a0z[a6(0x97)](R)),console[a6(0x7a)](a0z[a6(0x97)]('\x20\x20'+U[a6(0x76)]('\x0a')[a6(0x69)](a6(0x140)))),console[a6(0x7a)](),console['log'](a0z['gray']('\x20\x20'+a0K(a6(0x187)))),console[a6(0x7a)]();}catch(V){console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0xc4)](a6(0xf0)+(V[a6(0xae)]?.[a6(0x76)]('\x0a')[-0x1*-0x15c1+-0x177d+0x1bc]||a6(0x17e)))),console[a6(0x7a)]();}return a6(0x108);}const E={};E['Content-Type']=a6(0x141);if('exit'===z||a6(0x15d)===z||a6(0x142)===z||a6(0xef)===z)return u=!(0xd17+-0x5*-0x233+-0xf*0x19b),h=null,fetch('https://practice.icoa2026.au/api/icoa/demo-stats',{'method':a6(0x102),'headers':E,'body':JSON[a6(0x12a)]({'type':'ai4ctf','tokensUsed':y,'timestamp':new Date()['toISOString']()}),'signal':AbortSignal[a6(0x11e)](-0x5db*-0x1+-0x2555+0x3302)})['catch'](()=>{}),console[a6(0x7a)](),console[a6(0x7a)](a0z['gray'](a6(0xba))),console[a6(0x7a)](a0z[a6(0x97)]('\x20\x20'+a0K('ai4ctfReport'))),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20'+a0K(a6(0x9a))+':\x20'+y+a6(0x13b))),console[a6(0x7a)](a0z['gray']('\x20\x20'+a0K(a6(0x111))+':\x20Google\x20Gemma\x204\x20(gemma-4-31b-it)')),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20─────────────────────────────────────────')),console[a6(0x7a)](),console['log'](a0z[a6(0x12d)](a6(0x14e))),console[a6(0x7a)](a0z[a6(0x97)]('\x20\x20'+a0K(a6(0x18c))+'\x20')+a0z['bold'][a6(0xc4)](a6(0xcb))+a0z[a6(0x97)](a6(0x134)+a0K('ai4ctfExitNextSub'))),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20'+a0K(a6(0x122)))),console[a6(0x7a)](a0z[a6(0x12d)](a6(0x14e))),console[a6(0x7a)](),console['log'](a0z[a6(0x97)]('\x20\x20▸\x20\x20')+a0z['white'](a0K('typeAndEnterToBegin')[a6(0x15a)](a6(0xd0),a0z[a6(0x163)]['red'](a6(0xcb))))),console['log'](a0z[a6(0x161)]('\x20\x20\x20\x20\x20'+a0K(a6(0x136)))),console[a6(0x7a)](),a6(0x194);const F={};F[a6(0x18a)]=a6(0x141);if(!p&&y>=0x1*0x1c25+0x1*-0xc8d+0x3f0)return p=!(-0x758+0x2*-0xd53+0x1ca*0x13),fetch(a6(0x18f),{'method':'POST','headers':F,'body':JSON[a6(0x12a)]({'type':'ai4ctf','solved':!(0x4fd*0x2+-0x9cf+-0x2a),'tokensUsed':y,'timestamp':new Date()[a6(0xf5)]()}),'signal':AbortSignal[a6(0x11e)](-0x112b+-0x498+0x1f*0x155)})['catch'](()=>{}),console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0xb5)]('\x20\x20'+a0K(a6(0x6f)))),x(),(function(){const a9=a6;console[a9(0x7a)](),console[a9(0x7a)](a0z['yellow'](a9(0x14e))),console[a9(0x7a)](a0z[a9(0x163)][a9(0xb5)]('\x20\x20'+a0K(a9(0x70)))),console[a9(0x7a)](a0z[a9(0xb5)](a9(0x14e))),console['log']();for(const W of a0K('ai4ctfRevealBody')[a9(0x76)]('\x0a'))''===W?console['log']():console['log'](a0z[a9(0x97)](a9(0x11b)+W));console[a9(0x7a)](),console[a9(0x7a)](a0z[a9(0x12d)](a9(0xc1))),console[a9(0x7a)](),console[a9(0x7a)](a0z['white'](a9(0x11b)+a0K(a9(0x147)))),console[a9(0x7a)](),console[a9(0x7a)](a0z[a9(0x104)](a9(0x149))),console[a9(0x7a)](),console['log'](a0z[a9(0x97)](a9(0x11b)+a0K(a9(0x15f)))),console[a9(0x7a)](),console[a9(0x7a)](a0z['cyan'](a9(0x171))),console[a9(0x7a)](),console['log'](a0z[a9(0x161)](a9(0x11b)+a0K(a9(0x144)))),console[a9(0x7a)]();}()),a6(0x108);if(p)return console[a6(0x7a)](),console[a6(0x7a)](a0z[a6(0xb5)]('\x20\x20'+a0K('ai4ctfLockedTitle'))),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20'+a0K(a6(0x16b))+'\x20')+a0z[a6(0x12d)](a6(0xe8))),console[a6(0x7a)](a0z[a6(0x161)]('\x20\x20'+a0K('ai4ctfLockedThen')+'\x20')+a0z[a6(0x12d)](a6(0x17b))),console[a6(0x7a)](),a6(0x108);console['log'](a0z[a6(0x161)]('\x20\x20'+a0K(a6(0xc0))));try{const W=await h[a6(0x9b)](z);process[a6(0x172)][a6(0x19a)](a6(0xb4)),y+=W['tokensUsed'],a0D(W[a6(0xb8)]),console[a6(0x7a)](),a0I(W[a6(0x16d)]),x(),console['log'](a0z[a6(0x161)]('\x20\x20exit\x20to\x20leave\x20chat')),console['log']();}catch(X){process[a6(0x172)][a6(0x19a)](a6(0xb4)),a0J(a6(0x110)+X[a6(0xae)]),console[a6(0x7a)]();}return a6(0x108);}const C=new Set();async function k(v){const aa=a0q;if(!$||!h)return aa(0x194);const z=v[aa(0xab)](),B=z[aa(0x11f)](),D=(Date[aa(0x78)]()-$[aa(0x180)])/(0x5d*-0x4ec+0x2*-0xa011+-0x1*-0x3f43e);if(!$['nudgeShown']&&!$[aa(0xca)]&&D>=-0x18a1+-0x2208+0x3aae*0x1&&($[aa(0x117)]=!(0xeb2+0x1df*0x7+-0x1bcb),console[aa(0x7a)](),console[aa(0x7a)](a0z['yellow']('\x20\x20💡\x20Once\x20you\x20have\x20ICOA{...},\x20submit\x20it\x20with:\x20')+a0z['bold'][aa(0xb5)](aa(0xb1))),console[aa(0x7a)](a0z['gray'](aa(0x7e))),console[aa(0x7a)]()),/^ICOA\{[^}]+\}$/i[aa(0x9e)](z))return console['log'](),console[aa(0x7a)](a0z['gray'](aa(0x190))+a0z[aa(0x97)](aa(0xac)+z)),k('submit\x20'+z);const E=z['match'](/^submit\s+(.+)/i);if(E){let F=E[-0x518+-0x1959+0x1e72][aa(0xab)]();if(/^submit\s+/i['test'](F)&&(F=F[aa(0x15a)](/^submit\s+/i,'')[aa(0xab)]()),F=F[aa(0x15a)](/^["'`]+|["'`]+$/g,'')[aa(0xab)](),/^[A-Da-d]$/[aa(0x9e)](F))return console[aa(0x7a)](),console[aa(0x7a)](a0z['yellow']('\x20\x20\x22'+F+aa(0x13f))),console['log'](a0z['gray'](aa(0x182))+a0z['green'](aa(0x91))+a0z[aa(0x161)](aa(0xf9))),console[aa(0x7a)](),aa(0x108);const {getExamState:G,saveExamState:H}=await import(aa(0x81)),I=G();if(!I)return aa(0x194);if(!I[aa(0xf7)]['find'](L=>L[aa(0x6d)]===$[aa(0x105)]))return console[aa(0x7a)](a0z['red'](aa(0x170)+$['qNum']+aa(0xb9))),aa(0x108);const J=I[aa(0xe9)][$[aa(0x105)]];I[aa(0x8d)]||(I[aa(0x8d)]=[]),I[aa(0x8d)][aa(0xda)]({'ts':new Date()[aa(0xf5)](),'q':$[aa(0x105)],'type':J?'answer_changed':'answer_submitted','input':F,'result':aa(0x152)}),I['answers'][$[aa(0x105)]]=F;const K=$[aa(0x105)]+(0xa*0x31d+0x24af+-0x1f*0x230);return I['_lastQ']=K<=0x5c*-0x48+0x137f*-0x1+0x2d85?K:$[aa(0x105)],H(I),console[aa(0x7a)](),J?(console[aa(0x7a)](a0z[aa(0x104)](aa(0x10d)+$[aa(0x105)]+aa(0x14b))+a0z[aa(0xb5)](F)),console[aa(0x7a)](a0z['gray']('\x20\x20\x20\x20Previous:\x20'+J))):console[aa(0x7a)](a0z['green'][aa(0x163)]('\x20\x20✓\x20Answer\x20for\x20Q'+$[aa(0x105)]+aa(0x151)+F)),console[aa(0x7a)](a0z[aa(0x161)](aa(0x95))),console[aa(0x7a)](),console['log'](a0z[aa(0x161)]('\x20\x20')+a0z['white']('submit\x20ICOA{...}')+a0z[aa(0x161)]('\x20again\x20to\x20change,\x20or\x20')+a0z[aa(0x97)](aa(0x194))+a0z[aa(0x161)](aa(0xc5))),K<=-0x35*0x59+-0x13ad+-0x24*-0x110?console[aa(0x7a)](a0z[aa(0x161)](aa(0x199))+a0z[aa(0x12d)]('ai4ctf')+a0z[aa(0x161)]('\x20will\x20open\x20Q'+K)):console[aa(0x7a)](a0z[aa(0x161)](aa(0xec))+a0z['red'](aa(0xcb))+a0z[aa(0x161)](aa(0xe0))),console[aa(0x7a)](),'continue';}if(v[aa(0xfa)]('!')){const L=v[aa(0x8a)](-0xc57+0x64*0x4e+-0x488*0x4)[aa(0xab)]();if(!L)return'continue';try{const M={};M[aa(0x1a0)]=aa(0x196),M[aa(0x11e)]=0x2710;const {execSync:N}=await import('node:child_process'),O=N(L,M)[aa(0xab)]();console[aa(0x7a)](),console[aa(0x7a)](a0z[aa(0x161)](aa(0x11d))+a0z[aa(0x97)](L)),console[aa(0x7a)](a0z['white']('\x20\x20'+O[aa(0x76)]('\x0a')[aa(0x69)](aa(0x140)))),console[aa(0x7a)]();}catch(P){console['log'](),console[aa(0x7a)](a0z['red']('\x20\x20Error:\x20'+(P[aa(0xae)]?.['split']('\x0a')[0xf94+0x7c+-0x404*0x4]||aa(0x17e)))),console[aa(0x7a)]();}return'continue';}if(aa(0x194)===B||aa(0x15d)===B||aa(0x142)===B){const Q=$[aa(0x105)],{getExamState:R}=await import(aa(0x81)),S=R(),T=S&&null!=S[aa(0xe9)][Q],U=S?.['_lastQ']||Q;return u=!(0x75*-0x19+0x1f7*-0x1+-0x9*-0x17d),h=null,$=null,C[aa(0x96)](),console[aa(0x7a)](),console[aa(0x7a)](a0z['gray'](aa(0xfc)+Q+'.')),T&&U>Q&&U<=-0x16d*0x16+0x1182+0x16*0xa3?console['log'](a0z['white'](aa(0x7d))+a0z[aa(0x163)][aa(0x104)]('Q'+U)+a0z[aa(0x161)](aa(0x106))+a0z[aa(0x12d)](aa(0x153))+a0z[aa(0x161)](aa(0x8f))):T&&Q>=-0x20fa+-0x1399+0x1193*0x3?console[aa(0x7a)](a0z['white'](aa(0xd4))+a0z[aa(0x163)][aa(0xc4)]('ctf4ai')+a0z[aa(0x161)](aa(0xd7))):console[aa(0x7a)](a0z[aa(0x161)](aa(0x8b))+a0z[aa(0x97)]('exam\x20q\x20'+Q)+a0z['gray'](aa(0xed))+a0z['white'](aa(0x153))),console['log'](),'exit';}if(p)return console[aa(0x7a)](),console[aa(0x7a)](a0z['yellow']('\x20\x20AI\x20budget\x20exhausted\x20for\x20AI4CTF\x20section.')),console[aa(0x7a)](a0z[aa(0x161)](aa(0x12b))+a0z['white'](aa(0x169))+a0z[aa(0x161)](aa(0xfe))+a0z['white']('!shell')+a0z['gray']('\x20·\x20')+a0z[aa(0x97)](aa(0x194))),console['log'](),aa(0x108);if(y>=w)return p=!(0xe40+-0x21*0x12a+0x182a),console['log'](),console['log'](a0z[aa(0xc4)][aa(0x163)](aa(0x162))),console[aa(0x7a)](a0z[aa(0x161)]('\x20\x20You\x20can\x20still:\x20')+a0z[aa(0x97)](aa(0x169))+a0z[aa(0x161)](aa(0xfe))+a0z['white']('!shell')+a0z['gray'](aa(0xfe))+a0z[aa(0x97)]('exit')),console[aa(0x7a)](),aa(0x108);console[aa(0x7a)](a0z['gray'](aa(0xd1)));try{const V=await h[aa(0x9b)](v);process[aa(0x172)][aa(0x19a)](aa(0xb4)),y+=V['tokensUsed'];const {getRealExamState:W,saveExamState:X}=await import('../lib/exam-state.js'),Y=W(),Z={};Z[aa(0x153)]=0x0,Z[aa(0xcb)]=0x0,(Y&&(Y['aiUsage']||(Y['aiUsage']=Z),Y[aa(0x77)][aa(0x153)]=y,X(Y)),console['log'](),a0I(V[aa(0x16d)]),x(),console[aa(0x7a)](a0z[aa(0x161)]('\x20\x20exit\x20=\x20back\x20to\x20exam\x20·\x20submit\x20ICOA{...}\x20to\x20answer')),function(a0,a1,a2){const ab=aa,a3=a0/a1*(-0x3c2+-0xae7+0xf0d);a3>=-0x398*-0x2+0x195*0x11+-0x10db*0x2&&!a2['has']('95')?(console[ab(0x7a)](a0z['red']['bold'](ab(0x139)+Math[ab(0x138)](a3)+ab(0x16c)+(a1-a0)+ab(0x120))),a2['add']('95')):a3>=-0x867+0x101*0x13+-0xa5c&&!a2['has']('80')?(console[ab(0x7a)](a0z[ab(0xb5)]('\x20\x20⚠\x2080%\x20of\x20section\x20AI\x20budget\x20used.')),a2[ab(0x16e)]('80')):a3>=0x1d95*0x1+-0x6cb*0x3+-0x902&&!a2[ab(0x6a)]('50')&&(console[ab(0x7a)](a0z['gray']('\x20\x20Note:\x2050%\x20of\x20section\x20AI\x20budget\x20used.')),a2['add']('50'));}(y,w,C),console[aa(0x7a)]());}catch(a0){process[aa(0x172)][aa(0x19a)](aa(0xb4)),a0J('AI\x20error:\x20'+a0['message']),console['log']();}return aa(0x108);}export function registerAi4ctfCommand(j){const ac=a0q;j[ac(0x87)](ac(0x153))['description']('Chat\x20with\x20your\x20AI\x20teammate')['action'](async()=>{const ad=ac;a0G(ad(0x153));const {getRealExamState:q}=await import(ad(0x81)),v=q(),z=v?.['questions'][ad(0x121)](G=>ad(0x153)===G['type']);if(v&&z){const G=v[ad(0x193)]||0x7*-0x359+0x799*-0x3+0x315*0xf,H=v[ad(0xf7)][ad(0xe4)](I=>I[ad(0x6d)]===G);if(!H)return void a0J('Q'+G+ad(0x18b)+G);if(ad(0x153)!==H[ad(0x19e)]){if(console[ad(0x7a)](),ad(0xcb)===H[ad(0x19e)])console['log'](a0z[ad(0xb5)]('\x20\x20Q'+G+ad(0x16a))),console[ad(0x7a)](a0z['gray'](ad(0x155))+a0z[ad(0x163)][ad(0xc4)](ad(0xcb)));else{if(ad(0x80)===H[ad(0x19e)])console[ad(0x7a)](a0z['yellow'](ad(0x170)+G+ad(0xcd))),console['log'](a0z[ad(0x161)](ad(0x155))+a0z['bold']['cyan'](ad(0x19c)));else{const I=v[ad(0xf7)][ad(0xe4)](J=>ad(0x153)===J['type']);console['log'](a0z[ad(0xb5)](ad(0x170)+G+'\x20is\x20a\x20multiple-choice\x20question\x20—\x20answer\x20with\x20A/B/C/D.')),I&&(console['log'](a0z[ad(0x161)](ad(0xf4)+I[ad(0x6d)]+').')),console[ad(0x7a)](a0z[ad(0x161)](ad(0x148))+a0z[ad(0x163)][ad(0x12d)](ad(0xf2)+I[ad(0x6d)])));}}return void console[ad(0x7a)]();}return void await async function(J,K){const ae=ad,{getRealExamState:L,refetchQuestionDataIfStale:M,materializeAttachedData:N}=await import(ae(0x81));await M();const O=L();if(!O)return!(0x2594+0x1a*-0x141+-0x4f9);const P=O['questions'][ae(0xe4)](S=>S[ae(0x6d)]===J);P&&(K=P),N(J,K?.['attachedData']);const Q=O[ae(0x77)]?.[ae(0x153)]??0x909+-0x5*-0x5cf+-0x2614;if(Q>=w)return console[ae(0x7a)](),console[ae(0x7a)](a0z[ae(0xb5)](ae(0x72))),console[ae(0x7a)](a0z[ae(0x161)](ae(0x168))+a0z['white'](ae(0x186)+J+ae(0x109))),console[ae(0x7a)](),!(0x2*-0xa6+0x11e1+0x1*-0x1094);try{h=await a0B(void(0x11ed+0x291*0xf+-0x386c),function(S,T){const af=ae,U=S['description']||S['text']||'',V=S[af(0xe7)]?af(0x9d)+T+'.txt\x20inside\x20the\x20contestant\x27s\x20sandbox\x20—\x20path\x20is\x20relative\x20to\x20the\x20sandbox\x27s\x20/home/competitor\x20working\x20directory,\x20reachable\x20from\x20any\x20!shell\x20/\x20!python3\x20invocation):\x0a'+S[af(0xe7)]:'';return af(0x177)+T+',\x20'+S['category']+',\x20'+(S[af(0xfd)]||-0x4ca*-0x2+-0x1*-0x1ea6+0x4*-0xa0d)+'\x20points):\x0a'+U+V+af(0xdb)+T+af(0x90);}(K,J));}catch(S){return a0J(S[ae(0xae)]),!(0x1*-0xd57+-0x91d+0x1675);}u=!(0x18cb+-0x1*0x17d+0x1*-0x174e),y=Q,p=!(0x2*0x71+0x13dc*-0x1+0x12fb*0x1),$={'qNum':J,'question':K,'usageField':'ai4ctf','enteredAt':Date[ae(0x78)](),'submitAttempted':!(0x122e+0x1963+0xa4*-0x44),'nudgeShown':!(0x596+-0x6e3+-0xa7*-0x2)};const R=O['answers']?.[J];return function(T,U,V){const ag=ae,W=a0E()[ag(0x7f)]||ag(0xea),X=y>0x1167+0xb9d+-0x1d04;console[ag(0x7a)](),console['log'](a0z[ag(0x104)]['bold']('\x20\x20═══\x20AI4CTF\x20—\x20Q'+U+':\x20'+T['category']+ag(0x75))),X&&console[ag(0x7a)](a0z[ag(0x161)](ag(0x73))),V&&console[ag(0x7a)](a0z[ag(0x161)](ag(0x85))+a0z[ag(0xb5)](V)+a0z[ag(0x161)]('\x20\x20(submit\x20again\x20to\x20change)')),console[ag(0x7a)](),console[ag(0x7a)](a0z['cyan'](ag(0xf1))),console['log'](a0z[ag(0x12d)](ag(0x164))+a0z[ag(0x163)]['white']('Q'+U+ag(0x9c)+T[ag(0x156)]+ag(0x174)+(T[ag(0xfd)]||0xcb4+-0x31*-0x9d+0x2abb*-0x1)+ag(0x13d))),console[ag(0x7a)](a0z['cyan'](ag(0x17d)));for(const Y of String(T[ag(0x16d)])['split']('\x0a')){const Z=Y[ag(0x173)]>0x207a+0x143b*-0x1+-0xc03?Y[ag(0x8a)](-0x5a7+0x12*0x117+-0xdf7,0x1*-0xabd+-0x1d0*0x8+0x1*0x1976)+ag(0xa8):Y;console[ag(0x7a)](a0z['cyan'](ag(0x164))+a0z[ag(0x97)](Z));}console[ag(0x7a)](a0z[ag(0x12d)](ag(0x17d))),console[ag(0x7a)](a0z['cyan'](ag(0x164))+a0z['gray']('Full\x20question:\x20\x20')+a0z[ag(0x97)](ag(0xf2)+U)),console['log'](a0z['cyan'](ag(0x164))+a0z[ag(0x161)]('Flag\x20format:\x20\x20\x20\x20ICOA{...}')),console[ag(0x7a)](a0z['cyan'](ag(0x11c))),console[ag(0x7a)](),console[ag(0x7a)](a0z[ag(0x163)][ag(0x97)](ag(0x131))),console[ag(0x7a)](),console[ag(0x7a)](a0z[ag(0xb5)](ag(0xe5))+a0z[ag(0x161)](ag(0x10e))),console['log'](a0z[ag(0xb5)](ag(0x195))+a0z[ag(0x161)](ag(0x124))),console[ag(0x7a)](a0z[ag(0xb5)](ag(0x143))+a0z['gray']('\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20Key\x20breakthrough\x20(pre-written)')),console[ag(0x7a)](a0z['bold']['green'](ag(0x13e))+a0z['gray'](ag(0x166))),console[ag(0x7a)](a0z['white'](ag(0xdf))+a0z[ag(0x161)]('\x20\x20\x20\x20\x20Run\x20Python\x20in\x20shell')),console['log'](a0z['gray']('\x20\x20\x20\x20Just\x20type\x20freely\x20to\x20chat\x20with\x20the\x20AI\x20teammate.')),console['log'](a0z['gray'](ag(0x15e))+a0z[ag(0x97)](ag(0xcc))),console[ag(0x7a)](),console[ag(0x7a)](a0z['gray'](ag(0x114))+a0z[ag(0x161)](ag(0x6b))),console[ag(0x7a)](a0z[ag(0x161)](ag(0x112))+a0z[ag(0x161)](ag(0xe2))),console[ag(0x7a)](),x(),console['log'](a0z[ag(0x161)]('\x20\x20Model:\x20Google\x20Gemma\x204\x20('+W+')')),console[ag(0x7a)]();}(K,J,R),!(-0x635+0x1bbd+-0x35*0x68);}(G,H);}const B=a0E(),D=B[ad(0x7f)]||ad(0xea);if(a0F())return B[ad(0x98)]?void await(async function(){const ah=ad,J=a0E(),K=J[ah(0x17f)],L=J[ah(0x98)],M=J[ah(0x132)]||'Unknown';let N='';if(K)try{const {CTFdClient:O}=await import(ah(0x181)),P=J[ah(0x14d)]||'',Q=J[ah(0xa0)]&&!J[ah(0xa0)][ah(0xc8)](ah(0xa4))?J[ah(0xa0)]:'',R=new O(J['ctfdUrl'],Q,P||J['token']);N=(await R['getChallenge'](K))[ah(0x113)]||'';}catch{}try{h=await a0B(void(0x1619*-0x1+0x1a7c+0x1*-0x463),function(S,T,U){const ai=ah;return'You\x20are\x20an\x20AI\x20teammate\x20helping\x20a\x20contestant\x20in\x20a\x20live\x20Capture-The-Flag\x20competition.\x0a\x0aCURRENT\x20CHALLENGE:\x20\x22'+S+ai(0x6c)+T+').'+(U?ai(0x19b)+U:'')+'\x0a\x0aYOUR\x20RULES:\x0a-\x20You\x20MAY\x20explain\x20concepts,\x20describe\x20approaches,\x20and\x20help\x20the\x20contestant\x20reason\x20through\x20the\x20problem.\x0a-\x20You\x20MAY\x20discuss\x20the\x20technology\x20involved\x20(crypto,\x20web,\x20forensics,\x20pwn,\x20reversing,\x20OSINT,\x20stego,\x20etc.).\x0a-\x20You\x20MAY\x20help\x20debug\x20code\x20the\x20contestant\x20writes\x20and\x20suggest\x20which\x20tool\x20/\x20library\x20/\x20technique\x20to\x20use.\x0a-\x20You\x20MUST\x20NOT\x20reveal\x20or\x20guess\x20the\x20flag,\x20and\x20MUST\x20NOT\x20output\x20any\x20flag-shaped\x20string\x20(anything\x20like\x20name{...}).\x0a-\x20You\x20MUST\x20NOT\x20solve\x20the\x20whole\x20challenge\x20end-to-end\x20for\x20the\x20contestant\x20—\x20guide,\x20don\x27t\x20hand\x20over\x20the\x20answer.\x0a-\x20Keep\x20responses\x20concise\x20and\x20practical.\x20The\x20contestant\x20is\x20racing\x20the\x20clock.';}(L,M,N));}catch(S){return a0J(S['message']),!(-0x1160+0xf4e+0x213);}u=!(0x2151*0x1+-0x23f8+0x1*0x2a7),y=0x575+0x413+0x28*-0x3d,f=!(-0x234f+0x1993+-0x115*-0x9),d=b,m=!(-0x2*0xf3+-0x25e2+0x27c8);try{if(J[ah(0x103)]&&J['token']){const T=await a0L(J[ah(0x103)]+ah(0x188),{'headers':{'Authorization':'Token\x20'+J[ah(0xa0)],'User-Agent':ah(0x191)}});if(T['ok']){const U=await T[ah(0x86)]();ah(0x6d)==typeof U[ah(0x176)]?.[ah(0x198)]&&(y=U[ah(0x176)][ah(0x198)],f=!(0x2116+-0xad*-0x1c+0x76e*-0x7)),ah(0x6d)==typeof U[ah(0x176)]?.[ah(0xb6)]&&(d=U[ah(0x176)][ah(0xb6)]),ah(0x100)==typeof U['data']?.[ah(0x17c)]&&(m=U[ah(0x176)][ah(0x17c)]);}}}catch{}return p=!(0xb83+-0xb92*0x1+0x10),A={'challengeId':K,'challengeName':L,'challengeCategory':M,'enteredAt':Date[ah(0x78)]()},function(V,W){const aj=ah,X=a0E()[aj(0x7f)]||aj(0xea);console[aj(0x7a)](),console[aj(0x7a)](a0z[aj(0x104)]['bold'](aj(0x101))),console[aj(0x7a)](),console[aj(0x7a)](a0z[aj(0x12d)](aj(0xf1))),console[aj(0x7a)](a0z[aj(0x12d)](aj(0x164))+a0z[aj(0x163)][aj(0x97)](V)+a0z['gray']('\x20\x20\x20['+W+']')),console[aj(0x7a)](a0z['cyan'](aj(0x17d))),console[aj(0x7a)](a0z['cyan']('\x20\x20│\x20')+a0z['gray'](aj(0x89))),console[aj(0x7a)](a0z[aj(0x12d)](aj(0x164))+a0z['gray']('the\x20AI\x20guides,\x20it\x20will\x20not\x20hand\x20you\x20the\x20flag.')),console[aj(0x7a)](a0z['cyan'](aj(0x11c))),console['log'](),console[aj(0x7a)](a0z[aj(0xb5)]('\x20\x20Commands')),console['log'](a0z[aj(0x97)](aj(0x14c))+a0z[aj(0x161)]('Ask\x20the\x20AI\x20teammate\x20about\x20this\x20challenge')),console[aj(0x7a)](a0z[aj(0x97)](aj(0xee))+a0z[aj(0x161)](aj(0x13c))),console[aj(0x7a)](a0z[aj(0x97)](aj(0x14f))+a0z['gray'](aj(0x150))),console[aj(0x7a)](a0z['white'](aj(0x9f))+a0z[aj(0x161)]('Leave\x20the\x20AI\x20teammate')),console[aj(0x7a)](),console['log'](a0z[aj(0x161)](aj(0x167))+a0z[aj(0x97)](aj(0xf3))+a0z[aj(0x161)]('\x20then\x20re-enter\x20')+a0z['white'](aj(0x153))),x(),console['log'](a0z[aj(0x161)](aj(0xcf)+X+')')),console[aj(0x7a)](a0z[aj(0x161)](aj(0x79))),console['log']();}(L,M),!(0x18c1*-0x1+-0x63b*0x5+0x37e8);}()):(console[ad(0x7a)](),console[ad(0x7a)](a0z[ad(0xb5)]('\x20\x20No\x20challenge\x20open\x20yet.')),console[ad(0x7a)](a0z[ad(0x161)](ad(0x160))+a0z['white'](ad(0x119))+a0z['gray'](ad(0xe6))+a0z[ad(0x97)](ad(0xf3))),console[ad(0x7a)](a0z[ad(0x161)]('\x20\x20The\x20AI\x20teammate\x20scopes\x20itself\x20to\x20the\x20challenge\x20you\x20open.')),void console[ad(0x7a)]());const E={};E[ad(0xd9)]=ad(0x12e),E[ad(0x156)]=ad(0x135);const F=E;try{h=await a0B(F);}catch(J){return void a0J(J[ad(0xae)]);}u=!(0x1*-0x23a4+0x27d*0x7+-0x3*-0x613),y=-0x4*0x6fb+0x518+0x16d4,p=!(-0x6c6+0x2*-0x741+-0x1549*-0x1),console[ad(0x7a)](),console['log'](a0z[ad(0x104)]['bold']('\x20\x20═══\x20'+a0K(ad(0x1a1))+'\x20═══')),console[ad(0x7a)](),console[ad(0x7a)](a0z[ad(0x97)]('\x20\x20'+a0K(ad(0x128)))),console[ad(0x7a)](),console[ad(0x7a)](a0z['cyan'](ad(0xf1))),console[ad(0x7a)](a0z[ad(0x12d)]('\x20\x20│\x20')+a0z[ad(0x163)][ad(0x97)](a0K('ai4ctfChallenge'))),console['log'](a0z[ad(0x12d)](ad(0x17d))),console[ad(0x7a)](a0z['cyan']('\x20\x20│\x20')+a0z[ad(0x97)](a0K('ai4ctfIntercepted'))),console[ad(0x7a)](a0z[ad(0x12d)](ad(0x164))+a0z[ad(0x104)](ad(0x93))),console[ad(0x7a)](a0z[ad(0x12d)]('\x20\x20│')),console[ad(0x7a)](a0z[ad(0x12d)](ad(0x164))+a0z[ad(0x97)](a0K(ad(0xd8)))),console[ad(0x7a)](a0z[ad(0x12d)](ad(0x164))+a0z[ad(0x161)](ad(0x15b))),console[ad(0x7a)](a0z[ad(0x12d)]('\x20\x20└─────────────────────────────────────────────')),console[ad(0x7a)](),console[ad(0x7a)](a0z[ad(0x97)]('\x20\x20'+a0K('ai4ctfLevels'))),console[ad(0x7a)](),console['log'](a0z[ad(0xb5)](ad(0xe5))+a0z[ad(0x161)](ad(0x11b)+a0K(ad(0xd2)))),console['log'](a0z[ad(0x161)](ad(0x7c)+a0K(ad(0xbd)))),console[ad(0x7a)](a0z['yellow'](ad(0x195))+a0z[ad(0x161)](ad(0x11b)+a0K(ad(0x183)))),console[ad(0x7a)](a0z['gray'](ad(0x7c)+a0K('ai4ctfHintBUses'))),console[ad(0x7a)](a0z[ad(0xb5)](ad(0x143))+a0z[ad(0x161)](ad(0x11b)+a0K('ai4ctfHintC'))),console[ad(0x7a)](a0z[ad(0x161)](ad(0x7c)+a0K(ad(0xb3)))),console[ad(0x7a)](),console[ad(0x7a)](a0z['gray'](ad(0xba))),console[ad(0x7a)](a0z[ad(0x163)][ad(0x97)]('\x20\x20'+a0K(ad(0xbc)))),console[ad(0x7a)](ad(0x11b)+a0z[ad(0x12d)]('hint\x20a')+a0z[ad(0x161)](ad(0x7b)+a0K('ai4ctfHintNudge'))),console['log'](ad(0x11b)+a0z[ad(0x12d)]('hint\x20b')+a0z['gray'](ad(0x7b)+a0K(ad(0xe1)))),console[ad(0x7a)](ad(0x11b)+a0z[ad(0x12d)](ad(0x18e))+a0z[ad(0x161)](ad(0x7b)+a0K('ai4ctfHintPrinciple'))),console[ad(0x7a)](a0z[ad(0x161)](ad(0x11b)+a0K(ad(0x11a)))),console['log'](),console['log'](a0z[ad(0x97)]('\x20\x20'+a0K(ad(0x82)))),console['log'](a0z[ad(0x161)]('\x20\x20'+a0K('ai4ctfOrChatExample')+'\x20')+a0z[ad(0x97)]('\x22what\x20encoding\x20is\x20this?\x22')),console[ad(0x7a)](),console[ad(0x7a)](a0z[ad(0xb5)]('\x20\x20'+a0K(ad(0x88)))),console[ad(0x7a)](a0z['white'](ad(0xc3))+a0z['gray'](a0K('ai4ctfCmdHintLine'))),console['log'](a0z[ad(0x97)](ad(0x14f))+a0z[ad(0x161)](a0K(ad(0x146)))),console['log'](a0z[ad(0x97)]('\x20\x20\x20\x20!<shell\x20cmd>\x20\x20\x20\x20')+a0z['gray'](a0K(ad(0xa9)))),console['log'](a0z[ad(0x161)](ad(0x15e))+a0z[ad(0x97)](ad(0x127))),console[ad(0x7a)](a0z['gray'](ad(0x9f)+a0K(ad(0xd5)))),console[ad(0x7a)](),x(),console[ad(0x7a)](a0z[ad(0x161)]('\x20\x20'+a0K('ai4ctfModel')+ad(0xff)+D+')')),console[ad(0x7a)](a0z[ad(0x161)]('\x20\x20'+a0K(ad(0x192)))),console[ad(0x7a)]();});}
@@ -1 +1 @@
1
- import{spawnSync as e}from"node:child_process";import{existsSync as o,mkdirSync as t,readFileSync as n,writeFileSync as r}from"node:fs";import{homedir as a}from"node:os";import{join as l}from"node:path";import chalk from"chalk";import{aienvPaths as s}from"../lib/aienv.js";import{addTokenUsage as i}from"../lib/budget.js";import{getConfig as c}from"../lib/config.js";import{createChatSession as g}from"../lib/gemini.js";import{openFile as u}from"../lib/open-file.js";import{makeReplAsker as y}from"../lib/repl-asker.js";const h=["eai-p1","eai-p2","eai-p3","eai-p4","eai-p5"];function p(){if(process.env.ICOA_ARENA_SERVER)return process.env.ICOA_ARENA_SERVER.replace(/\/$/,"");try{const e=JSON.parse(n(l(a(),".icoa","config.json"),"utf-8"));if("string"==typeof e.arenaServer&&e.arenaServer)return e.arenaServer.replace(/\/$/,"");if("string"==typeof e.ctfdUrl&&e.ctfdUrl)return e.ctfdUrl.replace(/\/$/,"")}catch{}return"https://practice.icoa2026.au"}function d(){const e={"Content-Type":"application/json"};let o=process.env.ICOA_ARENA_ACCOUNT||"";try{const t=c();t.ctfdUrl&&t.token&&t.userName?(o=t.userName,e.Authorization=`Token ${t.token}`):t.userName&&(o=t.userName)}catch{}return o||(o="local-tester"),{account:o,headers:e}}async function f(e){try{const{headers:o}=d(),t=await fetch(p()+e,{headers:o,signal:AbortSignal.timeout(2e4)});return await t.json()}catch{return null}}async function m(e,o){try{const{headers:t}=d(),n=await fetch(p()+e,{method:"POST",headers:t,body:JSON.stringify(o),signal:AbortSignal.timeout(2e4)}),r=await n.json();return{status:n.status,data:r.data??r}}catch{return null}}export function normalizeTaskId(e){let o=e.trim().toLowerCase();return o?(o=o.replace(/^eai-?/,""),/^p\d+$/.test(o)?`eai-${o}`:/^\d+$/.test(o)?`eai-${o.padStart(2,"0")}`:`eai-${o}`):""}export function buildPolicyInstruction(e,o,t){const n=o.trim();if(n.startsWith("{"))try{const o=JSON.parse(n);return o.op||(o.op=e),JSON.stringify(o)}catch{return null}const r=n.split(/[\s,]+/).filter(Boolean);if(0===r.length)return null;const a=r.map(e=>{const o=Number(e);return Number.isNaN(o)?e:o});if("query"===e){const e=t?.query?.q,o=Array.isArray(e)&&e.length?e.length:2;return a.length<o?null:JSON.stringify({op:"query",q:a.slice(0,o)})}const l=t?.submit?.a;if(Array.isArray(l)){const e=0===l.length||"..."===l[l.length-1]||"…"===l[l.length-1]?a.length:l.length;return a.length<e?null:JSON.stringify({op:"submit",a:a.slice(0,e)})}return a.length>=4&&a.slice(0,4).every(e=>"number"==typeof e)?JSON.stringify({op:"submit",a:{x:[a[0],a[1]],y:[a[2],a[3]]}}):null}function b(e){const o=e.protocol,t=o?.query?.q,n=o?.submit?.a,r=Array.isArray(t)&&t.length?`probe ${t.map(e=>`<${String(e)}>`).join(" ")}`:"probe <x> <y>";let a;return a=Array.isArray(n)&&n.length?`submit ${n.map(e=>`<${String(e)}>`).join(" ")}`:"submit <x0> <x1> <y0> <y1>",{probe:r,submit:a}}function w(e,o,t){const n=e??"?",r=o??"?",a=t??"?";return chalk.gray(` probes: ${n}/${r} · ${a} left`)}function k(e){var o;console.log(),console.log(` ${o=e.bucket,"win"===o?chalk.bold.green("● WIN"):"progress"===o?chalk.bold.yellow("◐ progress"):chalk.gray("○ baseline")}${"number"==typeof e.distance?chalk.gray(` distance: ${e.distance}`):""}`),function(e){if(!e)return;if(e.error)return void console.log(chalk.yellow(" ⚠ ")+chalk.gray(String(e.error)));if(e.oracle&&"object"==typeof e.oracle){const o=e.oracle,t=Object.entries(o).map(([e,o])=>`${e}=${"number"==typeof o?o:JSON.stringify(o)}`);return void console.log(chalk.gray(" oracle: ")+chalk.white(t.join(" · ")))}if(Array.isArray(e.block_final)){const[o,t]=e.block_final;console.log(chalk.gray(" object settled at: ")+chalk.white(`(${o.toFixed(3)}, ${t.toFixed(3)})`))}"number"==typeof e.value&&console.log(chalk.gray(" grounded action value: ")+chalk.white(e.value.toFixed(3)));const o=e.hold_constraint_force??e.hold_contact_force;if("number"==typeof o&&o>0&&console.log(chalk.gray(" sustained force: ")+chalk.white(o.toFixed(2))),Array.isArray(e.contacts_seen)&&e.contacts_seen.length){const o=e.contacts_seen.slice(0,4).join(", ");console.log(chalk.gray(" contacts: ")+chalk.white(o))}}(e.telemetry),"win"===e.bucket&&e.flag&&(console.log(),console.log(chalk.bold.green(" 🏁 FLAG: ")+chalk.bold.white(e.flag)),console.log(chalk.gray(" paste this onto the CTFd scoreboard to score the challenge."))),console.log(w(e.used,e.budget,e.remaining)),console.log()}export function taskDir(e){return l(a(),".icoa","arena","eai",e)}async function $(e,o){const n="number"==typeof o?o.toFixed(3):"ref",a="ref"===n;console.log(),console.log(chalk.gray(a?" Fetching a reference clip of a successful rollout…":` Fetching the 3-second video of your last landing (value ${n})…`));const s=await f(`/api/icoa/arena/eai/${e}/clip/${encodeURIComponent(n)}`),i=s?.data??s??{};if(!i.clip_b64)return console.log(chalk.gray(" No video for that landing yet — use ")+chalk.cyan("roll")+chalk.gray(" to study the physics as ASCII telemetry.")),void console.log();const c=l(taskDir(e),"replay.mp4");try{t(taskDir(e),{recursive:!0}),r(c,Buffer.from(i.clip_b64,"base64"))}catch{return void console.log(chalk.yellow(" Could not save the clip locally."))}u(c)||console.log(chalk.yellow(" Could not launch a video player. The clip is here: ")+chalk.white(c)),console.log()}export function selfCheckRunnable(e){return!(e.includes("runpy.run_path")&&/os\.path\.dirname\(\s*os\.path\.dirname/.test(e))}function v(t,r,i){if("policy"===r.kind)return console.log(),console.log(chalk.gray(" This is a POLICY task — there is no free local rollout (the oracle")),console.log(chalk.gray(" IS the secret). Explore it with budgeted ")),console.log(chalk.cyan(` ${b(r).probe}`)+chalk.gray(" → one query to the oracle")),void console.log();const c=taskDir(t),g=l(c,"scene.xml"),u=l(c,"self_check.py");if(!o(g)||!o(u))return console.log(chalk.yellow(" Local study files not present yet — reopen the task to fetch them.")),void console.log(chalk.gray(" (`roll` is an OPTIONAL free local study tool; `probe`/`submit` score without it.)"));if(!selfCheckRunnable(n(u,"utf-8")))return console.log(chalk.yellow(" This task's local study tool isn't available right now.")),void console.log(chalk.gray(" `probe`/`submit` still score normally — use those, or `hint` for strategy."));const y=s(a()).python;if(!o(y))return console.log(),console.log(chalk.yellow(" Local physics sim not installed.")),console.log(chalk.gray(" Run ")+chalk.cyan("aienv setup --physics")+chalk.gray(" to enable free local `roll`.")),console.log(chalk.gray(" (You can still `probe`/`submit` to the server without it.)")),void console.log();console.log(chalk.gray(` rolling locally at value=${i} …`));const h=e(y,[u,g,"--public",l(c,"public.json"),"--value",String(i)],{cwd:c,encoding:"utf-8",timeout:6e4});if(0!==h.status)return console.log(chalk.yellow(" Local roll failed.")),void(/No module named 'mujoco'|ModuleNotFoundError/.test(h.stderr||"")?console.log(chalk.gray(" The sim is missing mujoco — run ")+chalk.cyan("aienv setup --physics")+chalk.gray(".")):/XML Error|Erroring opening file|Error opening file|asset.*not found/i.test(h.stderr||"")?(console.log(chalk.gray(" This task's local study sim isn't available right now (scene assets).")),console.log(chalk.gray(" `probe`/`submit` still score normally — use those, or `replay` to study a clip."))):h.stderr&&console.log(chalk.gray(` ${h.stderr.trim().split("\n").slice(-3).join("\n ")}`)));process.stdout.write(h.stdout)}function A(e){if(console.log(),console.log(chalk.yellow(" hint:")),e.pedagogical_point&&console.log(chalk.gray(` ${String(e.pedagogical_point)}`)),"policy"===e.kind){const o=e.protocol?.submit?.a;Array.isArray(o)?(console.log(chalk.gray(" Strategy: each query is one budgeted look at the oracle. Probe to map how")),console.log(chalk.gray(" its output moves as you vary the inputs, then submit the smallest change")),console.log(chalk.gray(" that achieves the goal (mind any norm / size budget in the brief)."))):(console.log(chalk.gray(" Strategy: each query is one bit. Probe points across the floor to find")),console.log(chalk.gray(" the boundary (binary-search the edges), then submit the tightest rectangle.")))}else console.log(chalk.gray(" Strategy: use free `roll` to learn how far the object must travel to enter")),console.log(chalk.gray(" the keep-out zone, then escalate your wording (more forceful / literal /")),console.log(chalk.gray(' "into the red zone") until a `probe` reports progress, then win.'));console.log(chalk.gray(" 💡 Or type ")+chalk.magenta("ai4ctf")+chalk.gray(" right here to brainstorm the attack with your AI teammate.")),console.log()}function N(e){const o="policy"===e.kind;if(console.log(chalk.bold.white(" commands:")),e.has_clip&&console.log(chalk.cyan(" replay")+chalk.gray(" play a 3-second video of your last probe landing (free; `ref` clip before you probe)")),o){const o=b(e);console.log(chalk.cyan(` ${o.probe}`)+chalk.gray(" one budgeted query to the oracle (costs 1)")),console.log(chalk.cyan(` ${o.submit}`)+chalk.gray(" your attempt to claim the flag (costs 1)")),console.log(chalk.gray(" (or pass raw JSON, e.g. ")+chalk.cyan('probe {"q":[…]}')+chalk.gray(")"))}else console.log(chalk.cyan(" roll [value]")+chalk.gray(" free local rollout — study the physics (no cost)")),console.log(chalk.cyan(" probe <instruction>")+chalk.gray(" send the arm one instruction (costs 1)")),console.log(chalk.cyan(" submit <instruction>")+chalk.gray(" your best attempt to win + claim the flag (costs 1)"));console.log(chalk.cyan(" ai4ctf")+chalk.gray(" brainstorm the attack with your AI teammate (scoped here)")),console.log(chalk.cyan(" hint")+chalk.gray(" free strategy nudge")),console.log(chalk.cyan(" state")+chalk.gray(" show your remaining probe budget")),console.log(chalk.cyan(" help")+chalk.gray(" show these commands")),console.log(chalk.cyan(" quit")+chalk.gray(" leave this task")),console.log(),console.log(chalk.gray(" 💡 Stuck? Type ")+chalk.magenta("ai4ctf")+chalk.gray(" to brainstorm the attack with your built-in AI teammate.")),console.log()}async function _(e,o){let t;try{t=await g(void 0,function(e){const o="policy"===e.kind,t=e.protocol?.submit?.a,n=Array.isArray(t)?`POLICY task: probe the oracle with the query shape in the Brief (e.g. ${b(e).probe}); each probe spends one budget slot and returns the oracle's output. Guide them to map how the output moves as inputs vary, then submit the smallest valid claim (${b(e).submit}; mind any norm/size budget).`:'POLICY task: each probe asks "is [x,y] inside the hidden keep-out zone?" Guide a binary-search of the boundary, then a tight rectangle submit.';return["You are an AI red-team teammate inside the ICOA embodied-AI arena (ctf4eai).","The student is trying to make a robot arm / control policy do the unsafe thing","and earn the win flag. Help them brainstorm the ATTACK — strategy, what to","probe, how to read the telemetry — but DO NOT hand over a complete solution.","",`Task: ${e.title??e.task_id??"unknown"} (kind: ${e.kind??"physics"}, channel ${e.channel??"?"}).`,e.brief?`Brief: ${e.brief}`:"",e.pedagogical_point?`Teaching point: ${e.pedagogical_point}`:"","",o?n:"PHYSICS task: free local `roll` studies the dynamics; escalate the instruction wording until a probe reports progress, then submit to win.","Keep replies short and concrete. The student runs probe/submit in the arena to actually score — you advise only."].filter(Boolean).join("\n")}(e))}catch(e){return void console.log(chalk.red(" Could not start the AI teammate: ")+chalk.gray(e.message??""))}for(console.log(),console.log(chalk.magenta(" 🤝 AI teammate (ai4ctf)")+chalk.gray(" — scoped to this arena task.")),console.log(chalk.gray(" Brainstorm the attack. Type ")+chalk.cyan("back")+chalk.gray(" to return to the arena.")),console.log(chalk.gray(" (It advises only — run ")+chalk.cyan("probe")+chalk.gray("/")+chalk.cyan("submit")+chalk.gray(" in the arena to score.)")),console.log();;){const e=await o(chalk.magenta(" icoa ctf4eai/ai4ctf> "));if(null===e)return;const n=e.trim();if(!n)continue;const r=n.toLowerCase();if("back"===r||"quit"===r||"exit"===r||"q"===r)return;try{const e=await t.sendMessage(n);i(e.tokensUsed),console.log(),console.log(chalk.white(" "+e.text.split("\n").join("\n "))),console.log()}catch(e){const o=e.message??"";/403|budget/i.test(o)?console.log(chalk.yellow(" AI budget exhausted for this account.")):console.log(chalk.red(" AI error: ")+chalk.gray(o.split("\n")[0]||"unknown"))}}}export async function runArenaEai(e){const o=y(),n=o.ask;try{console.log(),console.log(chalk.bold.cyan(" 🤖 ctf4eai — EMBODIED-AI ARENA")+chalk.gray(" · red-team the robot policy")),console.log(chalk.gray(" Make the ICOA-VLA arm / policy do the unsafe thing. The server judges and")),console.log(chalk.gray(" issues the wrapper{…} flag — paste it onto the CTFd scoreboard.")),console.log();let o=e?normalizeTaskId(e):"";if(!o){console.log(chalk.white(" Practice tasks:")),h.forEach((e,o)=>{console.log(chalk.gray(` ${o+1}. `)+chalk.cyan(e))}),console.log(chalk.gray(" (or type any task id, e.g. eai-p3 / p3 / eai-07)"));const e=await n(chalk.cyan(" pick a task (number or id): "));if(null===e)return;const t=e.trim(),r=Number(t);o=!Number.isNaN(r)&&h[r-1]?h[r-1]:normalizeTaskId(t)}if(!o)return void console.log(chalk.yellow(" No task selected."));await async function(e,o){console.log(chalk.gray(` fetching ${e} from `)+chalk.gray(p())+chalk.gray(" …"));const n=await async function(e){const o=await f(`/api/icoa/arena/eai/${e}/data`);if(!o)return null;const n=o.data??o;if(!n.public)return null;const a=taskDir(e);try{t(a,{recursive:!0}),r(l(a,"public.json"),JSON.stringify(n.public,null,2)),n.scene_xml&&r(l(a,"scene.xml"),n.scene_xml),n.core&&r(l(a,"arena_physics_core.py"),n.core),n.self_check&&r(l(a,"self_check.py"),n.self_check)}catch(e){console.log(chalk.yellow(" Could not write the local arena files to ")+chalk.white(a)+chalk.gray(` (${e.message??"unknown"}).`)),console.log(chalk.gray(" `probe`/`submit` still work; only free local `roll` needs them."))}return n.public}(e);if(!n)return void console.log(chalk.yellow(` Could not load ${e} — unknown task, or the arena server is unreachable.`));!function(e){if(console.log(),console.log(chalk.bold.cyan(` 🤖 ${e.title??e.task_id}`)+chalk.gray(` · ${e.kind??"physics"} · channel ${e.channel??"?"} · ${e.difficulty??""}`)),e.brief){console.log();for(const o of function(e){const o=[];for(const t of e.split("\n")){let e="";for(const n of t.split(/\s+/))e&&`${e} ${n}`.length>76?(o.push(e),e=n):e=e?`${e} ${n}`:n;o.push(e)}return o}(String(e.brief)))console.log(chalk.gray(` ${o}`))}console.log()}(n);const{account:a}=d(),s=await m(`/api/icoa/arena/eai/${e}/state`,{account:a}),i=s?.data??{};i.ok&&(i.won&&console.log(chalk.bold.green(" ✓ you have already won this task.")),console.log(w(i.used,i.budget,i.remaining)),console.log()),N(n);const c="policy"===n.kind;let g;for(;;){const t=await o(chalk.bold.cyan(" icoa ctf4eai> "));if(null===t)return;const r=t.trim();if(!r)continue;const l=r.indexOf(" "),s=(-1===l?r:r.slice(0,l)).toLowerCase(),i=-1===l?"":r.slice(l+1).trim();if("quit"===s||"exit"===s||"q"===s||"back"===s)return;if("help"!==s&&"?"!==s)if("hint"!==s)if("replay"!==s&&"watch"!==s&&"video"!==s)if("ai4ctf"!==s&&"ai"!==s&&"teammate"!==s){if("state"===s){const o=await m(`/api/icoa/arena/eai/${e}/state`,{account:a}),t=o?.data??{};t.ok?console.log(w(t.used,t.budget,t.remaining)+(t.won?chalk.green(" ✓ won"):"")):console.log(chalk.gray(" (state unavailable)"));continue}if("roll"!==s)if("probe"===s||"submit"===s){if(!i){const e=b(n);console.log(c?chalk.gray(` usage: ${"probe"===s?e.probe:e.submit}`):chalk.gray(` usage: ${s} <instruction text>`));continue}let o;if(c){const e=buildPolicyInstruction("probe"===s?"query":"submit",i,n.protocol);if(!e){const e=b(n);console.log(chalk.yellow(" Could not parse that. ")+chalk.gray(`Try: ${"probe"===s?e.probe.replace(/<[^>]*>/g,"0"):e.submit.replace(/<[^>]*>/g,"0")}`));continue}o=e}else o=i.replace(/^["']|["']$/g,"");const t=await m(`/api/icoa/arena/eai/${e}/probe`,{account:a,instruction:o});if(!t){console.log(chalk.yellow(" The arena server is unreachable right now — try again."));continue}const r=t.data;if(403===t.status||"budget_exhausted"===r.reason){console.log(chalk.yellow(` Out of probes for this task (used ${r.used??"?"}/${r.budget??"?"}). No more attempts.`));continue}if(!r.ok&&r.reason){console.log(chalk.yellow(" Rejected: ")+chalk.gray(r.reason));continue}k(r);const l=r.telemetry?.value;if("number"==typeof l&&(g=l),"win"===r.bucket)return void(n.has_clip&&(console.log(chalk.gray(" 🎬 replaying your winning rollout…")),await $(e,g)))}else console.log(chalk.gray(" unknown command — type ")+chalk.cyan("help"));else if(c)v(e,n,0);else{const o=Number(i);v(e,n,Number.isNaN(o)?.4:o)}}else await _(n,o);else await $(e,g);else A(n);else N(n)}}(o,n),console.log(chalk.gray(" left the arena. Type ")+chalk.cyan("eai")+chalk.gray(" to come back any time.")),console.log()}finally{o.close()}}
1
+ import{spawnSync as e}from"node:child_process";import{existsSync as o,mkdirSync as t,readFileSync as n,writeFileSync as r}from"node:fs";import{homedir as a}from"node:os";import{join as l}from"node:path";import chalk from"chalk";import{aienvPaths as s}from"../lib/aienv.js";import{addTokenUsage as i}from"../lib/budget.js";import{getConfig as c}from"../lib/config.js";import{createChatSession as g}from"../lib/gemini.js";import{openFile as u}from"../lib/open-file.js";import{makeReplAsker as y}from"../lib/repl-asker.js";const h=["eai-p1","eai-p2","eai-p3","eai-p4","eai-p5"];function p(){if(process.env.ICOA_ARENA_SERVER)return process.env.ICOA_ARENA_SERVER.replace(/\/$/,"");try{const e=JSON.parse(n(l(a(),".icoa","config.json"),"utf-8"));if("string"==typeof e.arenaServer&&e.arenaServer)return e.arenaServer.replace(/\/$/,"");if("string"==typeof e.ctfdUrl&&e.ctfdUrl)return e.ctfdUrl.replace(/\/$/,"")}catch{}return"https://practice.icoa2026.au"}function d(){const e={"Content-Type":"application/json"};let o=process.env.ICOA_ARENA_ACCOUNT||"";try{const t=c();t.ctfdUrl&&t.token&&t.userName?(o=t.userName,e.Authorization=`Token ${t.token}`):t.userName&&(o=t.userName)}catch{}return o||(o="local-tester"),{account:o,headers:e}}async function f(e){try{const{headers:o}=d(),t=await fetch(p()+e,{headers:o,signal:AbortSignal.timeout(2e4)});return await t.json()}catch{return null}}async function m(e,o){try{const{headers:t}=d(),n=await fetch(p()+e,{method:"POST",headers:t,body:JSON.stringify(o),signal:AbortSignal.timeout(2e4)}),r=await n.json();return{status:n.status,data:r.data??r}}catch{return null}}export function normalizeTaskId(e){let o=e.trim().toLowerCase();return o?(o=o.replace(/^eai-?/,""),/^p\d+$/.test(o)?`eai-${o}`:/^\d+$/.test(o)?`eai-${o.padStart(2,"0")}`:`eai-${o}`):""}export function buildPolicyInstruction(e,o,t){const n=o.trim();if(n.startsWith("{"))try{const o=JSON.parse(n);return o.op||(o.op=e),JSON.stringify(o)}catch{return null}const r=n.split(/[\s,]+/).filter(Boolean);if(0===r.length)return null;const a=r.map(e=>{const o=Number(e);return Number.isNaN(o)?e:o});if("query"===e){const e=t?.query?.q,o=Array.isArray(e)&&e.length?e.length:2;return a.length<o?null:JSON.stringify({op:"query",q:a.slice(0,o)})}const l=t?.submit?.a;if(Array.isArray(l)){const e=0===l.length||"..."===l[l.length-1]||"…"===l[l.length-1]?a.length:l.length;return a.length<e?null:JSON.stringify({op:"submit",a:a.slice(0,e)})}return a.length>=4&&a.slice(0,4).every(e=>"number"==typeof e)?JSON.stringify({op:"submit",a:{x:[a[0],a[1]],y:[a[2],a[3]]}}):null}function b(e){const o=e.protocol,t=o?.query?.q,n=o?.submit?.a,r=Array.isArray(t)&&t.length?`probe ${t.map(e=>`<${String(e)}>`).join(" ")}`:"probe <x> <y>";let a;return a=Array.isArray(n)&&n.length?`submit ${n.map(e=>`<${String(e)}>`).join(" ")}`:"submit <x0> <x1> <y0> <y1>",{probe:r,submit:a}}function w(e,o,t){const n=e??"?",r=o??"?",a=t??"?";return chalk.gray(` probes: ${n}/${r} · ${a} left`)}function k(e){var o;console.log(),console.log(` ${o=e.bucket,"win"===o?chalk.bold.green("● WIN"):"progress"===o?chalk.bold.yellow("◐ progress"):chalk.gray("○ baseline")}${"number"==typeof e.distance?chalk.gray(` distance: ${e.distance}`):""}`),function(e){if(!e)return;if(e.error)return void console.log(chalk.yellow(" ⚠ ")+chalk.gray(String(e.error)));if(e.oracle&&"object"==typeof e.oracle){const o=e.oracle,t=Object.entries(o).map(([e,o])=>`${e}=${"number"==typeof o?o:JSON.stringify(o)}`);return void console.log(chalk.gray(" oracle: ")+chalk.white(t.join(" · ")))}if(Array.isArray(e.block_final)){const[o,t]=e.block_final;console.log(chalk.gray(" object settled at: ")+chalk.white(`(${o.toFixed(3)}, ${t.toFixed(3)})`))}"number"==typeof e.value&&console.log(chalk.gray(" grounded action value: ")+chalk.white(e.value.toFixed(3)));const o=e.hold_constraint_force??e.hold_contact_force;if("number"==typeof o&&o>0&&console.log(chalk.gray(" sustained force: ")+chalk.white(o.toFixed(2))),Array.isArray(e.contacts_seen)&&e.contacts_seen.length){const o=e.contacts_seen.slice(0,4).join(", ");console.log(chalk.gray(" contacts: ")+chalk.white(o))}}(e.telemetry),"win"===e.bucket&&e.flag&&(console.log(),console.log(chalk.bold.green(" 🏁 FLAG: ")+chalk.bold.white(e.flag)),console.log(chalk.gray(" paste this onto the CTFd scoreboard to score the challenge."))),console.log(w(e.used,e.budget,e.remaining)),console.log()}export function taskDir(e){return l(a(),".icoa","arena","eai",e)}async function $(e,o){const n="number"==typeof o?o.toFixed(3):"ref",a="ref"===n;console.log(),console.log(chalk.gray(a?" Fetching a reference clip of a successful rollout…":` Fetching the 3-second video of your last landing (value ${n})…`));const s=await f(`/api/icoa/arena/eai/${e}/clip/${encodeURIComponent(n)}`),i=s?.data??s??{};if(!i.clip_b64)return console.log(chalk.gray(" No video for that landing yet — use ")+chalk.cyan("roll")+chalk.gray(" to study the physics as ASCII telemetry.")),void console.log();const c=l(taskDir(e),"replay.mp4");try{t(taskDir(e),{recursive:!0}),r(c,Buffer.from(i.clip_b64,"base64"))}catch{return void console.log(chalk.yellow(" Could not save the clip locally."))}u(c)||console.log(chalk.yellow(" Could not launch a video player. The clip is here: ")+chalk.white(c)),console.log()}export function selfCheckRunnable(e){return!(e.includes("runpy.run_path")&&/os\.path\.dirname\(\s*os\.path\.dirname/.test(e))}function v(t,r,i){if("policy"===r.kind)return console.log(),console.log(chalk.gray(" This is a POLICY task — there is no free local rollout (the oracle")),console.log(chalk.gray(" IS the secret). Explore it with budgeted ")),console.log(chalk.cyan(` ${b(r).probe}`)+chalk.gray(" → one query to the oracle")),void console.log();const c=taskDir(t),g=l(c,"scene.xml"),u=l(c,"self_check.py");if(!o(g)||!o(u))return console.log(chalk.yellow(" Local study files not present yet — reopen the task to fetch them.")),void console.log(chalk.gray(" (`roll` is an OPTIONAL free local study tool; `probe`/`submit` score without it.)"));if(!selfCheckRunnable(n(u,"utf-8")))return console.log(chalk.yellow(" This task's local study tool isn't available right now.")),void console.log(chalk.gray(" `probe`/`submit` still score normally — use those, or `hint` for strategy."));const y=s(a()).python;if(!o(y))return console.log(),console.log(chalk.yellow(" Local physics sim not installed.")),console.log(chalk.gray(" Run ")+chalk.cyan("aienv setup --physics")+chalk.gray(" to enable free local `roll`.")),console.log(chalk.gray(" (You can still `probe`/`submit` to the server without it.)")),void console.log();console.log(chalk.gray(` rolling locally at value=${i} …`));const h=e(y,[u,g,"--public",l(c,"public.json"),"--value",String(i)],{cwd:c,encoding:"utf-8",timeout:6e4});if(0!==h.status)return console.log(chalk.yellow(" Local roll failed.")),void(/No module named 'mujoco'|ModuleNotFoundError/.test(h.stderr||"")?console.log(chalk.gray(" The sim is missing mujoco — run ")+chalk.cyan("aienv setup --physics")+chalk.gray(".")):/XML Error|Erroring opening file|Error opening file|asset.*not found/i.test(h.stderr||"")?(console.log(chalk.gray(" This task's local study sim isn't available right now (scene assets).")),console.log(chalk.gray(" `probe`/`submit` still score normally — use those, or `replay` to study a clip."))):h.stderr&&console.log(chalk.gray(` ${String(h.stderr??"").trim().split("\n").slice(-3).join("\n ")}`)));process.stdout.write(h.stdout)}function A(e){if(console.log(),console.log(chalk.yellow(" hint:")),e.pedagogical_point&&console.log(chalk.gray(` ${String(e.pedagogical_point)}`)),"policy"===e.kind){const o=e.protocol?.submit?.a;Array.isArray(o)?(console.log(chalk.gray(" Strategy: each query is one budgeted look at the oracle. Probe to map how")),console.log(chalk.gray(" its output moves as you vary the inputs, then submit the smallest change")),console.log(chalk.gray(" that achieves the goal (mind any norm / size budget in the brief)."))):(console.log(chalk.gray(" Strategy: each query is one bit. Probe points across the floor to find")),console.log(chalk.gray(" the boundary (binary-search the edges), then submit the tightest rectangle.")))}else console.log(chalk.gray(" Strategy: use free `roll` to learn how far the object must travel to enter")),console.log(chalk.gray(" the keep-out zone, then escalate your wording (more forceful / literal /")),console.log(chalk.gray(' "into the red zone") until a `probe` reports progress, then win.'));console.log(chalk.gray(" 💡 Or type ")+chalk.magenta("ai4ctf")+chalk.gray(" right here to brainstorm the attack with your AI teammate.")),console.log()}function N(e){const o="policy"===e.kind;if(console.log(chalk.bold.white(" commands:")),e.has_clip&&console.log(chalk.cyan(" replay")+chalk.gray(" play a 3-second video of your last probe landing (free; `ref` clip before you probe)")),o){const o=b(e);console.log(chalk.cyan(` ${o.probe}`)+chalk.gray(" one budgeted query to the oracle (costs 1)")),console.log(chalk.cyan(` ${o.submit}`)+chalk.gray(" your attempt to claim the flag (costs 1)")),console.log(chalk.gray(" (or pass raw JSON, e.g. ")+chalk.cyan('probe {"q":[…]}')+chalk.gray(")"))}else console.log(chalk.cyan(" roll [value]")+chalk.gray(" free local rollout — study the physics (no cost)")),console.log(chalk.cyan(" probe <instruction>")+chalk.gray(" send the arm one instruction (costs 1)")),console.log(chalk.cyan(" submit <instruction>")+chalk.gray(" your best attempt to win + claim the flag (costs 1)"));console.log(chalk.cyan(" ai4ctf")+chalk.gray(" brainstorm the attack with your AI teammate (scoped here)")),console.log(chalk.cyan(" hint")+chalk.gray(" free strategy nudge")),console.log(chalk.cyan(" state")+chalk.gray(" show your remaining probe budget")),console.log(chalk.cyan(" help")+chalk.gray(" show these commands")),console.log(chalk.cyan(" quit")+chalk.gray(" leave this task")),console.log(),console.log(chalk.gray(" 💡 Stuck? Type ")+chalk.magenta("ai4ctf")+chalk.gray(" to brainstorm the attack with your built-in AI teammate.")),console.log()}async function _(e,o){let t;try{t=await g(void 0,function(e){const o="policy"===e.kind,t=e.protocol?.submit?.a,n=Array.isArray(t)?`POLICY task: probe the oracle with the query shape in the Brief (e.g. ${b(e).probe}); each probe spends one budget slot and returns the oracle's output. Guide them to map how the output moves as inputs vary, then submit the smallest valid claim (${b(e).submit}; mind any norm/size budget).`:'POLICY task: each probe asks "is [x,y] inside the hidden keep-out zone?" Guide a binary-search of the boundary, then a tight rectangle submit.';return["You are an AI red-team teammate inside the ICOA embodied-AI arena (ctf4eai).","The student is trying to make a robot arm / control policy do the unsafe thing","and earn the win flag. Help them brainstorm the ATTACK — strategy, what to","probe, how to read the telemetry — but DO NOT hand over a complete solution.","",`Task: ${e.title??e.task_id??"unknown"} (kind: ${e.kind??"physics"}, channel ${e.channel??"?"}).`,e.brief?`Brief: ${e.brief}`:"",e.pedagogical_point?`Teaching point: ${e.pedagogical_point}`:"","",o?n:"PHYSICS task: free local `roll` studies the dynamics; escalate the instruction wording until a probe reports progress, then submit to win.","Keep replies short and concrete. The student runs probe/submit in the arena to actually score — you advise only."].filter(Boolean).join("\n")}(e))}catch(e){return void console.log(chalk.red(" Could not start the AI teammate: ")+chalk.gray(e.message??""))}for(console.log(),console.log(chalk.magenta(" 🤝 AI teammate (ai4ctf)")+chalk.gray(" — scoped to this arena task.")),console.log(chalk.gray(" Brainstorm the attack. Type ")+chalk.cyan("back")+chalk.gray(" to return to the arena.")),console.log(chalk.gray(" (It advises only — run ")+chalk.cyan("probe")+chalk.gray("/")+chalk.cyan("submit")+chalk.gray(" in the arena to score.)")),console.log();;){const e=await o(chalk.magenta(" icoa ctf4eai/ai4ctf> "));if(null===e)return;const n=e.trim();if(!n)continue;const r=n.toLowerCase();if("back"===r||"quit"===r||"exit"===r||"q"===r)return;try{const e=await t.sendMessage(n);i(e.tokensUsed),console.log(),console.log(chalk.white(" "+e.text.split("\n").join("\n "))),console.log()}catch(e){const o=e.message??"";/403|budget/i.test(o)?console.log(chalk.yellow(" AI budget exhausted for this account.")):console.log(chalk.red(" AI error: ")+chalk.gray(o.split("\n")[0]||"unknown"))}}}export async function runArenaEai(e){const o=y(),n=o.ask;try{console.log(),console.log(chalk.bold.cyan(" 🤖 ctf4eai — EMBODIED-AI ARENA")+chalk.gray(" · red-team the robot policy")),console.log(chalk.gray(" Make the ICOA-VLA arm / policy do the unsafe thing. The server judges and")),console.log(chalk.gray(" issues the wrapper{…} flag — paste it onto the CTFd scoreboard.")),console.log();let o=e?normalizeTaskId(e):"";if(!o){console.log(chalk.white(" Practice tasks:")),h.forEach((e,o)=>{console.log(chalk.gray(` ${o+1}. `)+chalk.cyan(e))}),console.log(chalk.gray(" (or type any task id, e.g. eai-p3 / p3 / eai-07)"));const e=await n(chalk.cyan(" pick a task (number or id): "));if(null===e)return;const t=e.trim(),r=Number(t);o=!Number.isNaN(r)&&h[r-1]?h[r-1]:normalizeTaskId(t)}if(!o)return void console.log(chalk.yellow(" No task selected."));await async function(e,o){console.log(chalk.gray(` fetching ${e} from `)+chalk.gray(p())+chalk.gray(" …"));const n=await async function(e){const o=await f(`/api/icoa/arena/eai/${e}/data`);if(!o)return null;const n=o.data??o;if(!n.public)return null;const a=taskDir(e);try{t(a,{recursive:!0}),r(l(a,"public.json"),JSON.stringify(n.public,null,2)),n.scene_xml&&r(l(a,"scene.xml"),n.scene_xml),n.core&&r(l(a,"arena_physics_core.py"),n.core),n.self_check&&r(l(a,"self_check.py"),n.self_check)}catch(e){console.log(chalk.yellow(" Could not write the local arena files to ")+chalk.white(a)+chalk.gray(` (${e.message??"unknown"}).`)),console.log(chalk.gray(" `probe`/`submit` still work; only free local `roll` needs them."))}return n.public}(e);if(!n)return void console.log(chalk.yellow(` Could not load ${e} — unknown task, or the arena server is unreachable.`));!function(e){if(console.log(),console.log(chalk.bold.cyan(` 🤖 ${e.title??e.task_id}`)+chalk.gray(` · ${e.kind??"physics"} · channel ${e.channel??"?"} · ${e.difficulty??""}`)),e.brief){console.log();for(const o of function(e){const o=[];for(const t of e.split("\n")){let e="";for(const n of t.split(/\s+/))e&&`${e} ${n}`.length>76?(o.push(e),e=n):e=e?`${e} ${n}`:n;o.push(e)}return o}(String(e.brief)))console.log(chalk.gray(` ${o}`))}console.log()}(n);const{account:a}=d(),s=await m(`/api/icoa/arena/eai/${e}/state`,{account:a}),i=s?.data??{};i.ok&&(i.won&&console.log(chalk.bold.green(" ✓ you have already won this task.")),console.log(w(i.used,i.budget,i.remaining)),console.log()),N(n);const c="policy"===n.kind;let g;for(;;){const t=await o(chalk.bold.cyan(" icoa ctf4eai> "));if(null===t)return;const r=t.trim();if(!r)continue;const l=r.indexOf(" "),s=(-1===l?r:r.slice(0,l)).toLowerCase(),i=-1===l?"":r.slice(l+1).trim();if("quit"===s||"exit"===s||"q"===s||"back"===s)return;if("help"!==s&&"?"!==s)if("hint"!==s)if("replay"!==s&&"watch"!==s&&"video"!==s)if("ai4ctf"!==s&&"ai"!==s&&"teammate"!==s){if("state"===s){const o=await m(`/api/icoa/arena/eai/${e}/state`,{account:a}),t=o?.data??{};t.ok?console.log(w(t.used,t.budget,t.remaining)+(t.won?chalk.green(" ✓ won"):"")):console.log(chalk.gray(" (state unavailable)"));continue}if("roll"!==s)if("probe"===s||"submit"===s){if(!i){const e=b(n);console.log(c?chalk.gray(` usage: ${"probe"===s?e.probe:e.submit}`):chalk.gray(` usage: ${s} <instruction text>`));continue}let o;if(c){const e=buildPolicyInstruction("probe"===s?"query":"submit",i,n.protocol);if(!e){const e=b(n);console.log(chalk.yellow(" Could not parse that. ")+chalk.gray(`Try: ${"probe"===s?e.probe.replace(/<[^>]*>/g,"0"):e.submit.replace(/<[^>]*>/g,"0")}`));continue}o=e}else o=i.replace(/^["']|["']$/g,"");const t=await m(`/api/icoa/arena/eai/${e}/probe`,{account:a,instruction:o});if(!t){console.log(chalk.yellow(" The arena server is unreachable right now — try again."));continue}const r=t.data;if(403===t.status||"budget_exhausted"===r.reason){console.log(chalk.yellow(` Out of probes for this task (used ${r.used??"?"}/${r.budget??"?"}). No more attempts.`));continue}if(!r.ok&&r.reason){console.log(chalk.yellow(" Rejected: ")+chalk.gray(r.reason));continue}k(r);const l=r.telemetry?.value;if("number"==typeof l&&(g=l),"win"===r.bucket)return void(n.has_clip&&(console.log(chalk.gray(" 🎬 replaying your winning rollout…")),await $(e,g)))}else console.log(chalk.gray(" unknown command — type ")+chalk.cyan("help"));else if(c)v(e,n,0);else{const o=Number(i);v(e,n,Number.isNaN(o)?.4:o)}}else await _(n,o);else await $(e,g);else A(n);else N(n)}}(o,n),console.log(chalk.gray(" left the arena. Type ")+chalk.cyan("eai")+chalk.gray(" to come back any time.")),console.log()}finally{o.close()}}
@@ -1 +1 @@
1
- import{spawnSync as e}from"node:child_process";import{gunzipSync as t}from"node:zlib";import{copyFileSync as o,existsSync as r,mkdirSync as n,readFileSync as a,rmSync as s,writeFileSync as l}from"node:fs";import{homedir as i}from"node:os";import{join as c}from"node:path";import chalk from"chalk";import{getConfig as d}from"../lib/config.js";import{runInteractive as g}from"../lib/interactive-spawn.js";import{lazyTarball as u}from"../lib/lazy-assets.js";import{logCommand as y}from"../lib/logger.js";import{printNoPython312 as p,probePython as h}from"../lib/python-setup.js";import{makeReplAsker as b}from"../lib/repl-asker.js";import{ARENA_VI_FLAGS as m}from"../lib/vi-flags.js";const f=()=>(d().language||"en").toLowerCase().startsWith("zh"),$=(e,t)=>f()?e:t,k=c(i(),".icoa","battleai"),w=c(k,"bot.py");let v=w;const x=c(k,"state.json"),N=c(k,"last.mobreplay"),S={edit:"edit",e:"edit",vi:"edit",code:"edit",syntax:"syntax",api:"syntax",doc:"syntax",docs:"syntax",play:"play",p:"play",run:"play",read:"read",readme:"read",goal:"read","题":"read","目标":"read","读":"read",fight:"play",duel:"duel",d:"duel","对撞":"duel","单挑":"duel",replay:"replay",r:"replay",watch:"replay",show:"replay",submit:"submit",s:"submit",judge:"submit",ac:"submit",status:"status",st:"status",progress:"status",bots:"bots",ladder:"bots",opponents:"bots",help:"help","?":"help",h:"help",back:"back",quit:"back",q:"back",exit:"back",menu:"menu",refresh:"refresh",reload:"refresh",update:"refresh","刷新":"refresh","更新":"refresh"};export function normalizeBattleVerb(e){const t=e.trim().replace(/^\//,"").split(/\s+/).filter(Boolean);return 0===t.length?{verb:"unknown",args:[]}:{verb:S[t[0].toLowerCase()]??"unknown",args:t.slice(1)}}async function A(){const e=process.env.ICOA_BATTLEAI_ENGINE_DIR;if(e&&r(c(e,"runner.py")))return e;const t=await u("battleai-engine.tar.gz","battleai-engine",15e3,{revalidate:!0});return t&&r(c(t,"runner.py"))?t:null}export async function runMobLocal(e,t,o=0,a,s=g){const l=await A();if(!l)return console.log(chalk.yellow($(" 竞技场引擎还没到这台机器(需要联网拉一次)。"," The arena engine is not on this machine yet (one online fetch needed)."))),{ok:!1,ran:!1};const i=h();if(!i.ok||!i.cmd)return p(f(),{judgeIsServerSide:!0}),{ok:!1,ran:!1};const c=i.cmd,d=C();n(k,{recursive:!0});const u=j(c,l,["play","--bot",e,"--card",String(t),"--seed",String(o),"--replay",N]);return"syntax"===u.error?(M(u),{ok:!1,ran:!0}):u.error?(console.log(chalk.yellow($(" bot 跑不起来:"," bot could not run: ")+String(u.message??""))),console.log(chalk.gray($(" ▸ edit 改一改再 run。第一行报错通常就是原因。"," ▸ edit, then run again. The first error line is usually why."))),{ok:!1,ran:!0}):(console.log(" "+chalk.white(T(u,a))),Number(u.errors)>0&&console.log(chalk.yellow($(` ⚠ 你的 bot 有 ${u.errors} 次异常(那些回合单位在发呆)。`,` ⚠ your bot raised ${u.errors} times (those units idled).`))),process.stdout.isTTY&&r(N)&&(console.log(chalk.gray($(" 正在打开回放…"," opening the replay…"))),console.log(chalk.gray(W(d))),await s(c,I(l,d,N))),{ok:Boolean(u.ok),ran:!0})}function T(e,t){const o=String(e.line??"");if(f()||!Array.isArray(t)||0===t.length)return o;const r=Number(e.turns??0),n=Array.isArray(e.mined)?e.mined:[],a=Number(n[0]??0),s=(4===n.length?n.slice(2):n.slice(1)).reduce((e,t)=>e+Number(t),0),l=0===Number(e.winner),i=String(e.reason??"");switch(t[0]){case"mined":{const e=Number(t[1]);return`Turn ${r} · you mined ${a} opal · opponent ${s} · ${a>=e?"✅ over the bar":"❌ under the bar"} (≥ ${e})`}case"destroy":return`Turn ${r} · ${l&&"warrens"===i?"✅ enemy Warren destroyed":`❌ Warren still standing (${i})`}`;case"mined_ratio":{const e=a/Math.max(1,s);return`Mined ${a} vs ${s} (${e.toFixed(2)}×) · ${e>=Number(t[1])?"✅":`❌ need ≥ ${Number(t[1])}×`}`}case"winrate":case"winrate_avg":return`Turn ${r} · ${l?"✅ won":"❌ lost"} (${i})`;default:return o}}export function saveJudgeReplay(e){try{const o=t(Buffer.from(e,"base64"));return!(o.length<16||o.length>4e6||!o.subarray(0,3).toString("latin1").startsWith("MAP")||(n(k,{recursive:!0}),l(N,o),0))}catch{return!1}}export async function playSavedReplay(){if(!r(N))return!1;const e=await A();if(!e)return!1;const t=h();if(!t.ok||!t.cmd)return!1;const o=C();return console.log(chalk.gray(W(o))),await g(t.cmd,I(e,o,N)),!0}export function mobReportLine(e){let t=/^第 (\d+) 回合 · 你采了 (\d+) Opal · 对手 (\d+) · (✅ 达标|❌ 未达标)\(≥ (\d+)\)$/.exec(e);return t?`Turn ${t[1]} · you mined ${t[2]} opal · opponent ${t[3]} · ${t[4].startsWith("✅")?"✅ over the bar":"❌ under the bar"} (≥ ${t[5]})`:(t=/^第 (\d+) 回合 · ✅ 拆掉了对方 Warren$/.exec(e),t?`Turn ${t[1]} · ✅ enemy Warren destroyed`:(t=/^第 (\d+) 回合 · ❌ 没拆掉\((\w+)\)$/.exec(e),t?`Turn ${t[1]} · ❌ Warren still standing (${t[2]})`:(t=/^采矿 (\d+) vs (\d+)\(([\d.]+) 倍\)· (?:✅|❌ 需要 ≥ ([\d.]+) 倍)$/.exec(e),t?`Mined ${t[1]} vs ${t[2]} (${t[3]}×) · ${t[4]?`❌ need ≥ ${t[4]}×`:"✅"}`:(t=/^第 (\d+) 回合 · (✅ 赢了|❌ 输了)\((\w+)\)$/.exec(e),t?`Turn ${t[1]} · ${t[2].startsWith("✅")?"✅ won":"❌ lost"} (${t[3]})`:e))))}function j(t,o,r,n=18e4){const a=e(t,[c(o,"runner.py"),...r],{encoding:"utf-8",timeout:n,env:{...process.env,PYTHONDONTWRITEBYTECODE:"1"}}),s=(a.stdout||"").trim().split("\n").pop()||"";try{return JSON.parse(s)}catch{return{error:"engine",message:(a.stderr||"").trim().split("\n").slice(-3).join(" ")||`exit ${a.status}`}}}function C(){try{const e=JSON.parse(a(x,"utf-8"));return{ac:Array.isArray(e.ac)?e.ac:[],attempts:e.attempts??{}}}catch{return{ac:[],attempts:{}}}}function B(e){n(k,{recursive:!0}),l(x,JSON.stringify(e,null,1))}const z={tiles:"tiles",tile:"tiles",big:"tiles",large:"tiles","大格":"tiles","大":"tiles",emoji:"emoji",emojis:"emoji","贴图":"emoji",blocks:"half",block:"half",color:"half",colour:"half",pixel:"half","色块":"half"};function I(e,t,o){const r=[c(e,"render.py"),o];return"half"===t.style?r.push("--blocks"):"emoji"===t.style&&r.push("--emoji"),f()||r.push("--en"),r}function W(e){const t="half"!==e.style?$("c 色块","c = blocks"):$("t 大格","t = tiles");return $(` 空格 暂停 · ←→ 单步 · ↑↓ 调速 · ${t} · q 退出`,` space = pause · ← → = step · ↑ ↓ = speed · ${t} · q = quit`)}function _(e,t,o=0){if(o){const t=e.find(e=>e.card===o);if(t)return t;const r=e.find(e=>e.card>o);if(r)return r}return e.find(e=>!t.ac.includes(e.card))??null}const q={idle:"🥉 idle",rush:"🥈 rush",kite:"🥇 kite"};function E(e){return{phase:Math.floor((e-1)/12)+1,slot:{4:1,8:2,12:3}[(e-1)%12+1]??1}}function L(e,t,o=0){const r=_(e,t,o);if(console.log(chalk.gray(r?$(" 当前检查点:"," Checkpoint: ")+r.desc:$(" 12/12 全部 AC —— 竞技场对你开放"," 12/12 AC — the arena is yours"))),r?.hint&&console.log(chalk.white(" ▸ "+r.hint)),console.log(chalk.bold.white($(" ▸ 自由练习场:read 看目标 · edit 改 bot · run 试跑 · replay 看回放。检查点在卡片上敲 contest N 判分。"," ▸ Free-play ground: read the goal · edit the bot · run · replay. Checkpoints are judged from the card: contest N."))),r){const e=E(r.card).slot;console.log(v!==w?chalk.gray(" ✍ ")+chalk.white($(`这里改的就是卡 ${r.card} 检查点的 sol-1.py —— 和 contest ${e} 判分的是同一份文件。`,`You are editing card ${r.card}'s checkpoint file, sol-1.py — the same file contest ${e} judges.`)):chalk.gray(" ✍ ")+chalk.white($(`现在改的是通用 bot.py。想在这一关的真文件上练:先到卡 ${r.card} 敲 contest ${e}(生成 sol-1.py),再回来 battle。`,`You are editing the generic bot.py. To practise on this level's real file: type contest ${e} on card ${r.card} first (it creates sol-1.py), then come back to battle.`)))}console.log(chalk.gray($(" 其它:syntax 查函数 · duel 兵种对撞(空场单挑) · replay N 看卡 N 的示范 · replay last 看你上一局 · bots 看对手 · status 进度 · refresh 更新引擎 · back 回卡片 · menu 首页"," also: syntax API · duel = unit-vs-unit on a flat field · replay N = card N demo · replay last = your last game · bots · status · refresh engine · back · menu home")))}function O(e,t,o=0){console.log(chalk.bold.white(" BattleAI Hackathon · battleai-48"));const r=_(e,t,o);for(const o of e){const e=t.ac.includes(o.card),n=t.attempts[String(o.card)]??[],a=!e&&n.length?chalk.gray($(` (试了 ${n.length} 次)`,` (${n.length} tries)`)):"",s=o===r?chalk.cyan($(" ← 当前"," ← now")):"";console.log(` ${e?"✅":"⬜"} ${chalk.white(o.desc)}${a}${s}`)}}function M(e){const t=e.line,o=e.text||"",r=e.hint||"";console.log(chalk.yellow($(" ✗ 语法不对"," ✗ Syntax error")+(t?$(`,第 ${t} 行:`,`, line ${t}:`):":"))),o&&console.log(chalk.yellow(` ${o}`));const n={colon:$("少了一个冒号?","Missing a colon?"),bracket:$("括号没配对?","A bracket never closed?"),indent:$("缩进不对?","Indentation off?")};console.log(chalk.gray(" "+(n[r]??r)+$(" ▸ edit 改完再来"," ▸ edit, then try again")))}export async function runBattle(e=[]){y(["battle",...e].join(" "));const t=Number((e.find(e=>e.startsWith("from-card:"))??"").slice(10))||0;e=e.filter(e=>!e.startsWith("from-card:"));let a=await A();if(!a)return console.log(chalk.yellow($(" 竞技场引擎还没到本机(需要联网拉一次)。"," The arena engine is not on this machine yet (one online fetch needed)."))),console.log(chalk.gray($(" 联网后再敲 battle;联不上找组织者。"," Try `battle` again when online; ask the organiser if it keeps failing."))),"back";const l=h();if(!l.ok||!l.cmd)return p(f(),{judgeIsServerSide:!0}),"back";const d=l.cmd;if(n(k,{recursive:!0}),!r(w)){const e=j(d,a,f()?["template","--lang","zh"]:["template"]);"string"==typeof e.path&&r(e.path)&&(o(e.path,w),console.log(chalk.gray($(` (已把模板 bot.py 放到 ${w})`,` (template bot.py placed at ${w})`))))}v=w;const u=j(d,a,f()?["checkpoints"]:["checkpoints","--lang","en"]);if(!Array.isArray(u))return console.log(chalk.yellow($(" 引擎起不来:"," The engine did not start: ")+String(u.message??""))),"back";const x=u,S=C(),Y=t?_(x,S,t):null,D=Y?function(e){const{phase:t,slot:o}=E(e),n=c(process.cwd(),"icoa-contest",`battleai-48-phase${t}-g${o}`,"sol-1.py");return r(n)?n:null}(Y.card):null;D&&(v=D),console.log(),console.log(chalk.bold.cyan($("⚔ BattleAI 竞技场","⚔ BattleAI arena"))+chalk.gray($(" — 自由练习场:改 bot、打陪练、看回放。判分在卡片上敲 contest N。 ↩ back 回上一层 · menu 回首页"," — free-play: edit your bot, fight the sparring bots, watch replays. Judging is contest N on the card. ↩ back · menu"))),L(x,S,t);const J=b(),R=J.ask;let P=0;try{for(;;){const e=await R(chalk.bold.cyan("icoa battle> "));if(null===e)return"back";if(!e.trim())continue;const{verb:o,args:n}=normalizeBattleVerb(e);switch("unknown"!==o&&(P=0),o){case"back":return"back";case"refresh":{const e=c(i(),".icoa","assets");for(const t of["battleai-engine","battleai-engine.tar.gz"])try{s(c(e,t),{recursive:!0,force:!0})}catch{}console.log(chalk.gray($(" 拉取最新引擎…"," Pulling the latest engine…")));const o=await A();o?(a=o,console.log(chalk.green($(" ✅ 引擎已刷新到最新(卡片内容每次进 learn 自动更新)。"," ✅ Engine refreshed to the latest (card content auto-updates on each learn entry).")))):console.log(chalk.red($(" ✗ 拉取失败(离线?),仍用当前引擎。"," ✗ Fetch failed (offline?); keeping the current engine."))),L(x,S,t);break}case"menu":return"menu";case"read":{const e=_(x,S,t);if(!e){console.log(chalk.gray($(" 12/12 全部 AC —— 没有待过的关。"," 12/12 AC — no checkpoint left."))),L(x,S,t);break}const o=S.ac.includes(e.card);console.log(chalk.bold.yellow($(` ⚔ 这一关 · 卡 ${e.card} · ${e.title}`,` ⚔ This checkpoint · card ${e.card} · ${e.title}`))+(o?chalk.green($(" ✅ 已过(可重做)"," ✅ passed (redo anytime)")):"")),console.log(chalk.gray(" "+e.desc)),e.hint&&console.log(chalk.white(" ▸ "+e.hint)),console.log(chalk.gray($(" (edit 改 bot → run 试跑;判分回卡片敲 contest N)"," (edit → run; to be judged, go back to the card and type contest N)")));break}case"help":L(x,S,t);break;case"status":O(x,S,t);break;case"bots":for(const[e,t]of Object.entries(q))console.log(" "+t+chalk.gray("idle"===e?$(" 只采矿,不造兵"," digs, never builds a soldier"):"rush"===e?$(" 全 Kangaroo 往前冲,不集火不拉扯"," all kangaroos, no focus, no kiting"):$(" 混编 + 编波 + 集火 + 拉扯"," mixed army, waves, focus fire, kiting")));break;case"syntax":{const e=j(d,a,f()?["cheatsheet","--lang","zh"]:["cheatsheet"]);console.log(chalk.gray(String(e.text??"")));break}case"edit":console.log(chalk.gray($(" vi 三键: i 进入编辑 · Esc 退出编辑 · :wq 存盘离开 · :q! 放弃"," vi survival: i = edit · Esc = stop editing · :wq = save and leave · :q! = discard"))),await g("vi",[...m,v]);break;case"replay":{const e=n.map(e=>e.toLowerCase()),o=e.find(e=>e in z);o&&(S.style=z[o],B(S));const s=new Set(["r10","full","match","整场","全场"]),l=new Set(["last","mine","me","上一局","我的","刚才"]),i=e.find(e=>/^\d+$/.test(e)),c=e.find(e=>!(e in z)&&!/^\d+$/.test(e));let u=null;if(c&&l.has(c))r(N)?u=N:console.log(chalk.gray($(" 你还没打过。先 play 一局。"," You have not played yet. `play` a game first.")));else{const e=i?Number(i):c&&s.has(c)?1:t,o=j(d,a,e?["demo","--card",String(e)]:["demo"]);u="string"==typeof o.path?o.path:null,u?"number"==typeof o.card?console.log(chalk.gray($(` ▶ replay ${o.card} · 卡 ${o.card} 的示范`,` ▶ replay ${o.card} · card ${o.card} demo`))):e&&console.log(chalk.gray($(` 卡 ${e} 还没有自己的示范,放整场。`,` Card ${e} has no demo of its own yet — playing the full match.`))):console.log(chalk.gray($(" 示范回放不在本机。"," The demo replay is not on this machine.")))}u&&(console.log(chalk.gray(W(S))),await g(d,I(a,S,u)));break}case"duel":{const e=n.filter(e=>/^[a-z]+(:\d+)?$/i.test(e)&&!/^\d+$/.test(e)),t=e[0]??"magpie:4",o=e[1]??"kangaroo:5";process.stdout.write(chalk.gray($(` ${t} 对 ${o} · 空场 10 局 … `,` ${t} vs ${o} · flat arena, 10 games … `)));const r=j(d,a,["duel","--bot",v,"--army",t,"--opp",o,"--seeds","10","--replay",N,"--lang",f()?"zh":"en"]);if(console.log(),"syntax"===r.error){M(r);break}if(r.error){console.log(chalk.yellow($(" bot.py 跑不起来:"," bot.py could not run: ")+String(r.message??"")));break}const s=Number(r.wins??0),l=Number(r.losses??0),i=Number(r.draws??0);console.log(chalk.bold.white($(` ${s} 胜 ${l} 负 ${i} 平`,` ${s}W ${l}L ${i}D`))+chalk.gray($(" (判胜 = 伤亡价值:损失少的赢)"," (winner = whoever lost less army value)")));for(const e of(r.rows??[]).slice(0,3))console.log(chalk.gray($(` 第 ${e.seed} 局 · ${e.turns} 回合 · 你损 ${e.mine_lost} 对手损 ${e.their_lost}`,` game ${e.seed} · ${e.turns} turns · you lost ${e.mine_lost}, they lost ${e.their_lost}`)));console.log(chalk.gray($(" ▸ "," ▸ "))+chalk.bold.green("replay last")+chalk.gray(r.replay?$(" 看你输掉的第一局"," watch the first game you lost"):$(" (这一轮没输过)"," (you did not lose one this round)"))),console.log(chalk.gray($(" ▸ 试试:duel magpie:4 taipan:2 · duel kangaroo:5 redback:2 —— 换一对再打一轮"," ▸ try: duel magpie:4 taipan:2 · duel kangaroo:5 redback:2 — swap the pair and run again")));break}case"play":{const e=_(x,S,t);if(!e){console.log(chalk.green($(" 12 个检查点全部 AC —— 你毕业了。"," All 12 checkpoints AC — you graduated.")));break}const o=n.find(e=>["ballarat","murray","nullarbor"].includes(e.toLowerCase())),s=o?o.toLowerCase():"all"===e.map?"ballarat":e.map,l=S.attempts[String(e.card)]??[];process.stdout.write(chalk.gray($(` 对 ${q[e.opp]??e.opp} @${s} … `,` vs ${q[e.opp]??e.opp} @${s} … `)));const i=j(d,a,["play","--bot",v,"--card",String(e.card),"--map",s,"--seed",String(l.length),"--replay",N,"--lang",f()?"zh":"en"]);if(console.log(),"syntax"===i.error){M(i);break}if(i.error){console.log(chalk.yellow($(" bot.py 跑不起来:"," bot.py could not run: ")+String(i.message??""))),console.log(chalk.gray($(" ▸ edit 改一改再 play。第一行报错通常就是原因。"," ▸ edit, then play again. The first error line is usually the reason.")));break}console.log(" "+chalk.white(T(i,e.crit))),Number(i.errors)>0&&console.log(chalk.yellow($(` ⚠ 你的 bot 有 ${i.errors} 次异常(那些回合单位在发呆):`,` ⚠ your bot raised ${i.errors} times (those units idled): `)+String(i.last_error??""))),l.push(Boolean(i.ok)),S.attempts[String(e.card)]=l,B(S),i.ok||!e.hint||2!==l.length&&l.length%3!=0||console.log(chalk.gray($(" 排查:"," Check: ")+e.hint)),console.log(chalk.gray(i.ok?$(" ▸ submit 提交检查点 ▸ replay 再看一遍 ▸ edit 继续改"," ▸ submit ▸ replay to watch again ▸ edit to keep improving"):$(" ▸ replay 看看发生了什么 ▸ edit 改一改再 play"," ▸ replay to see what happened ▸ edit, then play"))),!n.includes("--noreplay")&&process.stdout.isTTY&&r(N)&&(console.log(chalk.gray($(" 正在打开回放…"," opening the replay…"))),console.log(chalk.gray(W(S))),await g(d,I(a,S,N)));break}case"submit":{const e=_(x,S,t);if(!e){console.log(chalk.green($(" 全部 AC。"," All AC.")));break}const o=j(d,a,["syntax","--bot",v]);if(!1===o.ok){M(o);break}if(!n.includes("--local")){console.log(chalk.yellow($(` 检查点在课程赛场里判分:back 回卡片 → contest ${E(e.card).slot} → submit 1(每关有自己的 sol-1.py)。`,` Checkpoints are judged in the lesson arena: back → contest ${E(e.card).slot} → submit 1 (each level has its own sol-1.py).`))),console.log(chalk.gray($(" 这里的 submit --local 只用本机判一遍 bot.py,不计分。"," submit --local here judges bot.py on this machine only — unscored.")));break}console.log(chalk.gray($(" ⚖ 判分中("," ⚖ judging (")+e.desc+$(")…",")…")));const r=j(d,a,["submit","--bot",v,"--card",String(e.card),"--replay",N,"--lang",f()?"zh":"en"]);if(r.error){"syntax"===r.error?M(r):console.log(chalk.yellow($(" bot.py 跑不起来:"," bot.py could not run: ")+String(r.message??"")));break}const s=r.lines??[];for(const e of s.slice(0,3))console.log(chalk.gray(" "+e.line));if(s.length>3&&console.log(chalk.gray($(` … 共 ${r.total} 局,达标 ${r.wins}`,` … ${r.total} games, ${r.wins} passed`))),r.passed){S.ac.push(e.card),B(S);const o=S.ac.length;console.log(chalk.green(` ✅ AC · ${o}/12`+(1===o?$(" 🎉 第一个检查点!"," 🎉 first checkpoint!"):"")));const r=_(x,S,t);console.log(chalk.green(r?$(` ▸ back 回卡片,读第 ${e.card+1} 张 —— 下一个检查点在卡 ${r.card}`,` ▸ back to the cards, read card ${e.card+1} — next checkpoint is card ${r.card}`):$(" 🎓 12/12 —— 你有一个能上赛场的 bot 了。"," 🎓 12/12 — you have a bot that can enter the arena.")))}else console.log(chalk.yellow($(` ❌ 未通过(${r.wins}/${r.total})。`,` ❌ not yet (${r.wins}/${r.total}).`))+chalk.gray($(" ▸ replay last 看你输的那局 ▸ edit 改代码"," ▸ replay last — watch the game you lost ▸ edit")));break}default:if(P+=1,console.log(chalk.yellow($(` 不认识「${e.trim()}」。`,` Don't know "${e.trim()}".`))+chalk.gray($(" 可用:edit · syntax · play · duel · replay N · replay last · submit · status · back"," Try: edit · syntax · play · duel · replay N · replay last · submit · status · back"))),P>=3)return console.log(chalk.gray($(" 连续三次没对上 —— 回上一层。"," Three misses — going back one level."))),"back"}}}finally{J.close()}}export function registerBattleCommand(e){e.command("battle [args...]").description("BattleAI Hackathon arena — edit your bot, fight sparring bots, watch replays, submit checkpoints").action(async e=>{await runBattle(e??[])})}
1
+ import{spawnSync as e}from"node:child_process";import{gunzipSync as t}from"node:zlib";import{copyFileSync as o,existsSync as r,mkdirSync as n,readFileSync as a,rmSync as s,writeFileSync as l}from"node:fs";import{homedir as i}from"node:os";import{join as c}from"node:path";import chalk from"chalk";import{getConfig as d}from"../lib/config.js";import{runInteractive as g}from"../lib/interactive-spawn.js";import{lazyTarball as u}from"../lib/lazy-assets.js";import{logCommand as y}from"../lib/logger.js";import{printNoPython312 as p,probePython as h}from"../lib/python-setup.js";import{makeReplAsker as b}from"../lib/repl-asker.js";import{ARENA_VI_FLAGS as m}from"../lib/vi-flags.js";const f=()=>(d().language||"en").toLowerCase().startsWith("zh"),$=(e,t)=>f()?e:t,k=c(i(),".icoa","battleai"),w=c(k,"bot.py");let v=w;const x=c(k,"state.json"),N=c(k,"last.mobreplay"),S={edit:"edit",e:"edit",vi:"edit",code:"edit",syntax:"syntax",api:"syntax",doc:"syntax",docs:"syntax",play:"play",p:"play",run:"play",read:"read",readme:"read",goal:"read","题":"read","目标":"read","读":"read",fight:"play",duel:"duel",d:"duel","对撞":"duel","单挑":"duel",replay:"replay",r:"replay",watch:"replay",show:"replay",submit:"submit",s:"submit",judge:"submit",ac:"submit",status:"status",st:"status",progress:"status",bots:"bots",ladder:"bots",opponents:"bots",help:"help","?":"help",h:"help",back:"back",quit:"back",q:"back",exit:"back",menu:"menu",refresh:"refresh",reload:"refresh",update:"refresh","刷新":"refresh","更新":"refresh"};export function normalizeBattleVerb(e){const t=e.trim().replace(/^\//,"").split(/\s+/).filter(Boolean);return 0===t.length?{verb:"unknown",args:[]}:{verb:S[t[0].toLowerCase()]??"unknown",args:t.slice(1)}}async function T(){const e=process.env.ICOA_BATTLEAI_ENGINE_DIR;if(e&&r(c(e,"runner.py")))return e;const t=await u("battleai-engine.tar.gz","battleai-engine",15e3,{revalidate:!0});return t&&r(c(t,"runner.py"))?t:null}export async function runMobLocal(e,t,o=0,a,s=g){const l=await T();if(!l)return console.log(chalk.yellow($(" 竞技场引擎还没到这台机器(需要联网拉一次)。"," The arena engine is not on this machine yet (one online fetch needed)."))),{ok:!1,ran:!1};const i=h();if(!i.ok||!i.cmd)return p(f(),{judgeIsServerSide:!0}),{ok:!1,ran:!1};const c=i.cmd,d=C();n(k,{recursive:!0});const u=j(c,l,["play","--bot",e,"--card",String(t),"--seed",String(o),"--replay",N,"--lang",f()?"zh":"en"]);return"syntax"===u.error?(M(u),{ok:!1,ran:!0}):u.error?(console.log(chalk.yellow($(" bot 跑不起来:"," bot could not run: ")+String(u.message??""))),console.log(chalk.gray($(" ▸ edit 改一改再 run。第一行报错通常就是原因。"," ▸ edit, then run again. The first error line is usually why."))),{ok:!1,ran:!0}):(console.log(" "+chalk.white(A(u,a))),Number(u.errors)>0&&console.log(chalk.yellow($(` ⚠ 你的 bot 有 ${u.errors} 次异常(那些回合单位在发呆)。`,` ⚠ your bot raised ${u.errors} times (those units idled).`))),process.stdout.isTTY&&r(N)&&(console.log(chalk.gray($(" 正在打开回放…"," opening the replay…"))),console.log(chalk.gray(I(d))),await s(c,z(l,d,N))),{ok:Boolean(u.ok),ran:!0})}function A(e,t){const o=String(e.line??"");if(f()||!Array.isArray(t)||0===t.length)return o;const r=Number(e.turns??0),n=Array.isArray(e.mined)?e.mined:[],a=Number(n[0]??0),s=(4===n.length?n.slice(2):n.slice(1)).reduce((e,t)=>e+Number(t),0),l=0===Number(e.winner),i=String(e.reason??"");switch(t[0]){case"mined":{const e=Number(t[1]);return`Turn ${r} · you mined ${a} opal · opponent ${s} · ${a>=e?"✅ over the bar":"❌ under the bar"} (≥ ${e})`}case"destroy":return`Turn ${r} · ${l&&"warrens"===i?"✅ enemy Warren destroyed":`❌ Warren still standing (${i})`}`;case"mined_ratio":{const e=a/Math.max(1,s);return`Mined ${a} vs ${s} (${e.toFixed(2)}×) · ${e>=Number(t[1])?"✅":`❌ need ≥ ${Number(t[1])}×`}`}case"winrate":case"winrate_avg":return`Turn ${r} · ${l?"✅ won":"❌ lost"} (${i})`;default:return o}}export function saveJudgeReplay(e){try{const o=t(Buffer.from(e,"base64"));return!(o.length<16||o.length>4e6||!o.subarray(0,3).toString("latin1").startsWith("MAP")||(n(k,{recursive:!0}),l(N,o),0))}catch{return!1}}export async function playSavedReplay(){if(!r(N))return!1;const e=await T();if(!e)return!1;const t=h();if(!t.ok||!t.cmd)return!1;const o=C();return console.log(chalk.gray(I(o))),await g(t.cmd,z(e,o,N)),!0}export function mobReportLine(e){let t=/^第 (\d+) 回合 · 你采了 (\d+) Opal · 对手 (\d+) · (✅ 达标|❌ 未达标)\(≥ (\d+)\)$/.exec(e);return t?`Turn ${t[1]} · you mined ${t[2]} opal · opponent ${t[3]} · ${t[4].startsWith("✅")?"✅ over the bar":"❌ under the bar"} (≥ ${t[5]})`:(t=/^第 (\d+) 回合 · ✅ 拆掉了对方 Warren$/.exec(e),t?`Turn ${t[1]} · ✅ enemy Warren destroyed`:(t=/^第 (\d+) 回合 · ❌ 没拆掉\((\w+)\)$/.exec(e),t?`Turn ${t[1]} · ❌ Warren still standing (${t[2]})`:(t=/^采矿 (\d+) vs (\d+)\(([\d.]+) 倍\)· (?:✅|❌ 需要 ≥ ([\d.]+) 倍)$/.exec(e),t?`Mined ${t[1]} vs ${t[2]} (${t[3]}×) · ${t[4]?`❌ need ≥ ${t[4]}×`:"✅"}`:(t=/^第 (\d+) 回合 · (✅ 赢了|❌ 输了)\((\w+)\)$/.exec(e),t?`Turn ${t[1]} · ${t[2].startsWith("✅")?"✅ won":"❌ lost"} (${t[3]})`:(t=/^第 (\d+) 回合 · 造了 (\d+) 只 (\w+) · 采矿 (\d+) · (✅ 达标|❌ 未达标)\(≥ (\d+)\)$/.exec(e),t?`Turn ${t[1]} · built ${t[2]} ${t[3]} · mined ${t[4]} · ${t[5].startsWith("✅")?"✅":"❌"} (≥ ${t[6]})`:(t=/^第 (\d+) 回合 · (赢|输) · (\w+) (\d+) · 存活 (\d+) · 阵亡 (\d+) · (✅ 达标|❌ 未达标)\((\w+) ≥ (\d+)\)$/.exec(e),t?`Turn ${t[1]} · ${"赢"===t[2]?"✅ won":"❌ lost"} · ${t[3]} ${t[4]} · alive ${t[5]} · lost ${t[6]} · ${t[7].startsWith("✅")?"✅":"❌"} (${t[8]} ≥ ${t[9]})`:e))))))}function j(t,o,r,n=18e4){const a=e(t,[c(o,"runner.py"),...r],{encoding:"utf-8",timeout:n,env:{...process.env,PYTHONDONTWRITEBYTECODE:"1"}}),s=String(a.stdout??"").trim().split("\n").pop()||"";try{return JSON.parse(s)}catch{return{error:"engine",message:String(a.stderr??"").trim().split("\n").slice(-3).join(" ")||`exit ${a.status}`}}}function C(){try{const e=JSON.parse(a(x,"utf-8"));return{ac:Array.isArray(e.ac)?e.ac:[],attempts:e.attempts??{}}}catch{return{ac:[],attempts:{}}}}function B(e){n(k,{recursive:!0}),l(x,JSON.stringify(e,null,1))}const W={tiles:"tiles",tile:"tiles",big:"tiles",large:"tiles","大格":"tiles","大":"tiles",emoji:"emoji",emojis:"emoji","贴图":"emoji",blocks:"half",block:"half",color:"half",colour:"half",pixel:"half","色块":"half"};function z(e,t,o){const r=[c(e,"render.py"),o];return"half"===t.style?r.push("--blocks"):"emoji"===t.style&&r.push("--emoji"),f()||r.push("--en"),r}function I(e){const t="half"!==e.style?$("c 色块","c = blocks"):$("t 大格","t = tiles");return $(` 空格 暂停 · ←→ 单步 · ↑↓ 调速 · ${t} · q 退出`,` space = pause · ← → = step · ↑ ↓ = speed · ${t} · q = quit`)}function _(e,t,o=0){if(o){const t=e.find(e=>e.card===o);if(t)return t;const r=e.find(e=>e.card>o);if(r)return r}return e.find(e=>!t.ac.includes(e.card))??null}const q={idle:"🥉 idle",rush:"🥈 rush",kite:"🥇 kite"};function E(e){return{phase:Math.floor((e-1)/12)+1,slot:{4:1,8:2,12:3}[(e-1)%12+1]??1}}function L(e,t,o=0){const r=_(e,t,o);if(console.log(chalk.gray(r?$(" 当前检查点:"," Checkpoint: ")+r.desc:$(" 12/12 全部 AC —— 竞技场对你开放"," 12/12 AC — the arena is yours"))),r?.hint&&console.log(chalk.white(" ▸ "+r.hint)),console.log(chalk.bold.white($(" ▸ 自由练习场:read 看目标 · edit 改 bot · run 试跑 · replay 看回放。检查点在卡片上敲 contest N 判分。"," ▸ Free-play ground: read the goal · edit the bot · run · replay. Checkpoints are judged from the card: contest N."))),r){const e=E(r.card).slot;console.log(v!==w?chalk.gray(" ✍ ")+chalk.white($(`这里改的就是卡 ${r.card} 检查点的 sol-1.py —— 和 contest ${e} 判分的是同一份文件。`,`You are editing card ${r.card}'s checkpoint file, sol-1.py — the same file contest ${e} judges.`)):chalk.gray(" ✍ ")+chalk.white($(`现在改的是通用 bot.py。想在这一关的真文件上练:先到卡 ${r.card} 敲 contest ${e}(生成 sol-1.py),再回来 battle。`,`You are editing the generic bot.py. To practise on this level's real file: type contest ${e} on card ${r.card} first (it creates sol-1.py), then come back to battle.`)))}console.log(chalk.gray($(" 其它:syntax 查函数 · duel 兵种对撞(空场单挑) · replay N 看卡 N 的示范 · replay last 看你上一局 · bots 看对手 · status 进度 · refresh 更新引擎 · back 回卡片 · menu 首页"," also: syntax API · duel = unit-vs-unit on a flat field · replay N = card N demo · replay last = your last game · bots · status · refresh engine · back · menu home")))}function O(e,t,o=0){console.log(chalk.bold.white(" BattleAI Hackathon · battleai-48"));const r=_(e,t,o);for(const o of e){const e=t.ac.includes(o.card),n=t.attempts[String(o.card)]??[],a=!e&&n.length?chalk.gray($(` (试了 ${n.length} 次)`,` (${n.length} tries)`)):"",s=o===r?chalk.cyan($(" ← 当前"," ← now")):"";console.log(` ${e?"✅":"⬜"} ${chalk.white(o.desc)}${a}${s}`)}}function M(e){const t=e.line,o=e.text||"",r=e.hint||"";console.log(chalk.yellow($(" ✗ 语法不对"," ✗ Syntax error")+(t?$(`,第 ${t} 行:`,`, line ${t}:`):":"))),o&&console.log(chalk.yellow(` ${o}`));const n={colon:$("少了一个冒号?","Missing a colon?"),bracket:$("括号没配对?","A bracket never closed?"),indent:$("缩进不对?","Indentation off?")};console.log(chalk.gray(" "+(n[r]??r)+$(" ▸ edit 改完再来"," ▸ edit, then try again")))}export async function runBattle(e=[]){y(["battle",...e].join(" "));const t=Number((e.find(e=>e.startsWith("from-card:"))??"").slice(10))||0;e=e.filter(e=>!e.startsWith("from-card:"));let a=await T();if(!a)return console.log(chalk.yellow($(" 竞技场引擎还没到本机(需要联网拉一次)。"," The arena engine is not on this machine yet (one online fetch needed)."))),console.log(chalk.gray($(" 联网后再敲 battle;联不上找组织者。"," Try `battle` again when online; ask the organiser if it keeps failing."))),"back";const l=h();if(!l.ok||!l.cmd)return p(f(),{judgeIsServerSide:!0}),"back";const d=l.cmd;if(n(k,{recursive:!0}),!r(w)){const e=j(d,a,f()?["template","--lang","zh"]:["template"]);"string"==typeof e.path&&r(e.path)&&(o(e.path,w),console.log(chalk.gray($(` (已把模板 bot.py 放到 ${w})`,` (template bot.py placed at ${w})`))))}v=w;const u=j(d,a,f()?["checkpoints"]:["checkpoints","--lang","en"]);if(!Array.isArray(u))return console.log(chalk.yellow($(" 引擎起不来:"," The engine did not start: ")+String(u.message??""))),"back";const x=u,S=C(),Y=t?_(x,S,t):null,D=Y?function(e){const{phase:t,slot:o}=E(e),n=c(process.cwd(),"icoa-contest",`battleai-48-phase${t}-g${o}`,"sol-1.py");return r(n)?n:null}(Y.card):null;D&&(v=D),console.log(),console.log(chalk.bold.cyan($("⚔ BattleAI 竞技场","⚔ BattleAI arena"))+chalk.gray($(" — 自由练习场:改 bot、打陪练、看回放。判分在卡片上敲 contest N。 ↩ back 回上一层 · menu 回首页"," — free-play: edit your bot, fight the sparring bots, watch replays. Judging is contest N on the card. ↩ back · menu"))),L(x,S,t);const J=b(),R=J.ask;let P=0;try{for(;;){const e=await R(chalk.bold.cyan("icoa battle> "));if(null===e)return"back";if(!e.trim())continue;const{verb:o,args:n}=normalizeBattleVerb(e);switch("unknown"!==o&&(P=0),o){case"back":return"back";case"refresh":{const e=c(i(),".icoa","assets");for(const t of["battleai-engine","battleai-engine.tar.gz"])try{s(c(e,t),{recursive:!0,force:!0})}catch{}console.log(chalk.gray($(" 拉取最新引擎…"," Pulling the latest engine…")));const o=await T();o?(a=o,console.log(chalk.green($(" ✅ 引擎已刷新到最新(卡片内容每次进 learn 自动更新)。"," ✅ Engine refreshed to the latest (card content auto-updates on each learn entry).")))):console.log(chalk.red($(" ✗ 拉取失败(离线?),仍用当前引擎。"," ✗ Fetch failed (offline?); keeping the current engine."))),L(x,S,t);break}case"menu":return"menu";case"read":{const e=_(x,S,t);if(!e){console.log(chalk.gray($(" 12/12 全部 AC —— 没有待过的关。"," 12/12 AC — no checkpoint left."))),L(x,S,t);break}const o=S.ac.includes(e.card);console.log(chalk.bold.yellow($(` ⚔ 这一关 · 卡 ${e.card} · ${e.title}`,` ⚔ This checkpoint · card ${e.card} · ${e.title}`))+(o?chalk.green($(" ✅ 已过(可重做)"," ✅ passed (redo anytime)")):"")),console.log(chalk.gray(" "+e.desc)),e.hint&&console.log(chalk.white(" ▸ "+e.hint)),console.log(chalk.gray($(" (edit 改 bot → run 试跑;判分回卡片敲 contest N)"," (edit → run; to be judged, go back to the card and type contest N)")));break}case"help":L(x,S,t);break;case"status":O(x,S,t);break;case"bots":for(const[e,t]of Object.entries(q))console.log(" "+t+chalk.gray("idle"===e?$(" 只采矿,不造兵"," digs, never builds a soldier"):"rush"===e?$(" 全 Kangaroo 往前冲,不集火不拉扯"," all kangaroos, no focus, no kiting"):$(" 混编 + 编波 + 集火 + 拉扯"," mixed army, waves, focus fire, kiting")));break;case"syntax":{const e=j(d,a,f()?["cheatsheet","--lang","zh"]:["cheatsheet"]);console.log(chalk.gray(String(e.text??"")));break}case"edit":console.log(chalk.gray($(" vi 三键: i 进入编辑 · Esc 退出编辑 · :wq 存盘离开 · :q! 放弃"," vi survival: i = edit · Esc = stop editing · :wq = save and leave · :q! = discard"))),await g("vi",[...m,v]);break;case"replay":{const e=n.map(e=>e.toLowerCase()),o=e.find(e=>e in W);o&&(S.style=W[o],B(S));const s=new Set(["r10","full","match","整场","全场"]),l=new Set(["last","mine","me","上一局","我的","刚才"]),i=e.find(e=>/^\d+$/.test(e)),c=e.find(e=>!(e in W)&&!/^\d+$/.test(e));let u=null;if(c&&l.has(c))r(N)?u=N:console.log(chalk.gray($(" 你还没打过。先 play 一局。"," You have not played yet. `play` a game first.")));else{const e=i?Number(i):c&&s.has(c)?1:t,o=j(d,a,e?["demo","--card",String(e)]:["demo"]);u="string"==typeof o.path?o.path:null,u?"number"==typeof o.card?console.log(chalk.gray($(` ▶ replay ${o.card} · 卡 ${o.card} 的示范`,` ▶ replay ${o.card} · card ${o.card} demo`))):e&&console.log(chalk.gray($(` 卡 ${e} 还没有自己的示范,放整场。`,` Card ${e} has no demo of its own yet — playing the full match.`))):console.log(chalk.gray($(" 示范回放不在本机。"," The demo replay is not on this machine.")))}u&&(console.log(chalk.gray(I(S))),await g(d,z(a,S,u)));break}case"duel":{const e=n.filter(e=>/^[a-z]+(:\d+)?$/i.test(e)&&!/^\d+$/.test(e)),t=e[0]??"magpie:4",o=e[1]??"kangaroo:5";process.stdout.write(chalk.gray($(` ${t} 对 ${o} · 空场 10 局 … `,` ${t} vs ${o} · flat arena, 10 games … `)));const r=j(d,a,["duel","--bot",v,"--army",t,"--opp",o,"--seeds","10","--replay",N,"--lang",f()?"zh":"en"]);if(console.log(),"syntax"===r.error){M(r);break}if(r.error){console.log(chalk.yellow($(" bot.py 跑不起来:"," bot.py could not run: ")+String(r.message??"")));break}const s=Number(r.wins??0),l=Number(r.losses??0),i=Number(r.draws??0);console.log(chalk.bold.white($(` ${s} 胜 ${l} 负 ${i} 平`,` ${s}W ${l}L ${i}D`))+chalk.gray($(" (判胜 = 伤亡价值:损失少的赢)"," (winner = whoever lost less army value)")));for(const e of(r.rows??[]).slice(0,3))console.log(chalk.gray($(` 第 ${e.seed} 局 · ${e.turns} 回合 · 你损 ${e.mine_lost} 对手损 ${e.their_lost}`,` game ${e.seed} · ${e.turns} turns · you lost ${e.mine_lost}, they lost ${e.their_lost}`)));console.log(chalk.gray($(" ▸ "," ▸ "))+chalk.bold.green("replay last")+chalk.gray(r.replay?$(" 看你输掉的第一局"," watch the first game you lost"):$(" (这一轮没输过)"," (you did not lose one this round)"))),console.log(chalk.gray($(" ▸ 试试:duel magpie:4 taipan:2 · duel kangaroo:5 redback:2 —— 换一对再打一轮"," ▸ try: duel magpie:4 taipan:2 · duel kangaroo:5 redback:2 — swap the pair and run again")));break}case"play":{const e=_(x,S,t);if(!e){console.log(chalk.green($(" 12 个检查点全部 AC —— 你毕业了。"," All 12 checkpoints AC — you graduated.")));break}const o=n.find(e=>["ballarat","murray","nullarbor"].includes(e.toLowerCase())),s=o?o.toLowerCase():"all"===e.map?"ballarat":e.map,l=S.attempts[String(e.card)]??[];process.stdout.write(chalk.gray($(` 对 ${q[e.opp]??e.opp} @${s} … `,` vs ${q[e.opp]??e.opp} @${s} … `)));const i=j(d,a,["play","--bot",v,"--card",String(e.card),"--map",s,"--seed",String(l.length),"--replay",N,"--lang",f()?"zh":"en"]);if(console.log(),"syntax"===i.error){M(i);break}if(i.error){console.log(chalk.yellow($(" bot.py 跑不起来:"," bot.py could not run: ")+String(i.message??""))),console.log(chalk.gray($(" ▸ edit 改一改再 play。第一行报错通常就是原因。"," ▸ edit, then play again. The first error line is usually the reason.")));break}console.log(" "+chalk.white(A(i,e.crit))),Number(i.errors)>0&&console.log(chalk.yellow($(` ⚠ 你的 bot 有 ${i.errors} 次异常(那些回合单位在发呆):`,` ⚠ your bot raised ${i.errors} times (those units idled): `)+String(i.last_error??""))),l.push(Boolean(i.ok)),S.attempts[String(e.card)]=l,B(S),i.ok||!e.hint||2!==l.length&&l.length%3!=0||console.log(chalk.gray($(" 排查:"," Check: ")+e.hint)),console.log(chalk.gray(i.ok?$(" ▸ submit 提交检查点 ▸ replay 再看一遍 ▸ edit 继续改"," ▸ submit ▸ replay to watch again ▸ edit to keep improving"):$(" ▸ replay 看看发生了什么 ▸ edit 改一改再 play"," ▸ replay to see what happened ▸ edit, then play"))),!n.includes("--noreplay")&&process.stdout.isTTY&&r(N)&&(console.log(chalk.gray($(" 正在打开回放…"," opening the replay…"))),console.log(chalk.gray(I(S))),await g(d,z(a,S,N)));break}case"submit":{const e=_(x,S,t);if(!e){console.log(chalk.green($(" 全部 AC。"," All AC.")));break}const o=j(d,a,["syntax","--bot",v]);if(!1===o.ok){M(o);break}if(!n.includes("--local")){console.log(chalk.yellow($(` 检查点在课程赛场里判分:back 回卡片 → contest ${E(e.card).slot} → submit 1(每关有自己的 sol-1.py)。`,` Checkpoints are judged in the lesson arena: back → contest ${E(e.card).slot} → submit 1 (each level has its own sol-1.py).`))),console.log(chalk.gray($(" 这里的 submit --local 只用本机判一遍 bot.py,不计分。"," submit --local here judges bot.py on this machine only — unscored.")));break}console.log(chalk.gray($(" ⚖ 判分中("," ⚖ judging (")+e.desc+$(")…",")…")));const r=j(d,a,["submit","--bot",v,"--card",String(e.card),"--replay",N,"--lang",f()?"zh":"en"]);if(r.error){"syntax"===r.error?M(r):console.log(chalk.yellow($(" bot.py 跑不起来:"," bot.py could not run: ")+String(r.message??"")));break}const s=r.lines??[];for(const e of s.slice(0,3))console.log(chalk.gray(" "+e.line));if(s.length>3&&console.log(chalk.gray($(` … 共 ${r.total} 局,达标 ${r.wins}`,` … ${r.total} games, ${r.wins} passed`))),r.passed){S.ac.push(e.card),B(S);const o=S.ac.length;console.log(chalk.green(` ✅ AC · ${o}/12`+(1===o?$(" 🎉 第一个检查点!"," 🎉 first checkpoint!"):"")));const r=_(x,S,t);console.log(chalk.green(r?$(` ▸ back 回卡片,读第 ${e.card+1} 张 —— 下一个检查点在卡 ${r.card}`,` ▸ back to the cards, read card ${e.card+1} — next checkpoint is card ${r.card}`):$(" 🎓 12/12 —— 你有一个能上赛场的 bot 了。"," 🎓 12/12 — you have a bot that can enter the arena.")))}else console.log(chalk.yellow($(` ❌ 未通过(${r.wins}/${r.total})。`,` ❌ not yet (${r.wins}/${r.total}).`))+chalk.gray($(" ▸ replay last 看你输的那局 ▸ edit 改代码"," ▸ replay last — watch the game you lost ▸ edit")));break}default:if(P+=1,console.log(chalk.yellow($(` 不认识「${e.trim()}」。`,` Don't know "${e.trim()}".`))+chalk.gray($(" 可用:edit · syntax · play · duel · replay N · replay last · submit · status · back"," Try: edit · syntax · play · duel · replay N · replay last · submit · status · back"))),P>=3)return console.log(chalk.gray($(" 连续三次没对上 —— 回上一层。"," Three misses — going back one level."))),"back"}}}finally{J.close()}}export function registerBattleCommand(e){e.command("battle [args...]").description("BattleAI Hackathon arena — edit your bot, fight sparring bots, watch replays, submit checkpoints").action(async e=>{await runBattle(e??[])})}