icoa-cli 2.19.679 → 2.19.680
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/aienv.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/arena-edit-dynamics.js +1 -1
- package/dist/lib/editor-spawn.js +1 -1
- package/dist/lib/paste-probe.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export function emptyDynamics(){return{editSessions:0,editMs:0,bytesFinal:0,bytesAdded:0,maxBytesPerSec:0,runs:0}}export function foldEditSession(e,
|
|
1
|
+
export function emptyDynamics(){return{editSessions:0,editMs:0,bytesFinal:0,bytesAdded:0,maxBytesPerSec:0,runs:0}}export function foldEditSession(e,s){const t=s.bytesAfter-s.bytesBefore,n=Math.max(1,s.ms/1e3),a=t>0?t/n:0;return{...e,editSessions:e.editSessions+1,editMs:e.editMs+Math.max(0,s.ms),bytesFinal:s.bytesAfter,bytesAdded:e.bytesAdded+t,maxBytesPerSec:Math.max(e.maxBytesPerSec,Math.round(10*a)/10),runs:e.runs}}export function noteRun(e){return{...e,runs:e.runs+1}}export function isEmpty(e){return 0===e.editSessions&&0===e.runs}export function foldPasteSession(e,s){const t=void 0===e.pasteProbe||e.pasteProbe===s.pasteProbe?s.pasteProbe:"mixed";return{...e,pasteProbe:t,pastes:(e.pastes??0)+s.pastes,pasteBytes:(e.pasteBytes??0)+s.pasteBytes,maxPasteBytes:Math.max(e.maxPasteBytes??0,s.maxPasteBytes),yanks:(e.yanks??0)+s.yanks}}
|
package/dist/lib/editor-spawn.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawnSync as t}from"node:child_process";import{mkdtempSync as e,readFileSync as
|
|
1
|
+
import{spawnSync as t}from"node:child_process";import{mkdtempSync as e,readFileSync as o,rmSync as r,writeFileSync as n}from"node:fs";import{tmpdir as s}from"node:os";import{join as i}from"node:path";import chalk from"chalk";import{getConfig as c}from"./config.js";import{rearmFocusMode as p}from"./input-dynamics.js";import{logCommand as a}from"./logger.js";import{startPasteProbe as m}from"./paste-probe.js";const d=["-c","set nocompatible","-c","set backspace=indent,eol,start","-c","silent! set complete=. completeopt=menu,menuone"],u=new Set(["vi","vim","vim.tiny","vim.basic","vimx"]),l=new Map;function f(e){const o=l.get(e);if(void 0!==o)return o;let r="";try{r=t(e,["--version"],{encoding:"utf8",timeout:2e3}).stdout??""}catch{r=""}return l.set(e,r),r}function v(t){return/VIM - Vi IMproved/.test(f(t))}export function probeVimInsertExpand(t){return/\+insert_expand/.test(f(t))}export function probeVimEval(t){const e=f(t);return/VIM - Vi IMproved/.test(e)&&/\+eval/.test(e)}export function buildEditorArgv(t,e,o=v){return function(t){const e=(t.split(/[\\/]/).pop()??"").toLowerCase().replace(/\.exe$/,"");return u.has(e)}(t.cmd)&&o(t.cmd)?[...t.args,...d,e]:[...t.args,e]}export function resolveEditor(t=process.env,e=process.platform){const o=(t.VISUAL??"").trim()||(t.EDITOR??"").trim();if(o){const t=o.split(/\s+/);return{cmd:t[0],args:t.slice(1)}}return"win32"===e?{cmd:"notepad",args:[]}:{cmd:"vi",args:[]}}export function editTextInEditor(d,u=".py"){const l=e(i(s(),"icoa-cell-")),f=i(l,`cell${u}`);n(f,""===d||d.endsWith("\n")?d:`${d}\n`);const v=resolveEditor(),g=process.stdin,h=!!g.isTTY&&g.isRaw;try{g.isTTY&&g.setRawMode(!1);const e=Date.now(),r=m(v.cmd),n=buildEditorArgv(v,f);"vim"===r.kind&&console.log(chalk.gray((c().language||"en").toLowerCase().startsWith("zh")?" 注意:编辑器里的复制 / 粘贴会被记录(只记次数与字节数,不记内容)。":" Note: copy / paste in the editor is recorded (counts and sizes only, never the text)."));const s=t(v.cmd,[...n.slice(0,-1),...r.args,f],{stdio:"inherit"}),i=r.finish();if(s.error||0!==s.status)return null;const p=o(f,"utf8");try{a(`editor-session cell${u}`,{ms:Date.now()-e,bytesBefore:Buffer.byteLength(d,"utf8"),bytesAfter:Buffer.byteLength(p,"utf8"),paste:i})}catch{}return p}catch{return null}finally{g.isTTY&&h&&g.setRawMode(!0),p(),r(l,{recursive:!0,force:!0})}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync as n,mkdirSync as e,readFileSync as t,rmSync as a,writeFileSync as o}from"node:fs";import{join as s}from"node:path";import{getIcoaDir as i}from"./config.js";import{probeVimEval as c}from"./editor-spawn.js";export const PASTE_LOG_VIM="\" ICOA paste probe — counts only, never text. See src/lib/paste-probe.ts.\nif exists('g:icoa_paste_loaded') || !exists('g:icoa_paste_log')\n finish\nendif\nlet g:icoa_paste_loaded = 1\nfunction! IcoaPasteSize() abort\n let n = line2byte(line('$') + 1) - 1\n if n < 0\n let n = 0\n for l in getline(1, '$')\n let n += strlen(l) + 1\n endfor\n endif\n return n\nendfunction\nfunction! IcoaPasteLog(kind, bytes, lines) abort\n try\n call writefile([printf('{\"kind\":\"%s\",\"bytes\":%d,\"lines\":%d,\"t\":%d}', a:kind, a:bytes, a:lines, localtime())], g:icoa_paste_log, 'a')\n catch\n endtry\nendfunction\nfunction! IcoaPasteInit() abort\n let b:icoa_bytes = IcoaPasteSize()\n let b:icoa_lines = line('$')\n let b:icoa_max = changenr()\nendfunction\nfunction! IcoaPasteCheck(mode) abort\n try\n if !exists('b:icoa_bytes')\n call IcoaPasteInit()\n return\n endif\n let sz = IcoaPasteSize()\n let ln = line('$')\n let cnr = changenr()\n let db = sz - b:icoa_bytes\n let dl = ln - b:icoa_lines\n let fresh = a:mode ==# 'i' ? cnr >= b:icoa_max : cnr > b:icoa_max\n let burst = a:mode ==# 'i' ? (db >= 16 || dl >= 2) : (db >= 16 || dl >= 1)\n if a:mode !=# 'p' && fresh && burst\n call IcoaPasteLog(a:mode ==# 'i' ? 'insert-burst' : 'put', db, dl)\n endif\n let b:icoa_bytes = sz\n let b:icoa_lines = ln\n if cnr > b:icoa_max\n let b:icoa_max = cnr\n endif\n catch\n endtry\nendfunction\nfunction! IcoaPasteYank(contents) abort\n try\n let n = 0\n for l in a:contents\n let n += strlen(l) + 1\n endfor\n call IcoaPasteLog('yank', n, len(a:contents))\n catch\n endtry\nendfunction\naugroup icoa_paste\n autocmd!\n autocmd BufReadPost,BufNewFile,BufWinEnter * silent! call IcoaPasteInit()\n autocmd TextChangedI * silent! call IcoaPasteCheck('i')\n autocmd TextChangedP * silent! call IcoaPasteCheck('p')\n autocmd TextChanged * silent! call IcoaPasteCheck('n')\n silent! autocmd TextYankPost * if v:event.operator ==# 'y' | silent! call IcoaPasteYank(v:event.regcontents) | endif\naugroup END\nsilent! call IcoaPasteInit()\n";export function summarizePasteLog(n,e="vim"){const t={pasteProbe:e,pastes:0,pasteBytes:0,maxPasteBytes:0,yanks:0,events:[]};for(const e of n.split("\n")){if(!e.trim())continue;let n;try{n=JSON.parse(e)}catch{continue}const a="string"==typeof n.kind?n.kind:"",o=Number(n.bytes)||0,s=Number(n.lines)||0,i=Number(n.t)||0;if("yank"===a)t.yanks++;else{if("insert-burst"!==a&&"put"!==a)continue;t.pastes++,t.pasteBytes+=o,t.maxPasteBytes=Math.max(t.maxPasteBytes,o)}t.events.length<50&&t.events.push({kind:a,bytes:o,lines:s,t:i})}return t}export function vimQuote(n){return`'${n.replace(/'/g,"''")}'`}export function pasteProbeArgs(n,e){return["-c",`let g:icoa_paste_log = ${vimQuote(e)}`,"-c",`silent! execute 'source' fnameescape(${vimQuote(n)})`]}export function startPasteProbe(r="vi",l=c){const u={kind:"none",args:[],finish:()=>summarizePasteLog("","none")};try{if(!l(r))return u;const c=s(i(),"vim");e(c,{recursive:!0});const d=s(c,"paste-log.vim");let f="";try{f=t(d,"utf8")}catch{}f!==PASTE_LOG_VIM&&o(d,PASTE_LOG_VIM);const m=s(c,`paste-${process.pid}-${Date.now()}.log`);return{kind:"vim",args:pasteProbeArgs(d,m),finish:()=>{let e="";try{n(m)&&(e=t(m,"utf8")),a(m,{force:!0})}catch{}return summarizePasteLog(e,"vim")}}}catch{return u}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.680",
|
|
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",
|