@vicvic-im/agent-bot 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/README.md +1 -1
- package/dist/bin-server.cjs +1292 -0
- package/dist/bin-server.cjs.map +1 -0
- package/dist/bin-server.d.ts +2 -0
- package/dist/bin-server.d.ts.map +1 -0
- package/dist/bin-server.js +19 -0
- package/dist/bin-server.js.map +1 -0
- package/dist/{chunk-FYLVJB7J.js → chunk-6CK4XIJB.js} +2 -2
- package/dist/{chunk-DMDFB2QE.js → chunk-X5QSWCDH.js} +19 -35
- package/dist/chunk-X5QSWCDH.js.map +1 -0
- package/dist/cli.cjs +93 -87
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +58 -34
- 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/core/pm2.d.ts +7 -0
- package/dist/core/pm2.d.ts.map +1 -0
- package/dist/index.cjs +12 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/server.cjs +12 -26
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-DMDFB2QE.js.map +0 -1
- /package/dist/{chunk-FYLVJB7J.js.map → chunk-6CK4XIJB.js.map} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,33 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ensureConfig
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6CK4XIJB.js";
|
|
5
5
|
import {
|
|
6
6
|
findConfigPath,
|
|
7
7
|
loadConfig,
|
|
8
8
|
runBot
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-X5QSWCDH.js";
|
|
10
10
|
|
|
11
11
|
// src/cli.ts
|
|
12
|
-
import { execFileSync } from "child_process";
|
|
13
|
-
import {
|
|
14
|
-
import { basename, dirname, join, resolve } from "path";
|
|
12
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
13
|
+
import { basename, resolve } from "path";
|
|
15
14
|
import { Command } from "commander";
|
|
16
15
|
import pc from "picocolors";
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
// src/core/cli-path.ts
|
|
18
|
+
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
19
|
+
import { dirname, join } from "path";
|
|
20
|
+
function resolveServerEntry(cliPath2) {
|
|
21
|
+
const real = realpathSync(cliPath2);
|
|
22
|
+
const candidate = join(dirname(real), "bin-server.js");
|
|
23
|
+
if (!existsSync(candidate)) {
|
|
24
|
+
throw new Error(`Server bundle not found at ${candidate}. Reinstall @vicvic-im/agent-bot.`);
|
|
25
|
+
}
|
|
26
|
+
return candidate;
|
|
19
27
|
}
|
|
28
|
+
function readPackageVersion(cliPath2) {
|
|
29
|
+
try {
|
|
30
|
+
const raw = readFileSync(join(dirname(realpathSync(cliPath2)), "..", "package.json"), "utf8");
|
|
31
|
+
return JSON.parse(raw).version ?? "0.1.0";
|
|
32
|
+
} catch {
|
|
33
|
+
return "0.1.0";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/core/pm2.ts
|
|
38
|
+
import { execFileSync } from "child_process";
|
|
20
39
|
var ENV_BIN = "/usr/bin/env";
|
|
21
|
-
function hasPm2() {
|
|
40
|
+
function hasPm2(exec = execFileSync) {
|
|
22
41
|
try {
|
|
23
|
-
|
|
42
|
+
exec(ENV_BIN, ["pm2", "--version"], { stdio: "ignore" });
|
|
24
43
|
return true;
|
|
25
44
|
} catch {
|
|
26
45
|
return false;
|
|
27
46
|
}
|
|
28
47
|
}
|
|
48
|
+
function ensurePm2(exec = execFileSync) {
|
|
49
|
+
if (hasPm2(exec)) return true;
|
|
50
|
+
try {
|
|
51
|
+
exec(ENV_BIN, ["npm", "i", "-g", "pm2"], { stdio: "inherit" });
|
|
52
|
+
return hasPm2(exec);
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/cli.ts
|
|
59
|
+
function processName(cwd) {
|
|
60
|
+
return `vbot-${basename(resolve(cwd)).replace(/[^a-zA-Z0-9._-]+/g, "-")}`;
|
|
61
|
+
}
|
|
62
|
+
var ENV_BIN2 = "/usr/bin/env";
|
|
29
63
|
function pm2(args, capture = false) {
|
|
30
|
-
return
|
|
64
|
+
return execFileSync2(ENV_BIN2, ["pm2", ...args], {
|
|
31
65
|
stdio: capture ? "pipe" : "inherit",
|
|
32
66
|
encoding: "utf8"
|
|
33
67
|
});
|
|
@@ -42,33 +76,23 @@ function resolveName(configPath) {
|
|
|
42
76
|
return "vbot";
|
|
43
77
|
}
|
|
44
78
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
if (!existsSync(candidate)) {
|
|
50
|
-
throw new Error(`Server bundle not found at ${candidate}. Run "pnpm build" first.`);
|
|
51
|
-
}
|
|
52
|
-
return candidate;
|
|
79
|
+
function cliPath() {
|
|
80
|
+
const path = process.argv[1];
|
|
81
|
+
if (!path) throw new Error("Cannot resolve vbot entry; run the installed binary.");
|
|
82
|
+
return path;
|
|
53
83
|
}
|
|
54
84
|
var program = new Command();
|
|
55
|
-
program.name("vbot").description("Connect local coding agents to vicvic.im").version(
|
|
56
|
-
function readVersion() {
|
|
57
|
-
try {
|
|
58
|
-
const raw = readFileSync(join(dirname(process.argv[1] ?? ""), "..", "package.json"), "utf8");
|
|
59
|
-
return JSON.parse(raw).version ?? "0.1.0";
|
|
60
|
-
} catch {
|
|
61
|
-
return "0.1.0";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
85
|
+
program.name("vbot").description("Connect local coding agents to vicvic.im").version(readPackageVersion(cliPath()));
|
|
64
86
|
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) => {
|
|
65
87
|
const { path } = await ensureConfig(options.config);
|
|
66
|
-
if (options.foreground
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
if (options.foreground) {
|
|
89
|
+
await runBot(path);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!hasPm2()) console.log(pc.yellow("pm2 not found, installing globally..."));
|
|
93
|
+
if (!ensurePm2()) {
|
|
94
|
+
console.error(pc.red("Failed to install pm2. Please install manually: npm i -g pm2"));
|
|
95
|
+
console.log(pc.yellow("Running in the foreground instead."));
|
|
72
96
|
await runBot(path);
|
|
73
97
|
return;
|
|
74
98
|
}
|
|
@@ -79,7 +103,7 @@ program.command("start").description("Start vbot (prompts for config on first ru
|
|
|
79
103
|
} catch {
|
|
80
104
|
pm2([
|
|
81
105
|
"start",
|
|
82
|
-
|
|
106
|
+
resolveServerEntry(cliPath()),
|
|
83
107
|
"--name",
|
|
84
108
|
name,
|
|
85
109
|
"--stop-exit-codes",
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { execFileSync } from \"node:child_process\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/core/cli-path.ts","../src/core/pm2.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { execFileSync } from \"node:child_process\";\nimport { basename, resolve } from \"node:path\";\nimport { Command } from \"commander\";\nimport pc from \"picocolors\";\nimport { ensureConfig } from \"./commands/setup.js\";\nimport { findConfigPath, loadConfig } from \"./config.js\";\nimport { readPackageVersion, resolveServerEntry } from \"./core/cli-path.js\";\nimport { ensurePm2, hasPm2 } from \"./core/pm2.js\";\nimport { runBot } from \"./server.js\";\n\ninterface GlobalOptions {\n config?: string;\n}\n\nfunction processName(cwd: string): string {\n return `vbot-${basename(resolve(cwd)).replace(/[^a-zA-Z0-9._-]+/g, \"-\")}`;\n}\n\n// pm2 是可选的外部工具。通过固定的 /usr/bin/env 调用,避免把任意 PATH 条目当作可执行文件;\n// Windows 一期不承诺后台模式,检测失败时退回前台运行。\nconst ENV_BIN = \"/usr/bin/env\";\n\nfunction pm2(args: string[], capture = false): string {\n return execFileSync(ENV_BIN, [\"pm2\", ...args], {\n stdio: capture ? \"pipe\" : \"inherit\",\n encoding: \"utf8\",\n });\n}\n\nfunction resolveName(configPath?: string): string {\n const path = findConfigPath(configPath);\n if (!path) return \"vbot\";\n try {\n const { config } = loadConfig(path);\n return processName(config.agent.cwd);\n } catch {\n return \"vbot\";\n }\n}\n\nfunction cliPath(): string {\n const path = process.argv[1];\n if (!path) throw new Error(\"Cannot resolve vbot entry; run the installed binary.\");\n return path;\n}\n\nconst program = new Command();\nprogram\n .name(\"vbot\")\n .description(\"Connect local coding agents to vicvic.im\")\n .version(readPackageVersion(cliPath()));\n\nprogram\n .command(\"start\")\n .description(\"Start vbot (prompts for config on first run)\")\n .option(\"--foreground\", \"run in the foreground instead of pm2\")\n .option(\"-c, --config <path>\", \"config file path\")\n .action(async (options: GlobalOptions & { foreground?: boolean }) => {\n const { path } = await ensureConfig(options.config);\n if (options.foreground) {\n await runBot(path);\n return;\n }\n if (!hasPm2()) console.log(pc.yellow(\"pm2 not found, installing globally...\"));\n if (!ensurePm2()) {\n console.error(pc.red(\"Failed to install pm2. Please install manually: npm i -g pm2\"));\n console.log(pc.yellow(\"Running in the foreground instead.\"));\n await runBot(path);\n return;\n }\n const name = resolveName(path);\n try {\n pm2([\"describe\", name], true);\n pm2([\"restart\", name, \"--update-env\"]);\n } catch {\n pm2([\n \"start\",\n resolveServerEntry(cliPath()),\n \"--name\",\n name,\n \"--stop-exit-codes\",\n \"2\",\n \"--log-date-format\",\n \"YYYY-MM-DD HH:mm:ss\",\n \"--\",\n path,\n ]);\n }\n pm2([\"save\"], true);\n console.log(pc.green(`✔ ${name} started. Use \"vbot logs\" to view output.`));\n });\n\nprogram\n .command(\"stop\")\n .option(\"-c, --config <path>\", \"config file path\")\n .action((options: GlobalOptions) => {\n try {\n pm2([\"stop\", resolveName(options.config)]);\n } catch {\n console.error(pc.red(\"Failed to stop vbot. Is it running?\"));\n }\n });\n\nprogram\n .command(\"restart\")\n .option(\"-c, --config <path>\", \"config file path\")\n .action((options: GlobalOptions) => {\n try {\n pm2([\"restart\", resolveName(options.config), \"--update-env\"]);\n } catch {\n console.error(pc.red('Failed to restart vbot. Try \"vbot start\".'));\n }\n });\n\nprogram\n .command(\"status\")\n .option(\"-c, --config <path>\", \"config file path\")\n .action((options: GlobalOptions) => {\n try {\n pm2([\"describe\", resolveName(options.config)]);\n } catch {\n console.log(pc.yellow(\"vbot is not running.\"));\n }\n });\n\nprogram\n .command(\"logs\")\n .option(\"-c, --config <path>\", \"config file path\")\n .action((options: GlobalOptions) => {\n try {\n pm2([\"logs\", resolveName(options.config), \"--lines\", \"50\"]);\n } catch {\n console.error(\"Failed to show logs. Is pm2 installed?\");\n }\n });\n\nprogram\n .command(\"delete\")\n .option(\"-c, --config <path>\", \"config file path\")\n .action((options: GlobalOptions) => {\n try {\n pm2([\"delete\", resolveName(options.config)]);\n } catch {\n console.error(\"Failed to delete vbot process.\");\n }\n });\n\nprogram.parseAsync(process.argv).catch((error: unknown) => {\n console.error(pc.red(error instanceof Error ? error.message : String(error)));\n process.exitCode = 1;\n});\n","import { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\n/**\n * 全局安装时 argv[1] 是 bin 目录的符号链接(如 ~/.nvm/.../bin/vbot),\n * 必须 realpath 后定位包内同目录的 server.js;直接 dirname(argv[1]) 会指向 bin 目录。\n */\nexport function resolveServerEntry(cliPath: string): string {\n const real = realpathSync(cliPath);\n const candidate = join(dirname(real), \"bin-server.js\");\n if (!existsSync(candidate)) {\n throw new Error(`Server bundle not found at ${candidate}. Reinstall @vicvic-im/agent-bot.`);\n }\n return candidate;\n}\n\n/** 从真实 dist/cli.js 位置向上读取包版本,避免符号链接导致读错 package.json。 */\nexport function readPackageVersion(cliPath: string): string {\n try {\n const raw = readFileSync(join(dirname(realpathSync(cliPath)), \"..\", \"package.json\"), \"utf8\");\n return (JSON.parse(raw) as { version?: string }).version ?? \"0.1.0\";\n } catch {\n return \"0.1.0\";\n }\n}\n","import { execFileSync } from \"node:child_process\";\n\n// pm2 是可选的外部工具。通过固定的 /usr/bin/env 调用,避免把任意 PATH 条目当作可执行文件。\nconst ENV_BIN = \"/usr/bin/env\";\n\ntype Exec = typeof execFileSync;\n\nexport function hasPm2(exec: Exec = execFileSync): boolean {\n try {\n exec(ENV_BIN, [\"pm2\", \"--version\"], { stdio: \"ignore\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/** 与 ccbot 一致:pm2 缺失时自动全局安装;安装失败返回 false,由调用方退前台。 */\nexport function ensurePm2(exec: Exec = execFileSync): boolean {\n if (hasPm2(exec)) return true;\n try {\n exec(ENV_BIN, [\"npm\", \"i\", \"-g\", \"pm2\"], { stdio: \"inherit\" });\n return hasPm2(exec);\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,UAAU,eAAe;AAClC,SAAS,eAAe;AACxB,OAAO,QAAQ;;;ACJf,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,SAAS,YAAY;AAMvB,SAAS,mBAAmBC,UAAyB;AAC1D,QAAM,OAAO,aAAaA,QAAO;AACjC,QAAM,YAAY,KAAK,QAAQ,IAAI,GAAG,eAAe;AACrD,MAAI,CAAC,WAAW,SAAS,GAAG;AAC1B,UAAM,IAAI,MAAM,8BAA8B,SAAS,mCAAmC;AAAA,EAC5F;AACA,SAAO;AACT;AAGO,SAAS,mBAAmBA,UAAyB;AAC1D,MAAI;AACF,UAAM,MAAM,aAAa,KAAK,QAAQ,aAAaA,QAAO,CAAC,GAAG,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
|
+
* 必须 realpath 后定位包内同目录的 server.js;直接 dirname(argv[1]) 会指向 bin 目录。
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveServerEntry(cliPath: string): string;
|
|
6
|
+
/** 从真实 dist/cli.js 位置向上读取包版本,避免符号链接导致读错 package.json。 */
|
|
7
|
+
export declare function readPackageVersion(cliPath: string): string;
|
|
8
|
+
//# sourceMappingURL=cli-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-path.d.ts","sourceRoot":"","sources":["../../src/core/cli-path.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAO1D;AAED,yDAAyD;AACzD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAO1D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
type Exec = typeof execFileSync;
|
|
3
|
+
export declare function hasPm2(exec?: Exec): boolean;
|
|
4
|
+
/** 与 ccbot 一致:pm2 缺失时自动全局安装;安装失败返回 false,由调用方退前台。 */
|
|
5
|
+
export declare function ensurePm2(exec?: Exec): boolean;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=pm2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pm2.d.ts","sourceRoot":"","sources":["../../src/core/pm2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,KAAK,IAAI,GAAG,OAAO,YAAY,CAAC;AAEhC,wBAAgB,MAAM,CAAC,IAAI,GAAE,IAAmB,GAAG,OAAO,CAOzD;AAED,qDAAqD;AACrD,wBAAgB,SAAS,CAAC,IAAI,GAAE,IAAmB,GAAG,OAAO,CAQ5D"}
|
package/dist/index.cjs
CHANGED
|
@@ -175,11 +175,11 @@ function parseEnv(value) {
|
|
|
175
175
|
if (value === void 0 || value === null) return void 0;
|
|
176
176
|
const record = asRecord(value, "agent.env");
|
|
177
177
|
const env = {};
|
|
178
|
-
for (const [key,
|
|
179
|
-
if (typeof
|
|
178
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
179
|
+
if (typeof entry !== "string") {
|
|
180
180
|
throw new ConfigError(`Invalid "agent.env.${key}": expected a string`);
|
|
181
181
|
}
|
|
182
|
-
env[key] =
|
|
182
|
+
env[key] = entry;
|
|
183
183
|
}
|
|
184
184
|
return env;
|
|
185
185
|
}
|
|
@@ -223,7 +223,7 @@ function parseAgent(root, configDir) {
|
|
|
223
223
|
return {
|
|
224
224
|
name: agentName,
|
|
225
225
|
command: optionalString(agentRaw.command, "agent.command"),
|
|
226
|
-
args: Array.isArray(argsRaw) ? argsRaw.map((
|
|
226
|
+
args: Array.isArray(argsRaw) ? argsRaw.map((entry) => String(entry)) : void 0,
|
|
227
227
|
cwd,
|
|
228
228
|
model: optionalString(agentRaw.model, "agent.model") ?? null,
|
|
229
229
|
env: parseEnv(agentRaw.env)
|
|
@@ -559,7 +559,7 @@ var AcpAgent = class {
|
|
|
559
559
|
);
|
|
560
560
|
pending.catch(() => void 0);
|
|
561
561
|
const response = await Promise.race([pending, aborted]);
|
|
562
|
-
await new Promise((
|
|
562
|
+
await new Promise((resolve3) => setImmediate(resolve3));
|
|
563
563
|
if (response.stopReason === "cancelled" || request.signal.aborted) {
|
|
564
564
|
throw new AgentAbortError();
|
|
565
565
|
}
|
|
@@ -592,7 +592,7 @@ var AcpAgent = class {
|
|
|
592
592
|
return true;
|
|
593
593
|
}
|
|
594
594
|
const option = this.configOptions.find(
|
|
595
|
-
(
|
|
595
|
+
(entry) => entry.type === "select" && (entry.id === "model" || entry.category === "model")
|
|
596
596
|
);
|
|
597
597
|
if (!option) return false;
|
|
598
598
|
await this.ctx.request(acp.methods.agent.session.setConfigOption, {
|
|
@@ -618,8 +618,8 @@ var AcpAgent = class {
|
|
|
618
618
|
} catch {
|
|
619
619
|
}
|
|
620
620
|
if (!child || child.exitCode !== null) return;
|
|
621
|
-
const exited = new Promise((
|
|
622
|
-
child.once("exit", () =>
|
|
621
|
+
const exited = new Promise((resolve3) => {
|
|
622
|
+
child.once("exit", () => resolve3());
|
|
623
623
|
});
|
|
624
624
|
child.kill("SIGTERM");
|
|
625
625
|
const timer = setTimeout(() => child.kill("SIGKILL"), 3e3);
|
|
@@ -736,7 +736,7 @@ var BotQueue = class {
|
|
|
736
736
|
};
|
|
737
737
|
|
|
738
738
|
// src/version.ts
|
|
739
|
-
var VBOT_VERSION = "0.1.
|
|
739
|
+
var VBOT_VERSION = "0.1.2";
|
|
740
740
|
|
|
741
741
|
// src/core/dispatcher.ts
|
|
742
742
|
var HELP_TEXT = `Available commands:
|
|
@@ -817,7 +817,7 @@ function handleAgent(runtime, args, send) {
|
|
|
817
817
|
const name = args.join(" ").trim();
|
|
818
818
|
if (!name) {
|
|
819
819
|
const current = runtime.config().agent.name;
|
|
820
|
-
const list = AGENT_NAMES.map((
|
|
820
|
+
const list = AGENT_NAMES.map((entry) => `${entry === current ? "*" : " "} ${entry}`).join("\n");
|
|
821
821
|
send(`Current agent: ${current}
|
|
822
822
|
Available agents:
|
|
823
823
|
${list}`);
|
|
@@ -1074,10 +1074,10 @@ var VicvicWire = class {
|
|
|
1074
1074
|
if (!socket || socket.readyState !== import_ws.default.OPEN) {
|
|
1075
1075
|
throw new Error("Bot connection is not open");
|
|
1076
1076
|
}
|
|
1077
|
-
await new Promise((
|
|
1077
|
+
await new Promise((resolve3, reject) => {
|
|
1078
1078
|
socket.send(JSON.stringify({ type: "reply", msgUid, text }), (error) => {
|
|
1079
1079
|
if (error) reject(error);
|
|
1080
|
-
else
|
|
1080
|
+
else resolve3();
|
|
1081
1081
|
});
|
|
1082
1082
|
});
|
|
1083
1083
|
}
|
|
@@ -1201,9 +1201,6 @@ function splitMessage(text, max = MAX_MESSAGE_CHARS) {
|
|
|
1201
1201
|
return chunks;
|
|
1202
1202
|
}
|
|
1203
1203
|
|
|
1204
|
-
// src/server.ts
|
|
1205
|
-
var import_node_path5 = require("path");
|
|
1206
|
-
|
|
1207
1204
|
// src/core/gate.ts
|
|
1208
1205
|
function createGate() {
|
|
1209
1206
|
let tail = Promise.resolve();
|
|
@@ -1410,19 +1407,6 @@ ${error.stderr}`);
|
|
|
1410
1407
|
console.error("[server] agent run failed:", error);
|
|
1411
1408
|
replySafe(reply, `Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1412
1409
|
}
|
|
1413
|
-
var entry = process.argv[1] ?? "";
|
|
1414
|
-
if (/(^|[\\/])server\.(js|cjs|ts)$/.test(entry)) {
|
|
1415
|
-
const configPath = process.argv[2];
|
|
1416
|
-
if (!configPath) {
|
|
1417
|
-
console.error("Usage: server.js <config-path>");
|
|
1418
|
-
process.exit(1);
|
|
1419
|
-
}
|
|
1420
|
-
runBot((0, import_node_path5.resolve)(configPath)).catch((error) => {
|
|
1421
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
1422
|
-
const expected = error instanceof ConfigError || error instanceof LockError;
|
|
1423
|
-
process.exit(expected ? 2 : 1);
|
|
1424
|
-
});
|
|
1425
|
-
}
|
|
1426
1410
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1427
1411
|
0 && (module.exports = {
|
|
1428
1412
|
AGENTS,
|