nikou-cli 0.1.3 → 0.1.5

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/index.js +379 -427
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1173,6 +1173,24 @@ function safeJsonStringify(payload) {
1173
1173
  return `{"error":"JSON.stringify failed","reason":"${msg}"}`;
1174
1174
  }
1175
1175
  }
1176
+ function countReplacementChars(text) {
1177
+ return (text.match(/\uFFFD/g) || []).length;
1178
+ }
1179
+ function decodeProcessOutputChunk(chunk) {
1180
+ if (typeof chunk === "string") {
1181
+ return chunk;
1182
+ }
1183
+ const utf8 = chunk.toString("utf8");
1184
+ if (process2.platform !== "win32" || !utf8.includes("\uFFFD")) {
1185
+ return utf8;
1186
+ }
1187
+ try {
1188
+ const decoded = new TextDecoder("gb18030").decode(chunk);
1189
+ return countReplacementChars(decoded) < countReplacementChars(utf8) ? decoded : utf8;
1190
+ } catch {
1191
+ return utf8;
1192
+ }
1193
+ }
1176
1194
  function toSingleLineLog(text, maxLength = 600) {
1177
1195
  const normalized = String(text || "").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
1178
1196
  if (normalized.length <= maxLength) return normalized;
@@ -6097,13 +6115,6 @@ import fs11 from "fs";
6097
6115
  import path10 from "path";
6098
6116
  import process6 from "process";
6099
6117
  import { spawnSync as spawnSync3 } from "child_process";
6100
- function quoteWindowsCmdArg(value) {
6101
- const text = String(value ?? "");
6102
- if (!text) {
6103
- return '""';
6104
- }
6105
- return `"${text.replace(/(["^&|<>%])/g, "^$1")}"`;
6106
- }
6107
6118
  function isExecutableFile(filePath) {
6108
6119
  if (!filePath || !fs11.existsSync(filePath)) {
6109
6120
  return false;
@@ -6202,22 +6213,22 @@ function resolveCliExecution(commandName, args, env = process6.env) {
6202
6213
  prependPathDir(env, path10.dirname(commandPath));
6203
6214
  }
6204
6215
  if (process6.platform === "win32") {
6205
- const commandLine = [
6206
- quoteWindowsCmdArg(commandPath),
6207
- ...normalizedArgs.map((item) => quoteWindowsCmdArg(item))
6208
- ].join(" ");
6209
6216
  return {
6210
6217
  command: "cmd.exe",
6211
- args: ["/d", "/s", "/c", `"${commandLine}"`],
6218
+ args: ["/d", "/c", "call", commandPath, ...normalizedArgs],
6212
6219
  shell: false,
6213
- displayCommand
6220
+ displayCommand,
6221
+ resolvedPath: commandPath,
6222
+ fallback: "cmd"
6214
6223
  };
6215
6224
  }
6216
6225
  return {
6217
6226
  command: commandPath,
6218
6227
  args: normalizedArgs,
6219
6228
  shell: false,
6220
- displayCommand
6229
+ displayCommand,
6230
+ resolvedPath: commandPath,
6231
+ fallback: commandPath === commandName ? "direct-unresolved" : "direct"
6221
6232
  };
6222
6233
  }
6223
6234
 
@@ -6309,6 +6320,19 @@ var CodexRunner = class {
6309
6320
  resolveCodexExecution(args, env = process7.env) {
6310
6321
  return resolveCliExecution("codex", args, env);
6311
6322
  }
6323
+ buildFailureMessage(stderr, stdout, code, dirPath, execConfig) {
6324
+ const reason = stderr.trim() || stdout.trim() || `codex \u9000\u51FA\u7801 ${code}`;
6325
+ return [
6326
+ reason,
6327
+ `cwd=${dirPath || "-"}`,
6328
+ `command=${execConfig.displayCommand || "codex"}`,
6329
+ `resolved=${execConfig.resolvedPath || "-"}`,
6330
+ `fallback=${execConfig.fallback || "-"}`
6331
+ ].join("\n");
6332
+ }
6333
+ buildExecutionLog(prefix, execConfig) {
6334
+ return `${prefix}: ${execConfig.displayCommand} (resolved=${execConfig.resolvedPath || "-"}, fallback=${execConfig.fallback || "direct"})`;
6335
+ }
6312
6336
  writePromptToChildStdin(child, prompt, traceMessage = "") {
6313
6337
  if (!this.shouldUseStdinPrompt(prompt) || !child?.stdin) {
6314
6338
  return;
@@ -6407,7 +6431,7 @@ var CodexRunner = class {
6407
6431
  this.logger.info(`Codex \u51C6\u5907\u6267\u884C: dir=${dirPath}, thread_key=${threadKey || "-"}, session_id=${resolvedSessionId || "-"}, resume=${isResume}`);
6408
6432
  const childEnv = this.buildChildEnv(resolveTraceId(threadKey, resolvedSessionId, dirPath));
6409
6433
  const execConfig = this.resolveCodexExecution(args, childEnv);
6410
- this.logger.info(formatTraceLog(resolveTraceId(threadKey, resolvedSessionId, dirPath), `Codex \u6267\u884C\u547D\u4EE4: ${execConfig.displayCommand}`));
6434
+ this.logger.info(formatTraceLog(resolveTraceId(threadKey, resolvedSessionId, dirPath), this.buildExecutionLog("Codex \u6267\u884C\u547D\u4EE4", execConfig)));
6411
6435
  const child = spawn(execConfig.command, execConfig.args, {
6412
6436
  cwd: dirPath,
6413
6437
  shell: execConfig.shell,
@@ -6425,15 +6449,17 @@ var CodexRunner = class {
6425
6449
  const timer = this.createTimeout(child, resolveTraceId(threadKey, resolvedSessionId, dirPath), reject, "Codex \u6267\u884C\u8D85\u65F6", CODEX_EXEC_TIMEOUT_MS);
6426
6450
  child.stdout?.on("data", (chunk) => {
6427
6451
  clearTimeout(startupTimer);
6428
- stdout += String(chunk);
6452
+ stdout += decodeProcessOutputChunk(chunk);
6429
6453
  });
6430
6454
  child.stderr?.on("data", (chunk) => {
6431
- stderr += String(chunk);
6455
+ stderr += decodeProcessOutputChunk(chunk);
6432
6456
  });
6433
6457
  child.on("error", (error) => {
6434
6458
  clearTimeout(startupTimer);
6435
6459
  clearTimeout(timer);
6436
- reject(error);
6460
+ reject(new Error(`${error.message}
6461
+ cwd=${dirPath || "-"}
6462
+ command=${execConfig.displayCommand}`));
6437
6463
  });
6438
6464
  child.on("close", (code) => {
6439
6465
  clearTimeout(startupTimer);
@@ -6451,8 +6477,7 @@ var CodexRunner = class {
6451
6477
  this.stateManager.markCodexRun(dirPath);
6452
6478
  }
6453
6479
  if (code !== 0) {
6454
- const err = stderr.trim() || stdout.trim() || `codex \u9000\u51FA\u7801 ${code}`;
6455
- reject(new Error(err));
6480
+ reject(new Error(this.buildFailureMessage(stderr, stdout, code, dirPath, execConfig)));
6456
6481
  return;
6457
6482
  }
6458
6483
  resolve3({
@@ -6503,7 +6528,7 @@ var CodexRunner = class {
6503
6528
  let notifiedSessionId = false;
6504
6529
  const childEnv = this.buildChildEnv(logTraceId);
6505
6530
  const execConfig = this.resolveCodexExecution(args, childEnv);
6506
- this.logger.info(formatTraceLog(logTraceId, `Codex \u6267\u884C\u547D\u4EE4(\u6D41\u5F0F): ${execConfig.displayCommand}`));
6531
+ this.logger.info(formatTraceLog(logTraceId, this.buildExecutionLog("Codex \u6267\u884C\u547D\u4EE4(\u6D41\u5F0F)", execConfig)));
6507
6532
  const child = spawn(execConfig.command, execConfig.args, {
6508
6533
  cwd: dirPath,
6509
6534
  shell: execConfig.shell,
@@ -6558,13 +6583,13 @@ var CodexRunner = class {
6558
6583
  };
6559
6584
  child.stdout?.on("data", (chunk) => {
6560
6585
  clearTimeout(startupTimer);
6561
- const text = String(chunk);
6586
+ const text = decodeProcessOutputChunk(chunk);
6562
6587
  stdout += text;
6563
6588
  pending += text;
6564
6589
  consumeLines();
6565
6590
  });
6566
6591
  child.stderr?.on("data", (chunk) => {
6567
- const text = String(chunk);
6592
+ const text = decodeProcessOutputChunk(chunk);
6568
6593
  stderr += text;
6569
6594
  text.split(/\r?\n/).forEach((line) => {
6570
6595
  if (line.trim() && !shouldIgnoreStderrLine(line)) {
@@ -6578,7 +6603,9 @@ var CodexRunner = class {
6578
6603
  if (taskKey) {
6579
6604
  this.activeChildrenByTaskId.delete(taskKey);
6580
6605
  }
6581
- reject(error);
6606
+ reject(new Error(`${error.message}
6607
+ cwd=${dirPath || "-"}
6608
+ command=${execConfig.displayCommand}`));
6582
6609
  });
6583
6610
  child.on("close", (code) => {
6584
6611
  clearTimeout(startupTimer);
@@ -6631,8 +6658,7 @@ var CodexRunner = class {
6631
6658
  this.stateManager.markCodexRun(dirPath);
6632
6659
  }
6633
6660
  if (code !== 0) {
6634
- const err = stderr.trim() || stdout.trim() || `codex \u9000\u51FA\u7801 ${code}`;
6635
- reject(new Error(err));
6661
+ reject(new Error(this.buildFailureMessage(stderr, stdout, code, dirPath, execConfig)));
6636
6662
  return;
6637
6663
  }
6638
6664
  resolve3({
@@ -6649,10 +6675,10 @@ var CodexRunner = class {
6649
6675
  import fs12 from "fs";
6650
6676
  import os5 from "os";
6651
6677
  import path11 from "path";
6652
- var VOPS_USER_CACHE_PATH2 = path11.join(os5.homedir(), "ops", "vops_user.json");
6653
- var CHAT_CACHE_TYPE = "__chat_cache__";
6654
- function normalize6(value) {
6655
- if (value == null) {
6678
+
6679
+ // src/hook/display-name.ts
6680
+ function normalizeText(value) {
6681
+ if (value === null || value === void 0) {
6656
6682
  return "";
6657
6683
  }
6658
6684
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
@@ -6660,24 +6686,15 @@ function normalize6(value) {
6660
6686
  }
6661
6687
  return "";
6662
6688
  }
6663
- function lower(value) {
6664
- return normalize6(value).toLowerCase();
6665
- }
6666
- function extractUserFromEmail(email) {
6667
- const normalizedEmail = lower(email);
6668
- if (!normalizedEmail.includes("@")) {
6669
- return "";
6670
- }
6671
- return normalizedEmail.split("@")[0] || "";
6672
- }
6673
6689
  function resolveDisplayName(value) {
6674
- const direct = normalize6(value);
6690
+ const direct = normalizeText(value);
6675
6691
  if (direct) {
6676
6692
  return direct;
6677
6693
  }
6678
6694
  if (!value || typeof value !== "object") {
6679
6695
  return "";
6680
6696
  }
6697
+ const record = value;
6681
6698
  const candidateKeys = [
6682
6699
  "zh_cn",
6683
6700
  "zh-CN",
@@ -6689,15 +6706,30 @@ function resolveDisplayName(value) {
6689
6706
  "name",
6690
6707
  "display_name",
6691
6708
  "full_name",
6692
- "value"
6709
+ "value",
6710
+ "default_value"
6693
6711
  ];
6694
6712
  for (const key of candidateKeys) {
6695
- const text = normalize6(value[key]);
6713
+ const text = normalizeText(record[key]);
6696
6714
  if (text) {
6697
6715
  return text;
6698
6716
  }
6699
6717
  }
6700
- return "";
6718
+ return resolveDisplayName(record.i18n_value) || resolveDisplayName(record.i18nValue) || resolveDisplayName(record.text);
6719
+ }
6720
+
6721
+ // src/hook/context/identity-resolver.ts
6722
+ var VOPS_USER_CACHE_PATH2 = path11.join(os5.homedir(), "ops", "vops_user.json");
6723
+ var CHAT_CACHE_TYPE = "__chat_cache__";
6724
+ function lower(value) {
6725
+ return normalizeText(value).toLowerCase();
6726
+ }
6727
+ function extractUserFromEmail(email) {
6728
+ const normalizedEmail = lower(email);
6729
+ if (!normalizedEmail.includes("@")) {
6730
+ return "";
6731
+ }
6732
+ return normalizedEmail.split("@")[0] || "";
6701
6733
  }
6702
6734
  function pickUserData(response) {
6703
6735
  const data = response?.data || {};
@@ -6721,7 +6753,7 @@ function hasUserProfileData(entry) {
6721
6753
  if (!entry || typeof entry !== "object") {
6722
6754
  return false;
6723
6755
  }
6724
- return Boolean(normalize6(entry.name) || normalize6(entry.user) || normalize6(entry.email));
6756
+ return Boolean(normalizeText(entry.name) || normalizeText(entry.user) || normalizeText(entry.email));
6725
6757
  }
6726
6758
  var IdentityResolver = class {
6727
6759
  logger;
@@ -6735,36 +6767,36 @@ var IdentityResolver = class {
6735
6767
  this.cachePath = VOPS_USER_CACHE_PATH2;
6736
6768
  }
6737
6769
  setTraceId(traceId = "") {
6738
- this.currentTraceId = normalize6(traceId) || "-";
6770
+ this.currentTraceId = normalizeText(traceId) || "-";
6739
6771
  }
6740
6772
  trace(message) {
6741
6773
  return formatTraceLog(this.currentTraceId, message);
6742
6774
  }
6743
6775
  scoreUserRecord(record) {
6744
6776
  let score = 0;
6745
- if (normalize6(record?.user || "")) score += 100;
6746
- if (normalize6(record?.email || "")) score += 40;
6747
- if (normalize6(record?.feishuUserId || "")) score += 30;
6748
- if (normalize6(record?.feishuOpenId || "")) score += 20;
6749
- if (normalize6(record?.name || "")) score += 10;
6750
- if (normalize6(record?.uId || "")) score += 5;
6777
+ if (normalizeText(record?.user || "")) score += 100;
6778
+ if (normalizeText(record?.email || "")) score += 40;
6779
+ if (normalizeText(record?.feishuUserId || "")) score += 30;
6780
+ if (normalizeText(record?.feishuOpenId || "")) score += 20;
6781
+ if (normalizeText(record?.name || "")) score += 10;
6782
+ if (normalizeText(record?.uId || "")) score += 5;
6751
6783
  return score;
6752
6784
  }
6753
6785
  mergeUserRecord(base, extra) {
6754
6786
  const merged = { ...base };
6755
6787
  const fields = ["uId", "name", "feishuUserId", "feishuOpenId", "feishuProjectUser", "user", "email"];
6756
6788
  for (const field of fields) {
6757
- const baseValue = normalize6(merged[field]);
6758
- const extraValue = normalize6(extra?.[field]);
6789
+ const baseValue = normalizeText(merged[field]);
6790
+ const extraValue = normalizeText(extra?.[field]);
6759
6791
  if (!baseValue && extraValue) {
6760
6792
  merged[field] = extraValue;
6761
6793
  }
6762
6794
  }
6763
- const baseUpdated = normalize6(base?.updatedAt);
6764
- const extraUpdated = normalize6(extra?.updatedAt);
6795
+ const baseUpdated = normalizeText(base?.updatedAt);
6796
+ const extraUpdated = normalizeText(extra?.updatedAt);
6765
6797
  merged.updatedAt = baseUpdated && extraUpdated ? baseUpdated >= extraUpdated ? baseUpdated : extraUpdated : baseUpdated || extraUpdated || (/* @__PURE__ */ new Date()).toISOString();
6766
6798
  const emailUser = extractUserFromEmail(merged.email);
6767
- if (!normalize6(merged.user) && emailUser) {
6799
+ if (!normalizeText(merged.user) && emailUser) {
6768
6800
  merged.user = emailUser;
6769
6801
  }
6770
6802
  return merged;
@@ -6782,8 +6814,8 @@ var IdentityResolver = class {
6782
6814
  chatEntries.push(row);
6783
6815
  continue;
6784
6816
  }
6785
- const normalizedEmail = normalize6(row.email);
6786
- const normalizedUser = normalize6(row.user) || extractUserFromEmail(normalizedEmail);
6817
+ const normalizedEmail = normalizeText(row.email);
6818
+ const normalizedUser = normalizeText(row.user) || extractUserFromEmail(normalizedEmail);
6787
6819
  row.email = normalizedEmail;
6788
6820
  row.user = lower(normalizedUser);
6789
6821
  userEntries.push(row);
@@ -6808,28 +6840,28 @@ var IdentityResolver = class {
6808
6840
  const userRecords = Array.from(byUser.values());
6809
6841
  const userNameCount = /* @__PURE__ */ new Map();
6810
6842
  userRecords.forEach((item) => {
6811
- const nameKey = normalize6(item.name);
6843
+ const nameKey = normalizeText(item.name);
6812
6844
  if (nameKey) {
6813
6845
  userNameCount.set(nameKey, (userNameCount.get(nameKey) || 0) + 1);
6814
6846
  }
6815
6847
  });
6816
6848
  const uniqueNameToUser = /* @__PURE__ */ new Map();
6817
6849
  userRecords.forEach((item) => {
6818
- const nameKey = normalize6(item.name);
6850
+ const nameKey = normalizeText(item.name);
6819
6851
  if (nameKey && userNameCount.get(nameKey) === 1) {
6820
6852
  uniqueNameToUser.set(nameKey, item);
6821
6853
  }
6822
6854
  });
6823
6855
  const byNoUserKey = /* @__PURE__ */ new Map();
6824
6856
  for (const record of noUser) {
6825
- const nameKey = normalize6(record.name);
6857
+ const nameKey = normalizeText(record.name);
6826
6858
  const uniqueNameTarget = uniqueNameToUser.get(nameKey);
6827
6859
  if (uniqueNameTarget) {
6828
6860
  const merged = this.mergeUserRecord(uniqueNameTarget, record);
6829
6861
  byUser.set(lower(merged.user || uniqueNameTarget.user || ""), merged);
6830
6862
  continue;
6831
6863
  }
6832
- const idKey = normalize6(record.feishuUserId) || normalize6(record.feishuOpenId) || normalize6(record.uId) || `${nameKey}#${normalize6(record.updatedAt)}`;
6864
+ const idKey = normalizeText(record.feishuUserId) || normalizeText(record.feishuOpenId) || normalizeText(record.uId) || `${nameKey}#${normalizeText(record.updatedAt)}`;
6833
6865
  const existed = byNoUserKey.get(idKey);
6834
6866
  if (!existed) {
6835
6867
  byNoUserKey.set(idKey, record);
@@ -6874,25 +6906,25 @@ var IdentityResolver = class {
6874
6906
  }
6875
6907
  }
6876
6908
  findUserEntries(cache, { userId, openId }) {
6877
- const uid = normalize6(userId);
6878
- const oid = normalize6(openId);
6909
+ const uid = normalizeText(userId);
6910
+ const oid = normalizeText(openId);
6879
6911
  return (cache || []).filter((item) => {
6880
6912
  if (!item || typeof item !== "object" || item.__cacheType === CHAT_CACHE_TYPE) {
6881
6913
  return false;
6882
6914
  }
6883
- return uid && normalize6(item.feishuUserId) === uid || oid && normalize6(item.feishuOpenId) === oid;
6915
+ return uid && normalizeText(item.feishuUserId) === uid || oid && normalizeText(item.feishuOpenId) === oid;
6884
6916
  });
6885
6917
  }
6886
6918
  findChatCache(cache, chatId) {
6887
- const cid = normalize6(chatId);
6919
+ const cid = normalizeText(chatId);
6888
6920
  if (!cid) {
6889
6921
  return null;
6890
6922
  }
6891
- return cache.find((item) => item.__cacheType === CHAT_CACHE_TYPE && normalize6(item.chatId) === cid) || null;
6923
+ return cache.find((item) => item.__cacheType === CHAT_CACHE_TYPE && normalizeText(item.chatId) === cid) || null;
6892
6924
  }
6893
6925
  patchRequesterOpenId(cache, { userId = "", openId = "" } = {}) {
6894
- const uid = normalize6(userId);
6895
- const oid = normalize6(openId);
6926
+ const uid = normalizeText(userId);
6927
+ const oid = normalizeText(openId);
6896
6928
  if (!uid || !oid) {
6897
6929
  return false;
6898
6930
  }
@@ -6901,7 +6933,7 @@ var IdentityResolver = class {
6901
6933
  if (!item || typeof item !== "object" || item.__cacheType === CHAT_CACHE_TYPE) {
6902
6934
  return;
6903
6935
  }
6904
- if (normalize6(item.feishuUserId) === uid && !normalize6(item.feishuOpenId)) {
6936
+ if (normalizeText(item.feishuUserId) === uid && !normalizeText(item.feishuOpenId)) {
6905
6937
  item.feishuOpenId = oid;
6906
6938
  item.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
6907
6939
  changed = true;
@@ -6910,8 +6942,8 @@ var IdentityResolver = class {
6910
6942
  return changed;
6911
6943
  }
6912
6944
  async fetchUserFromLark(userId, openId) {
6913
- const targetUserId = normalize6(userId);
6914
- const targetOpenId = normalize6(openId);
6945
+ const targetUserId = normalizeText(userId);
6946
+ const targetOpenId = normalizeText(openId);
6915
6947
  const userApi = this.larkClient?.contact?.v3?.user?.get;
6916
6948
  if (typeof userApi !== "function") {
6917
6949
  return null;
@@ -6940,7 +6972,7 @@ var IdentityResolver = class {
6940
6972
  return null;
6941
6973
  }
6942
6974
  async fetchEmployeeFromDirectory(openId) {
6943
- const oid = normalize6(openId);
6975
+ const oid = normalizeText(openId);
6944
6976
  const request = this.larkClient?.request;
6945
6977
  if (!oid || typeof request !== "function") {
6946
6978
  return null;
@@ -6966,10 +6998,10 @@ var IdentityResolver = class {
6966
6998
  if (!larkUser || typeof larkUser !== "object") {
6967
6999
  return;
6968
7000
  }
6969
- const userId = normalize6(larkUser.user_id || larkUser.userId || fallbackUserId);
6970
- const openId = normalize6(larkUser.open_id || larkUser.openId || fallbackOpenId);
7001
+ const userId = normalizeText(larkUser.user_id || larkUser.userId || fallbackUserId);
7002
+ const openId = normalizeText(larkUser.open_id || larkUser.openId || fallbackOpenId);
6971
7003
  const name = resolveDisplayName(larkUser.name) || resolveDisplayName(larkUser.display_name) || resolveDisplayName(larkUser.en_name) || resolveDisplayName(larkUser.full_name);
6972
- const email = normalize6(larkUser.email);
7004
+ const email = normalizeText(larkUser.email);
6973
7005
  const emailUser = extractUserFromEmail(email);
6974
7006
  const now = (/* @__PURE__ */ new Date()).toISOString();
6975
7007
  if (!userId && !openId && !name) {
@@ -6983,7 +7015,7 @@ var IdentityResolver = class {
6983
7015
  existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE && (lower(item.user) === lower(emailUser) || lower(item.email) === lower(email))) || null;
6984
7016
  }
6985
7017
  if (!existing && name) {
6986
- existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE && normalize6(item.name) === name && normalize6(item.user)) || null;
7018
+ existing = cache.find((item) => item.__cacheType !== CHAT_CACHE_TYPE && normalizeText(item.name) === name && normalizeText(item.user)) || null;
6987
7019
  }
6988
7020
  if (existing) {
6989
7021
  existing.name = name || existing.name || "";
@@ -7010,7 +7042,7 @@ var IdentityResolver = class {
7010
7042
  });
7011
7043
  }
7012
7044
  async fetchChatNameFromLark(chatId) {
7013
- const cid = normalize6(chatId);
7045
+ const cid = normalizeText(chatId);
7014
7046
  const chatApi = this.larkClient?.im?.v1?.chat?.get;
7015
7047
  if (!cid || typeof chatApi !== "function") {
7016
7048
  return "";
@@ -7033,7 +7065,7 @@ var IdentityResolver = class {
7033
7065
  return "";
7034
7066
  }
7035
7067
  async fetchChatMembersFromLark(chatId) {
7036
- const cid = normalize6(chatId);
7068
+ const cid = normalizeText(chatId);
7037
7069
  const api = this.larkClient?.im?.v1?.chatMembers?.get;
7038
7070
  if (!cid || typeof api !== "function") {
7039
7071
  return [];
@@ -7058,8 +7090,8 @@ var IdentityResolver = class {
7058
7090
  }
7059
7091
  let changed = false;
7060
7092
  for (const member of members) {
7061
- const userId = normalize6(member.member_id || member.user_id || member.userId);
7062
- const openId = normalize6(member.open_id || member.openId);
7093
+ const userId = normalizeText(member.member_id || member.user_id || member.userId);
7094
+ const openId = normalizeText(member.open_id || member.openId);
7063
7095
  const name = resolveDisplayName(member.name) || resolveDisplayName(member.display_name) || resolveDisplayName(member.en_name);
7064
7096
  if (!userId && !openId && !name) {
7065
7097
  continue;
@@ -7074,8 +7106,8 @@ var IdentityResolver = class {
7074
7106
  return changed;
7075
7107
  }
7076
7108
  upsertChatCache(cache, chatId, chatName) {
7077
- const cid = normalize6(chatId);
7078
- const cname = normalize6(chatName);
7109
+ const cid = normalizeText(chatId);
7110
+ const cname = normalizeText(chatName);
7079
7111
  if (!cid) {
7080
7112
  return;
7081
7113
  }
@@ -7094,7 +7126,7 @@ var IdentityResolver = class {
7094
7126
  }
7095
7127
  async resolveRequester({ userId = "", openId = "", chatId = "" } = {}) {
7096
7128
  const cache = this.loadCache();
7097
- this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u5F00\u59CB: user_id=${normalize6(userId) || "-"}, open_id=${normalize6(openId) || "-"}, chat_id=${normalize6(chatId) || "-"}`));
7129
+ this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u5F00\u59CB: user_id=${normalizeText(userId) || "-"}, open_id=${normalizeText(openId) || "-"}, chat_id=${normalizeText(chatId) || "-"}`));
7098
7130
  if (this.patchRequesterOpenId(cache, { userId, openId })) {
7099
7131
  this.saveCache();
7100
7132
  }
@@ -7102,12 +7134,12 @@ var IdentityResolver = class {
7102
7134
  if (matchedEntries.length > 0) {
7103
7135
  const first = matchedEntries[0] || {};
7104
7136
  if (hasUserProfileData(first)) {
7105
- this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u547D\u4E2D\u7F13\u5B58: matched=${matchedEntries.length}, name=${resolveDisplayName(first.name) || "-"}, user=${normalize6(first.user) || "-"}, email=${normalize6(first.email) || "-"}`));
7137
+ this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u547D\u4E2D\u7F13\u5B58: matched=${matchedEntries.length}, name=${resolveDisplayName(first.name) || "-"}, user=${normalizeText(first.user) || "-"}, email=${normalizeText(first.email) || "-"}`));
7106
7138
  return {
7107
- userId: normalize6(userId) || normalize6(first.feishuUserId),
7108
- openId: normalize6(openId) || normalize6(first.feishuOpenId),
7109
- name: resolveDisplayName(first.name) || normalize6(first.user) || normalize6(userId),
7110
- email: normalize6(first.email),
7139
+ userId: normalizeText(userId) || normalizeText(first.feishuUserId),
7140
+ openId: normalizeText(openId) || normalizeText(first.feishuOpenId),
7141
+ name: resolveDisplayName(first.name) || normalizeText(first.user) || normalizeText(userId),
7142
+ email: normalizeText(first.email),
7111
7143
  matchedEntries,
7112
7144
  from: "cache"
7113
7145
  };
@@ -7117,14 +7149,14 @@ var IdentityResolver = class {
7117
7149
  if (directoryEmployee) {
7118
7150
  const base = directoryEmployee.base_info || directoryEmployee.baseInfo || {};
7119
7151
  const dirName = resolveDisplayName(base.name) || resolveDisplayName(directoryEmployee.name);
7120
- const dirEmail = normalize6(base.email || directoryEmployee.email);
7152
+ const dirEmail = normalizeText(base.email || directoryEmployee.email);
7121
7153
  if (dirName || dirEmail) {
7122
- this.updateUserCache(cache, { user_id: normalize6(userId), open_id: normalize6(openId), name: dirName, email: dirEmail }, userId, openId);
7154
+ this.updateUserCache(cache, { user_id: normalizeText(userId), open_id: normalizeText(openId), name: dirName, email: dirEmail }, userId, openId);
7123
7155
  this.saveCache();
7124
7156
  return {
7125
- userId: normalize6(userId),
7126
- openId: normalize6(openId),
7127
- name: dirName || normalize6(userId) || "-",
7157
+ userId: normalizeText(userId),
7158
+ openId: normalizeText(openId),
7159
+ name: dirName || normalizeText(userId) || "-",
7128
7160
  email: dirEmail,
7129
7161
  matchedEntries: this.findUserEntries(cache, { userId, openId }),
7130
7162
  from: "directory"
@@ -7136,21 +7168,21 @@ var IdentityResolver = class {
7136
7168
  this.updateUserCache(cache, larkUser, userId, openId);
7137
7169
  this.saveCache();
7138
7170
  const refreshedMatches = this.findUserEntries(cache, {
7139
- userId: normalize6(larkUser.user_id || userId),
7140
- openId: normalize6(larkUser.open_id || openId)
7171
+ userId: normalizeText(larkUser.user_id || userId),
7172
+ openId: normalizeText(larkUser.open_id || openId)
7141
7173
  });
7142
7174
  return {
7143
- userId: normalize6(larkUser.user_id || userId),
7144
- openId: normalize6(larkUser.open_id || openId),
7145
- name: resolveDisplayName(larkUser.name) || normalize6(userId),
7146
- email: normalize6(larkUser.email),
7175
+ userId: normalizeText(larkUser.user_id || userId),
7176
+ openId: normalizeText(larkUser.open_id || openId),
7177
+ name: resolveDisplayName(larkUser.name) || normalizeText(userId),
7178
+ email: normalizeText(larkUser.email),
7147
7179
  matchedEntries: refreshedMatches,
7148
7180
  from: "lark"
7149
7181
  };
7150
7182
  }
7151
7183
  const members = await this.fetchChatMembersFromLark(chatId);
7152
7184
  if (members.length > 0) {
7153
- this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u7FA4\u6210\u5458\u515C\u5E95: chat_id=${normalize6(chatId) || "-"}, members=${members.length}`));
7185
+ this.logger.info(this.trace(`\u8EAB\u4EFD\u89E3\u6790\u7FA4\u6210\u5458\u515C\u5E95: chat_id=${normalizeText(chatId) || "-"}, members=${members.length}`));
7154
7186
  this.syncChatMembersToCache(cache, members);
7155
7187
  this.patchRequesterOpenId(cache, { userId, openId });
7156
7188
  this.saveCache();
@@ -7158,19 +7190,19 @@ var IdentityResolver = class {
7158
7190
  if (memberMatches.length > 0) {
7159
7191
  const first = memberMatches[0] || {};
7160
7192
  return {
7161
- userId: normalize6(userId) || normalize6(first.feishuUserId),
7162
- openId: normalize6(openId) || normalize6(first.feishuOpenId),
7163
- name: resolveDisplayName(first.name) || normalize6(first.user) || normalize6(userId),
7164
- email: normalize6(first.email),
7193
+ userId: normalizeText(userId) || normalizeText(first.feishuUserId),
7194
+ openId: normalizeText(openId) || normalizeText(first.feishuOpenId),
7195
+ name: resolveDisplayName(first.name) || normalizeText(first.user) || normalizeText(userId),
7196
+ email: normalizeText(first.email),
7165
7197
  matchedEntries: memberMatches,
7166
7198
  from: "chat_members"
7167
7199
  };
7168
7200
  }
7169
7201
  }
7170
7202
  return {
7171
- userId: normalize6(userId),
7172
- openId: normalize6(openId),
7173
- name: normalize6(userId) || "-",
7203
+ userId: normalizeText(userId),
7204
+ openId: normalizeText(openId),
7205
+ name: normalizeText(userId) || "-",
7174
7206
  email: "",
7175
7207
  matchedEntries: [],
7176
7208
  from: "id"
@@ -7179,16 +7211,16 @@ var IdentityResolver = class {
7179
7211
  async resolveChat({ chatId = "" } = {}) {
7180
7212
  const cache = this.loadCache();
7181
7213
  const cached = this.findChatCache(cache, chatId);
7182
- if (normalize6(cached?.chatName)) {
7183
- return { chatId: normalize6(chatId), chatName: normalize6(cached?.chatName), from: "cache" };
7214
+ if (normalizeText(cached?.chatName)) {
7215
+ return { chatId: normalizeText(chatId), chatName: normalizeText(cached?.chatName), from: "cache" };
7184
7216
  }
7185
7217
  const chatName = await this.fetchChatNameFromLark(chatId);
7186
7218
  if (chatName) {
7187
7219
  this.upsertChatCache(cache, chatId, chatName);
7188
7220
  this.saveCache();
7189
- return { chatId: normalize6(chatId), chatName, from: "lark" };
7221
+ return { chatId: normalizeText(chatId), chatName, from: "lark" };
7190
7222
  }
7191
- return { chatId: normalize6(chatId), chatName: normalize6(chatId) || "-", from: "id" };
7223
+ return { chatId: normalizeText(chatId), chatName: normalizeText(chatId) || "-", from: "id" };
7192
7224
  }
7193
7225
  async resolveConversationIdentity({ senderUserId = "", senderOpenId = "", chatId = "" } = {}) {
7194
7226
  const requester = await this.resolveRequester({ userId: senderUserId, openId: senderOpenId, chatId });
@@ -7251,7 +7283,7 @@ var REQUESTER_PERSONA_RULES = Object.freeze({
7251
7283
  var OPS_DIR = path12.join(os6.homedir(), "ops");
7252
7284
  var NIKOU_PROMPTS_DIR = path12.join(OPS_DIR, "nikou-prompts");
7253
7285
  var NIKOU_ROLE_PROMPTS_DIR = path12.join(NIKOU_PROMPTS_DIR, "roles");
7254
- function normalizeText(value) {
7286
+ function normalizeText2(value) {
7255
7287
  return String(value || "").trim();
7256
7288
  }
7257
7289
  function ensureDir(dirPath) {
@@ -7319,12 +7351,12 @@ function buildPromptDefinitions() {
7319
7351
  const roleDefinitions = Object.entries(REQUESTER_PERSONA_RULES.roles).map(([roleKey, roleConfig]) => ({
7320
7352
  id: roleKey,
7321
7353
  kind: "role",
7322
- title: `${normalizeText(roleConfig.label) || roleKey}\u89D2\u8272\u63D0\u793A\u8BCD`,
7354
+ title: `${normalizeText2(roleConfig.label) || roleKey}\u89D2\u8272\u63D0\u793A\u8BCD`,
7323
7355
  path: path12.join(NIKOU_ROLE_PROMPTS_DIR, `${roleKey}.md`),
7324
7356
  legacyPaths: [],
7325
7357
  defaultContent: Array.isArray(roleConfig.promptLines) ? roleConfig.promptLines.join("\n") : "",
7326
7358
  roleKey,
7327
- roleLabel: normalizeText(roleConfig.label) || roleKey
7359
+ roleLabel: normalizeText2(roleConfig.label) || roleKey
7328
7360
  }));
7329
7361
  return [
7330
7362
  {
@@ -7459,7 +7491,7 @@ var NikouPromptStore = class {
7459
7491
  });
7460
7492
  }
7461
7493
  readRolePrompt(roleKey) {
7462
- const normalizedRoleKey = normalizeText(roleKey);
7494
+ const normalizedRoleKey = normalizeText2(roleKey);
7463
7495
  if (!normalizedRoleKey || !this.definitions.has(normalizedRoleKey)) {
7464
7496
  return "";
7465
7497
  }
@@ -7590,9 +7622,9 @@ var MessageReceiveStrategy = class {
7590
7622
  const message = event?.message || {};
7591
7623
  const senderId = this.resolveSenderUserId(eventPayload);
7592
7624
  const senderOpenId = this.resolveSenderOpenId(eventPayload);
7593
- const chatId = String(message?.chat_id || "").trim();
7594
- const chatType = String(message?.chat_type || "").trim();
7595
- const messageId = String(message?.message_id || "").trim();
7625
+ const chatId = normalizeText(message?.chat_id || message?.chatId);
7626
+ const chatType = normalizeText(message?.chat_type || message?.chatType);
7627
+ const messageId = normalizeText(message?.message_id || message?.messageId);
7596
7628
  if (!chatId || !messageId) {
7597
7629
  return null;
7598
7630
  }
@@ -7602,12 +7634,12 @@ var MessageReceiveStrategy = class {
7602
7634
  messageId,
7603
7635
  senderId,
7604
7636
  senderOpenId,
7605
- messageType: String(message?.message_type || "text").trim(),
7606
- content: String(message?.content || "").trim(),
7607
- rootId: String(message?.root_id || "").trim(),
7608
- parentId: String(message?.parent_id || "").trim(),
7609
- threadId: String(message?.thread_id || "").trim(),
7610
- createTime: Number.parseInt(String(message?.create_time || 0), 10) || 0,
7637
+ messageType: normalizeText(message?.message_type || message?.messageType || "text"),
7638
+ content: normalizeText(message?.content),
7639
+ rootId: normalizeText(message?.root_id || message?.rootId),
7640
+ parentId: normalizeText(message?.parent_id || message?.parentId),
7641
+ threadId: normalizeText(message?.thread_id || message?.threadId),
7642
+ createTime: Number.parseInt(normalizeText(message?.create_time || message?.createTime || 0), 10) || 0,
7611
7643
  mentions: Array.isArray(message?.mentions) ? message.mentions : []
7612
7644
  };
7613
7645
  }
@@ -7677,7 +7709,8 @@ var MessageReceiveStrategy = class {
7677
7709
  lines.push(`\u6267\u884C\u8EAB\u4EFD: ${resolveOpsUserName()}`);
7678
7710
  }
7679
7711
  if (includeRequester && identity?.requester) {
7680
- lines.push(`\u63D0\u95EE\u8005: ${identity.requester.name || "-"}(${identity.requester.userId || "-"})`);
7712
+ const requesterName = resolveDisplayName(identity.requester.name) || normalizeText(identity.requester.user) || "-";
7713
+ lines.push(`\u63D0\u95EE\u8005: ${requesterName}(${normalizeText(identity.requester.userId) || "-"})`);
7681
7714
  if (includeRequesterEmail && identity.requester.email) {
7682
7715
  lines.push(`\u63D0\u95EE\u8005\u90AE\u7BB1: ${identity.requester.email}`);
7683
7716
  }
@@ -7686,7 +7719,7 @@ var MessageReceiveStrategy = class {
7686
7719
  }
7687
7720
  }
7688
7721
  if (includeChat && identity?.chat) {
7689
- lines.push(`\u63D0\u95EE\u7FA4\u804A: ${identity.chat.chatName || "-"}(${identity.chat.chatId || "-"})`);
7722
+ lines.push(`\u63D0\u95EE\u7FA4\u804A: ${resolveDisplayName(identity.chat.chatName) || "-"}(${normalizeText(identity.chat.chatId) || "-"})`);
7690
7723
  }
7691
7724
  return lines;
7692
7725
  }
@@ -11087,7 +11120,7 @@ var LocalBrowserWsServer = class {
11087
11120
  import fs17 from "fs";
11088
11121
  import os10 from "os";
11089
11122
  import path16 from "path";
11090
- function normalize7(value) {
11123
+ function normalize6(value) {
11091
11124
  if (value === null || value === void 0) {
11092
11125
  return "";
11093
11126
  }
@@ -11100,8 +11133,8 @@ var HostProfileService = class {
11100
11133
  cachePath;
11101
11134
  constructor(options) {
11102
11135
  this.logger = options.logger;
11103
- this.ownerUserId = normalize7(options.ownerUserId);
11104
- this.opsUserName = normalize7(options.opsUserName);
11136
+ this.ownerUserId = normalize6(options.ownerUserId);
11137
+ this.opsUserName = normalize6(options.opsUserName);
11105
11138
  this.cachePath = path16.join(os10.homedir(), "ops", "vops_user.json");
11106
11139
  }
11107
11140
  /**
@@ -11111,12 +11144,12 @@ var HostProfileService = class {
11111
11144
  getProfile() {
11112
11145
  const cacheEntry = this.findCacheEntry();
11113
11146
  return {
11114
- name: normalize7(cacheEntry?.name),
11115
- feishuUserId: this.ownerUserId || normalize7(cacheEntry?.feishuUserId),
11116
- feishuOpenId: normalize7(cacheEntry?.feishuOpenId),
11117
- employeeNo: normalize7(cacheEntry?.user || cacheEntry?.uId),
11118
- email: normalize7(cacheEntry?.email),
11119
- user: normalize7(cacheEntry?.user),
11147
+ name: normalize6(cacheEntry?.name),
11148
+ feishuUserId: this.ownerUserId || normalize6(cacheEntry?.feishuUserId),
11149
+ feishuOpenId: normalize6(cacheEntry?.feishuOpenId),
11150
+ employeeNo: normalize6(cacheEntry?.user || cacheEntry?.uId),
11151
+ email: normalize6(cacheEntry?.email),
11152
+ user: normalize6(cacheEntry?.user),
11120
11153
  opsUserName: this.opsUserName,
11121
11154
  source: cacheEntry ? "cache" : "fallback"
11122
11155
  };
@@ -11128,11 +11161,11 @@ var HostProfileService = class {
11128
11161
  try {
11129
11162
  const parsed = JSON.parse(fs17.readFileSync(this.cachePath, "utf-8"));
11130
11163
  const list = Array.isArray(parsed) ? parsed : [];
11131
- const byUserId = list.find((item) => normalize7(item.feishuUserId) === this.ownerUserId);
11164
+ const byUserId = list.find((item) => normalize6(item.feishuUserId) === this.ownerUserId);
11132
11165
  if (byUserId) {
11133
11166
  return byUserId;
11134
11167
  }
11135
- const byOpsUser = list.find((item) => normalize7(item.user) === this.opsUserName);
11168
+ const byOpsUser = list.find((item) => normalize6(item.user) === this.opsUserName);
11136
11169
  if (byOpsUser) {
11137
11170
  return byOpsUser;
11138
11171
  }
@@ -11151,7 +11184,7 @@ import os11 from "os";
11151
11184
  import path17 from "path";
11152
11185
 
11153
11186
  // src/hook/profile/codex-account-utils.ts
11154
- function normalize8(value) {
11187
+ function normalize7(value) {
11155
11188
  if (value === null || value === void 0) {
11156
11189
  return "";
11157
11190
  }
@@ -11164,7 +11197,7 @@ function compactLine(line) {
11164
11197
  return stripAnsi2(line).replace(/[│╭╮╰╯]/g, " ").replace(/\s+/g, " ").trim();
11165
11198
  }
11166
11199
  function pickLine(lines, prefix) {
11167
- const lowerPrefix = normalize8(prefix).toLowerCase();
11200
+ const lowerPrefix = normalize7(prefix).toLowerCase();
11168
11201
  return lines.find((item) => compactLine(item).toLowerCase().startsWith(lowerPrefix)) || "";
11169
11202
  }
11170
11203
  function extractValue(line) {
@@ -11262,7 +11295,7 @@ function normalizeMonth(monthText) {
11262
11295
  return monthMap[String(monthText || "").trim().toLowerCase()] || "";
11263
11296
  }
11264
11297
  function normalizeResetText(raw) {
11265
- const text = normalize8(raw);
11298
+ const text = normalize7(raw);
11266
11299
  if (!text) {
11267
11300
  return "";
11268
11301
  }
@@ -11309,7 +11342,7 @@ function normalizeUsageText(rawText) {
11309
11342
  return text;
11310
11343
  }
11311
11344
  function normalizePlan(plan) {
11312
- const raw = normalize8(plan).toLowerCase();
11345
+ const raw = normalize7(plan).toLowerCase();
11313
11346
  if (!raw) {
11314
11347
  return "";
11315
11348
  }
@@ -11329,10 +11362,10 @@ function extractAuthState(auth) {
11329
11362
  }
11330
11363
  const tokens = auth.tokens || {};
11331
11364
  return {
11332
- accessToken: normalize8(tokens.access_token),
11333
- idToken: normalize8(tokens.id_token),
11334
- accountId: normalize8(tokens.account_id || auth.account_id),
11335
- authMode: normalize8(auth.auth_mode)
11365
+ accessToken: normalize7(tokens.access_token),
11366
+ idToken: normalize7(tokens.id_token),
11367
+ accountId: normalize7(tokens.account_id || auth.account_id),
11368
+ authMode: normalize7(auth.auth_mode)
11336
11369
  };
11337
11370
  }
11338
11371
  function extractAccountInfo(auth) {
@@ -11340,10 +11373,10 @@ function extractAccountInfo(auth) {
11340
11373
  const payload = decodeJwtPayload(authState.accessToken || authState.idToken || "");
11341
11374
  const profileInfo = payload["https://api.openai.com/profile"] || {};
11342
11375
  const authInfo = payload["https://api.openai.com/auth"] || {};
11343
- const email = normalize8(profileInfo.email || payload.email);
11344
- const planType = normalize8(authInfo.chatgpt_plan_type);
11345
- const accountId = normalize8(authInfo.chatgpt_account_id || authState.accountId);
11346
- const userId = normalize8(authInfo.chatgpt_user_id || authInfo.user_id);
11376
+ const email = normalize7(profileInfo.email || payload.email);
11377
+ const planType = normalize7(authInfo.chatgpt_plan_type);
11378
+ const accountId = normalize7(authInfo.chatgpt_account_id || authState.accountId);
11379
+ const userId = normalize7(authInfo.chatgpt_user_id || authInfo.user_id);
11347
11380
  const planLabel = normalizePlan(planType);
11348
11381
  return {
11349
11382
  email,
@@ -11361,8 +11394,8 @@ function pickRealtimeLimits(payload) {
11361
11394
  const secondary = rateLimit.secondary_window || null;
11362
11395
  const additional = Array.isArray(payload.additional_rate_limits) ? payload.additional_rate_limits : [];
11363
11396
  const weeklyCandidate = additional.find((item) => {
11364
- const feature = normalize8(item.metered_feature).toLowerCase();
11365
- const name = normalize8(item.limit_name).toLowerCase();
11397
+ const feature = normalize7(item.metered_feature).toLowerCase();
11398
+ const name = normalize7(item.limit_name).toLowerCase();
11366
11399
  return feature.includes("weekly") || name.includes("weekly");
11367
11400
  }) || additional[0] || null;
11368
11401
  const weeklyRateLimit = weeklyCandidate ? (weeklyCandidate.rate_limit || {}).primary_window : secondary;
@@ -11504,7 +11537,7 @@ var CodexStatusService = class {
11504
11537
  import fs19 from "fs";
11505
11538
  import os12 from "os";
11506
11539
  import path18 from "path";
11507
- function normalize9(value) {
11540
+ function normalize8(value) {
11508
11541
  return String(value || "").trim();
11509
11542
  }
11510
11543
  function ensureStoreShape(store) {
@@ -11554,7 +11587,7 @@ function compareProfiles(left, right) {
11554
11587
  return String(left.alias || "").localeCompare(String(right.alias || ""), "zh-Hans-CN");
11555
11588
  }
11556
11589
  function isSameAccount(profile, targetAccount, targetState) {
11557
- const profileAccountId = normalize9(profile.account?.accountId);
11590
+ const profileAccountId = normalize8(profile.account?.accountId);
11558
11591
  if (profileAccountId && targetAccount.accountId && profileAccountId === targetAccount.accountId) {
11559
11592
  return true;
11560
11593
  }
@@ -11742,11 +11775,11 @@ var CodexAccountService = class {
11742
11775
  const profiles = refreshedProfiles.sort(compareProfiles).map((profile) => ({
11743
11776
  alias: profile.alias,
11744
11777
  current: profile.alias === store.current,
11745
- account: normalize9(profile.account?.displayText || profile.account?.email),
11746
- planLabel: normalize9(profile.account?.planLabel),
11747
- fiveHourLimit: normalize9(profile.usage?.fiveHourLimit),
11748
- weeklyLimit: normalize9(profile.usage?.weeklyLimit),
11749
- updatedAt: normalize9(profile.usage?.updatedAt || profile.updatedAt),
11778
+ account: normalize8(profile.account?.displayText || profile.account?.email),
11779
+ planLabel: normalize8(profile.account?.planLabel),
11780
+ fiveHourLimit: normalize8(profile.usage?.fiveHourLimit),
11781
+ weeklyLimit: normalize8(profile.usage?.weeklyLimit),
11782
+ updatedAt: normalize8(profile.usage?.updatedAt || profile.updatedAt),
11750
11783
  fetchOk: Boolean(profile.usage?.fiveHourLimit || profile.usage?.weeklyLimit)
11751
11784
  }));
11752
11785
  return {
@@ -11758,7 +11791,7 @@ var CodexAccountService = class {
11758
11791
  * 按别名切换当前 ~/.codex/auth.json。
11759
11792
  */
11760
11793
  async switchAlias(alias) {
11761
- const normalizedAlias = normalize9(alias);
11794
+ const normalizedAlias = normalize8(alias);
11762
11795
  const store = await this.ensureCurrentAuthProfile(this.loadStore());
11763
11796
  const target = normalizedAlias ? store.profiles[normalizedAlias] : void 0;
11764
11797
  if (!target) {
@@ -11781,10 +11814,10 @@ var CodexAccountService = class {
11781
11814
  return {
11782
11815
  ok: true,
11783
11816
  alias: normalizedAlias,
11784
- account: normalize9(refreshed.account?.displayText || refreshed.account?.email),
11785
- planLabel: normalize9(refreshed.account?.planLabel),
11786
- fiveHourLimit: normalize9(refreshed.usage?.fiveHourLimit),
11787
- weeklyLimit: normalize9(refreshed.usage?.weeklyLimit),
11817
+ account: normalize8(refreshed.account?.displayText || refreshed.account?.email),
11818
+ planLabel: normalize8(refreshed.account?.planLabel),
11819
+ fiveHourLimit: normalize8(refreshed.usage?.fiveHourLimit),
11820
+ weeklyLimit: normalize8(refreshed.usage?.weeklyLimit),
11788
11821
  message: ""
11789
11822
  };
11790
11823
  }
@@ -11793,7 +11826,7 @@ var CodexAccountService = class {
11793
11826
  // src/hook/bind/bind-chat-profile-service.ts
11794
11827
  import os13 from "os";
11795
11828
  import path19 from "path";
11796
- function normalize10(value) {
11829
+ function normalize9(value) {
11797
11830
  if (value === null || value === void 0) {
11798
11831
  return "";
11799
11832
  }
@@ -11817,7 +11850,7 @@ var BindChatProfileService = class {
11817
11850
  path: { chat_id: chatId }
11818
11851
  });
11819
11852
  const data = response?.data || response || {};
11820
- return normalize10(data.name || data.chat_name || data.chat?.name);
11853
+ return normalize9(data.name || data.chat_name || data.chat?.name);
11821
11854
  } catch (error) {
11822
11855
  const message = error instanceof Error ? error.message : String(error);
11823
11856
  this.logger.warn(`\u7FA4\u804A\u540D\u79F0\u89E3\u6790\u5931\u8D25: chat_id=${chatId}, error=${message}`);
@@ -11833,21 +11866,21 @@ var BindChatProfileService = class {
11833
11866
  const items = [];
11834
11867
  for (const [dirPath, binding] of Object.entries(bindings)) {
11835
11868
  const chatIds = Array.isArray(binding?.chat_ids) ? binding.chat_ids.filter(Boolean) : [];
11836
- const dirName = path19.basename(dirPath || "") || normalize10(dirPath);
11869
+ const dirName = path19.basename(dirPath || "") || normalize9(dirPath);
11837
11870
  for (const chatId of chatIds) {
11838
11871
  const chatName = await this.resolveChatName(chatId);
11839
11872
  items.push({
11840
- chatId: normalize10(chatId),
11841
- chatName: chatName || normalize10(chatId),
11873
+ chatId: normalize9(chatId),
11874
+ chatName: chatName || normalize9(chatId),
11842
11875
  dirName,
11843
- dirPath: normalize10(dirPath),
11844
- bindAt: normalize10(binding?.bindAt)
11876
+ dirPath: normalize9(dirPath),
11877
+ bindAt: normalize9(binding?.bindAt)
11845
11878
  });
11846
11879
  }
11847
11880
  }
11848
11881
  items.sort((left, right) => right.bindAt.localeCompare(left.bindAt));
11849
11882
  return {
11850
- hostName: normalize10(os13.hostname()),
11883
+ hostName: normalize9(os13.hostname()),
11851
11884
  count: items.length,
11852
11885
  items
11853
11886
  };
@@ -11859,7 +11892,7 @@ import fs20 from "fs";
11859
11892
  import os14 from "os";
11860
11893
  import path20 from "path";
11861
11894
  var LATEST_SESSION_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
11862
- function normalize11(value) {
11895
+ function normalize10(value) {
11863
11896
  return String(value || "").trim();
11864
11897
  }
11865
11898
  function isSameLocalDate(leftDate, rightDate) {
@@ -11936,10 +11969,10 @@ var P2PSessionService = class {
11936
11969
  }
11937
11970
  buildSessionKey(input) {
11938
11971
  return [
11939
- normalize11(input.ownerUserId),
11940
- normalize11(input.requesterUserId),
11941
- normalize11(input.chatId),
11942
- normalize11(input.anchorMessageId)
11972
+ normalize10(input.ownerUserId),
11973
+ normalize10(input.requesterUserId),
11974
+ normalize10(input.chatId),
11975
+ normalize10(input.anchorMessageId)
11943
11976
  ].join("::");
11944
11977
  }
11945
11978
  parseNewConversationCommand(text = "") {
@@ -11976,9 +12009,9 @@ var P2PSessionService = class {
11976
12009
  * 解析当前单聊应该复用哪个会话。
11977
12010
  */
11978
12011
  resolveSessionContext(input) {
11979
- const ownerUserId = normalize11(this.stateManager.getState()?.ownerUserId || "");
12012
+ const ownerUserId = normalize10(this.stateManager.getState()?.ownerUserId || "");
11980
12013
  if (!input.forceNew) {
11981
- const candidates = Array.from(new Set([normalize11(input.rootId), normalize11(input.parentId)].filter(Boolean)));
12014
+ const candidates = Array.from(new Set([normalize10(input.rootId), normalize10(input.parentId)].filter(Boolean)));
11982
12015
  for (const referencedId of candidates) {
11983
12016
  const matched = this.stateManager.getP2PSessionByMessageId(referencedId);
11984
12017
  if (!matched) {
@@ -11986,13 +12019,13 @@ var P2PSessionService = class {
11986
12019
  }
11987
12020
  return {
11988
12021
  ownerUserId,
11989
- requesterUserId: normalize11(input.requesterUserId),
11990
- chatId: normalize11(input.chatId),
11991
- dirPath: normalize11(input.dirPath),
11992
- anchorMessageId: normalize11(matched.anchorMessageId || referencedId || input.messageId),
11993
- existingSessionId: normalize11(matched.sessionId),
11994
- sessionKey: normalize11(matched.sessionKey),
11995
- messageIds: Array.isArray(matched.messageIds) ? matched.messageIds.map((item) => normalize11(item)).filter(Boolean) : [],
12022
+ requesterUserId: normalize10(input.requesterUserId),
12023
+ chatId: normalize10(input.chatId),
12024
+ dirPath: normalize10(input.dirPath),
12025
+ anchorMessageId: normalize10(matched.anchorMessageId || referencedId || input.messageId),
12026
+ existingSessionId: normalize10(matched.sessionId),
12027
+ sessionKey: normalize10(matched.sessionKey),
12028
+ messageIds: Array.isArray(matched.messageIds) ? matched.messageIds.map((item) => normalize10(item)).filter(Boolean) : [],
11996
12029
  matchedBy: "reference"
11997
12030
  };
11998
12031
  }
@@ -12001,26 +12034,26 @@ var P2PSessionService = class {
12001
12034
  requesterUserId: input.requesterUserId,
12002
12035
  chatId: input.chatId
12003
12036
  });
12004
- if (latest && normalize11(latest.sessionId)) {
12037
+ if (latest && normalize10(latest.sessionId)) {
12005
12038
  return {
12006
12039
  ownerUserId,
12007
- requesterUserId: normalize11(input.requesterUserId),
12008
- chatId: normalize11(input.chatId),
12009
- dirPath: normalize11(input.dirPath || latest.dirPath),
12010
- anchorMessageId: normalize11(latest.anchorMessageId),
12011
- existingSessionId: normalize11(latest.sessionId),
12012
- sessionKey: normalize11(latest.sessionKey),
12013
- messageIds: Array.isArray(latest.messageIds) ? latest.messageIds.map((item) => normalize11(item)).filter(Boolean) : [],
12040
+ requesterUserId: normalize10(input.requesterUserId),
12041
+ chatId: normalize10(input.chatId),
12042
+ dirPath: normalize10(input.dirPath || latest.dirPath),
12043
+ anchorMessageId: normalize10(latest.anchorMessageId),
12044
+ existingSessionId: normalize10(latest.sessionId),
12045
+ sessionKey: normalize10(latest.sessionKey),
12046
+ messageIds: Array.isArray(latest.messageIds) ? latest.messageIds.map((item) => normalize10(item)).filter(Boolean) : [],
12014
12047
  matchedBy: "latest"
12015
12048
  };
12016
12049
  }
12017
12050
  }
12018
- const anchorMessageId = normalize11(input.rootId || input.parentId || input.messageId);
12051
+ const anchorMessageId = normalize10(input.rootId || input.parentId || input.messageId);
12019
12052
  return {
12020
12053
  ownerUserId,
12021
- requesterUserId: normalize11(input.requesterUserId),
12022
- chatId: normalize11(input.chatId),
12023
- dirPath: normalize11(input.dirPath),
12054
+ requesterUserId: normalize10(input.requesterUserId),
12055
+ chatId: normalize10(input.chatId),
12056
+ dirPath: normalize10(input.dirPath),
12024
12057
  anchorMessageId,
12025
12058
  existingSessionId: "",
12026
12059
  sessionKey: this.buildSessionKey({
@@ -12039,12 +12072,12 @@ var P2PSessionService = class {
12039
12072
  }
12040
12073
  this.stateManager.upsertP2PSession({
12041
12074
  sessionKey: input.sessionKey,
12042
- ownerUserId: normalize11(input.ownerUserId),
12043
- requesterUserId: normalize11(input.requesterUserId),
12044
- chatId: normalize11(input.chatId),
12045
- anchorMessageId: normalize11(input.anchorMessageId),
12046
- dirPath: normalize11(input.dirPath),
12047
- sessionId: normalize11(input.sessionId)
12075
+ ownerUserId: normalize10(input.ownerUserId),
12076
+ requesterUserId: normalize10(input.requesterUserId),
12077
+ chatId: normalize10(input.chatId),
12078
+ anchorMessageId: normalize10(input.anchorMessageId),
12079
+ dirPath: normalize10(input.dirPath),
12080
+ sessionId: normalize10(input.sessionId)
12048
12081
  }, input.messageIds);
12049
12082
  }
12050
12083
  };
@@ -12052,11 +12085,11 @@ var P2PSessionService = class {
12052
12085
  // src/hook/memory/memory-bucket-resolver.ts
12053
12086
  import fs21 from "fs";
12054
12087
  import path21 from "path";
12055
- function normalize12(value) {
12088
+ function normalize11(value) {
12056
12089
  return String(value || "").trim();
12057
12090
  }
12058
12091
  function buildSafeSegment(value, fallback = "unknown") {
12059
- const normalized = normalize12(value).replace(/[<>:"/\\|?*\u0000-\u001F]/g, "_");
12092
+ const normalized = normalize11(value).replace(/[<>:"/\\|?*\u0000-\u001F]/g, "_");
12060
12093
  return normalized || fallback;
12061
12094
  }
12062
12095
  function buildTodayString(offsetDays = 0) {
@@ -12082,8 +12115,8 @@ var MemoryBucketResolver = class {
12082
12115
  const requester = buildSafeSegment(requesterUserId, "requester");
12083
12116
  const baseDir = path21.join(this.getRootDir(), "p2p", owner, requester);
12084
12117
  return this.buildBucket({
12085
- bucketKey: `p2p::${normalize12(ownerUserId)}::${normalize12(requesterUserId)}`,
12086
- bucketLabel: `\u5355\u804A(${normalize12(requesterUserId) || requester})`,
12118
+ bucketKey: `p2p::${normalize11(ownerUserId)}::${normalize11(requesterUserId)}`,
12119
+ bucketLabel: `\u5355\u804A(${normalize11(requesterUserId) || requester})`,
12087
12120
  bucketType: "p2p",
12088
12121
  baseDir,
12089
12122
  chatId
@@ -12093,8 +12126,8 @@ var MemoryBucketResolver = class {
12093
12126
  const chat = buildSafeSegment(chatId, "chat");
12094
12127
  const baseDir = path21.join(this.getRootDir(), "group", chat);
12095
12128
  return this.buildBucket({
12096
- bucketKey: `group::${normalize12(chatId)}`,
12097
- bucketLabel: `\u7FA4\u804A(${normalize12(chatId) || chat})`,
12129
+ bucketKey: `group::${normalize11(chatId)}`,
12130
+ bucketLabel: `\u7FA4\u804A(${normalize11(chatId) || chat})`,
12098
12131
  bucketType: "group",
12099
12132
  baseDir,
12100
12133
  chatId
@@ -12108,7 +12141,7 @@ var MemoryBucketResolver = class {
12108
12141
  bucketKey,
12109
12142
  bucketLabel,
12110
12143
  bucketType,
12111
- chatId: normalize12(chatId),
12144
+ chatId: normalize11(chatId),
12112
12145
  baseDir,
12113
12146
  memoryDir,
12114
12147
  longTermPath: path21.join(baseDir, "MEMORY.md"),
@@ -12138,11 +12171,11 @@ var MemoryBucketResolver = class {
12138
12171
  };
12139
12172
 
12140
12173
  // src/hook/memory/memory-extract-service.ts
12141
- function normalize13(value) {
12174
+ function normalize12(value) {
12142
12175
  return String(value || "").replace(/\s+/g, " ").trim();
12143
12176
  }
12144
12177
  function extractSummary(text = "") {
12145
- const normalized = normalize13(text).replace(/^\/new\s*/i, "").replace(/^(记住|记一下|写入记忆|更新记忆|记到长期记忆)\s*/i, "").trim();
12178
+ const normalized = normalize12(text).replace(/^\/new\s*/i, "").replace(/^(记住|记一下|写入记忆|更新记忆|记到长期记忆)\s*/i, "").trim();
12146
12179
  if (!normalized) {
12147
12180
  return "";
12148
12181
  }
@@ -12150,7 +12183,7 @@ function extractSummary(text = "") {
12150
12183
  }
12151
12184
  var MemoryExtractService = class {
12152
12185
  extractExplicit(text = "") {
12153
- const normalized = normalize13(text);
12186
+ const normalized = normalize12(text);
12154
12187
  if (!normalized) {
12155
12188
  return { matched: false, target: "DAILY", summary: "" };
12156
12189
  }
@@ -12166,8 +12199,8 @@ var MemoryExtractService = class {
12166
12199
  if (String(chatType || "").trim() !== "p2p") {
12167
12200
  return { shouldWrite: false, target: "DAILY", summary: "" };
12168
12201
  }
12169
- const normalized = normalize13(questionText);
12170
- if (!normalized || !normalize13(resultText)) {
12202
+ const normalized = normalize12(questionText);
12203
+ if (!normalized || !normalize12(resultText)) {
12171
12204
  return { shouldWrite: false, target: "DAILY", summary: "" };
12172
12205
  }
12173
12206
  const likelyMemory = /(以后|默认|偏好|习惯|优先|总是|不要|回答时|称呼我|风格|长期|固定规则)/i.test(normalized);
@@ -12184,7 +12217,7 @@ var MemoryExtractService = class {
12184
12217
  };
12185
12218
 
12186
12219
  // src/hook/memory/memory-index-service.ts
12187
- function normalize14(value) {
12220
+ function normalize13(value) {
12188
12221
  return String(value || "").trim();
12189
12222
  }
12190
12223
  function toSnippet(text = "", maxLength = 220) {
@@ -12207,7 +12240,7 @@ var MemoryIndexService = class {
12207
12240
  this.docsByBucket.set(String(bucket.bucketKey || ""), docs);
12208
12241
  }
12209
12242
  async search(bucket, query, limit = 5) {
12210
- const text = normalize14(query);
12243
+ const text = normalize13(query);
12211
12244
  if (!text) {
12212
12245
  return [];
12213
12246
  }
@@ -12243,7 +12276,7 @@ ${content}`.toLowerCase();
12243
12276
  // src/hook/memory/memory-service.ts
12244
12277
  import fs22 from "fs";
12245
12278
  import path22 from "path";
12246
- function normalize15(value) {
12279
+ function normalize14(value) {
12247
12280
  return String(value || "").trim();
12248
12281
  }
12249
12282
  function nowIso() {
@@ -12369,7 +12402,7 @@ ${nextLine}`;
12369
12402
  return { longTermText, dailyText, searchResults };
12370
12403
  }
12371
12404
  resolveCommand(text = "") {
12372
- const normalized = normalize15(text);
12405
+ const normalized = normalize14(text);
12373
12406
  if (!normalized) {
12374
12407
  return { matched: false };
12375
12408
  }
@@ -12380,7 +12413,7 @@ ${nextLine}`;
12380
12413
  if (/^确认重置长期记忆$/i.test(normalized)) return { matched: true, type: "confirm_reset_memory" };
12381
12414
  const searchMatch = normalized.match(/^搜索记忆\s+([\s\S]+)$/i);
12382
12415
  if (searchMatch) {
12383
- return { matched: true, type: "search_memory", query: normalize15(searchMatch[1]) };
12416
+ return { matched: true, type: "search_memory", query: normalize14(searchMatch[1]) };
12384
12417
  }
12385
12418
  const explicit = this.extractService.extractExplicit(normalized);
12386
12419
  if (explicit.matched) {
@@ -12432,7 +12465,7 @@ ${item.snippet}`);
12432
12465
  ${lines.join("\n\n")}` };
12433
12466
  }
12434
12467
  case "write_memory": {
12435
- const summary = normalize15(command.summary);
12468
+ const summary = normalize14(command.summary);
12436
12469
  if (!summary) {
12437
12470
  return { handled: true, text: "\u8BB0\u5FC6\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u5DF2\u5FFD\u7565" };
12438
12471
  }
@@ -12465,7 +12498,7 @@ ${lines.join("\n\n")}` };
12465
12498
  };
12466
12499
 
12467
12500
  // src/hook/reminder/reminder-action-classifier.ts
12468
- function normalize16(value) {
12501
+ function normalize15(value) {
12469
12502
  return String(value || "").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
12470
12503
  }
12471
12504
  var NOTIFY_PATTERNS = [
@@ -12500,7 +12533,7 @@ var AGENT_PATTERNS = [
12500
12533
  ];
12501
12534
  var ReminderActionClassifier = class {
12502
12535
  classify(rawText = "") {
12503
- const text = normalize16(rawText);
12536
+ const text = normalize15(rawText);
12504
12537
  if (!text) {
12505
12538
  return { ok: false, reason: "empty_action" };
12506
12539
  }
@@ -12517,7 +12550,7 @@ var ReminderActionClassifier = class {
12517
12550
 
12518
12551
  // src/hook/reminder/reminder-agent-executor.ts
12519
12552
  import fs23 from "fs";
12520
- function normalize17(value) {
12553
+ function normalize16(value) {
12521
12554
  return String(value || "").trim();
12522
12555
  }
12523
12556
  var ReminderAgentExecutor = class {
@@ -12540,16 +12573,16 @@ var ReminderAgentExecutor = class {
12540
12573
  this.isExecutionBusy = typeof isExecutionBusy === "function" ? isExecutionBusy : () => false;
12541
12574
  }
12542
12575
  resolveSessionKey(job) {
12543
- const ownerUserId = normalize17(job?.ownerUserId);
12544
- const chatType = normalize17(job?.delivery?.chatType || job?.chatType);
12545
- const chatId = normalize17(job?.delivery?.chatId || job?.chatId);
12546
- const rootId = normalize17(job?.rootId || job?.delivery?.rootId);
12576
+ const ownerUserId = normalize16(job?.ownerUserId);
12577
+ const chatType = normalize16(job?.delivery?.chatType || job?.chatType);
12578
+ const chatId = normalize16(job?.delivery?.chatId || job?.chatId);
12579
+ const rootId = normalize16(job?.rootId || job?.delivery?.rootId);
12547
12580
  if (chatType === "p2p") return `p2p::${ownerUserId || "unknown"}`;
12548
12581
  if (chatType === "group") return rootId ? `group::${chatId || "unknown"}::${rootId}` : `group::${chatId || "unknown"}`;
12549
12582
  return "";
12550
12583
  }
12551
12584
  loadAiHookPrompt(requesterUserId = "") {
12552
- const promptPath = requesterUserId ? requesterUserId === normalize17(process.env.AGENT_BLOCK_OWNER_USER_ID) ? resolveAiHookPath() : resolveAiHookGuestPath() : resolveAiHookGuestPath();
12585
+ const promptPath = requesterUserId ? requesterUserId === normalize16(process.env.AGENT_BLOCK_OWNER_USER_ID) ? resolveAiHookPath() : resolveAiHookGuestPath() : resolveAiHookGuestPath();
12553
12586
  if (!fs23.existsSync(promptPath)) {
12554
12587
  return "";
12555
12588
  }
@@ -12569,8 +12602,8 @@ var ReminderAgentExecutor = class {
12569
12602
  if (!dirResolved.ok || !dirResolved.dirPath) {
12570
12603
  return { ok: false, retryLater: false, error: dirResolved.error || "\u9ED8\u8BA4\u76EE\u5F55\u672A\u521D\u59CB\u5316" };
12571
12604
  }
12572
- const requesterUserId = normalize17(job?.requesterUserId || job?.delivery?.requesterUserId);
12573
- const actionPrompt = normalize17(job?.action?.prompt || job?.action?.text);
12605
+ const requesterUserId = normalize16(job?.requesterUserId || job?.delivery?.requesterUserId);
12606
+ const actionPrompt = normalize16(job?.action?.prompt || job?.action?.text);
12574
12607
  if (!actionPrompt) {
12575
12608
  return { ok: false, retryLater: false, error: "\u7F3A\u5C11\u5B9A\u65F6\u6267\u884C\u5185\u5BB9" };
12576
12609
  }
@@ -12580,9 +12613,9 @@ var ReminderAgentExecutor = class {
12580
12613
  ${actionPrompt}` : actionPrompt;
12581
12614
  const memoryBucket = this.memoryService?.resolveBucket({
12582
12615
  chatType: "p2p",
12583
- ownerUserId: normalize17(job?.ownerUserId),
12616
+ ownerUserId: normalize16(job?.ownerUserId),
12584
12617
  requesterUserId,
12585
- chatId: normalize17(job?.delivery?.chatId)
12618
+ chatId: normalize16(job?.delivery?.chatId)
12586
12619
  }) || null;
12587
12620
  this.logger.info(formatTraceLog(traceId, `\u5B9A\u65F6\u4EFB\u52A1\u5F00\u59CB\u6267\u884C: job_id=${job?.id || "-"}, dir=${dirResolved.dirPath}, action=agent_turn, session_key=${sessionKey || "-"}`));
12588
12621
  const result = await this.codexRunner.run(prompt, dirResolved.dirPath, {
@@ -12710,7 +12743,7 @@ var ReminderMessageBuilder = class {
12710
12743
  };
12711
12744
 
12712
12745
  // src/hook/reminder/reminder-parser.ts
12713
- function normalize18(value) {
12746
+ function normalize17(value) {
12714
12747
  return String(value || "").replace(/[\u200B-\u200D\uFEFF]/g, "").trim();
12715
12748
  }
12716
12749
  function pad23(value) {
@@ -12724,7 +12757,7 @@ function buildTodayOrTomorrow(baseDate, daysOffset, hour, minute) {
12724
12757
  return next;
12725
12758
  }
12726
12759
  function toMinutes(amount, unit) {
12727
- const normalized = normalize18(unit).toLowerCase();
12760
+ const normalized = normalize17(unit).toLowerCase();
12728
12761
  if (["\u5206\u949F", "\u5206", "m", "min", "mins", "minute", "minutes"].includes(normalized)) {
12729
12762
  return amount;
12730
12763
  }
@@ -12736,7 +12769,7 @@ var ReminderParser = class {
12736
12769
  this.actionClassifier = actionClassifier;
12737
12770
  }
12738
12771
  parse(rawText, now = /* @__PURE__ */ new Date(), context = {}) {
12739
- const text = normalize18(rawText);
12772
+ const text = normalize17(rawText);
12740
12773
  if (!text) {
12741
12774
  return { matched: false };
12742
12775
  }
@@ -12751,7 +12784,7 @@ var ReminderParser = class {
12751
12784
  if (/^清空提醒$/i.test(text)) return { matched: true, type: "clear_jobs" };
12752
12785
  const cancelMatch = text.match(/^取消提醒\s+([A-Za-z0-9_-]+)$/i);
12753
12786
  if (cancelMatch) {
12754
- return { matched: true, type: "cancel_job", jobId: normalize18(cancelMatch[1]) };
12787
+ return { matched: true, type: "cancel_job", jobId: normalize17(cancelMatch[1]) };
12755
12788
  }
12756
12789
  return { matched: false };
12757
12790
  }
@@ -12765,12 +12798,12 @@ var ReminderParser = class {
12765
12798
  parseSlashRemind(text, now) {
12766
12799
  const match = text.match(/^\/remind\s+(\d+)\s*(分钟|分|min|mins|minute|minutes|m|小时|时|hour|hours|h)\s+(.+)$/i);
12767
12800
  if (!match) return { matched: false };
12768
- return this.buildCreateResult(Number.parseInt(match[1] || "0", 10), normalize18(match[2]).toLowerCase(), normalize18(match[3]), now, { forceKind: "notify" });
12801
+ return this.buildCreateResult(Number.parseInt(match[1] || "0", 10), normalize17(match[2]).toLowerCase(), normalize17(match[3]), now, { forceKind: "notify" });
12769
12802
  }
12770
12803
  parseRelativeReminder(text, now, context) {
12771
12804
  const match = text.match(/^(\d+)\s*(分钟|分|min|mins|minute|minutes|m|小时|时|hour|hours|h)\s*后\s*(.+)$/i);
12772
12805
  if (!match) return { matched: false };
12773
- return this.buildCreateResult(Number.parseInt(match[1] || "0", 10), normalize18(match[2]).toLowerCase(), normalize18(match[3]), now, context);
12806
+ return this.buildCreateResult(Number.parseInt(match[1] || "0", 10), normalize17(match[2]).toLowerCase(), normalize17(match[3]), now, context);
12774
12807
  }
12775
12808
  buildCreateResult(amount, unit, content, now, context = {}) {
12776
12809
  if (!Number.isFinite(amount) || amount <= 0) {
@@ -12797,10 +12830,10 @@ var ReminderParser = class {
12797
12830
  parseFixedReminder(text, now, context) {
12798
12831
  const match = text.match(/^(今天|明天)\s*(\d{1,2})[::](\d{2})\s*(.+)$/i);
12799
12832
  if (!match) return { matched: false };
12800
- const dayToken = normalize18(match[1]);
12833
+ const dayToken = normalize17(match[1]);
12801
12834
  const hour = Number.parseInt(match[2] || "0", 10);
12802
12835
  const minute = Number.parseInt(match[3] || "0", 10);
12803
- const content = normalize18(match[4]);
12836
+ const content = normalize17(match[4]);
12804
12837
  if (!Number.isFinite(hour) || hour < 0 || hour > 23 || !Number.isFinite(minute) || minute < 0 || minute > 59) {
12805
12838
  return { matched: true, type: "invalid", error: "\u63D0\u9192\u65F6\u95F4\u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u8BF7\u4F7F\u7528 HH:mm" };
12806
12839
  }
@@ -12826,7 +12859,7 @@ var ReminderParser = class {
12826
12859
  };
12827
12860
  }
12828
12861
  resolveAction(content, context = {}, forceKind = "") {
12829
- const normalizedContent = normalize18(content);
12862
+ const normalizedContent = normalize17(content);
12830
12863
  if (!normalizedContent) {
12831
12864
  return { ok: false, reason: "empty_action" };
12832
12865
  }
@@ -12891,16 +12924,16 @@ var ReminderStore = class {
12891
12924
  };
12892
12925
 
12893
12926
  // src/hook/reminder/reminder-service.ts
12894
- function normalize19(value) {
12927
+ function normalize18(value) {
12895
12928
  return String(value || "").trim();
12896
12929
  }
12897
12930
  function normalizeTargets2(items = []) {
12898
12931
  const seen = /* @__PURE__ */ new Set();
12899
12932
  const targets = [];
12900
12933
  (Array.isArray(items) ? items : []).forEach((item) => {
12901
- const userId = normalize19(item?.userId || item?.user_id);
12902
- const openId = normalize19(item?.openId || item?.open_id);
12903
- const name = normalize19(item?.name);
12934
+ const userId = normalize18(item?.userId || item?.user_id);
12935
+ const openId = normalize18(item?.openId || item?.open_id);
12936
+ const name = normalize18(item?.name);
12904
12937
  if (!userId && !openId) {
12905
12938
  return;
12906
12939
  }
@@ -13026,27 +13059,27 @@ var ReminderService = class {
13026
13059
  const nowMs = Date.now();
13027
13060
  return {
13028
13061
  id: createJobId(),
13029
- ownerUserId: normalize19(context.ownerUserId),
13030
- requesterUserId: normalize19(context.requesterUserId),
13031
- requesterOpenId: normalize19(context.requesterOpenId),
13032
- chatType: normalize19(context.chatType),
13033
- messageId: normalize19(context.messageId),
13034
- rootId: normalize19(context.rootId),
13035
- parentId: normalize19(context.parentId),
13036
- traceId: normalize19(context.traceId),
13062
+ ownerUserId: normalize18(context.ownerUserId),
13063
+ requesterUserId: normalize18(context.requesterUserId),
13064
+ requesterOpenId: normalize18(context.requesterOpenId),
13065
+ chatType: normalize18(context.chatType),
13066
+ messageId: normalize18(context.messageId),
13067
+ rootId: normalize18(context.rootId),
13068
+ parentId: normalize18(context.parentId),
13069
+ traceId: normalize18(context.traceId),
13037
13070
  schedule: { kind: "at", runAtMs: Number(command?.schedule?.runAtMs || 0) },
13038
13071
  action: {
13039
- kind: normalize19(command?.action?.kind || "notify"),
13040
- text: normalize19(command?.action?.content || command?.action?.text || command?.sourceText),
13041
- prompt: normalize19(command?.action?.content || command?.action?.prompt || command?.sourceText)
13072
+ kind: normalize18(command?.action?.kind || "notify"),
13073
+ text: normalize18(command?.action?.content || command?.action?.text || command?.sourceText),
13074
+ prompt: normalize18(command?.action?.content || command?.action?.prompt || command?.sourceText)
13042
13075
  },
13043
13076
  delivery: {
13044
13077
  mode: "feishu_message",
13045
13078
  target: "origin_chat",
13046
- chatType: normalize19(context.chatType),
13047
- chatId: normalize19(context.chatId),
13048
- requesterUserId: normalize19(context.requesterUserId),
13049
- requesterOpenId: normalize19(context.requesterOpenId),
13079
+ chatType: normalize18(context.chatType),
13080
+ chatId: normalize18(context.chatId),
13081
+ requesterUserId: normalize18(context.requesterUserId),
13082
+ requesterOpenId: normalize18(context.requesterOpenId),
13050
13083
  notifyTargets: normalizeTargets2(context.reminderTargets)
13051
13084
  },
13052
13085
  state: {
@@ -13062,20 +13095,20 @@ var ReminderService = class {
13062
13095
  return this.store.readAll().filter((job) => this.isVisibleForContext(job, context) && job?.state?.status === "pending");
13063
13096
  }
13064
13097
  findPendingJobForContext(context, jobId = "") {
13065
- const normalized = normalize19(jobId);
13098
+ const normalized = normalize18(jobId);
13066
13099
  if (!normalized) {
13067
13100
  return null;
13068
13101
  }
13069
- return this.listPendingJobs(context).find((job) => normalize19(job?.id) === normalized) || null;
13102
+ return this.listPendingJobs(context).find((job) => normalize18(job?.id) === normalized) || null;
13070
13103
  }
13071
13104
  isVisibleForContext(job, context) {
13072
- const requesterUserId = normalize19(context.requesterUserId);
13073
- const chatId = normalize19(context.chatId);
13074
- const chatType = normalize19(context.chatType).toLowerCase();
13105
+ const requesterUserId = normalize18(context.requesterUserId);
13106
+ const chatId = normalize18(context.chatId);
13107
+ const chatType = normalize18(context.chatType).toLowerCase();
13075
13108
  if (chatType === "p2p") {
13076
- return normalize19(job?.requesterUserId) === requesterUserId && normalize19(job?.delivery?.chatId) === chatId;
13109
+ return normalize18(job?.requesterUserId) === requesterUserId && normalize18(job?.delivery?.chatId) === chatId;
13077
13110
  }
13078
- return normalize19(job?.requesterUserId) === requesterUserId && normalize19(job?.delivery?.chatId) === chatId;
13111
+ return normalize18(job?.requesterUserId) === requesterUserId && normalize18(job?.delivery?.chatId) === chatId;
13079
13112
  }
13080
13113
  scheduleNext() {
13081
13114
  if (!this.running) {
@@ -13111,9 +13144,9 @@ var ReminderService = class {
13111
13144
  this.scheduleNext();
13112
13145
  }
13113
13146
  async executeJob(job) {
13114
- const traceId = normalize19(job?.traceId || job?.messageId || job?.id);
13147
+ const traceId = normalize18(job?.traceId || job?.messageId || job?.id);
13115
13148
  try {
13116
- const actionKind = normalize19(job?.action?.kind);
13149
+ const actionKind = normalize18(job?.action?.kind);
13117
13150
  if (actionKind === "notify") {
13118
13151
  await this.sendNotify(job);
13119
13152
  } else if (actionKind === "agent_turn") {
@@ -13137,7 +13170,7 @@ var ReminderService = class {
13137
13170
  this.logger.info(formatTraceLog(traceId, `\u63D0\u9192\u5DF2\u89E6\u53D1: job_id=${job.id}, chat_id=${job?.delivery?.chatId || "-"}, chat_type=${job?.delivery?.chatType || "-"}`));
13138
13171
  } catch (error) {
13139
13172
  const message = error instanceof Error ? error.message : String(error);
13140
- if (normalize19(job?.action?.kind) === "agent_turn") {
13173
+ if (normalize18(job?.action?.kind) === "agent_turn") {
13141
13174
  try {
13142
13175
  await this.sendAgentTurnFailure(job, message);
13143
13176
  } catch (notifyError) {
@@ -13161,7 +13194,7 @@ var ReminderService = class {
13161
13194
  });
13162
13195
  }
13163
13196
  async sendNotify(job) {
13164
- const chatId = normalize19(job?.delivery?.chatId);
13197
+ const chatId = normalize18(job?.delivery?.chatId);
13165
13198
  if (!chatId) {
13166
13199
  throw new Error("\u63D0\u9192\u7F3A\u5C11 chat_id");
13167
13200
  }
@@ -13175,7 +13208,7 @@ var ReminderService = class {
13175
13208
  });
13176
13209
  }
13177
13210
  async sendAgentTurnResult(job, resultText = "") {
13178
- const chatId = normalize19(job?.delivery?.chatId);
13211
+ const chatId = normalize18(job?.delivery?.chatId);
13179
13212
  if (!chatId) {
13180
13213
  throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u7F3A\u5C11 chat_id");
13181
13214
  }
@@ -13189,7 +13222,7 @@ var ReminderService = class {
13189
13222
  });
13190
13223
  }
13191
13224
  async sendAgentTurnFailure(job, error = "") {
13192
- const chatId = normalize19(job?.delivery?.chatId);
13225
+ const chatId = normalize18(job?.delivery?.chatId);
13193
13226
  if (!chatId) {
13194
13227
  throw new Error("\u5B9A\u65F6\u4EFB\u52A1\u7F3A\u5C11 chat_id");
13195
13228
  }
@@ -13207,32 +13240,6 @@ var ReminderService = class {
13207
13240
  // src/hook/persona/requester-persona-service.ts
13208
13241
  import fs25 from "fs";
13209
13242
  import path24 from "path";
13210
- function normalize20(value) {
13211
- if (value === null || value === void 0) {
13212
- return "";
13213
- }
13214
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
13215
- return String(value).trim();
13216
- }
13217
- return "";
13218
- }
13219
- function resolveDisplayName2(value) {
13220
- const direct = normalize20(value);
13221
- if (direct) {
13222
- return direct;
13223
- }
13224
- if (!value || typeof value !== "object") {
13225
- return "";
13226
- }
13227
- const candidateKeys = ["zh_cn", "zh-CN", "zh_hans", "zh", "en_us", "en-US", "en", "name", "value"];
13228
- for (const key of candidateKeys) {
13229
- const text = normalize20(value?.[key]);
13230
- if (text) {
13231
- return text;
13232
- }
13233
- }
13234
- return "";
13235
- }
13236
13243
  function pickUserData2(response) {
13237
13244
  const data = response?.data || {};
13238
13245
  const user = data?.user || data?.data?.user || data?.items?.[0] || data?.item || {};
@@ -13310,8 +13317,8 @@ var RequesterPersonaService = class {
13310
13317
  }
13311
13318
  }
13312
13319
  buildCacheKey(userId = "", openId = "") {
13313
- const normalizedUserId = normalize20(userId);
13314
- const normalizedOpenId = normalize20(openId);
13320
+ const normalizedUserId = normalizeText(userId);
13321
+ const normalizedOpenId = normalizeText(openId);
13315
13322
  if (normalizedUserId) {
13316
13323
  return `user_id:${normalizedUserId}`;
13317
13324
  }
@@ -13350,8 +13357,8 @@ var RequesterPersonaService = class {
13350
13357
  return null;
13351
13358
  }
13352
13359
  const attempts = [];
13353
- const normalizedUserId = normalize20(userId);
13354
- const normalizedOpenId = normalize20(openId);
13360
+ const normalizedUserId = normalizeText(userId);
13361
+ const normalizedOpenId = normalizeText(openId);
13355
13362
  if (normalizedUserId) {
13356
13363
  attempts.push({
13357
13364
  path: { user_id: normalizedUserId },
@@ -13387,7 +13394,7 @@ var RequesterPersonaService = class {
13387
13394
  return null;
13388
13395
  }
13389
13396
  async tryFetchJobLevelName(jobLevelId = "") {
13390
- const normalizedJobLevelId = normalize20(jobLevelId);
13397
+ const normalizedJobLevelId = normalizeText(jobLevelId);
13391
13398
  if (!normalizedJobLevelId || !this.jobLevelNameLookupEnabled) {
13392
13399
  return "";
13393
13400
  }
@@ -13403,7 +13410,7 @@ var RequesterPersonaService = class {
13403
13410
  return "";
13404
13411
  }
13405
13412
  const jobLevel = pickJobLevelData(response);
13406
- return resolveDisplayName2(jobLevel.name) || resolveDisplayName2(jobLevel.i18n_name) || normalize20(jobLevel.code || "");
13413
+ return resolveDisplayName(jobLevel.name) || resolveDisplayName(jobLevel.i18n_name) || normalizeText(jobLevel.code || "");
13407
13414
  } catch (error) {
13408
13415
  const errorCode = error?.response?.data?.code || error?.code || "";
13409
13416
  if ((String(errorCode) === "99991672" || String(error?.message || "").includes("Access denied")) && !this.jobLevelPermissionDeniedLogged) {
@@ -13415,14 +13422,14 @@ var RequesterPersonaService = class {
13415
13422
  }
13416
13423
  }
13417
13424
  resolveRoleConfig(jobLevelId = "") {
13418
- const normalizedJobLevelId = normalize20(jobLevelId);
13425
+ const normalizedJobLevelId = normalizeText(jobLevelId);
13419
13426
  if (!normalizedJobLevelId) {
13420
13427
  return { roleKey: "", roleConfig: null };
13421
13428
  }
13422
13429
  const roles = this.rules?.roles || {};
13423
13430
  for (const [roleKey, roleConfig] of Object.entries(roles)) {
13424
13431
  const ids = Array.isArray(roleConfig?.jobLevelIds) ? roleConfig.jobLevelIds : [];
13425
- if (ids.map((item) => normalize20(item)).includes(normalizedJobLevelId)) {
13432
+ if (ids.map((item) => normalizeText(item)).includes(normalizedJobLevelId)) {
13426
13433
  return { roleKey, roleConfig };
13427
13434
  }
13428
13435
  }
@@ -13438,12 +13445,12 @@ var RequesterPersonaService = class {
13438
13445
  return "";
13439
13446
  }
13440
13447
  const lines = [
13441
- `- \u63D0\u95EE\u8005\u89D2\u8272: ${normalize20(roleConfig.label) || roleKey}`,
13442
- `- \u63D0\u95EE\u8005 user_id: ${normalize20(record.userId) || "-"}`,
13443
- `- \u63D0\u95EE\u8005\u59D3\u540D: ${normalize20(record.name) || "-"}`,
13444
- `- \u63D0\u95EE\u8005\u804C\u7EA7ID: ${normalize20(record.jobLevelId) || "-"}`
13448
+ `- \u63D0\u95EE\u8005\u89D2\u8272: ${normalizeText(roleConfig.label) || roleKey}`,
13449
+ `- \u63D0\u95EE\u8005 user_id: ${normalizeText(record.userId) || "-"}`,
13450
+ `- \u63D0\u95EE\u8005\u59D3\u540D: ${normalizeText(record.name) || "-"}`,
13451
+ `- \u63D0\u95EE\u8005\u804C\u7EA7ID: ${normalizeText(record.jobLevelId) || "-"}`
13445
13452
  ];
13446
- const jobLevelName = normalize20(record.jobLevelName);
13453
+ const jobLevelName = normalizeText(record.jobLevelName);
13447
13454
  if (jobLevelName) {
13448
13455
  lines.push(`- \u63D0\u95EE\u8005\u804C\u7EA7\u540D\u79F0: ${jobLevelName}`);
13449
13456
  }
@@ -13457,12 +13464,12 @@ var RequesterPersonaService = class {
13457
13464
  }
13458
13465
  buildRecord({ cached = null, user = null, identity = null, jobLevelName = "" } = {}) {
13459
13466
  const requester = identity?.requester || {};
13460
- const userId = normalize20(user?.user_id || cached?.userId || requester?.userId || "");
13461
- const openId = normalize20(user?.open_id || cached?.openId || requester?.openId || "");
13462
- const name = resolveDisplayName2(user?.name) || resolveDisplayName2(user?.en_name) || normalize20(cached?.name || requester?.name || "");
13463
- const email = normalize20(user?.email || cached?.email || requester?.email || "");
13464
- const jobLevelId = normalize20(user?.job_level_id || cached?.jobLevelId || "");
13465
- const nextJobLevelName = normalize20(jobLevelName || cached?.jobLevelName || "");
13467
+ const userId = normalizeText(user?.user_id || cached?.userId || requester?.userId || "");
13468
+ const openId = normalizeText(user?.open_id || cached?.openId || requester?.openId || "");
13469
+ const name = resolveDisplayName(user?.name) || resolveDisplayName(user?.en_name) || normalizeText(cached?.name || requester?.name || "");
13470
+ const email = normalizeText(user?.email || cached?.email || requester?.email || "");
13471
+ const jobLevelId = normalizeText(user?.job_level_id || cached?.jobLevelId || "");
13472
+ const nextJobLevelName = normalizeText(jobLevelName || cached?.jobLevelName || "");
13466
13473
  const { roleKey, roleConfig } = this.resolveRoleConfig(jobLevelId);
13467
13474
  const now = Date.now();
13468
13475
  return {
@@ -13473,18 +13480,18 @@ var RequesterPersonaService = class {
13473
13480
  jobLevelId,
13474
13481
  jobLevelName: nextJobLevelName,
13475
13482
  personaRole: roleKey,
13476
- personaLabel: normalize20(roleConfig?.label || ""),
13483
+ personaLabel: normalizeText(roleConfig?.label || ""),
13477
13484
  updatedAt: now,
13478
13485
  expiresAt: now + this.cacheTtlMs
13479
13486
  };
13480
13487
  }
13481
13488
  logUnmatchedJobLevel(jobLevelId = "", userId = "") {
13482
- const normalizedJobLevelId = normalize20(jobLevelId);
13489
+ const normalizedJobLevelId = normalizeText(jobLevelId);
13483
13490
  if (!normalizedJobLevelId || this.loggedUnknownJobLevelIds.has(normalizedJobLevelId)) {
13484
13491
  return;
13485
13492
  }
13486
13493
  this.loggedUnknownJobLevelIds.add(normalizedJobLevelId);
13487
- this.logger.info(`\u63D0\u95EE\u8005\u753B\u50CF\u672A\u547D\u4E2D\u6620\u5C04: user_id=${normalize20(userId) || "-"}, job_level_id=${normalizedJobLevelId}`);
13494
+ this.logger.info(`\u63D0\u95EE\u8005\u753B\u50CF\u672A\u547D\u4E2D\u6620\u5C04: user_id=${normalizeText(userId) || "-"}, job_level_id=${normalizedJobLevelId}`);
13488
13495
  }
13489
13496
  async resolveRequesterPersona({
13490
13497
  chatType = "",
@@ -13492,11 +13499,11 @@ var RequesterPersonaService = class {
13492
13499
  senderOpenId = "",
13493
13500
  identity = null
13494
13501
  } = {}) {
13495
- if (normalize20(chatType).toLowerCase() !== "group") {
13502
+ if (normalizeText(chatType).toLowerCase() !== "group") {
13496
13503
  return null;
13497
13504
  }
13498
- const normalizedUserId = normalize20(senderUserId);
13499
- const normalizedOpenId = normalize20(senderOpenId);
13505
+ const normalizedUserId = normalizeText(senderUserId);
13506
+ const normalizedOpenId = normalizeText(senderOpenId);
13500
13507
  if (!normalizedUserId && !normalizedOpenId) {
13501
13508
  return null;
13502
13509
  }
@@ -13522,7 +13529,7 @@ var RequesterPersonaService = class {
13522
13529
  if (!user) {
13523
13530
  return null;
13524
13531
  }
13525
- const jobLevelId = normalize20(user?.job_level_id || "");
13532
+ const jobLevelId = normalizeText(user?.job_level_id || "");
13526
13533
  let jobLevelName = "";
13527
13534
  if (jobLevelId) {
13528
13535
  jobLevelName = await this.tryFetchJobLevelName(jobLevelId);
@@ -13687,17 +13694,8 @@ function buildWorkerState(options) {
13687
13694
  }
13688
13695
 
13689
13696
  // src/hook/worker/worker-owner-resolver.ts
13690
- function normalize21(value) {
13691
- if (value === null || value === void 0) {
13692
- return "";
13693
- }
13694
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
13695
- return String(value).trim();
13696
- }
13697
- return "";
13698
- }
13699
13697
  function lower2(value) {
13700
- return normalize21(value).toLowerCase();
13698
+ return normalizeText(value).toLowerCase();
13701
13699
  }
13702
13700
  function buildEmailFromUser(user = "") {
13703
13701
  const normalizedUser = lower2(user);
@@ -13706,42 +13704,13 @@ function buildEmailFromUser(user = "") {
13706
13704
  }
13707
13705
  return normalizedUser.includes("@") ? normalizedUser : `${normalizedUser}@hstong.com`;
13708
13706
  }
13709
- function resolveDisplayName3(value) {
13710
- const direct = normalize21(value);
13711
- if (direct) {
13712
- return direct;
13713
- }
13714
- if (!value || typeof value !== "object") {
13715
- return "";
13716
- }
13717
- const candidateKeys = [
13718
- "zh_cn",
13719
- "zh-CN",
13720
- "zh_hans",
13721
- "zh",
13722
- "en_us",
13723
- "en-US",
13724
- "en",
13725
- "name",
13726
- "display_name",
13727
- "full_name",
13728
- "value"
13729
- ];
13730
- for (const key of candidateKeys) {
13731
- const text = normalize21(value[key]);
13732
- if (text) {
13733
- return text;
13734
- }
13735
- }
13736
- return "";
13737
- }
13738
13707
  function scoreEntry(entry) {
13739
13708
  let score = 0;
13740
- if (normalize21(entry.feishuUserId)) score += 100;
13741
- if (normalize21(entry.feishuOpenId)) score += 30;
13742
- if (normalize21(entry.email)) score += 20;
13743
- if (normalize21(entry.user)) score += 10;
13744
- if (normalize21(entry.name)) score += 5;
13709
+ if (normalizeText(entry.feishuUserId)) score += 100;
13710
+ if (normalizeText(entry.feishuOpenId)) score += 30;
13711
+ if (normalizeText(entry.email)) score += 20;
13712
+ if (normalizeText(entry.user)) score += 10;
13713
+ if (normalizeText(entry.name)) score += 5;
13745
13714
  return score;
13746
13715
  }
13747
13716
  var WorkerOwnerResolver = class {
@@ -13750,7 +13719,7 @@ var WorkerOwnerResolver = class {
13750
13719
  identityResolver;
13751
13720
  constructor({ logger: logger3, larkClient, opsUserName = "" }) {
13752
13721
  this.logger = logger3;
13753
- this.opsUserName = normalize21(opsUserName);
13722
+ this.opsUserName = normalizeText(opsUserName);
13754
13723
  this.identityResolver = new IdentityResolver({ logger: logger3, larkClient });
13755
13724
  }
13756
13725
  pickBestEntry(entries = []) {
@@ -13768,7 +13737,7 @@ var WorkerOwnerResolver = class {
13768
13737
  if (!item || typeof item !== "object" || item.__cacheType) {
13769
13738
  return false;
13770
13739
  }
13771
- return lower2(item.user) === ownerKey || normalize21(item.name) === this.opsUserName;
13740
+ return lower2(item.user) === ownerKey || normalizeText(item.name) === this.opsUserName;
13772
13741
  });
13773
13742
  return this.pickBestEntry(candidates);
13774
13743
  }
@@ -13796,10 +13765,10 @@ var WorkerOwnerResolver = class {
13796
13765
  return null;
13797
13766
  }
13798
13767
  return {
13799
- user_id: normalize21(user.user_id),
13800
- open_id: normalize21(user.open_id),
13801
- name: normalize21(user.name),
13802
- email: normalize21(user.email || normalizedEmail)
13768
+ user_id: normalizeText(user.user_id),
13769
+ open_id: normalizeText(user.open_id),
13770
+ name: normalizeText(user.name),
13771
+ email: normalizeText(user.email || normalizedEmail)
13803
13772
  };
13804
13773
  } catch (error) {
13805
13774
  const detail = error?.response?.data ? JSON.stringify(error.response.data) : error instanceof Error ? error.message : String(error);
@@ -13808,8 +13777,8 @@ var WorkerOwnerResolver = class {
13808
13777
  }
13809
13778
  }
13810
13779
  async enrichEntryFromEmail(cache, entry) {
13811
- const baseUser = normalize21(entry?.user) || this.opsUserName;
13812
- const candidateEmail = normalize21(entry?.email) || buildEmailFromUser(baseUser);
13780
+ const baseUser = normalizeText(entry?.user) || this.opsUserName;
13781
+ const candidateEmail = normalizeText(entry?.email) || buildEmailFromUser(baseUser);
13813
13782
  if (!candidateEmail) {
13814
13783
  return null;
13815
13784
  }
@@ -13818,19 +13787,19 @@ var WorkerOwnerResolver = class {
13818
13787
  return null;
13819
13788
  }
13820
13789
  let detailedUser = null;
13821
- if (!normalize21(larkUser.open_id)) {
13790
+ if (!normalizeText(larkUser.open_id)) {
13822
13791
  detailedUser = await this.identityResolver.fetchUserFromLark(larkUser.user_id, "");
13823
13792
  }
13824
13793
  this.identityResolver.updateUserCache(cache, {
13825
- user_id: normalize21(detailedUser?.user_id || larkUser.user_id),
13826
- open_id: normalize21(detailedUser?.open_id || larkUser.open_id),
13827
- name: normalize21(detailedUser?.name || larkUser.name || entry?.name),
13828
- email: normalize21(detailedUser?.email || larkUser.email || candidateEmail)
13829
- }, normalize21(detailedUser?.user_id || larkUser.user_id), normalize21(detailedUser?.open_id || larkUser.open_id));
13794
+ user_id: normalizeText(detailedUser?.user_id || larkUser.user_id),
13795
+ open_id: normalizeText(detailedUser?.open_id || larkUser.open_id),
13796
+ name: normalizeText(detailedUser?.name || larkUser.name || entry?.name),
13797
+ email: normalizeText(detailedUser?.email || larkUser.email || candidateEmail)
13798
+ }, normalizeText(detailedUser?.user_id || larkUser.user_id), normalizeText(detailedUser?.open_id || larkUser.open_id));
13830
13799
  this.identityResolver.saveCache();
13831
13800
  const refreshed = this.findOwnerEntry(cache);
13832
13801
  if (refreshed) {
13833
- this.logger.info(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u5DF2\u6309\u90AE\u7BB1\u8865\u9F50: ops_user=${this.opsUserName}, email=${candidateEmail}, owner_user_id=${normalize21(refreshed.feishuUserId) || "-"}`);
13802
+ this.logger.info(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u5DF2\u6309\u90AE\u7BB1\u8865\u9F50: ops_user=${this.opsUserName}, email=${candidateEmail}, owner_user_id=${normalizeText(refreshed.feishuUserId) || "-"}`);
13834
13803
  }
13835
13804
  return refreshed;
13836
13805
  }
@@ -13841,30 +13810,30 @@ var WorkerOwnerResolver = class {
13841
13810
  }
13842
13811
  const cache = this.identityResolver.loadCache();
13843
13812
  let entry = this.findOwnerEntry(cache);
13844
- if (!normalize21(entry?.feishuUserId) || !normalize21(entry?.feishuOpenId)) {
13813
+ if (!normalizeText(entry?.feishuUserId) || !normalizeText(entry?.feishuOpenId)) {
13845
13814
  entry = await this.enrichEntryFromEmail(cache, entry);
13846
13815
  }
13847
- const ownerUserId = normalize21(entry?.feishuUserId);
13816
+ const ownerUserId = normalizeText(entry?.feishuUserId);
13848
13817
  if (!ownerUserId) {
13849
13818
  this.logger.warn(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u89E3\u6790\u5931\u8D25: ops_user=${this.opsUserName}, reason=missing_feishu_user_id`);
13850
13819
  return {
13851
13820
  ...this.emptyProfile(entry ? "cache_incomplete" : "cache_miss"),
13852
- ownerDisplayName: resolveDisplayName3(entry?.name),
13853
- ownerOpenId: normalize21(entry?.feishuOpenId),
13854
- employeeNo: normalize21(entry?.uId),
13855
- email: normalize21(entry?.email),
13856
- user: normalize21(entry?.user)
13821
+ ownerDisplayName: resolveDisplayName(entry?.name),
13822
+ ownerOpenId: normalizeText(entry?.feishuOpenId),
13823
+ employeeNo: normalizeText(entry?.uId),
13824
+ email: normalizeText(entry?.email),
13825
+ user: normalizeText(entry?.user)
13857
13826
  };
13858
13827
  }
13859
- const ownerDisplayName = resolveDisplayName3(entry?.name) || normalize21(entry?.user) || this.opsUserName;
13828
+ const ownerDisplayName = resolveDisplayName(entry?.name) || normalizeText(entry?.user) || this.opsUserName;
13860
13829
  this.logger.info(`\u4ECE\u8282\u70B9\u5F52\u5C5E\u8EAB\u4EFD\u89E3\u6790\u6210\u529F: ops_user=${this.opsUserName}, owner_user_id=${ownerUserId}, owner_name=${ownerDisplayName}`);
13861
13830
  return {
13862
13831
  ownerUserId,
13863
13832
  ownerDisplayName,
13864
- ownerOpenId: normalize21(entry?.feishuOpenId),
13865
- employeeNo: normalize21(entry?.uId),
13866
- email: normalize21(entry?.email),
13867
- user: normalize21(entry?.user),
13833
+ ownerOpenId: normalizeText(entry?.feishuOpenId),
13834
+ employeeNo: normalizeText(entry?.uId),
13835
+ email: normalizeText(entry?.email),
13836
+ user: normalizeText(entry?.user),
13868
13837
  opsUserName: this.opsUserName,
13869
13838
  source: "cache"
13870
13839
  };
@@ -13890,28 +13859,11 @@ var PERSPECTIVE_RULES = [
13890
13859
  { key: "product", label: "\u4EA7\u54C1\u89C6\u89D2", pattern: /产品经理|产品/i },
13891
13860
  { key: "backend", label: "\u540E\u7AEF\u7814\u53D1\u89C6\u89D2", pattern: /java/i }
13892
13861
  ];
13893
- function normalize22(value) {
13894
- if (value === null || value === void 0) {
13895
- return "";
13896
- }
13897
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
13898
- return String(value).trim();
13899
- }
13900
- return "";
13901
- }
13902
13862
  function resolveLocalizedText(value) {
13903
- const direct = normalize22(value);
13904
- if (direct) {
13905
- return direct;
13906
- }
13907
- if (!value || typeof value !== "object") {
13908
- return "";
13909
- }
13910
- const record = value;
13911
- return normalize22(record.default_value) || normalize22(record.i18n_value?.zh_cn) || normalize22(record.i18n_value?.en_us);
13863
+ return resolveDisplayName(value);
13912
13864
  }
13913
13865
  function resolvePerspectiveByJobTitle(jobTitle = "") {
13914
- const matched = PERSPECTIVE_RULES.find((rule) => rule.pattern.test(normalize22(jobTitle)));
13866
+ const matched = PERSPECTIVE_RULES.find((rule) => rule.pattern.test(normalizeText(jobTitle)));
13915
13867
  return matched ? { perspectiveKey: matched.key, perspectiveLabel: matched.label } : { perspectiveKey: "general", perspectiveLabel: "\u901A\u7528\u89C6\u89D2" };
13916
13868
  }
13917
13869
  var WorkerPerspectiveResolver = class {
@@ -13922,7 +13874,7 @@ var WorkerPerspectiveResolver = class {
13922
13874
  this.larkClient = larkClient;
13923
13875
  }
13924
13876
  async resolve(ownerProfile) {
13925
- const ownerOpenId = normalize22(ownerProfile.ownerOpenId);
13877
+ const ownerOpenId = normalizeText(ownerProfile.ownerOpenId);
13926
13878
  if (!ownerOpenId || typeof this.larkClient?.request !== "function") {
13927
13879
  return this.buildResult();
13928
13880
  }
@@ -13946,9 +13898,9 @@ var WorkerPerspectiveResolver = class {
13946
13898
  const jobTitle = employee?.work_info?.job_title || {};
13947
13899
  const result = this.buildResult(
13948
13900
  resolveLocalizedText(jobTitle.job_title_name),
13949
- normalize22(jobTitle.job_title_id)
13901
+ normalizeText(jobTitle.job_title_id)
13950
13902
  );
13951
- this.logger.info(`\u5BBF\u4E3B\u804C\u52A1\u89E3\u6790\u5B8C\u6210: owner=${normalize22(ownerProfile.ownerDisplayName) || "-"}, job_title=${result.jobTitle || "-"}, perspective=${result.perspectiveLabel}`);
13903
+ this.logger.info(`\u5BBF\u4E3B\u804C\u52A1\u89E3\u6790\u5B8C\u6210: owner=${normalizeText(ownerProfile.ownerDisplayName) || "-"}, job_title=${result.jobTitle || "-"}, perspective=${result.perspectiveLabel}`);
13952
13904
  return result;
13953
13905
  } catch (error) {
13954
13906
  const message = error instanceof Error ? error.message : String(error);
@@ -13958,15 +13910,15 @@ var WorkerPerspectiveResolver = class {
13958
13910
  }
13959
13911
  buildResult(jobTitle = "", jobTitleId = "") {
13960
13912
  return {
13961
- jobTitle: normalize22(jobTitle),
13962
- jobTitleId: normalize22(jobTitleId),
13913
+ jobTitle: normalizeText(jobTitle),
13914
+ jobTitleId: normalizeText(jobTitleId),
13963
13915
  ...resolvePerspectiveByJobTitle(jobTitle)
13964
13916
  };
13965
13917
  }
13966
13918
  };
13967
13919
 
13968
13920
  // src/hook/worker/owner-notify-service.ts
13969
- function normalize23(value) {
13921
+ function normalize19(value) {
13970
13922
  return String(value || "").trim();
13971
13923
  }
13972
13924
  var OwnerNotifyService = class {
@@ -13980,12 +13932,12 @@ var OwnerNotifyService = class {
13980
13932
  this.ownerProfile = ownerProfile;
13981
13933
  }
13982
13934
  hasTarget() {
13983
- return Boolean(normalize23(this.ownerProfile.ownerUserId) || normalize23(this.ownerProfile.ownerOpenId));
13935
+ return Boolean(normalize19(this.ownerProfile.ownerUserId) || normalize19(this.ownerProfile.ownerOpenId));
13984
13936
  }
13985
13937
  async sendText(text) {
13986
13938
  const content = JSON.stringify({ text: String(text || "").trim() });
13987
- const userId = normalize23(this.ownerProfile.ownerUserId);
13988
- const openId = normalize23(this.ownerProfile.ownerOpenId);
13939
+ const userId = normalize19(this.ownerProfile.ownerUserId);
13940
+ const openId = normalize19(this.ownerProfile.ownerOpenId);
13989
13941
  if (userId) {
13990
13942
  return await this.larkClient.im.v1.message.create({
13991
13943
  params: { receive_id_type: "user_id" },