lark-remote 0.1.5 → 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.
Files changed (190) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.en.md +5 -1
  3. package/README.md +10 -2
  4. package/dist/bridge/approval-coordinator.d.ts +131 -0
  5. package/dist/bridge/approval-coordinator.js +409 -0
  6. package/dist/bridge/inbound-media.d.ts +62 -0
  7. package/dist/bridge/inbound-media.js +282 -0
  8. package/dist/bridge/index.d.ts +138 -5
  9. package/dist/bridge/index.js +569 -65
  10. package/dist/bridge/queue-manager.d.ts +11 -1
  11. package/dist/bridge/queue-manager.js +20 -11
  12. package/dist/card/approval-render.d.ts +16 -0
  13. package/dist/card/approval-render.js +363 -0
  14. package/dist/card/bash-card-session.d.ts +2 -24
  15. package/dist/card/bash-card-session.js +6 -73
  16. package/dist/card/bash-renderer.js +2 -3
  17. package/dist/card/card-budget.js +29 -75
  18. package/dist/card/card-session.d.ts +48 -0
  19. package/dist/card/card-session.js +86 -0
  20. package/dist/card/card-shared.d.ts +13 -10
  21. package/dist/card/card-shared.js +27 -24
  22. package/dist/card/run-card-session.d.ts +2 -55
  23. package/dist/card/run-card-session.js +6 -104
  24. package/dist/card/run-renderer.js +140 -202
  25. package/dist/card/run-state.d.ts +38 -3
  26. package/dist/card/run-state.js +221 -11
  27. package/dist/card/text-truncate.d.ts +13 -12
  28. package/dist/card/text-truncate.js +13 -63
  29. package/dist/common/fs.d.ts +8 -0
  30. package/dist/common/fs.js +17 -0
  31. package/dist/common/guards.d.ts +0 -20
  32. package/dist/common/guards.js +0 -43
  33. package/dist/common/sleep.d.ts +2 -0
  34. package/dist/common/sleep.js +5 -0
  35. package/dist/common/truncate.d.ts +39 -0
  36. package/dist/common/truncate.js +92 -0
  37. package/dist/config/codex-config.d.ts +1 -1
  38. package/dist/config/codex-config.js +1 -1
  39. package/dist/config/dir.js +1 -1
  40. package/dist/config/index.d.ts +116 -9
  41. package/dist/config/index.js +122 -29
  42. package/dist/connector/index.d.ts +74 -2
  43. package/dist/connector/index.js +119 -1
  44. package/dist/index.js +139 -99
  45. package/dist/instance-lock.js +4 -12
  46. package/dist/order/alias-resolve.d.ts +13 -0
  47. package/dist/order/alias-resolve.js +22 -0
  48. package/dist/order/alias-store.d.ts +38 -0
  49. package/dist/order/alias-store.js +106 -0
  50. package/dist/persistence/atomic-write.d.ts +8 -2
  51. package/dist/persistence/atomic-write.js +23 -7
  52. package/dist/restart.js +2 -1
  53. package/dist/router/card-helpers.d.ts +63 -0
  54. package/dist/router/card-helpers.js +146 -0
  55. package/dist/router/config/claude.js +25 -1
  56. package/dist/router/config/codex.d.ts +1 -1
  57. package/dist/router/config/codex.js +33 -5
  58. package/dist/router/config/common/model-patch.d.ts +22 -0
  59. package/dist/router/config/common/model-patch.js +26 -0
  60. package/dist/router/config/common/render.js +9 -4
  61. package/dist/router/config/index.d.ts +12 -0
  62. package/dist/router/config/index.js +25 -1
  63. package/dist/router/config/kimi.d.ts +4 -1
  64. package/dist/router/config/kimi.js +27 -0
  65. package/dist/router/config/opencode.js +18 -5
  66. package/dist/router/config/pi.js +4 -5
  67. package/dist/router/config/types.d.ts +12 -3
  68. package/dist/router/index.d.ts +77 -17
  69. package/dist/router/index.js +455 -549
  70. package/dist/router/utils.d.ts +4 -0
  71. package/dist/router/utils.js +9 -2
  72. package/dist/runner/agent-choices-common.d.ts +16 -0
  73. package/dist/runner/agent-choices-common.js +31 -0
  74. package/dist/runner/claude/runner.d.ts +47 -10
  75. package/dist/runner/claude/runner.js +117 -46
  76. package/dist/runner/claude/session.d.ts +166 -0
  77. package/dist/runner/claude/session.js +749 -0
  78. package/dist/runner/codex/app-server/protocol-types.d.ts +519 -0
  79. package/dist/runner/codex/app-server/protocol-types.js +56 -0
  80. package/dist/runner/codex/app-server/runner.d.ts +104 -0
  81. package/dist/runner/codex/app-server/runner.js +377 -0
  82. package/dist/runner/codex/app-server/translator.d.ts +89 -0
  83. package/dist/runner/codex/app-server/translator.js +716 -0
  84. package/dist/runner/codex/index.d.ts +1 -1
  85. package/dist/runner/codex/index.js +1 -1
  86. package/dist/runner/common/acp/protocol-helpers.d.ts +14 -0
  87. package/dist/runner/common/acp/protocol-helpers.js +21 -0
  88. package/dist/runner/common/acp/protocol-types.d.ts +238 -0
  89. package/dist/runner/common/acp/protocol-types.js +75 -0
  90. package/dist/runner/common/connection-based-runner.d.ts +111 -0
  91. package/dist/runner/common/connection-based-runner.js +261 -0
  92. package/dist/runner/common/jsonrpc/client.d.ts +89 -0
  93. package/dist/runner/common/jsonrpc/client.js +243 -0
  94. package/dist/runner/common/jsonrpc/connection-manager.d.ts +125 -0
  95. package/dist/runner/common/jsonrpc/connection-manager.js +205 -0
  96. package/dist/runner/common/jsonrpc/transport.d.ts +50 -0
  97. package/dist/runner/common/jsonrpc/transport.js +230 -0
  98. package/dist/runner/common/jsonrpc/types.d.ts +32 -0
  99. package/dist/runner/common/jsonrpc/types.js +9 -0
  100. package/dist/runner/common/process-stopper.d.ts +2 -1
  101. package/dist/runner/common/process-stopper.js +1 -0
  102. package/dist/runner/common/runner-utils.d.ts +6 -13
  103. package/dist/runner/common/runner-utils.js +6 -47
  104. package/dist/runner/common/spawning-runner.d.ts +24 -70
  105. package/dist/runner/common/spawning-runner.js +98 -152
  106. package/dist/runner/common/usage.d.ts +2 -0
  107. package/dist/runner/common/usage.js +2 -0
  108. package/dist/runner/index.d.ts +5 -5
  109. package/dist/runner/index.js +4 -4
  110. package/dist/runner/kimi/acp/runner.d.ts +106 -0
  111. package/dist/runner/kimi/acp/runner.js +448 -0
  112. package/dist/runner/kimi/acp/translator.d.ts +124 -0
  113. package/dist/runner/kimi/acp/translator.js +336 -0
  114. package/dist/runner/kimi/index.d.ts +1 -1
  115. package/dist/runner/kimi/index.js +1 -1
  116. package/dist/runner/opencode/acp/index.d.ts +1 -0
  117. package/dist/runner/opencode/acp/index.js +2 -0
  118. package/dist/runner/opencode/acp/runner.d.ts +121 -0
  119. package/dist/runner/opencode/acp/runner.js +429 -0
  120. package/dist/runner/opencode/acp/translator.d.ts +119 -0
  121. package/dist/runner/opencode/acp/translator.js +345 -0
  122. package/dist/runner/opencode/index.d.ts +1 -1
  123. package/dist/runner/opencode/index.js +1 -1
  124. package/dist/runner/pi/index.d.ts +1 -1
  125. package/dist/runner/pi/index.js +1 -1
  126. package/dist/runner/pi/rpc/client.d.ts +52 -0
  127. package/dist/runner/pi/rpc/client.js +114 -0
  128. package/dist/runner/pi/rpc/index.d.ts +4 -0
  129. package/dist/runner/pi/rpc/index.js +4 -0
  130. package/dist/runner/pi/rpc/protocol-types.d.ts +127 -0
  131. package/dist/runner/pi/rpc/protocol-types.js +21 -0
  132. package/dist/runner/pi/rpc/runner.d.ts +80 -0
  133. package/dist/runner/pi/rpc/runner.js +199 -0
  134. package/dist/runner/pi/rpc/translator.d.ts +55 -0
  135. package/dist/runner/pi/rpc/translator.js +258 -0
  136. package/dist/runner/registry.d.ts +7 -8
  137. package/dist/runner/registry.js +3 -4
  138. package/dist/runner/resolve-agent-choices.js +18 -59
  139. package/dist/runner/sync-agent-choices.js +16 -67
  140. package/dist/runner/types.d.ts +153 -2
  141. package/dist/session/claude/session-index.js +2 -3
  142. package/dist/session/claude/session-reader.js +3 -6
  143. package/dist/session/claude/sessions.js +6 -13
  144. package/dist/session/codex/rollout-reader.d.ts +2 -2
  145. package/dist/session/codex/rollout-reader.js +57 -17
  146. package/dist/session/codex/sessions.d.ts +1 -1
  147. package/dist/session/codex/sessions.js +2 -2
  148. package/dist/session/common/content-blocks.d.ts +7 -0
  149. package/dist/session/common/content-blocks.js +13 -9
  150. package/dist/session/common/jsonl.d.ts +8 -25
  151. package/dist/session/common/jsonl.js +126 -261
  152. package/dist/session/common/pagination.d.ts +28 -0
  153. package/dist/session/common/pagination.js +33 -0
  154. package/dist/session/kimi/sessions.d.ts +34 -1
  155. package/dist/session/kimi/sessions.js +208 -98
  156. package/dist/session/opencode/sessions.d.ts +17 -3
  157. package/dist/session/opencode/sessions.js +29 -29
  158. package/dist/session/pi/sessions.d.ts +5 -1
  159. package/dist/session/pi/sessions.js +12 -16
  160. package/dist/session/session-store.d.ts +11 -1
  161. package/dist/session/session-store.js +75 -178
  162. package/dist/update/index.d.ts +2 -2
  163. package/dist/update/index.js +2 -2
  164. package/dist/update/install.d.ts +20 -2
  165. package/dist/update/install.js +51 -7
  166. package/package.json +1 -1
  167. package/dist/runner/codex/argv.d.ts +0 -33
  168. package/dist/runner/codex/argv.js +0 -40
  169. package/dist/runner/codex/jsonl.d.ts +0 -37
  170. package/dist/runner/codex/jsonl.js +0 -221
  171. package/dist/runner/codex/runner.d.ts +0 -63
  172. package/dist/runner/codex/runner.js +0 -124
  173. package/dist/runner/common/exec-translator.d.ts +0 -73
  174. package/dist/runner/common/exec-translator.js +0 -105
  175. package/dist/runner/kimi/jsonl.d.ts +0 -28
  176. package/dist/runner/kimi/jsonl.js +0 -143
  177. package/dist/runner/kimi/runner.d.ts +0 -49
  178. package/dist/runner/kimi/runner.js +0 -105
  179. package/dist/runner/opencode/argv.d.ts +0 -32
  180. package/dist/runner/opencode/argv.js +0 -35
  181. package/dist/runner/opencode/jsonl.d.ts +0 -68
  182. package/dist/runner/opencode/jsonl.js +0 -295
  183. package/dist/runner/opencode/runner.d.ts +0 -61
  184. package/dist/runner/opencode/runner.js +0 -93
  185. package/dist/runner/pi/jsonl.d.ts +0 -128
  186. package/dist/runner/pi/jsonl.js +0 -249
  187. package/dist/runner/pi/runner.d.ts +0 -36
  188. package/dist/runner/pi/runner.js +0 -76
  189. package/dist/session/common/catch-up.d.ts +0 -12
  190. package/dist/session/common/catch-up.js +0 -31
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { loadPiConfig, getPiModelOptions } from '../../config/pi-config.js';
5
5
  import { PI_THINKING_LEVELS } from '../../config/index.js';
6
+ import { resetModelPatch } from './common/model-patch.js';
6
7
  export class PiConfigBuilder {
7
8
  buildFields(displayConfig) {
8
9
  const fields = [];
@@ -37,12 +38,10 @@ export class PiConfigBuilder {
37
38
  patches.push({ key, value });
38
39
  // provider 变更时,重置 model 为新 provider 的首个模型
39
40
  if (key === 'agents.pi.provider' && typeof value === 'string') {
40
- const newModelOptions = getPiModelOptions(value);
41
41
  const currentModel = config.agents?.pi?.model;
42
- const currentModelIsValid = newModelOptions.some((m) => m === currentModel);
43
- if (!currentModelIsValid && newModelOptions.length > 0) {
44
- patches.push({ key: 'agents.pi.model', value: newModelOptions[0] });
45
- }
42
+ const modelPatch = resetModelPatch(key, 'agents.pi.model', currentModel, getPiModelOptions(value));
43
+ if (modelPatch)
44
+ patches.push(modelPatch);
46
45
  }
47
46
  return patches;
48
47
  }
@@ -5,13 +5,22 @@
5
5
  * The router delegates to `getConfigBuilder(agent)` instead of a giant switch-case.
6
6
  */
7
7
  import type { AppConfig } from '../../config/index.js';
8
+ /** A select option with separate display text and config value. */
9
+ export interface SelectOption {
10
+ /** Display text shown in the dropdown (may include annotations). */
11
+ text: string;
12
+ /** Config value written to config.yaml (must match schema enum values). */
13
+ value: string;
14
+ }
8
15
  /** A single field descriptor in the /config card. */
9
16
  export interface ConfigField {
10
17
  key: string;
11
18
  label: string;
12
- type: 'boolean' | 'select' | 'input';
13
- /** For select type: the list of options shown in the dropdown. */
14
- options?: readonly string[];
19
+ type: 'boolean' | 'select' | 'input' | 'note';
20
+ /** For select type: the list of options shown in the dropdown.
21
+ * Accepts plain strings (text=value) or {text, value} objects for
22
+ * display-value separation (e.g. 'manual(逐项审批)' → value 'manual'). */
23
+ options?: readonly (string | SelectOption)[];
15
24
  /** Override the currentValue shown in the card (takes priority over getConfigValue). */
16
25
  currentValue?: string | boolean;
17
26
  }
@@ -60,6 +60,18 @@ export interface CardActionPayload {
60
60
  /** CardKit 2.0 input 组件自带提交图标触发回调时回传的输入值 */
61
61
  inputValue?: string;
62
62
  orderId?: string;
63
+ /** Approval request ID for approval card actions. */
64
+ requestId?: number | string;
65
+ /** Decision for approval.respond (e.g. 'accept', 'decline', 'cancel'). */
66
+ decision?: string;
67
+ /** Unique nonce to prevent duplicate processing. */
68
+ nonce?: string;
69
+ /** Permission item ID for approval.toggle. */
70
+ permId?: string;
71
+ /** Desired selection state for approval.toggle (card renders !current). */
72
+ selected?: boolean;
73
+ /** Claude AskUserQuestion 问题索引(approval.answer / approval.answerSubmit)。 */
74
+ questionIndex?: number;
63
75
  }
64
76
  /**
65
77
  * Response a cardAction handler may return to give the clicking user native
@@ -79,11 +91,15 @@ export declare class CommandRouter {
79
91
  /** Valid agent kinds — single source of truth for resume.use / resume.page / cmdResume. */
80
92
  static readonly VALID_AGENTS: readonly ["claude", "codex", "opencode", "pi", "kimi"];
81
93
  private sessionStore;
82
- private bridge;
83
- private config;
84
- private configPath;
94
+ /** 飞书桥接实例(public:测试直接访问断言,替代 as unknown as)。 */
95
+ bridge: Bridge;
96
+ /** 当前配置(public:测试直接读取断言,替代 as unknown as)。 */
97
+ config: AppConfig;
98
+ /** 配置文件的绝对路径(public:/config 保存链路与测试共用)。 */
99
+ configPath: string;
85
100
  private workspaceStore;
86
101
  private orderStore;
102
+ private aliasStore;
87
103
  private exitHandler;
88
104
  private pendingExit;
89
105
  /**
@@ -98,7 +114,8 @@ export declare class CommandRouter {
98
114
  private updateCachePath?;
99
115
  /** Injected update functions (for testability; defaults to real implementation). */
100
116
  private updateFns;
101
- private pendingConfig;
117
+ /** /config 卡片编辑暂存区(public:测试直接读取断言,替代 as unknown as)。 */
118
+ pendingConfig: AppConfig | null;
102
119
  /**
103
120
  * Monotonic counter minting unique internal keys for order.exec enqueue
104
121
  * actions. One order card can be clicked many times, so the Feishu card
@@ -119,7 +136,8 @@ export declare class CommandRouter {
119
136
  * it uses `listRegisteredAgents()` from `router/config/index.ts` (the
120
137
  * config-builder registry), which mirrors the agents with a config card.
121
138
  */
122
- private sessionReaderRegistry;
139
+ /** Session reader 注册中心(public:测试注入/读取,替代 as unknown as)。 */
140
+ sessionReaderRegistry: SessionReaderRegistry;
123
141
  /**
124
142
  * 串行化 config.* 卡片回调(2026-07-04)。
125
143
  * CardKit 2.0 input/button 回调经 `enqueueImmediate` 分发,**不进串行队列**,
@@ -136,6 +154,8 @@ export declare class CommandRouter {
136
154
  configPath: string;
137
155
  workspacePath?: string;
138
156
  ordersPath?: string;
157
+ /** 别名存储路径(<configDir>/aliases.json)。 */
158
+ aliasesPath?: string;
139
159
  exitHandler?: () => void;
140
160
  /** Spawn the detached replacement bridge process and return its pid (throws on failure). */
141
161
  restartSpawner?: () => number;
@@ -168,11 +188,22 @@ export declare class CommandRouter {
168
188
  cwdOverride?: string;
169
189
  binding?: AgentBinding;
170
190
  }): Promise<CommandResult | null>;
191
+ /**
192
+ * 一次别名展开:bridge 收到用户消息后、命令分发前调用。
193
+ * 仅 `$name` 开头的消息可能被展开;未知别名 / 非 `$` 消息原样返回。
194
+ */
195
+ expandAliasMessage(message: string): string;
171
196
  /**
172
197
  * Handle a CardKit card button click (§6.2).
173
198
  * Validates payload and dispatches to the corresponding command.
174
199
  */
175
200
  handleCardAction(value: CardActionPayload, ctx: CommandContext): Promise<CardActionResponse | void>;
201
+ /**
202
+ * Handle approval-related card actions.
203
+ * Routes to the appropriate bridge method based on value.cmd.
204
+ * Returns a toast response for immediate user feedback.
205
+ */
206
+ private handleApprovalAction;
176
207
  /**
177
208
  * Handle queue.cancel: remove this message from the queue.
178
209
  */
@@ -292,7 +323,7 @@ export declare class CommandRouter {
292
323
  */
293
324
  private cardLsFile;
294
325
  /** 确保 pendingConfig 已初始化(从当前 config 克隆) */
295
- private ensurePendingConfig;
326
+ ensurePendingConfig(): void;
296
327
  /**
297
328
  * 串行化 config.* 卡片回调(2026-07-04 修复 toggle 卡死 bug)。
298
329
  *
@@ -306,11 +337,14 @@ export declare class CommandRouter {
306
337
  */
307
338
  private enqueueConfigAction;
308
339
  /** 实际的 config.* 分发逻辑(在串行队列内执行) */
309
- private dispatchConfigAction;
340
+ /** config.* 卡片动作分发(public:测试直接调用,替代 as unknown as)。 */
341
+ dispatchConfigAction(value: CardActionPayload, ctx: CommandContext): Promise<CardActionResponse | void>;
310
342
  /** 设置嵌套属性值(仅修改内存对象,不写盘) */
311
- private setNestedValue;
343
+ /** 在 pendingConfig 上按 dot-separated key 设置嵌套值(config 卡片编辑用)。 */
344
+ setNestedValue(target: AppConfig, key: string, value: unknown): void;
312
345
  /** 对比原始 config 与 pendingConfig,返回变化的 key→string 映射 */
313
- private diffConfig;
346
+ /** config diff(public:测试直接调用,替代 as unknown as)。 */
347
+ diffConfig(original: AppConfig, pending: AppConfig): Record<string, string | undefined>;
314
348
  /** 递归收集差异 */
315
349
  private collectDiff;
316
350
  /**
@@ -332,7 +366,8 @@ export declare class CommandRouter {
332
366
  private propagateConfigSave;
333
367
  private executeCommand;
334
368
  cmdHelp(): CommandResult;
335
- private cmdStatus;
369
+ /** /status 实现(public:测试直接调用,替代 as any)。 */
370
+ cmdStatus(ctx: CommandContext): CommandResult;
336
371
  private cmdPs;
337
372
  private cmdStop;
338
373
  private cmdExit;
@@ -341,8 +376,7 @@ export declare class CommandRouter {
341
376
  * /update: check for newer version and upgrade if available.
342
377
  * /update check: only check, don't upgrade.
343
378
  *
344
- * Flow: check version → if newer, install → spawn replacement bridge → exit.
345
- * Reuses /restart's restartSpawner + pendingExit mechanism.
379
+ * Flow: check version → if newer, install → report success (no auto-restart).
346
380
  */
347
381
  private cmdUpdate;
348
382
  private cmdNew;
@@ -365,8 +399,29 @@ export declare class CommandRouter {
365
399
  * When the session was cleared, renders a compact notice card instead.
366
400
  */
367
401
  private buildConfigSwitchCard;
402
+ /**
403
+ * Whether a session of the given agent kind can be compacted from a resume
404
+ * card. Design doc §6.2-2: duck-typing — check if the runner has `runCompact`
405
+ * (codex app-server, kimi acp), instead of hardcoding agentKind === 'codex'.
406
+ */
407
+ private canCompactSession;
408
+ /**
409
+ * Assemble the action buttons for a resume / session-history card.
410
+ * Shared by buildAutoResumeCard, buildConfigSwitchCard, and cmdResume so the
411
+ * button set (stop / compact / new-session) follows one contract instead of
412
+ * drifting per call site.
413
+ *
414
+ * - stop: only when the session has an in-memory active run (isActive), bound
415
+ * to the real activeRun.runId so bridge.interruptCurrentRun can match.
416
+ * - compact: only when a compact-capable runner applies and the session is
417
+ * not running (a live run would occupy the runner, so compaction would
418
+ * fail). The caller passes `compact` only when canCompactSession holds.
419
+ * - new-session: when requested (always shown on resume cards).
420
+ */
421
+ private buildResumeActionButtons;
368
422
  private static readonly LS_PAGE_SIZE;
369
- private cmdLs;
423
+ /** /ls 实现(public:测试直接调用,替代 as unknown as)。 */
424
+ cmdLs(args: string[], ctx: CommandContext, offset?: number): CommandResult;
370
425
  private cmdWs;
371
426
  /**
372
427
  * L3: degraded card when a session's export is non-empty but unparseable
@@ -375,7 +430,11 @@ export declare class CommandRouter {
375
430
  * misleading "未找到". Reuses the same card-builder helpers (markdownDiv) as
376
431
  * the normal resume card; enforceCardBudget still applies at send time.
377
432
  */
378
- private cmdResume;
433
+ /**
434
+ * /resume 核心实现(public:handleResumePage / handle / resume.use 共用,
435
+ * 也是测试的直接 seam,避免测试用 @ts-expect-error 摸私有方法)。
436
+ */
437
+ cmdResume(args: string[], ctx: CommandContext, offset?: number): CommandResult;
379
438
  private cmdActive;
380
439
  /**
381
440
  * Build CardKit 2.0 /active card from bridge memory (not file system).
@@ -386,7 +445,8 @@ export declare class CommandRouter {
386
445
  private cmdReconnect;
387
446
  private cmdConfig;
388
447
  /** Build an interactive config card with CardKit 2.0 tabs + batch save */
389
- private buildConfigCard;
390
- private cmdOrder;
448
+ buildConfigCard(): CommandResult;
449
+ /** /order 实现(public:测试直接调用,替代 as unknown as)。 */
450
+ cmdOrder(args: string[], _ctx: CommandContext, offset?: number): CommandResult;
391
451
  }
392
- export { formatUsageStats } from './utils.js';
452
+ export {};