lark-remote 0.5.19 → 0.5.21

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 (136) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/bridge/approval-actions.d.ts +1 -1
  3. package/dist/bridge/approval-actions.js +1 -1
  4. package/dist/bridge/bash-run.d.ts +71 -0
  5. package/dist/bridge/bash-run.js +217 -0
  6. package/dist/bridge/compact.d.ts +155 -0
  7. package/dist/bridge/compact.js +450 -0
  8. package/dist/bridge/final-usage.js +4 -4
  9. package/dist/bridge/inbound-media.js +72 -46
  10. package/dist/bridge/index.d.ts +106 -153
  11. package/dist/bridge/index.js +400 -1000
  12. package/dist/bridge/job-watch.d.ts +68 -0
  13. package/dist/bridge/job-watch.js +146 -0
  14. package/dist/bridge/queue-manager.d.ts +3 -3
  15. package/dist/bridge/queue-manager.js +10 -29
  16. package/dist/card/approval-render.d.ts +2 -2
  17. package/dist/card/approval-render.js +141 -130
  18. package/dist/card/card-budget.js +123 -98
  19. package/dist/card/card-helpers.d.ts +3 -3
  20. package/dist/card/card-helpers.js +6 -6
  21. package/dist/card/final-answer-file.js +1 -1
  22. package/dist/card/run-renderer.d.ts +3 -3
  23. package/dist/card/run-renderer.js +114 -159
  24. package/dist/card/run-state.d.ts +1 -15
  25. package/dist/card/run-state.js +358 -292
  26. package/dist/card/tool-render.d.ts +1 -1
  27. package/dist/card/tool-render.js +21 -17
  28. package/dist/card/usage-format.d.ts +22 -7
  29. package/dist/card/usage-format.js +119 -100
  30. package/dist/cli.js +15 -3
  31. package/dist/clone.js +2 -2
  32. package/dist/common/text-width.js +36 -24
  33. package/dist/common/tool-summary.js +132 -90
  34. package/dist/config/codex-config.js +130 -106
  35. package/dist/config/index.d.ts +16 -2
  36. package/dist/config/index.js +23 -8
  37. package/dist/connector/index.js +6 -6
  38. package/dist/error-classification.js +3 -2
  39. package/dist/inbound/placeholder.d.ts +1 -1
  40. package/dist/inbound/placeholder.js +1 -1
  41. package/dist/index.js +387 -281
  42. package/dist/logger/index.js +6 -6
  43. package/dist/message-handlers.d.ts +0 -5
  44. package/dist/message-handlers.js +254 -237
  45. package/dist/model-catalog.d.ts +2 -2
  46. package/dist/model-catalog.js +3 -8
  47. package/dist/platform/identity.js +1 -1
  48. package/dist/platform/path.d.ts +1 -1
  49. package/dist/platform/path.js +1 -1
  50. package/dist/platform/sleep-blocker.js +1 -1
  51. package/dist/platform/terminator-win32.js +2 -1
  52. package/dist/router/commands/ls.d.ts +3 -0
  53. package/dist/router/commands/ls.js +256 -175
  54. package/dist/router/commands/order.js +184 -159
  55. package/dist/router/commands/resume.js +190 -152
  56. package/dist/router/commands/ws.js +219 -174
  57. package/dist/router/config/dsh.d.ts +4 -8
  58. package/dist/router/config/dsh.js +3 -10
  59. package/dist/router/config/kimi.js +1 -1
  60. package/dist/router/config/types.d.ts +1 -1
  61. package/dist/router/config-diff.js +1 -1
  62. package/dist/router/index.d.ts +56 -11
  63. package/dist/router/index.js +401 -391
  64. package/dist/runner/bash/runner.js +2 -4
  65. package/dist/runner/claude/session.d.ts +1 -1
  66. package/dist/runner/claude/session.js +6 -4
  67. package/dist/runner/codex/app-server/runner.d.ts +9 -2
  68. package/dist/runner/codex/app-server/runner.js +30 -25
  69. package/dist/runner/codex/app-server/translator.d.ts +2 -5
  70. package/dist/runner/codex/app-server/translator.js +291 -238
  71. package/dist/runner/common/acp/acp-approval.d.ts +1 -1
  72. package/dist/runner/common/acp/acp-approval.js +1 -1
  73. package/dist/runner/common/acp/base-acp-runner.d.ts +5 -2
  74. package/dist/runner/common/acp/base-acp-runner.js +26 -65
  75. package/dist/runner/common/acp/base-translator.d.ts +12 -2
  76. package/dist/runner/common/acp/base-translator.js +50 -26
  77. package/dist/runner/common/acp/protocol-types.d.ts +1 -1
  78. package/dist/runner/common/acp/protocol-types.js +2 -2
  79. package/dist/runner/common/connection-based-runner.d.ts +32 -1
  80. package/dist/runner/common/connection-based-runner.js +32 -2
  81. package/dist/runner/common/jsonl-stream.js +154 -187
  82. package/dist/runner/common/jsonrpc/client.d.ts +29 -0
  83. package/dist/runner/common/jsonrpc/client.js +43 -12
  84. package/dist/runner/common/jsonrpc/connection-manager.d.ts +2 -2
  85. package/dist/runner/common/jsonrpc/connection-manager.js +4 -4
  86. package/dist/runner/common/spawning-runner.d.ts +6 -1
  87. package/dist/runner/common/spawning-runner.js +9 -4
  88. package/dist/runner/common/turn-started.d.ts +8 -0
  89. package/dist/runner/common/turn-started.js +11 -0
  90. package/dist/runner/dsh/approval.js +84 -51
  91. package/dist/runner/dsh/catalog-probe.d.ts +17 -0
  92. package/dist/runner/dsh/catalog-probe.js +10 -0
  93. package/dist/runner/dsh/client.d.ts +7 -11
  94. package/dist/runner/dsh/client.js +356 -289
  95. package/dist/runner/dsh/exit-cancel.d.ts +2 -2
  96. package/dist/runner/dsh/exit-cancel.js +2 -2
  97. package/dist/runner/dsh/inflight.d.ts +1 -1
  98. package/dist/runner/dsh/inflight.js +1 -1
  99. package/dist/runner/dsh/mux-stream.js +28 -8
  100. package/dist/runner/dsh/runner.d.ts +44 -4
  101. package/dist/runner/dsh/runner.js +296 -199
  102. package/dist/runner/dsh/translator.d.ts +1 -31
  103. package/dist/runner/dsh/translator.js +180 -178
  104. package/dist/runner/index.d.ts +1 -1
  105. package/dist/runner/kimi/acp/runner.d.ts +1 -2
  106. package/dist/runner/kimi/acp/runner.js +82 -46
  107. package/dist/runner/kimi/acp/translator.d.ts +1 -1
  108. package/dist/runner/kimi/acp/translator.js +3 -4
  109. package/dist/runner/opencode/acp/error-monitor.js +5 -5
  110. package/dist/runner/opencode/acp/runner.d.ts +2 -2
  111. package/dist/runner/opencode/acp/runner.js +4 -4
  112. package/dist/runner/pi/rpc/client.js +4 -13
  113. package/dist/runner/pi/rpc/protocol-types.d.ts +1 -1
  114. package/dist/runner/pi/rpc/protocol-types.js +1 -1
  115. package/dist/runner/pi/rpc/runner.d.ts +3 -0
  116. package/dist/runner/pi/rpc/runner.js +27 -42
  117. package/dist/runner/pi/rpc/translator.js +61 -60
  118. package/dist/runner/types.d.ts +2 -2
  119. package/dist/runner/types.js +1 -1
  120. package/dist/session/claude/sessions.d.ts +45 -0
  121. package/dist/session/claude/sessions.js +160 -122
  122. package/dist/session/codex/rollout-reader.js +181 -182
  123. package/dist/session/common/throw-session-list-error.d.ts +10 -0
  124. package/dist/session/common/throw-session-list-error.js +16 -0
  125. package/dist/session/dsh/sessions.js +291 -235
  126. package/dist/session/kimi/sessions.d.ts +40 -8
  127. package/dist/session/kimi/sessions.js +373 -301
  128. package/dist/session/opencode/sessions.d.ts +142 -1
  129. package/dist/session/opencode/sessions.js +378 -321
  130. package/dist/session/pi/sessions.js +4 -5
  131. package/dist/session/session-store.d.ts +9 -1
  132. package/dist/session/session-store.js +99 -99
  133. package/dist/update/version-check.js +2 -1
  134. package/dist/workspace/index.d.ts +1 -1
  135. package/dist/workspace/index.js +1 -1
  136. package/package.json +1 -1
@@ -5,8 +5,8 @@
5
5
  * `dsh web` host (`DshDaemon`). So the usual "kill my spawned child" exit
6
6
  * cleanup does nothing for it, and a bridge that exits mid-turn leaves the
7
7
  * turn running with no subscriber — an orphan turn that keeps consuming tokens
8
- * and mutating the workspace invisibly (2026-10-19: one ran 2h21m / 345 steps
9
- * after its bridge died).
8
+ * and mutating the workspace invisibly, potentially for hours after the bridge
9
+ * died.
10
10
  *
11
11
  * `process.on('exit')` cannot await, so this path uses the same synchronous
12
12
  * curl transport the session reader already uses: bounded by `timeoutMs` and
@@ -5,8 +5,8 @@
5
5
  * `dsh web` host (`DshDaemon`). So the usual "kill my spawned child" exit
6
6
  * cleanup does nothing for it, and a bridge that exits mid-turn leaves the
7
7
  * turn running with no subscriber — an orphan turn that keeps consuming tokens
8
- * and mutating the workspace invisibly (2026-10-19: one ran 2h21m / 345 steps
9
- * after its bridge died).
8
+ * and mutating the workspace invisibly, potentially for hours after the bridge
9
+ * died.
10
10
  *
11
11
  * `process.on('exit')` cannot await, so this path uses the same synchronous
12
12
  * curl transport the session reader already uses: bounded by `timeoutMs` and
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A DSH turn runs inside the shared `dsh web` host, not in a child process. If
5
5
  * the bridge dies (SIGKILL, crash) the turn keeps running with no subscriber —
6
- * the 2026-10-19 incident ran 2h21m / 345 steps after its bridge exited. The
6
+ * one orphaned turn kept going for hours after its bridge exited. The
7
7
  * runner writes one entry when it submits a prompt and removes it once the run
8
8
  * (or a verified stop) accounts for that prompt; the next startup reconciles
9
9
  * anything left behind:
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A DSH turn runs inside the shared `dsh web` host, not in a child process. If
5
5
  * the bridge dies (SIGKILL, crash) the turn keeps running with no subscriber —
6
- * the 2026-10-19 incident ran 2h21m / 345 steps after its bridge exited. The
6
+ * one orphaned turn kept going for hours after its bridge exited. The
7
7
  * runner writes one entry when it submits a prompt and removes it once the run
8
8
  * (or a verified stop) accounts for that prompt; the next startup reconciles
9
9
  * anything left behind:
@@ -1,5 +1,28 @@
1
1
  import { getLogger } from '../../logger/index.js';
2
2
  import { DshError } from './errors.js';
3
+ function nonEmptyString(value) {
4
+ return typeof value === 'string' && value ? value : undefined;
5
+ }
6
+ // 模块级命名提取器:顺序即优先级,先命中先返回。抽到模块顶层后
7
+ // describeSocketError 只剩「校验 + 遍历」,决策点集中在独立的纯函数里。
8
+ function messageDetail(e) {
9
+ return nonEmptyString(e.message);
10
+ }
11
+ function errorObjectDetail(e) {
12
+ return e.error instanceof Error ? nonEmptyString(e.error.message) : undefined;
13
+ }
14
+ function errorStringDetail(e) {
15
+ return nonEmptyString(e.error);
16
+ }
17
+ function typeDetail(e) {
18
+ return nonEmptyString(e.type);
19
+ }
20
+ const SOCKET_ERROR_DETAIL_EXTRACTORS = [
21
+ messageDetail,
22
+ errorObjectDetail,
23
+ errorStringDetail,
24
+ typeDetail,
25
+ ];
3
26
  /**
4
27
  * onerror 的事件对象在 ws 实现之间形态不一({message} / {error} / {type})。
5
28
  * 尽力取出可读描述;取不到就不追加,别拿 '[object Object]' 充数。
@@ -8,14 +31,11 @@ function describeSocketError(event) {
8
31
  if (!event || typeof event !== 'object')
9
32
  return undefined;
10
33
  const e = event;
11
- if (typeof e.message === 'string' && e.message)
12
- return e.message;
13
- if (e.error instanceof Error && e.error.message)
14
- return e.error.message;
15
- if (typeof e.error === 'string' && e.error)
16
- return e.error;
17
- if (typeof e.type === 'string' && e.type)
18
- return e.type;
34
+ for (const extract of SOCKET_ERROR_DETAIL_EXTRACTORS) {
35
+ const detail = extract(e);
36
+ if (detail)
37
+ return detail;
38
+ }
19
39
  return undefined;
20
40
  }
21
41
  export async function* openMuxStream(opts) {
@@ -21,6 +21,7 @@ import type { AgentSessionReader } from '../../session-contract.js';
21
21
  import type { AgentEvent, AgentStatusInfo, BackgroundJobRoster, SpawnOptions, StopOutcome } from '../types.js';
22
22
  import type { AgentRunner } from '../types.js';
23
23
  import { DshClient, type WebSocketFactory } from './client.js';
24
+ import { DshApprovalTracker } from './approval.js';
24
25
  import type { DshDaemon } from './daemon.js';
25
26
  export interface DshRunnerOptions {
26
27
  kind: 'dsh';
@@ -110,7 +111,7 @@ export declare class DshRunner implements AgentRunner {
110
111
  /** 已对齐权限预设的 session;同一 session 只执行一次 `/permission`。 */
111
112
  private readonly permissionAlignedSessions;
112
113
  /** `$events` approval waterfall state for the current run. */
113
- private readonly approvalTracker;
114
+ readonly approvalTracker: DshApprovalTracker;
114
115
  /**
115
116
  * eventId → 待回答的 DSH `ask_user_question` waterfall。
116
117
  *
@@ -155,12 +156,51 @@ export declare class DshRunner implements AgentRunner {
155
156
  */
156
157
  private submitPrompt;
157
158
  run(message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
159
+ /**
160
+ * 准备一个 turn(run() 的准备阶段):模型对齐 + 权限预设对齐 + goal seed 探测。
161
+ *
162
+ * 红线(逐条保留):
163
+ * - 对齐失败 fail closed:显式配置 provider 时 selectModel 失败必须 throw
164
+ * (静默回退到其他 provider 会让用户以为切换成功,实际模型与账单都错);
165
+ * 权限预设失败由 alignPermissionPreset throw(用户明确选了安全策略,不能在
166
+ * 错误的权限下继续跑 prompt)。
167
+ * - 准备期间被 stop(abort)→ 返回 { ok:false },由调用方 yield interrupted
168
+ * result 收尾。
169
+ * - goal seed 只探测不推断:读不到按 unknown 上报,不冒充「没有 goal」。
170
+ */
171
+ private prepareTurn;
158
172
  /**
159
173
  * Consume one turn from both transports. `session/follow` owns transcript
160
174
  * events; `$events` owns the answerable approval waterfall. The merged
161
175
  * stream keeps either transport from starving the other.
176
+ *
177
+ * 事件源分派:projection(goal + 状态条)→ handleProjectionItem;
178
+ * $events waterfall(审批/提问)→ handleApprovalWaterfallItem;
179
+ * assistant-stream 直转发(translator 持有本 turn 的 usage 累计状态);
180
+ * session/follow 事件 → handleSessionEvent(含 result 收尾的 jobs + goal 复核)。
162
181
  */
163
182
  private runTurn;
183
+ /**
184
+ * 事件源 handler:Host-wide 投影(goal + 状态条)。
185
+ * 返回要回放的事件(可能为空——未变化/非本 session 的帧不产事件)。
186
+ */
187
+ private handleProjectionItem;
188
+ /**
189
+ * 事件源 handler:$events 审批/提问 waterfall(channel 状态、审批 waterfall
190
+ * 登记、提问卡、cancel 回流、审批卡)。
191
+ * 返回要回放的事件;channel 状态类帧(ready/unavailable/request)只改内部
192
+ * 状态、不产事件。
193
+ */
194
+ private handleApprovalWaterfallItem;
195
+ /**
196
+ * 事件源 handler:`session/follow` 会话事件。
197
+ * - goal/change:权威变更,不等投影直接更新;
198
+ * - tool/call:先记账(审批卡命令展示用)再落入 translator(卡片工具行来源);
199
+ * - approval/decided:审批回流,清审批卡;
200
+ * - 其余事件经 translator 翻译;result 事件先做收尾(后台任务名单 + goal
201
+ * 复核)再随 result 一起返回。
202
+ */
203
+ private handleSessionEvent;
164
204
  /**
165
205
  * 收尾时仍在跑的后台任务。
166
206
  *
@@ -168,7 +208,7 @@ export declare class DshRunner implements AgentRunner {
168
208
  * 现,卡片列出来只会误导"还没跑完"。`job/list` 拿不到时返回空数组——没有
169
209
  * 任务列表不等于有任务在跑。
170
210
  */
171
- private collectBackgroundJobs;
211
+ collectBackgroundJobs(sessionId: string, signal: AbortSignal): Promise<AgentEvent[]>;
172
212
  /**
173
213
  * 订阅本 session 的后台任务名单(跨 turn 生命周期)。
174
214
  *
@@ -204,7 +244,7 @@ export declare class DshRunner implements AgentRunner {
204
244
  * the Other input, multi-select submit and skip from this view alone.
205
245
  */
206
246
  private buildQuestionRequested;
207
- private approvalResolved;
247
+ approvalResolved(requestId: string): AgentEvent;
208
248
  private approvalFallbackText;
209
249
  /**
210
250
  * Compact the session through DSH's `/compact` command.
@@ -279,7 +319,7 @@ export declare class DshRunner implements AgentRunner {
279
319
  *
280
320
  * turn 跑在常驻共享的 `dsh web` host 里,不在本进程的子进程树上;所以
281
321
  * "杀自己的子进程"这套退出清理对它无效,桥接一退出,turn 继续无人接收地跑
282
- * (2026-10-19 实测:一个孤儿 turn 在桥接死后又跑了 2h21m / 345 个 step)。
322
+ * (孤儿 turn 在桥接死后可能再跑数小时)。
283
323
  * 这里复用进程级退出分发器,用同步 curl 发一次 `session/cancel`。
284
324
  */
285
325
  registerExitHandlers(): void;