icoa-cli 2.19.582 → 2.19.583
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
|
|
1
|
+
import{spawn as t}from"node:child_process";import{existsSync as e,mkdirSync as n}from"node:fs";import{homedir as r}from"node:os";import{isAbsolute as o,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='write with `echo "text" > file` here, or open the file in your own terminal',d={vi:c,vim:c,nano:c,emacs:c,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"},u={rm:"deletes for good — the shell has no bin to get it back from",rmdir:"removes a folder for good",unlink:"deletes for good — the shell has no bin to get it back from",shred:"overwrites a file so it can never be recovered",dd:"writes raw bytes over whatever you point it at, disks included"},l=/(^|[;&|(]\s*)(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:xargs\s+(?:-\S+\s+)*)?(rm|rmdir|unlink|shred|dd|mkfs(?:\.\S+)?)(?=\s|$)/;export function destructiveHint(t){const e=l.exec(t.trim());if(e){const t=e[2];return{word:t,why:u[t]??"formats a filesystem — everything on it is gone"}}return/^find\b.*\s-delete(\s|$)/.test(t.trim())?{word:"find -delete",why:"deletes every file it matches, for good"}:null}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 h={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(d[e])return d[e];if(h[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 h[e]}return null}export function resolveCd(t,n,r){const c=r&&"~"!==r?o(r)?r:i(n,r):t,d=s(a(c)),u=s(a(t));return(d===u||d.startsWith(`${u}/`))&&e(d)?d:null}export function labPath(t=process.env,n=r()){const o=i(n,".icoa","python312","bin"),s=t.PATH??"";return!e(o)||s.split(":").includes(o)?s:s?`${o}:${s}`:o}function f(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,r){const o=destructiveHint(n);if(o)return{kind:"refused",reason:o.word,hint:o.why};const i=interactiveHint(n);return i?{kind:"refused",reason:firstWord(n),hint:i}:e("/bin/sh")?await new Promise(e=>{const o=Date.now();let i="",s="",a=!1;const c=t("/bin/sh",["-c",n],{cwd:r,stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:labPath(),PAGER:"cat",GIT_PAGER:"cat",TERM:"dumb"}}),d=setTimeout(()=>{if(!a){a=!0;try{c.kill("SIGKILL")}catch{}e({kind:"timeout",ms:Date.now()-o})}},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(d),e({kind:"ran",stdout:"",stderr:String(t.message),code:127,ms:Date.now()-o,truncated:!1}))}),c.on("close",t=>{if(a)return;a=!0,clearTimeout(d);const n=f(i),r=f(s);e({kind:"ran",stdout:n.text,stderr:r.text,code:t??0,ms:Date.now()-o,truncated:n.truncated||r.truncated})})}):{kind:"no-shell"}}export function shortCwd(t,e){const n=s(a(t)),r=s(a(e));return r===n?"lab":`lab${r.slice(n.length)}`}export function tildePath(t){const e=r();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.583",
|
|
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",
|