@agentrix/cli 0.0.8 → 0.0.9
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/index.cjs +172 -46
- package/dist/index.mjs +156 -30
- package/dist/lib.cjs +1 -1
- package/dist/lib.mjs +1 -1
- package/dist/{logger-D8V27PkS.mjs → logger-6H3e_sL6.mjs} +1 -1
- package/dist/{logger-CNLPJOjS.cjs → logger-ChBQkYk7.cjs} +24 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,16 +6,16 @@ var chalk = require('chalk');
|
|
|
6
6
|
var shared = require('@agentrix/shared');
|
|
7
7
|
var node_crypto = require('node:crypto');
|
|
8
8
|
var axios = require('axios');
|
|
9
|
-
var _package = require('./logger-
|
|
9
|
+
var _package = require('./logger-ChBQkYk7.cjs');
|
|
10
10
|
var fs$1 = require('node:fs');
|
|
11
11
|
var node_readline = require('node:readline');
|
|
12
12
|
var fs = require('fs');
|
|
13
|
-
var
|
|
13
|
+
var path = require('path');
|
|
14
14
|
var os = require('node:os');
|
|
15
15
|
var open = require('open');
|
|
16
16
|
var socket_ioClient = require('socket.io-client');
|
|
17
17
|
var node_events = require('node:events');
|
|
18
|
-
var path = require('node:path');
|
|
18
|
+
var path$1 = require('node:path');
|
|
19
19
|
var child_process = require('child_process');
|
|
20
20
|
var psList = require('ps-list');
|
|
21
21
|
var spawn = require('cross-spawn');
|
|
@@ -51,7 +51,7 @@ function _interopNamespaceDefault(e) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
54
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
54
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
55
55
|
|
|
56
56
|
async function delay(ms) {
|
|
57
57
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -144,7 +144,7 @@ async function isLatestDaemonRunning() {
|
|
|
144
144
|
return false;
|
|
145
145
|
}
|
|
146
146
|
try {
|
|
147
|
-
const packageJsonPath =
|
|
147
|
+
const packageJsonPath = path.join(_package.projectPath(), "package.json");
|
|
148
148
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
149
149
|
const currentCliVersion = packageJson.version;
|
|
150
150
|
_package.logger.debug(`[DAEMON CONTROL] Current CLI version: ${currentCliVersion}, Daemon started with version: ${state.cliVersion}`);
|
|
@@ -11432,7 +11432,7 @@ function requireMimeTypes () {
|
|
|
11432
11432
|
* MIT Licensed
|
|
11433
11433
|
*/
|
|
11434
11434
|
var db = requireMimeDb();
|
|
11435
|
-
var extname =
|
|
11435
|
+
var extname = path.extname;
|
|
11436
11436
|
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
|
|
11437
11437
|
var TEXT_TYPE_REGEXP = /^text\//i;
|
|
11438
11438
|
exports$1.charset = charset;
|
|
@@ -11866,6 +11866,8 @@ async function findAllAgentrixProcesses() {
|
|
|
11866
11866
|
let type = "unknown";
|
|
11867
11867
|
if (cmd.includes(" worker")) {
|
|
11868
11868
|
type = "worker";
|
|
11869
|
+
} else if (cmd.includes(" upgrade-daemon")) {
|
|
11870
|
+
type = "upgrade-daemon";
|
|
11869
11871
|
} else if (cmd.includes(" daemon")) {
|
|
11870
11872
|
type = "daemon";
|
|
11871
11873
|
} else if (cmd.includes("doctor")) {
|
|
@@ -11953,8 +11955,8 @@ async function runDoctorCommand(filter) {
|
|
|
11953
11955
|
console.log("");
|
|
11954
11956
|
console.log(chalk.bold("\u{1F527} Daemon Spawn Diagnostics"));
|
|
11955
11957
|
const projectRoot = _package.projectPath();
|
|
11956
|
-
const wrapperPath = path.join(projectRoot, "bin", "agentrix.mjs");
|
|
11957
|
-
const cliEntrypoint = path.join(projectRoot, "dist", "index.mjs");
|
|
11958
|
+
const wrapperPath = path$1.join(projectRoot, "bin", "agentrix.mjs");
|
|
11959
|
+
const cliEntrypoint = path$1.join(projectRoot, "dist", "index.mjs");
|
|
11958
11960
|
console.log(`Project Root: ${chalk.blue(projectRoot)}`);
|
|
11959
11961
|
console.log(`Wrapper Script: ${chalk.blue(wrapperPath)}`);
|
|
11960
11962
|
console.log(`CLI Entrypoint: ${chalk.blue(cliEntrypoint)}`);
|
|
@@ -12018,6 +12020,7 @@ async function runDoctorCommand(filter) {
|
|
|
12018
12020
|
Object.entries(grouped).forEach(([type, processes]) => {
|
|
12019
12021
|
const typeLabels = {
|
|
12020
12022
|
"daemon": "\u{1F916} Daemon",
|
|
12023
|
+
"upgrade-daemon": "\u{1F504} Upgrade Daemon",
|
|
12021
12024
|
"worker": "\u{1F517} Workers",
|
|
12022
12025
|
"doctor": "\u{1FA7A} Doctor",
|
|
12023
12026
|
"unknown": "\u2753 Unknown"
|
|
@@ -12150,7 +12153,7 @@ function startDaemonControlServer({
|
|
|
12150
12153
|
|
|
12151
12154
|
function spawnAgentrixCLI(args, options = {}) {
|
|
12152
12155
|
const projectRoot = _package.projectPath();
|
|
12153
|
-
const entrypoint = path.join(projectRoot, "dist", "index.mjs");
|
|
12156
|
+
const entrypoint = path$1.join(projectRoot, "dist", "index.mjs");
|
|
12154
12157
|
const nodeArgs = ["--no-warnings", "--no-deprecation", entrypoint, ...args];
|
|
12155
12158
|
if (!fs$1.existsSync(entrypoint)) {
|
|
12156
12159
|
const errorMessage = `Entrypoint ${entrypoint} does not exist`;
|
|
@@ -12481,15 +12484,15 @@ const VALID_HOOK_NAMES = [
|
|
|
12481
12484
|
"RepositoryInit"
|
|
12482
12485
|
];
|
|
12483
12486
|
async function loadHooks(claudeDir) {
|
|
12484
|
-
const hooksDir =
|
|
12487
|
+
const hooksDir = path.join(claudeDir, "hooks");
|
|
12485
12488
|
if (!fs.existsSync(hooksDir)) {
|
|
12486
12489
|
return {};
|
|
12487
12490
|
}
|
|
12488
12491
|
const entryPoints = [
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12492
|
+
path.join(hooksDir, "dist", "index.mjs"),
|
|
12493
|
+
path.join(hooksDir, "dist", "index.js"),
|
|
12494
|
+
path.join(hooksDir, "index.mjs"),
|
|
12495
|
+
path.join(hooksDir, "index.js")
|
|
12493
12496
|
];
|
|
12494
12497
|
let hooksEntry = null;
|
|
12495
12498
|
for (const entry of entryPoints) {
|
|
@@ -12504,7 +12507,7 @@ async function loadHooks(claudeDir) {
|
|
|
12504
12507
|
console.warn(`[Hook Loader] cd ${hooksDir}`);
|
|
12505
12508
|
console.warn("[Hook Loader] npm install && npm run build");
|
|
12506
12509
|
console.warn("[Hook Loader] Or place hooks directly in:");
|
|
12507
|
-
console.warn(`[Hook Loader] ${
|
|
12510
|
+
console.warn(`[Hook Loader] ${path.join(hooksDir, "index.js")} or ${path.join(hooksDir, "index.mjs")}`);
|
|
12508
12511
|
return {};
|
|
12509
12512
|
}
|
|
12510
12513
|
try {
|
|
@@ -12820,7 +12823,7 @@ async function initialCommit(dir) {
|
|
|
12820
12823
|
await git.commit("Initial commit", { "--allow-empty": null });
|
|
12821
12824
|
}
|
|
12822
12825
|
async function gitClone(gitUrl, targetDir) {
|
|
12823
|
-
const parentDir = path.dirname(targetDir);
|
|
12826
|
+
const parentDir = path$1.dirname(targetDir);
|
|
12824
12827
|
if (!fs$1.existsSync(parentDir)) {
|
|
12825
12828
|
fs$1.mkdirSync(parentDir, { recursive: true });
|
|
12826
12829
|
}
|
|
@@ -13011,7 +13014,7 @@ async function generateAndSavePatch(workingDirectory, fromCommit, toCommit, data
|
|
|
13011
13014
|
if (!patch.trim()) {
|
|
13012
13015
|
return void 0;
|
|
13013
13016
|
}
|
|
13014
|
-
const patchPath = path.join(dataDir, "patch.diff");
|
|
13017
|
+
const patchPath = path$1.join(dataDir, "patch.diff");
|
|
13015
13018
|
await promises.writeFile(patchPath, patch);
|
|
13016
13019
|
return patchPath;
|
|
13017
13020
|
}
|
|
@@ -14046,7 +14049,7 @@ URL: ${result.pullRequestUrl}`
|
|
|
14046
14049
|
try {
|
|
14047
14050
|
const agentContext = shared.getAgentContext();
|
|
14048
14051
|
const agentDir = agentContext.resolveAgentDir(this.options.input.agentId);
|
|
14049
|
-
const claudeDir =
|
|
14052
|
+
const claudeDir = path.join(agentDir, ".claude");
|
|
14050
14053
|
const hooks = await loadHooks(claudeDir);
|
|
14051
14054
|
this.loadedHooks = hooks;
|
|
14052
14055
|
return hooks;
|
|
@@ -15762,9 +15765,9 @@ CRITICAL: Respond with ONLY the JSON object, no additional text before or after.
|
|
|
15762
15765
|
async function downloadImage(url, targetDir) {
|
|
15763
15766
|
try {
|
|
15764
15767
|
const urlPath = new URL(url).pathname;
|
|
15765
|
-
const extension = path.extname(urlPath) || ".jpg";
|
|
15768
|
+
const extension = path$1.extname(urlPath) || ".jpg";
|
|
15766
15769
|
const filename = `${node_crypto.randomUUID()}${extension}`;
|
|
15767
|
-
const filePath = path.join(targetDir, filename);
|
|
15770
|
+
const filePath = path$1.join(targetDir, filename);
|
|
15768
15771
|
const response = await fetch(url);
|
|
15769
15772
|
if (!response.ok) {
|
|
15770
15773
|
throw new Error(`Failed to download image: ${response.status} ${response.statusText}`);
|
|
@@ -16683,6 +16686,126 @@ async function performAutoUpgrade(upgradeCheck) {
|
|
|
16683
16686
|
}
|
|
16684
16687
|
}
|
|
16685
16688
|
|
|
16689
|
+
const UPGRADE_CHECK_INTERVAL = 6 * 60 * 60 * 1e3;
|
|
16690
|
+
function getUpgradeDaemonStatePath() {
|
|
16691
|
+
const statePaths = _package.machine.getStatePaths();
|
|
16692
|
+
return path.join(path.dirname(statePaths.daemonStateFile), "upgrade-daemon.state.json");
|
|
16693
|
+
}
|
|
16694
|
+
function readUpgradeDaemonState() {
|
|
16695
|
+
try {
|
|
16696
|
+
const statePath = getUpgradeDaemonStatePath();
|
|
16697
|
+
if (!fs.existsSync(statePath)) {
|
|
16698
|
+
return null;
|
|
16699
|
+
}
|
|
16700
|
+
const content = fs.readFileSync(statePath, "utf-8");
|
|
16701
|
+
return JSON.parse(content);
|
|
16702
|
+
} catch {
|
|
16703
|
+
return null;
|
|
16704
|
+
}
|
|
16705
|
+
}
|
|
16706
|
+
function writeUpgradeDaemonState(state) {
|
|
16707
|
+
const statePath = getUpgradeDaemonStatePath();
|
|
16708
|
+
fs.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
16709
|
+
}
|
|
16710
|
+
function deleteUpgradeDaemonState() {
|
|
16711
|
+
try {
|
|
16712
|
+
const statePath = getUpgradeDaemonStatePath();
|
|
16713
|
+
if (fs.existsSync(statePath)) {
|
|
16714
|
+
fs.unlinkSync(statePath);
|
|
16715
|
+
}
|
|
16716
|
+
} catch {
|
|
16717
|
+
}
|
|
16718
|
+
}
|
|
16719
|
+
function isProcessRunning(pid) {
|
|
16720
|
+
try {
|
|
16721
|
+
process.kill(pid, 0);
|
|
16722
|
+
return true;
|
|
16723
|
+
} catch {
|
|
16724
|
+
return false;
|
|
16725
|
+
}
|
|
16726
|
+
}
|
|
16727
|
+
function isUpgradeDaemonRunning() {
|
|
16728
|
+
const state = readUpgradeDaemonState();
|
|
16729
|
+
if (!state) {
|
|
16730
|
+
return false;
|
|
16731
|
+
}
|
|
16732
|
+
if (!isProcessRunning(state.pid)) {
|
|
16733
|
+
deleteUpgradeDaemonState();
|
|
16734
|
+
return false;
|
|
16735
|
+
}
|
|
16736
|
+
return true;
|
|
16737
|
+
}
|
|
16738
|
+
function stopUpgradeDaemon() {
|
|
16739
|
+
const state = readUpgradeDaemonState();
|
|
16740
|
+
if (!state) {
|
|
16741
|
+
return;
|
|
16742
|
+
}
|
|
16743
|
+
try {
|
|
16744
|
+
if (isProcessRunning(state.pid)) {
|
|
16745
|
+
process.kill(state.pid, "SIGTERM");
|
|
16746
|
+
}
|
|
16747
|
+
} catch {
|
|
16748
|
+
} finally {
|
|
16749
|
+
deleteUpgradeDaemonState();
|
|
16750
|
+
}
|
|
16751
|
+
}
|
|
16752
|
+
async function checkAndUpgrade() {
|
|
16753
|
+
if (isAutoUpgradeDisabled()) {
|
|
16754
|
+
return false;
|
|
16755
|
+
}
|
|
16756
|
+
const upgradeResult = await checkForUpgrades();
|
|
16757
|
+
if (upgradeResult.hasUpgrade) {
|
|
16758
|
+
const upgraded = await performAutoUpgrade(upgradeResult);
|
|
16759
|
+
if (upgraded) {
|
|
16760
|
+
await stopDaemon();
|
|
16761
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
16762
|
+
const daemonProcess = spawnAgentrixCLI(["daemon"], {
|
|
16763
|
+
detached: true,
|
|
16764
|
+
stdio: "ignore",
|
|
16765
|
+
env: process.env
|
|
16766
|
+
});
|
|
16767
|
+
daemonProcess.unref();
|
|
16768
|
+
return true;
|
|
16769
|
+
}
|
|
16770
|
+
}
|
|
16771
|
+
return false;
|
|
16772
|
+
}
|
|
16773
|
+
async function runUpgradeDaemonLoop() {
|
|
16774
|
+
writeUpgradeDaemonState({
|
|
16775
|
+
pid: process.pid,
|
|
16776
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
16777
|
+
});
|
|
16778
|
+
process.on("SIGTERM", () => {
|
|
16779
|
+
deleteUpgradeDaemonState();
|
|
16780
|
+
process.exit(0);
|
|
16781
|
+
});
|
|
16782
|
+
process.on("SIGINT", () => {
|
|
16783
|
+
deleteUpgradeDaemonState();
|
|
16784
|
+
process.exit(0);
|
|
16785
|
+
});
|
|
16786
|
+
try {
|
|
16787
|
+
await checkAndUpgrade();
|
|
16788
|
+
} catch (error) {
|
|
16789
|
+
}
|
|
16790
|
+
while (true) {
|
|
16791
|
+
await new Promise((resolve) => setTimeout(resolve, UPGRADE_CHECK_INTERVAL));
|
|
16792
|
+
try {
|
|
16793
|
+
await checkAndUpgrade();
|
|
16794
|
+
} catch (error) {
|
|
16795
|
+
}
|
|
16796
|
+
}
|
|
16797
|
+
}
|
|
16798
|
+
async function startUpgradeDaemon() {
|
|
16799
|
+
await runUpgradeDaemonLoop();
|
|
16800
|
+
}
|
|
16801
|
+
|
|
16802
|
+
var upgradeDaemon = /*#__PURE__*/Object.freeze({
|
|
16803
|
+
__proto__: null,
|
|
16804
|
+
isUpgradeDaemonRunning: isUpgradeDaemonRunning,
|
|
16805
|
+
startUpgradeDaemon: startUpgradeDaemon,
|
|
16806
|
+
stopUpgradeDaemon: stopUpgradeDaemon
|
|
16807
|
+
});
|
|
16808
|
+
|
|
16686
16809
|
const cli = yargs(helpers.hideBin(process.argv)).scriptName("agentrix").version(_package.packageJson.version).usage("$0 <command> [options]").option("debug", {
|
|
16687
16810
|
alias: "d",
|
|
16688
16811
|
type: "boolean",
|
|
@@ -16722,7 +16845,7 @@ cli.command("upgrade", "Upgrade CLI to the latest version", {}, async (argv) =>
|
|
|
16722
16845
|
}
|
|
16723
16846
|
}
|
|
16724
16847
|
try {
|
|
16725
|
-
const { version } = await Promise.resolve().then(function () { return require('./logger-
|
|
16848
|
+
const { version } = await Promise.resolve().then(function () { return require('./logger-ChBQkYk7.cjs'); }).then(function (n) { return n._package; });
|
|
16726
16849
|
console.log(chalk.green(`
|
|
16727
16850
|
\u2713 Now running version: ${version}`));
|
|
16728
16851
|
} catch {
|
|
@@ -16747,6 +16870,7 @@ cli.command("logout", "Logout from Agentrix", {}, async (argv) => {
|
|
|
16747
16870
|
process.exit(0);
|
|
16748
16871
|
});
|
|
16749
16872
|
cli.command("stop", "Stop the daemon", {}, async (argv) => {
|
|
16873
|
+
stopUpgradeDaemon();
|
|
16750
16874
|
await stopDaemon();
|
|
16751
16875
|
process.exit(0);
|
|
16752
16876
|
});
|
|
@@ -16867,6 +16991,17 @@ cli.command(
|
|
|
16867
16991
|
}
|
|
16868
16992
|
}
|
|
16869
16993
|
);
|
|
16994
|
+
cli.command(
|
|
16995
|
+
"upgrade-daemon",
|
|
16996
|
+
false,
|
|
16997
|
+
// Hidden command
|
|
16998
|
+
{},
|
|
16999
|
+
async (argv) => {
|
|
17000
|
+
const { startUpgradeDaemon } = await Promise.resolve().then(function () { return upgradeDaemon; });
|
|
17001
|
+
await startUpgradeDaemon();
|
|
17002
|
+
process.exit(0);
|
|
17003
|
+
}
|
|
17004
|
+
);
|
|
16870
17005
|
cli.command(
|
|
16871
17006
|
"start",
|
|
16872
17007
|
"Start daemon (if not running) and show status",
|
|
@@ -16881,31 +17016,6 @@ cli.command(
|
|
|
16881
17016
|
}
|
|
16882
17017
|
process.exit(1);
|
|
16883
17018
|
}
|
|
16884
|
-
const skipUpgradeCheck = process.env.AGENTRIX_SKIP_UPGRADE_CHECK === "true";
|
|
16885
|
-
const autoUpgradeDisabled = isAutoUpgradeDisabled();
|
|
16886
|
-
let upgradeResult = {
|
|
16887
|
-
hasUpgrade: false,
|
|
16888
|
-
currentVersion: "",
|
|
16889
|
-
latestVersion: null
|
|
16890
|
-
};
|
|
16891
|
-
if (!skipUpgradeCheck) {
|
|
16892
|
-
upgradeResult = await checkForUpgrades();
|
|
16893
|
-
}
|
|
16894
|
-
if (upgradeResult.hasUpgrade) {
|
|
16895
|
-
if (autoUpgradeDisabled) {
|
|
16896
|
-
displayUpgradeNotification(upgradeResult);
|
|
16897
|
-
} else {
|
|
16898
|
-
console.log(chalk.blue("\u{1F504} Starting upgrade in background..."));
|
|
16899
|
-
console.log(chalk.dim(` Upgrading from ${upgradeResult.currentVersion} to ${upgradeResult.latestVersion}`));
|
|
16900
|
-
console.log("");
|
|
16901
|
-
const upgradeProcess = spawnAgentrixCLI(["upgrade"], {
|
|
16902
|
-
detached: true,
|
|
16903
|
-
stdio: "ignore",
|
|
16904
|
-
env: process.env
|
|
16905
|
-
});
|
|
16906
|
-
upgradeProcess.unref();
|
|
16907
|
-
}
|
|
16908
|
-
}
|
|
16909
17019
|
const wasRunning = await isLatestDaemonRunning();
|
|
16910
17020
|
if (!wasRunning) {
|
|
16911
17021
|
console.log("Starting Agentrix background service...");
|
|
@@ -16929,6 +17039,22 @@ cli.command(
|
|
|
16929
17039
|
console.log(chalk.yellow("\u26A0\uFE0F Daemon may still be starting..."));
|
|
16930
17040
|
}
|
|
16931
17041
|
}
|
|
17042
|
+
const autoUpgradeDisabled = isAutoUpgradeDisabled();
|
|
17043
|
+
if (!autoUpgradeDisabled) {
|
|
17044
|
+
if (!isUpgradeDaemonRunning()) {
|
|
17045
|
+
const upgradeDaemonProcess = spawnAgentrixCLI(["upgrade-daemon"], {
|
|
17046
|
+
detached: true,
|
|
17047
|
+
stdio: "ignore",
|
|
17048
|
+
env: process.env
|
|
17049
|
+
});
|
|
17050
|
+
upgradeDaemonProcess.unref();
|
|
17051
|
+
}
|
|
17052
|
+
} else {
|
|
17053
|
+
const upgradeResult = await checkForUpgrades();
|
|
17054
|
+
if (upgradeResult.hasUpgrade) {
|
|
17055
|
+
displayUpgradeNotification(upgradeResult);
|
|
17056
|
+
}
|
|
17057
|
+
}
|
|
16932
17058
|
await runDoctorCommand("daemon");
|
|
16933
17059
|
process.exit(0);
|
|
16934
17060
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -4,12 +4,12 @@ import chalk from 'chalk';
|
|
|
4
4
|
import { encodeBase64, createKeyPairWithUit8Array, encryptMachineEncryptionKey, generateAESKey, decodeBase64, decryptWithEphemeralKey, createEventId, encryptFileContent, machineAuth, encryptSdkMessage, decryptSdkMessage, loadAgentConfig, getAgentContext, workerAuth } from '@agentrix/shared';
|
|
5
5
|
import { randomBytes, randomUUID as randomUUID$1 } from 'node:crypto';
|
|
6
6
|
import axios from 'axios';
|
|
7
|
-
import { m as machine, l as logger, p as projectPath, a as packageJson, c as createLogger, g as getLogPath, b as logger$1 } from './logger-
|
|
7
|
+
import { m as machine, l as logger, p as projectPath, a as packageJson, c as createLogger, g as getLogPath, b as logger$1 } from './logger-6H3e_sL6.mjs';
|
|
8
8
|
import * as fs from 'node:fs';
|
|
9
9
|
import { existsSync, rmSync, mkdirSync, readdirSync, createWriteStream } from 'node:fs';
|
|
10
10
|
import { createInterface } from 'node:readline';
|
|
11
|
-
import { readFileSync, existsSync as existsSync$1 } from 'fs';
|
|
12
|
-
import
|
|
11
|
+
import fs$1, { readFileSync, existsSync as existsSync$1 } from 'fs';
|
|
12
|
+
import path$1, { join } from 'path';
|
|
13
13
|
import os from 'node:os';
|
|
14
14
|
import open from 'open';
|
|
15
15
|
import { io } from 'socket.io-client';
|
|
@@ -11412,7 +11412,7 @@ function requireMimeTypes () {
|
|
|
11412
11412
|
* MIT Licensed
|
|
11413
11413
|
*/
|
|
11414
11414
|
var db = requireMimeDb();
|
|
11415
|
-
var extname =
|
|
11415
|
+
var extname = path$1.extname;
|
|
11416
11416
|
var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
|
|
11417
11417
|
var TEXT_TYPE_REGEXP = /^text\//i;
|
|
11418
11418
|
exports$1.charset = charset;
|
|
@@ -11846,6 +11846,8 @@ async function findAllAgentrixProcesses() {
|
|
|
11846
11846
|
let type = "unknown";
|
|
11847
11847
|
if (cmd.includes(" worker")) {
|
|
11848
11848
|
type = "worker";
|
|
11849
|
+
} else if (cmd.includes(" upgrade-daemon")) {
|
|
11850
|
+
type = "upgrade-daemon";
|
|
11849
11851
|
} else if (cmd.includes(" daemon")) {
|
|
11850
11852
|
type = "daemon";
|
|
11851
11853
|
} else if (cmd.includes("doctor")) {
|
|
@@ -11998,6 +12000,7 @@ async function runDoctorCommand(filter) {
|
|
|
11998
12000
|
Object.entries(grouped).forEach(([type, processes]) => {
|
|
11999
12001
|
const typeLabels = {
|
|
12000
12002
|
"daemon": "\u{1F916} Daemon",
|
|
12003
|
+
"upgrade-daemon": "\u{1F504} Upgrade Daemon",
|
|
12001
12004
|
"worker": "\u{1F517} Workers",
|
|
12002
12005
|
"doctor": "\u{1FA7A} Doctor",
|
|
12003
12006
|
"unknown": "\u2753 Unknown"
|
|
@@ -16663,6 +16666,126 @@ async function performAutoUpgrade(upgradeCheck) {
|
|
|
16663
16666
|
}
|
|
16664
16667
|
}
|
|
16665
16668
|
|
|
16669
|
+
const UPGRADE_CHECK_INTERVAL = 6 * 60 * 60 * 1e3;
|
|
16670
|
+
function getUpgradeDaemonStatePath() {
|
|
16671
|
+
const statePaths = machine.getStatePaths();
|
|
16672
|
+
return path$1.join(path$1.dirname(statePaths.daemonStateFile), "upgrade-daemon.state.json");
|
|
16673
|
+
}
|
|
16674
|
+
function readUpgradeDaemonState() {
|
|
16675
|
+
try {
|
|
16676
|
+
const statePath = getUpgradeDaemonStatePath();
|
|
16677
|
+
if (!fs$1.existsSync(statePath)) {
|
|
16678
|
+
return null;
|
|
16679
|
+
}
|
|
16680
|
+
const content = fs$1.readFileSync(statePath, "utf-8");
|
|
16681
|
+
return JSON.parse(content);
|
|
16682
|
+
} catch {
|
|
16683
|
+
return null;
|
|
16684
|
+
}
|
|
16685
|
+
}
|
|
16686
|
+
function writeUpgradeDaemonState(state) {
|
|
16687
|
+
const statePath = getUpgradeDaemonStatePath();
|
|
16688
|
+
fs$1.writeFileSync(statePath, JSON.stringify(state, null, 2));
|
|
16689
|
+
}
|
|
16690
|
+
function deleteUpgradeDaemonState() {
|
|
16691
|
+
try {
|
|
16692
|
+
const statePath = getUpgradeDaemonStatePath();
|
|
16693
|
+
if (fs$1.existsSync(statePath)) {
|
|
16694
|
+
fs$1.unlinkSync(statePath);
|
|
16695
|
+
}
|
|
16696
|
+
} catch {
|
|
16697
|
+
}
|
|
16698
|
+
}
|
|
16699
|
+
function isProcessRunning(pid) {
|
|
16700
|
+
try {
|
|
16701
|
+
process.kill(pid, 0);
|
|
16702
|
+
return true;
|
|
16703
|
+
} catch {
|
|
16704
|
+
return false;
|
|
16705
|
+
}
|
|
16706
|
+
}
|
|
16707
|
+
function isUpgradeDaemonRunning() {
|
|
16708
|
+
const state = readUpgradeDaemonState();
|
|
16709
|
+
if (!state) {
|
|
16710
|
+
return false;
|
|
16711
|
+
}
|
|
16712
|
+
if (!isProcessRunning(state.pid)) {
|
|
16713
|
+
deleteUpgradeDaemonState();
|
|
16714
|
+
return false;
|
|
16715
|
+
}
|
|
16716
|
+
return true;
|
|
16717
|
+
}
|
|
16718
|
+
function stopUpgradeDaemon() {
|
|
16719
|
+
const state = readUpgradeDaemonState();
|
|
16720
|
+
if (!state) {
|
|
16721
|
+
return;
|
|
16722
|
+
}
|
|
16723
|
+
try {
|
|
16724
|
+
if (isProcessRunning(state.pid)) {
|
|
16725
|
+
process.kill(state.pid, "SIGTERM");
|
|
16726
|
+
}
|
|
16727
|
+
} catch {
|
|
16728
|
+
} finally {
|
|
16729
|
+
deleteUpgradeDaemonState();
|
|
16730
|
+
}
|
|
16731
|
+
}
|
|
16732
|
+
async function checkAndUpgrade() {
|
|
16733
|
+
if (isAutoUpgradeDisabled()) {
|
|
16734
|
+
return false;
|
|
16735
|
+
}
|
|
16736
|
+
const upgradeResult = await checkForUpgrades();
|
|
16737
|
+
if (upgradeResult.hasUpgrade) {
|
|
16738
|
+
const upgraded = await performAutoUpgrade(upgradeResult);
|
|
16739
|
+
if (upgraded) {
|
|
16740
|
+
await stopDaemon();
|
|
16741
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
16742
|
+
const daemonProcess = spawnAgentrixCLI(["daemon"], {
|
|
16743
|
+
detached: true,
|
|
16744
|
+
stdio: "ignore",
|
|
16745
|
+
env: process.env
|
|
16746
|
+
});
|
|
16747
|
+
daemonProcess.unref();
|
|
16748
|
+
return true;
|
|
16749
|
+
}
|
|
16750
|
+
}
|
|
16751
|
+
return false;
|
|
16752
|
+
}
|
|
16753
|
+
async function runUpgradeDaemonLoop() {
|
|
16754
|
+
writeUpgradeDaemonState({
|
|
16755
|
+
pid: process.pid,
|
|
16756
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
16757
|
+
});
|
|
16758
|
+
process.on("SIGTERM", () => {
|
|
16759
|
+
deleteUpgradeDaemonState();
|
|
16760
|
+
process.exit(0);
|
|
16761
|
+
});
|
|
16762
|
+
process.on("SIGINT", () => {
|
|
16763
|
+
deleteUpgradeDaemonState();
|
|
16764
|
+
process.exit(0);
|
|
16765
|
+
});
|
|
16766
|
+
try {
|
|
16767
|
+
await checkAndUpgrade();
|
|
16768
|
+
} catch (error) {
|
|
16769
|
+
}
|
|
16770
|
+
while (true) {
|
|
16771
|
+
await new Promise((resolve) => setTimeout(resolve, UPGRADE_CHECK_INTERVAL));
|
|
16772
|
+
try {
|
|
16773
|
+
await checkAndUpgrade();
|
|
16774
|
+
} catch (error) {
|
|
16775
|
+
}
|
|
16776
|
+
}
|
|
16777
|
+
}
|
|
16778
|
+
async function startUpgradeDaemon() {
|
|
16779
|
+
await runUpgradeDaemonLoop();
|
|
16780
|
+
}
|
|
16781
|
+
|
|
16782
|
+
var upgradeDaemon = /*#__PURE__*/Object.freeze({
|
|
16783
|
+
__proto__: null,
|
|
16784
|
+
isUpgradeDaemonRunning: isUpgradeDaemonRunning,
|
|
16785
|
+
startUpgradeDaemon: startUpgradeDaemon,
|
|
16786
|
+
stopUpgradeDaemon: stopUpgradeDaemon
|
|
16787
|
+
});
|
|
16788
|
+
|
|
16666
16789
|
const cli = yargs(hideBin(process.argv)).scriptName("agentrix").version(packageJson.version).usage("$0 <command> [options]").option("debug", {
|
|
16667
16790
|
alias: "d",
|
|
16668
16791
|
type: "boolean",
|
|
@@ -16702,7 +16825,7 @@ cli.command("upgrade", "Upgrade CLI to the latest version", {}, async (argv) =>
|
|
|
16702
16825
|
}
|
|
16703
16826
|
}
|
|
16704
16827
|
try {
|
|
16705
|
-
const { version } = await import('./logger-
|
|
16828
|
+
const { version } = await import('./logger-6H3e_sL6.mjs').then(function (n) { return n._; });
|
|
16706
16829
|
console.log(chalk.green(`
|
|
16707
16830
|
\u2713 Now running version: ${version}`));
|
|
16708
16831
|
} catch {
|
|
@@ -16727,6 +16850,7 @@ cli.command("logout", "Logout from Agentrix", {}, async (argv) => {
|
|
|
16727
16850
|
process.exit(0);
|
|
16728
16851
|
});
|
|
16729
16852
|
cli.command("stop", "Stop the daemon", {}, async (argv) => {
|
|
16853
|
+
stopUpgradeDaemon();
|
|
16730
16854
|
await stopDaemon();
|
|
16731
16855
|
process.exit(0);
|
|
16732
16856
|
});
|
|
@@ -16847,6 +16971,17 @@ cli.command(
|
|
|
16847
16971
|
}
|
|
16848
16972
|
}
|
|
16849
16973
|
);
|
|
16974
|
+
cli.command(
|
|
16975
|
+
"upgrade-daemon",
|
|
16976
|
+
false,
|
|
16977
|
+
// Hidden command
|
|
16978
|
+
{},
|
|
16979
|
+
async (argv) => {
|
|
16980
|
+
const { startUpgradeDaemon } = await Promise.resolve().then(function () { return upgradeDaemon; });
|
|
16981
|
+
await startUpgradeDaemon();
|
|
16982
|
+
process.exit(0);
|
|
16983
|
+
}
|
|
16984
|
+
);
|
|
16850
16985
|
cli.command(
|
|
16851
16986
|
"start",
|
|
16852
16987
|
"Start daemon (if not running) and show status",
|
|
@@ -16861,31 +16996,6 @@ cli.command(
|
|
|
16861
16996
|
}
|
|
16862
16997
|
process.exit(1);
|
|
16863
16998
|
}
|
|
16864
|
-
const skipUpgradeCheck = process.env.AGENTRIX_SKIP_UPGRADE_CHECK === "true";
|
|
16865
|
-
const autoUpgradeDisabled = isAutoUpgradeDisabled();
|
|
16866
|
-
let upgradeResult = {
|
|
16867
|
-
hasUpgrade: false,
|
|
16868
|
-
currentVersion: "",
|
|
16869
|
-
latestVersion: null
|
|
16870
|
-
};
|
|
16871
|
-
if (!skipUpgradeCheck) {
|
|
16872
|
-
upgradeResult = await checkForUpgrades();
|
|
16873
|
-
}
|
|
16874
|
-
if (upgradeResult.hasUpgrade) {
|
|
16875
|
-
if (autoUpgradeDisabled) {
|
|
16876
|
-
displayUpgradeNotification(upgradeResult);
|
|
16877
|
-
} else {
|
|
16878
|
-
console.log(chalk.blue("\u{1F504} Starting upgrade in background..."));
|
|
16879
|
-
console.log(chalk.dim(` Upgrading from ${upgradeResult.currentVersion} to ${upgradeResult.latestVersion}`));
|
|
16880
|
-
console.log("");
|
|
16881
|
-
const upgradeProcess = spawnAgentrixCLI(["upgrade"], {
|
|
16882
|
-
detached: true,
|
|
16883
|
-
stdio: "ignore",
|
|
16884
|
-
env: process.env
|
|
16885
|
-
});
|
|
16886
|
-
upgradeProcess.unref();
|
|
16887
|
-
}
|
|
16888
|
-
}
|
|
16889
16999
|
const wasRunning = await isLatestDaemonRunning();
|
|
16890
17000
|
if (!wasRunning) {
|
|
16891
17001
|
console.log("Starting Agentrix background service...");
|
|
@@ -16909,6 +17019,22 @@ cli.command(
|
|
|
16909
17019
|
console.log(chalk.yellow("\u26A0\uFE0F Daemon may still be starting..."));
|
|
16910
17020
|
}
|
|
16911
17021
|
}
|
|
17022
|
+
const autoUpgradeDisabled = isAutoUpgradeDisabled();
|
|
17023
|
+
if (!autoUpgradeDisabled) {
|
|
17024
|
+
if (!isUpgradeDaemonRunning()) {
|
|
17025
|
+
const upgradeDaemonProcess = spawnAgentrixCLI(["upgrade-daemon"], {
|
|
17026
|
+
detached: true,
|
|
17027
|
+
stdio: "ignore",
|
|
17028
|
+
env: process.env
|
|
17029
|
+
});
|
|
17030
|
+
upgradeDaemonProcess.unref();
|
|
17031
|
+
}
|
|
17032
|
+
} else {
|
|
17033
|
+
const upgradeResult = await checkForUpgrades();
|
|
17034
|
+
if (upgradeResult.hasUpgrade) {
|
|
17035
|
+
displayUpgradeNotification(upgradeResult);
|
|
17036
|
+
}
|
|
17037
|
+
}
|
|
16912
17038
|
await runDoctorCommand("daemon");
|
|
16913
17039
|
process.exit(0);
|
|
16914
17040
|
}
|
package/dist/lib.cjs
CHANGED
package/dist/lib.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { dirname, resolve } from 'path';
|
|
|
10
10
|
import { fileURLToPath } from 'url';
|
|
11
11
|
|
|
12
12
|
var name = "@agentrix/cli";
|
|
13
|
-
var version = "0.0.
|
|
13
|
+
var version = "0.0.9";
|
|
14
14
|
var description = "Mobile and Web client for Claude Code and Codex";
|
|
15
15
|
var author = "agentrix.xmz.ai";
|
|
16
16
|
var type = "module";
|
|
@@ -6,14 +6,14 @@ var os = require('node:os');
|
|
|
6
6
|
var node_crypto = require('node:crypto');
|
|
7
7
|
var fs = require('node:fs');
|
|
8
8
|
var promises = require('node:fs/promises');
|
|
9
|
-
var path = require('node:path');
|
|
9
|
+
var path$1 = require('node:path');
|
|
10
10
|
var shared = require('@agentrix/shared');
|
|
11
|
-
var
|
|
11
|
+
var path = require('path');
|
|
12
12
|
var url = require('url');
|
|
13
13
|
|
|
14
14
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
15
15
|
var name = "@agentrix/cli";
|
|
16
|
-
var version = "0.0.
|
|
16
|
+
var version = "0.0.9";
|
|
17
17
|
var description = "Mobile and Web client for Claude Code and Codex";
|
|
18
18
|
var author = "agentrix.xmz.ai";
|
|
19
19
|
var type = "module";
|
|
@@ -185,10 +185,10 @@ var _package = /*#__PURE__*/Object.freeze({
|
|
|
185
185
|
version: version
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
-
const __dirname$1 =
|
|
188
|
+
const __dirname$1 = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('logger-ChBQkYk7.cjs', document.baseURI).href))));
|
|
189
189
|
function projectPath() {
|
|
190
|
-
const path =
|
|
191
|
-
return path;
|
|
190
|
+
const path$1 = path.resolve(__dirname$1, "..");
|
|
191
|
+
return path$1;
|
|
192
192
|
}
|
|
193
193
|
class Machine {
|
|
194
194
|
serverUrl;
|
|
@@ -206,9 +206,9 @@ class Machine {
|
|
|
206
206
|
this.isDaemonProcess = args[0] === "daemon";
|
|
207
207
|
this.serverUrl = process.env.AGENTRIX_SERVER_URL || "https://agentrix.xmz.ai";
|
|
208
208
|
this.webappUrl = process.env.AGENTRIX_WEBAPP_URL || "https://agentrix.xmz.ai";
|
|
209
|
-
this.agentrixHomeDir = process.env.AGENTRIX_HOME_DIR ? process.env.AGENTRIX_HOME_DIR.replace(/^~/, os.homedir()) : path.join(os.homedir(), ".agentrix");
|
|
210
|
-
this.agentrixWorkspaceHomeDir = process.env.AGENTRIX_WORKSPACE_HOME_DIR ? process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/, os.homedir()) : path.join(this.agentrixHomeDir, "workspaces");
|
|
211
|
-
this.agentrixAgentsHomeDir = process.env.AGENTRIX_AGENTS_HOME_DIR ? process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/, os.homedir()) : path.join(this.agentrixHomeDir, "agents");
|
|
209
|
+
this.agentrixHomeDir = process.env.AGENTRIX_HOME_DIR ? process.env.AGENTRIX_HOME_DIR.replace(/^~/, os.homedir()) : path$1.join(os.homedir(), ".agentrix");
|
|
210
|
+
this.agentrixWorkspaceHomeDir = process.env.AGENTRIX_WORKSPACE_HOME_DIR ? process.env.AGENTRIX_WORKSPACE_HOME_DIR.replace(/^~/, os.homedir()) : path$1.join(this.agentrixHomeDir, "workspaces");
|
|
211
|
+
this.agentrixAgentsHomeDir = process.env.AGENTRIX_AGENTS_HOME_DIR ? process.env.AGENTRIX_AGENTS_HOME_DIR.replace(/^~/, os.homedir()) : path$1.join(this.agentrixHomeDir, "agents");
|
|
212
212
|
this.disableCaffeinate = ["true", "1", "yes"].includes(
|
|
213
213
|
(process.env.AGENTRIX_DISABLE_CAFFEINATE ?? "").toLowerCase()
|
|
214
214
|
);
|
|
@@ -218,11 +218,11 @@ class Machine {
|
|
|
218
218
|
this.ensureDir(this.agentrixAgentsHomeDir);
|
|
219
219
|
this.statePaths = {
|
|
220
220
|
rootDir: this.agentrixHomeDir,
|
|
221
|
-
logsDir: this.ensureDir(path.join(this.agentrixHomeDir, "logs")),
|
|
222
|
-
settingsFile: path.join(this.agentrixHomeDir, "settings.json"),
|
|
223
|
-
credentialsFile: path.join(this.agentrixHomeDir, "credentials.json"),
|
|
224
|
-
daemonStateFile: path.join(this.agentrixHomeDir, "daemon.state.json"),
|
|
225
|
-
daemonLockFile: path.join(this.agentrixHomeDir, "daemon.state.json.lock")
|
|
221
|
+
logsDir: this.ensureDir(path$1.join(this.agentrixHomeDir, "logs")),
|
|
222
|
+
settingsFile: path$1.join(this.agentrixHomeDir, "settings.json"),
|
|
223
|
+
credentialsFile: path$1.join(this.agentrixHomeDir, "credentials.json"),
|
|
224
|
+
daemonStateFile: path$1.join(this.agentrixHomeDir, "daemon.state.json"),
|
|
225
|
+
daemonLockFile: path$1.join(this.agentrixHomeDir, "daemon.state.json.lock")
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
generateMachineId() {
|
|
@@ -357,22 +357,22 @@ class Machine {
|
|
|
357
357
|
if (cwd) {
|
|
358
358
|
return this.ensureDir(cwd.replace(/^~/, os.homedir()));
|
|
359
359
|
}
|
|
360
|
-
const workspaceDir = path.join(this.agentrixWorkspaceHomeDir, "users", userId, taskId, "project");
|
|
360
|
+
const workspaceDir = path$1.join(this.agentrixWorkspaceHomeDir, "users", userId, taskId, "project");
|
|
361
361
|
return this.ensureDir(workspaceDir);
|
|
362
362
|
}
|
|
363
363
|
resolveDataDir(userId, taskId) {
|
|
364
|
-
const dataDir = path.join(this.agentrixWorkspaceHomeDir, "users", userId, taskId, "data");
|
|
364
|
+
const dataDir = path$1.join(this.agentrixWorkspaceHomeDir, "users", userId, taskId, "data");
|
|
365
365
|
return this.ensureDir(dataDir);
|
|
366
366
|
}
|
|
367
367
|
resolveAttachmentsDir(userId, taskId) {
|
|
368
|
-
const attachmentsDir = path.join(this.resolveDataDir(userId, taskId), "attachments");
|
|
368
|
+
const attachmentsDir = path$1.join(this.resolveDataDir(userId, taskId), "attachments");
|
|
369
369
|
return this.ensureDir(attachmentsDir);
|
|
370
370
|
}
|
|
371
371
|
resolveAgentDir(agentId) {
|
|
372
|
-
return path.join(this.agentrixAgentsHomeDir, agentId);
|
|
372
|
+
return path$1.join(this.agentrixAgentsHomeDir, agentId);
|
|
373
373
|
}
|
|
374
374
|
getInitialCommitHashPath(userId, taskId) {
|
|
375
|
-
return path.join(this.resolveDataDir(userId, taskId), "initial-commit-hash.txt");
|
|
375
|
+
return path$1.join(this.resolveDataDir(userId, taskId), "initial-commit-hash.txt");
|
|
376
376
|
}
|
|
377
377
|
async readInitialCommitHash(userId, taskId) {
|
|
378
378
|
const path = this.getInitialCommitHashPath(userId, taskId);
|
|
@@ -391,13 +391,13 @@ class Machine {
|
|
|
391
391
|
await promises.writeFile(path, hash);
|
|
392
392
|
}
|
|
393
393
|
writeTaskInput(data) {
|
|
394
|
-
const path
|
|
395
|
-
const inputFile = path.join(path
|
|
394
|
+
const path = this.resolveDataDir(data.userId, data.taskId);
|
|
395
|
+
const inputFile = path$1.join(path, "input.json");
|
|
396
396
|
fs.writeFileSync(inputFile, JSON.stringify(data, null, 2));
|
|
397
397
|
}
|
|
398
398
|
readTaskInput(userId, taskId) {
|
|
399
|
-
const path
|
|
400
|
-
const inputFile = path.join(path
|
|
399
|
+
const path = this.resolveDataDir(userId, taskId);
|
|
400
|
+
const inputFile = path$1.join(path, "input.json");
|
|
401
401
|
if (!fs.existsSync(inputFile)) {
|
|
402
402
|
throw new Error(`Task input file does not exist: ${inputFile}`);
|
|
403
403
|
}
|
|
@@ -503,7 +503,7 @@ function getLogPath(context) {
|
|
|
503
503
|
return "";
|
|
504
504
|
}
|
|
505
505
|
const filename = context.type === "daemon" ? "daemon.log" : `task-${context.taskId}.log`;
|
|
506
|
-
return path.join(logsDir, filename);
|
|
506
|
+
return path$1.join(logsDir, filename);
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
var logger$1 = /*#__PURE__*/Object.freeze({
|