icoa-cli 2.19.616 → 2.19.618
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib/learn-render.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import chalk from"chalk";import e from"string-width";import{localized as o}from"./learn-curricula.js";import{t as n}from"./learn-i18n.js";import{arenaCadence as t}from"./learn-contest.js";import{getConfig as r}from"./config.js";import{icoaBannerLines as a}from"./banner.js";import{renderCharts as l,detectCaps as s}from"./render-card.js";import{replyChipLabel as c}from"./learn-replies.js";function g(){return(r().language||"en").toLowerCase()}let i="normal";export function resolveLearnWidth(e){return"normal"===e.learnWidth||"wide"===e.learnWidth||"wider"===e.learnWidth||"widest"===e.learnWidth?e.learnWidth:e.learnWide?"wide":"normal"}export function setLearnWidth(e){i=e}export function learnWidthCap(e=i){return"widest"===e?160:"wider"===e?120:"wide"===e?96:64}export function learnW(){const e=process.stdout.columns||69,o=Math.max(40,Math.min(64,e-5));return"normal"===i?o:Math.max(o,Math.min(e-6,learnWidthCap()))}const d=learnW;function h(e="─"){return e.repeat(d()+2)}function y(o,n){if(e(o)<=n)return o;let t=o;for(;t.length>0&&e(t)>Math.max(1,n-1);)t=t.slice(0,-1);return t.trimEnd()+"…"}function u(e,o,n=20){const t=o>0?e/o:0,r=Math.floor(t*n),a=n-r;return`${chalk.green("█".repeat(r))+chalk.gray("░".repeat(a))} ${(100*t).toFixed(1)}%`}function p(e){return e>=30?chalk.red("🔥🔥🔥 "+e+" days"):e>=7?chalk.yellow("🔥 "+e+" days"):e>=1?chalk.gray("· "+e+" day"+(e>1?"s":"")):chalk.gray("—")}export function renderWelcome(e,o,t){const r=g(),a=o.cardsCompleted.length,l=e.totalCards,s=l-a,c=e.modules.find(e=>o.currentCard>=e.cardRange[0]&&o.currentCard<=e.cardRange[1]),i=/demo/i.test(e.id);if(console.log(),console.log(chalk.cyan(" ╭"+h("═"))),console.log(chalk.cyan(" ║")),console.log(chalk.cyan(" ║ ")+chalk.bold.white(" "+(e.name?.trim()||n("academy_title",r)))),console.log(chalk.cyan(" ║")),t)console.log(chalk.cyan(" ║ ")+chalk.white(" "+n(i?"welcome_new_demo":"welcome_new",r)));else{const e=new Date(o.lastSeenAt),t=Math.floor((Date.now()-e.getTime())/36e5),a=t<1?n("just_now",r):t<24?`${t}${n("ago_hours",r)}`:`${Math.floor(t/24)}${n("ago_days",r)}`;console.log(chalk.cyan(" ║ ")+chalk.white(` ${n("welcome_back",r)} ${a}`))}console.log(chalk.cyan(" ║"));const b=y(c?`${c.number}. ${c.name}`:"—",d()-14);console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("module",r).padEnd(11))+chalk.white(b)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("progress",r).padEnd(11))+u(a,l,Math.max(6,Math.min(20,d()-26-`${a}/${l}`.length)))+chalk.gray(` (${a}/${l})`)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("streak",r).padEnd(11))+p(o.streakDays)),s>0&&o.currentCard<=l&&console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("next_card",r).padEnd(11))+chalk.white(`#${o.currentCard} ${n("of",r)} ${l}`)),console.log(chalk.cyan(" ║")),console.log(chalk.cyan(" ╰"+h("═"))),console.log(),console.log(chalk.gray(" ─────────────────────────────────────────────"));const m=0===a?n("continue_start",r):`${n("continue_resume",r)} ${o.currentCard}`;console.log(chalk.bold.green(" continue")+chalk.gray(" "+m)),console.log(chalk.yellow(" status")+chalk.gray(" "+n("status_full",r))),o.bookmarks.length>0&&console.log(chalk.yellow(" bookmarks")+chalk.gray(` ${o.bookmarks.length} ${n("bookmarks_desc",r)}`)),console.log(chalk.gray(" quit")+chalk.gray(" "+n("quit_desc",r))),console.log(chalk.gray(" ─────────────────────────────────────────────")),console.log()}function b(o,t){const r=g(),a=o.module,l=t.modules.find(e=>e.number===a),s=l?l.name:n("unknown_module",r),c=n("module",r).replace(":","").trim(),i=y(`${n("card",r)} ${o.number} / ${t.totalCards} · ${c} ${a} · ${s}`,d()-4);console.log(),console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(i)+" "+chalk.cyan("─".repeat(Math.max(0,d()-e(i)-4))))}function m(){console.log(chalk.cyan(" ╰"+h())),console.log()}function f(e){console.log(chalk.cyan(" │ ")+chalk.white(e))}function $(){console.log(chalk.cyan(" │"))}const w=/[┌┐└┘├┤┬┴┼─│╔╗╚╝═║╠╣╦╩╬▓▒░█]/;function k(e){return/^(?: {4}|\t)/.test(e)||w.test(e)||/ {3,}/.test(e)}const _=/[\u0E00-\u0E7F]/;function x(e){try{return new Intl.Segmenter("th",{granularity:e})}catch{return null}}const C=x("word"),v=x("grapheme");export function wrapMixed(o,n){const t=[];let r="",a=0,l=!1;for(const s of function(o){const n=[],t=o=>{let t="",r="";const a=()=>{t&&(n.push({t:"atom",s:t}),t="")},l=()=>{if(r){if(a(),C)for(const{segment:e}of C.segment(r))if(e.length<=20)n.push({t:"atom",s:e});else if(v)for(const o of v.segment(e))n.push({t:"atom",s:o.segment});else for(const o of e)n.push({t:"atom",s:o});else for(const e of r)n.push({t:"atom",s:e});r=""}};for(const s of o)" "===s?(l(),a(),n.push({t:"space"})):_.test(s)?r+=s:2===e(s)?(l(),a(),n.push({t:"wide",s:s})):(l(),t+=s);l(),a()},r=/`[^`]*`/g;let a,l=0;for(;null!==(a=r.exec(o));)t(o.slice(l,a.index)),n.push({t:"code",s:a[0]}),l=a.index+a[0].length;return t(o.slice(l)),n}(o)){if("space"===s.t){""!==r&&(l=!0);continue}const o=s.s,c=e("code"===s.t?o.replace(/`/g,""):o),g=l?1:0,i="atom"===s.t&&o.length<=2&&/^[.,;:!?)\]}…'"]+$/.test(o);""!==r&&!i&&a+g+c>n?(t.push(r),r=o,a=c,l=!1):(l&&(r+=" ",a+=1,l=!1),r+=o,a+=c)}return r&&t.push(r),t}const M=/\b(?:Common bug|Common mistake|Common error|Pitfall|Gotcha|Footgun)\b[::]?|\b(?:Warning|Caution)\b[::]|(?:常见错误|常见陷阱|常见误区|陷阱|注意|警告|误区)[::]/gi;function S(e,o){const n=o?chalk.bold.white:chalk.white;let t,r="",a=0;for(M.lastIndex=0;null!==(t=M.exec(e));)t.index>a&&(r+=n(e.slice(a,t.index))),r+=chalk.bold.yellow(t[0]),a=t.index+t[0].length;return a<e.length&&(r+=n(e.slice(a))),r}function j(e,o=!1){let n="",t=0;const r=/`([^`]*)`/g;let a;for(;null!==(a=r.exec(e));)a.index>t&&(n+=S(e.slice(t,a.index),o)),n+=chalk.cyan(a[1]),t=a.index+a[0].length;return t<e.length&&(n+=S(e.slice(t),o)),n}function A(e,o=!1){let n=!1;for(const t of e.split("\n"))if(/^\s*```/.test(t))n=!n;else if(n)console.log(chalk.cyan(" │ ")+chalk.cyan(` ${t}`));else if(""!==t)if(k(t))console.log(chalk.cyan(" │ ")+chalk.white(t));else for(const e of wrapMixed(t,d()-6))console.log(chalk.cyan(" │ ")+` ${j(e,o)}`);else $()}function W(e,o){const n=[];for(const t of e.split("\n"))""!==t?k(t)?n.push(t):n.push(...wrapMixed(t,o)):n.push("");return n}let z=!1,L=!1;export function setLearnAiEnabled(e,o=e){z=e,L=o}let R=new Set;export function setLearnPqsViewCards(e){R=e}let P=new Map;export function setLearnHonorRanks(e){P=e}const E=["①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩"];let q=[];export function setLearnReplies(e){q=e}let T=[];export function setLearnFaqs(e){T=e}let N=null;export function setLearnHometask(e){N=e}let F="full";export function setLearnFooterProfile(e){F=e}let O=null;export function setLearnFooterExtra(e){O=e}function D(){const e=O?.();e&&console.log(chalk.gray(" "+e))}let I=null;export function setLearnPracticeChips(e){I=e}let B=!1;export function setLearnShellLane(e){B=e}let H=!1,Q=new Map;export function setLearnArenaCards(e){Q=new Map(e.map(e=>[e.card,e.slot]))}export function setLearnArenaLane(e){H=e}export function learnCheckpointVerb(){return V?"duck":null}let V=!1;export function setLearnDuckLane(e){V=e}let Y=null;export function setLearnPracticeCount(e){Y=e}export function renderHonorWall(e){const o=g().startsWith("zh"),{totals:n,chapters:t}=e,r=n.gold+n.silver+n.bronze,a=(e,o)=>o>0?chalk.bold.white(`${e}×${o}`):chalk.gray(`${e}×0`);if(console.log(chalk.gray(" ─────────────────────────────────────────")),console.log(chalk.bold.white(o?" 🏅 奖牌墙 ":" 🏅 Medal wall ")+a("🥇",n.gold)+chalk.gray(" · ")+a("🥈",n.silver)+chalk.gray(" · ")+a("🥉",n.bronze)+chalk.gray(o?" (永久 — 挂上墙就不会摘下)":" (permanent — once earned, never removed)")),0===r){const n=null!=e.floor?`${e.floor}+`:o?"高分":"a high score";return console.log(chalk.gray(o?` 还没有奖牌 — 单卡提问评分 ${n} 并进入该卡前三,即可永久挂墙 🥇🥈🥉`:` No medals yet — score ${n} on a card and hold its top-3 to hang one 🥇🥈🥉`)),void console.log(chalk.gray(" ─────────────────────────────────────────"))}const l=t.map(e=>{const o=`Ch${e.chapter}`,n=(e.gold>0?`🥇${e.gold}`:"")+(e.silver>0?`🥈${e.silver}`:"")+(e.bronze>0?`🥉${e.bronze}`:"");return n?chalk.white(`${o} ${n}`):chalk.gray(`${o} —`)}).join(chalk.gray(" "));console.log(" "+l);const s=t.flatMap(e=>e.cards.map(o=>({...o,chapter:e.chapter})));s.sort((e,o)=>e.rank-o.rank||e.chapter-o.chapter||e.card-o.card);for(const e of s.slice(0,24)){const n=(e.since||"").slice(0,10);console.log(chalk.white(` ${e.icon} `)+chalk.gray(`Ch${e.chapter} · `)+chalk.white(o?`第 ${e.card} 张`:`card ${e.card}`)+chalk.gray(` · ${e.score}`)+(n?chalk.gray(o?` · 始于 ${n}`:` · since ${n}`):""))}s.length>24&&console.log(chalk.gray(o?` …还有 ${s.length-24} 枚`:` …and ${s.length-24} more`)),console.log(chalk.gray(" ─────────────────────────────────────────"))}export function renderKnowledgeCard(t,r){const a=g(),h=o(t,a);b(h,r),$();const y=wrapMixed(h.title,d()-4);for(const e of y)f(chalk.bold.yellow(e));f(chalk.gray("─".repeat(Math.min(Math.max(...y.map(o=>e(o))),d()))));const u=!!(t.chart_ids&&t.chart_ids.length>0);if(u&&l(t.chart_ids.slice(0,1),r.charts,s()),h.key_point&&""!==h.key_point.trim()?(u||$(),function(e,o,n){const t=g().startsWith("zh"),r=s().cols,a="-".repeat(Math.min(d(),Math.max(24,r-6))),l=t?"要点":"KEY POINT",c=t?`第 ${o} / ${n} 张`:`Card ${o} / ${n}`;console.log(chalk.cyan(" │ ")+chalk.green(a)),console.log(chalk.cyan(" │ ")+chalk.green(`${l} · ${c}`));for(const o of wrapMixed(e,d()-6))console.log(chalk.cyan(" │ ")+chalk.bold.green(" "+o));console.log(chalk.cyan(" │ ")+chalk.green(a)),$()}(h.key_point,h.number,r.totalCards)):u||$(),h.body.filter(e=>null!=e&&""!==e.trim()).forEach((e,o)=>{const n=0===o?e.match(/^([\s\S]*?(?:[.!?](?=\s|$)|[。!?]))(\s[\s\S]*)?$/):null;if(n&&n[1].trim().length<=180){A(n[1],!0);const e=n[2]?.trimStart();e&&A(e,!1)}else A(e,!1);$()}),h.icoaConnection){f(chalk.magenta(" "+n("icoa_connection",a))),f(chalk.gray(" "+"─".repeat(20)));for(const e of wrapMixed(h.icoaConnection,d()-6))f(" "+chalk.magenta(e));$()}if(t.check){const e=a.slice(0,2).toLowerCase(),o=t[`_${e}`],n=o?.checkStatement??o?.check?.statement??t.check.statement;for(const o of wrapMixed("zh"===e?"请回答 (输 y 或 n):":"Quick comprehension check (type y or n):",d()-10))f(chalk.cyan(" 🤔 "+o));f(chalk.gray(" "+"─".repeat(20)));for(const e of wrapMixed(n,d()-6))f(" "+chalk.white(e));$()}m(),function(o,n){const t=g().startsWith("zh"),r=s().cols,a="-".repeat(Math.min(d(),Math.max(24,r-6))),l=chalk.gray(" ");if("minimal"===F){const e=I?I(o.number):null;console.log(chalk.gray(" "+a)),console.log(chalk.gray(" "+(t?`第 ${o.number} / ${n.totalCards} 张`:`Card ${o.number} / ${n.totalCards}`))+(e?chalk.gray(t?" · 本卡练习 ":" · practice ")+e:""));const r=[];if(o.check?(r.push(chalk.bold.green("[y]")+chalk.gray(t?" 是":" yes")),r.push(chalk.bold.green("[n]")+chalk.gray(t?" 否":" no"))):r.push(chalk.bold.green("[ok]")+chalk.gray(t?" 下一张":" next")),e){const o=Math.max(1,(e.match(/\[\d\]/g)??[]).length),n=Array.from({length:o},(e,o)=>`[${o+1}]`).join("");r.push(chalk.bold.cyan(n)+chalk.gray(t?" 练习":" practice"))}B&&r.push(chalk.bold.magenta("[sh]")+chalk.gray(t?" 实验台":" shell")),z&&r.push(chalk.bold.magenta("[/ai]")+chalk.gray(t?" 🐼 熊猫导师":" 🐼 Panda tutor"));const s=Q.get(o.number);return H&&s?r.push(chalk.bold.magenta(`[contest ${s}]`)+chalk.gray(t?" 检查点":" checkpoint")):H&&0===Q.size&&r.push(chalk.bold.magenta("[battle]")+chalk.gray(t?" 进竞技场":" arena")),V&&r.push(chalk.bold.magenta("[duck]")+chalk.gray(t?" 跑仿真":" sim bench")),o.flow&&o.flow.length>0&&r.push(chalk.bold.magenta("[flow]")+chalk.gray(t?" 互动走一遍":" walk it")),r.push(chalk.bold.cyan("[b]")+chalk.gray(t?" 上一张":" back")),r.push(chalk.bold.yellow("[e]")+chalk.gray(t?" 求助":" help")),r.push(chalk.gray("[quit]")+(t?chalk.gray(" 退出"):"")),console.log(" "+r.join(l)),D(),void console.log()}const h=[];o.check?(h.push(chalk.bold.green("[y]")+chalk.gray(t?" 是":" yes")),h.push(chalk.bold.green("[n]")+chalk.gray(t?" 否":" no"))):h.push(chalk.bold.green("[ok]")+chalk.gray(t?" 继续":" next")),o.flow&&o.flow.length>0&&h.push(chalk.bold.magenta("[flow]")+chalk.gray(t?" 互动走一遍":" walk it")),z&&h.push(chalk.bold.magenta("[/ai]")+chalk.gray(t?" 🐼 熊猫导师":" 🐼 Panda tutor")),L&&h.push(chalk.bold.magenta("[/submit]")+chalk.gray(t?" 提问评分":" prompt score"));const y=P.get(o.number);var u;h.push(chalk.bold.magenta(y?`[/honors ${u=y,E[u-1]??`#${u}`}]`:"[/honors]")+chalk.gray(t?" 排行":" board")),"normal"===i?h.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 宽屏":" widen")):("wide"===i?h.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 更宽":" wider")):"wider"===i?(h.push(chalk.bold.cyan("[widest]")+chalk.gray(t?" 最宽":" widest")),h.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 回宽屏":" back to wide"))):h.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 回 wider":" back to wider")),h.push(chalk.bold.cyan("[normal]")+chalk.gray(t?" 标准":" standard")));const p=c(q,T,o.number,t),b=p.startsWith("💬");if(h.push((b?chalk.bold.yellow("[r]"):chalk.gray("[r]"))+(b?chalk.bold.white(` ${p}`):chalk.gray(` ${p}`))),h.push(chalk.bold.yellow("[e]")+chalk.gray(t?" 提问或报告":" ask or report")),N){const e=N,o=`${e.done}/${e.total}`,n=e.completedAt?chalk.bold.green:chalk.bold.cyan;h.push(n("[task]")+chalk.gray(t?` 本周 ${o}`:` week ${o}`))}h.push(chalk.bold.cyan("[b]")+chalk.gray(t?" 上一张":" back")),h.push(chalk.bold.cyan("[card N]")+chalk.gray(t?" 跳转":" jump")),h.push(chalk.gray("[reload]")+(t?chalk.gray(" 刷新"):"")),h.push(chalk.gray("[quit]")+(t?chalk.gray(" 退出"):""));const m=e(a);console.log(chalk.gray(" "+a)),console.log(chalk.gray(" "+(t?`第 ${o.number} / ${n.totalCards} 张`:`Card ${o.number} / ${n.totalCards}`)));let f="",$=0;for(const o of h){const n=e(o);f&&$+2+n>m?(console.log(" "+f),f=o,$=n):(f=f?f+l+o:o,$=f===o?n:$+2+n)}f&&console.log(" "+f),console.log(" "+chalk.magenta("✍ ")+chalk.magenta("[/py]")+chalk.gray(t?" Python 草稿本":" Python scratchpad")+l+chalk.magenta("[/pylist]")+chalk.gray(t?" 我的草稿":" my files")),console.log(chalk.gray(" "+a));const w=[t?"e = 就这张卡提问,或报告问题":"e = ask about this card, or report a problem",t?"更多: bookmark / unbookmark · status · lang · link":"more: bookmark / unbookmark · status · lang · link"];for(const e of w)for(const o of wrapMixed(e,m))console.log(chalk.gray(" "+o));D(),console.log()}(t,r)}export function renderCheckFeedback(e,o,n,t=!1){const r=g().startsWith("zh");if(console.log(),n)console.log(chalk.green(" ✓ ")+chalk.white(r?"答对了。":"Correct."));else if(console.log(chalk.yellow(" ✗ ")+chalk.white(r?"记下了,继续。":"Noted — moving on.")),t){const o="y"===e.check?.answer?r?"是":"Yes":r?"否":"No";console.log(chalk.gray(" "+(r?"正确答案: ":"Answer: ")+o+". "+(r?"回看上面那段。":"Re-read the paragraph above.")))}const a=r?e._zh?.solution??e.solution:e.solution;if(a&&a.length>0){console.log(),console.log(chalk.cyan(" 📝 "+(r?"解答:":"Worked solution:")));for(const e of a){for(const o of wrapMixed(e,d()-4))console.log(chalk.white(" "+o));console.log()}}console.log()}function G(e){return[chalk.white(" "+(e?"编著:Charlie Zhu":"Created & edited by Charlie Zhu")),chalk.gray(" "+(e?"ICOA 2026 创始人 · 课程总架构师":"Founder & Chief Curriculum Architect · ICOA 2026"))]}export function renderPhaseComplete(e,o,n,r,l,s){const c=t(n.cardRange[1]-n.cardRange[0]+1),i=g().startsWith("zh"),[h,y]=n.cardRange,u=o.checkResults||{};let p=0,b=0;for(let e=h;e<=y;e++){const o=u[String(e)];o&&(p++,o.correct&&b++)}const m="-".repeat(48);console.log();for(const e of a(" "))console.log(e);console.log(),console.log(chalk.bold.yellow(" "+m)),console.log(chalk.bold.yellow(" "+(i?`阶段 ${n.number} 完成`:`Phase ${n.number} complete`))+chalk.gray(" · ")+chalk.white(n.name));const f=p>0&&b===p?chalk.bold.green:chalk.bold.white;console.log(chalk.gray(" "+(i?"理解检查得分: ":"comprehension score: "))+f(`${b}/${p}`)+chalk.gray(0===p?i?" (本阶段未作答 y/n)":" (no y/n answered)":""));const $=String(y).length;let w=!1,k=0,_=0,x=0,C=0;for(let o=h;o<=y;o++){const n=e.cards.find(e=>e.number===o);if(!n)continue;const t=n,r=t.title??t.badge??"",a=(i?t._zh?.title??t._zh?.badge??r:r)||"",l=null!=n.check,s=u[String(o)];let c;c=s?s.correct?chalk.green("✓"):chalk.red("✗"):l?chalk.gray("○"):chalk.gray("·");const g=Y?Y(o):null;g&&(w=!0);const h=g?(g.solved>=g.total?chalk.green:g.solved>0?chalk.yellow:chalk.gray)(` ⚔${g.solved}/${g.total}`):"";g&&(k++,g.solved>=g.total&&_++,x+=g.solved,C+=g.total);const y=wrapMixed(a,d()-10-$-(g?6:0)),p=y[0]+(y.length>1?"…":"");console.log(chalk.gray(` ${String(o).padStart($)} `)+c+h+chalk.white(" "+p))}if(console.log(chalk.gray(i?" ✓ 答对 · ✗ 答错 · ○ 未作答 · 无 y/n 的卡不计分":" ✓ correct · ✗ wrong · ○ unanswered · cards without a y/n are unscored")),w&&console.log(chalk.bold.cyan(" ⚔ "+(i?"卡片练习: ":"practice: "))+(_>=k?chalk.bold.green:chalk.bold.white)(`${_}/${k}`)+chalk.gray(i?` 卡全完成 · ${x}/${C} 题 AC · 行内 ⚔已过/共(绿 完成 · 黄 部分 · 灰 未碰)`:` cards complete · ${x}/${C} problems AC · ⚔solved/total per row (green done · yellow partial · gray untouched)`)),l){const e=e=>"green"===e?chalk.bold.green:"blue"===e?chalk.bold.cyan:"yellow"===e?chalk.bold.yellow:chalk.bold.red;console.log(chalk.bold.magenta(" ⭐ "+(i?"提问得分 (best): ":"Prompt scores (best): "))+(0===l.length?chalk.gray(i?"本阶段尚未提问 — 用 /ai 研究,再 /submit 评分":"none this phase — research with /ai, then /submit"):l.map(o=>chalk.gray((i?"卡":"#")+o.card+" ")+e(o.tier)(String(o.score))).join(chalk.gray(" · "))))}if(s&&!s.configured){const o=y-h+1>12,n="fill"===e.practiceMode;console.log(chalk.gray(o?i?" 🔒 本阶段通关标准制作中 — 很快更新(360 层第二阶段标准设计中)":" 🔒 Pass criteria for this phase are in production — coming soon (360-tier second-stage standard in design)":n?i?c.n>1?` 🔒 本阶段 ${c.n} 场判分赛制作中 — 很快更新;赛场挂在卡 ${c.cards},${c.n} 场全过解锁下一阶段(本轨无 research)`:` 🔒 本阶段的判分赛制作中 — 很快更新;赛场挂在卡 ${c.cards},通过即解锁下一阶段(本轨无 research)`:c.n>1?` 🔒 This phase’s ${c.n} judged arenas are in production — coming soon; they hang on cards ${c.cards} and all ${c.n} unlock the next phase (no research on this track)`:` 🔒 This phase’s judged arena is in production — coming soon; it hangs on card ${c.cards} and passing it unlocks the next phase (no research on this track)`:i?" 🔒 本阶段通关标准制作中 — 很快更新(标准范式:3 场练习赛 + 3 卡研究)":" 🔒 Pass criteria for this phase are in production — coming soon (standard: 3 arenas + 3 research cards)"))}if(s?.configured&&s.contest){const e=s.contest;if(e.slots&&e.slots.length>0)for(const o of e.slots){const e=chalk.bold.cyan(` ⚔ ${i?"练习赛":"arena"} ${n.number}-${o.slot}: `);o.passed?console.log(e+chalk.bold.green(`${o.best_ac}/${o.n} AC ✅`)):0===o.attempts?console.log(e+chalk.white(i?`${o.n} 题 · 过 ${o.need} 题 — `:`${o.n} problems · AC ${o.need} — `)+chalk.bold.green(`contest ${o.slot}`)):console.log(e+chalk.yellow(i?`最好 ${o.best_ac}/${o.n}(需 ${o.need})· 已试 ${o.attempts} 次 — `:`best ${o.best_ac}/${o.n} (need ${o.need}) · ${o.attempts} attempt(s) — `)+chalk.bold.green(`contest ${o.slot}`))}else{const o=chalk.bold.cyan(" ⚖ "+(i?"判分赛: ":"Contest: "));e.passed?console.log(o+chalk.bold.green(`${e.best_ac}/${e.n} AC ✅ `+(i?"已过关":"passed"))):0===e.attempts?console.log(o+chalk.white(i?`${e.n} 题 · 过 ${e.need} 题解锁 — 输入 `:`${e.n} problems · AC ${e.need} to pass — type `)+chalk.bold.green("contest")+chalk.white(i?" 开始":" to start")):console.log(o+chalk.yellow(i?`最好 ${e.best_ac}/${e.n} AC(需 ${e.need})· 已试 ${e.attempts} 次 — 输入 `:`best ${e.best_ac}/${e.n} AC (need ${e.need}) · ${e.attempts} attempt(s) — type `)+chalk.bold.green("contest")+chalk.yellow(i?" 再战":" to retry"))}}r&&console.log(chalk.gray(" "+(i?"下一阶段: ":"next: "))+chalk.bold.cyan(i?`阶段 ${r.number}`:`Phase ${r.number}`)+chalk.gray(" · ")+chalk.white(r.name)),console.log(chalk.bold.yellow(" "+m));for(const e of G(i))console.log(e)}export function renderCurriculumComplete(e,o){const n=g().startsWith("zh"),t=o.checkResults||{},r="-".repeat(48);let l=0,s=0;console.log();for(const e of a(" "))console.log(e);console.log(),console.log(chalk.bold.green(" "+r)),console.log(chalk.bold.green(" 🏆 "+(n?`${e.name} — 全部完成!`:`${e.name} — complete!`))),console.log(chalk.bold.green(" "+r));for(const o of e.modules){const[e,r]=o.cardRange;let a=0,c=0;for(let o=e;o<=r;o++){const e=t[String(o)];e&&(a++,e.correct&&c++)}l+=a,s+=c;const g=a>0&&c===a?chalk.green:chalk.white;console.log(chalk.gray(" "+(n?`阶段 ${o.number}`:`Phase ${o.number}`).padEnd(8))+g(`${c}/${a}`.padEnd(7))+chalk.gray(o.name))}console.log(chalk.bold.green(" "+r)),console.log(chalk.bold.green(" "+(n?"总分 / overall: ":"Overall: "))+chalk.bold.white(`${s}/${l}`)),console.log(chalk.bold.green(" "+r));for(const e of G(n))console.log(e);console.log()}export function renderMCQCard(e,t){const r=g(),a=o(e,r);b(a,t),$(),f(chalk.bold.yellow("🎯 "+a.title)),f(chalk.gray("─".repeat(Math.min(a.title.length+4,d())))),$();for(const e of W(a.question,d()-4))f(" "+e);$();for(const e of["A","B","C","D"])f(chalk.cyan(` ${e}.`)+" "+chalk.white(a.options[e]));$(),m(),console.log(chalk.gray(" "+(r.startsWith("zh")?"输入 ":"Type "))+chalk.bold.green("A")+chalk.gray(" / ")+chalk.bold.green("B")+chalk.gray(" / ")+chalk.bold.green("C")+chalk.gray(" / ")+chalk.bold.green("D")+chalk.gray(" "+n("type_to_answer",r))),console.log(chalk.gray(" ")+chalk.bold.cyan("back")+chalk.gray(r.startsWith("zh")?" 上一张 · ":" previous card · ")+chalk.bold.cyan("card N")+chalk.gray(r.startsWith("zh")?" 跳转":" jump")),console.log()}export function renderMCQFeedback(e,t,r,a){const l=g(),s=o(e,l);console.log(),r?console.log(" "+chalk.bold.green(n("correct",l)+" ")+chalk.gray(`${n("one_point",l)} · ${t} = ${s.options[t]}`)):console.log(" "+chalk.bold.red(n("not_quite",l)+" ")+chalk.gray(`${n("you_chose",l)} ${t}; ${n("answer_is",l)} ${s.answer}.`)),console.log(),console.log(chalk.gray(" "+n("explanation",l)));for(const e of W(s.explanation,d()-4))console.log(chalk.gray(" "+e));const c=Object.values(a.mcqResults),i=c.filter(e=>e.correct).length;console.log(),console.log(chalk.gray(" "+n("mcq_accuracy_so_far",l)+" ")+chalk.white(`${i}/${c.length}`)),console.log(),r||(console.log(chalk.gray(" "+n("press_ok_continue",l)+" ")+chalk.bold.green("ok")+chalk.gray(" "+n("to_continue",l))),console.log())}export function renderPracticalCard(e,t){const r=g(),a=o(e,r);b(a,t),$(),f(chalk.bold.yellow("🛠 "+a.title)),f(chalk.gray("─".repeat(Math.min(a.title.length+4,d())))),$();for(const e of W(a.task,d()-4))f(" "+e);if(a.starterCode){$(),f(chalk.gray(" "+n("starter_code",r))),$();for(const e of a.starterCode.split("\n"))f(" "+chalk.cyan(e))}$(),m(),console.log(chalk.gray(" "+n("try_in_sandbox",r)+" ")+chalk.bold.cyan("!python3")+chalk.gray(" "+n("drops_into_python",r))),console.log(chalk.gray(" "+n("when_done",r))),console.log(chalk.gray(" ")+chalk.bold.green("done")+chalk.gray(" "+n("done_desc",r))),console.log(chalk.gray(" ")+chalk.bold.yellow("skip")+chalk.gray(" "+n("skip_desc",r))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log()}export function renderPracticalSuccess(e){const t=g(),r=o(e,t);console.log(),console.log(" "+chalk.bold.green(n("practical_recorded",t))),console.log(),console.log(chalk.gray(" "+n("reference_answer",t)));for(const e of W(r.successHint,d()-4))console.log(chalk.gray(" "+e));console.log(),console.log(chalk.gray(" "+n("press_ok_continue",t)+" ")+chalk.bold.green("ok")+chalk.gray(" "+n("to_continue",t))),console.log()}export function renderSimDemoCard(e,t){const r=g(),a=o(e,r);b(a,t),$(),f(chalk.bold.yellow("🎬 "+a.title)),$();for(const e of W(a.description,d()-4))f(" "+e);$(),f(chalk.gray(" "+n("sim_requires",r))),$(),m(),console.log(chalk.gray(" ")+chalk.bold.cyan("sim")+chalk.gray(" "+n("sim_launch_desc",r))),console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(" "+n("continue_to_next",r))),console.log(chalk.gray(" bookmark "+n("bookmark_desc",r))),console.log(chalk.gray(" back "+n("back_desc",r))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+n("quit_desc",r))),console.log()}export function renderArenaTaskCard(e,n){const t=g(),r=t.startsWith("zh"),a=o(e,t);b(a,n),$(),f(chalk.bold.cyan("🏟 "+a.title)),f(chalk.gray(" "+a.origin+" · "+a.domain+" · "+a.metric)),$();for(const e of a.statement){for(const o of W(e,d()-4))f(" "+o);$()}f(chalk.bold.green(r?" 核心要点 — baseline → 解法的关键变化":" CORE DELTA — baseline → solution"));for(const e of a.core_delta)for(const o of W("• "+e,d()-6))f(" "+chalk.white(o));$(),f(chalk.gray((r?" 提交格式: ":" Submission: ")+a.submission_format)),a.hints&&f(chalk.gray(r?" 本题有 5 级提示 (a–e),进入 arena 后逐级解锁。":" 5 progressive hints (a–e) unlock inside the arena.")),$(),m(),console.log(chalk.gray(" ")+chalk.bold.cyan("arena "+a.task_id)+chalk.gray(r?" 动手做这道题(下载 / 提示 / 提交 / 榜单)":" open the arena (download / hints / submit / board)")),console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(r?" 继续下一张":" continue to next")),console.log(chalk.gray(" back "+(r?"上一张":"previous"))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+(r?"退出":"exit"))),console.log()}export function renderComingSoonCard(e,n){const t=g(),r=t.startsWith("zh"),a=o(e,t);b(a,n),$(),f(chalk.bold.yellow("🔜 "+a.title)),$();const l=a.note||(r?"这道竞技场题目正在编写中,敬请期待。":"This arena task is coming soon.");for(const e of W(l,d()-4))f(" "+chalk.gray(e));$(),m(),console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(r?" 继续":" continue")),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+(r?"退出":"exit"))),console.log()}export function renderMilestone(e,t){const r=g(),a=o(e,r),l=e.number===t.totalCards;console.log(),console.log(chalk.bold.yellow(" ╭"+h("═"))),console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+chalk.white(" "+n("milestone_header",r))),console.log(chalk.bold.yellow(" ║"));const s=` ${a.badge} ${a.emoji}`;console.log(chalk.bold.yellow(" ║ ")+chalk.bold.green(s)),console.log(chalk.bold.yellow(" ║ ")+chalk.gray(" ─".repeat(Math.max(1,Math.floor(a.badge.length/2+2))))),console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+" "+chalk.gray(n("in_wild_corresponds",r)));for(const e of W(a.realWorldLevel,d()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(e));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+" "+chalk.gray(n("whats_next",r)));for(const e of W(a.unlockedNext,d()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(e));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ╰"+h("═"))),console.log(),l?(console.log(chalk.gray(" "+n("demo_complete",r))),console.log(),console.log(chalk.gray(" "+n("unlock_full",r)+" ")+chalk.white(n("curriculum_name",r))+chalk.gray(",")),console.log(chalk.gray(" "+n("contact_team_leader",r)+" ")+chalk.bold.yellow("EA")+chalk.gray(" "+n("learn_token",r))),console.log(chalk.gray(" "+n("or_email",r)+" ")+chalk.cyan("australia@icoa2026.au")+chalk.gray(" "+n("for_partnership",r))),console.log(),console.log(chalk.gray(" "+n("type_quit",r)+" ")+chalk.bold.green("quit")+chalk.gray(" "+n("to_exit",r)+" ")+chalk.bold.green("status")+chalk.gray(" "+n("for_dashboard",r)))):(console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(" "+n("continue_to_next",r))),console.log(chalk.gray(" status "+n("status_full",r))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+n("quit_desc",r)))),console.log()}export function renderStatus(o,t,r={}){const a=g(),l=a.startsWith("zh"),s=t.cardsCompleted.length,c=o.totalCards,i=t.checkResults||{},h=r.gate??null,b=!!r.gated,w=r.focus??"current",k=r.posForSlot??(e=>4===e?10:4*e),_=e=>r.practiceCount?r.practiceCount(e):Y?Y(e):null,x=t.currentCard,C=o.modules.find(e=>x>=e.cardRange[0]&&x<=e.cardRange[1]),v=(o,n)=>o+" ".repeat(Math.max(0,n-e((e=>e.replace(/\x1b\[[0-9;]*m/g,""))(o))));console.log();const M=`${o.name} — ${l?"状态":"Status"}`;console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(M)+" "+chalk.cyan("─".repeat(Math.max(4,d()-2-e(M))))),$(),f(" "+chalk.gray(n("total_progress",a)+" ")+u(s,c)+chalk.gray(` (${s}/${c})`)+chalk.gray(" "+n("streak",a)+" ")+p(t.streakDays));{let n=0,a=0,s=0,c=0,g=0,y=0,u=!1;for(const e of o.modules){for(let t=e.cardRange[0];t<=e.cardRange[1];t++){const e=_(t);e&&(n++,e.solved>=e.total&&a++);const r=o.cards.find(e=>e.number===t);null!=r?.check&&(s++,i[String(t)]?.correct&&c++)}const t=h?.phases.find(o=>o.phase===e.number);if(t?.configured)for(const e of t.contest?.slots??[])g++,e.passed&&y++;t?.research&&(u=!0)}const p=(e,o)=>(e>=o?chalk.green:chalk.white)(`${e}/${o}`),b=[];n&&b.push(chalk.gray(l?"⚔ 练习卡 ":"⚔ practice cards ")+p(a,n)),g&&b.push(chalk.gray(l?"赛场 ":"arena ")+p(y,g)),s&&b.push(chalk.gray(l?"✓ 自测 ":"✓ checks ")+p(c,s)),b.length&&f(" "+b.join(chalk.gray(" "))),r._anyResearch=u;{let n=0;const r=[];let a=0,c=0,h=0;for(const e of o.modules)for(let l=e.cardRange[0];l<=e.cardRange[1];l++){c++,t.cardsCompleted.includes(l)&&a++;const e=o.cards.find(e=>e.number===l);null!=e?.check&&i[String(l)]&&h++;const s=_(l);s&&s.solved<s.total&&(n+=s.total-s.solved,r.push(l))}const u=l?"▸ 通关还差 ":"▸ to finish ",p=[];if(a<c&&p.push(chalk.gray(l?"卡片 ":"cards ")+chalk.white(""+(c-a))+chalk.gray(l?" 张未读":" unread")),s&&h<s&&p.push(chalk.gray("✓ ")+chalk.white(""+(s-h))+chalk.gray(l?" 题自测未答":" checks unanswered")),n>0){const o=l?`练习还差 ${n} 题`:`${n} practice problem${n>1?"s":""}`,t=l?"(卡 ":" (cards ",a=")",s=" │ ⚔ ",c=d()-e(s)-e(u)-e(o)-e(t+a),g=e=>{const o=[];let n=0;for(const t of r){const r=String(t).length+(o.length?3:0);if(n+r>e)break;n+=r,o.push(t)}return o};let i=g(c);i.length<r.length&&(i=g(c-e(` +${r.length}`))),!i.length&&r.length&&(i=[r[0]]);const h=r.length-i.length,y=i.join(" · ")+(h>0?` +${h}`:"");p.push(chalk.gray("⚔ ")+chalk.white(o)+chalk.gray(t+y+a))}g&&y<g&&p.push(chalk.gray(l?"赛 ":"arena ")+chalk.white(""+(g-y))+chalk.gray(l?" 场未过":" to pass"));const b=a>0;b&&p.length?p.forEach((o,n)=>f(" "+(0===n?chalk.bold.yellow(u):" ".repeat(e(u)))+o)):b&&!p.length&&f(" "+chalk.bold.green(l?"✅ 通关条件已全部达成":"✅ every completion gate met"))}}$();const S=e=>l?`阶段 ${e}`:`Phase ${e}`,j=Math.max(10,Math.min(28,d()-54));for(const e of o.modules){const[n,r]=e.cardRange,a=r-n+1,s=t.cardsCompleted.filter(e=>e>=n&&e<=r).length,c=b&&!!h&&e.number>h.unlocked_through_phase,g=h?.phases.find(o=>o.phase===e.number);let u=0,p=0,m=0;const $=[],M=[];let A=0,W=0,z=0;const L=[];for(let e=n;e<=r;e++){const n=o.cards.find(o=>o.number===e);if(null!=n?.check){u++;const o=i[String(e)];o?(p++,o.correct?m++:M.push(e)):$.push(e)}const t=_(e);t&&(A++,z+=t.solved,t.solved>=t.total?W++:L.push(`${e}:${t.solved}/${t.total}`))}const R=g?.configured?g.contest?.slots??[]:[],P=e=>e.passed?chalk.green("✅"):e.attempts>0?chalk.yellow("❌"):chalk.gray("⬜"),E=s>=a&&(0===u||m===u)&&(0===A||W===A)&&(0===R.length||R.every(e=>e.passed))&&(!g?.research||g.research.passed),q=s>0||p>0||z>0||R.some(e=>e.attempts>0),T=c?chalk.gray("🔒"):E?chalk.green("✅"):e.number===C?.number?chalk.bold.cyan("▶ "):q?chalk.yellow("▶ "):chalk.gray("⬜"),N=y(e.name,j),F=[];if(F.push((s>=a?chalk.green:chalk.white)(`${s}/${a}`)+chalk.gray(l?"卡":"c")),u>0&&F.push(chalk.gray("✓")+(m===u?chalk.green:chalk.white)(`${m}/${u}`)),A>0&&F.push(chalk.gray("⚔")+(W===A?chalk.green:chalk.white)(`${W}/${A}`)+chalk.gray(l?"卡":"c")),R.length>0&&F.push(chalk.gray(l?"赛":"arena ")+R.map(P).join("")),g?.research&&F.push(chalk.gray("⭐")+(g.research.passed?chalk.green:chalk.white)(`${g.research.good_cards}/${g.research.need_cards}`)),f(" "+T+" "+chalk.white(v(S(e.number),l?5:8))+chalk.gray(v(N,j+1))+F.join(chalk.gray(" · "))),c||"all"!==w&&w!==e.number&&("current"!==w||e.number!==C?.number)){if(!c&&q&&!E){const o=[],t=R.filter(e=>!e.passed).map(o=>(o.attempts>0?chalk.yellow:chalk.gray)(`${e.number}-${o.slot}@${l?"卡":"card "}${n+k(o.slot)-1}`));t.length&&o.push(chalk.gray(l?"赛 ":"arena ")+t.join(chalk.gray(" · ")));const r=(e,o)=>e.slice(0,8).join(o)+(e.length>8?chalk.gray(" +"+(e.length-8)):"");L.length&&o.push(chalk.gray("⚔ ")+chalk.white(r(L," "))),M.length&&o.push(chalk.red("✗ ")+chalk.white(r(M.map(String),","))),$.length&&o.push(chalk.gray("○ ")+chalk.white(r($.map(String),","))),g?.research&&!g.research.passed&&o.push(chalk.gray(`⭐ ${g.research.good_cards}/${g.research.need_cards}`)),o.forEach((e,o)=>f(chalk.gray(0===o?l?" 待办: ":" todo: ":" ")+e))}}else{const t=String(r).length;for(let s=n;s<=r;s++){const r=o.cards.find(e=>e.number===s);if(!r)continue;const c=r,g=c.title??c.badge??"",h=(l?c._zh?.title??c._zh?.badge??g:g)||"",y=null!=r.check,u=i[String(s)],p=u?u.correct?chalk.green("✓"):chalk.red("✗"):y?chalk.gray("○"):chalk.gray("·"),b=_(s),m=b?(b.solved>=b.total?chalk.green:b.solved>0?chalk.yellow:chalk.gray)(`⚔${b.solved}/${b.total}`):" ",$=s===x?chalk.bold.cyan("▶"):" ",w=wrapMixed(h,Math.max(16,d()-14-t)),C=w[0]+(w.length>1?"…":"");f(` ${$} `+chalk.gray(String(s).padStart(t))+" "+p+" "+v(m,5)+" "+chalk.white(C));const M=12===a?R.find(e=>n+k(e.slot)-1===s):void 0;if(M){const o=chalk.gray(` ${" ".repeat(t)} ⚔ ${l?"练习赛":"arena"} ${e.number}-${M.slot}: `);M.passed?f(o+chalk.bold.green(`${M.best_ac}/${M.n} AC ✅`)):0===M.attempts?f(o+chalk.gray("⬜ ")+chalk.white(l?`未开始 · ${M.n} 题 · 过 ${M.need} 题 → `:`not started · ${M.n} problems · AC ${M.need} → `)+chalk.bold.green(`contest ${M.slot}`)):f(o+chalk.yellow(l?`❌ 最好 ${M.best_ac}/${M.n}(需 ${M.need})· 已试 ${M.attempts} 次 → `:`❌ best ${M.best_ac}/${M.n} (need ${M.need}) · ${M.attempts} attempt(s) → `)+chalk.bold.green(`contest ${M.slot}`))}}if(12!==a)for(const o of R){const n=chalk.gray(` ⚔ ${l?"练习赛":"arena"} ${e.number}-${o.slot}: `);o.passed?f(n+chalk.bold.green(`${o.best_ac}/${o.n} AC ✅`)):0===o.attempts?f(n+chalk.gray("⬜ ")+chalk.white(l?`未开始 · ${o.n} 题 · 过 ${o.need} 题 → `:`not started · ${o.n} problems · AC ${o.need} → `)+chalk.bold.green(`contest ${o.slot}`)):f(n+chalk.yellow(l?`❌ 最好 ${o.best_ac}/${o.n}(需 ${o.need})· 已试 ${o.attempts} 次 → `:`❌ best ${o.best_ac}/${o.n} (need ${o.need}) · ${o.attempts} attempt(s) → `)+chalk.bold.green(`contest ${o.slot}`))}g?.research&&!g.research.passed&&f(chalk.gray(l?` ⭐ 研究: ${g.research.good_cards}/${g.research.need_cards} 卡达 ${g.research.min_score} 分 — /ai 研究后 /submit`:` ⭐ research: ${g.research.good_cards}/${g.research.need_cards} cards at ${g.research.min_score}+ — /ai then /submit`)),g&&!g.configured&&f(chalk.gray(l?" 🔒 本阶段通关标准制作中 — 很快更新":" 🔒 pass criteria for this phase in production — coming soon"))}}$(),f(chalk.gray(l?" ✓ 答对 ✗ 答错 ○ 未答 · ⚔ 练习 已过/共 · 赛 ✅ 过 ❌ 试过 ⬜ 未碰"+(r._anyResearch?" · ⭐ 研究":""):" ✓ right ✗ wrong ○ unanswered · ⚔ practice solved/total"+(r._anyResearch?" · ⭐ research":""))),f(chalk.gray(l?" 展开某阶段: ":" arena ✅ passed ❌ tried ⬜ untouched · expand: ")+chalk.bold.green("status all")+chalk.gray(" / ")+chalk.bold.green("status N")),t.achievements.length>0&&f(" "+chalk.gray(n("achievements",a)+" ")+t.achievements.map(e=>chalk.bold.yellow("★ ")+chalk.white(e)).join(chalk.gray(" · "))),$(),m()}function K(e){try{Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}catch{}}export function renderArenaIntro(e=12){const o=g().startsWith("zh"),n=t(e),r=["","one","two","three"][n.n]??String(n.n),a=learnCheckpointVerb(),l=!!process.stdout.isTTY&&!/^(C|POSIX)$/i.test(process.env.LANG||"")&&!process.env.ICOA_TEST_BOOT_MODE,s=o?[chalk.bold.yellow(" ⚔ 你读完 4 张卡了 — 前面是第一个检查点。"),n.n>1?chalk.white(" ⚔ 每 4 张卡有一场判分赛:")+chalk.bold.yellow(`卡 ${n.cards}`)+chalk.white(`,一个阶段共 ${n.n} 场。`):chalk.white(" ⚔ 每个阶段有一场判分赛:")+chalk.bold.yellow(`卡 ${n.cards}`)+chalk.white("。"),...a?[chalk.white(" · 敲 ")+chalk.bold.green(a)+chalk.white(" 进竞技场 — ")+chalk.bold.green("battle"===a?"play":"run")+chalk.white(" 本机试跑,")+chalk.bold.green("submit")+chalk.white(" 交给判分机;第一次 submit 时计时开始。")]:[chalk.white(" · 敲 ")+chalk.bold.green("contest 1")+chalk.white(" 开始 — 计时器同时开始,题目在赛场里读。")],chalk.white(" · 判分机会真的跑你的代码,不是对答案。"),chalk.white(n.n>1?` · ${n.n} 场全过 → 解锁下一阶段。`:" · 过了这一场 → 解锁下一阶段。"),chalk.gray(" ▸ 现在不想打?敲 ")+chalk.bold.green("next")+chalk.gray(" 继续读卡,赛场一直在那儿等你。")]:[chalk.bold.yellow(" ⚔ Four cards down — a checkpoint is waiting."),n.n>1?chalk.white(" ⚔ Every 4 cards there is a judged arena: ")+chalk.bold.yellow(`cards ${n.cards}`)+chalk.white(`, ${r} per phase.`):chalk.white(" ⚔ Each phase has one judged arena: ")+chalk.bold.yellow(`card ${n.cards}`)+chalk.white("."),...a?[chalk.white(" · Type ")+chalk.bold.green(a)+chalk.white(" to enter the arena — ")+chalk.bold.green("battle"===a?"play":"run")+chalk.white(" to try it here, ")+chalk.bold.green("submit")+chalk.white(" to send it to the judge; the clock starts at your first submit.")]:[chalk.white(" · Type ")+chalk.bold.green("contest 1")+chalk.white(" to start — the clock starts with it; the problems are read inside.")],chalk.white(" · The judge really runs your code. It is not an answer key."),chalk.white(n.n>1?` · Pass all ${r} → the next phase unlocks.`:" · Pass it → the next phase unlocks."),chalk.gray(" ▸ Not now? Type ")+chalk.bold.green("next")+chalk.gray(" and keep reading — the arena waits for you.")];console.log();for(const e of s)console.log(e),l&&K(200);console.log()}
|
|
1
|
+
import chalk from"chalk";import e from"string-width";import{localized as o}from"./learn-curricula.js";import{t as n}from"./learn-i18n.js";import{arenaCadence as t}from"./learn-contest.js";import{getConfig as r}from"./config.js";import{icoaBannerLines as a}from"./banner.js";import{renderCharts as l,detectCaps as s}from"./render-card.js";import{replyChipLabel as c}from"./learn-replies.js";function g(){return(r().language||"en").toLowerCase()}let i="normal";export function resolveLearnWidth(e){return"normal"===e.learnWidth||"wide"===e.learnWidth||"wider"===e.learnWidth||"widest"===e.learnWidth?e.learnWidth:e.learnWide?"wide":"normal"}export function setLearnWidth(e){i=e}export function learnWidthCap(e=i){return"widest"===e?160:"wider"===e?120:"wide"===e?96:64}export function learnW(){const e=process.stdout.columns||69,o=Math.max(40,Math.min(64,e-5));return"normal"===i?o:Math.max(o,Math.min(e-6,learnWidthCap()))}const d=learnW;function h(e="─"){return e.repeat(d()+2)}function y(o,n){if(e(o)<=n)return o;let t=o;for(;t.length>0&&e(t)>Math.max(1,n-1);)t=t.slice(0,-1);return t.trimEnd()+"…"}function u(e,o,n=20){const t=o>0?e/o:0,r=Math.floor(t*n),a=n-r;return`${chalk.green("█".repeat(r))+chalk.gray("░".repeat(a))} ${(100*t).toFixed(1)}%`}function p(e){return e>=30?chalk.red("🔥🔥🔥 "+e+" days"):e>=7?chalk.yellow("🔥 "+e+" days"):e>=1?chalk.gray("· "+e+" day"+(e>1?"s":"")):chalk.gray("—")}export function renderWelcome(e,o,t){const r=g(),a=o.cardsCompleted.length,l=e.totalCards,s=l-a,c=e.modules.find(e=>o.currentCard>=e.cardRange[0]&&o.currentCard<=e.cardRange[1]),i=/demo/i.test(e.id);if(console.log(),console.log(chalk.cyan(" ╭"+h("═"))),console.log(chalk.cyan(" ║")),console.log(chalk.cyan(" ║ ")+chalk.bold.white(" "+(e.name?.trim()||n("academy_title",r)))),console.log(chalk.cyan(" ║")),t)console.log(chalk.cyan(" ║ ")+chalk.white(" "+n(i?"welcome_new_demo":"welcome_new",r)));else{const e=new Date(o.lastSeenAt),t=Math.floor((Date.now()-e.getTime())/36e5),a=t<1?n("just_now",r):t<24?`${t}${n("ago_hours",r)}`:`${Math.floor(t/24)}${n("ago_days",r)}`;console.log(chalk.cyan(" ║ ")+chalk.white(` ${n("welcome_back",r)} ${a}`))}console.log(chalk.cyan(" ║"));const b=y(c?`${c.number}. ${c.name}`:"—",d()-14);console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("module",r).padEnd(11))+chalk.white(b)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("progress",r).padEnd(11))+u(a,l,Math.max(6,Math.min(20,d()-26-`${a}/${l}`.length)))+chalk.gray(` (${a}/${l})`)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("streak",r).padEnd(11))+p(o.streakDays)),s>0&&o.currentCard<=l&&console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("next_card",r).padEnd(11))+chalk.white(`#${o.currentCard} ${n("of",r)} ${l}`)),console.log(chalk.cyan(" ║")),console.log(chalk.cyan(" ╰"+h("═"))),console.log(),console.log(chalk.gray(" ─────────────────────────────────────────────"));const m=0===a?n("continue_start",r):`${n("continue_resume",r)} ${o.currentCard}`;console.log(chalk.bold.green(" continue")+chalk.gray(" "+m)),console.log(chalk.yellow(" status")+chalk.gray(" "+n("status_full",r))),o.bookmarks.length>0&&console.log(chalk.yellow(" bookmarks")+chalk.gray(` ${o.bookmarks.length} ${n("bookmarks_desc",r)}`)),console.log(chalk.gray(" quit")+chalk.gray(" "+n("quit_desc",r))),console.log(chalk.gray(" ─────────────────────────────────────────────")),console.log()}function b(o,t){const r=g(),a=o.module,l=t.modules.find(e=>e.number===a),s=l?l.name:n("unknown_module",r),c=n("module",r).replace(":","").trim(),i=y(`${n("card",r)} ${o.number} / ${t.totalCards} · ${c} ${a} · ${s}`,d()-4);console.log(),console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(i)+" "+chalk.cyan("─".repeat(Math.max(0,d()-e(i)-4))))}function m(){console.log(chalk.cyan(" ╰"+h())),console.log()}function f(e){console.log(chalk.cyan(" │ ")+chalk.white(e))}function w(){console.log(chalk.cyan(" │"))}const $=/[┌┐└┘├┤┬┴┼─│╔╗╚╝═║╠╣╦╩╬▓▒░█]/;function k(e){return/^(?: {4}|\t)/.test(e)||$.test(e)||/ {3,}/.test(e)}const _=/[\u0E00-\u0E7F]/;function x(e){try{return new Intl.Segmenter("th",{granularity:e})}catch{return null}}const C=x("word"),v=x("grapheme");export function wrapMixed(o,n){const t=[];let r="",a=0,l=!1;for(const s of function(o){const n=[],t=o=>{let t="",r="";const a=()=>{t&&(n.push({t:"atom",s:t}),t="")},l=()=>{if(r){if(a(),C)for(const{segment:e}of C.segment(r))if(e.length<=20)n.push({t:"atom",s:e});else if(v)for(const o of v.segment(e))n.push({t:"atom",s:o.segment});else for(const o of e)n.push({t:"atom",s:o});else for(const e of r)n.push({t:"atom",s:e});r=""}};for(const s of o)" "===s?(l(),a(),n.push({t:"space"})):_.test(s)?r+=s:2===e(s)?(l(),a(),n.push({t:"wide",s:s})):(l(),t+=s);l(),a()},r=/`[^`]*`/g;let a,l=0;for(;null!==(a=r.exec(o));)t(o.slice(l,a.index)),n.push({t:"code",s:a[0]}),l=a.index+a[0].length;return t(o.slice(l)),n}(o)){if("space"===s.t){""!==r&&(l=!0);continue}const o=s.s,c=e("code"===s.t?o.replace(/`/g,""):o),g=l?1:0,i="atom"===s.t&&o.length<=2&&/^[.,;:!?)\]}…'"]+$/.test(o);""!==r&&!i&&a+g+c>n?(t.push(r),r=o,a=c,l=!1):(l&&(r+=" ",a+=1,l=!1),r+=o,a+=c)}return r&&t.push(r),t}const M=/\b(?:Common bug|Common mistake|Common error|Pitfall|Gotcha|Footgun)\b[::]?|\b(?:Warning|Caution)\b[::]|(?:常见错误|常见陷阱|常见误区|陷阱|注意|警告|误区)[::]/gi;function S(e,o){const n=o?chalk.bold.white:chalk.white;let t,r="",a=0;for(M.lastIndex=0;null!==(t=M.exec(e));)t.index>a&&(r+=n(e.slice(a,t.index))),r+=chalk.bold.yellow(t[0]),a=t.index+t[0].length;return a<e.length&&(r+=n(e.slice(a))),r}function j(e,o=!1){let n="",t=0;const r=/`([^`]*)`/g;let a;for(;null!==(a=r.exec(e));)a.index>t&&(n+=S(e.slice(t,a.index),o)),n+=chalk.cyan(a[1]),t=a.index+a[0].length;return t<e.length&&(n+=S(e.slice(t),o)),n}function A(e,o=!1){let n=!1;for(const t of e.split("\n"))if(/^\s*```/.test(t))n=!n;else if(n)console.log(chalk.cyan(" │ ")+chalk.cyan(` ${t}`));else if(""!==t)if(k(t))console.log(chalk.cyan(" │ ")+chalk.white(t));else for(const e of wrapMixed(t,d()-6))console.log(chalk.cyan(" │ ")+` ${j(e,o)}`);else w()}function W(e,o){const n=[];for(const t of e.split("\n"))""!==t?k(t)?n.push(t):n.push(...wrapMixed(t,o)):n.push("");return n}let z=!1,L=!1;export function setLearnAiEnabled(e,o=e){z=e,L=o}let R=new Set;export function setLearnPqsViewCards(e){R=e}let P=new Map;export function setLearnHonorRanks(e){P=e}const q=["①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩"];let E=[];export function setLearnReplies(e){E=e}let T=[];export function setLearnFaqs(e){T=e}let N=null;export function setLearnHometask(e){N=e}let F="full";export function setLearnFooterProfile(e){F=e}let O=null;export function setLearnFooterExtra(e){O=e}function D(){const e=O?.();e&&console.log(chalk.gray(" "+e))}let I=null;export function setLearnPracticeChips(e){I=e}let B=!1;export function setLearnShellLane(e){B=e}let H=!1,Q=new Map;export function setLearnArenaCards(e){Q=new Map(e.map(e=>[e.card,e.slot]))}export function setLearnArenaLane(e){H=e}export function learnCheckpointVerb(){return V?"duck":null}let V=!1;export function setLearnDuckLane(e){V=e}let Y=null;export function setLearnPracticeCount(e){Y=e}export function renderHonorWall(e){const o=g().startsWith("zh"),{totals:n,chapters:t}=e,r=n.gold+n.silver+n.bronze,a=(e,o)=>o>0?chalk.bold.white(`${e}×${o}`):chalk.gray(`${e}×0`);if(console.log(chalk.gray(" ─────────────────────────────────────────")),console.log(chalk.bold.white(o?" 🏅 奖牌墙 ":" 🏅 Medal wall ")+a("🥇",n.gold)+chalk.gray(" · ")+a("🥈",n.silver)+chalk.gray(" · ")+a("🥉",n.bronze)+chalk.gray(o?" (永久 — 挂上墙就不会摘下)":" (permanent — once earned, never removed)")),0===r){const n=null!=e.floor?`${e.floor}+`:o?"高分":"a high score";return console.log(chalk.gray(o?` 还没有奖牌 — 单卡提问评分 ${n} 并进入该卡前三,即可永久挂墙 🥇🥈🥉`:` No medals yet — score ${n} on a card and hold its top-3 to hang one 🥇🥈🥉`)),void console.log(chalk.gray(" ─────────────────────────────────────────"))}const l=t.map(e=>{const o=`Ch${e.chapter}`,n=(e.gold>0?`🥇${e.gold}`:"")+(e.silver>0?`🥈${e.silver}`:"")+(e.bronze>0?`🥉${e.bronze}`:"");return n?chalk.white(`${o} ${n}`):chalk.gray(`${o} —`)}).join(chalk.gray(" "));console.log(" "+l);const s=t.flatMap(e=>e.cards.map(o=>({...o,chapter:e.chapter})));s.sort((e,o)=>e.rank-o.rank||e.chapter-o.chapter||e.card-o.card);for(const e of s.slice(0,24)){const n=(e.since||"").slice(0,10);console.log(chalk.white(` ${e.icon} `)+chalk.gray(`Ch${e.chapter} · `)+chalk.white(o?`第 ${e.card} 张`:`card ${e.card}`)+chalk.gray(` · ${e.score}`)+(n?chalk.gray(o?` · 始于 ${n}`:` · since ${n}`):""))}s.length>24&&console.log(chalk.gray(o?` …还有 ${s.length-24} 枚`:` …and ${s.length-24} more`)),console.log(chalk.gray(" ─────────────────────────────────────────"))}export function renderKnowledgeCard(t,r){const a=g(),h=o(t,a);b(h,r),w();const y=wrapMixed(h.title,d()-4);for(const e of y)f(chalk.bold.yellow(e));f(chalk.gray("─".repeat(Math.min(Math.max(...y.map(o=>e(o))),d()))));const u=!!(t.chart_ids&&t.chart_ids.length>0);if(u&&l(t.chart_ids.slice(0,1),r.charts,s()),h.key_point&&""!==h.key_point.trim()?(u||w(),function(e,o,n){const t=g().startsWith("zh"),r=s().cols,a="-".repeat(Math.min(d(),Math.max(24,r-6))),l=t?"要点":"KEY POINT",c=t?`第 ${o} / ${n} 张`:`Card ${o} / ${n}`;console.log(chalk.cyan(" │ ")+chalk.green(a)),console.log(chalk.cyan(" │ ")+chalk.green(`${l} · ${c}`));for(const o of wrapMixed(e,d()-6))console.log(chalk.cyan(" │ ")+chalk.bold.green(" "+o));console.log(chalk.cyan(" │ ")+chalk.green(a)),w()}(h.key_point,h.number,r.totalCards)):u||w(),h.body.filter(e=>null!=e&&""!==e.trim()).forEach((e,o)=>{const n=0===o?e.match(/^([\s\S]*?(?:[.!?](?=\s|$)|[。!?]))(\s[\s\S]*)?$/):null;if(n&&n[1].trim().length<=180){A(n[1],!0);const e=n[2]?.trimStart();e&&A(e,!1)}else A(e,!1);w()}),h.icoaConnection){f(chalk.magenta(" "+n("icoa_connection",a))),f(chalk.gray(" "+"─".repeat(20)));for(const e of wrapMixed(h.icoaConnection,d()-6))f(" "+chalk.magenta(e));w()}if(t.check){const e=a.slice(0,2).toLowerCase(),o=t[`_${e}`],n=o?.checkStatement??o?.check?.statement??t.check.statement;for(const o of wrapMixed("zh"===e?"请回答 (输 y 或 n):":"Quick comprehension check (type y or n):",d()-10))f(chalk.cyan(" 🤔 "+o));f(chalk.gray(" "+"─".repeat(20)));for(const e of wrapMixed(n,d()-6))f(" "+chalk.white(e));w()}m(),function(o,n){const t=g().startsWith("zh"),r=s().cols,a="-".repeat(Math.min(d(),Math.max(24,r-6))),l=chalk.gray(" ");if("minimal"===F){const e=I?I(o.number):null;console.log(chalk.gray(" "+a)),console.log(chalk.gray(" "+(t?`第 ${o.number} / ${n.totalCards} 张`:`Card ${o.number} / ${n.totalCards}`))+(e?chalk.gray(t?" · 本卡练习 ":" · practice ")+e:""));const r=[];if(o.check?(r.push(chalk.bold.green("[y]")+chalk.gray(t?" 是":" yes")),r.push(chalk.bold.green("[n]")+chalk.gray(t?" 否":" no"))):r.push(chalk.bold.green("[ok]")+chalk.gray(t?" 下一张":" next")),e){const o=Math.max(1,(e.match(/\[\d\]/g)??[]).length),n=Array.from({length:o},(e,o)=>`[${o+1}]`).join("");r.push(chalk.bold.cyan(n)+chalk.gray(t?" 练习":" practice"))}B&&r.push(chalk.bold.magenta("[sh]")+chalk.gray(t?" 实验台":" shell")),z&&r.push(chalk.bold.magenta("[/ai]")+chalk.gray(t?" 🐼 熊猫导师":" 🐼 Panda tutor"));const s=Q.get(o.number);return H&&s?r.push(chalk.bold.magenta(`[contest ${s}]`)+chalk.gray(t?" 检查点":" checkpoint")):H&&0===Q.size&&r.push(chalk.bold.magenta("[battle]")+chalk.gray(t?" 进竞技场":" arena")),V&&r.push(chalk.bold.magenta("[duck]")+chalk.gray(t?" 跑仿真":" sim bench")),o.flow&&o.flow.length>0&&r.push(chalk.bold.magenta("[flow]")+chalk.gray(t?" 互动走一遍":" walk it")),r.push(chalk.bold.cyan("[b]")+chalk.gray(t?" 上一张":" back")),r.push(chalk.bold.yellow("[e]")+chalk.gray(t?" 求助":" help")),r.push(chalk.gray("[quit]")+(t?chalk.gray(" 退出"):"")),console.log(" "+r.join(l)),D(),void console.log()}const h=[];o.check?(h.push(chalk.bold.green("[y]")+chalk.gray(t?" 是":" yes")),h.push(chalk.bold.green("[n]")+chalk.gray(t?" 否":" no"))):h.push(chalk.bold.green("[ok]")+chalk.gray(t?" 继续":" next")),o.flow&&o.flow.length>0&&h.push(chalk.bold.magenta("[flow]")+chalk.gray(t?" 互动走一遍":" walk it")),z&&h.push(chalk.bold.magenta("[/ai]")+chalk.gray(t?" 🐼 熊猫导师":" 🐼 Panda tutor")),L&&h.push(chalk.bold.magenta("[/submit]")+chalk.gray(t?" 提问评分":" prompt score"));const y=P.get(o.number);var u;h.push(chalk.bold.magenta(y?`[/honors ${u=y,q[u-1]??`#${u}`}]`:"[/honors]")+chalk.gray(t?" 排行":" board")),"normal"===i?h.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 宽屏":" widen")):("wide"===i?h.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 更宽":" wider")):"wider"===i?(h.push(chalk.bold.cyan("[widest]")+chalk.gray(t?" 最宽":" widest")),h.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 回宽屏":" back to wide"))):h.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 回 wider":" back to wider")),h.push(chalk.bold.cyan("[normal]")+chalk.gray(t?" 标准":" standard")));const p=c(E,T,o.number,t),b=p.startsWith("💬");if(h.push((b?chalk.bold.yellow("[r]"):chalk.gray("[r]"))+(b?chalk.bold.white(` ${p}`):chalk.gray(` ${p}`))),h.push(chalk.bold.yellow("[e]")+chalk.gray(t?" 提问或报告":" ask or report")),N){const e=N,o=`${e.done}/${e.total}`,n=e.completedAt?chalk.bold.green:chalk.bold.cyan;h.push(n("[task]")+chalk.gray(t?` 本周 ${o}`:` week ${o}`))}h.push(chalk.bold.cyan("[b]")+chalk.gray(t?" 上一张":" back")),h.push(chalk.bold.cyan("[card N]")+chalk.gray(t?" 跳转":" jump")),h.push(chalk.gray("[reload]")+(t?chalk.gray(" 刷新"):"")),h.push(chalk.gray("[quit]")+(t?chalk.gray(" 退出"):""));const m=e(a);console.log(chalk.gray(" "+a)),console.log(chalk.gray(" "+(t?`第 ${o.number} / ${n.totalCards} 张`:`Card ${o.number} / ${n.totalCards}`)));let f="",w=0;for(const o of h){const n=e(o);f&&w+2+n>m?(console.log(" "+f),f=o,w=n):(f=f?f+l+o:o,w=f===o?n:w+2+n)}f&&console.log(" "+f),console.log(" "+chalk.magenta("✍ ")+chalk.magenta("[/py]")+chalk.gray(t?" Python 草稿本":" Python scratchpad")+l+chalk.magenta("[/pylist]")+chalk.gray(t?" 我的草稿":" my files")),console.log(chalk.gray(" "+a));const $=[t?"e = 就这张卡提问,或报告问题":"e = ask about this card, or report a problem",t?"更多: bookmark / unbookmark · status · lang · link":"more: bookmark / unbookmark · status · lang · link"];for(const e of $)for(const o of wrapMixed(e,m))console.log(chalk.gray(" "+o));D(),console.log()}(t,r)}export function renderCheckFeedback(e,o,n,t=!1){const r=g().startsWith("zh");if(console.log(),n)console.log(chalk.green(" ✓ ")+chalk.white(r?"答对了。":"Correct."));else if(console.log(chalk.yellow(" ✗ ")+chalk.white(r?"记下了,继续。":"Noted — moving on.")),t){const o="y"===e.check?.answer?r?"是":"Yes":r?"否":"No";console.log(chalk.gray(" "+(r?"正确答案: ":"Answer: ")+o+". "+(r?"回看上面那段。":"Re-read the paragraph above.")))}const a=r?e._zh?.solution??e.solution:e.solution;if(a&&a.length>0){console.log(),console.log(chalk.cyan(" 📝 "+(r?"解答:":"Worked solution:")));for(const e of a){for(const o of wrapMixed(e,d()-4))console.log(chalk.white(" "+o));console.log()}}console.log()}function G(e){return[chalk.white(" "+(e?"编著:Charlie Zhu":"Created & edited by Charlie Zhu")),chalk.gray(" "+(e?"ICOA 2026 创始人 · 课程总架构师":"Founder & Chief Curriculum Architect · ICOA 2026"))]}export function renderPhaseComplete(e,o,n,r,l,s){const c=t(n.cardRange[1]-n.cardRange[0]+1),i=g().startsWith("zh"),[h,y]=n.cardRange,u=o.checkResults||{};let p=0,b=0;for(let e=h;e<=y;e++){const o=u[String(e)];o&&(p++,o.correct&&b++)}const m="-".repeat(48);console.log();for(const e of a(" "))console.log(e);console.log(),console.log(chalk.bold.yellow(" "+m)),console.log(chalk.bold.yellow(" "+(i?`阶段 ${n.number} 完成`:`Phase ${n.number} complete`))+chalk.gray(" · ")+chalk.white(n.name));const f=p>0&&b===p?chalk.bold.green:chalk.bold.white;console.log(chalk.gray(" "+(i?"理解检查得分: ":"comprehension score: "))+f(`${b}/${p}`)+chalk.gray(0===p?i?" (本阶段未作答 y/n)":" (no y/n answered)":""));const w=String(y).length;let $=!1,k=0,_=0,x=0,C=0;for(let o=h;o<=y;o++){const n=e.cards.find(e=>e.number===o);if(!n)continue;const t=n,r=t.title??t.badge??"",a=(i?t._zh?.title??t._zh?.badge??r:r)||"",l=null!=n.check,s=u[String(o)];let c;c=s?s.correct?chalk.green("✓"):chalk.red("✗"):l?chalk.gray("○"):chalk.gray("·");const g=Y?Y(o):null;g&&($=!0);const h=g?(g.solved>=g.total?chalk.green:g.solved>0?chalk.yellow:chalk.gray)(` ⚔${g.solved}/${g.total}`):"";g&&(k++,g.solved>=g.total&&_++,x+=g.solved,C+=g.total);const y=wrapMixed(a,d()-10-w-(g?6:0)),p=y[0]+(y.length>1?"…":"");console.log(chalk.gray(` ${String(o).padStart(w)} `)+c+h+chalk.white(" "+p))}if(console.log(chalk.gray(i?" ✓ 答对 · ✗ 答错 · ○ 未作答 · 无 y/n 的卡不计分":" ✓ correct · ✗ wrong · ○ unanswered · cards without a y/n are unscored")),$&&console.log(chalk.bold.cyan(" ⚔ "+(i?"卡片练习: ":"practice: "))+(_>=k?chalk.bold.green:chalk.bold.white)(`${_}/${k}`)+chalk.gray(i?` 卡全完成 · ${x}/${C} 题 AC · 行内 ⚔已过/共(绿 完成 · 黄 部分 · 灰 未碰)`:` cards complete · ${x}/${C} problems AC · ⚔solved/total per row (green done · yellow partial · gray untouched)`)),l){const e=e=>"green"===e?chalk.bold.green:"blue"===e?chalk.bold.cyan:"yellow"===e?chalk.bold.yellow:chalk.bold.red;console.log(chalk.bold.magenta(" ⭐ "+(i?"提问得分 (best): ":"Prompt scores (best): "))+(0===l.length?chalk.gray(i?"本阶段尚未提问 — 用 /ai 研究,再 /submit 评分":"none this phase — research with /ai, then /submit"):l.map(o=>chalk.gray((i?"卡":"#")+o.card+" ")+e(o.tier)(String(o.score))).join(chalk.gray(" · "))))}if(s&&!s.configured){const o=y-h+1>12,n="fill"===e.practiceMode;console.log(chalk.gray(o?i?" 🔒 本阶段通关标准制作中 — 很快更新(360 层第二阶段标准设计中)":" 🔒 Pass criteria for this phase are in production — coming soon (360-tier second-stage standard in design)":n?i?c.n>1?` 🔒 本阶段 ${c.n} 场判分赛制作中 — 很快更新;赛场挂在卡 ${c.cards},${c.n} 场全过解锁下一阶段(本轨无 research)`:` 🔒 本阶段的判分赛制作中 — 很快更新;赛场挂在卡 ${c.cards},通过即解锁下一阶段(本轨无 research)`:c.n>1?` 🔒 This phase’s ${c.n} judged arenas are in production — coming soon; they hang on cards ${c.cards} and all ${c.n} unlock the next phase (no research on this track)`:` 🔒 This phase’s judged arena is in production — coming soon; it hangs on card ${c.cards} and passing it unlocks the next phase (no research on this track)`:i?" 🔒 本阶段通关标准制作中 — 很快更新(标准范式:3 场练习赛 + 3 卡研究)":" 🔒 Pass criteria for this phase are in production — coming soon (standard: 3 arenas + 3 research cards)"))}if(s?.configured&&s.contest){const e=s.contest;if(e.slots&&e.slots.length>0)for(const o of e.slots){const e=chalk.bold.cyan(` ⚔ ${i?"练习赛":"arena"} ${n.number}-${o.slot}: `);o.passed?console.log(e+chalk.bold.green(`${o.best_ac}/${o.n} AC ✅`)):0===o.attempts?console.log(e+chalk.white(i?`${o.n} 题 · 过 ${o.need} 题 — `:`${o.n} problems · AC ${o.need} — `)+chalk.bold.green(`contest ${o.slot}`)):console.log(e+chalk.yellow(i?`最好 ${o.best_ac}/${o.n}(需 ${o.need})· 已试 ${o.attempts} 次 — `:`best ${o.best_ac}/${o.n} (need ${o.need}) · ${o.attempts} attempt(s) — `)+chalk.bold.green(`contest ${o.slot}`))}else{const o=chalk.bold.cyan(" ⚖ "+(i?"判分赛: ":"Contest: "));e.passed?console.log(o+chalk.bold.green(`${e.best_ac}/${e.n} AC ✅ `+(i?"已过关":"passed"))):0===e.attempts?console.log(o+chalk.white(i?`${e.n} 题 · 过 ${e.need} 题解锁 — 输入 `:`${e.n} problems · AC ${e.need} to pass — type `)+chalk.bold.green("contest")+chalk.white(i?" 开始":" to start")):console.log(o+chalk.yellow(i?`最好 ${e.best_ac}/${e.n} AC(需 ${e.need})· 已试 ${e.attempts} 次 — 输入 `:`best ${e.best_ac}/${e.n} AC (need ${e.need}) · ${e.attempts} attempt(s) — type `)+chalk.bold.green("contest")+chalk.yellow(i?" 再战":" to retry"))}}r&&console.log(chalk.gray(" "+(i?"下一阶段: ":"next: "))+chalk.bold.cyan(i?`阶段 ${r.number}`:`Phase ${r.number}`)+chalk.gray(" · ")+chalk.white(r.name)),console.log(chalk.bold.yellow(" "+m));for(const e of G(i))console.log(e)}export function renderCurriculumComplete(e,o){const n=g().startsWith("zh"),t=o.checkResults||{},r="-".repeat(48);let l=0,s=0;console.log();for(const e of a(" "))console.log(e);console.log(),console.log(chalk.bold.green(" "+r)),console.log(chalk.bold.green(" 🏆 "+(n?`${e.name} — 全部完成!`:`${e.name} — complete!`))),console.log(chalk.bold.green(" "+r));for(const o of e.modules){const[e,r]=o.cardRange;let a=0,c=0;for(let o=e;o<=r;o++){const e=t[String(o)];e&&(a++,e.correct&&c++)}l+=a,s+=c;const g=a>0&&c===a?chalk.green:chalk.white;console.log(chalk.gray(" "+(n?`阶段 ${o.number}`:`Phase ${o.number}`).padEnd(8))+g(`${c}/${a}`.padEnd(7))+chalk.gray(o.name))}console.log(chalk.bold.green(" "+r)),console.log(chalk.bold.green(" "+(n?"总分 / overall: ":"Overall: "))+chalk.bold.white(`${s}/${l}`)),console.log(chalk.bold.green(" "+r));for(const e of G(n))console.log(e);console.log()}export function renderMCQCard(e,t){const r=g(),a=o(e,r);b(a,t),w(),f(chalk.bold.yellow("🎯 "+a.title)),f(chalk.gray("─".repeat(Math.min(a.title.length+4,d())))),w();for(const e of W(a.question,d()-4))f(" "+e);w();for(const e of["A","B","C","D"])f(chalk.cyan(` ${e}.`)+" "+chalk.white(a.options[e]));w(),m(),console.log(chalk.gray(" "+(r.startsWith("zh")?"输入 ":"Type "))+chalk.bold.green("A")+chalk.gray(" / ")+chalk.bold.green("B")+chalk.gray(" / ")+chalk.bold.green("C")+chalk.gray(" / ")+chalk.bold.green("D")+chalk.gray(" "+n("type_to_answer",r))),console.log(chalk.gray(" ")+chalk.bold.cyan("back")+chalk.gray(r.startsWith("zh")?" 上一张 · ":" previous card · ")+chalk.bold.cyan("card N")+chalk.gray(r.startsWith("zh")?" 跳转":" jump")),console.log()}export function renderMCQFeedback(e,t,r,a){const l=g(),s=o(e,l);console.log(),r?console.log(" "+chalk.bold.green(n("correct",l)+" ")+chalk.gray(`${n("one_point",l)} · ${t} = ${s.options[t]}`)):console.log(" "+chalk.bold.red(n("not_quite",l)+" ")+chalk.gray(`${n("you_chose",l)} ${t}; ${n("answer_is",l)} ${s.answer}.`)),console.log(),console.log(chalk.gray(" "+n("explanation",l)));for(const e of W(s.explanation,d()-4))console.log(chalk.gray(" "+e));const c=Object.values(a.mcqResults),i=c.filter(e=>e.correct).length;console.log(),console.log(chalk.gray(" "+n("mcq_accuracy_so_far",l)+" ")+chalk.white(`${i}/${c.length}`)),console.log(),r||(console.log(chalk.gray(" "+n("press_ok_continue",l)+" ")+chalk.bold.green("ok")+chalk.gray(" "+n("to_continue",l))),console.log())}export function renderPracticalCard(e,t){const r=g(),a=o(e,r);b(a,t),w(),f(chalk.bold.yellow("🛠 "+a.title)),f(chalk.gray("─".repeat(Math.min(a.title.length+4,d())))),w();for(const e of W(a.task,d()-4))f(" "+e);if(a.starterCode){w(),f(chalk.gray(" "+n("starter_code",r))),w();for(const e of a.starterCode.split("\n"))f(" "+chalk.cyan(e))}w(),m(),console.log(chalk.gray(" "+n("try_in_sandbox",r)+" ")+chalk.bold.cyan("!python3")+chalk.gray(" "+n("drops_into_python",r))),console.log(chalk.gray(" "+n("when_done",r))),console.log(chalk.gray(" ")+chalk.bold.green("done")+chalk.gray(" "+n("done_desc",r))),console.log(chalk.gray(" ")+chalk.bold.yellow("skip")+chalk.gray(" "+n("skip_desc",r))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log()}export function renderPracticalSuccess(e){const t=g(),r=o(e,t);console.log(),console.log(" "+chalk.bold.green(n("practical_recorded",t))),console.log(),console.log(chalk.gray(" "+n("reference_answer",t)));for(const e of W(r.successHint,d()-4))console.log(chalk.gray(" "+e));console.log(),console.log(chalk.gray(" "+n("press_ok_continue",t)+" ")+chalk.bold.green("ok")+chalk.gray(" "+n("to_continue",t))),console.log()}export function renderSimDemoCard(e,t){const r=g(),a=o(e,r);b(a,t),w(),f(chalk.bold.yellow("🎬 "+a.title)),w();for(const e of W(a.description,d()-4))f(" "+e);w(),f(chalk.gray(" "+n("sim_requires",r))),w(),m(),console.log(chalk.gray(" ")+chalk.bold.cyan("sim")+chalk.gray(" "+n("sim_launch_desc",r))),console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(" "+n("continue_to_next",r))),console.log(chalk.gray(" bookmark "+n("bookmark_desc",r))),console.log(chalk.gray(" back "+n("back_desc",r))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+n("quit_desc",r))),console.log()}export function renderArenaTaskCard(e,n){const t=g(),r=t.startsWith("zh"),a=o(e,t);b(a,n),w(),f(chalk.bold.cyan("🏟 "+a.title)),f(chalk.gray(" "+a.origin+" · "+a.domain+" · "+a.metric)),w();for(const e of a.statement){for(const o of W(e,d()-4))f(" "+o);w()}f(chalk.bold.green(r?" 核心要点 — baseline → 解法的关键变化":" CORE DELTA — baseline → solution"));for(const e of a.core_delta)for(const o of W("• "+e,d()-6))f(" "+chalk.white(o));w(),f(chalk.gray((r?" 提交格式: ":" Submission: ")+a.submission_format)),a.hints&&f(chalk.gray(r?" 本题有 5 级提示 (a–e),进入 arena 后逐级解锁。":" 5 progressive hints (a–e) unlock inside the arena.")),w(),m(),console.log(chalk.gray(" ")+chalk.bold.cyan("arena "+a.task_id)+chalk.gray(r?" 动手做这道题(下载 / 提示 / 提交 / 榜单)":" open the arena (download / hints / submit / board)")),console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(r?" 继续下一张":" continue to next")),console.log(chalk.gray(" back "+(r?"上一张":"previous"))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+(r?"退出":"exit"))),console.log()}export function renderComingSoonCard(e,n){const t=g(),r=t.startsWith("zh"),a=o(e,t);b(a,n),w(),f(chalk.bold.yellow("🔜 "+a.title)),w();const l=a.note||(r?"这道竞技场题目正在编写中,敬请期待。":"This arena task is coming soon.");for(const e of W(l,d()-4))f(" "+chalk.gray(e));w(),m(),console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(r?" 继续":" continue")),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+(r?"退出":"exit"))),console.log()}export function renderMilestone(e,t){const r=g(),a=o(e,r),l=e.number===t.totalCards;console.log(),console.log(chalk.bold.yellow(" ╭"+h("═"))),console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+chalk.white(" "+n("milestone_header",r))),console.log(chalk.bold.yellow(" ║"));const s=` ${a.badge} ${a.emoji}`;console.log(chalk.bold.yellow(" ║ ")+chalk.bold.green(s)),console.log(chalk.bold.yellow(" ║ ")+chalk.gray(" ─".repeat(Math.max(1,Math.floor(a.badge.length/2+2))))),console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+" "+chalk.gray(n("in_wild_corresponds",r)));for(const e of W(a.realWorldLevel,d()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(e));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+" "+chalk.gray(n("whats_next",r)));for(const e of W(a.unlockedNext,d()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(e));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ╰"+h("═"))),console.log(),l?(console.log(chalk.gray(" "+n("demo_complete",r))),console.log(),console.log(chalk.gray(" "+n("unlock_full",r)+" ")+chalk.white(n("curriculum_name",r))+chalk.gray(",")),console.log(chalk.gray(" "+n("contact_team_leader",r)+" ")+chalk.bold.yellow("EA")+chalk.gray(" "+n("learn_token",r))),console.log(chalk.gray(" "+n("or_email",r)+" ")+chalk.cyan("australia@icoa2026.au")+chalk.gray(" "+n("for_partnership",r))),console.log(),console.log(chalk.gray(" "+n("type_quit",r)+" ")+chalk.bold.green("quit")+chalk.gray(" "+n("to_exit",r)+" ")+chalk.bold.green("status")+chalk.gray(" "+n("for_dashboard",r)))):(console.log(chalk.gray(" ")+chalk.bold.green("ok")+chalk.gray(" / ")+chalk.bold.green("next")+chalk.gray(" "+n("continue_to_next",r))),console.log(chalk.gray(" status "+n("status_full",r))),console.log(chalk.gray(" back previous card")),console.log(chalk.gray(" card N jump to a card by number")),console.log(chalk.gray(" quit "+n("quit_desc",r)))),console.log()}export function renderStatus(o,t,r={}){const a=g(),l=a.startsWith("zh"),s=t.cardsCompleted.length,c=o.totalCards,i=t.checkResults||{},h=r.gate??null,b=!!r.gated,$=r.focus??"current",k=r.posForSlot??(e=>4===e?10:4*e),_=e=>r.practiceCount?r.practiceCount(e):Y?Y(e):null,x=t.currentCard,C=o.modules.find(e=>x>=e.cardRange[0]&&x<=e.cardRange[1]),v=(o,n)=>o+" ".repeat(Math.max(0,n-e((e=>e.replace(/\x1b\[[0-9;]*m/g,""))(o))));console.log();const M=`${o.name} — ${l?"状态":"Status"}`;console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(M)+" "+chalk.cyan("─".repeat(Math.max(4,d()-2-e(M))))),w(),f(" "+chalk.gray(n("total_progress",a)+" ")+u(s,c)+chalk.gray(` (${s}/${c})`)+chalk.gray(" "+n("streak",a)+" ")+p(t.streakDays));{let n=0,a=0,s=0,c=0,g=0,y=0,u=!1;for(const e of o.modules){for(let t=e.cardRange[0];t<=e.cardRange[1];t++){const e=_(t);e&&(n++,e.solved>=e.total&&a++);const r=o.cards.find(e=>e.number===t);null!=r?.check&&(s++,i[String(t)]?.correct&&c++)}const t=h?.phases.find(o=>o.phase===e.number);if(t?.configured)for(const e of t.contest?.slots??[])g++,e.passed&&y++;t?.research&&(u=!0)}const p=(e,o)=>(e>=o?chalk.green:chalk.white)(`${e}/${o}`),b=[];n&&b.push(chalk.gray(l?"⚔ 练习卡 ":"⚔ practice cards ")+p(a,n)),g&&b.push(chalk.gray(l?"赛场 ":"arena ")+p(y,g)),s&&b.push(chalk.gray(l?"✓ 自测 ":"✓ checks ")+p(c,s)),b.length&&f(" "+b.join(chalk.gray(" "))),r._anyResearch=u;{let n=0;const r=[];let a=0,c=0,h=0;for(const e of o.modules)for(let l=e.cardRange[0];l<=e.cardRange[1];l++){c++,t.cardsCompleted.includes(l)&&a++;const e=o.cards.find(e=>e.number===l);null!=e?.check&&i[String(l)]&&h++;const s=_(l);s&&s.solved<s.total&&(n+=s.total-s.solved,r.push(l))}const u=l?"▸ 通关还差 ":"▸ to finish ",p=[];if(a<c&&p.push(chalk.gray(l?"卡片 ":"cards ")+chalk.white(""+(c-a))+chalk.gray(l?" 张未读":" unread")),s&&h<s&&p.push(chalk.gray("✓ ")+chalk.white(""+(s-h))+chalk.gray(l?" 题自测未答":" checks unanswered")),n>0){const o=l?`练习还差 ${n} 题`:`${n} practice problem${n>1?"s":""}`,t=l?"(卡 ":" (cards ",a=")",s=" │ ⚔ ",c=d()-e(s)-e(u)-e(o)-e(t+a),g=e=>{const o=[];let n=0;for(const t of r){const r=String(t).length+(o.length?3:0);if(n+r>e)break;n+=r,o.push(t)}return o};let i=g(c);i.length<r.length&&(i=g(c-e(` +${r.length}`))),!i.length&&r.length&&(i=[r[0]]);const h=r.length-i.length,y=i.join(" · ")+(h>0?` +${h}`:"");p.push(chalk.gray("⚔ ")+chalk.white(o)+chalk.gray(t+y+a))}g&&y<g&&p.push(chalk.gray(l?"赛 ":"arena ")+chalk.white(""+(g-y))+chalk.gray(l?" 场未过":" to pass"));const b=a>0;b&&p.length?p.forEach((o,n)=>f(" "+(0===n?chalk.bold.yellow(u):" ".repeat(e(u)))+o)):b&&!p.length&&f(" "+chalk.bold.green(l?"✅ 通关条件已全部达成":"✅ every completion gate met"))}}w();const S=e=>l?`阶段 ${e}`:`Phase ${e}`,j=Math.max(10,Math.min(28,d()-54));for(const e of o.modules){const[n,r]=e.cardRange,a=r-n+1,s=t.cardsCompleted.filter(e=>e>=n&&e<=r).length,c=b&&!!h&&e.number>h.unlocked_through_phase,g=h?.phases.find(o=>o.phase===e.number);let u=0,p=0,m=0;const w=[],M=[];let A=0,W=0,z=0;const L=[];for(let e=n;e<=r;e++){const n=o.cards.find(o=>o.number===e);if(null!=n?.check){u++;const o=i[String(e)];o?(p++,o.correct?m++:M.push(e)):w.push(e)}const t=_(e);t&&(A++,z+=t.solved,t.solved>=t.total?W++:L.push(`${e}:${t.solved}/${t.total}`))}const R=g?.configured?g.contest?.slots??[]:[],P=e=>e.passed?chalk.green("✅"):e.attempts>0?chalk.yellow("❌"):chalk.gray("⬜"),q=s>=a&&(0===u||m===u)&&(0===A||W===A)&&(0===R.length||R.every(e=>e.passed))&&(!g?.research||g.research.passed),E=s>0||p>0||z>0||R.some(e=>e.attempts>0),T=c?chalk.gray("🔒"):q?chalk.green("✅"):e.number===C?.number?chalk.bold.cyan("▶ "):E?chalk.yellow("▶ "):chalk.gray("⬜"),N=y(e.name,j),F=[];if(F.push((s>=a?chalk.green:chalk.white)(`${s}/${a}`)+chalk.gray(l?"卡":"c")),u>0&&F.push(chalk.gray("✓")+(m===u?chalk.green:chalk.white)(`${m}/${u}`)),A>0&&F.push(chalk.gray("⚔")+(W===A?chalk.green:chalk.white)(`${W}/${A}`)+chalk.gray(l?"卡":"c")),R.length>0&&F.push(chalk.gray(l?"赛":"arena ")+R.map(P).join("")),g?.research&&F.push(chalk.gray("⭐")+(g.research.passed?chalk.green:chalk.white)(`${g.research.good_cards}/${g.research.need_cards}`)),f(" "+T+" "+chalk.white(v(S(e.number),l?5:8))+chalk.gray(v(N,j+1))+F.join(chalk.gray(" · "))),c||"all"!==$&&$!==e.number&&("current"!==$||e.number!==C?.number)){if(!c&&E&&!q){const o=[],t=R.filter(e=>!e.passed).map(o=>(o.attempts>0?chalk.yellow:chalk.gray)(`${e.number}-${o.slot}@${l?"卡":"card "}${n+k(o.slot)-1}`));t.length&&o.push(chalk.gray(l?"赛 ":"arena ")+t.join(chalk.gray(" · ")));const r=(e,o)=>e.slice(0,8).join(o)+(e.length>8?chalk.gray(" +"+(e.length-8)):"");L.length&&o.push(chalk.gray("⚔ ")+chalk.white(r(L," "))),M.length&&o.push(chalk.red("✗ ")+chalk.white(r(M.map(String),","))),w.length&&o.push(chalk.gray("○ ")+chalk.white(r(w.map(String),","))),g?.research&&!g.research.passed&&o.push(chalk.gray(`⭐ ${g.research.good_cards}/${g.research.need_cards}`)),o.forEach((e,o)=>f(chalk.gray(0===o?l?" 待办: ":" todo: ":" ")+e))}}else{const t=String(r).length;for(let s=n;s<=r;s++){const r=o.cards.find(e=>e.number===s);if(!r)continue;const c=r,g=c.title??c.badge??"",h=(l?c._zh?.title??c._zh?.badge??g:g)||"",y=null!=r.check,u=i[String(s)],p=u?u.correct?chalk.green("✓"):chalk.red("✗"):y?chalk.gray("○"):chalk.gray("·"),b=_(s),m=b?(b.solved>=b.total?chalk.green:b.solved>0?chalk.yellow:chalk.gray)(`⚔${b.solved}/${b.total}`):" ",w=s===x?chalk.bold.cyan("▶"):" ",$=wrapMixed(h,Math.max(16,d()-14-t)),C=$[0]+($.length>1?"…":"");f(` ${w} `+chalk.gray(String(s).padStart(t))+" "+p+" "+v(m,5)+" "+chalk.white(C));const M=12===a?R.find(e=>n+k(e.slot)-1===s):void 0;if(M){const o=chalk.gray(` ${" ".repeat(t)} ⚔ ${l?"练习赛":"arena"} ${e.number}-${M.slot}: `);M.passed?f(o+chalk.bold.green(`${M.best_ac}/${M.n} AC ✅`)):0===M.attempts?f(o+chalk.gray("⬜ ")+chalk.white(l?`未开始 · ${M.n} 题 · 过 ${M.need} 题 → `:`not started · ${M.n} problems · AC ${M.need} → `)+chalk.bold.green(`contest ${M.slot}`)):f(o+chalk.yellow(l?`❌ 最好 ${M.best_ac}/${M.n}(需 ${M.need})· 已试 ${M.attempts} 次 → `:`❌ best ${M.best_ac}/${M.n} (need ${M.need}) · ${M.attempts} attempt(s) → `)+chalk.bold.green(`contest ${M.slot}`))}}if(12!==a)for(const o of R){const n=chalk.gray(` ⚔ ${l?"练习赛":"arena"} ${e.number}-${o.slot}: `);o.passed?f(n+chalk.bold.green(`${o.best_ac}/${o.n} AC ✅`)):0===o.attempts?f(n+chalk.gray("⬜ ")+chalk.white(l?`未开始 · ${o.n} 题 · 过 ${o.need} 题 → `:`not started · ${o.n} problems · AC ${o.need} → `)+chalk.bold.green(`contest ${o.slot}`)):f(n+chalk.yellow(l?`❌ 最好 ${o.best_ac}/${o.n}(需 ${o.need})· 已试 ${o.attempts} 次 → `:`❌ best ${o.best_ac}/${o.n} (need ${o.need}) · ${o.attempts} attempt(s) → `)+chalk.bold.green(`contest ${o.slot}`))}g?.research&&!g.research.passed&&f(chalk.gray(l?` ⭐ 研究: ${g.research.good_cards}/${g.research.need_cards} 卡达 ${g.research.min_score} 分 — /ai 研究后 /submit`:` ⭐ research: ${g.research.good_cards}/${g.research.need_cards} cards at ${g.research.min_score}+ — /ai then /submit`)),g&&!g.configured&&f(chalk.gray(l?" 🔒 本阶段通关标准制作中 — 很快更新":" 🔒 pass criteria for this phase in production — coming soon"))}}w(),f(chalk.gray(l?" ✓ 答对 ✗ 答错 ○ 未答 · ⚔ 练习 已过/共 · 赛 ✅ 过 ❌ 试过 ⬜ 未碰"+(r._anyResearch?" · ⭐ 研究":""):" ✓ right ✗ wrong ○ unanswered · ⚔ practice solved/total"+(r._anyResearch?" · ⭐ research":""))),f(chalk.gray(l?" 展开某阶段: ":" arena ✅ passed ❌ tried ⬜ untouched · expand: ")+chalk.bold.green("status all")+chalk.gray(" / ")+chalk.bold.green("status N")),t.achievements.length>0&&f(" "+chalk.gray(n("achievements",a)+" ")+t.achievements.map(e=>chalk.bold.yellow("★ ")+chalk.white(e)).join(chalk.gray(" · "))),w(),m()}function K(e){try{Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}catch{}}export function renderArenaIntro(e=12){const o=g().startsWith("zh");if(e>12){const e=o?[chalk.bold.yellow(" ⚔ 你读完 4 张卡了 — 前面是本模块的定位检查。"),chalk.white(" ⚔ 每个模块两场:")+chalk.bold.yellow("卡 4")+chalk.white(" 定位检查(8 题 8 分钟,对 6 题即可跳到下一模块),")+chalk.bold.yellow("卡 8")+chalk.white(" 完整模拟卷(35 题 40 分钟,真卷格式)。"),chalk.white(" · 敲 ")+chalk.bold.green("contest 1")+chalk.white(" 开始 — 计时同时开始;每题选一个字母提交。"),chalk.white(" · 不锁任何卡:过不过都能继续往下读。"),chalk.gray(" ▸ 现在不想打?敲 ")+chalk.bold.green("next")+chalk.gray(" 继续读卡,检查点一直在那儿等你。")]:[chalk.bold.yellow(" ⚔ Four cards down — this module's placement check is waiting."),chalk.white(" ⚔ Two checkpoints per module: ")+chalk.bold.yellow("card 4")+chalk.white(" placement check (8 questions, 8 min; 6/8 lets you skip ahead), ")+chalk.bold.yellow("card 8")+chalk.white(" full mock paper (35 questions, 40 min, real NSW format)."),chalk.white(" · Type ")+chalk.bold.green("contest 1")+chalk.white(" to start — the clock starts with it; answer each question with a letter."),chalk.white(" · Nothing locks: pass or not, you can keep reading."),chalk.gray(" ▸ Not now? Type ")+chalk.bold.green("next")+chalk.gray(" and keep reading — the checkpoint waits for you.")];console.log();for(const o of e)console.log(o);return void console.log()}const n=t(e),r=["","one","two","three"][n.n]??String(n.n),a=learnCheckpointVerb(),l=!!process.stdout.isTTY&&!/^(C|POSIX)$/i.test(process.env.LANG||"")&&!process.env.ICOA_TEST_BOOT_MODE,s=o?[chalk.bold.yellow(" ⚔ 你读完 4 张卡了 — 前面是第一个检查点。"),n.n>1?chalk.white(" ⚔ 每 4 张卡有一场判分赛:")+chalk.bold.yellow(`卡 ${n.cards}`)+chalk.white(`,一个阶段共 ${n.n} 场。`):chalk.white(" ⚔ 每个阶段有一场判分赛:")+chalk.bold.yellow(`卡 ${n.cards}`)+chalk.white("。"),...a?[chalk.white(" · 敲 ")+chalk.bold.green(a)+chalk.white(" 进竞技场 — ")+chalk.bold.green("battle"===a?"play":"run")+chalk.white(" 本机试跑,")+chalk.bold.green("submit")+chalk.white(" 交给判分机;第一次 submit 时计时开始。")]:[chalk.white(" · 敲 ")+chalk.bold.green("contest 1")+chalk.white(" 开始 — 计时器同时开始,题目在赛场里读。")],chalk.white(" · 判分机会真的跑你的代码,不是对答案。"),chalk.white(n.n>1?` · ${n.n} 场全过 → 解锁下一阶段。`:" · 过了这一场 → 解锁下一阶段。"),chalk.gray(" ▸ 现在不想打?敲 ")+chalk.bold.green("next")+chalk.gray(" 继续读卡,赛场一直在那儿等你。")]:[chalk.bold.yellow(" ⚔ Four cards down — a checkpoint is waiting."),n.n>1?chalk.white(" ⚔ Every 4 cards there is a judged arena: ")+chalk.bold.yellow(`cards ${n.cards}`)+chalk.white(`, ${r} per phase.`):chalk.white(" ⚔ Each phase has one judged arena: ")+chalk.bold.yellow(`card ${n.cards}`)+chalk.white("."),...a?[chalk.white(" · Type ")+chalk.bold.green(a)+chalk.white(" to enter the arena — ")+chalk.bold.green("battle"===a?"play":"run")+chalk.white(" to try it here, ")+chalk.bold.green("submit")+chalk.white(" to send it to the judge; the clock starts at your first submit.")]:[chalk.white(" · Type ")+chalk.bold.green("contest 1")+chalk.white(" to start — the clock starts with it; the problems are read inside.")],chalk.white(" · The judge really runs your code. It is not an answer key."),chalk.white(n.n>1?` · Pass all ${r} → the next phase unlocks.`:" · Pass it → the next phase unlocks."),chalk.gray(" ▸ Not now? Type ")+chalk.bold.green("next")+chalk.gray(" and keep reading — the arena waits for you.")];console.log();for(const e of s)console.log(e),l&&K(200);console.log()}
|
package/dist/lib/python-setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import chalk from"chalk";import{execSync as o}from"node:child_process";import{createWriteStream as
|
|
1
|
+
import chalk from"chalk";import{execSync as o}from"node:child_process";import{createHash as t}from"node:crypto";import{createWriteStream as e,existsSync as r,mkdirSync as n,mkdtempSync as s,renameSync as i,rmSync as a}from"node:fs";import{homedir as c}from"node:os";import{join as l}from"node:path";import{Readable as h,Transform as p}from"node:stream";import{pipeline as u}from"node:stream/promises";import{icoaStandalonePython as d,parsePyVersion as y,REQUIRED_PY as m,resolveHostPython as f,resolveRunPython as g}from"./aienv.js";import{httpFetch as $}from"./http.js";import{lazyJson as w}from"./lazy-assets.js";function b(t){try{return o(`${t} --version 2>&1`,{encoding:"utf-8",timeout:4e3}).trim()}catch{return null}}let v,P;export function probePython(o=!1,t={}){const e=t.hostOnly?P:v;if(e&&!o)return e;const r=c(),n=t.hostOnly?(()=>{const o=f(b,process.platform,r);return o?{...o,source:"host"}:null})():g(b,process.platform,r);if(n){const o=(b(n.cmd.includes(" ")?n.cmd:`"${n.cmd}"`)??"").replace(/^Python\s+/i,"")||`${n.version.major}.${n.version.minor}`,e=d(r,process.platform),s="aienv"===n.source?"aienv":n.cmd===e?"icoa":"system",i={ok:!0,version:o,cmd:n.cmd,source:s};return t.hostOnly?P=i:v=i,i}let s;for(const o of["python3","python"]){const t=b(o);if(y(t)){s=(t??"").replace(/^Python\s+/i,"").trim();break}}const i={ok:!1,otherVersion:s};return t.hostOnly?P=i:v=i,i}export function resetPythonProbe(){v=void 0,P=void 0}const x=`${m.major}.${m.minor}`;export function pythonDoorLine(o,t=!1,e){const r=e??probePython(),n=t?"":"🐍 ";if(r.ok){const t="aienv"===r.source?o?"aienv 环境":"aienv venv":"icoa"===r.source?o?"icoa 装的":"installed by icoa":o?"系统自带":"system";return chalk.gray(` ${n}Python ${r.version} · ${t} · `)+chalk.gray(o?"本机可跑代码":"code runs locally")}return r.otherVersion?chalk.gray(` ${n}Python ${r.otherVersion} — `)+chalk.gray(o?`课程按 ${x} 校准 · `:`courses are calibrated on ${x} · `)+chalk.bold.green("python setup")+chalk.gray(o?` 装并存的 ${x}(免 sudo,不动系统 python3)`:" adds one side-by-side (no sudo, system python3 untouched)"):chalk.gray(` ${n}`+(o?"没有 Python — 读卡答题不需要它 · ":"No Python — reading and answering cards works without it · "))+chalk.bold.green("python setup")+chalk.gray(o?" 让 /py 里能跑代码":" when you want to run code in /py")}export function selectionSetupLine(o,t=!1,e){const r=e??probePython(!1,{hostOnly:!0}),n=t?"":"🐍 ",s=chalk.gray(" (Paper C · SIMOC are MCQ-only — neither is needed)");return r.ok?o?chalk.gray(` ${n}Python ${r.version} · `)+chalk.green("exam toolkit ready"):chalk.gray(` ${n}Python ${r.version} · toolkit not installed · `)+chalk.bold.green("exam setup")+chalk.gray(" (13 packages, ~150 MB)")+s:chalk.gray(` ${n}`+(r.otherVersion?`Python ${r.otherVersion} — the exam runs on ${x} · `:`No Python ${x} yet · `))+chalk.bold.green("exam setup")+chalk.gray(" installs it (~20 s) plus the toolkit (~150 MB)")+s}export function printNoPython312(o,t={}){const e=probePython();console.log(chalk.yellow(o?e.otherVersion?` 这台机器只有 Python ${e.otherVersion} — 课程和判分机都在 ${x} 线上。`:` 找不到 Python ${x} — 不是你的代码有问题。`:e.otherVersion?` This machine has Python ${e.otherVersion} only — courses and the judge both run on the ${x} line.`:` Python ${x} not found — this is not your code.`)),console.log(chalk.gray(o?" 装一份并存的(免 sudo,二十秒,不动系统 python3): ":" Add one side-by-side (no sudo, ~20 s, system python3 untouched): ")+chalk.bold.cyan("python setup")),t.judgeIsServerSide&&console.log(chalk.gray(o?" 判分在服务器上跑,所以 /submit 照样能用 — 只是没法先本地自测。":" Judging is server-side — /submit still works, only self-check is off.")),console.log()}export function standaloneTriple(o=process.platform,t=""){const e=t.toLowerCase(),r="aarch64"===e||"arm64"===e,n="x86_64"===e||"amd64"===e||"x64"===e;return"darwin"===o?r?"aarch64-apple-darwin":n?"x86_64-apple-darwin":"":"win32"===o?r?"aarch64-pc-windows-msvc":n?"x86_64-pc-windows-msvc":"":r?"aarch64-unknown-linux-gnu":n?"x86_64-unknown-linux-gnu":""}export function pickStandaloneAsset(o,t){const e=`${m.major}\\.${m.minor}`,r=new RegExp(`^cpython-${e}\\.\\d+\\+\\d+-${t}-install_only_stripped\\.tar\\.gz$`),n=new RegExp(`^cpython-${e}\\.\\d+\\+\\d+-${t}-install_only\\.tar\\.gz$`);return o.find(o=>r.test(o.name))??o.find(o=>n.test(o.name))}export function isAllowedAssetUrl(o){return/^https:\/\/github\.com\/astral-sh\/python-build-standalone\/releases\/download\/[\w.%+-]+\/cpython-3\.12\.[\w.%+-]+\.tar\.gz$/.test(o)}const k=/^[0-9a-f]{64}$/;export function candidatesFromManifest(o,t){const e=o?.assets?.[t];if(!e||"string"!=typeof e.path||!function(o,t){const e=`${m.major}\\.${m.minor}`;return new RegExp(`^\\d{8}/cpython-${e}\\.\\d+\\+\\d+-${t}-install_only(_stripped)?\\.tar\\.gz$`).test(o)}(e.path,t))return[];const r="string"==typeof e.sha256&&k.test(e.sha256)?e.sha256:void 0,n=e.path.slice(e.path.indexOf("/")+1),s=[];for(const t of Array.isArray(o.mirrors)?o.mirrors:[]){if("string"!=typeof t||!/^https:\/\/[\w.-]+(\/[\w./%-]*)?$/.test(t))continue;const o=`${t.replace(/\/+$/,"")}/${e.path.replace(/\+/g,"%2B")}`;s.push({url:o,name:n,via:new URL(o).host,sha256:r})}return"string"==typeof e.github&&isAllowedAssetUrl(e.github)&&s.push({url:e.github,name:n,via:"github.com",sha256:r}),s}const _="win32"===process.platform?"tar.exe":"tar";async function j(o,r,n){const s=await $(o,{timeoutMs:3e4,retries:0,headers:{"User-Agent":"icoa-cli"}});if(!s.ok)throw new Error(`HTTP ${s.status}`);if(!s.body)throw new Error("empty body");const i=t("sha256"),a=new p({transform(o,t,e){i.update(o),e(null,o)}});if(await u(h.fromWeb(s.body),a,e(r)),n&&i.digest("hex")!==n)throw new Error("sha256 mismatch")}export async function provisionPython312(t={}){const e=c(),h=l(e,".icoa","python312"),p=d(e,process.platform),u=o=>{t.quiet||console.log(o)};if(!t.force&&r(p)){const o=b(`"${p}"`);if(o&&new RegExp(`^Python ${m.major}\\.${m.minor}\\.`).test(o))return u(chalk.green(` ✓ ${o}`)+chalk.gray(` → ${p}`)),resetPythonProbe(),!0}const y=function(){if("win32"===process.platform)return"arm64"===process.arch?"aarch64":"x86_64";try{return o("uname -m",{encoding:"utf-8"}).trim()}catch{return"arm64"===process.arch?"aarch64":"x86_64"}}(),f=standaloneTriple(process.platform,y);if(!f)return u(chalk.yellow(` ~ No prebuilt Python ${x} for '${y||"unknown"}' on this platform.`)),!1;if(!function(){try{return o(`${_} --version`,{stdio:"ignore",timeout:4e3}),!0}catch{return!1}}())return u(chalk.red(" ✗ `tar` is not installed")+chalk.gray(" — needed to unpack the download.")),"linux"===process.platform&&u(chalk.gray(" Install it: ")+chalk.cyan("sudo apt install -y tar")),!1;let g=candidatesFromManifest(await w("python312/manifest.json",8e3,{force:!0}),f);if(0===g.length)try{const o=await $("https://api.github.com/repos/astral-sh/python-build-standalone/releases/latest",{headers:{"User-Agent":"icoa-cli",Accept:"application/vnd.github+json"}});if(!o.ok)throw new Error(`GitHub API ${o.status}`);const t=pickStandaloneAsset((await o.json()).assets??[],f);if(!t)throw new Error(`no CPython ${x} build for ${f} in the latest release`);if(!isAllowedAssetUrl(t.browser_download_url))throw new Error("asset URL failed the allowlist check");g=[{url:t.browser_download_url,name:t.name,via:"github.com"}]}catch(o){return u(chalk.red(` ✗ Could not resolve a standalone Python ${x}`)+chalk.gray(` (mirror list unreachable · ${o.message})`)),!1}const v=g[0].name.match(/^cpython-(\d+\.\d+\.\d+)/)?.[1]??x;let P="";try{n(l(e,".icoa"),{recursive:!0}),P=s(l(e,".icoa",".py312-"));const t=l(P,"py.tgz"),r=[];let c=!1;for(const o of g){u(chalk.gray(` Fetching CPython ${v} for ${f} via ${o.via} …`));try{await j(o.url,t,o.sha256),c=!0;break}catch(t){const e=t.message.split("\n")[0].slice(0,80);r.push(`${o.via}: ${e}`),u(chalk.gray(` ~ ${o.via} did not work (${e}) — trying the next source`))}}if(!c)throw new Error(`no source reachable — ${r.join(" · ")}`);o(`${_} -xzf "${t}" -C "${P}"`,{stdio:["ignore","ignore","pipe"]}),a(h,{recursive:!0,force:!0}),i(l(P,"python"),h);const d=o(`"${p}" --version`,{encoding:"utf-8"}).trim();if(!new RegExp(`^Python ${m.major}\\.${m.minor}\\.`).test(d))throw new Error(`unexpected version: ${d}`);return resetPythonProbe(),u(chalk.green(` ✓ ${d} installed`)+chalk.gray(` → ${p} (system python3 untouched)`)),!0}catch(o){const t=String(o.stderr??o.message).trim().split("\n").pop();return u(chalk.red(` ✗ Python ${x} install failed`)+chalk.gray(t?` (${t})`:"")),!1}finally{P&&a(P,{recursive:!0,force:!0})}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.618",
|
|
4
4
|
"description": "ICOA CLI — AI-native competition runtime of the International Cyber Olympiad in AI: learn, practise, and compete in AI & cybersecurity from the terminal (AI4CTF · CTF4AI · CTF4EAI)",
|
|
5
5
|
"author": "Charlie Zhu",
|
|
6
6
|
"type": "module",
|