@codex-native/sdk 0.0.12 → 0.0.15
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/dist/cli.cjs +15 -12
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +15 -12
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.ts +2245 -447
- package/package.json +14 -12
- package/dist/codex_native.darwin-arm64.node +0 -0
- package/dist/index.js +0 -626
package/dist/index.d.ts
CHANGED
|
@@ -1,488 +1,2286 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ContentBlock } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { Diagnostic } from 'vscode-languageserver-types';
|
|
3
|
+
import { ModelProvider, Model, StreamEvent } from '@openai/agents-core';
|
|
4
|
+
import { tool } from '@openai/agents';
|
|
5
|
+
import { OpencodeClient, Event } from '@opencode-ai/sdk';
|
|
6
|
+
|
|
7
|
+
/** The status of a command execution. */
|
|
8
|
+
type CommandExecutionStatus = "in_progress" | "completed" | "failed";
|
|
9
|
+
/** A command executed by the agent. */
|
|
10
|
+
type CommandExecutionItem = {
|
|
11
|
+
id: string;
|
|
12
|
+
type: "command_execution";
|
|
13
|
+
/** The command line executed by the agent. */
|
|
14
|
+
command: string;
|
|
15
|
+
/** Aggregated stdout and stderr captured while the command was running. */
|
|
16
|
+
aggregated_output: string;
|
|
17
|
+
/** Set when the command exits; omitted while still running. */
|
|
18
|
+
exit_code?: number;
|
|
19
|
+
/** Current status of the command execution. */
|
|
20
|
+
status: CommandExecutionStatus;
|
|
21
|
+
};
|
|
22
|
+
/** Indicates the type of the file change. */
|
|
23
|
+
type PatchChangeKind = "add" | "delete" | "update";
|
|
24
|
+
/** A set of file changes by the agent. */
|
|
25
|
+
type FileUpdateChange = {
|
|
26
|
+
path: string;
|
|
27
|
+
kind: PatchChangeKind;
|
|
28
|
+
};
|
|
29
|
+
/** The status of a file change. */
|
|
30
|
+
type PatchApplyStatus = "completed" | "failed";
|
|
31
|
+
/** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
|
|
32
|
+
type FileChangeItem = {
|
|
33
|
+
id: string;
|
|
34
|
+
type: "file_change";
|
|
35
|
+
/** Individual file changes that comprise the patch. */
|
|
36
|
+
changes: FileUpdateChange[];
|
|
37
|
+
/** Whether the patch ultimately succeeded or failed. */
|
|
38
|
+
status: PatchApplyStatus;
|
|
39
|
+
};
|
|
40
|
+
/** The status of an MCP tool call. */
|
|
41
|
+
type McpToolCallStatus = "in_progress" | "completed" | "failed";
|
|
42
|
+
/**
|
|
43
|
+
* Represents a call to an MCP tool. The item starts when the invocation is dispatched
|
|
44
|
+
* and completes when the MCP server reports success or failure.
|
|
45
|
+
*/
|
|
46
|
+
type McpToolCallItem = {
|
|
47
|
+
id: string;
|
|
48
|
+
type: "mcp_tool_call";
|
|
49
|
+
/** Name of the MCP server handling the request. */
|
|
50
|
+
server: string;
|
|
51
|
+
/** The tool invoked on the MCP server. */
|
|
52
|
+
tool: string;
|
|
53
|
+
/** Arguments forwarded to the tool invocation. */
|
|
54
|
+
arguments: unknown;
|
|
55
|
+
/** Result payload returned by the MCP server for successful calls. */
|
|
56
|
+
result?: {
|
|
57
|
+
content: ContentBlock[];
|
|
58
|
+
structured_content: unknown;
|
|
59
|
+
};
|
|
60
|
+
/** Error message reported for failed calls. */
|
|
61
|
+
error?: {
|
|
62
|
+
message: string;
|
|
63
|
+
};
|
|
64
|
+
/** Current status of the tool invocation. */
|
|
65
|
+
status: McpToolCallStatus;
|
|
66
|
+
};
|
|
67
|
+
/** Response from the agent. Either natural-language text or JSON when structured output is requested. */
|
|
68
|
+
type AgentMessageItem = {
|
|
69
|
+
id: string;
|
|
70
|
+
type: "agent_message";
|
|
71
|
+
/** Either natural-language text or JSON when structured output is requested. */
|
|
72
|
+
text: string;
|
|
73
|
+
};
|
|
74
|
+
/** Agent's reasoning summary. */
|
|
75
|
+
type ReasoningItem = {
|
|
76
|
+
id: string;
|
|
77
|
+
type: "reasoning";
|
|
78
|
+
text: string;
|
|
79
|
+
};
|
|
80
|
+
/** Captures a web search request. Completes when results are returned to the agent. */
|
|
81
|
+
type WebSearchItem = {
|
|
82
|
+
id: string;
|
|
83
|
+
type: "web_search";
|
|
84
|
+
query: string;
|
|
85
|
+
};
|
|
86
|
+
/** Describes a non-fatal error surfaced as an item. */
|
|
87
|
+
type ErrorItem = {
|
|
88
|
+
id: string;
|
|
89
|
+
type: "error";
|
|
90
|
+
message: string;
|
|
91
|
+
};
|
|
92
|
+
/** An item in the agent's to-do list. */
|
|
93
|
+
type TodoItem = {
|
|
94
|
+
text: string;
|
|
95
|
+
completed: boolean;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Tracks the agent's running to-do list. Starts when the plan is issued, updates as steps change,
|
|
99
|
+
* and completes when the turn ends.
|
|
100
|
+
*/
|
|
101
|
+
type TodoListItem = {
|
|
102
|
+
id: string;
|
|
103
|
+
type: "todo_list";
|
|
104
|
+
items: TodoItem[];
|
|
105
|
+
};
|
|
106
|
+
/** Canonical union of thread items and their type-specific payloads. */
|
|
107
|
+
type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | WebSearchItem | TodoListItem | ErrorItem;
|
|
108
|
+
|
|
109
|
+
/** Emitted when a new thread is started as the first event. */
|
|
110
|
+
type ThreadStartedEvent = {
|
|
111
|
+
type: "thread.started";
|
|
112
|
+
/** The identifier of the new thread. Can be used to resume the thread later. */
|
|
113
|
+
thread_id: string;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Emitted when a turn is started by sending a new prompt to the model.
|
|
117
|
+
* A turn encompasses all events that happen while the agent is processing the prompt.
|
|
118
|
+
*/
|
|
119
|
+
type TurnStartedEvent = {
|
|
120
|
+
type: "turn.started";
|
|
121
|
+
};
|
|
122
|
+
/** Describes the usage of tokens during a turn. */
|
|
123
|
+
type Usage = {
|
|
124
|
+
/** The number of input tokens used during the turn. */
|
|
125
|
+
input_tokens: number;
|
|
126
|
+
/** The number of cached input tokens used during the turn. */
|
|
127
|
+
cached_input_tokens: number;
|
|
128
|
+
/** The number of output tokens used during the turn. */
|
|
129
|
+
output_tokens: number;
|
|
130
|
+
};
|
|
131
|
+
/** Emitted when a turn is completed. Typically right after the assistant's response. */
|
|
132
|
+
type TurnCompletedEvent = {
|
|
133
|
+
type: "turn.completed";
|
|
134
|
+
usage: Usage;
|
|
135
|
+
};
|
|
136
|
+
/** Indicates that a turn failed with an error. */
|
|
137
|
+
type TurnFailedEvent = {
|
|
138
|
+
type: "turn.failed";
|
|
139
|
+
error: ThreadError;
|
|
140
|
+
};
|
|
141
|
+
/** Background notification emitted during an active turn. */
|
|
142
|
+
type BackgroundEvent = {
|
|
143
|
+
type: "background_event";
|
|
144
|
+
message: string;
|
|
145
|
+
};
|
|
146
|
+
/** Emitted when a new item is added to the thread. Typically the item is initially "in progress". */
|
|
147
|
+
type ItemStartedEvent = {
|
|
148
|
+
type: "item.started";
|
|
149
|
+
item: ThreadItem;
|
|
150
|
+
};
|
|
151
|
+
/** Emitted when an item is updated. */
|
|
152
|
+
type ItemUpdatedEvent = {
|
|
153
|
+
type: "item.updated";
|
|
154
|
+
item: ThreadItem;
|
|
155
|
+
};
|
|
156
|
+
/** Signals that an item has reached a terminal state—either success or failure. */
|
|
157
|
+
type ItemCompletedEvent = {
|
|
158
|
+
type: "item.completed";
|
|
159
|
+
item: ThreadItem;
|
|
160
|
+
};
|
|
161
|
+
/** Fatal error emitted by the stream. */
|
|
162
|
+
type ThreadError = {
|
|
163
|
+
message: string;
|
|
164
|
+
};
|
|
165
|
+
/** Represents an unrecoverable error emitted directly by the event stream. */
|
|
166
|
+
type ThreadErrorEvent = {
|
|
167
|
+
type: "error";
|
|
168
|
+
message: string;
|
|
169
|
+
};
|
|
170
|
+
/** Review finding with code location */
|
|
171
|
+
type ReviewFinding = {
|
|
172
|
+
title: string;
|
|
173
|
+
body: string;
|
|
174
|
+
confidence_score: number;
|
|
175
|
+
priority: number;
|
|
176
|
+
code_location: {
|
|
177
|
+
absolute_file_path: string;
|
|
178
|
+
line_range: {
|
|
179
|
+
start: number;
|
|
180
|
+
end: number;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
/** Structured review output */
|
|
185
|
+
type ReviewOutputEvent = {
|
|
186
|
+
findings: ReviewFinding[];
|
|
187
|
+
overall_correctness: string;
|
|
188
|
+
overall_explanation: string;
|
|
189
|
+
overall_confidence_score: number;
|
|
190
|
+
};
|
|
191
|
+
/** Emitted when exiting review mode with optional structured results */
|
|
192
|
+
type ExitedReviewModeEvent = {
|
|
193
|
+
type: "exited_review_mode";
|
|
194
|
+
review_output: ReviewOutputEvent | null;
|
|
195
|
+
};
|
|
196
|
+
/** Top-level JSONL events emitted by codex exec. */
|
|
197
|
+
type ThreadEvent = ThreadStartedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | BackgroundEvent | ItemStartedEvent | ItemUpdatedEvent | ItemCompletedEvent | ExitedReviewModeEvent | ThreadErrorEvent | RawThreadEvent;
|
|
198
|
+
/** Raw protocol event forwarded without transformation. */
|
|
199
|
+
type RawThreadEvent = {
|
|
200
|
+
type: "raw_event";
|
|
201
|
+
raw: unknown;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
type SkillDefinition = {
|
|
205
|
+
/**
|
|
206
|
+
* Skill name referenced via `$<name>` (default) or `@<name>` in prompts.
|
|
207
|
+
*/
|
|
208
|
+
name: string;
|
|
209
|
+
/**
|
|
210
|
+
* Optional human description (not currently injected automatically).
|
|
211
|
+
*/
|
|
212
|
+
description?: string;
|
|
213
|
+
/**
|
|
214
|
+
* The skill body/instructions that will be injected when referenced.
|
|
215
|
+
*/
|
|
216
|
+
contents: string;
|
|
217
|
+
};
|
|
218
|
+
type SkillMentionTrigger = "$" | "@";
|
|
219
|
+
|
|
220
|
+
type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
|
|
221
|
+
type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
|
|
222
|
+
/**
|
|
223
|
+
* Reasoning effort level for reasoning-capable models (e.g., o1, o3).
|
|
224
|
+
* See https://platform.openai.com/docs/guides/reasoning
|
|
225
|
+
*
|
|
226
|
+
* @default "medium" - When undefined, codex uses "medium" as the default
|
|
227
|
+
*/
|
|
228
|
+
type ReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
229
|
+
/**
|
|
230
|
+
* Controls whether reasoning summaries are included for reasoning-capable models.
|
|
231
|
+
* See https://platform.openai.com/docs/guides/reasoning#reasoning-summaries
|
|
232
|
+
*
|
|
233
|
+
* @default "auto" - When undefined, codex uses "auto" as the default
|
|
234
|
+
*/
|
|
235
|
+
type ReasoningSummary = "auto" | "concise" | "detailed" | "none";
|
|
236
|
+
type WorkspaceWriteOptions = {
|
|
237
|
+
/** Enable network access in workspace-write mode. Default: false */
|
|
238
|
+
networkAccess?: boolean;
|
|
239
|
+
/** Additional directories that should be writable */
|
|
240
|
+
writableRoots?: string[];
|
|
241
|
+
/** Exclude the TMPDIR environment variable from writable roots. Default: false */
|
|
242
|
+
excludeTmpdirEnvVar?: boolean;
|
|
243
|
+
/** Exclude /tmp from writable roots on Unix. Default: false */
|
|
244
|
+
excludeSlashTmp?: boolean;
|
|
245
|
+
};
|
|
246
|
+
type ThreadOptions = {
|
|
247
|
+
model?: string;
|
|
248
|
+
/** Override the model provider declared in config.toml */
|
|
249
|
+
modelProvider?: string;
|
|
250
|
+
/** Use local OSS provider via Ollama (pulls models as needed) */
|
|
251
|
+
oss?: boolean;
|
|
252
|
+
sandboxMode?: SandboxMode;
|
|
253
|
+
/** Approval policy for command execution */
|
|
254
|
+
approvalMode?: ApprovalMode;
|
|
255
|
+
/** Options for workspace-write sandbox mode */
|
|
256
|
+
workspaceWriteOptions?: WorkspaceWriteOptions;
|
|
257
|
+
workingDirectory?: string;
|
|
258
|
+
skipGitRepoCheck?: boolean;
|
|
259
|
+
/** Reasoning effort level (only honored for reasoning-capable models). Defaults to "medium" when undefined. */
|
|
260
|
+
reasoningEffort?: ReasoningEffort;
|
|
261
|
+
/** Reasoning summary preference (only honored for reasoning-capable models). Defaults to "auto" when undefined. */
|
|
262
|
+
reasoningSummary?: ReasoningSummary;
|
|
263
|
+
/** @deprecated Use sandboxMode and approvalMode instead */
|
|
264
|
+
fullAuto?: boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Programmatically registered skills (no SKILL.md files required) for this thread.
|
|
267
|
+
* These augment any skills registered on the parent Codex instance.
|
|
268
|
+
*/
|
|
269
|
+
skills?: SkillDefinition[] | Record<string, string | Omit<SkillDefinition, "name">>;
|
|
270
|
+
/**
|
|
271
|
+
* Prefixes that activate skills when present immediately before the skill name.
|
|
272
|
+
*
|
|
273
|
+
* Defaults to `["$"]` when omitted.
|
|
274
|
+
*/
|
|
275
|
+
skillMentionTriggers?: SkillMentionTrigger[];
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
type TurnOptions = {
|
|
279
|
+
/** JSON schema describing the expected agent output. */
|
|
280
|
+
outputSchema?: unknown;
|
|
281
|
+
/** Whether to use OSS mode with Ollama models */
|
|
282
|
+
oss?: boolean;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
type NativeConversationSummary = {
|
|
286
|
+
id: string;
|
|
287
|
+
path: string;
|
|
288
|
+
createdAt?: string;
|
|
289
|
+
updatedAt?: string;
|
|
290
|
+
};
|
|
291
|
+
type NativeConversationListPage = {
|
|
292
|
+
conversations: NativeConversationSummary[];
|
|
293
|
+
nextCursor?: string;
|
|
294
|
+
numScannedFiles: number;
|
|
295
|
+
reachedScanCap: boolean;
|
|
296
|
+
};
|
|
297
|
+
type NativeTuiRequest = {
|
|
298
|
+
prompt?: string;
|
|
299
|
+
images?: string[];
|
|
300
|
+
model?: string;
|
|
301
|
+
oss?: boolean;
|
|
302
|
+
sandboxMode?: SandboxMode;
|
|
303
|
+
approvalMode?: ApprovalMode;
|
|
304
|
+
resumeSessionId?: string;
|
|
305
|
+
resumeLast?: boolean;
|
|
306
|
+
resumePicker?: boolean;
|
|
307
|
+
fullAuto?: boolean;
|
|
308
|
+
dangerouslyBypassApprovalsAndSandbox?: boolean;
|
|
309
|
+
workingDirectory?: string;
|
|
310
|
+
configProfile?: string;
|
|
311
|
+
configOverrides?: string[];
|
|
312
|
+
addDir?: string[];
|
|
313
|
+
webSearch?: boolean;
|
|
314
|
+
linuxSandboxPath?: string;
|
|
315
|
+
baseUrl?: string;
|
|
316
|
+
apiKey?: string;
|
|
317
|
+
reasoningEffort?: ReasoningEffort;
|
|
318
|
+
reasoningSummary?: ReasoningSummary;
|
|
319
|
+
};
|
|
320
|
+
type NativeTokenUsage = {
|
|
321
|
+
inputTokens: number;
|
|
322
|
+
cachedInputTokens: number;
|
|
323
|
+
outputTokens: number;
|
|
324
|
+
reasoningOutputTokens: number;
|
|
325
|
+
totalTokens: number;
|
|
326
|
+
};
|
|
327
|
+
type NativeUpdateActionKind = "npmGlobalLatest" | "bunGlobalLatest" | "brewUpgrade";
|
|
328
|
+
type NativeUpdateActionInfo = {
|
|
329
|
+
kind: NativeUpdateActionKind;
|
|
330
|
+
command: string;
|
|
331
|
+
};
|
|
332
|
+
type NativeTuiExitInfo = {
|
|
333
|
+
tokenUsage: NativeTokenUsage;
|
|
334
|
+
conversationId?: string;
|
|
335
|
+
updateAction?: NativeUpdateActionInfo;
|
|
336
|
+
};
|
|
337
|
+
type RepoDiffFileChange = {
|
|
338
|
+
path: string;
|
|
339
|
+
status: string;
|
|
340
|
+
diff: string;
|
|
341
|
+
truncated: boolean;
|
|
342
|
+
previousPath?: string | null;
|
|
343
|
+
};
|
|
344
|
+
type RepoDiffSummary = {
|
|
345
|
+
repoPath: string;
|
|
346
|
+
branch: string;
|
|
347
|
+
baseBranch: string;
|
|
348
|
+
upstreamRef?: string | null;
|
|
349
|
+
mergeBase: string;
|
|
350
|
+
statusSummary: string;
|
|
351
|
+
diffStat: string;
|
|
352
|
+
recentCommits: string;
|
|
353
|
+
changedFiles: RepoDiffFileChange[];
|
|
354
|
+
totalChangedFiles: number;
|
|
355
|
+
};
|
|
356
|
+
type RepoDiffSummaryOptions = {
|
|
357
|
+
cwd?: string;
|
|
358
|
+
baseBranchOverride?: string;
|
|
359
|
+
maxFiles?: number;
|
|
360
|
+
diffContextLines?: number;
|
|
361
|
+
diffCharLimit?: number;
|
|
362
|
+
};
|
|
363
|
+
type ReverieConversation = {
|
|
364
|
+
id: string;
|
|
365
|
+
path: string;
|
|
366
|
+
createdAt?: string;
|
|
367
|
+
updatedAt?: string;
|
|
368
|
+
headRecords: string[];
|
|
369
|
+
tailRecords: string[];
|
|
370
|
+
headRecordsToon: string[];
|
|
371
|
+
tailRecordsToon: string[];
|
|
372
|
+
};
|
|
373
|
+
type ReverieSearchResult = {
|
|
374
|
+
conversation: ReverieConversation;
|
|
375
|
+
relevanceScore: number;
|
|
376
|
+
matchingExcerpts: string[];
|
|
377
|
+
insights: string[];
|
|
378
|
+
rerankerScore?: number;
|
|
379
|
+
};
|
|
380
|
+
type FastEmbedRerankerModelCode = "BAAI/bge-reranker-base" | "rozgo/bge-reranker-v2-m3" | "jinaai/jina-reranker-v1-turbo-en" | "jinaai/jina-reranker-v2-base-multilingual";
|
|
381
|
+
type ReverieSemanticSearchOptions = {
|
|
382
|
+
limit?: number;
|
|
383
|
+
maxCandidates?: number;
|
|
384
|
+
projectRoot?: string;
|
|
385
|
+
batchSize?: number;
|
|
386
|
+
normalize?: boolean;
|
|
387
|
+
cache?: boolean;
|
|
388
|
+
rerankerModel?: FastEmbedRerankerModelCode;
|
|
389
|
+
rerankerCacheDir?: string;
|
|
390
|
+
rerankerMaxLength?: number;
|
|
391
|
+
rerankerShowProgress?: boolean;
|
|
392
|
+
rerankerBatchSize?: number;
|
|
393
|
+
rerankerTopK?: number;
|
|
394
|
+
};
|
|
395
|
+
type ReverieSemanticIndexStats = {
|
|
396
|
+
conversationsIndexed: number;
|
|
397
|
+
documentsEmbedded: number;
|
|
398
|
+
batches: number;
|
|
399
|
+
};
|
|
400
|
+
type FastEmbedInitOptions = {
|
|
401
|
+
model?: string;
|
|
402
|
+
cacheDir?: string;
|
|
403
|
+
maxLength?: number;
|
|
404
|
+
showDownloadProgress?: boolean;
|
|
405
|
+
};
|
|
406
|
+
type FastEmbedEmbedRequest = {
|
|
407
|
+
inputs: string[];
|
|
408
|
+
batchSize?: number;
|
|
409
|
+
normalize?: boolean;
|
|
410
|
+
projectRoot?: string;
|
|
411
|
+
cache?: boolean;
|
|
412
|
+
};
|
|
413
|
+
type TokenizerOptions = {
|
|
414
|
+
model?: string;
|
|
415
|
+
encoding?: "o200k_base" | "cl100k_base";
|
|
416
|
+
};
|
|
417
|
+
type TokenizerEncodeOptions = TokenizerOptions & {
|
|
418
|
+
withSpecialTokens?: boolean;
|
|
419
|
+
};
|
|
420
|
+
type NativeToolInfo = {
|
|
421
|
+
name: string;
|
|
422
|
+
description?: string;
|
|
423
|
+
parameters?: unknown;
|
|
424
|
+
strict?: boolean;
|
|
425
|
+
supportsParallel?: boolean;
|
|
426
|
+
};
|
|
427
|
+
type NativeToolInvocation = {
|
|
428
|
+
toolName: string;
|
|
429
|
+
callId: string;
|
|
430
|
+
arguments?: string;
|
|
431
|
+
input?: string;
|
|
432
|
+
};
|
|
433
|
+
type NativeToolResult = {
|
|
434
|
+
output?: string;
|
|
435
|
+
success?: boolean;
|
|
436
|
+
error?: string;
|
|
437
|
+
};
|
|
438
|
+
type NativeForkResult = {
|
|
439
|
+
threadId: string;
|
|
440
|
+
rolloutPath: string;
|
|
441
|
+
};
|
|
442
|
+
type ApprovalRequest = {
|
|
443
|
+
type: "shell" | "file_write" | "network_access";
|
|
444
|
+
details?: unknown;
|
|
445
|
+
context?: string;
|
|
446
|
+
};
|
|
447
|
+
declare function reverieListConversations(codexHomePath: string, limit?: number, offset?: number): Promise<ReverieConversation[]>;
|
|
448
|
+
declare function reverieSearchConversations(codexHomePath: string, query: string, limit?: number): Promise<ReverieSearchResult[]>;
|
|
449
|
+
declare function reverieSearchSemantic(codexHomePath: string, context: string, options?: ReverieSemanticSearchOptions): Promise<ReverieSearchResult[]>;
|
|
450
|
+
declare function reverieIndexSemantic(codexHomePath: string, options?: ReverieSemanticSearchOptions): Promise<ReverieSemanticIndexStats>;
|
|
451
|
+
declare function reverieGetConversationInsights(conversationPath: string, query?: string): Promise<string[]>;
|
|
452
|
+
declare function encodeToToon(value: unknown): string;
|
|
453
|
+
declare function fastEmbedInit(options: FastEmbedInitOptions): Promise<void>;
|
|
454
|
+
declare function fastEmbedEmbed(request: FastEmbedEmbedRequest): Promise<number[][]>;
|
|
455
|
+
declare function tokenizerCount(text: string, options?: TokenizerOptions): number;
|
|
456
|
+
declare function tokenizerEncode(text: string, options?: TokenizerEncodeOptions): number[];
|
|
457
|
+
declare function tokenizerDecode(tokens: number[], options?: TokenizerOptions): string;
|
|
458
|
+
declare function collectRepoDiffSummary(options?: RepoDiffSummaryOptions): Promise<RepoDiffSummary>;
|
|
459
|
+
|
|
460
|
+
interface TuiSession {
|
|
461
|
+
wait(): Promise<NativeTuiExitInfo>;
|
|
462
|
+
shutdown(): void;
|
|
463
|
+
readonly closed: boolean;
|
|
9
464
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(threadId: string, title?: string | undefined | null)
|
|
13
|
-
sendMessage(message: string): void
|
|
14
|
-
receiveMessage(message: string): void
|
|
15
|
-
updateStatus(status: string): void
|
|
16
|
-
appendOutput(output: string): void
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export declare class LayoutManager {
|
|
20
|
-
constructor()
|
|
21
|
-
setSplit(orientation: string, ratio: number, leftId: string, rightId: string): void
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export declare class StatusBoard {
|
|
25
|
-
constructor(layout?: string | undefined | null)
|
|
26
|
-
addTextTile(id: string, title: string, value: string): void
|
|
27
|
-
addProgressTile(id: string, title: string, value: number): void
|
|
28
|
-
updateTile(id: string, value: string): void
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export declare class TuiApp {
|
|
32
|
-
constructor(title?: string | undefined | null, width?: number | undefined | null, height?: number | undefined | null)
|
|
33
|
-
addComponent(id: string, componentType: WidgetType): void
|
|
34
|
-
startTerminal(): void
|
|
35
|
-
stopTerminal(): void
|
|
465
|
+
interface RunTuiOptions {
|
|
466
|
+
signal?: AbortSignal;
|
|
36
467
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
468
|
+
/**
|
|
469
|
+
* Starts the Codex TUI (Terminal User Interface) and returns a controllable session handle.
|
|
470
|
+
*
|
|
471
|
+
* Use {@link TuiSession.wait} to await completion or {@link TuiSession.shutdown} to
|
|
472
|
+
* request a graceful exit from another part of your program.
|
|
473
|
+
*/
|
|
474
|
+
declare function startTui(request: NativeTuiRequest): TuiSession;
|
|
475
|
+
/**
|
|
476
|
+
* Launches the Codex TUI and waits for it to exit. Supports optional cancellation via AbortSignal.
|
|
477
|
+
*/
|
|
478
|
+
declare function runTui(request: NativeTuiRequest, options?: RunTuiOptions): Promise<NativeTuiExitInfo>;
|
|
479
|
+
|
|
480
|
+
/** Completed turn. */
|
|
481
|
+
type Turn = {
|
|
482
|
+
items: ThreadItem[];
|
|
483
|
+
finalResponse: string;
|
|
484
|
+
usage: Usage | null;
|
|
485
|
+
};
|
|
486
|
+
/** Alias for `Turn` to describe the result of `run()`. */
|
|
487
|
+
type RunResult = Turn;
|
|
488
|
+
/** The result of the `runStreamed` method. */
|
|
489
|
+
type StreamedTurn = {
|
|
490
|
+
events: AsyncGenerator<ThreadEvent>;
|
|
491
|
+
};
|
|
492
|
+
/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */
|
|
493
|
+
type RunStreamedResult = StreamedTurn;
|
|
494
|
+
/** An input to send to the agent. */
|
|
495
|
+
type UserInput = {
|
|
496
|
+
type: "text";
|
|
497
|
+
text: string;
|
|
498
|
+
} | {
|
|
499
|
+
type: "local_image";
|
|
500
|
+
path: string;
|
|
501
|
+
};
|
|
502
|
+
type Input = string | UserInput[];
|
|
503
|
+
type ForkOptions = {
|
|
504
|
+
nthUserMessage: number;
|
|
505
|
+
threadOptions?: Partial<ThreadOptions>;
|
|
506
|
+
};
|
|
507
|
+
/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */
|
|
508
|
+
declare class Thread {
|
|
509
|
+
private _exec;
|
|
510
|
+
private _options;
|
|
511
|
+
private _id;
|
|
512
|
+
private _threadOptions;
|
|
513
|
+
private _eventListeners;
|
|
514
|
+
private _approvalHandler;
|
|
515
|
+
private readonly _skills;
|
|
516
|
+
private readonly _skillMentionTriggers;
|
|
517
|
+
private readonly _codexSkills?;
|
|
518
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
519
|
+
get id(): string | null;
|
|
520
|
+
/**
|
|
521
|
+
* Register an event listener for thread events.
|
|
522
|
+
* @param listener Callback function that receives ThreadEvent objects
|
|
523
|
+
* @returns Unsubscribe function to remove the listener
|
|
524
|
+
*/
|
|
525
|
+
onEvent(listener: (event: ThreadEvent) => void): () => void;
|
|
526
|
+
/**
|
|
527
|
+
* Remove an event listener.
|
|
528
|
+
* @param listener The listener function to remove
|
|
529
|
+
*/
|
|
530
|
+
offEvent(listener: (event: ThreadEvent) => void): void;
|
|
531
|
+
/**
|
|
532
|
+
* Register a callback to handle approval requests from the agent.
|
|
533
|
+
* The handler should return true to approve the action, false to deny it.
|
|
534
|
+
*
|
|
535
|
+
* @param handler Callback function that receives ApprovalRequest and returns approval decision
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* thread.onApprovalRequest(async (request) => {
|
|
539
|
+
* console.log(`Approval requested for ${request.type}`);
|
|
540
|
+
* return true; // Auto-approve
|
|
541
|
+
* });
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
onApprovalRequest(handler: (request: ApprovalRequest) => boolean | Promise<boolean>): void;
|
|
545
|
+
/**
|
|
546
|
+
* Emit a background notification while the agent is running the current turn.
|
|
547
|
+
* The message is surfaced to event subscribers but does not modify the user input queue.
|
|
548
|
+
*
|
|
549
|
+
* @throws Error if the thread has not been started yet.
|
|
550
|
+
*/
|
|
551
|
+
sendBackgroundEvent(message: string): Promise<void>;
|
|
552
|
+
/**
|
|
553
|
+
* Programmatically update the agent's plan/todo list.
|
|
554
|
+
* The plan will be applied at the start of the next turn.
|
|
555
|
+
*
|
|
556
|
+
* @param args The plan update arguments
|
|
557
|
+
* @throws Error if no thread ID is available
|
|
558
|
+
*/
|
|
559
|
+
updatePlan(args: {
|
|
560
|
+
explanation?: string;
|
|
561
|
+
plan: Array<{
|
|
562
|
+
step: string;
|
|
563
|
+
status: "pending" | "in_progress" | "completed";
|
|
564
|
+
}>;
|
|
565
|
+
}): void;
|
|
566
|
+
/**
|
|
567
|
+
* Modify the agent's plan/todo list with granular operations.
|
|
568
|
+
* Changes will be applied at the start of the next turn.
|
|
569
|
+
*
|
|
570
|
+
* @param operations Array of operations to perform on the plan
|
|
571
|
+
* @throws Error if no thread ID is available
|
|
572
|
+
*/
|
|
573
|
+
modifyPlan(operations: Array<{
|
|
574
|
+
type: "add";
|
|
575
|
+
item: {
|
|
576
|
+
step: string;
|
|
577
|
+
status?: "pending" | "in_progress" | "completed";
|
|
578
|
+
};
|
|
579
|
+
} | {
|
|
580
|
+
type: "update";
|
|
581
|
+
index: number;
|
|
582
|
+
updates: Partial<{
|
|
583
|
+
step: string;
|
|
584
|
+
status: "pending" | "in_progress" | "completed";
|
|
585
|
+
}>;
|
|
586
|
+
} | {
|
|
587
|
+
type: "remove";
|
|
588
|
+
index: number;
|
|
589
|
+
} | {
|
|
590
|
+
type: "reorder";
|
|
591
|
+
newOrder: number[];
|
|
592
|
+
}>): void;
|
|
593
|
+
/**
|
|
594
|
+
* Add a new todo item to the agent's plan.
|
|
595
|
+
*
|
|
596
|
+
* @param step The todo step description
|
|
597
|
+
* @param status The initial status (defaults to "pending")
|
|
598
|
+
*/
|
|
599
|
+
addTodo(step: string, status?: "pending" | "in_progress" | "completed"): void;
|
|
600
|
+
/**
|
|
601
|
+
* Update an existing todo item.
|
|
602
|
+
*
|
|
603
|
+
* @param index The index of the todo item to update
|
|
604
|
+
* @param updates The updates to apply
|
|
605
|
+
*/
|
|
606
|
+
updateTodo(index: number, updates: Partial<{
|
|
607
|
+
step: string;
|
|
608
|
+
status: "pending" | "in_progress" | "completed";
|
|
609
|
+
}>): void;
|
|
610
|
+
/**
|
|
611
|
+
* Remove a todo item from the plan.
|
|
612
|
+
*
|
|
613
|
+
* @param index The index of the todo item to remove
|
|
614
|
+
*/
|
|
615
|
+
removeTodo(index: number): void;
|
|
616
|
+
/**
|
|
617
|
+
* Reorder the todo items in the plan.
|
|
618
|
+
*
|
|
619
|
+
* @param newOrder Array of indices representing the new order
|
|
620
|
+
*/
|
|
621
|
+
reorderTodos(newOrder: number[]): void;
|
|
622
|
+
/** Compacts the conversation history for this thread using Codex's builtin compaction. */
|
|
623
|
+
compact(): Promise<void>;
|
|
624
|
+
/**
|
|
625
|
+
* Fork this thread at the specified user message, returning a new thread that starts
|
|
626
|
+
* from the conversation history prior to that message.
|
|
627
|
+
*
|
|
628
|
+
* @param options Fork configuration including which user message to branch before and optional thread overrides.
|
|
629
|
+
*/
|
|
630
|
+
fork(options: ForkOptions): Promise<Thread>;
|
|
631
|
+
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
632
|
+
runStreamed(input: Input, turnOptions?: TurnOptions): Promise<StreamedTurn>;
|
|
633
|
+
private runStreamedInternal;
|
|
634
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
635
|
+
run(input: Input, turnOptions?: TurnOptions): Promise<Turn>;
|
|
636
|
+
private buildTuiRequest;
|
|
637
|
+
/**
|
|
638
|
+
* Launches the interactive Codex TUI (Terminal User Interface) for this thread and returns a session handle.
|
|
639
|
+
*
|
|
640
|
+
* The handle allows advanced workflows where the TUI can be started and stopped programmatically,
|
|
641
|
+
* while preserving the underlying conversation state.
|
|
642
|
+
*/
|
|
643
|
+
launchTui(overrides?: Partial<NativeTuiRequest>): TuiSession;
|
|
644
|
+
/**
|
|
645
|
+
* Launches the interactive Codex TUI (Terminal User Interface) for this thread.
|
|
646
|
+
*
|
|
647
|
+
* This method enables seamless transition from programmatic agent interaction to
|
|
648
|
+
* interactive terminal chat within the same session. The TUI takes over the terminal
|
|
649
|
+
* and allows you to continue the conversation interactively.
|
|
650
|
+
*
|
|
651
|
+
* @param overrides - Optional configuration to override thread defaults. Supports all TUI options
|
|
652
|
+
* including prompt, sandbox mode, approval mode, and resume options.
|
|
653
|
+
* @param options - Optional run options including an AbortSignal to request shutdown.
|
|
654
|
+
* @returns A Promise that resolves to TUI exit information including:
|
|
655
|
+
* - tokenUsage: Token consumption statistics
|
|
656
|
+
* - conversationId: Session ID for resuming later
|
|
657
|
+
* - updateAction: Optional suggested update command
|
|
658
|
+
* @throws {Error} If not in a trusted git repository (unless skipGitRepoCheck is set)
|
|
659
|
+
* @throws {Error} If the terminal is not interactive (TTY required)
|
|
660
|
+
*/
|
|
661
|
+
tui(overrides?: Partial<NativeTuiRequest>, options?: RunTuiOptions): Promise<NativeTuiExitInfo>;
|
|
662
|
+
private wrapTuiSession;
|
|
663
|
+
private attachDefaultLspBridge;
|
|
664
|
+
private registerSkillsFromConfig;
|
|
665
|
+
private buildNativeInputItems;
|
|
176
666
|
}
|
|
177
667
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
668
|
+
type NativeToolDefinition = NativeToolInfo & {
|
|
669
|
+
handler: (call: NativeToolInvocation) => Promise<NativeToolResult> | NativeToolResult;
|
|
670
|
+
};
|
|
671
|
+
type CodexOptions = {
|
|
672
|
+
codexPathOverride?: string;
|
|
673
|
+
baseUrl?: string;
|
|
674
|
+
apiKey?: string;
|
|
675
|
+
/** Optional model provider override to use instead of the default */
|
|
676
|
+
modelProvider?: string;
|
|
677
|
+
/** Default model to use when a thread omits an explicit choice */
|
|
678
|
+
defaultModel?: string;
|
|
679
|
+
tools?: NativeToolDefinition[];
|
|
680
|
+
/**
|
|
681
|
+
* When true, constructor will not clear already-registered tools on the native binding.
|
|
682
|
+
* Useful when other code (CLI, plugins) pre-register tools before instantiating Codex.
|
|
683
|
+
*/
|
|
684
|
+
preserveRegisteredTools?: boolean;
|
|
685
|
+
/**
|
|
686
|
+
* Programmatically registered skills (no SKILL.md files required).
|
|
687
|
+
*
|
|
688
|
+
* Mention a skill by name in prompts using `$<name>` (default) or `@<name>` if enabled.
|
|
689
|
+
*/
|
|
690
|
+
skills?: SkillDefinition[] | Record<string, string | Omit<SkillDefinition, "name">>;
|
|
691
|
+
/**
|
|
692
|
+
* Prefixes that activate skills when present immediately before the skill name.
|
|
693
|
+
*
|
|
694
|
+
* Defaults to `["$"]` to match Codex CLI/TUI behavior.
|
|
695
|
+
*/
|
|
696
|
+
skillMentionTriggers?: SkillMentionTrigger[];
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
type CurrentChangesReview = {
|
|
700
|
+
type: "current_changes";
|
|
701
|
+
};
|
|
702
|
+
type BranchReview = {
|
|
703
|
+
type: "branch";
|
|
704
|
+
baseBranch: string;
|
|
705
|
+
};
|
|
706
|
+
type CommitReview = {
|
|
707
|
+
type: "commit";
|
|
708
|
+
sha: string;
|
|
709
|
+
subject?: string;
|
|
710
|
+
};
|
|
711
|
+
type CustomReview = {
|
|
712
|
+
type: "custom";
|
|
713
|
+
prompt: string;
|
|
714
|
+
hint?: string;
|
|
715
|
+
};
|
|
716
|
+
type ReviewTarget = CurrentChangesReview | BranchReview | CommitReview | CustomReview;
|
|
717
|
+
type ReviewInvocationOptions = {
|
|
718
|
+
target: ReviewTarget;
|
|
719
|
+
threadOptions?: ThreadOptions;
|
|
720
|
+
turnOptions?: TurnOptions;
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
type NativeToolInterceptorContext = {
|
|
724
|
+
invocation: NativeToolInvocation;
|
|
725
|
+
callBuiltin: (invocation?: NativeToolInvocation) => Promise<NativeToolResult>;
|
|
726
|
+
};
|
|
727
|
+
type ConversationSummary = NativeConversationSummary;
|
|
728
|
+
type ConversationListPage = NativeConversationListPage;
|
|
729
|
+
type ConversationListOptions = ThreadOptions & {
|
|
730
|
+
pageSize?: number;
|
|
731
|
+
cursor?: string;
|
|
732
|
+
modelProviders?: string[];
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Codex is the main class for interacting with the Codex agent.
|
|
737
|
+
*
|
|
738
|
+
* This is the native NAPI-based implementation that uses Rust bindings directly.
|
|
739
|
+
*
|
|
740
|
+
* Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
|
|
741
|
+
*/
|
|
742
|
+
declare class Codex {
|
|
743
|
+
private exec;
|
|
744
|
+
private options;
|
|
745
|
+
private readonly nativeBinding;
|
|
746
|
+
private readonly lspForTools;
|
|
747
|
+
private readonly skills;
|
|
748
|
+
private readonly skillMentionTriggers;
|
|
749
|
+
constructor(options?: CodexOptions);
|
|
750
|
+
registerSkill(skill: SkillDefinition): void;
|
|
751
|
+
registerSkills(skills: SkillDefinition[]): void;
|
|
752
|
+
listSkills(): SkillDefinition[];
|
|
753
|
+
clearSkills(): void;
|
|
754
|
+
private registerSkillsFromConfig;
|
|
755
|
+
/**
|
|
756
|
+
* Register a tool for Codex. When `tool.name` matches a built-in Codex tool,
|
|
757
|
+
* the native implementation is replaced for this Codex instance.
|
|
758
|
+
*/
|
|
759
|
+
registerTool(tool: NativeToolDefinition): void;
|
|
760
|
+
/**
|
|
761
|
+
* Register a tool interceptor for Codex. Interceptors can modify tool invocations
|
|
762
|
+
* and results, and can call the built-in implementation.
|
|
763
|
+
*/
|
|
764
|
+
registerToolInterceptor(toolName: string, handler: (context: NativeToolInterceptorContext) => Promise<NativeToolResult> | NativeToolResult): void;
|
|
765
|
+
/**
|
|
766
|
+
* Clear all registered tools, restoring built-in defaults.
|
|
767
|
+
*/
|
|
768
|
+
clearTools(): void;
|
|
769
|
+
private buildConversationConfig;
|
|
770
|
+
private createLspManagerForTools;
|
|
771
|
+
private registerDefaultReadFileInterceptor;
|
|
772
|
+
/**
|
|
773
|
+
* Register a programmatic approval callback that Codex will call before executing
|
|
774
|
+
* sensitive operations (e.g., shell commands, file writes).
|
|
775
|
+
*/
|
|
776
|
+
setApprovalCallback(handler: (request: ApprovalRequest) => boolean | Promise<boolean>): void;
|
|
777
|
+
/**
|
|
778
|
+
* Starts a new conversation with an agent.
|
|
779
|
+
* @returns A new thread instance.
|
|
780
|
+
*/
|
|
781
|
+
startThread(options?: ThreadOptions): Thread;
|
|
782
|
+
/**
|
|
783
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
784
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
785
|
+
*
|
|
786
|
+
* @param id The id of the thread to resume.
|
|
787
|
+
* @returns A new thread instance.
|
|
788
|
+
*/
|
|
789
|
+
resumeThread(id: string, options?: ThreadOptions): Thread;
|
|
790
|
+
listConversations(options?: ConversationListOptions): Promise<ConversationListPage>;
|
|
791
|
+
deleteConversation(id: string, options?: ThreadOptions): Promise<boolean>;
|
|
792
|
+
resumeConversationFromRollout(rolloutPath: string, options?: ThreadOptions): Promise<Thread>;
|
|
793
|
+
/**
|
|
794
|
+
* Starts a review task using the built-in Codex review flow.
|
|
795
|
+
*/
|
|
796
|
+
review(options: ReviewInvocationOptions): Promise<Turn>;
|
|
797
|
+
/**
|
|
798
|
+
* Starts a review task and returns the event stream.
|
|
799
|
+
*/
|
|
800
|
+
reviewStreamed(options: ReviewInvocationOptions): Promise<StreamedTurn>;
|
|
801
|
+
private reviewStreamedInternal;
|
|
185
802
|
}
|
|
186
803
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
804
|
+
type LspDiagnosticSeverity = "error" | "warning" | "info" | "hint";
|
|
805
|
+
type NormalizedDiagnostic = {
|
|
806
|
+
message: string;
|
|
807
|
+
severity: LspDiagnosticSeverity;
|
|
808
|
+
source?: string;
|
|
809
|
+
code?: string | number;
|
|
810
|
+
range: Diagnostic["range"];
|
|
811
|
+
};
|
|
812
|
+
type FileDiagnostics = {
|
|
813
|
+
path: string;
|
|
814
|
+
diagnostics: NormalizedDiagnostic[];
|
|
815
|
+
};
|
|
816
|
+
type WorkspaceLocator = {
|
|
817
|
+
type: "markers";
|
|
818
|
+
include: string[];
|
|
819
|
+
exclude?: string[];
|
|
820
|
+
} | {
|
|
821
|
+
type: "fixed";
|
|
822
|
+
path: string;
|
|
823
|
+
};
|
|
824
|
+
type LspServerConfig = {
|
|
825
|
+
id: string;
|
|
826
|
+
displayName: string;
|
|
827
|
+
command: string[];
|
|
828
|
+
extensions: string[];
|
|
829
|
+
env?: NodeJS.ProcessEnv;
|
|
830
|
+
initializationOptions?: Record<string, unknown>;
|
|
831
|
+
workspace?: WorkspaceLocator;
|
|
832
|
+
};
|
|
833
|
+
type LspManagerOptions = {
|
|
834
|
+
workingDirectory: string;
|
|
835
|
+
waitForDiagnostics?: boolean;
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
declare class LspDiagnosticsBridge {
|
|
839
|
+
private readonly options;
|
|
840
|
+
private readonly manager;
|
|
841
|
+
private readonly attached;
|
|
842
|
+
constructor(options: LspManagerOptions);
|
|
843
|
+
attach(thread: Thread): () => void;
|
|
844
|
+
dispose(): Promise<void>;
|
|
845
|
+
private processDiagnostics;
|
|
190
846
|
}
|
|
191
847
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
848
|
+
/**
|
|
849
|
+
* Attaches the LSP diagnostics bridge to a thread.
|
|
850
|
+
* Returns a cleanup function that detaches the bridge and disposes shared resources.
|
|
851
|
+
*/
|
|
852
|
+
declare function attachLspDiagnostics(thread: Thread, options: LspManagerOptions): () => void;
|
|
853
|
+
|
|
854
|
+
declare class LspManager {
|
|
855
|
+
private readonly options;
|
|
856
|
+
private clients;
|
|
857
|
+
constructor(options: LspManagerOptions);
|
|
858
|
+
collectDiagnostics(files: string[]): Promise<FileDiagnostics[]>;
|
|
859
|
+
dispose(): Promise<void>;
|
|
860
|
+
private getClient;
|
|
861
|
+
private createClient;
|
|
196
862
|
}
|
|
197
863
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
864
|
+
declare const DEFAULT_SERVERS: LspServerConfig[];
|
|
865
|
+
declare function findServerForFile(filePath: string): LspServerConfig | undefined;
|
|
866
|
+
declare function resolveWorkspaceRoot(filePath: string, locator: WorkspaceLocator | undefined, fallbackDir: string): string;
|
|
867
|
+
|
|
868
|
+
type DiagnosticSeverity = "error" | "warning" | "info" | "hint";
|
|
869
|
+
declare function formatDiagnosticsForTool(diagnostics: FileDiagnostics[]): string;
|
|
870
|
+
declare function formatDiagnosticsForBackgroundEvent(diagnostics: FileDiagnostics[], cwd: string): string;
|
|
871
|
+
/**
|
|
872
|
+
* Filter diagnostics by minimum severity level
|
|
873
|
+
*/
|
|
874
|
+
declare function filterBySeverity(diagnostics: FileDiagnostics[], minSeverity?: DiagnosticSeverity): FileDiagnostics[];
|
|
875
|
+
/**
|
|
876
|
+
* Generate summary statistics for diagnostics
|
|
877
|
+
*/
|
|
878
|
+
declare function summarizeDiagnostics(diagnostics: FileDiagnostics[]): {
|
|
879
|
+
fileCount: number;
|
|
880
|
+
errorCount: number;
|
|
881
|
+
warningCount: number;
|
|
882
|
+
infoCount: number;
|
|
883
|
+
hintCount: number;
|
|
884
|
+
totalCount: number;
|
|
885
|
+
};
|
|
886
|
+
/**
|
|
887
|
+
* Format diagnostics with summary (concise format for post-merge validation)
|
|
888
|
+
*/
|
|
889
|
+
declare function formatDiagnosticsWithSummary(diagnostics: FileDiagnostics[], cwd: string, options?: {
|
|
890
|
+
minSeverity?: DiagnosticSeverity;
|
|
891
|
+
maxPerFile?: number;
|
|
892
|
+
}): string;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Options for creating a CodexProvider
|
|
896
|
+
*/
|
|
897
|
+
interface CodexProviderOptions extends CodexOptions {
|
|
898
|
+
/**
|
|
899
|
+
* Default model to use when none is specified
|
|
900
|
+
*/
|
|
901
|
+
defaultModel?: string;
|
|
902
|
+
/**
|
|
903
|
+
* Approval policy forwarded to threads created by this provider.
|
|
904
|
+
*/
|
|
905
|
+
approvalMode?: ThreadOptions["approvalMode"];
|
|
906
|
+
/**
|
|
907
|
+
* Use local OSS provider via Ollama (pulls models as needed)
|
|
908
|
+
*/
|
|
909
|
+
oss?: boolean;
|
|
910
|
+
/**
|
|
911
|
+
* Working directory for Codex operations
|
|
912
|
+
* @default process.cwd()
|
|
913
|
+
*/
|
|
914
|
+
workingDirectory?: string;
|
|
915
|
+
/**
|
|
916
|
+
* Skip git repository check
|
|
917
|
+
* @default false
|
|
918
|
+
*/
|
|
919
|
+
skipGitRepoCheck?: boolean;
|
|
920
|
+
/**
|
|
921
|
+
* Sandbox policy to use when executing shell commands
|
|
922
|
+
* @default "danger-full-access"
|
|
923
|
+
*/
|
|
924
|
+
sandboxMode?: ThreadOptions["sandboxMode"];
|
|
925
|
+
/**
|
|
926
|
+
* Reasoning effort level for reasoning-capable models
|
|
927
|
+
* @default "medium"
|
|
928
|
+
*/
|
|
929
|
+
reasoningEffort?: ThreadOptions["reasoningEffort"];
|
|
930
|
+
/**
|
|
931
|
+
* Reasoning summary preference for reasoning-capable models
|
|
932
|
+
* @default "auto"
|
|
933
|
+
*/
|
|
934
|
+
reasoningSummary?: ThreadOptions["reasoningSummary"];
|
|
935
|
+
/**
|
|
936
|
+
* Enable LSP diagnostics for threads created by this provider
|
|
937
|
+
* @default true
|
|
938
|
+
*/
|
|
939
|
+
enableLsp?: boolean;
|
|
201
940
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
941
|
+
/**
|
|
942
|
+
* Provider implementation that uses Codex as the backend for OpenAI Agents
|
|
943
|
+
*
|
|
944
|
+
* @example
|
|
945
|
+
* ```typescript
|
|
946
|
+
* import { CodexProvider } from '@codex-native/sdk/agents';
|
|
947
|
+
* import { Agent, Runner } from '@openai/agents';
|
|
948
|
+
*
|
|
949
|
+
* const provider = new CodexProvider({
|
|
950
|
+
* defaultModel: 'gpt-5.2-codex'
|
|
951
|
+
* });
|
|
952
|
+
*
|
|
953
|
+
* const agent = new Agent({
|
|
954
|
+
* name: 'CodeAssistant',
|
|
955
|
+
* instructions: 'You are a helpful coding assistant'
|
|
956
|
+
* });
|
|
957
|
+
*
|
|
958
|
+
* const runner = new Runner({ modelProvider: provider });
|
|
959
|
+
* const result = await runner.run(agent, 'Fix the failing tests');
|
|
960
|
+
* ```
|
|
961
|
+
*/
|
|
962
|
+
declare class CodexProvider implements ModelProvider {
|
|
963
|
+
private codex;
|
|
964
|
+
private options;
|
|
965
|
+
constructor(options?: CodexProviderOptions);
|
|
966
|
+
/**
|
|
967
|
+
* Lazy initialization of Codex instance
|
|
968
|
+
*/
|
|
969
|
+
private getCodex;
|
|
970
|
+
getModel(modelName?: string): Model;
|
|
971
|
+
/**
|
|
972
|
+
* Register a programmatic approval callback on the underlying Codex instance.
|
|
973
|
+
*/
|
|
974
|
+
setApprovalCallback(callback: (request: ApprovalRequest) => boolean | Promise<boolean>): void;
|
|
206
975
|
}
|
|
207
976
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
977
|
+
type BaseToolOptions = Parameters<typeof tool>[0];
|
|
978
|
+
type AgentTool = ReturnType<typeof tool>;
|
|
979
|
+
type CodexToolOptions = BaseToolOptions & {
|
|
980
|
+
codexExecute: (input: unknown) => Promise<unknown> | unknown;
|
|
981
|
+
};
|
|
982
|
+
declare function codexTool(options: CodexToolOptions): AgentTool;
|
|
983
|
+
|
|
984
|
+
type ToolCallEvent = {
|
|
985
|
+
name?: string;
|
|
986
|
+
input?: unknown;
|
|
987
|
+
output?: unknown;
|
|
988
|
+
status?: "started" | "completed";
|
|
989
|
+
};
|
|
990
|
+
type FormattedStream = {
|
|
991
|
+
text: string;
|
|
992
|
+
reasoning: string;
|
|
993
|
+
toolCalls: ToolCallEvent[];
|
|
994
|
+
usage?: {
|
|
995
|
+
requests?: number;
|
|
996
|
+
inputTokens: number;
|
|
997
|
+
outputTokens: number;
|
|
998
|
+
totalTokens: number;
|
|
999
|
+
inputTokensDetails?: Record<string, number>;
|
|
1000
|
+
outputTokensDetails?: Record<string, number>;
|
|
1001
|
+
};
|
|
1002
|
+
/**
|
|
1003
|
+
* Convenience field when providers report cached tokens (e.g. via inputTokensDetails.cachedTokens)
|
|
1004
|
+
*/
|
|
1005
|
+
cachedTokens?: number;
|
|
1006
|
+
responseId?: string;
|
|
1007
|
+
/**
|
|
1008
|
+
* Raw provider-specific data (e.g., costs, cache hit ratios, rate limit info)
|
|
1009
|
+
*/
|
|
1010
|
+
providerData?: Record<string, unknown>;
|
|
1011
|
+
errors: {
|
|
1012
|
+
message: string;
|
|
1013
|
+
}[];
|
|
1014
|
+
};
|
|
1015
|
+
type FormatStreamOptions = {
|
|
1016
|
+
onUpdate?: (partial: Partial<FormattedStream>) => void;
|
|
1017
|
+
};
|
|
1018
|
+
/**
|
|
1019
|
+
* Consume a stream of StreamEvent and aggregate into a coherent object:
|
|
1020
|
+
* - Concatenates output_text deltas into `text`
|
|
1021
|
+
* - Concatenates reasoning deltas into `reasoning`
|
|
1022
|
+
* - Captures usage and responseId on response_done
|
|
1023
|
+
* - Prepares space for tool call events (future-friendly; empty for now)
|
|
1024
|
+
*
|
|
1025
|
+
* Optionally invokes `onUpdate` with partial snapshots as data arrives.
|
|
1026
|
+
*/
|
|
1027
|
+
declare function formatStream(stream: AsyncIterable<StreamEvent>, options?: FormatStreamOptions): Promise<FormattedStream>;
|
|
1028
|
+
|
|
1029
|
+
type PermissionDecision = boolean | "once" | "always" | "reject" | {
|
|
1030
|
+
response: "once" | "always" | "reject";
|
|
1031
|
+
};
|
|
1032
|
+
interface PermissionRequest {
|
|
1033
|
+
id: string;
|
|
1034
|
+
type: string;
|
|
1035
|
+
title: string;
|
|
1036
|
+
sessionId: string;
|
|
1037
|
+
metadata: Record<string, unknown>;
|
|
1038
|
+
pattern?: string | string[];
|
|
214
1039
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
1040
|
+
interface OpenCodeAgentOptions {
|
|
1041
|
+
/** Fully qualified base URL for an existing opencode server. When omitted the agent will start its own server. */
|
|
1042
|
+
baseUrl?: string;
|
|
1043
|
+
/** Hostname passed to `createOpencode` when auto-starting the server. */
|
|
1044
|
+
hostname?: string;
|
|
1045
|
+
/** Port passed to `createOpencode` when auto-starting the server. */
|
|
1046
|
+
port?: number;
|
|
1047
|
+
/** Additional configuration forwarded to `createOpencode`. */
|
|
1048
|
+
config?: Record<string, unknown>;
|
|
1049
|
+
/** Preferred model string in the form `provider/model`. */
|
|
1050
|
+
model?: string;
|
|
1051
|
+
/** Directory the OpenCode session should operate within. Defaults to the current working directory. */
|
|
1052
|
+
workingDirectory?: string;
|
|
1053
|
+
/** Optional user-friendly session title. */
|
|
1054
|
+
title?: string;
|
|
1055
|
+
/** Callback invoked whenever opencode asks for a permission decision. */
|
|
1056
|
+
onApprovalRequest?: (request: PermissionRequest) => PermissionDecision | Promise<PermissionDecision>;
|
|
1057
|
+
/** Override for tests – returns a hydrated opencode client. */
|
|
1058
|
+
clientFactory?: () => Promise<{
|
|
1059
|
+
client: OpencodeClient;
|
|
1060
|
+
close?: () => void;
|
|
1061
|
+
}>;
|
|
219
1062
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
1063
|
+
interface DelegationResult {
|
|
1064
|
+
sessionId: string;
|
|
1065
|
+
/** Deprecated alias retained for backwards compatibility. */
|
|
1066
|
+
threadId?: string;
|
|
1067
|
+
output: string;
|
|
1068
|
+
success: boolean;
|
|
1069
|
+
error?: string;
|
|
1070
|
+
usage?: Usage | null;
|
|
224
1071
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
1072
|
+
declare class OpenCodeAgent {
|
|
1073
|
+
private readonly options;
|
|
1074
|
+
private readonly approvalHandler?;
|
|
1075
|
+
private clientPromise?;
|
|
1076
|
+
private closeCallback?;
|
|
1077
|
+
constructor(options?: OpenCodeAgentOptions);
|
|
1078
|
+
/**
|
|
1079
|
+
* Cleanup method to shut down the OpenCode server if one was started.
|
|
1080
|
+
* Should be called when done using the agent to prevent zombie processes.
|
|
1081
|
+
*/
|
|
1082
|
+
close(): Promise<void>;
|
|
1083
|
+
delegate(task: string): Promise<DelegationResult>;
|
|
1084
|
+
delegateStreaming(task: string, onEvent?: (event: Event) => void, sessionId?: string): Promise<DelegationResult>;
|
|
1085
|
+
resume(sessionId: string, task: string): Promise<DelegationResult>;
|
|
1086
|
+
workflow(steps: string[]): Promise<DelegationResult[]>;
|
|
1087
|
+
private executeTask;
|
|
1088
|
+
private ensureClient;
|
|
1089
|
+
private ensureSession;
|
|
1090
|
+
private createSessionTitle;
|
|
1091
|
+
private parseModel;
|
|
1092
|
+
private collectText;
|
|
1093
|
+
private toUsage;
|
|
1094
|
+
private extractData;
|
|
1095
|
+
private describeError;
|
|
1096
|
+
private watchEvents;
|
|
1097
|
+
private extractSessionId;
|
|
1098
|
+
private respondToPermission;
|
|
1099
|
+
private normalizeDecision;
|
|
1100
|
+
private getWorkingDirectory;
|
|
231
1101
|
}
|
|
232
1102
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
1103
|
+
type CloudTaskStatus = "pending" | "ready" | "applied" | "error";
|
|
1104
|
+
type DiffSummary = {
|
|
1105
|
+
files_changed: number;
|
|
1106
|
+
lines_added: number;
|
|
1107
|
+
lines_removed: number;
|
|
1108
|
+
};
|
|
1109
|
+
type CloudTaskSummary = {
|
|
1110
|
+
id: string;
|
|
1111
|
+
title: string;
|
|
1112
|
+
status: CloudTaskStatus;
|
|
1113
|
+
updated_at: string;
|
|
1114
|
+
environment_id?: string | null;
|
|
1115
|
+
environment_label?: string | null;
|
|
1116
|
+
summary: DiffSummary;
|
|
1117
|
+
is_review?: boolean;
|
|
1118
|
+
attempt_total?: number | null;
|
|
1119
|
+
};
|
|
1120
|
+
type CloudApplyStatus = "success" | "partial" | "error";
|
|
1121
|
+
type CloudApplyOutcome = {
|
|
1122
|
+
applied: boolean;
|
|
1123
|
+
status: CloudApplyStatus;
|
|
1124
|
+
message: string;
|
|
1125
|
+
skipped_paths: string[];
|
|
1126
|
+
conflict_paths: string[];
|
|
1127
|
+
};
|
|
1128
|
+
type CloudTaskCreateResult = {
|
|
1129
|
+
id: string;
|
|
1130
|
+
};
|
|
1131
|
+
type CloudTasksOptions = {
|
|
1132
|
+
baseUrl?: string;
|
|
1133
|
+
apiKey?: string;
|
|
1134
|
+
};
|
|
1135
|
+
declare class CloudTasks {
|
|
1136
|
+
private readonly options;
|
|
1137
|
+
constructor(options?: CloudTasksOptions);
|
|
1138
|
+
private binding;
|
|
1139
|
+
list(env?: string): Promise<CloudTaskSummary[]>;
|
|
1140
|
+
getDiff(taskId: string): Promise<string | null>;
|
|
1141
|
+
applyPreflight(taskId: string, diffOverride?: string): Promise<CloudApplyOutcome>;
|
|
1142
|
+
apply(taskId: string, diffOverride?: string): Promise<CloudApplyOutcome>;
|
|
1143
|
+
create(envId: string, prompt: string, opts?: {
|
|
1144
|
+
gitRef?: string;
|
|
1145
|
+
qaMode?: boolean;
|
|
1146
|
+
bestOfN?: number;
|
|
1147
|
+
}): Promise<CloudTaskCreateResult>;
|
|
238
1148
|
}
|
|
239
1149
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
1150
|
+
/**
|
|
1151
|
+
* Log level enumeration
|
|
1152
|
+
*/
|
|
1153
|
+
declare enum LogLevel {
|
|
1154
|
+
DEBUG = 0,
|
|
1155
|
+
INFO = 1,
|
|
1156
|
+
WARN = 2,
|
|
1157
|
+
ERROR = 3,
|
|
1158
|
+
SILENT = 4
|
|
247
1159
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
1160
|
+
/**
|
|
1161
|
+
* Log scopes for different subsystems
|
|
1162
|
+
*/
|
|
1163
|
+
type LogScope = "thread" | "merge" | "git" | "coordinator" | "worker" | "supervisor" | "reviewer" | "validation" | "lsp" | "agent" | "provider" | "ci" | "test" | "system";
|
|
1164
|
+
/**
|
|
1165
|
+
* Configuration for logger instances
|
|
1166
|
+
*/
|
|
1167
|
+
interface LoggerConfig {
|
|
1168
|
+
/** Minimum log level to output */
|
|
1169
|
+
level?: LogLevel;
|
|
1170
|
+
/** Enable colored output (default: true for TTY) */
|
|
1171
|
+
colors?: boolean;
|
|
1172
|
+
/** Include timestamps in output (default: false) */
|
|
1173
|
+
timestamps?: boolean;
|
|
1174
|
+
/** Prefix for all log messages */
|
|
1175
|
+
prefix?: string;
|
|
1176
|
+
/** Enable structured JSON output instead of formatted text */
|
|
1177
|
+
json?: boolean;
|
|
1178
|
+
/** Custom output stream (default: console) */
|
|
1179
|
+
output?: LogOutput;
|
|
257
1180
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
1181
|
+
/**
|
|
1182
|
+
* Output interface for log messages
|
|
1183
|
+
*/
|
|
1184
|
+
interface LogOutput {
|
|
1185
|
+
debug(message: string): void;
|
|
1186
|
+
info(message: string): void;
|
|
1187
|
+
warn(message: string): void;
|
|
1188
|
+
error(message: string): void;
|
|
263
1189
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
export interface RepoDiffFileChange {
|
|
272
|
-
path: string
|
|
273
|
-
status: string
|
|
274
|
-
diff: string
|
|
275
|
-
truncated: boolean
|
|
276
|
-
previousPath?: string
|
|
1190
|
+
/**
|
|
1191
|
+
* Thread logging sink interface
|
|
1192
|
+
*/
|
|
1193
|
+
interface ThreadLoggingSink {
|
|
1194
|
+
info(message: string): void;
|
|
1195
|
+
warn(message: string): void;
|
|
1196
|
+
recordUsage?(usage: Usage): void;
|
|
277
1197
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
1198
|
+
/**
|
|
1199
|
+
* Structured log entry for JSON output
|
|
1200
|
+
*/
|
|
1201
|
+
interface LogEntry {
|
|
1202
|
+
timestamp: string;
|
|
1203
|
+
level: string;
|
|
1204
|
+
scope?: string;
|
|
1205
|
+
subject?: string;
|
|
1206
|
+
message: string;
|
|
1207
|
+
data?: Record<string, unknown>;
|
|
283
1208
|
}
|
|
284
1209
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1210
|
+
/**
|
|
1211
|
+
* Centralized logger with support for scopes, levels, and structured output
|
|
1212
|
+
*/
|
|
1213
|
+
declare class Logger {
|
|
1214
|
+
private level;
|
|
1215
|
+
private colors;
|
|
1216
|
+
private timestamps;
|
|
1217
|
+
private prefix;
|
|
1218
|
+
private json;
|
|
1219
|
+
private output;
|
|
1220
|
+
constructor(config?: LoggerConfig);
|
|
1221
|
+
/**
|
|
1222
|
+
* Create a new logger with modified configuration
|
|
1223
|
+
*/
|
|
1224
|
+
configure(config: Partial<LoggerConfig>): Logger;
|
|
1225
|
+
/**
|
|
1226
|
+
* Create a scoped logger
|
|
1227
|
+
*/
|
|
1228
|
+
scope(scope: LogScope, subject?: string): ScopedLogger;
|
|
1229
|
+
/**
|
|
1230
|
+
* Log a debug message
|
|
1231
|
+
*/
|
|
1232
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
1233
|
+
/**
|
|
1234
|
+
* Log an info message
|
|
1235
|
+
*/
|
|
1236
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
1237
|
+
/**
|
|
1238
|
+
* Log a warning message
|
|
1239
|
+
*/
|
|
1240
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
1241
|
+
/**
|
|
1242
|
+
* Log an error message
|
|
1243
|
+
*/
|
|
1244
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
1245
|
+
/**
|
|
1246
|
+
* Internal log method
|
|
1247
|
+
*/
|
|
1248
|
+
private log;
|
|
1249
|
+
/**
|
|
1250
|
+
* Log in JSON format
|
|
1251
|
+
*/
|
|
1252
|
+
private logJson;
|
|
1253
|
+
/**
|
|
1254
|
+
* Log in formatted text
|
|
1255
|
+
*/
|
|
1256
|
+
private logFormatted;
|
|
1257
|
+
/**
|
|
1258
|
+
* Internal scoped log method (used by ScopedLogger)
|
|
1259
|
+
*/
|
|
1260
|
+
logScoped(level: LogLevel, message: string, scope: LogScope, subject?: string, data?: Record<string, unknown>): void;
|
|
296
1261
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
1262
|
+
/**
|
|
1263
|
+
* Scoped logger for a specific subsystem
|
|
1264
|
+
*/
|
|
1265
|
+
declare class ScopedLogger {
|
|
1266
|
+
private logger;
|
|
1267
|
+
private scope;
|
|
1268
|
+
private subject?;
|
|
1269
|
+
constructor(logger: Logger, scope: LogScope, subject?: string | undefined);
|
|
1270
|
+
/**
|
|
1271
|
+
* Log a debug message
|
|
1272
|
+
*/
|
|
1273
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
1274
|
+
/**
|
|
1275
|
+
* Log an info message
|
|
1276
|
+
*/
|
|
1277
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
1278
|
+
/**
|
|
1279
|
+
* Log a warning message
|
|
1280
|
+
*/
|
|
1281
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
1282
|
+
/**
|
|
1283
|
+
* Log an error message
|
|
1284
|
+
*/
|
|
1285
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
1286
|
+
/**
|
|
1287
|
+
* Create a ThreadLoggingSink adapter
|
|
1288
|
+
*/
|
|
1289
|
+
asThreadSink(): ThreadLoggingSink;
|
|
303
1290
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
1291
|
+
/**
|
|
1292
|
+
* Global default logger instance
|
|
1293
|
+
*/
|
|
1294
|
+
declare const logger: Logger;
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Create a thread logging sink from a scoped logger
|
|
1298
|
+
*/
|
|
1299
|
+
declare function createThreadLogger(scopedLogger: ScopedLogger, onUsage?: (usage: Usage) => void): ThreadLoggingSink;
|
|
1300
|
+
/**
|
|
1301
|
+
* Run a thread turn with automatic event logging
|
|
1302
|
+
*/
|
|
1303
|
+
declare function runThreadTurnWithLogs(thread: Thread, sink: ThreadLoggingSink, prompt: string, turnOptions?: TurnOptions): Promise<Turn>;
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* Reverie System Constants
|
|
1307
|
+
*
|
|
1308
|
+
* Configuration constants for reverie search, filtering, and grading.
|
|
1309
|
+
* These values are tuned for optimal balance between result quality and performance.
|
|
1310
|
+
*/
|
|
1311
|
+
/**
|
|
1312
|
+
* Default number of final reverie insights to return.
|
|
1313
|
+
* After all filtering and grading, this is the target result count.
|
|
1314
|
+
*/
|
|
1315
|
+
declare const DEFAULT_REVERIE_LIMIT = 6;
|
|
1316
|
+
/**
|
|
1317
|
+
* Maximum number of candidate insights to fetch initially.
|
|
1318
|
+
* We fetch many candidates upfront and then filter aggressively.
|
|
1319
|
+
*/
|
|
1320
|
+
declare const DEFAULT_REVERIE_MAX_CANDIDATES = 80;
|
|
1321
|
+
/**
|
|
1322
|
+
* Embedding model for semantic search.
|
|
1323
|
+
* Large model provides better semantic understanding at cost of memory/speed.
|
|
1324
|
+
*/
|
|
1325
|
+
declare const REVERIE_EMBED_MODEL = "BAAI/bge-large-en-v1.5";
|
|
1326
|
+
/**
|
|
1327
|
+
* Reranker model for improving search precision.
|
|
1328
|
+
* Applied after initial embedding search to rerank top candidates.
|
|
1329
|
+
*/
|
|
1330
|
+
declare const REVERIE_RERANKER_MODEL = "rozgo/bge-reranker-v2-m3";
|
|
1331
|
+
/**
|
|
1332
|
+
* Candidate multiplier for aggressive filtering.
|
|
1333
|
+
* Fetch 3x candidates since we'll filter heavily for quality.
|
|
1334
|
+
*/
|
|
1335
|
+
declare const REVERIE_CANDIDATE_MULTIPLIER = 3;
|
|
1336
|
+
/**
|
|
1337
|
+
* Minimum relevance score threshold for LLM grading.
|
|
1338
|
+
* Only insights scoring >= 0.7 are sent for expensive LLM evaluation.
|
|
1339
|
+
* This optimizes API costs by skipping obvious low-quality candidates.
|
|
1340
|
+
*/
|
|
1341
|
+
declare const REVERIE_LLM_GRADE_THRESHOLD = 0.7;
|
|
1342
|
+
/**
|
|
1343
|
+
* Default reranker top-k value.
|
|
1344
|
+
* Number of results to rerank after initial retrieval.
|
|
1345
|
+
*/
|
|
1346
|
+
declare const DEFAULT_RERANKER_TOP_K = 20;
|
|
1347
|
+
/**
|
|
1348
|
+
* Default reranker batch size.
|
|
1349
|
+
* Number of candidates to process per reranker batch.
|
|
1350
|
+
*/
|
|
1351
|
+
declare const DEFAULT_RERANKER_BATCH_SIZE = 8;
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Reverie Type Definitions
|
|
1355
|
+
*
|
|
1356
|
+
* Core types used throughout the reverie system.
|
|
1357
|
+
*/
|
|
1358
|
+
/**
|
|
1359
|
+
* Represents a single reverie insight from past conversations.
|
|
1360
|
+
*/
|
|
1361
|
+
interface ReverieInsight$1 {
|
|
1362
|
+
/** Unique identifier for the conversation */
|
|
1363
|
+
conversationId: string;
|
|
1364
|
+
/** ISO timestamp of when the conversation occurred */
|
|
1365
|
+
timestamp: string;
|
|
1366
|
+
/** Relevance score from semantic search (0-1) */
|
|
1367
|
+
relevance: number;
|
|
1368
|
+
/** Text excerpt from the conversation */
|
|
1369
|
+
excerpt: string;
|
|
1370
|
+
/** Extracted insights or key points from the excerpt */
|
|
1371
|
+
insights: string[];
|
|
314
1372
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
/** Search using blocks from the current ongoing conversation to find similar past sessions */
|
|
323
|
-
export declare function reverieSearchByConversation(codexHomePath: string, conversationMessages: Array<string>, options?: ReverieSemanticSearchOptions | undefined | null): Promise<Array<ReverieSearchResult>>
|
|
324
|
-
|
|
325
|
-
export declare function reverieSearchConversations(codexHomePath: string, query: string, limit?: number | undefined | null): Promise<Array<ReverieSearchResult>>
|
|
326
|
-
|
|
327
|
-
export interface ReverieSearchResult {
|
|
328
|
-
conversation: ReverieConversation
|
|
329
|
-
relevanceScore: number
|
|
330
|
-
matchingExcerpts: Array<string>
|
|
331
|
-
insights: Array<string>
|
|
332
|
-
rerankerScore?: number
|
|
1373
|
+
interface ReverieEpisodeSummary {
|
|
1374
|
+
conversationId: string;
|
|
1375
|
+
episodeId: string;
|
|
1376
|
+
timestamp: string;
|
|
1377
|
+
summary: string;
|
|
1378
|
+
keyDecisions?: string[];
|
|
1379
|
+
importance?: number;
|
|
333
1380
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
1381
|
+
/**
|
|
1382
|
+
* Options for reverie semantic search.
|
|
1383
|
+
*/
|
|
1384
|
+
interface ReverieSearchOptions {
|
|
1385
|
+
/** Maximum number of final results to return (after all filtering) */
|
|
1386
|
+
limit?: number;
|
|
1387
|
+
/** Maximum number of candidates to fetch initially */
|
|
1388
|
+
maxCandidates?: number;
|
|
1389
|
+
/** Whether to use reranker for improving precision */
|
|
1390
|
+
useReranker?: boolean;
|
|
1391
|
+
/** Reranker model identifier */
|
|
1392
|
+
rerankerModel?: string;
|
|
1393
|
+
/** Number of results to rerank */
|
|
1394
|
+
rerankerTopK?: number;
|
|
1395
|
+
/** Batch size for reranking operations */
|
|
1396
|
+
rerankerBatchSize?: number;
|
|
1397
|
+
/** Multiplier for candidate fetching (fetch N × limit candidates) */
|
|
1398
|
+
candidateMultiplier?: number;
|
|
341
1399
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
rerankerModel?: string
|
|
351
|
-
rerankerCacheDir?: string
|
|
352
|
-
rerankerMaxLength?: number
|
|
353
|
-
rerankerShowProgress?: boolean
|
|
354
|
-
rerankerBatchSize?: number
|
|
355
|
-
rerankerTopK?: number
|
|
1400
|
+
/**
|
|
1401
|
+
* Options for LLM-based relevance grading.
|
|
1402
|
+
*/
|
|
1403
|
+
interface GradingOptions {
|
|
1404
|
+
/** Minimum relevance score to trigger LLM grading (default: 0.7) */
|
|
1405
|
+
minRelevanceForGrading?: number;
|
|
1406
|
+
/** Whether to grade insights in parallel (default: true) */
|
|
1407
|
+
parallel?: boolean;
|
|
356
1408
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
outputSchema?: JsonValue
|
|
376
|
-
baseUrl?: string
|
|
377
|
-
apiKey?: string
|
|
378
|
-
linuxSandboxPath?: string
|
|
379
|
-
reasoningEffort?: string
|
|
380
|
-
reasoningSummary?: string
|
|
381
|
-
fullAuto?: boolean
|
|
1409
|
+
/**
|
|
1410
|
+
* Statistics from reverie filtering pipeline.
|
|
1411
|
+
*/
|
|
1412
|
+
interface ReverieFilterStats {
|
|
1413
|
+
/** Total raw results from search */
|
|
1414
|
+
total: number;
|
|
1415
|
+
/** Results after basic quality filtering */
|
|
1416
|
+
afterQuality: number;
|
|
1417
|
+
/** Results after embedding-based boilerplate filtering */
|
|
1418
|
+
afterBoilerplate?: number;
|
|
1419
|
+
/** Results after relevance score threshold */
|
|
1420
|
+
afterScore: number;
|
|
1421
|
+
/** Results after deduplication */
|
|
1422
|
+
afterDedup: number;
|
|
1423
|
+
/** Results after LLM grading */
|
|
1424
|
+
afterLLMGrade?: number;
|
|
1425
|
+
/** Final result count */
|
|
1426
|
+
final: number;
|
|
382
1427
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
export declare function sse(events: Array<string>): string
|
|
391
|
-
|
|
392
|
-
export declare function startTui(req: TuiRequest): TuiSession
|
|
393
|
-
|
|
394
|
-
export interface TokenizerBaseOptions {
|
|
395
|
-
model?: string
|
|
396
|
-
encoding?: "o200k_base" | "cl100k_base"
|
|
1428
|
+
/**
|
|
1429
|
+
* Complete pipeline options combining search, filtering, and grading.
|
|
1430
|
+
*/
|
|
1431
|
+
interface ReveriePipelineOptions extends ReverieSearchOptions, GradingOptions {
|
|
1432
|
+
/** Whether to skip LLM grading entirely (default: false) */
|
|
1433
|
+
skipLLMGrading?: boolean;
|
|
397
1434
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
1435
|
+
/**
|
|
1436
|
+
* Reverie search level types for multi-level search hierarchy.
|
|
1437
|
+
*/
|
|
1438
|
+
type ReverieSearchLevel = 'project' | 'branch' | 'file';
|
|
1439
|
+
/**
|
|
1440
|
+
* Project-level search context for repository-wide patterns.
|
|
1441
|
+
*/
|
|
1442
|
+
interface ProjectLevelContext {
|
|
1443
|
+
/** Search level identifier */
|
|
1444
|
+
level: 'project';
|
|
1445
|
+
/** Repository root path */
|
|
1446
|
+
repoPath: string;
|
|
1447
|
+
/** Search query describing what to find */
|
|
1448
|
+
query: string;
|
|
1449
|
+
/** Optional file patterns to filter search scope (e.g., ["*.ts", "src/**"]) */
|
|
1450
|
+
filePatterns?: string[];
|
|
409
1451
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
1452
|
+
/**
|
|
1453
|
+
* Branch-level search context for feature/branch-specific work.
|
|
1454
|
+
*/
|
|
1455
|
+
interface BranchLevelContext {
|
|
1456
|
+
/** Search level identifier */
|
|
1457
|
+
level: 'branch';
|
|
1458
|
+
/** Repository root path */
|
|
1459
|
+
repoPath: string;
|
|
1460
|
+
/** Current branch name */
|
|
1461
|
+
branch: string;
|
|
1462
|
+
/** Base branch for comparison (e.g., "main") */
|
|
1463
|
+
baseBranch?: string;
|
|
1464
|
+
/** List of changed file paths in this branch */
|
|
1465
|
+
changedFiles: string[];
|
|
1466
|
+
/** Recent commit messages or summaries */
|
|
1467
|
+
recentCommits?: string;
|
|
417
1468
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
sandboxMode?: string
|
|
433
|
-
approvalMode?: string
|
|
434
|
-
resumeSessionId?: string
|
|
435
|
-
resumeLast?: boolean
|
|
436
|
-
resumePicker?: boolean
|
|
437
|
-
fullAuto?: boolean
|
|
438
|
-
dangerouslyBypassApprovalsAndSandbox?: boolean
|
|
439
|
-
workingDirectory?: string
|
|
440
|
-
configProfile?: string
|
|
441
|
-
configOverrides?: Array<string>
|
|
442
|
-
addDir?: Array<string>
|
|
443
|
-
webSearch?: boolean
|
|
444
|
-
linuxSandboxPath?: string
|
|
445
|
-
baseUrl?: string
|
|
446
|
-
apiKey?: string
|
|
447
|
-
reasoningEffort?: string
|
|
448
|
-
reasoningSummary?: string
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
export interface TuiTestRequest {
|
|
452
|
-
width: number
|
|
453
|
-
height: number
|
|
454
|
-
viewport: TuiTestViewport
|
|
455
|
-
lines: Array<string>
|
|
1469
|
+
/**
|
|
1470
|
+
* File-level search context for individual file changes.
|
|
1471
|
+
*/
|
|
1472
|
+
interface FileLevelContext {
|
|
1473
|
+
/** Search level identifier */
|
|
1474
|
+
level: 'file';
|
|
1475
|
+
/** Repository root path */
|
|
1476
|
+
repoPath: string;
|
|
1477
|
+
/** Path to the file being analyzed */
|
|
1478
|
+
filePath: string;
|
|
1479
|
+
/** Git diff or change content */
|
|
1480
|
+
diff?: string;
|
|
1481
|
+
/** Extracted symbols from the file (functions, classes, etc.) */
|
|
1482
|
+
symbols?: string[];
|
|
456
1483
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
1484
|
+
/**
|
|
1485
|
+
* Union type representing any level of search context.
|
|
1486
|
+
*/
|
|
1487
|
+
type ReverieContext = ProjectLevelContext | BranchLevelContext | FileLevelContext;
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* Reverie Quality Utilities
|
|
1491
|
+
*
|
|
1492
|
+
* Provides filtering, deduplication, and quality assessment for reverie search results.
|
|
1493
|
+
* Ensures that only meaningful conversation excerpts are surfaced to agents and users.
|
|
1494
|
+
*/
|
|
1495
|
+
/**
|
|
1496
|
+
* Represents a single reverie insight from past conversations.
|
|
1497
|
+
* This is a generic interface that can be extended with additional metadata.
|
|
1498
|
+
*/
|
|
1499
|
+
interface ReverieInsight {
|
|
1500
|
+
/** Unique identifier for the conversation */
|
|
1501
|
+
conversationId: string;
|
|
1502
|
+
/** ISO timestamp of when the conversation occurred */
|
|
1503
|
+
timestamp: string;
|
|
1504
|
+
/** Relevance score from semantic search (0-1) */
|
|
1505
|
+
relevance: number;
|
|
1506
|
+
/** Text excerpt from the conversation */
|
|
1507
|
+
excerpt: string;
|
|
1508
|
+
/** Extracted insights or key points from the excerpt */
|
|
1509
|
+
insights: string[];
|
|
465
1510
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
1511
|
+
/**
|
|
1512
|
+
* Type alias for reverie results (used for logging compatibility).
|
|
1513
|
+
*/
|
|
1514
|
+
type ReverieResult = ReverieInsight;
|
|
1515
|
+
/**
|
|
1516
|
+
* Statistics from the quality filtering pipeline.
|
|
1517
|
+
*/
|
|
1518
|
+
interface QualityFilterStats {
|
|
1519
|
+
/** Number of insights before filtering */
|
|
1520
|
+
initial: number;
|
|
1521
|
+
/** Number after validity filtering */
|
|
1522
|
+
afterValidityFilter: number;
|
|
1523
|
+
/** Number after deduplication */
|
|
1524
|
+
afterDeduplication: number;
|
|
1525
|
+
/** Final number of insights */
|
|
1526
|
+
final: number;
|
|
470
1527
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
1528
|
+
/**
|
|
1529
|
+
* Validates whether a reverie excerpt contains meaningful content worth indexing.
|
|
1530
|
+
*
|
|
1531
|
+
* Filters out:
|
|
1532
|
+
* - Very short excerpts (< 20 chars)
|
|
1533
|
+
* - System prompts and boilerplate text
|
|
1534
|
+
* - Tool outputs and structured data
|
|
1535
|
+
* - Excerpts with excessive XML/HTML tags
|
|
1536
|
+
* - JSON objects and configuration snippets
|
|
1537
|
+
*
|
|
1538
|
+
* @param excerpt - The text excerpt to validate
|
|
1539
|
+
* @returns true if the excerpt contains meaningful content, false otherwise
|
|
1540
|
+
*
|
|
1541
|
+
* @example
|
|
1542
|
+
* ```typescript
|
|
1543
|
+
* const excerpt = "Let's refactor the auth module to use async/await";
|
|
1544
|
+
* isValidReverieExcerpt(excerpt); // true
|
|
1545
|
+
*
|
|
1546
|
+
* const systemPrompt = "<INSTRUCTIONS>You are a coding assistant</INSTRUCTIONS>";
|
|
1547
|
+
* isValidReverieExcerpt(systemPrompt); // false
|
|
1548
|
+
* ```
|
|
1549
|
+
*/
|
|
1550
|
+
declare function isValidReverieExcerpt(excerpt: string): boolean;
|
|
1551
|
+
/**
|
|
1552
|
+
* Removes duplicate or highly similar reverie insights based on content fingerprinting.
|
|
1553
|
+
*
|
|
1554
|
+
* CRITICAL FIX: Groups by fingerprint and keeps the insight with the HIGHEST relevance score.
|
|
1555
|
+
* Previous implementations incorrectly kept the first occurrence, which could discard
|
|
1556
|
+
* higher-quality duplicates found later in the list.
|
|
1557
|
+
*
|
|
1558
|
+
* Uses the first 100 characters of each excerpt (normalized) as a fingerprint
|
|
1559
|
+
* to identify duplicates. This prevents redundant insights from being shown
|
|
1560
|
+
* to the user while preserving the most relevant unique insights.
|
|
1561
|
+
*
|
|
1562
|
+
* @param insights - Array of reverie insights to deduplicate
|
|
1563
|
+
* @returns Deduplicated array of reverie insights, sorted by relevance (highest first)
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* ```typescript
|
|
1567
|
+
* const insights = [
|
|
1568
|
+
* { excerpt: "We refactored the auth module...", relevance: 0.7, ... },
|
|
1569
|
+
* { excerpt: "We refactored the auth module to use async/await", relevance: 0.9, ... },
|
|
1570
|
+
* { excerpt: "Updated the database schema", relevance: 0.8, ... }
|
|
1571
|
+
* ];
|
|
1572
|
+
*
|
|
1573
|
+
* const deduplicated = deduplicateReverieInsights(insights);
|
|
1574
|
+
* // Returns 2 insights: the higher-scoring auth one (0.9) and the database one (0.8)
|
|
1575
|
+
* ```
|
|
1576
|
+
*/
|
|
1577
|
+
declare function deduplicateReverieInsights<T extends ReverieInsight>(insights: T[]): T[];
|
|
1578
|
+
/**
|
|
1579
|
+
* Applies the complete quality pipeline to reverie insights.
|
|
1580
|
+
*
|
|
1581
|
+
* Pipeline steps:
|
|
1582
|
+
* 1. Filter out invalid excerpts (system prompts, boilerplate, etc.)
|
|
1583
|
+
* 2. Deduplicate similar insights, keeping highest relevance
|
|
1584
|
+
* 3. Sort by relevance score (highest first)
|
|
1585
|
+
* 4. Limit to top N results
|
|
1586
|
+
*
|
|
1587
|
+
* @param insights - Raw reverie insights from search
|
|
1588
|
+
* @param limit - Maximum number of insights to return (default: 10)
|
|
1589
|
+
* @returns Filtered, deduplicated, and sorted insights with statistics
|
|
1590
|
+
*
|
|
1591
|
+
* @example
|
|
1592
|
+
* ```typescript
|
|
1593
|
+
* const rawInsights = await reverieSearchSemantic(codexHome, query, options);
|
|
1594
|
+
* const { insights, stats } = applyQualityPipeline(rawInsights, 5);
|
|
1595
|
+
*
|
|
1596
|
+
* console.log(`Filtered ${stats.initial} → ${stats.final} insights`);
|
|
1597
|
+
* insights.forEach(insight => {
|
|
1598
|
+
* console.log(`[${insight.relevance.toFixed(2)}] ${insight.excerpt.slice(0, 100)}`);
|
|
1599
|
+
* });
|
|
1600
|
+
* ```
|
|
1601
|
+
*/
|
|
1602
|
+
declare function applyQualityPipeline<T extends ReverieInsight>(insights: T[], limit?: number): {
|
|
1603
|
+
insights: T[];
|
|
1604
|
+
stats: QualityFilterStats;
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* LLM-Based Relevance Grading for Reverie Insights
|
|
1609
|
+
*
|
|
1610
|
+
* Uses an LLM to evaluate whether reverie excerpts contain specific technical details
|
|
1611
|
+
* relevant to the current work context. This provides a more sophisticated filter than
|
|
1612
|
+
* simple keyword matching or relevance scores.
|
|
1613
|
+
*
|
|
1614
|
+
* Key optimizations:
|
|
1615
|
+
* - Only grades high-scoring candidates (relevance >= 0.7) to minimize API costs
|
|
1616
|
+
* - Parallel grading for performance
|
|
1617
|
+
* - Strict filtering to reject boilerplate and generic content
|
|
1618
|
+
*/
|
|
1619
|
+
|
|
1620
|
+
/**
|
|
1621
|
+
* Minimal interface for an agent runner that can execute prompts.
|
|
1622
|
+
* Compatible with @openai/agents Runner and similar implementations.
|
|
1623
|
+
*/
|
|
1624
|
+
interface AgentRunner {
|
|
1625
|
+
run(agent: {
|
|
1626
|
+
name: string;
|
|
1627
|
+
instructions: string | ((...args: any[]) => any);
|
|
1628
|
+
outputType?: unknown;
|
|
1629
|
+
getEnabledHandoffs?: (...args: any[]) => Promise<unknown> | unknown;
|
|
1630
|
+
getAllTools?: (...args: any[]) => Promise<unknown> | unknown;
|
|
1631
|
+
}, prompt: string): Promise<{
|
|
1632
|
+
finalOutput?: unknown;
|
|
1633
|
+
}>;
|
|
481
1634
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
1635
|
+
/**
|
|
1636
|
+
* Uses LLM to evaluate if a reverie excerpt contains specific technical details
|
|
1637
|
+
* relevant to the search context.
|
|
1638
|
+
*
|
|
1639
|
+
* The grader is extremely strict and only approves excerpts with:
|
|
1640
|
+
* - Specific code/file references
|
|
1641
|
+
* - Technical decisions and rationale
|
|
1642
|
+
* - Error messages and debugging details
|
|
1643
|
+
* - Implementation specifics
|
|
1644
|
+
*
|
|
1645
|
+
* It rejects:
|
|
1646
|
+
* - Greetings and pleasantries
|
|
1647
|
+
* - Thinking markers (**, ##)
|
|
1648
|
+
* - JSON objects and structured data
|
|
1649
|
+
* - Generic phrases ("Context from past work")
|
|
1650
|
+
* - Metadata and system information
|
|
1651
|
+
*
|
|
1652
|
+
* @param runner - Agent runner capable of executing LLM prompts
|
|
1653
|
+
* @param searchContext - Context describing what we're searching for
|
|
1654
|
+
* @param insight - Reverie insight to evaluate
|
|
1655
|
+
* @returns true if the excerpt contains valuable technical details, false otherwise
|
|
1656
|
+
*
|
|
1657
|
+
* @example
|
|
1658
|
+
* ```typescript
|
|
1659
|
+
* const context = "Implementing authentication with JWT tokens";
|
|
1660
|
+
* const insight = {
|
|
1661
|
+
* excerpt: "We decided to use RS256 for JWT signing because...",
|
|
1662
|
+
* relevance: 0.85,
|
|
1663
|
+
* // ...
|
|
1664
|
+
* };
|
|
1665
|
+
*
|
|
1666
|
+
* const isRelevant = await gradeReverieRelevance(runner, context, insight);
|
|
1667
|
+
* // Returns: true (contains specific technical decision)
|
|
1668
|
+
* ```
|
|
1669
|
+
*/
|
|
1670
|
+
declare function gradeReverieRelevance(runner: AgentRunner, searchContext: string, insight: ReverieInsight$1): Promise<boolean>;
|
|
1671
|
+
/**
|
|
1672
|
+
* Grades multiple reverie insights in parallel using LLM evaluation.
|
|
1673
|
+
*
|
|
1674
|
+
* Pipeline:
|
|
1675
|
+
* 1. Filter insights by minimum relevance threshold (default: 0.7)
|
|
1676
|
+
* 2. Send high-scoring insights to LLM grader in parallel
|
|
1677
|
+
* 3. Return only insights that pass LLM evaluation
|
|
1678
|
+
*
|
|
1679
|
+
* This approach optimizes API costs by:
|
|
1680
|
+
* - Skipping low-scoring candidates entirely
|
|
1681
|
+
* - Running high-scoring evaluations in parallel for speed
|
|
1682
|
+
* - Using strict filtering to minimize false positives
|
|
1683
|
+
*
|
|
1684
|
+
* @param runner - Agent runner capable of executing LLM prompts
|
|
1685
|
+
* @param context - Search context describing what we're looking for
|
|
1686
|
+
* @param insights - Array of insights to grade
|
|
1687
|
+
* @param options - Grading configuration options
|
|
1688
|
+
* @returns Filtered array containing only LLM-approved insights
|
|
1689
|
+
*
|
|
1690
|
+
* @example
|
|
1691
|
+
* ```typescript
|
|
1692
|
+
* const allInsights = await searchReveries("authentication bug", repo);
|
|
1693
|
+
* const approved = await gradeReveriesInParallel(
|
|
1694
|
+
* runner,
|
|
1695
|
+
* "Fix authentication token validation",
|
|
1696
|
+
* allInsights,
|
|
1697
|
+
* { minRelevanceForGrading: 0.75, parallel: true }
|
|
1698
|
+
* );
|
|
1699
|
+
*
|
|
1700
|
+
* console.log(`${approved.length}/${allInsights.length} insights approved`);
|
|
1701
|
+
* ```
|
|
1702
|
+
*/
|
|
1703
|
+
declare function gradeReveriesInParallel(runner: AgentRunner, context: string, insights: ReverieInsight$1[], options?: GradingOptions): Promise<ReverieInsight$1[]>;
|
|
1704
|
+
|
|
1705
|
+
/**
|
|
1706
|
+
* Complete Reverie Pipeline
|
|
1707
|
+
*
|
|
1708
|
+
* Orchestrates the full reverie search and filtering process:
|
|
1709
|
+
* 1. Search with 3x candidates for aggressive filtering headroom
|
|
1710
|
+
* 2. Basic quality filter (remove boilerplate and system prompts)
|
|
1711
|
+
* 3. Split by relevance threshold (high vs low scoring)
|
|
1712
|
+
* 4. LLM grade high-scoring candidates only (cost optimization)
|
|
1713
|
+
* 5. Deduplicate results (keep highest relevance)
|
|
1714
|
+
* 6. Log statistics at every stage (transparent operation)
|
|
1715
|
+
*
|
|
1716
|
+
* This pipeline matches diff-agent's sophistication while being fully generic
|
|
1717
|
+
* and reusable across different contexts.
|
|
1718
|
+
*/
|
|
1719
|
+
|
|
1720
|
+
/**
|
|
1721
|
+
* Result from the complete reverie pipeline.
|
|
1722
|
+
*/
|
|
1723
|
+
interface ReveriePipelineResult {
|
|
1724
|
+
/** Final filtered and graded insights */
|
|
1725
|
+
insights: ReverieInsight$1[];
|
|
1726
|
+
/** Statistics from each pipeline stage */
|
|
1727
|
+
stats: ReverieFilterStats;
|
|
488
1728
|
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Applies the complete reverie pipeline with all sophisticated features from diff-agent.
|
|
1731
|
+
*
|
|
1732
|
+
* Pipeline stages:
|
|
1733
|
+
* 1. **Search** - Fetch 3x candidates with optional reranking
|
|
1734
|
+
* 2. **Quality Filter** - Remove system prompts, boilerplate, JSON objects
|
|
1735
|
+
* 3. **Score Split** - Separate high-scoring (≥0.7) from low-scoring candidates
|
|
1736
|
+
* 4. **LLM Grading** - Grade only high-scoring candidates (cost optimization)
|
|
1737
|
+
* 5. **Deduplication** - Remove similar excerpts, keeping highest relevance
|
|
1738
|
+
* 6. **Logging** - Transparent statistics at each stage
|
|
1739
|
+
*
|
|
1740
|
+
* Key optimizations:
|
|
1741
|
+
* - 3x candidate multiplier provides headroom for aggressive filtering
|
|
1742
|
+
* - LLM grading only applied to high-scoring candidates (≥0.7)
|
|
1743
|
+
* - Parallel grading for performance
|
|
1744
|
+
* - Deduplication preserves highest-relevance duplicates
|
|
1745
|
+
* - Comprehensive logging for debugging and monitoring
|
|
1746
|
+
*
|
|
1747
|
+
* @param codexHome - Path to .codex directory containing conversation data
|
|
1748
|
+
* @param searchText - Search query describing what to look for
|
|
1749
|
+
* @param repo - Repository root path for filtering conversations
|
|
1750
|
+
* @param runner - Agent runner for LLM-based relevance grading (required unless skipLLMGrading is true)
|
|
1751
|
+
* @param options - Pipeline configuration options
|
|
1752
|
+
* @returns Pipeline result with filtered insights and statistics
|
|
1753
|
+
*
|
|
1754
|
+
* @example
|
|
1755
|
+
* ```typescript
|
|
1756
|
+
* // Full pipeline with LLM grading
|
|
1757
|
+
* const result = await applyReveriePipeline(
|
|
1758
|
+
* "/Users/me/.codex",
|
|
1759
|
+
* "authentication bug with JWT tokens",
|
|
1760
|
+
* "/Users/me/my-project",
|
|
1761
|
+
* runner,
|
|
1762
|
+
* {
|
|
1763
|
+
* limit: 6,
|
|
1764
|
+
* useReranker: true,
|
|
1765
|
+
* minRelevanceForGrading: 0.7
|
|
1766
|
+
* }
|
|
1767
|
+
* );
|
|
1768
|
+
*
|
|
1769
|
+
* console.log(`Found ${result.insights.length} relevant insights`);
|
|
1770
|
+
* console.log(`Filtered: ${result.stats.total} → ${result.stats.final}`);
|
|
1771
|
+
*
|
|
1772
|
+
* // Without LLM grading (faster, lower quality)
|
|
1773
|
+
* const fastResult = await applyReveriePipeline(
|
|
1774
|
+
* codexHome,
|
|
1775
|
+
* query,
|
|
1776
|
+
* repo,
|
|
1777
|
+
* null,
|
|
1778
|
+
* { skipLLMGrading: true }
|
|
1779
|
+
* );
|
|
1780
|
+
* ```
|
|
1781
|
+
*/
|
|
1782
|
+
declare function applyReveriePipeline(codexHome: string, searchText: string, repo: string, runner: AgentRunner | null, options?: ReveriePipelineOptions): Promise<ReveriePipelineResult>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Simplified pipeline for file-specific searches.
|
|
1785
|
+
*
|
|
1786
|
+
* Similar to main pipeline but optimized for individual file contexts:
|
|
1787
|
+
* - Uses fewer candidates (maxCandidates / 2)
|
|
1788
|
+
* - Same filtering and grading logic
|
|
1789
|
+
* - Transparent logging
|
|
1790
|
+
*
|
|
1791
|
+
* @param codexHome - Path to .codex directory
|
|
1792
|
+
* @param filePath - File path being analyzed
|
|
1793
|
+
* @param fileContext - Contextual information about the file (symbols, changes, etc.)
|
|
1794
|
+
* @param repo - Repository root path
|
|
1795
|
+
* @param runner - Agent runner for LLM grading
|
|
1796
|
+
* @param options - Pipeline options
|
|
1797
|
+
* @returns Pipeline result with file-specific insights
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* ```typescript
|
|
1801
|
+
* const fileInsights = await applyFileReveriePipeline(
|
|
1802
|
+
* codexHome,
|
|
1803
|
+
* "src/auth/jwt.ts",
|
|
1804
|
+
* "File: src/auth/jwt.ts\nImplementing: validateToken, generateToken",
|
|
1805
|
+
* repo,
|
|
1806
|
+
* runner,
|
|
1807
|
+
* { limit: 3 }
|
|
1808
|
+
* );
|
|
1809
|
+
* ```
|
|
1810
|
+
*/
|
|
1811
|
+
declare function applyFileReveriePipeline(codexHome: string, filePath: string, fileContext: string, repo: string, runner: AgentRunner | null, options?: ReveriePipelineOptions): Promise<ReveriePipelineResult>;
|
|
1812
|
+
/**
|
|
1813
|
+
* Multi-level reverie search pipeline.
|
|
1814
|
+
*
|
|
1815
|
+
* Executes searches at multiple levels (project, branch, file) and returns
|
|
1816
|
+
* results organized by level. This enables comprehensive context gathering
|
|
1817
|
+
* from different scopes in a single operation.
|
|
1818
|
+
*
|
|
1819
|
+
* @param codexHome - Path to .codex directory
|
|
1820
|
+
* @param contexts - Array of search contexts at different levels
|
|
1821
|
+
* @param runner - Agent runner for LLM grading (optional if skipLLMGrading is true)
|
|
1822
|
+
* @param options - Pipeline options
|
|
1823
|
+
* @returns Map of search level to pipeline results
|
|
1824
|
+
*
|
|
1825
|
+
* @example
|
|
1826
|
+
* ```typescript
|
|
1827
|
+
* import { buildProjectContext, buildBranchContext, buildFileContext } from './context.js';
|
|
1828
|
+
*
|
|
1829
|
+
* const contexts = [
|
|
1830
|
+
* buildProjectContext("Testing conventions in this codebase"),
|
|
1831
|
+
* buildBranchContext("feat/auth", ["src/auth.ts", "src/login.ts"]),
|
|
1832
|
+
* buildFileContext("src/auth.ts", { extractSymbols: true })
|
|
1833
|
+
* ];
|
|
1834
|
+
*
|
|
1835
|
+
* const results = await searchMultiLevel(codexHome, contexts, runner, {
|
|
1836
|
+
* limit: 5,
|
|
1837
|
+
* useReranker: true
|
|
1838
|
+
* });
|
|
1839
|
+
*
|
|
1840
|
+
* // Access results by level
|
|
1841
|
+
* const projectInsights = results.get('project')?.insights || [];
|
|
1842
|
+
* const branchInsights = results.get('branch')?.insights || [];
|
|
1843
|
+
* const fileInsights = results.get('file')?.insights || [];
|
|
1844
|
+
* ```
|
|
1845
|
+
*/
|
|
1846
|
+
declare function searchMultiLevel(codexHome: string, contexts: ReverieContext[], runner: AgentRunner | null, options?: ReveriePipelineOptions): Promise<Map<ReverieSearchLevel, ReveriePipelineResult>>;
|
|
1847
|
+
/**
|
|
1848
|
+
* Search at project level for repository-wide patterns.
|
|
1849
|
+
*
|
|
1850
|
+
* Optimized for broad searches across the entire codebase to find
|
|
1851
|
+
* architectural decisions, common practices, and project conventions.
|
|
1852
|
+
*
|
|
1853
|
+
* @param codexHome - Path to .codex directory
|
|
1854
|
+
* @param context - Project-level search context
|
|
1855
|
+
* @param runner - Agent runner for LLM grading
|
|
1856
|
+
* @param options - Pipeline options
|
|
1857
|
+
* @returns Pipeline result with project-wide insights
|
|
1858
|
+
*
|
|
1859
|
+
* @example
|
|
1860
|
+
* ```typescript
|
|
1861
|
+
* const context = buildProjectContext(
|
|
1862
|
+
* "How we handle database migrations",
|
|
1863
|
+
* { repoPath: "/Users/me/my-project" }
|
|
1864
|
+
* );
|
|
1865
|
+
*
|
|
1866
|
+
* const result = await searchProjectLevel(codexHome, context, runner, {
|
|
1867
|
+
* limit: 8,
|
|
1868
|
+
* useReranker: true
|
|
1869
|
+
* });
|
|
1870
|
+
*
|
|
1871
|
+
* console.log(`Found ${result.insights.length} project-wide insights`);
|
|
1872
|
+
* ```
|
|
1873
|
+
*/
|
|
1874
|
+
declare function searchProjectLevel(codexHome: string, context: ProjectLevelContext, runner: AgentRunner | null, options?: ReveriePipelineOptions): Promise<ReveriePipelineResult>;
|
|
1875
|
+
/**
|
|
1876
|
+
* Search at branch level for feature-specific context.
|
|
1877
|
+
*
|
|
1878
|
+
* Optimized for understanding work done in a specific branch,
|
|
1879
|
+
* including intent, changed files, and commit history.
|
|
1880
|
+
*
|
|
1881
|
+
* @param codexHome - Path to .codex directory
|
|
1882
|
+
* @param context - Branch-level search context
|
|
1883
|
+
* @param runner - Agent runner for LLM grading
|
|
1884
|
+
* @param options - Pipeline options
|
|
1885
|
+
* @returns Pipeline result with branch-specific insights
|
|
1886
|
+
*
|
|
1887
|
+
* @example
|
|
1888
|
+
* ```typescript
|
|
1889
|
+
* const context = buildBranchContext(
|
|
1890
|
+
* "feat/oauth2",
|
|
1891
|
+
* ["src/auth.ts", "src/login.ts"],
|
|
1892
|
+
* {
|
|
1893
|
+
* baseBranch: "main",
|
|
1894
|
+
* recentCommits: "Add OAuth2 support\nImplement token refresh"
|
|
1895
|
+
* }
|
|
1896
|
+
* );
|
|
1897
|
+
*
|
|
1898
|
+
* const result = await searchBranchLevel(codexHome, context, runner, {
|
|
1899
|
+
* limit: 6
|
|
1900
|
+
* });
|
|
1901
|
+
*
|
|
1902
|
+
* console.log(`Found ${result.insights.length} branch insights`);
|
|
1903
|
+
* ```
|
|
1904
|
+
*/
|
|
1905
|
+
declare function searchBranchLevel(codexHome: string, context: BranchLevelContext, runner: AgentRunner | null, options?: ReveriePipelineOptions): Promise<ReveriePipelineResult>;
|
|
1906
|
+
/**
|
|
1907
|
+
* Search at file level for specific file changes.
|
|
1908
|
+
*
|
|
1909
|
+
* Optimized for focused searches on individual file modifications,
|
|
1910
|
+
* using extracted symbols for better targeting.
|
|
1911
|
+
*
|
|
1912
|
+
* @param codexHome - Path to .codex directory
|
|
1913
|
+
* @param context - File-level search context
|
|
1914
|
+
* @param runner - Agent runner for LLM grading
|
|
1915
|
+
* @param options - Pipeline options
|
|
1916
|
+
* @returns Pipeline result with file-specific insights
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```typescript
|
|
1920
|
+
* const context = buildFileContext(
|
|
1921
|
+
* "src/auth/jwt.ts",
|
|
1922
|
+
* {
|
|
1923
|
+
* diff: "+function validateToken(...)\n+function refreshToken(...)",
|
|
1924
|
+
* extractSymbols: true
|
|
1925
|
+
* }
|
|
1926
|
+
* );
|
|
1927
|
+
*
|
|
1928
|
+
* const result = await searchFileLevel(codexHome, context, runner, {
|
|
1929
|
+
* limit: 3
|
|
1930
|
+
* });
|
|
1931
|
+
*
|
|
1932
|
+
* console.log(`Found ${result.insights.length} file-specific insights`);
|
|
1933
|
+
* ```
|
|
1934
|
+
*/
|
|
1935
|
+
declare function searchFileLevel(codexHome: string, context: FileLevelContext, runner: AgentRunner | null, options?: ReveriePipelineOptions): Promise<ReveriePipelineResult>;
|
|
1936
|
+
|
|
1937
|
+
/**
|
|
1938
|
+
* Reverie logging utilities.
|
|
1939
|
+
* Provides transparent logging for reverie search and filtering operations.
|
|
1940
|
+
*/
|
|
1941
|
+
|
|
1942
|
+
/**
|
|
1943
|
+
* Logs reverie search operation details.
|
|
1944
|
+
*
|
|
1945
|
+
* @param query - The search query
|
|
1946
|
+
* @param context - Optional context about the search
|
|
1947
|
+
*/
|
|
1948
|
+
declare function logReverieSearch(query: string, context?: string): void;
|
|
1949
|
+
/**
|
|
1950
|
+
* Logs reverie filtering pipeline statistics.
|
|
1951
|
+
*
|
|
1952
|
+
* @param stats - Filtering statistics
|
|
1953
|
+
*/
|
|
1954
|
+
declare function logReverieFiltering(stats: {
|
|
1955
|
+
total: number;
|
|
1956
|
+
afterQuality: number;
|
|
1957
|
+
afterBoilerplate?: number;
|
|
1958
|
+
afterScore: number;
|
|
1959
|
+
afterDedup: number;
|
|
1960
|
+
minScore?: number;
|
|
1961
|
+
}): void;
|
|
1962
|
+
/**
|
|
1963
|
+
* Logs top reverie insights for debugging.
|
|
1964
|
+
*
|
|
1965
|
+
* @param insights - Filtered reverie insights
|
|
1966
|
+
* @param limit - Maximum number of insights to log (default: 3)
|
|
1967
|
+
*/
|
|
1968
|
+
declare function logReverieInsights(insights: ReverieResult[], limit?: number): void;
|
|
1969
|
+
/**
|
|
1970
|
+
* Logs quality filtering statistics for hint collection.
|
|
1971
|
+
*
|
|
1972
|
+
* @param stats - Hint collection statistics
|
|
1973
|
+
*/
|
|
1974
|
+
declare function logReverieHintQuality(stats: {
|
|
1975
|
+
totalRaw: number;
|
|
1976
|
+
afterQuality: number;
|
|
1977
|
+
afterDedup: number;
|
|
1978
|
+
}): void;
|
|
1979
|
+
/**
|
|
1980
|
+
* Logs LLM grading statistics showing approved vs rejected counts.
|
|
1981
|
+
*
|
|
1982
|
+
* @param stats - LLM grading statistics
|
|
1983
|
+
*/
|
|
1984
|
+
declare function logLLMGrading(stats: {
|
|
1985
|
+
total: number;
|
|
1986
|
+
approved: number;
|
|
1987
|
+
rejected: number;
|
|
1988
|
+
minScore?: number;
|
|
1989
|
+
}): void;
|
|
1990
|
+
/**
|
|
1991
|
+
* Logs approved reverie excerpts with relevance scores (verbose mode).
|
|
1992
|
+
*
|
|
1993
|
+
* @param insights - Approved reverie insights to log
|
|
1994
|
+
* @param maxToShow - Maximum number of insights to display (default: 5)
|
|
1995
|
+
*/
|
|
1996
|
+
declare function logApprovedReveries(insights: ReverieResult[], maxToShow?: number): void;
|
|
1997
|
+
/**
|
|
1998
|
+
* Truncates a string to a maximum length, adding ellipsis if needed.
|
|
1999
|
+
*/
|
|
2000
|
+
declare function truncate(text: string, maxLength: number): string;
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Logs multi-level search initiation.
|
|
2004
|
+
*
|
|
2005
|
+
* @param levels - Array of search levels being executed
|
|
2006
|
+
*
|
|
2007
|
+
* @example
|
|
2008
|
+
* ```typescript
|
|
2009
|
+
* logMultiLevelSearch(['project', 'branch', 'file']);
|
|
2010
|
+
* // Output: "🔍 Multi-level reverie search: project → branch → file"
|
|
2011
|
+
* ```
|
|
2012
|
+
*/
|
|
2013
|
+
declare function logMultiLevelSearch(levels: ReverieSearchLevel[]): void;
|
|
2014
|
+
/**
|
|
2015
|
+
* Logs results for a specific search level.
|
|
2016
|
+
*
|
|
2017
|
+
* @param level - The search level
|
|
2018
|
+
* @param result - Pipeline result for this level
|
|
2019
|
+
*
|
|
2020
|
+
* @example
|
|
2021
|
+
* ```typescript
|
|
2022
|
+
* logLevelResults('project', {
|
|
2023
|
+
* insights: [...],
|
|
2024
|
+
* stats: { total: 50, final: 8, ... }
|
|
2025
|
+
* });
|
|
2026
|
+
* // Output: " 🌐 Project level: 8 insights (50 → 8, 84% filtered)"
|
|
2027
|
+
* ```
|
|
2028
|
+
*/
|
|
2029
|
+
declare function logLevelResults(level: ReverieSearchLevel, result: ReveriePipelineResult): void;
|
|
2030
|
+
/**
|
|
2031
|
+
* Logs a summary of multi-level search results.
|
|
2032
|
+
*
|
|
2033
|
+
* @param results - Map of level to pipeline results
|
|
2034
|
+
*
|
|
2035
|
+
* @example
|
|
2036
|
+
* ```typescript
|
|
2037
|
+
* const results = new Map([
|
|
2038
|
+
* ['project', { insights: [...], stats: {...} }],
|
|
2039
|
+
* ['branch', { insights: [...], stats: {...} }],
|
|
2040
|
+
* ['file', { insights: [...], stats: {...} }]
|
|
2041
|
+
* ]);
|
|
2042
|
+
*
|
|
2043
|
+
* logMultiLevelSummary(results);
|
|
2044
|
+
* // Output summary of all levels with total counts
|
|
2045
|
+
* ```
|
|
2046
|
+
*/
|
|
2047
|
+
declare function logMultiLevelSummary(results: Map<ReverieSearchLevel, ReveriePipelineResult>): void;
|
|
2048
|
+
|
|
2049
|
+
/**
|
|
2050
|
+
* Symbol Extraction for Reverie Search
|
|
2051
|
+
*
|
|
2052
|
+
* Extracts key code symbols from diffs to create more focused search queries.
|
|
2053
|
+
* This improves search precision by targeting specific functions, classes, and variables.
|
|
2054
|
+
*/
|
|
2055
|
+
/**
|
|
2056
|
+
* Extracts key symbols and terms from a diff to make search queries more targeted.
|
|
2057
|
+
*
|
|
2058
|
+
* Focuses on:
|
|
2059
|
+
* - Function and class definitions
|
|
2060
|
+
* - Variable declarations (const, let, var)
|
|
2061
|
+
* - Exported symbols
|
|
2062
|
+
* - Interface and type definitions
|
|
2063
|
+
*
|
|
2064
|
+
* Avoids:
|
|
2065
|
+
* - Language keywords (true, false, null, etc.)
|
|
2066
|
+
* - Very short symbols (< 3 chars)
|
|
2067
|
+
* - Boilerplate patterns
|
|
2068
|
+
*
|
|
2069
|
+
* @param diff - Git diff content to extract symbols from
|
|
2070
|
+
* @returns Comma-separated string of top 5 symbols, or "code changes" if none found
|
|
2071
|
+
*
|
|
2072
|
+
* @example
|
|
2073
|
+
* ```typescript
|
|
2074
|
+
* const diff = `
|
|
2075
|
+
* +function processUser(user: User) {
|
|
2076
|
+
* + const userName = user.name;
|
|
2077
|
+
* + return userName;
|
|
2078
|
+
* +}
|
|
2079
|
+
* `;
|
|
2080
|
+
*
|
|
2081
|
+
* extractKeySymbols(diff); // "processUser, userName"
|
|
2082
|
+
* ```
|
|
2083
|
+
*/
|
|
2084
|
+
declare function extractKeySymbols(diff: string): string;
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* Advanced Reverie Search
|
|
2088
|
+
*
|
|
2089
|
+
* Provides semantic search over past conversation history with sophisticated filtering:
|
|
2090
|
+
* - 3x candidate multiplier for aggressive filtering
|
|
2091
|
+
* - Reranker support for improved precision
|
|
2092
|
+
* - Multi-stage filtering with transparent logging
|
|
2093
|
+
* - Quality and deduplication pipelines
|
|
2094
|
+
*/
|
|
2095
|
+
|
|
2096
|
+
/**
|
|
2097
|
+
* Performs advanced semantic search over reverie conversation history.
|
|
2098
|
+
*
|
|
2099
|
+
* Search pipeline:
|
|
2100
|
+
* 1. Fetch 3x candidates (candidateMultiplier × limit)
|
|
2101
|
+
* 2. Apply quality filtering (remove boilerplate, system prompts)
|
|
2102
|
+
* 3. Deduplicate similar excerpts (keep highest relevance)
|
|
2103
|
+
* 4. Apply reranker if enabled (improve precision)
|
|
2104
|
+
* 5. Return top N results
|
|
2105
|
+
*
|
|
2106
|
+
* Key features:
|
|
2107
|
+
* - Aggressive candidate fetching for better filtering headroom
|
|
2108
|
+
* - Optional reranker support for precision improvement
|
|
2109
|
+
* - Quality filtering removes system prompts and boilerplate
|
|
2110
|
+
* - Deduplication preserves highest-relevance duplicates
|
|
2111
|
+
* - Transparent logging at each stage
|
|
2112
|
+
*
|
|
2113
|
+
* @param codexHome - Path to .codex directory containing conversation data
|
|
2114
|
+
* @param text - Search query text
|
|
2115
|
+
* @param repo - Repository root path for filtering conversations
|
|
2116
|
+
* @param options - Search configuration options
|
|
2117
|
+
* @returns Array of relevant reverie insights, sorted by relevance
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```typescript
|
|
2121
|
+
* const insights = await searchReveries(
|
|
2122
|
+
* "/Users/me/.codex",
|
|
2123
|
+
* "authentication bug with JWT tokens",
|
|
2124
|
+
* "/Users/me/my-project",
|
|
2125
|
+
* {
|
|
2126
|
+
* limit: 6,
|
|
2127
|
+
* useReranker: true,
|
|
2128
|
+
* candidateMultiplier: 3
|
|
2129
|
+
* }
|
|
2130
|
+
* );
|
|
2131
|
+
*
|
|
2132
|
+
* console.log(`Found ${insights.length} relevant insights`);
|
|
2133
|
+
* insights.forEach(insight => {
|
|
2134
|
+
* console.log(`[${insight.relevance.toFixed(2)}] ${insight.excerpt.slice(0, 100)}`);
|
|
2135
|
+
* });
|
|
2136
|
+
* ```
|
|
2137
|
+
*/
|
|
2138
|
+
declare function searchReveries(codexHome: string, text: string, repo: string, options?: ReverieSearchOptions): Promise<ReverieInsight$1[]>;
|
|
2139
|
+
|
|
2140
|
+
/**
|
|
2141
|
+
* Reverie Context Builders
|
|
2142
|
+
*
|
|
2143
|
+
* Utilities for building search contexts at different levels:
|
|
2144
|
+
* - Project level: Repository-wide patterns and architecture
|
|
2145
|
+
* - Branch level: Feature/branch-specific work and intent
|
|
2146
|
+
* - File level: Individual file changes and symbols
|
|
2147
|
+
*/
|
|
2148
|
+
|
|
2149
|
+
/**
|
|
2150
|
+
* Builds project-level search context for repository-wide patterns.
|
|
2151
|
+
*
|
|
2152
|
+
* Use this for searching architectural decisions, common practices,
|
|
2153
|
+
* and project-wide patterns across the entire codebase.
|
|
2154
|
+
*
|
|
2155
|
+
* @param query - Natural language query describing what to find
|
|
2156
|
+
* @param options - Optional configuration
|
|
2157
|
+
* @returns Project-level context ready for search
|
|
2158
|
+
*
|
|
2159
|
+
* @example
|
|
2160
|
+
* ```typescript
|
|
2161
|
+
* const context = buildProjectContext(
|
|
2162
|
+
* "How we handle database migrations in this repository",
|
|
2163
|
+
* { repoPath: "/Users/me/my-project" }
|
|
2164
|
+
* );
|
|
2165
|
+
*
|
|
2166
|
+
* const results = await searchProjectLevel(codexHome, context, runner);
|
|
2167
|
+
* ```
|
|
2168
|
+
*/
|
|
2169
|
+
declare function buildProjectContext(query: string, options?: {
|
|
2170
|
+
repoPath?: string;
|
|
2171
|
+
filePatterns?: string[];
|
|
2172
|
+
}): ProjectLevelContext;
|
|
2173
|
+
/**
|
|
2174
|
+
* Builds branch-level search context for feature/branch-specific work.
|
|
2175
|
+
*
|
|
2176
|
+
* Use this for understanding branch intent, feature context, and changes
|
|
2177
|
+
* made across multiple files in a feature branch.
|
|
2178
|
+
*
|
|
2179
|
+
* @param branch - Current branch name
|
|
2180
|
+
* @param changedFiles - List of files modified in this branch
|
|
2181
|
+
* @param options - Optional configuration
|
|
2182
|
+
* @returns Branch-level context ready for search
|
|
2183
|
+
*
|
|
2184
|
+
* @example
|
|
2185
|
+
* ```typescript
|
|
2186
|
+
* const context = buildBranchContext(
|
|
2187
|
+
* "feat/oauth2",
|
|
2188
|
+
* ["src/auth.ts", "src/login.ts", "test/auth.test.ts"],
|
|
2189
|
+
* {
|
|
2190
|
+
* baseBranch: "main",
|
|
2191
|
+
* recentCommits: "Add OAuth2 support\nImplement token refresh",
|
|
2192
|
+
* repoPath: "/Users/me/my-project"
|
|
2193
|
+
* }
|
|
2194
|
+
* );
|
|
2195
|
+
*
|
|
2196
|
+
* const results = await searchBranchLevel(codexHome, context, runner);
|
|
2197
|
+
* ```
|
|
2198
|
+
*/
|
|
2199
|
+
declare function buildBranchContext(branch: string, changedFiles: string[], options?: {
|
|
2200
|
+
baseBranch?: string;
|
|
2201
|
+
recentCommits?: string;
|
|
2202
|
+
repoPath?: string;
|
|
2203
|
+
}): BranchLevelContext;
|
|
2204
|
+
/**
|
|
2205
|
+
* Builds file-level search context for individual file changes.
|
|
2206
|
+
*
|
|
2207
|
+
* Use this for focused searches on specific file modifications,
|
|
2208
|
+
* with optional symbol extraction for better targeting.
|
|
2209
|
+
*
|
|
2210
|
+
* @param filePath - Path to the file being analyzed
|
|
2211
|
+
* @param options - Optional configuration
|
|
2212
|
+
* @returns File-level context ready for search
|
|
2213
|
+
*
|
|
2214
|
+
* @example
|
|
2215
|
+
* ```typescript
|
|
2216
|
+
* // Without symbol extraction
|
|
2217
|
+
* const context = buildFileContext(
|
|
2218
|
+
* "src/auth/jwt.ts",
|
|
2219
|
+
* {
|
|
2220
|
+
* diff: "... git diff content ...",
|
|
2221
|
+
* repoPath: "/Users/me/my-project"
|
|
2222
|
+
* }
|
|
2223
|
+
* );
|
|
2224
|
+
*
|
|
2225
|
+
* // With automatic symbol extraction
|
|
2226
|
+
* const context = buildFileContext(
|
|
2227
|
+
* "src/auth/jwt.ts",
|
|
2228
|
+
* {
|
|
2229
|
+
* diff: "+function validateToken(...)\n+function refreshToken(...)",
|
|
2230
|
+
* extractSymbols: true,
|
|
2231
|
+
* repoPath: "/Users/me/my-project"
|
|
2232
|
+
* }
|
|
2233
|
+
* );
|
|
2234
|
+
* // context.symbols will be: ["validateToken", "refreshToken"]
|
|
2235
|
+
*
|
|
2236
|
+
* const results = await searchFileLevel(codexHome, context, runner);
|
|
2237
|
+
* ```
|
|
2238
|
+
*/
|
|
2239
|
+
declare function buildFileContext(filePath: string, options?: {
|
|
2240
|
+
diff?: string;
|
|
2241
|
+
extractSymbols?: boolean;
|
|
2242
|
+
repoPath?: string;
|
|
2243
|
+
}): FileLevelContext;
|
|
2244
|
+
/**
|
|
2245
|
+
* Converts a ReverieContext to a search query string.
|
|
2246
|
+
*
|
|
2247
|
+
* Transforms structured context objects into natural language queries
|
|
2248
|
+
* suitable for semantic search.
|
|
2249
|
+
*
|
|
2250
|
+
* @param context - Any level of reverie context
|
|
2251
|
+
* @returns Formatted search query string
|
|
2252
|
+
*
|
|
2253
|
+
* @example
|
|
2254
|
+
* ```typescript
|
|
2255
|
+
* const projectCtx = buildProjectContext("Authentication patterns");
|
|
2256
|
+
* const query = contextToQuery(projectCtx);
|
|
2257
|
+
* // Returns: "Project-wide: Authentication patterns"
|
|
2258
|
+
*
|
|
2259
|
+
* const branchCtx = buildBranchContext("feat/auth", ["auth.ts", "login.ts"]);
|
|
2260
|
+
* const query = contextToQuery(branchCtx);
|
|
2261
|
+
* // Returns: "Branch: feat/auth\nFiles: auth.ts, login.ts"
|
|
2262
|
+
*
|
|
2263
|
+
* const fileCtx = buildFileContext("auth.ts", {
|
|
2264
|
+
* symbols: ["validateToken", "refreshToken"]
|
|
2265
|
+
* });
|
|
2266
|
+
* const query = contextToQuery(fileCtx);
|
|
2267
|
+
* // Returns: "File: auth.ts\nSymbols: validateToken, refreshToken"
|
|
2268
|
+
* ```
|
|
2269
|
+
*/
|
|
2270
|
+
declare function contextToQuery(context: ReverieContext): string;
|
|
2271
|
+
/**
|
|
2272
|
+
* Helper to format file paths for display in contexts.
|
|
2273
|
+
*
|
|
2274
|
+
* @param files - Array of file paths
|
|
2275
|
+
* @param maxFiles - Maximum number of files to show before truncating
|
|
2276
|
+
* @returns Formatted file list string
|
|
2277
|
+
*/
|
|
2278
|
+
declare function formatFileList(files: string[], maxFiles?: number): string;
|
|
2279
|
+
|
|
2280
|
+
declare function evCompleted(id: string): string;
|
|
2281
|
+
declare function evResponseCreated(id: string): string;
|
|
2282
|
+
declare function evAssistantMessage(id: string, text: string): string;
|
|
2283
|
+
declare function evFunctionCall(callId: string, name: string, args: string): string;
|
|
2284
|
+
declare function sse(events: string[]): string;
|
|
2285
|
+
|
|
2286
|
+
export { type AgentMessageItem, type AgentRunner, type ApprovalMode, type ApprovalRequest, type BranchLevelContext, type BranchReview, type CloudApplyOutcome, type CloudApplyStatus, type DiffSummary as CloudDiffSummary, type CloudTaskStatus, type CloudTaskSummary, CloudTasks, type CloudTasksOptions, Codex, type CodexOptions, CodexProvider, type CodexProviderOptions, type CodexToolOptions, type CommandExecutionItem, type CommandExecutionStatus, type CommitReview, type ConversationListOptions, type ConversationListPage, type ConversationSummary, type CurrentChangesReview, type CustomReview, DEFAULT_RERANKER_BATCH_SIZE, DEFAULT_RERANKER_TOP_K, DEFAULT_REVERIE_LIMIT, DEFAULT_REVERIE_MAX_CANDIDATES, DEFAULT_SERVERS, type DelegationResult, type DiagnosticSeverity, type ErrorItem, type FastEmbedEmbedRequest, type FastEmbedInitOptions, type FastEmbedRerankerModelCode, type FileChangeItem, type FileDiagnostics, type FileLevelContext, type FileUpdateChange, type ForkOptions, type FormatStreamOptions, type FormattedStream, type GradingOptions, type Input, type ItemCompletedEvent, type ItemStartedEvent, type ItemUpdatedEvent, type LogEntry, LogLevel, type LogOutput, type LogScope, Logger, type LoggerConfig, type LspDiagnosticSeverity, LspDiagnosticsBridge, LspManager, type LspManagerOptions, type LspServerConfig, type McpToolCallItem, type McpToolCallStatus, type NativeForkResult, type NativeTokenUsage, type NativeToolDefinition, type NativeToolInterceptorContext, type NativeToolInvocation, type NativeToolResult, type NativeTuiExitInfo, type NativeTuiRequest, type NativeUpdateActionInfo, type NativeUpdateActionKind, type NormalizedDiagnostic, OpenCodeAgent, type OpenCodeAgentOptions, type PatchApplyStatus, type PatchChangeKind, type PermissionDecision, type PermissionRequest, type ProjectLevelContext, type QualityFilterStats, REVERIE_CANDIDATE_MULTIPLIER, REVERIE_EMBED_MODEL, REVERIE_LLM_GRADE_THRESHOLD, REVERIE_RERANKER_MODEL, type ReasoningItem, type RepoDiffFileChange, type RepoDiffSummary, type RepoDiffSummaryOptions, type ReverieContext, type ReverieEpisodeSummary, type ReverieFilterStats, type ReverieInsight$1 as ReverieInsight, type ReveriePipelineOptions, type ReveriePipelineResult, type ReverieResult, type ReverieSearchLevel, type ReverieSearchOptions, type ReverieSemanticIndexStats, type ReverieSemanticSearchOptions, type ReviewInvocationOptions, type ReviewTarget, type RunResult, type RunStreamedResult, type RunTuiOptions, type SandboxMode, ScopedLogger, type SkillDefinition, type SkillMentionTrigger, Thread, type ThreadError, type ThreadErrorEvent, type ThreadEvent, type ThreadItem, type ThreadLoggingSink, type ThreadOptions, type ThreadStartedEvent, type TodoItem, type TodoListItem, type TokenizerEncodeOptions, type TokenizerOptions, type ToolCallEvent, type TuiSession, type TurnCompletedEvent, type TurnFailedEvent, type TurnOptions, type TurnStartedEvent, type Usage, type UserInput, type WebSearchItem, type WorkspaceLocator, applyFileReveriePipeline, applyQualityPipeline, applyReveriePipeline, attachLspDiagnostics, buildBranchContext, buildFileContext, buildProjectContext, codexTool, collectRepoDiffSummary, contextToQuery, createThreadLogger, deduplicateReverieInsights, encodeToToon, evAssistantMessage, evCompleted, evFunctionCall, evResponseCreated, extractKeySymbols, fastEmbedEmbed, fastEmbedInit, filterBySeverity, findServerForFile, formatDiagnosticsForBackgroundEvent, formatDiagnosticsForTool, formatDiagnosticsWithSummary, formatFileList, formatStream, gradeReverieRelevance, gradeReveriesInParallel, isValidReverieExcerpt, logApprovedReveries, logLLMGrading, logLevelResults, logMultiLevelSearch, logMultiLevelSummary, logReverieFiltering, logReverieHintQuality, logReverieInsights, logReverieSearch, logger, resolveWorkspaceRoot, reverieGetConversationInsights, reverieIndexSemantic, reverieListConversations, reverieSearchConversations, reverieSearchSemantic, runThreadTurnWithLogs, runTui, searchBranchLevel, searchFileLevel, searchMultiLevel, searchProjectLevel, searchReveries, sse, startTui, summarizeDiagnostics, tokenizerCount, tokenizerDecode, tokenizerEncode, truncate as truncateText };
|