@agentrix/cli 0.3.5 → 0.3.7
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-
|
|
1
|
+
"use strict";var _package=require("./logger-DHYBD5hB.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.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-D9vQTfsa.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 +1 @@
|
|
|
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 a,readFileSync as o,unlinkSync as l,mkdirSync as c}from"node:fs";import{readFile as d,writeFile as m,unlink as p,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 y,dirname as x,resolve as D}from"path";import{fileURLToPath as b}from"url";import{z as k}from"zod";import{NetworkConfigSchema as S,SandboxInstanceConfigSchema as v}from"@xmz-ai/sandbox-runtime";import{homedir as w}from"os";import{getPlatform as _}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";var E="@agentrix/cli",P="0.3.5",j="Mobile and Web client for Claude Code and Codex",H="agentrix.xmz.ai",O="module",C="https://github.com/xmz-ai/agentrix-cli",I="https://github.com/xmz-ai/agentrix-cli/issues",N="xmz-ai/agentrix-cli",R={agentrix:"./bin/agentrix.mjs"},W="./dist/index.cjs",A="./dist/index.mjs",T="./dist/index.d.cts",F={".":{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"}}},L=["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"},z={minify:!0,sourcemap:!1},U={"@agentrix/shared":"*","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.101.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.10.0","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"},X={"@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"},M={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},$={registry:"https://registry.npmjs.org"},J="yarn@1.22.22",q={name:E,version:P,description:j,author:H,type:O,homepage:C,bugs:I,repository:N,bin:R,main:W,module:A,types:T,exports:F,files:L,scripts:G,pkgroll:z,dependencies:U,devDependencies:X,resolutions:M,publishConfig:$,packageManager:J},K=Object.freeze({__proto__:null,author:H,bin:R,bugs:I,default:q,dependencies:U,description:j,devDependencies:X,exports:F,files:L,homepage:C,main:W,module:A,name:E,packageManager:J,pkgroll:z,publishConfig:$,repository:N,resolutions:M,scripts:G,type:O,types:T,version:P});const B=k.object({enabled:k.boolean().default(!0),network:S,filesystem:v.shape.filesystem.optional(),env:v.shape.env.optional()});function V(e,t){const s=w();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[y(s,".codex"),y(s,"claude"),y(s,".claude.json"),y(s,".claude.json.lock")],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,SRT_DEBUG:null,NODE_OPTIONS:`--require ${y(e,"dist","sandbox","node-proxy-boot.js")}`}}}const Y=x(b(import.meta.url));function Q(){return D(Y,"..")}class Z{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;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=q.version,this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),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 m(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();i(e.credentialsFile)&&await p(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 p(e.daemonStateFile),i(e.daemonLockFile))try{await p(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,a.O_CREAT|a.O_EXCL|a.O_WRONLY);return await e.writeFile(String(process.pid)),e}catch(i){if("EEXIST"===i.code)try{const e=o(s.daemonLockFile,"utf-8").trim();if(e&&!Number.isNaN(Number(e)))try{process.kill(Number(e),0)}catch{l(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)&&l(t.daemonLockFile)}catch{}}ensureDir(e){return i(e)||c(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=o(s,"utf-8");return JSON.parse(e)}catch{return null}const r=this.resolveDataDir(e,t),a=h(r,"cwd.txt");if(!i(a))return null;try{const e=o(a,"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{l(a)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const r=this.getWorkspaceStatePath(e,t);await m(r,JSON.stringify(s,null,2))}getLastSentCommitHashPath(e,t){return h(this.resolveDataDir(e,t),"last-sent-commit-hash.txt")}async readLastSentCommitHash(e,t){const s=this.getLastSentCommitHashPath(e,t);if(!i(s))return null;try{return(await d(s,"utf-8")).trim()}catch{return null}}async writeLastSentCommitHash(e,t,s){const r=this.getLastSentCommitHashPath(e,t);await m(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=o(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=o(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}loadSandboxSettings(){const e=function(e,t,s){return"macos"===e?function(e,t){w();const s=V(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=V(e,t);return{enabled:s.enabled,network:s.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}(t,s)}(_(),Q(),this.agentrixHomeDir),t={sandbox:e},s=this.readOrInitSettings(t);return s.sandbox?B.parse(s.sandbox):e}getSandboxSettings(){return this.sandboxSettings}}const ee=new Z;g(ee);var te=Object.freeze({__proto__:null,Machine:Z,machine:ee,projectPath:Q});const se=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 a=e;switch(e){case"error":a=t.red(e.toUpperCase());break;case"warn":a=t.yellow(e.toUpperCase());break;case"info":a=t.blue(e.toUpperCase());break;case"debug":a=t.gray(e.toUpperCase())}return`[${n}] ${a}: ${s}${Object.keys(i).length>0?" "+JSON.stringify(i):""}`}),re=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 ie(t){const s=ee.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(),se),transports:[new e.transports.Console]});const i="daemon"===t.type?"daemon.log":`task-${t.taskId}.log`,n="daemon"===t.type?3:1,a=[new e.transports.File({filename:i,dirname:s,zippedArchive:!0,maxsize:104857600,maxFiles:n,tailable:!0,format:e.format.combine(e.format.timestamp(),re)})];return process.env.DEBUG&&a.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),se)})),e.createLogger({level:r,transports:a})}let ne=ie({type:"console-only"});function ae(e){const t=ee.getStatePaths().logsDir;if("console-only"===e.type)return"";const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`;return h(t,s)}var oe=Object.freeze({__proto__:null,createLogger:ie,getLogPath:ae,logger:ne});export{Z as M,K as _,q as a,oe as b,ie as c,te as d,ae as g,ne as l,ee as m,Q as p};
|
|
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 a,readFileSync as o,unlinkSync as l,mkdirSync as c}from"node:fs";import{readFile as d,writeFile as m,unlink as p,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 y,dirname as x,resolve as D}from"path";import{fileURLToPath as b}from"url";import{z as k}from"zod";import{NetworkConfigSchema as S,SandboxInstanceConfigSchema as v}from"@xmz-ai/sandbox-runtime";import{homedir as w}from"os";import{getPlatform as _}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";var E="@agentrix/cli",P="0.3.7",j="Mobile and Web client for Claude Code and Codex",H="agentrix.xmz.ai",O="module",C="https://github.com/xmz-ai/agentrix-cli",I="https://github.com/xmz-ai/agentrix-cli/issues",N="xmz-ai/agentrix-cli",R={agentrix:"./bin/agentrix.mjs"},W="./dist/index.cjs",A="./dist/index.mjs",T="./dist/index.d.cts",F={".":{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"}}},L=["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"},z={minify:!0,sourcemap:!1},U={"@agentrix/shared":"*","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.101.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.10.0","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"},X={"@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"},M={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},$={registry:"https://registry.npmjs.org"},J="yarn@1.22.22",q={name:E,version:P,description:j,author:H,type:O,homepage:C,bugs:I,repository:N,bin:R,main:W,module:A,types:T,exports:F,files:L,scripts:G,pkgroll:z,dependencies:U,devDependencies:X,resolutions:M,publishConfig:$,packageManager:J},K=Object.freeze({__proto__:null,author:H,bin:R,bugs:I,default:q,dependencies:U,description:j,devDependencies:X,exports:F,files:L,homepage:C,main:W,module:A,name:E,packageManager:J,pkgroll:z,publishConfig:$,repository:N,resolutions:M,scripts:G,type:O,types:T,version:P});const B=k.object({enabled:k.boolean().default(!0),network:S,filesystem:v.shape.filesystem.optional(),env:v.shape.env.optional()});function V(e,t){const s=w();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[y(s,".codex"),y(s,"claude"),y(s,".claude.json"),y(s,".claude.json.lock")],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,SRT_DEBUG:null,NODE_OPTIONS:`--require ${y(e,"dist","sandbox","node-proxy-boot.js")}`}}}const Y=x(b(import.meta.url));function Q(){return D(Y,"..")}class Z{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;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=q.version,this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),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 m(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();i(e.credentialsFile)&&await p(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 p(e.daemonStateFile),i(e.daemonLockFile))try{await p(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,a.O_CREAT|a.O_EXCL|a.O_WRONLY);return await e.writeFile(String(process.pid)),e}catch(i){if("EEXIST"===i.code)try{const e=o(s.daemonLockFile,"utf-8").trim();if(e&&!Number.isNaN(Number(e)))try{process.kill(Number(e),0)}catch{l(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)&&l(t.daemonLockFile)}catch{}}ensureDir(e){return i(e)||c(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=o(s,"utf-8");return JSON.parse(e)}catch{return null}const r=this.resolveDataDir(e,t),a=h(r,"cwd.txt");if(!i(a))return null;try{const e=o(a,"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{l(a)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const r=this.getWorkspaceStatePath(e,t);await m(r,JSON.stringify(s,null,2))}getLastSentCommitHashPath(e,t){return h(this.resolveDataDir(e,t),"last-sent-commit-hash.txt")}async readLastSentCommitHash(e,t){const s=this.getLastSentCommitHashPath(e,t);if(!i(s))return null;try{return(await d(s,"utf-8")).trim()}catch{return null}}async writeLastSentCommitHash(e,t,s){const r=this.getLastSentCommitHashPath(e,t);await m(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=o(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=o(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}loadSandboxSettings(){const e=function(e,t,s){return"macos"===e?function(e,t){w();const s=V(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=V(e,t);return{enabled:s.enabled,network:s.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:s.commonWritePaths,denyWrite:[]},env:s.env}}(t,s)}(_(),Q(),this.agentrixHomeDir),t={sandbox:e},s=this.readOrInitSettings(t);return s.sandbox?B.parse(s.sandbox):e}getSandboxSettings(){return this.sandboxSettings}}const ee=new Z;g(ee);var te=Object.freeze({__proto__:null,Machine:Z,machine:ee,projectPath:Q});const se=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 a=e;switch(e){case"error":a=t.red(e.toUpperCase());break;case"warn":a=t.yellow(e.toUpperCase());break;case"info":a=t.blue(e.toUpperCase());break;case"debug":a=t.gray(e.toUpperCase())}return`[${n}] ${a}: ${s}${Object.keys(i).length>0?" "+JSON.stringify(i):""}`}),re=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 ie(t){const s=ee.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(),se),transports:[new e.transports.Console]});const i="daemon"===t.type?"daemon.log":`task-${t.taskId}.log`,n="daemon"===t.type?3:1,a=[new e.transports.File({filename:i,dirname:s,zippedArchive:!0,maxsize:104857600,maxFiles:n,tailable:!0,format:e.format.combine(e.format.timestamp(),re)})];return process.env.DEBUG&&a.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),se)})),e.createLogger({level:r,transports:a})}let ne=ie({type:"console-only"});function ae(e){const t=ee.getStatePaths().logsDir;if("console-only"===e.type)return"";const s="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`;return h(t,s)}var oe=Object.freeze({__proto__:null,createLogger:ie,getLogPath:ae,logger:ne});export{Z as M,K as _,q as a,oe as b,ie as c,te as d,ae as g,ne as l,ee as m,Q 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"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.3.5",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":"*","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.101.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.10.0","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"},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,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,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(s,".codex"),path.join(s,"claude"),path.join(s,".claude.json"),path.join(s,".claude.json.lock")],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,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-w9vl6wBY.cjs",document.baseURI).href));function projectPath(){return path.resolve(__dirname$1,"..")}class Machine{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;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.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),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 n=1;n<=e;n++)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(i){if("EEXIST"===i.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(n===e)return null;const r=n*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 n=path$1.join(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(n)}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 n=this.resolveDataDir(e,t),i=path$1.join(n,"cwd.txt");if(!fs.existsSync(i))return null;try{const e=fs.readFileSync(i,"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(i)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const n=this.getWorkspaceStatePath(e,t);await promises.writeFile(n,JSON.stringify(s,null,2))}getLastSentCommitHashPath(e,t){return path$1.join(this.resolveDataDir(e,t),"last-sent-commit-hash.txt")}async readLastSentCommitHash(e,t){const s=this.getLastSentCommitHashPath(e,t);if(!fs.existsSync(s))return null;try{return(await promises.readFile(s,"utf-8")).trim()}catch{return null}}async writeLastSentCommitHash(e,t,s){const n=this.getLastSentCommitHashPath(e,t);await promises.writeFile(n,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),n=path$1.join(s,"input.json");if(!fs.existsSync(n))throw new Error(`Task input file does not exist: ${n}`);const i=fs.readFileSync(n,"utf-8");return JSON.parse(i)}getTaskCwd(e,t){const s=this.getWorkspaceState(e,t);return s?.cwd?s.cwd:null}resolveWorkspaceFilePath(e,t,s){const n=s.replace(/^\/+/,"");if("project"===n||n.startsWith("project/")){const s=this.getTaskCwd(e,t),i=this.resolveProjectCWD(s||void 0,e,t),r="project"===n?"":n.slice(8);return r?path$1.join(i,r):i}if("data"===n||n.startsWith("data/")){const s=this.resolveDataDir(e,t),i="data"===n?"":n.slice(5);return i?path$1.join(s,i):s}const i=this.resolveTaskDir(e,t);return path$1.join(i,n)}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}loadSandboxSettings(){const e=getDefaultSandboxSettings(platform_js.getPlatform(),projectPath(),this.agentrixHomeDir),t={sandbox:e},s=this.readOrInitSettings(t);return s.sandbox?SandboxSettingsSchema.parse(s.sandbox):e}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,...n})=>{const i=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`[${i}] ${r}: ${t}${Object.keys(n).length>0?" "+JSON.stringify(n):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:s,...n})=>{const i=Object.keys(n).length>0?" "+JSON.stringify(n):"";return`[${s}] ${e.toUpperCase()}: ${t}${i}`});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 n="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`,i="daemon"===e.type?3:1,r=[new winston.transports.File({filename:n,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:i,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;
|
|
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.3.7",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":"*","@anthropic-ai/claude-agent-sdk":"^0.2.31","@anthropic-ai/sdk":"0.71.2","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.101.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.10.0","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"},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,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,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(s,".codex"),path.join(s,"claude"),path.join(s,".claude.json"),path.join(s,".claude.json.lock")],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,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-DHYBD5hB.cjs",document.baseURI).href));function projectPath(){return path.resolve(__dirname$1,"..")}class Machine{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;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.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),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 n=1;n<=e;n++)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(i){if("EEXIST"===i.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(n===e)return null;const r=n*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 n=path$1.join(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(n)}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 n=this.resolveDataDir(e,t),i=path$1.join(n,"cwd.txt");if(!fs.existsSync(i))return null;try{const e=fs.readFileSync(i,"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(i)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,s){const n=this.getWorkspaceStatePath(e,t);await promises.writeFile(n,JSON.stringify(s,null,2))}getLastSentCommitHashPath(e,t){return path$1.join(this.resolveDataDir(e,t),"last-sent-commit-hash.txt")}async readLastSentCommitHash(e,t){const s=this.getLastSentCommitHashPath(e,t);if(!fs.existsSync(s))return null;try{return(await promises.readFile(s,"utf-8")).trim()}catch{return null}}async writeLastSentCommitHash(e,t,s){const n=this.getLastSentCommitHashPath(e,t);await promises.writeFile(n,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),n=path$1.join(s,"input.json");if(!fs.existsSync(n))throw new Error(`Task input file does not exist: ${n}`);const i=fs.readFileSync(n,"utf-8");return JSON.parse(i)}getTaskCwd(e,t){const s=this.getWorkspaceState(e,t);return s?.cwd?s.cwd:null}resolveWorkspaceFilePath(e,t,s){const n=s.replace(/^\/+/,"");if("project"===n||n.startsWith("project/")){const s=this.getTaskCwd(e,t),i=this.resolveProjectCWD(s||void 0,e,t),r="project"===n?"":n.slice(8);return r?path$1.join(i,r):i}if("data"===n||n.startsWith("data/")){const s=this.resolveDataDir(e,t),i="data"===n?"":n.slice(5);return i?path$1.join(s,i):s}const i=this.resolveTaskDir(e,t);return path$1.join(i,n)}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}loadSandboxSettings(){const e=getDefaultSandboxSettings(platform_js.getPlatform(),projectPath(),this.agentrixHomeDir),t={sandbox:e},s=this.readOrInitSettings(t);return s.sandbox?SandboxSettingsSchema.parse(s.sandbox):e}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,...n})=>{const i=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`[${i}] ${r}: ${t}${Object.keys(n).length>0?" "+JSON.stringify(n):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:s,...n})=>{const i=Object.keys(n).length>0?" "+JSON.stringify(n):"";return`[${s}] ${e.toUpperCase()}: ${t}${i}`});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 n="daemon"===e.type?"daemon.log":`task-${e.taskId}.log`,i="daemon"===e.type?3:1,r=[new winston.transports.File({filename:n,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:i,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;
|