Repository navigation
Expand file tree
/
Copy pathExtensionMessage.ts
More file actions
431 lines (402 loc) · 13.4 KB
/
Copy pathExtensionMessage.ts
File metadata and controls
431 lines (402 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
// type that represents json data that is sent from extension to webview, called ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or 'settingsButtonClicked' or 'hello'
import type { GeneratedMedia } from "@cline/shared"
import { WorkspaceRoot } from "@shared/multi-root/types"
import { RemoteConfigFields } from "@shared/storage/state-keys"
import type { Environment } from "../config"
import { AutoApprovalSettings } from "./AutoApprovalSettings"
import { ApiConfiguration } from "./api"
import { BrowserSettings } from "./BrowserSettings"
import { ClineFeatureSetting } from "./ClineFeatureSetting"
import { BannerCardData } from "./cline/banner"
import { ClineRulesToggles } from "./cline-rules"
import type { CloudTaskTargetView, CurrentCloudTaskInfo } from "./cloud/cloud-sessions"
import { HistoryItem } from "./HistoryItem"
import { McpDisplayMode } from "./McpDisplayMode"
import { ClineMessageModelInfo } from "./messages"
import { Mode } from "./storage/types"
import { TelemetrySetting } from "./TelemetrySetting"
import { UserInfo } from "./UserInfo"
// webview will hold state
export interface ExtensionMessage {
type: "grpc_response" // New type for gRPC responses
grpc_response?: GrpcResponse
}
export type GrpcResponse = {
message?: any // JSON serialized protobuf message
request_id: string // Same ID as the request
error?: string // Optional error message
is_streaming?: boolean // Whether this is part of a streaming response
sequence_number?: number // For ordering chunks in streaming responses
}
export type Platform = "aix" | "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "win32" | "unknown"
export const DEFAULT_PLATFORM = "unknown"
export const COMMAND_CANCEL_TOKEN = "__cline_command_cancel__"
export interface ExtensionState {
isNewUser: boolean
welcomeViewCompleted: boolean
apiConfiguration?: ApiConfiguration
autoApprovalSettings: AutoApprovalSettings
browserSettings: BrowserSettings
remoteBrowserHost?: string
preferredLanguage?: string
mode: Mode
clineMessages: ClineMessage[]
checkpointRestoreInput?: {
text: string
images?: string[]
files?: string[]
sessionId: string
}
/**
* The single authoritative UI mode for the current turn, owned by the extension. The webview
* renders the footer/buttons/thinking indicator from this, NOT from the tail of clineMessages.
* Optional for classic/legacy (absent => webview falls back to legacy tail heuristics).
*/
turnState?: TurnState
/**
* Follow-up prompts submitted while the active agent turn is still running.
* These are owned by the SDK pending-prompt queue and are sent after the
* current turn reaches a safe continuation point.
*/
queuedPrompts?: QueuedPrompt[]
/**
* Monotonic version of this state snapshot. The webview applies a snapshot only if its
* stateVersion is newer than the last applied, so stale/out-of-order state pushes are
* ignored. Stamped by the extension. Optional for classic/legacy.
*/
stateVersion?: number
/**
* Conversation/replica fence for this snapshot (see ClineMessage.epoch). A snapshot with a
* newer epoch replaces the webview transcript; an older one is dropped; an equal one merges.
* Optional for classic/legacy.
*/
epoch?: number
currentTaskItem?: HistoryItem
mcpMarketplaceEnabled?: boolean
mcpDisplayMode: McpDisplayMode
planActSeparateModelsSetting: boolean
enableCheckpointsSetting?: boolean
platform: Platform
environment?: Environment
/** The editor Cline runs in, as the host reports it ("Visual Studio Code", "Cursor", "PyCharm Professional"). */
hostName?: string
shouldShowAnnouncement: boolean
taskHistory: HistoryItem[]
telemetrySetting: TelemetrySetting
shellIntegrationTimeout: number
terminalReuseEnabled?: boolean
defaultTerminalProfile?: string
vscodeTerminalExecutionMode: string
backgroundCommandRunning?: boolean
backgroundCommandTaskId?: string
/**
* True while a foreground (VS Code terminal) command is awaited by a
* run_commands tool call. Drives the "Proceed While Running" button.
*/
foregroundCommandRunning?: boolean
lastCompletedCommandTs?: number
userInfo?: UserInfo
version: string
/**
* Which rollout bundle this build is ("legacy" or "next"). Only present for
* bundles built by the combined rollout workflow; undefined for ordinary builds.
*/
extensionVariant?: "legacy" | "next"
distinctId: string
globalClineRulesToggles: ClineRulesToggles
localClineRulesToggles: ClineRulesToggles
localWorkflowToggles: ClineRulesToggles
globalWorkflowToggles: ClineRulesToggles
localCursorRulesToggles: ClineRulesToggles
localWindsurfRulesToggles: ClineRulesToggles
remoteRulesToggles?: ClineRulesToggles
remoteWorkflowToggles?: ClineRulesToggles
localAgentsRulesToggles: ClineRulesToggles
mcpResponsesCollapsed?: boolean
useAutoCondense?: boolean
compactionStrategy?: string
webSearchEnabled?: boolean
subagentsEnabled?: boolean
worktreesEnabled?: ClineFeatureSetting
favoritedModelIds: string[]
// NEW: Add workspace information
workspaceRoots: WorkspaceRoot[]
primaryRootIndex: number
isMultiRootWorkspace: boolean
multiRootSetting: ClineFeatureSetting
lastDismissedInfoBannerVersion: number
lastDismissedModelBannerVersion: number
lastDismissedCliBannerVersion: number
dismissedBanners?: Array<{ bannerId: string; dismissedAt: number }>
hooksEnabled?: boolean
remoteConfigSettings?: Partial<RemoteConfigFields>
remoteConfigRevision?: number
globalSkillsToggles?: Record<string, boolean>
localSkillsToggles?: Record<string, boolean>
backgroundEditEnabled?: boolean
optOutOfRemoteConfig?: boolean
remoteConfigAvailable?: boolean
showFeatureTips?: boolean
banners?: BannerCardData[]
welcomeBanners?: BannerCardData[]
/** Cline Cloud sessions rollout flag; shows the Settings toggle. */
cloudSessionsAvailable?: boolean
/** Cline Cloud sessions are available and turned on in Settings. */
cloudSessionsEnabled?: boolean
/** Where a new task runs, resolved from the user's choice, the account's repositories and the workspace. */
cloudTaskTarget?: CloudTaskTargetView
/** Present while the displayed task runs in Cline Cloud. */
currentCloudTask?: CurrentCloudTaskInfo
/** Cline model the displayed cloud task runs on, else the one a new cloud task would use. */
cloudModelId?: string
/** Cline model a new cloud task would run on; Settings edits this one. */
nextCloudModelId?: string
/** Whether the account has ClinePass for cloud tasks; unset until checked, or when the check failed. */
clinePassSubscribed?: boolean
openAiCodexIsAuthenticated?: boolean
}
/**
* The authoritative UI mode for the current agent turn, owned by the extension. The webview reads
* this instead of inferring mode from the tail of clineMessages.
*/
export type TurnPhase =
| "idle" // no active turn; input enabled, no buttons
| "streaming" // model producing content / tool running; Thinking + Cancel
| "awaiting_approval" // a tool/command/mcp/subagent approval is pending
| "awaiting_followup" // ask_question / plan_mode_respond / done-without-completion
| "completed" // attempt_completion done; Start New Task
| "error" // api_req_failed / fatal; Retry / recovery
| "resumable" // task cancelled / interrupted; Resume Task
export interface TurnState {
phase: TurnPhase
/** ts of the ClineMessage this phase is "about" (e.g. the pending approval/ask). */
anchorTs?: number
/** Monotonic; the webview keeps the highest-seq TurnState and ignores older ones. */
seq: number
}
export interface QueuedPrompt {
id: string
prompt: string
delivery: "queue" | "steer"
attachmentCount: number
}
export interface ClineMessage {
ts: number
type: "ask" | "say"
ask?: ClineAsk
say?: ClineSay
text?: string
reasoning?: string
images?: string[]
media?: GeneratedMedia[]
files?: string[]
partial?: boolean
/**
* Freshness counter for convergent-replica merging on the webview side. Monotonically
* increasing per process; a higher `seq` means a newer copy of the SAME `ts` (identity).
* Stamped by the extension as the message flows to the webview. Optional for classic/legacy.
*/
seq?: number
/**
* Conversation/replica fence. Messages from an older epoch (a previous task or a previous
* render of the same task) are dropped by the webview. Stamped by the extension. Optional
* for classic/legacy.
*/
epoch?: number
commandCompleted?: boolean
lastCheckpointHash?: string
isCheckpointCheckedOut?: boolean
isOperationOutsideWorkspace?: boolean
conversationHistoryIndex?: number
conversationHistoryDeletedRange?: [number, number] // for when conversation history is truncated for API requests
modelInfo?: ClineMessageModelInfo
}
export type ClineAsk =
| "followup"
| "plan_mode_respond"
| "act_mode_respond"
| "command"
| "command_output"
| "completion_result"
| "tool"
| "api_req_failed"
| "resume_task"
| "resume_completed_task"
| "mistake_limit_reached"
| "browser_action_launch"
| "use_mcp_server"
| "new_task"
| "condense"
| "summarize_task"
| "report_bug"
| "use_subagents"
export type ClineSay =
| "task"
| "error"
| "api_req_started"
| "api_req_finished"
| "text"
| "reasoning"
| "completion_result"
| "plan_completion_result" // turn-final plan-mode response inferred at turn end (SDK path)
| "user_feedback"
| "user_feedback_diff"
| "command"
| "command_output"
| "tool"
| "shell_integration_warning"
| "shell_integration_warning_with_suggestion"
| "browser_action_launch"
| "browser_action"
| "browser_action_result"
| "mcp_server_request_started"
| "mcp_server_response"
| "mcp_notification"
| "use_mcp_server"
| "diff_error"
| "deleted_api_reqs"
| "clineignore_error"
| "command_permission_denied"
| "checkpoint_created"
| "load_mcp_documentation"
| "info" // Added for general informational messages like retry status
| "hook_status"
| "hook_output_stream"
| "subagent"
| "use_subagents"
| "subagent_usage"
| "conditional_rules_applied"
| "compaction" // context compaction progress/result divider
| "cloud_provisioning" // cloud sandbox start/resume progress
export interface ClineSayTool {
tool:
| "editedExistingFile"
| "newFileCreated"
| "fileDeleted"
| "readFile"
| "listFilesTopLevel"
| "listFilesRecursive"
| "listCodeDefinitionNames"
| "searchFiles"
| "webFetch"
| "webSearch"
| "summarizeTask"
| "useSkill"
path?: string
diff?: string
content?: string
regex?: string
filePattern?: string
operationIsLocatedInWorkspace?: boolean
/** Starting line numbers in the original file where each SEARCH block matched */
startLineNumbers?: number[]
/** One-based inclusive line range requested by read_file; readLineEnd omitted = open-ended read (for UI summaries). */
readLineStart?: number
readLineEnd?: number
}
// must keep in sync with system prompt
const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
export type BrowserAction = (typeof browserActions)[number]
export interface ClineSayBrowserAction {
action: BrowserAction
coordinate?: string
text?: string
}
export type SubagentExecutionStatus = "pending" | "running" | "completed" | "failed"
export interface SubagentStatusItem {
index: number
prompt: string
status: SubagentExecutionStatus
toolCalls: number
inputTokens: number
outputTokens: number
totalCost: number
contextTokens: number
contextWindow: number
contextUsagePercentage: number
latestToolCall?: string
result?: string
error?: string
}
export interface ClineSaySubagentStatus {
status: "running" | "completed" | "failed"
total: number
completed: number
successes: number
failures: number
toolCalls: number
inputTokens: number
outputTokens: number
contextWindow: number
maxContextTokens: number
maxContextUsagePercentage: number
items: SubagentStatusItem[]
}
export type BrowserActionResult = {
screenshot?: string
logs?: string
currentUrl?: string
currentMousePosition?: string
}
export interface ClineAskUseMcpServer {
serverName: string
type: "use_mcp_tool" | "access_mcp_resource"
toolName?: string
arguments?: string
uri?: string
}
export interface ClineAskUseSubagents {
prompts: string[]
}
export interface ClinePlanModeResponse {
response: string
options?: string[]
selected?: string
}
export interface ClineAskQuestion {
question: string
options?: string[]
selected?: string
}
export interface ClineApiReqInfo {
request?: string
tokensIn?: number
tokensOut?: number
cacheWrites?: number
cacheReads?: number
cost?: number
cancelReason?: ClineApiReqCancelReason
streamingFailedMessage?: string
}
/**
* JSON payload of a say:"compaction" message. Mirrors the CLI's compaction
* divider (apps/cli/src/tui/utils/compaction-status.ts): a "started" row shows
* a spinner and is later updated in place (same ts) to its terminal status.
*/
export interface ClineCompactionInfo {
status: "started" | "completed" | "skipped" | "failed" | "cancelled"
mode: "auto" | "manual"
tokensBefore?: number
tokensAfter?: number
messagesBefore?: number
messagesAfter?: number
}
/**
* JSON payload of a say:"cloud_provisioning" message. The row is updated in
* place (same ts) as the sandbox advances through its phases.
*/
export interface ClineCloudProvisioningInfo {
phase: "starting" | "cloning_repo" | "agent_starting" | "resuming"
repo?: string
branch?: string
}
export interface ClineSubagentUsageInfo {
source: "subagents"
tokensIn: number
tokensOut: number
cacheWrites: number
cacheReads: number
cost: number
}
type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled" | "retries_exhausted"
export const COMPLETION_RESULT_CHANGES_FLAG = "HAS_CHANGES"