@agentrix/cli 0.45.0 → 0.46.0
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.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var machine=require("./logger-
|
|
1
|
+
"use strict";var machine=require("./logger-B9N6ngW3.cjs");require("winston"),require("chalk"),require("node:os"),require("node:crypto"),require("node:fs"),require("node:fs/promises"),require("node:path"),require("@agentrix/shared"),require("path"),require("url"),require("zod"),require("@xmz-ai/sandbox-runtime"),require("os"),require("@xmz-ai/sandbox-runtime/dist/utils/platform.js"),require("node:url"),exports.Machine=machine.Machine,Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return machine.logger}}),exports.machine=machine.machine;
|
package/dist/lib.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{M as Machine,l as logger,m as machine}from"./logger-
|
|
1
|
+
export{M as Machine,l as logger,m as machine}from"./logger-0VPsm8z4.mjs";import"winston";import"chalk";import"node:os";import"node:crypto";import"node:fs";import"node:fs/promises";import"node:path";import"@agentrix/shared";import"path";import"url";import"zod";import"@xmz-ai/sandbox-runtime";import"os";import"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import"node:url";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"winston";import t from"chalk";import r from"node:os";import{randomUUID as s}from"node:crypto";import{existsSync as i,writeFileSync as n,mkdirSync as o,readFileSync as a,unlinkSync as c,constants as l}from"node:fs";import{readFile as d,writeFile as u,unlink as m,open as p}from"node:fs/promises";import{join as h,basename as g}from"node:path";import{setAgentContext as f,createKeyPair as D}from"@agentrix/shared";import{join as y,dirname as x,resolve as b}from"path";import{fileURLToPath as S}from"url";import{z as v}from"zod";import{SandboxInstanceConfigSchema as k,NetworkConfigSchema as w}from"@xmz-ai/sandbox-runtime";import{homedir as E}from"os";import{getPlatform as A}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import{fileURLToPath as _}from"node:url";var R={name:"@agentrix/cli",version:"0.45.0",description:"Mobile and Web client for Claude Code and Codex",author:"agentrix.xmz.ai",type:"module",homepage:"https://github.com/xmz-ai/agentrix-cli",bugs:"https://github.com/xmz-ai/agentrix-cli/issues",repository:"xmz-ai/agentrix-cli",bin:{agentrix:"./bin/agentrix.mjs"},main:"./dist/index.cjs",module:"./dist/index.mjs",types:"./dist/index.d.cts",exports:{".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files:["dist","bin","scripts","package.json"],scripts:{"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:'yarn build && tsx --env-file .env.integration-test "$(yarn -s bin vitest)" run',dev:"yarn build && tsx --env-file .env.dev src/index.ts",local:"yarn build && tsx --env-file .env.local src/index.ts","prod-local":"yarn build && tsx --env ./bin/agentrix.mjs",prepublishOnly:"yarn build && yarn test",release:"release-it",postinstall:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll:{minify:!0,sourcemap:!1},dependencies:{"@agentrix/shared":"^2.42.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.141.0","@stablelib/base64":"^2.0.1","@stablelib/hex":"^2.0.1","@types/better-sqlite3":"^7.6.13","@types/cross-spawn":"^6.0.6","@types/http-proxy":"^1.17.16","@types/ps-list":"^6.2.1","@types/qrcode-terminal":"^0.12.2","@types/react":"^19.1.9","@types/tmp":"^0.2.6","@types/yargs":"^17.0.33","@xmz-ai/gitlab-webhook-bridge":"0.1.2","@xmz-ai/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies:{"node-datachannel":"0.9.1"},devDependencies:{"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions:{"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides:{"node-datachannel":"0.9.1"},publishConfig:{registry:"https://registry.npmjs.org"},packageManager:"yarn@1.22.22"};const O=v.object({enabled:v.boolean().default(!0),network:w,filesystem:k.shape.filesystem.optional(),env:k.shape.env.optional()});function C(e,t){const r=E();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[y(t,"config","codex"),y(t,"config","claude"),y(t,"config","gemini"),y(r,".codex"),y(r,".claude"),y(r,".claude.json"),y(r,".claude.json.lock"),y(t,"agents/companion")],agentrixHomeDir:t,env:{DEBUG:null,AGENTRIX_SERVER_URL:null,AGENTRIX_WEBAPP_URL:null,AGENTRIX_HOME_DIR:null,AGENTRIX_WORKSPACE_HOME_DIR:null,AGENTRIX_AGENTS_HOME_DIR:null,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${y(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function H(e,t,r){return"macos"===e?function(e,t){E();const r=C(e,t);return{enabled:r.enabled,network:r.network,filesystem:{denyRead:[],allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r):function(e,t){const r=C(e,t);return{enabled:r.enabled,network:r.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r)}const I=x(S(import.meta.url));function j(){return b(I,"..")}function N(e){return Boolean(e&&(void 0===e.status||"ready"===e.status)&&"number"==typeof e.pid&&"number"==typeof e.port)}function P(e){return Boolean(e&&"starting"===e.status&&"number"==typeof e.pid)}const T=v.object({sandbox:O,daemonEnv:v.object({enabled:v.boolean().default(!1),variables:v.record(v.string(),v.string()).optional()}).optional(),daemonControl:v.object({allowLanAccess:v.boolean().default(!1)}).default({allowLanAccess:!1}),allowDirectBash:v.boolean().default(!0),promptOnUncommittedChanges:v.boolean().default(!1),storageManagement:v.object({autoSelectTaskOlderThanDays:v.number().int().nonnegative().default(14)}).default({autoSelectTaskOlderThanDays:14})});class L{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;claudeConfigDir;codexHomeDir;currentCliVersion;disableCaffeinate;statePaths;secretKey;sandboxSettings;constructor(){const e=process.argv.slice(2);this.isDaemonProcess="daemon"===e[0],this.serverUrl=process.env.AGENTRIX_SERVER_URL||"https://agentrix.xmz.ai",this.webappUrl=process.env.AGENTRIX_WEBAPP_URL||"https://agentrix.xmz.ai",this.agentrixHomeDir=process.env.AGENTRIX_HOME_DIR?process.env.AGENTRIX_HOME_DIR.replace(/^~/,r.homedir()):h(r.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=R.version,this.claudeConfigDir=h(r.homedir(),".claude"),this.codexHomeDir=h(r.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(h(this.agentrixHomeDir,"logs")),settingsFile:h(this.agentrixHomeDir,"settings.json"),credentialsFile:h(this.agentrixHomeDir,"credentials.json"),daemonStateFile:h(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:h(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${s()}`}metadata(){return{host:r.hostname(),platform:r.platform(),cliVersion:this.currentCliVersion,homeDir:r.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!i(e.credentialsFile))return null;try{const t=await d(e.credentialsFile,"utf8"),r=JSON.parse(t);return{secret:r.secret,token:r.token,machineId:r.machineId,machineAesKey:"string"==typeof r.machineAesKey?r.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await u(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();i(e.credentialsFile)&&await m(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!i(e.daemonStateFile))return null;const t=await d(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();n(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(i(e.daemonStateFile)&&await m(e.daemonStateFile),i(e.daemonLockFile))try{await m(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return i(e)||o(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=h(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(r)}resolveProjectCWD(e,t,s){if(e)return this.ensureDir(e.replace(/^~/,r.homedir()));const i=h(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(i)}resolveProjectDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(r)}resolveDataDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(r)}resolveAttachmentsDir(e,t){const r=h(this.resolveDataDir(e,t),"attachments");return this.ensureDir(r)}resolveRepoStoreRootDir(){return h(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,r){return h(this.resolveRepoStoreRootDir(),e,t,r)}resolveRepoStoreCheckoutDir(e,t,r){return this.ensureDir(h(this.resolveRepoStoreDir(e,t,r),"repo"))}resolveRepoStoreMetaPath(e,t,r){return h(this.resolveRepoStoreDir(e,t,r),"meta.json")}resolveRepoStoreLockPath(e,t,r){return h(this.resolveRepoStoreDir(e,t,r),"lock")}resolveAgentDirUnder(e,t){const r=h(t,e);return i(h(r,"agent.json"))?r:null}resolveAgentDir(e,t){if(t){const r=this.resolveAgentDirUnder(e,h(t,".agentrix","agents"));if(r)return r}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||h(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return h(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const r=this.getWorkspaceStatePath(e,t);if(i(r))try{const e=a(r,"utf-8");return JSON.parse(e)}catch{return null}const s=this.resolveDataDir(e,t),o=h(s,"cwd.txt");if(!i(o))return null;try{const e=a(o,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{n(r,JSON.stringify(t,null,2));try{c(o)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,r){const s=this.getWorkspaceStatePath(e,t);await u(s,JSON.stringify(r,null,2))}getLastSentArtifactVersionPath(e,t){return h(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const r=this.getLastSentArtifactVersionPath(e,t);if(!i(r))return null;try{return(await d(r,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,r){const s=this.getLastSentArtifactVersionPath(e,t);await u(s,r)}async acquireFileLock(e,t=60,r=200){this.ensureDir(x(e));for(let s=1;s<=t;s++)try{const t=await p(e,l.O_CREAT|l.O_EXCL|l.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(i){if("EEXIST"===i.code)try{const t=(await d(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{c(e);continue}}catch{}if(s===t)return null;const n=s*r;await new Promise(e=>setTimeout(e,n))}return null}async releaseFileLock(e,t){try{await t.close()}catch{}try{c(e)}catch{}}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),r=h(t,"input.json");n(r,JSON.stringify(e,null,2))}readTaskInput(e,t){const r=this.resolveDataDir(e,t),s=h(r,"input.json");if(!i(s))throw new Error(`Task input file does not exist: ${s}`);const n=a(s,"utf-8");return JSON.parse(n)}getTaskCwd(e,t){const r=this.getWorkspaceState(e,t);return r?.cwd?r.cwd:null}resolveWorkspaceFilePath(e,t,r){const s=r.replace(/^\/+/,"");if("project"===s||s.startsWith("project/")){const r=this.getTaskCwd(e,t),i=this.resolveProjectCWD(r||void 0,e,t),n="project"===s?"":s.slice(8);return n?h(i,n):i}if("data"===s||s.startsWith("data/")){const r=this.resolveDataDir(e,t),i="data"===s?"":s.slice(5);return i?h(r,i):r}const i=this.resolveTaskDir(e,t);return h(i,s)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await D(e.secret);this.secretKey=t.secretKey}return this.secretKey}readSettings(){const{settingsFile:e}=this.statePaths;if(!i(e))return null;try{const t=a(e,"utf-8");return JSON.parse(t)}catch(e){throw new Error(`Failed to parse settings file: ${e}`)}}writeSettings(e){const{settingsFile:t}=this.statePaths;this.ensureDir(x(t)),n(t,JSON.stringify(e,null,2),"utf-8")}readOrInitSettings(e){let t=this.readSettings();return t||(this.writeSettings(e),t=e),t}getDefaultMachineSettings(){return{sandbox:H(A(),j(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0,promptOnUncommittedChanges:!1,storageManagement:{autoSelectTaskOlderThanDays:14}}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),r={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return T.parse(r)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}shouldPromptOnUncommittedChanges(){return this.readMachineSettings().promptOnUncommittedChanges}getStorageManagementSettings(){return this.readMachineSettings().storageManagement}getDaemonControlHost(){return this.readMachineSettings().daemonControl.allowLanAccess?"0.0.0.0":"127.0.0.1"}getDaemonWebhookHost(){if("0.0.0.0"!==this.getDaemonControlHost())return"127.0.0.1";const e=r.networkInterfaces();for(const t of Object.values(e))for(const e of t??[])if("IPv4"===e.family&&!e.internal)return e.address;return"127.0.0.1"}getSandboxSettings(){return this.sandboxSettings}}const W=new L;f(W);var M=Object.freeze({__proto__:null,Machine:L,isDaemonReadyState:N,isDaemonStartingState:P,machine:W,projectPath:j});function F(e,t,r){const s=function(e){const t=e.startsWith("file:")?_(e):e;return g(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}(e),i=(e,t,i)=>{!1!==r?.filter?.(t,e)&&K[e](`[${s}] ${t}`,...i)};return{debug:(e,...t)=>i("debug",e,t),info:(e,...t)=>i("info",e,t),warn:(e,...t)=>i("warn",e,t),error:(e,...t)=>i("error",e,t)}}function U(e){const t=$(e);return function(e){K=e}(t),t}function G(){return K}const X=e.format.printf(({level:e,message:r,timestamp:s,...i})=>{const n=new Date(s).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3});let o=e;switch(e){case"error":o=t.red(e.toUpperCase());break;case"warn":o=t.yellow(e.toUpperCase());break;case"info":o=t.blue(e.toUpperCase());break;case"debug":o=t.gray(e.toUpperCase())}return`[${n}] ${o}: ${r}${Object.keys(i).length>0?" "+JSON.stringify(i):""}`}),z=e.format.printf(({level:e,message:t,timestamp:r,...s})=>{const i=Object.keys(s).length>0?" "+JSON.stringify(s):"";return`[${r}] ${e.toUpperCase()}: ${t}${i}`});function $(t){const r=W.getStatePaths().logsDir,s=process.env.DEBUG?"debug":"info";if("console-only"===t.type)return e.createLogger({level:s,format:e.format.combine(e.format.timestamp(),X),transports:[new e.transports.Console]});const i="daemon"===t.type?"daemon.log":`task-${t.taskId}.log`,n="daemon"===t.type?3:1,o=[new e.transports.File({filename:i,dirname:r,zippedArchive:!0,maxsize:104857600,maxFiles:n,tailable:!0,format:e.format.combine(e.format.timestamp(),z)})];return process.env.DEBUG&&o.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),X)})),e.createLogger({level:s,transports:o})}let K=$({type:"console-only"});function B(e){const t=W.getStatePaths().logsDir;return h(t,"daemon.log")}export{L as M,P as a,R as b,F as c,U as d,G as e,M as f,B as g,N as i,K as l,W as m,j as p};
|
|
1
|
+
import e from"winston";import t from"chalk";import r from"node:os";import{randomUUID as s}from"node:crypto";import{existsSync as i,writeFileSync as n,mkdirSync as o,readFileSync as a,unlinkSync as c,constants as l}from"node:fs";import{readFile as d,writeFile as u,unlink as m,open as p}from"node:fs/promises";import{join as h,basename as g}from"node:path";import{setAgentContext as f,createKeyPair as D}from"@agentrix/shared";import{join as y,dirname as x,resolve as b}from"path";import{fileURLToPath as S}from"url";import{z as v}from"zod";import{SandboxInstanceConfigSchema as k,NetworkConfigSchema as w}from"@xmz-ai/sandbox-runtime";import{homedir as E}from"os";import{getPlatform as A}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import{fileURLToPath as _}from"node:url";var R={name:"@agentrix/cli",version:"0.46.0",description:"Mobile and Web client for Claude Code and Codex",author:"agentrix.xmz.ai",type:"module",homepage:"https://github.com/xmz-ai/agentrix-cli",bugs:"https://github.com/xmz-ai/agentrix-cli/issues",repository:"xmz-ai/agentrix-cli",bin:{agentrix:"./bin/agentrix.mjs"},main:"./dist/index.cjs",module:"./dist/index.mjs",types:"./dist/index.d.cts",exports:{".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files:["dist","bin","scripts","package.json"],scripts:{"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:'yarn build && tsx --env-file .env.integration-test "$(yarn -s bin vitest)" run',dev:"yarn build && tsx --env-file .env.dev src/index.ts",local:"yarn build && tsx --env-file .env.local src/index.ts","prod-local":"yarn build && tsx --env ./bin/agentrix.mjs",prepublishOnly:"yarn build && yarn test",release:"release-it",postinstall:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll:{minify:!0,sourcemap:!1},dependencies:{"@agentrix/shared":"^2.43.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.141.0","@stablelib/base64":"^2.0.1","@stablelib/hex":"^2.0.1","@types/better-sqlite3":"^7.6.13","@types/cross-spawn":"^6.0.6","@types/http-proxy":"^1.17.16","@types/ps-list":"^6.2.1","@types/qrcode-terminal":"^0.12.2","@types/react":"^19.1.9","@types/tmp":"^0.2.6","@types/yargs":"^17.0.33","@xmz-ai/gitlab-webhook-bridge":"0.1.2","@xmz-ai/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies:{"node-datachannel":"0.9.1"},devDependencies:{"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions:{"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides:{"node-datachannel":"0.9.1"},publishConfig:{registry:"https://registry.npmjs.org"},packageManager:"yarn@1.22.22"};const O=v.object({enabled:v.boolean().default(!0),network:w,filesystem:k.shape.filesystem.optional(),env:k.shape.env.optional()});function C(e,t){const r=E();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[y(t,"config","codex"),y(t,"config","claude"),y(t,"config","gemini"),y(r,".codex"),y(r,".claude"),y(r,".claude.json"),y(r,".claude.json.lock"),y(t,"agents/companion")],agentrixHomeDir:t,env:{DEBUG:null,AGENTRIX_SERVER_URL:null,AGENTRIX_WEBAPP_URL:null,AGENTRIX_HOME_DIR:null,AGENTRIX_WORKSPACE_HOME_DIR:null,AGENTRIX_AGENTS_HOME_DIR:null,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${y(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function H(e,t,r){return"macos"===e?function(e,t){E();const r=C(e,t);return{enabled:r.enabled,network:r.network,filesystem:{denyRead:[],allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r):function(e,t){const r=C(e,t);return{enabled:r.enabled,network:r.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r)}const I=x(S(import.meta.url));function j(){return b(I,"..")}function N(e){return Boolean(e&&(void 0===e.status||"ready"===e.status)&&"number"==typeof e.pid&&"number"==typeof e.port)}function P(e){return Boolean(e&&"starting"===e.status&&"number"==typeof e.pid)}const T=v.object({sandbox:O,daemonEnv:v.object({enabled:v.boolean().default(!1),variables:v.record(v.string(),v.string()).optional()}).optional(),daemonControl:v.object({allowLanAccess:v.boolean().default(!1)}).default({allowLanAccess:!1}),allowDirectBash:v.boolean().default(!0),promptOnUncommittedChanges:v.boolean().default(!1),storageManagement:v.object({autoSelectTaskOlderThanDays:v.number().int().nonnegative().default(14)}).default({autoSelectTaskOlderThanDays:14})});class L{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;claudeConfigDir;codexHomeDir;currentCliVersion;disableCaffeinate;statePaths;secretKey;sandboxSettings;constructor(){const e=process.argv.slice(2);this.isDaemonProcess="daemon"===e[0],this.serverUrl=process.env.AGENTRIX_SERVER_URL||"https://agentrix.xmz.ai",this.webappUrl=process.env.AGENTRIX_WEBAPP_URL||"https://agentrix.xmz.ai",this.agentrixHomeDir=process.env.AGENTRIX_HOME_DIR?process.env.AGENTRIX_HOME_DIR.replace(/^~/,r.homedir()):h(r.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=R.version,this.claudeConfigDir=h(r.homedir(),".claude"),this.codexHomeDir=h(r.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(h(this.agentrixHomeDir,"logs")),settingsFile:h(this.agentrixHomeDir,"settings.json"),credentialsFile:h(this.agentrixHomeDir,"credentials.json"),daemonStateFile:h(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:h(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${s()}`}metadata(){return{host:r.hostname(),platform:r.platform(),cliVersion:this.currentCliVersion,homeDir:r.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!i(e.credentialsFile))return null;try{const t=await d(e.credentialsFile,"utf8"),r=JSON.parse(t);return{secret:r.secret,token:r.token,machineId:r.machineId,machineAesKey:"string"==typeof r.machineAesKey?r.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await u(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();i(e.credentialsFile)&&await m(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!i(e.daemonStateFile))return null;const t=await d(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();n(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(i(e.daemonStateFile)&&await m(e.daemonStateFile),i(e.daemonLockFile))try{await m(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return i(e)||o(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=h(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(r)}resolveProjectCWD(e,t,s){if(e)return this.ensureDir(e.replace(/^~/,r.homedir()));const i=h(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(i)}resolveProjectDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(r)}resolveDataDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(r)}resolveAttachmentsDir(e,t){const r=h(this.resolveDataDir(e,t),"attachments");return this.ensureDir(r)}resolveRepoStoreRootDir(){return h(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,r){return h(this.resolveRepoStoreRootDir(),e,t,r)}resolveRepoStoreCheckoutDir(e,t,r){return this.ensureDir(h(this.resolveRepoStoreDir(e,t,r),"repo"))}resolveRepoStoreMetaPath(e,t,r){return h(this.resolveRepoStoreDir(e,t,r),"meta.json")}resolveRepoStoreLockPath(e,t,r){return h(this.resolveRepoStoreDir(e,t,r),"lock")}resolveAgentDirUnder(e,t){const r=h(t,e);return i(h(r,"agent.json"))?r:null}resolveAgentDir(e,t){if(t){const r=this.resolveAgentDirUnder(e,h(t,".agentrix","agents"));if(r)return r}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||h(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return h(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const r=this.getWorkspaceStatePath(e,t);if(i(r))try{const e=a(r,"utf-8");return JSON.parse(e)}catch{return null}const s=this.resolveDataDir(e,t),o=h(s,"cwd.txt");if(!i(o))return null;try{const e=a(o,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{n(r,JSON.stringify(t,null,2));try{c(o)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,r){const s=this.getWorkspaceStatePath(e,t);await u(s,JSON.stringify(r,null,2))}getLastSentArtifactVersionPath(e,t){return h(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const r=this.getLastSentArtifactVersionPath(e,t);if(!i(r))return null;try{return(await d(r,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,r){const s=this.getLastSentArtifactVersionPath(e,t);await u(s,r)}async acquireFileLock(e,t=60,r=200){this.ensureDir(x(e));for(let s=1;s<=t;s++)try{const t=await p(e,l.O_CREAT|l.O_EXCL|l.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(i){if("EEXIST"===i.code)try{const t=(await d(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{c(e);continue}}catch{}if(s===t)return null;const n=s*r;await new Promise(e=>setTimeout(e,n))}return null}async releaseFileLock(e,t){try{await t.close()}catch{}try{c(e)}catch{}}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),r=h(t,"input.json");n(r,JSON.stringify(e,null,2))}readTaskInput(e,t){const r=this.resolveDataDir(e,t),s=h(r,"input.json");if(!i(s))throw new Error(`Task input file does not exist: ${s}`);const n=a(s,"utf-8");return JSON.parse(n)}getTaskCwd(e,t){const r=this.getWorkspaceState(e,t);return r?.cwd?r.cwd:null}resolveWorkspaceFilePath(e,t,r){const s=r.replace(/^\/+/,"");if("project"===s||s.startsWith("project/")){const r=this.getTaskCwd(e,t),i=this.resolveProjectCWD(r||void 0,e,t),n="project"===s?"":s.slice(8);return n?h(i,n):i}if("data"===s||s.startsWith("data/")){const r=this.resolveDataDir(e,t),i="data"===s?"":s.slice(5);return i?h(r,i):r}const i=this.resolveTaskDir(e,t);return h(i,s)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await D(e.secret);this.secretKey=t.secretKey}return this.secretKey}readSettings(){const{settingsFile:e}=this.statePaths;if(!i(e))return null;try{const t=a(e,"utf-8");return JSON.parse(t)}catch(e){throw new Error(`Failed to parse settings file: ${e}`)}}writeSettings(e){const{settingsFile:t}=this.statePaths;this.ensureDir(x(t)),n(t,JSON.stringify(e,null,2),"utf-8")}readOrInitSettings(e){let t=this.readSettings();return t||(this.writeSettings(e),t=e),t}getDefaultMachineSettings(){return{sandbox:H(A(),j(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0,promptOnUncommittedChanges:!1,storageManagement:{autoSelectTaskOlderThanDays:14}}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),r={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return T.parse(r)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}shouldPromptOnUncommittedChanges(){return this.readMachineSettings().promptOnUncommittedChanges}getStorageManagementSettings(){return this.readMachineSettings().storageManagement}getDaemonControlHost(){return this.readMachineSettings().daemonControl.allowLanAccess?"0.0.0.0":"127.0.0.1"}getDaemonWebhookHost(){if("0.0.0.0"!==this.getDaemonControlHost())return"127.0.0.1";const e=r.networkInterfaces();for(const t of Object.values(e))for(const e of t??[])if("IPv4"===e.family&&!e.internal)return e.address;return"127.0.0.1"}getSandboxSettings(){return this.sandboxSettings}}const W=new L;f(W);var M=Object.freeze({__proto__:null,Machine:L,isDaemonReadyState:N,isDaemonStartingState:P,machine:W,projectPath:j});function F(e,t,r){const s=function(e){const t=e.startsWith("file:")?_(e):e;return g(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}(e),i=(e,t,i)=>{!1!==r?.filter?.(t,e)&&K[e](`[${s}] ${t}`,...i)};return{debug:(e,...t)=>i("debug",e,t),info:(e,...t)=>i("info",e,t),warn:(e,...t)=>i("warn",e,t),error:(e,...t)=>i("error",e,t)}}function U(e){const t=$(e);return function(e){K=e}(t),t}function G(){return K}const X=e.format.printf(({level:e,message:r,timestamp:s,...i})=>{const n=new Date(s).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3});let o=e;switch(e){case"error":o=t.red(e.toUpperCase());break;case"warn":o=t.yellow(e.toUpperCase());break;case"info":o=t.blue(e.toUpperCase());break;case"debug":o=t.gray(e.toUpperCase())}return`[${n}] ${o}: ${r}${Object.keys(i).length>0?" "+JSON.stringify(i):""}`}),z=e.format.printf(({level:e,message:t,timestamp:r,...s})=>{const i=Object.keys(s).length>0?" "+JSON.stringify(s):"";return`[${r}] ${e.toUpperCase()}: ${t}${i}`});function $(t){const r=W.getStatePaths().logsDir,s=process.env.DEBUG?"debug":"info";if("console-only"===t.type)return e.createLogger({level:s,format:e.format.combine(e.format.timestamp(),X),transports:[new e.transports.Console]});const i="daemon"===t.type?"daemon.log":`task-${t.taskId}.log`,n="daemon"===t.type?3:1,o=[new e.transports.File({filename:i,dirname:r,zippedArchive:!0,maxsize:104857600,maxFiles:n,tailable:!0,format:e.format.combine(e.format.timestamp(),z)})];return process.env.DEBUG&&o.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),X)})),e.createLogger({level:s,transports:o})}let K=$({type:"console-only"});function B(e){const t=W.getStatePaths().logsDir;return h(t,"daemon.log")}export{L as M,P as a,R as b,F as c,U as d,G as e,M as f,B as g,N as i,K as l,W as m,j as p};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var winston=require("winston"),chalk=require("chalk"),os$1=require("node:os"),node_crypto=require("node:crypto"),fs=require("node:fs"),promises=require("node:fs/promises"),path$1=require("node:path"),shared=require("@agentrix/shared"),path=require("path"),url=require("url"),zod=require("zod"),sandboxRuntime=require("@xmz-ai/sandbox-runtime"),os=require("os"),platform_js=require("@xmz-ai/sandbox-runtime/dist/utils/platform.js"),node_url=require("node:url"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.45.0",description="Mobile and Web client for Claude Code and Codex",author="agentrix.xmz.ai",type="module",homepage="https://github.com/xmz-ai/agentrix-cli",bugs="https://github.com/xmz-ai/agentrix-cli/issues",repository="xmz-ai/agentrix-cli",bin={agentrix:"./bin/agentrix.mjs"},main="./dist/index.cjs",module$1="./dist/index.mjs",types="./dist/index.d.cts",exports$1={".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files=["dist","bin","scripts","package.json"],scripts={"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:'yarn build && tsx --env-file .env.integration-test "$(yarn -s bin vitest)" run',dev:"yarn build && tsx --env-file .env.dev src/index.ts",local:"yarn build && tsx --env-file .env.local src/index.ts","prod-local":"yarn build && tsx --env ./bin/agentrix.mjs",prepublishOnly:"yarn build && yarn test",release:"release-it",postinstall:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll={minify:!0,sourcemap:!1},dependencies={"@agentrix/shared":"^2.42.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.141.0","@stablelib/base64":"^2.0.1","@stablelib/hex":"^2.0.1","@types/better-sqlite3":"^7.6.13","@types/cross-spawn":"^6.0.6","@types/http-proxy":"^1.17.16","@types/ps-list":"^6.2.1","@types/qrcode-terminal":"^0.12.2","@types/react":"^19.1.9","@types/tmp":"^0.2.6","@types/yargs":"^17.0.33","@xmz-ai/gitlab-webhook-bridge":"0.1.2","@xmz-ai/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies={"node-datachannel":"0.9.1"},devDependencies={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides={"node-datachannel":"0.9.1"},publishConfig={registry:"https://registry.npmjs.org"},packageManager="yarn@1.22.22",packageJson={name:name,version:version,description:description,author:author,type:type,homepage:homepage,bugs:bugs,repository:repository,bin:bin,main:main,module:module$1,types:types,exports:exports$1,files:files,scripts:scripts,pkgroll:pkgroll,dependencies:dependencies,optionalDependencies:optionalDependencies,devDependencies:devDependencies,resolutions:resolutions,overrides:overrides,publishConfig:publishConfig,packageManager:packageManager};const SandboxSettingsSchema=zod.z.object({enabled:zod.z.boolean().default(!0),network:sandboxRuntime.NetworkConfigSchema,filesystem:sandboxRuntime.SandboxInstanceConfigSchema.shape.filesystem.optional(),env:sandboxRuntime.SandboxInstanceConfigSchema.shape.env.optional()});function getCommonConfig(e,t){const n=os.homedir();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[path.join(t,"config","codex"),path.join(t,"config","claude"),path.join(t,"config","gemini"),path.join(n,".codex"),path.join(n,".claude"),path.join(n,".claude.json"),path.join(n,".claude.json.lock"),path.join(t,"agents/companion")],agentrixHomeDir:t,env:{DEBUG:null,AGENTRIX_SERVER_URL:null,AGENTRIX_WEBAPP_URL:null,AGENTRIX_HOME_DIR:null,AGENTRIX_WORKSPACE_HOME_DIR:null,AGENTRIX_AGENTS_HOME_DIR:null,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${path.join(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function getDefaultMacOSSettings(e,t){os.homedir();const n=getCommonConfig(e,t);return{enabled:n.enabled,network:n.network,filesystem:{denyRead:[],allowWrite:n.commonWritePaths,denyWrite:[]},env:n.env}}function getDefaultLinuxSettings(e,t){const n=getCommonConfig(e,t);return{enabled:n.enabled,network:n.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:n.commonWritePaths,denyWrite:[]},env:n.env}}function getDefaultSandboxSettings(e,t,n){return"macos"===e?getDefaultMacOSSettings(t,n):getDefaultLinuxSettings(t,n)}const __dirname$1=path.dirname(url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("logger-D-a2Obut.cjs",document.baseURI).href));function projectPath(){return path.resolve(__dirname$1,"..")}function isDaemonReadyState(e){return Boolean(e&&(void 0===e.status||"ready"===e.status)&&"number"==typeof e.pid&&"number"==typeof e.port)}function isDaemonStartingState(e){return Boolean(e&&"starting"===e.status&&"number"==typeof e.pid)}const MachineSettingsSchema=zod.z.object({sandbox:SandboxSettingsSchema,daemonEnv:zod.z.object({enabled:zod.z.boolean().default(!1),variables:zod.z.record(zod.z.string(),zod.z.string()).optional()}).optional(),daemonControl:zod.z.object({allowLanAccess:zod.z.boolean().default(!1)}).default({allowLanAccess:!1}),allowDirectBash:zod.z.boolean().default(!0),promptOnUncommittedChanges:zod.z.boolean().default(!1),storageManagement:zod.z.object({autoSelectTaskOlderThanDays:zod.z.number().int().nonnegative().default(14)}).default({autoSelectTaskOlderThanDays:14})});class Machine{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;claudeConfigDir;codexHomeDir;currentCliVersion;disableCaffeinate;statePaths;secretKey;sandboxSettings;constructor(){const e=process.argv.slice(2);this.isDaemonProcess="daemon"===e[0],this.serverUrl=process.env.AGENTRIX_SERVER_URL||"https://agentrix.xmz.ai",this.webappUrl=process.env.AGENTRIX_WEBAPP_URL||"https://agentrix.xmz.ai",this.agentrixHomeDir=process.env.AGENTRIX_HOME_DIR?process.env.AGENTRIX_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(os$1.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=packageJson.version,this.claudeConfigDir=path$1.join(os$1.homedir(),".claude"),this.codexHomeDir=path$1.join(os$1.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(path$1.join(this.agentrixHomeDir,"logs")),settingsFile:path$1.join(this.agentrixHomeDir,"settings.json"),credentialsFile:path$1.join(this.agentrixHomeDir,"credentials.json"),daemonStateFile:path$1.join(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:path$1.join(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${node_crypto.randomUUID()}`}metadata(){return{host:os$1.hostname(),platform:os$1.platform(),cliVersion:this.currentCliVersion,homeDir:os$1.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!fs.existsSync(e.credentialsFile))return null;try{const t=await promises.readFile(e.credentialsFile,"utf8"),n=JSON.parse(t);return{secret:n.secret,token:n.token,machineId:n.machineId,machineAesKey:"string"==typeof n.machineAesKey?n.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await promises.writeFile(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();fs.existsSync(e.credentialsFile)&&await promises.unlink(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!fs.existsSync(e.daemonStateFile))return null;const t=await promises.readFile(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();fs.writeFileSync(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(fs.existsSync(e.daemonStateFile)&&await promises.unlink(e.daemonStateFile),fs.existsSync(e.daemonLockFile))try{await promises.unlink(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=path$1.join(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const n=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(n)}resolveProjectCWD(e,t,n){if(e)return this.ensureDir(e.replace(/^~/,os$1.homedir()));const s=path$1.join(this.agentrixWorkspaceHomeDir,"users",t,n,"project");return this.ensureDir(s)}resolveProjectDir(e,t){const n=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(n)}resolveDataDir(e,t){const n=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(n)}resolveAttachmentsDir(e,t){const n=path$1.join(this.resolveDataDir(e,t),"attachments");return this.ensureDir(n)}resolveRepoStoreRootDir(){return path$1.join(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,n){return path$1.join(this.resolveRepoStoreRootDir(),e,t,n)}resolveRepoStoreCheckoutDir(e,t,n){return this.ensureDir(path$1.join(this.resolveRepoStoreDir(e,t,n),"repo"))}resolveRepoStoreMetaPath(e,t,n){return path$1.join(this.resolveRepoStoreDir(e,t,n),"meta.json")}resolveRepoStoreLockPath(e,t,n){return path$1.join(this.resolveRepoStoreDir(e,t,n),"lock")}resolveAgentDirUnder(e,t){const n=path$1.join(t,e);return fs.existsSync(path$1.join(n,"agent.json"))?n:null}resolveAgentDir(e,t){if(t){const n=this.resolveAgentDirUnder(e,path$1.join(t,".agentrix","agents"));if(n)return n}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||path$1.join(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return path$1.join(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const n=this.getWorkspaceStatePath(e,t);if(fs.existsSync(n))try{const e=fs.readFileSync(n,"utf-8");return JSON.parse(e)}catch{return null}const s=this.resolveDataDir(e,t),r=path$1.join(s,"cwd.txt");if(!fs.existsSync(r))return null;try{const e=fs.readFileSync(r,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{fs.writeFileSync(n,JSON.stringify(t,null,2));try{fs.unlinkSync(r)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,n){const s=this.getWorkspaceStatePath(e,t);await promises.writeFile(s,JSON.stringify(n,null,2))}getLastSentArtifactVersionPath(e,t){return path$1.join(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const n=this.getLastSentArtifactVersionPath(e,t);if(!fs.existsSync(n))return null;try{return(await promises.readFile(n,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,n){const s=this.getLastSentArtifactVersionPath(e,t);await promises.writeFile(s,n)}async acquireFileLock(e,t=60,n=200){this.ensureDir(path.dirname(e));for(let s=1;s<=t;s++)try{const t=await promises.open(e,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(r){if("EEXIST"===r.code)try{const t=(await promises.readFile(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{fs.unlinkSync(e);continue}}catch{}if(s===t)return null;const i=s*n;await new Promise(e=>setTimeout(e,i))}return null}async releaseFileLock(e,t){try{await t.close()}catch{}try{fs.unlinkSync(e)}catch{}}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),n=path$1.join(t,"input.json");fs.writeFileSync(n,JSON.stringify(e,null,2))}readTaskInput(e,t){const n=this.resolveDataDir(e,t),s=path$1.join(n,"input.json");if(!fs.existsSync(s))throw new Error(`Task input file does not exist: ${s}`);const r=fs.readFileSync(s,"utf-8");return JSON.parse(r)}getTaskCwd(e,t){const n=this.getWorkspaceState(e,t);return n?.cwd?n.cwd:null}resolveWorkspaceFilePath(e,t,n){const s=n.replace(/^\/+/,"");if("project"===s||s.startsWith("project/")){const n=this.getTaskCwd(e,t),r=this.resolveProjectCWD(n||void 0,e,t),i="project"===s?"":s.slice(8);return i?path$1.join(r,i):r}if("data"===s||s.startsWith("data/")){const n=this.resolveDataDir(e,t),r="data"===s?"":s.slice(5);return r?path$1.join(n,r):n}const r=this.resolveTaskDir(e,t);return path$1.join(r,s)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await shared.createKeyPair(e.secret);this.secretKey=t.secretKey}return this.secretKey}readSettings(){const{settingsFile:e}=this.statePaths;if(!fs.existsSync(e))return null;try{const t=fs.readFileSync(e,"utf-8");return JSON.parse(t)}catch(e){throw new Error(`Failed to parse settings file: ${e}`)}}writeSettings(e){const{settingsFile:t}=this.statePaths;this.ensureDir(path.dirname(t)),fs.writeFileSync(t,JSON.stringify(e,null,2),"utf-8")}readOrInitSettings(e){let t=this.readSettings();return t||(this.writeSettings(e),t=e),t}getDefaultMachineSettings(){return{sandbox:getDefaultSandboxSettings(platform_js.getPlatform(),projectPath(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0,promptOnUncommittedChanges:!1,storageManagement:{autoSelectTaskOlderThanDays:14}}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),n={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return MachineSettingsSchema.parse(n)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}shouldPromptOnUncommittedChanges(){return this.readMachineSettings().promptOnUncommittedChanges}getStorageManagementSettings(){return this.readMachineSettings().storageManagement}getDaemonControlHost(){return this.readMachineSettings().daemonControl.allowLanAccess?"0.0.0.0":"127.0.0.1"}getDaemonWebhookHost(){if("0.0.0.0"!==this.getDaemonControlHost())return"127.0.0.1";const e=os$1.networkInterfaces();for(const t of Object.values(e))for(const e of t??[])if("IPv4"===e.family&&!e.internal)return e.address;return"127.0.0.1"}getSandboxSettings(){return this.sandboxSettings}}const machine=new Machine;shared.setAgentContext(machine);var machine$1=Object.freeze({__proto__:null,Machine:Machine,isDaemonReadyState:isDaemonReadyState,isDaemonStartingState:isDaemonStartingState,machine:machine,projectPath:projectPath});function resolveModuleName(e){const t=e.startsWith("file:")?node_url.fileURLToPath(e):e;return path$1.basename(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}function createModuleLogger(e,t,n){const s=resolveModuleName(e),r=(e,t,r)=>{!1!==n?.filter?.(t,e)&&exports.logger[e](`[${s}] ${t}`,...r)};return{debug:(e,...t)=>r("debug",e,t),info:(e,...t)=>r("info",e,t),warn:(e,...t)=>r("warn",e,t),error:(e,...t)=>r("error",e,t)}}function setLoggerBase(e){exports.logger=e}function initializeLogger(e){const t=createLogger(e);return setLoggerBase(t),t}function getLoggerBase(){return exports.logger}const consoleFormat=winston.format.printf(({level:e,message:t,timestamp:n,...s})=>{const r=new Date(n).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3});let i=e;switch(e){case"error":i=chalk.red(e.toUpperCase());break;case"warn":i=chalk.yellow(e.toUpperCase());break;case"info":i=chalk.blue(e.toUpperCase());break;case"debug":i=chalk.gray(e.toUpperCase())}return`[${r}] ${i}: ${t}${Object.keys(s).length>0?" "+JSON.stringify(s):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:n,...s})=>{const r=Object.keys(s).length>0?" "+JSON.stringify(s):"";return`[${n}] ${e.toUpperCase()}: ${t}${r}`});function createLogger(e){const t=machine.getStatePaths().logsDir,n=process.env.DEBUG?"debug":"info";if("console-only"===e.type)return winston.createLogger({level:n,format:winston.format.combine(winston.format.timestamp(),consoleFormat),transports:[new winston.transports.Console]});const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`,r="daemon"===e.type?3:1,i=[new winston.transports.File({filename:s,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:r,tailable:!0,format:winston.format.combine(winston.format.timestamp(),fileFormat)})];return process.env.DEBUG&&i.push(new winston.transports.Console({format:winston.format.combine(winston.format.timestamp(),consoleFormat)})),winston.createLogger({level:n,transports:i})}function getLogPath(e){const t=machine.getStatePaths().logsDir;return path$1.join(t,"daemon.log")}exports.logger=createLogger({type:"console-only"}),exports.Machine=Machine,exports.createModuleLogger=createModuleLogger,exports.getLogPath=getLogPath,exports.getLoggerBase=getLoggerBase,exports.initializeLogger=initializeLogger,exports.isDaemonReadyState=isDaemonReadyState,exports.isDaemonStartingState=isDaemonStartingState,exports.machine=machine,exports.machine$1=machine$1,exports.packageJson=packageJson,exports.projectPath=projectPath;
|
|
1
|
+
"use strict";var winston=require("winston"),chalk=require("chalk"),os$1=require("node:os"),node_crypto=require("node:crypto"),fs=require("node:fs"),promises=require("node:fs/promises"),path$1=require("node:path"),shared=require("@agentrix/shared"),path=require("path"),url=require("url"),zod=require("zod"),sandboxRuntime=require("@xmz-ai/sandbox-runtime"),os=require("os"),platform_js=require("@xmz-ai/sandbox-runtime/dist/utils/platform.js"),node_url=require("node:url"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.46.0",description="Mobile and Web client for Claude Code and Codex",author="agentrix.xmz.ai",type="module",homepage="https://github.com/xmz-ai/agentrix-cli",bugs="https://github.com/xmz-ai/agentrix-cli/issues",repository="xmz-ai/agentrix-cli",bin={agentrix:"./bin/agentrix.mjs"},main="./dist/index.cjs",module$1="./dist/index.mjs",types="./dist/index.d.cts",exports$1={".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files=["dist","bin","scripts","package.json"],scripts={"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:'yarn build && tsx --env-file .env.integration-test "$(yarn -s bin vitest)" run',dev:"yarn build && tsx --env-file .env.dev src/index.ts",local:"yarn build && tsx --env-file .env.local src/index.ts","prod-local":"yarn build && tsx --env ./bin/agentrix.mjs",prepublishOnly:"yarn build && yarn test",release:"release-it",postinstall:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll={minify:!0,sourcemap:!1},dependencies={"@agentrix/shared":"^2.43.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.141.0","@stablelib/base64":"^2.0.1","@stablelib/hex":"^2.0.1","@types/better-sqlite3":"^7.6.13","@types/cross-spawn":"^6.0.6","@types/http-proxy":"^1.17.16","@types/ps-list":"^6.2.1","@types/qrcode-terminal":"^0.12.2","@types/react":"^19.1.9","@types/tmp":"^0.2.6","@types/yargs":"^17.0.33","@xmz-ai/gitlab-webhook-bridge":"0.1.2","@xmz-ai/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies={"node-datachannel":"0.9.1"},devDependencies={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides={"node-datachannel":"0.9.1"},publishConfig={registry:"https://registry.npmjs.org"},packageManager="yarn@1.22.22",packageJson={name:name,version:version,description:description,author:author,type:type,homepage:homepage,bugs:bugs,repository:repository,bin:bin,main:main,module:module$1,types:types,exports:exports$1,files:files,scripts:scripts,pkgroll:pkgroll,dependencies:dependencies,optionalDependencies:optionalDependencies,devDependencies:devDependencies,resolutions:resolutions,overrides:overrides,publishConfig:publishConfig,packageManager:packageManager};const SandboxSettingsSchema=zod.z.object({enabled:zod.z.boolean().default(!0),network:sandboxRuntime.NetworkConfigSchema,filesystem:sandboxRuntime.SandboxInstanceConfigSchema.shape.filesystem.optional(),env:sandboxRuntime.SandboxInstanceConfigSchema.shape.env.optional()});function getCommonConfig(e,t){const n=os.homedir();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[path.join(t,"config","codex"),path.join(t,"config","claude"),path.join(t,"config","gemini"),path.join(n,".codex"),path.join(n,".claude"),path.join(n,".claude.json"),path.join(n,".claude.json.lock"),path.join(t,"agents/companion")],agentrixHomeDir:t,env:{DEBUG:null,AGENTRIX_SERVER_URL:null,AGENTRIX_WEBAPP_URL:null,AGENTRIX_HOME_DIR:null,AGENTRIX_WORKSPACE_HOME_DIR:null,AGENTRIX_AGENTS_HOME_DIR:null,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${path.join(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function getDefaultMacOSSettings(e,t){os.homedir();const n=getCommonConfig(e,t);return{enabled:n.enabled,network:n.network,filesystem:{denyRead:[],allowWrite:n.commonWritePaths,denyWrite:[]},env:n.env}}function getDefaultLinuxSettings(e,t){const n=getCommonConfig(e,t);return{enabled:n.enabled,network:n.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:n.commonWritePaths,denyWrite:[]},env:n.env}}function getDefaultSandboxSettings(e,t,n){return"macos"===e?getDefaultMacOSSettings(t,n):getDefaultLinuxSettings(t,n)}const __dirname$1=path.dirname(url.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&"SCRIPT"===_documentCurrentScript.tagName.toUpperCase()&&_documentCurrentScript.src||new URL("logger-B9N6ngW3.cjs",document.baseURI).href));function projectPath(){return path.resolve(__dirname$1,"..")}function isDaemonReadyState(e){return Boolean(e&&(void 0===e.status||"ready"===e.status)&&"number"==typeof e.pid&&"number"==typeof e.port)}function isDaemonStartingState(e){return Boolean(e&&"starting"===e.status&&"number"==typeof e.pid)}const MachineSettingsSchema=zod.z.object({sandbox:SandboxSettingsSchema,daemonEnv:zod.z.object({enabled:zod.z.boolean().default(!1),variables:zod.z.record(zod.z.string(),zod.z.string()).optional()}).optional(),daemonControl:zod.z.object({allowLanAccess:zod.z.boolean().default(!1)}).default({allowLanAccess:!1}),allowDirectBash:zod.z.boolean().default(!0),promptOnUncommittedChanges:zod.z.boolean().default(!1),storageManagement:zod.z.object({autoSelectTaskOlderThanDays:zod.z.number().int().nonnegative().default(14)}).default({autoSelectTaskOlderThanDays:14})});class Machine{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;claudeConfigDir;codexHomeDir;currentCliVersion;disableCaffeinate;statePaths;secretKey;sandboxSettings;constructor(){const e=process.argv.slice(2);this.isDaemonProcess="daemon"===e[0],this.serverUrl=process.env.AGENTRIX_SERVER_URL||"https://agentrix.xmz.ai",this.webappUrl=process.env.AGENTRIX_WEBAPP_URL||"https://agentrix.xmz.ai",this.agentrixHomeDir=process.env.AGENTRIX_HOME_DIR?process.env.AGENTRIX_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(os$1.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=packageJson.version,this.claudeConfigDir=path$1.join(os$1.homedir(),".claude"),this.codexHomeDir=path$1.join(os$1.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(path$1.join(this.agentrixHomeDir,"logs")),settingsFile:path$1.join(this.agentrixHomeDir,"settings.json"),credentialsFile:path$1.join(this.agentrixHomeDir,"credentials.json"),daemonStateFile:path$1.join(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:path$1.join(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${node_crypto.randomUUID()}`}metadata(){return{host:os$1.hostname(),platform:os$1.platform(),cliVersion:this.currentCliVersion,homeDir:os$1.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!fs.existsSync(e.credentialsFile))return null;try{const t=await promises.readFile(e.credentialsFile,"utf8"),n=JSON.parse(t);return{secret:n.secret,token:n.token,machineId:n.machineId,machineAesKey:"string"==typeof n.machineAesKey?n.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await promises.writeFile(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();fs.existsSync(e.credentialsFile)&&await promises.unlink(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!fs.existsSync(e.daemonStateFile))return null;const t=await promises.readFile(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();fs.writeFileSync(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(fs.existsSync(e.daemonStateFile)&&await promises.unlink(e.daemonStateFile),fs.existsSync(e.daemonLockFile))try{await promises.unlink(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=path$1.join(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const n=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(n)}resolveProjectCWD(e,t,n){if(e)return this.ensureDir(e.replace(/^~/,os$1.homedir()));const s=path$1.join(this.agentrixWorkspaceHomeDir,"users",t,n,"project");return this.ensureDir(s)}resolveProjectDir(e,t){const n=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(n)}resolveDataDir(e,t){const n=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(n)}resolveAttachmentsDir(e,t){const n=path$1.join(this.resolveDataDir(e,t),"attachments");return this.ensureDir(n)}resolveRepoStoreRootDir(){return path$1.join(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,n){return path$1.join(this.resolveRepoStoreRootDir(),e,t,n)}resolveRepoStoreCheckoutDir(e,t,n){return this.ensureDir(path$1.join(this.resolveRepoStoreDir(e,t,n),"repo"))}resolveRepoStoreMetaPath(e,t,n){return path$1.join(this.resolveRepoStoreDir(e,t,n),"meta.json")}resolveRepoStoreLockPath(e,t,n){return path$1.join(this.resolveRepoStoreDir(e,t,n),"lock")}resolveAgentDirUnder(e,t){const n=path$1.join(t,e);return fs.existsSync(path$1.join(n,"agent.json"))?n:null}resolveAgentDir(e,t){if(t){const n=this.resolveAgentDirUnder(e,path$1.join(t,".agentrix","agents"));if(n)return n}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||path$1.join(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return path$1.join(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const n=this.getWorkspaceStatePath(e,t);if(fs.existsSync(n))try{const e=fs.readFileSync(n,"utf-8");return JSON.parse(e)}catch{return null}const s=this.resolveDataDir(e,t),r=path$1.join(s,"cwd.txt");if(!fs.existsSync(r))return null;try{const e=fs.readFileSync(r,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{fs.writeFileSync(n,JSON.stringify(t,null,2));try{fs.unlinkSync(r)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,n){const s=this.getWorkspaceStatePath(e,t);await promises.writeFile(s,JSON.stringify(n,null,2))}getLastSentArtifactVersionPath(e,t){return path$1.join(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const n=this.getLastSentArtifactVersionPath(e,t);if(!fs.existsSync(n))return null;try{return(await promises.readFile(n,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,n){const s=this.getLastSentArtifactVersionPath(e,t);await promises.writeFile(s,n)}async acquireFileLock(e,t=60,n=200){this.ensureDir(path.dirname(e));for(let s=1;s<=t;s++)try{const t=await promises.open(e,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(r){if("EEXIST"===r.code)try{const t=(await promises.readFile(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{fs.unlinkSync(e);continue}}catch{}if(s===t)return null;const i=s*n;await new Promise(e=>setTimeout(e,i))}return null}async releaseFileLock(e,t){try{await t.close()}catch{}try{fs.unlinkSync(e)}catch{}}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),n=path$1.join(t,"input.json");fs.writeFileSync(n,JSON.stringify(e,null,2))}readTaskInput(e,t){const n=this.resolveDataDir(e,t),s=path$1.join(n,"input.json");if(!fs.existsSync(s))throw new Error(`Task input file does not exist: ${s}`);const r=fs.readFileSync(s,"utf-8");return JSON.parse(r)}getTaskCwd(e,t){const n=this.getWorkspaceState(e,t);return n?.cwd?n.cwd:null}resolveWorkspaceFilePath(e,t,n){const s=n.replace(/^\/+/,"");if("project"===s||s.startsWith("project/")){const n=this.getTaskCwd(e,t),r=this.resolveProjectCWD(n||void 0,e,t),i="project"===s?"":s.slice(8);return i?path$1.join(r,i):r}if("data"===s||s.startsWith("data/")){const n=this.resolveDataDir(e,t),r="data"===s?"":s.slice(5);return r?path$1.join(n,r):n}const r=this.resolveTaskDir(e,t);return path$1.join(r,s)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await shared.createKeyPair(e.secret);this.secretKey=t.secretKey}return this.secretKey}readSettings(){const{settingsFile:e}=this.statePaths;if(!fs.existsSync(e))return null;try{const t=fs.readFileSync(e,"utf-8");return JSON.parse(t)}catch(e){throw new Error(`Failed to parse settings file: ${e}`)}}writeSettings(e){const{settingsFile:t}=this.statePaths;this.ensureDir(path.dirname(t)),fs.writeFileSync(t,JSON.stringify(e,null,2),"utf-8")}readOrInitSettings(e){let t=this.readSettings();return t||(this.writeSettings(e),t=e),t}getDefaultMachineSettings(){return{sandbox:getDefaultSandboxSettings(platform_js.getPlatform(),projectPath(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0,promptOnUncommittedChanges:!1,storageManagement:{autoSelectTaskOlderThanDays:14}}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),n={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return MachineSettingsSchema.parse(n)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}shouldPromptOnUncommittedChanges(){return this.readMachineSettings().promptOnUncommittedChanges}getStorageManagementSettings(){return this.readMachineSettings().storageManagement}getDaemonControlHost(){return this.readMachineSettings().daemonControl.allowLanAccess?"0.0.0.0":"127.0.0.1"}getDaemonWebhookHost(){if("0.0.0.0"!==this.getDaemonControlHost())return"127.0.0.1";const e=os$1.networkInterfaces();for(const t of Object.values(e))for(const e of t??[])if("IPv4"===e.family&&!e.internal)return e.address;return"127.0.0.1"}getSandboxSettings(){return this.sandboxSettings}}const machine=new Machine;shared.setAgentContext(machine);var machine$1=Object.freeze({__proto__:null,Machine:Machine,isDaemonReadyState:isDaemonReadyState,isDaemonStartingState:isDaemonStartingState,machine:machine,projectPath:projectPath});function resolveModuleName(e){const t=e.startsWith("file:")?node_url.fileURLToPath(e):e;return path$1.basename(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}function createModuleLogger(e,t,n){const s=resolveModuleName(e),r=(e,t,r)=>{!1!==n?.filter?.(t,e)&&exports.logger[e](`[${s}] ${t}`,...r)};return{debug:(e,...t)=>r("debug",e,t),info:(e,...t)=>r("info",e,t),warn:(e,...t)=>r("warn",e,t),error:(e,...t)=>r("error",e,t)}}function setLoggerBase(e){exports.logger=e}function initializeLogger(e){const t=createLogger(e);return setLoggerBase(t),t}function getLoggerBase(){return exports.logger}const consoleFormat=winston.format.printf(({level:e,message:t,timestamp:n,...s})=>{const r=new Date(n).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3});let i=e;switch(e){case"error":i=chalk.red(e.toUpperCase());break;case"warn":i=chalk.yellow(e.toUpperCase());break;case"info":i=chalk.blue(e.toUpperCase());break;case"debug":i=chalk.gray(e.toUpperCase())}return`[${r}] ${i}: ${t}${Object.keys(s).length>0?" "+JSON.stringify(s):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:n,...s})=>{const r=Object.keys(s).length>0?" "+JSON.stringify(s):"";return`[${n}] ${e.toUpperCase()}: ${t}${r}`});function createLogger(e){const t=machine.getStatePaths().logsDir,n=process.env.DEBUG?"debug":"info";if("console-only"===e.type)return winston.createLogger({level:n,format:winston.format.combine(winston.format.timestamp(),consoleFormat),transports:[new winston.transports.Console]});const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`,r="daemon"===e.type?3:1,i=[new winston.transports.File({filename:s,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:r,tailable:!0,format:winston.format.combine(winston.format.timestamp(),fileFormat)})];return process.env.DEBUG&&i.push(new winston.transports.Console({format:winston.format.combine(winston.format.timestamp(),consoleFormat)})),winston.createLogger({level:n,transports:i})}function getLogPath(e){const t=machine.getStatePaths().logsDir;return path$1.join(t,"daemon.log")}exports.logger=createLogger({type:"console-only"}),exports.Machine=Machine,exports.createModuleLogger=createModuleLogger,exports.getLogPath=getLogPath,exports.getLoggerBase=getLoggerBase,exports.initializeLogger=initializeLogger,exports.isDaemonReadyState=isDaemonReadyState,exports.isDaemonStartingState=isDaemonStartingState,exports.machine=machine,exports.machine$1=machine$1,exports.packageJson=packageJson,exports.projectPath=projectPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentrix/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Mobile and Web client for Claude Code and Codex",
|
|
5
5
|
"author": "agentrix.xmz.ai",
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"sourcemap": false
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@agentrix/shared": "^2.
|
|
63
|
+
"@agentrix/shared": "^2.43.0",
|
|
64
64
|
"@anthropic-ai/claude-agent-sdk": "^0.2.133",
|
|
65
65
|
"@anthropic-ai/sdk": "0.71.2",
|
|
66
66
|
"@larksuiteoapi/node-sdk": "^1.63.1",
|