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