forked from pullfrog/pullfrog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal.ts
More file actions
299 lines (272 loc) · 9.06 KB
/
Copy pathexternal.ts
File metadata and controls
299 lines (272 loc) · 9.06 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
/**
* ⚠️ LIMITED IMPORTS - this file is imported by Next.js and must avoid pulling in backend code.
* All shared constants, types, and data used by both the Next.js app and the action runtime live here.
* Other files in action/ re-export from this file for backward compatibility.
*/
// mcp name constant
export const pullfrogMcpName = "pullfrog";
/** @see {@link file://./agents/shared.ts} Agent interface that uses this type */
export type AgentId = "claude" | "opencode";
/**
* format a tool name the way each agent's MCP client presents it to the model.
* claude code: mcp__pullfrog__select_mode
* opencode: pullfrog_select_mode
*/
export function formatMcpToolRef(agentId: AgentId, toolName: string): string {
switch (agentId) {
case "claude":
return `mcp__${pullfrogMcpName}__${toolName}`;
case "opencode":
return `${pullfrogMcpName}_${toolName}`;
default:
return agentId satisfies never;
}
}
// model alias registry lives in models.ts — re-exported here for shared access
export type { ModelAlias, ModelProvider, ProviderConfig } from "./models.ts";
export {
DEFAULT_PROXY_MODEL,
getAutoSelectHintModel,
getModelEnvVars,
getModelManagedCredentials,
getModelProvider,
getProviderDisplayName,
modelAliases,
parseModel,
providers,
resolveCliModel,
resolveDisplayAlias,
resolveModelSlug,
resolveOpenRouterModel,
} from "./models.ts";
// tool permission types shared with server dispatch
export type ToolPermission = "disabled" | "enabled";
export type ShellPermission = "disabled" | "restricted" | "enabled";
export type PushPermission = "disabled" | "restricted" | "enabled";
// workflow yml permissions for GITHUB_TOKEN
export type WorkflowPermissionValue = "read" | "write" | "none";
export type WorkflowIdTokenPermissionValue = "write" | "none";
export interface WorkflowPermissions {
actions?: WorkflowPermissionValue;
attestations?: WorkflowPermissionValue;
checks?: WorkflowPermissionValue;
contents?: WorkflowPermissionValue;
deployments?: WorkflowPermissionValue;
discussions?: WorkflowPermissionValue;
"id-token"?: WorkflowIdTokenPermissionValue;
issues?: WorkflowPermissionValue;
models?: WorkflowPermissionValue;
packages?: WorkflowPermissionValue;
pages?: WorkflowPermissionValue;
"pull-requests"?: WorkflowPermissionValue;
"repository-projects"?: WorkflowPermissionValue;
"security-events"?: WorkflowPermissionValue;
statuses?: WorkflowPermissionValue;
}
// permission level for the author who triggered the event
// matches GitHub's permission levels: admin > write > maintain > triage > read > none
export type AuthorPermission = "admin" | "maintain" | "write" | "triage" | "read" | "none";
// base interface for common payload event fields
interface BasePayloadEvent {
issue_number?: number;
is_pr?: boolean;
branch?: string;
/** title of the issue/PR (or contextual title for comments) */
title?: string;
/** primary content for this trigger (issue body, PR body, comment body, review body, etc.) */
body?: string | null;
comment_id?: number;
review_id?: number;
review_state?: string;
thread?: any;
pull_request?: any;
check_suite?: {
id: number;
head_sha: string;
head_branch: string | null;
status: string | null;
conclusion: string | null;
url: string;
};
comment_ids?: number[] | "all";
/** permission level of the user who triggered this event */
authorPermission?: AuthorPermission;
/** when true, runs silently without progress comments (e.g., auto-labeling) */
silent?: boolean;
[key: string]: any;
}
interface PullRequestOpenedEvent extends BasePayloadEvent {
trigger: "pull_request_opened";
issue_number: number;
is_pr: true;
title: string;
body: string | null;
branch: string;
}
interface PullRequestReadyForReviewEvent extends BasePayloadEvent {
trigger: "pull_request_ready_for_review";
issue_number: number;
is_pr: true;
title: string;
body: string | null;
branch: string;
}
interface PullRequestReviewRequestedEvent extends BasePayloadEvent {
trigger: "pull_request_review_requested";
issue_number: number;
is_pr: true;
title: string;
body: string | null;
branch: string;
}
interface PullRequestReviewSubmittedEvent extends BasePayloadEvent {
trigger: "pull_request_review_submitted";
issue_number: number;
is_pr: true;
review_id: number;
/** review body is the primary content */
body: string | null;
review_state: string;
branch: string;
}
interface PullRequestReviewCommentCreatedEvent extends BasePayloadEvent {
trigger: "pull_request_review_comment_created";
issue_number: number;
is_pr: true;
title: string;
comment_id: number;
/** comment body is the primary content (null if already in prompt) */
body: string | null;
thread?: any;
branch: string;
}
interface IssuesOpenedEvent extends BasePayloadEvent {
trigger: "issues_opened";
issue_number: number;
title: string;
body: string | null;
}
interface IssuesAssignedEvent extends BasePayloadEvent {
trigger: "issues_assigned";
issue_number: number;
title: string;
body: string | null;
}
interface IssuesLabeledEvent extends BasePayloadEvent {
trigger: "issues_labeled";
issue_number: number;
title: string;
body: string | null;
}
interface IssueCommentCreatedEvent extends BasePayloadEvent {
trigger: "issue_comment_created";
comment_id: number;
/** distinguishes this from PR review comments (which use pull_request_review_comment_created) */
comment_type: "issue";
/** comment body is the primary content (null if already in prompt) */
body: string | null;
issue_number: number;
// PR-specific fields (only present when is_pr is true)
is_pr?: true;
branch?: string;
title?: string;
}
interface CheckSuiteCompletedEvent extends BasePayloadEvent {
trigger: "check_suite_completed";
issue_number: number;
is_pr: true;
title: string;
body: string | null;
pull_request: any;
branch: string;
check_suite: {
id: number;
head_sha: string;
head_branch: string | null;
status: string | null;
conclusion: string | null;
url: string;
};
}
interface WorkflowDispatchEvent extends BasePayloadEvent {
trigger: "workflow_dispatch";
}
interface FixReviewEvent extends BasePayloadEvent {
trigger: "fix_review";
issue_number: number;
is_pr: true;
review_id: number;
/** when true, only address comments the triggerer approved with 👍 (vs all comments) */
approved_only?: boolean | undefined;
}
interface ImplementPlanEvent extends BasePayloadEvent {
trigger: "implement_plan";
issue_number: number;
plan_comment_id: number;
/** plan content is the primary content (null if already in prompt) */
body: string | null;
}
interface PullRequestSynchronizeEvent extends BasePayloadEvent {
trigger: "pull_request_synchronize";
issue_number: number;
is_pr: true;
title: string;
body: string | null;
branch: string;
/** SHA before the push -- used to compute incremental range-diff between PR versions */
before_sha: string;
}
interface UnknownEvent extends BasePayloadEvent {
trigger: "unknown";
}
// discriminated union for payload event based on trigger
// note: all events use issue_number for consistency (PRs are issues in GitHub's API)
export type PayloadEvent =
| PullRequestOpenedEvent
| PullRequestReadyForReviewEvent
| PullRequestSynchronizeEvent
| PullRequestReviewRequestedEvent
| PullRequestReviewSubmittedEvent
| PullRequestReviewCommentCreatedEvent
| IssuesOpenedEvent
| IssuesAssignedEvent
| IssuesLabeledEvent
| IssueCommentCreatedEvent
| CheckSuiteCompletedEvent
| WorkflowDispatchEvent
| FixReviewEvent
| ImplementPlanEvent
| UnknownEvent;
// writeable payload type for building payloads
export interface WriteablePayload {
"~pullfrog": true;
/** semantic version of the payload to ensure compatibility */
version: string;
/** provider/model slug (e.g. "anthropic/claude-opus") */
model?: string | undefined;
/** the user's actual request (body if @pullfrog tagged) */
prompt: string;
/** github username of the human who triggered this workflow run */
triggerer?: string | undefined;
/** event-level instructions for this trigger type (flag-expanded server-side) */
eventInstructions?: string | undefined;
/**
* system-injected note about prior superseded runs (e.g. when the
* triggering @pullfrog comment is edited). rendered alongside the user's
* prompt rather than via eventInstructions so it survives user-prompt
* precedence.
*/
previousRunsNote?: string | undefined;
/** event data from webhook payload - discriminated union based on trigger field */
event: PayloadEvent;
/** timeout for agent run (e.g., "10m", "1h30m") - defaults to "1h" */
timeout?: string | undefined;
/** working directory for the agent */
cwd?: string | undefined;
/** pre-created progress comment (ID + type) for updating status */
progressComment?: { id: string; type: "issue" | "review" } | undefined;
/** when true, seed the PR summary tmpfile + persist edits at run end */
generateSummary?: boolean | undefined;
}
// immutable payload type for agent execution
export type Payload = Readonly<WriteablePayload>;