@appchy/jarvis 0.1.15 → 0.1.16
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/bin.js +35 -65
- package/dist/bin.js.map +1 -1
- package/package.json +2 -2
package/dist/bin.js
CHANGED
|
@@ -5237,10 +5237,6 @@ var PKG_VERSION = _require("../package.json").version ?? "dev";
|
|
|
5237
5237
|
var LOG_DIR = path8.join(os5.homedir(), ".jarvis");
|
|
5238
5238
|
var LOG_FILE = path8.join(LOG_DIR, "agent.log");
|
|
5239
5239
|
var PID_FILE = path8.join(LOG_DIR, "agent.pid");
|
|
5240
|
-
function savePid(pid) {
|
|
5241
|
-
fs8.mkdirSync(LOG_DIR, { recursive: true });
|
|
5242
|
-
fs8.writeFileSync(PID_FILE, String(pid));
|
|
5243
|
-
}
|
|
5244
5240
|
function readPid() {
|
|
5245
5241
|
try {
|
|
5246
5242
|
const pid = parseInt(fs8.readFileSync(PID_FILE, "utf-8").trim(), 10);
|
|
@@ -5308,7 +5304,7 @@ async function findFreePort() {
|
|
|
5308
5304
|
async function browserAuth(appUrl) {
|
|
5309
5305
|
const config = loadConfig();
|
|
5310
5306
|
const callbackPort = await findFreePort();
|
|
5311
|
-
const loginUrl = `${appUrl}/
|
|
5307
|
+
const loginUrl = `${appUrl}/auth/cli?port=${callbackPort}`;
|
|
5312
5308
|
console.log();
|
|
5313
5309
|
console.log("Opening browser for sign in...");
|
|
5314
5310
|
console.log(` If it doesn't open, visit: ${loginUrl}`);
|
|
@@ -5339,7 +5335,7 @@ async function browserAuth(appUrl) {
|
|
|
5339
5335
|
}
|
|
5340
5336
|
}
|
|
5341
5337
|
function getAppUrl() {
|
|
5342
|
-
return
|
|
5338
|
+
return "https://jarvis.appchy.com";
|
|
5343
5339
|
}
|
|
5344
5340
|
function getTokenExpiry(token) {
|
|
5345
5341
|
try {
|
|
@@ -5372,24 +5368,25 @@ async function tryRefreshToken(config) {
|
|
|
5372
5368
|
}
|
|
5373
5369
|
async function ensureSetup() {
|
|
5374
5370
|
const config = loadConfig();
|
|
5375
|
-
if (!config?.token && !config?.anthropicApiKey && !config?.useSubscription) {
|
|
5376
|
-
return browserAuth(getAppUrl());
|
|
5377
|
-
}
|
|
5378
5371
|
if (config?.anthropicApiKey || config?.useSubscription) {
|
|
5379
5372
|
return true;
|
|
5380
5373
|
}
|
|
5381
|
-
if (config?.token
|
|
5382
|
-
console.log("Token expired, attempting refresh...");
|
|
5383
|
-
const newToken = await tryRefreshToken(config);
|
|
5384
|
-
if (newToken) {
|
|
5385
|
-
saveConfig({ ...config, token: newToken, connectedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
5386
|
-
console.log("Token refreshed successfully.");
|
|
5387
|
-
return true;
|
|
5388
|
-
}
|
|
5389
|
-
console.log("Token refresh failed. Re-authenticating...");
|
|
5374
|
+
if (!config?.token) {
|
|
5390
5375
|
return browserAuth(getAppUrl());
|
|
5391
5376
|
}
|
|
5392
|
-
|
|
5377
|
+
if (!isTokenExpired(config.token)) {
|
|
5378
|
+
return true;
|
|
5379
|
+
}
|
|
5380
|
+
console.log("Token expired, attempting refresh...");
|
|
5381
|
+
const newToken = await tryRefreshToken(config);
|
|
5382
|
+
if (newToken) {
|
|
5383
|
+
saveConfig({ ...config, token: newToken, connectedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
5384
|
+
console.log("Token refreshed successfully.");
|
|
5385
|
+
return true;
|
|
5386
|
+
}
|
|
5387
|
+
console.log("Token refresh failed. Re-authenticating...");
|
|
5388
|
+
clearConfig();
|
|
5389
|
+
return browserAuth(getAppUrl());
|
|
5393
5390
|
}
|
|
5394
5391
|
function createCli() {
|
|
5395
5392
|
const program = new Command().name("jarvis").description("Jarvis local agent \u2014 runs Claude Code on your machine").version(PKG_VERSION);
|
|
@@ -5457,16 +5454,6 @@ function createCli() {
|
|
|
5457
5454
|
return;
|
|
5458
5455
|
}
|
|
5459
5456
|
const service = createServiceManager();
|
|
5460
|
-
if (service.isInstalled()) {
|
|
5461
|
-
try {
|
|
5462
|
-
service.stop();
|
|
5463
|
-
} catch {
|
|
5464
|
-
}
|
|
5465
|
-
await new Promise((r) => setTimeout(r, 1e3));
|
|
5466
|
-
service.start();
|
|
5467
|
-
console.log("Jarvis agent started via OS service.");
|
|
5468
|
-
return;
|
|
5469
|
-
}
|
|
5470
5457
|
const stalePid = readPid();
|
|
5471
5458
|
if (stalePid) {
|
|
5472
5459
|
try {
|
|
@@ -5475,6 +5462,12 @@ function createCli() {
|
|
|
5475
5462
|
}
|
|
5476
5463
|
clearPid();
|
|
5477
5464
|
}
|
|
5465
|
+
if (service.isInstalled()) {
|
|
5466
|
+
try {
|
|
5467
|
+
service.stop();
|
|
5468
|
+
} catch {
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5478
5471
|
if (await isPortInUse(port)) {
|
|
5479
5472
|
try {
|
|
5480
5473
|
const output = execSync2(`lsof -ti :${port}`, { encoding: "utf-8" }).trim();
|
|
@@ -5490,51 +5483,28 @@ function createCli() {
|
|
|
5490
5483
|
}
|
|
5491
5484
|
await new Promise((r) => setTimeout(r, 1e3));
|
|
5492
5485
|
}
|
|
5493
|
-
fs8.mkdirSync(LOG_DIR, { recursive: true });
|
|
5494
|
-
const logFd = fs8.openSync(LOG_FILE, "a");
|
|
5495
|
-
const args = [
|
|
5496
|
-
"start",
|
|
5497
|
-
"--foreground",
|
|
5498
|
-
"--port",
|
|
5499
|
-
String(port),
|
|
5500
|
-
"--workspace",
|
|
5501
|
-
workspacePath
|
|
5502
|
-
];
|
|
5503
|
-
if (!opts.upstream) {
|
|
5504
|
-
args.push("--no-upstream");
|
|
5505
|
-
}
|
|
5506
|
-
if (anthropicApiKey) {
|
|
5507
|
-
args.push("--api-key", anthropicApiKey);
|
|
5508
|
-
}
|
|
5509
5486
|
const binPath = process.argv[1];
|
|
5510
5487
|
const cliRoot = path8.resolve(path8.dirname(binPath), "..");
|
|
5511
5488
|
const distEntry = path8.join(cliRoot, "dist", "bin.js");
|
|
5512
|
-
const
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
NODE_NO_WARNINGS: "1",
|
|
5523
|
-
// Strip API key when using subscription to prevent SDK from picking it up
|
|
5524
|
-
...useSubscription ? { ANTHROPIC_API_KEY: "" } : {}
|
|
5525
|
-
}
|
|
5526
|
-
}
|
|
5527
|
-
);
|
|
5528
|
-
child.unref();
|
|
5529
|
-
fs8.closeSync(logFd);
|
|
5530
|
-
savePid(child.pid);
|
|
5531
|
-
console.log(`Jarvis agent started (PID: ${child.pid})`);
|
|
5489
|
+
const entryPath = fs8.existsSync(distEntry) ? distEntry : binPath;
|
|
5490
|
+
service.install({
|
|
5491
|
+
port,
|
|
5492
|
+
workspacePath,
|
|
5493
|
+
nodePath: process.execPath,
|
|
5494
|
+
entryPath,
|
|
5495
|
+
upstream: opts.upstream
|
|
5496
|
+
});
|
|
5497
|
+
const status = service.status();
|
|
5498
|
+
console.log(`Jarvis agent started`);
|
|
5532
5499
|
console.log(` Local: ws://127.0.0.1:${port}`);
|
|
5533
5500
|
console.log(` Workspace: ${workspacePath}`);
|
|
5534
5501
|
console.log(` Logs: ${LOG_FILE}`);
|
|
5535
5502
|
if (config?.apiUrl) {
|
|
5536
5503
|
console.log(` Cloud: ${config.apiUrl}`);
|
|
5537
5504
|
}
|
|
5505
|
+
if (status.os) {
|
|
5506
|
+
console.log(` Service: ${status.os} (auto-start on login, crash recovery)`);
|
|
5507
|
+
}
|
|
5538
5508
|
}
|
|
5539
5509
|
);
|
|
5540
5510
|
program.command("stop").description("Stop the running agent").action(async () => {
|