@appchy/jarvis 0.1.0 → 0.1.2

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
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env node
2
- #!/usr/bin/env node
3
1
  var __create = Object.create;
4
2
  var __defProp = Object.defineProperty;
5
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -50734,9 +50732,44 @@ function createGitHandler(workspacePath, broadcast) {
50734
50732
 
50735
50733
  // src/server.ts
50736
50734
  import { WebSocketServer, WebSocket as WebSocket2 } from "ws";
50735
+ async function isPortInUse(port) {
50736
+ return new Promise((resolve) => {
50737
+ const ws = new WebSocket2(`ws://127.0.0.1:${port}`);
50738
+ const timeout = setTimeout(() => {
50739
+ ws.close();
50740
+ resolve(false);
50741
+ }, 1e3);
50742
+ ws.on("open", () => {
50743
+ clearTimeout(timeout);
50744
+ ws.send(JSON.stringify({ type: "ping" }));
50745
+ ws.on("message", () => {
50746
+ ws.close();
50747
+ resolve(true);
50748
+ });
50749
+ });
50750
+ ws.on("error", () => {
50751
+ clearTimeout(timeout);
50752
+ resolve(false);
50753
+ });
50754
+ });
50755
+ }
50737
50756
  function createLocalServer(port) {
50738
50757
  const clients = /* @__PURE__ */ new Set();
50739
50758
  const wss = new WebSocketServer({ host: "127.0.0.1", port });
50759
+ wss.on("error", (err) => {
50760
+ if (err.code === "EADDRINUSE") {
50761
+ console.error(
50762
+ `
50763
+ Error: Port ${port} is already in use.
50764
+ Another Jarvis agent is already running on this port.
50765
+ Clients (jarvis chat, VSCode) can connect to the existing agent.
50766
+ To use a different port: jarvis start --port <port>
50767
+ `
50768
+ );
50769
+ process.exit(1);
50770
+ }
50771
+ throw err;
50772
+ });
50740
50773
  wss.on("connection", (ws) => {
50741
50774
  clients.add(ws);
50742
50775
  ws.on("close", () => clients.delete(ws));
@@ -52958,6 +52991,14 @@ function createCli() {
52958
52991
  program.command("start").description("Start the local agent").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)").action(async (opts) => {
52959
52992
  const config = loadConfig();
52960
52993
  const port = parseInt(opts.port, 10);
52994
+ const alreadyRunning = await isPortInUse(port);
52995
+ if (alreadyRunning) {
52996
+ console.log(`
52997
+ Jarvis agent is already running on ws://127.0.0.1:${port}`);
52998
+ console.log(`Clients (jarvis chat, VSCode) can connect to it.
52999
+ `);
53000
+ return;
53001
+ }
52961
53002
  const workspacePath = opts.workspace ?? config?.workspacePath ?? process.cwd();
52962
53003
  const anthropicApiKey = opts.apiKey ?? config?.anthropicApiKey ?? process.env.ANTHROPIC_API_KEY;
52963
53004
  const userId = config?.userId ?? process.env.JARVIS_USER_ID ?? "local";