@agentrix/cli 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var machine=require("./logger-D-NJyt5I.cjs");require("winston"),require("chalk"),require("node:os"),require("node:crypto"),require("node:fs"),require("node:fs/promises"),require("node:path"),require("@agentrix/shared"),require("path"),require("url"),require("zod"),require("@xmz-ai/sandbox-runtime"),require("os"),require("@xmz-ai/sandbox-runtime/dist/utils/platform.js"),require("node:url"),exports.Machine=machine.Machine,Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return machine.logger}}),exports.machine=machine.machine;
1
+ "use strict";var machine=require("./logger-Dtz6MdP6.cjs");require("winston"),require("chalk"),require("node:os"),require("node:crypto"),require("node:fs"),require("node:fs/promises"),require("node:path"),require("@agentrix/shared"),require("path"),require("url"),require("zod"),require("@xmz-ai/sandbox-runtime"),require("os"),require("@xmz-ai/sandbox-runtime/dist/utils/platform.js"),require("node:url"),exports.Machine=machine.Machine,Object.defineProperty(exports,"logger",{enumerable:!0,get:function(){return machine.logger}}),exports.machine=machine.machine;
package/dist/lib.d.cts CHANGED
@@ -84,6 +84,42 @@ type MachineStatePaths = {
84
84
  daemonStateFile: string;
85
85
  daemonLockFile: string;
86
86
  };
87
+ declare const MachineSettingsSchema: z.ZodObject<{
88
+ sandbox: z.ZodObject<{
89
+ enabled: z.ZodDefault<z.ZodBoolean>;
90
+ network: z.ZodObject<{
91
+ allowedDomains: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>;
92
+ deniedDomains: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>;
93
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
95
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
96
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
97
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
98
+ noProxyAddresses: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ allowNetworkMetadata: z.ZodOptional<z.ZodBoolean>;
100
+ }, z.core.$strip>;
101
+ filesystem: z.ZodOptional<z.ZodObject<{
102
+ denyRead: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ allowRead: z.ZodOptional<z.ZodArray<z.ZodString>>;
104
+ autoAllowSystemPaths: z.ZodOptional<z.ZodBoolean>;
105
+ allowWrite: z.ZodOptional<z.ZodArray<z.ZodString>>;
106
+ denyWrite: z.ZodOptional<z.ZodArray<z.ZodString>>;
107
+ }, z.core.$strip>>;
108
+ env: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>>>;
109
+ }, z.core.$strip>;
110
+ daemonEnv: z.ZodOptional<z.ZodObject<{
111
+ enabled: z.ZodDefault<z.ZodBoolean>;
112
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
113
+ }, z.core.$strip>>;
114
+ daemonControl: z.ZodDefault<z.ZodObject<{
115
+ allowLanAccess: z.ZodDefault<z.ZodBoolean>;
116
+ }, z.core.$strip>>;
117
+ allowDirectBash: z.ZodDefault<z.ZodBoolean>;
118
+ storageManagement: z.ZodDefault<z.ZodObject<{
119
+ autoSelectTaskOlderThanDays: z.ZodDefault<z.ZodNumber>;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>;
122
+ type MachineSettings = z.infer<typeof MachineSettingsSchema>;
87
123
  declare class Machine implements AgentContext {
88
124
  readonly serverUrl: string;
89
125
  readonly webappUrl: string;
@@ -154,6 +190,7 @@ declare class Machine implements AgentContext {
154
190
  private readMachineSettings;
155
191
  private loadSandboxSettings;
156
192
  isDirectBashAllowed(): boolean;
193
+ getStorageManagementSettings(): MachineSettings['storageManagement'];
157
194
  getDaemonControlHost(): '127.0.0.1' | '0.0.0.0';
158
195
  getDaemonWebhookHost(): string;
159
196
  getSandboxSettings(): SandboxSettings;
package/dist/lib.d.mts CHANGED
@@ -84,6 +84,42 @@ type MachineStatePaths = {
84
84
  daemonStateFile: string;
85
85
  daemonLockFile: string;
86
86
  };
87
+ declare const MachineSettingsSchema: z.ZodObject<{
88
+ sandbox: z.ZodObject<{
89
+ enabled: z.ZodDefault<z.ZodBoolean>;
90
+ network: z.ZodObject<{
91
+ allowedDomains: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>;
92
+ deniedDomains: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>;
93
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString>>;
94
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
95
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
96
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
97
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
98
+ noProxyAddresses: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ allowNetworkMetadata: z.ZodOptional<z.ZodBoolean>;
100
+ }, z.core.$strip>;
101
+ filesystem: z.ZodOptional<z.ZodObject<{
102
+ denyRead: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ allowRead: z.ZodOptional<z.ZodArray<z.ZodString>>;
104
+ autoAllowSystemPaths: z.ZodOptional<z.ZodBoolean>;
105
+ allowWrite: z.ZodOptional<z.ZodArray<z.ZodString>>;
106
+ denyWrite: z.ZodOptional<z.ZodArray<z.ZodString>>;
107
+ }, z.core.$strip>>;
108
+ env: z.ZodOptional<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>>>;
109
+ }, z.core.$strip>;
110
+ daemonEnv: z.ZodOptional<z.ZodObject<{
111
+ enabled: z.ZodDefault<z.ZodBoolean>;
112
+ variables: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
113
+ }, z.core.$strip>>;
114
+ daemonControl: z.ZodDefault<z.ZodObject<{
115
+ allowLanAccess: z.ZodDefault<z.ZodBoolean>;
116
+ }, z.core.$strip>>;
117
+ allowDirectBash: z.ZodDefault<z.ZodBoolean>;
118
+ storageManagement: z.ZodDefault<z.ZodObject<{
119
+ autoSelectTaskOlderThanDays: z.ZodDefault<z.ZodNumber>;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>;
122
+ type MachineSettings = z.infer<typeof MachineSettingsSchema>;
87
123
  declare class Machine implements AgentContext {
88
124
  readonly serverUrl: string;
89
125
  readonly webappUrl: string;
@@ -154,6 +190,7 @@ declare class Machine implements AgentContext {
154
190
  private readMachineSettings;
155
191
  private loadSandboxSettings;
156
192
  isDirectBashAllowed(): boolean;
193
+ getStorageManagementSettings(): MachineSettings['storageManagement'];
157
194
  getDaemonControlHost(): '127.0.0.1' | '0.0.0.0';
158
195
  getDaemonWebhookHost(): string;
159
196
  getSandboxSettings(): SandboxSettings;
package/dist/lib.mjs CHANGED
@@ -1 +1 @@
1
- export{M as Machine,l as logger,m as machine}from"./logger-BuUuvtBc.mjs";import"winston";import"chalk";import"node:os";import"node:crypto";import"node:fs";import"node:fs/promises";import"node:path";import"@agentrix/shared";import"path";import"url";import"zod";import"@xmz-ai/sandbox-runtime";import"os";import"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import"node:url";
1
+ export{M as Machine,l as logger,m as machine}from"./logger-De-o40Bc.mjs";import"winston";import"chalk";import"node:os";import"node:crypto";import"node:fs";import"node:fs/promises";import"node:path";import"@agentrix/shared";import"path";import"url";import"zod";import"@xmz-ai/sandbox-runtime";import"os";import"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import"node:url";
@@ -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 u,unlink as m,open as h}from"node:fs/promises";import{join as p,basename as g}from"node:path";import{setAgentContext as f,createKeyPair as D}from"@agentrix/shared";import{join as x,dirname as y,resolve as b}from"path";import{fileURLToPath as S}from"url";import{z as v}from"zod";import{SandboxInstanceConfigSchema as k,NetworkConfigSchema as w}from"@xmz-ai/sandbox-runtime";import{homedir as E}from"os";import{getPlatform as _}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import{fileURLToPath as A}from"node:url";var R={name:"@agentrix/cli",version:"0.39.0",description:"Mobile and Web client for Claude Code and Codex",author:"agentrix.xmz.ai",type:"module",homepage:"https://github.com/xmz-ai/agentrix-cli",bugs:"https://github.com/xmz-ai/agentrix-cli/issues",repository:"xmz-ai/agentrix-cli",bin:{agentrix:"./bin/agentrix.mjs"},main:"./dist/index.cjs",module:"./dist/index.mjs",types:"./dist/index.d.cts",exports:{".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files:["dist","bin","scripts","package.json"],scripts:{"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test 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:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll:{minify:!0,sourcemap:!1},dependencies:{"@agentrix/shared":"^2.38.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.133.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",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies:{"node-datachannel":"0.9.1"},devDependencies:{"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions:{"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides:{"node-datachannel":"0.9.1"},publishConfig:{registry:"https://registry.npmjs.org"},packageManager:"yarn@1.22.22"};const O=v.object({enabled:v.boolean().default(!0),network:w,filesystem:k.shape.filesystem.optional(),env:k.shape.env.optional()});function C(e,t){const r=E();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[x(t,"config","codex"),x(t,"config","claude"),x(t,"config","gemini"),x(r,".codex"),x(r,".claude"),x(r,".claude.json"),x(r,".claude.json.lock"),x(t,"agents/companion")],agentrixHomeDir:t,env:{DEBUG:null,AGENTRIX_SERVER_URL:null,AGENTRIX_WEBAPP_URL:null,AGENTRIX_HOME_DIR:null,AGENTRIX_WORKSPACE_HOME_DIR:null,AGENTRIX_AGENTS_HOME_DIR:null,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${x(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function H(e,t,r){return"macos"===e?function(e,t){E();const r=C(e,t);return{enabled:r.enabled,network:r.network,filesystem:{denyRead:[],allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r):function(e,t){const r=C(e,t);return{enabled:r.enabled,network:r.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r)}const I=y(S(import.meta.url));function j(){return b(I,"..")}const N=v.object({sandbox:O,daemonEnv:v.object({enabled:v.boolean().default(!1),variables:v.record(v.string(),v.string()).optional()}).optional(),daemonControl:v.object({allowLanAccess:v.boolean().default(!1)}).default({allowLanAccess:!1}),allowDirectBash:v.boolean().default(!0),storageManagement:v.object({autoSelectTaskOlderThanDays:v.number().int().nonnegative().default(14)}).default({autoSelectTaskOlderThanDays:14})});class P{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()):p(r.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,r.homedir()):p(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,r.homedir()):p(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=R.version,this.claudeConfigDir=p(r.homedir(),".claude"),this.codexHomeDir=p(r.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(p(this.agentrixHomeDir,"logs")),settingsFile:p(this.agentrixHomeDir,"settings.json"),credentialsFile:p(this.agentrixHomeDir,"credentials.json"),daemonStateFile:p(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:p(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${s()}`}metadata(){return{host:r.hostname(),platform:r.platform(),cliVersion:this.currentCliVersion,homeDir:r.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!i(e.credentialsFile))return null;try{const t=await d(e.credentialsFile,"utf8"),r=JSON.parse(t);return{secret:r.secret,token:r.token,machineId:r.machineId,machineAesKey:"string"==typeof r.machineAesKey?r.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await u(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();i(e.credentialsFile)&&await m(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!i(e.daemonStateFile))return null;const t=await d(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();n(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(i(e.daemonStateFile)&&await m(e.daemonStateFile),i(e.daemonLockFile))try{await m(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return i(e)||o(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=p(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const r=p(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(r)}resolveProjectCWD(e,t,s){if(e)return this.ensureDir(e.replace(/^~/,r.homedir()));const i=p(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(i)}resolveProjectDir(e,t){const r=p(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(r)}resolveDataDir(e,t){const r=p(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(r)}resolveAttachmentsDir(e,t){const r=p(this.resolveDataDir(e,t),"attachments");return this.ensureDir(r)}resolveRepoStoreRootDir(){return p(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,r){return p(this.resolveRepoStoreRootDir(),e,t,r)}resolveRepoStoreCheckoutDir(e,t,r){return this.ensureDir(p(this.resolveRepoStoreDir(e,t,r),"repo"))}resolveRepoStoreMetaPath(e,t,r){return p(this.resolveRepoStoreDir(e,t,r),"meta.json")}resolveRepoStoreLockPath(e,t,r){return p(this.resolveRepoStoreDir(e,t,r),"lock")}resolveAgentDirUnder(e,t){const r=p(t,e);return i(p(r,"agent.json"))?r:null}resolveAgentDir(e,t){if(t){const r=this.resolveAgentDirUnder(e,p(t,".agentrix","agents"));if(r)return r}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||p(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return p(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=p(s,"cwd.txt");if(!i(o))return null;try{const e=a(o,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{n(r,JSON.stringify(t,null,2));try{c(o)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,r){const s=this.getWorkspaceStatePath(e,t);await u(s,JSON.stringify(r,null,2))}getLastSentArtifactVersionPath(e,t){return p(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const r=this.getLastSentArtifactVersionPath(e,t);if(!i(r))return null;try{return(await d(r,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,r){const s=this.getLastSentArtifactVersionPath(e,t);await u(s,r)}async acquireFileLock(e,t=60,r=200){this.ensureDir(y(e));for(let s=1;s<=t;s++)try{const t=await h(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=p(t,"input.json");n(r,JSON.stringify(e,null,2))}readTaskInput(e,t){const r=this.resolveDataDir(e,t),s=p(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?p(i,n):i}if("data"===s||s.startsWith("data/")){const r=this.resolveDataDir(e,t),i="data"===s?"":s.slice(5);return i?p(r,i):r}const i=this.resolveTaskDir(e,t);return p(i,s)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await D(e.secret);this.secretKey=t.secretKey}return this.secretKey}readSettings(){const{settingsFile:e}=this.statePaths;if(!i(e))return null;try{const t=a(e,"utf-8");return JSON.parse(t)}catch(e){throw new Error(`Failed to parse settings file: ${e}`)}}writeSettings(e){const{settingsFile:t}=this.statePaths;this.ensureDir(y(t)),n(t,JSON.stringify(e,null,2),"utf-8")}readOrInitSettings(e){let t=this.readSettings();return t||(this.writeSettings(e),t=e),t}getDefaultMachineSettings(){return{sandbox:H(_(),j(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0,storageManagement:{autoSelectTaskOlderThanDays:14}}}readMachineSettings(){const e=this.getDefaultMachineSettings(),t=this.readOrInitSettings(e),r={...e,...t&&"object"==typeof t?t:{},sandbox:{...e.sandbox,...t&&"object"==typeof t&&t.sandbox&&"object"==typeof t.sandbox?t.sandbox:{}}};return N.parse(r)}loadSandboxSettings(){return this.readMachineSettings().sandbox}isDirectBashAllowed(){return this.readMachineSettings().allowDirectBash}getStorageManagementSettings(){return this.readMachineSettings().storageManagement}getDaemonControlHost(){return this.readMachineSettings().daemonControl.allowLanAccess?"0.0.0.0":"127.0.0.1"}getDaemonWebhookHost(){if("0.0.0.0"!==this.getDaemonControlHost())return"127.0.0.1";const e=r.networkInterfaces();for(const t of Object.values(e))for(const e of t??[])if("IPv4"===e.family&&!e.internal)return e.address;return"127.0.0.1"}getSandboxSettings(){return this.sandboxSettings}}const T=new P;f(T);var L=Object.freeze({__proto__:null,Machine:P,machine:T,projectPath:j});function W(e,t,r){const s=function(e){const t=e.startsWith("file:")?A(e):e;return g(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}(e),i=(e,t,i)=>{!1!==r?.filter?.(t,e)&&z[e](`[${s}] ${t}`,...i)};return{debug:(e,...t)=>i("debug",e,t),info:(e,...t)=>i("info",e,t),warn:(e,...t)=>i("warn",e,t),error:(e,...t)=>i("error",e,t)}}function F(e){const t=X(e);return function(e){z=e}(t),t}function M(){return z}const G=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):""}`}),U=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 X(t){const r=T.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(),G),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(),U)})];return process.env.DEBUG&&o.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),G)})),e.createLogger({level:s,transports:o})}let z=X({type:"console-only"});function $(e){const t=T.getStatePaths().logsDir;return p(t,"daemon.log")}export{P as M,R as a,M as b,W as c,L as d,$ as g,F as i,z as l,T as m,j 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"),node_url=require("node:url"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.39.0",description="Mobile and Web client for Claude Code and Codex",author="agentrix.xmz.ai",type="module",homepage="https://github.com/xmz-ai/agentrix-cli",bugs="https://github.com/xmz-ai/agentrix-cli/issues",repository="xmz-ai/agentrix-cli",bin={agentrix:"./bin/agentrix.mjs"},main="./dist/index.cjs",module$1="./dist/index.mjs",types="./dist/index.d.cts",exports$1={".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files=["dist","bin","scripts","package.json"],scripts={"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test 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:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll={minify:!0,sourcemap:!1},dependencies={"@agentrix/shared":"^2.38.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.133.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",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies={"node-datachannel":"0.9.1"},devDependencies={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides={"node-datachannel":"0.9.1"},publishConfig={registry:"https://registry.npmjs.org"},packageManager="yarn@1.22.22",packageJson={name:name,version:version,description:description,author:author,type:type,homepage:homepage,bugs:bugs,repository:repository,bin:bin,main:main,module:module$1,types:types,exports:exports$1,files:files,scripts:scripts,pkgroll:pkgroll,dependencies:dependencies,optionalDependencies:optionalDependencies,devDependencies:devDependencies,resolutions:resolutions,overrides:overrides,publishConfig:publishConfig,packageManager:packageManager};const SandboxSettingsSchema=zod.z.object({enabled:zod.z.boolean().default(!0),network:sandboxRuntime.NetworkConfigSchema,filesystem:sandboxRuntime.SandboxInstanceConfigSchema.shape.filesystem.optional(),env:sandboxRuntime.SandboxInstanceConfigSchema.shape.env.optional()});function getCommonConfig(e,t){const s=os.homedir();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[path.join(t,"config","codex"),path.join(t,"config","claude"),path.join(t,"config","gemini"),path.join(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,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${path.join(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function getDefaultMacOSSettings(e,t){os.homedir();const 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-Dtz6MdP6.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),storageManagement:zod.z.object({autoSelectTaskOlderThanDays:zod.z.number().int().nonnegative().default(14)}).default({autoSelectTaskOlderThanDays:14})});class Machine{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;claudeConfigDir;codexHomeDir;currentCliVersion;disableCaffeinate;statePaths;secretKey;sandboxSettings;constructor(){const e=process.argv.slice(2);this.isDaemonProcess="daemon"===e[0],this.serverUrl=process.env.AGENTRIX_SERVER_URL||"https://agentrix.xmz.ai",this.webappUrl=process.env.AGENTRIX_WEBAPP_URL||"https://agentrix.xmz.ai",this.agentrixHomeDir=process.env.AGENTRIX_HOME_DIR?process.env.AGENTRIX_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(os$1.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,os$1.homedir()):path$1.join(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=packageJson.version,this.claudeConfigDir=path$1.join(os$1.homedir(),".claude"),this.codexHomeDir=path$1.join(os$1.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(path$1.join(this.agentrixHomeDir,"logs")),settingsFile:path$1.join(this.agentrixHomeDir,"settings.json"),credentialsFile:path$1.join(this.agentrixHomeDir,"credentials.json"),daemonStateFile:path$1.join(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:path$1.join(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${node_crypto.randomUUID()}`}metadata(){return{host:os$1.hostname(),platform:os$1.platform(),cliVersion:this.currentCliVersion,homeDir:os$1.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!fs.existsSync(e.credentialsFile))return null;try{const t=await promises.readFile(e.credentialsFile,"utf8"),s=JSON.parse(t);return{secret:s.secret,token:s.token,machineId:s.machineId,machineAesKey:"string"==typeof s.machineAesKey?s.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await promises.writeFile(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();fs.existsSync(e.credentialsFile)&&await promises.unlink(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!fs.existsSync(e.daemonStateFile))return null;const t=await promises.readFile(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();fs.writeFileSync(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(fs.existsSync(e.daemonStateFile)&&await promises.unlink(e.daemonStateFile),fs.existsSync(e.daemonLockFile))try{await promises.unlink(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=path$1.join(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const 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)}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")}resolveAgentDirUnder(e,t){const s=path$1.join(t,e);return fs.existsSync(path$1.join(s,"agent.json"))?s:null}resolveAgentDir(e,t){if(t){const s=this.resolveAgentDirUnder(e,path$1.join(t,".agentrix","agents"));if(s)return s}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||path$1.join(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return path$1.join(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const 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),r=path$1.join(n,"cwd.txt");if(!fs.existsSync(r))return null;try{const e=fs.readFileSync(r,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{fs.writeFileSync(s,JSON.stringify(t,null,2));try{fs.unlinkSync(r)}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))}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 n=this.getLastSentArtifactVersionPath(e,t);await promises.writeFile(n,s)}async acquireFileLock(e,t=60,s=200){this.ensureDir(path.dirname(e));for(let n=1;n<=t;n++)try{const t=await promises.open(e,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(r){if("EEXIST"===r.code)try{const t=(await promises.readFile(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{fs.unlinkSync(e);continue}}catch{}if(n===t)return null;const i=n*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),n=path$1.join(s,"input.json");if(!fs.existsSync(n))throw new Error(`Task input file does not exist: ${n}`);const r=fs.readFileSync(n,"utf-8");return JSON.parse(r)}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),r=this.resolveProjectCWD(s||void 0,e,t),i="project"===n?"":n.slice(8);return i?path$1.join(r,i):r}if("data"===n||n.startsWith("data/")){const s=this.resolveDataDir(e,t),r="data"===n?"":n.slice(5);return r?path$1.join(s,r):s}const r=this.resolveTaskDir(e,t);return path$1.join(r,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}getDefaultMachineSettings(){return{sandbox:getDefaultSandboxSettings(platform_js.getPlatform(),projectPath(),this.agentrixHomeDir),daemonEnv:{enabled:!1,variables:{}},daemonControl:{allowLanAccess:!1},allowDirectBash:!0,storageManagement:{autoSelectTaskOlderThanDays:14}}}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}getStorageManagementSettings(){return this.readMachineSettings().storageManagement}getDaemonControlHost(){return this.readMachineSettings().daemonControl.allowLanAccess?"0.0.0.0":"127.0.0.1"}getDaemonWebhookHost(){if("0.0.0.0"!==this.getDaemonControlHost())return"127.0.0.1";const e=os$1.networkInterfaces();for(const t of Object.values(e))for(const e of t??[])if("IPv4"===e.family&&!e.internal)return e.address;return"127.0.0.1"}getSandboxSettings(){return this.sandboxSettings}}const machine=new Machine;shared.setAgentContext(machine);var machine$1=Object.freeze({__proto__:null,Machine:Machine,machine:machine,projectPath:projectPath});function resolveModuleName(e){const t=e.startsWith("file:")?node_url.fileURLToPath(e):e;return path$1.basename(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}function createModuleLogger(e,t,s){const n=resolveModuleName(e),r=(e,t,r)=>{!1!==s?.filter?.(t,e)&&exports.logger[e](`[${n}] ${t}`,...r)};return{debug:(e,...t)=>r("debug",e,t),info:(e,...t)=>r("info",e,t),warn:(e,...t)=>r("warn",e,t),error:(e,...t)=>r("error",e,t)}}function setLoggerBase(e){exports.logger=e}function initializeLogger(e){const t=createLogger(e);return setLoggerBase(t),t}function getLoggerBase(){return exports.logger}const consoleFormat=winston.format.printf(({level:e,message:t,timestamp:s,...n})=>{const r=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`[${r}] ${i}: ${t}${Object.keys(n).length>0?" "+JSON.stringify(n):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:s,...n})=>{const r=Object.keys(n).length>0?" "+JSON.stringify(n):"";return`[${s}] ${e.toUpperCase()}: ${t}${r}`});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`,r="daemon"===e.type?3:1,i=[new winston.transports.File({filename:n,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:r,tailable:!0,format:winston.format.combine(winston.format.timestamp(),fileFormat)})];return process.env.DEBUG&&i.push(new winston.transports.Console({format:winston.format.combine(winston.format.timestamp(),consoleFormat)})),winston.createLogger({level:s,transports:i})}function getLogPath(e){const t=machine.getStatePaths().logsDir;return path$1.join(t,"daemon.log")}exports.logger=createLogger({type:"console-only"}),exports.Machine=Machine,exports.createModuleLogger=createModuleLogger,exports.getLogPath=getLogPath,exports.getLoggerBase=getLoggerBase,exports.initializeLogger=initializeLogger,exports.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.38.0",
3
+ "version": "0.39.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.37.0",
63
+ "@agentrix/shared": "^2.38.0",
64
64
  "@anthropic-ai/claude-agent-sdk": "^0.2.133",
65
65
  "@anthropic-ai/sdk": "0.71.2",
66
66
  "@larksuiteoapi/node-sdk": "^1.63.1",
@@ -1 +0,0 @@
1
- import e from"winston";import t from"chalk";import r from"node:os";import{randomUUID as s}from"node:crypto";import{existsSync as i,writeFileSync as n,mkdirSync as o,readFileSync as a,unlinkSync as c,constants as l}from"node:fs";import{readFile as d,writeFile as u,unlink as m,open as p}from"node:fs/promises";import{join as h,basename as g}from"node:path";import{setAgentContext as f,createKeyPair as D}from"@agentrix/shared";import{join as x,dirname as y,resolve as b}from"path";import{fileURLToPath as S}from"url";import{z as v}from"zod";import{SandboxInstanceConfigSchema as k,NetworkConfigSchema as w}from"@xmz-ai/sandbox-runtime";import{homedir as E}from"os";import{getPlatform as _}from"@xmz-ai/sandbox-runtime/dist/utils/platform.js";import{fileURLToPath as A}from"node:url";var R={name:"@agentrix/cli",version:"0.38.0",description:"Mobile and Web client for Claude Code and Codex",author:"agentrix.xmz.ai",type:"module",homepage:"https://github.com/xmz-ai/agentrix-cli",bugs:"https://github.com/xmz-ai/agentrix-cli/issues",repository:"xmz-ai/agentrix-cli",bin:{agentrix:"./bin/agentrix.mjs"},main:"./dist/index.cjs",module:"./dist/index.mjs",types:"./dist/index.d.cts",exports:{".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files:["dist","bin","scripts","package.json"],scripts:{"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test 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:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll:{minify:!0,sourcemap:!1},dependencies:{"@agentrix/shared":"^2.37.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.133.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",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies:{"node-datachannel":"0.9.1"},devDependencies:{"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions:{"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides:{"node-datachannel":"0.9.1"},publishConfig:{registry:"https://registry.npmjs.org"},packageManager:"yarn@1.22.22"};const C=v.object({enabled:v.boolean().default(!0),network:w,filesystem:k.shape.filesystem.optional(),env:k.shape.env.optional()});function H(e,t){const r=E();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[x(t,"config","codex"),x(t,"config","claude"),x(t,"config","gemini"),x(r,".codex"),x(r,".claude"),x(r,".claude.json"),x(r,".claude.json.lock"),x(t,"agents/companion")],agentrixHomeDir:t,env:{DEBUG:null,AGENTRIX_SERVER_URL:null,AGENTRIX_WEBAPP_URL:null,AGENTRIX_HOME_DIR:null,AGENTRIX_WORKSPACE_HOME_DIR:null,AGENTRIX_AGENTS_HOME_DIR:null,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${x(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function I(e,t,r){return"macos"===e?function(e,t){E();const r=H(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=H(e,t);return{enabled:r.enabled,network:r.network,filesystem:{allowRead:[t],autoAllowSystemPaths:!0,allowWrite:r.commonWritePaths,denyWrite:[]},env:r.env}}(t,r)}const O=y(S(import.meta.url));function j(){return b(O,"..")}const N=v.object({sandbox:C,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 P{serverUrl;webappUrl;isDaemonProcess;agentrixHomeDir;agentrixWorkspaceHomeDir;agentrixAgentsHomeDir;claudeConfigDir;codexHomeDir;currentCliVersion;disableCaffeinate;statePaths;secretKey;sandboxSettings;constructor(){const e=process.argv.slice(2);this.isDaemonProcess="daemon"===e[0],this.serverUrl=process.env.AGENTRIX_SERVER_URL||"https://agentrix.xmz.ai",this.webappUrl=process.env.AGENTRIX_WEBAPP_URL||"https://agentrix.xmz.ai",this.agentrixHomeDir=process.env.AGENTRIX_HOME_DIR?process.env.AGENTRIX_HOME_DIR.replace(/^~/,r.homedir()):h(r.homedir(),".agentrix"),this.agentrixWorkspaceHomeDir=process.env.AGENTRIX_WORKSPACE_HOME_DIR?process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"workspaces"),this.agentrixAgentsHomeDir=process.env.AGENTRIX_AGENTS_HOME_DIR?process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/,r.homedir()):h(this.agentrixHomeDir,"agents"),this.disableCaffeinate=["true","1","yes"].includes((process.env.AGENTRIX_DISABLE_CAFFEINATE??"").toLowerCase()),this.currentCliVersion=R.version,this.claudeConfigDir=h(r.homedir(),".claude"),this.codexHomeDir=h(r.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(h(this.agentrixHomeDir,"logs")),settingsFile:h(this.agentrixHomeDir,"settings.json"),credentialsFile:h(this.agentrixHomeDir,"credentials.json"),daemonStateFile:h(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:h(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${s()}`}metadata(){return{host:r.hostname(),platform:r.platform(),cliVersion:this.currentCliVersion,homeDir:r.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!i(e.credentialsFile))return null;try{const t=await d(e.credentialsFile,"utf8"),r=JSON.parse(t);return{secret:r.secret,token:r.token,machineId:r.machineId,machineAesKey:"string"==typeof r.machineAesKey?r.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await u(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();i(e.credentialsFile)&&await m(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!i(e.daemonStateFile))return null;const t=await d(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();n(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(i(e.daemonStateFile)&&await m(e.daemonStateFile),i(e.daemonLockFile))try{await m(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return i(e)||o(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=h(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t);return this.ensureDir(r)}resolveProjectCWD(e,t,s){if(e)return this.ensureDir(e.replace(/^~/,r.homedir()));const i=h(this.agentrixWorkspaceHomeDir,"users",t,s,"project");return this.ensureDir(i)}resolveProjectDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t,"project");return this.ensureDir(r)}resolveDataDir(e,t){const r=h(this.agentrixWorkspaceHomeDir,"users",e,t,"data");return this.ensureDir(r)}resolveAttachmentsDir(e,t){const r=h(this.resolveDataDir(e,t),"attachments");return this.ensureDir(r)}resolveRepoStoreRootDir(){return h(this.agentrixHomeDir,"repos")}resolveRepoStoreDir(e,t,r){return h(this.resolveRepoStoreRootDir(),e,t,r)}resolveRepoStoreCheckoutDir(e,t,r){return this.ensureDir(h(this.resolveRepoStoreDir(e,t,r),"repo"))}resolveRepoStoreMetaPath(e,t,r){return h(this.resolveRepoStoreDir(e,t,r),"meta.json")}resolveRepoStoreLockPath(e,t,r){return h(this.resolveRepoStoreDir(e,t,r),"lock")}resolveAgentDirUnder(e,t){const r=h(t,e);return i(h(r,"agent.json"))?r:null}resolveAgentDir(e,t){if(t){const r=this.resolveAgentDirUnder(e,h(t,".agentrix","agents"));if(r)return r}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||h(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return h(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const r=this.getWorkspaceStatePath(e,t);if(i(r))try{const e=a(r,"utf-8");return JSON.parse(e)}catch{return null}const s=this.resolveDataDir(e,t),o=h(s,"cwd.txt");if(!i(o))return null;try{const e=a(o,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{n(r,JSON.stringify(t,null,2));try{c(o)}catch{}}catch{}return t}catch{return null}}async writeWorkspaceState(e,t,r){const s=this.getWorkspaceStatePath(e,t);await u(s,JSON.stringify(r,null,2))}getLastSentArtifactVersionPath(e,t){return h(this.resolveDataDir(e,t),"last-sent-artifact-version.txt")}async readLastSentArtifactVersion(e,t){const r=this.getLastSentArtifactVersionPath(e,t);if(!i(r))return null;try{return(await d(r,"utf-8")).trim()}catch{return null}}async writeLastSentArtifactVersion(e,t,r){const s=this.getLastSentArtifactVersionPath(e,t);await u(s,r)}async acquireFileLock(e,t=60,r=200){this.ensureDir(y(e));for(let s=1;s<=t;s++)try{const t=await p(e,l.O_CREAT|l.O_EXCL|l.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(i){if("EEXIST"===i.code)try{const t=(await d(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{c(e);continue}}catch{}if(s===t)return null;const n=s*r;await new Promise(e=>setTimeout(e,n))}return null}async releaseFileLock(e,t){try{await t.close()}catch{}try{c(e)}catch{}}writeTaskInput(e){const t=this.resolveDataDir(e.userId,e.taskId),r=h(t,"input.json");n(r,JSON.stringify(e,null,2))}readTaskInput(e,t){const r=this.resolveDataDir(e,t),s=h(r,"input.json");if(!i(s))throw new Error(`Task input file does not exist: ${s}`);const n=a(s,"utf-8");return JSON.parse(n)}getTaskCwd(e,t){const r=this.getWorkspaceState(e,t);return r?.cwd?r.cwd:null}resolveWorkspaceFilePath(e,t,r){const s=r.replace(/^\/+/,"");if("project"===s||s.startsWith("project/")){const r=this.getTaskCwd(e,t),i=this.resolveProjectCWD(r||void 0,e,t),n="project"===s?"":s.slice(8);return n?h(i,n):i}if("data"===s||s.startsWith("data/")){const r=this.resolveDataDir(e,t),i="data"===s?"":s.slice(5);return i?h(r,i):r}const i=this.resolveTaskDir(e,t);return h(i,s)}async getSecretKey(){if(this.secretKey)return this.secretKey;const e=await this.readCredentials();if(e&&e.secret){const t=await D(e.secret);this.secretKey=t.secretKey}return this.secretKey}readSettings(){const{settingsFile:e}=this.statePaths;if(!i(e))return null;try{const t=a(e,"utf-8");return JSON.parse(t)}catch(e){throw new Error(`Failed to parse settings file: ${e}`)}}writeSettings(e){const{settingsFile:t}=this.statePaths;this.ensureDir(y(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:I(_(),j(),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 N.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 L=new P;f(L);var T=Object.freeze({__proto__:null,Machine:P,machine:L,projectPath:j});function W(e,t,r){const s=function(e){const t=e.startsWith("file:")?A(e):e;return g(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}(e),i=(e,t,i)=>{!1!==r?.filter?.(t,e)&&z[e](`[${s}] ${t}`,...i)};return{debug:(e,...t)=>i("debug",e,t),info:(e,...t)=>i("info",e,t),warn:(e,...t)=>i("warn",e,t),error:(e,...t)=>i("error",e,t)}}function F(e){const t=X(e);return function(e){z=e}(t),t}function G(){return z}const M=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):""}`}),U=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 X(t){const r=L.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(),M),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(),U)})];return process.env.DEBUG&&o.push(new e.transports.Console({format:e.format.combine(e.format.timestamp(),M)})),e.createLogger({level:s,transports:o})}let z=X({type:"console-only"});function $(e){const t=L.getStatePaths().logsDir;return h(t,"daemon.log")}export{P as M,R as a,G as b,W as c,T as d,$ as g,F as i,z as l,L as m,j 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"),node_url=require("node:url"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null,name="@agentrix/cli",version="0.38.0",description="Mobile and Web client for Claude Code and Codex",author="agentrix.xmz.ai",type="module",homepage="https://github.com/xmz-ai/agentrix-cli",bugs="https://github.com/xmz-ai/agentrix-cli/issues",repository="xmz-ai/agentrix-cli",bin={agentrix:"./bin/agentrix.mjs"},main="./dist/index.cjs",module$1="./dist/index.mjs",types="./dist/index.d.cts",exports$1={".":{require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"},import:{types:"./dist/index.d.mts",default:"./dist/index.mjs"}},"./lib":{require:{types:"./dist/lib.d.cts",default:"./dist/lib.cjs"},import:{types:"./dist/lib.d.mts",default:"./dist/lib.mjs"}}},files=["dist","bin","scripts","package.json"],scripts={"why do we need to build before running tests / dev?":"We need the binary to be built so we run daemon commands which directly run the binary",typecheck:"tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true)",build:"shx rm -rf dist && tsc --noEmit --skipLibCheck 2>&1 | (grep -v 'node_modules/effect' | grep -v 'Symbol.dispose' || true) && pkgroll && shx mkdir -p dist/sandbox && shx cp src/sandbox/node-proxy-boot.cjs dist/sandbox/ && shx mkdir -p dist/migrations && shx cp src/worker/history/migrations/*.sql dist/migrations/ && node scripts/minify-dist.mjs",prod:"node --env-file=.env ./bin/agentrix.mjs",test:"yarn build && tsx --env-file .env.integration-test 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:"node scripts/ensure-better-sqlite3.cjs",lint:"eslint 'src/**/*.{js,ts}' --fix"},pkgroll={minify:!0,sourcemap:!1},dependencies={"@agentrix/shared":"^2.37.0","@anthropic-ai/claude-agent-sdk":"^0.2.133","@anthropic-ai/sdk":"0.71.2","@larksuiteoapi/node-sdk":"^1.63.1","@modelcontextprotocol/sdk":"^1.15.1","@openai/codex-sdk":"^0.133.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",croner:"^9.0.0","cross-spawn":"^7.0.6","expo-server-sdk":"^3.15.0",fastify:"^5.5.0","fastify-type-provider-zod":"^6.1.0","http-proxy":"^1.18.1","http-proxy-middleware":"^3.0.5",ink:"^6.1.0","ink-box":"^2.0.0","ink-select-input":"^6.0.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","node-gyp":"^10.3.1",open:"^10.2.0","ps-list":"^8.1.1","qrcode-terminal":"^0.12.0",react:"^19.1.1","simple-git":"^3.30.0","socket.io-client":"^4.8.1",tmp:"^0.2.5",tweetnacl:"^1.0.3",undici:"^7.16.0",winston:"^3.18.3","winston-daily-rotate-file":"^5.0.0",yargs:"^17.7.2",zod:"^4.0.0","zod-to-json-schema":"^3.25.1"},optionalDependencies={"node-datachannel":"0.9.1"},devDependencies={"@eslint/compat":"^1","@types/mime-types":"^3.0.1","@types/node":">=20",dotenv:"^16.6.1",eslint:"^9","eslint-config-prettier":"^10",pkgroll:"^2.14.2","release-it":"^19.0.4",shx:"^0.3.3",terser:"^5.39.0","ts-node":"^10",tsx:"^4.20.3",typescript:"^5",vitest:"^3.2.4"},resolutions={"whatwg-url":"14.2.0","parse-path":"7.0.3","@types/parse-path":"7.0.3"},overrides={"node-datachannel":"0.9.1"},publishConfig={registry:"https://registry.npmjs.org"},packageManager="yarn@1.22.22",packageJson={name:name,version:version,description:description,author:author,type:type,homepage:homepage,bugs:bugs,repository:repository,bin:bin,main:main,module:module$1,types:types,exports:exports$1,files:files,scripts:scripts,pkgroll:pkgroll,dependencies:dependencies,optionalDependencies:optionalDependencies,devDependencies:devDependencies,resolutions:resolutions,overrides:overrides,publishConfig:publishConfig,packageManager:packageManager};const SandboxSettingsSchema=zod.z.object({enabled:zod.z.boolean().default(!0),network:sandboxRuntime.NetworkConfigSchema,filesystem:sandboxRuntime.SandboxInstanceConfigSchema.shape.filesystem.optional(),env:sandboxRuntime.SandboxInstanceConfigSchema.shape.env.optional()});function getCommonConfig(e,t){const s=os.homedir();return{enabled:!1,network:{allowedDomains:"*",deniedDomains:[]},commonWritePaths:[path.join(t,"config","codex"),path.join(t,"config","claude"),path.join(t,"config","gemini"),path.join(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,AGENTRIX_API_KEY:null,CLAUDE_CONFIG_DIR:null,AGENTRIX_CLAUDE_HOME:null,AGENTRIX_CODEX_HOME:null,AGENTRIX_GEMINI_HOME:null,CODEX_HOME:null,SRT_DEBUG:null,NODE_OPTIONS:`--require ${path.join(e,"dist","sandbox","node-proxy-boot.cjs")}`}}}function getDefaultMacOSSettings(e,t){os.homedir();const 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-D-NJyt5I.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,this.claudeConfigDir=path$1.join(os$1.homedir(),".claude"),this.codexHomeDir=path$1.join(os$1.homedir(),".codex"),this.ensureDir(this.agentrixHomeDir),this.ensureDir(this.agentrixWorkspaceHomeDir),this.ensureDir(this.agentrixAgentsHomeDir),this.ensureDir(this.claudeConfigDir),this.ensureDir(this.codexHomeDir),process.env.AGENTRIX_CLAUDE_HOME=this.claudeConfigDir,process.env.CLAUDE_CONFIG_DIR=this.claudeConfigDir,process.env.AGENTRIX_CODEX_HOME=this.codexHomeDir,process.env.CODEX_HOME=this.codexHomeDir,this.statePaths={rootDir:this.agentrixHomeDir,logsDir:this.ensureDir(path$1.join(this.agentrixHomeDir,"logs")),settingsFile:path$1.join(this.agentrixHomeDir,"settings.json"),credentialsFile:path$1.join(this.agentrixHomeDir,"credentials.json"),daemonStateFile:path$1.join(this.agentrixHomeDir,"daemon.state.json"),daemonLockFile:path$1.join(this.agentrixHomeDir,"daemon.state.json.lock")},this.sandboxSettings=this.loadSandboxSettings()}generateMachineId(){return`machine-${node_crypto.randomUUID()}`}metadata(){return{host:os$1.hostname(),platform:os$1.platform(),cliVersion:this.currentCliVersion,homeDir:os$1.homedir(),agentrixHomeDir:this.agentrixHomeDir,agentrixWorkspaceHomeDir:this.agentrixWorkspaceHomeDir}}getStatePaths(){return this.statePaths}async readCredentials(){const e=this.getStatePaths();if(!fs.existsSync(e.credentialsFile))return null;try{const t=await promises.readFile(e.credentialsFile,"utf8"),s=JSON.parse(t);return{secret:s.secret,token:s.token,machineId:s.machineId,machineAesKey:"string"==typeof s.machineAesKey?s.machineAesKey:void 0}}catch{return null}}async writeCredentials(e){const t=this.getStatePaths();await promises.writeFile(t.credentialsFile,JSON.stringify(e,null,2))}async clearCredentials(){const e=this.getStatePaths();fs.existsSync(e.credentialsFile)&&await promises.unlink(e.credentialsFile)}async readDaemonState(){const e=this.getStatePaths();try{if(!fs.existsSync(e.daemonStateFile))return null;const t=await promises.readFile(e.daemonStateFile,"utf-8");return JSON.parse(t)}catch(t){return console.error(`[PERSISTENCE] Daemon state file corrupted: ${e.daemonStateFile}`,t),null}}writeDaemonState(e){const t=this.getStatePaths();fs.writeFileSync(t.daemonStateFile,JSON.stringify(e,null,2),"utf-8")}async clearDaemonState(){const e=this.getStatePaths();if(fs.existsSync(e.daemonStateFile)&&await promises.unlink(e.daemonStateFile),fs.existsSync(e.daemonLockFile))try{await promises.unlink(e.daemonLockFile)}catch{}}async acquireDaemonLock(e=5,t=200){return this.acquireFileLock(this.getStatePaths().daemonLockFile,e,t)}async releaseDaemonLock(e){return this.releaseFileLock(this.getStatePaths().daemonLockFile,e)}ensureDir(e){return fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),e}resolveUserWorkSpaceDir(e){const t=path$1.join(this.agentrixWorkspaceHomeDir,"users",e);return this.ensureDir(t)}resolveTaskDir(e,t){const 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)}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")}resolveAgentDirUnder(e,t){const s=path$1.join(t,e);return fs.existsSync(path$1.join(s,"agent.json"))?s:null}resolveAgentDir(e,t){if(t){const s=this.resolveAgentDirUnder(e,path$1.join(t,".agentrix","agents"));if(s)return s}return this.resolveAgentDirUnder(e,this.agentrixAgentsHomeDir)||path$1.join(this.agentrixAgentsHomeDir,e)}getWorkspaceStatePath(e,t){return path$1.join(this.resolveDataDir(e,t),"workspace.json")}getWorkspaceState(e,t){const 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),r=path$1.join(n,"cwd.txt");if(!fs.existsSync(r))return null;try{const e=fs.readFileSync(r,"utf-8").trim();if(!e)return null;const t={initialized:!0,initializedAt:(new Date).toISOString(),cwd:e};try{fs.writeFileSync(s,JSON.stringify(t,null,2));try{fs.unlinkSync(r)}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))}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 n=this.getLastSentArtifactVersionPath(e,t);await promises.writeFile(n,s)}async acquireFileLock(e,t=60,s=200){this.ensureDir(path.dirname(e));for(let n=1;n<=t;n++)try{const t=await promises.open(e,fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_WRONLY);return await t.writeFile(String(process.pid)),t}catch(r){if("EEXIST"===r.code)try{const t=(await promises.readFile(e,"utf-8")).trim();if(t&&!Number.isNaN(Number(t)))try{process.kill(Number(t),0)}catch{fs.unlinkSync(e);continue}}catch{}if(n===t)return null;const i=n*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),n=path$1.join(s,"input.json");if(!fs.existsSync(n))throw new Error(`Task input file does not exist: ${n}`);const r=fs.readFileSync(n,"utf-8");return JSON.parse(r)}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),r=this.resolveProjectCWD(s||void 0,e,t),i="project"===n?"":n.slice(8);return i?path$1.join(r,i):r}if("data"===n||n.startsWith("data/")){const s=this.resolveDataDir(e,t),r="data"===n?"":n.slice(5);return r?path$1.join(s,r):s}const r=this.resolveTaskDir(e,t);return path$1.join(r,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}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});function resolveModuleName(e){const t=e.startsWith("file:")?node_url.fileURLToPath(e):e;return path$1.basename(t).replace(/\.(test\.)?[cm]?[tj]sx?$/,"")}function createModuleLogger(e,t,s){const n=resolveModuleName(e),r=(e,t,r)=>{!1!==s?.filter?.(t,e)&&exports.logger[e](`[${n}] ${t}`,...r)};return{debug:(e,...t)=>r("debug",e,t),info:(e,...t)=>r("info",e,t),warn:(e,...t)=>r("warn",e,t),error:(e,...t)=>r("error",e,t)}}function setLoggerBase(e){exports.logger=e}function initializeLogger(e){const t=createLogger(e);return setLoggerBase(t),t}function getLoggerBase(){return exports.logger}const consoleFormat=winston.format.printf(({level:e,message:t,timestamp:s,...n})=>{const r=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`[${r}] ${i}: ${t}${Object.keys(n).length>0?" "+JSON.stringify(n):""}`}),fileFormat=winston.format.printf(({level:e,message:t,timestamp:s,...n})=>{const r=Object.keys(n).length>0?" "+JSON.stringify(n):"";return`[${s}] ${e.toUpperCase()}: ${t}${r}`});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`,r="daemon"===e.type?3:1,i=[new winston.transports.File({filename:n,dirname:t,zippedArchive:!0,maxsize:104857600,maxFiles:r,tailable:!0,format:winston.format.combine(winston.format.timestamp(),fileFormat)})];return process.env.DEBUG&&i.push(new winston.transports.Console({format:winston.format.combine(winston.format.timestamp(),consoleFormat)})),winston.createLogger({level:s,transports:i})}function getLogPath(e){const t=machine.getStatePaths().logsDir;return path$1.join(t,"daemon.log")}exports.logger=createLogger({type:"console-only"}),exports.Machine=Machine,exports.createModuleLogger=createModuleLogger,exports.getLogPath=getLogPath,exports.getLoggerBase=getLoggerBase,exports.initializeLogger=initializeLogger,exports.machine=machine,exports.machine$1=machine$1,exports.packageJson=packageJson,exports.projectPath=projectPath;