tryharness 0.7.45 → 0.7.54
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/README.md +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import { once } from "node:events";
|
|
3
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
const random = () => randomBytes(32).toString("base64url");
|
|
6
|
+
function authUrl(value) {
|
|
7
|
+
const url = new URL(value);
|
|
8
|
+
if (
|
|
9
|
+
url.username ||
|
|
10
|
+
url.password ||
|
|
11
|
+
(url.protocol !== "https:" &&
|
|
12
|
+
!(
|
|
13
|
+
url.protocol === "http:" &&
|
|
14
|
+
["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)
|
|
15
|
+
))
|
|
16
|
+
)
|
|
17
|
+
throw new Error("OAuth requires HTTPS or a local test provider");
|
|
18
|
+
return url.href;
|
|
19
|
+
}
|
|
20
|
+
async function metadata(url, signal) {
|
|
21
|
+
const response = await fetch(authUrl(url), { redirect: "error", signal });
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
await response.body?.cancel();
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return response.json();
|
|
27
|
+
}
|
|
28
|
+
function wellKnown(value, kind) {
|
|
29
|
+
const url = new URL(value);
|
|
30
|
+
const suffix = url.pathname === "/" ? "" : url.pathname.replace(/\/$/, "");
|
|
31
|
+
return [
|
|
32
|
+
...new Set([
|
|
33
|
+
`${url.origin}/.well-known/${kind}${suffix}`,
|
|
34
|
+
`${url.origin}/.well-known/${kind}`,
|
|
35
|
+
]),
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
async function firstMetadata(urls, signal) {
|
|
39
|
+
for (const url of urls) {
|
|
40
|
+
const found = await metadata(url, signal);
|
|
41
|
+
if (found) return found;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The loopback callback belongs to this sign-in only. Credentials go straight to
|
|
47
|
+
// the local connection owner; neither a browser tab nor Harness stores them.
|
|
48
|
+
export async function authorizeConnector({
|
|
49
|
+
url,
|
|
50
|
+
clientId,
|
|
51
|
+
clientSecret,
|
|
52
|
+
scope,
|
|
53
|
+
signal,
|
|
54
|
+
metadata: configuredMetadata,
|
|
55
|
+
resource: includeResource = true,
|
|
56
|
+
offline = false,
|
|
57
|
+
redirectUri: configuredRedirect,
|
|
58
|
+
}) {
|
|
59
|
+
let resource;
|
|
60
|
+
if (!configuredMetadata) {
|
|
61
|
+
const challenge = await fetch(authUrl(url), { redirect: "error", signal });
|
|
62
|
+
const resourceUrl = challenge.headers
|
|
63
|
+
.get("www-authenticate")
|
|
64
|
+
?.match(/resource_metadata="([^"]+)"/i)?.[1];
|
|
65
|
+
await challenge.body?.cancel();
|
|
66
|
+
resource = await firstMetadata(
|
|
67
|
+
[
|
|
68
|
+
...(resourceUrl ? [resourceUrl] : []),
|
|
69
|
+
...wellKnown(url, "oauth-protected-resource"),
|
|
70
|
+
],
|
|
71
|
+
signal
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const issuer = resource?.authorization_servers?.[0] || new URL(url).origin;
|
|
75
|
+
const provider =
|
|
76
|
+
configuredMetadata ||
|
|
77
|
+
(await firstMetadata(
|
|
78
|
+
[
|
|
79
|
+
...wellKnown(issuer, "oauth-authorization-server"),
|
|
80
|
+
...wellKnown(issuer, "openid-configuration"),
|
|
81
|
+
],
|
|
82
|
+
signal
|
|
83
|
+
));
|
|
84
|
+
if (!provider?.authorization_endpoint || !provider.token_endpoint)
|
|
85
|
+
throw new Error("the provider did not advertise OAuth sign-in");
|
|
86
|
+
const authorizationEndpoint = authUrl(provider.authorization_endpoint);
|
|
87
|
+
const tokenEndpoint = authUrl(provider.token_endpoint);
|
|
88
|
+
const resourceIndicator = resource?.resource || url;
|
|
89
|
+
if (includeResource) {
|
|
90
|
+
const advertised = new URL(authUrl(resourceIndicator));
|
|
91
|
+
const requested = new URL(url);
|
|
92
|
+
const path = advertised.pathname.replace(/\/$/, "");
|
|
93
|
+
if (
|
|
94
|
+
advertised.origin !== requested.origin ||
|
|
95
|
+
!(
|
|
96
|
+
requested.pathname === path || requested.pathname.startsWith(`${path}/`)
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
throw new Error("the provider advertised a different protected resource");
|
|
100
|
+
}
|
|
101
|
+
const state = random();
|
|
102
|
+
const verifier = random();
|
|
103
|
+
let resolveCompletion;
|
|
104
|
+
let rejectCompletion;
|
|
105
|
+
const completion = new Promise((resolve, reject) => {
|
|
106
|
+
resolveCompletion = resolve;
|
|
107
|
+
rejectCompletion = reject;
|
|
108
|
+
});
|
|
109
|
+
// The owner can take time at the provider. Cancellation closes this listener;
|
|
110
|
+
// there is no guessed endpoint deadline or automatic grant expansion.
|
|
111
|
+
const server = http.createServer();
|
|
112
|
+
const abort = () => {
|
|
113
|
+
server.close();
|
|
114
|
+
rejectCompletion(new Error("sign-in cancelled"));
|
|
115
|
+
};
|
|
116
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
117
|
+
let redirectUri;
|
|
118
|
+
const supportedMethods = provider.token_endpoint_auth_methods_supported;
|
|
119
|
+
let authMethod = clientSecret
|
|
120
|
+
? supportedMethods?.includes("client_secret_post") || !supportedMethods
|
|
121
|
+
? "client_secret_post"
|
|
122
|
+
: "client_secret_basic"
|
|
123
|
+
: "none";
|
|
124
|
+
try {
|
|
125
|
+
let port = 0;
|
|
126
|
+
if (configuredRedirect) {
|
|
127
|
+
const target = new URL(configuredRedirect);
|
|
128
|
+
if (
|
|
129
|
+
target.protocol !== "http:" ||
|
|
130
|
+
target.hostname !== "127.0.0.1" ||
|
|
131
|
+
!target.port ||
|
|
132
|
+
target.pathname !== "/callback" ||
|
|
133
|
+
target.search ||
|
|
134
|
+
target.hash ||
|
|
135
|
+
target.username ||
|
|
136
|
+
target.password
|
|
137
|
+
)
|
|
138
|
+
throw new Error(
|
|
139
|
+
"the registered callback must be http://127.0.0.1:PORT/callback"
|
|
140
|
+
);
|
|
141
|
+
port = Number(target.port);
|
|
142
|
+
}
|
|
143
|
+
if (signal.aborted) throw new Error("sign-in cancelled");
|
|
144
|
+
server.listen(port, "127.0.0.1");
|
|
145
|
+
await once(server, "listening");
|
|
146
|
+
redirectUri = `http://127.0.0.1:${server.address().port}/callback`;
|
|
147
|
+
if (!clientId) {
|
|
148
|
+
if (!provider.registration_endpoint)
|
|
149
|
+
throw new Error(
|
|
150
|
+
"This provider requires a registered OAuth app. Supply its client ID for the local pilot."
|
|
151
|
+
);
|
|
152
|
+
const registered = await fetch(authUrl(provider.registration_endpoint), {
|
|
153
|
+
method: "POST",
|
|
154
|
+
redirect: "error",
|
|
155
|
+
signal,
|
|
156
|
+
headers: { "content-type": "application/json" },
|
|
157
|
+
body: JSON.stringify({
|
|
158
|
+
client_name: "Harness Relay",
|
|
159
|
+
redirect_uris: [redirectUri],
|
|
160
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
161
|
+
response_types: ["code"],
|
|
162
|
+
token_endpoint_auth_method: "none",
|
|
163
|
+
}),
|
|
164
|
+
});
|
|
165
|
+
if (!registered.ok) {
|
|
166
|
+
await registered.body?.cancel();
|
|
167
|
+
throw new Error("the provider refused OAuth app registration");
|
|
168
|
+
}
|
|
169
|
+
const app = await registered.json();
|
|
170
|
+
if (typeof app.client_id !== "string")
|
|
171
|
+
throw new Error("the provider returned no OAuth client identity");
|
|
172
|
+
clientId = app.client_id;
|
|
173
|
+
clientSecret = app.client_secret;
|
|
174
|
+
authMethod =
|
|
175
|
+
app.token_endpoint_auth_method ||
|
|
176
|
+
(clientSecret ? "client_secret_post" : "none");
|
|
177
|
+
}
|
|
178
|
+
if (
|
|
179
|
+
!["none", "client_secret_post", "client_secret_basic"].includes(
|
|
180
|
+
authMethod
|
|
181
|
+
) ||
|
|
182
|
+
(supportedMethods && !supportedMethods.includes(authMethod))
|
|
183
|
+
)
|
|
184
|
+
throw new Error(
|
|
185
|
+
"this provider requires a supported registered OAuth client and secret"
|
|
186
|
+
);
|
|
187
|
+
const authorize = new URL(authorizationEndpoint);
|
|
188
|
+
for (const [name, value] of Object.entries({
|
|
189
|
+
response_type: "code",
|
|
190
|
+
client_id: clientId,
|
|
191
|
+
redirect_uri: redirectUri,
|
|
192
|
+
state,
|
|
193
|
+
code_challenge: createHash("sha256").update(verifier).digest("base64url"),
|
|
194
|
+
code_challenge_method: "S256",
|
|
195
|
+
...(includeResource ? { resource: resourceIndicator } : {}),
|
|
196
|
+
...(offline ? { access_type: "offline", prompt: "consent" } : {}),
|
|
197
|
+
...(scope ? { scope } : {}),
|
|
198
|
+
}))
|
|
199
|
+
authorize.searchParams.set(name, value);
|
|
200
|
+
let used = false;
|
|
201
|
+
server.on("request", async (request, response) => {
|
|
202
|
+
const callback = new URL(request.url, redirectUri);
|
|
203
|
+
if (
|
|
204
|
+
request.method !== "GET" ||
|
|
205
|
+
callback.pathname !== "/callback" ||
|
|
206
|
+
callback.searchParams.get("state") !== state
|
|
207
|
+
) {
|
|
208
|
+
response.writeHead(400).end("Invalid sign-in callback.");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (used) {
|
|
212
|
+
response.writeHead(409).end("This sign-in has already been used.");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
used = true;
|
|
216
|
+
try {
|
|
217
|
+
const code = callback.searchParams.get("code");
|
|
218
|
+
if (!code || callback.searchParams.has("error"))
|
|
219
|
+
throw new Error("provider sign-in was declined");
|
|
220
|
+
const values = {
|
|
221
|
+
grant_type: "authorization_code",
|
|
222
|
+
code,
|
|
223
|
+
redirect_uri: redirectUri,
|
|
224
|
+
code_verifier: verifier,
|
|
225
|
+
client_id: clientId,
|
|
226
|
+
...(includeResource ? { resource: resourceIndicator } : {}),
|
|
227
|
+
...(clientSecret && authMethod === "client_secret_post"
|
|
228
|
+
? { client_secret: clientSecret }
|
|
229
|
+
: {}),
|
|
230
|
+
};
|
|
231
|
+
const token = await fetch(tokenEndpoint, {
|
|
232
|
+
method: "POST",
|
|
233
|
+
redirect: "error",
|
|
234
|
+
signal,
|
|
235
|
+
headers: {
|
|
236
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
237
|
+
...(clientSecret && authMethod === "client_secret_basic"
|
|
238
|
+
? {
|
|
239
|
+
authorization: `Basic ${Buffer.from(`${encodeURIComponent(clientId)}:${encodeURIComponent(clientSecret)}`).toString("base64")}`,
|
|
240
|
+
}
|
|
241
|
+
: {}),
|
|
242
|
+
},
|
|
243
|
+
body: new URLSearchParams(values),
|
|
244
|
+
});
|
|
245
|
+
if (!token.ok) {
|
|
246
|
+
await token.body?.cancel();
|
|
247
|
+
throw new Error("the provider refused the sign-in exchange");
|
|
248
|
+
}
|
|
249
|
+
const tokens = await token.json();
|
|
250
|
+
if (typeof tokens.access_token !== "string")
|
|
251
|
+
throw new Error("the provider returned no access token");
|
|
252
|
+
resolveCompletion({
|
|
253
|
+
accessToken: tokens.access_token,
|
|
254
|
+
refreshToken: tokens.refresh_token,
|
|
255
|
+
expiresAt:
|
|
256
|
+
typeof tokens.expires_in === "number"
|
|
257
|
+
? new Date(Date.now() + tokens.expires_in * 1000).toISOString()
|
|
258
|
+
: null,
|
|
259
|
+
clientId,
|
|
260
|
+
clientSecret,
|
|
261
|
+
authMethod,
|
|
262
|
+
tokenEndpoint,
|
|
263
|
+
resource: includeResource ? resourceIndicator : null,
|
|
264
|
+
...(tokens.user_id && tokens.workspace_id
|
|
265
|
+
? {
|
|
266
|
+
identity: {
|
|
267
|
+
id: String(tokens.user_id),
|
|
268
|
+
workspaceId: String(tokens.workspace_id),
|
|
269
|
+
workspaceName:
|
|
270
|
+
typeof tokens.workspace_name === "string"
|
|
271
|
+
? tokens.workspace_name
|
|
272
|
+
: null,
|
|
273
|
+
source: tokenEndpoint,
|
|
274
|
+
checkedAt: new Date().toISOString(),
|
|
275
|
+
},
|
|
276
|
+
}
|
|
277
|
+
: {}),
|
|
278
|
+
grantedScope: tokens.scope || scope || "",
|
|
279
|
+
});
|
|
280
|
+
response.setHeader("content-type", "text/html; charset=utf-8");
|
|
281
|
+
response.setHeader("referrer-policy", "no-referrer");
|
|
282
|
+
response.setHeader(
|
|
283
|
+
"content-security-policy",
|
|
284
|
+
"default-src 'none'; frame-ancestors 'none'"
|
|
285
|
+
);
|
|
286
|
+
response.end(
|
|
287
|
+
"<!doctype html><title>Connected to Harness Relay</title><p>Connected. You can close this window and return to Harness.</p>"
|
|
288
|
+
);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
response
|
|
291
|
+
.writeHead(400)
|
|
292
|
+
.end("Sign-in did not complete. Return to Harness to try again.");
|
|
293
|
+
rejectCompletion(error);
|
|
294
|
+
} finally {
|
|
295
|
+
signal.removeEventListener("abort", abort);
|
|
296
|
+
server.close();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
if (signal.aborted) throw new Error("sign-in cancelled");
|
|
300
|
+
return { authorizeUrl: authorize.href, completion };
|
|
301
|
+
} catch (error) {
|
|
302
|
+
signal.removeEventListener("abort", abort);
|
|
303
|
+
server.close();
|
|
304
|
+
// Before the callback is offered, no one owns the completion promise.
|
|
305
|
+
completion.catch(() => {});
|
|
306
|
+
rejectCompletion(error);
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "calendar",
|
|
4
|
+
"name": "Google Calendar",
|
|
5
|
+
"url": "https://www.googleapis.com/calendar/v3",
|
|
6
|
+
"scope": "https://www.googleapis.com/auth/calendar.events.readonly https://www.googleapis.com/auth/calendar.calendarlist.readonly",
|
|
7
|
+
"note": "Connect with a Google Desktop OAuth client configured in Relay. Uses the public Calendar API; no Developer Preview enrollment is needed.",
|
|
8
|
+
"writeScope": "https://www.googleapis.com/auth/calendar.events https://www.googleapis.com/auth/calendar.calendarlist.readonly"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"id": "gmail",
|
|
12
|
+
"name": "Gmail",
|
|
13
|
+
"url": "https://gmail.googleapis.com/gmail/v1",
|
|
14
|
+
"scope": "https://www.googleapis.com/auth/gmail.readonly",
|
|
15
|
+
"note": "Connect with a Google Desktop OAuth client configured in Relay. Starts with reading mail. Saving drafts and sending require additional consent and separate agent permissions.",
|
|
16
|
+
"writeScope": "https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.compose",
|
|
17
|
+
"sendScope": "https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.compose https://www.googleapis.com/auth/gmail.send"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "slack",
|
|
21
|
+
"name": "Slack",
|
|
22
|
+
"url": "https://mcp.slack.com/mcp",
|
|
23
|
+
"note": "Requires your internal or Marketplace-published Slack OAuth app, its client secret and registered loopback callback. Starts with public-channel search and reading; private channels and messages need separate scopes.",
|
|
24
|
+
"scope": "channels:history search:read.public users:read",
|
|
25
|
+
"writeScope": "channels:history search:read.public users:read chat:write"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "notion",
|
|
29
|
+
"name": "Notion",
|
|
30
|
+
"url": "https://mcp.notion.com/mcp",
|
|
31
|
+
"note": "Sign in to the workspace you want your swarm to use."
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "linear",
|
|
35
|
+
"name": "Linear",
|
|
36
|
+
"url": "https://mcp.linear.app/mcp",
|
|
37
|
+
"scope": "read",
|
|
38
|
+
"note": "Starts with read access. Broader OAuth access and Relay grants are separate choices.",
|
|
39
|
+
"writeScope": "read write"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { daemonRequest } from "./control-client.mjs";
|
|
5
|
+
|
|
6
|
+
const catalog = createRequire(import.meta.url)("./connectorCatalog.json");
|
|
7
|
+
|
|
8
|
+
export async function connectorCommands(argv) {
|
|
9
|
+
const option = (name) => {
|
|
10
|
+
const at = argv.indexOf(name);
|
|
11
|
+
return at < 0 ? null : argv[at + 1];
|
|
12
|
+
};
|
|
13
|
+
const action = argv[0] || "list";
|
|
14
|
+
const id = argv[1];
|
|
15
|
+
const call = (op, fields = {}) =>
|
|
16
|
+
daemonRequest({
|
|
17
|
+
command: `board.connector.${op}`,
|
|
18
|
+
agent: "user",
|
|
19
|
+
...fields,
|
|
20
|
+
});
|
|
21
|
+
let result;
|
|
22
|
+
if (action === "catalog") result = { ok: true, providers: catalog };
|
|
23
|
+
else if (action === "add" || action === "reconnect") {
|
|
24
|
+
const provider = catalog.find((candidate) => candidate.id === id);
|
|
25
|
+
const tokenName = option("--token-env");
|
|
26
|
+
const secretName = option("--client-secret-env");
|
|
27
|
+
if (tokenName && !process.env[tokenName])
|
|
28
|
+
throw new Error(`no token is set in ${tokenName}`);
|
|
29
|
+
if (secretName && !process.env[secretName])
|
|
30
|
+
throw new Error(`no client secret is set in ${secretName}`);
|
|
31
|
+
result = await call(action, {
|
|
32
|
+
...(action === "reconnect" ? { id } : {}),
|
|
33
|
+
label: option("--name") || provider?.name || id,
|
|
34
|
+
provider: provider?.id,
|
|
35
|
+
account: option("--account") || "",
|
|
36
|
+
url: option("--url") || provider?.url,
|
|
37
|
+
credentials: tokenName ? { bearer: process.env[tokenName] } : {},
|
|
38
|
+
signIn: !tokenName,
|
|
39
|
+
oauth: {
|
|
40
|
+
clientId: option("--client-id"),
|
|
41
|
+
clientSecret: secretName ? process.env[secretName] : undefined,
|
|
42
|
+
scope: option("--scope") || provider?.scope,
|
|
43
|
+
redirectUri: option("--callback"),
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
if (result.ok && !tokenName) {
|
|
47
|
+
let connection = result.connection;
|
|
48
|
+
while (connection.status === "authorizing") {
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
50
|
+
const state = await call("tools", { id: connection.id });
|
|
51
|
+
if (!state.ok) throw new Error(state.error);
|
|
52
|
+
connection = state.connection;
|
|
53
|
+
}
|
|
54
|
+
result.connection = connection;
|
|
55
|
+
if (connection.authorizeUrl) {
|
|
56
|
+
console.log(`Finish sign-in: ${connection.authorizeUrl}`);
|
|
57
|
+
if (!argv.includes("--no-open")) {
|
|
58
|
+
const command =
|
|
59
|
+
process.platform === "darwin"
|
|
60
|
+
? "open"
|
|
61
|
+
: process.platform === "win32"
|
|
62
|
+
? "rundll32"
|
|
63
|
+
: "xdg-open";
|
|
64
|
+
const args =
|
|
65
|
+
process.platform === "win32"
|
|
66
|
+
? ["url.dll,FileProtocolHandler", connection.authorizeUrl]
|
|
67
|
+
: [connection.authorizeUrl];
|
|
68
|
+
const child = spawn(command, args, {
|
|
69
|
+
stdio: "ignore",
|
|
70
|
+
detached: true,
|
|
71
|
+
});
|
|
72
|
+
child.on("error", () => {});
|
|
73
|
+
child.unref();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else if (action === "grant") {
|
|
78
|
+
const listed = await call("tools", { id });
|
|
79
|
+
if (!listed.ok) throw new Error(listed.error);
|
|
80
|
+
const agent = option("--agent"),
|
|
81
|
+
tool = option("--tool"),
|
|
82
|
+
effect = option("--effect");
|
|
83
|
+
if (!agent || !tool || !effect)
|
|
84
|
+
throw new Error(
|
|
85
|
+
"grant needs --agent, --tool and --effect read|write|send|delete"
|
|
86
|
+
);
|
|
87
|
+
const constraints = option("--arguments-file");
|
|
88
|
+
const grant = {
|
|
89
|
+
agent,
|
|
90
|
+
tool,
|
|
91
|
+
effect,
|
|
92
|
+
standing: argv.includes("--standing"),
|
|
93
|
+
hosted: argv.includes("--hosted"),
|
|
94
|
+
task: option("--task"),
|
|
95
|
+
arguments: constraints
|
|
96
|
+
? JSON.parse(fs.readFileSync(constraints, "utf8"))
|
|
97
|
+
: {},
|
|
98
|
+
};
|
|
99
|
+
const others = listed.connection.grants.filter(
|
|
100
|
+
(entry) => entry.agent !== agent || entry.tool !== tool
|
|
101
|
+
);
|
|
102
|
+
result = await call("grant", {
|
|
103
|
+
id,
|
|
104
|
+
revision: listed.connection.revision,
|
|
105
|
+
grants: [...others, grant],
|
|
106
|
+
});
|
|
107
|
+
} else if (["approve", "deny"].includes(action))
|
|
108
|
+
result = await call("decide", { id, approve: action === "approve" });
|
|
109
|
+
else if (
|
|
110
|
+
["list", "tools", "result", "operations", "revoke", "refresh"].includes(
|
|
111
|
+
action
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
result = await call(action, { id });
|
|
115
|
+
else
|
|
116
|
+
throw new Error(
|
|
117
|
+
"connections: catalog | add <provider> [--url URL] [--token-env NAME] | list | tools <id> | grant <id> --agent NAME --tool NAME --effect read|write|send|delete | operations | approve|deny <operation> | result <operation> | revoke|refresh <id>"
|
|
118
|
+
);
|
|
119
|
+
if (!result.ok) throw new Error(result.error);
|
|
120
|
+
console.log(JSON.stringify(result, null, 2));
|
|
121
|
+
}
|