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.
- package/CHANGELOG.md +29 -0
- package/dist/bridge/approval-actions.d.ts +1 -1
- package/dist/bridge/approval-actions.js +1 -1
- package/dist/bridge/bash-run.d.ts +71 -0
- package/dist/bridge/bash-run.js +217 -0
- package/dist/bridge/compact.d.ts +155 -0
- package/dist/bridge/compact.js +450 -0
- package/dist/bridge/final-usage.js +4 -4
- package/dist/bridge/inbound-media.js +72 -46
- package/dist/bridge/index.d.ts +106 -153
- package/dist/bridge/index.js +400 -1000
- package/dist/bridge/job-watch.d.ts +68 -0
- package/dist/bridge/job-watch.js +146 -0
- package/dist/bridge/queue-manager.d.ts +3 -3
- package/dist/bridge/queue-manager.js +10 -29
- package/dist/card/approval-render.d.ts +2 -2
- package/dist/card/approval-render.js +141 -130
- package/dist/card/card-budget.js +123 -98
- package/dist/card/card-helpers.d.ts +3 -3
- package/dist/card/card-helpers.js +6 -6
- package/dist/card/final-answer-file.js +1 -1
- package/dist/card/run-renderer.d.ts +3 -3
- package/dist/card/run-renderer.js +114 -159
- package/dist/card/run-state.d.ts +1 -15
- package/dist/card/run-state.js +358 -292
- package/dist/card/tool-render.d.ts +1 -1
- package/dist/card/tool-render.js +21 -17
- package/dist/card/usage-format.d.ts +22 -7
- package/dist/card/usage-format.js +119 -100
- package/dist/cli.js +15 -3
- package/dist/clone.js +2 -2
- package/dist/common/text-width.js +36 -24
- package/dist/common/tool-summary.js +132 -90
- package/dist/config/codex-config.js +130 -106
- package/dist/config/index.d.ts +16 -2
- package/dist/config/index.js +23 -8
- package/dist/connector/index.js +6 -6
- package/dist/error-classification.js +3 -2
- package/dist/inbound/placeholder.d.ts +1 -1
- package/dist/inbound/placeholder.js +1 -1
- package/dist/index.js +387 -281
- package/dist/logger/index.js +6 -6
- package/dist/message-handlers.d.ts +0 -5
- package/dist/message-handlers.js +254 -237
- package/dist/model-catalog.d.ts +2 -2
- package/dist/model-catalog.js +3 -8
- package/dist/platform/identity.js +1 -1
- package/dist/platform/path.d.ts +1 -1
- package/dist/platform/path.js +1 -1
- package/dist/platform/sleep-blocker.js +1 -1
- package/dist/platform/terminator-win32.js +2 -1
- package/dist/router/commands/ls.d.ts +3 -0
- package/dist/router/commands/ls.js +256 -175
- package/dist/router/commands/order.js +184 -159
- package/dist/router/commands/resume.js +190 -152
- package/dist/router/commands/ws.js +219 -174
- package/dist/router/config/dsh.d.ts +4 -8
- package/dist/router/config/dsh.js +3 -10
- package/dist/router/config/kimi.js +1 -1
- package/dist/router/config/types.d.ts +1 -1
- package/dist/router/config-diff.js +1 -1
- package/dist/router/index.d.ts +56 -11
- package/dist/router/index.js +401 -391
- package/dist/runner/bash/runner.js +2 -4
- package/dist/runner/claude/session.d.ts +1 -1
- package/dist/runner/claude/session.js +6 -4
- package/dist/runner/codex/app-server/runner.d.ts +9 -2
- package/dist/runner/codex/app-server/runner.js +30 -25
- package/dist/runner/codex/app-server/translator.d.ts +2 -5
- package/dist/runner/codex/app-server/translator.js +291 -238
- package/dist/runner/common/acp/acp-approval.d.ts +1 -1
- package/dist/runner/common/acp/acp-approval.js +1 -1
- package/dist/runner/common/acp/base-acp-runner.d.ts +5 -2
- package/dist/runner/common/acp/base-acp-runner.js +26 -65
- package/dist/runner/common/acp/base-translator.d.ts +12 -2
- package/dist/runner/common/acp/base-translator.js +50 -26
- package/dist/runner/common/acp/protocol-types.d.ts +1 -1
- package/dist/runner/common/acp/protocol-types.js +2 -2
- package/dist/runner/common/connection-based-runner.d.ts +32 -1
- package/dist/runner/common/connection-based-runner.js +32 -2
- package/dist/runner/common/jsonl-stream.js +154 -187
- package/dist/runner/common/jsonrpc/client.d.ts +29 -0
- package/dist/runner/common/jsonrpc/client.js +43 -12
- package/dist/runner/common/jsonrpc/connection-manager.d.ts +2 -2
- package/dist/runner/common/jsonrpc/connection-manager.js +4 -4
- package/dist/runner/common/spawning-runner.d.ts +6 -1
- package/dist/runner/common/spawning-runner.js +9 -4
- package/dist/runner/common/turn-started.d.ts +8 -0
- package/dist/runner/common/turn-started.js +11 -0
- package/dist/runner/dsh/approval.js +84 -51
- package/dist/runner/dsh/catalog-probe.d.ts +17 -0
- package/dist/runner/dsh/catalog-probe.js +10 -0
- package/dist/runner/dsh/client.d.ts +7 -11
- package/dist/runner/dsh/client.js +356 -289
- package/dist/runner/dsh/exit-cancel.d.ts +2 -2
- package/dist/runner/dsh/exit-cancel.js +2 -2
- package/dist/runner/dsh/inflight.d.ts +1 -1
- package/dist/runner/dsh/inflight.js +1 -1
- package/dist/runner/dsh/mux-stream.js +28 -8
- package/dist/runner/dsh/runner.d.ts +44 -4
- package/dist/runner/dsh/runner.js +296 -199
- package/dist/runner/dsh/translator.d.ts +1 -31
- package/dist/runner/dsh/translator.js +180 -178
- package/dist/runner/index.d.ts +1 -1
- package/dist/runner/kimi/acp/runner.d.ts +1 -2
- package/dist/runner/kimi/acp/runner.js +82 -46
- package/dist/runner/kimi/acp/translator.d.ts +1 -1
- package/dist/runner/kimi/acp/translator.js +3 -4
- package/dist/runner/opencode/acp/error-monitor.js +5 -5
- package/dist/runner/opencode/acp/runner.d.ts +2 -2
- package/dist/runner/opencode/acp/runner.js +4 -4
- package/dist/runner/pi/rpc/client.js +4 -13
- package/dist/runner/pi/rpc/protocol-types.d.ts +1 -1
- package/dist/runner/pi/rpc/protocol-types.js +1 -1
- package/dist/runner/pi/rpc/runner.d.ts +3 -0
- package/dist/runner/pi/rpc/runner.js +27 -42
- package/dist/runner/pi/rpc/translator.js +61 -60
- package/dist/runner/types.d.ts +2 -2
- package/dist/runner/types.js +1 -1
- package/dist/session/claude/sessions.d.ts +45 -0
- package/dist/session/claude/sessions.js +160 -122
- package/dist/session/codex/rollout-reader.js +181 -182
- package/dist/session/common/throw-session-list-error.d.ts +10 -0
- package/dist/session/common/throw-session-list-error.js +16 -0
- package/dist/session/dsh/sessions.js +291 -235
- package/dist/session/kimi/sessions.d.ts +40 -8
- package/dist/session/kimi/sessions.js +373 -301
- package/dist/session/opencode/sessions.d.ts +142 -1
- package/dist/session/opencode/sessions.js +378 -321
- package/dist/session/pi/sessions.js +4 -5
- package/dist/session/session-store.d.ts +9 -1
- package/dist/session/session-store.js +99 -99
- package/dist/update/version-check.js +2 -1
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/package.json +1 -1
package/dist/bridge/index.d.ts
CHANGED
|
@@ -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
|
|
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 {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
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
|
|
214
|
+
private readonly compact;
|
|
166
215
|
/**
|
|
167
216
|
* 终态卡片的渲染快照(runId → state + options):run 结束后 activeRuns 已
|
|
168
217
|
* 清空,而卡片上的「⏹ 停止」后台任务按钮(job.kill)还活着,需要按 runId
|
|
@@ -173,31 +222,22 @@ export declare class Bridge {
|
|
|
173
222
|
private runCardSnapshots;
|
|
174
223
|
private static readonly RUN_CARD_SNAPSHOT_MAX;
|
|
175
224
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* 受 RUN_CARD_SNAPSHOT_MAX 约束(一张卡最多一条流)。
|
|
225
|
+
* 终态卡后台任务订阅与停止(见 job-watch.ts):job.kill、名单订阅与
|
|
226
|
+
* PATCH 串行链收在该模块;jobCardPatches 链内渲染读 snapshot.state,
|
|
227
|
+
* 「停止」与「订阅帧」并发不会把卡片写回旧内容。
|
|
180
228
|
*/
|
|
181
|
-
private
|
|
229
|
+
private readonly jobWatch;
|
|
182
230
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* 后发先至的那条会把卡片写回旧内容(任务又变回「运行中」)。
|
|
231
|
+
* `!` bash 命令执行(见 bash-run.ts):独立 runId 空间、独立登记表,不进
|
|
232
|
+
* activeRuns;绝不 re-chain 到 QueueManager(会自等待死锁)。/stop 的 bash
|
|
233
|
+
* 侧匹配与中断也收在该模块,避免误杀并行跑的 `!` 任务。
|
|
187
234
|
*/
|
|
188
|
-
private
|
|
189
|
-
/**
|
|
190
|
-
* Active `!` bash runs, keyed by runId (NOT cwd). Bash runs bypass the serial
|
|
191
|
-
* queue and may run in parallel with claude runs / other bash runs in the same
|
|
192
|
-
* cwd, so they live outside `activeRuns`. Tracked so `/stop` can reach
|
|
193
|
-
* the per-run BashRunner instance via interruptCurrentRun.
|
|
194
|
-
*/
|
|
195
|
-
private activeBashRuns;
|
|
235
|
+
private readonly bashRuns;
|
|
196
236
|
constructor(deps: BridgeDeps);
|
|
197
237
|
/**
|
|
198
238
|
* Get or create a runner for the given cwd, keyed by current defaultAgent.
|
|
199
239
|
*
|
|
200
|
-
*
|
|
240
|
+
* Cache key includes agentKind, so switching defaultAgent
|
|
201
241
|
* creates a NEW runner under a different key without evicting the old one.
|
|
202
242
|
* This eliminates the need for clearRunners() on agent switch.
|
|
203
243
|
*/
|
|
@@ -354,16 +394,6 @@ export declare class Bridge {
|
|
|
354
394
|
terminal: RunTerminal;
|
|
355
395
|
command: string;
|
|
356
396
|
}>;
|
|
357
|
-
interruptCurrentRun(input: {
|
|
358
|
-
userId: string;
|
|
359
|
-
chatId: string;
|
|
360
|
-
runId?: string;
|
|
361
|
-
/** Card callback's server-provided message id. */
|
|
362
|
-
cardMessageId?: string;
|
|
363
|
-
/** Restrict the match to a single cwd (queue.immediate). When
|
|
364
|
-
* omitted, all workspaces are candidates (used by /stop, /t, and card stop button which don't know which cwd to target). */
|
|
365
|
-
cwd?: string;
|
|
366
|
-
}): Promise<boolean>;
|
|
367
397
|
/**
|
|
368
398
|
* Same as {@link interruptCurrentRun}, plus what the runner's stop actually
|
|
369
399
|
* achieved. DSH returns a {@link StopOutcome} (withdrawn / cancelled /
|
|
@@ -410,10 +440,10 @@ export declare class Bridge {
|
|
|
410
440
|
/**
|
|
411
441
|
* Deliver a final answer that cannot fit in the run card as a Markdown file
|
|
412
442
|
* attachment. 卡片正文已被标记替代,文件是唯一的内容通道;此处绝不发纯文本
|
|
413
|
-
*
|
|
443
|
+
* (纯文本与卡片重复,也丢 Markdown 结构)。
|
|
414
444
|
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
445
|
+
* 发送成功即清理临时文件;失败时发一张提示卡(不是纯文本),完整回答
|
|
446
|
+
* 留在临时文件里(路径见错误日志),便于事后找回。
|
|
417
447
|
*/
|
|
418
448
|
private sendFinalAnswerFile;
|
|
419
449
|
/**
|
|
@@ -448,37 +478,8 @@ export declare class Bridge {
|
|
|
448
478
|
* 与 activeRuns 生命周期在同一个地方收口。
|
|
449
479
|
*/
|
|
450
480
|
private rememberRunCardSnapshot;
|
|
451
|
-
/**
|
|
452
|
-
private stopJobWatch;
|
|
453
|
-
/**
|
|
454
|
-
* 停止终态卡上的一个后台任务。
|
|
455
|
-
*
|
|
456
|
-
* 后台任务的生命周期跨 run(这就是它需要单独入口的原因),所以解析路径是
|
|
457
|
-
* 终态快照(runId → sessionId/cwd/agentKind)+ 该工作区的 runner 实例,
|
|
458
|
-
* 而不是 activeRuns。成功后同步摘掉 state 里的任务并就地重渲染,否则按钮
|
|
459
|
-
* 会留在卡片上而任务早已结束。
|
|
460
|
-
*/
|
|
481
|
+
/** 停止终态卡上的一个后台任务(job.kill 卡片动作)。 */
|
|
461
482
|
killBackgroundJob(runId: string, jobId: string, ctx: CommandContext): Promise<boolean>;
|
|
462
|
-
/**
|
|
463
|
-
* 让终态卡的后台任务小节跟着宿主继续更新。
|
|
464
|
-
*
|
|
465
|
-
* run 的卡片在 `result` 那一帧就关闭了,但后台任务还能再跑很久:不订阅,
|
|
466
|
-
* 卡片会一直写「运行中」并留着停止按钮,点了必然失败。退订条件写
|
|
467
|
-
* 在 {@link consumeJobRoster} 里——名单清空、patch 失败、订阅中断、快照被
|
|
468
|
-
* 淘汰,任一命中即退出;**绝不因为 patch 失败补发新卡**。
|
|
469
|
-
*/
|
|
470
|
-
private startBackgroundJobWatch;
|
|
471
|
-
/** 消费宿主推来的整份任务名单,直到全结束 / 流断 / patch 失败 / 外部退订。 */
|
|
472
|
-
private consumeJobRoster;
|
|
473
|
-
/** 订阅断了但任务仍未结算:把在跑的任务标成「状态未知」并重渲染一次。 */
|
|
474
|
-
private markJobsUnknown;
|
|
475
|
-
/**
|
|
476
|
-
* 一张终态卡的 PATCH 串行链。
|
|
477
|
-
*
|
|
478
|
-
* 渲染放在链内执行(`task` 里读 `snapshot.state`),后入链的任务必然看到更新
|
|
479
|
-
* 后的状态;否则「停止」与「订阅帧」并发时卡片可能回退。
|
|
480
|
-
*/
|
|
481
|
-
private enqueueJobCardPatch;
|
|
482
483
|
/** Send a file to the user via Feishu. */
|
|
483
484
|
sendFile(filePath: string, ctx: CommandContext): Promise<void>;
|
|
484
485
|
/**
|
|
@@ -510,7 +511,7 @@ export declare class Bridge {
|
|
|
510
511
|
*
|
|
511
512
|
* DSH 把上游 `finish_reason: content_filter` 归一成 PI_AI_ERROR:既不在默认
|
|
512
513
|
* 重试码里(EMPTY_RESPONSE/RATE_LIMIT/SERVER/TIMEOUT/TRANSPORT),也不会换模型,
|
|
513
|
-
* 于是一次(多数是误报的)判定就把整个 turn 判死。
|
|
514
|
+
* 于是一次(多数是误报的)判定就把整个 turn 判死。60 步、
|
|
514
515
|
* 10 分钟的 turn 在最后一步被截断,已写入的文件还在,用户只看到「运行出错」
|
|
515
516
|
* 加一句英文报文。
|
|
516
517
|
*
|
|
@@ -540,7 +541,7 @@ export declare class Bridge {
|
|
|
540
541
|
* result 在 system.init 之后才到。
|
|
541
542
|
*
|
|
542
543
|
* 例外:app-server runner(usageAuthority==='live')的 init 是 runner 自己补发
|
|
543
|
-
* 的 synthetic init
|
|
544
|
+
* 的 synthetic init。此分支保留为防御性兜底:live runner 若
|
|
544
545
|
* 在无 init 时发出 result(旧构建等),session 写回照常执行,但 sawResult 不置
|
|
545
546
|
* 真——卡片不会把半初始化的 run 当作已收尾。
|
|
546
547
|
*
|
|
@@ -568,6 +569,31 @@ export declare class Bridge {
|
|
|
568
569
|
* Handles idle watchdog, event processing, session sync, and state transitions.
|
|
569
570
|
*/
|
|
570
571
|
private runAgentStreamToEnd;
|
|
572
|
+
/**
|
|
573
|
+
* runAgentStreamToEnd 的 try 主体(建卡 → 事件循环 → 收尾),抽成独立方法
|
|
574
|
+
* 降低外层圈复杂度;state 为跨方法共享的可变状态。逻辑与文案逐字保留。
|
|
575
|
+
*/
|
|
576
|
+
private executeStream;
|
|
577
|
+
/** runAgentStreamToEnd 的 catch 主体(抽成独立方法,state.sawResult 沿用循环累计值)。 */
|
|
578
|
+
private handleStreamFailure;
|
|
579
|
+
/** runAgentStreamToEnd 的 finally 主体(抽成独立方法)。 */
|
|
580
|
+
private cleanupStream;
|
|
581
|
+
/**
|
|
582
|
+
* 事件循环的看门狗喂狗(runAgentStreamToEnd 抽出的纯向方法)。
|
|
583
|
+
*
|
|
584
|
+
* §9.12:事件到达只 `touch()` 刷新时间戳(无 timer 操作),interval 周期检查
|
|
585
|
+
* 静默时长;喂狗点与红线口径见 runAgentStreamToEnd 循环内两处调用点注释
|
|
586
|
+
* (每个事件含 result 都必须喂,被守卫丢弃的 result 也喂——CLI 活着就在产事件)。
|
|
587
|
+
*/
|
|
588
|
+
private handleEventForWatchdog;
|
|
589
|
+
/**
|
|
590
|
+
* 事件循环的 session 同步(runAgentStreamToEnd 抽出的纯向方法):
|
|
591
|
+
* init / turn_started 两写回点 + compact_boundary 用量观察。
|
|
592
|
+
*
|
|
593
|
+
* @returns 事件是否为本轮 `system.init`(调用方据此置 sawInit,供 pre-init
|
|
594
|
+
* result 守卫判定)。init 分支的全部副作用完成后才返回,与原内联顺序一致。
|
|
595
|
+
*/
|
|
596
|
+
private maybeSyncSession;
|
|
571
597
|
/**
|
|
572
598
|
* 终态 reaction 收尾:撤掉 Typing、打上下方终态表情。
|
|
573
599
|
*
|
|
@@ -641,89 +667,16 @@ export declare class Bridge {
|
|
|
641
667
|
text: string;
|
|
642
668
|
nonce: string;
|
|
643
669
|
}): Promise<void>;
|
|
644
|
-
/**
|
|
645
|
-
* 记下一次「可压缩 run」:终态卡上的 Compact 按钮点击时据此反查
|
|
646
|
-
* sessionId + agentKind。runId 是按钮自带的唯一键,同 cwd 内唯一。
|
|
647
|
-
* 超出上限按插入序淘汰最旧的一条(Map 保持插入序;重复写同一 runId
|
|
648
|
-
* 先 delete 再 set 以刷新位置)。
|
|
649
|
-
*/
|
|
650
|
-
private recordCompactableRun;
|
|
651
|
-
/**
|
|
652
|
-
* 终态 Compact 记账:把本次 run 实际使用的 sessionId 记进
|
|
653
|
-
* {@link compactableRuns},供终态卡上的 Compact 按钮按 runId 反查。
|
|
654
|
-
*
|
|
655
|
-
* 调用点固定在 `finalizeRun` 的 `finally` 里、**槽位所有权守卫之外**。
|
|
656
|
-
* 所有权守卫只回答「cwd 槽位还归不归本 run」(决定能否删槽位 / evict
|
|
657
|
-
* runner);记账回答「本次 run 结束了吗、用的哪个 sessionId」。两者在不同
|
|
658
|
-
* 维度上:外部中断(`/stop`、停止卡按钮、`queue.immediate`)会先摘槽位,
|
|
659
|
-
* 记账若跟着守卫走就永远不会落,中断卡片的按钮必然反查不到(中断
|
|
660
|
-
* 后点 Compact 一律回「该任务已结束或不属于当前会话」)。
|
|
661
|
-
*
|
|
662
|
-
* 覆盖所有终态入口(正常结束、error、interrupted、idle_timeout、
|
|
663
|
-
* goal_continuing)——这些卡片都渲染 Compact 按钮(`goal` 仍 active 时
|
|
664
|
-
* 除外)。记账失败不能影响清理,故内部兜错。
|
|
665
|
-
*/
|
|
666
|
-
private recordCompactableRunForTerminal;
|
|
667
|
-
/**
|
|
668
|
-
* 按 runId 反查可压缩 run 记录(跨 cwd 扫描)。
|
|
669
|
-
*
|
|
670
|
-
* 为什么不带 cwd 过滤:按钮属于「那一次 run」,与用户此刻在哪个工作目录、
|
|
671
|
-
* 排队期间有没有 /cd 无关。`/stop` 的 interruptCurrentRun 同样是全局按 runId
|
|
672
|
-
* 找(从不查当前 cwd),compact 与它保持一致。用当前 cwd 收窄会让「切了工作区
|
|
673
|
-
* 再点旧卡片」和「排队期间 /cd」两种情况误报「该任务已结束或不属于当前会话」。
|
|
674
|
-
*/
|
|
675
|
-
private findCompactableRun;
|
|
676
|
-
/**
|
|
677
|
-
* Handle compact card action — trigger a compaction request for any
|
|
678
|
-
* runCompact-capable runner(codex/kimi/opencode/pi/claude)。按钮带的是
|
|
679
|
-
* 那次 run 的 runId,据此反查该 run 实际使用的 sessionId + agentKind
|
|
680
|
-
* + cwd(compactableRuns,按 runId 记录),再调 runner 的 runCompact()。
|
|
681
|
-
*/
|
|
670
|
+
/** 终态卡 Compact 按钮:按 runId 反查那次 run 的会话并发起压缩。 */
|
|
682
671
|
handleCompactAction(value: {
|
|
683
672
|
runId?: string;
|
|
684
673
|
}, ctx: CommandContext): Promise<void>;
|
|
685
|
-
/**
|
|
686
|
-
* §5.3: kimi 压缩在途检测——reader 实现契约的 `readCompactionState` 时,若
|
|
687
|
-
* wire 状态机判定当前有未终结的压缩(最后一次 begin 无 terminal 记录),
|
|
688
|
-
* 直接回文本「已有一次 Compact 正在进行」并返回 true(调用方不开卡、不发
|
|
689
|
-
* session/prompt)。codex/claude 等 reader 无此方法 → 返回 false,行为不变。
|
|
690
|
-
*/
|
|
691
|
-
private rejectIfCompactionInFlight;
|
|
692
|
-
/**
|
|
693
|
-
* Stream a compaction to a card: start a RunCardSession with
|
|
694
|
-
* operationKind='compaction' (no recursive Compact button), consume
|
|
695
|
-
* runner.runCompact() events, read authoritative jsonl usage, and finish
|
|
696
|
-
* the card. Shared by handleCompactAction (run card button) and
|
|
697
|
-
* handleResumeCompact (resume cards) so both flows stay in sync.
|
|
698
|
-
*
|
|
699
|
-
* Precondition: callers have already validated that `runner` implements
|
|
700
|
-
* runCompact and that the session exists in `cwd`.
|
|
701
|
-
*/
|
|
702
|
-
private streamCompact;
|
|
703
|
-
/**
|
|
704
|
-
* Handle resume.compact card action — compact a session directly from a
|
|
705
|
-
* resume card (auto-resume / `/resume <id>`), without a runId.
|
|
706
|
-
*
|
|
707
|
-
* Unlike handleCompactAction (which validates against the last finished run's
|
|
708
|
-
* runId), the resume card carries the sessionId + agent it was rendered for.
|
|
709
|
-
* Validation: the session must exist in the current cwd (same rule as
|
|
710
|
-
* cmdResume / resume.use) and the runner must implement runCompact.
|
|
711
|
-
*/
|
|
674
|
+
/** resume 卡 Compact 按钮:直接压缩卡上指定的 session(无需 runId)。 */
|
|
712
675
|
handleResumeCompact(value: {
|
|
713
676
|
sessionId?: string;
|
|
714
677
|
agent?: string;
|
|
715
678
|
}, ctx: CommandContext): Promise<void>;
|
|
716
|
-
/**
|
|
717
|
-
* Execute a bash command and stream output to a card.
|
|
718
|
-
* `!` commands bypass the serial queue entirely (see body comment + §9.6):
|
|
719
|
-
* bash runs in parallel with same-workspace agent runs, tracked in
|
|
720
|
-
* `activeBashRuns` separately from `activeRuns`.
|
|
721
|
-
*/
|
|
679
|
+
/** Execute a bash command and stream output to a card(`!` 命令入口)。 */
|
|
722
680
|
executeBash(command: string, ctx: CommandContext): Promise<void>;
|
|
723
|
-
/**
|
|
724
|
-
* Internal execution of bash command (called directly from executeBash,
|
|
725
|
-
* bypassing the serial queue — see executeBash).
|
|
726
|
-
*/
|
|
727
|
-
private executeBashInternal;
|
|
728
681
|
}
|
|
729
682
|
export {};
|