aai-lark-bridge 0.2.47 → 0.2.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import { Command } from "commander";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "aai-lark-bridge",
7
- version: "0.2.47",
7
+ version: "0.2.49",
8
8
  description: "Lark AI Native Bridge - Lark\u57FA\u7840\u8BBE\u65BD\u5C42\u548CCLI\u96C6\u6210",
9
9
  type: "module",
10
10
  main: "./dist/index.js",
@@ -7703,7 +7703,7 @@ async function submitClaudeLogin(cfg, sub, deps = {}) {
7703
7703
  }
7704
7704
 
7705
7705
  // src/bridge/bot/channel.ts
7706
- import { dirname as dirname19, join as join28 } from "path";
7706
+ import { dirname as dirname19, join as join29 } from "path";
7707
7707
 
7708
7708
  // src/bridge/agent/capability.ts
7709
7709
  function claudeCapability(profile2) {
@@ -8151,6 +8151,68 @@ function taskRunHooks(input) {
8151
8151
  };
8152
8152
  }
8153
8153
 
8154
+ // src/bridge/binding/awaiting.ts
8155
+ import { createHash as createHash3 } from "crypto";
8156
+ import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync5, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
8157
+ import { join as join21 } from "path";
8158
+ var AWAITING_TTL_MS = 24 * 36e5;
8159
+ var DECISION_SHOW_MAX = 200;
8160
+ var DECISION_MAX = 1e3;
8161
+ var SAFE = /^[A-Za-z0-9_.:@+-]{1,200}$/;
8162
+ function awaitingDecision(dir, taskId, threadRootId, now = Date.now()) {
8163
+ if (!threadRootId || !SAFE.test(taskId)) return void 0;
8164
+ let v;
8165
+ try {
8166
+ v = JSON.parse(readFileSync5(join21(dir, "awaiting", `${taskId}.json`), "utf8"));
8167
+ } catch {
8168
+ return void 0;
8169
+ }
8170
+ if (!v || v.task_id !== taskId || v.thread_root !== threadRootId) return void 0;
8171
+ if (typeof v.card_message_id !== "string" || typeof v.nonce !== "string" || !v.nonce) return void 0;
8172
+ const at = Date.parse(String(v.asked_at));
8173
+ if (!Number.isFinite(at) || now - at > AWAITING_TTL_MS) return void 0;
8174
+ return v;
8175
+ }
8176
+ var QUESTION = /[??]\s*$|吗|什么意思|为什么|是什么|怎么|如何|能不能|可不可以/;
8177
+ var ACK = /^(好的?|嗯+|哦+|行|收到|ok|okay|谢谢|thanks?|👍|可以)[。.!!\s]*$/i;
8178
+ function isDecisionText(msg) {
8179
+ const t = (msg.content ?? "").trim();
8180
+ if (msg.rawContentType !== "text" || (msg.resources?.length ?? 0) > 0) return false;
8181
+ if (t.length < 2 || t.startsWith("/")) return false;
8182
+ return !QUESTION.test(t) && !ACK.test(t);
8183
+ }
8184
+ function submitDecision(dir, handoffDir, a, msg) {
8185
+ const text = msg.content.trim().slice(0, DECISION_MAX);
8186
+ const name = `${createHash3("sha256").update(`decide-text:${msg.messageId}`).digest("hex").slice(0, 24)}.json`;
8187
+ mkdirSync4(handoffDir, { recursive: true });
8188
+ const file = join21(handoffDir, name);
8189
+ if (!existsSync8(file)) {
8190
+ const tmp = join21(handoffDir, `.${name}.${process.pid}.tmp`);
8191
+ writeFileSync4(
8192
+ tmp,
8193
+ JSON.stringify({
8194
+ event_id: "",
8195
+ kind: "sdlc-task",
8196
+ value: { kind: "sdlc-task", guid: a.task_id, action: "decide-text", nonce: a.nonce, text },
8197
+ operator_open_id: msg.senderId,
8198
+ message_id: msg.messageId,
8199
+ chat_id: msg.chatId,
8200
+ token: "",
8201
+ received_at: (/* @__PURE__ */ new Date()).toISOString()
8202
+ })
8203
+ );
8204
+ renameSync3(tmp, file);
8205
+ }
8206
+ rmSync3(join21(dir, "awaiting", `${a.task_id}.json`), { force: true });
8207
+ }
8208
+ function decisionAck(text) {
8209
+ const t = text.trim();
8210
+ const shown = t.length > DECISION_SHOW_MAX ? `${t.slice(0, DECISION_SHOW_MAX)}\u2026` : t;
8211
+ return `\u5DF2\u5F53\u4F5C\u51B3\u5B9A\u63D0\u4EA4\u7ED9\u4EFB\u52A1\uFF1A
8212
+ > ${shown.replace(/\n/g, "\n> ")}
8213
+ \u4EFB\u52A1\u51E0\u5206\u949F\u5185\u4F1A\u5E26\u7740\u5B83\u63A5\u7740\u8DD1\uFF1B\u4E0D\u662F\u8FD9\u4E2A\u610F\u601D\uFF0C\u5C31\u5728\u300Cagent \u505C\u4E0B\u6765\u7B49\u4F60\u5B9A\u300D\u90A3\u5F20\u5361\u7247\u7684\u8F93\u5165\u6846\u91CC\u91CD\u65B0\u5199\u3002`;
8214
+ }
8215
+
8154
8216
  // src/bridge/commands/index.ts
8155
8217
  import { randomUUID as randomUUID2 } from "crypto";
8156
8218
  import { readFile as readFile12 } from "fs/promises";
@@ -8896,7 +8958,7 @@ function escapeCode(s) {
8896
8958
  }
8897
8959
 
8898
8960
  // src/bridge/policy/fingerprint.ts
8899
- import { createHash as createHash3 } from "crypto";
8961
+ import { createHash as createHash4 } from "crypto";
8900
8962
 
8901
8963
  // src/bridge/session/jcs.ts
8902
8964
  function canonicalizeJcs(value) {
@@ -8959,7 +9021,7 @@ function attachmentPolicyConfigDigest(input) {
8959
9021
  });
8960
9022
  }
8961
9023
  function digestCanonical(value) {
8962
- return createHash3("sha256").update(canonicalizeJcs(value)).digest().subarray(0, 16).toString("base64url");
9024
+ return createHash4("sha256").update(canonicalizeJcs(value)).digest().subarray(0, 16).toString("base64url");
8963
9025
  }
8964
9026
 
8965
9027
  // src/bridge/policy/access.ts
@@ -9521,7 +9583,7 @@ function finalizeIfRunning(state) {
9521
9583
  import { createReadStream } from "fs";
9522
9584
  import { readdir as readdir4, stat as stat6 } from "fs/promises";
9523
9585
  import { homedir as homedir5 } from "os";
9524
- import { join as join21 } from "path";
9586
+ import { join as join22 } from "path";
9525
9587
  import { createInterface as createInterface5 } from "readline";
9526
9588
 
9527
9589
  // src/bridge/session/preview.ts
@@ -9560,7 +9622,7 @@ function encodeCwd(cwd) {
9560
9622
  return cwd.replace(/[^A-Za-z0-9]/g, "-");
9561
9623
  }
9562
9624
  function claudeProjectDir(cwd) {
9563
- return join21(homedir5(), ".claude", "projects", encodeCwd(cwd));
9625
+ return join22(homedir5(), ".claude", "projects", encodeCwd(cwd));
9564
9626
  }
9565
9627
  async function listRecentSessions(cwd, limit = 5) {
9566
9628
  const dir = claudeProjectDir(cwd);
@@ -9574,7 +9636,7 @@ async function listRecentSessions(cwd, limit = 5) {
9574
9636
  const jsonls = files.filter((f) => f.endsWith(".jsonl"));
9575
9637
  const withStats = await Promise.all(
9576
9638
  jsonls.map(async (f) => {
9577
- const path = join21(dir, f);
9639
+ const path = join22(dir, f);
9578
9640
  try {
9579
9641
  const st = await stat6(path);
9580
9642
  return { file: f, path, mtime: st.mtimeMs };
@@ -9645,7 +9707,7 @@ function formatRelTime(mtime) {
9645
9707
 
9646
9708
  // src/bridge/session/codex-history.ts
9647
9709
  import { createInterface as createInterface6 } from "readline";
9648
- import { join as join22 } from "path";
9710
+ import { join as join23 } from "path";
9649
9711
  var CodexHistoryError = class extends Error {
9650
9712
  code;
9651
9713
  constructor(code, message, options) {
@@ -9760,7 +9822,7 @@ function spawnCodexAppServer(options) {
9760
9822
  if (options.codexHome) {
9761
9823
  envOverrides.CODEX_HOME = options.codexHome;
9762
9824
  } else if (options.inheritCodexHome === false) {
9763
- envOverrides.CODEX_HOME = join22(options.profileStateDir, "codex-home");
9825
+ envOverrides.CODEX_HOME = join23(options.profileStateDir, "codex-home");
9764
9826
  }
9765
9827
  return spawnProcess(options.binary, ["app-server", "--listen", "stdio://"], {
9766
9828
  env: mergeProcessEnv(process.env, envOverrides),
@@ -12768,9 +12830,9 @@ async function lookupMessageRoot(channel, messageId) {
12768
12830
  }
12769
12831
 
12770
12832
  // src/bridge/card/handoff.ts
12771
- import { createHash as createHash4 } from "crypto";
12772
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "fs";
12773
- import { isAbsolute as isAbsolute4, join as join23 } from "path";
12833
+ import { createHash as createHash5 } from "crypto";
12834
+ import { existsSync as existsSync9, mkdirSync as mkdirSync5, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "fs";
12835
+ import { isAbsolute as isAbsolute4, join as join24 } from "path";
12774
12836
  function handoffDirs(raw) {
12775
12837
  if (!raw || typeof raw !== "object") return {};
12776
12838
  const out = {};
@@ -12791,14 +12853,14 @@ function tryHandoff(evt, dirs) {
12791
12853
  const token = typeof raw?.token === "string" && raw.token.startsWith("c-") ? raw.token : "";
12792
12854
  const eventId = typeof raw?.event_id === "string" ? raw.event_id : "";
12793
12855
  const key = eventId || `${evt.messageId}:${evt.operator.openId}:${JSON.stringify(value)}`;
12794
- const name = `${createHash4("sha256").update(key).digest("hex").slice(0, 24)}.json`;
12856
+ const name = `${createHash5("sha256").update(key).digest("hex").slice(0, 24)}.json`;
12795
12857
  const dir = dirs[kind];
12796
12858
  try {
12797
- mkdirSync4(dir, { recursive: true });
12798
- const file = join23(dir, name);
12799
- if (existsSync8(file)) return true;
12800
- const tmp = join23(dir, `.${name}.${process.pid}.tmp`);
12801
- writeFileSync4(
12859
+ mkdirSync5(dir, { recursive: true });
12860
+ const file = join24(dir, name);
12861
+ if (existsSync9(file)) return true;
12862
+ const tmp = join24(dir, `.${name}.${process.pid}.tmp`);
12863
+ writeFileSync5(
12802
12864
  tmp,
12803
12865
  JSON.stringify({
12804
12866
  event_id: eventId,
@@ -12812,7 +12874,7 @@ function tryHandoff(evt, dirs) {
12812
12874
  received_at: (/* @__PURE__ */ new Date()).toISOString()
12813
12875
  })
12814
12876
  );
12815
- renameSync3(tmp, file);
12877
+ renameSync4(tmp, file);
12816
12878
  log.info("cardAction", "handoff", { kind, file: name });
12817
12879
  } catch (err) {
12818
12880
  log.fail("cardAction", err, { kind, step: "handoff" });
@@ -13281,10 +13343,10 @@ function footerLine(status, apiRetry) {
13281
13343
  }
13282
13344
 
13283
13345
  // src/bridge/media/cache.ts
13284
- import { createHash as createHash5 } from "crypto";
13346
+ import { createHash as createHash6 } from "crypto";
13285
13347
  import { createReadStream as createReadStream2 } from "fs";
13286
13348
  import { mkdir as mkdir15, readdir as readdir5, rename as rename4, rm as rm13, stat as stat7 } from "fs/promises";
13287
- import { join as join24 } from "path";
13349
+ import { join as join25 } from "path";
13288
13350
 
13289
13351
  // src/bridge/media/attachment.ts
13290
13352
  var DEFAULT_POLICY = {
@@ -13420,7 +13482,7 @@ var MediaCache = class {
13420
13482
  return null;
13421
13483
  }
13422
13484
  const kind = r.type;
13423
- const tmpPath = join24(
13485
+ const tmpPath = join25(
13424
13486
  this.rootDir,
13425
13487
  `.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
13426
13488
  );
@@ -13434,7 +13496,7 @@ var MediaCache = class {
13434
13496
  const hash = await hashFile(tmpPath);
13435
13497
  const mime = contentType ?? defaultMime(kind);
13436
13498
  const ext = safeExtensionForMime(mime);
13437
- const absPath = join24(this.rootDir, `${hash}.${ext}`);
13499
+ const absPath = join25(this.rootDir, `${hash}.${ext}`);
13438
13500
  try {
13439
13501
  await stat7(absPath);
13440
13502
  await rm13(tmpPath, { force: true });
@@ -13476,7 +13538,7 @@ async function listFiles(root) {
13476
13538
  const out = [];
13477
13539
  const entries = await readdir5(root, { withFileTypes: true }).catch(() => []);
13478
13540
  for (const entry of entries) {
13479
- const full = join24(root, entry.name);
13541
+ const full = join25(root, entry.name);
13480
13542
  if (entry.isDirectory()) {
13481
13543
  out.push(...await listFiles(full));
13482
13544
  } else if (entry.isFile()) {
@@ -13486,7 +13548,7 @@ async function listFiles(root) {
13486
13548
  return out;
13487
13549
  }
13488
13550
  async function hashFile(path) {
13489
- const hash = createHash5("sha256");
13551
+ const hash = createHash6("sha256");
13490
13552
  for await (const chunk of createReadStream2(path)) {
13491
13553
  hash.update(chunk);
13492
13554
  }
@@ -14033,9 +14095,9 @@ import { mkdir as mkdir16 } from "fs/promises";
14033
14095
  import { dirname as dirname18 } from "path";
14034
14096
 
14035
14097
  // src/bridge/bot/comment-resource.ts
14036
- import { createHash as createHash6 } from "crypto";
14098
+ import { createHash as createHash7 } from "crypto";
14037
14099
  function commentTokenDigest(token) {
14038
- return createHash6("sha256").update(token).digest("hex").slice(0, 16);
14100
+ return createHash7("sha256").update(token).digest("hex").slice(0, 16);
14039
14101
  }
14040
14102
  function commentDocumentScopeId(fileToken) {
14041
14103
  return `comment-doc:${commentTokenDigest(fileToken)}`;
@@ -14589,9 +14651,9 @@ function preview(text) {
14589
14651
  }
14590
14652
 
14591
14653
  // src/bridge/bot/doc-confirmation.ts
14592
- import { createHash as createHash7 } from "crypto";
14593
- import { mkdirSync as mkdirSync5, realpathSync as realpathSync2, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "fs";
14594
- import { isAbsolute as isAbsolute5, join as join25, sep as sep3 } from "path";
14654
+ import { createHash as createHash8 } from "crypto";
14655
+ import { mkdirSync as mkdirSync6, realpathSync as realpathSync2, renameSync as renameSync5, writeFileSync as writeFileSync6 } from "fs";
14656
+ import { isAbsolute as isAbsolute5, join as join26, sep as sep3 } from "path";
14595
14657
  import { spawn as spawn2 } from "child_process";
14596
14658
  var waking = /* @__PURE__ */ new Set();
14597
14659
  function enqueueDocConfirmation(workspace, event, { selfReply = false } = {}) {
@@ -14600,18 +14662,18 @@ function enqueueDocConfirmation(workspace, event, { selfReply = false } = {}) {
14600
14662
  if (event.fileType !== "docx") return false;
14601
14663
  if (![event.fileToken, event.commentId, event.replyId ?? "none"].every((x) => /^[\w:-]{1,128}$/.test(x))) return false;
14602
14664
  const root = realpathSync2(workspace);
14603
- const script = realpathSync2(join25(root, ".sdlc-intake/intake.mjs"));
14665
+ const script = realpathSync2(join26(root, ".sdlc-intake/intake.mjs"));
14604
14666
  if (!script.startsWith(root + sep3)) throw new Error("SDLC \u6838\u9A8C\u5165\u53E3\u8D85\u51FA\u5DE5\u4F5C\u533A");
14605
- const inbox = join25(root, ".sdlc-intake/state/confirmation-inbox");
14606
- mkdirSync5(inbox, { recursive: true });
14667
+ const inbox = join26(root, ".sdlc-intake/state/confirmation-inbox");
14668
+ mkdirSync6(inbox, { recursive: true });
14607
14669
  if (!realpathSync2(inbox).startsWith(root + sep3)) throw new Error("SDLC \u6536\u4EF6\u76EE\u5F55\u8D85\u51FA\u5DE5\u4F5C\u533A");
14608
14670
  const { fileToken: fileId, commentId: comment_id } = event;
14609
14671
  const hint = { file_token: fileId, comment_id, reply_id: event.replyId ?? null, received_at: (/* @__PURE__ */ new Date()).toISOString() };
14610
- const key = createHash7("sha256").update(JSON.stringify([hint.file_token, hint.comment_id, hint.reply_id])).digest("hex");
14611
- const target = join25(inbox, key + ".json");
14672
+ const key = createHash8("sha256").update(JSON.stringify([hint.file_token, hint.comment_id, hint.reply_id])).digest("hex");
14673
+ const target = join26(inbox, key + ".json");
14612
14674
  const tmp = target + `.new-${process.pid}`;
14613
- writeFileSync5(tmp, JSON.stringify(hint), { mode: 384 });
14614
- renameSync4(tmp, target);
14675
+ writeFileSync6(tmp, JSON.stringify(hint), { mode: 384 });
14676
+ renameSync5(tmp, target);
14615
14677
  if (!waking.has(root)) {
14616
14678
  waking.add(root);
14617
14679
  try {
@@ -14925,8 +14987,8 @@ function runningWorkers(scopes, chatId) {
14925
14987
  }
14926
14988
 
14927
14989
  // src/bridge/bot/spawn-inbox.ts
14928
- import { existsSync as existsSync9, mkdirSync as mkdirSync6, readFileSync as readFileSync5, readdirSync as readdirSync2, rmSync as rmSync3 } from "fs";
14929
- import { join as join26 } from "path";
14990
+ import { existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync6, readdirSync as readdirSync2, rmSync as rmSync4 } from "fs";
14991
+ import { join as join27 } from "path";
14930
14992
  var SPAWN_DIR = "spawn";
14931
14993
  var SPAWN_POLL_MS = 1500;
14932
14994
  var RECENT_TTL_MS = 15 * 6e4;
@@ -14950,22 +15012,22 @@ var RecentMessages = class {
14950
15012
  }
14951
15013
  };
14952
15014
  function processSpawnFiles(o) {
14953
- const folder = join26(o.dir, SPAWN_DIR);
14954
- if (!existsSync9(folder)) return [];
15015
+ const folder = join27(o.dir, SPAWN_DIR);
15016
+ if (!existsSync10(folder)) return [];
14955
15017
  const now = (o.now ?? Date.now)();
14956
15018
  const out = [];
14957
15019
  for (const name of readdirSync2(folder)) {
14958
15020
  if (!name.endsWith(".json")) continue;
14959
- const file = join26(folder, name);
15021
+ const file = join27(folder, name);
14960
15022
  let req;
14961
15023
  try {
14962
- req = JSON.parse(readFileSync5(file, "utf8"));
15024
+ req = JSON.parse(readFileSync6(file, "utf8"));
14963
15025
  } catch {
14964
- rmSync3(file, { force: true });
15026
+ rmSync4(file, { force: true });
14965
15027
  out.push("bad-file");
14966
15028
  continue;
14967
15029
  }
14968
- rmSync3(file, { force: true });
15030
+ rmSync4(file, { force: true });
14969
15031
  const chatId = req.chat_id;
14970
15032
  const messageId = req.message_id;
14971
15033
  if (!chatId || !messageId || req.at && now - Date.parse(req.at) > STALE_FILE_MS) {
@@ -15003,7 +15065,7 @@ function processSpawnFiles(o) {
15003
15065
  return out;
15004
15066
  }
15005
15067
  function startSpawnInbox(o, intervalMs = SPAWN_POLL_MS) {
15006
- mkdirSync6(join26(o.dir, SPAWN_DIR), { recursive: true });
15068
+ mkdirSync7(join27(o.dir, SPAWN_DIR), { recursive: true });
15007
15069
  const timer = setInterval(() => {
15008
15070
  try {
15009
15071
  processSpawnFiles(o);
@@ -15016,8 +15078,8 @@ function startSpawnInbox(o, intervalMs = SPAWN_POLL_MS) {
15016
15078
  }
15017
15079
 
15018
15080
  // src/bridge/bot/worker-report.ts
15019
- import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync7 } from "fs";
15020
- import { join as join27 } from "path";
15081
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync8 } from "fs";
15082
+ import { join as join28 } from "path";
15021
15083
  var REPORT_MARKER = "[worker-report]";
15022
15084
  var SUMMARY_LINES = 4;
15023
15085
  var clip = (s, n) => s.length > n ? `${s.slice(0, n)}\u2026` : s;
@@ -15063,9 +15125,9 @@ function reportMessage(r, senderId, senderName) {
15063
15125
  }
15064
15126
  function appendWorkerLog(dir, r) {
15065
15127
  if (!/^[A-Za-z0-9_-]+$/.test(r.chatId)) return;
15066
- const folder = join27(dir, "workers");
15067
- mkdirSync7(folder, { recursive: true });
15068
- appendFileSync2(join27(folder, `${r.chatId}.jsonl`), `${JSON.stringify(r)}
15128
+ const folder = join28(dir, "workers");
15129
+ mkdirSync8(folder, { recursive: true });
15130
+ appendFileSync2(join28(folder, `${r.chatId}.jsonl`), `${JSON.stringify(r)}
15069
15131
  `);
15070
15132
  }
15071
15133
  async function observeWorkerRun(i) {
@@ -15339,39 +15401,6 @@ async function removeReaction(channel, messageId, reactionId) {
15339
15401
  var POSITIVE_EMOJIS = /* @__PURE__ */ new Set(["OK", "THUMBSUP", "DONE", "JIAYI", "LGTM"]);
15340
15402
  var CONFIRM_WINDOW_MS = 45 * 6e4;
15341
15403
  var SCOPE_MAX = 500;
15342
- function extractText(content) {
15343
- if (!content) return "";
15344
- let tree;
15345
- try {
15346
- tree = JSON.parse(content);
15347
- } catch {
15348
- return content;
15349
- }
15350
- if (tree && typeof tree === "object" && tree.schema === "2.0") {
15351
- const elements = tree.body?.elements;
15352
- const parts = [];
15353
- if (Array.isArray(elements)) {
15354
- for (const el of elements) {
15355
- const e = el;
15356
- if (e?.tag === "markdown" && typeof e.content === "string" && e.text_size !== "notation") parts.push(e.content);
15357
- }
15358
- }
15359
- return parts.join("\n");
15360
- }
15361
- const out = [];
15362
- const walk = (v, key) => {
15363
- if (typeof v === "string") {
15364
- if (key === "text" || key === "content" || key === "title") out.push(v);
15365
- } else if (Array.isArray(v)) v.forEach((x) => walk(x, key));
15366
- else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, k);
15367
- };
15368
- walk(tree);
15369
- return out.join("\n");
15370
- }
15371
- function isConfirmQuestion(text) {
15372
- const tail = text.trim().split(/[。!!\n]/).map((s) => s.trim()).filter(Boolean).pop() ?? "";
15373
- return /[??]$/.test(tail) && /吗|是否|要不要|可不可以|对不对|行不行|可以不/.test(tail);
15374
- }
15375
15404
  var ReactionConfirmer = class {
15376
15405
  constructor(now = Date.now) {
15377
15406
  this.now = now;
@@ -15416,7 +15445,6 @@ var ReactionConfirmer = class {
15416
15445
  if (this.latestByScope.get(handled.scope) !== parentId) return reject4("not-latest");
15417
15446
  if (handled.msg.chatId !== bot.chat_id) return reject4("chat-mismatch");
15418
15447
  if (evt.operator.openId !== handled.msg.senderId) return reject4("not-asker");
15419
- if (!isConfirmQuestion(extractText(bot.body?.content))) return reject4("not-a-question");
15420
15448
  const t = this.now();
15421
15449
  if (t - handled.msg.createTime > CONFIRM_WINDOW_MS) return reject4("expired");
15422
15450
  this.used.add(evt.messageId);
@@ -15982,7 +16010,7 @@ async function startChannel(deps) {
15982
16010
  const pool = new ProcessPool(() => getMaxConcurrentRuns(controls.cfg));
15983
16011
  const executor = new RunExecutor({ agent, pool, activeRuns });
15984
16012
  const appSecret = await resolveAppSecret(cfg, deps.appPaths);
15985
- const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join28(dirname19(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
16013
+ const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join29(dirname19(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
15986
16014
  await callbackNonceStore?.load();
15987
16015
  const callbackAuth = callbackNonceStore ? new CallbackAuth({
15988
16016
  keys: [{ version: 1, secret: appSecret }],
@@ -16523,6 +16551,7 @@ async function intakeMessage(deps) {
16523
16551
  );
16524
16552
  }
16525
16553
  const bound2 = binding?.kind === "bound" ? binding.binding : void 0;
16554
+ if (bound2?.viaThread && emsg.rootId) void submitThreadDecision(channel, controls, bound2, emsg);
16526
16555
  const handled = await tryHandleCommand({
16527
16556
  channel,
16528
16557
  msg: emsg,
@@ -16561,6 +16590,20 @@ async function intakeMessage(deps) {
16561
16590
  const size = pending.push(scope, emsg);
16562
16591
  log.info("intake", "queued", { scope, queueSize: size, debounceMs: DEBOUNCE_MS });
16563
16592
  }
16593
+ async function submitThreadDecision(channel, controls, bound2, msg) {
16594
+ try {
16595
+ if (!isDecisionText(msg)) return;
16596
+ const handoffDir = handoffDirs(controls.profileConfig.preferences.cardHandoffs)["sdlc-task"];
16597
+ if (!handoffDir) return;
16598
+ const awaiting = awaitingDecision(bound2.dir, bound2.task.task_id, msg.rootId);
16599
+ if (!awaiting) return;
16600
+ submitDecision(bound2.dir, handoffDir, awaiting, msg);
16601
+ log.info("binding", "decision-submitted", { taskId: awaiting.task_id, messageId: msg.messageId });
16602
+ await channel.send(msg.chatId, { markdown: decisionAck(msg.content) }, { replyTo: msg.messageId, replyInThread: true });
16603
+ } catch (err) {
16604
+ log.warn("binding", "decision-submit-failed", { reason: err instanceof Error ? err.message : String(err) });
16605
+ }
16606
+ }
16564
16607
  function dmBinding(controls, msg, scope, opts = {}) {
16565
16608
  const cfg = controls.profileConfig.preferences.taskBindings;
16566
16609
  if (!cfg) return void 0;
@@ -19962,8 +20005,8 @@ function openBrowser(url) {
19962
20005
 
19963
20006
  // src/bridge/cli/commands/user-gateway.ts
19964
20007
  import { spawnSync as spawnSync5 } from "child_process";
19965
- import { existsSync as existsSync11 } from "fs";
19966
- import { join as join30 } from "path";
20008
+ import { existsSync as existsSync12 } from "fs";
20009
+ import { join as join31 } from "path";
19967
20010
 
19968
20011
  // src/bridge/user-gateway/db-query.ts
19969
20012
  import { spawn as spawn3 } from "child_process";
@@ -20016,14 +20059,14 @@ function toResult(r) {
20016
20059
  }
20017
20060
 
20018
20061
  // src/bridge/user-gateway/gateway.ts
20019
- import { createHash as createHash8, randomBytes as randomBytes10 } from "crypto";
20020
- import { existsSync as existsSync10, rmSync as rmSync4 } from "fs";
20062
+ import { createHash as createHash9, randomBytes as randomBytes10 } from "crypto";
20063
+ import { existsSync as existsSync11, rmSync as rmSync5 } from "fs";
20021
20064
  import { mkdir as mkdir19, readdir as readdir6, readFile as readFileFs, rm as rm14, stat as stat8, writeFile as writeFile9 } from "fs/promises";
20022
- import { join as join29 } from "path";
20065
+ import { join as join30 } from "path";
20023
20066
 
20024
20067
  // src/bridge/user-gateway/app-token.ts
20025
20068
  import { spawn as spawn4 } from "child_process";
20026
- import { readFileSync as readFileSync6 } from "fs";
20069
+ import { readFileSync as readFileSync7 } from "fs";
20027
20070
  var APP_TOKEN_REFRESH_BEFORE_MS = 5 * 6e4;
20028
20071
  var APP_TOKEN_FAIL_BACKOFF_MS = 6e4;
20029
20072
  function createAppTokenCache(fetcher, now = Date.now) {
@@ -20068,7 +20111,7 @@ function brandOfTenant(tenant) {
20068
20111
  }
20069
20112
  function sourceBrand(sourceConfigFile) {
20070
20113
  try {
20071
- return brandOfTenant(JSON.parse(readFileSync6(sourceConfigFile, "utf8")).accounts?.app?.tenant);
20114
+ return brandOfTenant(JSON.parse(readFileSync7(sourceConfigFile, "utf8")).accounts?.app?.tenant);
20072
20115
  } catch {
20073
20116
  return "lark";
20074
20117
  }
@@ -20105,7 +20148,7 @@ function run(command, args, input, env, timeoutMs) {
20105
20148
  }
20106
20149
  function realAppTokenFetcher(sourceConfigFile) {
20107
20150
  return async () => {
20108
- const cfg = JSON.parse(readFileSync6(sourceConfigFile, "utf8"));
20151
+ const cfg = JSON.parse(readFileSync7(sourceConfigFile, "utf8"));
20109
20152
  const app = cfg.accounts?.app;
20110
20153
  if (!app?.id) throw new Error("source \u914D\u7F6E\u91CC\u6CA1\u6709\u5E94\u7528 id");
20111
20154
  let cred;
@@ -20695,10 +20738,10 @@ function createGateway(opts) {
20695
20738
  const issuedFor = /* @__PURE__ */ new Map();
20696
20739
  const inFlight = /* @__PURE__ */ new Set();
20697
20740
  const pendingAuth = /* @__PURE__ */ new Map();
20698
- const tokenRoot = join29(opts.stateDir, "user-tokens", opts.appId);
20699
- const userDir = (openId) => join29(tokenRoot, openId);
20700
- const authorizedMark = (openId) => join29(userDir(openId), ".authorized");
20701
- const isAuthorized = (openId) => existsSync10(authorizedMark(openId));
20741
+ const tokenRoot = join30(opts.stateDir, "user-tokens", opts.appId);
20742
+ const userDir = (openId) => join30(tokenRoot, openId);
20743
+ const authorizedMark = (openId) => join30(userDir(openId), ".authorized");
20744
+ const isAuthorized = (openId) => existsSync11(authorizedMark(openId));
20702
20745
  const larkNudgedAt = /* @__PURE__ */ new Map();
20703
20746
  const brand = sourceBrand(opts.larkSourceConfig);
20704
20747
  function env(dir) {
@@ -20710,11 +20753,11 @@ function createGateway(opts) {
20710
20753
  LARKSUITE_CLI_NO_SKILLS_NOTIFIER: "1"
20711
20754
  };
20712
20755
  }
20713
- const appDir = join29(opts.stateDir, "app");
20756
+ const appDir = join30(opts.stateDir, "app");
20714
20757
  const bound2 = /* @__PURE__ */ new Set();
20715
20758
  async function ensureBound(dir, identity) {
20716
20759
  if (bound2.has(dir)) return;
20717
- if (!existsSync10(join29(dir, "lark-channel", "config.json"))) {
20760
+ if (!existsSync11(join30(dir, "lark-channel", "config.json"))) {
20718
20761
  await mkdir19(dir, { recursive: true, mode: 448 });
20719
20762
  const r = await opts.exec(["config", "bind", "--source", "lark-channel", "--identity", identity], env(dir), 3e4);
20720
20763
  if (r.code !== 0) throw new Error(`lark-cli \u7ED1\u5B9A\u5931\u8D25\uFF1A${larkError(r).detail}`);
@@ -20742,12 +20785,12 @@ function createGateway(opts) {
20742
20785
  }
20743
20786
  return r;
20744
20787
  };
20745
- const tmpRoot = join29(opts.stateDir, "tmp-files");
20746
- const tmpDirOf = (runId) => join29(tmpRoot, createHash8("sha256").update(runId).digest("hex").slice(0, 32));
20788
+ const tmpRoot = join30(opts.stateDir, "tmp-files");
20789
+ const tmpDirOf = (runId) => join30(tmpRoot, createHash9("sha256").update(runId).digest("hex").slice(0, 32));
20747
20790
  const downloads = /* @__PURE__ */ new Map();
20748
20791
  const sheetCache = /* @__PURE__ */ new Map();
20749
20792
  try {
20750
- rmSync4(tmpRoot, { recursive: true, force: true });
20793
+ rmSync5(tmpRoot, { recursive: true, force: true });
20751
20794
  } catch {
20752
20795
  }
20753
20796
  async function cleanupTmp() {
@@ -20761,8 +20804,8 @@ function createGateway(opts) {
20761
20804
  }
20762
20805
  for (const n of names) {
20763
20806
  if (live.has(n)) continue;
20764
- for (const k of sheetCache.keys()) if (k.startsWith(join29(tmpRoot, n))) sheetCache.delete(k);
20765
- await rm14(join29(tmpRoot, n), { recursive: true, force: true }).catch(() => {
20807
+ for (const k of sheetCache.keys()) if (k.startsWith(join30(tmpRoot, n))) sheetCache.delete(k);
20808
+ await rm14(join30(tmpRoot, n), { recursive: true, force: true }).catch(() => {
20766
20809
  });
20767
20810
  }
20768
20811
  }
@@ -20776,7 +20819,7 @@ function createGateway(opts) {
20776
20819
  }
20777
20820
  for (const d of dirs) {
20778
20821
  try {
20779
- for (const f of await readdir6(join29(tmpRoot, d))) total += (await stat8(join29(tmpRoot, d, f))).size;
20822
+ for (const f of await readdir6(join30(tmpRoot, d))) total += (await stat8(join30(tmpRoot, d, f))).size;
20780
20823
  } catch {
20781
20824
  }
20782
20825
  }
@@ -21043,9 +21086,9 @@ function createGateway(opts) {
21043
21086
  const { messageId, fileKey, opts: ropts } = readFileParams(input);
21044
21087
  const dir = tmpDirOf(h.runId);
21045
21088
  const outName = `${fileKey}.bin`;
21046
- let path = join29(dir, outName);
21089
+ let path = join30(dir, outName);
21047
21090
  const fail = (result, extra = {}) => log.warn("user-gateway", "read.failed", { ...fields, result, ...extra });
21048
- if (!existsSync10(path)) {
21091
+ if (!existsSync11(path)) {
21049
21092
  if (await tmpBytes() >= (opts.tmpMaxBytes ?? MAX_TMP_BYTES)) {
21050
21093
  fail("busy");
21051
21094
  return { status: "busy" };
@@ -21071,10 +21114,10 @@ function createGateway(opts) {
21071
21114
  return larkFailure(h, fields, r);
21072
21115
  }
21073
21116
  }
21074
- if (!existsSync10(path)) {
21117
+ if (!existsSync11(path)) {
21075
21118
  try {
21076
21119
  const hit = (await readdir6(dir)).filter((n) => n.startsWith(fileKey));
21077
- if (hit.length === 1) path = join29(dir, hit[0]);
21120
+ if (hit.length === 1) path = join30(dir, hit[0]);
21078
21121
  } catch {
21079
21122
  }
21080
21123
  }
@@ -21212,7 +21255,7 @@ function createGateway(opts) {
21212
21255
  if (typeof v === "string") return { status: v };
21213
21256
  if (v.text?.trim() !== REVOKE_TEXT2) return { status: "not_revoke" };
21214
21257
  for (const [h, x] of handles) if (x.openId === v.openId) forget(h, "revoke", x.runId);
21215
- const had = existsSync10(userDir(v.openId));
21258
+ const had = existsSync11(userDir(v.openId));
21216
21259
  await rm14(userDir(v.openId), { recursive: true, force: true });
21217
21260
  bound2.delete(userDir(v.openId));
21218
21261
  log.info("user-gateway", "auth.revoked", { sender: tail6(v.openId), messageId, had });
@@ -21378,13 +21421,13 @@ function createGateway(opts) {
21378
21421
  }
21379
21422
 
21380
21423
  // src/bridge/user-gateway/server.ts
21381
- import { createHash as createHash9, timingSafeEqual as timingSafeEqual3 } from "crypto";
21424
+ import { createHash as createHash10, timingSafeEqual as timingSafeEqual3 } from "crypto";
21382
21425
  import { createServer as createServer2 } from "http";
21383
21426
  var MAX_BODY = 16 * 1024;
21384
21427
  var CLAUDE_ROUTES = /* @__PURE__ */ new Set(["/claude/token", "/claude/task-token", "/claude/ready", "/claude/login-submit", "/claude/logout"]);
21385
21428
  var DB_TASK_HANDLE = "/db/task-handle";
21386
21429
  var DB_QUERY = "/db/query";
21387
- var digest = (s) => createHash9("sha256").update(s).digest();
21430
+ var digest = (s) => createHash10("sha256").update(s).digest();
21388
21431
  function tokenOk(given, expected) {
21389
21432
  if (typeof given !== "string" || !given) return false;
21390
21433
  return timingSafeEqual3(digest(given), expected);
@@ -21492,10 +21535,10 @@ function fetchToken(cmd) {
21492
21535
  }
21493
21536
  async function runUserGateway(opts) {
21494
21537
  if (!/^cli_[A-Za-z0-9]+$/.test(opts.appId)) throw new Error("--app-id \u683C\u5F0F\u4E0D\u5BF9");
21495
- if (!existsSync11(opts.larkSourceConfig)) throw new Error(`\u627E\u4E0D\u5230 lark-cli source \u914D\u7F6E\uFF1A${opts.larkSourceConfig}`);
21538
+ if (!existsSync12(opts.larkSourceConfig)) throw new Error(`\u627E\u4E0D\u5230 lark-cli source \u914D\u7F6E\uFF1A${opts.larkSourceConfig}`);
21496
21539
  const port = Number(opts.port ?? 8788);
21497
21540
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("--port \u4E0D\u5BF9");
21498
- configureLogger({ logsDir: join30(opts.stateDir, "logs") });
21541
+ configureLogger({ logsDir: join31(opts.stateDir, "logs") });
21499
21542
  const gateway = createGateway({
21500
21543
  appId: opts.appId,
21501
21544
  stateDir: opts.stateDir,