lark-remote 0.5.18 → 0.5.20

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 (123) hide show
  1. package/CHANGELOG.md +32 -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 +1 -1
  10. package/dist/bridge/index.d.ts +120 -119
  11. package/dist/bridge/index.js +257 -695
  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 +109 -97
  18. package/dist/card/bash-card-session.js +2 -0
  19. package/dist/card/card-budget.js +1 -1
  20. package/dist/card/card-helpers.d.ts +3 -3
  21. package/dist/card/card-helpers.js +6 -6
  22. package/dist/card/card-session.d.ts +17 -0
  23. package/dist/card/card-session.js +35 -0
  24. package/dist/card/final-answer-file.js +1 -1
  25. package/dist/card/run-card-session.js +2 -0
  26. package/dist/card/run-renderer.d.ts +3 -3
  27. package/dist/card/run-renderer.js +77 -102
  28. package/dist/card/run-state.d.ts +35 -8
  29. package/dist/card/run-state.js +117 -90
  30. package/dist/card/tool-render.d.ts +1 -1
  31. package/dist/card/tool-render.js +1 -1
  32. package/dist/card/usage-format.d.ts +12 -0
  33. package/dist/card/usage-format.js +8 -3
  34. package/dist/cli.js +15 -3
  35. package/dist/clone.js +2 -2
  36. package/dist/config/codex-config.js +130 -106
  37. package/dist/config/index.d.ts +16 -2
  38. package/dist/config/index.js +23 -8
  39. package/dist/connector/index.js +6 -6
  40. package/dist/error-classification.js +3 -2
  41. package/dist/inbound/placeholder.d.ts +1 -1
  42. package/dist/inbound/placeholder.js +1 -1
  43. package/dist/index.js +203 -133
  44. package/dist/logger/index.js +6 -6
  45. package/dist/message-handlers.d.ts +0 -5
  46. package/dist/message-handlers.js +4 -2
  47. package/dist/model-catalog.d.ts +2 -2
  48. package/dist/model-catalog.js +3 -8
  49. package/dist/platform/identity.js +1 -1
  50. package/dist/platform/path.d.ts +1 -1
  51. package/dist/platform/path.js +1 -1
  52. package/dist/platform/sleep-blocker.js +1 -1
  53. package/dist/platform/terminator-win32.js +2 -1
  54. package/dist/router/commands/resume.js +2 -20
  55. package/dist/router/config/dsh.d.ts +4 -8
  56. package/dist/router/config/dsh.js +3 -10
  57. package/dist/router/config/kimi.js +1 -1
  58. package/dist/router/config/types.d.ts +1 -1
  59. package/dist/router/config-diff.js +1 -1
  60. package/dist/router/index.d.ts +56 -11
  61. package/dist/router/index.js +222 -202
  62. package/dist/runner/claude/session.d.ts +1 -1
  63. package/dist/runner/claude/session.js +6 -4
  64. package/dist/runner/codex/app-server/runner.d.ts +9 -2
  65. package/dist/runner/codex/app-server/runner.js +30 -25
  66. package/dist/runner/codex/app-server/translator.d.ts +0 -5
  67. package/dist/runner/codex/app-server/translator.js +4 -17
  68. package/dist/runner/common/acp/acp-approval.d.ts +1 -1
  69. package/dist/runner/common/acp/acp-approval.js +1 -1
  70. package/dist/runner/common/acp/base-acp-runner.d.ts +5 -2
  71. package/dist/runner/common/acp/base-acp-runner.js +26 -65
  72. package/dist/runner/common/acp/base-translator.d.ts +12 -2
  73. package/dist/runner/common/acp/base-translator.js +31 -9
  74. package/dist/runner/common/acp/protocol-types.d.ts +1 -1
  75. package/dist/runner/common/acp/protocol-types.js +2 -2
  76. package/dist/runner/common/connection-based-runner.d.ts +32 -1
  77. package/dist/runner/common/connection-based-runner.js +32 -2
  78. package/dist/runner/common/jsonrpc/connection-manager.d.ts +2 -2
  79. package/dist/runner/common/jsonrpc/connection-manager.js +4 -4
  80. package/dist/runner/common/spawning-runner.d.ts +1 -1
  81. package/dist/runner/common/spawning-runner.js +1 -1
  82. package/dist/runner/dsh/catalog-probe.d.ts +17 -0
  83. package/dist/runner/dsh/catalog-probe.js +10 -0
  84. package/dist/runner/dsh/client.d.ts +13 -8
  85. package/dist/runner/dsh/client.js +23 -15
  86. package/dist/runner/dsh/exit-cancel.d.ts +2 -2
  87. package/dist/runner/dsh/exit-cancel.js +2 -2
  88. package/dist/runner/dsh/inflight.d.ts +1 -1
  89. package/dist/runner/dsh/inflight.js +1 -1
  90. package/dist/runner/dsh/runner.d.ts +48 -2
  91. package/dist/runner/dsh/runner.js +288 -199
  92. package/dist/runner/dsh/translator.d.ts +1 -1
  93. package/dist/runner/dsh/translator.js +1 -1
  94. package/dist/runner/index.d.ts +1 -1
  95. package/dist/runner/kimi/acp/runner.d.ts +1 -2
  96. package/dist/runner/kimi/acp/runner.js +1 -2
  97. package/dist/runner/kimi/acp/translator.d.ts +1 -1
  98. package/dist/runner/kimi/acp/translator.js +3 -4
  99. package/dist/runner/opencode/acp/runner.d.ts +2 -2
  100. package/dist/runner/opencode/acp/runner.js +4 -4
  101. package/dist/runner/pi/rpc/protocol-types.d.ts +1 -1
  102. package/dist/runner/pi/rpc/protocol-types.js +1 -1
  103. package/dist/runner/pi/rpc/runner.d.ts +3 -0
  104. package/dist/runner/pi/rpc/runner.js +27 -42
  105. package/dist/runner/types.d.ts +25 -8
  106. package/dist/runner/types.js +1 -1
  107. package/dist/session/claude/sessions.d.ts +45 -0
  108. package/dist/session/claude/sessions.js +97 -71
  109. package/dist/session/codex/rollout-reader.js +4 -4
  110. package/dist/session/common/throw-session-list-error.d.ts +10 -0
  111. package/dist/session/common/throw-session-list-error.js +16 -0
  112. package/dist/session/dsh/sessions.js +11 -5
  113. package/dist/session/kimi/sessions.d.ts +40 -1
  114. package/dist/session/kimi/sessions.js +244 -192
  115. package/dist/session/opencode/sessions.d.ts +153 -1
  116. package/dist/session/opencode/sessions.js +354 -321
  117. package/dist/session/pi/sessions.js +4 -5
  118. package/dist/session/session-store.d.ts +1 -1
  119. package/dist/session/session-store.js +1 -1
  120. package/dist/update/version-check.js +2 -1
  121. package/dist/workspace/index.d.ts +1 -1
  122. package/dist/workspace/index.js +1 -1
  123. package/package.json +1 -1
@@ -1,11 +1,12 @@
1
- import type { AgentRunner } from '../runner/index.js';
1
+ import type { Runner, AgentRunner } from '../runner/index.js';
2
2
  import type { AgentRegistry } from '../runner/registry.js';
3
3
  import type { SessionReaderRegistry, SessionStore } from '../session/index.js';
4
4
  import type { AppConfig } from '../config/index.js';
5
- import { type RunCardChannel } from '../card/run-card-session.js';
6
- import { type RunTerminal } from '../card/run-state.js';
5
+ import { RunCardSession, type RunCardChannel } from '../card/run-card-session.js';
6
+ import { type RunCardRenderOptions } from '../card/run-renderer.js';
7
+ import { type RunState, type RunTerminal } from '../card/run-state.js';
7
8
  import type { AgentKind } from '../agent-kinds.js';
8
- import { type StopOutcome } from '../runner/types.js';
9
+ import type { StopOutcome } from '../runner/types.js';
9
10
  import { QueueManager, type QueuedTask, type EnqueueOptions, type AgentBinding, type ExecutingInfo } from './queue-manager.js';
10
11
  import type { InboundMediaPayload } from '../connector/index.js';
11
12
  import type { MediaOutcome } from '../inbound/turn.js';
@@ -29,6 +30,23 @@ export interface BridgeChannel extends RunCardChannel {
29
30
  addReaction(messageId: string, emoji: string): Promise<void>;
30
31
  removeReactionByEmoji(messageId: string, emoji: string): Promise<void>;
31
32
  }
33
+ /**
34
+ * 终态卡的渲染快照:run 结束后唯一还能改这张卡的地方。
35
+ *
36
+ * 后台任务的生命周期跨 turn,卡片收尾只是"这一轮的投影结束了",任务本身还在
37
+ * 跑;订阅拿到新名单后必须按 runId 找回同一张卡(state + 渲染选项 + 消息 id)。
38
+ */
39
+ export interface RunCardSnapshot {
40
+ state: RunState;
41
+ options: RunCardRenderOptions;
42
+ cwd: string;
43
+ agentKind: AgentKind;
44
+ /**
45
+ * 这张终态卡的消息 id。缺失(流式卡没建起来、走了兜底纯发送)时后台任务
46
+ * 订阅无法落地——宁可退化成收尾快照,也不能凭空补发一张新卡。
47
+ */
48
+ messageId?: string;
49
+ }
32
50
  /** Caller context shared by bridge operations and router command handling. */
33
51
  export interface CommandContext {
34
52
  userId: string;
@@ -95,6 +113,42 @@ interface BridgeDeps {
95
113
  */
96
114
  sessionReaderRegistry: SessionReaderRegistry;
97
115
  }
116
+ export interface ActiveRun {
117
+ runId: string;
118
+ userId: string;
119
+ chatId: string;
120
+ session: RunCardSession;
121
+ cwd: string;
122
+ /**
123
+ * The exact runner instance that is running this run. interruptCurrentRun
124
+ * stops THIS instance directly rather than re-resolving via getRunner(cwd),
125
+ * so the runner is reachable even after clearRunners() empties the cache
126
+ * mid-run (a fresh empty runner's stop() was a no-op,
127
+ * leaving the real subprocess alive and the queue chain blocked forever).
128
+ */
129
+ runner: Runner;
130
+ /**
131
+ * The agent kind that this run started with. The runner cache is keyed by
132
+ * (cwd, agentKind); eviction must use THIS kind, not `this.config.defaultAgent`
133
+ * at eviction time. Otherwise switching defaultAgent mid-run
134
+ * (via `/config`, whose clearRunners skips the active cwd) makes finalizeRun
135
+ * delete the wrong slot — the original agent's runner lingers in the cache
136
+ * with a stale config snapshot.
137
+ */
138
+ agentKind: AgentKind;
139
+ /**
140
+ * Session id this run actually used (from system.init / turn_started).
141
+ * Immutable run identity for final usage: a mid-run /new //resume //cd moves
142
+ * the global session pointer, so reading `sessionStore.getSessionId()` at the
143
+ * end attributes another session's tokens to this run.
144
+ */
145
+ sessionId?: string;
146
+ }
147
+ /** `startIdleWatchdog` 的句柄:事件到达时 `touch()`,流结束/收尾时 `stop()`。 */
148
+ export interface IdleWatchdog {
149
+ touch(): void;
150
+ stop(): void;
151
+ }
98
152
  /**
99
153
  * Bridge owns the per-workspace serial processing queue (§9.6) and the
100
154
  * single-card streaming forwarding loop (§9.12 watchdog + session sync).
@@ -129,7 +183,7 @@ export declare class Bridge {
129
183
  private readonly mediaHandler;
130
184
  /**
131
185
  * Per-workspace runner instances, keyed by (cwd, agentKind).
132
- * Fix 4 (2026-07-18): Each agentKind has its own cache slot, so switching
186
+ * Each agentKind has its own cache slot, so switching
133
187
  * defaultAgent creates a NEW runner without evicting the old one. This
134
188
  * eliminates the need for clearRunners() on agent switch, preventing the
135
189
  * regression where clearRunners() orphaned a running subprocess and
@@ -153,16 +207,11 @@ export declare class Bridge {
153
207
  /** 审批卡动作的实现(只读上面那张表;见 approval-actions.ts)。 */
154
208
  private approvalActions;
155
209
  /**
156
- * 最近若干次已完成的、runner 有 runCompact 的 run(cwd → runId → 记录)。
157
- * run 结束后 activeRuns 已清空,而终态卡上的 Compact 按钮只带 runId,
158
- * 需要它反查 sessionId + agentKind。
159
- *
160
- * 为什么按 runId 存而不是「每 cwd 只留最新一条」:compact 卡片动作走串行
161
- * 队列(会被正在跑的 run 挡住),点击到执行之间可能夹着别的 run 收尾。
162
- * 单槽会被覆盖 —— 旧卡片的压缩必然报「该任务已结束或不属于当前会话」,
163
- * 与 session 是否还在、能否压缩无关(2026-10-08 线上缺陷)。
210
+ * Compact 生命周期(见 compact.ts):可压缩 run 记账、终态卡 / resume 卡
211
+ * 两条 Compact 入口、kimi 在途检测与压缩流式卡。activeRuns 槽位表按引用
212
+ * 共用——压缩注册前确认槽位空闲,否则 /stop 停错对象。
164
213
  */
165
- private compactableRuns;
214
+ private readonly compact;
166
215
  /**
167
216
  * 终态卡片的渲染快照(runId → state + options):run 结束后 activeRuns 已
168
217
  * 清空,而卡片上的「⏹ 停止」后台任务按钮(job.kill)还活着,需要按 runId
@@ -173,17 +222,22 @@ export declare class Bridge {
173
222
  private runCardSnapshots;
174
223
  private static readonly RUN_CARD_SNAPSHOT_MAX;
175
224
  /**
176
- * Active `!` bash runs, keyed by runId (NOT cwd). Bash runs bypass the serial
177
- * queue and may run in parallel with claude runs / other bash runs in the same
178
- * cwd, so they live outside `activeRuns`. Tracked so `/stop` can reach
179
- * the per-run BashRunner instance via interruptCurrentRun.
225
+ * 终态卡后台任务订阅与停止(见 job-watch.ts):job.kill、名单订阅与
226
+ * PATCH 串行链收在该模块;jobCardPatches 链内渲染读 snapshot.state,
227
+ * 「停止」与「订阅帧」并发不会把卡片写回旧内容。
180
228
  */
181
- private activeBashRuns;
229
+ private readonly jobWatch;
230
+ /**
231
+ * `!` bash 命令执行(见 bash-run.ts):独立 runId 空间、独立登记表,不进
232
+ * activeRuns;绝不 re-chain 到 QueueManager(会自等待死锁)。/stop 的 bash
233
+ * 侧匹配与中断也收在该模块,避免误杀并行跑的 `!` 任务。
234
+ */
235
+ private readonly bashRuns;
182
236
  constructor(deps: BridgeDeps);
183
237
  /**
184
238
  * Get or create a runner for the given cwd, keyed by current defaultAgent.
185
239
  *
186
- * Fix 4 (2026-07-18): Cache key includes agentKind, so switching defaultAgent
240
+ * Cache key includes agentKind, so switching defaultAgent
187
241
  * creates a NEW runner under a different key without evicting the old one.
188
242
  * This eliminates the need for clearRunners() on agent switch.
189
243
  */
@@ -340,14 +394,6 @@ export declare class Bridge {
340
394
  terminal: RunTerminal;
341
395
  command: string;
342
396
  }>;
343
- interruptCurrentRun(input: {
344
- userId: string;
345
- chatId: string;
346
- runId?: string;
347
- /** Restrict the match to a single cwd (queue.immediate). When
348
- * omitted, all workspaces are candidates (used by /stop, /t, and card stop button which don't know which cwd to target). */
349
- cwd?: string;
350
- }): Promise<boolean>;
351
397
  /**
352
398
  * Same as {@link interruptCurrentRun}, plus what the runner's stop actually
353
399
  * achieved. DSH returns a {@link StopOutcome} (withdrawn / cancelled /
@@ -360,8 +406,20 @@ export declare class Bridge {
360
406
  userId: string;
361
407
  chatId: string;
362
408
  runId?: string;
409
+ /**
410
+ * Card callback's server-provided message id. Used only as a narrow fallback
411
+ * when the behavior-value runId is missing or stale: the clicked card must
412
+ * be the one active run's card. A dashboard or historical card never matches.
413
+ */
414
+ cardMessageId?: string;
363
415
  cwd?: string;
364
416
  }): Promise<InterruptOutcome>;
417
+ /**
418
+ * Resolve a scoped card click by card identity. Empty input or multiple
419
+ * matches fail closed; production message ids are unique, but refusing an
420
+ * ambiguous stop is safer than killing several workspaces.
421
+ */
422
+ private activeRunsForCard;
365
423
  /**
366
424
  * 停掉一条已注册的 active run:置终态、停 runner、摘槽位、标 stale、
367
425
  * 归零该 cwd 的队列执行计数。返回 runner 的停止结果(DSH 才有)。
@@ -370,15 +428,22 @@ export declare class Bridge {
370
428
  * 出现「停第一条就 return」的漏停。
371
429
  */
372
430
  private interruptActiveRun;
373
- /** Send a result message to the user (§7). Returns true on success, false on failure. */
374
- sendResult(result: CommandResult, ctx: CommandContext): Promise<boolean>;
431
+ /**
432
+ * Send a result message to the user (§7). Returns true on success, false on failure.
433
+ *
434
+ * `opts.onCardSent` 回传卡片的 messageId:终态卡收尾后还要靠它接收后台任务
435
+ * 更新(流式卡从 `cardSession.cardMessageId` 取,兜底发送只能从这里拿)。
436
+ */
437
+ sendResult(result: CommandResult, ctx: CommandContext, opts?: {
438
+ onCardSent?: (messageId: string) => void;
439
+ }): Promise<boolean>;
375
440
  /**
376
441
  * Deliver a final answer that cannot fit in the run card as a Markdown file
377
442
  * attachment. 卡片正文已被标记替代,文件是唯一的内容通道;此处绝不发纯文本
378
- * (2026-11-02 定规:纯文本与卡片重复,也丢 Markdown 结构)。
443
+ * (纯文本与卡片重复,也丢 Markdown 结构)。
379
444
  *
380
- * 失败时发一张提示卡(不是纯文本),并把完整回答留在临时文件里记日志,
381
- * 便于事后找回。
445
+ * 发送成功即清理临时文件;失败时发一张提示卡(不是纯文本),完整回答
446
+ * 留在临时文件里(路径见错误日志),便于事后找回。
382
447
  */
383
448
  private sendFinalAnswerFile;
384
449
  /**
@@ -413,14 +478,7 @@ export declare class Bridge {
413
478
  * 与 activeRuns 生命周期在同一个地方收口。
414
479
  */
415
480
  private rememberRunCardSnapshot;
416
- /**
417
- * 停止终态卡上的一个后台任务。
418
- *
419
- * 后台任务的生命周期跨 run(这就是它需要单独入口的原因),所以解析路径是
420
- * 终态快照(runId → sessionId/cwd/agentKind)+ 该工作区的 runner 实例,
421
- * 而不是 activeRuns。成功后同步摘掉 state 里的任务并就地重渲染,否则按钮
422
- * 会留在卡片上而任务早已结束。
423
- */
481
+ /** 停止终态卡上的一个后台任务(job.kill 卡片动作)。 */
424
482
  killBackgroundJob(runId: string, jobId: string, ctx: CommandContext): Promise<boolean>;
425
483
  /** Send a file to the user via Feishu. */
426
484
  sendFile(filePath: string, ctx: CommandContext): Promise<void>;
@@ -453,7 +511,7 @@ export declare class Bridge {
453
511
  *
454
512
  * DSH 把上游 `finish_reason: content_filter` 归一成 PI_AI_ERROR:既不在默认
455
513
  * 重试码里(EMPTY_RESPONSE/RATE_LIMIT/SERVER/TIMEOUT/TRANSPORT),也不会换模型,
456
- * 于是一次(多数是误报的)判定就把整个 turn 判死。2026-10-21 现场:60 步、
514
+ * 于是一次(多数是误报的)判定就把整个 turn 判死。60 步、
457
515
  * 10 分钟的 turn 在最后一步被截断,已写入的文件还在,用户只看到「运行出错」
458
516
  * 加一句英文报文。
459
517
  *
@@ -483,7 +541,7 @@ export declare class Bridge {
483
541
  * result 在 system.init 之后才到。
484
542
  *
485
543
  * 例外:app-server runner(usageAuthority==='live')的 init 是 runner 自己补发
486
- * 的 synthetic init(2026-08-13 修复)。此分支保留为防御性兜底:live runner 若
544
+ * 的 synthetic init。此分支保留为防御性兜底:live runner 若
487
545
  * 在无 init 时发出 result(旧构建等),session 写回照常执行,但 sawResult 不置
488
546
  * 真——卡片不会把半初始化的 run 当作已收尾。
489
547
  *
@@ -511,6 +569,22 @@ export declare class Bridge {
511
569
  * Handles idle watchdog, event processing, session sync, and state transitions.
512
570
  */
513
571
  private runAgentStreamToEnd;
572
+ /**
573
+ * 事件循环的看门狗喂狗(runAgentStreamToEnd 抽出的纯向方法)。
574
+ *
575
+ * §9.12:事件到达只 `touch()` 刷新时间戳(无 timer 操作),interval 周期检查
576
+ * 静默时长;喂狗点与红线口径见 runAgentStreamToEnd 循环内两处调用点注释
577
+ * (每个事件含 result 都必须喂,被守卫丢弃的 result 也喂——CLI 活着就在产事件)。
578
+ */
579
+ private handleEventForWatchdog;
580
+ /**
581
+ * 事件循环的 session 同步(runAgentStreamToEnd 抽出的纯向方法):
582
+ * init / turn_started 两写回点 + compact_boundary 用量观察。
583
+ *
584
+ * @returns 事件是否为本轮 `system.init`(调用方据此置 sawInit,供 pre-init
585
+ * result 守卫判定)。init 分支的全部副作用完成后才返回,与原内联顺序一致。
586
+ */
587
+ private maybeSyncSession;
514
588
  /**
515
589
  * 终态 reaction 收尾:撤掉 Typing、打上下方终态表情。
516
590
  *
@@ -584,89 +658,16 @@ export declare class Bridge {
584
658
  text: string;
585
659
  nonce: string;
586
660
  }): Promise<void>;
587
- /**
588
- * 记下一次「可压缩 run」:终态卡上的 Compact 按钮点击时据此反查
589
- * sessionId + agentKind。runId 是按钮自带的唯一键,同 cwd 内唯一。
590
- * 超出上限按插入序淘汰最旧的一条(Map 保持插入序;重复写同一 runId
591
- * 先 delete 再 set 以刷新位置)。
592
- */
593
- private recordCompactableRun;
594
- /**
595
- * 终态 Compact 记账:把本次 run 实际使用的 sessionId 记进
596
- * {@link compactableRuns},供终态卡上的 Compact 按钮按 runId 反查。
597
- *
598
- * 调用点固定在 `finalizeRun` 的 `finally` 里、**槽位所有权守卫之外**。
599
- * 所有权守卫只回答「cwd 槽位还归不归本 run」(决定能否删槽位 / evict
600
- * runner);记账回答「本次 run 结束了吗、用的哪个 sessionId」。两者在不同
601
- * 维度上:外部中断(`/stop`、停止卡按钮、`queue.immediate`)会先摘槽位,
602
- * 记账若跟着守卫走就永远不会落,中断卡片的按钮必然反查不到(中断
603
- * 后点 Compact 一律回「该任务已结束或不属于当前会话」)。
604
- *
605
- * 覆盖所有终态入口(正常结束、error、interrupted、idle_timeout、
606
- * goal_continuing)——这些卡片都渲染 Compact 按钮(`goal` 仍 active 时
607
- * 除外)。记账失败不能影响清理,故内部兜错。
608
- */
609
- private recordCompactableRunForTerminal;
610
- /**
611
- * 按 runId 反查可压缩 run 记录(跨 cwd 扫描)。
612
- *
613
- * 为什么不带 cwd 过滤:按钮属于「那一次 run」,与用户此刻在哪个工作目录、
614
- * 排队期间有没有 /cd 无关。`/stop` 的 interruptCurrentRun 同样是全局按 runId
615
- * 找(从不查当前 cwd),compact 与它保持一致。用当前 cwd 收窄会让「切了工作区
616
- * 再点旧卡片」和「排队期间 /cd」两种情况误报「该任务已结束或不属于当前会话」。
617
- */
618
- private findCompactableRun;
619
- /**
620
- * Handle compact card action — trigger a compaction request for any
621
- * runCompact-capable runner(codex/kimi/opencode/pi/claude)。按钮带的是
622
- * 那次 run 的 runId,据此反查该 run 实际使用的 sessionId + agentKind
623
- * + cwd(compactableRuns,按 runId 记录),再调 runner 的 runCompact()。
624
- */
661
+ /** 终态卡 Compact 按钮:按 runId 反查那次 run 的会话并发起压缩。 */
625
662
  handleCompactAction(value: {
626
663
  runId?: string;
627
664
  }, ctx: CommandContext): Promise<void>;
628
- /**
629
- * §5.3: kimi 压缩在途检测——reader 实现契约的 `readCompactionState` 时,若
630
- * wire 状态机判定当前有未终结的压缩(最后一次 begin 无 terminal 记录),
631
- * 直接回文本「已有一次 Compact 正在进行」并返回 true(调用方不开卡、不发
632
- * session/prompt)。codex/claude 等 reader 无此方法 → 返回 false,行为不变。
633
- */
634
- private rejectIfCompactionInFlight;
635
- /**
636
- * Stream a compaction to a card: start a RunCardSession with
637
- * operationKind='compaction' (no recursive Compact button), consume
638
- * runner.runCompact() events, read authoritative jsonl usage, and finish
639
- * the card. Shared by handleCompactAction (run card button) and
640
- * handleResumeCompact (resume cards) so both flows stay in sync.
641
- *
642
- * Precondition: callers have already validated that `runner` implements
643
- * runCompact and that the session exists in `cwd`.
644
- */
645
- private streamCompact;
646
- /**
647
- * Handle resume.compact card action — compact a session directly from a
648
- * resume card (auto-resume / `/resume <id>`), without a runId.
649
- *
650
- * Unlike handleCompactAction (which validates against the last finished run's
651
- * runId), the resume card carries the sessionId + agent it was rendered for.
652
- * Validation: the session must exist in the current cwd (same rule as
653
- * cmdResume / resume.use) and the runner must implement runCompact.
654
- */
665
+ /** resume 卡 Compact 按钮:直接压缩卡上指定的 session(无需 runId)。 */
655
666
  handleResumeCompact(value: {
656
667
  sessionId?: string;
657
668
  agent?: string;
658
669
  }, ctx: CommandContext): Promise<void>;
659
- /**
660
- * Execute a bash command and stream output to a card.
661
- * `!` commands bypass the serial queue entirely (see body comment + §9.6):
662
- * bash runs in parallel with same-workspace agent runs, tracked in
663
- * `activeBashRuns` separately from `activeRuns`.
664
- */
670
+ /** Execute a bash command and stream output to a card(`!` 命令入口)。 */
665
671
  executeBash(command: string, ctx: CommandContext): Promise<void>;
666
- /**
667
- * Internal execution of bash command (called directly from executeBash,
668
- * bypassing the serial queue — see executeBash).
669
- */
670
- private executeBashInternal;
671
672
  }
672
673
  export {};