aai-lark-bridge 0.2.46 → 0.2.48

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.46",
7
+ version: "0.2.48",
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",
@@ -7536,7 +7536,7 @@ var PROMPT_TOOL = `## \u7528\u63D0\u95EE\u4EBA\u7684\u8EAB\u4EFD\u53EA\u8BFB\uFF
7536
7536
 
7537
7537
  \u8BFB\u9644\u4EF6\uFF1A\u6D88\u606F\u5185\u5BB9\u91CC\u7684 \`<file key="file_v3_\u2026" name="\u2026.xlsx"/>\` \u5C31\u662F\u9644\u4EF6\uFF0Ckey \u662F \`--file-key\`\uFF0C\u6D88\u606F\u53F7\u662F \`--message-id\`\uFF08\u7528 \`get-message\`\u3001\`list-chat-messages\`\u3001\`search-messages\` \u62FF\uFF09\u3002\u652F\u6301 Excel\uFF08xlsx\uFF09\u3001Word\uFF08docx\uFF09\u3001PPT\uFF08pptx\uFF09\u3001csv\u3001txt\u3001md\u3001json\u3002\u4E0D\u5E26 \`--sheet\` \u65F6\u8FD4\u56DE\u5DE5\u4F5C\u8868\u6E05\u5355\uFF08\u540D\u79F0\u3001\u884C\u6570\u3001\u5217\u6570\uFF09\u548C\u7B2C\u4E00\u5F20\u8868\u7684\u7B2C\u4E00\u9875\uFF1B\u6BCF\u9875\u6700\u591A 200 \u884C\u6216 100KB\uFF0C\`hasMore\` \u4E3A\u771F\u5C31\u7528 \`nextOffset\` \u4F5C \`--offset\` \u7FFB\u9875\uFF1B\u627E\u67D0\u4E9B\u884C\u7528 \`--grep \u5173\u952E\u8BCD\`\uFF08\u53EA\u8FD4\u56DE\u542B\u5173\u952E\u8BCD\u7684\u884C\uFF0C\`--offset\` \u6309\u547D\u4E2D\u5E8F\u53F7\u7FFB\uFF09\uFF1BExcel \u7684\u6BCF\u4E00\u884C\u5F00\u5934\u662F\u539F\u8868\u884C\u53F7\u3002\u4E0D\u8981\u4E3A\u4E86\u627E\u51E0\u884C\u628A\u6574\u5F20\u5927\u8868\u4E00\u9875\u9875\u7FFB\u5B8C\uFF0C\u5148\u770B\u6E05\u5355\uFF0C\u518D\u7528 \`--grep\`\u3002\u8FD4\u56DE \`unsupported_type\`\uFF08PDF\u3001\u65E7\u7248 xls\u3001doc\u3001ppt\u3001\u56FE\u7247\u7B49\uFF09\uFF1A\u544A\u8BC9\u4ED6\u8FD9\u4E2A\u683C\u5F0F\u8BFB\u4E0D\u4E86\uFF0C\u8BF7\u4ED6\u8F6C\u6210 xlsx\u3001docx\u3001pptx \u6216 csv \u518D\u53D1\uFF1B\`too_large\`\uFF1A\u6587\u4EF6\u8D85\u8FC7 20MB\uFF1B\`unreadable\`\uFF1A\u6587\u4EF6\u635F\u574F\u6216\u592A\u590D\u6742\uFF1B\`busy\`\uFF1A\u7A0D\u540E\u518D\u8BD5\uFF1B\`lark_error\`\uFF1A\u4ED6\u770B\u4E0D\u5230\u8FD9\u6761\u6D88\u606F\u6216\u6587\u4EF6\u3002\u8BFB\u4E0D\u5230\u9644\u4EF6\u65F6\u5982\u5B9E\u8BF4\uFF0C\u522B\u62FF\u7FA4\u91CC\u7684\u7ED3\u8BBA\u5F53\u6210\u9010\u884C\u6838\u5BF9\u8FC7\u7684\u3002
7538
7538
 
7539
- \u8BFB\u591A\u7EF4\u8868\u683C\uFF1Afetch-doc \u8BFB\u4E0D\u4E86\u591A\u7EF4\u8868\u683C\uFF0C\u7528 \`read-base\`\u3002\u53EA\u7ED9 \`--url\` \u4E14\u94FE\u63A5\u6CA1\u6307\u5230\u67D0\u5F20\u6570\u636E\u8868\u65F6\uFF0C\u8FD4\u56DE\u6570\u636E\u8868\u6E05\u5355\uFF08\`kind\` \u4E3A tables\uFF09\uFF1B\u518D\u5E26 \`--table\`\uFF08\u8868\u540D\u6216 tbl \u5F00\u5934\u7684 ID\uFF09\u8BFB\u8BB0\u5F55\uFF08\`kind\` \u4E3A records\uFF0C\`markdown\` \u662F\u8868\u683C\u6587\u5B57\uFF0C\u6BCF\u6B21\u6700\u591A \`--limit\` \u884C\uFF0C\u9ED8\u8BA4 100\u3001\u6700\u5927 200\uFF1B\u8FD8\u8981\u540E\u9762\u7684\u884C\u5C31\u7528 \`--offset\` \u7FFB\u9875\uFF0C\u8FD4\u56DE\u7684\u884C\u6570\u7B49\u4E8E limit \u65F6\u591A\u534A\u8FD8\u6709\uFF1B\`truncated\` \u4E3A\u771F\u8BF4\u660E\u6587\u5B57\u88AB\u622A\u65AD\uFF0C\u8C03\u5C0F \`--limit\`\uFF09\u3002\u627E\u4E0D\u5230\u7684\u6570\u636E\u4E0D\u8981\u51ED\u5370\u8C61\u8865\uFF0C\u5148\u770B\u6E05\u5355\u518D\u8BFB\u5BF9\u7684\u90A3\u5F20\u8868\u3002\u8FD4\u56DE \`lark_error\`\uFF1A\u4ED6\u770B\u4E0D\u5230\u8FD9\u5F20\u8868\uFF0C\u6216\u94FE\u63A5\u4E0D\u662F\u591A\u7EF4\u8868\u683C\uFF1Bdetail \u91CC\u63D0\u5230\u7F3A\u6743\u9650\uFF08scope\uFF09\u65F6\uFF0C\u8BF7\u4ED6\u5728\u79C1\u804A\u91CC\u53D1\u300C\u64A4\u9500\u6388\u6743\u300D\uFF0C\u518D\u95EE\u4E00\u6B21\uFF0C\u91CD\u65B0\u6388\u6743\u540E\u624D\u80FD\u8BFB\u591A\u7EF4\u8868\u683C\u3002
7539
+ \u8BFB\u591A\u7EF4\u8868\u683C\uFF1Afetch-doc \u8BFB\u4E0D\u4E86\u591A\u7EF4\u8868\u683C\uFF0C\u7528 \`read-base\`\u3002\u53EA\u7ED9 \`--url\` \u4E14\u94FE\u63A5\u6CA1\u6307\u5230\u67D0\u5F20\u6570\u636E\u8868\u65F6\uFF0C\u8FD4\u56DE\u6570\u636E\u8868\u6E05\u5355\uFF08\`kind\` \u4E3A tables\uFF09\uFF1B\u518D\u5E26 \`--table\`\uFF08\u8868\u540D\u6216 tbl \u5F00\u5934\u7684 ID\uFF09\u8BFB\u8BB0\u5F55\uFF08\`kind\` \u4E3A records\uFF0C\`markdown\` \u662F\u8868\u683C\u6587\u5B57\uFF0C\u6BCF\u6B21\u6700\u591A \`--limit\` \u884C\uFF0C\u9ED8\u8BA4 100\u3001\u6700\u5927 200\uFF1B\u8FD8\u8981\u540E\u9762\u7684\u884C\u5C31\u7528 \`--offset\` \u7FFB\u9875\uFF0C\u8FD4\u56DE\u7684\u884C\u6570\u7B49\u4E8E limit \u65F6\u591A\u534A\u8FD8\u6709\uFF1B\`truncated\` \u4E3A\u771F\u8BF4\u660E\u6587\u5B57\u88AB\u622A\u65AD\uFF0C\u8C03\u5C0F \`--limit\`\uFF09\u3002\u627E\u4E0D\u5230\u7684\u6570\u636E\u4E0D\u8981\u51ED\u5370\u8C61\u8865\uFF0C\u5148\u770B\u6E05\u5355\u518D\u8BFB\u5BF9\u7684\u90A3\u5F20\u8868\u3002\u8FD4\u56DE \`lark_error\`\uFF1A\u4ED6\u770B\u4E0D\u5230\u8FD9\u5F20\u8868\uFF0C\u6216\u94FE\u63A5\u4E0D\u662F\u591A\u7EF4\u8868\u683C\u3002\u6388\u6743\u91CC\u7F3A\u8BFB\u591A\u7EF4\u8868\u683C\u7684\u6743\u9650\u65F6\uFF0C\u7F51\u5173\u4F1A\u6309 need_auth \u5904\u7406\uFF08\u91CD\u53D1\u6388\u6743\u5361\u7247\uFF09\uFF0C\u4E0D\u7528\u53EB\u4ED6\u64A4\u9500\u6388\u6743\u3002
7540
7540
 
7541
7541
  \u8F93\u51FA\u662F JSON\u3002\u53EA\u5728\u56DE\u7B54\u4ED6\u7684\u95EE\u9898\u9700\u8981\u65F6\u8BFB\uFF0C\u8BFB\u5230\u7684\u5185\u5BB9\u53EA\u7528\u6765\u56DE\u7B54\u8FD9\u4E2A\u4EBA\uFF0C\u522B\u8F6C\u8FF0\u5230\u522B\u5904\u3002\u8FD4\u56DE expired \u8BF4\u660E\u8FD9\u4E00\u8F6E\u7684\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u544A\u8BC9\u4ED6\u91CD\u65B0\u53D1\u4E00\u6B21\u95EE\u9898\u3002\u8FD4\u56DE need_auth \u8BF4\u660E\u4ED6\u7684\u6388\u6743\u5931\u6548\u4E86\uFF08\u592A\u4E45\u6CA1\u7528\u6216\u5728\u98DE\u4E66\u91CC\u64A4\u9500\u8FC7\uFF09\uFF0C\u7CFB\u7EDF\u5DF2\u7ECF\u7ED9\u4ED6\u91CD\u53D1\u4E86\u4E00\u5F20\u6388\u6743\u5361\u7247\uFF1A\u544A\u8BC9\u4ED6\u70B9\u5361\u7247\u91CD\u65B0\u6388\u6743\uFF0C\u6388\u6743\u540E\u518D\u95EE\u4E00\u6B21\u3002\u8FD4\u56DE auth_failed \u8BF4\u660E\u6388\u6743\u5931\u6548\u3001\u800C\u4E14\u5361\u7247\u6CA1\u53D1\u51FA\u53BB\uFF1A\u544A\u8BC9\u4ED6\u7A0D\u540E\u518D\u95EE\u4E00\u6B21\u3002
7542
7542
 
@@ -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) {
@@ -15982,7 +16044,7 @@ async function startChannel(deps) {
15982
16044
  const pool = new ProcessPool(() => getMaxConcurrentRuns(controls.cfg));
15983
16045
  const executor = new RunExecutor({ agent, pool, activeRuns });
15984
16046
  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;
16047
+ const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join29(dirname19(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
15986
16048
  await callbackNonceStore?.load();
15987
16049
  const callbackAuth = callbackNonceStore ? new CallbackAuth({
15988
16050
  keys: [{ version: 1, secret: appSecret }],
@@ -16523,6 +16585,7 @@ async function intakeMessage(deps) {
16523
16585
  );
16524
16586
  }
16525
16587
  const bound2 = binding?.kind === "bound" ? binding.binding : void 0;
16588
+ if (bound2?.viaThread && emsg.rootId) void submitThreadDecision(channel, controls, bound2, emsg);
16526
16589
  const handled = await tryHandleCommand({
16527
16590
  channel,
16528
16591
  msg: emsg,
@@ -16561,6 +16624,20 @@ async function intakeMessage(deps) {
16561
16624
  const size = pending.push(scope, emsg);
16562
16625
  log.info("intake", "queued", { scope, queueSize: size, debounceMs: DEBOUNCE_MS });
16563
16626
  }
16627
+ async function submitThreadDecision(channel, controls, bound2, msg) {
16628
+ try {
16629
+ if (!isDecisionText(msg)) return;
16630
+ const handoffDir = handoffDirs(controls.profileConfig.preferences.cardHandoffs)["sdlc-task"];
16631
+ if (!handoffDir) return;
16632
+ const awaiting = awaitingDecision(bound2.dir, bound2.task.task_id, msg.rootId);
16633
+ if (!awaiting) return;
16634
+ submitDecision(bound2.dir, handoffDir, awaiting, msg);
16635
+ log.info("binding", "decision-submitted", { taskId: awaiting.task_id, messageId: msg.messageId });
16636
+ await channel.send(msg.chatId, { markdown: decisionAck(msg.content) }, { replyTo: msg.messageId, replyInThread: true });
16637
+ } catch (err) {
16638
+ log.warn("binding", "decision-submit-failed", { reason: err instanceof Error ? err.message : String(err) });
16639
+ }
16640
+ }
16564
16641
  function dmBinding(controls, msg, scope, opts = {}) {
16565
16642
  const cfg = controls.profileConfig.preferences.taskBindings;
16566
16643
  if (!cfg) return void 0;
@@ -19962,8 +20039,8 @@ function openBrowser(url) {
19962
20039
 
19963
20040
  // src/bridge/cli/commands/user-gateway.ts
19964
20041
  import { spawnSync as spawnSync5 } from "child_process";
19965
- import { existsSync as existsSync11 } from "fs";
19966
- import { join as join30 } from "path";
20042
+ import { existsSync as existsSync12 } from "fs";
20043
+ import { join as join31 } from "path";
19967
20044
 
19968
20045
  // src/bridge/user-gateway/db-query.ts
19969
20046
  import { spawn as spawn3 } from "child_process";
@@ -20016,14 +20093,14 @@ function toResult(r) {
20016
20093
  }
20017
20094
 
20018
20095
  // 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";
20096
+ import { createHash as createHash9, randomBytes as randomBytes10 } from "crypto";
20097
+ import { existsSync as existsSync11, rmSync as rmSync5 } from "fs";
20021
20098
  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";
20099
+ import { join as join30 } from "path";
20023
20100
 
20024
20101
  // src/bridge/user-gateway/app-token.ts
20025
20102
  import { spawn as spawn4 } from "child_process";
20026
- import { readFileSync as readFileSync6 } from "fs";
20103
+ import { readFileSync as readFileSync7 } from "fs";
20027
20104
  var APP_TOKEN_REFRESH_BEFORE_MS = 5 * 6e4;
20028
20105
  var APP_TOKEN_FAIL_BACKOFF_MS = 6e4;
20029
20106
  function createAppTokenCache(fetcher, now = Date.now) {
@@ -20068,7 +20145,7 @@ function brandOfTenant(tenant) {
20068
20145
  }
20069
20146
  function sourceBrand(sourceConfigFile) {
20070
20147
  try {
20071
- return brandOfTenant(JSON.parse(readFileSync6(sourceConfigFile, "utf8")).accounts?.app?.tenant);
20148
+ return brandOfTenant(JSON.parse(readFileSync7(sourceConfigFile, "utf8")).accounts?.app?.tenant);
20072
20149
  } catch {
20073
20150
  return "lark";
20074
20151
  }
@@ -20105,7 +20182,7 @@ function run(command, args, input, env, timeoutMs) {
20105
20182
  }
20106
20183
  function realAppTokenFetcher(sourceConfigFile) {
20107
20184
  return async () => {
20108
- const cfg = JSON.parse(readFileSync6(sourceConfigFile, "utf8"));
20185
+ const cfg = JSON.parse(readFileSync7(sourceConfigFile, "utf8"));
20109
20186
  const app = cfg.accounts?.app;
20110
20187
  if (!app?.id) throw new Error("source \u914D\u7F6E\u91CC\u6CA1\u6709\u5E94\u7528 id");
20111
20188
  let cred;
@@ -20695,10 +20772,10 @@ function createGateway(opts) {
20695
20772
  const issuedFor = /* @__PURE__ */ new Map();
20696
20773
  const inFlight = /* @__PURE__ */ new Set();
20697
20774
  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));
20775
+ const tokenRoot = join30(opts.stateDir, "user-tokens", opts.appId);
20776
+ const userDir = (openId) => join30(tokenRoot, openId);
20777
+ const authorizedMark = (openId) => join30(userDir(openId), ".authorized");
20778
+ const isAuthorized = (openId) => existsSync11(authorizedMark(openId));
20702
20779
  const larkNudgedAt = /* @__PURE__ */ new Map();
20703
20780
  const brand = sourceBrand(opts.larkSourceConfig);
20704
20781
  function env(dir) {
@@ -20710,11 +20787,11 @@ function createGateway(opts) {
20710
20787
  LARKSUITE_CLI_NO_SKILLS_NOTIFIER: "1"
20711
20788
  };
20712
20789
  }
20713
- const appDir = join29(opts.stateDir, "app");
20790
+ const appDir = join30(opts.stateDir, "app");
20714
20791
  const bound2 = /* @__PURE__ */ new Set();
20715
20792
  async function ensureBound(dir, identity) {
20716
20793
  if (bound2.has(dir)) return;
20717
- if (!existsSync10(join29(dir, "lark-channel", "config.json"))) {
20794
+ if (!existsSync11(join30(dir, "lark-channel", "config.json"))) {
20718
20795
  await mkdir19(dir, { recursive: true, mode: 448 });
20719
20796
  const r = await opts.exec(["config", "bind", "--source", "lark-channel", "--identity", identity], env(dir), 3e4);
20720
20797
  if (r.code !== 0) throw new Error(`lark-cli \u7ED1\u5B9A\u5931\u8D25\uFF1A${larkError(r).detail}`);
@@ -20742,12 +20819,12 @@ function createGateway(opts) {
20742
20819
  }
20743
20820
  return r;
20744
20821
  };
20745
- const tmpRoot = join29(opts.stateDir, "tmp-files");
20746
- const tmpDirOf = (runId) => join29(tmpRoot, createHash8("sha256").update(runId).digest("hex").slice(0, 32));
20822
+ const tmpRoot = join30(opts.stateDir, "tmp-files");
20823
+ const tmpDirOf = (runId) => join30(tmpRoot, createHash9("sha256").update(runId).digest("hex").slice(0, 32));
20747
20824
  const downloads = /* @__PURE__ */ new Map();
20748
20825
  const sheetCache = /* @__PURE__ */ new Map();
20749
20826
  try {
20750
- rmSync4(tmpRoot, { recursive: true, force: true });
20827
+ rmSync5(tmpRoot, { recursive: true, force: true });
20751
20828
  } catch {
20752
20829
  }
20753
20830
  async function cleanupTmp() {
@@ -20761,8 +20838,8 @@ function createGateway(opts) {
20761
20838
  }
20762
20839
  for (const n of names) {
20763
20840
  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(() => {
20841
+ for (const k of sheetCache.keys()) if (k.startsWith(join30(tmpRoot, n))) sheetCache.delete(k);
20842
+ await rm14(join30(tmpRoot, n), { recursive: true, force: true }).catch(() => {
20766
20843
  });
20767
20844
  }
20768
20845
  }
@@ -20776,7 +20853,7 @@ function createGateway(opts) {
20776
20853
  }
20777
20854
  for (const d of dirs) {
20778
20855
  try {
20779
- for (const f of await readdir6(join29(tmpRoot, d))) total += (await stat8(join29(tmpRoot, d, f))).size;
20856
+ for (const f of await readdir6(join30(tmpRoot, d))) total += (await stat8(join30(tmpRoot, d, f))).size;
20780
20857
  } catch {
20781
20858
  }
20782
20859
  }
@@ -20997,7 +21074,8 @@ function createGateway(opts) {
20997
21074
  }, MAINTENANCE_MS).unref();
20998
21075
  async function larkFailure(h, fields, r) {
20999
21076
  const e = larkError(r);
21000
- if (!r.timedOut && e.type === "authentication") {
21077
+ const missingOurScope = !r.timedOut && /missing_scope/.test(e.detail) && (e.detail.match(/[a-z][a-z_]*:[a-z_.:]*[a-z]/g) ?? []).some((x) => USER_READ_SCOPES.includes(x));
21078
+ if (!r.timedOut && (e.type === "authentication" || missingOurScope)) {
21001
21079
  await rm14(authorizedMark(h.openId), { force: true });
21002
21080
  for (const [k, v] of handles) if (v.openId === h.openId) forget(k, "auth", v.runId);
21003
21081
  try {
@@ -21042,9 +21120,9 @@ function createGateway(opts) {
21042
21120
  const { messageId, fileKey, opts: ropts } = readFileParams(input);
21043
21121
  const dir = tmpDirOf(h.runId);
21044
21122
  const outName = `${fileKey}.bin`;
21045
- let path = join29(dir, outName);
21123
+ let path = join30(dir, outName);
21046
21124
  const fail = (result, extra = {}) => log.warn("user-gateway", "read.failed", { ...fields, result, ...extra });
21047
- if (!existsSync10(path)) {
21125
+ if (!existsSync11(path)) {
21048
21126
  if (await tmpBytes() >= (opts.tmpMaxBytes ?? MAX_TMP_BYTES)) {
21049
21127
  fail("busy");
21050
21128
  return { status: "busy" };
@@ -21070,10 +21148,10 @@ function createGateway(opts) {
21070
21148
  return larkFailure(h, fields, r);
21071
21149
  }
21072
21150
  }
21073
- if (!existsSync10(path)) {
21151
+ if (!existsSync11(path)) {
21074
21152
  try {
21075
21153
  const hit = (await readdir6(dir)).filter((n) => n.startsWith(fileKey));
21076
- if (hit.length === 1) path = join29(dir, hit[0]);
21154
+ if (hit.length === 1) path = join30(dir, hit[0]);
21077
21155
  } catch {
21078
21156
  }
21079
21157
  }
@@ -21211,7 +21289,7 @@ function createGateway(opts) {
21211
21289
  if (typeof v === "string") return { status: v };
21212
21290
  if (v.text?.trim() !== REVOKE_TEXT2) return { status: "not_revoke" };
21213
21291
  for (const [h, x] of handles) if (x.openId === v.openId) forget(h, "revoke", x.runId);
21214
- const had = existsSync10(userDir(v.openId));
21292
+ const had = existsSync11(userDir(v.openId));
21215
21293
  await rm14(userDir(v.openId), { recursive: true, force: true });
21216
21294
  bound2.delete(userDir(v.openId));
21217
21295
  log.info("user-gateway", "auth.revoked", { sender: tail6(v.openId), messageId, had });
@@ -21377,13 +21455,13 @@ function createGateway(opts) {
21377
21455
  }
21378
21456
 
21379
21457
  // src/bridge/user-gateway/server.ts
21380
- import { createHash as createHash9, timingSafeEqual as timingSafeEqual3 } from "crypto";
21458
+ import { createHash as createHash10, timingSafeEqual as timingSafeEqual3 } from "crypto";
21381
21459
  import { createServer as createServer2 } from "http";
21382
21460
  var MAX_BODY = 16 * 1024;
21383
21461
  var CLAUDE_ROUTES = /* @__PURE__ */ new Set(["/claude/token", "/claude/task-token", "/claude/ready", "/claude/login-submit", "/claude/logout"]);
21384
21462
  var DB_TASK_HANDLE = "/db/task-handle";
21385
21463
  var DB_QUERY = "/db/query";
21386
- var digest = (s) => createHash9("sha256").update(s).digest();
21464
+ var digest = (s) => createHash10("sha256").update(s).digest();
21387
21465
  function tokenOk(given, expected) {
21388
21466
  if (typeof given !== "string" || !given) return false;
21389
21467
  return timingSafeEqual3(digest(given), expected);
@@ -21491,10 +21569,10 @@ function fetchToken(cmd) {
21491
21569
  }
21492
21570
  async function runUserGateway(opts) {
21493
21571
  if (!/^cli_[A-Za-z0-9]+$/.test(opts.appId)) throw new Error("--app-id \u683C\u5F0F\u4E0D\u5BF9");
21494
- if (!existsSync11(opts.larkSourceConfig)) throw new Error(`\u627E\u4E0D\u5230 lark-cli source \u914D\u7F6E\uFF1A${opts.larkSourceConfig}`);
21572
+ if (!existsSync12(opts.larkSourceConfig)) throw new Error(`\u627E\u4E0D\u5230 lark-cli source \u914D\u7F6E\uFF1A${opts.larkSourceConfig}`);
21495
21573
  const port = Number(opts.port ?? 8788);
21496
21574
  if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("--port \u4E0D\u5BF9");
21497
- configureLogger({ logsDir: join30(opts.stateDir, "logs") });
21575
+ configureLogger({ logsDir: join31(opts.stateDir, "logs") });
21498
21576
  const gateway = createGateway({
21499
21577
  appId: opts.appId,
21500
21578
  stateDir: opts.stateDir,