Lines 1-21javascript
2import{program as k}from"commander";var L="1.0.30";import Mn from"os";function Ln(e){try{let t=JSON.parse(e);return typeof t.code=="string"?t.code:null}catch{return null}}var Me=class extends Error{constructor(n,r){super(`Registration failed (${n}): ${r}`);this.status=n;this.body=r;this.name="RegistrationError",this.code=Ln(r)}status;body;code};async function Le(e,t,n={}){let r={hostname:Mn.hostname(),platform:process.platform,arch:process.arch,agentVersion:L,...t?{deviceId:t.deviceId,deviceSecret:t.deviceSecret}:{},...n.forceNew?{forceNew:!0}:n.currentCode?{currentCode:n.currentCode}:{}},s=aw ...
3`),process.exit(127)}let m={...process.env,PATH:jn},y=Vn(i,c,{stdio:"inherit",env:m,shell:!1}),u=!1;return y.on("error",f=>{u||(u=!0,process.stderr.write(`secure-exec: spawn failed: ${f.message}
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
dist/bin/agent.jsView on unpkg · L1 HighCommand Output Exfiltration
Source combines command execution, command-output handling, and outbound requests; review data flow before blocking.
dist/bin/agent.jsView on unpkg · L1 MediumInstall Persistence
Source writes installer persistence such as shell profile or service configuration.
dist/bin/agent.js 4`),process.exit(127))}),y.on("exit",(f,p)=>{if(!u){if(u=!0,p){let E=Bn.signals[p];process.exit(128+(typeof E=="number"?E:0))}process.exit(f??0)}}),!0}var Jn=4294967295,Yn=new Set(pt);function Ve(e,t){if(!/^\d+$/.test(e))throw new Error(`invalid numeric id in ${t}`);let n=Number(e);if(!Number.isSafeInteger(n)||n<0||n>Jn)throw new Error(`invalid numeric id in ${t}`);return n}function qn(){let e;try{e=Ct("/etc/group","utf8")}catch{throw new Error("cannot read /etc/group to verify secure-exec group membership")}let t=[],n=new Set,r=new Set;for(let[s,i]of e.split(`
5`).entries()){if(i==="")continue;let c=i.split(":");if(c.length!==4)throw new Error(`malformed /etc/group entry at line ${s+1}`);let a=c[0],d=Ve(c[2],`/etc/group line ${s+1}`),l=c[3];if(!a||/[\s,\u0000-\u001f\u007f]/.test(a))throw new Error(`malformed /etc/group entry at line ${s+1}`);let m=l===""?[]:l.split(",");if(m.some(y=>!y||/[\s
6`).filter(a=>a.startsWith(`${S}:`));if(t.length===0)throw new Error(`secure exec user "${S}" not found in /etc/passwd \u2014 reinstall the agent to create it`);if(t.length>1
7 \u26A0 Ignoring malformed AICOMMANDER_SERVER (${t}); using ${C}.
8`),C}if(n.origin===Mt())return C;let r=Lt(n.hostname);return!nr()&&!r?(console.warn(`
9 \u26A0 AICOMMANDER_SERVER override to "${n.origin}" ignored for safety \u2014
10 the agent runs as root and is host-locked to ${Mt()}.
11 Set AICOMMANDER_DEV=1 to allow a custom relay for development.
12`),C):n.protocol!=="https:"&&!r?(console.warn(`
13 \u26A0 Refusing plaintext relay "${n.origin}" (https required); using ${C}.
14`),C):t.replace(/\/+$/,"")}function We(e){let t;try{t=new URL(e)}catch{throw new Error("Refusing to connect: malformed relay WebSocket URL.")}if(t.protocol!=="wss:"&&!(t.protocol==="ws:"&&Lt(t.hostname)))throw new Error(`Refusing to open a plaintext relay socket (${t.protocol}//${t.host}); wss:// required.`)}var je={capable:!1,enabled:!1,expiresAt:null},Pt=360*60*1e3,sr=/^[a-f0-9]{64}$/;function ir(e,t){return new Promise((n,r)=>{if(t.aborted){r(new DOMException("Aborted","AbortError"));return}let s=setTimeout(n,e);t.addEventListener("abort",()=>{clearTimeout(s),r(new DOMException("Aborted","A ...
15 \u2B06 A newer AI Commander agent is available (v${e.version}; you have v${L}).
16 Update safely (verify before sudo): ${B}/howto/#install-agent
17`)}async function un(){process.env.AIC_ROLE==="worker"?await Ar():await an()}async function Ar(){let e=process.env.AIC_ROLE==="worker";e&&on(process.env.AIC_HEARTBEAT||we());let t=()=>{e&&ze(),Kt(),process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t),typeof process.getuid=="function"&&process.getuid()!==0&&console.warn(`
18 \u26A0 Warning: not running as root.
19 Commands requiring sudo (apt, systemctl, brew cask\u2026) will fail.
20 Recommended: sudo aicommander-agent
21`);let n=Z(),r=tn(),s=r?null:zt(),i,c;try{let l=await Le(B,n,{forceNew:r,...s?{currentCode:s.sessionCode}:{}});i=l.sessionCode,c=l.agentToken}catch(l){console.error(` Failed to register: ${String(l)}`),process.exit(1)}try{Ze({sessionCode:i,agentToken:c})}catch(l){console.error(` Failed to persist session credentials: ${String(l)}`),process.exit(1)}let a=!!(process.env.INVOCATION_ID||process.env.JOURNAL_STREAM);Dt(i,B,process.stdout.isTTY===!0||!a);try{await jt({sessionCode:i,pid:process.pid,startedAt:new Date().toISOString(),serverUrl:B})}catch(l){console.error(` Failed to persist runtime s ...
Long lines were clipped for display.