icoa-cli 2.19.255 → 2.19.257

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
- import chalk from"chalk";import{createInterface as e}from"node:readline";import{spawn as o}from"node:child_process";import{getMainRl as r}from"../lib/main-rl.js";import{existsSync as n}from"node:fs";import{dirname as l,join as t}from"node:path";import{fileURLToPath as a}from"node:url";import{loadCurriculumById as c,validateEAToken as s,syncProgress as i,syncCardFeedback as u}from"../lib/learn-curricula.js";import{getConfig as d,saveConfig as g}from"../lib/config.js";import{loadLearnState as m,saveLearnState as y,newLearnState as f,updateStreak as p,markCardComplete as h,recordMCQ as b,recordCheck as w,markPracticalComplete as k,addAchievement as C}from"../lib/learn-state.js";import{renderWelcome as v,renderKnowledgeCard as A,renderMCQCard as E,renderMCQFeedback as _,renderPracticalCard as I,renderPracticalSuccess as D,renderSimDemoCard as $,renderMilestone as O,renderStatus as S,renderPhaseComplete as M,renderCurriculumComplete as P}from"../lib/learn-render.js";import{printError as L}from"../lib/ui.js";export function registerLearnCommand(T){T.command("learn [token]").description("Enter learn mode (free demo, or team-issued EA/EI/AC/CA/IO/IA token for full curriculum)").action(async T=>{T&&T.trim()||(console.log(),console.log(chalk.gray(" No token given — starting free 11-card demo (")+chalk.bold.green("LEARNDEMO01")+chalk.gray(").")),console.log(chalk.gray(" Full curriculum: ")+chalk.bold.yellow("learn EA|EI|AC|CA|IO|IA + 8 chars")+chalk.gray(" — token from your country team leader.")),console.log(),T="LEARNDEMO01");const j=T.trim().toUpperCase();let x=null;const N=/^(LEARNDEMO01|AI4CTFDEMO01|CTF4AIDEMO01)$/i.test(j),q=/^[A-Z]{2}[A-Z0-9]{8}$/i.test(j);if(N)console.log(),console.log(chalk.gray(" Loading demo curriculum...")),x=await c(j);else if(q){const e=d().ctfdUrl||"https://practice.icoa2026.au";console.log(),console.log(chalk.gray(" Validating token..."));const o=await s(j,e);if(!o.ok)return L(`Token validation failed: ${o.message}`),console.log(),console.log(chalk.gray(" Possible causes:")),console.log(chalk.gray(" · Token expired or revoked")),console.log(chalk.gray(" · Network down (check connection)")),console.log(chalk.gray(" · Typo in token")),void console.log();if(console.log(chalk.green(` ✓ Token valid · curriculum: ${o.curriculumId} · status: ${o.status}`)),x=await c(o.curriculumId||"LEARNDEMO01"),!x)return L(`Could not open a learn curriculum for token '${j}'.`),console.log(),console.log(chalk.gray(" If this is an ")+chalk.bold.yellow("EXAM token")+chalk.gray(", start it with ")+chalk.bold.green(`exam ${j}`)+chalk.gray(" instead.")),console.log(chalk.gray(" Otherwise: the full curriculum is ~3 MB; on a slow link the download")),console.log(chalk.gray(" can take a while — stay on a stable connection and run ")+chalk.bold.yellow(`learn ${j}`)+chalk.gray(" again")),console.log(chalk.gray(" (it caches after the first load). If it keeps failing, check ")+chalk.cyan(e)+chalk.gray(" is reachable.")),void console.log()}if(!x)return L(`Unknown learn token: ${j}`),console.log(),console.log(chalk.gray(" Available tokens:")),console.log(chalk.gray(" ")+chalk.bold.green("LEARNDEMO01")+chalk.gray(" free 11-card demo (anyone can use)")),console.log(chalk.gray(" ")+chalk.bold.yellow("EA|EI|AC|CA|IO|IA")+chalk.gray(" + 8 chars full curriculum (issued by team leader)")),console.log(),console.log(chalk.gray(" Tracks: ")+chalk.cyan("EA")+chalk.gray("=ctf4eai · ")+chalk.cyan("AC")+chalk.gray("=ai4ctf · ")+chalk.cyan("CA")+chalk.gray("=ctf4ai · ")+chalk.cyan("IO")+chalk.gray("=ioai · ")+chalk.cyan("IA")+chalk.gray("=iaio")),console.log(),console.log(chalk.gray(" To get a full curriculum, email ")),console.log(chalk.gray(" ")+chalk.cyan("australia@icoa2026.au")+chalk.gray(" or ask your country's team leader.")),void console.log();let F=m(),R=!1;try{F&&F.token===j?p(F):(F=f(j,x.id,x.totalCards),R=!0),y(F),v(x,F,R)}catch{return L("Could not open this curriculum — it may be malformed or not a learn curriculum."),console.log(chalk.gray(" If this is an ")+chalk.bold.yellow("EXAM token")+chalk.gray(", start it with ")+chalk.bold.green(`exam ${j}`)+chalk.gray(".")),void console.log()}const U=r(),z=null!==U,B=z?U.listeners("line").slice():[];z&&U.removeAllListeners("line");const J=z?U:e({input:process.stdin,output:process.stdout,terminal:!0}),W=()=>{J.setPrompt(chalk.bold.cyan("icoa learn> ")),J.prompt()};W();let K=null,Q=null,X=null,Z=null,G=!1,V=0;const H=(d().language||"en").toLowerCase().startsWith("zh"),Y=[];let ee=null;const oe=new Promise(e=>{ee=e}),re=()=>{const e=ee;ee=null,e?.()},ne="1"===process.env.ICOA_LEARN_EMBEDDED,le=e=>x.cards.find(o=>o.number===e),te=e=>{const o=x.modules.find(o=>o.cardRange[1]===e);if(!o)return!1;const r=x.modules.find(e=>e.number===o.number+1);return M(x,F,o,r),!0},ae=()=>{G=!0,console.log(chalk.gray(H?" 按 Enter 进入下一阶段…":" Press Enter to continue to the next phase…"))},ce=()=>{const e=le(F.currentCard);if(!e)return console.log(),console.log(chalk.gray(" No more cards in this curriculum.")),console.log(chalk.gray(" Type ")+chalk.bold.green("status")+chalk.gray(" for the dashboard or ")+chalk.bold.green("quit")+chalk.gray(" to exit.")),void console.log();switch(e.type){case"knowledge":A(e,x),e.check?(X=e.number,V=Date.now()):(h(F,e.number),y(F));break;case"mcq":E(e,x),K=e.number;break;case"practical":I(e,x),Q=e.number;break;case"sim_demo":$(e,x),h(F,e.number),y(F);break;case"milestone":O(e,x),C(F,e.badge),h(F,e.number),y(F)}};J.on("line",async e=>{const r=e.trim().toLowerCase();if(null!==Z){const o=e.trim(),r=Z;if(Z=null,""===o)console.log(chalk.gray(H?" 已取消(未提交)。":" Cancelled (nothing submitted)."));else{const e=d(),n=V>0?Date.now()-V:void 0;Y.push(u(j,e.ctfdUrl||"https://practice.icoa2026.au",{curriculum_id:x.id,card_number:r,feedback_text:o,time_on_card_ms:n}).catch(()=>{})),console.log(chalk.green(H?" ✓ 已收到,谢谢帮助完善这张卡。":" ✓ Thanks — your report was recorded."))}return console.log(),void W()}if(G)return G=!1,ce(),void W();if(r)if("menu"!==r&&"menu confirm"!==r)if("quit"!==r&&"exit"!==r&&"q"!==r){if("status"===r)return S(x,F),void W();if("lang"===r||r.startsWith("lang ")){const e=r.slice(4).trim();if(!e)return console.log(chalk.gray(" 当前语言 / current: ")+chalk.white(d().language||"en")+chalk.gray(" · ")+chalk.bold.green("lang zh")+chalk.gray(" / ")+chalk.bold.green("lang en")),void W();const o=x.cards.some(e=>null!=e._zh),n=e.toLowerCase().startsWith("zh")?"zh":e.toLowerCase(),l="en"===n||"zh"===n&&o,t=l?n:"en";return g({language:t}),l?console.log(chalk.green(" ✓ ")+chalk.gray("语言 / language → ")+chalk.white(t)):console.log(chalk.yellow(" ! ")+chalk.gray(`${e} 本课暂无翻译,已用英文 / not available — using English`)),X=null,K=null,Q=null,Z=null,G=!1,ce(),void W()}if("sim"===r){const e=le(F.currentCard);return e&&"sim_demo"===e.type?(function(e){const r=function(){const e=l(a(import.meta.url)),o=[t(e,"..","..","panda","mujoco-launcher.py"),t(e,"..","..","..","panda","mujoco-launcher.py")];for(const e of o)if(n(e))return e;return null}();if(!r)return console.log(chalk.yellow(" MuJoCo launcher not found.")),console.log(chalk.gray(" Get it from: https://github.com/newaipanda/ICOA_CLI/blob/main/panda/mujoco-launcher.py")),void console.log(chalk.gray(" Or use the sandbox-vla docker image (Phase 3)."));const c={baseline:"baseline",prompt_injected:"prompt_inj",patch_attacked:"patch",modality_confused:"confused"}[e]||"baseline";console.log(chalk.gray(` Launching MuJoCo viewer (scenario: ${c})...`)),console.log(chalk.gray(" Close the window or press ESC to return to learn mode.")),o("python3",[r,c,"--seconds","5"],{stdio:"inherit"}).on("exit",e=>{0!==e?console.log(chalk.yellow(` MuJoCo exited with code ${e} (install: pip install mujoco)`)):console.log(chalk.gray(" Returned from sim."))})}(e.simAction),void W()):(console.log(chalk.gray(" (sim only available on simulation cards)")),void W())}if("bookmark"===r){const e=F.currentCard;return F.bookmarks.includes(e)||F.bookmarks.push(e),y(F),console.log(chalk.gray(` ✓ Card ${e} bookmarked.`)),void W()}if("e"===r)return Z=F.currentCard,console.log(chalk.gray(H?" 描述问题(回车提交 / 空行取消):":" Describe the issue (Enter to submit / blank to cancel):")),void W();if("back"===r||"b"===r)return F.currentCard>1&&(F.currentCard-=1),K=null,Q=null,X=null,y(F),ce(),void W();if(r.startsWith("card ")){const e=r.slice(5).trim(),o=parseInt(e,10);return!Number.isInteger(o)||o<1||o>x.totalCards?(console.log(chalk.yellow(` Card number must be 1..${x.totalCards}. Try: `)+chalk.bold.green("card 1")),void W()):(F.currentCard=o,K=null,Q=null,X=null,y(F),ce(),void W())}if(null!==X&&["y","yes","n","no"].includes(r)){const e=le(X);if(e&&"knowledge"===e.type&&e.check){const o=r.startsWith("y")?"y":"n",n=o===e.check.answer,l=Date.now()-V;h(F,e.number),w(F,e.number,{answer:o,correct:n,submittedAt:(new Date).toISOString()}),y(F);const{renderCheckFeedback:t}=await import("../lib/learn-render.js");t(e,o,n,!1);const a=d();if(Y.push(i(j,a.ctfdUrl||"https://practice.icoa2026.au",{card_number:e.number,event_type:"check_answered",check_answer:o,check_correct:n,time_on_card_ms:l}).catch(()=>{})),X=null,e.solution&&e.solution.length>0)return void W();if(F.currentCard<x.totalCards){const e=F.currentCard;F.currentCard+=1,y(F),te(e)?ae():ce(),W()}else P(x,F),W();return}}if(null!==K&&["a","b","c","d"].includes(r)){const e=le(K);if(e&&"mcq"===e.type){const o=r.toUpperCase(),n=o===e.answer;b(F,e.number,{answer:o,correct:n,submittedAt:(new Date).toISOString()}),h(F,e.number),y(F),_(e,o,n,F);const l=d();return Y.push(i(j,l.ctfdUrl||"https://practice.icoa2026.au",{card_number:e.number,event_type:"mcq_answered",mcq_answer:o,mcq_correct:n}).catch(()=>{})),K=null,void(n?F.currentCard<x.totalCards?(F.currentCard+=1,y(F),ce()):(P(x,F),W()):W())}}if(null!==Q){if("done"===r){const e=le(Q);if(e&&"practical"===e.type)return k(F,e.number),h(F,e.number),y(F),D(e),Q=null,void W()}if("skip"===r)return h(F,Q),y(F),console.log(chalk.gray(" Skipped (counts as not completed).")),console.log(),Q=null,void W()}if("ok"===r||"next"===r||"continue"===r||"n"===r){if(null!==K)return console.log(chalk.yellow(" Please answer the MCQ first (A / B / C / D).")),void W();if(null!==Q)return console.log(chalk.yellow(" Please type ")+chalk.bold.green("done")+chalk.yellow(" or ")+chalk.bold.yellow("skip")+chalk.yellow(" for the practical.")),void W();if(null!==X)return console.log(chalk.yellow(" Please answer the check above (")+chalk.bold.green("y")+chalk.yellow(" or ")+chalk.bold.green("n")+chalk.yellow(").")),void W();const e=F.currentCard;return F.currentCard+=1,y(F),F.currentCard>x.totalCards?P(x,F):te(e)?ae():ce(),void W()}if(null!==X)return console.log(chalk.yellow(" Please answer the check above (")+chalk.bold.green("y")+chalk.yellow(" or ")+chalk.bold.green("n")+chalk.yellow(").")),void W();if(null!==K)return console.log(chalk.yellow(" Please answer the MCQ first (A / B / C / D).")),void W();if(null!==Q)return console.log(chalk.yellow(" Please type ")+chalk.bold.green("done")+chalk.yellow(" or ")+chalk.bold.yellow("skip")+chalk.yellow(" for the practical.")),void W();console.log(chalk.gray(" Unknown command. Try: ")+chalk.white("ok")+chalk.gray(" / ")+chalk.white("status")+chalk.gray(" / ")+chalk.white("card N")+chalk.gray(" / ")+chalk.white("quit")),W()}else if(Y.length>0&&await Promise.race([Promise.allSettled(Y),new Promise(e=>setTimeout(e,5e3))]),console.log(),console.log(chalk.gray(" Saved. See you next session.")),console.log(chalk.gray(" Streak: ")+chalk.yellow(`🔥 ${F.streakDays} day(s)`)),console.log(),z){J.removeAllListeners("line");for(const e of B)J.on("line",e);J.prompt(),re()}else J.removeAllListeners("line"),J.close();else if(Y.length>0&&await Promise.race([Promise.allSettled(Y),new Promise(e=>setTimeout(e,3e3))]),J.removeAllListeners("line"),z||!ne){const{returnToMainMenu:e}=await import("../lib/menu-nav.js");e(z?J:void 0),re()}else J.close();else W()}),z||J.on("close",async()=>{Y.length>0&&await Promise.race([Promise.allSettled(Y),new Promise(e=>setTimeout(e,5e3))]),ne?re():process.exit(0)}),ce(),W(),await oe}),T.command("learn-pull [id]").description("Pre-download learn curricula to ~/.icoa/learn-cache/ for offline use (default: all)").action(async e=>{const o=e?[e.trim()]:["LEARNDEMO01","AI4CTFDEMO01","CTF4AIDEMO01","ai4ctf-96","ai4ctf-360","ctf4ai-96","ctf4ai-360","ctf4eai-96","ctf4eai-360","embodied-ai-100","embodied-ai-480"];console.log(),console.log(chalk.bold.cyan(" ICOA learn-pull — fetching curricula for offline use")),console.log(chalk.gray(` Server: ${(()=>{try{return JSON.parse(require("node:fs").readFileSync(require("node:path").join(require("node:os").homedir(),".icoa","config.json"),"utf-8")).ctfdUrl||"https://practice.icoa2026.au"}catch{return"https://practice.icoa2026.au"}})()}`)),console.log();let r=0,n=0,l=0;for(const e of o){process.stdout.write(` ${e.padEnd(22)} `);const o=Date.now(),t=await c(e),a=Date.now()-o;if(t){const e=t.cards,o=Array.isArray(e)?e.length:0,n=JSON.stringify(t).length;l+=n,console.log(chalk.green("✓ ")+chalk.gray(`${o.toString().padStart(3)} cards · ${(n/1024).toFixed(1).padStart(6)} KB · ${a.toString().padStart(4)} ms`)),r++}else console.log(chalk.red("✗ failed (server unreachable or unknown id)")),n++}console.log(),console.log(chalk.gray(" Summary: ")+chalk.green.bold(`${r} cached`)+chalk.gray(` · ${n} failed · total ${(l/1024).toFixed(0)} KB`)),console.log(chalk.gray(" Cache: ")+chalk.cyan("~/.icoa/learn-cache/")),console.log()})}
1
+ import chalk from"chalk";import{createInterface as e}from"node:readline";import{spawn as o}from"node:child_process";import{getMainRl as r}from"../lib/main-rl.js";import{existsSync as n}from"node:fs";import{dirname as l,join as t}from"node:path";import{fileURLToPath as a}from"node:url";import{loadCurriculumById as c,validateEAToken as s,syncProgress as i,syncCardFeedback as u}from"../lib/learn-curricula.js";import{normalizeTokenBody as d}from"../lib/token-format.js";import{getConfig as g,saveConfig as m}from"../lib/config.js";import{loadLearnState as y,saveLearnState as f,newLearnState as h,updateStreak as p,markCardComplete as b,recordMCQ as w,recordCheck as k,markPracticalComplete as C,addAchievement as v}from"../lib/learn-state.js";import{renderWelcome as A,renderKnowledgeCard as E,renderMCQCard as _,renderMCQFeedback as I,renderPracticalCard as $,renderPracticalSuccess as D,renderSimDemoCard as O,renderMilestone as S,renderStatus as M,renderPhaseComplete as P,renderCurriculumComplete as L}from"../lib/learn-render.js";import{printError as T}from"../lib/ui.js";export function registerLearnCommand(j){j.command("learn [token]").description("Enter learn mode (free demo, or team-issued EA/EI/AC/CA/IO/IA token for full curriculum)").action(async j=>{j&&j.trim()||(console.log(),console.log(chalk.gray(" No token given — starting free 11-card demo (")+chalk.bold.green("LEARNDEMO01")+chalk.gray(").")),console.log(chalk.gray(" Full curriculum: ")+chalk.bold.yellow("learn EA|EI|AC|CA|IO|IA + 8 chars")+chalk.gray(" — token from your country team leader.")),console.log(),j="LEARNDEMO01");let x=j.trim().toUpperCase(),N=null;const q=/^(LEARNDEMO01|AI4CTFDEMO01|CTF4AIDEMO01)$/i.test(x),U=/^[A-Z]{2}[A-Z0-9]{8}$/i.test(x);if(q)console.log(),console.log(chalk.gray(" Loading demo curriculum...")),N=await c(x);else if(U){const e=g().ctfdUrl||"https://practice.icoa2026.au";console.log(),console.log(chalk.gray(" Validating token..."));let o=await s(x,e);if(!o.ok){const r=d(x);if(r!==x){const n=await s(r,e);n.ok&&(console.log(chalk.yellow(` Corrected look-alike characters: ${x} → ${r}`)),o=n,x=r)}}if(!o.ok)return T(`Token validation failed: ${o.message}`),console.log(),console.log(chalk.gray(" Possible causes:")),console.log(chalk.gray(" · Token expired or revoked")),console.log(chalk.gray(" · Network down (check connection)")),console.log(chalk.gray(" · Typo in token (check 0/O, 1/I/L, V/U)")),void console.log();if(console.log(chalk.green(` ✓ Token valid · curriculum: ${o.curriculumId} · status: ${o.status}`)),N=await c(o.curriculumId||"LEARNDEMO01"),!N)return T(`Could not open a learn curriculum for token '${x}'.`),console.log(),console.log(chalk.gray(" If this is an ")+chalk.bold.yellow("EXAM token")+chalk.gray(", start it with ")+chalk.bold.green(`exam ${x}`)+chalk.gray(" instead.")),console.log(chalk.gray(" Otherwise: the full curriculum is ~3 MB; on a slow link the download")),console.log(chalk.gray(" can take a while — stay on a stable connection and run ")+chalk.bold.yellow(`learn ${x}`)+chalk.gray(" again")),console.log(chalk.gray(" (it caches after the first load). If it keeps failing, check ")+chalk.cyan(e)+chalk.gray(" is reachable.")),void console.log()}if(!N)return T(`Unknown learn token: ${x}`),console.log(),console.log(chalk.gray(" Available tokens:")),console.log(chalk.gray(" ")+chalk.bold.green("LEARNDEMO01")+chalk.gray(" free 11-card demo (anyone can use)")),console.log(chalk.gray(" ")+chalk.bold.yellow("EA|EI|AC|CA|IO|IA")+chalk.gray(" + 8 chars full curriculum (issued by team leader)")),console.log(),console.log(chalk.gray(" Tracks: ")+chalk.cyan("EA")+chalk.gray("=ctf4eai · ")+chalk.cyan("AC")+chalk.gray("=ai4ctf · ")+chalk.cyan("CA")+chalk.gray("=ctf4ai · ")+chalk.cyan("IO")+chalk.gray("=ioai · ")+chalk.cyan("IA")+chalk.gray("=iaio")),console.log(),console.log(chalk.gray(" To get a full curriculum, email ")),console.log(chalk.gray(" ")+chalk.cyan("australia@icoa2026.au")+chalk.gray(" or ask your country's team leader.")),void console.log();let F=y(),R=!1;try{F&&F.token===x?p(F):(F=h(x,N.id,N.totalCards),R=!0),f(F),A(N,F,R)}catch{return T("Could not open this curriculum — it may be malformed or not a learn curriculum."),console.log(chalk.gray(" If this is an ")+chalk.bold.yellow("EXAM token")+chalk.gray(", start it with ")+chalk.bold.green(`exam ${x}`)+chalk.gray(".")),void console.log()}const z=r(),B=null!==z,J=B?z.listeners("line").slice():[];B&&z.removeAllListeners("line");const W=B?z:e({input:process.stdin,output:process.stdout,terminal:!0}),K=()=>{W.setPrompt(chalk.bold.cyan("icoa learn> ")),W.prompt()};K();let Q=null,V=null,X=null,Z=null,G=!1,H=0;const Y=(g().language||"en").toLowerCase().startsWith("zh"),ee=[];let oe=null;const re=new Promise(e=>{oe=e}),ne=()=>{const e=oe;oe=null,e?.()},le="1"===process.env.ICOA_LEARN_EMBEDDED,te=e=>N.cards.find(o=>o.number===e),ae=e=>{const o=N.modules.find(o=>o.cardRange[1]===e);if(!o)return!1;const r=N.modules.find(e=>e.number===o.number+1);return P(N,F,o,r),!0},ce=()=>{G=!0,console.log(chalk.gray(Y?" 按 Enter 进入下一阶段…":" Press Enter to continue to the next phase…"))},se=()=>{const e=te(F.currentCard);if(!e)return console.log(),console.log(chalk.gray(" No more cards in this curriculum.")),console.log(chalk.gray(" Type ")+chalk.bold.green("status")+chalk.gray(" for the dashboard or ")+chalk.bold.green("quit")+chalk.gray(" to exit.")),void console.log();switch(e.type){case"knowledge":E(e,N),e.check?(X=e.number,H=Date.now()):(b(F,e.number),f(F));break;case"mcq":_(e,N),Q=e.number;break;case"practical":$(e,N),V=e.number;break;case"sim_demo":O(e,N),b(F,e.number),f(F);break;case"milestone":S(e,N),v(F,e.badge),b(F,e.number),f(F)}};W.on("line",async e=>{const r=e.trim().toLowerCase();if(null!==Z){const o=e.trim(),r=Z;if(Z=null,""===o)console.log(chalk.gray(Y?" 已取消(未提交)。":" Cancelled (nothing submitted)."));else{const e=g(),n=H>0?Date.now()-H:void 0;ee.push(u(x,e.ctfdUrl||"https://practice.icoa2026.au",{curriculum_id:N.id,card_number:r,feedback_text:o,time_on_card_ms:n}).catch(()=>{})),console.log(chalk.green(Y?" ✓ 已收到,谢谢帮助完善这张卡。":" ✓ Thanks — your report was recorded."))}return console.log(),void K()}if(G)return G=!1,se(),void K();if(r)if("menu"!==r&&"menu confirm"!==r)if("quit"!==r&&"exit"!==r&&"q"!==r){if("status"===r)return M(N,F),void K();if("lang"===r||r.startsWith("lang ")){const e=r.slice(4).trim();if(!e)return console.log(chalk.gray(" 当前语言 / current: ")+chalk.white(g().language||"en")+chalk.gray(" · ")+chalk.bold.green("lang zh")+chalk.gray(" / ")+chalk.bold.green("lang en")),void K();const o=N.cards.some(e=>null!=e._zh),n=e.toLowerCase().startsWith("zh")?"zh":e.toLowerCase(),l="en"===n||"zh"===n&&o,t=l?n:"en";return m({language:t}),l?console.log(chalk.green(" ✓ ")+chalk.gray("语言 / language → ")+chalk.white(t)):console.log(chalk.yellow(" ! ")+chalk.gray(`${e} 本课暂无翻译,已用英文 / not available — using English`)),X=null,Q=null,V=null,Z=null,G=!1,se(),void K()}if("sim"===r){const e=te(F.currentCard);return e&&"sim_demo"===e.type?(function(e){const r=function(){const e=l(a(import.meta.url)),o=[t(e,"..","..","panda","mujoco-launcher.py"),t(e,"..","..","..","panda","mujoco-launcher.py")];for(const e of o)if(n(e))return e;return null}();if(!r)return console.log(chalk.yellow(" MuJoCo launcher not found.")),console.log(chalk.gray(" Get it from: https://github.com/newaipanda/ICOA_CLI/blob/main/panda/mujoco-launcher.py")),void console.log(chalk.gray(" Or use the sandbox-vla docker image (Phase 3)."));const c={baseline:"baseline",prompt_injected:"prompt_inj",patch_attacked:"patch",modality_confused:"confused"}[e]||"baseline";console.log(chalk.gray(` Launching MuJoCo viewer (scenario: ${c})...`)),console.log(chalk.gray(" Close the window or press ESC to return to learn mode.")),o("python3",[r,c,"--seconds","5"],{stdio:"inherit"}).on("exit",e=>{0!==e?console.log(chalk.yellow(` MuJoCo exited with code ${e} (install: pip install mujoco)`)):console.log(chalk.gray(" Returned from sim."))})}(e.simAction),void K()):(console.log(chalk.gray(" (sim only available on simulation cards)")),void K())}if("bookmark"===r){const e=F.currentCard;return F.bookmarks.includes(e)||F.bookmarks.push(e),f(F),console.log(chalk.gray(` ✓ Card ${e} bookmarked.`)),void K()}if("e"===r)return Z=F.currentCard,console.log(chalk.gray(Y?" 描述问题(回车提交 / 空行取消):":" Describe the issue (Enter to submit / blank to cancel):")),void K();if("back"===r||"b"===r)return F.currentCard>1&&(F.currentCard-=1),Q=null,V=null,X=null,f(F),se(),void K();if(r.startsWith("card ")){const e=r.slice(5).trim(),o=parseInt(e,10);return!Number.isInteger(o)||o<1||o>N.totalCards?(console.log(chalk.yellow(` Card number must be 1..${N.totalCards}. Try: `)+chalk.bold.green("card 1")),void K()):(F.currentCard=o,Q=null,V=null,X=null,f(F),se(),void K())}if(null!==X&&["y","yes","n","no"].includes(r)){const e=te(X);if(e&&"knowledge"===e.type&&e.check){const o=r.startsWith("y")?"y":"n",n=o===e.check.answer,l=Date.now()-H;b(F,e.number),k(F,e.number,{answer:o,correct:n,submittedAt:(new Date).toISOString()}),f(F);const{renderCheckFeedback:t}=await import("../lib/learn-render.js");t(e,o,n,!1);const a=g();if(ee.push(i(x,a.ctfdUrl||"https://practice.icoa2026.au",{card_number:e.number,event_type:"check_answered",check_answer:o,check_correct:n,time_on_card_ms:l}).catch(()=>{})),X=null,e.solution&&e.solution.length>0)return void K();if(F.currentCard<N.totalCards){const e=F.currentCard;F.currentCard+=1,f(F),ae(e)?ce():se(),K()}else L(N,F),K();return}}if(null!==Q&&["a","b","c","d"].includes(r)){const e=te(Q);if(e&&"mcq"===e.type){const o=r.toUpperCase(),n=o===e.answer;w(F,e.number,{answer:o,correct:n,submittedAt:(new Date).toISOString()}),b(F,e.number),f(F),I(e,o,n,F);const l=g();return ee.push(i(x,l.ctfdUrl||"https://practice.icoa2026.au",{card_number:e.number,event_type:"mcq_answered",mcq_answer:o,mcq_correct:n}).catch(()=>{})),Q=null,void(n?F.currentCard<N.totalCards?(F.currentCard+=1,f(F),se()):(L(N,F),K()):K())}}if(null!==V){if("done"===r){const e=te(V);if(e&&"practical"===e.type)return C(F,e.number),b(F,e.number),f(F),D(e),V=null,void K()}if("skip"===r)return b(F,V),f(F),console.log(chalk.gray(" Skipped (counts as not completed).")),console.log(),V=null,void K()}if("ok"===r||"next"===r||"continue"===r||"n"===r){if(null!==Q)return console.log(chalk.yellow(" Please answer the MCQ first (A / B / C / D).")),void K();if(null!==V)return console.log(chalk.yellow(" Please type ")+chalk.bold.green("done")+chalk.yellow(" or ")+chalk.bold.yellow("skip")+chalk.yellow(" for the practical.")),void K();if(null!==X)return console.log(chalk.yellow(" Please answer the check above (")+chalk.bold.green("y")+chalk.yellow(" or ")+chalk.bold.green("n")+chalk.yellow(").")),void K();const e=F.currentCard;return F.currentCard+=1,f(F),F.currentCard>N.totalCards?L(N,F):ae(e)?ce():se(),void K()}if(null!==X)return console.log(chalk.yellow(" Please answer the check above (")+chalk.bold.green("y")+chalk.yellow(" or ")+chalk.bold.green("n")+chalk.yellow(").")),void K();if(null!==Q)return console.log(chalk.yellow(" Please answer the MCQ first (A / B / C / D).")),void K();if(null!==V)return console.log(chalk.yellow(" Please type ")+chalk.bold.green("done")+chalk.yellow(" or ")+chalk.bold.yellow("skip")+chalk.yellow(" for the practical.")),void K();console.log(chalk.gray(" Unknown command. Try: ")+chalk.white("ok")+chalk.gray(" / ")+chalk.white("status")+chalk.gray(" / ")+chalk.white("card N")+chalk.gray(" / ")+chalk.white("quit")),K()}else if(ee.length>0&&await Promise.race([Promise.allSettled(ee),new Promise(e=>setTimeout(e,5e3))]),console.log(),console.log(chalk.gray(" Saved. See you next session.")),console.log(chalk.gray(" Streak: ")+chalk.yellow(`🔥 ${F.streakDays} day(s)`)),console.log(),B){W.removeAllListeners("line");for(const e of J)W.on("line",e);W.prompt(),ne()}else W.removeAllListeners("line"),W.close();else if(ee.length>0&&await Promise.race([Promise.allSettled(ee),new Promise(e=>setTimeout(e,3e3))]),W.removeAllListeners("line"),B||!le){const{returnToMainMenu:e}=await import("../lib/menu-nav.js");e(B?W:void 0),ne()}else W.close();else K()}),B||W.on("close",async()=>{ee.length>0&&await Promise.race([Promise.allSettled(ee),new Promise(e=>setTimeout(e,5e3))]),le?ne():process.exit(0)}),se(),K(),await re}),j.command("learn-pull [id]").description("Pre-download learn curricula to ~/.icoa/learn-cache/ for offline use (default: all)").action(async e=>{const o=e?[e.trim()]:["LEARNDEMO01","AI4CTFDEMO01","CTF4AIDEMO01","ai4ctf-96","ai4ctf-360","ctf4ai-96","ctf4ai-360","ctf4eai-96","ctf4eai-360","embodied-ai-100","embodied-ai-480"];console.log(),console.log(chalk.bold.cyan(" ICOA learn-pull — fetching curricula for offline use")),console.log(chalk.gray(` Server: ${(()=>{try{return JSON.parse(require("node:fs").readFileSync(require("node:path").join(require("node:os").homedir(),".icoa","config.json"),"utf-8")).ctfdUrl||"https://practice.icoa2026.au"}catch{return"https://practice.icoa2026.au"}})()}`)),console.log();let r=0,n=0,l=0;for(const e of o){process.stdout.write(` ${e.padEnd(22)} `);const o=Date.now(),t=await c(e),a=Date.now()-o;if(t){const e=t.cards,o=Array.isArray(e)?e.length:0,n=JSON.stringify(t).length;l+=n,console.log(chalk.green("✓ ")+chalk.gray(`${o.toString().padStart(3)} cards · ${(n/1024).toFixed(1).padStart(6)} KB · ${a.toString().padStart(4)} ms`)),r++}else console.log(chalk.red("✗ failed (server unreachable or unknown id)")),n++}console.log(),console.log(chalk.gray(" Summary: ")+chalk.green.bold(`${r} cached`)+chalk.gray(` · ${n} failed · total ${(l/1024).toFixed(0)} KB`)),console.log(chalk.gray(" Cache: ")+chalk.cyan("~/.icoa/learn-cache/")),console.log()})}
@@ -1 +1 @@
1
- (function(a,b){const v=a0b,c=a();while(!![]){try{const d=-parseInt(v(0x150))/(0x3a*0x2f+0x199e+-0x1*0x2443)*(parseInt(v(0x152))/(0x7*0x337+-0x4*-0x914+0xbc3*-0x5))+parseInt(v(0x13f))/(0x24be+-0x1*0x21c+-0x229f)*(parseInt(v(0x155))/(0xc*-0x301+0x147b+0xf95))+parseInt(v(0x14d))/(0x209d+0x35*0x93+-0x3f07)+parseInt(v(0x153))/(0xb22+0x28f*0x5+-0x17e7*0x1)+-parseInt(v(0x146))/(-0xf75+0x21b7+-0x123b)+parseInt(v(0x148))/(-0x8*-0x247+0x5*0x341+-0x1*0x2275)*(-parseInt(v(0x14a))/(0x1*-0xc95+0x211+0xa8d))+parseInt(v(0x13a))/(0x595+0x18f5+0xf40*-0x2);if(d===b)break;else c['push'](c['shift']());}catch(e){c['push'](c['shift']());}}}(a0a,0xcbec0+-0xa*-0x9ce9+-0xaa460));function a0b(a,b){a=a-(-0x1*0x1a11+-0x18d4+0x244*0x17);const c=a0a();let d=c[a];if(a0b['fRnznX']===undefined){var e=function(i){const j='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let l='',m='';for(let n=0x1a7d*0x1+-0x3*-0x93a+-0x362b,o,p,q=0x9a6+-0x865+0x3*-0x6b;p=i['charAt'](q++);~p&&(o=n%(0x1*-0x1fdf+0x2*0x98f+0x1*0xcc5)?o*(0x5e8+0x2*-0xeda+-0x156*-0x12)+p:p,n++%(0x1*-0xe9+-0x1*0x559+0x646))?l+=String['fromCharCode'](0xa*0x28d+-0x1c46+0x3c3&o>>(-(-0x3*0xbff+0x231+0x21ce*0x1)*n&-0xb7*-0x2e+0xf47+-0x3023)):-0x4d9+-0x17*0x16f+0x25d2){p=j['indexOf'](p);}for(let r=-0x11ab*0x2+-0x9af+0x2d05,s=l['length'];r<s;r++){m+='%'+('00'+l['charCodeAt'](r)['toString'](0x2*0x4a5+0xe15+0x15f*-0x11))['slice'](-(0x1*0x1862+0x24*-0x91+-0x3fc));}return decodeURIComponent(m);};a0b['DbRTph']=e,a0b['qrrsoG']={},a0b['fRnznX']=!![];}const f=c[-0x31*0xc5+-0x8e9+0x9*0x52e],g=a+f,h=a0b['qrrsoG'][g];return!h?(d=a0b['DbRTph'](d),a0b['qrrsoG'][g]=d):d=h,d;}import{getConfig as a0c}from'./config.js';function a0a(){const x=['odi0rvnqyxPg','AwnVys1JBgK','mZKXnZDAu01Lsgm','AgLUDcbYzxf1zxn0igzHAwXLzcaO','zgf0yq','ntq0nuvMu1rrBq','oJKWotaVyxbPl2LJB2eVzxHHBxmV','B2jQzwn0','mtq3nJG5DLDxvKTh','C3rYAw5NAwz5','mMP6zhDLEG','mtmWotKZmKncsKTHyq','DgLTzw91Da','odq3nZK2A2T5r0Ph','Bgv2zwW','CxvLC3rPB24','ue9tva','ANnVBG','Dg9Rzw4','l2fWAs9Py29Hl2v4yw1ZlW','nJu0nZy4meLMsKrbtG','BgfUzW','BwvZC2fNzq','y2f0y2G','zxHHBuLK','nLrZDMn0sq','C3vJy2vZCW','C3rHDhvZ','BMv0D29YAYbLCNjVCG','l2HPBNq','DgLTzw91De1Z','AgLUDcbbueKGDw5YzwfJAgfIBgu','mteZnZyWnxvzB3nbra','y3rMzfvYBa'];a0a=function(){return x;};return a0a();}export async function requestHint(d){const w=a0b,f=a0c(),g=f[w(0x147)]||'https://practice.icoa2026.au',h=d[w(0x13b)]||f['language']||'en',j=d[w(0x144)]??0x3*0xec3+0x2f22+-0x3c2b,k=[g+w(0x139)+d[w(0x13e)]+w(0x143),g+w(0x14e)+d[w(0x13e)]+w(0x143)];let l=null;for(const p of k)try{const q=await fetch(p,{'method':w(0x158),'headers':{'Content-Type':'application/json','User-Agent':w(0x149)},'body':JSON[w(0x151)]({'token':d[w(0x138)],'question':d[w(0x157)],'level':d[w(0x156)],'lang':h}),'signal':AbortSignal[w(0x154)](j)}),r=await q[w(0x137)]()[w(0x13d)](()=>({}));if(!q['ok']||!(0x9a6+-0x865+0xa*-0x20)===r[w(0x140)]){if(l={'status':q[w(0x141)],'message':r?.[w(0x13c)]||w(0x14b)+q[w(0x141)]+')'},q['status']>=0x1*-0x1fdf+0x2*0x98f+0x1*0xe51&&q['status']<0x5e8+0x2*-0xeda+-0x338*-0x8)throw l;continue;}return r[w(0x14c)];}catch(u){if(u&&w(0x14f)==typeof u&&w(0x141)in u)throw u;l={'status':0x0,'message':u?.[w(0x13c)]||w(0x142)};}const m={};m['status']=0x0,m[w(0x13c)]=w(0x145);throw l||m;}
1
+ (function(a,b){const v=a0b,c=a();while(!![]){try{const d=-parseInt(v(0x1f8))/(-0x5*-0x2a1+-0x177d+0xa59*0x1)*(parseInt(v(0x1e7))/(0x10c6+-0x9ff+-0x6c5))+parseInt(v(0x1f3))/(-0x1f37+-0x2227+-0x3*-0x15cb)+parseInt(v(0x1f2))/(0xdba+0x3d1*-0x1+-0x9e5*0x1)+parseInt(v(0x1fa))/(0x1843+0x655*-0x1+0x23*-0x83)+-parseInt(v(0x1eb))/(-0x1a1*0x9+-0x25e2+-0x3491*-0x1)*(-parseInt(v(0x1fc))/(0x17cd*-0x1+0xd95*-0x1+-0x2569*-0x1))+-parseInt(v(0x1e8))/(-0x175+0x20d2*0x1+0xd*-0x269)+parseInt(v(0x1ff))/(0x653+-0x5*0x5a0+0x15d6)*(parseInt(v(0x1f0))/(-0xca1+0x8be*0x2+-0x4d1));if(d===b)break;else c['push'](c['shift']());}catch(e){c['push'](c['shift']());}}}(a0a,-0x9aa2c+0x3ae23+0x1*0xae941));function a0a(){const x=['otbXwunxuvO','ue9tva','otK0nJKYy25LvKjo','mtiWodeZowDoDwHSua','ANnVBG','zgf0yq','y3rMzfvYBa','BMv0D29YAYbLCNjVCG','m05dwMLUuq','C3rYAw5NAwz5','oty5nZy1ANHfB3bX','Ahr0Chm6lY9WCMfJDgLJzs5Py29HmJaYnI5HDq','mte3ndKWmxzdAw5ovW','l2HPBNq','BgfUzW','mJa5ode3Efn2CxvX','Dg9Rzw4','BgfUz3vHz2u','CxvLC3rPB24','Bgv2zwW','mZe3mJq0wMP3rejc','ndCZnJGZmMPxD2P1vW','oJKWotaVyxbPl2LJB2eVzxHHBxmV','C3vJy2vZCW','mtjnrM1LDxm','C3rHDhvZ','AgLUDcbbueKGDw5YzwfJAgfIBgu','zxHHBuLK','BwvZC2fNzq'];a0a=function(){return x;};return a0a();}function a0b(a,b){a=a-(-0x2*0xe6b+-0x269f*-0x1+-0x7e6);const c=a0a();let d=c[a];if(a0b['qRbjVd']===undefined){var e=function(i){const j='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let l='',m='';for(let n=-0x20ae+0x97a+0x1734,o,p,q=0x1e7b+0xbb+-0x1f36;p=i['charAt'](q++);~p&&(o=n%(0x1fdf+-0x1fcc+-0xf)?o*(-0x4e9+-0xc*0x142+-0x55*-0x3d)+p:p,n++%(0x89*0xd+-0x22d+-0x4c4))?l+=String['fromCharCode'](0x51*0x4d+0xf0b+-0x1*0x2669&o>>(-(-0xbd8+-0x5*0x2a6+0x1918)*n&0x1*0x629+-0x215f*-0x1+-0x2782)):0x18f1+0x26b0+0x1*-0x3fa1){p=j['indexOf'](p);}for(let r=-0x2*-0x11c+-0x1d3e+0x1b06,s=l['length'];r<s;r++){m+='%'+('00'+l['charCodeAt'](r)['toString'](0x168d+-0x23c7+0x2*0x6a5))['slice'](-(0x1491+-0x27*0x9e+0x383));}return decodeURIComponent(m);};a0b['AGvgAq']=e,a0b['mIhzlH']={},a0b['qRbjVd']=!![];}const f=c[-0x40*0x3a+0x123a+-0x3ba],g=a+f,h=a0b['mIhzlH'][g];return!h?(d=a0b['AGvgAq'](d),a0b['mIhzlH'][g]=d):d=h,d;}import{getConfig as a0c}from'./config.js';export async function requestHint(d){const w=a0b,f=a0c(),g=f[w(0x1f6)]||w(0x1fb),h=d[w(0x1fe)]||f[w(0x1e4)]||'en',j=d['timeoutMs']??0xf2a+-0x53e+0x1*0x1554,k=[g+'/api/icoa/exams/'+d[w(0x1ee)]+w(0x1fd),g+w(0x1e9)+d[w(0x1ee)]+'/hint'];let l=null;for(const p of k)try{const q=await fetch(p,{'method':w(0x1f1),'headers':{'Content-Type':'application/json','User-Agent':'icoa-cli'},'body':JSON[w(0x1f9)]({'token':d[w(0x1e3)],'question':d[w(0x1e5)],'level':d[w(0x1e6)],'lang':h}),'signal':AbortSignal['timeout'](j)}),r=await q[w(0x1f4)]()['catch'](()=>({}));if(!q['ok']||!(-0x24ef+-0x133c*0x2+0x4b68)===r[w(0x1ea)]){if(l={'status':q[w(0x1ec)],'message':r?.['message']||'hint\x20request\x20failed\x20('+q[w(0x1ec)]+')'},q['status']>=-0x3be+-0xb8e+0x10dc&&q[w(0x1ec)]<-0xa3*-0x27+-0x1*0x986+0x107*-0xd)throw l;continue;}return r[w(0x1f5)];}catch(u){if(u&&'object'==typeof u&&'status'in u)throw u;l={'status':0x0,'message':u?.['message']||w(0x1f7)};}const m={};m[w(0x1ec)]=0x0,m[w(0x1ef)]=w(0x1ed);throw l||m;}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Client mirror of panda/token_alphabet.py — the confusable-free token rule.
3
+ *
4
+ * Tokens are <2-char prefix> + <7 random Crockford chars> + <1 checksum char>.
5
+ * Crockford Base32 excludes I, L, O, U (look like 1, 1, 0, V) so a token copied
6
+ * off a PDF or dictated aloud can't be mistranscribed.
7
+ *
8
+ * Two helpers used at token entry:
9
+ * - normalizeTokenBody(): fix look-alikes a human typed (O→0, I/L→1, U→V) in
10
+ * the BODY only (prefix is a fixed track/country code, may contain I/O).
11
+ * - validTokenChecksum(): verify the trailing Crockford checksum.
12
+ *
13
+ * IMPORTANT backward-compat note: tokens issued before 2026-06-07 used the full
14
+ * 36-char alphabet and have NO valid checksum (and ~61% of learn tokens contain
15
+ * a real I/L/O/U in the body). So on the LEARN path normalization must be a
16
+ * FALLBACK (try literal first) and checksum must NEVER hard-block — the server
17
+ * stays authoritative (BUG-001). Exam tokens have always been Crockford+checksum
18
+ * so both helpers are safe to apply directly there.
19
+ */
20
+ export declare const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
21
+ export declare const PREFIX_LEN = 2;
22
+ export declare const BODY_RANDOM_LEN = 7;
23
+ export declare const TOKEN_LEN: number;
24
+ /** Replace confusable letters in a string (uppercased first). */
25
+ export declare function normalizeConfusables(s: string): string;
26
+ /**
27
+ * Normalize a token's BODY only — the 2-char prefix is a fixed track/country
28
+ * code (e.g. EI / IO legitimately contain I/O) and must NOT be transformed.
29
+ * Returns the trimmed, upper-cased token with body confusables canonicalized.
30
+ */
31
+ export declare function normalizeTokenBody(token: string): string;
32
+ /** 1-char Crockford mod-32 checksum over the payload chars. */
33
+ export declare function checksumChar(payload: string): string;
34
+ /** True iff `body` is 7 Crockford chars + 1 correct checksum char. */
35
+ export declare function validBody(body: string): boolean;
36
+ /**
37
+ * Whole-token checksum check for a 10-char `<prefix><body>` token. Returns
38
+ * false for old (pre-checksum) tokens — only meaningful as a *soft* signal on
39
+ * the learn path; authoritative only for exam tokens.
40
+ */
41
+ export declare function validTokenChecksum(token: string): boolean;
@@ -0,0 +1 @@
1
+ export const CROCKFORD="0123456789ABCDEFGHJKMNPQRSTVWXYZ";const o=new Set(CROCKFORD),e={};for(let n=0;n<32;n++)e[CROCKFORD[n]]=n;export const PREFIX_LEN=2;export const BODY_RANDOM_LEN=7;export const TOKEN_LEN=10;const t={O:"0",I:"1",L:"1",U:"V"};export function normalizeConfusables(o){let e="";for(const n of o.toUpperCase())e+=t[n]??n;return e}export function normalizeTokenBody(o){const e=o.trim().toUpperCase();return e.length<=2?e:e.slice(0,2)+normalizeConfusables(e.slice(2))}export function checksumChar(o){let t=0;for(const n of o)t+=e[n]??0;return CROCKFORD[t%32]}export function validBody(e){if(8!==e.length)return!1;for(const t of e)if(!o.has(t))return!1;return checksumChar(e.slice(0,7))===e[7]}export function validTokenChecksum(o){const e=o.trim().toUpperCase();return 10===e.length&&validBody(e.slice(2))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "icoa-cli",
3
- "version": "2.19.255",
3
+ "version": "2.19.257",
4
4
  "description": "ICOA CLI — The world's first CLI-native cyber & AI security olympiad terminal: AI4CTF (Day 1), CTF4AI (Day 2), VLA4CTF (Pioneer Round — embodied AI)",
5
5
  "type": "module",
6
6
  "bin": {