@modelzen/feishu-codex-bridge 0.2.2-win → 0.2.3-win
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.js +146 -121
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3556,9 +3556,9 @@ function buildGroupSettingsCard(project) {
|
|
|
3556
3556
|
}
|
|
3557
3557
|
|
|
3558
3558
|
// src/service/update.ts
|
|
3559
|
-
import { execFile, spawn as
|
|
3560
|
-
import { existsSync as
|
|
3561
|
-
import { dirname as
|
|
3559
|
+
import { execFile, spawn as spawn5 } from "child_process";
|
|
3560
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
3561
|
+
import { dirname as dirname9, join as join11, resolve as resolve5 } from "path";
|
|
3562
3562
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
3563
3563
|
import { promisify } from "util";
|
|
3564
3564
|
|
|
@@ -3792,126 +3792,150 @@ function launchctlError(command, result) {
|
|
|
3792
3792
|
return new Error(`${command} \u5931\u8D25\uFF08exit ${result.status ?? "unknown"}\uFF09${output ? `\uFF1A${output}` : ""}`);
|
|
3793
3793
|
}
|
|
3794
3794
|
|
|
3795
|
-
// src/service/
|
|
3796
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
3797
|
-
import {
|
|
3798
|
-
import { mkdir as mkdir7,
|
|
3799
|
-
import {
|
|
3800
|
-
var
|
|
3795
|
+
// src/service/win-startup.ts
|
|
3796
|
+
import { spawn as spawn4, spawnSync as spawnSync2 } from "child_process";
|
|
3797
|
+
import { openSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "fs";
|
|
3798
|
+
import { mkdir as mkdir7, writeFile as writeFile6 } from "fs/promises";
|
|
3799
|
+
import { join as join9 } from "path";
|
|
3800
|
+
var RUN_KEY_PATH = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
3801
|
+
var RUN_KEY_NAME = "feishu-codex-bridge";
|
|
3802
|
+
var SERVICE_ENV_FLAG = "FEISHU_CODEX_BRIDGE_SERVICE";
|
|
3801
3803
|
function launcherCmdPath() {
|
|
3802
3804
|
return join9(paths.appDir, "service-launcher.cmd");
|
|
3803
3805
|
}
|
|
3806
|
+
function launcherVbsPath() {
|
|
3807
|
+
return join9(paths.appDir, "service-launcher.vbs");
|
|
3808
|
+
}
|
|
3809
|
+
function servicePidFile() {
|
|
3810
|
+
return join9(paths.appDir, "service.pid");
|
|
3811
|
+
}
|
|
3804
3812
|
function buildLauncherCmd() {
|
|
3805
|
-
const nodePath = process.execPath;
|
|
3806
|
-
const cliBinPath = resolveCliBinPath();
|
|
3807
|
-
const pathEnv = process.env.PATH ?? "";
|
|
3808
3813
|
return [
|
|
3809
3814
|
"@echo off",
|
|
3810
|
-
`set "PATH=${
|
|
3811
|
-
`
|
|
3815
|
+
`set "PATH=${process.env.PATH ?? ""}"`,
|
|
3816
|
+
`set "${SERVICE_ENV_FLAG}=1"`,
|
|
3817
|
+
`"${process.execPath}" "${resolveCliBinPath()}" run >> "${serviceStdoutPath()}" 2>> "${serviceStderrPath()}"`,
|
|
3812
3818
|
""
|
|
3813
3819
|
].join("\r\n");
|
|
3814
3820
|
}
|
|
3815
|
-
function
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
};
|
|
3821
|
+
function buildLauncherVbs() {
|
|
3822
|
+
return [
|
|
3823
|
+
"' Auto-generated by feishu-codex-bridge. Do not edit.",
|
|
3824
|
+
'Set sh = CreateObject("WScript.Shell")',
|
|
3825
|
+
`sh.Run "cmd /c ""${launcherCmdPath()}""", 0, False`,
|
|
3826
|
+
""
|
|
3827
|
+
].join("\r\n");
|
|
3823
3828
|
}
|
|
3824
|
-
function
|
|
3825
|
-
const out =
|
|
3826
|
-
|
|
3829
|
+
function startNow() {
|
|
3830
|
+
const out = openSync(serviceStdoutPath(), "a");
|
|
3831
|
+
const err = openSync(serviceStderrPath(), "a");
|
|
3832
|
+
const child = spawn4(process.execPath, [resolveCliBinPath(), "run"], {
|
|
3833
|
+
detached: true,
|
|
3834
|
+
windowsHide: true,
|
|
3835
|
+
stdio: ["ignore", out, err],
|
|
3836
|
+
env: mergeProcessEnv(process.env, { [SERVICE_ENV_FLAG]: "1" })
|
|
3837
|
+
});
|
|
3838
|
+
if (child.pid) writeFileSync(servicePidFile(), String(child.pid), "utf8");
|
|
3839
|
+
child.unref();
|
|
3840
|
+
}
|
|
3841
|
+
async function installWinStartup() {
|
|
3842
|
+
await mkdir7(paths.appDir, { recursive: true });
|
|
3843
|
+
await ensureLogFiles();
|
|
3844
|
+
await writeFile6(launcherCmdPath(), buildLauncherCmd(), "utf8");
|
|
3845
|
+
await writeFile6(launcherVbsPath(), buildLauncherVbs(), "utf8");
|
|
3846
|
+
const reg = spawnSync2(
|
|
3847
|
+
"reg",
|
|
3848
|
+
["add", RUN_KEY_PATH, "/v", RUN_KEY_NAME, "/t", "REG_SZ", "/d", `wscript.exe "${launcherVbsPath()}"`, "/f"],
|
|
3849
|
+
{ encoding: "utf8" }
|
|
3850
|
+
);
|
|
3851
|
+
if (reg.status !== 0) {
|
|
3852
|
+
throw new Error(`\u5199\u5165\u767B\u5F55\u81EA\u542F\u6CE8\u518C\u8868\u9879\u5931\u8D25\uFF08exit ${reg.status ?? "unknown"}\uFF09\uFF1A${(reg.stderr || reg.stdout || "").trim()}`);
|
|
3853
|
+
}
|
|
3854
|
+
startNow();
|
|
3855
|
+
return statusWinStartup();
|
|
3856
|
+
}
|
|
3857
|
+
async function uninstallWinStartup() {
|
|
3858
|
+
spawnSync2("reg", ["delete", RUN_KEY_PATH, "/v", RUN_KEY_NAME, "/f"], { stdio: "ignore" });
|
|
3859
|
+
killService();
|
|
3860
|
+
rmSync(servicePidFile(), { force: true });
|
|
3827
3861
|
}
|
|
3828
|
-
async function
|
|
3829
|
-
|
|
3830
|
-
|
|
3862
|
+
async function restartWinStartup() {
|
|
3863
|
+
if (!isInstalled()) {
|
|
3864
|
+
throw new Error("\u767B\u5F55\u81EA\u542F\u672A\u5B89\u88C5\uFF08\u5148\u8FD0\u884C `feishu-codex-bridge start`\uFF09\u3002");
|
|
3865
|
+
}
|
|
3831
3866
|
await ensureLogFiles();
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
"ONLOGON",
|
|
3841
|
-
"/RL",
|
|
3842
|
-
"LIMITED",
|
|
3843
|
-
"/TN",
|
|
3844
|
-
WINDOWS_TASK_NAME,
|
|
3845
|
-
"/TR",
|
|
3846
|
-
`"${launcherCmdPath()}"`
|
|
3847
|
-
]);
|
|
3848
|
-
if (!create.ok) throw schtasksError("schtasks /Create", create);
|
|
3849
|
-
const run = runSchtasks(["/Run", "/TN", WINDOWS_TASK_NAME]);
|
|
3850
|
-
if (!run.ok) throw schtasksError("schtasks /Run", run);
|
|
3851
|
-
return statusSchtask();
|
|
3852
|
-
}
|
|
3853
|
-
async function uninstallSchtask() {
|
|
3854
|
-
runSchtasks(["/End", "/TN", WINDOWS_TASK_NAME]);
|
|
3855
|
-
const del = runSchtasks(["/Delete", "/F", "/TN", WINDOWS_TASK_NAME]);
|
|
3856
|
-
if (!del.ok && isTaskRegistered()) throw schtasksError("schtasks /Delete", del);
|
|
3857
|
-
if (existsSync5(launcherCmdPath())) await rm3(launcherCmdPath(), { force: true });
|
|
3858
|
-
}
|
|
3859
|
-
async function restartSchtask() {
|
|
3860
|
-
if (!isTaskRegistered()) {
|
|
3861
|
-
throw new Error(`\u8BA1\u5212\u4EFB\u52A1\u672A\u5B89\u88C5\uFF1A${WINDOWS_TASK_NAME}\uFF08\u5148\u8FD0\u884C \`feishu-codex-bridge start\`\uFF09`);
|
|
3862
|
-
}
|
|
3863
|
-
runSchtasks(["/End", "/TN", WINDOWS_TASK_NAME]);
|
|
3864
|
-
await waitUntilStopped();
|
|
3865
|
-
const run = runSchtasks(["/Run", "/TN", WINDOWS_TASK_NAME]);
|
|
3866
|
-
if (!run.ok) throw schtasksError("schtasks /Run", run);
|
|
3867
|
-
return statusSchtask();
|
|
3868
|
-
}
|
|
3869
|
-
function statusSchtask() {
|
|
3870
|
-
const installed = isTaskRegistered();
|
|
3871
|
-
const raw = installed ? describeTask() : "";
|
|
3867
|
+
killService();
|
|
3868
|
+
startNow();
|
|
3869
|
+
return statusWinStartup();
|
|
3870
|
+
}
|
|
3871
|
+
function statusWinStartup() {
|
|
3872
|
+
const installed = isInstalled();
|
|
3873
|
+
const pid = readServicePid();
|
|
3874
|
+
const running = pid !== null && pidAlive(pid);
|
|
3872
3875
|
return {
|
|
3873
|
-
platformName: "
|
|
3876
|
+
platformName: "Windows \u767B\u5F55\u81EA\u542F\uFF08HKCU Run\uFF0C\u514D\u7BA1\u7406\u5458\uFF09",
|
|
3874
3877
|
installed,
|
|
3875
|
-
running
|
|
3876
|
-
servicePath:
|
|
3878
|
+
running,
|
|
3879
|
+
servicePath: `${RUN_KEY_PATH}\\${RUN_KEY_NAME}`,
|
|
3877
3880
|
stdoutPath: serviceStdoutPath(),
|
|
3878
3881
|
stderrPath: serviceStderrPath(),
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
// `Last Result: 0` ⇒ last run succeeded. Surface it as the exit code.
|
|
3882
|
-
lastExit: raw.match(/Last Result:\s*(-?\d+)/i)?.[1],
|
|
3883
|
-
raw
|
|
3882
|
+
pid: running && pid !== null ? String(pid) : void 0,
|
|
3883
|
+
raw: ""
|
|
3884
3884
|
};
|
|
3885
3885
|
}
|
|
3886
|
-
function
|
|
3887
|
-
const
|
|
3886
|
+
function winStartupRunning() {
|
|
3887
|
+
const pid = readServicePid();
|
|
3888
|
+
return pid !== null && pidAlive(pid);
|
|
3889
|
+
}
|
|
3890
|
+
function recordServicePid() {
|
|
3891
|
+
if (process.platform !== "win32" || !process.env[SERVICE_ENV_FLAG]) return;
|
|
3892
|
+
try {
|
|
3893
|
+
writeFileSync(servicePidFile(), String(process.pid), "utf8");
|
|
3894
|
+
} catch {
|
|
3895
|
+
}
|
|
3896
|
+
process.once("exit", clearServicePid);
|
|
3897
|
+
}
|
|
3898
|
+
function clearServicePid() {
|
|
3899
|
+
if (process.platform !== "win32" || !process.env[SERVICE_ENV_FLAG]) return;
|
|
3900
|
+
try {
|
|
3901
|
+
if (readServicePid() === process.pid) rmSync(servicePidFile(), { force: true });
|
|
3902
|
+
} catch {
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
function isInstalled() {
|
|
3906
|
+
const r = spawnSync2("reg", ["query", RUN_KEY_PATH, "/v", RUN_KEY_NAME], {
|
|
3888
3907
|
stdio: ["ignore", "ignore", "ignore"]
|
|
3889
3908
|
});
|
|
3890
3909
|
return r.status === 0;
|
|
3891
3910
|
}
|
|
3892
|
-
function
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3911
|
+
function readServicePid() {
|
|
3912
|
+
try {
|
|
3913
|
+
const pid = Number.parseInt(readFileSync2(servicePidFile(), "utf8").trim(), 10);
|
|
3914
|
+
return Number.isFinite(pid) ? pid : null;
|
|
3915
|
+
} catch {
|
|
3916
|
+
return null;
|
|
3917
|
+
}
|
|
3899
3918
|
}
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3919
|
+
function pidAlive(pid) {
|
|
3920
|
+
try {
|
|
3921
|
+
process.kill(pid, 0);
|
|
3922
|
+
return true;
|
|
3923
|
+
} catch (err) {
|
|
3924
|
+
return err.code === "EPERM";
|
|
3905
3925
|
}
|
|
3906
|
-
|
|
3926
|
+
}
|
|
3927
|
+
function killService() {
|
|
3928
|
+
const pid = readServicePid();
|
|
3929
|
+
if (pid === null || !pidAlive(pid)) return;
|
|
3930
|
+
spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" });
|
|
3907
3931
|
}
|
|
3908
3932
|
|
|
3909
3933
|
// src/service/systemd.ts
|
|
3910
3934
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
3911
|
-
import { existsSync as
|
|
3912
|
-
import { mkdir as mkdir8, rm as
|
|
3935
|
+
import { existsSync as existsSync5 } from "fs";
|
|
3936
|
+
import { mkdir as mkdir8, rm as rm3, writeFile as writeFile7 } from "fs/promises";
|
|
3913
3937
|
import { homedir as homedir4 } from "os";
|
|
3914
|
-
import { dirname as
|
|
3938
|
+
import { dirname as dirname8, join as join10 } from "path";
|
|
3915
3939
|
var SYSTEMD_UNIT_NAME = "feishu-codex-bridge.service";
|
|
3916
3940
|
function systemdUnitPath() {
|
|
3917
3941
|
const base = process.env.XDG_CONFIG_HOME ?? join10(homedir4(), ".config");
|
|
@@ -3969,7 +3993,7 @@ function ensureSystemdOrThrow() {
|
|
|
3969
3993
|
async function installSystemd() {
|
|
3970
3994
|
ensureSystemdOrThrow();
|
|
3971
3995
|
const unitPath = systemdUnitPath();
|
|
3972
|
-
await mkdir8(
|
|
3996
|
+
await mkdir8(dirname8(unitPath), { recursive: true });
|
|
3973
3997
|
await ensureLogFiles();
|
|
3974
3998
|
await writeFile7(unitPath, buildUnit(), "utf8");
|
|
3975
3999
|
const reload = runSystemctl(["daemon-reload"]);
|
|
@@ -3982,7 +4006,7 @@ async function uninstallSystemd() {
|
|
|
3982
4006
|
if (systemdAvailable() && unitExists()) {
|
|
3983
4007
|
runSystemctl(["disable", "--now", SYSTEMD_UNIT_NAME]);
|
|
3984
4008
|
}
|
|
3985
|
-
await
|
|
4009
|
+
await rm3(systemdUnitPath(), { force: true });
|
|
3986
4010
|
if (systemdAvailable()) runSystemctl(["daemon-reload"]);
|
|
3987
4011
|
}
|
|
3988
4012
|
async function restartSystemd() {
|
|
@@ -4012,7 +4036,7 @@ function statusSystemd() {
|
|
|
4012
4036
|
};
|
|
4013
4037
|
}
|
|
4014
4038
|
function unitExists() {
|
|
4015
|
-
return
|
|
4039
|
+
return existsSync5(systemdUnitPath());
|
|
4016
4040
|
}
|
|
4017
4041
|
function systemdActive() {
|
|
4018
4042
|
const r = spawnSync3("systemctl", ["--user", "is-active", SYSTEMD_UNIT_NAME], {
|
|
@@ -4038,10 +4062,10 @@ function getServiceAdapter() {
|
|
|
4038
4062
|
}
|
|
4039
4063
|
if (process.platform === "win32") {
|
|
4040
4064
|
return {
|
|
4041
|
-
install:
|
|
4042
|
-
uninstall:
|
|
4043
|
-
status: async () =>
|
|
4044
|
-
restart:
|
|
4065
|
+
install: installWinStartup,
|
|
4066
|
+
uninstall: uninstallWinStartup,
|
|
4067
|
+
status: async () => statusWinStartup(),
|
|
4068
|
+
restart: restartWinStartup,
|
|
4045
4069
|
logs: tailServiceLogs
|
|
4046
4070
|
};
|
|
4047
4071
|
}
|
|
@@ -4061,7 +4085,7 @@ function getServiceAdapter() {
|
|
|
4061
4085
|
function isServiceRunning() {
|
|
4062
4086
|
try {
|
|
4063
4087
|
if (process.platform === "darwin") return isLoaded();
|
|
4064
|
-
if (process.platform === "win32") return
|
|
4088
|
+
if (process.platform === "win32") return winStartupRunning();
|
|
4065
4089
|
if (process.platform === "linux") return systemdActive();
|
|
4066
4090
|
} catch {
|
|
4067
4091
|
}
|
|
@@ -4072,11 +4096,11 @@ function isServiceRunning() {
|
|
|
4072
4096
|
var execFileP = promisify(execFile);
|
|
4073
4097
|
var NPM = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
4074
4098
|
function pkgRoot() {
|
|
4075
|
-
return resolve5(
|
|
4099
|
+
return resolve5(dirname9(fileURLToPath4(import.meta.url)), "..");
|
|
4076
4100
|
}
|
|
4077
4101
|
function pkgJson() {
|
|
4078
4102
|
try {
|
|
4079
|
-
return JSON.parse(
|
|
4103
|
+
return JSON.parse(readFileSync3(join11(pkgRoot(), "package.json"), "utf8"));
|
|
4080
4104
|
} catch {
|
|
4081
4105
|
return {};
|
|
4082
4106
|
}
|
|
@@ -4088,7 +4112,7 @@ function packageName() {
|
|
|
4088
4112
|
return pkgJson().name ?? "@modelzen/feishu-codex-bridge";
|
|
4089
4113
|
}
|
|
4090
4114
|
function isDevSource() {
|
|
4091
|
-
return
|
|
4115
|
+
return existsSync6(join11(pkgRoot(), ".git"));
|
|
4092
4116
|
}
|
|
4093
4117
|
function isNewer(a, b) {
|
|
4094
4118
|
const pa = a.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
@@ -4111,7 +4135,7 @@ async function latestVersion() {
|
|
|
4111
4135
|
async function installLatest(opts = {}) {
|
|
4112
4136
|
const target = `${packageName()}@latest`;
|
|
4113
4137
|
return await new Promise((resolveP) => {
|
|
4114
|
-
const child =
|
|
4138
|
+
const child = spawn5(NPM, ["install", "-g", target], {
|
|
4115
4139
|
stdio: opts.inherit ? ["ignore", "inherit", "inherit"] : ["ignore", "pipe", "pipe"]
|
|
4116
4140
|
});
|
|
4117
4141
|
let out = "";
|
|
@@ -4135,7 +4159,7 @@ async function restartDaemon() {
|
|
|
4135
4159
|
|
|
4136
4160
|
// src/project/lifecycle.ts
|
|
4137
4161
|
import { mkdir as mkdir9 } from "fs/promises";
|
|
4138
|
-
import { existsSync as
|
|
4162
|
+
import { existsSync as existsSync7 } from "fs";
|
|
4139
4163
|
import { isAbsolute as isAbsolute2, join as join12, resolve as resolve6 } from "path";
|
|
4140
4164
|
|
|
4141
4165
|
// src/project/git-info.ts
|
|
@@ -4272,7 +4296,7 @@ async function onboardGroup(channel, project) {
|
|
|
4272
4296
|
async function resolveCwd(name, existingPath) {
|
|
4273
4297
|
if (existingPath) {
|
|
4274
4298
|
const cwd2 = isAbsolute2(existingPath) ? existingPath : resolve6(existingPath);
|
|
4275
|
-
if (!
|
|
4299
|
+
if (!existsSync7(cwd2)) throw new Error(`\u6587\u4EF6\u5939\u4E0D\u5B58\u5728\uFF1A${cwd2}`);
|
|
4276
4300
|
return { cwd: cwd2, blank: false };
|
|
4277
4301
|
}
|
|
4278
4302
|
const cwd = join12(paths.projectsRootDir, name);
|
|
@@ -4344,7 +4368,7 @@ async function leaveChat(channel, chatId) {
|
|
|
4344
4368
|
|
|
4345
4369
|
// src/bot/session-store.ts
|
|
4346
4370
|
import { mkdir as mkdir10, readFile as readFile8, rename as rename5, writeFile as writeFile8 } from "fs/promises";
|
|
4347
|
-
import { dirname as
|
|
4371
|
+
import { dirname as dirname10 } from "path";
|
|
4348
4372
|
var FILE_VERSION3 = 1;
|
|
4349
4373
|
async function read2() {
|
|
4350
4374
|
try {
|
|
@@ -4357,7 +4381,7 @@ async function read2() {
|
|
|
4357
4381
|
}
|
|
4358
4382
|
}
|
|
4359
4383
|
async function write2(sessions) {
|
|
4360
|
-
await mkdir10(
|
|
4384
|
+
await mkdir10(dirname10(paths.sessionsFile), { recursive: true });
|
|
4361
4385
|
const tmp = `${paths.sessionsFile}.tmp-${process.pid}`;
|
|
4362
4386
|
const body = { version: FILE_VERSION3, sessions };
|
|
4363
4387
|
await writeFile8(tmp, `${JSON.stringify(body, null, 2)}
|
|
@@ -4404,7 +4428,7 @@ async function handleDmConsole(channel, cfg, msg) {
|
|
|
4404
4428
|
}
|
|
4405
4429
|
|
|
4406
4430
|
// src/bot/media.ts
|
|
4407
|
-
import { mkdir as mkdir11, readdir as readdir2, rm as
|
|
4431
|
+
import { mkdir as mkdir11, readdir as readdir2, rm as rm4, stat as stat3 } from "fs/promises";
|
|
4408
4432
|
import { join as join13 } from "path";
|
|
4409
4433
|
var MAX_IMAGES2 = 9;
|
|
4410
4434
|
var MEDIA_TTL_MS = 60 * 6e4;
|
|
@@ -4547,7 +4571,7 @@ async function pruneOldMedia() {
|
|
|
4547
4571
|
const file = join13(paths.mediaDir, name);
|
|
4548
4572
|
try {
|
|
4549
4573
|
const st = await stat3(file);
|
|
4550
|
-
if (st.mtimeMs < cutoff) await
|
|
4574
|
+
if (st.mtimeMs < cutoff) await rm4(file, { force: true });
|
|
4551
4575
|
} catch {
|
|
4552
4576
|
}
|
|
4553
4577
|
}
|
|
@@ -5918,8 +5942,8 @@ async function startBridge(opts) {
|
|
|
5918
5942
|
}
|
|
5919
5943
|
|
|
5920
5944
|
// src/core/single-instance.ts
|
|
5921
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
5922
|
-
import { dirname as
|
|
5945
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
|
|
5946
|
+
import { dirname as dirname11 } from "path";
|
|
5923
5947
|
var BridgeAlreadyRunningError = class extends Error {
|
|
5924
5948
|
constructor(pid) {
|
|
5925
5949
|
super(
|
|
@@ -5941,20 +5965,20 @@ function isAlive(pid) {
|
|
|
5941
5965
|
function acquireSingleInstanceLock(appId) {
|
|
5942
5966
|
const file = paths.processesFile;
|
|
5943
5967
|
try {
|
|
5944
|
-
const rec = JSON.parse(
|
|
5968
|
+
const rec = JSON.parse(readFileSync4(file, "utf8"));
|
|
5945
5969
|
if (rec.pid && rec.pid !== process.pid && rec.appId === appId && isAlive(rec.pid)) {
|
|
5946
5970
|
throw new BridgeAlreadyRunningError(rec.pid);
|
|
5947
5971
|
}
|
|
5948
5972
|
} catch (err) {
|
|
5949
5973
|
if (err instanceof BridgeAlreadyRunningError) throw err;
|
|
5950
5974
|
}
|
|
5951
|
-
mkdirSync2(
|
|
5975
|
+
mkdirSync2(dirname11(file), { recursive: true });
|
|
5952
5976
|
const record = { pid: process.pid, appId, startedAt: Date.now() };
|
|
5953
|
-
|
|
5977
|
+
writeFileSync2(file, `${JSON.stringify(record)}
|
|
5954
5978
|
`, "utf8");
|
|
5955
5979
|
const release = () => {
|
|
5956
5980
|
try {
|
|
5957
|
-
const rec = JSON.parse(
|
|
5981
|
+
const rec = JSON.parse(readFileSync4(file, "utf8"));
|
|
5958
5982
|
if (rec.pid === process.pid) unlinkSync(file);
|
|
5959
5983
|
} catch {
|
|
5960
5984
|
}
|
|
@@ -5983,6 +6007,7 @@ async function runRun() {
|
|
|
5983
6007
|
}
|
|
5984
6008
|
throw err;
|
|
5985
6009
|
}
|
|
6010
|
+
recordServicePid();
|
|
5986
6011
|
const fallbackCwd = process.env.FEISHU_CODEX_CWD || process.cwd();
|
|
5987
6012
|
console.log("\n\u6B63\u5728\u542F\u52A8\u957F\u8FDE\u63A5 bot\u2026");
|
|
5988
6013
|
console.log("\u79C1\u804A\u6211 `/new <\u540D>` \u5EFA\u9879\u76EE\uFF1B\u5728\u9879\u76EE\u7FA4\u91CC @\u6211 \u5E72\u6D3B\u3002Ctrl+C \u9000\u51FA\u3002\n");
|
|
@@ -6038,7 +6063,7 @@ async function runLogs(follow) {
|
|
|
6038
6063
|
function installedNote() {
|
|
6039
6064
|
switch (process.platform) {
|
|
6040
6065
|
case "win32":
|
|
6041
|
-
return "\u2713 \u540E\u53F0\u670D\u52A1\u5DF2\u5B89\u88C5\u5E76\u542F\u52A8\uFF08\u767B\u5F55\u81EA\u542F\uFF1B\u6CE8\u610F
|
|
6066
|
+
return "\u2713 \u540E\u53F0\u670D\u52A1\u5DF2\u5B89\u88C5\u5E76\u542F\u52A8\uFF08\u767B\u5F55\u81EA\u542F\uFF0C\u514D\u7BA1\u7406\u5458\uFF09\u3002\n \u63D0\u793A\uFF1A\u767B\u5F55\u81EA\u542F\u5728\u4E0B\u6B21\u767B\u5F55\u751F\u6548\uFF1B\u5F53\u524D\u5DF2\u5728\u540E\u53F0\u9690\u85CF\u542F\u52A8\u3002\u6CE8\u610F Windows \u767B\u5F55\u81EA\u542F\u65E0\u5D29\u6E83\u81EA\u52A8\u62C9\u8D77\u3002";
|
|
6042
6067
|
case "linux":
|
|
6043
6068
|
return "\u2713 \u540E\u53F0\u670D\u52A1\u5DF2\u5B89\u88C5\u5E76\u542F\u52A8\uFF08\u767B\u5F55\u81EA\u542F\u3001\u5D29\u6E83\u81EA\u52A8\u62C9\u8D77\uFF09\u3002\n \u63D0\u793A\uFF1A\u6CE8\u9500\u540E\u4ECD\u4FDD\u6301\u8FD0\u884C\u9700\u6267\u884C\u4E00\u6B21 `loginctl enable-linger $USER`\u3002";
|
|
6044
6069
|
default:
|
|
@@ -6110,7 +6135,7 @@ async function runUpdate(opts = {}) {
|
|
|
6110
6135
|
}
|
|
6111
6136
|
|
|
6112
6137
|
// src/cli/commands/bot.ts
|
|
6113
|
-
import { rm as
|
|
6138
|
+
import { rm as rm5 } from "fs/promises";
|
|
6114
6139
|
async function runBotInit(name) {
|
|
6115
6140
|
if (!ensureCodex()) {
|
|
6116
6141
|
process.exitCode = 1;
|
|
@@ -6165,7 +6190,7 @@ async function runBotRm(name) {
|
|
|
6165
6190
|
}
|
|
6166
6191
|
const after = await removeBot(bot2.appId);
|
|
6167
6192
|
await removeSecret(secretKeyForApp(bot2.appId));
|
|
6168
|
-
await
|
|
6193
|
+
await rm5(botDir(bot2.appId), { recursive: true, force: true });
|
|
6169
6194
|
console.log(`\u2713 \u5DF2\u79FB\u9664\u673A\u5668\u4EBA\u300C${bot2.name}\u300D(${bot2.appId})\uFF1A\u6CE8\u518C\u8868 + \u5BC6\u94A5 + \u72B6\u6001\u76EE\u5F55(projects/sessions)\u3002`);
|
|
6170
6195
|
if (after.bots.length === 0) {
|
|
6171
6196
|
console.log(" \u5DF2\u65E0\u4EFB\u4F55\u673A\u5668\u4EBA\uFF0C`bot init` \u91CD\u65B0\u521B\u5EFA\u3002");
|
package/package.json
CHANGED