lark-remote 0.5.13 → 0.5.14

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 (126) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/agent-kinds.d.ts +27 -0
  3. package/dist/agent-kinds.js +38 -0
  4. package/dist/bridge/approval-actions.d.ts +95 -0
  5. package/dist/bridge/approval-actions.js +104 -0
  6. package/dist/bridge/final-usage.d.ts +8 -17
  7. package/dist/bridge/final-usage.js +1 -18
  8. package/dist/bridge/index.d.ts +46 -39
  9. package/dist/bridge/index.js +201 -229
  10. package/dist/bridge/queue-manager.d.ts +25 -1
  11. package/dist/bridge/queue-manager.js +179 -160
  12. package/dist/bridge/run-approval.d.ts +2 -1
  13. package/dist/bridge/run-usage.d.ts +16 -30
  14. package/dist/bridge/run-usage.js +41 -50
  15. package/dist/bridge/session-writeback.d.ts +3 -2
  16. package/dist/card/approval-render.d.ts +3 -2
  17. package/dist/card/approval-render.js +3 -2
  18. package/dist/{router → card}/card-helpers.d.ts +7 -7
  19. package/dist/{router → card}/card-helpers.js +8 -8
  20. package/dist/card/card-session.d.ts +4 -2
  21. package/dist/card/card-session.js +8 -6
  22. package/dist/card/card-shared.d.ts +1 -1
  23. package/dist/card/card-shared.js +1 -1
  24. package/dist/card/final-answer-overflow.d.ts +0 -6
  25. package/dist/card/final-answer-overflow.js +1 -1
  26. package/dist/card/run-card-session.d.ts +2 -2
  27. package/dist/card/run-card-session.js +2 -2
  28. package/dist/card/run-renderer.js +7 -22
  29. package/dist/card/run-state.d.ts +28 -50
  30. package/dist/card/run-state.js +23 -0
  31. package/dist/card/usage-format.d.ts +30 -0
  32. package/dist/{router → card}/usage-format.js +3 -10
  33. package/dist/clone.js +6 -1
  34. package/dist/config/index.d.ts +16 -20
  35. package/dist/config/index.js +0 -16
  36. package/dist/config/pi-config.js +6 -4
  37. package/dist/connector/index.d.ts +2 -4
  38. package/dist/connector/index.js +7 -11
  39. package/dist/{runner/dsh → dsh}/auth.js +1 -1
  40. package/dist/dsh/protocol.d.ts +9 -0
  41. package/dist/dsh/protocol.js +61 -0
  42. package/dist/index.js +10 -5
  43. package/dist/model-catalog.d.ts +14 -0
  44. package/dist/model-catalog.js +25 -0
  45. package/dist/platform/path.d.ts +9 -0
  46. package/dist/platform/path.js +18 -0
  47. package/dist/router/active-run-usage.d.ts +4 -0
  48. package/dist/router/active-run-usage.js +12 -0
  49. package/dist/router/commands/ls.js +1 -1
  50. package/dist/router/commands/order.js +1 -1
  51. package/dist/router/commands/resume.d.ts +5 -4
  52. package/dist/router/commands/resume.js +4 -4
  53. package/dist/router/commands/ws.js +1 -1
  54. package/dist/router/config/claude.js +2 -1
  55. package/dist/router/config/common/render.d.ts +5 -1
  56. package/dist/router/config/common/render.js +6 -13
  57. package/dist/router/config/dsh.d.ts +1 -1
  58. package/dist/router/config/index.d.ts +1 -1
  59. package/dist/router/config/types.d.ts +11 -3
  60. package/dist/router/index.d.ts +41 -11
  61. package/dist/router/index.js +165 -226
  62. package/dist/runner/agent-choices-common.d.ts +1 -1
  63. package/dist/runner/claude/runner.d.ts +20 -2
  64. package/dist/runner/claude/runner.js +2 -15
  65. package/dist/runner/codex/app-server/runner.d.ts +3 -1
  66. package/dist/runner/codex/app-server/translator.d.ts +11 -0
  67. package/dist/runner/codex/app-server/translator.js +56 -149
  68. package/dist/runner/common/acp/base-acp-runner.d.ts +3 -1
  69. package/dist/runner/common/connection-based-runner.d.ts +3 -1
  70. package/dist/runner/common/jsonrpc/transport.js +17 -7
  71. package/dist/runner/dsh/client.d.ts +1 -4
  72. package/dist/runner/dsh/client.js +2 -55
  73. package/dist/runner/dsh/daemon.js +9 -2
  74. package/dist/runner/dsh/exit-cancel.js +1 -1
  75. package/dist/runner/dsh/mux-stream.js +21 -2
  76. package/dist/runner/dsh/runner.d.ts +21 -1
  77. package/dist/runner/dsh/runner.js +76 -73
  78. package/dist/runner/dsh/translator.d.ts +1 -1
  79. package/dist/runner/index.d.ts +1 -1
  80. package/dist/runner/kimi/acp/runner.d.ts +22 -1
  81. package/dist/runner/kimi/acp/runner.js +83 -60
  82. package/dist/runner/opencode/acp/error-monitor.d.ts +11 -0
  83. package/dist/runner/opencode/acp/error-monitor.js +31 -2
  84. package/dist/runner/opencode/acp/runner.d.ts +3 -1
  85. package/dist/runner/pi/rpc/runner.d.ts +2 -1
  86. package/dist/runner/probe.d.ts +1 -1
  87. package/dist/runner/probe.js +10 -9
  88. package/dist/runner/registry.d.ts +2 -1
  89. package/dist/runner/types.d.ts +20 -154
  90. package/dist/runner/types.js +4 -24
  91. package/dist/session/claude/session-index.d.ts +11 -4
  92. package/dist/session/claude/session-index.js +30 -8
  93. package/dist/session/claude/session-reader.d.ts +1 -1
  94. package/dist/session/claude/sessions.d.ts +2 -2
  95. package/dist/session/claude/sessions.js +41 -26
  96. package/dist/session/codex/rollout-reader.d.ts +1 -1
  97. package/dist/session/codex/rollout-reader.js +14 -13
  98. package/dist/session/codex/sessions.d.ts +1 -1
  99. package/dist/session/codex/sessions.js +4 -2
  100. package/dist/session/common/jsonl.js +7 -1
  101. package/dist/session/common/pagination.d.ts +2 -0
  102. package/dist/session/common/pagination.js +1 -1
  103. package/dist/session/common/recency.d.ts +6 -0
  104. package/dist/session/common/recency.js +7 -5
  105. package/dist/session/common/two-pass.d.ts +1 -1
  106. package/dist/session/common/usage-accumulator.d.ts +1 -1
  107. package/dist/session/dsh/sessions.d.ts +1 -1
  108. package/dist/session/dsh/sessions.js +37 -12
  109. package/dist/session/kimi/sessions.d.ts +1 -1
  110. package/dist/session/kimi/sessions.js +35 -8
  111. package/dist/session/opencode/sessions.d.ts +1 -1
  112. package/dist/session/opencode/sessions.js +51 -47
  113. package/dist/session/pi/sessions.d.ts +1 -1
  114. package/dist/session/pi/sessions.js +20 -7
  115. package/dist/session/registry.d.ts +2 -1
  116. package/dist/session/session-store.d.ts +1 -2
  117. package/dist/session/session-store.js +14 -7
  118. package/dist/session-contract.d.ts +178 -0
  119. package/dist/session-contract.js +9 -0
  120. package/package.json +1 -1
  121. package/dist/router/usage-format.d.ts +0 -60
  122. /package/dist/{runner/dsh → dsh}/auth.d.ts +0 -0
  123. /package/dist/{runner/dsh → dsh}/home.d.ts +0 -0
  124. /package/dist/{runner/dsh → dsh}/home.js +0 -0
  125. /package/dist/{runner/dsh → dsh}/types.d.ts +0 -0
  126. /package/dist/{runner/dsh → dsh}/types.js +0 -0
@@ -0,0 +1,178 @@
1
+ /**
2
+ * 会话读取契约:`AgentSessionReader` 与其数据类型。
3
+ *
4
+ * 中立模块——runner 与 session 两侧都只是它的实现方/消费方。此前住在
5
+ * `runner/types.ts` 里,于是 session/* 有十一处为了一个类型反向 import 上层
6
+ * runner(runner ↔ session 双向循环的一半);挪到这里后两边同向依赖它。
7
+ */
8
+ /** Unified session descriptor returned by every AgentSessionReader. */
9
+ export interface AgentSession {
10
+ sessionId: string;
11
+ summary: string;
12
+ mtime: number;
13
+ /** DSH:session 创建时固定的 preset;其他 agent 无此概念(undefined)。 */
14
+ agentPreset?: string;
15
+ /**
16
+ * 服务端投影已有的会话标题(DSH `projections.values.title`)。
17
+ *
18
+ * 与 `summary` 的区别:`summary` 是「首条用户输入」的兜底口径(claude /
19
+ * codex / pi / kimi 无标题字段),`title` 是 agent 自己起的标题。列表卡
20
+ * 用它决定标签文案(标题 / 会话摘要),缺省时回退 `summary`。
21
+ */
22
+ title?: string;
23
+ /**
24
+ * 最后一轮用户输入(服务端投影,单行预览)。
25
+ *
26
+ * 只给「列表响应里已顺带返回」的 reader 用(DSH 的 `turnOutline` 末条),
27
+ * 目的是让列表卡不必为每行做一次全量内容读取。
28
+ */
29
+ lastUserMessage?: string;
30
+ /** 最后一轮助手输出(服务端投影已截断,单行预览)。 */
31
+ lastAssistantMessage?: string;
32
+ }
33
+ /** A single renderable event from session history. */
34
+ export interface AgentSessionContentEvent {
35
+ type: string;
36
+ /** 正文(展开后的面板内容)。 */
37
+ content: string;
38
+ /**
39
+ * 面板标题(可选,覆盖 reader 的默认标签)。
40
+ *
41
+ * 折叠面板默认只显示标题:工具调用这种"标题即全部信息"的事件必须把
42
+ * `bash — npm test` 这类摘要放进标题,否则折叠态只剩 `🔧 工具调用`。
43
+ */
44
+ title?: string;
45
+ timestamp?: string;
46
+ }
47
+ export interface AgentSessionUsage {
48
+ inputTokens: number;
49
+ outputTokens: number;
50
+ contextLength: number;
51
+ /** Agent 上报的当前模型 context window 上限(codex token_count.info.model_context_window)。
52
+ * 仅 codex 提供;缺省时卡片只显示绝对量、不显示百分比。 */
53
+ contextLimit?: number;
54
+ /** Claude auto-compact 次数(数 compact_boundary 事件);codex/opencode 无此概念,留 undefined。 */
55
+ compactCount?: number;
56
+ /** 压缩前上下文水位(codex compact 后从会话 jsonl 读取,仅会话以压缩收尾时有值)。 */
57
+ compactPreContextLength?: number;
58
+ /** 从缓存读取的 token 数(节省的费用)。 */
59
+ cacheReadTokens?: number;
60
+ /** 新建缓存的 token 数。 */
61
+ cacheCreationTokens?: number;
62
+ /** Agent 声明的总量;展示用 max(total, 分项和)。 */
63
+ totalTokens?: number;
64
+ /** 会话累计 total token(所有 run 之和,含本次)。用于 Run 卡片"累计"展示。 */
65
+ cumulativeTotalTokens?: number;
66
+ /** 会话累计 input token(所有 run 之和,含本次)。用于 Run 卡片"累计"展示。 */
67
+ cumulativeInputTokens?: number;
68
+ /** 会话累计 output token(所有 run 之和,含本次)。 */
69
+ cumulativeOutputTokens?: number;
70
+ /** 会话累计 cache read token(所有 run 之和)。用于 Run 卡片展示累计缓存命中。 */
71
+ cumulativeCacheReadTokens?: number;
72
+ /** 会话累计 cache creation token(所有 run 之和)。 */
73
+ cumulativeCacheCreationTokens?: number;
74
+ }
75
+ /**
76
+ * 一张 run 卡的用量快照:`AgentSessionUsage` 的可选形态 + 只有 live 侧有的
77
+ * 推理计数。桥侧记账、reducer 写入 RunState、渲染层格式化都吃这一份——
78
+ * 字段清单原先手抄在 6 个 interface 里(§9.21「五处一致」靠人记),
79
+ * 新增一个 usage 字段要同步改 6 处,漏一处就是卡片少一行。
80
+ *
81
+ * 中立层:card / bridge / runner / router 都引用它,谁也不向上依赖。
82
+ */
83
+ export type UsageSnapshot = Partial<AgentSessionUsage> & {
84
+ /** 推理 token(pi usage.reasoning 累加);reader 契约里没有,只有 live 事件带。 */
85
+ reasoningTokens?: number;
86
+ };
87
+ /** Unified session content payload returned by every AgentSessionReader. */
88
+ export interface SessionContent {
89
+ events: AgentSessionContentEvent[];
90
+ usage?: AgentSessionUsage;
91
+ aiTitle?: string;
92
+ recap?: string;
93
+ displayTitle?: string;
94
+ }
95
+ /**
96
+ * Lightweight session summary used by `/resume` list prefetch.
97
+ *
98
+ * Carries only the display fields (title / recap / usage) — **no `events`
99
+ * array**. Readers that can extract these without constructing the full event
100
+ * list (e.g. codex, which would otherwise JSON.parse every response_item and
101
+ * build an `events[]` that the prefetch immediately discards) implement the
102
+ * optional `readSessionSummary` on `AgentSessionReader`.
103
+ */
104
+ export interface SessionSummary {
105
+ aiTitle?: string;
106
+ recap?: string;
107
+ displayTitle?: string;
108
+ usage?: AgentSessionUsage;
109
+ }
110
+ /**
111
+ * 手动压缩的在途状态(由会话里的 begin/terminal 记录重建)。
112
+ * 只有把压缩写成 wire 状态机的 agent 能提供,见
113
+ * {@link AgentSessionReader.readCompactionState}。
114
+ */
115
+ export interface CompactionState {
116
+ inFlight: boolean;
117
+ /** 在途 begin 的 time(epoch ms)。 */
118
+ inFlightSince?: number;
119
+ }
120
+ /**
121
+ * Reads an agent's session history. Each agent implements its own (Claude reads
122
+ * `~/.claude/projects/`, Codex calls `thread/list`, OpenCode calls `GET /session`).
123
+ *
124
+ * Q-C decision: `projectsDir` and other agent-specific path config live on the
125
+ * concrete reader's constructor, NOT on these method opts. The router/bridge
126
+ * depend only on this interface and never pass path config.
127
+ */
128
+ export interface AgentSessionReader {
129
+ /**
130
+ * List sessions for a cwd, newest first by mtime.
131
+ *
132
+ * `sessions` is the page `[offset, offset+limit)` of the full set ordered
133
+ * by mtime desc, with same-mtime ties broken by a deterministic secondary
134
+ * key (sessionId/file path) so ordering is stable across calls. When
135
+ * `limit` is omitted, codex/pi/kimi return their default-sized page
136
+ * (default 20); claude/opencode return the full remaining set from
137
+ * `offset`. `total` is ALWAYS the size of the full cwd-matched set before
138
+ * pagination — never the truncated page length. A negative `offset` is
139
+ * clamped to 0 (first page).
140
+ */
141
+ listSessions(cwd: string, opts?: {
142
+ limit?: number;
143
+ offset?: number;
144
+ }): {
145
+ sessions: AgentSession[];
146
+ total: number;
147
+ };
148
+ getNewestSession(cwd: string): AgentSession | null;
149
+ readSessionContent(sessionId: string, cwd: string, opts?: {
150
+ maxEvents?: number;
151
+ }): SessionContent;
152
+ /**
153
+ * Optional lightweight summary for list-prefetch.
154
+ *
155
+ * Returns only the display fields (aiTitle/recap/displayTitle/usage) without
156
+ * constructing the full `events` array. When absent, callers fall back to
157
+ * `readSessionContent` and take the needed fields.
158
+ */
159
+ readSessionSummary?(sessionId: string, cwd: string): SessionSummary;
160
+ /**
161
+ * 这个会话此刻是否还在被使用。**证据强度按 reader 不同,调用方必须知道自己
162
+ * 问的是哪一个**:
163
+ *
164
+ * - DSH:服务端事实(session 有在跑的 turn)。启动自动恢复路径用它,
165
+ * 见 `src/index.ts` 的 `stillRunning` 分支。
166
+ * - claude/codex/opencode/pi/kimi:只有「最近一段时间有写入」这一层文件证据
167
+ * (mtime + 末行终态标记),拿它当 turn 在跑会每次误报。
168
+ *
169
+ * 「agent 现在忙不忙」的运行时真相仍归 `bridge.isBusyFor(cwd)`(内存态,
170
+ * 见 cmdPs);本方法是文件/服务端侧的补充探针,不是它的替代品。
171
+ */
172
+ isSessionActive(sessionId: string, cwd: string): boolean;
173
+ /**
174
+ * 手动压缩是否已在途(只有把压缩写成 wire 状态机的 agent 能提供,目前 kimi)。
175
+ * 未实现 = 该 agent 没有这个概念,调用方按「不在途」处理。
176
+ */
177
+ readCompactionState?(sessionId: string, cwd: string): CompactionState;
178
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 会话读取契约:`AgentSessionReader` 与其数据类型。
3
+ *
4
+ * 中立模块——runner 与 session 两侧都只是它的实现方/消费方。此前住在
5
+ * `runner/types.ts` 里,于是 session/* 有十一处为了一个类型反向 import 上层
6
+ * runner(runner ↔ session 双向循环的一半);挪到这里后两边同向依赖它。
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=session-contract.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lark-remote",
3
- "version": "0.5.13",
3
+ "version": "0.5.14",
4
4
  "description": "Feishu (Lark) private-chat bridge to local coding agents — Claude Code / Codex / opencode / pi / kimi, with live-streaming CardKit 2.0 cards",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,60 +0,0 @@
1
- /**
2
- * Format session/run usage stats (context, compact count, tokens, cost) into
3
- * the display strings shown on cards. Pure — no Router state.
4
- */
5
- import type { ActiveRunSnapshot } from '../bridge/index.js';
6
- export interface SessionDisplayUsage {
7
- contextLength?: number;
8
- /** 当前模型 context window 上限(仅 codex 提供);用于渲染 "Context - X (Y%)"。 */
9
- contextLimit?: number;
10
- compactCount?: number;
11
- cacheReadTokens?: number;
12
- cacheCreationTokens?: number;
13
- }
14
- export declare function activeRunUsage(activeRun: ActiveRunSnapshot | undefined): SessionDisplayUsage | undefined;
15
- /**
16
- * Format usage stats (context length, compact count, cache tokens) into a display string.
17
- * Each stat on its own line with blank lines between sections.
18
- * @param usage - Usage stats object
19
- * @param options - Optional display options (showResult adds result line)
20
- */
21
- export declare function formatUsageStats(usage?: {
22
- contextLength?: number;
23
- contextLimit?: number;
24
- compactCount?: number;
25
- /** 压缩前上下文水位;与 contextLength(压缩后)成对出现在 Compact 卡上。 */
26
- compactPreContextLength?: number;
27
- cacheReadTokens?: number;
28
- cacheCreationTokens?: number;
29
- /** Agent-declared total; when present the display uses max(total, sum of parts). */
30
- totalTokens?: number;
31
- /** Real input tokens from the agent's result event. When present, used
32
- * directly for the "Input token" line instead of contextLength+cache. */
33
- inputTokens?: number;
34
- /** Real output tokens from the agent's result event. When present, used
35
- * directly instead of the 10% estimate. */
36
- outputTokens?: number;
37
- /** Session-cumulative total/input/output (all runs), from session jsonl. When
38
- * present, appended as "· 累计 X" on the Total/Input/Output lines. */
39
- cumulativeTotalTokens?: number;
40
- cumulativeInputTokens?: number;
41
- cumulativeOutputTokens?: number;
42
- /** Session-cumulative cache read tokens (all runs). */
43
- cumulativeCacheReadTokens?: number;
44
- /** Session-cumulative cache creation tokens (all runs). */
45
- cumulativeCacheCreationTokens?: number;
46
- /** 实际生效模型(system.init 携带)。非空字符串才显示。 */
47
- model?: string;
48
- /** 本次 run 花费(USD)。存在才显示。 */
49
- costUsd?: number;
50
- /** 推理 token(pi 提供)。> 0 才显示。 */
51
- reasoningTokens?: number;
52
- }, options?: {
53
- showResult?: boolean;
54
- result?: string;
55
- /**
56
- * 首行状态文案。默认 `✅ 已完成`;goal 仍 active 的收尾卡必须换掉它——
57
- * 本轮 turn 结束不等于任务结束。
58
- */
59
- completedLabel?: string;
60
- }): string;
File without changes
File without changes
File without changes
File without changes
File without changes