icoa-cli 2.19.696 → 2.19.698
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/mujoco-setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import chalk from"chalk";import{execSync as o}from"node:child_process";import{existsSync as
|
|
1
|
+
import chalk from"chalk";import{execSync as o}from"node:child_process";import{existsSync as e,mkdirSync as n,readFileSync as r,rmSync as t,writeFileSync as i}from"node:fs";import{homedir as s}from"node:os";import{posix as c,win32 as a}from"node:path";import{icoaStandalonePython as u,REQUIRED_PY as p}from"./aienv.js";import{pipInstall as m,planPipSources as l}from"./pip-index.js";import{probePython as d,provisionPython312 as y,resetPythonProbe as g}from"./python-setup.js";const h=`${p.major}.${p.minor}`;export const MUJOCO_STANDARD="3.16.0";export const MUJOCO_PACKAGES=[{name:"numpy",module:"numpy",spec:"numpy>=1.26",role:"vectors"},{name:"mujoco",module:"mujoco",spec:"mujoco==3.16.0",role:"physics + rendering",pinned:"3.16.0"},{name:"onnxruntime",module:"onnxruntime",spec:"onnxruntime>=1.18",role:"runs the walking policy"}];export function mujocoPaths(o,e=process.platform){const n="win32"===e?a:c,r=n.join(o,".icoa","mujoco");if("win32"===e){const o=n.join(r,"Scripts");return{root:r,binDir:o,python:n.join(o,"python.exe"),marker:n.join(r,"icoa-mujoco.json")}}const t=n.join(r,"bin");return{root:r,binDir:t,python:n.join(t,"python"),marker:n.join(r,"icoa-mujoco.json")}}let f;export function probeMujoco(n=!1){if(f&&!n)return f;const r=mujocoPaths(s()),t={ok:!1,venv:e(r.python),python:r.python,versions:{},missing:[]};if(!t.venv)return t.missing=MUJOCO_PACKAGES.map(o=>o.module),f=t,t;const i=MUJOCO_PACKAGES.map(o=>o.module),c=["import json, importlib","out = {}",`for m in ${JSON.stringify(i)}:`," try:",' mod = importlib.import_module(m); out[m] = str(getattr(mod, "__version__", "?"))'," except Exception:"," out[m] = None","print(json.dumps(out))",""].join("\n");try{const e=o(`"${r.python}" -`,{input:c,encoding:"utf-8",stdio:["pipe","pipe","ignore"],timeout:2e4}).trim(),n=JSON.parse(e.split("\n").pop()??"{}");for(const o of i)n[o]?t.versions[o]=n[o]:t.missing.push(o)}catch{t.missing=i}return t.ok=0===t.missing.length,f=t,t}export function mujocoVersionsLine(o){return MUJOCO_PACKAGES.filter(e=>o.versions[e.module]).map(e=>`${e.name} ${o.versions[e.module]}`).join(" · ")}export function mujocoDoorLine(o,e=!1,n){const r=n??probeMujoco(),t=e?"":"🦆 ";if(r.ok){const e=r.versions.mujoco&&"3.16.0"!==r.versions.mujoco;return chalk.gray(` ${t}${mujocoVersionsLine(r)} · `)+chalk.gray(o?"本机可跑仿真":"sim runs locally")+(e?chalk.yellow(o?" · 判分机是 mujoco 3.16.0:":" · the judge runs mujoco 3.16.0: ")+chalk.bold.green("mujoco setup")+chalk.yellow(o?" 对齐":" to match"):"")}return r.venv?chalk.gray(` ${t}`+(o?`缺 ${r.missing.join(", ")} · `:`missing ${r.missing.join(", ")} · `))+chalk.bold.green("mujoco setup")+chalk.gray(o?" 补齐":" finishes the install"):chalk.gray(` ${t}${o?"没有 MuJoCo — 读卡答题不需要它,回放可由判分机送回 · ":"No MuJoCo — reading and answering cards works without it, replays can come from the judge · "}`)+chalk.bold.green("mujoco setup")+chalk.gray(o?" 让 run 在本机出图(~45 MB,免 sudo)":" to run the sim here (~45 MB, no sudo)")}function v(e){try{return o(`"${e}" -m pip --version`,{stdio:"ignore",timeout:15e3}),!0}catch{return!1}}function j(o){const e=(o?.stderr?.toString()??"").split("\n").map(o=>o.trim()).filter(Boolean);return e.length?e[e.length-1].slice(0,120):""}export async function provisionMujoco(r={}){const a=o=>{r.quiet||console.log(o)},p=s(),f=mujocoPaths(p);let $=d(!0,{hostOnly:!0});if(!$.ok){if(a(chalk.gray(` No Python ${h} here — installing one first (stage 0, no sudo) …`)),!await y({quiet:r.quiet}))return a(chalk.red(` ✗ Could not get a Python ${h}`)+chalk.gray(" — try ")+chalk.bold.cyan("python setup")),!1;if(g(),$=d(!0,{hostOnly:!0}),!$.ok||!$.cmd)return!1}const x=$.cmd;a(chalk.green(` ✓ Python ${$.version}`)+chalk.gray(` · ${x}`));const O=u(p),b="win32"!==process.platform&&x.replace(/"/g,"")!==O,w=async()=>{if(a(chalk.gray(" This Python 3.12 has no venv/pip (a system build) — switching to the ICOA one …")),!e(O)&&!await y({quiet:r.quiet}))return!1;try{t(f.root,{recursive:!0,force:!0}),o(`"${O}" -m venv "${f.root}"`,{stdio:["ignore","ignore","pipe"]})}catch{return!1}return!!v(f.python)&&(a(chalk.green(" ✓ venv recreated")+chalk.gray(` · ${O}`)),!0)};let C=!1;if(r.force&&e(f.root)){a(chalk.gray(" --force: recreating the venv …")),C=!0;try{o(`${x.includes(" ")?x:`"${x}"`} -m venv --clear "${f.root}"`,{stdio:["ignore","ignore","pipe"]})}catch{}}if(e(f.python))a(C?chalk.green(" ✓ venv recreated"):chalk.green(" ✓ venv exists")+chalk.gray(" — reusing"));else{a(chalk.gray(` Creating venv → ${f.root}`));try{n(c.join(p,".icoa"),{recursive:!0}),o(`${x.includes(" ")?x:`"${x}"`} -m venv "${f.root}"`,{stdio:["ignore","ignore","pipe"]})}catch(o){if(!b||!await w())return a(chalk.red(" ✗ Could not create the venv")+chalk.gray(j(o)?` (${j(o)})`:"")),"linux"===process.platform&&a(chalk.gray(" A distro 3.12 without venv? ")+chalk.bold.cyan("python setup")+chalk.gray(" installs one that has venv and pip built in.")),!1}v(f.python)&&a(chalk.green(" ✓ venv created"))}if(!v(f.python)){a(chalk.gray(" Bootstrapping pip …"));try{o(`"${f.python}" -m ensurepip --upgrade`,{stdio:["ignore","ignore","pipe"]})}catch{}if(!(v(f.python)||b&&await w()))return a(chalk.red(" ✗ The venv has no pip and it could not be bootstrapped.")),a(chalk.gray(" Fix: ")+chalk.bold.cyan("python setup")+chalk.gray(" then ")+chalk.bold.cyan("mujoco setup --force")),!1}const M=probeMujoco(!0);let P=0;const A=o=>!(!M.versions[o.module]||o.pinned&&M.versions[o.module]!==o.pinned),J=MUJOCO_PACKAGES.filter(o=>!A(o)).length?await l(f.python):void 0;J&&a(chalk.gray(` ${J.line}`));for(const o of MUJOCO_PACKAGES)if(A(o))a(chalk.green(` ✓ ${o.name} ${M.versions[o.module]}`)+chalk.gray(" (already installed)"));else{M.versions[o.module]?a(chalk.cyan(` ↻ ${o.name} ${M.versions[o.module]} → ${o.pinned}`)+chalk.gray(" — the judge's version; everyone runs the same one")):a(chalk.cyan(` ⬇ ${o.name}`)+chalk.gray(` ${o.spec} — ${o.role}`));try{m(f.python,o.spec,J,{extra:"-q --only-binary=:all:",onRetry:e=>a(chalk.yellow(` ~ ${o.name}: that source failed — trying ${e.host} …`))})}catch(e){a(chalk.red(` ✗ ${o.name} failed to install`)+chalk.gray(j(e)?` (${j(e)})`:"")),P++}}const _=probeMujoco(!0);for(const o of MUJOCO_PACKAGES)A(o)||(_.versions[o.module]?a(chalk.green(` ✓ ${o.name} ${_.versions[o.module]} installed`)):P||a(chalk.red(` ✗ ${o.name} installed but does not import`)));if(!_.ok)return!1;const k={version:1,hostPython:(function(e){try{return o(`${e} --version`,{encoding:"utf-8",stdio:["ignore","pipe","ignore"],timeout:5e3}).trim()}catch{return null}}(x.includes(" ")?x:`"${x}"`)??$.version??h).replace(/^Python\s+/i,""),venvPython:f.python,packages:MUJOCO_PACKAGES.map(o=>o.name),created:(new Date).toISOString()};try{i(f.marker,`${JSON.stringify(k,null,2)}\n`)}catch{}return!0}export function glCandidates(o=process.platform){return"darwin"===o?["cgl","glfw"]:"linux"===o?["egl","glfw","osmesa"]:["glfw"]}function $(o=s()){return c.join(o,".icoa","duck","gl.json")}export function cachedGl(){try{const o=JSON.parse(r($(),"utf-8"));return 1===o.version?o.backend??null:void 0}catch{return}}export function probeRender(e){for(const r of glCandidates()){const t={...process.env,MUJOCO_GL:r};"osmesa"===r&&(t.PYOPENGL_PLATFORM="osmesa");try{const s=o(`"${e}" -c "import sys, mujoco; r = mujoco.Renderer(mujoco.MjModel.from_xml_string('<mujoco/>'), 8, 8); r.render(); print(sys.executable)"`,{env:t,encoding:"utf-8",stdio:["ignore","pipe","ignore"],timeout:3e4}).trim().split("\n").pop();try{n(c.dirname($()),{recursive:!0}),i($(),JSON.stringify({version:1,python:s||e,backend:r}))}catch{}return r}catch{}}try{t($(),{force:!0})}catch{}return null}export function renderLines(o,e=process.platform){if(o)return[chalk.green(` ✓ Pictures: MuJoCo can draw here (${o})`)+chalk.gray(" — the duck sandbox shows video")];const n=[chalk.yellow(" ⚠ Pictures: MuJoCo cannot draw on this machine")+chalk.gray(" — the sim still runs, the duck sandbox shows text only.")];return"linux"===e&&n.push(chalk.gray(" Fix: ")+chalk.cyan("sudo apt install -y libosmesa6")+chalk.gray(" then ")+chalk.bold.cyan("mujoco setup")+chalk.gray(" again.")),n}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.698",
|
|
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",
|