lark-remote 0.1.6 → 0.1.8

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 (216) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.en.md +9 -1
  3. package/README.md +14 -2
  4. package/dist/bridge/approval-coordinator.d.ts +71 -34
  5. package/dist/bridge/approval-coordinator.js +225 -41
  6. package/dist/bridge/inbound-media.d.ts +62 -0
  7. package/dist/bridge/inbound-media.js +282 -0
  8. package/dist/bridge/index.d.ts +97 -13
  9. package/dist/bridge/index.js +227 -87
  10. package/dist/bridge/queue-manager.d.ts +2 -1
  11. package/dist/bridge/queue-manager.js +1 -0
  12. package/dist/card/approval-render.js +294 -36
  13. package/dist/card/bash-card-session.d.ts +2 -24
  14. package/dist/card/bash-card-session.js +6 -73
  15. package/dist/card/bash-renderer.js +2 -3
  16. package/dist/card/card-budget.js +29 -75
  17. package/dist/card/card-session.d.ts +48 -0
  18. package/dist/card/card-session.js +86 -0
  19. package/dist/card/card-shared.d.ts +7 -16
  20. package/dist/card/card-shared.js +7 -30
  21. package/dist/card/run-card-session.d.ts +2 -55
  22. package/dist/card/run-card-session.js +6 -104
  23. package/dist/card/run-renderer.d.ts +7 -0
  24. package/dist/card/run-renderer.js +116 -238
  25. package/dist/card/run-state.d.ts +13 -0
  26. package/dist/card/run-state.js +25 -16
  27. package/dist/card/text-truncate.d.ts +13 -12
  28. package/dist/card/text-truncate.js +13 -63
  29. package/dist/common/fs.d.ts +8 -0
  30. package/dist/common/fs.js +17 -0
  31. package/dist/common/guards.d.ts +0 -20
  32. package/dist/common/guards.js +0 -43
  33. package/dist/common/sleep.d.ts +2 -0
  34. package/dist/common/sleep.js +5 -0
  35. package/dist/common/truncate.d.ts +39 -0
  36. package/dist/common/truncate.js +92 -0
  37. package/dist/config/codex-config.d.ts +1 -1
  38. package/dist/config/codex-config.js +1 -1
  39. package/dist/config/index.d.ts +112 -24
  40. package/dist/config/index.js +139 -37
  41. package/dist/connector/index.d.ts +69 -2
  42. package/dist/connector/index.js +107 -1
  43. package/dist/index.js +150 -118
  44. package/dist/instance-lock.js +4 -12
  45. package/dist/order/alias-resolve.d.ts +13 -0
  46. package/dist/order/alias-resolve.js +22 -0
  47. package/dist/order/alias-store.d.ts +38 -0
  48. package/dist/order/alias-store.js +106 -0
  49. package/dist/persistence/atomic-write.d.ts +8 -2
  50. package/dist/persistence/atomic-write.js +23 -7
  51. package/dist/restart.js +2 -1
  52. package/dist/router/card-action-payload.d.ts +30 -0
  53. package/dist/router/card-action-payload.js +39 -0
  54. package/dist/router/card-helpers.d.ts +63 -0
  55. package/dist/router/card-helpers.js +146 -0
  56. package/dist/router/config/claude.js +30 -1
  57. package/dist/router/config/codex.js +29 -50
  58. package/dist/router/config/common/model-patch.d.ts +22 -0
  59. package/dist/router/config/common/model-patch.js +26 -0
  60. package/dist/router/config/common/render.js +5 -4
  61. package/dist/router/config/dsh.d.ts +51 -0
  62. package/dist/router/config/dsh.js +179 -0
  63. package/dist/router/config/index.d.ts +12 -0
  64. package/dist/router/config/index.js +28 -1
  65. package/dist/router/config/kimi.d.ts +4 -1
  66. package/dist/router/config/kimi.js +27 -0
  67. package/dist/router/config/opencode.js +18 -5
  68. package/dist/router/config/pi.js +4 -5
  69. package/dist/router/config/types.d.ts +17 -2
  70. package/dist/router/index.d.ts +76 -22
  71. package/dist/router/index.js +479 -548
  72. package/dist/router/utils.d.ts +2 -0
  73. package/dist/router/utils.js +16 -2
  74. package/dist/runner/agent-choices-common.d.ts +16 -0
  75. package/dist/runner/agent-choices-common.js +34 -0
  76. package/dist/runner/claude/runner.d.ts +47 -10
  77. package/dist/runner/claude/runner.js +117 -46
  78. package/dist/runner/claude/session.d.ts +166 -0
  79. package/dist/runner/claude/session.js +768 -0
  80. package/dist/runner/codex/app-server/protocol-types.d.ts +66 -39
  81. package/dist/runner/codex/app-server/protocol-types.js +2 -13
  82. package/dist/runner/codex/app-server/runner.d.ts +52 -59
  83. package/dist/runner/codex/app-server/runner.js +216 -338
  84. package/dist/runner/codex/app-server/translator.d.ts +8 -21
  85. package/dist/runner/codex/app-server/translator.js +45 -18
  86. package/dist/runner/codex/index.d.ts +0 -2
  87. package/dist/runner/codex/index.js +0 -2
  88. package/dist/runner/common/acp/protocol-helpers.d.ts +14 -0
  89. package/dist/runner/common/acp/protocol-helpers.js +21 -0
  90. package/dist/runner/common/acp/protocol-types.d.ts +271 -0
  91. package/dist/runner/common/acp/protocol-types.js +77 -0
  92. package/dist/runner/common/connection-based-runner.d.ts +111 -0
  93. package/dist/runner/common/connection-based-runner.js +261 -0
  94. package/dist/runner/{codex/app-server → common/jsonrpc}/client.d.ts +14 -7
  95. package/dist/runner/{codex/app-server → common/jsonrpc}/client.js +27 -18
  96. package/dist/runner/common/jsonrpc/connection-manager.d.ts +125 -0
  97. package/dist/runner/{codex/app-server → common/jsonrpc}/connection-manager.js +63 -28
  98. package/dist/runner/{codex/app-server → common/jsonrpc}/transport.d.ts +5 -4
  99. package/dist/runner/{codex/app-server → common/jsonrpc}/transport.js +18 -19
  100. package/dist/runner/common/jsonrpc/types.d.ts +32 -0
  101. package/dist/runner/common/jsonrpc/types.js +9 -0
  102. package/dist/runner/common/process-stopper.d.ts +2 -1
  103. package/dist/runner/common/process-stopper.js +1 -0
  104. package/dist/runner/common/runner-utils.d.ts +6 -13
  105. package/dist/runner/common/runner-utils.js +6 -47
  106. package/dist/runner/common/spawning-runner.d.ts +24 -70
  107. package/dist/runner/common/spawning-runner.js +98 -152
  108. package/dist/runner/dsh/client.d.ts +95 -0
  109. package/dist/runner/dsh/client.js +418 -0
  110. package/dist/runner/dsh/fake-dsh-server.d.ts +60 -0
  111. package/dist/runner/dsh/fake-dsh-server.js +156 -0
  112. package/dist/runner/dsh/index.d.ts +3 -0
  113. package/dist/runner/dsh/index.js +4 -0
  114. package/dist/runner/dsh/runner.d.ts +57 -0
  115. package/dist/runner/dsh/runner.js +191 -0
  116. package/dist/runner/dsh/translator.d.ts +28 -0
  117. package/dist/runner/dsh/translator.js +98 -0
  118. package/dist/runner/dsh/types.d.ts +155 -0
  119. package/dist/runner/dsh/types.js +14 -0
  120. package/dist/runner/index.d.ts +5 -4
  121. package/dist/runner/index.js +5 -4
  122. package/dist/runner/kimi/acp/runner.d.ts +106 -0
  123. package/dist/runner/kimi/acp/runner.js +516 -0
  124. package/dist/runner/kimi/acp/translator.d.ts +138 -0
  125. package/dist/runner/kimi/acp/translator.js +441 -0
  126. package/dist/runner/kimi/index.d.ts +1 -1
  127. package/dist/runner/kimi/index.js +1 -1
  128. package/dist/runner/opencode/acp/index.d.ts +1 -0
  129. package/dist/runner/opencode/acp/index.js +2 -0
  130. package/dist/runner/opencode/acp/runner.d.ts +121 -0
  131. package/dist/runner/opencode/acp/runner.js +429 -0
  132. package/dist/runner/opencode/acp/translator.d.ts +119 -0
  133. package/dist/runner/opencode/acp/translator.js +345 -0
  134. package/dist/runner/opencode/index.d.ts +1 -1
  135. package/dist/runner/opencode/index.js +1 -1
  136. package/dist/runner/pi/index.d.ts +1 -1
  137. package/dist/runner/pi/index.js +1 -1
  138. package/dist/runner/pi/rpc/client.d.ts +52 -0
  139. package/dist/runner/pi/rpc/client.js +114 -0
  140. package/dist/runner/pi/rpc/index.d.ts +4 -0
  141. package/dist/runner/pi/rpc/index.js +4 -0
  142. package/dist/runner/pi/rpc/protocol-types.d.ts +127 -0
  143. package/dist/runner/pi/rpc/protocol-types.js +21 -0
  144. package/dist/runner/pi/rpc/runner.d.ts +74 -0
  145. package/dist/runner/pi/rpc/runner.js +190 -0
  146. package/dist/runner/pi/rpc/translator.d.ts +55 -0
  147. package/dist/runner/pi/rpc/translator.js +258 -0
  148. package/dist/runner/probe.js +6 -1
  149. package/dist/runner/question-common.d.ts +26 -0
  150. package/dist/runner/question-common.js +42 -0
  151. package/dist/runner/registry.d.ts +7 -8
  152. package/dist/runner/registry.js +3 -4
  153. package/dist/runner/resolve-agent-choices.js +18 -59
  154. package/dist/runner/sync-agent-choices.js +16 -67
  155. package/dist/runner/types.d.ts +97 -14
  156. package/dist/session/claude/session-index.js +2 -3
  157. package/dist/session/claude/session-reader.js +3 -6
  158. package/dist/session/claude/sessions.js +43 -28
  159. package/dist/session/codex/rollout-reader.d.ts +2 -2
  160. package/dist/session/codex/rollout-reader.js +14 -17
  161. package/dist/session/codex/sessions.d.ts +1 -1
  162. package/dist/session/codex/sessions.js +2 -2
  163. package/dist/session/common/content-blocks.d.ts +7 -0
  164. package/dist/session/common/content-blocks.js +13 -9
  165. package/dist/session/common/jsonl.d.ts +8 -25
  166. package/dist/session/common/jsonl.js +126 -261
  167. package/dist/session/common/pagination.d.ts +28 -0
  168. package/dist/session/common/pagination.js +33 -0
  169. package/dist/session/dsh/index.d.ts +1 -0
  170. package/dist/session/dsh/index.js +2 -0
  171. package/dist/session/dsh/sessions.d.ts +39 -0
  172. package/dist/session/dsh/sessions.js +237 -0
  173. package/dist/session/index.d.ts +1 -0
  174. package/dist/session/index.js +1 -0
  175. package/dist/session/kimi/sessions.d.ts +34 -1
  176. package/dist/session/kimi/sessions.js +208 -98
  177. package/dist/session/opencode/sessions.d.ts +17 -3
  178. package/dist/session/opencode/sessions.js +29 -29
  179. package/dist/session/pi/sessions.d.ts +5 -1
  180. package/dist/session/pi/sessions.js +12 -16
  181. package/dist/session/session-store.d.ts +11 -1
  182. package/dist/session/session-store.js +75 -178
  183. package/dist/update/index.d.ts +2 -2
  184. package/dist/update/index.js +2 -2
  185. package/dist/update/install.d.ts +20 -2
  186. package/dist/update/install.js +51 -7
  187. package/dist/workspace/index.d.ts +4 -0
  188. package/dist/workspace/index.js +8 -1
  189. package/package.json +2 -1
  190. package/dist/runner/codex/app-server/connection-manager.d.ts +0 -56
  191. package/dist/runner/codex/argv.d.ts +0 -33
  192. package/dist/runner/codex/argv.js +0 -40
  193. package/dist/runner/codex/factory.d.ts +0 -29
  194. package/dist/runner/codex/factory.js +0 -39
  195. package/dist/runner/codex/jsonl.d.ts +0 -37
  196. package/dist/runner/codex/jsonl.js +0 -221
  197. package/dist/runner/codex/runner.d.ts +0 -66
  198. package/dist/runner/codex/runner.js +0 -129
  199. package/dist/runner/common/exec-translator.d.ts +0 -73
  200. package/dist/runner/common/exec-translator.js +0 -105
  201. package/dist/runner/kimi/jsonl.d.ts +0 -28
  202. package/dist/runner/kimi/jsonl.js +0 -143
  203. package/dist/runner/kimi/runner.d.ts +0 -49
  204. package/dist/runner/kimi/runner.js +0 -105
  205. package/dist/runner/opencode/argv.d.ts +0 -32
  206. package/dist/runner/opencode/argv.js +0 -35
  207. package/dist/runner/opencode/jsonl.d.ts +0 -68
  208. package/dist/runner/opencode/jsonl.js +0 -295
  209. package/dist/runner/opencode/runner.d.ts +0 -61
  210. package/dist/runner/opencode/runner.js +0 -93
  211. package/dist/runner/pi/jsonl.d.ts +0 -128
  212. package/dist/runner/pi/jsonl.js +0 -249
  213. package/dist/runner/pi/runner.d.ts +0 -36
  214. package/dist/runner/pi/runner.js +0 -76
  215. package/dist/session/common/catch-up.d.ts +0 -12
  216. package/dist/session/common/catch-up.js +0 -31
@@ -0,0 +1,237 @@
1
+ /**
2
+ * DshSessionReader — AgentSessionReader backed by the DSH Web Host over HTTP.
3
+ *
4
+ * The AgentSessionReader contract is fully synchronous (file-style readers),
5
+ * but DSH exposes only async HTTP. The reader therefore bridges with
6
+ * `spawnSync('curl', ...)` for its unary calls (session.list / session.history)
7
+ * — a synchronous HTTP round-trip to the local DSH host. This keeps the
8
+ * router/bridge interface contract intact without touching any upstream logic.
9
+ *
10
+ * listSessions: session.list → filter by cwd → sort by updatedAt desc → local
11
+ * pagination (DSH v1 has no cursor pagination).
12
+ * readSessionContent: session.history → map SessionEvents to display events +
13
+ * session-wide usage accumulation (assistant/message.usage).
14
+ */
15
+ import { spawnSync } from 'node:child_process';
16
+ import { getLogger } from '../../logger/index.js';
17
+ import { DEFAULT_DSH_HOST } from '../../config/index.js';
18
+ import { capEvents, paginate } from '../common/pagination.js';
19
+ import { truncateUtf8, TOOL_RESULT_MAX_BYTES } from '../../common/truncate.js';
20
+ /** Synchronous unary POST via curl (the reader interface is synchronous). */
21
+ function defaultSyncRequest(baseUrl, method, payload) {
22
+ const body = JSON.stringify({
23
+ type: 'client-request',
24
+ rpcId: `rpc-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
25
+ method,
26
+ payload,
27
+ });
28
+ const res = spawnSync('curl', [
29
+ '-s',
30
+ '-X',
31
+ 'POST',
32
+ `${baseUrl}/api/${method}`,
33
+ '-H',
34
+ 'content-type: application/json',
35
+ '--data',
36
+ body,
37
+ ], { encoding: 'utf-8', timeout: 15_000, maxBuffer: 64 * 1024 * 1024 });
38
+ if (res.error || res.status !== 0) {
39
+ throw new Error(`DSH ${method} failed: ${(res.error?.message ?? res.stderr) || 'unknown'}`);
40
+ }
41
+ let parsed;
42
+ try {
43
+ parsed = JSON.parse(res.stdout);
44
+ }
45
+ catch (err) {
46
+ throw new Error(`DSH ${method} returned non-JSON: ${err.message}`, {
47
+ cause: err,
48
+ });
49
+ }
50
+ if (parsed.result?.ok !== true) {
51
+ throw new Error(parsed.result?.error?.message ?? `DSH ${method} failed`);
52
+ }
53
+ return parsed.result.value;
54
+ }
55
+ export class DshSessionReader {
56
+ baseUrl;
57
+ syncRequest;
58
+ constructor(opts = {}) {
59
+ this.baseUrl = (opts.host ?? DEFAULT_DSH_HOST).replace(/\/$/, '');
60
+ this.syncRequest = opts.syncRequest ?? defaultSyncRequest;
61
+ }
62
+ unary(method, payload) {
63
+ return this.syncRequest(this.baseUrl, method, payload);
64
+ }
65
+ listSessions(cwd, opts) {
66
+ try {
67
+ const value = this.unary('session.list', {});
68
+ const items = value.items ?? [];
69
+ const filtered = items
70
+ .filter((i) => i.cwd === cwd)
71
+ .sort((a, b) => b.updatedAt - a.updatedAt || String(a.sessionId).localeCompare(String(b.sessionId)))
72
+ .map((i) => ({
73
+ sessionId: String(i.sessionId),
74
+ summary: '',
75
+ mtime: i.updatedAt,
76
+ ...(i.agentPreset ? { agentPreset: i.agentPreset } : {}),
77
+ }));
78
+ const { items: page, total } = paginate(filtered, opts ?? {});
79
+ return { sessions: page, total };
80
+ }
81
+ catch (error) {
82
+ getLogger().error(`[dsh-session-reader] listSessions error: ${error.message}`);
83
+ return { sessions: [], total: 0 };
84
+ }
85
+ }
86
+ getNewestSession(cwd) {
87
+ return this.listSessions(cwd, { limit: 1 }).sessions[0] ?? null;
88
+ }
89
+ readSessionContent(sessionId, cwd, opts) {
90
+ try {
91
+ const value = this.unary('session.history', {
92
+ sessionId,
93
+ maxMessages: opts?.maxEvents ?? 50,
94
+ });
95
+ const events = [];
96
+ let displayTitle;
97
+ let cumInput = 0;
98
+ let cumOutput = 0;
99
+ let cumCacheRead = 0;
100
+ let cumCacheWrite = 0;
101
+ let lastUsage;
102
+ for (const entry of value.events ?? []) {
103
+ const ev = entry.event;
104
+ if (!ev)
105
+ continue;
106
+ const contentEvents = mapEvent(ev);
107
+ events.push(...contentEvents.events);
108
+ if (contentEvents.title)
109
+ displayTitle = contentEvents.title;
110
+ const u = contentEvents.usage;
111
+ if (u) {
112
+ // Cumulative (session-wide): sum across ALL assistant/message usage.
113
+ cumInput += u.inputTokens ?? 0;
114
+ cumOutput += u.outputTokens ?? 0;
115
+ cumCacheRead += u.cacheReadTokens ?? 0;
116
+ cumCacheWrite += u.cacheWriteTokens ?? 0;
117
+ // Per-turn "current window" fields reflect the LAST assistant/message
118
+ // with usage (ccusage/`last_token_usage` 口径, AGENTS.md §9.21) — a
119
+ // multi-turn session's current context water-mark is the last turn's,
120
+ // not the accumulated total.
121
+ lastUsage = u;
122
+ }
123
+ }
124
+ let sessionUsage;
125
+ if (lastUsage) {
126
+ const input = lastUsage.inputTokens ?? 0;
127
+ const output = lastUsage.outputTokens ?? 0;
128
+ const cacheRead = lastUsage.cacheReadTokens ?? 0;
129
+ const cacheWrite = lastUsage.cacheWriteTokens ?? 0;
130
+ sessionUsage = {
131
+ inputTokens: input,
132
+ outputTokens: output,
133
+ contextLength: input + cacheRead + cacheWrite,
134
+ cacheReadTokens: cacheRead,
135
+ cacheCreationTokens: cacheWrite,
136
+ totalTokens: input + output + cacheRead + cacheWrite,
137
+ cumulativeTotalTokens: cumInput + cumOutput + cumCacheRead + cumCacheWrite,
138
+ cumulativeInputTokens: cumInput,
139
+ cumulativeOutputTokens: cumOutput,
140
+ cumulativeCacheReadTokens: cumCacheRead,
141
+ cumulativeCacheCreationTokens: cumCacheWrite,
142
+ };
143
+ }
144
+ return {
145
+ events: capEvents(events, opts?.maxEvents),
146
+ ...(sessionUsage ? { usage: sessionUsage } : {}),
147
+ ...(displayTitle ? { displayTitle } : {}),
148
+ };
149
+ }
150
+ catch (error) {
151
+ getLogger().error(`[dsh-session-reader] readSessionContent error: ${error.message}`);
152
+ return { events: [] };
153
+ }
154
+ }
155
+ isSessionActive(sessionId, cwd) {
156
+ try {
157
+ const value = this.unary('session.list', {});
158
+ const found = (value.items ?? []).find((i) => String(i.sessionId) === sessionId && i.cwd === cwd);
159
+ return found?.running === true;
160
+ }
161
+ catch (error) {
162
+ getLogger().error(`[dsh-session-reader] isSessionActive error: ${error.message}`);
163
+ return false;
164
+ }
165
+ }
166
+ }
167
+ /** Map one DSH SessionEvent to display content events (+ title/usage side effects). */
168
+ function mapEvent(ev) {
169
+ const out = { events: [] };
170
+ switch (ev.type) {
171
+ case 'user/message': {
172
+ const content = ev.data.content ?? [];
173
+ const text = content
174
+ .filter((c) => c.type === 'text')
175
+ .map((c) => c.text ?? '')
176
+ .join('');
177
+ out.events.push({ type: 'user', content: text, timestamp: new Date(ev.time).toISOString() });
178
+ break;
179
+ }
180
+ case 'assistant/message': {
181
+ const content = ev.data.message
182
+ ?.content ?? [];
183
+ const text = content
184
+ .filter((c) => c.type === 'text')
185
+ .map((c) => c.text ?? '')
186
+ .join('');
187
+ if (text)
188
+ out.events.push({
189
+ type: 'assistant',
190
+ content: text,
191
+ timestamp: new Date(ev.time).toISOString(),
192
+ });
193
+ const usage = ev.data.usage;
194
+ if (usage && typeof usage === 'object')
195
+ out.usage = usage;
196
+ break;
197
+ }
198
+ case 'tool/call': {
199
+ const name = String(ev.data.name ?? '');
200
+ const args = typeof ev.data.arguments === 'string' ? ev.data.arguments : '';
201
+ out.events.push({
202
+ type: 'tool_use',
203
+ content: `${name}(${truncateUtf8(args, 200)})`,
204
+ timestamp: new Date(ev.time).toISOString(),
205
+ });
206
+ break;
207
+ }
208
+ case 'tool/result': {
209
+ const msg = ev.data.message;
210
+ const raw = stringifyContent(msg?.content);
211
+ out.events.push({
212
+ type: 'tool_result',
213
+ content: truncateUtf8(raw, TOOL_RESULT_MAX_BYTES),
214
+ timestamp: new Date(ev.time).toISOString(),
215
+ });
216
+ break;
217
+ }
218
+ default:
219
+ break;
220
+ }
221
+ return out;
222
+ }
223
+ function stringifyContent(content) {
224
+ if (content == null)
225
+ return '[tool result]';
226
+ if (typeof content === 'string')
227
+ return content;
228
+ if (Array.isArray(content)) {
229
+ return content
230
+ .map((c) => c && typeof c === 'object' && 'text' in c
231
+ ? String(c.text)
232
+ : JSON.stringify(c))
233
+ .join('');
234
+ }
235
+ return JSON.stringify(content);
236
+ }
237
+ //# sourceMappingURL=sessions.js.map
@@ -5,3 +5,4 @@ export { CodexSessionReader } from './codex/index.js';
5
5
  export { OpencodeSessionReader } from './opencode/index.js';
6
6
  export { PiSessionReader } from './pi/index.js';
7
7
  export { KimiSessionReader } from './kimi/index.js';
8
+ export { DshSessionReader } from './dsh/index.js';
@@ -8,4 +8,5 @@ export { CodexSessionReader } from './codex/index.js';
8
8
  export { OpencodeSessionReader } from './opencode/index.js';
9
9
  export { PiSessionReader } from './pi/index.js';
10
10
  export { KimiSessionReader } from './kimi/index.js';
11
+ export { DshSessionReader } from './dsh/index.js';
11
12
  //# sourceMappingURL=index.js.map
@@ -9,6 +9,25 @@ export interface KimiSessionState {
9
9
  cwd?: string;
10
10
  lastPrompt?: string;
11
11
  }
12
+ /**
13
+ * Compaction completion record in wire.jsonl (§6.3 / kimi-code wire-manifest).
14
+ *
15
+ * REAL shape (2026-08-16 实弹 wire.jsonl + kimi-code 源码):
16
+ * - `context.apply_compaction`:带 `compactedCount` / `tokensBefore` /
17
+ * `tokensAfter`(以及 summary 等);
18
+ * - `full_compaction.complete`:只有 `{type, time}`。
19
+ * `messagesCompacted` 是死字段,真实 record 里不存在——禁止再写。
20
+ */
21
+ export interface KimiCompactionRecord {
22
+ type: 'full_compaction.complete' | 'context.apply_compaction';
23
+ /** 压缩掉的消息条数(仅 context.apply_compaction 携带)。 */
24
+ compactedCount?: number;
25
+ /** 压缩前上下文 token 水位(仅 context.apply_compaction 携带)。 */
26
+ tokensBefore?: number;
27
+ /** 压缩后上下文 token 水位(仅 context.apply_compaction 携带)。 */
28
+ tokensAfter?: number;
29
+ time: number;
30
+ }
12
31
  /** Detect schema version from state.json content */
13
32
  export declare function detectSchemaVersion(state: KimiSessionState): 1 | 2;
14
33
  /**
@@ -76,8 +95,22 @@ export declare class KimiSessionReader implements AgentSessionReader {
76
95
  readSessionContent(sessionId: string, cwd: string, opts?: {
77
96
  maxEvents?: number;
78
97
  }): SessionContent;
98
+ /**
99
+ * Read the compaction records (context.apply_compaction /
100
+ * full_compaction.complete) from a session's wire.jsonl.
101
+ *
102
+ * Same cwd guard as readSessionContent. Used by KimiAcpRunner.runCompact
103
+ * (R2) to wait for the background compaction to land before ending the run.
104
+ */
105
+ readCompactionRecords(sessionId: string, cwd: string): KimiCompactionRecord[];
106
+ /**
107
+ * Resolve the main wire.jsonl path for a session after passing the cwd
108
+ * guard (state.json + session index fallback). Returns null when the
109
+ * session is unknown, fails the guard, or has no wire file.
110
+ */
111
+ private resolveSessionWirePath;
79
112
  /**
80
113
  * Check if a session is currently active
81
114
  */
82
- isSessionActive(sessionId: string, _cwd: string): boolean;
115
+ isSessionActive(sessionId: string, cwd: string): boolean;
83
116
  }