aai-lark-bridge 0.1.6 → 0.1.7

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/README.md CHANGED
@@ -35,6 +35,18 @@ lark-cli --version # 见下方说明
35
35
  **非交互环境不会自动安装**,会打印 `(non-interactive mode; skipping auto-install)`
36
36
  并给出手工安装提示。所以非交互场景请先手工装好 `lark-cli`。
37
37
 
38
+ #### Codex 会话与 shell 兼容性
39
+
40
+ - 话题历史只在本轮真正新建会话时补全,恢复已有会话不重复注入;切换 agent、目录或
41
+ 策略后按实际可恢复身份重新判断。切回旧目录时仍可恢复其 catalog 会话。
42
+ - bridge 的 Codex 调用关闭 shell snapshot 和用户 shell profile 自动加载,并在工具
43
+ shell 中清空会抢占 Lark source 的 Hermes/OpenClaw 标记。只修改本次子进程参数,
44
+ 不改全局 Codex 配置、模型、登录状态或沙箱权限。
45
+ - 若新会话可用,但恢复原会话报 `paginated_threads is not supported`,先检查实际
46
+ `codex.binaryPath` 的版本与会话格式是否兼容。已验证 0.153.4 能恢复本机的 paginated
47
+ 会话;不要通过删历史、改会话元数据或自动另开会话处理兼容问题。
48
+ - 启动失败会显示 stderr 的最后 500 字符,避免真正的终止错误被前面的插件警告盖住。
49
+
38
50
  ### 第 2 步:安装
39
51
 
40
52
  ```bash
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.1.6",
7
+ version: "0.1.7",
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",
@@ -6017,9 +6017,9 @@ var BRIDGE_SYSTEM_PROMPT = `# aai-lark-bridge \u8FD0\u884C\u7EA6\u5B9A
6017
6017
 
6018
6018
  \u4F60\u60F3\u53D1\u4E00\u5F20\u53EF\u4EA4\u4E92\u7684\u5361\u7247\u8BA9\u7528\u6237\u70B9\u9009\u65F6\uFF1A
6019
6019
 
6020
- 1. \u7528 \`lark-cli\` \u628A\u5361\u53D1\u5230 \`bridge_context.chat_id\`\uFF1A
6021
- \`lark-cli im send-card --chat-id <chat_id> --card '<json>'\`
6022
- 2. \u5361\u7247\u7528 CardKit 2.0 schema\uFF08\`schema: "2.0"\`\uFF09\u3002
6020
+ 1. \u5148\u8BFB\u53D6\u5DF2\u5B89\u88C5\u7684 lark-im skill\uFF0C\u6309\u5176\u4E2D\u7684\u5361\u7247\u5DE5\u4F5C\u6D41\u751F\u6210 JSON\uFF0C\u518D\u7528 \`lark-cli\` \u628A\u5361\u53D1\u5230 \`bridge_context.chatId\`\uFF1A
6021
+ \`lark-cli im +messages-send --as bot --chat-id <chat_id> --msg-type interactive --content '<json>'\`
6022
+ 2. \u5361\u7247\u7528 CardKit 2.0 schema\uFF08\`schema: "2.0"\`\uFF09\uFF0C\u53D1\u9001\u540E\u6309\u8FD4\u56DE\u7684 message_id \u8BFB\u53D6\u6838\u9A8C\u3002
6023
6023
  3. **\u5982\u679C\u4F60\u5E0C\u671B\u7528\u6237\u70B9\u6309\u94AE\u540E\u56DE\u8C03\u5230\u4F60\uFF08\u8BA9\u4F60\u5728\u540C\u4E00\u4F1A\u8BDD\u91CC\u7EE7\u7EED\u5904\u7406\uFF09**\uFF1A
6024
6024
  - \u6309\u94AE\u7684 \`value\` \u5BF9\u8C61**\u5FC5\u987B**\u540C\u65F6\u5305\u542B \`__bridge_cb: true\` \u548C \`bridge_token: "<signed token>"\`\u3002
6025
6025
  - \`bridge_token\` \u5FC5\u987B\u7531 bridge-aware \u7684 lark-cli \u56DE\u8C03\u7B7E\u540D\u80FD\u529B\u751F\u6210\uFF1B\u4E0D\u8981\u731C\u6D4B\u3001\u4F2A\u9020\u3001\u590D\u7528\u6216\u624B\u5199 token\u3002
@@ -6058,8 +6058,19 @@ bridge \u4F1A\u7ED9\u4F60\u7684\u5B50\u8FDB\u7A0B\u6CE8\u5165\u5F53\u524D\u8FD0\
6058
6058
 
6059
6059
  \u5982\u679C \`lark-cli\` \u63D0\u793A \`lark-channel context detected but lark-cli is not bound to it\`,\u4E0D\u8981\u6539\u7528\u666E\u901A profile,\u4E0D\u8981\u76F4\u63A5\u8BFB\u53D6 \`config.json\` \u91CC\u7684\u8D26\u53F7\u6216\u5BC6\u94A5,\u4E5F\u4E0D\u8981\u81EA\u884C\u6267\u884C bind\u3002\u505C\u6B62\u5F53\u524D\u64CD\u4F5C\u5E76\u8BF7\u7528\u6237\u91CD\u542F bridge \u6216\u8FD0\u884C bridge doctor/preflight\u3002
6060
6060
 
6061
+ \u5982\u679C\u62A5\u7684\u662F \`hermes context detected\` \u6216 \`openclaw context detected\`\uFF0C\u8FD9\u662F\u5176\u4ED6 agent \u6807\u8BB0\u8FDB\u5165 shell \u540E\u9020\u6210\u7684\u4E0A\u4E0B\u6587\u6C61\u67D3\uFF0C\u4E0D\u662F\u5F53\u524D Lark profile \u672A\u7ED1\u5B9A\u3002\u4E0D\u8981\u5EFA\u8BAE\u91CD\u65B0 OAuth \u6216\u7ED9\u9519\u8BEF\u7684 source \u6267\u884C bind\u3002\u53EA\u68C0\u67E5\u51B2\u7A81\u53D8\u91CF\u662F\u5426\u975E\u7A7A\uFF0C\u4E0D\u8F93\u51FA\u53D8\u91CF\u503C\u6216\u51ED\u636E\uFF1B\u62A5\u544A\u5F53\u524D\u5DE5\u5177\u73AF\u5883\u4E0E bridge preflight \u7684\u5DEE\u5F02\u3002
6062
+
6061
6063
  \u914D\u7F6E\u6587\u4EF6\u53EF\u80FD\u662F\u591A profile \u7ED3\u6784,\u4E0D\u8981\u5047\u8BBE\u6839\u5C42\u4E00\u5B9A\u6709\u65E7\u7248\u5355 profile \u7684 \`accounts.app\`;\u786E\u5B9E\u9700\u8981\u8BFB\u53D6\u914D\u7F6E\u65F6\u6309\u5F53\u524D profile \u53D6\u503C,\u4E14\u4E0D\u8981\u8F93\u51FA\u5BC6\u94A5\u3002
6062
6064
 
6065
+ ## \u6545\u969C\u8BCA\u65AD\u4E0E\u5B8C\u6210\u72B6\u6001
6066
+
6067
+ - \u5206\u5F00\u62A5\u544A\u672C\u5730\u63D0\u4EA4\u3001\u8FDC\u7AEF\u63A8\u9001\u3001MR \u521B\u5EFA\u3001\u5408\u5E76\u3001\u53D1\u5E03\u3001\u5B89\u88C5\u3001\u91CD\u542F\u3001\u771F\u5B9E\u4E1A\u52A1\u9A8C\u6536\u3002\u6BCF\u4E00\u9879\u53EA\u6309\u672C\u8F6E\u53EF\u6838\u67E5\u8BC1\u636E\u786E\u8BA4\uFF1B\u8FDB\u7A0B\u5728\u7EBF\u6216\u6D4B\u8BD5\u901A\u8FC7\u4E0D\u80FD\u66FF\u4EE3\u7528\u6237\u8981\u6C42\u7684\u4EA4\u4ED8\u7269\u3002
6068
+ - \u7F51\u7EDC\u6216\u6743\u9650\u4E0D\u8DB3\u65F6\u8BF4\u201C\u65E0\u6CD5\u6838\u5B9E\u201D\uFF0C\u4E0D\u8981\u4ECE\u672C\u5730\u63A8\u9001\u5931\u8D25\u3001\u65E7\u5206\u652F\u6216\u65E7\u56DE\u7B54\u63A8\u65AD\u8FDC\u7AEF MR \u4E0D\u5B58\u5728\u3002\u8DE8\u65E5\u6216\u957F\u65F6\u95F4\u7EED\u804A\u5148\u6838\u5BF9\u5F53\u524D\u65F6\u95F4\u3002
6069
+ - \u591A\u6B21\u5931\u8D25\u8981\u9010\u6B21\u6838\u5BF9 scope\u3001\u6062\u590D\u7684\u4F1A\u8BDD\u3001\u8FD0\u884C\u7248\u672C\u548C\u9519\u8BEF\u53D1\u751F\u9636\u6BB5\u3002\u666E\u901A\u79C1\u804A\u7684 topicContext=0\uFF0C\u4E0D\u80FD\u7528\u8BDD\u9898\u91CD\u590D\u6CE8\u5165\u89E3\u91CA\uFF1B\u6267\u884C\u8FC7\u5DE5\u5177\u540E\u624D\u62D2\u7EDD\uFF0C\u4E5F\u4E0D\u80FD\u8BF4\u6210\u6240\u6709\u8BF7\u6C42\u90FD\u5728\u4F1A\u8BDD\u5EFA\u7ACB\u524D\u5931\u8D25\u3002
6070
+ - \u4E0A\u6E38\u62D2\u7EDD\u7684\u6839\u56E0\u672A\u590D\u73B0\u65F6\u6807\u4E3A\u5F85\u67E5\u3002\u4E0D\u8981\u5173\u95ED\u5BA1\u6838\u3001\u6539\u5199\u8BF7\u6C42\u4EE5\u89C4\u907F\u5BA1\u6838\u6216\u9759\u9ED8\u5220\u9664\u4F1A\u8BDD\u5386\u53F2\uFF1B\u4E0D\u8981\u628A\u65B0\u4F1A\u8BDD\u6210\u529F\u5F53\u6210\u539F\u4F1A\u8BDD\u5DF2\u4FEE\u590D\u3002
6071
+ - \u6C99\u7BB1\u62D2\u7EDD\u670D\u52A1\u7BA1\u7406\u65F6\u5982\u5B9E\u62A5\u544A\uFF0C\u4E0D\u6269\u5927\u6743\u9650\u6216\u53CD\u590D\u91CD\u8BD5\u3002\`/reconnect\` \u53EA\u91CD\u8FDE\u6216\u70ED\u52A0\u8F7D\uFF0C\u4E0D\u80FD\u5F53\u6210\u5B89\u88C5\u65B0\u4EE3\u7801\u540E\u7684\u5B8C\u6574\u8FDB\u7A0B\u91CD\u542F\u3002
6072
+ - \u5361\u7247\u6216\u5B9A\u65F6\u63A8\u9001\u53EA\u6709\u5728\u53D1\u9001\u6210\u529F\u5E76\u8BFB\u56DE\u5185\u5BB9\u3001\u6392\u7A0B\u88AB\u5B9E\u9645\u6CE8\u518C\u540E\u624D\u7B97\u4EA4\u4ED8\uFF1B\u5148\u524D\u7528\u6237\u5C1A\u672A\u5B8C\u6210\u7684\u8BF7\u6C42\u8981\u660E\u786E\u5217\u51FA\uFF0C\u4E0D\u80FD\u628A\u8BCA\u65AD\u56DE\u590D\u5F53\u4F5C\u5B8C\u6210\u3002
6073
+
6063
6074
  ## \u98DE\u4E66 OAuth \u6388\u6743\uFF08\`lark-cli auth login\`\uFF09
6064
6075
 
6065
6076
  \u6388\u6743\u6D41\u7A0B\u8981\u8BA9 \`lark-cli\` \u8FDB\u7A0B\u4E00\u76F4\u6D3B\u5230\u7528\u6237\u5728\u6D4F\u89C8\u5668\u91CC\u70B9\u5B8C\u4E3A\u6B62\u3002bridge \u5728\u4F60\u7684 run \u7ED3\u675F\u4E4B\u540E\u4F1A\u56DE\u6536 agent \u5B50\u8FDB\u7A0B\uFF0C**\u4F60 spawn \u7684\u4EFB\u4F55\u540E\u53F0 bash \u4E5F\u4F1A\u8DDF\u7740\u6B7B**\u2014\u2014\u6240\u4EE5\u6388\u6743\u5FC5\u987B\u7528"\u524D\u53F0\u963B\u585E"\u7684\u65B9\u5F0F\u8DD1\uFF1A
@@ -6488,6 +6499,16 @@ function buildCodexArgs(input) {
6488
6499
  'approval_policy="never"',
6489
6500
  "-c",
6490
6501
  'shell_environment_policy.inherit="all"',
6502
+ // Shell snapshots source the user's interactive rc and can restore agent
6503
+ // markers after spawn-time cleanup. Keep this scoped to bridge runs.
6504
+ "-c",
6505
+ "features.shell_snapshot=false",
6506
+ "-c",
6507
+ "shell_environment_policy.experimental_use_profile=false",
6508
+ ...COMPETING_AGENT_ENV_VARS.flatMap((key) => [
6509
+ "-c",
6510
+ `shell_environment_policy.set.${key}=""`
6511
+ ]),
6491
6512
  ...input.ignoreUserConfig === true ? ["--ignore-user-config"] : [],
6492
6513
  ...input.ignoreRules === false ? [] : ["--ignore-rules"],
6493
6514
  "--skip-git-repo-check",
@@ -6925,7 +6946,7 @@ async function* createEventStream2(child, stderrTail, getError, getStopReason) {
6925
6946
  if (exitCode !== 0 && exitCode !== null) {
6926
6947
  if (!translator.terminalEmitted()) {
6927
6948
  const stderr = stderrTail.text();
6928
- const detail = stderr ? `: ${stderr.slice(0, 500)}` : "";
6949
+ const detail = stderr ? `: ${stderr.slice(-500)}` : "";
6929
6950
  yield* translator.fail(`codex exited with code ${exitCode}${detail}`);
6930
6951
  }
6931
6952
  return;
@@ -9637,18 +9658,23 @@ async function startRunFlow(input) {
9637
9658
  }
9638
9659
  }
9639
9660
  if (!resumeFrom && input.capability.agentId === "claude") {
9640
- resumeFrom = input.sessions.resumeFor(input.scopeId, workspace.cwdRealpath);
9661
+ const legacySessionId = input.sessions.resumeFor(input.scopeId, workspace.cwdRealpath);
9662
+ const catalogOwnsSession = legacySessionId && input.sessionCatalog?.entries().some(
9663
+ (entry) => entry.scopeId === input.scopeId && entry.agentId === "claude" && entry.sessionId === legacySessionId
9664
+ );
9665
+ resumeFrom = catalogOwnsSession ? void 0 : legacySessionId;
9641
9666
  sessionId = resumeFrom;
9642
9667
  const stale = input.sessions.getRaw(input.scopeId);
9643
9668
  if (!resumeFrom && stale?.cwd && stale.cwd !== workspace.cwdRealpath) {
9644
9669
  input.sessions.clear(input.scopeId);
9645
9670
  }
9646
9671
  }
9672
+ const runPolicy = !resumeFrom && input.prepareFreshPrompt ? { ...policy, prompt: await input.prepareFreshPrompt() } : policy;
9647
9673
  let execution;
9648
9674
  try {
9649
9675
  execution = await input.executor.submit({
9650
9676
  scopeId: input.scopeId,
9651
- policy,
9677
+ policy: runPolicy,
9652
9678
  sessionId,
9653
9679
  threadId,
9654
9680
  model: resolveModelArg(
@@ -9675,7 +9701,7 @@ async function startRunFlow(input) {
9675
9701
  return {
9676
9702
  ok: true,
9677
9703
  execution,
9678
- policy,
9704
+ policy: runPolicy,
9679
9705
  cwdRealpath: workspace.cwdRealpath,
9680
9706
  ...resumeFrom ? { resumeFrom } : {}
9681
9707
  };
@@ -14104,7 +14130,7 @@ var STREAM_TRUSTED_LIFETIME_MS = 9 * 6e4;
14104
14130
  var BRIDGE_AGENT_INSTRUCTIONS = [
14105
14131
  "\u4F60\u5728 bridge \u8FDB\u7A0B\u4E2D\u8FD0\u884C\uFF0C\u666E\u901A lark-cli \u4F1A\u7EE7\u627F LARK_CHANNEL=1 \u5E76\u8FDB\u5165 bridge-bound \u6A21\u5F0F\u3002",
14106
14132
  "\u4E0D\u8981 unset LARK_CHANNEL / LARK_CHANNEL_HOME / LARK_CHANNEL_PROFILE / LARKSUITE_CLI_CONFIG_DIR\uFF0C\u4E5F\u4E0D\u8981\u7528 env -u LARK_CHANNEL \u7ED5\u56DE\u672C\u673A\u666E\u901A\u914D\u7F6E\u3002",
14107
- "Codex bridge \u9ED8\u8BA4\u4F7F\u7528 danger-full-access \u5BF9\u9F50 Claude bridge \u7684 bypassPermissions \u884C\u4E3A\uFF0C\u56E0\u6B64 lark-cli \u5E94\u80FD\u50CF\u7528\u6237\u672C\u673A\u7EC8\u7AEF\u4E00\u6837\u8BBF\u95EE keychain\u3002",
14133
+ "\u5B9E\u9645\u6C99\u7BB1\u4E0E keychain \u53EF\u7528\u6027\u53D6\u51B3\u4E8E\u5F53\u524D profile \u548C\u5BBF\u4E3B\u6743\u9650\uFF0C\u5E94\u4EE5\u5DE5\u5177\u68C0\u67E5\u7ED3\u679C\u4E3A\u51C6\uFF1B\u4E0D\u8981\u4E3A\u4E86\u8BBF\u95EE\u51ED\u636E\u800C\u6269\u5927\u6743\u9650\u6216\u5173\u95ED\u5BA1\u6838\u3002",
14108
14134
  "\u5982\u679C\u63D0\u793A lark-channel context detected but not bound\uFF0C\u505C\u6B62\u5F53\u524D\u64CD\u4F5C\u5E76\u8BF7\u7528\u6237\u91CD\u542F bridge \u6216\u8FD0\u884C bridge doctor/preflight\uFF1B\u4E0D\u8981\u6539\u7528\u666E\u901A profile\uFF0C\u4E0D\u8981\u81EA\u884C bind\uFF0C\u4E5F\u4E0D\u8981\u76F4\u63A5\u8BFB\u53D6 config.json \u91CC\u7684\u8D26\u53F7\u6216\u5BC6\u94A5\u3002"
14109
14135
  ];
14110
14136
  var SUPPRESSED_API_ERROR_CODES = /* @__PURE__ */ new Set([
@@ -14724,27 +14750,7 @@ async function runAgentBatch(deps) {
14724
14750
  });
14725
14751
  }
14726
14752
  }
14727
- const scopeCwd = workspaces.cwdFor(scope);
14728
- const scopeEngaged = Boolean(sessions2.getRaw(scope)) || (sessionCatalog?.hasResumableForScope({
14729
- scopeId: scope,
14730
- agentId: controls.profileConfig.agentKind,
14731
- ...scopeCwd ? { cwdRealpath: scopeCwd } : {}
14732
- }) ?? false);
14733
14753
  let topicContext = [];
14734
- if (mode === "topic" && threadId && !scopeEngaged) {
14735
- const exclude = /* @__PURE__ */ new Set([...batchIds, ...quoteTargets]);
14736
- topicContext = await fetchTopicContext(channel, threadId, {
14737
- maxMessages: 40,
14738
- excludeIds: exclude
14739
- });
14740
- if (topicContext.length > 0) {
14741
- log.info("topic", "context-fetched", {
14742
- scope,
14743
- threadId,
14744
- count: topicContext.length
14745
- });
14746
- }
14747
- }
14748
14754
  const agentKind = controls.profileConfig.agentKind;
14749
14755
  const modelPref = controls.profileConfig.preferences.model;
14750
14756
  const modelSelection = normalizeModelSelection(agentKind, modelPref);
@@ -14763,12 +14769,6 @@ async function runAgentBatch(deps) {
14763
14769
  channel.botIdentity,
14764
14770
  extraInstructions
14765
14771
  );
14766
- log.info("prompt", "built", {
14767
- promptChars: prompt.length,
14768
- quotes: quotes.length,
14769
- topicContext: topicContext.length,
14770
- ...modelSwitched ? { modelSwitchedTo: modelSelection } : {}
14771
- });
14772
14772
  const sendOpts = {
14773
14773
  replyTo: lastMsg.messageId,
14774
14774
  ...mode === "topic" && threadId ? { replyInThread: true } : {}
@@ -14793,6 +14793,17 @@ async function runAgentBatch(deps) {
14793
14793
  scopeId: scope,
14794
14794
  scope: scopeContext,
14795
14795
  prompt,
14796
+ prepareFreshPrompt: async () => {
14797
+ if (mode !== "topic" || !threadId) return prompt;
14798
+ topicContext = await fetchTopicContext(channel, threadId, {
14799
+ maxMessages: 40,
14800
+ excludeIds: /* @__PURE__ */ new Set([...batchIds, ...quoteTargets])
14801
+ });
14802
+ if (topicContext.length > 0) {
14803
+ log.info("topic", "context-fetched", { scope, threadId, count: topicContext.length });
14804
+ }
14805
+ return buildPrompt(batch, attachments, quotes, topicContext, channel.botIdentity, extraInstructions);
14806
+ },
14796
14807
  attachments: attachments.map(toPolicyAttachment),
14797
14808
  access: accessDecision,
14798
14809
  capability,
@@ -14821,6 +14832,12 @@ async function runAgentBatch(deps) {
14821
14832
  return;
14822
14833
  }
14823
14834
  const { execution, cwdRealpath: cwd } = flow;
14835
+ log.info("prompt", "built", {
14836
+ promptChars: flow.policy.prompt.length,
14837
+ quotes: quotes.length,
14838
+ topicContext: topicContext.length,
14839
+ ...modelSwitched ? { modelSwitchedTo: modelSelection } : {}
14840
+ });
14824
14841
  activePolicyFingerprints.set(scope, flow.policy.policyFingerprint);
14825
14842
  const handle2 = execution.handle;
14826
14843
  const eventStream = execution.subscribe();
@@ -16943,24 +16960,7 @@ var SessionCatalog = class {
16943
16960
  }
16944
16961
  return { ...entry };
16945
16962
  }
16946
- /**
16947
- * Whether a run for this scope would find something to resume. Callers that
16948
- * run before the policy is resolved cannot build a full identity, but still
16949
- * need to know "has the agent already engaged here" — topic upstream
16950
- * backfill is the case: it must not re-inject the thread's history into a
16951
- * conversation that already carries it.
16952
- *
16953
- * Narrow it with everything the caller *does* know. `activeFor()` resumes
16954
- * only on an exact identity match, so a probe that answers on `scopeId`
16955
- * alone reports "engaged" for entries that will not in fact be resumed —
16956
- * and then a genuinely fresh session starts with no upstream history at all.
16957
- * `/cd` and `/ws use` create exactly that state: they reset the session but
16958
- * deliberately leave the old cwd's entry active so cd-ing back still resumes.
16959
- *
16960
- * `policyFingerprint` is the one axis that stays open: it does not exist
16961
- * until the policy resolves. A profile change that alters it still costs the
16962
- * next fresh session its backfill.
16963
- */
16963
+ /** 按已知身份探测活跃记录;未匹配策略指纹,不能代替实际 resume 或话题补全决策。 */
16964
16964
  hasResumableForScope(probe) {
16965
16965
  for (const entry of this.data.values()) {
16966
16966
  if (entry.scopeId !== probe.scopeId) continue;