Repository navigation
Expand file tree
/
Copy pathclientRpcPermissions.ts
More file actions
143 lines (138 loc) · 7.97 KB
/
Copy pathclientRpcPermissions.ts
File metadata and controls
143 lines (138 loc) · 7.97 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
import * as Schema from "effect/Schema";
import { GitPreparePullRequestThreadInput, GitRunStackedActionInput } from "./git.ts";
import {
AuthAccessWriteScope,
AuthEnvironmentMaintainScope,
AuthOrchestrationOperateScope,
AuthFilesystemReadScope,
AuthProvidersManageScope,
AuthOrchestrationReadScope,
AuthPreviewOperateScope,
AuthSettingsWriteScope,
AuthSourceControlWriteScope,
AuthTerminalOperateScope,
type AuthEnvironmentScope,
} from "./auth.ts";
import { ORCHESTRATION_V2_WS_METHODS } from "./orchestrationV2.ts";
import { WS_METHODS } from "./rpc.ts";
/** Incremental client enforcement; the server still authorizes every request. */
export const CLIENT_GUARDED_RPC_SCOPES = {
[WS_METHODS.projectCodeQuery]: AuthFilesystemReadScope,
[WS_METHODS.projectCodeFileHistory]: AuthOrchestrationReadScope,
[WS_METHODS.projectKnowledgeMutate]: AuthOrchestrationOperateScope,
[WS_METHODS.modelEvaluationsClear]: AuthSettingsWriteScope,
[WS_METHODS.providerAuthRemoveMethod]: AuthProvidersManageScope,
// An MCP sign-in stores a credential for the agent, as an account sign-in does.
[WS_METHODS.providerMcpSignInStart]: AuthProvidersManageScope,
[WS_METHODS.providerMcpSignInComplete]: AuthProvidersManageScope,
[WS_METHODS.previewClose]: AuthPreviewOperateScope,
// Stopping a server signals its processes, as closing a terminal does.
[WS_METHODS.previewStopLocalServer]: AuthTerminalOperateScope,
[WS_METHODS.serverRunStorageCleanup]: AuthSettingsWriteScope,
// Restarts the server, as an update does.
[WS_METHODS.serverReclaimDatabaseSpace]: AuthEnvironmentMaintainScope,
[WS_METHODS.serverCheckOtlpEndpoint]: AuthSettingsWriteScope,
[WS_METHODS.serverCheckSecretSource]: AuthSettingsWriteScope,
// Refreshing moves skill folders in the host's harness homes, as the switch does.
[WS_METHODS.serverRefreshSkillsLibrary]: AuthSettingsWriteScope,
// Listing models spends the stored API key, so only those who can choose a model may.
[WS_METHODS.serverListTextGeneratorModels]: AuthSettingsWriteScope,
[WS_METHODS.serverRefreshProviders]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsRunAction]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsUpdate]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsComment]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsUpdateComment]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsSubmitReview]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsReplyToThread]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsSetThreadResolution]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsSetReaction]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsSetFilesViewed]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsRequestReviewers]: AuthSourceControlWriteScope,
[WS_METHODS.pullRequestsSetLabels]: AuthSourceControlWriteScope,
[WS_METHODS.issuesCreate]: AuthSourceControlWriteScope,
[WS_METHODS.issuesComment]: AuthSourceControlWriteScope,
[WS_METHODS.issuesUpdate]: AuthSourceControlWriteScope,
[WS_METHODS.issuesSetState]: AuthSourceControlWriteScope,
[WS_METHODS.issuesReact]: AuthSourceControlWriteScope,
// A tracker credential and a project's binding are settings, saved under the same grant.
[WS_METHODS.issueTrackersConnect]: AuthSettingsWriteScope,
[WS_METHODS.issueTrackersBindProject]: AuthSettingsWriteScope,
// Writing a guide runs a model on this environment's providers, which reading one does not.
[WS_METHODS.pullRequestsGenerateReviewGuide]: AuthOrchestrationOperateScope,
[WS_METHODS.projectsCreateFromThread]: AuthOrchestrationOperateScope,
[WS_METHODS.sourceControlCloneRepository]: AuthSourceControlWriteScope,
[WS_METHODS.sourceControlPublishRepository]: AuthSourceControlWriteScope,
[WS_METHODS.sourceControlStar]: AuthSourceControlWriteScope,
// Signing in replaces the server's GitHub credential, as saving a token in Settings does.
[WS_METHODS.sourceControlSignInStart]: AuthSettingsWriteScope,
[WS_METHODS.sourceControlSignInWait]: AuthSettingsWriteScope,
[WS_METHODS.sourceControlSignInCancel]: AuthSettingsWriteScope,
[WS_METHODS.projectCloneStart]: AuthSourceControlWriteScope,
[WS_METHODS.projectCloneCancel]: AuthSourceControlWriteScope,
[WS_METHODS.projectCloneRetry]: AuthSourceControlWriteScope,
[WS_METHODS.vcsPull]: AuthSourceControlWriteScope,
[WS_METHODS.gitRunStackedAction]: AuthSourceControlWriteScope,
[WS_METHODS.gitPreparePullRequestThread]: AuthSourceControlWriteScope,
[WS_METHODS.vcsCreateWorktree]: AuthSourceControlWriteScope,
[WS_METHODS.vcsRemoveWorktree]: AuthSourceControlWriteScope,
[WS_METHODS.workspaceAddTaskFolderRepository]: AuthSourceControlWriteScope,
[WS_METHODS.vcsCreateRef]: AuthSourceControlWriteScope,
[WS_METHODS.vcsSwitchRef]: AuthSourceControlWriteScope,
[WS_METHODS.vcsInit]: AuthSourceControlWriteScope,
[WS_METHODS.providerInstallStart]: AuthProvidersManageScope,
[WS_METHODS.providerInstallCancel]: AuthProvidersManageScope,
[WS_METHODS.providerInstallRemove]: AuthProvidersManageScope,
// Export returns plaintext provider secrets.
[WS_METHODS.inferenceStatus]: AuthProvidersManageScope,
[WS_METHODS.inferenceManage]: AuthProvidersManageScope,
[WS_METHODS.inferenceGrant]: AuthProvidersManageScope,
[WS_METHODS.inferenceConnect]: AuthProvidersManageScope,
[WS_METHODS.inferenceRegisterFallback]: AuthProvidersManageScope,
[WS_METHODS.providerAccountExport]: AuthProvidersManageScope,
[WS_METHODS.providerAccountImport]: AuthProvidersManageScope,
// Starts an agent session on this environment that can read its logs and database.
[WS_METHODS.serverPrepareTriage]: AuthOrchestrationOperateScope,
[WS_METHODS.scheduledTasksUpsert]: AuthOrchestrationOperateScope,
[WS_METHODS.scheduledTasksSetEnabled]: AuthOrchestrationOperateScope,
[WS_METHODS.scheduledTasksDelete]: AuthOrchestrationOperateScope,
[WS_METHODS.scheduledTasksRunNow]: AuthOrchestrationOperateScope,
[WS_METHODS.scheduledTasksRotateWebhookToken]: AuthOrchestrationOperateScope,
[ORCHESTRATION_V2_WS_METHODS.stopWorkflow]: AuthOrchestrationOperateScope,
[ORCHESTRATION_V2_WS_METHODS.threadGroupInvite]: AuthOrchestrationOperateScope,
[ORCHESTRATION_V2_WS_METHODS.threadGroupRemove]: AuthOrchestrationOperateScope,
[ORCHESTRATION_V2_WS_METHODS.threadGroupEnd]: AuthOrchestrationOperateScope,
// Force stop kills agent processes, as Stop on a terminal does.
[ORCHESTRATION_V2_WS_METHODS.forceStopThread]: AuthOrchestrationOperateScope,
// A guest link hands thread access to someone outside, like a pairing link.
[WS_METHODS.guestShareCreate]: AuthAccessWriteScope,
[WS_METHODS.peerLinksLink]: AuthAccessWriteScope,
[WS_METHODS.peerLinksUnlink]: AuthAccessWriteScope,
// A link lets every agent here reach the other environment: Settings' bar.
[WS_METHODS.peerLinksAnswerRequest]: AuthAccessWriteScope,
[WS_METHODS.peerLinksPairClient]: AuthAccessWriteScope,
[WS_METHODS.peerLinksPairLink]: AuthAccessWriteScope,
} as const;
export type ClientGuardedRpcTag = keyof typeof CLIENT_GUARDED_RPC_SCOPES;
const decodePrepareThread = Schema.decodeUnknownSync(GitPreparePullRequestThreadInput);
const decodeStackedAction = Schema.decodeUnknownSync(GitRunStackedActionInput);
export function clientRpcRequiredScopes(
method: string,
input: unknown,
): readonly AuthEnvironmentScope[] {
if (method === WS_METHODS.gitPreparePullRequestThread && input !== undefined) {
const payload = decodePrepareThread(input);
if (payload.mode === "worktree" && payload.threadId !== undefined)
return [AuthSourceControlWriteScope, AuthOrchestrationOperateScope];
}
if (method === WS_METHODS.gitRunStackedAction && input !== undefined) {
const payload = decodeStackedAction(input);
if (
payload.threadId !== undefined &&
(payload.action === "create_pr" || payload.action === "commit_push_pr")
)
return [AuthSourceControlWriteScope, AuthOrchestrationReadScope];
}
return Object.hasOwn(CLIENT_GUARDED_RPC_SCOPES, method)
? [CLIENT_GUARDED_RPC_SCOPES[method as ClientGuardedRpcTag]]
: [];
}