lark-remote 0.5.12 → 0.5.14

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 (172) hide show
  1. package/CHANGELOG.md +28 -2
  2. package/README.en.md +1 -14
  3. package/README.md +1 -14
  4. package/dist/agent-kinds.d.ts +27 -0
  5. package/dist/agent-kinds.js +38 -0
  6. package/dist/bridge/approval-actions.d.ts +95 -0
  7. package/dist/bridge/approval-actions.js +104 -0
  8. package/dist/bridge/approval-coordinator.d.ts +1 -0
  9. package/dist/bridge/approval-coordinator.js +12 -24
  10. package/dist/bridge/final-usage.d.ts +8 -17
  11. package/dist/bridge/final-usage.js +1 -18
  12. package/dist/bridge/index.d.ts +52 -38
  13. package/dist/bridge/index.js +255 -433
  14. package/dist/bridge/queue-manager.d.ts +25 -1
  15. package/dist/bridge/queue-manager.js +179 -160
  16. package/dist/bridge/run-approval.d.ts +16 -0
  17. package/dist/bridge/run-approval.js +41 -0
  18. package/dist/bridge/run-usage.d.ts +32 -0
  19. package/dist/bridge/run-usage.js +87 -0
  20. package/dist/bridge/session-writeback.d.ts +19 -0
  21. package/dist/bridge/session-writeback.js +36 -0
  22. package/dist/card/approval-render.d.ts +3 -2
  23. package/dist/card/approval-render.js +3 -2
  24. package/dist/card/bash-card-session.js +2 -5
  25. package/dist/{router → card}/card-helpers.d.ts +7 -7
  26. package/dist/{router → card}/card-helpers.js +8 -8
  27. package/dist/card/card-session.d.ts +6 -2
  28. package/dist/card/card-session.js +28 -28
  29. package/dist/card/card-shared.d.ts +4 -4
  30. package/dist/card/card-shared.js +4 -10
  31. package/dist/card/collapsible.js +3 -2
  32. package/dist/card/final-answer-overflow.d.ts +1 -0
  33. package/dist/card/final-answer-overflow.js +46 -0
  34. package/dist/card/run-card-session.d.ts +2 -2
  35. package/dist/card/run-card-session.js +4 -9
  36. package/dist/card/run-renderer.d.ts +14 -0
  37. package/dist/card/run-renderer.js +126 -23
  38. package/dist/card/run-state.d.ts +40 -51
  39. package/dist/card/run-state.js +96 -34
  40. package/dist/card/usage-format.d.ts +30 -0
  41. package/dist/{router → card}/usage-format.js +3 -10
  42. package/dist/clone.js +6 -1
  43. package/dist/config/codex-config.js +4 -4
  44. package/dist/config/index.d.ts +18 -20
  45. package/dist/config/index.js +6 -20
  46. package/dist/config/pi-config.js +6 -4
  47. package/dist/connector/index.d.ts +2 -4
  48. package/dist/connector/index.js +7 -11
  49. package/dist/{runner/dsh → dsh}/auth.js +3 -4
  50. package/dist/dsh/home.d.ts +2 -0
  51. package/dist/dsh/home.js +8 -0
  52. package/dist/dsh/protocol.d.ts +9 -0
  53. package/dist/dsh/protocol.js +61 -0
  54. package/dist/inbound/turn-assembler.js +6 -0
  55. package/dist/index.js +25 -414
  56. package/dist/message-handlers.d.ts +26 -0
  57. package/dist/message-handlers.js +275 -0
  58. package/dist/model-catalog.d.ts +14 -0
  59. package/dist/model-catalog.js +25 -0
  60. package/dist/platform/path.d.ts +9 -0
  61. package/dist/platform/path.js +18 -0
  62. package/dist/router/active-run-usage.d.ts +4 -0
  63. package/dist/router/active-run-usage.js +12 -0
  64. package/dist/router/card-action-payload.d.ts +1 -1
  65. package/dist/router/card-action-payload.js +1 -1
  66. package/dist/router/commands/ls.d.ts +9 -0
  67. package/dist/router/commands/ls.js +243 -0
  68. package/dist/router/commands/order.d.ts +12 -0
  69. package/dist/router/commands/order.js +178 -0
  70. package/dist/router/commands/resume.d.ts +48 -0
  71. package/dist/router/commands/resume.js +246 -0
  72. package/dist/router/commands/ws.d.ts +15 -0
  73. package/dist/router/commands/ws.js +189 -0
  74. package/dist/router/config/claude.js +5 -4
  75. package/dist/router/config/codex.js +2 -6
  76. package/dist/router/config/common/render.d.ts +5 -1
  77. package/dist/router/config/common/render.js +6 -13
  78. package/dist/router/config/common/turn-idle.d.ts +2 -0
  79. package/dist/router/config/common/turn-idle.js +9 -0
  80. package/dist/router/config/dsh.d.ts +1 -1
  81. package/dist/router/config/index.d.ts +1 -1
  82. package/dist/router/config/kimi.js +2 -6
  83. package/dist/router/config/opencode.js +2 -6
  84. package/dist/router/config/types.d.ts +11 -3
  85. package/dist/router/index.d.ts +55 -33
  86. package/dist/router/index.js +233 -1376
  87. package/dist/router/paging.d.ts +13 -0
  88. package/dist/router/paging.js +20 -0
  89. package/dist/router/path-validation.d.ts +27 -0
  90. package/dist/router/path-validation.js +45 -0
  91. package/dist/runner/agent-choices-common.d.ts +1 -1
  92. package/dist/runner/claude/runner.d.ts +23 -6
  93. package/dist/runner/claude/runner.js +6 -20
  94. package/dist/runner/claude/session.js +1 -1
  95. package/dist/runner/codex/app-server/runner.d.ts +3 -1
  96. package/dist/runner/codex/app-server/translator.d.ts +13 -0
  97. package/dist/runner/codex/app-server/translator.js +114 -151
  98. package/dist/runner/common/acp/base-acp-runner.d.ts +3 -1
  99. package/dist/runner/common/acp/base-translator.d.ts +3 -8
  100. package/dist/runner/common/acp/base-translator.js +16 -7
  101. package/dist/runner/common/connection-based-runner.d.ts +3 -1
  102. package/dist/runner/common/jsonrpc/transport.js +17 -7
  103. package/dist/runner/common/spawning-runner.js +10 -4
  104. package/dist/runner/common/turn-started.d.ts +2 -0
  105. package/dist/runner/common/turn-started.js +10 -0
  106. package/dist/runner/dsh/client.d.ts +2 -10
  107. package/dist/runner/dsh/client.js +13 -220
  108. package/dist/runner/dsh/daemon.d.ts +0 -2
  109. package/dist/runner/dsh/daemon.js +9 -7
  110. package/dist/runner/dsh/errors.d.ts +5 -0
  111. package/dist/runner/dsh/errors.js +11 -0
  112. package/dist/runner/dsh/exit-cancel.d.ts +0 -2
  113. package/dist/runner/dsh/exit-cancel.js +2 -2
  114. package/dist/runner/dsh/inflight.d.ts +0 -2
  115. package/dist/runner/dsh/inflight.js +1 -1
  116. package/dist/runner/dsh/mux-stream.d.ts +26 -0
  117. package/dist/runner/dsh/mux-stream.js +176 -0
  118. package/dist/runner/dsh/runner.d.ts +21 -1
  119. package/dist/runner/dsh/runner.js +76 -73
  120. package/dist/runner/dsh/translator.d.ts +1 -11
  121. package/dist/runner/dsh/translator.js +1 -1
  122. package/dist/runner/index.d.ts +1 -1
  123. package/dist/runner/kimi/acp/runner.d.ts +22 -1
  124. package/dist/runner/kimi/acp/runner.js +83 -60
  125. package/dist/runner/kimi/acp/translator.js +1 -12
  126. package/dist/runner/opencode/acp/error-monitor.d.ts +11 -0
  127. package/dist/runner/opencode/acp/error-monitor.js +31 -2
  128. package/dist/runner/opencode/acp/runner.d.ts +3 -1
  129. package/dist/runner/opencode/acp/translator.js +1 -12
  130. package/dist/runner/pi/rpc/runner.d.ts +2 -1
  131. package/dist/runner/pi/rpc/translator.d.ts +2 -8
  132. package/dist/runner/pi/rpc/translator.js +2 -7
  133. package/dist/runner/probe.d.ts +1 -1
  134. package/dist/runner/probe.js +10 -9
  135. package/dist/runner/registry.d.ts +2 -20
  136. package/dist/runner/registry.js +0 -32
  137. package/dist/runner/types.d.ts +37 -155
  138. package/dist/runner/types.js +4 -24
  139. package/dist/session/claude/session-index.d.ts +11 -4
  140. package/dist/session/claude/session-index.js +34 -10
  141. package/dist/session/claude/session-reader.d.ts +1 -1
  142. package/dist/session/claude/sessions.d.ts +2 -2
  143. package/dist/session/claude/sessions.js +41 -26
  144. package/dist/session/codex/rollout-reader.d.ts +1 -1
  145. package/dist/session/codex/rollout-reader.js +14 -13
  146. package/dist/session/codex/sessions.d.ts +1 -1
  147. package/dist/session/codex/sessions.js +4 -2
  148. package/dist/session/common/jsonl.js +7 -1
  149. package/dist/session/common/pagination.d.ts +2 -0
  150. package/dist/session/common/pagination.js +1 -1
  151. package/dist/session/common/recency.d.ts +6 -0
  152. package/dist/session/common/recency.js +7 -5
  153. package/dist/session/common/two-pass.d.ts +1 -1
  154. package/dist/session/common/usage-accumulator.d.ts +1 -1
  155. package/dist/session/dsh/sessions.d.ts +1 -1
  156. package/dist/session/dsh/sessions.js +37 -12
  157. package/dist/session/kimi/sessions.d.ts +1 -1
  158. package/dist/session/kimi/sessions.js +37 -10
  159. package/dist/session/opencode/sessions.d.ts +1 -1
  160. package/dist/session/opencode/sessions.js +53 -48
  161. package/dist/session/pi/sessions.d.ts +1 -1
  162. package/dist/session/pi/sessions.js +23 -9
  163. package/dist/session/registry.d.ts +2 -1
  164. package/dist/session/session-store.d.ts +1 -2
  165. package/dist/session/session-store.js +14 -7
  166. package/dist/session-contract.d.ts +178 -0
  167. package/dist/session-contract.js +9 -0
  168. package/package.json +1 -1
  169. package/dist/router/usage-format.d.ts +0 -60
  170. /package/dist/{runner/dsh → dsh}/auth.d.ts +0 -0
  171. /package/dist/{runner/dsh → dsh}/types.d.ts +0 -0
  172. /package/dist/{runner/dsh → dsh}/types.js +0 -0
@@ -0,0 +1,13 @@
1
+ export declare function pageInfo(totalCount: number, offset: number, pageSize: number): {
2
+ totalPages: number;
3
+ safeOffset: number;
4
+ currentPage: number;
5
+ };
6
+ export declare function pageSlice<T>(items: readonly T[], offset: number, pageSize: number): {
7
+ totalCount: number;
8
+ totalPages: number;
9
+ safeOffset: number;
10
+ currentPage: number;
11
+ pageItems: T[];
12
+ hasPagination: boolean;
13
+ };
@@ -0,0 +1,20 @@
1
+ import { clampInt } from '../common/clamp.js';
2
+ export function pageInfo(totalCount, offset, pageSize) {
3
+ const totalPages = Math.max(1, Math.ceil(totalCount / pageSize));
4
+ const maxOffset = Math.max(0, (totalPages - 1) * pageSize);
5
+ const safeOffset = clampInt(offset, 0, maxOffset);
6
+ const currentPage = Math.floor(safeOffset / pageSize) + 1;
7
+ return { totalPages, safeOffset, currentPage };
8
+ }
9
+ export function pageSlice(items, offset, pageSize) {
10
+ const { totalPages, safeOffset, currentPage } = pageInfo(items.length, offset, pageSize);
11
+ return {
12
+ totalCount: items.length,
13
+ totalPages,
14
+ safeOffset,
15
+ currentPage,
16
+ pageItems: items.slice(safeOffset, safeOffset + pageSize),
17
+ hasPagination: items.length > pageSize,
18
+ };
19
+ }
20
+ //# sourceMappingURL=paging.js.map
@@ -0,0 +1,27 @@
1
+ import fs from 'node:fs';
2
+ export type PathKind = 'directory' | 'file' | 'missing' | 'unreadable';
3
+ export type StatResolution = {
4
+ ok: true;
5
+ stat: fs.Stats;
6
+ } | {
7
+ ok: false;
8
+ reason: 'missing' | 'unreadable';
9
+ };
10
+ export type DirectoryResolution = {
11
+ ok: true;
12
+ canonical: string;
13
+ } | {
14
+ ok: false;
15
+ reason: 'missing' | 'not_directory' | 'unreadable';
16
+ };
17
+ /**
18
+ * Inspect a path without a preceding existsSync call.
19
+ *
20
+ * stat already distinguishes missing paths from files/directories and closes
21
+ * the exists→stat race. Permission and other IO failures stay distinguishable
22
+ * from a normal missing path so callers can keep their user-facing messages.
23
+ */
24
+ export declare function statPath(target: string): StatResolution;
25
+ export declare function inspectPath(target: string): PathKind;
26
+ export declare function resolveDirectory(target: string): DirectoryResolution;
27
+ export declare function isDirectorySafe(target: string): boolean;
@@ -0,0 +1,45 @@
1
+ import fs from 'node:fs';
2
+ /**
3
+ * Inspect a path without a preceding existsSync call.
4
+ *
5
+ * stat already distinguishes missing paths from files/directories and closes
6
+ * the exists→stat race. Permission and other IO failures stay distinguishable
7
+ * from a normal missing path so callers can keep their user-facing messages.
8
+ */
9
+ export function statPath(target) {
10
+ try {
11
+ return { ok: true, stat: fs.statSync(target) };
12
+ }
13
+ catch (err) {
14
+ const code = err.code;
15
+ return {
16
+ ok: false,
17
+ reason: code === 'ENOENT' || code === 'ENOTDIR' ? 'missing' : 'unreadable',
18
+ };
19
+ }
20
+ }
21
+ export function inspectPath(target) {
22
+ const resolution = statPath(target);
23
+ if (!resolution.ok)
24
+ return resolution.reason;
25
+ return resolution.stat.isDirectory() ? 'directory' : 'file';
26
+ }
27
+ export function resolveDirectory(target) {
28
+ const kind = inspectPath(target);
29
+ if (kind === 'missing')
30
+ return { ok: false, reason: 'missing' };
31
+ if (kind === 'unreadable')
32
+ return { ok: false, reason: 'unreadable' };
33
+ if (kind === 'file')
34
+ return { ok: false, reason: 'not_directory' };
35
+ try {
36
+ return { ok: true, canonical: fs.realpathSync(target) };
37
+ }
38
+ catch {
39
+ return { ok: false, reason: 'unreadable' };
40
+ }
41
+ }
42
+ export function isDirectorySafe(target) {
43
+ return inspectPath(target) === 'directory';
44
+ }
45
+ //# sourceMappingURL=path-validation.js.map
@@ -1,4 +1,4 @@
1
- import type { AgentKind } from './types.js';
1
+ import type { AgentKind } from '../agent-kinds.js';
2
2
  /** 一对需要同步的字段:agents.<agent> 上的配置键 ↔ agentChoices.<agent> 上的选择键。 */
3
3
  export interface ChoiceField {
4
4
  configKey: string;
@@ -1,12 +1,24 @@
1
- import { type AgentEvent, type SpawnOptions, type AgentSessionReader, type AgentRunner, type AgentStatusInfo } from '../types.js';
1
+ /**
2
+ * Claude Runner 实现
3
+ *
4
+ * ClaudeRunner 从「一次一跑」(claude -p <msg> --permission-mode
5
+ * bypassPermissions)升级为长驻交互会话(--input-format stream-json 双向
6
+ * 通道),同时复用本项目已有的 ApprovalCoordinator + run 卡审批区。
7
+ *
8
+ * 架构:ClaudeRunner 是 workspace-lifetime 的薄包装,进程与协议细节在
9
+ * ClaudeSession(src/runner/claude/session.ts,extends SpawningRunner 复用
10
+ * pid 文件/killOrphan/Terminator/心跳/退出分发器机制)。每次 run() 委托
11
+ * session:确保进程(可 --resume)→ 写 user 消息 → 消费事件直到本 turn result。
12
+ */
13
+ import type { AgentSessionReader } from '../../session-contract.js';
14
+ import { type AgentEvent, type SpawnOptions, type AgentRunner, type AgentStatusInfo } from '../types.js';
2
15
  /**
3
16
  * Claude Agent Runner(长驻交互模式)。
4
17
  *
5
18
  * 权限模式(permissionMode)在 spawn 时经 --permission-mode 生效:
6
- * - 默认 bypassPermissions:claude 内部自动放行,无 control_request → 行为与
7
- * 旧版完全一致(无审批卡);
8
- * - 配置为 default/acceptEdits/manual/plan 等:工具调用经 control_request
9
- * 上抛 → bridge ApprovalCoordinator → run 卡审批区。
19
+ * - 默认 auto:低风险操作自动放行,高风险操作的 control_request 上抛 →
20
+ * bridge ApprovalCoordinator → run 卡审批区;
21
+ * - bypassPermissions:claude 内部全部放行,无 control_request(无审批卡)。
10
22
  */
11
23
  export declare class ClaudeRunner implements AgentRunner {
12
24
  readonly kind: "claude";
@@ -24,7 +36,12 @@ export declare class ClaudeRunner implements AgentRunner {
24
36
  pidDir?: string;
25
37
  cwd: string;
26
38
  spawnHeartbeatMs?: number;
27
- sessionReader?: AgentSessionReader;
39
+ /**
40
+ * 由组合根(`src/index.ts`)注入,与 sessionReaderRegistry 里的**同一个**实例。
41
+ * claude 不在此处自己 new:那会让 runner 反向依赖 session 层(runner ↔ session
42
+ * 循环的一半);其余 agent 从一开始就是注入的。
43
+ */
44
+ sessionReader: AgentSessionReader;
28
45
  /** Claude 权限模式(官方 --permission-mode 枚举;'default'=省略参数)。 */
29
46
  permissionMode?: string;
30
47
  /** 会话级空闲回收 TTL(ms);0=禁用。 */
@@ -1,18 +1,5 @@
1
- /**
2
- * Claude Runner 实现
3
- *
4
- * ClaudeRunner 从「一次一跑」(claude -p <msg> --permission-mode
5
- * bypassPermissions)升级为长驻交互会话(--input-format stream-json 双向
6
- * 通道),同时复用本项目已有的 ApprovalCoordinator + run 卡审批区。
7
- *
8
- * 架构:ClaudeRunner 是 workspace-lifetime 的薄包装,进程与协议细节在
9
- * ClaudeSession(src/runner/claude/session.ts,extends SpawningRunner 复用
10
- * pid 文件/killOrphan/Terminator/心跳/退出分发器机制)。每次 run() 委托
11
- * session:确保进程(可 --resume)→ 写 user 消息 → 消费事件直到本 turn result。
12
- */
13
- import { ClaudeSessionReader } from '../../session/claude/index.js';
14
1
  import { ClaudeSession } from './session.js';
15
- import { MODEL_ID_TO_ALIAS } from '../../config/index.js';
2
+ import { MODEL_ID_TO_ALIAS } from '../../model-catalog.js';
16
3
  /**
17
4
  * Claude 内建压缩命令。stream-json 输入模式下该文本会被 CLI 本地拦截为
18
5
  * slash 命令(不会作为模型提示词转发),压缩 turn 以普通 result 收尾
@@ -24,10 +11,9 @@ const COMPACT_COMMAND = '/compact';
24
11
  * Claude Agent Runner(长驻交互模式)。
25
12
  *
26
13
  * 权限模式(permissionMode)在 spawn 时经 --permission-mode 生效:
27
- * - 默认 bypassPermissions:claude 内部自动放行,无 control_request → 行为与
28
- * 旧版完全一致(无审批卡);
29
- * - 配置为 default/acceptEdits/manual/plan 等:工具调用经 control_request
30
- * 上抛 → bridge ApprovalCoordinator → run 卡审批区。
14
+ * - 默认 auto:低风险操作自动放行,高风险操作的 control_request 上抛 →
15
+ * bridge ApprovalCoordinator → run 卡审批区;
16
+ * - bypassPermissions:claude 内部全部放行,无 control_request(无审批卡)。
31
17
  */
32
18
  export class ClaudeRunner {
33
19
  kind = 'claude';
@@ -40,8 +26,8 @@ export class ClaudeRunner {
40
26
  constructor(opts) {
41
27
  this.defaultModel = opts.model ?? 'claude-opus-4-8';
42
28
  this.defaultEffort = opts.effort ?? 'medium';
43
- this.permissionMode = opts.permissionMode ?? 'bypassPermissions';
44
- this.sessionReader = opts.sessionReader ?? new ClaudeSessionReader();
29
+ this.permissionMode = opts.permissionMode ?? 'auto';
30
+ this.sessionReader = opts.sessionReader;
45
31
  this.session = new ClaudeSession({
46
32
  pidDir: opts.pidDir,
47
33
  cwd: opts.cwd,
@@ -100,7 +100,7 @@ export class ClaudeSession extends SpawningRunner {
100
100
  agent: 'claude',
101
101
  });
102
102
  this.binary = 'claude';
103
- this.permissionMode = opts.permissionMode ?? 'bypassPermissions';
103
+ this.permissionMode = opts.permissionMode ?? 'auto';
104
104
  this.settings = opts.settings;
105
105
  this.defaultEffort = opts.effort;
106
106
  this.idleTtlMs = opts.idleTtlMs ?? DEFAULT_IDLE_TTL_MS;
@@ -10,7 +10,9 @@
10
10
  * queue + waitResolve pump, forceFinish/stopRequested semantics, turn idle
11
11
  * watchdog, and ConnectionLostError respawn-and-retry-once.
12
12
  */
13
- import type { AgentKind, AgentSessionReader, AgentEvent, AgentStatusInfo, SpawnOptions } from '../../types.js';
13
+ import type { AgentKind } from '../../../agent-kinds.js';
14
+ import type { AgentSessionReader } from '../../../session-contract.js';
15
+ import type { AgentEvent, AgentStatusInfo, SpawnOptions } from '../../types.js';
14
16
  import { JsonRpcClient } from '../../common/jsonrpc/client.js';
15
17
  import { type TranslatorEvent } from './translator.js';
16
18
  import { type AskForApproval, type SandboxMode, type InitializeResult } from './protocol-types.js';
@@ -17,6 +17,8 @@ export declare class CodexAppServerTranslator {
17
17
  private turnStatus;
18
18
  /** Full agentMessage text per item id (item-scoped snapshot). */
19
19
  private textByItem;
20
+ /** agentMessage item ids whose protocol phase is `final_answer`. */
21
+ private finalTextItems;
20
22
  /**
21
23
  * Reasoning content per item id: paragraphs keyed by `contentIndex`
22
24
  * (textDelta) plus the summary stream (summaryTextDelta). Each reasoning
@@ -103,6 +105,17 @@ export declare class CodexAppServerTranslator {
103
105
  private handleCommandApproval;
104
106
  private handleFileApproval;
105
107
  private handleItemStarted;
108
+ /**
109
+ * turn_diff 的统一信封:`type` + threadId/turnId/timestamp 三个公共字段在此
110
+ * 一次装配(十余个构造点原本各抄一遍,还得挂 `as TurnDiffEvent`)。
111
+ */
112
+ private turnDiffEvent;
113
+ /**
114
+ * 工具型 item 的 started 处理(commandExecution / webSearch / mcpToolCall /
115
+ * dynamicToolCall 四个分支同形):登记「已开始」锚点 + 记录工具身份 meta,
116
+ * 再发一帧空的 turn_diff 把工具块按真实时序插进卡片。
117
+ */
118
+ private beginToolItem;
106
119
  private handlePermissionsApproval;
107
120
  private buildPermissionItems;
108
121
  /** Get (or lazily create) the reasoning accumulator for one item. */