@appchy/jarvis 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -388,7 +388,7 @@ function claudeCodeProvider(config = {}) {
388
388
  options: {
389
389
  model: req.model,
390
390
  systemPrompt: systemPromptOption,
391
- maxTurns: config.maxTurns ?? 50,
391
+ ...config.maxTurns ? { maxTurns: config.maxTurns } : {},
392
392
  ...permissionOptions,
393
393
  ...config.mcpServers ? { mcpServers: config.mcpServers } : {},
394
394
  ...config.workingDirectory ? { cwd: config.workingDirectory } : {},
@@ -557,7 +557,7 @@ function claudeCodeProvider(config = {}) {
557
557
  options: {
558
558
  model: req.model,
559
559
  systemPrompt: streamSystemPromptOption,
560
- maxTurns: config.maxTurns ?? 50,
560
+ ...config.maxTurns ? { maxTurns: config.maxTurns } : {},
561
561
  ...permissionOptions,
562
562
  ...config.mcpServers ? { mcpServers: config.mcpServers } : {},
563
563
  ...config.workingDirectory ? { cwd: config.workingDirectory } : {},
@@ -2056,7 +2056,7 @@ function createWsProgressHandlers(deps) {
2056
2056
  id: `status-plan-${crypto2.randomUUID()}`,
2057
2057
  role: "assistant",
2058
2058
  type: "status",
2059
- content: "Planning...",
2059
+ content: "Planning",
2060
2060
  isPartial: true,
2061
2061
  createdAt: now
2062
2062
  });
@@ -2238,7 +2238,7 @@ function createAgent(deps) {
2238
2238
  systemPrompt: systemMsg?.content ?? "",
2239
2239
  workingDirectory: wsPath,
2240
2240
  tools: claudeCodeTools,
2241
- maxTurns: msg.maxTurns ?? 200,
2241
+ ...msg.maxTurns ? { maxTurns: msg.maxTurns } : {},
2242
2242
  userId: deps.userId,
2243
2243
  abortController,
2244
2244
  heartbeat: () => {
@@ -2266,7 +2266,7 @@ function createAgent(deps) {
2266
2266
  ...deps.useSubscription ? { useSubscription: true } : { apiKey: deps.anthropicApiKey },
2267
2267
  workingDirectory: wsPath,
2268
2268
  tools: claudeCodeTools,
2269
- maxTurns: msg.maxTurns ?? 200,
2269
+ ...msg.maxTurns ? { maxTurns: msg.maxTurns } : {},
2270
2270
  userId: deps.userId,
2271
2271
  abortController,
2272
2272
  heartbeat: () => {
@@ -2520,12 +2520,15 @@ function createUpstreamClient(config) {
2520
2520
  let messageHandler = null;
2521
2521
  let reconnectTimer = null;
2522
2522
  let closed = false;
2523
+ let authFailures = 0;
2524
+ const MAX_AUTH_RETRIES = 3;
2523
2525
  function connect() {
2524
2526
  if (closed) return;
2525
2527
  ws = new WebSocket2(config.apiUrl, {
2526
2528
  headers: { authorization: `Bearer ${config.token}` }
2527
2529
  });
2528
2530
  ws.on("open", () => {
2531
+ authFailures = 0;
2529
2532
  logger.sys.info("[Upstream] Connected to cloud", { apiUrl: config.apiUrl });
2530
2533
  });
2531
2534
  ws.on("message", (raw) => {
@@ -2539,11 +2542,25 @@ function createUpstreamClient(config) {
2539
2542
  } catch {
2540
2543
  }
2541
2544
  });
2542
- ws.on("close", () => {
2543
- if (!closed) {
2544
- logger.sys.info("[Upstream] Disconnected, reconnecting in 3s...");
2545
- reconnectTimer = setTimeout(connect, 3e3);
2545
+ ws.on("close", (code) => {
2546
+ if (closed) return;
2547
+ if (code === 4001 || code === 4003) {
2548
+ authFailures++;
2549
+ if (authFailures >= MAX_AUTH_RETRIES) {
2550
+ logger.sys.error("[Upstream] Auth failed after max retries, giving up", {
2551
+ code,
2552
+ attempts: authFailures
2553
+ });
2554
+ return;
2555
+ }
2556
+ logger.sys.warn("[Upstream] Auth failed, retrying...", {
2557
+ code,
2558
+ attempt: authFailures,
2559
+ maxRetries: MAX_AUTH_RETRIES
2560
+ });
2546
2561
  }
2562
+ logger.sys.info("[Upstream] Disconnected, reconnecting in 3s...");
2563
+ reconnectTimer = setTimeout(connect, 3e3);
2547
2564
  });
2548
2565
  ws.on("error", (err) => {
2549
2566
  logger.sys.error("[Upstream] Connection error", {
@@ -4664,6 +4681,9 @@ async function waitForAgent(port, maxAttempts = 30) {
4664
4681
  }
4665
4682
 
4666
4683
  // src/cli.ts
4684
+ import { createRequire } from "module";
4685
+ var _require = createRequire(import.meta.url);
4686
+ var PKG_VERSION = _require("../package.json").version ?? "dev";
4667
4687
  var LOG_DIR = path7.join(os4.homedir(), ".jarvis");
4668
4688
  var LOG_FILE = path7.join(LOG_DIR, "agent.log");
4669
4689
  var PID_FILE = path7.join(LOG_DIR, "agent.pid");
@@ -4693,7 +4713,7 @@ function clearPid() {
4693
4713
  }
4694
4714
  }
4695
4715
  function createCli() {
4696
- const program = new Command().name("jarvis").description("Jarvis local agent \u2014 runs Claude Code on your machine").version("0.0.0");
4716
+ const program = new Command().name("jarvis").description("Jarvis local agent \u2014 runs Claude Code on your machine").version(PKG_VERSION);
4697
4717
  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) => {
4698
4718
  try {
4699
4719
  const parsed = parseConnectToken(token);
@@ -4762,12 +4782,19 @@ function createCli() {
4762
4782
  args.push("--api-key", anthropicApiKey);
4763
4783
  }
4764
4784
  const binPath = process.argv[1];
4765
- const child = spawn2(process.execPath, [binPath, ...args], {
4766
- detached: true,
4767
- stdio: ["ignore", logFd, logFd],
4768
- cwd: workspacePath,
4769
- env: { ...process.env, NODE_NO_WARNINGS: "1" }
4770
- });
4785
+ const cliRoot = path7.resolve(path7.dirname(binPath), "..");
4786
+ const distEntry = path7.join(cliRoot, "dist", "bin.js");
4787
+ const useDistEntry = fs7.existsSync(distEntry);
4788
+ const child = spawn2(
4789
+ process.execPath,
4790
+ useDistEntry ? [distEntry, ...args] : [binPath, ...args],
4791
+ {
4792
+ detached: true,
4793
+ stdio: ["ignore", logFd, logFd],
4794
+ cwd: workspacePath,
4795
+ env: { ...process.env, NODE_NO_WARNINGS: "1" }
4796
+ }
4797
+ );
4771
4798
  child.unref();
4772
4799
  fs7.closeSync(logFd);
4773
4800
  savePid(child.pid);
@@ -4858,7 +4885,7 @@ function createCli() {
4858
4885
  const pid = readPid();
4859
4886
  const port = config?.port ?? 7862;
4860
4887
  const running = await isPortInUse(port);
4861
- console.log("Jarvis Agent:");
4888
+ console.log(`Jarvis Agent v${PKG_VERSION}:`);
4862
4889
  console.log(` Status: ${running ? `\x1B[32mrunning\x1B[0m` : `\x1B[31mstopped\x1B[0m`}${pid ? ` (PID: ${pid})` : ""}`);
4863
4890
  console.log(` Port: ${port}`);
4864
4891
  console.log(` Config: ${getConfigPath()}`);