-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
227 lines (200 loc) · 5.14 KB
/
types.ts
File metadata and controls
227 lines (200 loc) · 5.14 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
/**
* Cursor Hook Payload Types
* Based on Cursor 1.7+ hooks system
*/
// Base payload fields present in all hook events
export interface CursorBasePayload {
conversation_id: string;
generation_id: string;
hook_event_name: string;
workspace_roots: string[];
}
// beforeSubmitPrompt - fires when user submits a prompt
export interface BeforeSubmitPromptPayload extends CursorBasePayload {
hook_event_name: "beforeSubmitPrompt";
prompt: string;
}
// beforeShellExecution - fires before shell command runs
export interface BeforeShellExecutionPayload extends CursorBasePayload {
hook_event_name: "beforeShellExecution";
command: string;
cwd: string;
}
// beforeMCPExecution - fires before MCP tool runs
export interface BeforeMCPExecutionPayload extends CursorBasePayload {
hook_event_name: "beforeMCPExecution";
tool_name: string;
tool_input: Record<string, unknown>;
url?: string;
command?: string;
}
// beforeReadFile - fires before file is read
export interface BeforeReadFilePayload extends CursorBasePayload {
hook_event_name: "beforeReadFile";
file_path: string;
content?: string;
attachments?: Array<{
type: string;
file_path: string;
}>;
}
// afterFileEdit - fires after a file is modified
export interface AfterFileEditPayload extends CursorBasePayload {
hook_event_name: "afterFileEdit";
file_path: string;
edits: Array<{
old_string: string;
new_string: string;
}>;
}
// stop - fires when agent session completes
export interface StopPayload extends CursorBasePayload {
hook_event_name: "stop";
status?: "completed" | "aborted" | "error";
loop_count?: number;
}
// afterAgentResponse - fires after agent completes an assistant message
export interface AfterAgentResponsePayload extends CursorBasePayload {
hook_event_name: "afterAgentResponse";
text: string;
}
// Union type for all payloads
export type CursorHookPayload =
| BeforeSubmitPromptPayload
| BeforeShellExecutionPayload
| BeforeMCPExecutionPayload
| BeforeReadFilePayload
| AfterFileEditPayload
| AfterAgentResponsePayload
| StopPayload;
// Hook response types
export interface HookResponseAllow {
continue: true;
permission: "allow";
}
export interface HookResponseDeny {
continue: false;
permission: "deny";
userMessage?: string;
agentMessage?: string;
}
export interface HookResponseAsk {
continue: boolean;
permission: "ask";
userMessage?: string;
}
export type HookResponse = HookResponseAllow | HookResponseDeny | HookResponseAsk;
/**
* OpenSync API Types
*/
export interface OpenSyncConfig {
convexUrl: string;
apiKey: string;
autoSync?: boolean;
syncToolCalls?: boolean;
syncThinking?: boolean;
debug?: boolean;
}
// Source identifier for this plugin
export const OPENSYNC_SOURCE = "cursor-sync" as const;
export type OpenSyncSource = typeof OPENSYNC_SOURCE;
export interface OpenSyncSession {
id?: string;
externalId: string;
title: string;
model?: string;
source: OpenSyncSource;
project?: string;
directory?: string;
gitBranch?: string;
startedAt: number;
endedAt?: number;
totalTokens?: number;
promptTokens?: number;
completionTokens?: number;
cost?: number;
messageCount?: number;
toolCallCount?: number;
}
// Message part types for structured content
// Backend requires: { type: string, content: any }
export interface MessagePart {
type: string;
content: string;
}
export interface OpenSyncMessage {
id?: string;
sessionExternalId: string;
externalId: string;
source: OpenSyncSource;
role: "user" | "assistant" | "system" | "tool";
textContent?: string;
parts?: MessagePart[];
timestamp: number;
promptTokens?: number;
completionTokens?: number;
model?: string;
}
// Request types for OpenSync API
export type SyncSessionPayload = Omit<OpenSyncSession, "id">;
export type SyncMessagePayload = Omit<OpenSyncMessage, "id">;
export interface SyncSessionRequest {
session: SyncSessionPayload;
}
export interface SyncMessageRequest {
message: SyncMessagePayload;
}
export interface SyncBatchRequest {
sessions?: SyncSessionPayload[];
messages?: SyncMessagePayload[];
}
// Response types from OpenSync API (backend uses 'ok', we normalize to 'success')
export interface SyncSessionResponse {
success?: boolean;
ok?: boolean;
sessionId?: string;
error?: string;
}
export interface SyncMessageResponse {
success?: boolean;
ok?: boolean;
messageId?: string;
error?: string;
}
export interface SyncBatchResponse {
success?: boolean;
ok?: boolean;
sessionIds?: string[];
messageIds?: string[];
error?: string;
}
/**
* In-memory session state for accumulating data across hook events
*/
export interface SessionState {
conversationId: string;
generationId: string;
prompt?: string;
workspaceRoots: string[];
startedAt: number;
messages: Array<{
role: "user" | "assistant" | "tool";
content: string;
timestamp: number;
toolName?: string;
}>;
fileEdits: Array<{
filePath: string;
timestamp: number;
}>;
shellCommands: Array<{
command: string;
cwd: string;
timestamp: number;
}>;
mcpCalls: Array<{
toolName: string;
toolInput: Record<string, unknown>;
timestamp: number;
}>;
}