lark-remote 0.1.13 → 0.2.1

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 (132) hide show
  1. package/CHANGELOG.md +36 -3
  2. package/README.en.md +7 -11
  3. package/README.md +7 -11
  4. package/dist/bridge/final-usage.d.ts +24 -0
  5. package/dist/bridge/final-usage.js +55 -0
  6. package/dist/bridge/index.d.ts +0 -7
  7. package/dist/bridge/index.js +22 -64
  8. package/dist/bridge/queue-manager.js +4 -3
  9. package/dist/card/approval-render.js +39 -94
  10. package/dist/card/bash-renderer.js +12 -21
  11. package/dist/card/card-shared.d.ts +13 -1
  12. package/dist/card/card-shared.js +21 -30
  13. package/dist/card/run-renderer.d.ts +0 -22
  14. package/dist/card/run-renderer.js +206 -153
  15. package/dist/card/run-state.d.ts +29 -1
  16. package/dist/card/run-state.js +172 -84
  17. package/dist/card/text-truncate.d.ts +0 -9
  18. package/dist/card/text-truncate.js +0 -9
  19. package/dist/card/tool-render.d.ts +4 -1
  20. package/dist/card/tool-render.js +76 -32
  21. package/dist/cli.js +2 -2
  22. package/dist/common/fs.d.ts +14 -0
  23. package/dist/common/fs.js +57 -3
  24. package/dist/config/codex-config.js +2 -0
  25. package/dist/config/index.d.ts +0 -5
  26. package/dist/config/index.js +0 -11
  27. package/dist/config/kimi-config.js +1 -0
  28. package/dist/config/opencode-config.js +13 -2
  29. package/dist/config/qr.d.ts +36 -0
  30. package/dist/config/qr.js +124 -0
  31. package/dist/config/wizard.js +69 -27
  32. package/dist/connector/index.d.ts +3 -2
  33. package/dist/connector/index.js +5 -4
  34. package/dist/index.js +15 -42
  35. package/dist/instance-lock.js +7 -0
  36. package/dist/persistence/atomic-write.d.ts +2 -0
  37. package/dist/persistence/atomic-write.js +20 -5
  38. package/dist/persistence/load-json-file.d.ts +1 -2
  39. package/dist/persistence/load-json-file.js +2 -3
  40. package/dist/platform/agent-stopper.d.ts +22 -0
  41. package/dist/platform/agent-stopper.js +19 -0
  42. package/dist/platform/command.d.ts +11 -0
  43. package/dist/platform/command.js +107 -0
  44. package/dist/platform/identity.d.ts +33 -0
  45. package/dist/platform/identity.js +187 -0
  46. package/dist/platform/path.d.ts +24 -0
  47. package/dist/platform/path.js +110 -0
  48. package/dist/platform/select.d.ts +9 -0
  49. package/dist/platform/select.js +12 -0
  50. package/dist/platform/shell.d.ts +51 -0
  51. package/dist/platform/shell.js +75 -0
  52. package/dist/platform/spawn.d.ts +41 -0
  53. package/dist/platform/spawn.js +77 -0
  54. package/dist/platform/terminator-posix.d.ts +38 -0
  55. package/dist/platform/terminator-posix.js +103 -0
  56. package/dist/platform/terminator-win32.d.ts +21 -0
  57. package/dist/platform/terminator-win32.js +110 -0
  58. package/dist/platform/terminator.d.ts +44 -0
  59. package/dist/platform/terminator.js +24 -0
  60. package/dist/platform/types.d.ts +23 -0
  61. package/dist/platform/types.js +5 -0
  62. package/dist/restart.js +4 -2
  63. package/dist/router/card-helpers.d.ts +33 -6
  64. package/dist/router/card-helpers.js +67 -11
  65. package/dist/router/config/common/render.d.ts +1 -1
  66. package/dist/router/config/common/render.js +1 -1
  67. package/dist/router/config-diff.d.ts +4 -0
  68. package/dist/router/config-diff.js +70 -0
  69. package/dist/router/index.d.ts +66 -6
  70. package/dist/router/index.js +451 -316
  71. package/dist/router/utils.d.ts +6 -0
  72. package/dist/router/utils.js +12 -0
  73. package/dist/runner/bash/runner.d.ts +9 -2
  74. package/dist/runner/bash/runner.js +45 -20
  75. package/dist/runner/claude/session.d.ts +4 -1
  76. package/dist/runner/claude/session.js +18 -4
  77. package/dist/runner/codex/app-server/protocol-types.d.ts +35 -1
  78. package/dist/runner/codex/app-server/translator.d.ts +18 -0
  79. package/dist/runner/codex/app-server/translator.js +146 -0
  80. package/dist/runner/common/acp/base-acp-runner.d.ts +116 -0
  81. package/dist/runner/common/acp/base-acp-runner.js +248 -0
  82. package/dist/runner/common/acp/base-translator.d.ts +141 -0
  83. package/dist/runner/common/acp/base-translator.js +271 -0
  84. package/dist/runner/common/acp/protocol-helpers.d.ts +39 -0
  85. package/dist/runner/common/acp/protocol-helpers.js +34 -0
  86. package/dist/runner/common/jsonrpc/transport.d.ts +2 -0
  87. package/dist/runner/common/jsonrpc/transport.js +25 -5
  88. package/dist/runner/common/process-stopper.d.ts +4 -26
  89. package/dist/runner/common/process-stopper.js +4 -76
  90. package/dist/runner/common/runner-utils.d.ts +0 -5
  91. package/dist/runner/common/runner-utils.js +0 -7
  92. package/dist/runner/common/spawning-runner.d.ts +42 -132
  93. package/dist/runner/common/spawning-runner.js +52 -271
  94. package/dist/runner/common/usage.d.ts +2 -0
  95. package/dist/runner/common/usage.js +2 -0
  96. package/dist/runner/index.d.ts +1 -1
  97. package/dist/runner/kimi/acp/runner.d.ts +45 -42
  98. package/dist/runner/kimi/acp/runner.js +140 -293
  99. package/dist/runner/kimi/acp/translator.d.ts +18 -100
  100. package/dist/runner/kimi/acp/translator.js +56 -242
  101. package/dist/runner/opencode/acp/runner.d.ts +22 -46
  102. package/dist/runner/opencode/acp/runner.js +73 -256
  103. package/dist/runner/opencode/acp/translator.d.ts +28 -103
  104. package/dist/runner/opencode/acp/translator.js +51 -236
  105. package/dist/runner/pi/rpc/translator.d.ts +3 -0
  106. package/dist/runner/pi/rpc/translator.js +47 -9
  107. package/dist/runner/probe.d.ts +8 -11
  108. package/dist/runner/probe.js +17 -21
  109. package/dist/runner/registry.d.ts +4 -4
  110. package/dist/runner/registry.js +4 -4
  111. package/dist/runner/types.d.ts +38 -1
  112. package/dist/session/claude/sessions.js +35 -58
  113. package/dist/session/codex/rollout-reader.d.ts +10 -0
  114. package/dist/session/codex/rollout-reader.js +123 -41
  115. package/dist/session/common/constants.d.ts +7 -0
  116. package/dist/session/common/constants.js +9 -0
  117. package/dist/session/common/two-pass.d.ts +22 -0
  118. package/dist/session/common/two-pass.js +70 -0
  119. package/dist/session/dsh/sessions.js +7 -6
  120. package/dist/session/kimi/sessions.d.ts +6 -0
  121. package/dist/session/kimi/sessions.js +50 -73
  122. package/dist/session/opencode/sessions.js +26 -8
  123. package/dist/session/pi/sessions.js +54 -73
  124. package/dist/update/index.d.ts +1 -2
  125. package/dist/update/index.js +1 -2
  126. package/dist/update/install.d.ts +2 -1
  127. package/dist/update/install.js +58 -9
  128. package/dist/update/version-check.d.ts +5 -0
  129. package/dist/update/version-check.js +9 -0
  130. package/package.json +9 -6
  131. package/dist/update/startup-hint.d.ts +0 -5
  132. package/dist/update/startup-hint.js +0 -11
@@ -2,20 +2,20 @@ import { type ChildProcess } from 'node:child_process';
2
2
  import type { Readable } from 'node:stream';
3
3
  import { ProcessStopper } from './process-stopper.js';
4
4
  import { SpawnHeartbeat } from './spawn-heartbeat.js';
5
- import type { AgentEvent, SpawnOptions } from '../types.js';
5
+ import type { SpawnOptions } from '../types.js';
6
6
  /**
7
7
  * 进程级退出监听单例分发(P1-1 修复,2026-08-02)。
8
8
  *
9
- * 背景:5 个 runner(claude/codex/opencode/pi/kimi)的 registerExitHandlers 曾是
10
- * 同构复制,每个实例 process.on('exit'|'SIGINT'|'SIGTERM') 注册 3 个永不移除的
11
- * 闭包(捕获整个 runner 实例 + sessionReader + pidFilePath)。Bridge 每次 run
12
- * 结束淘汰 (cwd, kind) 槽位、下次 run cache miss 新建实例再注册 → 约第 4 个 run
13
- * 起 MaxListenersExceededWarning 刷屏,历史实例被闭包永久持有,内存无界增长。
9
+ * 背景:各 agent runner 的 registerExitHandlers 曾是同构复制,每个实例
10
+ * process.on('exit'|'SIGINT'|'SIGTERM') 注册 3 个永不移除的闭包(捕获整个
11
+ * runner 实例 + sessionReader + pidFilePath)。Bridge 每次 run 结束淘汰
12
+ * (cwd, kind) 槽位、下次 run cache miss 新建实例再注册 → 约第 4 个 run 起
13
+ * MaxListenersExceededWarning 刷屏,历史实例被闭包永久持有,内存无界增长。
14
14
  *
15
- * 现在:进程级监听只注册一次,内部 Set<SpawningRunner> 管理注册实例;
16
- * registerExitHandlers() 只把实例加入集合(幂等),桥接层在淘汰槽位时调
17
- * unregisterExitHandlers() 移除实例,让 runner 可被 GC。SIGINT/SIGTERM 语义
18
- * 保持原样:cleanup 全部已注册实例后 exit 130/143。
15
+ * 现在:进程级监听只注册一次,内部 Set 管理注册实例;registerExitHandlers()
16
+ * 只把实例加入集合(幂等),桥接层在淘汰槽位时调 unregisterExitHandlers()
17
+ * 移除实例,让 runner 可被 GC。SIGINT/SIGTERM 语义保持原样:cleanup 全部
18
+ * 已注册实例后 exit 130/143。
19
19
  */
20
20
  /**
21
21
  * Exit-cleanup contract: anything that spawns a child process group and wants
@@ -30,47 +30,22 @@ export declare function registerExitCleanup(handler: ExitCleanupHandler): void;
30
30
  /** Remove a handler so it can be GC'd (agent slots / finished bash runs). */
31
31
  export declare function unregisterExitCleanup(handler: ExitCleanupHandler): void;
32
32
  /**
33
- * Stateful translator contract for runners that need per-run translation state
34
- * (codex/opencode/pi/kimi). Subclasses return an instance from
35
- * `createTranslator(opts)`; the base `run()` loop calls `translate(raw)` per
36
- * event, then folds terminal state into `buildResultEvent(...)` at the end.
33
+ * Abstract base class encapsulating the spawn lifecycle shared by agent
34
+ * runners: spawn lead-in (pid-undefined check, pid file write, heartbeat,
35
+ * stderr tail accumulation), user-initiated stop, orphan kill with pid
36
+ * identity verification, and process-exit cleanup registration.
37
37
  *
38
- * `translate()` returns `AgentEvent | AgentEvent[] | null` (single event,
39
- * multiple events, or filtered-out). `isTerminal()` / `finish()` / `getTerminalError()`
40
- * / `hasAgentTerminalError()` are folded into the unified result event at the
41
- * end of `run()`.
38
+ * The sole production subclass is ClaudeSession (src/runner/claude/session.ts),
39
+ * a long-lived interactive session that overrides `run()` with its own
40
+ * per-turn consumption loop and reads `spawnStderr` / `stoppedByUser` /
41
+ * `commandNotFoundSeen` to build its terminal result events.
42
42
  *
43
- * `getSessionId()` / `getLastUsage()` are optional because ClaudeRunner uses
44
- * the stateless `translate()` hook (no translator object) and reads neither.
45
- */
46
- export interface RunnerTranslator {
47
- translate(raw: unknown): AgentEvent | AgentEvent[] | null;
48
- isTerminal(): boolean;
49
- finish(reason: 'failed' | 'interrupted' | 'timeout'): void;
50
- getTerminalError(): string | undefined;
51
- hasAgentTerminalError(): boolean;
52
- getSessionId?(): string | undefined;
53
- getLastUsage?(): Record<string, unknown> | undefined;
54
- }
55
- /**
56
- * Abstract base class for runners that spawn a child process per turn.
57
- *
58
- * Encapsulates the spawn + completion + cleanup orchestration shared by
59
- * Claude/Pi runners. Subclasses override:
60
- * - buildArgv(opts) → agent-specific CLI flags (required)
61
- * - createTranslator(opts) → stateful translator (pi)
62
- * OR translate(raw, ctx) → stateless passthrough (claude)
43
+ * Subclasses override:
44
+ * - buildArgv(opts) → agent-specific CLI flags (required)
63
45
  *
64
46
  * Optional hooks (with sensible defaults):
65
- * - getStdio() → stdio config (default ['ignore','pipe','pipe'])
66
- * - createStreamReader(stdout) → JSONL or readline parser (default createJSONLStream)
67
- * - awaitSpawnError(proc) → wait for spawn error (default once('error'))
68
- *
69
- * The base class always emits a unified result event at the end of `run()`
70
- * via `buildResultEvent(...)` — never throws on non-zero exit. This matches
71
- * the contract pinned by the agent subclass anchors and the bridge's
72
- * `runAgentStreamToEnd` error handling (which accepts both thrown errors and
73
- * yielded error-result events).
47
+ * - getStdio() → stdio config (default ['ignore','pipe','pipe'])
48
+ * - createStreamReader(stdout) → JSONL or readline parser (default createJSONLStream)
74
49
  */
75
50
  export declare abstract class SpawningRunner {
76
51
  protected currentProcess: ChildProcess | null;
@@ -85,26 +60,23 @@ export declare abstract class SpawningRunner {
85
60
  * Log prefix used in all operational log lines emitted by this runner
86
61
  * (spawn, pid file, non-zero exit, stderr, killOrphan, stop cleanup) and
87
62
  * as the SpawnHeartbeat label. Subclasses pass their own tag (e.g.
88
- * 'claude-runner') so operators can grep agent-specific logs; the default
89
- * 'spawning-runner' keeps the base-class anchor tests' neutral identity.
63
+ * 'claude-runner') so operators can grep agent-specific logs.
90
64
  */
91
65
  protected readonly logTag: string;
92
- /**
93
- * The `message` argument from the most recent `run(message, opts)` call.
94
- * Set in `run()` before `buildArgv(opts)` is invoked so subclasses can
95
- * embed the message in their agent-specific argv (e.g. claude's `-p
96
- * <message>`). This avoids changing the `buildArgv(opts)` signature,
97
- * which would break existing anchor subclasses.
98
- */
99
- protected currentMessage: string;
100
66
  /**
101
67
  * Whether the current run was interrupted by user-initiated stop().
102
68
  * Set to true by stop() when a running process is being terminated;
103
- * reset to false at the top of run(). `resolveTranslatorError()` and
104
- * `buildResultEvent()` read this to decide result event subtype
105
- * (error vs success) and the error message precedence.
69
+ * subclasses reset it at the start of a turn and read it when building
70
+ * the terminal result event (interrupted vs error precedence).
106
71
  */
107
72
  protected stoppedByUser: boolean;
73
+ /**
74
+ * §4.4 win32 command-not-found 嗅探嫌疑标记:stderr 命中特征行时置位,
75
+ * 但**不**立即杀进程——agent 正常输出可能引用该错误文本(调试 Windows
76
+ * 报错场景),见行即杀会误杀 run。定性走双条件:子类收尾时「标记在 +
77
+ * 非零退出」才判 command-not-found;真挂起由既有 grace/超时兜底。
78
+ */
79
+ protected commandNotFoundSeen: boolean;
108
80
  constructor(opts: {
109
81
  pidDir?: string;
110
82
  workspace: string;
@@ -127,28 +99,23 @@ export declare abstract class SpawningRunner {
127
99
  });
128
100
  get isRunning(): boolean;
129
101
  /**
130
- * stdio config for spawn. Default: stdin ignored (claude/kimi/pi pass the
131
- * prompt via argv).
102
+ * stdio config for spawn. Default: stdin ignored (agents pass the prompt
103
+ * via argv).
132
104
  */
133
105
  protected getStdio(): ('ignore' | 'pipe')[];
134
106
  /**
135
107
  * Create an async iterator over the child's stdout. Default: createJSONLStream
136
- * (claude/kimi/pi) with P1-4 backpressure enabled (pauseThreshold=100).
108
+ * with P1-4 backpressure enabled (pauseThreshold=100).
137
109
  */
138
110
  protected createStreamReader(stdout: Readable): AsyncGenerator<unknown>;
139
- /**
140
- * Create a stateful translator for this run. Default: null (uses the
141
- * stateless passthrough). pi overrides to return its translator instance.
142
- */
143
- protected createTranslator(_opts: SpawnOptions): RunnerTranslator | null;
144
111
  /**
145
112
  * Await the spawn 'error' event when proc.pid === undefined. Races a
146
113
  * finite timeout (review P2-11) against the 'error' event: Node guarantees
147
114
  * 'error' for ENOENT/EACCES, but some binaries fail silently without ever
148
- * emitting it (kimi's CLI is documented to do so). Without the race, run()
149
- * hangs forever → the workspace serial queue never settles → permanent
150
- * deadlock, and /stop can't recover (ProcessStopper returns early when
151
- * pid === undefined). The timeout keeps the deadlock bounded.
115
+ * emitting it. Without the race, the spawn lead-in hangs forever → the
116
+ * workspace serial queue never settles → permanent deadlock, and /stop
117
+ * can't recover (ProcessStopper returns early when pid === undefined).
118
+ * The timeout keeps the deadlock bounded.
152
119
  */
153
120
  protected awaitSpawnError(proc: ChildProcess): Promise<Error | undefined>;
154
121
  /**
@@ -158,30 +125,14 @@ export declare abstract class SpawningRunner {
158
125
  *
159
126
  * Throws a `SpawnChildError` (carrying the user-facing spawn failure
160
127
  * message) when the process fails to spawn (binary missing / pid undefined).
161
- * On success returns the spawned child plus the accumulated stderr tail.
162
- *
163
- * Shared by the base `run()` (yields an authErrorEvent on failure) and
164
- * ClaudeSession's `doStartProcess` (returns the error message), which would
165
- * otherwise duplicate ~60 lines of spawn lead-in with two copies of the
166
- * STDERR_TAIL_BYTES cap.
128
+ * On success returns the spawned child.
167
129
  */
168
130
  protected spawnChild(opts: SpawnOptions): Promise<ChildProcess>;
169
- /**
170
- * Spawn the agent binary with argv built by buildArgv(opts), iterate its
171
- * stdout stream, and yield translated events. Always emits a unified
172
- * result event at the end via `buildResultEvent(...)` — never throws on
173
- * non-zero exit (the bridge accepts both thrown errors and yielded
174
- * error-result events, and the latter carries richer diagnostic info).
175
- *
176
- * Spawn failures (binary missing, pid undefined) yield an `authErrorEvent`
177
- * instead of throwing, so the user sees a friendly error card.
178
- */
179
- run(message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
180
131
  /**
181
132
  * Stop the current process if one is running. Delegates the actual
182
133
  * SIGTERM → grace → SIGKILL sequence to `this.stopper.stop(proc, opts)`
183
134
  * (see `src/runner/common/process-stopper.ts`), forwarding the `immediate`
184
- * flag verbatim so all 5 subclasses inherit identical stop semantics.
135
+ * flag verbatim so all subclasses inherit identical stop semantics.
185
136
  */
186
137
  stop(opts?: {
187
138
  immediate?: boolean;
@@ -224,51 +175,10 @@ export declare abstract class SpawningRunner {
224
175
  /**
225
176
  * Shared process-exit cleanup: SIGTERM the still-running child process and
226
177
  * remove the pid file. Called by the singleton dispatcher for every
227
- * registered runner; previously duplicated verbatim in all 5 runner
178
+ * registered runner; previously duplicated verbatim in the runner
228
179
  * subclasses.
229
180
  */
230
181
  cleanupOnExit(): void;
231
- /**
232
- * Build a unified result event from process exit state. Centralizes the
233
- * result-event semantics specified in Candidate 2:
234
- * - stoppedByUser → error ("interrupted by user")
235
- * - translatorError set → error (translator-supplied message, e.g. codex
236
- * `turn.failed` or "stream ended before a terminal event")
237
- * - code !== 0 && code !== null → error (exit code + stderr tail)
238
- * - signal !== null → error (killed by signal)
239
- * - otherwise → success (with optional usage)
240
- *
241
- * Error message precedence (most-specific first):
242
- * - stoppedByUser: "{binary} interrupted by user"
243
- * - translatorError: verbatim translator-supplied message
244
- * - signal: "{binary} killed by signal {signal}{stderr tail}"
245
- * - non-zero code: "{binary} exited code={code}{stderr tail}"
246
- *
247
- * @param opts.code - Process exit code (null if killed by signal)
248
- * @param opts.signal - Process signal code (null if exited normally)
249
- * @param opts.stderr - Accumulated stderr (tail included in code/signal errors)
250
- * @param opts.sessionId - Session ID to include in the result event
251
- * @param opts.usage - Token usage to include on success
252
- * @param opts.translatorError - Agent-specific terminal error message (e.g.
253
- * codex turn.failed, or "stream ended early")
254
- * @returns AgentEvent with type='result'
255
- */
256
- protected buildResultEvent(opts: {
257
- code: number | null;
258
- signal: NodeJS.Signals | null;
259
- stderr?: string;
260
- sessionId?: string;
261
- usage?: Record<string, unknown>;
262
- translatorError?: string;
263
- }): AgentEvent;
264
182
  protected abstract buildArgv(opts: SpawnOptions): string[];
265
- /**
266
- * Stateless passthrough translator hook. Used by ClaudeRunner
267
- * which does not need per-run translation state. Subclasses that return
268
- * a translator from `createTranslator(opts)` leave this as the default
269
- * no-op — the base `run()` loop only calls `translate()` when
270
- * `createTranslator()` returns null.
271
- */
272
- protected translate(_rawEvent: unknown, _ctx: unknown): AgentEvent | AgentEvent[] | null;
273
183
  }
274
184
  export {};