@appchy/jarvis 0.1.12 → 0.1.14
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 +38 -31
- package/dist/bin.js.map +1 -1
- package/package.json +3 -3
package/dist/bin.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// src/bin.ts
|
|
2
|
-
import dotenv from "dotenv";
|
|
3
|
-
import fs8 from "fs";
|
|
4
|
-
import path8 from "path";
|
|
5
|
-
|
|
6
1
|
// src/cli.ts
|
|
7
2
|
import { Command } from "commander";
|
|
8
3
|
import { spawn as spawn2, execSync } from "child_process";
|
|
@@ -14,7 +9,7 @@ import os4 from "os";
|
|
|
14
9
|
import fs from "fs";
|
|
15
10
|
import path from "path";
|
|
16
11
|
import os from "os";
|
|
17
|
-
var CONFIG_DIR = path.join(os.homedir(), ".jarvis");
|
|
12
|
+
var CONFIG_DIR = process.env.JARVIS_CONFIG_DIR ?? path.join(os.homedir(), ".jarvis");
|
|
18
13
|
var CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
19
14
|
function loadConfig() {
|
|
20
15
|
try {
|
|
@@ -2632,6 +2627,7 @@ function createUpstreamClient(config) {
|
|
|
2632
2627
|
}
|
|
2633
2628
|
});
|
|
2634
2629
|
ws.on("close", (code) => {
|
|
2630
|
+
console.error("[Upstream] Connection closed, code:", code);
|
|
2635
2631
|
if (closed) return;
|
|
2636
2632
|
if (code === 4001 || code === 4003) {
|
|
2637
2633
|
if (config.refreshToken) {
|
|
@@ -2683,6 +2679,7 @@ function createUpstreamClient(config) {
|
|
|
2683
2679
|
reconnectTimer = setTimeout(connect, 3e3);
|
|
2684
2680
|
});
|
|
2685
2681
|
ws.on("error", (err) => {
|
|
2682
|
+
console.error("[Upstream] Connection error:", err.message);
|
|
2686
2683
|
logger.sys.error("[Upstream] Connection error", {
|
|
2687
2684
|
error: err.message
|
|
2688
2685
|
});
|
|
@@ -4915,17 +4912,21 @@ async function ensureSetup() {
|
|
|
4915
4912
|
if (config?.token || config?.anthropicApiKey || config?.useSubscription) {
|
|
4916
4913
|
return true;
|
|
4917
4914
|
}
|
|
4918
|
-
|
|
4915
|
+
const ok = await browserAuth(APP_URL);
|
|
4916
|
+
if (!ok) return false;
|
|
4917
|
+
const pid = readPid();
|
|
4918
|
+
if (pid) {
|
|
4919
|
+
try {
|
|
4920
|
+
process.kill(pid, "SIGTERM");
|
|
4921
|
+
} catch {
|
|
4922
|
+
}
|
|
4923
|
+
clearPid();
|
|
4924
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
4925
|
+
}
|
|
4926
|
+
return true;
|
|
4919
4927
|
}
|
|
4920
4928
|
function createCli() {
|
|
4921
4929
|
const program = new Command().name("jarvis").description("Jarvis local agent \u2014 runs Claude Code on your machine").version(PKG_VERSION);
|
|
4922
|
-
program.argument("[message]", "Optional initial message to send").option("--model <id>", "Model (e.g., claude-opus-4-20250514)").option("--mode <mode>", "Permission mode: supervised|auto|plan|yolo").option("--thinking <config>", "Thinking: adaptive|enabled|disabled").option("--thinking-budget <n>", "Token budget when thinking=enabled").option("--max-turns <n>", "Max turns per task").option("-p, --port <port>", "Agent server port", "7862").option("-w, --workspace <path>", "Workspace root path").option("--no-server", "Connect to existing server, don't auto-start").action(async (message, opts) => {
|
|
4923
|
-
if (message && program.commands.some((c) => c.name() === message)) {
|
|
4924
|
-
return;
|
|
4925
|
-
}
|
|
4926
|
-
await ensureSetup();
|
|
4927
|
-
await launchChat(opts);
|
|
4928
|
-
});
|
|
4929
4930
|
program.command("connect <token>").description("Connect to Jarvis cloud using a token from the web UI").option("-w, --workspace <path>", "Workspace root path for repo operations").action((token, opts) => {
|
|
4930
4931
|
try {
|
|
4931
4932
|
const parsed = parseConnectToken(token);
|
|
@@ -4953,14 +4954,18 @@ function createCli() {
|
|
|
4953
4954
|
}
|
|
4954
4955
|
});
|
|
4955
4956
|
program.command("start").description("Start the local agent (runs as background daemon)").option("-p, --port <port>", "Local WS server port", "7862").option("-w, --workspace <path>", "Workspace root path").option("--api-key <key>", "Anthropic API key (for local-only use)").option("--no-upstream", "Don't connect to cloud (local-only mode)").option("--foreground", "Run in foreground (don't daemonize)").action(async (opts) => {
|
|
4956
|
-
|
|
4957
|
+
if (!opts.foreground) {
|
|
4958
|
+
await ensureSetup();
|
|
4959
|
+
}
|
|
4957
4960
|
const config = loadConfig();
|
|
4958
4961
|
const port = parseInt(opts.port, 10);
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4962
|
+
if (!opts.foreground) {
|
|
4963
|
+
const alreadyRunning = await isPortInUse(port);
|
|
4964
|
+
if (alreadyRunning) {
|
|
4965
|
+
console.log(`Jarvis agent is already running on ws://127.0.0.1:${port}`);
|
|
4966
|
+
console.log(`Use 'jarvis restart' to restart, or 'jarvis logs' to view logs.`);
|
|
4967
|
+
return;
|
|
4968
|
+
}
|
|
4964
4969
|
}
|
|
4965
4970
|
const workspacePath = opts.workspace ?? config?.workspacePath ?? process.cwd();
|
|
4966
4971
|
const userId = config?.userId ?? process.env.JARVIS_USER_ID ?? "local";
|
|
@@ -4968,6 +4973,9 @@ function createCli() {
|
|
|
4968
4973
|
const useSubscription = !explicitApiKey;
|
|
4969
4974
|
const anthropicApiKey = explicitApiKey;
|
|
4970
4975
|
if (opts.foreground) {
|
|
4976
|
+
if (useSubscription && process.env.ANTHROPIC_API_KEY) {
|
|
4977
|
+
delete process.env.ANTHROPIC_API_KEY;
|
|
4978
|
+
}
|
|
4971
4979
|
await startAgent({
|
|
4972
4980
|
port,
|
|
4973
4981
|
workspacePath,
|
|
@@ -5012,7 +5020,12 @@ function createCli() {
|
|
|
5012
5020
|
detached: true,
|
|
5013
5021
|
stdio: ["ignore", logFd, logFd],
|
|
5014
5022
|
cwd: workspacePath,
|
|
5015
|
-
env: {
|
|
5023
|
+
env: {
|
|
5024
|
+
...process.env,
|
|
5025
|
+
NODE_NO_WARNINGS: "1",
|
|
5026
|
+
// Strip API key when using subscription to prevent SDK from picking it up
|
|
5027
|
+
...useSubscription ? { ANTHROPIC_API_KEY: "" } : {}
|
|
5028
|
+
}
|
|
5016
5029
|
}
|
|
5017
5030
|
);
|
|
5018
5031
|
child.unref();
|
|
@@ -5123,19 +5136,13 @@ function createCli() {
|
|
|
5123
5136
|
clearConfig();
|
|
5124
5137
|
console.log("Configuration cleared.");
|
|
5125
5138
|
});
|
|
5139
|
+
program.command("chat", { isDefault: true, hidden: true }).description("Interactive TUI").option("--model <id>", "Model (e.g., claude-opus-4-20250514)").option("--mode <mode>", "Permission mode: supervised|auto|plan|yolo").option("--thinking <config>", "Thinking: adaptive|enabled|disabled").option("--thinking-budget <n>", "Token budget when thinking=enabled").option("--max-turns <n>", "Max turns per task").option("-p, --port <port>", "Agent server port", "7862").option("-w, --workspace <path>", "Workspace root path").option("--no-server", "Connect to existing server, don't auto-start").action(async (opts) => {
|
|
5140
|
+
await ensureSetup();
|
|
5141
|
+
await launchChat(opts);
|
|
5142
|
+
});
|
|
5126
5143
|
return program;
|
|
5127
5144
|
}
|
|
5128
5145
|
|
|
5129
5146
|
// src/bin.ts
|
|
5130
|
-
function findEnv() {
|
|
5131
|
-
let dir = process.cwd();
|
|
5132
|
-
while (dir !== path8.dirname(dir)) {
|
|
5133
|
-
const envPath = path8.join(dir, ".env");
|
|
5134
|
-
if (fs8.existsSync(envPath)) return envPath;
|
|
5135
|
-
dir = path8.dirname(dir);
|
|
5136
|
-
}
|
|
5137
|
-
return void 0;
|
|
5138
|
-
}
|
|
5139
|
-
dotenv.config({ path: findEnv() });
|
|
5140
5147
|
createCli().parse();
|
|
5141
5148
|
//# sourceMappingURL=bin.js.map
|