lark-remote 0.1.0
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 +52 -0
- package/LICENSE +21 -0
- package/README.en.md +162 -0
- package/README.md +161 -0
- package/dist/binder.d.ts +57 -0
- package/dist/binder.js +105 -0
- package/dist/bridge/index.d.ts +338 -0
- package/dist/bridge/index.js +1281 -0
- package/dist/bridge/queue-manager.d.ts +277 -0
- package/dist/bridge/queue-manager.js +729 -0
- package/dist/card/bash-card-session.d.ts +78 -0
- package/dist/card/bash-card-session.js +174 -0
- package/dist/card/bash-renderer.d.ts +24 -0
- package/dist/card/bash-renderer.js +187 -0
- package/dist/card/card-budget.d.ts +31 -0
- package/dist/card/card-budget.js +280 -0
- package/dist/card/card-session.d.ts +83 -0
- package/dist/card/card-session.js +185 -0
- package/dist/card/card-shared.d.ts +28 -0
- package/dist/card/card-shared.js +99 -0
- package/dist/card/collapsible.d.ts +26 -0
- package/dist/card/collapsible.js +87 -0
- package/dist/card/run-card-session.d.ts +78 -0
- package/dist/card/run-card-session.js +165 -0
- package/dist/card/run-renderer.d.ts +66 -0
- package/dist/card/run-renderer.js +841 -0
- package/dist/card/run-state.d.ts +103 -0
- package/dist/card/run-state.js +313 -0
- package/dist/card/text-truncate.d.ts +56 -0
- package/dist/card/text-truncate.js +184 -0
- package/dist/card/time.d.ts +1 -0
- package/dist/card/time.js +14 -0
- package/dist/card/tool-render.d.ts +25 -0
- package/dist/card/tool-render.js +176 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.js +89 -0
- package/dist/common/guards.d.ts +37 -0
- package/dist/common/guards.js +65 -0
- package/dist/config/codex-config.d.ts +113 -0
- package/dist/config/codex-config.js +428 -0
- package/dist/config/dir.d.ts +17 -0
- package/dist/config/dir.js +81 -0
- package/dist/config/index.d.ts +219 -0
- package/dist/config/index.js +388 -0
- package/dist/config/kimi-config.d.ts +33 -0
- package/dist/config/kimi-config.js +111 -0
- package/dist/config/opencode-config.d.ts +20 -0
- package/dist/config/opencode-config.js +124 -0
- package/dist/config/pi-config.d.ts +49 -0
- package/dist/config/pi-config.js +151 -0
- package/dist/config/wizard.d.ts +12 -0
- package/dist/config/wizard.js +84 -0
- package/dist/connector/file-limits.d.ts +7 -0
- package/dist/connector/file-limits.js +8 -0
- package/dist/connector/index.d.ts +86 -0
- package/dist/connector/index.js +340 -0
- package/dist/error-classification.d.ts +15 -0
- package/dist/error-classification.js +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +580 -0
- package/dist/instance-lock.d.ts +30 -0
- package/dist/instance-lock.js +184 -0
- package/dist/logger/index.d.ts +57 -0
- package/dist/logger/index.js +178 -0
- package/dist/order/index.d.ts +27 -0
- package/dist/order/index.js +90 -0
- package/dist/persistence/atomic-write.d.ts +10 -0
- package/dist/persistence/atomic-write.js +65 -0
- package/dist/persistence/load-json-file.d.ts +9 -0
- package/dist/persistence/load-json-file.js +23 -0
- package/dist/restart.d.ts +24 -0
- package/dist/restart.js +73 -0
- package/dist/router/card-helpers.d.ts +28 -0
- package/dist/router/card-helpers.js +65 -0
- package/dist/router/config/claude.d.ts +14 -0
- package/dist/router/config/claude.js +72 -0
- package/dist/router/config/codex.d.ts +22 -0
- package/dist/router/config/codex.js +100 -0
- package/dist/router/config/common/render.d.ts +16 -0
- package/dist/router/config/common/render.js +158 -0
- package/dist/router/config/index.d.ts +18 -0
- package/dist/router/config/index.js +38 -0
- package/dist/router/config/kimi.d.ts +21 -0
- package/dist/router/config/kimi.js +63 -0
- package/dist/router/config/opencode.d.ts +12 -0
- package/dist/router/config/opencode.js +44 -0
- package/dist/router/config/pi.d.ts +12 -0
- package/dist/router/config/pi.js +50 -0
- package/dist/router/config/types.d.ts +43 -0
- package/dist/router/config/types.js +8 -0
- package/dist/router/index.d.ts +318 -0
- package/dist/router/index.js +2715 -0
- package/dist/router/order-exec-dispatch.d.ts +30 -0
- package/dist/router/order-exec-dispatch.js +48 -0
- package/dist/router/utils.d.ts +44 -0
- package/dist/router/utils.js +116 -0
- package/dist/runner/bash/index.d.ts +4 -0
- package/dist/runner/bash/index.js +5 -0
- package/dist/runner/bash/runner.d.ts +55 -0
- package/dist/runner/bash/runner.js +213 -0
- package/dist/runner/claude/index.d.ts +4 -0
- package/dist/runner/claude/index.js +5 -0
- package/dist/runner/claude/runner.d.ts +29 -0
- package/dist/runner/claude/runner.js +83 -0
- package/dist/runner/codex/argv.d.ts +33 -0
- package/dist/runner/codex/argv.js +40 -0
- package/dist/runner/codex/index.d.ts +1 -0
- package/dist/runner/codex/index.js +2 -0
- package/dist/runner/codex/jsonl.d.ts +37 -0
- package/dist/runner/codex/jsonl.js +221 -0
- package/dist/runner/codex/runner.d.ts +65 -0
- package/dist/runner/codex/runner.js +124 -0
- package/dist/runner/common/exec-translator.d.ts +73 -0
- package/dist/runner/common/exec-translator.js +105 -0
- package/dist/runner/common/jsonl-stream.d.ts +39 -0
- package/dist/runner/common/jsonl-stream.js +203 -0
- package/dist/runner/common/process-stopper.d.ts +28 -0
- package/dist/runner/common/process-stopper.js +79 -0
- package/dist/runner/common/runner-utils.d.ts +21 -0
- package/dist/runner/common/runner-utils.js +65 -0
- package/dist/runner/common/spawn-heartbeat.d.ts +33 -0
- package/dist/runner/common/spawn-heartbeat.js +51 -0
- package/dist/runner/common/spawning-runner.d.ts +321 -0
- package/dist/runner/common/spawning-runner.js +634 -0
- package/dist/runner/common/usage.d.ts +31 -0
- package/dist/runner/common/usage.js +29 -0
- package/dist/runner/index.d.ts +19 -0
- package/dist/runner/index.js +24 -0
- package/dist/runner/kimi/index.d.ts +1 -0
- package/dist/runner/kimi/index.js +2 -0
- package/dist/runner/kimi/jsonl.d.ts +28 -0
- package/dist/runner/kimi/jsonl.js +143 -0
- package/dist/runner/kimi/runner.d.ts +50 -0
- package/dist/runner/kimi/runner.js +105 -0
- package/dist/runner/opencode/argv.d.ts +32 -0
- package/dist/runner/opencode/argv.js +35 -0
- package/dist/runner/opencode/index.d.ts +1 -0
- package/dist/runner/opencode/index.js +2 -0
- package/dist/runner/opencode/jsonl.d.ts +68 -0
- package/dist/runner/opencode/jsonl.js +295 -0
- package/dist/runner/opencode/runner.d.ts +63 -0
- package/dist/runner/opencode/runner.js +93 -0
- package/dist/runner/pi/index.d.ts +1 -0
- package/dist/runner/pi/index.js +2 -0
- package/dist/runner/pi/jsonl.d.ts +128 -0
- package/dist/runner/pi/jsonl.js +249 -0
- package/dist/runner/pi/runner.d.ts +37 -0
- package/dist/runner/pi/runner.js +76 -0
- package/dist/runner/registry.d.ts +54 -0
- package/dist/runner/registry.js +75 -0
- package/dist/runner/resolve-agent-choices.d.ts +7 -0
- package/dist/runner/resolve-agent-choices.js +76 -0
- package/dist/runner/sync-agent-choices.d.ts +6 -0
- package/dist/runner/sync-agent-choices.js +73 -0
- package/dist/runner/types.d.ts +250 -0
- package/dist/runner/types.js +8 -0
- package/dist/session/claude/index.d.ts +1 -0
- package/dist/session/claude/index.js +2 -0
- package/dist/session/claude/session-reader.d.ts +34 -0
- package/dist/session/claude/session-reader.js +46 -0
- package/dist/session/claude/sessions.d.ts +53 -0
- package/dist/session/claude/sessions.js +528 -0
- package/dist/session/codex/index.d.ts +1 -0
- package/dist/session/codex/index.js +2 -0
- package/dist/session/codex/rollout-reader.d.ts +88 -0
- package/dist/session/codex/rollout-reader.js +473 -0
- package/dist/session/codex/sessions.d.ts +21 -0
- package/dist/session/codex/sessions.js +40 -0
- package/dist/session/common/catch-up.d.ts +12 -0
- package/dist/session/common/catch-up.js +31 -0
- package/dist/session/common/constants.d.ts +11 -0
- package/dist/session/common/constants.js +12 -0
- package/dist/session/common/content-blocks.d.ts +37 -0
- package/dist/session/common/content-blocks.js +68 -0
- package/dist/session/common/jsonl.d.ts +77 -0
- package/dist/session/common/jsonl.js +351 -0
- package/dist/session/common/usage-accumulator.d.ts +58 -0
- package/dist/session/common/usage-accumulator.js +72 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.js +11 -0
- package/dist/session/kimi/index.d.ts +1 -0
- package/dist/session/kimi/index.js +2 -0
- package/dist/session/kimi/sessions.d.ts +81 -0
- package/dist/session/kimi/sessions.js +527 -0
- package/dist/session/opencode/index.d.ts +1 -0
- package/dist/session/opencode/index.js +2 -0
- package/dist/session/opencode/sessions.d.ts +81 -0
- package/dist/session/opencode/sessions.js +388 -0
- package/dist/session/pi/index.d.ts +1 -0
- package/dist/session/pi/index.js +2 -0
- package/dist/session/pi/sessions.d.ts +27 -0
- package/dist/session/pi/sessions.js +399 -0
- package/dist/session/registry.d.ts +12 -0
- package/dist/session/registry.js +20 -0
- package/dist/session/session-store.d.ts +86 -0
- package/dist/session/session-store.js +450 -0
- package/dist/startup-contact.d.ts +18 -0
- package/dist/startup-contact.js +51 -0
- package/dist/workspace/index.d.ts +19 -0
- package/dist/workspace/index.js +53 -0
- package/package.json +93 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner 模块类型定义
|
|
3
|
+
*
|
|
4
|
+
* 本文件包含所有 Agent 相关的类型定义,从 runner/index.ts 提取。
|
|
5
|
+
* 所有下游模块应从本文件 import 类型,而非直接依赖实现。
|
|
6
|
+
*/
|
|
7
|
+
export interface SystemInitEvent {
|
|
8
|
+
type: 'system';
|
|
9
|
+
subtype: 'init';
|
|
10
|
+
session_id: string;
|
|
11
|
+
cwd: string;
|
|
12
|
+
model: string;
|
|
13
|
+
timestamp?: string;
|
|
14
|
+
}
|
|
15
|
+
interface SystemCompactEvent {
|
|
16
|
+
type: 'system';
|
|
17
|
+
subtype: 'compact_boundary';
|
|
18
|
+
timestamp?: string;
|
|
19
|
+
compactMetadata?: {
|
|
20
|
+
postTokens: number;
|
|
21
|
+
preTokens: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface ThinkingContent {
|
|
25
|
+
type: 'thinking';
|
|
26
|
+
thinking: string;
|
|
27
|
+
}
|
|
28
|
+
interface TextContent {
|
|
29
|
+
type: 'text';
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
32
|
+
interface ToolUseContent {
|
|
33
|
+
type: 'tool_use';
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
input: unknown;
|
|
37
|
+
}
|
|
38
|
+
interface ToolResultContent {
|
|
39
|
+
type: 'tool_result';
|
|
40
|
+
tool_use_id: string;
|
|
41
|
+
content: unknown;
|
|
42
|
+
is_error: boolean;
|
|
43
|
+
}
|
|
44
|
+
export type AssistantContent = ThinkingContent | TextContent | ToolUseContent;
|
|
45
|
+
export interface AssistantEvent {
|
|
46
|
+
type: 'assistant';
|
|
47
|
+
timestamp?: string;
|
|
48
|
+
message: {
|
|
49
|
+
content: AssistantContent[];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface UserEvent {
|
|
53
|
+
type: 'user';
|
|
54
|
+
timestamp?: string;
|
|
55
|
+
message: {
|
|
56
|
+
content: ToolResultContent[];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface ResultEvent {
|
|
60
|
+
type: 'result';
|
|
61
|
+
subtype: 'success' | 'error';
|
|
62
|
+
session_id: string;
|
|
63
|
+
timestamp?: string;
|
|
64
|
+
usage?: {
|
|
65
|
+
/** Non-cached input tokens. For codex this is raw `input_tokens` minus
|
|
66
|
+
* `cached_input_tokens`; for pi/claude/opencode the raw value is already
|
|
67
|
+
* non-cached. Aligns with ccusage's displayed-input semantics. */
|
|
68
|
+
input_tokens: number;
|
|
69
|
+
output_tokens: number;
|
|
70
|
+
cache_read_tokens?: number;
|
|
71
|
+
/** Cache-write (prompt-cache creation) tokens. Codex has none (0). */
|
|
72
|
+
cache_creation_tokens?: number;
|
|
73
|
+
/** Anthropic 原生命名,claude CLI 的 result 事件使用此字段名。 */
|
|
74
|
+
cache_read_input_tokens?: number;
|
|
75
|
+
cache_creation_input_tokens?: number;
|
|
76
|
+
/** Agent-declared total; when present the display uses max(total, sum of parts). */
|
|
77
|
+
total_tokens?: number;
|
|
78
|
+
};
|
|
79
|
+
total_cost_usd?: number;
|
|
80
|
+
errorMessage?: string;
|
|
81
|
+
}
|
|
82
|
+
/** TokenUsage = ResultEvent['usage'] without the optional wrapper.
|
|
83
|
+
*
|
|
84
|
+
* Usage sites that have already checked `event.usage` is present can type the
|
|
85
|
+
* value as `TokenUsage` to avoid repeated `!` assertions.
|
|
86
|
+
*/
|
|
87
|
+
export type TokenUsage = NonNullable<ResultEvent['usage']>;
|
|
88
|
+
/** Plan event — for agents that report execution plans (e.g. Codex). */
|
|
89
|
+
export interface PlanEvent {
|
|
90
|
+
type: 'plan';
|
|
91
|
+
plan: string;
|
|
92
|
+
timestamp?: string;
|
|
93
|
+
}
|
|
94
|
+
/** File change event — for agents that report file modifications (e.g. Codex). */
|
|
95
|
+
export interface FileChangeEvent {
|
|
96
|
+
type: 'file_change';
|
|
97
|
+
path: string;
|
|
98
|
+
diff?: string;
|
|
99
|
+
operation: 'create' | 'edit' | 'delete' | 'read';
|
|
100
|
+
timestamp?: string;
|
|
101
|
+
}
|
|
102
|
+
export type AgentEvent = SystemInitEvent | SystemCompactEvent | AssistantEvent | UserEvent | ResultEvent | PlanEvent | FileChangeEvent;
|
|
103
|
+
export interface SpawnOptions {
|
|
104
|
+
cwd: string;
|
|
105
|
+
sessionId?: string;
|
|
106
|
+
model?: string;
|
|
107
|
+
effort?: string;
|
|
108
|
+
/** Codex reasoning effort override (per-run, takes precedence over constructor default). */
|
|
109
|
+
reasoningEffort?: string;
|
|
110
|
+
settings?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Seam (§3): the contract any agent runner (claude/codex/opencode/pi/kimi)
|
|
114
|
+
* must satisfy for the router/bridge.
|
|
115
|
+
* Declared here so callers depend on the interface, not the concrete
|
|
116
|
+
* runner classes — test stubs satisfy this structurally.
|
|
117
|
+
*/
|
|
118
|
+
export interface Runner {
|
|
119
|
+
readonly isRunning: boolean;
|
|
120
|
+
run(message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
|
|
121
|
+
/**
|
|
122
|
+
* Stop the running process. SIGTERM → grace → SIGKILL on the per-workspace
|
|
123
|
+
* proc. `immediate: true` skips the grace period and SIGKILLs directly
|
|
124
|
+
* (used by user-initiated `/stop`).
|
|
125
|
+
*/
|
|
126
|
+
stop(opts?: {
|
|
127
|
+
immediate?: boolean;
|
|
128
|
+
}): Promise<void>;
|
|
129
|
+
killOrphan(): void;
|
|
130
|
+
registerExitHandlers(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Remove the runner from the process-level exit dispatcher (P1-1). Called by
|
|
133
|
+
* the bridge when the (cwd, kind) cache slot is evicted so the instance is
|
|
134
|
+
* not retained by the singleton dispatcher. Optional so test stubs that only
|
|
135
|
+
* satisfy `registerExitHandlers` remain structurally valid.
|
|
136
|
+
*/
|
|
137
|
+
unregisterExitHandlers?(): void;
|
|
138
|
+
}
|
|
139
|
+
export type AgentKind = 'claude' | 'codex' | 'opencode' | 'pi' | 'kimi';
|
|
140
|
+
/** Unified session descriptor returned by every AgentSessionReader. */
|
|
141
|
+
export interface AgentSession {
|
|
142
|
+
sessionId: string;
|
|
143
|
+
summary: string;
|
|
144
|
+
mtime: number;
|
|
145
|
+
}
|
|
146
|
+
/** A single renderable event from session history. */
|
|
147
|
+
export interface AgentSessionContentEvent {
|
|
148
|
+
type: string;
|
|
149
|
+
content: string;
|
|
150
|
+
timestamp?: string;
|
|
151
|
+
}
|
|
152
|
+
export interface AgentSessionUsage {
|
|
153
|
+
inputTokens: number;
|
|
154
|
+
outputTokens: number;
|
|
155
|
+
contextLength: number;
|
|
156
|
+
/** Claude auto-compact 次数(数 compact_boundary 事件);codex/opencode 无此概念,留 undefined。 */
|
|
157
|
+
compactCount?: number;
|
|
158
|
+
/** 从缓存读取的 token 数(节省的费用)。 */
|
|
159
|
+
cacheReadTokens?: number;
|
|
160
|
+
/** 新建缓存的 token 数。 */
|
|
161
|
+
cacheCreationTokens?: number;
|
|
162
|
+
/** Agent 声明的总量;展示用 max(total, 分项和)。 */
|
|
163
|
+
totalTokens?: number;
|
|
164
|
+
/** 会话累计 total token(所有 run 之和,含本次)。用于 Run 卡片"累计"展示。 */
|
|
165
|
+
cumulativeTotalTokens?: number;
|
|
166
|
+
/** 会话累计 input token(所有 run 之和,含本次)。用于 Run 卡片"累计"展示。 */
|
|
167
|
+
cumulativeInputTokens?: number;
|
|
168
|
+
/** 会话累计 output token(所有 run 之和,含本次)。 */
|
|
169
|
+
cumulativeOutputTokens?: number;
|
|
170
|
+
/** 会话累计 cache read token(所有 run 之和)。用于 Run 卡片展示累计缓存命中。 */
|
|
171
|
+
cumulativeCacheReadTokens?: number;
|
|
172
|
+
/** 会话累计 cache creation token(所有 run 之和)。 */
|
|
173
|
+
cumulativeCacheCreationTokens?: number;
|
|
174
|
+
}
|
|
175
|
+
/** Unified session content payload returned by every AgentSessionReader. */
|
|
176
|
+
export interface SessionContent {
|
|
177
|
+
events: AgentSessionContentEvent[];
|
|
178
|
+
usage?: AgentSessionUsage;
|
|
179
|
+
aiTitle?: string;
|
|
180
|
+
recap?: string;
|
|
181
|
+
displayTitle?: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Reads an agent's session history. Each agent implements its own (Claude reads
|
|
185
|
+
* `~/.claude/projects/`, Codex calls `thread/list`, OpenCode calls `GET /session`).
|
|
186
|
+
*
|
|
187
|
+
* Q-C decision: `projectsDir` and other agent-specific path config live on the
|
|
188
|
+
* concrete reader's constructor, NOT on these method opts. The router/bridge
|
|
189
|
+
* depend only on this interface and never pass path config.
|
|
190
|
+
*/
|
|
191
|
+
export interface AgentSessionReader {
|
|
192
|
+
/**
|
|
193
|
+
* List sessions for a cwd, newest first by mtime.
|
|
194
|
+
*
|
|
195
|
+
* `sessions` is the page `[offset, offset+limit)` of the full set ordered
|
|
196
|
+
* by mtime desc, with same-mtime ties broken by a deterministic secondary
|
|
197
|
+
* key (sessionId/file path) so ordering is stable across calls. When
|
|
198
|
+
* `limit` is omitted, codex/pi/kimi return their default-sized page
|
|
199
|
+
* (default 20); claude/opencode return the full remaining set from
|
|
200
|
+
* `offset`. `total` is ALWAYS the size of the full cwd-matched set before
|
|
201
|
+
* pagination — never the truncated page length. A negative `offset` is
|
|
202
|
+
* clamped to 0 (first page).
|
|
203
|
+
*/
|
|
204
|
+
listSessions(cwd: string, opts?: {
|
|
205
|
+
limit?: number;
|
|
206
|
+
offset?: number;
|
|
207
|
+
}): {
|
|
208
|
+
sessions: AgentSession[];
|
|
209
|
+
total: number;
|
|
210
|
+
};
|
|
211
|
+
getNewestSession(cwd: string): AgentSession | null;
|
|
212
|
+
readSessionContent(sessionId: string, cwd: string, opts?: {
|
|
213
|
+
maxEvents?: number;
|
|
214
|
+
}): SessionContent;
|
|
215
|
+
/**
|
|
216
|
+
* Whether a session is still active (process may still be running).
|
|
217
|
+
*
|
|
218
|
+
* Dormant API: no production caller reads this today — the router decides
|
|
219
|
+
* "is an agent running" via the in-memory `bridge.isBusyFor(cwd)` (see
|
|
220
|
+
* `cmdPs`), not by probing session files. Retained on the reader contract
|
|
221
|
+
* because all 5 readers implement it and it is the natural hook if a
|
|
222
|
+
* file-based liveness check is ever needed; not wired into the bridge.
|
|
223
|
+
*/
|
|
224
|
+
isSessionActive(sessionId: string, cwd: string): boolean;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* AgentRunner extends Runner with agent identity and a session reader.
|
|
228
|
+
* Bridge/Router depend on this interface so adding a new agent is
|
|
229
|
+
* "implement AgentRunner + register" with zero upstream changes.
|
|
230
|
+
*/
|
|
231
|
+
export interface AgentRunner extends Runner {
|
|
232
|
+
readonly kind: AgentKind;
|
|
233
|
+
readonly sessionReader: AgentSessionReader;
|
|
234
|
+
/** Return current status info for /status display. */
|
|
235
|
+
getStatusInfo(): AgentStatusInfo;
|
|
236
|
+
}
|
|
237
|
+
/** Agent self-describing status info for /status display. */
|
|
238
|
+
export interface AgentStatusInfo {
|
|
239
|
+
/** Agent kind (claude/codex/opencode/pi/kimi). */
|
|
240
|
+
kind: AgentKind;
|
|
241
|
+
/** Display model name. */
|
|
242
|
+
model: string;
|
|
243
|
+
/** Optional provider name. */
|
|
244
|
+
provider?: string;
|
|
245
|
+
/** Reasoning/thinking level. */
|
|
246
|
+
reasoning?: string;
|
|
247
|
+
/** Agent-specific extra fields (e.g. codex.sandbox). */
|
|
248
|
+
extras?: Record<string, string>;
|
|
249
|
+
}
|
|
250
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ClaudeSessionReader } from './session-reader.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AgentSession, AgentSessionReader, SessionContent } from '../../runner/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter that exposes Claude Code's session-reading functions through the
|
|
4
|
+
* unified `AgentSessionReader` interface. This lets `SessionReaderRegistry`
|
|
5
|
+
* treat Claude / Codex / OpenCode uniformly.
|
|
6
|
+
*
|
|
7
|
+
* Q-C decision: `projectsDir` lives on the reader (not the router). The router
|
|
8
|
+
* injects a reader configured with its test `projectsDir`; production code
|
|
9
|
+
* uses the default (`~/.claude/projects/`).
|
|
10
|
+
*
|
|
11
|
+
* All methods are thin wrappers around `claude-sessions.ts` exports — zero
|
|
12
|
+
* behavior change. Router and bridge reach session data exclusively through
|
|
13
|
+
* this reader (via `SessionReaderRegistry`); the underlying functions remain
|
|
14
|
+
* exported for tests and the reader itself.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ClaudeSessionReader implements AgentSessionReader {
|
|
17
|
+
private readonly projectsDir?;
|
|
18
|
+
constructor(opts?: {
|
|
19
|
+
projectsDir?: string;
|
|
20
|
+
});
|
|
21
|
+
listSessions(cwd: string, opts?: {
|
|
22
|
+
limit?: number;
|
|
23
|
+
offset?: number;
|
|
24
|
+
}): {
|
|
25
|
+
sessions: AgentSession[];
|
|
26
|
+
total: number;
|
|
27
|
+
};
|
|
28
|
+
getNewestSession(cwd: string): AgentSession | null;
|
|
29
|
+
readSessionContent(sessionId: string, cwd: string, opts?: {
|
|
30
|
+
maxEvents?: number;
|
|
31
|
+
}): SessionContent;
|
|
32
|
+
isSessionActive(sessionId: string, cwd: string): boolean;
|
|
33
|
+
private readerOpts;
|
|
34
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { listClaudeSessions, getNewestSession, readSessionContent, isClaudeSessionActive, } from '../../session/claude/sessions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter that exposes Claude Code's session-reading functions through the
|
|
4
|
+
* unified `AgentSessionReader` interface. This lets `SessionReaderRegistry`
|
|
5
|
+
* treat Claude / Codex / OpenCode uniformly.
|
|
6
|
+
*
|
|
7
|
+
* Q-C decision: `projectsDir` lives on the reader (not the router). The router
|
|
8
|
+
* injects a reader configured with its test `projectsDir`; production code
|
|
9
|
+
* uses the default (`~/.claude/projects/`).
|
|
10
|
+
*
|
|
11
|
+
* All methods are thin wrappers around `claude-sessions.ts` exports — zero
|
|
12
|
+
* behavior change. Router and bridge reach session data exclusively through
|
|
13
|
+
* this reader (via `SessionReaderRegistry`); the underlying functions remain
|
|
14
|
+
* exported for tests and the reader itself.
|
|
15
|
+
*/
|
|
16
|
+
export class ClaudeSessionReader {
|
|
17
|
+
projectsDir;
|
|
18
|
+
constructor(opts = {}) {
|
|
19
|
+
this.projectsDir = opts.projectsDir;
|
|
20
|
+
}
|
|
21
|
+
listSessions(cwd, opts) {
|
|
22
|
+
// 先拿全集(不传 limit → listClaudeSessions 不切片),total 用全集长度,
|
|
23
|
+
// 再由 reader 按 [offset, offset+limit) 切片。
|
|
24
|
+
const all = listClaudeSessions(cwd, this.readerOpts());
|
|
25
|
+
const offset = Math.max(0, opts?.offset ?? 0);
|
|
26
|
+
const limit = opts?.limit;
|
|
27
|
+
return {
|
|
28
|
+
sessions: limit === undefined ? all.slice(offset) : all.slice(offset, offset + limit),
|
|
29
|
+
total: all.length,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
getNewestSession(cwd) {
|
|
33
|
+
const session = getNewestSession(cwd, this.readerOpts());
|
|
34
|
+
return session ?? null;
|
|
35
|
+
}
|
|
36
|
+
readSessionContent(sessionId, cwd, opts) {
|
|
37
|
+
return readSessionContent(sessionId, cwd, { ...this.readerOpts(), ...opts });
|
|
38
|
+
}
|
|
39
|
+
isSessionActive(sessionId, cwd) {
|
|
40
|
+
return isClaudeSessionActive(sessionId, cwd, this.readerOpts());
|
|
41
|
+
}
|
|
42
|
+
readerOpts() {
|
|
43
|
+
return this.projectsDir ? { projectsDir: this.projectsDir } : {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=session-reader.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AgentSession, AgentSessionContentEvent, AgentSessionUsage } from '../../runner/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read cwd from a Claude session JSONL by scanning events for the first
|
|
4
|
+
* `cwd` field. Claude CLI writes the absolute (symlink-resolved) cwd on
|
|
5
|
+
* every event that produces one; older versions wrote it once on init.
|
|
6
|
+
* Returns the first non-empty value, or undefined if absent.
|
|
7
|
+
*
|
|
8
|
+
* This is the SOLE source of truth for cwd. The directory name under
|
|
9
|
+
* ~/.claude/projects/ is lossy (encodes `/` AND `_` as `-`), so it cannot
|
|
10
|
+
* be decoded back to a real path. See regression 2026-06-21 /resume & /cd 路径错乱.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readCwdFromJsonl(filePath: string): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* List Claude Code sessions for a given cwd, newest first. Each entry has
|
|
15
|
+
* the sessionId (= jsonl filename stem), a one-line summary extracted from
|
|
16
|
+
* the first user message, and the file mtime. Returns an empty array when
|
|
17
|
+
* the project directory doesn't exist or no jsonl has a matching cwd field.
|
|
18
|
+
*
|
|
19
|
+
* We locate the directory via `projectDirForCwd` (lossy but OK for locating
|
|
20
|
+
* a known cwd) and then **verify** each jsonl's cwd field matches. This
|
|
21
|
+
* prevents collision: `my_disk/foo` and `my-disk/foo` both encode to the same
|
|
22
|
+
* directory name, but only the matching cwd field is kept.
|
|
23
|
+
*/
|
|
24
|
+
export declare function listClaudeSessions(cwd: string, opts?: {
|
|
25
|
+
limit?: number;
|
|
26
|
+
projectsDir?: string;
|
|
27
|
+
}): AgentSession[];
|
|
28
|
+
/** Get the newest session for a given cwd. Returns undefined if none exist. */
|
|
29
|
+
export declare function getNewestSession(cwd: string, opts?: {
|
|
30
|
+
projectsDir?: string;
|
|
31
|
+
}): AgentSession | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a Claude session (by sessionId + cwd) is still active.
|
|
34
|
+
* Public wrapper around the internal `isSessionActive(filePath, mtimeMs, now)`
|
|
35
|
+
* for use by `ClaudeSessionReader` and the multi-agent adapter layer.
|
|
36
|
+
*
|
|
37
|
+
* Resolves the jsonl path via `projectDirForCwd`, stats it for mtime, then
|
|
38
|
+
* applies the same mtime-freshness + terminal-marker heuristic
|
|
39
|
+
* used for session-active detection. Returns false if the file doesn't exist.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isClaudeSessionActive(sessionId: string, cwd: string, opts?: {
|
|
42
|
+
projectsDir?: string;
|
|
43
|
+
}): boolean;
|
|
44
|
+
export declare function readSessionContent(sessionId: string, cwd: string, opts?: {
|
|
45
|
+
projectsDir?: string;
|
|
46
|
+
maxEvents?: number;
|
|
47
|
+
}): {
|
|
48
|
+
events: AgentSessionContentEvent[];
|
|
49
|
+
usage?: AgentSessionUsage;
|
|
50
|
+
aiTitle?: string;
|
|
51
|
+
recap?: string;
|
|
52
|
+
displayTitle?: string;
|
|
53
|
+
};
|