icoa-cli 2.19.553 → 2.19.555
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/sh-lab.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawn as t}from"node:child_process";import{existsSync as e,mkdirSync as n}from"node:fs";import{homedir as o}from"node:os";import{isAbsolute as r,join as i,normalize as s,resolve as
|
|
1
|
+
import{spawn as t}from"node:child_process";import{existsSync as e,mkdirSync as n}from"node:fs";import{homedir as o}from"node:os";import{isAbsolute as r,join as i,normalize as s,resolve as a}from"node:path";export const SH_TIMEOUT_MS=3e4;export const SH_MAX_LINES=200;export const SH_MAX_BYTES=262144;const c={vi:"edit",vim:"edit",nano:"edit",emacs:"edit",less:"use `cat` or `head -n 40`",more:"use `cat` or `head -n 40`",top:"use `ps aux`",htop:"use `ps aux`",man:"use `<cmd> --help`",ssh:"not from inside icoa",sftp:"not from inside icoa",telnet:"not from inside icoa",ftp:"not from inside icoa",tmux:"run it in your own terminal",screen:"run it in your own terminal",sudo:"the lab never needs root",su:"the lab never needs root"};export function labRoot(t,e){return i(t,"icoa-lab",e)}export function labCardDir(t,e,n){return i(labRoot(t,e),`card-${n}`)}export function ensureLabDir(t){try{n(t,{recursive:!0})}catch{}return t}export function firstWord(t){for(const e of t.trim().split(/\s+/))if(!/^[A-Za-z_][A-Za-z0-9_]*=/.test(e))return e;return""}const u={node:'bare `node` opens a REPL — use `node -e "…"`',python:'bare `python` opens a REPL — use `/py`, or `python3 -c "…"`',python3:'bare `python3` opens a REPL — use `/py`, or `python3 -c "…"`',ipython:"use `/py`",irb:'bare `irb` opens a REPL — use `ruby -e "…"`'};export function interactiveHint(t){const e=firstWord(t);if(c[e])return c[e];if(u[e]){const n=t.trim().split(/\s+/).filter(t=>!/^[A-Za-z_][A-Za-z0-9_]*=/.test(t)).slice(1);if(0===n.length||n.every(t=>"-i"===t||"--interactive"===t))return u[e]}return null}export function resolveCd(t,n,o){const c=o&&"~"!==o?r(o)?o:i(n,o):t,u=s(a(c)),d=s(a(t));return(u===d||u.startsWith(`${d}/`))&&e(u)?u:null}function d(t){let e=t.length>262144?t.slice(0,262144):t;const n=e.split("\n");return n.length>200?(e=n.slice(0,200).join("\n"),{text:e,truncated:!0}):{text:e,truncated:t.length>262144}}export async function runShell(n,o){const r=interactiveHint(n);return r?{kind:"refused",reason:firstWord(n),hint:r}:e("/bin/sh")?await new Promise(e=>{const r=Date.now();let i="",s="",a=!1;const c=t("/bin/sh",["-c",n],{cwd:o,stdio:["ignore","pipe","pipe"],env:{...process.env,PAGER:"cat",GIT_PAGER:"cat",TERM:"dumb"}}),u=setTimeout(()=>{if(!a){a=!0;try{c.kill("SIGKILL")}catch{}e({kind:"timeout",ms:Date.now()-r})}},3e4);c.stdout?.on("data",t=>{i.length<262144&&(i+=String(t))}),c.stderr?.on("data",t=>{s.length<262144&&(s+=String(t))}),c.on("error",t=>{a||(a=!0,clearTimeout(u),e({kind:"ran",stdout:"",stderr:String(t.message),code:127,ms:Date.now()-r,truncated:!1}))}),c.on("close",t=>{if(a)return;a=!0,clearTimeout(u);const n=d(i),o=d(s);e({kind:"ran",stdout:n.text,stderr:o.text,code:t??0,ms:Date.now()-r,truncated:n.truncated||o.truncated})})}):{kind:"no-shell"}}export function shortCwd(t,e){const n=s(a(t)),o=s(a(e));return o===n?"lab":`lab${o.slice(n.length)}`}export function tildePath(t){const e=o();return t.startsWith(e)?`~${t.slice(e.length)}`:t}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.555",
|
|
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",
|