UNPKG

rawi

Version:

Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into

6 lines 7.45 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into an intelligent development workspace. */ var _chunkOWJR5FYZcjs = require('./chunk-OWJR5FYZ.cjs');var _child_process = require('child_process');var _os = require('os'); var r = _interopRequireWildcard(_os);var _util = require('util');var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);var m=_util.promisify.call(void 0, _child_process.exec);function h(e){let t=e||_chunkOWJR5FYZcjs.a.call(void 0, );if(process.platform==="win32")switch(t){case"pwsh":return{shell:"pwsh.exe",args:["-NoProfile","-Command"]};case"powershell":return{shell:"powershell.exe",args:["-NoProfile","-Command"]};case"cmd":return{shell:"cmd.exe",args:["/c"]};default:return{shell:"pwsh.exe",args:["-NoProfile","-Command"]}}else return{shell:e||process.env.SHELL||"/bin/bash",args:["-c"]}}var x=["btop","htop","top","nano","vim","nvim","emacs","less","more","vi","tmux","screen","watch","tail -f","journalctl -f","docker exec -it","kubectl exec -it","ssh","mysql","psql","mongo","redis-cli","python3 -i","python -i","node -i","irb","ghci"];function b(e){let t=e.trim().toLowerCase();return x.some(s=>t.startsWith(s)||t.includes(` ${s}`))}async function R(e){let t=Date.now();if(e.copyCommand&&setTimeout(()=>{S(e.command).then(c=>c&&console.log(_chalk2.default.dim("\u{1F4CB} Command copied to clipboard"))).catch(()=>{})},0),e.dryRun)return{command:e.command,stdout:"[DRY RUN] Command would be executed here",stderr:void 0,exitCode:0,executionTime:Date.now()-t,success:!0};if(e.interactive||b(e.command))return await C(e,t);try{e.command.includes("ssh-add")&&await y();let c=h(e.shell),n={cwd:e.cwd||process.cwd(),timeout:e.timeout||3e4,maxBuffer:1024*1024,encoding:"utf8"};process.platform==="win32"?(n.shell="cmd.exe",n.windowsHide=!0):n.shell=c.shell;let{stdout:o,stderr:i}=await m(e.command,n),a=Date.now()-t;return{command:e.command,stdout:_optionalChain([o, 'optionalAccess', _ => _.toString, 'call', _2 => _2()])||void 0,stderr:_optionalChain([i, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()])||void 0,exitCode:0,executionTime:a,success:!0}}catch(c){let n=Date.now()-t;return{command:e.command,stdout:c.stdout||void 0,stderr:c.stderr||c.message,exitCode:c.code||1,executionTime:n,success:!1}}}async function C(e,t){return new Promise(s=>{let c=h(e.shell),n;process.platform==="win32"?n=_child_process.spawn.call(void 0, "cmd.exe",["/c",e.command],{stdio:"inherit",cwd:e.cwd||process.cwd(),windowsHide:!1}):n=_child_process.spawn.call(void 0, c.shell,["-c",e.command],{stdio:"inherit",cwd:e.cwd||process.cwd()}),n.on("exit",o=>{let i=Date.now()-t;s({command:e.command,stdout:void 0,stderr:o!==0?`Process exited with code ${o}`:void 0,exitCode:o||0,executionTime:i,success:o===0})}),n.on("error",o=>{let i=Date.now()-t;s({command:e.command,stdout:void 0,stderr:o.message,exitCode:1,executionTime:i,success:!1})})})}async function y(){if(process.env.SSH_AUTH_SOCK){console.log("\u{1F511} SSH agent is already running.");return}console.log("\u{1F680} Starting SSH agent...");try{let{stdout:e}=await m("ssh-agent -s");if(e.split(` `).forEach(t=>{let s=t.match(/^(SSH_AUTH_SOCK|SSH_AGENT_PID)=(.*?);/);s&&(process.env[s[1]]=s[2])}),!process.env.SSH_AUTH_SOCK)throw new Error("Failed to start ssh-agent")}catch(e){console.warn("Warning: Could not start SSH agent:",e)}}function T(e){let t=[];return t.push(`\u{1F916} Command: ${e.command}`),t.push(`\u23F1\uFE0F Execution time: ${e.executionTime}ms`),e.success?(t.push("\u2705 Success"),e.stdout&&(t.push("\u{1F4C4} Output:"),t.push(e.stdout))):(t.push(`\u274C Failed (exit code: ${e.exitCode})`),e.stderr&&(t.push("\u26A0\uFE0F Error:"),t.push(e.stderr))),t.join(` `)}async function $(){let e="";try{if(process.platform==="win32"){let{stdout:t}=await m("dir /b",{encoding:"utf8"});e=t}else{let{stdout:t}=await m("ls",{encoding:"utf8"});e=t}}catch (e2){e="Unable to get directory listing"}return{os:{type:r.type(),release:r.release(),platform:r.platform(),arch:r.arch()},node:{version:process.version},shell:process.env.SHELL||_chunkOWJR5FYZcjs.a.call(void 0, )||"unknown",cwd:process.cwd(),home:r.homedir(),cpu:{model:_optionalChain([r, 'access', _5 => _5.cpus, 'call', _6 => _6(), 'access', _7 => _7[0], 'optionalAccess', _8 => _8.model])||"unknown",cores:r.cpus().length},memory:{total:Math.floor(r.totalmem()/1024/1024),free:Math.floor(r.freemem()/1024/1024)},directoryListing:e}}async function S(e){if(!e||e.trim()==="")return!1;let t=await Promise.resolve().then(() => _interopRequireWildcard(require("fs/promises"))),s=await Promise.resolve().then(() => _interopRequireWildcard(require("path"))),c=await Promise.resolve().then(() => _interopRequireWildcard(require("os"))),{execSync:n}=await Promise.resolve().then(() => _interopRequireWildcard(require("child_process"))),o=s.join(c.tmpdir(),`clipboard-${Date.now()}.txt`);try{if(await t.writeFile(o,e,{flag:"w"}),process.platform==="darwin")n(`pbcopy < "${o}"`,{stdio:"ignore"});else if(process.platform==="win32")n(`type "${o}" | clip`,{stdio:"ignore"});else try{n(`xclip -selection clipboard < "${o}"`,{stdio:"ignore"})}catch (e3){n(`xsel --clipboard --input < "${o}"`,{stdio:"ignore"})}return!0}catch (e4){return!1}finally{t.unlink(o).catch(()=>{})}}function k(e,t={}){if(!e)return"";let{maxLength:s=1e4,removeAnsi:c=!0,extractCodeBlock:n=!1}=t,o=e.length>s?`${e.substring(0,s)}... (truncated)`:e;if(c){let a=new RegExp("\x1B\\[\\d+m","g");o=o.replace(a,"")}if(n){let i=/```(?:[^\n]*)\n([\s\S]*?)```/g,a=null,d=[...o.matchAll(i)];if(d.length>0){let u=d[d.length-1];u[1]&&(a=u[1])}a&&(o=a)}return o}function A(e){return[/\brm\s+(-rf?|--recursive|--force)\b.*\//,/\bdd\s+.*of=/,/\bmkfs\b/,/\bformat\b/,/\bshred\b/,/\b:(){:|:&};:\b/,/\bchmod\s+-R\s+777\b/,/\b>.*\/(etc|var|usr)\//,/\bwget\s+.*\s+\|\s+bash\b/,/\bcurl\s+.*\s+\|\s+bash\b/].some(s=>s.test(e.toLowerCase()))}exports.a = R; exports.b = T; exports.c = $; exports.d = S; exports.e = k; exports.f = A; /* Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into an intelligent development workspace. */ //# sourceMappingURL=chunk-MGIUGMP2.cjs.map