icoa-cli 2.19.545 → 2.19.547
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/commands/ai4ctf.js +1 -1
- package/dist/commands/ctf4ai-demo.js +1 -1
- package/dist/commands/ctf4vla.js +1 -1
- package/dist/commands/exam.js +1 -1
- package/dist/commands/learn.js +1 -1
- package/dist/lib/learn-render.js +1 -1
- package/dist/lib/python-setup.js +1 -1
- package/dist/repl.js +1 -1
- package/package.json +1 -1
package/dist/lib/learn-render.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import chalk from"chalk";import o from"string-width";import{localized as e}from"./learn-curricula.js";import{t as n}from"./learn-i18n.js";import{getConfig as t}from"./config.js";import{icoaBannerLines as r}from"./banner.js";import{renderCharts as l,detectCaps as a}from"./render-card.js";import{replyChipLabel as s}from"./learn-replies.js";function c(){return(t().language||"en").toLowerCase()}let g="normal";export function resolveLearnWidth(o){return"normal"===o.learnWidth||"wide"===o.learnWidth||"wider"===o.learnWidth||"widest"===o.learnWidth?o.learnWidth:o.learnWide?"wide":"normal"}export function setLearnWidth(o){g=o}export function learnWidthCap(o=g){return"widest"===o?160:"wider"===o?120:"wide"===o?96:64}export function learnW(){const o=process.stdout.columns||69,e=Math.max(40,Math.min(64,o-5));return"normal"===g?e:Math.max(e,Math.min(o-6,learnWidthCap()))}const i=learnW;function d(o="─"){return o.repeat(i()+2)}function y(e,n){if(o(e)<=n)return e;let t=e;for(;t.length>0&&o(t)>Math.max(1,n-1);)t=t.slice(0,-1);return t.trimEnd()+"…"}function h(o,e,n=20){const t=e>0?o/e:0,r=Math.floor(t*n),l=n-r;return`${chalk.green("█".repeat(r))+chalk.gray("░".repeat(l))} ${(100*t).toFixed(1)}%`}function u(o){return o>=30?chalk.red("🔥🔥🔥 "+o+" days"):o>=7?chalk.yellow("🔥 "+o+" days"):o>=1?chalk.gray("· "+o+" day"+(o>1?"s":"")):chalk.gray("—")}export function renderWelcome(o,e,t){const r=c(),l=e.cardsCompleted.length,a=o.totalCards,s=a-l,g=o.modules.find(o=>e.currentCard>=o.cardRange[0]&&e.currentCard<=o.cardRange[1]),p=/demo/i.test(o.id);if(console.log(),console.log(chalk.cyan(" ╭"+d("═"))),console.log(chalk.cyan(" ║")),console.log(chalk.cyan(" ║ ")+chalk.bold.white(" "+(o.name?.trim()||n("academy_title",r)))),console.log(chalk.cyan(" ║")),t)console.log(chalk.cyan(" ║ ")+chalk.white(" "+n(p?"welcome_new_demo":"welcome_new",r)));else{const o=new Date(e.lastSeenAt),t=Math.floor((Date.now()-o.getTime())/36e5),l=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)} ${l}`))}console.log(chalk.cyan(" ║"));const m=y(g?`${g.number}. ${g.name}`:"—",i()-14);console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("module",r).padEnd(11))+chalk.white(m)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("progress",r).padEnd(11))+h(l,a,Math.max(6,Math.min(20,i()-26-`${l}/${a}`.length)))+chalk.gray(` (${l}/${a})`)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("streak",r).padEnd(11))+u(e.streakDays)),s>0&&e.currentCard<=a&&console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("next_card",r).padEnd(11))+chalk.white(`#${e.currentCard} ${n("of",r)} ${a}`)),console.log(chalk.cyan(" ║")),console.log(chalk.cyan(" ╰"+d("═"))),console.log(),console.log(chalk.gray(" ─────────────────────────────────────────────"));const b=0===l?n("continue_start",r):`${n("continue_resume",r)} ${e.currentCard}`;console.log(chalk.bold.green(" continue")+chalk.gray(" "+b)),console.log(chalk.yellow(" status")+chalk.gray(" "+n("status_full",r))),e.bookmarks.length>0&&console.log(chalk.yellow(" bookmarks")+chalk.gray(` ${e.bookmarks.length} ${n("bookmarks_desc",r)}`)),console.log(chalk.gray(" quit")+chalk.gray(" "+n("quit_desc",r))),console.log(chalk.gray(" ─────────────────────────────────────────────")),console.log()}function p(e,t){const r=c(),l=e.module,a=t.modules.find(o=>o.number===l),s=a?a.name:n("unknown_module",r),g=n("module",r).replace(":","").trim(),d=y(`${n("card",r)} ${e.number} / ${t.totalCards} · ${g} ${l} · ${s}`,i()-4);console.log(),console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(d)+" "+chalk.cyan("─".repeat(Math.max(0,i()-o(d)-4))))}function m(){console.log(chalk.cyan(" ╰"+d())),console.log()}function b(o){console.log(chalk.cyan(" │ ")+chalk.white(o))}function f(){console.log(chalk.cyan(" │"))}const $=/[┌┐└┘├┤┬┴┼─│╔╗╚╝═║╠╣╦╩╬▓▒░█]/;function w(o){return/^(?: {4}|\t)/.test(o)||$.test(o)||/ {3,}/.test(o)}export function wrapMixed(e,n){const t=[];let r="",l=0,a=!1;for(const s of function(e){const n=[],t=e=>{let t="";const r=()=>{t&&(n.push({t:"atom",s:t}),t="")};for(const l of e)" "===l?(r(),n.push({t:"space"})):2===o(l)?(r(),n.push({t:"wide",s:l})):t+=l;r()},r=/`[^`]*`/g;let l,a=0;for(;null!==(l=r.exec(e));)t(e.slice(a,l.index)),n.push({t:"code",s:l[0]}),a=l.index+l[0].length;return t(e.slice(a)),n}(e)){if("space"===s.t){""!==r&&(a=!0);continue}const e=s.s,c=o("code"===s.t?e.replace(/`/g,""):e),g=a?1:0,i="atom"===s.t&&e.length<=2&&/^[.,;:!?)\]}…'"]+$/.test(e);""!==r&&!i&&l+g+c>n?(t.push(r),r=e,l=c,a=!1):(a&&(r+=" ",l+=1,a=!1),r+=e,l+=c)}return r&&t.push(r),t}const _=/\b(?:Common bug|Common mistake|Common error|Pitfall|Gotcha|Footgun)\b[::]?|\b(?:Warning|Caution)\b[::]|(?:常见错误|常见陷阱|常见误区|陷阱|注意|警告|误区)[::]/gi;function k(o,e){const n=e?chalk.bold.white:chalk.white;let t,r="",l=0;for(_.lastIndex=0;null!==(t=_.exec(o));)t.index>l&&(r+=n(o.slice(l,t.index))),r+=chalk.bold.yellow(t[0]),l=t.index+t[0].length;return l<o.length&&(r+=n(o.slice(l))),r}function x(o,e=!1){let n="",t=0;const r=/`([^`]*)`/g;let l;for(;null!==(l=r.exec(o));)l.index>t&&(n+=k(o.slice(t,l.index),e)),n+=chalk.cyan(l[1]),t=l.index+l[0].length;return t<o.length&&(n+=k(o.slice(t),e)),n}function C(o,e=!1){let n=!1;for(const t of o.split("\n"))if(/^\s*```/.test(t))n=!n;else if(n)console.log(chalk.cyan(" │ ")+chalk.cyan(` ${t}`));else if(""!==t)if(w(t))console.log(chalk.cyan(" │ ")+chalk.white(t));else for(const o of wrapMixed(t,i()-4))console.log(chalk.cyan(" │ ")+` ${x(o,e)}`);else f()}function M(o,e){const n=[];for(const t of o.split("\n")){if(""===t){n.push("");continue}if(w(t)){n.push(t);continue}let o="";for(const r of t.split(" "))(o+" "+r).trim().length>e?(n.push(o.trim()),o=r):o=(o+" "+r).trim();o&&n.push(o)}return n}let v=!1;export function setLearnAiEnabled(o){v=o}let W=new Set;export function setLearnPqsViewCards(o){W=o}let S=new Map;export function setLearnHonorRanks(o){S=o}const j=["①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩"];let z=[];export function setLearnReplies(o){z=o}let A=[];export function setLearnFaqs(o){A=o}let R=null;export function setLearnHometask(o){R=o}let q="full";export function setLearnFooterProfile(o){q=o}let P=null;export function setLearnFooterExtra(o){P=o}function E(){const o=P?.();o&&console.log(chalk.gray(" "+o))}let L=null;export function setLearnPracticeChips(o){L=o}let N=null;export function setLearnPracticeCount(o){N=o}export function renderHonorWall(o){const e=c().startsWith("zh"),{totals:n,chapters:t}=o,r=n.gold+n.silver+n.bronze,l=(o,e)=>e>0?chalk.bold.white(`${o}×${e}`):chalk.gray(`${o}×0`);if(console.log(chalk.gray(" ─────────────────────────────────────────")),console.log(chalk.bold.white(e?" 🏅 奖牌墙 ":" 🏅 Medal wall ")+l("🥇",n.gold)+chalk.gray(" · ")+l("🥈",n.silver)+chalk.gray(" · ")+l("🥉",n.bronze)+chalk.gray(e?" (永久 — 挂上墙就不会摘下)":" (permanent — once earned, never removed)")),0===r){const n=null!=o.floor?`${o.floor}+`:e?"高分":"a high score";return console.log(chalk.gray(e?` 还没有奖牌 — 单卡提问评分 ${n} 并进入该卡前三,即可永久挂墙 🥇🥈🥉`:` No medals yet — score ${n} on a card and hold its top-3 to hang one 🥇🥈🥉`)),void console.log(chalk.gray(" ─────────────────────────────────────────"))}const a=t.map(o=>{const e=`Ch${o.chapter}`,n=(o.gold>0?`🥇${o.gold}`:"")+(o.silver>0?`🥈${o.silver}`:"")+(o.bronze>0?`🥉${o.bronze}`:"");return n?chalk.white(`${e} ${n}`):chalk.gray(`${e} —`)}).join(chalk.gray(" "));console.log(" "+a);const s=t.flatMap(o=>o.cards.map(e=>({...e,chapter:o.chapter})));s.sort((o,e)=>o.rank-e.rank||o.chapter-e.chapter||o.card-e.card);for(const o of s.slice(0,24)){const n=(o.since||"").slice(0,10);console.log(chalk.white(` ${o.icon} `)+chalk.gray(`Ch${o.chapter} · `)+chalk.white(e?`第 ${o.card} 张`:`card ${o.card}`)+chalk.gray(` · ${o.score}`)+(n?chalk.gray(e?` · 始于 ${n}`:` · since ${n}`):""))}s.length>24&&console.log(chalk.gray(e?` …还有 ${s.length-24} 枚`:` …and ${s.length-24} more`)),console.log(chalk.gray(" ─────────────────────────────────────────"))}export function renderKnowledgeCard(t,r){const d=c(),y=e(t,d);p(y,r),f();const h=wrapMixed(y.title,i()-4);for(const o of h)b(chalk.bold.yellow(o));b(chalk.gray("─".repeat(Math.min(Math.max(...h.map(e=>o(e))),i()))));const u=!!(t.chart_ids&&t.chart_ids.length>0);if(u&&l(t.chart_ids.slice(0,1),r.charts,a()),y.key_point&&""!==y.key_point.trim()?(u||f(),function(o,e,n){const t=c().startsWith("zh"),r=a().cols,l="-".repeat(Math.min(i(),Math.max(24,r-6))),s=t?"要点":"KEY POINT",g=t?`第 ${e} / ${n} 张`:`Card ${e} / ${n}`;console.log(chalk.cyan(" │ ")+chalk.green(l)),console.log(chalk.cyan(" │ ")+chalk.green(`${s} · ${g}`));for(const e of wrapMixed(o,i()-4))console.log(chalk.cyan(" │ ")+chalk.bold.green(" "+e));console.log(chalk.cyan(" │ ")+chalk.green(l)),f()}(y.key_point,y.number,r.totalCards)):u||f(),y.body.filter(o=>null!=o&&""!==o.trim()).forEach((o,e)=>{const n=0===e?o.match(/^([\s\S]*?(?:[.!?](?=\s|$)|[。!?]))(\s[\s\S]*)?$/):null;if(n&&n[1].trim().length<=180){C(n[1],!0);const o=n[2]?.trimStart();o&&C(o,!1)}else C(o,!1);f()}),y.icoaConnection){b(chalk.magenta(" "+n("icoa_connection",d))),b(chalk.gray(" "+"─".repeat(20)));for(const o of wrapMixed(y.icoaConnection,i()-4))b(" "+chalk.magenta(o));f()}if(t.check){const o=d.startsWith("zh"),e=t._zh?.checkStatement??t._zh?.check?.statement,n=o?e??t.check.statement:t.check.statement;for(const e of wrapMixed(o?"请回答 (输 y 或 n):":"Quick comprehension check (type y or n):",i()-8))b(chalk.cyan(" 🤔 "+e));b(chalk.gray(" "+"─".repeat(20)));for(const o of wrapMixed(n,i()-4))b(" "+chalk.white(o));f()}m(),function(e,n){const t=c().startsWith("zh"),r=a().cols,l="-".repeat(Math.min(i(),Math.max(24,r-6))),d=chalk.gray(" ");if("minimal"===q){const o=L?L(e.number):null;console.log(chalk.gray(" "+l)),console.log(chalk.gray(" "+(t?`第 ${e.number} / ${n.totalCards} 张`:`Card ${e.number} / ${n.totalCards}`))+(o?chalk.gray(t?" · 本卡练习 ":" · practice ")+o:""));const r=[];if(e.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")),o){const e=Math.max(1,(o.match(/\[\d\]/g)??[]).length),n=Array.from({length:e},(o,e)=>`[${e+1}]`).join("");r.push(chalk.bold.cyan(n)+chalk.gray(t?" 练习":" practice"))}return 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(d)),E(),void console.log()}const y=[];e.check?(y.push(chalk.bold.green("[y]")+chalk.gray(t?" 是":" yes")),y.push(chalk.bold.green("[n]")+chalk.gray(t?" 否":" no"))):y.push(chalk.bold.green("[ok]")+chalk.gray(t?" 继续":" next")),v&&(y.push(chalk.bold.magenta("[/ai]")+chalk.gray(t?" 🐼 熊猫导师":" 🐼 Panda tutor")),y.push(chalk.bold.magenta("[/submit]")+chalk.gray(t?" 提问评分":" prompt score")));const h=S.get(e.number);var u;y.push(chalk.bold.magenta(h?`[/honors ${u=h,j[u-1]??`#${u}`}]`:"[/honors]")+chalk.gray(t?" 排行":" board")),"normal"===g?y.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 宽屏":" widen")):("wide"===g?y.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 更宽":" wider")):"wider"===g?(y.push(chalk.bold.cyan("[widest]")+chalk.gray(t?" 最宽":" widest")),y.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 回宽屏":" back to wide"))):y.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 回 wider":" back to wider")),y.push(chalk.bold.cyan("[normal]")+chalk.gray(t?" 标准":" standard")));const p=s(z,A,e.number,t),m=p.startsWith("💬");if(y.push((m?chalk.bold.yellow("[r]"):chalk.gray("[r]"))+(m?chalk.bold.white(` ${p}`):chalk.gray(` ${p}`))),y.push(chalk.bold.yellow("[e]")+chalk.gray(t?" 提问或报告":" ask or report")),R){const o=R,e=`${o.done}/${o.total}`,n=o.completedAt?chalk.bold.green:chalk.bold.cyan;y.push(n("[task]")+chalk.gray(t?` 本周 ${e}`:` week ${e}`))}y.push(chalk.bold.cyan("[b]")+chalk.gray(t?" 上一张":" back")),y.push(chalk.bold.cyan("[card N]")+chalk.gray(t?" 跳转":" jump")),y.push(chalk.gray("[reload]")+(t?chalk.gray(" 刷新"):"")),y.push(chalk.gray("[quit]")+(t?chalk.gray(" 退出"):""));const b=o(l);console.log(chalk.gray(" "+l)),console.log(chalk.gray(" "+(t?`第 ${e.number} / ${n.totalCards} 张`:`Card ${e.number} / ${n.totalCards}`)));let f="",$=0;for(const e of y){const n=o(e);f&&$+2+n>b?(console.log(" "+f),f=e,$=n):(f=f?f+d+e:e,$=f===e?n:$+2+n)}f&&console.log(" "+f),console.log(" "+chalk.magenta("✍ ")+chalk.magenta("[/py]")+chalk.gray(t?" Python 草稿本":" Python scratchpad")+d+chalk.magenta("[/pylist]")+chalk.gray(t?" 我的草稿":" my files")),console.log(chalk.gray(" "+l));const w=[t?"e = 就这张卡提问,或报告问题":"e = ask about this card, or report a problem",t?"更多: bookmark / unbookmark · status · lang zh/en · link":"more: bookmark / unbookmark · status · lang zh/en · link"];for(const o of w)for(const e of wrapMixed(o,b))console.log(chalk.gray(" "+e));E(),console.log()}(t,r)}export function renderCheckFeedback(o,e,n,t=!1){const r=c().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 e="y"===o.check?.answer?r?"是":"Yes":r?"否":"No";console.log(chalk.gray(" "+(r?"正确答案: ":"Answer: ")+e+". "+(r?"回看上面那段。":"Re-read the paragraph above.")))}const l=r?o._zh?.solution??o.solution:o.solution;if(l&&l.length>0){console.log(),console.log(chalk.cyan(" 📝 "+(r?"解答:":"Worked solution:")));for(const o of l){for(const e of wrapMixed(o,i()-4))console.log(chalk.white(" "+e));console.log()}}console.log()}function F(o){return[chalk.white(" "+(o?"编著:Charlie Zhu":"Created & edited by Charlie Zhu")),chalk.gray(" "+(o?"ICOA 2026 创始人 · 课程总架构师":"Founder & Chief Curriculum Architect · ICOA 2026"))]}export function renderPhaseComplete(o,e,n,t,l,a){const s=c().startsWith("zh"),[g,d]=n.cardRange,y=e.checkResults||{};let h=0,u=0;for(let o=g;o<=d;o++){const e=y[String(o)];e&&(h++,e.correct&&u++)}const p="-".repeat(48);console.log();for(const o of r(" "))console.log(o);console.log(),console.log(chalk.bold.yellow(" "+p)),console.log(chalk.bold.yellow(" "+(s?`阶段 ${n.number} 完成`:`Phase ${n.number} complete`))+chalk.gray(" · ")+chalk.white(n.name));const m=h>0&&u===h?chalk.bold.green:chalk.bold.white;console.log(chalk.gray(" "+(s?"理解检查得分: ":"comprehension score: "))+m(`${u}/${h}`)+chalk.gray(0===h?s?" (本阶段未作答 y/n)":" (no y/n answered)":""));const b=String(d).length;let f=!1,$=0,w=0,_=0,k=0;for(let e=g;e<=d;e++){const n=o.cards.find(o=>o.number===e);if(!n)continue;const t=n,r=t.title??t.badge??"",l=(s?t._zh?.title??t._zh?.badge??r:r)||"",a=null!=n.check,c=y[String(e)];let g;g=c?c.correct?chalk.green("✓"):chalk.red("✗"):a?chalk.gray("○"):chalk.gray("·");const d=N?N(e):null;d&&(f=!0);const h=d?(d.solved>=d.total?chalk.green:d.solved>0?chalk.yellow:chalk.gray)(` ⚔${d.solved}/${d.total}`):"";d&&($++,d.solved>=d.total&&w++,_+=d.solved,k+=d.total);const u=wrapMixed(l,i()-10-b-(d?6:0)),p=u[0]+(u.length>1?"…":"");console.log(chalk.gray(` ${String(e).padStart(b)} `)+g+h+chalk.white(" "+p))}if(console.log(chalk.gray(s?" ✓ 答对 · ✗ 答错 · ○ 未作答 · 无 y/n 的卡不计分":" ✓ correct · ✗ wrong · ○ unanswered · cards without a y/n are unscored")),f&&console.log(chalk.bold.cyan(" ⚔ "+(s?"卡片练习: ":"practice: "))+(w>=$?chalk.bold.green:chalk.bold.white)(`${w}/${$}`)+chalk.gray(s?` 卡全完成 · ${_}/${k} 题 AC · 行内 ⚔已过/共(绿 完成 · 黄 部分 · 灰 未碰)`:` cards complete · ${_}/${k} problems AC · ⚔solved/total per row (green done · yellow partial · gray untouched)`)),l){const o=o=>"green"===o?chalk.bold.green:"blue"===o?chalk.bold.cyan:"yellow"===o?chalk.bold.yellow:chalk.bold.red;console.log(chalk.bold.magenta(" ⭐ "+(s?"提问得分 (best): ":"Prompt scores (best): "))+(0===l.length?chalk.gray(s?"本阶段尚未提问 — 用 /ai 研究,再 /submit 评分":"none this phase — research with /ai, then /submit"):l.map(e=>chalk.gray((s?"卡":"#")+e.card+" ")+o(e.tier)(String(e.score))).join(chalk.gray(" · "))))}if(a&&!a.configured){const o=d-g+1>12;console.log(chalk.gray(o?s?" 🔒 本阶段通关标准制作中 — 很快更新(360 层第二阶段标准设计中)":" 🔒 Pass criteria for this phase are in production — coming soon (360-tier second-stage standard in design)":s?" 🔒 本阶段通关标准制作中 — 很快更新(标准范式:3 场练习赛 + 3 卡研究)":" 🔒 Pass criteria for this phase are in production — coming soon (standard: 3 arenas + 3 research cards)"))}if(a?.configured&&a.contest){const o=a.contest;if(o.slots&&o.slots.length>0)for(const e of o.slots){const o=chalk.bold.cyan(` ⚔ ${s?"练习赛":"arena"} ${n.number}-${e.slot}: `);e.passed?console.log(o+chalk.bold.green(`${e.best_ac}/${e.n} AC ✅`)):0===e.attempts?console.log(o+chalk.white(s?`${e.n} 题 · 过 ${e.need} 题 — `:`${e.n} problems · AC ${e.need} — `)+chalk.bold.green(`contest ${e.slot}`)):console.log(o+chalk.yellow(s?`最好 ${e.best_ac}/${e.n}(需 ${e.need})· 已试 ${e.attempts} 次 — `:`best ${e.best_ac}/${e.n} (need ${e.need}) · ${e.attempts} attempt(s) — `)+chalk.bold.green(`contest ${e.slot}`))}else{const e=chalk.bold.cyan(" ⚖ "+(s?"判分赛: ":"Contest: "));o.passed?console.log(e+chalk.bold.green(`${o.best_ac}/${o.n} AC ✅ `+(s?"已过关":"passed"))):0===o.attempts?console.log(e+chalk.white(s?`${o.n} 题 · 过 ${o.need} 题解锁 — 输入 `:`${o.n} problems · AC ${o.need} to pass — type `)+chalk.bold.green("contest")+chalk.white(s?" 开始":" to start")):console.log(e+chalk.yellow(s?`最好 ${o.best_ac}/${o.n} AC(需 ${o.need})· 已试 ${o.attempts} 次 — 输入 `:`best ${o.best_ac}/${o.n} AC (need ${o.need}) · ${o.attempts} attempt(s) — type `)+chalk.bold.green("contest")+chalk.yellow(s?" 再战":" to retry"))}}t&&console.log(chalk.gray(" "+(s?"下一阶段: ":"next: "))+chalk.bold.cyan(s?`阶段 ${t.number}`:`Phase ${t.number}`)+chalk.gray(" · ")+chalk.white(t.name)),console.log(chalk.bold.yellow(" "+p));for(const o of F(s))console.log(o)}export function renderCurriculumComplete(o,e){const n=c().startsWith("zh"),t=e.checkResults||{},l="-".repeat(48);let a=0,s=0;console.log();for(const o of r(" "))console.log(o);console.log(),console.log(chalk.bold.green(" "+l)),console.log(chalk.bold.green(" 🏆 "+(n?`${o.name} — 全部完成!`:`${o.name} — complete!`))),console.log(chalk.bold.green(" "+l));for(const e of o.modules){const[o,r]=e.cardRange;let l=0,c=0;for(let e=o;e<=r;e++){const o=t[String(e)];o&&(l++,o.correct&&c++)}a+=l,s+=c;const g=l>0&&c===l?chalk.green:chalk.white;console.log(chalk.gray(" "+(n?`阶段 ${e.number}`:`Phase ${e.number}`).padEnd(8))+g(`${c}/${l}`.padEnd(7))+chalk.gray(e.name))}console.log(chalk.bold.green(" "+l)),console.log(chalk.bold.green(" "+(n?"总分 / overall: ":"Overall: "))+chalk.bold.white(`${s}/${a}`)),console.log(chalk.bold.green(" "+l));for(const o of F(n))console.log(o);console.log()}export function renderMCQCard(o,t){const r=c(),l=e(o,r);p(l,t),f(),b(chalk.bold.yellow("🎯 "+l.title)),b(chalk.gray("─".repeat(Math.min(l.title.length+4,i())))),f();for(const o of M(l.question,i()-4))b(" "+o);f();for(const o of["A","B","C","D"])b(chalk.cyan(` ${o}.`)+" "+chalk.white(l.options[o]));f(),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(o,t,r,l){const a=c(),s=e(o,a);console.log(),r?console.log(" "+chalk.bold.green(n("correct",a)+" ")+chalk.gray(`${n("one_point",a)} · ${t} = ${s.options[t]}`)):console.log(" "+chalk.bold.red(n("not_quite",a)+" ")+chalk.gray(`${n("you_chose",a)} ${t}; ${n("answer_is",a)} ${s.answer}.`)),console.log(),console.log(chalk.gray(" "+n("explanation",a)));for(const o of M(s.explanation,i()-4))console.log(chalk.gray(" "+o));const g=Object.values(l.mcqResults),d=g.filter(o=>o.correct).length;console.log(),console.log(chalk.gray(" "+n("mcq_accuracy_so_far",a)+" ")+chalk.white(`${d}/${g.length}`)),console.log(),r||(console.log(chalk.gray(" "+n("press_ok_continue",a)+" ")+chalk.bold.green("ok")+chalk.gray(" "+n("to_continue",a))),console.log())}export function renderPracticalCard(o,t){const r=c(),l=e(o,r);p(l,t),f(),b(chalk.bold.yellow("🛠 "+l.title)),b(chalk.gray("─".repeat(Math.min(l.title.length+4,i())))),f();for(const o of M(l.task,i()-4))b(" "+o);if(l.starterCode){f(),b(chalk.gray(" "+n("starter_code",r))),f();for(const o of l.starterCode.split("\n"))b(" "+chalk.cyan(o))}f(),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(o){const t=c(),r=e(o,t);console.log(),console.log(" "+chalk.bold.green(n("practical_recorded",t))),console.log(),console.log(chalk.gray(" "+n("reference_answer",t)));for(const o of M(r.successHint,i()-4))console.log(chalk.gray(" "+o));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(o,t){const r=c(),l=e(o,r);p(l,t),f(),b(chalk.bold.yellow("🎬 "+l.title)),f();for(const o of M(l.description,i()-4))b(" "+o);f(),b(chalk.gray(" "+n("sim_requires",r))),f(),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(o,n){const t=c(),r=t.startsWith("zh"),l=e(o,t);p(l,n),f(),b(chalk.bold.cyan("🏟 "+l.title)),b(chalk.gray(" "+l.origin+" · "+l.domain+" · "+l.metric)),f();for(const o of l.statement){for(const e of M(o,i()-4))b(" "+e);f()}b(chalk.bold.green(r?" 核心要点 — baseline → 解法的关键变化":" CORE DELTA — baseline → solution"));for(const o of l.core_delta)for(const e of M("• "+o,i()-6))b(" "+chalk.white(e));f(),b(chalk.gray((r?" 提交格式: ":" Submission: ")+l.submission_format)),l.hints&&b(chalk.gray(r?" 本题有 5 级提示 (a–e),进入 arena 后逐级解锁。":" 5 progressive hints (a–e) unlock inside the arena.")),f(),m(),console.log(chalk.gray(" ")+chalk.bold.cyan("arena "+l.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(o,n){const t=c(),r=t.startsWith("zh"),l=e(o,t);p(l,n),f(),b(chalk.bold.yellow("🔜 "+l.title)),f();const a=l.note||(r?"这道竞技场题目正在编写中,敬请期待。":"This arena task is coming soon.");for(const o of M(a,i()-4))b(" "+chalk.gray(o));f(),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(o,t){const r=c(),l=e(o,r),a=o.number===t.totalCards;console.log(),console.log(chalk.bold.yellow(" ╭"+d("═"))),console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+chalk.white(" "+n("milestone_header",r))),console.log(chalk.bold.yellow(" ║"));const s=` ${l.badge} ${l.emoji}`;console.log(chalk.bold.yellow(" ║ ")+chalk.bold.green(s)),console.log(chalk.bold.yellow(" ║ ")+chalk.gray(" ─".repeat(Math.max(1,Math.floor(l.badge.length/2+2))))),console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+" "+chalk.gray(n("in_wild_corresponds",r)));for(const o of M(l.realWorldLevel,i()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(o));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ║ ")+" "+chalk.gray(n("whats_next",r)));for(const o of M(l.unlockedNext,i()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(o));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ╰"+d("═"))),console.log(),a?(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(e,t,r={}){const l=c(),a=l.startsWith("zh"),s=t.cardsCompleted.length,g=e.totalCards,d=t.checkResults||{},p=r.gate??null,$=!!r.gated,w=r.focus??"current",_=r.posForSlot??(o=>4===o?10:4*o),k=t.currentCard,x=e.modules.find(o=>k>=o.cardRange[0]&&k<=o.cardRange[1]),C=(e,n)=>e+" ".repeat(Math.max(0,n-o((o=>o.replace(/\x1b\[[0-9;]*m/g,""))(e))));console.log();const M=`${e.name} — ${a?"状态":"Status"}`;console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(M)+" "+chalk.cyan("─".repeat(Math.max(4,i()-2-o(M))))),f(),b(" "+chalk.gray(n("total_progress",l)+" ")+h(s,g)+chalk.gray(` (${s}/${g})`)+chalk.gray(" "+n("streak",l)+" ")+u(t.streakDays));{let o=0,n=0,t=0,l=0,s=0,c=0,g=!1;for(const r of e.modules){for(let a=r.cardRange[0];a<=r.cardRange[1];a++){const r=N?N(a):null;r&&(o++,r.solved>=r.total&&n++);const s=e.cards.find(o=>o.number===a);null!=s?.check&&(t++,d[String(a)]?.correct&&l++)}const a=p?.phases.find(o=>o.phase===r.number);if(a?.configured)for(const o of a.contest?.slots??[])s++,o.passed&&c++;a?.research&&(g=!0)}const i=(o,e)=>(o>=e?chalk.green:chalk.white)(`${o}/${e}`),y=[];o&&y.push(chalk.gray(a?"⚔ 练习卡 ":"⚔ practice cards ")+i(n,o)),s&&y.push(chalk.gray(a?"赛场 ":"arena ")+i(c,s)),t&&y.push(chalk.gray(a?"✓ 自测 ":"✓ checks ")+i(l,t)),y.length&&b(" "+y.join(chalk.gray(" "))),r._anyResearch=g}f();const v=o=>a?`阶段 ${o}`:`Phase ${o}`,W=Math.max(10,Math.min(28,i()-54));for(const o of e.modules){const[n,r]=o.cardRange,l=r-n+1,s=t.cardsCompleted.filter(o=>o>=n&&o<=r).length,c=$&&!!p&&o.number>p.unlocked_through_phase,g=p?.phases.find(e=>e.phase===o.number);let h=0,u=0,m=0;const f=[],M=[];let S=0,j=0,z=0;const A=[];for(let o=n;o<=r;o++){const n=e.cards.find(e=>e.number===o);if(null!=n?.check){h++;const e=d[String(o)];e?(u++,e.correct?m++:M.push(o)):f.push(o)}const t=N?N(o):null;t&&(S++,z+=t.solved,t.solved>=t.total?j++:A.push(`${o}:${t.solved}/${t.total}`))}const R=g?.configured?g.contest?.slots??[]:[],q=o=>o.passed?chalk.green("✅"):o.attempts>0?chalk.yellow("❌"):chalk.gray("⬜"),P=s>=l&&(0===h||m===h)&&(0===S||j===S)&&(0===R.length||R.every(o=>o.passed))&&(!g?.research||g.research.passed),E=s>0||u>0||z>0||R.some(o=>o.attempts>0),L=c?chalk.gray("🔒"):P?chalk.green("✅"):o.number===x?.number?chalk.bold.cyan("▶ "):E?chalk.yellow("▶ "):chalk.gray("⬜"),F=y(o.name,W),D=[];if(D.push((s>=l?chalk.green:chalk.white)(`${s}/${l}`)+chalk.gray(a?"卡":"c")),h>0&&D.push(chalk.gray("✓")+(m===h?chalk.green:chalk.white)(`${m}/${h}`)),S>0&&D.push(chalk.gray("⚔")+(j===S?chalk.green:chalk.white)(`${j}/${S}`)+chalk.gray(a?"卡":"c")),R.length>0&&D.push(chalk.gray(a?"赛":"arena ")+R.map(q).join("")),g?.research&&D.push(chalk.gray("⭐")+(g.research.passed?chalk.green:chalk.white)(`${g.research.good_cards}/${g.research.need_cards}`)),b(" "+L+" "+chalk.white(C(v(o.number),a?5:8))+chalk.gray(C(F,W+1))+D.join(chalk.gray(" · "))),c||"all"!==w&&w!==o.number&&("current"!==w||o.number!==x?.number)){if(!c&&E&&!P){const e=[],t=R.filter(o=>!o.passed).map(e=>(e.attempts>0?chalk.yellow:chalk.gray)(`${o.number}-${e.slot}@${a?"卡":"card "}${n+_(e.slot)-1}`));t.length&&e.push(chalk.gray(a?"赛 ":"arena ")+t.join(chalk.gray(" · ")));const r=(o,e)=>o.slice(0,8).join(e)+(o.length>8?chalk.gray(" +"+(o.length-8)):"");A.length&&e.push(chalk.gray("⚔ ")+chalk.white(r(A," "))),M.length&&e.push(chalk.red("✗ ")+chalk.white(r(M.map(String),","))),f.length&&e.push(chalk.gray("○ ")+chalk.white(r(f.map(String),","))),g?.research&&!g.research.passed&&e.push(chalk.gray(`⭐ ${g.research.good_cards}/${g.research.need_cards}`)),e.forEach((o,e)=>b(chalk.gray(0===e?a?" 待办: ":" todo: ":" ")+o))}}else{const t=String(r).length;for(let s=n;s<=r;s++){const r=e.cards.find(o=>o.number===s);if(!r)continue;const c=r,g=c.title??c.badge??"",y=(a?c._zh?.title??c._zh?.badge??g:g)||"",h=null!=r.check,u=d[String(s)],p=u?u.correct?chalk.green("✓"):chalk.red("✗"):h?chalk.gray("○"):chalk.gray("·"),m=N?N(s):null,f=m?(m.solved>=m.total?chalk.green:m.solved>0?chalk.yellow:chalk.gray)(`⚔${m.solved}/${m.total}`):" ",$=s===k?chalk.bold.cyan("▶"):" ",w=wrapMixed(y,Math.max(16,i()-14-t)),x=w[0]+(w.length>1?"…":"");b(` ${$} `+chalk.gray(String(s).padStart(t))+" "+p+" "+C(f,5)+" "+chalk.white(x));const M=12===l?R.find(o=>n+_(o.slot)-1===s):void 0;if(M){const e=chalk.gray(` ${" ".repeat(t)} ⚔ ${a?"练习赛":"arena"} ${o.number}-${M.slot}: `);M.passed?b(e+chalk.bold.green(`${M.best_ac}/${M.n} AC ✅`)):0===M.attempts?b(e+chalk.gray("⬜ ")+chalk.white(a?`未开始 · ${M.n} 题 · 过 ${M.need} 题 → `:`not started · ${M.n} problems · AC ${M.need} → `)+chalk.bold.green(`contest ${M.slot}`)):b(e+chalk.yellow(a?`❌ 最好 ${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!==l)for(const e of R){const n=chalk.gray(` ⚔ ${a?"练习赛":"arena"} ${o.number}-${e.slot}: `);e.passed?b(n+chalk.bold.green(`${e.best_ac}/${e.n} AC ✅`)):0===e.attempts?b(n+chalk.gray("⬜ ")+chalk.white(a?`未开始 · ${e.n} 题 · 过 ${e.need} 题 → `:`not started · ${e.n} problems · AC ${e.need} → `)+chalk.bold.green(`contest ${e.slot}`)):b(n+chalk.yellow(a?`❌ 最好 ${e.best_ac}/${e.n}(需 ${e.need})· 已试 ${e.attempts} 次 → `:`❌ best ${e.best_ac}/${e.n} (need ${e.need}) · ${e.attempts} attempt(s) → `)+chalk.bold.green(`contest ${e.slot}`))}g?.research&&!g.research.passed&&b(chalk.gray(a?` ⭐ 研究: ${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&&b(chalk.gray(a?" 🔒 本阶段通关标准制作中 — 很快更新":" 🔒 pass criteria for this phase in production — coming soon"))}}f(),b(chalk.gray(a?" ✓ 答对 ✗ 答错 ○ 未答 · ⚔ 练习 已过/共 · 赛 ✅ 过 ❌ 试过 ⬜ 未碰"+(r._anyResearch?" · ⭐ 研究":""):" ✓ right ✗ wrong ○ unanswered · ⚔ practice solved/total"+(r._anyResearch?" · ⭐ research":""))),b(chalk.gray(a?" 展开某阶段: ":" arena ✅ passed ❌ tried ⬜ untouched · expand: ")+chalk.bold.green("status all")+chalk.gray(" / ")+chalk.bold.green("status N")),t.achievements.length>0&&b(" "+chalk.gray(n("achievements",l)+" ")+t.achievements.map(o=>chalk.bold.yellow("★ ")+chalk.white(o)).join(chalk.gray(" · "))),f(),m()}
|
|
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{getConfig as t}from"./config.js";import{icoaBannerLines as r}from"./banner.js";import{renderCharts as a,detectCaps as l}from"./render-card.js";import{replyChipLabel as s}from"./learn-replies.js";function c(){return(t().language||"en").toLowerCase()}let g="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){g=e}export function learnWidthCap(e=g){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"===g?o:Math.max(o,Math.min(e-6,learnWidthCap()))}const i=learnW;function d(e="─"){return e.repeat(i()+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 h(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 u(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=c(),a=o.cardsCompleted.length,l=e.totalCards,s=l-a,g=e.modules.find(e=>o.currentCard>=e.cardRange[0]&&o.currentCard<=e.cardRange[1]),p=/demo/i.test(e.id);if(console.log(),console.log(chalk.cyan(" ╭"+d("═"))),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(p?"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 m=y(g?`${g.number}. ${g.name}`:"—",i()-14);console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("module",r).padEnd(11))+chalk.white(m)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("progress",r).padEnd(11))+h(a,l,Math.max(6,Math.min(20,i()-26-`${a}/${l}`.length)))+chalk.gray(` (${a}/${l})`)),console.log(chalk.cyan(" ║ ")+" "+chalk.gray(n("streak",r).padEnd(11))+u(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(" ╰"+d("═"))),console.log(),console.log(chalk.gray(" ─────────────────────────────────────────────"));const b=0===a?n("continue_start",r):`${n("continue_resume",r)} ${o.currentCard}`;console.log(chalk.bold.green(" continue")+chalk.gray(" "+b)),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 p(o,t){const r=c(),a=o.module,l=t.modules.find(e=>e.number===a),s=l?l.name:n("unknown_module",r),g=n("module",r).replace(":","").trim(),d=y(`${n("card",r)} ${o.number} / ${t.totalCards} · ${g} ${a} · ${s}`,i()-4);console.log(),console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(d)+" "+chalk.cyan("─".repeat(Math.max(0,i()-e(d)-4))))}function m(){console.log(chalk.cyan(" ╰"+d())),console.log()}function b(e){console.log(chalk.cyan(" │ ")+chalk.white(e))}function f(){console.log(chalk.cyan(" │"))}const $=/[┌┐└┘├┤┬┴┼─│╔╗╚╝═║╠╣╦╩╬▓▒░█]/;function w(e){return/^(?: {4}|\t)/.test(e)||$.test(e)||/ {3,}/.test(e)}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="";const r=()=>{t&&(n.push({t:"atom",s:t}),t="")};for(const a of o)" "===a?(r(),n.push({t:"space"})):2===e(a)?(r(),n.push({t:"wide",s:a})):t+=a;r()},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 _=/\b(?:Common bug|Common mistake|Common error|Pitfall|Gotcha|Footgun)\b[::]?|\b(?:Warning|Caution)\b[::]|(?:常见错误|常见陷阱|常见误区|陷阱|注意|警告|误区)[::]/gi;function k(e,o){const n=o?chalk.bold.white:chalk.white;let t,r="",a=0;for(_.lastIndex=0;null!==(t=_.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 x(e,o=!1){let n="",t=0;const r=/`([^`]*)`/g;let a;for(;null!==(a=r.exec(e));)a.index>t&&(n+=k(e.slice(t,a.index),o)),n+=chalk.cyan(a[1]),t=a.index+a[0].length;return t<e.length&&(n+=k(e.slice(t),o)),n}function C(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(w(t))console.log(chalk.cyan(" │ ")+chalk.white(t));else for(const e of wrapMixed(t,i()-4))console.log(chalk.cyan(" │ ")+` ${x(e,o)}`);else f()}function v(e,o){const n=[];for(const t of e.split("\n")){if(""===t){n.push("");continue}if(w(t)){n.push(t);continue}let e="";for(const r of t.split(" "))(e+" "+r).trim().length>o?(n.push(e.trim()),e=r):e=(e+" "+r).trim();e&&n.push(e)}return n}let M=!1;export function setLearnAiEnabled(e){M=e}let W=new Set;export function setLearnPqsViewCards(e){W=e}let A=new Map;export function setLearnHonorRanks(e){A=e}const S=["①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩"];let j=[];export function setLearnReplies(e){j=e}let z=[];export function setLearnFaqs(e){z=e}let P=null;export function setLearnHometask(e){P=e}let R="full";export function setLearnFooterProfile(e){R=e}let q=null;export function setLearnFooterExtra(e){q=e}function E(){const e=q?.();e&&console.log(chalk.gray(" "+e))}let L=null;export function setLearnPracticeChips(e){L=e}let N=null;export function setLearnPracticeCount(e){N=e}export function renderHonorWall(e){const o=c().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 d=c(),y=o(t,d);p(y,r),f();const h=wrapMixed(y.title,i()-4);for(const e of h)b(chalk.bold.yellow(e));b(chalk.gray("─".repeat(Math.min(Math.max(...h.map(o=>e(o))),i()))));const u=!!(t.chart_ids&&t.chart_ids.length>0);if(u&&a(t.chart_ids.slice(0,1),r.charts,l()),y.key_point&&""!==y.key_point.trim()?(u||f(),function(e,o,n){const t=c().startsWith("zh"),r=l().cols,a="-".repeat(Math.min(i(),Math.max(24,r-6))),s=t?"要点":"KEY POINT",g=t?`第 ${o} / ${n} 张`:`Card ${o} / ${n}`;console.log(chalk.cyan(" │ ")+chalk.green(a)),console.log(chalk.cyan(" │ ")+chalk.green(`${s} · ${g}`));for(const o of wrapMixed(e,i()-4))console.log(chalk.cyan(" │ ")+chalk.bold.green(" "+o));console.log(chalk.cyan(" │ ")+chalk.green(a)),f()}(y.key_point,y.number,r.totalCards)):u||f(),y.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){C(n[1],!0);const e=n[2]?.trimStart();e&&C(e,!1)}else C(e,!1);f()}),y.icoaConnection){b(chalk.magenta(" "+n("icoa_connection",d))),b(chalk.gray(" "+"─".repeat(20)));for(const e of wrapMixed(y.icoaConnection,i()-4))b(" "+chalk.magenta(e));f()}if(t.check){const e=d.startsWith("zh"),o=t._zh?.checkStatement??t._zh?.check?.statement,n=e?o??t.check.statement:t.check.statement;for(const o of wrapMixed(e?"请回答 (输 y 或 n):":"Quick comprehension check (type y or n):",i()-8))b(chalk.cyan(" 🤔 "+o));b(chalk.gray(" "+"─".repeat(20)));for(const e of wrapMixed(n,i()-4))b(" "+chalk.white(e));f()}m(),function(o,n){const t=c().startsWith("zh"),r=l().cols,a="-".repeat(Math.min(i(),Math.max(24,r-6))),d=chalk.gray(" ");if("minimal"===R){const e=L?L(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"))}return 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(d)),E(),void console.log()}const y=[];o.check?(y.push(chalk.bold.green("[y]")+chalk.gray(t?" 是":" yes")),y.push(chalk.bold.green("[n]")+chalk.gray(t?" 否":" no"))):y.push(chalk.bold.green("[ok]")+chalk.gray(t?" 继续":" next")),M&&(y.push(chalk.bold.magenta("[/ai]")+chalk.gray(t?" 🐼 熊猫导师":" 🐼 Panda tutor")),y.push(chalk.bold.magenta("[/submit]")+chalk.gray(t?" 提问评分":" prompt score")));const h=A.get(o.number);var u;y.push(chalk.bold.magenta(h?`[/honors ${u=h,S[u-1]??`#${u}`}]`:"[/honors]")+chalk.gray(t?" 排行":" board")),"normal"===g?y.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 宽屏":" widen")):("wide"===g?y.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 更宽":" wider")):"wider"===g?(y.push(chalk.bold.cyan("[widest]")+chalk.gray(t?" 最宽":" widest")),y.push(chalk.bold.cyan("[wide]")+chalk.gray(t?" 回宽屏":" back to wide"))):y.push(chalk.bold.cyan("[wider]")+chalk.gray(t?" 回 wider":" back to wider")),y.push(chalk.bold.cyan("[normal]")+chalk.gray(t?" 标准":" standard")));const p=s(j,z,o.number,t),m=p.startsWith("💬");if(y.push((m?chalk.bold.yellow("[r]"):chalk.gray("[r]"))+(m?chalk.bold.white(` ${p}`):chalk.gray(` ${p}`))),y.push(chalk.bold.yellow("[e]")+chalk.gray(t?" 提问或报告":" ask or report")),P){const e=P,o=`${e.done}/${e.total}`,n=e.completedAt?chalk.bold.green:chalk.bold.cyan;y.push(n("[task]")+chalk.gray(t?` 本周 ${o}`:` week ${o}`))}y.push(chalk.bold.cyan("[b]")+chalk.gray(t?" 上一张":" back")),y.push(chalk.bold.cyan("[card N]")+chalk.gray(t?" 跳转":" jump")),y.push(chalk.gray("[reload]")+(t?chalk.gray(" 刷新"):"")),y.push(chalk.gray("[quit]")+(t?chalk.gray(" 退出"):""));const b=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 y){const n=e(o);f&&$+2+n>b?(console.log(" "+f),f=o,$=n):(f=f?f+d+o:o,$=f===o?n:$+2+n)}f&&console.log(" "+f),console.log(" "+chalk.magenta("✍ ")+chalk.magenta("[/py]")+chalk.gray(t?" Python 草稿本":" Python scratchpad")+d+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 zh/en · link":"more: bookmark / unbookmark · status · lang zh/en · link"];for(const e of w)for(const o of wrapMixed(e,b))console.log(chalk.gray(" "+o));E(),console.log()}(t,r)}export function renderCheckFeedback(e,o,n,t=!1){const r=c().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,i()-4))console.log(chalk.white(" "+o));console.log()}}console.log()}function T(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,t,a,l){const s=c().startsWith("zh"),[g,d]=n.cardRange,y=o.checkResults||{};let h=0,u=0;for(let e=g;e<=d;e++){const o=y[String(e)];o&&(h++,o.correct&&u++)}const p="-".repeat(48);console.log();for(const e of r(" "))console.log(e);console.log(),console.log(chalk.bold.yellow(" "+p)),console.log(chalk.bold.yellow(" "+(s?`阶段 ${n.number} 完成`:`Phase ${n.number} complete`))+chalk.gray(" · ")+chalk.white(n.name));const m=h>0&&u===h?chalk.bold.green:chalk.bold.white;console.log(chalk.gray(" "+(s?"理解检查得分: ":"comprehension score: "))+m(`${u}/${h}`)+chalk.gray(0===h?s?" (本阶段未作答 y/n)":" (no y/n answered)":""));const b=String(d).length;let f=!1,$=0,w=0,_=0,k=0;for(let o=g;o<=d;o++){const n=e.cards.find(e=>e.number===o);if(!n)continue;const t=n,r=t.title??t.badge??"",a=(s?t._zh?.title??t._zh?.badge??r:r)||"",l=null!=n.check,c=y[String(o)];let g;g=c?c.correct?chalk.green("✓"):chalk.red("✗"):l?chalk.gray("○"):chalk.gray("·");const d=N?N(o):null;d&&(f=!0);const h=d?(d.solved>=d.total?chalk.green:d.solved>0?chalk.yellow:chalk.gray)(` ⚔${d.solved}/${d.total}`):"";d&&($++,d.solved>=d.total&&w++,_+=d.solved,k+=d.total);const u=wrapMixed(a,i()-10-b-(d?6:0)),p=u[0]+(u.length>1?"…":"");console.log(chalk.gray(` ${String(o).padStart(b)} `)+g+h+chalk.white(" "+p))}if(console.log(chalk.gray(s?" ✓ 答对 · ✗ 答错 · ○ 未作答 · 无 y/n 的卡不计分":" ✓ correct · ✗ wrong · ○ unanswered · cards without a y/n are unscored")),f&&console.log(chalk.bold.cyan(" ⚔ "+(s?"卡片练习: ":"practice: "))+(w>=$?chalk.bold.green:chalk.bold.white)(`${w}/${$}`)+chalk.gray(s?` 卡全完成 · ${_}/${k} 题 AC · 行内 ⚔已过/共(绿 完成 · 黄 部分 · 灰 未碰)`:` cards complete · ${_}/${k} problems AC · ⚔solved/total per row (green done · yellow partial · gray untouched)`)),a){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(" ⭐ "+(s?"提问得分 (best): ":"Prompt scores (best): "))+(0===a.length?chalk.gray(s?"本阶段尚未提问 — 用 /ai 研究,再 /submit 评分":"none this phase — research with /ai, then /submit"):a.map(o=>chalk.gray((s?"卡":"#")+o.card+" ")+e(o.tier)(String(o.score))).join(chalk.gray(" · "))))}if(l&&!l.configured){const o=d-g+1>12,n="fill"===e.practiceMode;console.log(chalk.gray(o?s?" 🔒 本阶段通关标准制作中 — 很快更新(360 层第二阶段标准设计中)":" 🔒 Pass criteria for this phase are in production — coming soon (360-tier second-stage standard in design)":n?s?" 🔒 本阶段 3 场判分赛制作中 — 很快更新;赛场挂在卡 4 / 8 / 12,3 场全过解锁下一阶段(本轨无 research)":" 🔒 This phase’s 3 judged arenas are in production — coming soon; they hang on cards 4 / 8 / 12 and all 3 unlock the next phase (no research on this track)":s?" 🔒 本阶段通关标准制作中 — 很快更新(标准范式:3 场练习赛 + 3 卡研究)":" 🔒 Pass criteria for this phase are in production — coming soon (standard: 3 arenas + 3 research cards)"))}if(l?.configured&&l.contest){const e=l.contest;if(e.slots&&e.slots.length>0)for(const o of e.slots){const e=chalk.bold.cyan(` ⚔ ${s?"练习赛":"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(s?`${o.n} 题 · 过 ${o.need} 题 — `:`${o.n} problems · AC ${o.need} — `)+chalk.bold.green(`contest ${o.slot}`)):console.log(e+chalk.yellow(s?`最好 ${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(" ⚖ "+(s?"判分赛: ":"Contest: "));e.passed?console.log(o+chalk.bold.green(`${e.best_ac}/${e.n} AC ✅ `+(s?"已过关":"passed"))):0===e.attempts?console.log(o+chalk.white(s?`${e.n} 题 · 过 ${e.need} 题解锁 — 输入 `:`${e.n} problems · AC ${e.need} to pass — type `)+chalk.bold.green("contest")+chalk.white(s?" 开始":" to start")):console.log(o+chalk.yellow(s?`最好 ${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(s?" 再战":" to retry"))}}t&&console.log(chalk.gray(" "+(s?"下一阶段: ":"next: "))+chalk.bold.cyan(s?`阶段 ${t.number}`:`Phase ${t.number}`)+chalk.gray(" · ")+chalk.white(t.name)),console.log(chalk.bold.yellow(" "+p));for(const e of T(s))console.log(e)}export function renderCurriculumComplete(e,o){const n=c().startsWith("zh"),t=o.checkResults||{},a="-".repeat(48);let l=0,s=0;console.log();for(const e of r(" "))console.log(e);console.log(),console.log(chalk.bold.green(" "+a)),console.log(chalk.bold.green(" 🏆 "+(n?`${e.name} — 全部完成!`:`${e.name} — complete!`))),console.log(chalk.bold.green(" "+a));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(" "+a)),console.log(chalk.bold.green(" "+(n?"总分 / overall: ":"Overall: "))+chalk.bold.white(`${s}/${l}`)),console.log(chalk.bold.green(" "+a));for(const e of T(n))console.log(e);console.log()}export function renderMCQCard(e,t){const r=c(),a=o(e,r);p(a,t),f(),b(chalk.bold.yellow("🎯 "+a.title)),b(chalk.gray("─".repeat(Math.min(a.title.length+4,i())))),f();for(const e of v(a.question,i()-4))b(" "+e);f();for(const e of["A","B","C","D"])b(chalk.cyan(` ${e}.`)+" "+chalk.white(a.options[e]));f(),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=c(),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 v(s.explanation,i()-4))console.log(chalk.gray(" "+e));const g=Object.values(a.mcqResults),d=g.filter(e=>e.correct).length;console.log(),console.log(chalk.gray(" "+n("mcq_accuracy_so_far",l)+" ")+chalk.white(`${d}/${g.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=c(),a=o(e,r);p(a,t),f(),b(chalk.bold.yellow("🛠 "+a.title)),b(chalk.gray("─".repeat(Math.min(a.title.length+4,i())))),f();for(const e of v(a.task,i()-4))b(" "+e);if(a.starterCode){f(),b(chalk.gray(" "+n("starter_code",r))),f();for(const e of a.starterCode.split("\n"))b(" "+chalk.cyan(e))}f(),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=c(),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 v(r.successHint,i()-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=c(),a=o(e,r);p(a,t),f(),b(chalk.bold.yellow("🎬 "+a.title)),f();for(const e of v(a.description,i()-4))b(" "+e);f(),b(chalk.gray(" "+n("sim_requires",r))),f(),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=c(),r=t.startsWith("zh"),a=o(e,t);p(a,n),f(),b(chalk.bold.cyan("🏟 "+a.title)),b(chalk.gray(" "+a.origin+" · "+a.domain+" · "+a.metric)),f();for(const e of a.statement){for(const o of v(e,i()-4))b(" "+o);f()}b(chalk.bold.green(r?" 核心要点 — baseline → 解法的关键变化":" CORE DELTA — baseline → solution"));for(const e of a.core_delta)for(const o of v("• "+e,i()-6))b(" "+chalk.white(o));f(),b(chalk.gray((r?" 提交格式: ":" Submission: ")+a.submission_format)),a.hints&&b(chalk.gray(r?" 本题有 5 级提示 (a–e),进入 arena 后逐级解锁。":" 5 progressive hints (a–e) unlock inside the arena.")),f(),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=c(),r=t.startsWith("zh"),a=o(e,t);p(a,n),f(),b(chalk.bold.yellow("🔜 "+a.title)),f();const l=a.note||(r?"这道竞技场题目正在编写中,敬请期待。":"This arena task is coming soon.");for(const e of v(l,i()-4))b(" "+chalk.gray(e));f(),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=c(),a=o(e,r),l=e.number===t.totalCards;console.log(),console.log(chalk.bold.yellow(" ╭"+d("═"))),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 v(a.realWorldLevel,i()-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 v(a.unlockedNext,i()-4))console.log(chalk.bold.yellow(" ║ ")+" "+chalk.white(e));console.log(chalk.bold.yellow(" ║")),console.log(chalk.bold.yellow(" ╰"+d("═"))),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=c(),l=a.startsWith("zh"),s=t.cardsCompleted.length,g=o.totalCards,d=t.checkResults||{},p=r.gate??null,$=!!r.gated,w=r.focus??"current",_=r.posForSlot??(e=>4===e?10:4*e),k=t.currentCard,x=o.modules.find(e=>k>=e.cardRange[0]&&k<=e.cardRange[1]),C=(o,n)=>o+" ".repeat(Math.max(0,n-e((e=>e.replace(/\x1b\[[0-9;]*m/g,""))(o))));console.log();const v=`${o.name} — ${l?"状态":"Status"}`;console.log(chalk.cyan(" ╭─ ")+chalk.bold.white(v)+" "+chalk.cyan("─".repeat(Math.max(4,i()-2-e(v))))),f(),b(" "+chalk.gray(n("total_progress",a)+" ")+h(s,g)+chalk.gray(` (${s}/${g})`)+chalk.gray(" "+n("streak",a)+" ")+u(t.streakDays));{let e=0,n=0,t=0,a=0,s=0,c=0,g=!1;for(const r of o.modules){for(let l=r.cardRange[0];l<=r.cardRange[1];l++){const r=N?N(l):null;r&&(e++,r.solved>=r.total&&n++);const s=o.cards.find(e=>e.number===l);null!=s?.check&&(t++,d[String(l)]?.correct&&a++)}const l=p?.phases.find(e=>e.phase===r.number);if(l?.configured)for(const e of l.contest?.slots??[])s++,e.passed&&c++;l?.research&&(g=!0)}const i=(e,o)=>(e>=o?chalk.green:chalk.white)(`${e}/${o}`),y=[];e&&y.push(chalk.gray(l?"⚔ 练习卡 ":"⚔ practice cards ")+i(n,e)),s&&y.push(chalk.gray(l?"赛场 ":"arena ")+i(c,s)),t&&y.push(chalk.gray(l?"✓ 自测 ":"✓ checks ")+i(a,t)),y.length&&b(" "+y.join(chalk.gray(" "))),r._anyResearch=g}f();const M=e=>l?`阶段 ${e}`:`Phase ${e}`,W=Math.max(10,Math.min(28,i()-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=$&&!!p&&e.number>p.unlocked_through_phase,g=p?.phases.find(o=>o.phase===e.number);let h=0,u=0,m=0;const f=[],v=[];let A=0,S=0,j=0;const z=[];for(let e=n;e<=r;e++){const n=o.cards.find(o=>o.number===e);if(null!=n?.check){h++;const o=d[String(e)];o?(u++,o.correct?m++:v.push(e)):f.push(e)}const t=N?N(e):null;t&&(A++,j+=t.solved,t.solved>=t.total?S++:z.push(`${e}:${t.solved}/${t.total}`))}const P=g?.configured?g.contest?.slots??[]:[],R=e=>e.passed?chalk.green("✅"):e.attempts>0?chalk.yellow("❌"):chalk.gray("⬜"),q=s>=a&&(0===h||m===h)&&(0===A||S===A)&&(0===P.length||P.every(e=>e.passed))&&(!g?.research||g.research.passed),E=s>0||u>0||j>0||P.some(e=>e.attempts>0),L=c?chalk.gray("🔒"):q?chalk.green("✅"):e.number===x?.number?chalk.bold.cyan("▶ "):E?chalk.yellow("▶ "):chalk.gray("⬜"),T=y(e.name,W),O=[];if(O.push((s>=a?chalk.green:chalk.white)(`${s}/${a}`)+chalk.gray(l?"卡":"c")),h>0&&O.push(chalk.gray("✓")+(m===h?chalk.green:chalk.white)(`${m}/${h}`)),A>0&&O.push(chalk.gray("⚔")+(S===A?chalk.green:chalk.white)(`${S}/${A}`)+chalk.gray(l?"卡":"c")),P.length>0&&O.push(chalk.gray(l?"赛":"arena ")+P.map(R).join("")),g?.research&&O.push(chalk.gray("⭐")+(g.research.passed?chalk.green:chalk.white)(`${g.research.good_cards}/${g.research.need_cards}`)),b(" "+L+" "+chalk.white(C(M(e.number),l?5:8))+chalk.gray(C(T,W+1))+O.join(chalk.gray(" · "))),c||"all"!==w&&w!==e.number&&("current"!==w||e.number!==x?.number)){if(!c&&E&&!q){const o=[],t=P.filter(e=>!e.passed).map(o=>(o.attempts>0?chalk.yellow:chalk.gray)(`${e.number}-${o.slot}@${l?"卡":"card "}${n+_(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)):"");z.length&&o.push(chalk.gray("⚔ ")+chalk.white(r(z," "))),v.length&&o.push(chalk.red("✗ ")+chalk.white(r(v.map(String),","))),f.length&&o.push(chalk.gray("○ ")+chalk.white(r(f.map(String),","))),g?.research&&!g.research.passed&&o.push(chalk.gray(`⭐ ${g.research.good_cards}/${g.research.need_cards}`)),o.forEach((e,o)=>b(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??"",y=(l?c._zh?.title??c._zh?.badge??g:g)||"",h=null!=r.check,u=d[String(s)],p=u?u.correct?chalk.green("✓"):chalk.red("✗"):h?chalk.gray("○"):chalk.gray("·"),m=N?N(s):null,f=m?(m.solved>=m.total?chalk.green:m.solved>0?chalk.yellow:chalk.gray)(`⚔${m.solved}/${m.total}`):" ",$=s===k?chalk.bold.cyan("▶"):" ",w=wrapMixed(y,Math.max(16,i()-14-t)),x=w[0]+(w.length>1?"…":"");b(` ${$} `+chalk.gray(String(s).padStart(t))+" "+p+" "+C(f,5)+" "+chalk.white(x));const v=12===a?P.find(e=>n+_(e.slot)-1===s):void 0;if(v){const o=chalk.gray(` ${" ".repeat(t)} ⚔ ${l?"练习赛":"arena"} ${e.number}-${v.slot}: `);v.passed?b(o+chalk.bold.green(`${v.best_ac}/${v.n} AC ✅`)):0===v.attempts?b(o+chalk.gray("⬜ ")+chalk.white(l?`未开始 · ${v.n} 题 · 过 ${v.need} 题 → `:`not started · ${v.n} problems · AC ${v.need} → `)+chalk.bold.green(`contest ${v.slot}`)):b(o+chalk.yellow(l?`❌ 最好 ${v.best_ac}/${v.n}(需 ${v.need})· 已试 ${v.attempts} 次 → `:`❌ best ${v.best_ac}/${v.n} (need ${v.need}) · ${v.attempts} attempt(s) → `)+chalk.bold.green(`contest ${v.slot}`))}}if(12!==a)for(const o of P){const n=chalk.gray(` ⚔ ${l?"练习赛":"arena"} ${e.number}-${o.slot}: `);o.passed?b(n+chalk.bold.green(`${o.best_ac}/${o.n} AC ✅`)):0===o.attempts?b(n+chalk.gray("⬜ ")+chalk.white(l?`未开始 · ${o.n} 题 · 过 ${o.need} 题 → `:`not started · ${o.n} problems · AC ${o.need} → `)+chalk.bold.green(`contest ${o.slot}`)):b(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&&b(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&&b(chalk.gray(l?" 🔒 本阶段通关标准制作中 — 很快更新":" 🔒 pass criteria for this phase in production — coming soon"))}}f(),b(chalk.gray(l?" ✓ 答对 ✗ 答错 ○ 未答 · ⚔ 练习 已过/共 · 赛 ✅ 过 ❌ 试过 ⬜ 未碰"+(r._anyResearch?" · ⭐ 研究":""):" ✓ right ✗ wrong ○ unanswered · ⚔ practice solved/total"+(r._anyResearch?" · ⭐ research":""))),b(chalk.gray(l?" 展开某阶段: ":" arena ✅ passed ❌ tried ⬜ untouched · expand: ")+chalk.bold.green("status all")+chalk.gray(" / ")+chalk.bold.green("status N")),t.achievements.length>0&&b(" "+chalk.gray(n("achievements",a)+" ")+t.achievements.map(e=>chalk.bold.yellow("★ ")+chalk.white(e)).join(chalk.gray(" · "))),f(),m()}function O(e){try{Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}catch{}}export function renderArenaIntro(){const e=c().startsWith("zh"),o=!!process.stdout.isTTY&&!/^(C|POSIX)$/i.test(process.env.LANG||"")&&!process.env.ICOA_TEST_BOOT_MODE,n=e?[chalk.bold.yellow(" ⚔ 你读完 4 张卡了 — 前面是第一个检查点。"),chalk.white(" · 每 4 张卡有一场判分赛:卡 4 / 8 / 12,一个阶段共 3 场。"),chalk.white(" · 敲 ")+chalk.bold.green("contest 1")+chalk.white(" 开始 — 计时器同时开始,题目在赛场里读。"),chalk.white(" · 判分机会真的跑你的代码,不是对答案。"),chalk.white(" · 3 场全过 → 解锁下一阶段。"),chalk.gray(" ▸ 现在不想打?敲 ")+chalk.bold.green("next")+chalk.gray(" 继续读卡,赛场一直在那儿等你。")]:[chalk.bold.yellow(" ⚔ Four cards down — a checkpoint is waiting."),chalk.white(" · Every 4 cards there is a judged arena: cards 4 / 8 / 12, three per phase."),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(" · Pass all three → 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 n)console.log(e),o&&O(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{existsSync as t,mkdirSync as e}from"node:fs";import{homedir as n}from"node:os";import{join as r}from"node:path";import{icoaStandalonePython as s,parsePyVersion as i,REQUIRED_PY as a,resolveRunPython as
|
|
1
|
+
import chalk from"chalk";import{execSync as o}from"node:child_process";import{existsSync as t,mkdirSync as e}from"node:fs";import{homedir as n}from"node:os";import{join as r}from"node:path";import{icoaStandalonePython as s,parsePyVersion as i,REQUIRED_PY as a,resolveHostPython as c,resolveRunPython as l}from"./aienv.js";import{httpFetch as p}from"./http.js";function h(t){try{return o(`${t} --version 2>&1`,{encoding:"utf-8",timeout:4e3}).trim()}catch{return null}}let y,d;export function probePython(o=!1,t={}){const e=t.hostOnly?d:y;if(e&&!o)return e;const r=n(),a=t.hostOnly?(()=>{const o=c(h,process.platform,r);return o?{...o,source:"host"}:null})():l(h,process.platform,r);if(a){const o=(h(a.cmd.includes(" ")?a.cmd:`"${a.cmd}"`)??"").replace(/^Python\s+/i,"")||`${a.version.major}.${a.version.minor}`,e=s(r,process.platform),n="aienv"===a.source?"aienv":a.cmd===e?"icoa":"system",i={ok:!0,version:o,cmd:a.cmd,source:n};return t.hostOnly?d=i:y=i,i}let p;for(const o of["python3","python"]){const t=h(o);if(i(t)){p=(t??"").replace(/^Python\s+/i,"").trim();break}}const u={ok:!1,otherVersion:p};return t.hostOnly?d=u:y=u,u}export function resetPythonProbe(){y=void 0,d=void 0}const u=`${a.major}.${a.minor}`;export function pythonDoorLine(o,t=!1,e){const n=e??probePython(),r=t?"":"🐍 ";if(n.ok){const t="aienv"===n.source?o?"aienv 环境":"aienv venv":"icoa"===n.source?o?"icoa 装的":"installed by icoa":o?"系统自带":"system";return chalk.gray(` ${r}Python ${n.version} · ${t} · `)+chalk.gray(o?"本机可跑代码":"code runs locally")}return n.otherVersion?chalk.gray(` ${r}Python ${n.otherVersion} — `)+chalk.gray(o?`课程按 ${u} 校准 · `:`courses are calibrated on ${u} · `)+chalk.bold.green("python setup")+chalk.gray(o?` 装并存的 ${u}(免 sudo,不动系统 python3)`:" adds one side-by-side (no sudo, system python3 untouched)"):chalk.gray(` ${r}`+(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 n=e??probePython(!1,{hostOnly:!0}),r=t?"":"🐍 ",s=chalk.gray(" (Paper C · SIMOC are MCQ-only — neither is needed)");return n.ok?o?chalk.gray(` ${r}Python ${n.version} · `)+chalk.green("exam toolkit ready"):chalk.gray(` ${r}Python ${n.version} · toolkit not installed · `)+chalk.bold.green("exam setup")+chalk.gray(" (13 packages, ~150 MB)")+s:chalk.gray(` ${r}`+(n.otherVersion?`Python ${n.otherVersion} — the exam runs on ${u} · `:`No Python ${u} 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} — 课程和判分机都在 ${u} 线上。`:` 找不到 Python ${u} — 不是你的代码有问题。`:e.otherVersion?` This machine has Python ${e.otherVersion} only — courses and the judge both run on the ${u} line.`:` Python ${u} 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(),n="aarch64"===e||"arm64"===e,r="x86_64"===e||"amd64"===e||"x64"===e;return"darwin"===o?n?"aarch64-apple-darwin":r?"x86_64-apple-darwin":"":"win32"===o?n?"aarch64-pc-windows-msvc":r?"x86_64-pc-windows-msvc":"":n?"aarch64-unknown-linux-gnu":r?"x86_64-unknown-linux-gnu":""}export function pickStandaloneAsset(o,t){const e=`${a.major}\\.${a.minor}`,n=new RegExp(`^cpython-${e}\\.\\d+\\+\\d+-${t}-install_only_stripped\\.tar\\.gz$`),r=new RegExp(`^cpython-${e}\\.\\d+\\+\\d+-${t}-install_only\\.tar\\.gz$`);return o.find(o=>n.test(o.name))??o.find(o=>r.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)}export async function provisionPython312(i={}){const c=n(),l=r(c,".icoa","python312"),y=s(c,process.platform),d=o=>{i.quiet||console.log(o)};if(!i.force&&t(y)){const o=h(`"${y}"`);if(o&&new RegExp(`^Python ${a.major}\\.${a.minor}\\.`).test(o))return d(chalk.green(` ✓ ${o}`)+chalk.gray(` → ${y}`)),resetPythonProbe(),!0}const m=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"}}(),$=standaloneTriple(process.platform,m);if(!$)return d(chalk.yellow(` ~ No prebuilt Python ${u} for '${m||"unknown"}' on this platform.`)),!1;let g="",f="";try{const o=await p("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??[],$);if(!t)throw new Error(`no CPython ${u} build for ${$} in the latest release`);if(g=t.browser_download_url,f=t.name,!isAllowedAssetUrl(g))throw new Error("asset URL failed the allowlist check")}catch(o){return d(chalk.red(` ✗ Could not resolve a standalone Python ${u}`)+chalk.gray(` (${o.message})`)),!1}const w=f.match(/^cpython-(\d+\.\d+\.\d+)/)?.[1]??u;d(chalk.gray(` Fetching CPython ${w} for ${$} …`));try{e(r(c,".icoa"),{recursive:!0}),"win32"===process.platform?o(`curl.exe -fsSL -o "%TEMP%\\icoa-py.tgz" "${g}" && if exist "${l}" rmdir /s /q "${l}" && mkdir "${l}.tmp" && tar.exe -xzf "%TEMP%\\icoa-py.tgz" -C "${l}.tmp" && move "${l}.tmp\\python" "${l}" && rmdir /s /q "${l}.tmp" && del "%TEMP%\\icoa-py.tgz"`,{stdio:["ignore","ignore","pipe"],shell:"cmd.exe"}):o(`set -e; tmp="$(mktemp -d)"; curl -fsSL -o "$tmp/py.tgz" '${g}'; tar -xzf "$tmp/py.tgz" -C "$tmp"; rm -rf '${l}'; mv "$tmp/python" '${l}'; rm -rf "$tmp"`,{stdio:["ignore","ignore","pipe"]});const t=o(`"${y}" --version`,{encoding:"utf-8"}).trim();if(!new RegExp(`^Python ${a.major}\\.${a.minor}\\.`).test(t))throw new Error(`unexpected version: ${t}`);return resetPythonProbe(),d(chalk.green(` ✓ ${t} installed`)+chalk.gray(` → ${y} (system python3 untouched)`)),!0}catch(o){const t=String(o.stderr??o.message).trim().split("\n").pop();return d(chalk.red(` ✗ Python ${u} install failed`)+chalk.gray(t?` (${t})`:"")),!1}}
|