icoa-cli 2.19.524 → 2.19.525
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import chalk from"chalk";import t from"string-width";export const CREDITS_LINE_MS=350;export function creditsProgress(t,e,s){const c=t.cards.filter(t=>"knowledge"===t.type&&Boolean(t.check)).length,o=Object.keys(e.checkResults??{}).length;let
|
|
1
|
+
import chalk from"chalk";import t from"string-width";export const CREDITS_LINE_MS=350;export function creditsProgress(t,e,s){const c=t.cards.filter(t=>"knowledge"===t.type&&Boolean(t.check)).length,o=Object.keys(e.checkResults??{}).length;let a=0,r=0;for(const t of s?.practice??[])a+=t.total,r+=Math.min(t.total,t.solved.length);let n=0,l=0;for(const t of s?.phases??[]){const e=t.contest;e&&(e.slots&&e.slots.length>0?(n+=e.slots.length,l+=e.slots.filter(t=>t.passed).length):"number"==typeof e.group_count&&e.group_count>0?(n+=e.group_count,l+=e.groups_passed??0):(n+=1,l+=e.passed?1:0))}return{checks:[o,c],practice:[r,a],contests:[l,n],complete:c>0&&o>=c&&r>=a&&l>=n&&(null!==s||0===a&&0===n)}}function e(t,e){if(!t)return null;const s=new Date(t);return Number.isNaN(s.getTime())?null:e?`${s.getMonth()+1} 月 ${s.getDate()} 日`:s.toLocaleDateString("en-AU",{day:"numeric",month:"short",year:"numeric"})}function s(t){return t.toUpperCase().split("").join(" ")}export function buildCreditLines(c,o,a,r,n,l,i){const d=Math.max(48,Math.min(l,72)),h=(e,s=d)=>" ".repeat(Math.max(0,Math.floor((s-t(e))/2)))+e,u=(i?"=":"━").repeat(Math.min(34,d-8)),p=[],$=c.credits,[m,g]=c.curriculum_id.includes("-")?[c.curriculum_id.slice(0,c.curriculum_id.lastIndexOf("-")),c.curriculum_id.slice(c.curriculum_id.lastIndexOf("-")+1)]:[c.curriculum_id,""],f=`${s(m)}${g?` · ${s(g)}`:""}`;p.push(""),p.push(chalk.cyan(h(u))),p.push(chalk.bold.white(h(f))),p.push(chalk.gray(h(n?"一段学习的故事":"a learning story"))),a&&a!==c.curriculum_id&&p.push(chalk.gray(h(a.slice(0,d-4)))),p.push(chalk.cyan(h(u))),p.push("");const _=Math.min(40,d-20),k=(e,s)=>{const c=Math.max(2,_-t(e));p.push(chalk.gray(` ${e} ${".".repeat(c)} `)+chalk.white((t=>i?t.replace(/ · /g," - "):t)(s)))};var y;k(n?"主演":"Starring",(y=c.token,/^[A-Z]{2}[A-Z0-9]{8}$/i.test(y)?`${y.slice(0,2)}••••••${y.slice(-2)}`:y));const b=e($?.opening_night??c.first_seen,n);if(b&&k(n?"开场之夜":"Opening night",`${b} · ${n?"第 1 张卡":"card 1"}`),$&&$.active_days>0){const t=r.longestStreak&&r.longestStreak>1?n?` · 最长连续 ${r.longestStreak} 天`:` · longest streak ${r.longestStreak}`:"";k(n?"伏案之夜":"Nights at the desk",`${$.active_days}${t}`)}if(k(n?"卡片":"Cards",`${c.cards_done} / ${c.total_cards}`),$&&$.checks_total>0&&k(n?"自测":"Checks",n?`答了 ${$.checks_answered} / ${$.checks_total} · ${$.checks_correct} 次一击即中`:`${$.checks_answered} / ${$.checks_total} answered · ${$.checks_correct} first-try`),c.practice.total>0&&k(n?"练习":"Practice",`${c.practice.ac} / ${c.practice.total} AC`),c.contests.total>0){const t=c.contests.carried>0?` (${c.contests.carried} ✅↗)`:"";k(n?"检查点":"Checkpoints",`${c.contests.passed} / ${c.contests.total} ${n?"过线":"passed"}${t}`)}c.research_cards>0&&k(n?"研究":"Research",n?`${c.research_cards} 张卡上榜`:`${c.research_cards} cards on the board`);const w=c.medals;if(w.gold+w.silver+w.bronze>0&&k(n?"奖牌":"Medals",`${w.gold} ${i?"gold":"🥇"} ${w.silver} ${i?"silver":"🥈"} ${w.bronze} ${i?"bronze":"🥉"}`),$?.best_day){const t=e($.best_day.date,n);t&&k(n?"最快的一夜":"Fastest night",n?`${t} · ${$.best_day.cards} 张卡`:`${t} · ${$.best_day.cards} cards`)}if(o&&o.focus.sessions>0){const t=Math.floor(o.focus.total_min/60),e=o.focus.total_min%60;k(n?"专注":"Focus sessions",`${o.focus.sessions} · ${t>0?`${t}h `:""}${e}m`)}r.bookmarks&&r.bookmarks>0&&k(n?"折角的卡":"Dog-eared cards",`${r.bookmarks}`),p.push(""),p.push(chalk.cyan(h(u)));let M=null,x=!1;for(const t of o?.ladders??[]){const e=t.steps.findIndex(t=>t.curriculum_id===c.curriculum_id);if(e<0)continue;const s=t.steps.slice(e+1).find(t=>"done"!==t.state);s?M=s.curriculum_id+("soon"===s.state?n?"(即将上线)":" (soon)":""):x=!0;break}M?k(n?"阶梯的下一级":"Next on the ladder",M):x&&p.push(chalk.gray(h(n?"— 你已站在这条阶梯的顶端 —":"— you reached the top of this ladder —"))),p.push("");const v=Boolean($?.completed);if(v)p.push(chalk.bold.white(h(n?"— 剧终 —":"— fin —")));else{const t=[];$&&$.checks_total>0&&t.push(n?`自测 ${$.checks_answered}/${$.checks_total}`:`checks ${$.checks_answered}/${$.checks_total}`),c.practice.total>0&&t.push(n?`练习 ${c.practice.ac}/${c.practice.total} AC`:`practice ${c.practice.ac}/${c.practice.total} AC`),c.contests.total>0&&t.push(n?`检查点 ${c.contests.passed}/${c.contests.total}`:`checkpoints ${c.contests.passed}/${c.contests.total}`),t.length&&k(n?"离谢幕还差":"To the credits",t.join(" · ")),p.push(""),p.push(chalk.bold.white(h(n?"— 未完待续 —":"— to be continued —")))}p.push("");const C=v?e($?.completed_at??c.last_seen,n):null;return p.push(chalk.gray(` ${i?"share:":"📋 share:"} `)+chalk.white(`${c.curriculum_id} ${v?i?"done":"✓":`${c.cards_done}/${c.total_cards}`}${v?` · ${c.total_cards} cards`:" cards"}`+(c.contests.total>0?` · ${c.contests.total} checkpoints`:"")+($&&$.active_days>0?` · ${$.active_days} night${1===$.active_days?"":"s"}`:"")+(C?` · ${C}`:"")+" · icoa-cli")),p}export async function rollCredits(t,e,s=350){for(let c=0;c<t.length;c++)console.log(t[c]),c<t.length-1&&!e()&&await new Promise(e=>setTimeout(e,""===t[c]?Math.round(s/2):s))}export function storyListLines(t,e){const s=[];return s.push(chalk.bold.white(e?" 📖 你的故事 — 选一门:":" 📖 Your stories — pick one:")),t.tokens.forEach((t,c)=>{const o=t.credits?.completed?e?" 🏁 已通关":" 🏁 complete":` ${t.cards_done}/${t.total_cards}`;s.push(chalk.green(` ${c+1} `)+chalk.white(t.curriculum_id.padEnd(18))+chalk.gray(o))}),s.push(chalk.gray(e?" story <序号|课程名> 观看 · 例如 story 1":" story <n|track> to watch · e.g. story 1")),s}export function creditsRoadLines(e,s,c,o,a=6){const r=[];for(const t of c?.phases??[]){const s=e.modules.find(e=>e.number===t.phase),c=t.contest?.slots??[];for(const e of c){if(e.passed)continue;let a=null;if(s){const[t,o]=s.cardRange,r=o-t+1,n=Math.max(1,c.findIndex(t=>t.slot===e.slot)+1);a=t+Math.min(r,Math.ceil(n*r/Math.max(1,c.length)))-1}const n=e.title?e.title:o?`阶段 ${t.phase} 检查点 ${e.slot}`:`phase ${t.phase} checkpoint ${e.slot}`;r.push({label:n,cmd:null!==a?o?`card ${a},再 contest ${e.slot}`:`card ${a}, then contest ${e.slot}`:`contest ${e.slot}`})}}for(const t of c?.practice??[]){const e=t.total-Math.min(t.total,t.solved.length);e>0&&r.push({label:o?`第 ${t.card} 张卡的练习(还差 ${e} 题)`:`practice on card ${t.card} (${e} left)`,cmd:o?`card ${t.card},再 practice 1`:`card ${t.card}, then practice 1`})}const n=new Set(Object.keys(s.checkResults??{}).map(Number));for(const t of e.cards)"knowledge"===t.type&&t.check&&!n.has(t.number)&&r.push({label:o?`第 ${t.number} 张卡的自测`:`check on card ${t.number}`,cmd:`card ${t.number}`});const l=[],i=Math.min(34,Math.max(...r.map(e=>t(e.label)),10)+2);for(const e of r.slice(0,a)){const s=Math.max(2,i-t(e.label));l.push(chalk.green(" ▸ ")+chalk.white(e.label)+chalk.gray(` ${".".repeat(s)} `)+chalk.bold.green(e.cmd))}return r.length>a&&l.push(chalk.gray(o?` …还有 ${r.length-a} 项`:` … +${r.length-a} more`)),l}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.525",
|
|
4
4
|
"description": "ICOA CLI — The world's first CLI-native cyber & AI security olympiad terminal: AI4CTF (Day 1), CTF4AI (Day 2), VLA4CTF (Pioneer Round — embodied AI)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|