@kodax-ai/kodax 0.7.49 → 0.7.51

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 (55) hide show
  1. package/CHANGELOG.md +1800 -1741
  2. package/README.md +1215 -1210
  3. package/README_CN.md +636 -632
  4. package/dist/chunks/agent-EFA7BSE7.js +2 -0
  5. package/dist/chunks/argument-completer-MAJVHSE7.js +2 -0
  6. package/dist/chunks/{chunk-TYZAH3YP.js → chunk-CCZMQE3Q.js} +1 -1
  7. package/dist/chunks/chunk-E3HENKTX.js +420 -0
  8. package/dist/chunks/chunk-FAIGYAEX.js +301 -0
  9. package/dist/chunks/chunk-HMATTIU6.js +574 -0
  10. package/dist/chunks/{chunk-YW4RQV7U.js → chunk-JJTUBNQX.js} +1 -1
  11. package/dist/chunks/chunk-ODVA5VTE.js +492 -0
  12. package/dist/chunks/chunk-PEWH3AAL.js +31 -0
  13. package/dist/chunks/chunk-WQTVG2T5.js +648 -0
  14. package/dist/chunks/{compaction-config-BQBYOWX2.js → compaction-config-UBPCNGC2.js} +1 -1
  15. package/dist/chunks/{construction-bootstrap-5TFGMSWQ.js → construction-bootstrap-WY5MDXRX.js} +1 -1
  16. package/dist/chunks/{dist-BL7IBQHD.js → dist-B73FQEAA.js} +1 -1
  17. package/dist/chunks/dist-BTWS2ENP.js +2 -0
  18. package/dist/chunks/utils-HVOJRR5C.js +2 -0
  19. package/dist/index.d.ts +11 -11
  20. package/dist/index.js +4 -4
  21. package/dist/kodax_cli.js +1091 -984
  22. package/dist/provider-capabilities.json +2 -0
  23. package/dist/sdk-agent.d.ts +25 -11
  24. package/dist/sdk-agent.js +1 -1
  25. package/dist/sdk-coding.d.ts +160 -34
  26. package/dist/sdk-coding.js +1 -1
  27. package/dist/sdk-llm.d.ts +3 -5
  28. package/dist/sdk-llm.js +1 -1
  29. package/dist/sdk-mcp.js +1 -1
  30. package/dist/sdk-repl.d.ts +38 -727
  31. package/dist/sdk-repl.js +2 -2
  32. package/dist/sdk-session.d.ts +8 -200
  33. package/dist/sdk-session.js +1 -1
  34. package/dist/sdk-skills.js +1 -1
  35. package/dist/types-chunks/{types.d-rPRl2LSB.d.ts → base.d-GZ6jvICS.d.ts} +270 -3
  36. package/dist/types-chunks/{bash-prefix-extractor.d-CI_xcPhn.d.ts → bash-prefix-extractor.d-DTOiDMlG.d.ts} +84 -537
  37. package/dist/types-chunks/{capsule.d-DaPuhyyK.d.ts → capsule.d-CXGdLGAn.d.ts} +6 -3
  38. package/dist/types-chunks/guardrail.d-D47yu9AO.d.ts +518 -0
  39. package/dist/types-chunks/{types.d-BR9oNWup.d.ts → process.d-B8kEBnQD.d.ts} +487 -275
  40. package/dist/types-chunks/{resolver.d-B_wm409c.d.ts → resolver.d-D75XFRH2.d.ts} +23 -6
  41. package/dist/types-chunks/sdk-session-BKQJN9oH.d.ts +977 -0
  42. package/dist/types-chunks/{storage.d-J2GqOgaX.d.ts → storage.d-BN1xIn8R.d.ts} +78 -3
  43. package/dist/types-chunks/types.d-DQ_hdN70.d.ts +273 -0
  44. package/dist/types-chunks/{utils.d-BJ_-y8gC.d.ts → utils.d-ZfRDo-kX.d.ts} +8 -80
  45. package/package.json +2 -2
  46. package/dist/chunks/argument-completer-GDG5OHN7.js +0 -2
  47. package/dist/chunks/chunk-67SWUEEN.js +0 -1035
  48. package/dist/chunks/chunk-C5PKZX5Z.js +0 -291
  49. package/dist/chunks/chunk-ISGHUKRY.js +0 -428
  50. package/dist/chunks/chunk-JTHMWRXM.js +0 -566
  51. package/dist/chunks/chunk-YACQ4OST.js +0 -31
  52. package/dist/chunks/dist-D7HOETCE.js +0 -2
  53. package/dist/chunks/utils-XWDT3W5X.js +0 -2
  54. package/dist/types-chunks/base.d-C4jYVjJh.d.ts +0 -270
  55. package/dist/types-chunks/types.d-BnjX2Gn4.d.ts +0 -297
@@ -0,0 +1,977 @@
1
+ import { b as PermissionMode, S as SessionData, F as FileSessionStorage } from './storage.d-BN1xIn8R.js';
2
+ import { G as KodaXReasoningMode, o as KodaXMessage, h as KodaXContentBlock } from './base.d-GZ6jvICS.js';
3
+ import { k as KodaXAgentMode } from './bash-prefix-extractor.d-DTOiDMlG.js';
4
+ import { ac as KodaXSessionUiHistoryItem, ag as KodaXSessionUiToolCall } from './process.d-B8kEBnQD.js';
5
+
6
+ /**
7
+ * TextBuffer - Text buffer management class - 文本缓冲区管理类
8
+ *
9
+ * Reference implementation: Gemini CLI text-buffer.ts - 参考实现: Gemini CLI text-buffer.ts
10
+ * Supports multi-line text editing, cursor navigation, and Unicode-safe operations - 支持多行文本编辑,光标导航,Unicode 安全操作
11
+ */
12
+ interface CursorPosition {
13
+ row: number;
14
+ col: number;
15
+ }
16
+ interface VisualCursor$1 {
17
+ row: number;
18
+ col: number;
19
+ }
20
+ interface TextBufferOptions {
21
+ maxHistory?: number;
22
+ }
23
+ declare class TextBuffer {
24
+ private _text;
25
+ private _lines;
26
+ private _cursor;
27
+ private _rememberedCol;
28
+ private _history;
29
+ private _historyIndex;
30
+ private _maxHistory;
31
+ constructor(options?: TextBufferOptions);
32
+ get text(): string;
33
+ get lines(): string[];
34
+ get cursor(): CursorPosition;
35
+ get lineCount(): number;
36
+ get currentLine(): string;
37
+ get isEmpty(): boolean;
38
+ /**
39
+ * Get visual width of current line - 获取当前行的视觉宽度
40
+ */
41
+ get currentLineVisualWidth(): number;
42
+ /**
43
+ * Get visual position of cursor (considering wide characters) - 获取光标的视觉位置(考虑宽字符)
44
+ */
45
+ get visualCursor(): VisualCursor$1;
46
+ /**
47
+ * Get visual width of character at cursor position on current line - 获取当前行在光标位置的字符视觉宽度
48
+ */
49
+ getCharWidthAtCursor(): number;
50
+ /**
51
+ * Convert visual column position to logical column position - 将视觉列位置转换为逻辑列位置
52
+ */
53
+ visualColToLogicalCol(visualCol: number): number;
54
+ /**
55
+ * Move to visual column position - 移动到视觉列位置
56
+ */
57
+ moveToVisualCol(visualCol: number): void;
58
+ /**
59
+ * Set entire text content - 设置整个文本内容
60
+ */
61
+ setText(text: string): void;
62
+ /**
63
+ * Replace a text range and leave the cursor after the replacement.
64
+ */
65
+ replaceRange(start: number, end: number, replacement: string): void;
66
+ /**
67
+ * Insert text at cursor position - 在光标位置插入文本
68
+ */
69
+ insert(text: string, options?: {
70
+ paste?: boolean;
71
+ }): void;
72
+ /**
73
+ * Insert text on current line - 在当前行插入文本
74
+ */
75
+ private _insertText;
76
+ /**
77
+ * Insert newline character - 插入换行符
78
+ */
79
+ newline(): void;
80
+ private _insertNewline;
81
+ /**
82
+ * Delete character before cursor - 删除光标前的字符
83
+ */
84
+ backspace(): void;
85
+ /**
86
+ * Delete character after cursor - 删除光标后的字符
87
+ */
88
+ delete(): void;
89
+ /**
90
+ * Move cursor - 移动光标
91
+ */
92
+ move(direction: "up" | "down" | "left" | "right" | "home" | "end"): void;
93
+ private _moveUp;
94
+ private _moveDown;
95
+ private _moveLeft;
96
+ private _moveRight;
97
+ private _moveHome;
98
+ private _moveEnd;
99
+ /**
100
+ * Clamp column position within current line range using rememberedCol - 限制列位置在当前行范围内,使用 rememberedCol
101
+ */
102
+ private _clampColumn;
103
+ /**
104
+ * Clamp cursor to valid range - 限制光标在有效范围内
105
+ */
106
+ private _clampCursor;
107
+ /**
108
+ * Delete content from cursor to end of line (Ctrl+K) - 删除光标到行尾的内容 (Ctrl+K)
109
+ */
110
+ killLineRight(): void;
111
+ /**
112
+ * Delete content from line start to cursor (Ctrl+U) - 删除行首到光标的内容 (Ctrl+U)
113
+ */
114
+ killLineLeft(): void;
115
+ /**
116
+ * Delete word before cursor (Ctrl+W) - 删除光标前的一个词 (Ctrl+W)
117
+ */
118
+ deleteWordLeft(): void;
119
+ private _saveHistory;
120
+ /**
121
+ * Undo - 撤销
122
+ */
123
+ undo(): boolean;
124
+ /**
125
+ * Redo - 重做
126
+ */
127
+ redo(): boolean;
128
+ private _updateText;
129
+ private _setTextInternal;
130
+ /**
131
+ * Move cursor to an absolute string offset - 将光标移动到文本中的绝对偏移位置
132
+ */
133
+ moveToAbsoluteOffset(offset: number): void;
134
+ /**
135
+ * Clear buffer - 清空缓冲区
136
+ */
137
+ clear(): void;
138
+ /**
139
+ * Get absolute position of cursor in text - 获取光标在文本中的绝对位置
140
+ */
141
+ getAbsoluteOffset(): number;
142
+ /**
143
+ * Check if current line ends with backslash - 检查当前行是否以反斜杠结尾
144
+ */
145
+ isLineContinuation(): boolean;
146
+ /**
147
+ * Move cursor to end of entire text - 将光标移动到整个文本的末尾
148
+ */
149
+ moveToEnd(): void;
150
+ }
151
+
152
+ /**
153
+ * PasteStore — per-session paste content registry + placeholder ref helpers.
154
+ *
155
+ * Design: see docs/KNOWN_ISSUES.md Issue 121 (三层防御:粘贴拦截 / 输入兜底 / 渲染硬上限).
156
+ * Reference implementation: Claude Code src/history.ts + src/utils/pasteStore.ts.
157
+ *
158
+ * Responsibilities (pure / deterministic where possible):
159
+ * - Format / parse `[Pasted text #N +K lines]` and related refs
160
+ * - Allocate monotonic per-session paste IDs
161
+ * - Store / expand paste content in memory
162
+ * - Find placeholder boundaries adjacent to cursor (for atomic edit)
163
+ *
164
+ * Stateful concerns are confined to the `PasteStore` class. Everything else is
165
+ * pure so rendering and controller code can call them safely.
166
+ */
167
+ type PastedContentType = "text" | "image";
168
+ interface PastedContent {
169
+ id: number;
170
+ type: PastedContentType;
171
+ content: string;
172
+ /** Optional sha256 hash — set when backed by on-disk paste-cache */
173
+ contentHash?: string;
174
+ /** Media type for image pastes; unused for text */
175
+ mediaType?: string;
176
+ /** Optional filename hint for image pastes */
177
+ filename?: string;
178
+ }
179
+ /**
180
+ * Session-scoped stateful registry. One instance per REPL session (not per
181
+ * paste). Lives as long as the composer. IDs are monotonic and never recycled
182
+ * so undo/redo never collides with a fresh paste that reused an id.
183
+ */
184
+ declare class PasteStore {
185
+ private readonly contents;
186
+ private nextId;
187
+ /**
188
+ * Register text content, returns the allocated id + the placeholder string
189
+ * to insert into the buffer in place of the raw content.
190
+ */
191
+ registerText(content: string): {
192
+ id: number;
193
+ placeholder: string;
194
+ numLines: number;
195
+ };
196
+ /**
197
+ * Register pre-computed Layer 2 truncation output. Caller is responsible
198
+ * for constructing the truncated text; this just stores the middle chunk.
199
+ */
200
+ registerTruncatedText(content: string): {
201
+ id: number;
202
+ numLines: number;
203
+ };
204
+ /**
205
+ * Adopt a pre-allocated id + content (e.g. when restoring from disk-backed
206
+ * input history).
207
+ */
208
+ adopt(entry: PastedContent): void;
209
+ /** Allocate the NEXT id without registering anything yet. */
210
+ peekNextId(): number;
211
+ get(id: number): PastedContent | undefined;
212
+ /** Expand all placeholders in `input` using this store's contents. */
213
+ expand(input: string): string;
214
+ /**
215
+ * Snapshot the current contents map. Returned map is a COPY — mutation does
216
+ * not leak back. Used by undo buffer snapshots.
217
+ */
218
+ snapshot(): Map<number, PastedContent>;
219
+ /** Replace contents from a snapshot. Used by undo. `nextId` preserved. */
220
+ restore(snapshot: ReadonlyMap<number, PastedContent>): void;
221
+ /**
222
+ * Session-level reset. Called on `/clear`, start-new-session, etc.
223
+ * Does NOT clear on per-submit since Up-arrow navigation re-submits may
224
+ * reuse stored refs.
225
+ */
226
+ reset(): void;
227
+ size(): number;
228
+ /** Export contents for persistence (input history serialization). */
229
+ export(): PastedContent[];
230
+ }
231
+
232
+ /**
233
+ * Keyboard info interface - 键盘信息接口
234
+ * Reference: Gemini CLI Key interface - 参考: Gemini CLI Key interface
235
+ */
236
+ interface KeyInfo {
237
+ name: string;
238
+ sequence: string;
239
+ ctrl: boolean;
240
+ meta: boolean;
241
+ shift: boolean;
242
+ insertable: boolean;
243
+ isPasted?: boolean;
244
+ mouse?: {
245
+ action: "press" | "release" | "drag" | "move" | "wheel";
246
+ button: "left" | "middle" | "right" | "wheelup" | "wheeldown" | "unknown";
247
+ row: number;
248
+ column: number;
249
+ };
250
+ }
251
+
252
+ type PromptEditingMode = "idle" | "typing" | "pasting";
253
+ interface UseTextBufferReturn {
254
+ buffer: TextBuffer;
255
+ text: string;
256
+ cursor: CursorPosition;
257
+ lines: string[];
258
+ isPasting: boolean;
259
+ editingMode: PromptEditingMode;
260
+ /**
261
+ * Issue 121: session-scoped paste registry. Registered paste ids survive
262
+ * submit so Up-arrow input-history recall can still expand them.
263
+ */
264
+ pasteStore: PasteStore;
265
+ resetTransientState: () => void;
266
+ setText: (text: string) => void;
267
+ replaceRange: (start: number, end: number, replacement: string) => void;
268
+ insert: (text: string, options?: {
269
+ paste?: boolean;
270
+ }) => void;
271
+ newline: () => void;
272
+ backspace: () => void;
273
+ delete: () => void;
274
+ move: (direction: "up" | "down" | "left" | "right" | "home" | "end") => void;
275
+ moveToEnd: () => void;
276
+ moveToOffset: (offset: number) => void;
277
+ killLineRight: () => void;
278
+ killLineLeft: () => void;
279
+ deleteWordLeft: () => void;
280
+ clear: () => void;
281
+ undo: () => boolean;
282
+ redo: () => boolean;
283
+ }
284
+ /**
285
+ * Visual Layout Interface - 视觉布局接口
286
+ * Reference: Gemini CLI text-buffer.ts - VisualLayout
287
+ */
288
+ interface VisualLayout {
289
+ /** All visual lines for rendering - 所有视觉行(用于渲染) */
290
+ visualLines: string[];
291
+ /** For each logical line: [[visualLineIndex, startColInLogical], ...] - 每个逻辑行 -> 视觉行索引 + 起始列的映射 */
292
+ logicalToVisualMap: Array<Array<[number, number]>>;
293
+ /** For each visual line: [logicalLineIndex, startColInLogical] - 每个视觉行 -> 逻辑行 + 起始列的映射 */
294
+ visualToLogicalMap: Array<[number, number]>;
295
+ }
296
+ type VisualCursor = [number, number];
297
+ /**
298
+ * An input-history entry. `text` is the display form (may contain
299
+ * `[Pasted text #N]` placeholders). `pastedContents`, when present, carries
300
+ * the stored contents needed to expand those placeholders after recall.
301
+ *
302
+ * Issue 121: pastedContents preserves paste fidelity across Up-arrow and
303
+ * undo. For entries loaded from disk-backed history, contents may carry only
304
+ * `contentHash` until `retrievePastedText` resolves them.
305
+ */
306
+ interface HistoryEntry {
307
+ text: string;
308
+ timestamp: number;
309
+ pastedContents?: PastedContent[];
310
+ }
311
+ interface Completion {
312
+ text: string;
313
+ display: string;
314
+ description?: string;
315
+ type: "file" | "command" | "argument";
316
+ }
317
+ interface Completer {
318
+ canComplete(input: string, cursorPos: number): boolean;
319
+ getCompletions(input: string, cursorPos: number): Promise<Completion[]>;
320
+ }
321
+ /**
322
+ * Autocomplete suggestion item - 自动补全建议项
323
+ * For SuggestionsDisplay component - 用于 SuggestionsDisplay 组件
324
+ */
325
+ interface Suggestion {
326
+ id: string;
327
+ text: string;
328
+ displayText?: string;
329
+ description?: string;
330
+ type?: "command" | "file" | "history" | "argument" | "snippet" | "skill";
331
+ icon?: string;
332
+ }
333
+ interface ThemeColors {
334
+ primary: string;
335
+ secondary: string;
336
+ accent: string;
337
+ text: string;
338
+ dim: string;
339
+ thinking: string;
340
+ success: string;
341
+ warning: string;
342
+ error: string;
343
+ info: string;
344
+ hint: string;
345
+ background: string;
346
+ inputBackground: string;
347
+ }
348
+ interface ThemeSymbols {
349
+ prompt: string;
350
+ success: string;
351
+ error: string;
352
+ warning: string;
353
+ spinner: string[];
354
+ }
355
+ interface Theme {
356
+ name: string;
357
+ colors: ThemeColors;
358
+ symbols: ThemeSymbols;
359
+ }
360
+ interface PromptSubmitPayload {
361
+ /**
362
+ * Display form — what the user saw in the input bar. May contain
363
+ * `[Pasted text #N +K lines]` placeholders or `[...Truncated text #N ...]`
364
+ * refs (Issue 121).
365
+ */
366
+ displayText: string;
367
+ /**
368
+ * Fully expanded form — all paste placeholders substituted for their raw
369
+ * stored contents. This is what parseCommand / the agent pipeline consume.
370
+ */
371
+ fullText: string;
372
+ /** Paste contents referenced by displayText — for persistence / recall. */
373
+ pastedContents: PastedContent[];
374
+ }
375
+ interface InputPromptProps {
376
+ onSubmit: (payload: PromptSubmitPayload) => void;
377
+ placeholder?: string;
378
+ prompt?: string;
379
+ focus?: boolean;
380
+ initialValue?: string;
381
+ /** Callback when input text changes - 输入文本变化时的回调 */
382
+ onInputChange?: (text: string) => void;
383
+ /**
384
+ * Called when the ↑ arrow history recall brings back an entry with stored
385
+ * paste contents. Consumer can hydrate a disk-backed paste cache here.
386
+ */
387
+ onHistoryRecall?: (entry: {
388
+ text: string;
389
+ pastedContents: PastedContent[];
390
+ }) => void;
391
+ /**
392
+ * FEATURE_149 Phase 2.1 (v0.7.38) — pop the queued follow-up inputs back
393
+ * into the editor when the user presses ↑ on an empty buffer. Return the
394
+ * joined text to load (queue gets atomically cleared by the consumer), or
395
+ * `undefined` to leave history-recall behavior intact when the queue is
396
+ * empty.
397
+ */
398
+ onPopPendingInputs?: () => string | undefined;
399
+ }
400
+ interface StatusBarProps {
401
+ sessionId: string;
402
+ permissionMode: PermissionMode;
403
+ agentMode: KodaXAgentMode;
404
+ provider: string;
405
+ model: string;
406
+ tokenUsage?: {
407
+ input: number;
408
+ output: number;
409
+ total: number;
410
+ };
411
+ currentTool?: string;
412
+ activeToolCount?: number;
413
+ thinking?: boolean;
414
+ reasoningMode?: KodaXReasoningMode;
415
+ reasoningCapability?: string;
416
+ /** Is context currently compacting - 是否正在压缩上下文 */
417
+ isCompacting?: boolean;
418
+ /** Thinking character count - Issue 068: 显示 thinking 进度 */
419
+ thinkingCharCount?: number;
420
+ /** Whether a thinking stream is currently active */
421
+ isThinkingActive?: boolean;
422
+ /** Tool input character count - Issue 068: 显示 tool 输入进度 */
423
+ toolInputCharCount?: number;
424
+ /** Tool input content (truncated) - Issue 068 Phase 4: 显示参数摘要 */
425
+ toolInputContent?: string;
426
+ /** Current iteration number - Issue 068: 显示迭代进度 */
427
+ currentIteration?: number;
428
+ /** Maximum iterations - Issue 068: 显示迭代进度 */
429
+ maxIter?: number;
430
+ /** Context usage info - Issue 070: 显示上下文使用情况 */
431
+ contextUsage?: {
432
+ /** Current token count in context */
433
+ currentTokens: number;
434
+ /** Context window size (effective contextWindow) */
435
+ contextWindow: number;
436
+ /** Compaction trigger percentage (0-100) */
437
+ triggerPercent: number;
438
+ };
439
+ /** Whether current busy/thinking status should be visible in the bar */
440
+ showBusyStatus?: boolean;
441
+ managedPhase?: "starting" | "routing" | "preflight" | "round" | "worker" | "upgrade" | "verifying" | "completed";
442
+ managedHarnessProfile?: string;
443
+ managedWorkerTitle?: string;
444
+ managedRound?: number;
445
+ managedMaxRounds?: number;
446
+ managedGlobalWorkBudget?: number;
447
+ managedBudgetUsage?: number;
448
+ managedBudgetApprovalRequired?: boolean;
449
+ /**
450
+ * v0.7.38 FEATURE_156 — true when the runner-driven outer loop is
451
+ * parked in `waitForWakeEvent` (idle-yield from FEATURE_155). The
452
+ * status bar renders this as "{role} - waiting for N children"
453
+ * instead of falling back to the last role-emit label, so the user
454
+ * can tell the spinner is actively waiting on something concrete.
455
+ * Consumers MUST branch on `=== true` (undefined transitions out).
456
+ */
457
+ managedIdleWaiting?: boolean;
458
+ /** v0.7.38 FEATURE_156 — child count surfaced in the idle-wait label. */
459
+ managedIdleWaitingPendingCount?: number;
460
+ /**
461
+ * FEATURE_092 phase 2b.8: classifier engine indicator. Only renders when
462
+ * permissionMode is in the auto family. `'llm'` shows green `auto[LLM]`
463
+ * (healthy), `'rules'` shows yellow `auto[RULES]` (downgraded — every
464
+ * non-Tier-1 tool call escalates to user confirm).
465
+ */
466
+ autoModeEngine?: 'llm' | 'rules';
467
+ }
468
+ /**
469
+ * @deprecated Use MessageListProps from components/MessageList.js instead
470
+ */
471
+ interface LegacyMessageListProps {
472
+ messages: Message[];
473
+ isLoading?: boolean;
474
+ }
475
+ interface Message {
476
+ id: string;
477
+ role: "user" | "assistant" | "system";
478
+ content: string;
479
+ timestamp: number;
480
+ }
481
+ interface AppState {
482
+ messages: Message[];
483
+ isLoading: boolean;
484
+ error?: string;
485
+ sessionId: string;
486
+ }
487
+ interface AppProps {
488
+ model: string;
489
+ provider: string;
490
+ onSubmit: (input: string) => Promise<void>;
491
+ permissionMode?: PermissionMode;
492
+ agentMode?: KodaXAgentMode;
493
+ }
494
+ /**
495
+ * Streaming response state enum - 流式响应状态枚举
496
+ * Reference: Gemini CLI StreamingContext.tsx - 参考: Gemini CLI StreamingContext.tsx
497
+ */
498
+ declare enum StreamingState {
499
+ Idle = "idle",
500
+ Responding = "responding",
501
+ WaitingForConfirmation = "waiting_for_confirmation"
502
+ }
503
+ /**
504
+ * Tool call status enum - 工具调用状态枚举
505
+ * Reference: Gemini CLI useToolScheduler - 参考: Gemini CLI useToolScheduler
506
+ */
507
+ declare enum ToolCallStatus {
508
+ Scheduled = "scheduled",
509
+ Validating = "validating",
510
+ AwaitingApproval = "awaiting_approval",
511
+ Executing = "executing",
512
+ Success = "success",
513
+ Error = "error",
514
+ Cancelled = "cancelled"
515
+ }
516
+ /**
517
+ * Tool call status icons - 工具调用状态图标
518
+ */
519
+ declare const TOOL_STATUS_ICONS: Record<ToolCallStatus, string>;
520
+ /**
521
+ * Single tool call - 单个工具调用
522
+ */
523
+ interface ToolCall {
524
+ id: string;
525
+ name: string;
526
+ status: ToolCallStatus;
527
+ input?: Record<string, unknown>;
528
+ preview?: string;
529
+ output?: unknown;
530
+ error?: string;
531
+ progress?: number;
532
+ /** Real-time progress lines displayed inside the tool block during execution. */
533
+ progressLines?: string[];
534
+ startTime: number;
535
+ endTime?: number;
536
+ }
537
+ /**
538
+ * History item type - 历史项类型
539
+ * Reference: Gemini CLI HistoryItem - 参考: Gemini CLI HistoryItem
540
+ */
541
+ type HistoryItemType = "user" | "assistant" | "system" | "tool_group" | "thinking" | "error" | "event" | "info" | "hint";
542
+ /**
543
+ * History item base class - 历史项基类
544
+ */
545
+ interface HistoryItemBase {
546
+ id: string;
547
+ type: HistoryItemType;
548
+ timestamp: number;
549
+ }
550
+ /**
551
+ * User message - 用户消息
552
+ */
553
+ interface HistoryItemUser extends HistoryItemBase {
554
+ type: "user";
555
+ text: string;
556
+ }
557
+ /**
558
+ * Assistant message - 助手消息
559
+ */
560
+ interface HistoryItemAssistant extends HistoryItemBase {
561
+ type: "assistant";
562
+ text: string;
563
+ compactText?: string;
564
+ isStreaming?: boolean;
565
+ }
566
+ /**
567
+ * System message - 系统消息
568
+ */
569
+ interface HistoryItemSystem extends HistoryItemBase {
570
+ type: "system";
571
+ text: string;
572
+ }
573
+ /**
574
+ * Tool group - 工具组
575
+ */
576
+ interface HistoryItemToolGroup extends HistoryItemBase {
577
+ type: "tool_group";
578
+ tools: ToolCall[];
579
+ }
580
+ /**
581
+ * Thinking content - 思考内容
582
+ */
583
+ interface HistoryItemThinking extends HistoryItemBase {
584
+ type: "thinking";
585
+ text: string;
586
+ compactText?: string;
587
+ }
588
+ /**
589
+ * Error message - 错误消息
590
+ */
591
+ interface HistoryItemError extends HistoryItemBase {
592
+ type: "error";
593
+ text: string;
594
+ }
595
+ interface HistoryItemEvent extends HistoryItemBase {
596
+ type: "event";
597
+ text: string;
598
+ icon?: string;
599
+ compactText?: string;
600
+ }
601
+ /**
602
+ * Info message - 信息消息
603
+ */
604
+ interface HistoryItemInfo extends HistoryItemBase {
605
+ type: "info";
606
+ text: string;
607
+ icon?: string;
608
+ compactText?: string;
609
+ /**
610
+ * When true, drop the default bottom margin so consecutive info items
611
+ * (e.g. a burst of repo-intelligence trace stages emitted within one
612
+ * turn) visually stack as a block instead of each getting a blank
613
+ * spacer line. Non-tight items following a tight run restore normal
614
+ * spacing on their own via their own `marginBottom`.
615
+ */
616
+ tightSpacing?: boolean;
617
+ }
618
+ /**
619
+ * Hint message - 提示消息
620
+ */
621
+ interface HistoryItemHint extends HistoryItemBase {
622
+ type: "hint";
623
+ text: string;
624
+ }
625
+ /**
626
+ * Union type of all history items - 所有历史项的联合类型
627
+ */
628
+ type HistoryItem = HistoryItemUser | HistoryItemAssistant | HistoryItemSystem | HistoryItemToolGroup | HistoryItemThinking | HistoryItemError | HistoryItemEvent | HistoryItemInfo | HistoryItemHint;
629
+ /**
630
+ * Creatable history item types (with text property) - 可创建的历史项类型(带 text 属性)
631
+ * Used for addHistoryItem function parameter type - 用于 addHistoryItem 等函数的参数类型
632
+ */
633
+ type CreatableHistoryItem = Omit<HistoryItemUser, "id" | "timestamp"> | Omit<HistoryItemAssistant, "id" | "timestamp"> | Omit<HistoryItemSystem, "id" | "timestamp"> | Omit<HistoryItemThinking, "id" | "timestamp"> | Omit<HistoryItemError, "id" | "timestamp"> | Omit<HistoryItemEvent, "id" | "timestamp"> | Omit<HistoryItemInfo, "id" | "timestamp"> | Omit<HistoryItemHint, "id" | "timestamp"> | Omit<HistoryItemToolGroup, "id" | "timestamp">;
634
+ /**
635
+ * UI global state interface - UI 全局状态接口
636
+ * Reference: Gemini CLI UIStateContext - 参考: Gemini CLI UIStateContext
637
+ */
638
+ interface UIState {
639
+ streamingState: StreamingState;
640
+ currentResponse: string;
641
+ history: HistoryItem[];
642
+ pendingToolCalls: ToolCall[];
643
+ sessionId: string;
644
+ provider: string;
645
+ model: string;
646
+ tokenUsage?: {
647
+ input: number;
648
+ output: number;
649
+ total: number;
650
+ };
651
+ error?: string;
652
+ isLoading: boolean;
653
+ }
654
+ /**
655
+ * UI actions interface - UI 操作接口
656
+ */
657
+ interface UIActions {
658
+ setStreamingState: (state: StreamingState) => void;
659
+ appendToResponse: (text: string) => void;
660
+ clearResponse: () => void;
661
+ addHistoryItem: (item: CreatableHistoryItem) => void;
662
+ addHistoryItems: (items: CreatableHistoryItem[]) => void;
663
+ updateHistoryItem: (id: string, updates: Partial<HistoryItem>) => void;
664
+ clearHistory: () => void;
665
+ addToolCall: (tool: Omit<ToolCall, "id" | "startTime">) => string;
666
+ updateToolCall: (id: string, updates: Partial<ToolCall>) => void;
667
+ clearToolCalls: () => void;
668
+ setSessionId: (id: string) => void;
669
+ setProvider: (provider: string) => void;
670
+ setModel: (model: string) => void;
671
+ setTokenUsage: (usage: UIState["tokenUsage"]) => void;
672
+ setError: (error: string | undefined) => void;
673
+ setLoading: (loading: boolean) => void;
674
+ }
675
+ /**
676
+ * Keyboard event handler priority - 键盘事件处理器优先级
677
+ * Reference: Gemini CLI KeypressContext - 参考: Gemini CLI KeypressContext
678
+ */
679
+ declare enum KeypressHandlerPriority {
680
+ Low = -100,
681
+ Normal = 0,
682
+ High = 100,
683
+ Critical = 200
684
+ }
685
+ /**
686
+ * Keyboard event handler - 键盘事件处理器
687
+ */
688
+ type KeypressHandler = (event: KeyInfo) => boolean | void;
689
+ /**
690
+ * Keyboard event - 键盘事件
691
+ */
692
+ interface KeypressEvent {
693
+ key: KeyInfo;
694
+ handled: boolean;
695
+ }
696
+ /**
697
+ * Default UI state - 默认 UI 状态
698
+ */
699
+ declare const DEFAULT_UI_STATE: UIState;
700
+
701
+ interface RestoreHistoryItemsFromSessionInput {
702
+ messages: readonly KodaXMessage[];
703
+ uiHistory?: readonly KodaXSessionUiHistoryItem[];
704
+ }
705
+ declare function trimPersistedUiHistorySnapshot(items: readonly KodaXSessionUiHistoryItem[]): KodaXSessionUiHistoryItem[];
706
+ declare function restoreHistoryItemsFromSession(input: RestoreHistoryItemsFromSessionInput): CreatableHistoryItem[];
707
+
708
+ /**
709
+ * Utilities for extracting message content for history rendering, copy, and previews.
710
+ */
711
+
712
+ type RestoredHistorySeed = {
713
+ type: "user";
714
+ text: string;
715
+ } | {
716
+ type: "assistant";
717
+ text: string;
718
+ } | {
719
+ type: "system";
720
+ text: string;
721
+ } | {
722
+ type: "thinking";
723
+ text: string;
724
+ } | {
725
+ type: "tool_summary";
726
+ text: string;
727
+ } | {
728
+ type: "tool_group";
729
+ tools: KodaXSessionUiToolCall[];
730
+ };
731
+ /** Convert a RestoredHistorySeed to a CreatableHistoryItem. tool_summary → event with icon. */
732
+ declare function seedToHistoryItem(seed: RestoredHistorySeed): CreatableHistoryItem;
733
+ declare function toolCallSeedToHistoryToolCall(tool: KodaXSessionUiToolCall): ToolCall;
734
+ /**
735
+ * Minimal message shape required to restore UI history items.
736
+ */
737
+ interface HistorySeedSourceMessage {
738
+ role: KodaXMessage["role"];
739
+ content: string | KodaXContentBlock[];
740
+ _synthetic?: boolean;
741
+ }
742
+ declare function extractHistorySeedsFromMessage(message: HistorySeedSourceMessage): RestoredHistorySeed[];
743
+ declare function extractHistorySeedsFromMessages(messages: readonly HistorySeedSourceMessage[]): RestoredHistorySeed[];
744
+ /**
745
+ * Extract plain text from message content.
746
+ * Thinking/tool blocks are omitted so callers get only visible assistant text.
747
+ */
748
+ declare function extractTextContent(content: string | readonly unknown[]): string;
749
+ /**
750
+ * Extract a session title from the first user message.
751
+ */
752
+ declare function extractTitle(messages: KodaXMessage[]): string;
753
+ /**
754
+ * Format a single-line preview for session lists.
755
+ */
756
+ declare function formatMessagePreview(content: string, maxLength?: number): string;
757
+
758
+ /**
759
+ * FEATURE_173 Part B (v0.7.42) — Session Management Public SDK.
760
+ *
761
+ * Thin facades over FileSessionStorage + discoverInstances. All methods
762
+ * NEVER throw — missing sessions return null, blocked operations return
763
+ * an error envelope, missing directories return empty arrays / no-op
764
+ * watchers.
765
+ *
766
+ * The `@kodax-ai/kodax/session` SDK subpath re-exports this module.
767
+ */
768
+
769
+ interface SessionSummary {
770
+ readonly id: string;
771
+ readonly title: string;
772
+ readonly msgCount: number;
773
+ readonly tag?: string;
774
+ readonly createdAt?: string;
775
+ readonly runtimeInfo?: {
776
+ workspaceRoot?: string;
777
+ gitRoot?: string;
778
+ };
779
+ /**
780
+ * FEATURE_219 (v0.7.46) — the per-project directory key this session lives
781
+ * under (ADR-038 §7). A backward-compatible hint: consumers may pass it back
782
+ * for precise disambiguation, but `loadSession(id)` works without it.
783
+ */
784
+ readonly projectKey?: string;
785
+ /** FEATURE_219 — true when the session is whole-session archived (only ever
786
+ * surfaced when `includeArchived` is set). */
787
+ readonly archived?: boolean;
788
+ }
789
+ type SessionTranscriptEntryType = 'message' | 'compaction' | 'branch_summary';
790
+ interface SessionTranscriptEntry {
791
+ readonly entryId: string;
792
+ readonly parentId: string | null;
793
+ readonly timestamp: string;
794
+ readonly type: SessionTranscriptEntryType;
795
+ readonly message: KodaXMessage;
796
+ readonly active: boolean;
797
+ readonly summary?: string;
798
+ }
799
+ interface FullTranscriptSessionData extends Omit<SessionData, 'messages'> {
800
+ readonly messages: KodaXMessage[];
801
+ readonly activeMessages: KodaXMessage[];
802
+ readonly transcriptEntries: SessionTranscriptEntry[];
803
+ }
804
+ interface ListSessionsOptions {
805
+ /**
806
+ * Alias for gitRoot; backwards-compat with KodaX Space terminology.
807
+ * When provided, list() is scoped to sessions from this project root.
808
+ */
809
+ readonly projectRoot?: string;
810
+ /**
811
+ * Which session scopes to include.
812
+ * - 'user' (default): only user-initiated sessions.
813
+ * - 'managed-task-worker': only managed-task worker sessions.
814
+ * - 'all': no scope filter.
815
+ */
816
+ readonly scope?: 'user' | 'managed-task-worker' | 'all';
817
+ /**
818
+ * Whether to include whole-session-archived sessions. FEATURE_219 (v0.7.46):
819
+ * archived sessions live in `<projectKey>/archived/` (see `archiveSession`);
820
+ * also still hides the legacy `archived-` filename prefix. Default false.
821
+ */
822
+ readonly includeArchived?: boolean;
823
+ /** Maximum number of sessions to return. Default 50. */
824
+ readonly limit?: number;
825
+ /**
826
+ * ISO date string — return only sessions whose createdAt is before this
827
+ * timestamp. Applied after list + scope filtering.
828
+ */
829
+ readonly before?: string;
830
+ /** Exact match. Omitted means no tag filter. */
831
+ readonly tag?: string;
832
+ }
833
+ type WatchSessionsCallback = (event: {
834
+ kind: 'change' | 'add' | 'remove';
835
+ sessionId: string;
836
+ }) => void;
837
+ interface SessionManager {
838
+ listSessions: typeof listSessions;
839
+ loadSession: typeof loadSession;
840
+ loadFullTranscript: typeof loadFullTranscript;
841
+ forkSession: typeof forkSession;
842
+ rewindSession: typeof rewindSession;
843
+ setActiveEntry: typeof setActiveEntry;
844
+ deleteSession: typeof deleteSession;
845
+ archiveSession: typeof archiveSession;
846
+ unarchiveSession: typeof unarchiveSession;
847
+ listRunningSessions: typeof listRunningSessions;
848
+ watchSessions: typeof watchSessions;
849
+ /**
850
+ * v0.7.43 — the raw write-side storage instance. SDK embedders pass
851
+ * this into `runKodaX({ session: { id, scope, storage } })` so the
852
+ * SA / AMA loops write per-turn JSONL snapshots to disk. Without an
853
+ * injected storage, `saveSessionSnapshot` is a silent no-op and the
854
+ * sessions directory stays empty regardless of `session.id`.
855
+ *
856
+ * See {@link FileSessionStorage} for the concrete implementation and
857
+ * `docs/SDK_EMBEDDER_GUIDE.md` §6 for the end-to-end recipe.
858
+ */
859
+ storage: FileSessionStorage;
860
+ }
861
+ /**
862
+ * List sessions, optionally filtered by scope, limit, and date.
863
+ * NEVER throws. Returns [] when the sessions directory is empty or missing.
864
+ */
865
+ declare function listSessions(opts?: ListSessionsOptions): Promise<SessionSummary[]>;
866
+ /**
867
+ * Load full session data by ID.
868
+ * Returns null for a missing session. NEVER throws.
869
+ */
870
+ declare function loadSession(id: string): Promise<SessionData | null>;
871
+ /**
872
+ * Load append-order transcript data by ID.
873
+ *
874
+ * `loadSession` remains the active model-context API. This helper is for UI
875
+ * scrollback: it returns every persisted transcript-bearing lineage entry in
876
+ * append order and keeps the active branch in `activeMessages`.
877
+ */
878
+ declare function loadFullTranscript(id: string): Promise<FullTranscriptSessionData | null>;
879
+ /**
880
+ * Fork a session at an optional selector.
881
+ * Returns null for a missing session. NEVER throws.
882
+ */
883
+ declare function forkSession(id: string, opts?: {
884
+ selector?: string;
885
+ sessionId?: string;
886
+ title?: string;
887
+ }): Promise<{
888
+ sessionId: string;
889
+ data: SessionData;
890
+ } | null>;
891
+ /**
892
+ * Rewind a session to a previous user entry.
893
+ * Returns null for a missing session. NEVER throws.
894
+ */
895
+ declare function rewindSession(id: string, opts?: {
896
+ selector?: string;
897
+ }): Promise<SessionData | null>;
898
+ /**
899
+ * Set the active lineage entry by selector.
900
+ * Returns null for a missing session. NEVER throws.
901
+ */
902
+ declare function setActiveEntry(id: string, selector: string): Promise<SessionData | null>;
903
+ interface RunningSessionInfo {
904
+ readonly pid: number;
905
+ readonly startedAt: number;
906
+ readonly cwd: string;
907
+ /**
908
+ * v0.7.43 — populated from `PersistedSessionState.sessionId`, published
909
+ * by the REPL after `createInteractiveContext`. Remains `undefined` for
910
+ * a brief window during a peer's bootstrap (before the first sessionId
911
+ * is generated) and for peers running pre-v0.7.43 binaries; consumers
912
+ * MUST handle `undefined`.
913
+ */
914
+ readonly sessionId: string | undefined;
915
+ }
916
+ /**
917
+ * Returns live KodaX sibling instances (excluding this process).
918
+ * Uses discoverInstances() from @kodax-ai/agent (FEATURE_125 Team Mode).
919
+ * NEVER throws. Returns [] when no instances directory exists.
920
+ */
921
+ declare function listRunningSessions(): Promise<RunningSessionInfo[]>;
922
+ type DeleteSessionResult = {
923
+ ok: true;
924
+ } | {
925
+ error: {
926
+ code: 'session_running';
927
+ runningProcess: {
928
+ pid: number;
929
+ startedAt: number;
930
+ };
931
+ };
932
+ };
933
+ /**
934
+ * Delete a session by ID.
935
+ * Returns { ok: true } on success (including when the session doesn't exist).
936
+ * Returns an error envelope when the session is currently running.
937
+ * NEVER throws.
938
+ */
939
+ declare function deleteSession(id: string): Promise<DeleteSessionResult>;
940
+ /**
941
+ * FEATURE_219 (v0.7.46) — whole-session archive. Moves the session (and its
942
+ * island sidecar) into `<projectKey>/archived/`. Returns false for a missing
943
+ * session. NEVER throws. Archived sessions are hidden from the default listing
944
+ * and resurface only with `listSessions({ includeArchived: true })`.
945
+ */
946
+ declare function archiveSession(id: string): Promise<boolean>;
947
+ /** Restore an archived session back into its project directory. NEVER throws. */
948
+ declare function unarchiveSession(id: string): Promise<boolean>;
949
+ /**
950
+ * Watch the sessions directory for changes.
951
+ * Returns { close() } that stops the watcher / poll interval.
952
+ *
953
+ * Platform branches:
954
+ * - POSIX: fs.watch() with 100ms debounce.
955
+ * - Windows: readdir poll every 1000ms, diffed against a snapshot.
956
+ *
957
+ * NEVER throws — if the directory doesn't exist the watcher is a no-op
958
+ * until the directory is created.
959
+ */
960
+ declare function watchSessions(cb: WatchSessionsCallback): {
961
+ close: () => void;
962
+ };
963
+ /**
964
+ * Factory that returns an object with all session management methods bound.
965
+ *
966
+ * v0.7.43 (FEATURE_173 Part B follow-up) — the `sessionsDir` override is
967
+ * now honored. When provided, all read/write/watch operations go through
968
+ * that directory instead of the module-load-frozen `KODAX_SESSIONS_DIR`.
969
+ * `listRunningSessions` still consults the agent-config-home instances
970
+ * directory (sibling-process awareness is not scoped per sessions dir).
971
+ */
972
+ declare function createSessionManager(opts?: {
973
+ sessionsDir?: string;
974
+ }): SessionManager;
975
+
976
+ export { DEFAULT_UI_STATE as D, StreamingState as N, TextBuffer as Q, TOOL_STATUS_ICONS as T, ToolCallStatus as Z, archiveSession as a4, createSessionManager as a5, deleteSession as a6, extractHistorySeedsFromMessage as a7, extractHistorySeedsFromMessages as a8, extractTextContent as a9, extractTitle as aa, forkSession as ab, formatMessagePreview as ac, listRunningSessions as ad, listSessions as ae, loadFullTranscript as af, loadSession as ag, restoreHistoryItemsFromSession as ah, rewindSession as ai, seedToHistoryItem as aj, setActiveEntry as ak, toolCallSeedToHistoryToolCall as al, trimPersistedUiHistorySnapshot as am, unarchiveSession as an, watchSessions as ao, KeypressHandlerPriority as u };
977
+ export type { UIState as $, AppProps as A, SessionSummary as B, Completer as C, SessionTranscriptEntry as E, FullTranscriptSessionData as F, SessionTranscriptEntryType as G, HistoryEntry as H, InputPromptProps as I, StatusBarProps as J, KeyInfo as K, LegacyMessageListProps as L, Message as M, Suggestion as O, PastedContent as P, RestoreHistoryItemsFromSessionInput as R, SessionManager as S, TextBufferOptions as U, Theme as V, ThemeColors as W, ThemeSymbols as X, ToolCall as Y, UIActions as _, AppState as a, UseTextBufferReturn as a0, VisualCursor as a1, VisualLayout as a2, WatchSessionsCallback as a3, Completion as b, CreatableHistoryItem as c, CursorPosition as d, DeleteSessionResult as e, HistoryItem as f, HistoryItemAssistant as g, HistoryItemBase as h, HistoryItemError as i, HistoryItemEvent as j, HistoryItemHint as k, HistoryItemInfo as l, HistoryItemSystem as m, HistoryItemThinking as n, HistoryItemToolGroup as o, HistoryItemType as p, HistoryItemUser as q, HistorySeedSourceMessage as r, KeypressEvent as s, KeypressHandler as t, ListSessionsOptions as v, PromptEditingMode as w, PromptSubmitPayload as x, RestoredHistorySeed as y, RunningSessionInfo as z };