@modelzen/feishu-codex-bridge 0.6.7-test.0 → 0.6.7-test.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.
Files changed (2) hide show
  1. package/dist/cli.js +63 -49
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -8510,7 +8510,7 @@ function withCodexHooksFeature(text) {
8510
8510
 
8511
8511
  // src/service/update.ts
8512
8512
  import { existsSync as existsSync9, readFileSync as readFileSync4 } from "fs";
8513
- import { dirname as dirname9, join as join15, resolve as resolve6 } from "path";
8513
+ import { dirname as dirname10, join as join15, resolve as resolve6 } from "path";
8514
8514
  import { fileURLToPath as fileURLToPath4 } from "url";
8515
8515
 
8516
8516
  // src/service/launchd.ts
@@ -8538,9 +8538,9 @@ async function ensureLogFiles() {
8538
8538
  await appendFile(serviceStdoutPath(), "");
8539
8539
  await appendFile(serviceStderrPath(), "");
8540
8540
  }
8541
- function appendServiceErr(tag, line) {
8541
+ function appendServiceErr(tag, line, filePath = serviceStderrPath()) {
8542
8542
  try {
8543
- appendFileSync(serviceStderrPath(), `[${(/* @__PURE__ */ new Date()).toISOString()}] [${tag}] ${line}
8543
+ appendFileSync(filePath, `[${(/* @__PURE__ */ new Date()).toISOString()}] [${tag}] ${line}
8544
8544
  `);
8545
8545
  } catch {
8546
8546
  }
@@ -8756,7 +8756,7 @@ init_paths();
8756
8756
  import { spawn as spawn3, spawnSync as spawnSync2 } from "child_process";
8757
8757
  import { existsSync as existsSync7, openSync, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
8758
8758
  import { mkdir as mkdir9, writeFile as writeFile8 } from "fs/promises";
8759
- import { join as join13 } from "path";
8759
+ import { dirname as dirname8, join as join13 } from "path";
8760
8760
  var RELAUNCH_TASK_NAME = "feishu-codex-bridge-relaunch";
8761
8761
  var RUN_KEY_PATH = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
8762
8762
  var RUN_KEY_NAME = "feishu-codex-bridge";
@@ -8787,18 +8787,20 @@ function buildLauncherVbs() {
8787
8787
  ""
8788
8788
  ].join("\r\n");
8789
8789
  }
8790
- function startNow(envPath) {
8791
- const out = openSync(serviceStdoutPath(), "a");
8792
- const err = openSync(serviceStderrPath(), "a");
8790
+ function startNow(opts = {}) {
8791
+ const dir = opts.appDir ?? paths.appDir;
8792
+ const out = openSync(join13(dir, "service.log"), "a");
8793
+ const err = openSync(join13(dir, "service.err.log"), "a");
8793
8794
  const overrides = { [SERVICE_ENV_FLAG]: "1" };
8794
- if (envPath) overrides.PATH = envPath;
8795
+ if (opts.envPath) overrides.PATH = opts.envPath;
8796
+ if (opts.userProfile) overrides.USERPROFILE = opts.userProfile;
8795
8797
  const child = spawn3(process.execPath, [resolveCliBinPath(), "run"], {
8796
8798
  detached: true,
8797
8799
  windowsHide: true,
8798
8800
  stdio: ["ignore", out, err],
8799
8801
  env: mergeProcessEnv(process.env, overrides)
8800
8802
  });
8801
- if (child.pid) writeFileSync(servicePidFile(), String(child.pid), "utf8");
8803
+ if (child.pid) writeFileSync(join13(dir, "service.pid"), String(child.pid), "utf8");
8802
8804
  child.unref();
8803
8805
  }
8804
8806
  async function installWinStartup() {
@@ -8832,8 +8834,14 @@ async function restartWinStartup() {
8832
8834
  startNow();
8833
8835
  return statusWinStartup();
8834
8836
  }
8835
- writeRelaunchRequest({ oldPid, envPath: process.env.PATH ?? "", nonce: `${process.pid}-${Date.now()}` });
8836
- if (!spawnTreeFreeRelauncher()) {
8837
+ const reqPath = relaunchRequestFile();
8838
+ writeRelaunchRequest({
8839
+ oldPid,
8840
+ envPath: process.env.PATH ?? "",
8841
+ userProfile: process.env.USERPROFILE ?? "",
8842
+ nonce: `${process.pid}-${Date.now()}`
8843
+ });
8844
+ if (!spawnTreeFreeRelauncher(reqPath)) {
8837
8845
  clearRelaunchRequest();
8838
8846
  appendServiceErr("relaunch", `no tree-free backend (powershell/schtasks); kept old pid=${oldPid} running, did NOT restart`);
8839
8847
  throw new Error("\u65E0\u6CD5\u62C9\u8D77\u300C\u6811\u5916\u300D\u91CD\u542F\u8FDB\u7A0B\uFF08powershell \u4E0E schtasks \u5747\u4E0D\u53EF\u7528\uFF09\uFF1B\u5DF2\u4FDD\u7559\u65E7\u670D\u52A1\u7EE7\u7EED\u8FD0\u884C\uFF0C\u672A\u91CD\u542F\u3002");
@@ -8850,13 +8858,10 @@ function writeRelaunchRequest(req) {
8850
8858
  function clearRelaunchRequest() {
8851
8859
  rmSync(relaunchRequestFile(), { force: true });
8852
8860
  }
8853
- function relaunchClaimFile() {
8854
- return `${relaunchRequestFile()}.claim.${process.pid}`;
8855
- }
8856
- function claimRelaunchRequest() {
8857
- const claim = relaunchClaimFile();
8861
+ function claimRelaunchRequest(reqPath) {
8862
+ const claim = `${reqPath}.claim.${process.pid}`;
8858
8863
  try {
8859
- renameSync(relaunchRequestFile(), claim);
8864
+ renameSync(reqPath, claim);
8860
8865
  } catch {
8861
8866
  return null;
8862
8867
  }
@@ -8866,6 +8871,7 @@ function claimRelaunchRequest() {
8866
8871
  return {
8867
8872
  oldPid: r.oldPid,
8868
8873
  envPath: typeof r.envPath === "string" ? r.envPath : "",
8874
+ userProfile: typeof r.userProfile === "string" ? r.userProfile : "",
8869
8875
  nonce: String(r.nonce ?? "")
8870
8876
  };
8871
8877
  }
@@ -8873,26 +8879,29 @@ function claimRelaunchRequest() {
8873
8879
  }
8874
8880
  return null;
8875
8881
  }
8876
- function clearRelaunchClaim() {
8877
- rmSync(relaunchClaimFile(), { force: true });
8882
+ function clearRelaunchClaim(reqPath) {
8883
+ rmSync(`${reqPath}.claim.${process.pid}`, { force: true });
8878
8884
  }
8879
- function buildRelauncherPowershell(binPath = resolveCliBinPath(), nodePath = process.execPath) {
8880
- const inner = `"${nodePath}" "${binPath}" __win-relaunch`;
8885
+ function buildRelauncherPowershell(reqPath, binPath = resolveCliBinPath(), nodePath = process.execPath) {
8886
+ const inner = `"${nodePath}" "${binPath}" __win-relaunch "${reqPath}"`;
8881
8887
  const lit = `'${inner.replace(/'/g, "''")}'`;
8882
8888
  return `$c=${lit}; try { Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine=$c } -ErrorAction Stop | Out-Null } catch { schtasks /create /tn ${RELAUNCH_TASK_NAME} /tr $c /sc ONCE /st 00:00 /f | Out-Null; schtasks /run /tn ${RELAUNCH_TASK_NAME} | Out-Null }`;
8883
8889
  }
8890
+ function encodePowershellCommand(script) {
8891
+ return Buffer.from(script, "utf16le").toString("base64");
8892
+ }
8884
8893
  function powershellPath() {
8885
8894
  const root = process.env.SystemRoot || process.env.windir || "C:\\Windows";
8886
8895
  const p = join13(root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
8887
8896
  return existsSync7(p) ? p : null;
8888
8897
  }
8889
- function spawnTreeFreeRelauncher() {
8898
+ function spawnTreeFreeRelauncher(reqPath) {
8890
8899
  const ps = powershellPath();
8891
8900
  if (ps) {
8892
8901
  const errFd = openSync(serviceStderrPath(), "a");
8893
8902
  const child = spawn3(
8894
8903
  ps,
8895
- ["-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", buildRelauncherPowershell()],
8904
+ ["-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-EncodedCommand", encodePowershellCommand(buildRelauncherPowershell(reqPath))],
8896
8905
  { detached: true, windowsHide: true, stdio: ["ignore", errFd, errFd] }
8897
8906
  );
8898
8907
  child.on("error", (e) => appendServiceErr("relaunch", `powershell spawn error: ${e.message}`));
@@ -8900,10 +8909,10 @@ function spawnTreeFreeRelauncher() {
8900
8909
  return true;
8901
8910
  }
8902
8911
  appendServiceErr("relaunch", "powershell.exe not found; trying schtasks fallback");
8903
- return spawnSchtasksRelauncher();
8912
+ return spawnSchtasksRelauncher(reqPath);
8904
8913
  }
8905
- function spawnSchtasksRelauncher() {
8906
- const tr = `"${process.execPath}" "${resolveCliBinPath()}" __win-relaunch`;
8914
+ function spawnSchtasksRelauncher(reqPath) {
8915
+ const tr = `"${process.execPath}" "${resolveCliBinPath()}" __win-relaunch "${reqPath}"`;
8907
8916
  const create = spawnSync2(
8908
8917
  "schtasks",
8909
8918
  ["/create", "/tn", RELAUNCH_TASK_NAME, "/tr", tr, "/sc", "ONCE", "/st", "00:00", "/f"],
@@ -8925,6 +8934,8 @@ function defaultTaskkill(pid) {
8925
8934
  return { status: r.status, stderr: (r.stderr || "").toString() };
8926
8935
  }
8927
8936
  async function runWinRelaunch(deps = {}) {
8937
+ const reqPath = deps.requestPath ?? relaunchRequestFile();
8938
+ const appDir2 = dirname8(reqPath);
8928
8939
  const claim = deps.claimRequest ?? claimRelaunchRequest;
8929
8940
  const clearClaim = deps.clearRequest ?? clearRelaunchClaim;
8930
8941
  const alive = deps.pidAlive ?? pidAlive;
@@ -8935,9 +8946,12 @@ async function runWinRelaunch(deps = {}) {
8935
8946
  const pollMs = deps.pollMs ?? 200;
8936
8947
  const now = deps.now ?? (() => Date.now());
8937
8948
  const ensureLogs = deps.ensureLogs ?? ensureLogFiles;
8938
- const logLine = deps.logLine ?? ((line) => appendServiceErr("relaunch", line));
8939
- await ensureLogs();
8940
- const req = claim();
8949
+ const logLine = deps.logLine ?? ((line) => appendServiceErr("relaunch", line, join13(appDir2, "service.err.log")));
8950
+ try {
8951
+ await ensureLogs();
8952
+ } catch {
8953
+ }
8954
+ const req = claim(reqPath);
8941
8955
  if (!req) {
8942
8956
  logLine("no relaunch request to claim (already handled by another relauncher, or none)");
8943
8957
  return;
@@ -8959,10 +8973,10 @@ async function runWinRelaunch(deps = {}) {
8959
8973
  return;
8960
8974
  }
8961
8975
  await sleep(300);
8962
- start(req.envPath);
8963
- logLine(`relaunched; new service.pid=${readServicePid() ?? "?"}`);
8976
+ start({ appDir: appDir2, envPath: req.envPath, userProfile: req.userProfile });
8977
+ logLine(`relaunched; new daemon started (appDir=${appDir2})`);
8964
8978
  } finally {
8965
- clearClaim();
8979
+ clearClaim(reqPath);
8966
8980
  if (process.platform === "win32") {
8967
8981
  try {
8968
8982
  spawnSync2("schtasks", ["/delete", "/tn", RELAUNCH_TASK_NAME, "/f"], { stdio: "ignore", windowsHide: true });
@@ -9041,7 +9055,7 @@ import { spawnSync as spawnSync3 } from "child_process";
9041
9055
  import { existsSync as existsSync8 } from "fs";
9042
9056
  import { mkdir as mkdir10, rm as rm4, writeFile as writeFile9 } from "fs/promises";
9043
9057
  import { homedir as homedir5 } from "os";
9044
- import { dirname as dirname8, join as join14 } from "path";
9058
+ import { dirname as dirname9, join as join14 } from "path";
9045
9059
  var SYSTEMD_UNIT_NAME = "feishu-codex-bridge.service";
9046
9060
  function systemdUnitPath() {
9047
9061
  const base = process.env.XDG_CONFIG_HOME ?? join14(homedir5(), ".config");
@@ -9099,7 +9113,7 @@ function ensureSystemdOrThrow() {
9099
9113
  async function installSystemd() {
9100
9114
  ensureSystemdOrThrow();
9101
9115
  const unitPath = systemdUnitPath();
9102
- await mkdir10(dirname8(unitPath), { recursive: true });
9116
+ await mkdir10(dirname9(unitPath), { recursive: true });
9103
9117
  await ensureLogFiles();
9104
9118
  await writeFile9(unitPath, buildUnit(), "utf8");
9105
9119
  const reload = runSystemctl(["daemon-reload"]);
@@ -9201,7 +9215,7 @@ function isServiceRunning() {
9201
9215
  // src/service/update.ts
9202
9216
  var NPM2 = "npm";
9203
9217
  function pkgRoot() {
9204
- return resolve6(dirname9(fileURLToPath4(import.meta.url)), "..");
9218
+ return resolve6(dirname10(fileURLToPath4(import.meta.url)), "..");
9205
9219
  }
9206
9220
  function pkgJson() {
9207
9221
  try {
@@ -9863,9 +9877,9 @@ function buildUsageShareCard(data, opts = {}) {
9863
9877
  init_paths();
9864
9878
  import { randomUUID as randomUUID4 } from "crypto";
9865
9879
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
9866
- import { dirname as dirname10 } from "path";
9880
+ import { dirname as dirname11 } from "path";
9867
9881
  function publishWebConsole(rec, file = paths.webConsoleFile) {
9868
- mkdirSync2(dirname10(file), { recursive: true });
9882
+ mkdirSync2(dirname11(file), { recursive: true });
9869
9883
  try {
9870
9884
  unlinkSync(file);
9871
9885
  } catch {
@@ -9905,7 +9919,7 @@ function stableWebConsoleToken(file = paths.webTokenFile) {
9905
9919
  }
9906
9920
  const token = randomUUID4();
9907
9921
  try {
9908
- mkdirSync2(dirname10(file), { recursive: true });
9922
+ mkdirSync2(dirname11(file), { recursive: true });
9909
9923
  try {
9910
9924
  unlinkSync(file);
9911
9925
  } catch {
@@ -10216,7 +10230,7 @@ async function leaveChat(channel, chatId) {
10216
10230
  init_paths();
10217
10231
  import { mkdir as mkdir12, readFile as readFile11, rename as rename5, writeFile as writeFile10 } from "fs/promises";
10218
10232
  import { randomUUID as randomUUID5 } from "crypto";
10219
- import { dirname as dirname11 } from "path";
10233
+ import { dirname as dirname12 } from "path";
10220
10234
  var FILE_VERSION3 = 2;
10221
10235
  var LEGACY_V1_SESSION_FIELD = "codexThreadId";
10222
10236
  function migrate(raw) {
@@ -10252,7 +10266,7 @@ function withLock2(fn) {
10252
10266
  return run;
10253
10267
  }
10254
10268
  async function write2(sessions) {
10255
- await mkdir12(dirname11(paths.sessionsFile), { recursive: true });
10269
+ await mkdir12(dirname12(paths.sessionsFile), { recursive: true });
10256
10270
  const tmp = `${paths.sessionsFile}.tmp-${process.pid}-${randomUUID5()}`;
10257
10271
  const body = { version: FILE_VERSION3, sessions };
10258
10272
  await writeFile10(tmp, `${JSON.stringify(body, null, 2)}
@@ -10868,7 +10882,7 @@ function weaveSender(text, sender) {
10868
10882
  // src/bot/comments.ts
10869
10883
  init_logger();
10870
10884
  import { mkdir as mkdir14, readdir as readdir4, readFile as readFile12, writeFile as writeFile11 } from "fs/promises";
10871
- import { dirname as dirname12, join as join19 } from "path";
10885
+ import { dirname as dirname13, join as join19 } from "path";
10872
10886
  var SUPPORTED_FILE_TYPES = /* @__PURE__ */ new Set(["doc", "docx", "sheet", "bitable"]);
10873
10887
  var REPLY_MAX_CHARS = 2e3;
10874
10888
  function apiErrCode(err) {
@@ -11000,7 +11014,7 @@ async function loadCommentInstructions(masterFile) {
11000
11014
  return existing.trim() ? existing : DEFAULT_COMMENT_INSTRUCTIONS;
11001
11015
  } catch {
11002
11016
  }
11003
- await mkdir14(dirname12(masterFile), { recursive: true }).catch(() => void 0);
11017
+ await mkdir14(dirname13(masterFile), { recursive: true }).catch(() => void 0);
11004
11018
  await writeFile11(masterFile, DEFAULT_COMMENT_INSTRUCTIONS, "utf8").catch(() => void 0);
11005
11019
  return DEFAULT_COMMENT_INSTRUCTIONS;
11006
11020
  }
@@ -11012,7 +11026,7 @@ async function syncCommentInstructions(cwd, instructions) {
11012
11026
  ]);
11013
11027
  }
11014
11028
  async function saveCommentInstructions(masterFile, content) {
11015
- await mkdir14(dirname12(masterFile), { recursive: true });
11029
+ await mkdir14(dirname13(masterFile), { recursive: true });
11016
11030
  await writeFile11(masterFile, content, "utf8");
11017
11031
  }
11018
11032
  function renderCommentInstructions(template, tenant, fileType, fileToken) {
@@ -14283,7 +14297,7 @@ init_logger();
14283
14297
  // src/admin/host.ts
14284
14298
  init_paths();
14285
14299
  import { readdir as readdir5, stat as stat4 } from "fs/promises";
14286
- import { dirname as dirname13, join as join21, resolve as resolve8 } from "path";
14300
+ import { dirname as dirname14, join as join21, resolve as resolve8 } from "path";
14287
14301
  import { fileURLToPath as fileURLToPath5 } from "url";
14288
14302
  import { arch, platform as platform2, release } from "os";
14289
14303
  function toDaemonStatus(opts) {
@@ -14335,7 +14349,7 @@ async function collectHostDoctor(logsDir2 = join21(paths.appDir, "logs")) {
14335
14349
  };
14336
14350
  }
14337
14351
  function resolveCliBinPath3() {
14338
- const distDir = dirname13(fileURLToPath5(import.meta.url));
14352
+ const distDir = dirname14(fileURLToPath5(import.meta.url));
14339
14353
  return resolve8(distDir, "..", "bin", "feishu-codex-bridge.mjs");
14340
14354
  }
14341
14355
  function buildDaemonControlCommand(action, binPath = resolveCliBinPath3(), nodePath = process.execPath) {
@@ -18462,7 +18476,7 @@ async function runSupervisor(bots) {
18462
18476
  // src/core/single-instance.ts
18463
18477
  init_paths();
18464
18478
  import { mkdirSync as mkdirSync4, readFileSync as readFileSync6, statSync as statSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "fs";
18465
- import { dirname as dirname14 } from "path";
18479
+ import { dirname as dirname15 } from "path";
18466
18480
  var CLAIM_ATTEMPTS = 5;
18467
18481
  var PID_REUSE_SLACK_MS = 15e3;
18468
18482
  var EMPTY_LOCK_STALE_MS = 2e3;
@@ -18508,7 +18522,7 @@ function isLiveHolder(rec, appId) {
18508
18522
  return true;
18509
18523
  }
18510
18524
  function acquireSingleInstanceLock(appId, file = paths.processesFile) {
18511
- mkdirSync4(dirname14(file), { recursive: true });
18525
+ mkdirSync4(dirname15(file), { recursive: true });
18512
18526
  const record = { pid: process.pid, appId, startedAt: Date.now() };
18513
18527
  for (let attempt = 0; attempt < CLAIM_ATTEMPTS; attempt++) {
18514
18528
  try {
@@ -19220,8 +19234,8 @@ program.command("web").description("\u672C\u673A Web \u63A7\u5236\u53F0\uFF08\u5
19220
19234
  program.command("__daemon-control <action>", { hidden: true }).action(async (action) => {
19221
19235
  await runDaemonControl(action);
19222
19236
  });
19223
- program.command("__win-relaunch", { hidden: true }).action(async () => {
19224
- await runWinRelaunch();
19237
+ program.command("__win-relaunch [requestPath]", { hidden: true }).action(async (requestPath) => {
19238
+ await runWinRelaunch({ requestPath });
19225
19239
  });
19226
19240
  var bot = program.command("bot").description("\u98DE\u4E66\u673A\u5668\u4EBA\u7BA1\u7406\uFF08\u591A\u673A\u5668\u4EBA\uFF09");
19227
19241
  bot.command("init [name]").description("\u6CE8\u518C\u4E00\u4E2A\u98DE\u4E66\u673A\u5668\u4EBA\u5E76\u6388\u6743\uFF08\u53EF\u9009\u77ED\u540D\uFF09").action(async (name) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelzen/feishu-codex-bridge",
3
- "version": "0.6.7-test.0",
3
+ "version": "0.6.7-test.1",
4
4
  "description": "Bridge Feishu/Lark messenger with local Codex via app-server (project=group, thread=session)",
5
5
  "type": "module",
6
6
  "bin": {