@agentrix/cli 0.12.0 → 0.13.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 _package=require("./logger-CmNBqkS2.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"),exports.Machine=_package.Machine,exports.logger=_package.logger,exports.machine=_package.machine;
1
+ "use strict";var _package=require("./logger-CnmGrOSq.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"),exports.Machine=_package.Machine,exports.logger=_package.logger,exports.machine=_package.machine;
package/dist/lib.d.cts CHANGED
@@ -44,6 +44,8 @@ type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
44
44
  interface DaemonState {
45
45
  pid: number;
46
46
  port: number;
47
+ host?: string;
48
+ webhookHost?: string;
47
49
  startTime: string;
48
50
  cliVersion: string;
49
51
  logPath: string;
@@ -63,6 +65,7 @@ interface WorkspaceState {
63
65
  cwd: string;
64
66
  initialCommitHash?: string;
65
67
  repositorySourceType?: 'temporary' | 'directory' | 'git-server';
68
+ useWorktree?: boolean;
66
69
  userCwd?: string;
67
70
  forceUserCwd?: boolean;
68
71
  gitUrl?: string;
@@ -111,6 +114,11 @@ declare class Machine implements AgentContext {
111
114
  resolveProjectDir(userId: string, taskId: string): string;
112
115
  resolveDataDir(userId: string, taskId: string): string;
113
116
  resolveAttachmentsDir(userId: string, taskId: string): string;
117
+ resolveRepoStoreRootDir(): string;
118
+ resolveRepoStoreDir(gitServerId: string, owner: string, repositoryName: string): string;
119
+ resolveRepoStoreCheckoutDir(gitServerId: string, owner: string, repositoryName: string): string;
120
+ resolveRepoStoreMetaPath(gitServerId: string, owner: string, repositoryName: string): string;
121
+ resolveRepoStoreLockPath(gitServerId: string, owner: string, repositoryName: string): string;
114
122
  resolveAgentDir(agentId: string): string;
115
123
  getWorkspaceStatePath(userId: string, taskId: string): string;
116
124
  getWorkspaceState(userId: string, taskId: string): WorkspaceState | null;
@@ -118,6 +126,8 @@ declare class Machine implements AgentContext {
118
126
  getLastSentArtifactVersionPath(userId: string, taskId: string): string;
119
127
  readLastSentArtifactVersion(userId: string, taskId: string): Promise<string | null>;
120
128
  writeLastSentArtifactVersion(userId: string, taskId: string, version: string): Promise<void>;
129
+ acquireFileLock(lockFilePath: string, maxAttempts?: number, delayIncrementMs?: number): Promise<FileHandle | null>;
130
+ releaseFileLock(lockFilePath: string, lockHandle: FileHandle): Promise<void>;
121
131
  writeTaskInput(data: CreateTaskEventData | ResumeTaskEventData | DeployAgentEventData): void;
122
132
  readTaskInput(userId: string, taskId: string): (CreateTaskEventData | ResumeTaskEventData);
123
133
  getTaskCwd(userId: string, taskId: string): string | null;
@@ -140,6 +150,8 @@ declare class Machine implements AgentContext {
140
150
  private readMachineSettings;
141
151
  private loadSandboxSettings;
142
152
  isDirectBashAllowed(): boolean;
153
+ getDaemonControlHost(): '127.0.0.1' | '0.0.0.0';
154
+ getDaemonWebhookHost(): string;
143
155
  getSandboxSettings(): SandboxSettings;
144
156
  }
145
157
  declare const machine: Machine;
package/dist/lib.d.mts CHANGED
@@ -44,6 +44,8 @@ type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
44
44
  interface DaemonState {
45
45
  pid: number;
46
46
  port: number;
47
+ host?: string;
48
+ webhookHost?: string;
47
49
  startTime: string;
48
50
  cliVersion: string;
49
51
  logPath: string;
@@ -63,6 +65,7 @@ interface WorkspaceState {
63
65
  cwd: string;
64
66
  initialCommitHash?: string;
65
67
  repositorySourceType?: 'temporary' | 'directory' | 'git-server';
68
+ useWorktree?: boolean;
66
69
  userCwd?: string;
67
70
  forceUserCwd?: boolean;
68
71
  gitUrl?: string;
@@ -111,6 +114,11 @@ declare class Machine implements AgentContext {
111
114
  resolveProjectDir(userId: string, taskId: string): string;
112
115
  resolveDataDir(userId: string, taskId: string): string;
113
116
  resolveAttachmentsDir(userId: string, taskId: string): string;
117
+ resolveRepoStoreRootDir(): string;
118
+ resolveRepoStoreDir(gitServerId: string, owner: string, repositoryName: string): string;
119
+ resolveRepoStoreCheckoutDir(gitServerId: string, owner: string, repositoryName: string): string;
120
+ resolveRepoStoreMetaPath(gitServerId: string, owner: string, repositoryName: string): string;
121
+ resolveRepoStoreLockPath(gitServerId: string, owner: string, repositoryName: string): string;
114
122
  resolveAgentDir(agentId: string): string;
115
123
  getWorkspaceStatePath(userId: string, taskId: string): string;
116
124
  getWorkspaceState(userId: string, taskId: string): WorkspaceState | null;
@@ -118,6 +126,8 @@ declare class Machine implements AgentContext {
118
126
  getLastSentArtifactVersionPath(userId: string, taskId: string): string;
119
127
  readLastSentArtifactVersion(userId: string, taskId: string): Promise<string | null>;
120
128
  writeLastSentArtifactVersion(userId: string, taskId: string, version: string): Promise<void>;
129
+ acquireFileLock(lockFilePath: string, maxAttempts?: number, delayIncrementMs?: number): Promise<FileHandle | null>;
130
+ releaseFileLock(lockFilePath: string, lockHandle: FileHandle): Promise<void>;
121
131
  writeTaskInput(data: CreateTaskEventData | ResumeTaskEventData | DeployAgentEventData): void;
122
132
  readTaskInput(userId: string, taskId: string): (CreateTaskEventData | ResumeTaskEventData);
123
133
  getTaskCwd(userId: string, taskId: string): string | null;
@@ -140,6 +150,8 @@ declare class Machine implements AgentContext {
140
150
  private readMachineSettings;
141
151
  private loadSandboxSettings;
142
152
  isDirectBashAllowed(): boolean;
153
+ getDaemonControlHost(): '127.0.0.1' | '0.0.0.0';
154
+ getDaemonWebhookHost(): string;
143
155
  getSandboxSettings(): SandboxSettings;
144
156
  }
145
157
  declare const machine: Machine;
package/dist/lib.mjs CHANGED
@@ -1 +1 @@
1
- export{M as Machine,l as logger,m as machine}from"./logger-BdEo-cJO.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";
1
+ export{M as Machine,l as logger,m as machine}from"./logger-CmTLsBO2.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";
@@ -0,0 +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 p,unlink as m,open as u}from"node:fs/promises";import{join as h}from"node:path";import{setAgentContext as g,createKeyPair as f}from"@agentrix/shared";import{join as D,dirname as x,resolve as y}from"path";import{fileURLToPath as b}from"url";import{z as v}from"zod";import{SandboxInstanceConfigSchema as S,NetworkConfigSchema as k}from"@xmz-ai/sandbox-runtime";import{homedir as w}from"os";import{getPlatform as E}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";var _="@agentrix/cli",C="0.13.0",O="Mobile and Web client for Claude Code and Codex",R="agentrix.xmz.ai",H="module",A="https://github.com/xmz-ai/agentrix-cli",I="https://github.com/xmz-ai/agentrix-cli/issues",j="xmz-ai/agentrix-cli",N={agentrix:"./bin/agentrix.mjs"},P="./dist/index.cjs",L="./dist/index.mjs",T="./dist/index.d.cts",W={".":{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"}}},F=["dist","bin","scripts","package.json"],M={"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 && npx 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.js dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs && npm rebuild node-datachannel",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test node_modules/.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:"npm rebuild node-datachannel && node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},G={minify:!0,sourcemap:!1},X={"@agentrix/shared":"^2.13.0","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.120.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/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1","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-datachannel":"0.9.1","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"},U={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20","cross-env":"^10.0.0",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"},z={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},$={"node-datachannel":"0.9.1"},J={registry:"https://registry.npmjs.org"},q="yarn@1.22.22",B={name:_,version:C,description:O,author:R,type:H,homepage:A,bugs:I,repository:j,bin:N,main:P,module:L,types:T,exports:W,files:F,scripts:M,pkgroll:G,dependencies:X,devDependencies:U,resolutions:z,overrides:$,publishConfig:J,packageManager:q},V=Object.freeze({__proto__:null,author:R,bin:N,bugs:I,default:B,dependencies:X,description:O,devDependencies:U,exports:W,files:F,homepage:A,main:P,module:L,name:_,overrides:$,packageManager:q,pkgroll:G,publishConfig:J,repository:j,resolutions:z,scripts:M,type:H,types:T,version:C});const K=v.object({enabled:v.boolean().default(!0),network:k,filesystem:S.shape.filesystem.optional(),env:S.shape.env.optional()});function Y(e,t){const r=w();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[D(t,"config","codex"),D(t,"config","claude"),D(r,".codex"),D(r,".claude"),D(r,".claude.json"),D(r,".claude.json.lock"),D(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,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${D(e,"dist","sandbox","node-proxy-boot.js")}`}}}function Q(e,t,r){return"macos"===e?function(e,t){w();const r=Y(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=Y(e,t);return{enabled:r.enabled,network:r.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r)}const Z=x(b(import.meta.url));function ee(){return y(Z,"..")}const te=v.object({sandbox:K,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)});class re{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=B.version;const t=process.env.AGENTRIX_CLAUDE_HOME||process.env.CLAUDE_CONFIG_DIR;this.claudeConfigDir=t?t.replace(/^~(?=\/|$)/,r.homedir()):h(this.agentrixHomeDir,"config","claude");const s=process.env.AGENTRIX_CODEX_HOME||process.env.CODEX_HOME;this.codexHomeDir=s?s.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"config","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}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await p(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")}resolveAgentDir(e){return 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 p(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 p(s,r)}async acquireFileLock(e,t=60,r=200){this.ensureDir(x(e));for(let s=1;s<=t;s++)try{const t=await u(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 f(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:Q(E(),ee(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0}}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 te.parse(r)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}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 se=new re;g(se);var ie=Object.freeze({__proto__:null,Machine:re,machine:se,projectPath:ee});const ne=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):""}`}),oe=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 ae(t){const r=se.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(),ne),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(),oe)})];return process.env.DEBUG&&o.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),ne)})),e.createLogger({level:s,transports:o})}let ce=ae({type:"console-only"});function le(e){const t=se.getStatePaths().logsDir;if("console-only"===e.type)return"";const r="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`;return h(t,r)}var de=Object.freeze({__proto__:null,createLogger:ae,getLogPath:le,logger:ce});export{re as M,V as _,B as a,de as b,ae as c,ie as d,le as g,ce as l,se as m,ee as p};
@@ -0,0 +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"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.13.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 && npx 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.js dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs && npm rebuild node-datachannel",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test node_modules/.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:"npm rebuild node-datachannel && node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll={minify:!0,sourcemap:!1},dependencies={"@agentrix/shared":"^2.13.0","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.120.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/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1","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-datachannel":"0.9.1","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"},devDependencies={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20","cross-env":"^10.0.0",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,devDependencies:devDependencies,resolutions:resolutions,overrides:overrides,publishConfig:publishConfig,packageManager:packageManager},_package=Object.freeze({__proto__:null,author:author,bin:bin,bugs:bugs,default:packageJson,dependencies:dependencies,description:description,devDependencies:devDependencies,exports:exports$1,files:files,homepage:homepage,main:main,module:module$1,name:name,overrides:overrides,packageManager:packageManager,pkgroll:pkgroll,publishConfig:publishConfig,repository:repository,resolutions:resolutions,scripts:scripts,type:type,types:types,version:version});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 s=os.homedir();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[path.join(t,"config","codex"),path.join(t,"config","claude"),path.join(s,".codex"),path.join(s,".claude"),path.join(s,".claude.json"),path.join(s,".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,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${path.join(e,"dist","sandbox","node-proxy-boot.js")}`}}}function getDefaultMacOSSettings(e,t){os.homedir();const s=getCommonConfig(e,t);return{enabled:s.enabled,network:s.network,filesystem:{denyRead:[],allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}function getDefaultLinuxSettings(e,t){const s=getCommonConfig(e,t);return{enabled:s.enabled,network:s.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}function getDefaultSandboxSettings(e,t,s){return"macos"===e?getDefaultMacOSSettings(t,s):getDefaultLinuxSettings(t,s)}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-CnmGrOSq.cjs",document.baseURI).href));function projectPath(){return path.resolve(__dirname$1,"..")}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)});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;const t=process.env.AGENTRIX_CLAUDE_HOME||process.env.CLAUDE_CONFIG_DIR;this.claudeConfigDir=t?t.replace(/^~(?=\/|$)/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"config","claude");const s=process.env.AGENTRIX_CODEX_HOME||process.env.CODEX_HOME;this.codexHomeDir=s?s.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"config","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"),s=JSON.parse(t);return{secret:s.secret,token:s.token,machineId:s.machineId}}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 s=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(s)}resolveProjectCWD(e,t,s){if(e)return this.ensureDir(e.replace(/^~/,os$1.homedir()));const r=path$1.join(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(r)}resolveProjectDir(e,t){const s=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(s)}resolveDataDir(e,t){const s=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(s)}resolveAttachmentsDir(e,t){const s=path$1.join(this.resolveDataDir(e,t),"attachments");return this.ensureDir(s)}resolveRepoStoreRootDir(){return path$1.join(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,s){return path$1.join(this.resolveRepoStoreRootDir(),e,t,s)}resolveRepoStoreCheckoutDir(e,t,s){return this.ensureDir(path$1.join(this.resolveRepoStoreDir(e,t,s),"repo"))}resolveRepoStoreMetaPath(e,t,s){return path$1.join(this.resolveRepoStoreDir(e,t,s),"meta.json")}resolveRepoStoreLockPath(e,t,s){return path$1.join(this.resolveRepoStoreDir(e,t,s),"lock")}resolveAgentDir(e){return path$1.join(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return path$1.join(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const s=this.getWorkspaceStatePath(e,t);if(fs.existsSync(s))try{const e=fs.readFileSync(s,"utf-8");return JSON.parse(e)}catch{return null}const r=this.resolveDataDir(e,t),n=path$1.join(r,"cwd.txt");if(!fs.existsSync(n))return null;try{const e=fs.readFileSync(n,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{fs.writeFileSync(s,JSON.stringify(t,null,2));try{fs.unlinkSync(n)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const r=this.getWorkspaceStatePath(e,t);await promises.writeFile(r,JSON.stringify(s,null,2))}getLastSentArtifactVersionPath(e,t){return path$1.join(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const s=this.getLastSentArtifactVersionPath(e,t);if(!fs.existsSync(s))return null;try{return(await promises.readFile(s,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,s){const r=this.getLastSentArtifactVersionPath(e,t);await promises.writeFile(r,s)}async acquireFileLock(e,t=60,s=200){this.ensureDir(path.dirname(e));for(let r=1;r<=t;r++)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(n){if("EEXIST"===n.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(r===t)return null;const i=r*s;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),s=path$1.join(t,"input.json");fs.writeFileSync(s,JSON.stringify(e,null,2))}readTaskInput(e,t){const s=this.resolveDataDir(e,t),r=path$1.join(s,"input.json");if(!fs.existsSync(r))throw new Error(`Task input file does not exist: ${r}`);const n=fs.readFileSync(r,"utf-8");return JSON.parse(n)}getTaskCwd(e,t){const s=this.getWorkspaceState(e,t);return s?.cwd?s.cwd:null}resolveWorkspaceFilePath(e,t,s){const r=s.replace(/^\/+/,"");if("project"===r||r.startsWith("project/")){const s=this.getTaskCwd(e,t),n=this.resolveProjectCWD(s||void 0,e,t),i="project"===r?"":r.slice(8);return i?path$1.join(n,i):n}if("data"===r||r.startsWith("data/")){const s=this.resolveDataDir(e,t),n="data"===r?"":r.slice(5);return n?path$1.join(s,n):s}const n=this.resolveTaskDir(e,t);return path$1.join(n,r)}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}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),s={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return MachineSettingsSchema.parse(s)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}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,machine:machine,projectPath:projectPath});const consoleFormat=winston.format.printf(({level:e,message:t,timestamp:s,...r})=>{const n=new Date(s).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`[${n}] ${i}: ${t}${Object.keys(r).length>0?" "+JSON.stringify(r):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:s,...r})=>{const n=Object.keys(r).length>0?" "+JSON.stringify(r):"";return`[${s}] ${e.toUpperCase()}: ${t}${n}`});function createLogger(e){const t=machine.getStatePaths().logsDir,s=process.env.DEBUG?"debug":"info";if("console-only"===e.type)return winston.createLogger({level:s,format:winston.format.combine(winston.format.timestamp(),consoleFormat),transports:[new winston.transports.Console]});const r="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`,n="daemon"===e.type?3:1,i=[new winston.transports.File({filename:r,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:n,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:s,transports:i})}let logger=createLogger({type:"console-only"});function getLogPath(e){const t=machine.getStatePaths().logsDir;if("console-only"===e.type)return"";const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`;return path$1.join(t,s)}var logger$1=Object.freeze({__proto__:null,createLogger:createLogger,getLogPath:getLogPath,logger:logger});exports.Machine=Machine,exports._package=_package,exports.createLogger=createLogger,exports.getLogPath=getLogPath,exports.logger=logger,exports.logger$1=logger$1,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.12.0",
3
+ "version": "0.13.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.12.0",
63
+ "@agentrix/shared": "^2.13.0",
64
64
  "@anthropic-ai/claude-agent-sdk": "^0.2.31",
65
65
  "@anthropic-ai/sdk": "0.71.2",
66
66
  "@modelcontextprotocol/sdk": "^1.15.1",
@@ -1 +0,0 @@
1
- import e from"winston";import t from"chalk";import s from"node:os";import{randomUUID as r}from"node:crypto";import{existsSync as i,writeFileSync as n,constants as o,readFileSync as a,unlinkSync as c,mkdirSync as l}from"node:fs";import{readFile as d,writeFile as p,unlink as m,open as u}from"node:fs/promises";import{join as h}from"node:path";import{setAgentContext as g,createKeyPair as f}from"@agentrix/shared";import{join as D,dirname as x,resolve as y}from"path";import{fileURLToPath as b}from"url";import{z as v}from"zod";import{SandboxInstanceConfigSchema as S,NetworkConfigSchema as k}from"@xmz-ai/sandbox-runtime";import{homedir as E}from"os";import{getPlatform as w}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";var _="@agentrix/cli",O="0.12.0",C="Mobile and Web client for Claude Code and Codex",H="agentrix.xmz.ai",A="module",I="https://github.com/xmz-ai/agentrix-cli",N="https://github.com/xmz-ai/agentrix-cli/issues",R="xmz-ai/agentrix-cli",j={agentrix:"./bin/agentrix.mjs"},P="./dist/index.cjs",T="./dist/index.mjs",W="./dist/index.d.cts",L={".":{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"}}},F=["dist","bin","scripts","package.json"],G={"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 && npx 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.js dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs && npm rebuild node-datachannel",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test node_modules/.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:"npm rebuild node-datachannel && node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},M={minify:!0,sourcemap:!1},X={"@agentrix/shared":"^2.12.0","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.120.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/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1","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-datachannel":"0.9.1","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"},U={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20","cross-env":"^10.0.0",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"},z={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},$={"node-datachannel":"0.9.1"},J={registry:"https://registry.npmjs.org"},B="yarn@1.22.22",V={name:_,version:O,description:C,author:H,type:A,homepage:I,bugs:N,repository:R,bin:j,main:P,module:T,types:W,exports:L,files:F,scripts:G,pkgroll:M,dependencies:X,devDependencies:U,resolutions:z,overrides:$,publishConfig:J,packageManager:B},q=Object.freeze({__proto__:null,author:H,bin:j,bugs:N,default:V,dependencies:X,description:C,devDependencies:U,exports:L,files:F,homepage:I,main:P,module:T,name:_,overrides:$,packageManager:B,pkgroll:M,publishConfig:J,repository:R,resolutions:z,scripts:G,type:A,types:W,version:O});const K=v.object({enabled:v.boolean().default(!0),network:k,filesystem:S.shape.filesystem.optional(),env:S.shape.env.optional()});function Y(e,t){const s=E();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[D(t,"config","codex"),D(t,"config","claude"),D(s,".codex"),D(s,".claude"),D(s,".claude.json"),D(s,".claude.json.lock"),D(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,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${D(e,"dist","sandbox","node-proxy-boot.js")}`}}}function Q(e,t,s){return"macos"===e?function(e,t){E();const s=Y(e,t);return{enabled:s.enabled,network:s.network,filesystem:{denyRead:[],allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}(t,s):function(e,t){const s=Y(e,t);return{enabled:s.enabled,network:s.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}(t,s)}const Z=x(b(import.meta.url));function ee(){return y(Z,"..")}const te=v.object({sandbox:K,daemonEnv:v.object({enabled:v.boolean().default(!1),variables:v.record(v.string(),v.string()).optional()}).optional(),allowDirectBash:v.boolean().default(!0)});class se{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(/^~/,s.homedir()):h(s.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,s.homedir()):h(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,s.homedir()):h(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=V.version;const t=process.env.AGENTRIX_CLAUDE_HOME||process.env.CLAUDE_CONFIG_DIR;this.claudeConfigDir=t?t.replace(/^~(?=\/|$)/,s.homedir()):h(this.agentrixHomeDir,"config","claude");const r=process.env.AGENTRIX_CODEX_HOME||process.env.CODEX_HOME;this.codexHomeDir=r?r.replace(/^~/,s.homedir()):h(this.agentrixHomeDir,"config","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-${r()}`}metadata(){return{host:s.hostname(),platform:s.platform(),cliVersion:this.currentCliVersion,homeDir:s.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"),s=JSON.parse(t);return{secret:s.secret,token:s.token,machineId:s.machineId}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await p(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){const s=this.getStatePaths();for(let r=1;r<=e;r++)try{const e=await u(s.daemonLockFile,o.O_CREAT|o.O_EXCL|o.O_WRONLY);return await e.writeFile(String(process.pid)),e}catch(i){if("EEXIST"===i.code)try{const e=a(s.daemonLockFile,"utf-8").trim();if(e&&!Number.isNaN(Number(e)))try{process.kill(Number(e),0)}catch{c(s.daemonLockFile);continue}}catch{}if(r===e)return null;const n=r*t;await new Promise(e=>setTimeout(e,n))}return null}async releaseDaemonLock(e){const t=this.getStatePaths();try{await e.close()}catch{}try{i(t.daemonLockFile)&&c(t.daemonLockFile)}catch{}}ensureDir(e){return i(e)||l(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=h(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const s=h(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(s)}resolveProjectCWD(e,t,r){if(e)return this.ensureDir(e.replace(/^~/,s.homedir()));const i=h(this.agentrixWorkspaceHomeDir,"users",t,r,"project");return this.ensureDir(i)}resolveProjectDir(e,t){const s=h(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(s)}resolveDataDir(e,t){const s=h(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(s)}resolveAttachmentsDir(e,t){const s=h(this.resolveDataDir(e,t),"attachments");return this.ensureDir(s)}resolveAgentDir(e){return h(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return h(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const s=this.getWorkspaceStatePath(e,t);if(i(s))try{const e=a(s,"utf-8");return JSON.parse(e)}catch{return null}const r=this.resolveDataDir(e,t),o=h(r,"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(s,JSON.stringify(t,null,2));try{c(o)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const r=this.getWorkspaceStatePath(e,t);await p(r,JSON.stringify(s,null,2))}getLastSentArtifactVersionPath(e,t){return h(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const s=this.getLastSentArtifactVersionPath(e,t);if(!i(s))return null;try{return(await d(s,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,s){const r=this.getLastSentArtifactVersionPath(e,t);await p(r,s)}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),s=h(t,"input.json");n(s,JSON.stringify(e,null,2))}readTaskInput(e,t){const s=this.resolveDataDir(e,t),r=h(s,"input.json");if(!i(r))throw new Error(`Task input file does not exist: ${r}`);const n=a(r,"utf-8");return JSON.parse(n)}getTaskCwd(e,t){const s=this.getWorkspaceState(e,t);return s?.cwd?s.cwd:null}resolveWorkspaceFilePath(e,t,s){const r=s.replace(/^\/+/,"");if("project"===r||r.startsWith("project/")){const s=this.getTaskCwd(e,t),i=this.resolveProjectCWD(s||void 0,e,t),n="project"===r?"":r.slice(8);return n?h(i,n):i}if("data"===r||r.startsWith("data/")){const s=this.resolveDataDir(e,t),i="data"===r?"":r.slice(5);return i?h(s,i):s}const i=this.resolveTaskDir(e,t);return h(i,r)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await f(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:Q(w(),ee(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},allowDirectBash:!0}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),s={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return te.parse(s)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}getSandboxSettings(){return this.sandboxSettings}}const re=new se;g(re);var ie=Object.freeze({__proto__:null,Machine:se,machine:re,projectPath:ee});const ne=e.format.printf(({level:e,message:s,timestamp:r,...i})=>{const n=new Date(r).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}: ${s}${Object.keys(i).length>0?" "+JSON.stringify(i):""}`}),oe=e.format.printf(({level:e,message:t,timestamp:s,...r})=>{const i=Object.keys(r).length>0?" "+JSON.stringify(r):"";return`[${s}] ${e.toUpperCase()}: ${t}${i}`});function ae(t){const s=re.getStatePaths().logsDir,r=process.env.DEBUG?"debug":"info";if("console-only"===t.type)return e.createLogger({level:r,format:e.format.combine(e.format.timestamp(),ne),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:s,zippedArchive:!0,maxsize:104857600,maxFiles:n,tailable:!0,format:e.format.combine(e.format.timestamp(),oe)})];return process.env.DEBUG&&o.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),ne)})),e.createLogger({level:r,transports:o})}let ce=ae({type:"console-only"});function le(e){const t=re.getStatePaths().logsDir;if("console-only"===e.type)return"";const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`;return h(t,s)}var de=Object.freeze({__proto__:null,createLogger:ae,getLogPath:le,logger:ce});export{se as M,q as _,V as a,de as b,ae as c,ie as d,le as g,ce as l,re as m,ee as p};
@@ -1 +0,0 @@
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"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.12.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 && npx 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.js dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs && npm rebuild node-datachannel",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test node_modules/.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:"npm rebuild node-datachannel && node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll={minify:!0,sourcemap:!1},dependencies={"@agentrix/shared":"^2.12.0","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.120.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/sandbox-runtime":"^0.2.5",axios:"1.13.2","better-sqlite3":"^12.6.2",chalk:"^5.4.1","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-datachannel":"0.9.1","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"},devDependencies={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20","cross-env":"^10.0.0",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,devDependencies:devDependencies,resolutions:resolutions,overrides:overrides,publishConfig:publishConfig,packageManager:packageManager},_package=Object.freeze({__proto__:null,author:author,bin:bin,bugs:bugs,default:packageJson,dependencies:dependencies,description:description,devDependencies:devDependencies,exports:exports$1,files:files,homepage:homepage,main:main,module:module$1,name:name,overrides:overrides,packageManager:packageManager,pkgroll:pkgroll,publishConfig:publishConfig,repository:repository,resolutions:resolutions,scripts:scripts,type:type,types:types,version:version});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 s=os.homedir();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[path.join(t,"config","codex"),path.join(t,"config","claude"),path.join(s,".codex"),path.join(s,".claude"),path.join(s,".claude.json"),path.join(s,".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,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${path.join(e,"dist","sandbox","node-proxy-boot.js")}`}}}function getDefaultMacOSSettings(e,t){os.homedir();const s=getCommonConfig(e,t);return{enabled:s.enabled,network:s.network,filesystem:{denyRead:[],allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}function getDefaultLinuxSettings(e,t){const s=getCommonConfig(e,t);return{enabled:s.enabled,network:s.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}function getDefaultSandboxSettings(e,t,s){return"macos"===e?getDefaultMacOSSettings(t,s):getDefaultLinuxSettings(t,s)}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-CmNBqkS2.cjs",document.baseURI).href));function projectPath(){return path.resolve(__dirname$1,"..")}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(),allowDirectBash:zod.z.boolean().default(!0)});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;const t=process.env.AGENTRIX_CLAUDE_HOME||process.env.CLAUDE_CONFIG_DIR;this.claudeConfigDir=t?t.replace(/^~(?=\/|$)/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"config","claude");const s=process.env.AGENTRIX_CODEX_HOME||process.env.CODEX_HOME;this.codexHomeDir=s?s.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"config","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"),s=JSON.parse(t);return{secret:s.secret,token:s.token,machineId:s.machineId}}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){const s=this.getStatePaths();for(let i=1;i<=e;i++)try{const e=await promises.open(s.daemonLockFile,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY);return await e.writeFile(String(process.pid)),e}catch(n){if("EEXIST"===n.code)try{const e=fs.readFileSync(s.daemonLockFile,"utf-8").trim();if(e&&!Number.isNaN(Number(e)))try{process.kill(Number(e),0)}catch{fs.unlinkSync(s.daemonLockFile);continue}}catch{}if(i===e)return null;const r=i*t;await new Promise(e=>setTimeout(e,r))}return null}async releaseDaemonLock(e){const t=this.getStatePaths();try{await e.close()}catch{}try{fs.existsSync(t.daemonLockFile)&&fs.unlinkSync(t.daemonLockFile)}catch{}}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 s=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(s)}resolveProjectCWD(e,t,s){if(e)return this.ensureDir(e.replace(/^~/,os$1.homedir()));const i=path$1.join(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(i)}resolveProjectDir(e,t){const s=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(s)}resolveDataDir(e,t){const s=path$1.join(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(s)}resolveAttachmentsDir(e,t){const s=path$1.join(this.resolveDataDir(e,t),"attachments");return this.ensureDir(s)}resolveAgentDir(e){return path$1.join(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return path$1.join(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const s=this.getWorkspaceStatePath(e,t);if(fs.existsSync(s))try{const e=fs.readFileSync(s,"utf-8");return JSON.parse(e)}catch{return null}const i=this.resolveDataDir(e,t),n=path$1.join(i,"cwd.txt");if(!fs.existsSync(n))return null;try{const e=fs.readFileSync(n,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{fs.writeFileSync(s,JSON.stringify(t,null,2));try{fs.unlinkSync(n)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const i=this.getWorkspaceStatePath(e,t);await promises.writeFile(i,JSON.stringify(s,null,2))}getLastSentArtifactVersionPath(e,t){return path$1.join(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const s=this.getLastSentArtifactVersionPath(e,t);if(!fs.existsSync(s))return null;try{return(await promises.readFile(s,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,s){const i=this.getLastSentArtifactVersionPath(e,t);await promises.writeFile(i,s)}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),s=path$1.join(t,"input.json");fs.writeFileSync(s,JSON.stringify(e,null,2))}readTaskInput(e,t){const s=this.resolveDataDir(e,t),i=path$1.join(s,"input.json");if(!fs.existsSync(i))throw new Error(`Task input file does not exist: ${i}`);const n=fs.readFileSync(i,"utf-8");return JSON.parse(n)}getTaskCwd(e,t){const s=this.getWorkspaceState(e,t);return s?.cwd?s.cwd:null}resolveWorkspaceFilePath(e,t,s){const i=s.replace(/^\/+/,"");if("project"===i||i.startsWith("project/")){const s=this.getTaskCwd(e,t),n=this.resolveProjectCWD(s||void 0,e,t),r="project"===i?"":i.slice(8);return r?path$1.join(n,r):n}if("data"===i||i.startsWith("data/")){const s=this.resolveDataDir(e,t),n="data"===i?"":i.slice(5);return n?path$1.join(s,n):s}const n=this.resolveTaskDir(e,t);return path$1.join(n,i)}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:{}},allowDirectBash:!0}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),s={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return MachineSettingsSchema.parse(s)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}getSandboxSettings(){return this.sandboxSettings}}const machine=new Machine;shared.setAgentContext(machine);var machine$1=Object.freeze({__proto__:null,Machine:Machine,machine:machine,projectPath:projectPath});const consoleFormat=winston.format.printf(({level:e,message:t,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 r=e;switch(e){case"error":r=chalk.red(e.toUpperCase());break;case"warn":r=chalk.yellow(e.toUpperCase());break;case"info":r=chalk.blue(e.toUpperCase());break;case"debug":r=chalk.gray(e.toUpperCase())}return`[${n}] ${r}: ${t}${Object.keys(i).length>0?" "+JSON.stringify(i):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:s,...i})=>{const n=Object.keys(i).length>0?" "+JSON.stringify(i):"";return`[${s}] ${e.toUpperCase()}: ${t}${n}`});function createLogger(e){const t=machine.getStatePaths().logsDir,s=process.env.DEBUG?"debug":"info";if("console-only"===e.type)return winston.createLogger({level:s,format:winston.format.combine(winston.format.timestamp(),consoleFormat),transports:[new winston.transports.Console]});const i="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`,n="daemon"===e.type?3:1,r=[new winston.transports.File({filename:i,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:n,tailable:!0,format:winston.format.combine(winston.format.timestamp(),fileFormat)})];return process.env.DEBUG&&r.push(new winston.transports.Console({format:winston.format.combine(winston.format.timestamp(),consoleFormat)})),winston.createLogger({level:s,transports:r})}let logger=createLogger({type:"console-only"});function getLogPath(e){const t=machine.getStatePaths().logsDir;if("console-only"===e.type)return"";const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`;return path$1.join(t,s)}var logger$1=Object.freeze({__proto__:null,createLogger:createLogger,getLogPath:getLogPath,logger:logger});exports.Machine=Machine,exports._package=_package,exports.createLogger=createLogger,exports.getLogPath=getLogPath,exports.logger=logger,exports.logger$1=logger$1,exports.machine=machine,exports.machine$1=machine$1,exports.packageJson=packageJson,exports.projectPath=projectPath;