@vicvic-im/agent-bot 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/{chunk-FYLVJB7J.js → chunk-QQ2NXJ3L.js} +2 -2
- package/dist/{chunk-DMDFB2QE.js → chunk-SCVC76UL.js} +2 -2
- package/dist/{chunk-DMDFB2QE.js.map → chunk-SCVC76UL.js.map} +1 -1
- package/dist/cli.cjs +53 -46
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +31 -22
- package/dist/cli.js.map +1 -1
- package/dist/core/cli-path.d.ts +8 -0
- package/dist/core/cli-path.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-FYLVJB7J.js.map → chunk-QQ2NXJ3L.js.map} +0 -0
package/dist/cli.cjs
CHANGED
|
@@ -25,8 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
|
|
26
26
|
// src/cli.ts
|
|
27
27
|
var import_node_child_process2 = require("child_process");
|
|
28
|
-
var
|
|
29
|
-
var import_node_path6 = require("path");
|
|
28
|
+
var import_node_path7 = require("path");
|
|
30
29
|
var import_commander = require("commander");
|
|
31
30
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
32
31
|
|
|
@@ -314,8 +313,28 @@ async function ensureConfig(explicit) {
|
|
|
314
313
|
return { config, path: target };
|
|
315
314
|
}
|
|
316
315
|
|
|
316
|
+
// src/core/cli-path.ts
|
|
317
|
+
var import_node_fs3 = require("fs");
|
|
318
|
+
var import_node_path3 = require("path");
|
|
319
|
+
function resolveServerEntry(cliPath2) {
|
|
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");
|
|
322
|
+
if (!(0, import_node_fs3.existsSync)(candidate)) {
|
|
323
|
+
throw new Error(`Server bundle not found at ${candidate}. Reinstall @vicvic-im/agent-bot.`);
|
|
324
|
+
}
|
|
325
|
+
return candidate;
|
|
326
|
+
}
|
|
327
|
+
function readPackageVersion(cliPath2) {
|
|
328
|
+
try {
|
|
329
|
+
const raw = (0, import_node_fs3.readFileSync)((0, import_node_path3.join)((0, import_node_path3.dirname)((0, import_node_fs3.realpathSync)(cliPath2)), "..", "package.json"), "utf8");
|
|
330
|
+
return JSON.parse(raw).version ?? "0.1.0";
|
|
331
|
+
} catch {
|
|
332
|
+
return "0.1.0";
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
317
336
|
// src/server.ts
|
|
318
|
-
var
|
|
337
|
+
var import_node_path6 = require("path");
|
|
319
338
|
|
|
320
339
|
// src/agents/acp.ts
|
|
321
340
|
var import_node_child_process = require("child_process");
|
|
@@ -701,7 +720,7 @@ var BotQueue = class {
|
|
|
701
720
|
};
|
|
702
721
|
|
|
703
722
|
// src/version.ts
|
|
704
|
-
var VBOT_VERSION = "0.1.
|
|
723
|
+
var VBOT_VERSION = "0.1.1";
|
|
705
724
|
|
|
706
725
|
// src/core/dispatcher.ts
|
|
707
726
|
var HELP_TEXT = `Available commands:
|
|
@@ -899,25 +918,25 @@ async function switchAgent(ctx, name) {
|
|
|
899
918
|
}
|
|
900
919
|
|
|
901
920
|
// src/core/lock.ts
|
|
902
|
-
var
|
|
903
|
-
var
|
|
921
|
+
var import_node_fs5 = require("fs");
|
|
922
|
+
var import_node_path5 = require("path");
|
|
904
923
|
|
|
905
924
|
// src/core/state.ts
|
|
906
925
|
var import_node_crypto = require("crypto");
|
|
907
|
-
var
|
|
926
|
+
var import_node_fs4 = require("fs");
|
|
908
927
|
var import_node_os2 = require("os");
|
|
909
|
-
var
|
|
928
|
+
var import_node_path4 = require("path");
|
|
910
929
|
function vbotHome() {
|
|
911
|
-
return process.env.VBOT_HOME?.trim() || (0,
|
|
930
|
+
return process.env.VBOT_HOME?.trim() || (0, import_node_path4.join)((0, import_node_os2.homedir)(), ".vbot");
|
|
912
931
|
}
|
|
913
932
|
function stateDir() {
|
|
914
|
-
return (0,
|
|
933
|
+
return (0, import_node_path4.join)(vbotHome(), "state");
|
|
915
934
|
}
|
|
916
935
|
function tokenHash(token) {
|
|
917
936
|
return (0, import_node_crypto.createHash)("sha256").update(token).digest("hex").slice(0, 16);
|
|
918
937
|
}
|
|
919
938
|
function statePath(token) {
|
|
920
|
-
return (0,
|
|
939
|
+
return (0, import_node_path4.join)(stateDir(), `${tokenHash(token)}.json`);
|
|
921
940
|
}
|
|
922
941
|
function emptyState(token, agent, cwd) {
|
|
923
942
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -933,9 +952,9 @@ function emptyState(token, agent, cwd) {
|
|
|
933
952
|
}
|
|
934
953
|
function loadState(token) {
|
|
935
954
|
const path = statePath(token);
|
|
936
|
-
if (!(0,
|
|
955
|
+
if (!(0, import_node_fs4.existsSync)(path)) return null;
|
|
937
956
|
try {
|
|
938
|
-
const parsed = JSON.parse((0,
|
|
957
|
+
const parsed = JSON.parse((0, import_node_fs4.readFileSync)(path, "utf8"));
|
|
939
958
|
if (typeof parsed.acpSessionId !== "string" && parsed.acpSessionId !== null) return null;
|
|
940
959
|
if (typeof parsed.agent !== "string") return null;
|
|
941
960
|
return {
|
|
@@ -953,12 +972,12 @@ function loadState(token) {
|
|
|
953
972
|
}
|
|
954
973
|
function saveState(state) {
|
|
955
974
|
const dir = stateDir();
|
|
956
|
-
(0,
|
|
957
|
-
const path = (0,
|
|
975
|
+
(0, import_node_fs4.mkdirSync)(dir, { recursive: true });
|
|
976
|
+
const path = (0, import_node_path4.join)(dir, `${state.tokenHash}.json`);
|
|
958
977
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
959
|
-
(0,
|
|
978
|
+
(0, import_node_fs4.writeFileSync)(tmp, `${JSON.stringify(state, null, 2)}
|
|
960
979
|
`, { mode: 384 });
|
|
961
|
-
(0,
|
|
980
|
+
(0, import_node_fs4.renameSync)(tmp, path);
|
|
962
981
|
}
|
|
963
982
|
|
|
964
983
|
// src/core/lock.ts
|
|
@@ -968,10 +987,10 @@ var LockError = class extends Error {
|
|
|
968
987
|
this.name = "LockError";
|
|
969
988
|
}
|
|
970
989
|
};
|
|
971
|
-
var lockPath = (token) => (0,
|
|
990
|
+
var lockPath = (token) => (0, import_node_path5.join)(stateDir(), `${tokenHash(token)}.lock`);
|
|
972
991
|
function readPid(path) {
|
|
973
992
|
try {
|
|
974
|
-
const pid = Number.parseInt((0,
|
|
993
|
+
const pid = Number.parseInt((0, import_node_fs5.readFileSync)(path, "utf8").trim(), 10);
|
|
975
994
|
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
976
995
|
} catch {
|
|
977
996
|
return null;
|
|
@@ -986,13 +1005,13 @@ function isAlive(pid) {
|
|
|
986
1005
|
}
|
|
987
1006
|
}
|
|
988
1007
|
function acquireLock(token) {
|
|
989
|
-
(0,
|
|
1008
|
+
(0, import_node_fs5.mkdirSync)(stateDir(), { recursive: true });
|
|
990
1009
|
const path = lockPath(token);
|
|
991
1010
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
992
1011
|
try {
|
|
993
|
-
const fd = (0,
|
|
994
|
-
(0,
|
|
995
|
-
(0,
|
|
1012
|
+
const fd = (0, import_node_fs5.openSync)(path, "wx");
|
|
1013
|
+
(0, import_node_fs5.writeSync)(fd, String(process.pid));
|
|
1014
|
+
(0, import_node_fs5.closeSync)(fd);
|
|
996
1015
|
return () => releaseLock(token);
|
|
997
1016
|
} catch (error) {
|
|
998
1017
|
if (!(error instanceof Error) || !("code" in error) || error.code !== "EEXIST") {
|
|
@@ -1003,7 +1022,7 @@ function acquireLock(token) {
|
|
|
1003
1022
|
throw new LockError(`This bot is already running in another vbot process (pid ${pid}).`);
|
|
1004
1023
|
}
|
|
1005
1024
|
try {
|
|
1006
|
-
(0,
|
|
1025
|
+
(0, import_node_fs5.unlinkSync)(path);
|
|
1007
1026
|
} catch {
|
|
1008
1027
|
}
|
|
1009
1028
|
}
|
|
@@ -1012,11 +1031,11 @@ function acquireLock(token) {
|
|
|
1012
1031
|
}
|
|
1013
1032
|
function releaseLock(token) {
|
|
1014
1033
|
const path = lockPath(token);
|
|
1015
|
-
if (!(0,
|
|
1034
|
+
if (!(0, import_node_fs5.existsSync)(path)) return;
|
|
1016
1035
|
const pid = readPid(path);
|
|
1017
1036
|
if (pid !== process.pid) return;
|
|
1018
1037
|
try {
|
|
1019
|
-
(0,
|
|
1038
|
+
(0, import_node_fs5.unlinkSync)(path);
|
|
1020
1039
|
} catch {
|
|
1021
1040
|
}
|
|
1022
1041
|
}
|
|
@@ -1370,7 +1389,7 @@ if (/(^|[\\/])server\.(js|cjs|ts)$/.test(entry)) {
|
|
|
1370
1389
|
console.error("Usage: server.js <config-path>");
|
|
1371
1390
|
process.exit(1);
|
|
1372
1391
|
}
|
|
1373
|
-
runBot((0,
|
|
1392
|
+
runBot((0, import_node_path6.resolve)(configPath)).catch((error) => {
|
|
1374
1393
|
console.error(error instanceof Error ? error.message : String(error));
|
|
1375
1394
|
const expected = error instanceof ConfigError || error instanceof LockError;
|
|
1376
1395
|
process.exit(expected ? 2 : 1);
|
|
@@ -1379,7 +1398,7 @@ if (/(^|[\\/])server\.(js|cjs|ts)$/.test(entry)) {
|
|
|
1379
1398
|
|
|
1380
1399
|
// src/cli.ts
|
|
1381
1400
|
function processName(cwd) {
|
|
1382
|
-
return `vbot-${(0,
|
|
1401
|
+
return `vbot-${(0, import_node_path7.basename)((0, import_node_path7.resolve)(cwd)).replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
1383
1402
|
}
|
|
1384
1403
|
var ENV_BIN = "/usr/bin/env";
|
|
1385
1404
|
function hasPm2() {
|
|
@@ -1406,25 +1425,13 @@ function resolveName(configPath) {
|
|
|
1406
1425
|
return "vbot";
|
|
1407
1426
|
}
|
|
1408
1427
|
}
|
|
1409
|
-
function
|
|
1410
|
-
const
|
|
1411
|
-
if (!
|
|
1412
|
-
|
|
1413
|
-
if (!(0, import_node_fs5.existsSync)(candidate)) {
|
|
1414
|
-
throw new Error(`Server bundle not found at ${candidate}. Run "pnpm build" first.`);
|
|
1415
|
-
}
|
|
1416
|
-
return candidate;
|
|
1428
|
+
function cliPath() {
|
|
1429
|
+
const path = process.argv[1];
|
|
1430
|
+
if (!path) throw new Error("Cannot resolve vbot entry; run the installed binary.");
|
|
1431
|
+
return path;
|
|
1417
1432
|
}
|
|
1418
1433
|
var program = new import_commander.Command();
|
|
1419
|
-
program.name("vbot").description("Connect local coding agents to vicvic.im").version(
|
|
1420
|
-
function readVersion() {
|
|
1421
|
-
try {
|
|
1422
|
-
const raw = (0, import_node_fs5.readFileSync)((0, import_node_path6.join)((0, import_node_path6.dirname)(process.argv[1] ?? ""), "..", "package.json"), "utf8");
|
|
1423
|
-
return JSON.parse(raw).version ?? "0.1.0";
|
|
1424
|
-
} catch {
|
|
1425
|
-
return "0.1.0";
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1434
|
+
program.name("vbot").description("Connect local coding agents to vicvic.im").version(readPackageVersion(cliPath()));
|
|
1428
1435
|
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) => {
|
|
1429
1436
|
const { path } = await ensureConfig(options.config);
|
|
1430
1437
|
if (options.foreground || !hasPm2()) {
|
|
@@ -1443,7 +1450,7 @@ program.command("start").description("Start vbot (prompts for config on first ru
|
|
|
1443
1450
|
} catch {
|
|
1444
1451
|
pm2([
|
|
1445
1452
|
"start",
|
|
1446
|
-
|
|
1453
|
+
resolveServerEntry(cliPath()),
|
|
1447
1454
|
"--name",
|
|
1448
1455
|
name,
|
|
1449
1456
|
"--stop-exit-codes",
|