@nanocollective/roster 0.1.0-beta.2 → 0.1.0-beta.21
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 +8 -0
- package/dist/agents-POITEZRI.js +232 -0
- package/dist/chunk-FF2WBNNW.js +370 -0
- package/dist/chunk-GDAJPOHK.js +562 -0
- package/dist/cli.js +3187 -1105
- package/dist/compose-5DBEHSEV.js +17 -0
- package/dist/connectors-5E5ZMGZV.js +23 -0
- package/dist/worker/assets/assets/css/base.css +21 -2
- package/dist/worker/assets/assets/css/brain.css +20 -0
- package/dist/worker/assets/assets/css/connectors.css +50 -0
- package/dist/worker/assets/assets/css/home.css +141 -54
- package/dist/worker/assets/assets/css/inbox.css +11 -0
- package/dist/worker/assets/assets/css/layout.css +6 -0
- package/dist/worker/assets/assets/css/markdown.css +21 -0
- package/dist/worker/assets/assets/css/routines.css +40 -0
- package/dist/worker/assets/assets/js/api.js +33 -0
- package/dist/worker/assets/assets/js/app.js +47 -3
- package/dist/worker/assets/assets/js/homesort.js +28 -21
- package/dist/worker/assets/assets/js/icons.js +4 -0
- package/dist/worker/assets/assets/js/md.js +7 -2
- package/dist/worker/assets/assets/js/refcard.js +216 -0
- package/dist/worker/assets/assets/js/refresh.js +4 -2
- package/dist/worker/assets/assets/js/report.js +51 -0
- package/dist/worker/assets/assets/js/state.js +14 -1
- package/dist/worker/assets/assets/js/views/connectors.js +290 -0
- package/dist/worker/assets/assets/js/views/home.js +368 -152
- package/dist/worker/assets/assets/js/views/inbox.js +68 -16
- package/dist/worker/assets/assets/js/views/org.js +2 -0
- package/dist/worker/assets/assets/js/views/people.js +103 -0
- package/dist/worker/assets/assets/js/views/routines.js +378 -0
- package/dist/worker/assets/index.html +8 -0
- package/dist/worker/index.js +3972 -963
- package/docs/README.md +2 -0
- package/docs/architecture.md +23 -4
- package/docs/commands.md +111 -9
- package/docs/concepts.md +2 -1
- package/docs/connectors.md +157 -0
- package/docs/cost.md +1 -1
- package/docs/developing.md +3 -3
- package/docs/doctor-codes.md +8 -2
- package/docs/export.md +4 -3
- package/docs/extending.md +1 -1
- package/docs/getting-started.md +19 -2
- package/docs/hosting.md +42 -3
- package/docs/memory.md +3 -2
- package/docs/org-yaml.md +58 -5
- package/docs/portal.md +37 -6
- package/docs/prompts.md +3 -2
- package/docs/routines.md +65 -0
- package/docs/security.md +35 -4
- package/docs/session-workflow.md +31 -8
- package/docs/staff-yaml.md +7 -3
- package/docs/troubleshooting.md +1 -1
- package/docs/upgrading.md +1 -1
- package/docs/writing-a-charter.md +1 -1
- package/package.json +2 -1
- package/templates/brain/.gitattributes +3 -0
- package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +24 -15
- package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +12 -10
- package/templates/brain/CHARTER.md +2 -2
- package/templates/brain/STATE.md +16 -0
- package/templates/brain/memory/INDEX.md +1 -1
- package/templates/brain/staff.yaml +3 -0
- package/templates/ops/.gitattributes +3 -0
- package/templates/ops/.github/workflows/session.yaml +74 -13
- package/templates/ops/agents.mjs +38 -11
- package/templates/ops/compose.mjs +60 -2
- package/templates/ops/connectors.mjs +722 -0
- package/templates/ops/org/operating.md +10 -0
- package/templates/ops/org/voice.md +21 -3
- package/templates/ops/prompts/_identity.md +20 -0
- package/templates/ops/prompts/daily.md +70 -19
- package/templates/ops/prompts/mention.md +7 -2
- package/templates/ops/status-week.mjs +169 -0
- package/templates/portal/css/base.css +21 -2
- package/templates/portal/css/brain.css +20 -0
- package/templates/portal/css/connectors.css +50 -0
- package/templates/portal/css/home.css +141 -54
- package/templates/portal/css/inbox.css +11 -0
- package/templates/portal/css/layout.css +6 -0
- package/templates/portal/css/markdown.css +21 -0
- package/templates/portal/css/routines.css +40 -0
- package/templates/portal/index.html +8 -0
- package/templates/portal/js/api.js +33 -0
- package/templates/portal/js/app.js +47 -3
- package/templates/portal/js/homesort.js +28 -21
- package/templates/portal/js/icons.js +4 -0
- package/templates/portal/js/md.js +7 -2
- package/templates/portal/js/refcard.js +216 -0
- package/templates/portal/js/refresh.js +4 -2
- package/templates/portal/js/report.js +51 -0
- package/templates/portal/js/state.js +14 -1
- package/templates/portal/js/views/connectors.js +290 -0
- package/templates/portal/js/views/home.js +368 -152
- package/templates/portal/js/views/inbox.js +68 -16
- package/templates/portal/js/views/org.js +2 -0
- package/templates/portal/js/views/people.js +103 -0
- package/templates/portal/js/views/routines.js +378 -0
- package/templates/skill/SKILL.md +115 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
// templates/ops/connectors.mjs
|
|
2
|
+
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { join, resolve } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
var bearer = (token) => ({ Authorization: `Bearer ${token}` });
|
|
6
|
+
var key = (label, extra = {}) => ({ id: "token", label, secret: true, ...extra });
|
|
7
|
+
var CATALOGUE = {
|
|
8
|
+
sentry: {
|
|
9
|
+
name: "Sentry",
|
|
10
|
+
summary: "Read errors, issues and releases.",
|
|
11
|
+
suggest: ["cto"],
|
|
12
|
+
link: "https://sentry.io/settings/account/api/auth-tokens/",
|
|
13
|
+
steps: [
|
|
14
|
+
"Open Sentry, then Settings, then Personal Tokens.",
|
|
15
|
+
"Create a token with read access to your organisation and projects.",
|
|
16
|
+
"Copy it and paste it here."
|
|
17
|
+
],
|
|
18
|
+
fields: [key("Auth token")],
|
|
19
|
+
// Sentry-Bearer, not Bearer: Sentry keeps plain Bearer for its own sign-in.
|
|
20
|
+
server: (v) => ({
|
|
21
|
+
transport: "http",
|
|
22
|
+
url: "https://mcp.sentry.dev/mcp",
|
|
23
|
+
headers: { Authorization: `Sentry-Bearer ${v.token}` }
|
|
24
|
+
}),
|
|
25
|
+
check: (v) => ({ url: "https://sentry.io/api/0/organizations/", headers: bearer(v.token) })
|
|
26
|
+
},
|
|
27
|
+
linear: {
|
|
28
|
+
name: "Linear",
|
|
29
|
+
summary: "Read and update issues, projects and cycles.",
|
|
30
|
+
suggest: ["cto", "cpo"],
|
|
31
|
+
link: "https://linear.app/settings/account/security",
|
|
32
|
+
steps: [
|
|
33
|
+
"Open Linear, then Settings, then Security & access.",
|
|
34
|
+
"Under Personal API keys, create a key.",
|
|
35
|
+
"Copy it and paste it here."
|
|
36
|
+
],
|
|
37
|
+
fields: [key("API key", { pattern: "^lin_api_" })],
|
|
38
|
+
server: (v) => ({ transport: "http", url: "https://mcp.linear.app/mcp", headers: bearer(v.token) }),
|
|
39
|
+
// The GraphQL API takes the key bare, unlike the MCP server.
|
|
40
|
+
check: (v) => ({
|
|
41
|
+
url: "https://api.linear.app/graphql",
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { Authorization: v.token, "Content-Type": "application/json" },
|
|
44
|
+
body: JSON.stringify({ query: "{ viewer { id } }" })
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
github: {
|
|
48
|
+
name: "GitHub",
|
|
49
|
+
summary: "Read and act on repos outside this org.",
|
|
50
|
+
suggest: [],
|
|
51
|
+
link: "https://github.com/settings/personal-access-tokens",
|
|
52
|
+
steps: [
|
|
53
|
+
"Open GitHub, then Settings, then Developer settings, then Fine-grained tokens.",
|
|
54
|
+
"Create a token for the repos the staff should reach.",
|
|
55
|
+
"Copy it and paste it here."
|
|
56
|
+
],
|
|
57
|
+
fields: [key("Personal access token", { pattern: "^(github_pat_|ghp_)" })],
|
|
58
|
+
server: (v, o) => ({
|
|
59
|
+
transport: "http",
|
|
60
|
+
url: "https://api.githubcopilot.com/mcp/",
|
|
61
|
+
headers: { ...bearer(v.token), ...o.readOnly ? { "X-MCP-Readonly": "true" } : {} }
|
|
62
|
+
}),
|
|
63
|
+
readOnly: { server: true },
|
|
64
|
+
check: (v) => ({ url: "https://api.github.com/user", headers: bearer(v.token) })
|
|
65
|
+
},
|
|
66
|
+
supabase: {
|
|
67
|
+
name: "Supabase",
|
|
68
|
+
summary: "Query the database and read project settings.",
|
|
69
|
+
suggest: ["cto"],
|
|
70
|
+
link: "https://supabase.com/dashboard/account/tokens",
|
|
71
|
+
steps: [
|
|
72
|
+
"Open Supabase, then Account, then Access Tokens.",
|
|
73
|
+
"Generate a token.",
|
|
74
|
+
"Copy it and paste it here, with the project's reference ID from Project Settings."
|
|
75
|
+
],
|
|
76
|
+
fields: [
|
|
77
|
+
key("Access token", { pattern: "^sbp_" }),
|
|
78
|
+
{ id: "project_ref", label: "Project reference ID", required: false }
|
|
79
|
+
],
|
|
80
|
+
server: (v, o) => {
|
|
81
|
+
const q = new URLSearchParams();
|
|
82
|
+
if (v.project_ref) q.set("project_ref", v.project_ref);
|
|
83
|
+
if (o.readOnly) q.set("read_only", "true");
|
|
84
|
+
const qs = q.toString();
|
|
85
|
+
return {
|
|
86
|
+
transport: "http",
|
|
87
|
+
url: `https://mcp.supabase.com/mcp${qs ? `?${qs}` : ""}`,
|
|
88
|
+
headers: bearer(v.token)
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
readOnly: { server: true },
|
|
92
|
+
check: (v) => ({ url: "https://api.supabase.com/v1/projects", headers: bearer(v.token) })
|
|
93
|
+
},
|
|
94
|
+
postgres: {
|
|
95
|
+
name: "Postgres",
|
|
96
|
+
summary: "Query a Postgres database.",
|
|
97
|
+
suggest: ["cto"],
|
|
98
|
+
link: "",
|
|
99
|
+
steps: [
|
|
100
|
+
"Use a connection string for a database user with only the access the staff should have.",
|
|
101
|
+
"It looks like postgresql://user:password@host:5432/database."
|
|
102
|
+
],
|
|
103
|
+
fields: [key("Connection string", { pattern: "^postgres(ql)?://" })],
|
|
104
|
+
// No official server. postgres-mcp is the maintained one, and pipx is on GitHub's runners.
|
|
105
|
+
server: (v, o) => ({
|
|
106
|
+
transport: "stdio",
|
|
107
|
+
command: "pipx",
|
|
108
|
+
args: ["run", "postgres-mcp", `--access-mode=${o.readOnly ? "restricted" : "unrestricted"}`],
|
|
109
|
+
env: { DATABASE_URI: v.token }
|
|
110
|
+
}),
|
|
111
|
+
readOnly: { server: true }
|
|
112
|
+
},
|
|
113
|
+
cloudflare: {
|
|
114
|
+
name: "Cloudflare",
|
|
115
|
+
summary: "Read and change Workers, DNS and other account settings.",
|
|
116
|
+
suggest: ["cto"],
|
|
117
|
+
link: "https://dash.cloudflare.com/profile/api-tokens",
|
|
118
|
+
steps: [
|
|
119
|
+
"Open Cloudflare, then My Profile, then API Tokens.",
|
|
120
|
+
"Create a token with the permissions the staff should have.",
|
|
121
|
+
"Copy it and paste it here."
|
|
122
|
+
],
|
|
123
|
+
fields: [key("API token")],
|
|
124
|
+
server: (v) => ({ transport: "http", url: "https://mcp.cloudflare.com/mcp", headers: bearer(v.token) }),
|
|
125
|
+
check: (v) => ({
|
|
126
|
+
url: "https://api.cloudflare.com/client/v4/user/tokens/verify",
|
|
127
|
+
headers: bearer(v.token)
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
posthog: {
|
|
131
|
+
name: "PostHog",
|
|
132
|
+
summary: "Read analytics, insights and feature flags.",
|
|
133
|
+
suggest: ["cpo", "cmo"],
|
|
134
|
+
link: "https://app.posthog.com/settings/user-api-keys",
|
|
135
|
+
steps: [
|
|
136
|
+
"Open PostHog, then Settings, then Personal API keys.",
|
|
137
|
+
"Create a key with the MCP Server preset.",
|
|
138
|
+
"Copy it and paste it here."
|
|
139
|
+
],
|
|
140
|
+
fields: [key("Personal API key", { pattern: "^phx_" })],
|
|
141
|
+
server: (v, o) => ({
|
|
142
|
+
transport: "http",
|
|
143
|
+
url: "https://mcp.posthog.com/mcp",
|
|
144
|
+
headers: { ...bearer(v.token), ...o.readOnly ? { "x-posthog-read-only": "true" } : {} }
|
|
145
|
+
}),
|
|
146
|
+
readOnly: { server: true }
|
|
147
|
+
},
|
|
148
|
+
stripe: {
|
|
149
|
+
name: "Stripe",
|
|
150
|
+
summary: "Read payments, customers and subscriptions.",
|
|
151
|
+
suggest: ["cfo"],
|
|
152
|
+
link: "https://dashboard.stripe.com/apikeys",
|
|
153
|
+
steps: [
|
|
154
|
+
"Open Stripe, then Developers, then API keys.",
|
|
155
|
+
"Create a restricted key for agent access, with read permissions only.",
|
|
156
|
+
"Copy it and paste it here."
|
|
157
|
+
],
|
|
158
|
+
fields: [key("Restricted key", { pattern: "^rk_(live|test)_" })],
|
|
159
|
+
server: (v) => ({ transport: "http", url: "https://mcp.stripe.com", headers: bearer(v.token) }),
|
|
160
|
+
check: (v) => ({ url: "https://api.stripe.com/v1/balance", headers: bearer(v.token) })
|
|
161
|
+
},
|
|
162
|
+
resend: {
|
|
163
|
+
name: "Resend",
|
|
164
|
+
summary: "Send email and read domains and delivery.",
|
|
165
|
+
suggest: ["cmo"],
|
|
166
|
+
link: "https://resend.com/api-keys",
|
|
167
|
+
steps: ["Open Resend, then API Keys.", "Create a key.", "Copy it and paste it here."],
|
|
168
|
+
fields: [key("API key", { pattern: "^re_" })],
|
|
169
|
+
server: (v) => ({ transport: "http", url: "https://mcp.resend.com/mcp", headers: bearer(v.token) }),
|
|
170
|
+
check: (v) => ({ url: "https://api.resend.com/domains", headers: bearer(v.token) })
|
|
171
|
+
},
|
|
172
|
+
notion: {
|
|
173
|
+
name: "Notion",
|
|
174
|
+
summary: "Read and write pages and databases.",
|
|
175
|
+
suggest: ["cmo", "cpo"],
|
|
176
|
+
auth: "oauth",
|
|
177
|
+
steps: ["Sign in to Notion and choose the pages to share."],
|
|
178
|
+
fields: [],
|
|
179
|
+
oauth: { resource: "https://mcp.notion.com/mcp" },
|
|
180
|
+
server: (v) => ({ transport: "http", url: "https://mcp.notion.com/mcp", headers: bearer(v.access_token) })
|
|
181
|
+
},
|
|
182
|
+
"notion-key": {
|
|
183
|
+
name: "Notion (integration key)",
|
|
184
|
+
summary: "Read and write the pages shared with an integration.",
|
|
185
|
+
suggest: [],
|
|
186
|
+
link: "https://www.notion.so/profile/integrations",
|
|
187
|
+
steps: [
|
|
188
|
+
"Open Notion, then Settings, then Integrations, and create an internal integration.",
|
|
189
|
+
"Share the pages the staff should see with it.",
|
|
190
|
+
"Copy its secret and paste it here."
|
|
191
|
+
],
|
|
192
|
+
fields: [key("Integration secret", { pattern: "^(ntn_|secret_)" })],
|
|
193
|
+
server: (v) => ({
|
|
194
|
+
transport: "stdio",
|
|
195
|
+
command: "npx",
|
|
196
|
+
args: ["-y", "@notionhq/notion-mcp-server"],
|
|
197
|
+
env: { NOTION_TOKEN: v.token }
|
|
198
|
+
}),
|
|
199
|
+
check: (v) => ({
|
|
200
|
+
url: "https://api.notion.com/v1/users/me",
|
|
201
|
+
headers: { ...bearer(v.token), "Notion-Version": "2022-06-28" }
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var ID = /^[a-z][a-z0-9-]{0,30}$/;
|
|
206
|
+
function secretName(id, field) {
|
|
207
|
+
return `CONNECTOR_${id}_${field}`.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
|
|
208
|
+
}
|
|
209
|
+
function declared(org) {
|
|
210
|
+
const raw = org?.connectors;
|
|
211
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return [];
|
|
212
|
+
return Object.entries(raw).map(([id, entry]) => describe(id, entry ?? {}));
|
|
213
|
+
}
|
|
214
|
+
function describe(id, entry) {
|
|
215
|
+
const known = CATALOGUE[entry.catalogue ?? id] ?? null;
|
|
216
|
+
const staff = Array.isArray(entry.staff) ? entry.staff.map(String) : entry.staff ? [String(entry.staff)] : [];
|
|
217
|
+
const out = {
|
|
218
|
+
id,
|
|
219
|
+
name: known?.name ?? entry.name ?? id,
|
|
220
|
+
known: Boolean(known),
|
|
221
|
+
catalogue: known ? entry.catalogue ?? id : null,
|
|
222
|
+
staff,
|
|
223
|
+
readOnly: entry.read_only === true,
|
|
224
|
+
auth: known?.auth ?? (entry.auth === "oauth" ? "oauth" : "key"),
|
|
225
|
+
portal: entry.portal ? String(entry.portal) : null,
|
|
226
|
+
settings: {},
|
|
227
|
+
secrets: [],
|
|
228
|
+
problem: null,
|
|
229
|
+
entry
|
|
230
|
+
};
|
|
231
|
+
if (!ID.test(id)) {
|
|
232
|
+
out.problem = `"${id}" is not a usable name: lower case letters, digits and -, starting with a letter`;
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
if (known) {
|
|
236
|
+
for (const f of known.fields ?? []) {
|
|
237
|
+
if (f.secret) out.secrets.push({ field: f.id, label: f.label, name: secretName(id, f.id) });
|
|
238
|
+
else if (entry[f.id] !== void 0 && entry[f.id] !== null) out.settings[f.id] = String(entry[f.id]);
|
|
239
|
+
else if (f.required !== false) out.problem = `${out.name} needs ${f.id} in org.yaml`;
|
|
240
|
+
}
|
|
241
|
+
if (out.auth === "oauth" && !out.portal) {
|
|
242
|
+
out.problem = `${out.name} signs in through the hosted portal, and org.yaml names none (portal:)`;
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
if (!entry.url && !entry.command) {
|
|
247
|
+
out.problem = `${id} is not in the catalogue, so it needs a url or a command`;
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
for (const s of list(entry.secrets)) {
|
|
251
|
+
out.secrets.push({ field: String(s).toLowerCase(), label: String(s), name: secretName(id, String(s)) });
|
|
252
|
+
}
|
|
253
|
+
if (out.auth === "oauth" && (!entry.url || !out.portal)) {
|
|
254
|
+
out.problem = `${id} signs in through the hosted portal, so it needs a url and a portal`;
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
function list(v) {
|
|
259
|
+
if (Array.isArray(v)) return v;
|
|
260
|
+
return v === void 0 || v === null || v === "" ? [] : [v];
|
|
261
|
+
}
|
|
262
|
+
function connectorsOf(org, handle) {
|
|
263
|
+
return declared(org).filter((c) => c.staff.includes(handle));
|
|
264
|
+
}
|
|
265
|
+
function serverFor(c, values, opts = {}) {
|
|
266
|
+
const readOnly = opts.readOnly === true;
|
|
267
|
+
const known = c.catalogue ? CATALOGUE[c.catalogue] : null;
|
|
268
|
+
let spec;
|
|
269
|
+
if (known) {
|
|
270
|
+
spec = known.server({ ...c.settings, ...values }, { readOnly });
|
|
271
|
+
} else {
|
|
272
|
+
const fill = (s) => String(s).replace(/\$\{([A-Za-z0-9_]+)\}/g, (_, k) => values[k.toLowerCase()] ?? "");
|
|
273
|
+
spec = c.entry.url ? {
|
|
274
|
+
transport: "http",
|
|
275
|
+
url: String(c.entry.url),
|
|
276
|
+
headers: {
|
|
277
|
+
...Object.fromEntries(Object.entries(c.entry.headers ?? {}).map(([k, v]) => [k, fill(v)])),
|
|
278
|
+
...values.access_token ? bearer(values.access_token) : {}
|
|
279
|
+
}
|
|
280
|
+
} : {
|
|
281
|
+
transport: "stdio",
|
|
282
|
+
...splitCommand(String(c.entry.command)),
|
|
283
|
+
env: Object.fromEntries(Object.entries(c.entry.env ?? {}).map(([k, v]) => [k, fill(v)]))
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
const tools = readOnly && known?.readOnly?.tools ? known.readOnly.tools : null;
|
|
287
|
+
return { name: c.id, ...spec, tools };
|
|
288
|
+
}
|
|
289
|
+
function readOnlyMode(c, agentTakesTools) {
|
|
290
|
+
const known = c.catalogue ? CATALOGUE[c.catalogue] : null;
|
|
291
|
+
const how = known?.readOnly;
|
|
292
|
+
if (!how) return null;
|
|
293
|
+
if (how.server) return "server";
|
|
294
|
+
if (how.tools && agentTakesTools) return "tools";
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
function splitCommand(line) {
|
|
298
|
+
const parts = line.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
|
|
299
|
+
const clean = parts.map((p) => p.replace(/^(["'])(.*)\1$/, "$2"));
|
|
300
|
+
return { command: clean[0] ?? "", args: clean.slice(1) };
|
|
301
|
+
}
|
|
302
|
+
var CLAUDE = /* @__PURE__ */ new Set(["claude-code-action", "claude"]);
|
|
303
|
+
function wiringFor(agentId, servers, dir) {
|
|
304
|
+
if (!servers.length) return { files: {}, flags: "", tools: [], env: {} };
|
|
305
|
+
if (agentId === "codex") return codexWiring(servers, dir);
|
|
306
|
+
if (agentId === "nanocoder") {
|
|
307
|
+
const file2 = join(dir, "nanocoder-mcp.json");
|
|
308
|
+
const mcpServers2 = {};
|
|
309
|
+
for (const s of servers) {
|
|
310
|
+
mcpServers2[s.name] = s.transport === "http" ? { transport: "http", url: s.url, headers: s.headers ?? {} } : { transport: "stdio", command: s.command, args: s.args ?? [], env: s.env ?? {} };
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
files: { [file2]: JSON.stringify({ mcpServers: mcpServers2 }, null, 2) },
|
|
314
|
+
flags: "",
|
|
315
|
+
tools: [],
|
|
316
|
+
env: { NANOCODER_MCPSERVERS_FILE: file2 }
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
const file = join(dir, "mcp.json");
|
|
320
|
+
const mcpServers = {};
|
|
321
|
+
for (const s of servers) {
|
|
322
|
+
mcpServers[s.name] = s.transport === "http" ? { type: "http", url: s.url, headers: s.headers ?? {} } : { type: "stdio", command: s.command, args: s.args ?? [], env: s.env ?? {} };
|
|
323
|
+
}
|
|
324
|
+
const tools = servers.flatMap(
|
|
325
|
+
(s) => s.tools ? s.tools.map((t) => `mcp__${s.name}__${t}`) : [`mcp__${s.name}`]
|
|
326
|
+
);
|
|
327
|
+
return {
|
|
328
|
+
files: { [file]: JSON.stringify({ mcpServers }, null, 2) },
|
|
329
|
+
flags: CLAUDE.has(agentId) ? `--mcp-config ${file}` : "",
|
|
330
|
+
tools: CLAUDE.has(agentId) ? tools : [],
|
|
331
|
+
env: { ROSTER_MCP_CONFIG: file }
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function codexWiring(servers, dir) {
|
|
335
|
+
const home = join(dir, "codex");
|
|
336
|
+
const lines = [];
|
|
337
|
+
for (const s of servers) {
|
|
338
|
+
lines.push(`[mcp_servers.${tomlKey(s.name)}]`);
|
|
339
|
+
if (s.transport === "http") {
|
|
340
|
+
lines.push(`url = ${toml(s.url)}`);
|
|
341
|
+
if (Object.keys(s.headers ?? {}).length) lines.push(`http_headers = ${toml(s.headers)}`);
|
|
342
|
+
} else {
|
|
343
|
+
lines.push(`command = ${toml(s.command)}`, `args = ${toml(s.args ?? [])}`);
|
|
344
|
+
if (Object.keys(s.env ?? {}).length) lines.push(`env = ${toml(s.env)}`);
|
|
345
|
+
}
|
|
346
|
+
if (s.tools) lines.push(`enabled_tools = ${toml(s.tools)}`);
|
|
347
|
+
lines.push("");
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
files: { [join(home, "config.toml")]: lines.join("\n") },
|
|
351
|
+
flags: "",
|
|
352
|
+
tools: [],
|
|
353
|
+
env: { CODEX_HOME: home }
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function tomlKey(k) {
|
|
357
|
+
return /^[A-Za-z0-9_-]+$/.test(k) ? k : JSON.stringify(k);
|
|
358
|
+
}
|
|
359
|
+
function toml(x) {
|
|
360
|
+
if (Array.isArray(x)) return `[${x.map(toml).join(", ")}]`;
|
|
361
|
+
if (x && typeof x === "object") {
|
|
362
|
+
return `{ ${Object.entries(x).map(([k, v]) => `${tomlKey(k)} = ${toml(v)}`).join(", ")} }`;
|
|
363
|
+
}
|
|
364
|
+
return JSON.stringify(String(x));
|
|
365
|
+
}
|
|
366
|
+
async function prepare({ org, handle, permissions, agentId, secrets, dir, fetchToken }) {
|
|
367
|
+
const takesTools = CLAUDE.has(agentId);
|
|
368
|
+
const connected = [];
|
|
369
|
+
const skipped = [];
|
|
370
|
+
const servers = [];
|
|
371
|
+
for (const c of connectorsOf(org, handle)) {
|
|
372
|
+
if (c.problem) {
|
|
373
|
+
skipped.push({ id: c.id, why: c.problem });
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const readOnly = permissions === "read-only" || c.readOnly;
|
|
377
|
+
if (readOnly && !readOnlyMode(c, takesTools)) {
|
|
378
|
+
skipped.push({ id: c.id, why: `${c.name} cannot be held to reading only on ${agentId}` });
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const values = {};
|
|
382
|
+
let missing = null;
|
|
383
|
+
if (c.auth === "oauth") {
|
|
384
|
+
try {
|
|
385
|
+
values.access_token = await fetchToken(c);
|
|
386
|
+
} catch (err) {
|
|
387
|
+
missing = `could not collect its sign-in from ${c.portal}: ${err.message}`;
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
for (const s of c.secrets) {
|
|
391
|
+
const v = secrets?.[s.name];
|
|
392
|
+
if (!v) {
|
|
393
|
+
missing = `no ${s.name} secret`;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
values[s.field] = v;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (missing) {
|
|
400
|
+
skipped.push({ id: c.id, why: missing });
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
servers.push(serverFor(c, values, { readOnly }));
|
|
404
|
+
connected.push({ id: c.id, name: c.name, readOnly });
|
|
405
|
+
}
|
|
406
|
+
return { connected, skipped, wiring: wiringFor(agentId, servers, dir) };
|
|
407
|
+
}
|
|
408
|
+
async function portalToken(c, env = process.env) {
|
|
409
|
+
const ask = env.ACTIONS_ID_TOKEN_REQUEST_URL;
|
|
410
|
+
const bearer2 = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
|
411
|
+
if (!ask || !bearer2) throw new Error("this run has no id-token permission; run roster upgrade");
|
|
412
|
+
const base = c.portal.replace(/\/+$/, "");
|
|
413
|
+
const audience = new URL(base).origin;
|
|
414
|
+
const idRes = await fetch(`${ask}&audience=${encodeURIComponent(audience)}`, {
|
|
415
|
+
headers: { authorization: `Bearer ${bearer2}` }
|
|
416
|
+
});
|
|
417
|
+
if (!idRes.ok) throw new Error(`GitHub gave no id token (${idRes.status})`);
|
|
418
|
+
const { value } = await idRes.json();
|
|
419
|
+
const res = await fetch(`${base}/connectors/token`, {
|
|
420
|
+
method: "POST",
|
|
421
|
+
headers: { authorization: `Bearer ${value}`, "content-type": "application/json" },
|
|
422
|
+
body: JSON.stringify({ connector: c.id })
|
|
423
|
+
});
|
|
424
|
+
const body = await res.json().catch(() => ({}));
|
|
425
|
+
if (!res.ok || !body.access_token) throw new Error(body.error ?? `the portal answered ${res.status}`);
|
|
426
|
+
return body.access_token;
|
|
427
|
+
}
|
|
428
|
+
function withConnectors(text, entries) {
|
|
429
|
+
const lines = text.split("\n");
|
|
430
|
+
const start = lines.findIndex((l) => /^connectors:\s*(#.*)?$/.test(l));
|
|
431
|
+
let end = start;
|
|
432
|
+
if (start !== -1) {
|
|
433
|
+
end = start + 1;
|
|
434
|
+
while (end < lines.length && (lines[end] === "" || /^\s/.test(lines[end]) || /^#/.test(lines[end]))) {
|
|
435
|
+
if (/^#/.test(lines[end])) {
|
|
436
|
+
let next = end + 1;
|
|
437
|
+
while (next < lines.length && /^#/.test(lines[next])) next++;
|
|
438
|
+
if (next >= lines.length || !/^\s/.test(lines[next])) break;
|
|
439
|
+
}
|
|
440
|
+
end++;
|
|
441
|
+
}
|
|
442
|
+
while (end > start + 1 && lines[end - 1] === "") end--;
|
|
443
|
+
}
|
|
444
|
+
const block = renderBlock(entries);
|
|
445
|
+
if (start === -1) {
|
|
446
|
+
if (!block.length) return text;
|
|
447
|
+
const body = text.replace(/\n+$/, "");
|
|
448
|
+
return `${body}
|
|
449
|
+
|
|
450
|
+
${block.join("\n")}
|
|
451
|
+
`;
|
|
452
|
+
}
|
|
453
|
+
const out = [...lines.slice(0, start), ...block, ...lines.slice(end)];
|
|
454
|
+
return out.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
455
|
+
}
|
|
456
|
+
function renderBlock(entries) {
|
|
457
|
+
const ids = Object.keys(entries ?? {});
|
|
458
|
+
if (!ids.length) return [];
|
|
459
|
+
const out = ["connectors:"];
|
|
460
|
+
for (const id of ids) {
|
|
461
|
+
out.push(` ${id}:`);
|
|
462
|
+
for (const [k, v] of Object.entries(entries[id] ?? {})) {
|
|
463
|
+
if (v === void 0 || v === null || v === "") continue;
|
|
464
|
+
out.push(...renderValue(k, v, 4));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return out;
|
|
468
|
+
}
|
|
469
|
+
function renderValue(key2, v, indent) {
|
|
470
|
+
const pad = " ".repeat(indent);
|
|
471
|
+
if (Array.isArray(v)) return [`${pad}${key2}: [${v.map(scalar).join(", ")}]`];
|
|
472
|
+
if (v && typeof v === "object") {
|
|
473
|
+
const keys = Object.keys(v);
|
|
474
|
+
if (!keys.length) return [];
|
|
475
|
+
return [`${pad}${key2}:`, ...keys.flatMap((k) => renderValue(k, v[k], indent + 2))];
|
|
476
|
+
}
|
|
477
|
+
return [`${pad}${key2}: ${scalar(v)}`];
|
|
478
|
+
}
|
|
479
|
+
function scalar(v) {
|
|
480
|
+
if (typeof v === "boolean" || typeof v === "number") return String(v);
|
|
481
|
+
const s = String(v);
|
|
482
|
+
return /^[A-Za-z0-9_./@:-]+$/.test(s) && !/^(true|false|null|~|-?\d+)$/.test(s) && !s.includes(": ") ? s : JSON.stringify(s);
|
|
483
|
+
}
|
|
484
|
+
async function main(argv) {
|
|
485
|
+
const at = (flag) => {
|
|
486
|
+
const i = argv.indexOf(flag);
|
|
487
|
+
return i === -1 ? void 0 : argv[i + 1];
|
|
488
|
+
};
|
|
489
|
+
const opsDir = at("--ops") ?? "roster-ops";
|
|
490
|
+
const brainsDir = at("--brains") ?? ".";
|
|
491
|
+
const handle = at("--staff");
|
|
492
|
+
const dir = resolve(at("--out") ?? join(process.env.RUNNER_TEMP ?? ".", "roster-connectors"));
|
|
493
|
+
const { parseYaml } = await import("./compose-5DBEHSEV.js");
|
|
494
|
+
const { resolveAgent, permissionOf } = await import("./agents-POITEZRI.js");
|
|
495
|
+
const org = parseYaml(readFileSync(join(opsDir, "org.yaml"), "utf8"), "org.yaml");
|
|
496
|
+
const entry = (org.staff ?? []).find((s) => s.handle === handle);
|
|
497
|
+
if (!entry) throw new Error(`no staff member "${handle}" in org.yaml`);
|
|
498
|
+
let manifest = {};
|
|
499
|
+
try {
|
|
500
|
+
manifest = parseYaml(readFileSync(join(brainsDir, entry.dir ?? entry.handle, "staff.yaml"), "utf8"), "staff.yaml");
|
|
501
|
+
} catch {
|
|
502
|
+
}
|
|
503
|
+
const agent = resolveAgent(org, manifest);
|
|
504
|
+
let secrets = {};
|
|
505
|
+
try {
|
|
506
|
+
secrets = JSON.parse(process.env.ROSTER_SECRETS || "{}");
|
|
507
|
+
} catch {
|
|
508
|
+
process.stderr.write("::warning::the caller's secrets did not arrive as JSON\n");
|
|
509
|
+
}
|
|
510
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
511
|
+
const { connected, skipped, wiring } = await prepare({
|
|
512
|
+
org,
|
|
513
|
+
handle,
|
|
514
|
+
permissions: permissionOf(org, manifest),
|
|
515
|
+
agentId: agent.id,
|
|
516
|
+
secrets,
|
|
517
|
+
dir,
|
|
518
|
+
fetchToken: (c) => portalToken(c)
|
|
519
|
+
});
|
|
520
|
+
for (const [path, text] of Object.entries(wiring.files)) writeFileSync(path, text, { mode: 384 });
|
|
521
|
+
const manifestFile = join(dir, "wiring.json");
|
|
522
|
+
writeFileSync(manifestFile, JSON.stringify({ flags: wiring.flags, tools: wiring.tools }));
|
|
523
|
+
if (process.env.GITHUB_ENV) {
|
|
524
|
+
for (const [k, v] of Object.entries(wiring.env)) appendFileSync(process.env.GITHUB_ENV, `${k}=${v}
|
|
525
|
+
`);
|
|
526
|
+
}
|
|
527
|
+
const lines = [
|
|
528
|
+
...connected.map((c) => `- ${c.name}${c.readOnly ? " (read only)" : ""}`),
|
|
529
|
+
...skipped.map((s) => `- ${s.id}: left out, ${s.why}`)
|
|
530
|
+
];
|
|
531
|
+
if (lines.length && process.env.GITHUB_STEP_SUMMARY) {
|
|
532
|
+
appendFileSync(process.env.GITHUB_STEP_SUMMARY, `### Connectors
|
|
533
|
+
|
|
534
|
+
${lines.join("\n")}
|
|
535
|
+
`);
|
|
536
|
+
}
|
|
537
|
+
for (const s of skipped) process.stderr.write(`::warning::connector ${s.id} left out: ${s.why}
|
|
538
|
+
`);
|
|
539
|
+
process.stdout.write(`file=${manifestFile}
|
|
540
|
+
connected=${connected.map((c) => c.id).join(",")}
|
|
541
|
+
`);
|
|
542
|
+
}
|
|
543
|
+
var self = import.meta.url ? fileURLToPath(import.meta.url) : "";
|
|
544
|
+
if (process.argv[1] && self.endsWith("connectors.mjs") && resolve(process.argv[1]) === resolve(self)) {
|
|
545
|
+
main(process.argv.slice(2)).catch((err) => {
|
|
546
|
+
process.stderr.write(`::warning::connectors: ${err.message}
|
|
547
|
+
`);
|
|
548
|
+
process.exit(1);
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export {
|
|
553
|
+
CATALOGUE,
|
|
554
|
+
secretName,
|
|
555
|
+
declared,
|
|
556
|
+
connectorsOf,
|
|
557
|
+
serverFor,
|
|
558
|
+
readOnlyMode,
|
|
559
|
+
wiringFor,
|
|
560
|
+
prepare,
|
|
561
|
+
withConnectors
|
|
562
|
+
};
|