@vicvic-im/agent-bot 0.1.1 → 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/cli.cjs CHANGED
@@ -24,8 +24,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/cli.ts
27
- var import_node_child_process2 = require("child_process");
28
- var import_node_path7 = require("path");
27
+ var import_node_child_process3 = require("child_process");
28
+ var import_node_path6 = require("path");
29
29
  var import_commander = require("commander");
30
30
  var import_picocolors2 = __toESM(require("picocolors"), 1);
31
31
 
@@ -136,11 +136,11 @@ function parseEnv(value) {
136
136
  if (value === void 0 || value === null) return void 0;
137
137
  const record = asRecord(value, "agent.env");
138
138
  const env = {};
139
- for (const [key, entry2] of Object.entries(record)) {
140
- if (typeof entry2 !== "string") {
139
+ for (const [key, entry] of Object.entries(record)) {
140
+ if (typeof entry !== "string") {
141
141
  throw new ConfigError(`Invalid "agent.env.${key}": expected a string`);
142
142
  }
143
- env[key] = entry2;
143
+ env[key] = entry;
144
144
  }
145
145
  return env;
146
146
  }
@@ -184,7 +184,7 @@ function parseAgent(root, configDir) {
184
184
  return {
185
185
  name: agentName,
186
186
  command: optionalString(agentRaw.command, "agent.command"),
187
- args: Array.isArray(argsRaw) ? argsRaw.map((entry2) => String(entry2)) : void 0,
187
+ args: Array.isArray(argsRaw) ? argsRaw.map((entry) => String(entry)) : void 0,
188
188
  cwd,
189
189
  model: optionalString(agentRaw.model, "agent.model") ?? null,
190
190
  env: parseEnv(agentRaw.env)
@@ -318,7 +318,7 @@ var import_node_fs3 = require("fs");
318
318
  var import_node_path3 = require("path");
319
319
  function resolveServerEntry(cliPath2) {
320
320
  const real = (0, import_node_fs3.realpathSync)(cliPath2);
321
- const candidate = (0, import_node_path3.join)((0, import_node_path3.dirname)(real), "server.js");
321
+ const candidate = (0, import_node_path3.join)((0, import_node_path3.dirname)(real), "bin-server.js");
322
322
  if (!(0, import_node_fs3.existsSync)(candidate)) {
323
323
  throw new Error(`Server bundle not found at ${candidate}. Reinstall @vicvic-im/agent-bot.`);
324
324
  }
@@ -333,11 +333,29 @@ function readPackageVersion(cliPath2) {
333
333
  }
334
334
  }
335
335
 
336
- // src/server.ts
337
- var import_node_path6 = require("path");
336
+ // src/core/pm2.ts
337
+ var import_node_child_process = require("child_process");
338
+ var ENV_BIN = "/usr/bin/env";
339
+ function hasPm2(exec = import_node_child_process.execFileSync) {
340
+ try {
341
+ exec(ENV_BIN, ["pm2", "--version"], { stdio: "ignore" });
342
+ return true;
343
+ } catch {
344
+ return false;
345
+ }
346
+ }
347
+ function ensurePm2(exec = import_node_child_process.execFileSync) {
348
+ if (hasPm2(exec)) return true;
349
+ try {
350
+ exec(ENV_BIN, ["npm", "i", "-g", "pm2"], { stdio: "inherit" });
351
+ return hasPm2(exec);
352
+ } catch {
353
+ return false;
354
+ }
355
+ }
338
356
 
339
357
  // src/agents/acp.ts
340
- var import_node_child_process = require("child_process");
358
+ var import_node_child_process2 = require("child_process");
341
359
  var import_node_stream = require("stream");
342
360
  var acp = __toESM(require("@agentclientprotocol/sdk"), 1);
343
361
 
@@ -404,7 +422,7 @@ var AcpAgent = class {
404
422
  const definition = definitionOf(this.name);
405
423
  const command = this.config.command ?? definition.command.command;
406
424
  const args = this.config.args ?? definition.command.args;
407
- const child = (0, import_node_child_process.spawn)(command, args, {
425
+ const child = (0, import_node_child_process2.spawn)(command, args, {
408
426
  cwd: this.config.cwd,
409
427
  env: { ...process.env, ...this.config.env },
410
428
  stdio: ["pipe", "pipe", "pipe"]
@@ -543,7 +561,7 @@ var AcpAgent = class {
543
561
  );
544
562
  pending.catch(() => void 0);
545
563
  const response = await Promise.race([pending, aborted]);
546
- await new Promise((resolve5) => setImmediate(resolve5));
564
+ await new Promise((resolve4) => setImmediate(resolve4));
547
565
  if (response.stopReason === "cancelled" || request.signal.aborted) {
548
566
  throw new AgentAbortError();
549
567
  }
@@ -576,7 +594,7 @@ var AcpAgent = class {
576
594
  return true;
577
595
  }
578
596
  const option = this.configOptions.find(
579
- (entry2) => entry2.type === "select" && (entry2.id === "model" || entry2.category === "model")
597
+ (entry) => entry.type === "select" && (entry.id === "model" || entry.category === "model")
580
598
  );
581
599
  if (!option) return false;
582
600
  await this.ctx.request(acp.methods.agent.session.setConfigOption, {
@@ -602,8 +620,8 @@ var AcpAgent = class {
602
620
  } catch {
603
621
  }
604
622
  if (!child || child.exitCode !== null) return;
605
- const exited = new Promise((resolve5) => {
606
- child.once("exit", () => resolve5());
623
+ const exited = new Promise((resolve4) => {
624
+ child.once("exit", () => resolve4());
607
625
  });
608
626
  child.kill("SIGTERM");
609
627
  const timer = setTimeout(() => child.kill("SIGKILL"), 3e3);
@@ -720,7 +738,7 @@ var BotQueue = class {
720
738
  };
721
739
 
722
740
  // src/version.ts
723
- var VBOT_VERSION = "0.1.1";
741
+ var VBOT_VERSION = "0.1.2";
724
742
 
725
743
  // src/core/dispatcher.ts
726
744
  var HELP_TEXT = `Available commands:
@@ -801,7 +819,7 @@ function handleAgent(runtime, args, send) {
801
819
  const name = args.join(" ").trim();
802
820
  if (!name) {
803
821
  const current = runtime.config().agent.name;
804
- const list = AGENT_NAMES.map((entry2) => `${entry2 === current ? "*" : " "} ${entry2}`).join("\n");
822
+ const list = AGENT_NAMES.map((entry) => `${entry === current ? "*" : " "} ${entry}`).join("\n");
805
823
  send(`Current agent: ${current}
806
824
  Available agents:
807
825
  ${list}`);
@@ -1085,10 +1103,10 @@ var VicvicWire = class {
1085
1103
  if (!socket || socket.readyState !== import_ws.default.OPEN) {
1086
1104
  throw new Error("Bot connection is not open");
1087
1105
  }
1088
- await new Promise((resolve5, reject) => {
1106
+ await new Promise((resolve4, reject) => {
1089
1107
  socket.send(JSON.stringify({ type: "reply", msgUid, text }), (error) => {
1090
1108
  if (error) reject(error);
1091
- else resolve5();
1109
+ else resolve4();
1092
1110
  });
1093
1111
  });
1094
1112
  }
@@ -1382,35 +1400,14 @@ ${error.stderr}`);
1382
1400
  console.error("[server] agent run failed:", error);
1383
1401
  replySafe(reply, `Error: ${error instanceof Error ? error.message : String(error)}`);
1384
1402
  }
1385
- var entry = process.argv[1] ?? "";
1386
- if (/(^|[\\/])server\.(js|cjs|ts)$/.test(entry)) {
1387
- const configPath = process.argv[2];
1388
- if (!configPath) {
1389
- console.error("Usage: server.js <config-path>");
1390
- process.exit(1);
1391
- }
1392
- runBot((0, import_node_path6.resolve)(configPath)).catch((error) => {
1393
- console.error(error instanceof Error ? error.message : String(error));
1394
- const expected = error instanceof ConfigError || error instanceof LockError;
1395
- process.exit(expected ? 2 : 1);
1396
- });
1397
- }
1398
1403
 
1399
1404
  // src/cli.ts
1400
1405
  function processName(cwd) {
1401
- return `vbot-${(0, import_node_path7.basename)((0, import_node_path7.resolve)(cwd)).replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
1402
- }
1403
- var ENV_BIN = "/usr/bin/env";
1404
- function hasPm2() {
1405
- try {
1406
- (0, import_node_child_process2.execFileSync)(ENV_BIN, ["pm2", "--version"], { stdio: "ignore" });
1407
- return true;
1408
- } catch {
1409
- return false;
1410
- }
1406
+ return `vbot-${(0, import_node_path6.basename)((0, import_node_path6.resolve)(cwd)).replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
1411
1407
  }
1408
+ var ENV_BIN2 = "/usr/bin/env";
1412
1409
  function pm2(args, capture = false) {
1413
- return (0, import_node_child_process2.execFileSync)(ENV_BIN, ["pm2", ...args], {
1410
+ return (0, import_node_child_process3.execFileSync)(ENV_BIN2, ["pm2", ...args], {
1414
1411
  stdio: capture ? "pipe" : "inherit",
1415
1412
  encoding: "utf8"
1416
1413
  });
@@ -1434,12 +1431,14 @@ var program = new import_commander.Command();
1434
1431
  program.name("vbot").description("Connect local coding agents to vicvic.im").version(readPackageVersion(cliPath()));
1435
1432
  program.command("start").description("Start vbot (prompts for config on first run)").option("--foreground", "run in the foreground instead of pm2").option("-c, --config <path>", "config file path").action(async (options) => {
1436
1433
  const { path } = await ensureConfig(options.config);
1437
- if (options.foreground || !hasPm2()) {
1438
- if (!options.foreground) {
1439
- console.log(
1440
- import_picocolors2.default.yellow("pm2 not found; running in the foreground. Install pm2 for background mode.")
1441
- );
1442
- }
1434
+ if (options.foreground) {
1435
+ await runBot(path);
1436
+ return;
1437
+ }
1438
+ if (!hasPm2()) console.log(import_picocolors2.default.yellow("pm2 not found, installing globally..."));
1439
+ if (!ensurePm2()) {
1440
+ console.error(import_picocolors2.default.red("Failed to install pm2. Please install manually: npm i -g pm2"));
1441
+ console.log(import_picocolors2.default.yellow("Running in the foreground instead."));
1443
1442
  await runBot(path);
1444
1443
  return;
1445
1444
  }