Lines 1-21javascript
2import{program as _}from"commander";var O="1.0.26";import dn from"os";function un(e){try{let t=JSON.parse(e);return typeof t.code=="string"?t.code:null}catch{return null}}var we=class extends Error{constructor(r,s){super(`Registration failed (${r}): ${s}`);this.status=r;this.body=s;this.name="RegistrationError",this.code=un(s)}status;body;code};async function Re(e,t,r={}){let s={hostname:dn.hostname(),platform:process.platform,arch:process.arch,agentVersion:O,...t?{deviceId:t.deviceId,deviceSecret:t.deviceSecret}:{},...r.forceNew?{forceNew:!0}:r.currentCode?{currentCode:r.currentCode}:{}},i=aw ...
3`),process.exit(127)}let f={...process.env,PATH:yn},m=fn(o,l,{stdio:"inherit",env:f,shell:!1}),u=!1;return m.on("error",p=>{u||(u=!0,process.stderr.write(`secure-exec: spawn failed: ${p.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 HighSandbox Evasion Gated Capability
Source gates dangerous network, credential, or execution behavior behind CI, host, platform, time, or geo fingerprint checks.
4`),process.exit(127))}),m.on("exit",(p,S)=>{if(!u){if(u=!0,S){let A=Sn.signals[S];process.exit(128+(typeof A=="number"?A:0))}process.exit(p??0)}}),!0}function wn(){let e;try{e=vn("/etc/passwd","utf8")}catch{throw new Error("cannot read /etc/passwd to resolve the secure-exec user")}let t=e.split(`
5`).filter(d=>d.startsWith(`${v}:`));if(t.length===0)throw new Error(`secure exec user "${v}" not found in /etc/passwd \u2014 reinstall the agent to create it`);if(t.length>1)throw new Error(`multiple /etc/passwd entries for "${v}" \u2014 refusing to guess which is the sandbox user`);let r=t[0].split(":");if(r.length!==7)throw new Error(`malformed passwd entry for ${v}`);let s=r[2],i=r[3];if(!/^\d+$/.test(s)||!/^\d+$/.test(i))throw new Error(`could not resolve uid/gid for ${v}
6 \u26A0 Ignoring malformed AICOMMANDER_SERVER (${t}); using ${k}.
7`),k}if(r.origin===dt())return k;let s=ut(r.hostname);return!xn()&&!s?(console.warn(`
8 \u26A0 AICOMMANDER_SERVER override to "${r.origin}" ignored for safety \u2014
9 the agent runs as root and is host-locked to ${dt()}.
10 Set AICOMMANDER_DEV=1 to allow a custom relay for development.
11`),k):r.protocol!=="https:"&&!s?(console.warn(`
12 \u26A0 Refusing plaintext relay "${r.origin}" (https required); using ${k}.
13`),k):t.replace(/\/+$/,"")}function pt(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:"&&ut(t.hostname)))throw new Error(`Refusing to open a plaintext relay socket (${t.protocol}//${t.host}); wss:// required.`)}var Ie={capable:!1,enabled:!1,expiresAt:null},St=360*60*1e3;function kn(e,t){return new Promise((r,s)=>{if(t.aborted){s(new DOMException("Aborted","AbortError"));return}let i=setTimeout(r,e);t.addEventListener("abort",()=>{clearTimeout(i),s(new DOMException("Aborted","AbortError"))},{once: ...
14 \u2B06 A newer AI Commander agent is available (v${e.version}; you have v${O}).
15 Update: curl -fsSL ${H}/install | sudo bash
16`)}async function Ft(){process.env.AIC_ROLE==="worker"?await qn():await $t()}async function qn(){let e=process.env.AIC_ROLE==="worker";e&&Nt(process.env.AIC_HEARTBEAT||ue());let t=()=>{e&&Me(),wt(),process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t),typeof process.getuid=="function"&&process.getuid()!==0&&console.warn(`
17 \u26A0 Warning: not running as root.
18 Commands requiring sudo (apt, systemctl, brew cask\u2026) will fail.
19 Recommended: sudo aicommander-agent
20`);let r=K(),s=Ct(),i=s?null:_t(),o,l;try{let c=await Re(H,r,{forceNew:s,...i?{currentCode:i.sessionCode}:{}});o=c.sessionCode,l=c.agentToken,Ne({sessionCode:o,agentToken:l})}catch(c){console.error(` Failed to register: ${String(c)}`),process.exit(1)}let a=!!(process.env.INVOCATION_ID||process.env.JOURNAL_STREAM);at(o,H,process.stdout.isTTY===!0||!a),bt({sessionCode:o,pid:process.pid,startedAt:new Date().toISOString(),serverUrl:H}),Ht(),setInterval(()=>{Ht()},Yn).unref?.(),await ht({serverUrl:H,sessionCode:o,agentToken:l,reauthIntervalMs:St,reauth:async()=>{let c=await Re(H,r,{currentCode:o}) ...
Long lines were clipped for display.