@pidgeon-ai/mcp 0.16.4 → 0.17.0
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 +17 -0
- package/dist/chunk-67QGOBKE.js +267 -0
- package/dist/chunk-67QGOBKE.js.map +1 -0
- package/dist/{chunk-RPWBMILU.js → chunk-I37JZ2RW.js} +29 -175
- package/dist/chunk-I37JZ2RW.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/clients-N7HG6WUL.js +24 -0
- package/dist/clients-N7HG6WUL.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/init-TDXCNVQ5.js +246 -0
- package/dist/init-TDXCNVQ5.js.map +1 -0
- package/package.json +4 -2
- package/server.json +2 -2
- package/dist/chunk-RPWBMILU.js.map +0 -1
package/README.md
CHANGED
|
@@ -49,6 +49,23 @@ surfaces as a model quietly getting an error you never see. Then it writes
|
|
|
49
49
|
client keeps its own somewhere else. `--force` to replace an entry that is
|
|
50
50
|
already there.
|
|
51
51
|
|
|
52
|
+
For Codex, VS Code and Gemini CLI, `--client` writes the hosted server into
|
|
53
|
+
that client's own file instead:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
npx -y @pidgeon-ai/mcp init --client codex # ~/.codex/config.toml
|
|
57
|
+
npx -y @pidgeon-ai/mcp init --client vscode # .vscode/mcp.json
|
|
58
|
+
npx -y @pidgeon-ai/mcp init --client gemini # .gemini/settings.json
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
With no `PIDGEON_API_KEY` it writes the URL alone and the client signs you in
|
|
62
|
+
(`codex mcp login pidgeon`, `/mcp auth pidgeon` in Gemini CLI, a browser
|
|
63
|
+
prompt in VS Code). With a key it checks the key first and has the client read
|
|
64
|
+
it from the variable, or ask for it once in VS Code, so it is never in the
|
|
65
|
+
file. It keeps everything already in the file, comments included, backs a
|
|
66
|
+
changed file up to `<file>.bak`, and is a no-op the second time. `--scope
|
|
67
|
+
user|project` picks the other file; `--sign-in` ignores a key that is set.
|
|
68
|
+
|
|
52
69
|
The key is referenced from the environment rather than written into the file,
|
|
53
70
|
so the config can be committed and the credential cannot:
|
|
54
71
|
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/clients.ts
|
|
4
|
+
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import { dirname, join, resolve } from "path";
|
|
6
|
+
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
7
|
+
import { parse as parseToml } from "smol-toml";
|
|
8
|
+
var CLIENTS = ["codex", "vscode", "gemini"];
|
|
9
|
+
var SERVER_NAME = "pidgeon";
|
|
10
|
+
var KEY_VARIABLE = "PIDGEON_API_KEY";
|
|
11
|
+
var VSCODE_INPUT = {
|
|
12
|
+
type: "promptString",
|
|
13
|
+
id: "pidgeon-key",
|
|
14
|
+
description: "Pidgeon API key",
|
|
15
|
+
password: true
|
|
16
|
+
};
|
|
17
|
+
var CODEX_TOOL_TIMEOUT_SEC = 300;
|
|
18
|
+
var CLIENT_NAMES = {
|
|
19
|
+
codex: "Codex",
|
|
20
|
+
vscode: "VS Code",
|
|
21
|
+
gemini: "Gemini CLI"
|
|
22
|
+
};
|
|
23
|
+
function defaultScope(client) {
|
|
24
|
+
return client === "codex" ? "user" : "project";
|
|
25
|
+
}
|
|
26
|
+
function configPath(client, scope, where) {
|
|
27
|
+
const { cwd, home, platform, env } = where;
|
|
28
|
+
if (client === "codex") {
|
|
29
|
+
if (scope === "project") return resolve(cwd, ".codex", "config.toml");
|
|
30
|
+
return join(env.CODEX_HOME || join(home, ".codex"), "config.toml");
|
|
31
|
+
}
|
|
32
|
+
if (client === "gemini") {
|
|
33
|
+
return scope === "project" ? resolve(cwd, ".gemini", "settings.json") : join(home, ".gemini", "settings.json");
|
|
34
|
+
}
|
|
35
|
+
if (scope === "project") return resolve(cwd, ".vscode", "mcp.json");
|
|
36
|
+
if (platform === "darwin")
|
|
37
|
+
return join(home, "Library", "Application Support", "Code", "User", "mcp.json");
|
|
38
|
+
if (platform === "win32") {
|
|
39
|
+
return join(env.APPDATA || join(home, "AppData", "Roaming"), "Code", "User", "mcp.json");
|
|
40
|
+
}
|
|
41
|
+
return join(env.XDG_CONFIG_HOME || join(home, ".config"), "Code", "User", "mcp.json");
|
|
42
|
+
}
|
|
43
|
+
function entry(client, mcpUrl, withKey) {
|
|
44
|
+
if (client === "codex") {
|
|
45
|
+
return withKey ? {
|
|
46
|
+
url: mcpUrl,
|
|
47
|
+
bearer_token_env_var: KEY_VARIABLE,
|
|
48
|
+
tool_timeout_sec: CODEX_TOOL_TIMEOUT_SEC
|
|
49
|
+
} : { url: mcpUrl, tool_timeout_sec: CODEX_TOOL_TIMEOUT_SEC };
|
|
50
|
+
}
|
|
51
|
+
if (client === "gemini") {
|
|
52
|
+
return withKey ? { httpUrl: mcpUrl, headers: { Authorization: `Bearer \${${KEY_VARIABLE}}` } } : { httpUrl: mcpUrl };
|
|
53
|
+
}
|
|
54
|
+
return withKey ? {
|
|
55
|
+
type: "http",
|
|
56
|
+
url: mcpUrl,
|
|
57
|
+
headers: { Authorization: `Bearer \${input:${VSCODE_INPUT.id}}` }
|
|
58
|
+
} : { type: "http", url: mcpUrl };
|
|
59
|
+
}
|
|
60
|
+
function nextSteps(client, withKey) {
|
|
61
|
+
if (withKey) {
|
|
62
|
+
if (client === "codex") {
|
|
63
|
+
return [
|
|
64
|
+
`Codex reads the key from ${KEY_VARIABLE}, so keep it in the environment Codex starts in.`
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
if (client === "gemini") {
|
|
68
|
+
return [`Gemini CLI reads the key from ${KEY_VARIABLE} when it loads its settings.`];
|
|
69
|
+
}
|
|
70
|
+
return [
|
|
71
|
+
"VS Code asks for the key the first time the server starts, and keeps it in its secret storage."
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
if (client === "codex") return ["Sign in:", " codex mcp login pidgeon"];
|
|
75
|
+
if (client === "gemini") return ["Sign in, inside Gemini CLI:", " /mcp auth pidgeon"];
|
|
76
|
+
return ["When the server first starts, VS Code sends you to Pidgeon to sign in."];
|
|
77
|
+
}
|
|
78
|
+
function edit(client, path, current, block, force) {
|
|
79
|
+
return client === "codex" ? editToml(path, current, block, force) : editJson(client, path, current, block, force);
|
|
80
|
+
}
|
|
81
|
+
function writeClientConfig(client, path, block, force) {
|
|
82
|
+
let current = null;
|
|
83
|
+
try {
|
|
84
|
+
current = readFileSync(path, "utf8");
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error.code !== "ENOENT") {
|
|
87
|
+
return { ok: false, message: `${path} could not be read, so nothing was written.` };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const result = edit(client, path, current, block, force);
|
|
91
|
+
if (!result.ok) return result;
|
|
92
|
+
if (result.text === current) return { ok: true, changed: false, backup: null, text: result.text };
|
|
93
|
+
let backup = null;
|
|
94
|
+
if (current !== null) {
|
|
95
|
+
backup = `${path}.bak`;
|
|
96
|
+
copyFileSync(path, backup);
|
|
97
|
+
}
|
|
98
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
99
|
+
writeFileSync(path, result.text);
|
|
100
|
+
return { ok: true, changed: true, backup, text: result.text };
|
|
101
|
+
}
|
|
102
|
+
function differs(path) {
|
|
103
|
+
return `${path} already has a different "${SERVER_NAME}" server, so nothing was written.
|
|
104
|
+
Run again with --force to replace it, or edit the file by hand.`;
|
|
105
|
+
}
|
|
106
|
+
function same(a, b) {
|
|
107
|
+
if (a === b) return true;
|
|
108
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
109
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
110
|
+
const keysA = Object.keys(a);
|
|
111
|
+
const keysB = Object.keys(b);
|
|
112
|
+
if (keysA.length !== keysB.length) return false;
|
|
113
|
+
return keysA.every(
|
|
114
|
+
(key) => same(a[key], b[key])
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
function editJson(client, path, current, block, force) {
|
|
118
|
+
const text = current ?? "{}";
|
|
119
|
+
const errors = [];
|
|
120
|
+
const parsed = parse(text, errors, {
|
|
121
|
+
allowTrailingComma: true,
|
|
122
|
+
disallowComments: false
|
|
123
|
+
});
|
|
124
|
+
if (errors.length > 0 || typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
125
|
+
return { ok: false, message: `${path} exists and is not valid JSON, so nothing was written.` };
|
|
126
|
+
}
|
|
127
|
+
const root = parsed;
|
|
128
|
+
const key = client === "vscode" ? "servers" : "mcpServers";
|
|
129
|
+
const servers = root[key];
|
|
130
|
+
if (servers !== void 0 && (typeof servers !== "object" || servers === null || Array.isArray(servers))) {
|
|
131
|
+
return { ok: false, message: `"${key}" in ${path} is not an object, so nothing was written.` };
|
|
132
|
+
}
|
|
133
|
+
const existing = servers?.[SERVER_NAME];
|
|
134
|
+
if (existing !== void 0 && !same(existing, block) && !force) {
|
|
135
|
+
return { ok: false, message: differs(path) };
|
|
136
|
+
}
|
|
137
|
+
const formatting = formattingOf(text);
|
|
138
|
+
let next = text;
|
|
139
|
+
if (!same(existing, block)) {
|
|
140
|
+
next = applyEdits(
|
|
141
|
+
next,
|
|
142
|
+
modify(next, [key, SERVER_NAME], block, { formattingOptions: formatting })
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (client === "vscode" && JSON.stringify(block).includes("${input:")) {
|
|
146
|
+
const inputs = root.inputs;
|
|
147
|
+
if (inputs !== void 0 && !Array.isArray(inputs)) {
|
|
148
|
+
return { ok: false, message: `"inputs" in ${path} is not a list, so nothing was written.` };
|
|
149
|
+
}
|
|
150
|
+
const at = (inputs ?? []).findIndex(
|
|
151
|
+
(input) => input?.id === VSCODE_INPUT.id
|
|
152
|
+
);
|
|
153
|
+
if (at === -1) {
|
|
154
|
+
next = applyEdits(
|
|
155
|
+
next,
|
|
156
|
+
modify(next, ["inputs", -1], VSCODE_INPUT, {
|
|
157
|
+
formattingOptions: formatting,
|
|
158
|
+
isArrayInsertion: true
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
} else if (!same(inputs[at], VSCODE_INPUT)) {
|
|
162
|
+
if (!force) return { ok: false, message: differs(path) };
|
|
163
|
+
next = applyEdits(
|
|
164
|
+
next,
|
|
165
|
+
modify(next, ["inputs", at], VSCODE_INPUT, { formattingOptions: formatting })
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (current === null) next = `${next.trimEnd()}
|
|
170
|
+
`;
|
|
171
|
+
return { ok: true, text: next };
|
|
172
|
+
}
|
|
173
|
+
function formattingOf(text) {
|
|
174
|
+
const indent = /\n([ \t]+)\S/.exec(text)?.[1];
|
|
175
|
+
if (indent?.startsWith(" ")) return { insertSpaces: false, tabSize: 1, eol: "\n" };
|
|
176
|
+
return {
|
|
177
|
+
insertSpaces: true,
|
|
178
|
+
tabSize: indent ? indent.length : 2,
|
|
179
|
+
eol: text.includes("\r\n") ? "\r\n" : "\n"
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
var OUR_TABLE = /^\s*\[\s*mcp_servers\s*\.\s*(?:pidgeon|"pidgeon"|'pidgeon')\s*(?:\.[^\]]*)?\]\s*(?:#.*)?$/;
|
|
183
|
+
var ANY_TABLE = /^\s*\[/;
|
|
184
|
+
function editToml(path, current, block, force) {
|
|
185
|
+
const text = current ?? "";
|
|
186
|
+
let before;
|
|
187
|
+
try {
|
|
188
|
+
before = parseToml(text);
|
|
189
|
+
} catch {
|
|
190
|
+
return { ok: false, message: `${path} exists and is not valid TOML, so nothing was written.` };
|
|
191
|
+
}
|
|
192
|
+
const servers = before.mcp_servers;
|
|
193
|
+
const existing = servers?.[SERVER_NAME];
|
|
194
|
+
if (existing !== void 0 && same(existing, block)) return { ok: true, text };
|
|
195
|
+
if (existing !== void 0 && !force) return { ok: false, message: differs(path) };
|
|
196
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
197
|
+
const table = [
|
|
198
|
+
`[mcp_servers.${SERVER_NAME}]`,
|
|
199
|
+
...Object.entries(block).map(([k, v]) => `${k} = ${tomlValue(v)}`)
|
|
200
|
+
];
|
|
201
|
+
let next;
|
|
202
|
+
if (existing === void 0) {
|
|
203
|
+
const body = text.replace(/\s*$/, "");
|
|
204
|
+
next = `${body}${body ? `${eol}${eol}` : ""}${table.join(eol)}${eol}`;
|
|
205
|
+
} else {
|
|
206
|
+
const lines = text.split(/\r?\n/);
|
|
207
|
+
const start = lines.findIndex((line) => OUR_TABLE.test(line));
|
|
208
|
+
if (start === -1) {
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
message: `${path} defines "${SERVER_NAME}" in a form this cannot edit safely, so nothing was written.`
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
let end = start + 1;
|
|
215
|
+
while (end < lines.length && (!ANY_TABLE.test(lines[end]) || OUR_TABLE.test(lines[end])))
|
|
216
|
+
end += 1;
|
|
217
|
+
let keep = end;
|
|
218
|
+
while (keep > start + 1 && lines[keep - 1].trim() === "") keep -= 1;
|
|
219
|
+
next = [...lines.slice(0, start), ...table, ...lines.slice(keep)].join(eol);
|
|
220
|
+
if (!next.endsWith(eol)) next = `${next}${eol}`;
|
|
221
|
+
}
|
|
222
|
+
let after;
|
|
223
|
+
try {
|
|
224
|
+
after = parseToml(next);
|
|
225
|
+
} catch {
|
|
226
|
+
return { ok: false, message: `Editing ${path} would have broken it, so nothing was written.` };
|
|
227
|
+
}
|
|
228
|
+
const expected = {
|
|
229
|
+
...before,
|
|
230
|
+
mcp_servers: { ...servers ?? {}, [SERVER_NAME]: block }
|
|
231
|
+
};
|
|
232
|
+
if (!same(after, expected)) {
|
|
233
|
+
return {
|
|
234
|
+
ok: false,
|
|
235
|
+
message: `${path} is laid out in a way this cannot edit safely, so nothing was written.`
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return { ok: true, text: next };
|
|
239
|
+
}
|
|
240
|
+
function tomlValue(value) {
|
|
241
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
242
|
+
return JSON.stringify(String(value));
|
|
243
|
+
}
|
|
244
|
+
function render(client, block) {
|
|
245
|
+
if (client === "codex") {
|
|
246
|
+
return [
|
|
247
|
+
`[mcp_servers.${SERVER_NAME}]`,
|
|
248
|
+
...Object.entries(block).map(([k, v]) => `${k} = ${tomlValue(v)}`)
|
|
249
|
+
].join("\n");
|
|
250
|
+
}
|
|
251
|
+
const withKey = JSON.stringify(block).includes("${input:");
|
|
252
|
+
const shape = client === "vscode" ? { ...withKey ? { inputs: [VSCODE_INPUT] } : {}, servers: { [SERVER_NAME]: block } } : { mcpServers: { [SERVER_NAME]: block } };
|
|
253
|
+
return JSON.stringify(shape, null, 2);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
CLIENTS,
|
|
258
|
+
CLIENT_NAMES,
|
|
259
|
+
defaultScope,
|
|
260
|
+
configPath,
|
|
261
|
+
entry,
|
|
262
|
+
nextSteps,
|
|
263
|
+
edit,
|
|
264
|
+
writeClientConfig,
|
|
265
|
+
render
|
|
266
|
+
};
|
|
267
|
+
//# sourceMappingURL=chunk-67QGOBKE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/clients.ts"],"sourcesContent":["import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\n\nimport { applyEdits, type FormattingOptions, modify, parse, type ParseError } from 'jsonc-parser';\nimport { parse as parseToml } from 'smol-toml';\n\n/**\n * `init --client codex|vscode|gemini`: the hosted server, in the file that\n * client reads.\n *\n * The bare `init` writes `.mcp.json` and says so, because a map of every\n * client's config path is a map that goes stale. These three are the\n * exception, each looked up in the client's own docs and source on 25\n * October 2026, because each has one documented file, a format of its own,\n * and a way to reach a remote server over streamable HTTP — so the right\n * entry is the hosted `/api/mcp`, not a local `npx` process:\n *\n * | Client | File (default scope) | Remote server | Key, never in the file |\n * | ------- | --------------------------------------------- | --------------------- | ------------------------------- |\n * | Codex | `~/.codex/config.toml` (`$CODEX_HOME`), user | `url` | `bearer_token_env_var` |\n * | VS Code | `.vscode/mcp.json`, workspace | `type: \"http\"`, `url` | `${input:…}`, a password prompt |\n * | Gemini | `.gemini/settings.json`, project | `httpUrl` (not `url`) | `${PIDGEON_API_KEY}` in headers |\n *\n * **With no key it writes the URL alone, and the client signs in.** All\n * three answer the server's `401` with OAuth: Codex and VS Code by CIMD or\n * DCR, Gemini CLI by DCR (it has no CIMD).\n *\n * **It edits, never rewrites.** VS Code's and Gemini's files are JSON with\n * comments, so the entry goes in through `jsonc-parser`'s edits and every\n * comment and other server stays where it was. TOML is edited as text — the\n * table appended, or replaced between its header and the next — and the\n * result is parsed again and must hold exactly the old file plus our entry,\n * or nothing is written. A file it cannot parse is never touched; a\n * `pidgeon` entry that differs is replaced only with `--force`; the same\n * entry is a no-op; and a file that changes is copied to `<file>.bak` first.\n */\n\nexport const CLIENTS = ['codex', 'vscode', 'gemini'] as const;\nexport type Client = (typeof CLIENTS)[number];\n\nexport type Scope = 'user' | 'project';\n\nconst SERVER_NAME = 'pidgeon';\n\n/** The variable the key is read from, wherever the client can read one. */\nconst KEY_VARIABLE = 'PIDGEON_API_KEY';\n\n/** VS Code's prompt for the key: asked once, kept in its secret storage. */\nconst VSCODE_INPUT = {\n type: 'promptString',\n id: 'pidgeon-key',\n description: 'Pidgeon API key',\n password: true,\n};\n\n/**\n * `await_message` holds a request open for up to 280 seconds. Codex's docs\n * give 60 as the default tool timeout and its source 300, so it is said\n * rather than left to whichever is true. VS Code sets none, and Gemini's\n * default is ten minutes.\n */\nconst CODEX_TOOL_TIMEOUT_SEC = 300;\n\nexport const CLIENT_NAMES: Record<Client, string> = {\n codex: 'Codex',\n vscode: 'VS Code',\n gemini: 'Gemini CLI',\n};\n\nexport interface Where {\n cwd: string;\n home: string;\n platform: NodeJS.Platform;\n env: Record<string, string | undefined>;\n}\n\nexport function defaultScope(client: Client): Scope {\n // Codex reads a project's file only once the project is trusted; `codex\n // mcp add` writes the user's. VS Code and Gemini default to the workspace.\n return client === 'codex' ? 'user' : 'project';\n}\n\nexport function configPath(client: Client, scope: Scope, where: Where): string {\n const { cwd, home, platform, env } = where;\n\n if (client === 'codex') {\n if (scope === 'project') return resolve(cwd, '.codex', 'config.toml');\n return join(env.CODEX_HOME || join(home, '.codex'), 'config.toml');\n }\n\n if (client === 'gemini') {\n return scope === 'project'\n ? resolve(cwd, '.gemini', 'settings.json')\n : join(home, '.gemini', 'settings.json');\n }\n\n if (scope === 'project') return resolve(cwd, '.vscode', 'mcp.json');\n\n // The default profile's folder, beside its settings.json.\n if (platform === 'darwin')\n return join(home, 'Library', 'Application Support', 'Code', 'User', 'mcp.json');\n if (platform === 'win32') {\n return join(env.APPDATA || join(home, 'AppData', 'Roaming'), 'Code', 'User', 'mcp.json');\n }\n return join(env.XDG_CONFIG_HOME || join(home, '.config'), 'Code', 'User', 'mcp.json');\n}\n\n/** The entry for this client, and for VS Code the prompt it refers to. */\nexport function entry(client: Client, mcpUrl: string, withKey: boolean): Record<string, unknown> {\n if (client === 'codex') {\n return withKey\n ? {\n url: mcpUrl,\n bearer_token_env_var: KEY_VARIABLE,\n tool_timeout_sec: CODEX_TOOL_TIMEOUT_SEC,\n }\n : { url: mcpUrl, tool_timeout_sec: CODEX_TOOL_TIMEOUT_SEC };\n }\n\n if (client === 'gemini') {\n return withKey\n ? { httpUrl: mcpUrl, headers: { Authorization: `Bearer \\${${KEY_VARIABLE}}` } }\n : { httpUrl: mcpUrl };\n }\n\n return withKey\n ? {\n type: 'http',\n url: mcpUrl,\n headers: { Authorization: `Bearer \\${input:${VSCODE_INPUT.id}}` },\n }\n : { type: 'http', url: mcpUrl };\n}\n\n/** What a person does next, once the file is written. */\nexport function nextSteps(client: Client, withKey: boolean): string[] {\n if (withKey) {\n if (client === 'codex') {\n return [\n `Codex reads the key from ${KEY_VARIABLE}, so keep it in the environment Codex starts in.`,\n ];\n }\n if (client === 'gemini') {\n return [`Gemini CLI reads the key from ${KEY_VARIABLE} when it loads its settings.`];\n }\n return [\n 'VS Code asks for the key the first time the server starts, and keeps it in its secret storage.',\n ];\n }\n\n if (client === 'codex') return ['Sign in:', ' codex mcp login pidgeon'];\n if (client === 'gemini') return ['Sign in, inside Gemini CLI:', ' /mcp auth pidgeon'];\n return ['When the server first starts, VS Code sends you to Pidgeon to sign in.'];\n}\n\nexport type WriteResult =\n | { ok: true; changed: boolean; backup: string | null; text: string }\n | { ok: false; message: string };\n\n/**\n * The file as it would be with our entry in it, without writing anything.\n * `current` is null when there is no file.\n */\nexport function edit(\n client: Client,\n path: string,\n current: string | null,\n block: Record<string, unknown>,\n force: boolean,\n): { ok: true; text: string } | { ok: false; message: string } {\n return client === 'codex'\n ? editToml(path, current, block, force)\n : editJson(client, path, current, block, force);\n}\n\n/** Write the entry into the client's file. See the module comment for the rules. */\nexport function writeClientConfig(\n client: Client,\n path: string,\n block: Record<string, unknown>,\n force: boolean,\n): WriteResult {\n let current: string | null = null;\n\n try {\n current = readFileSync(path, 'utf8');\n } catch (error) {\n if ((error as { code?: string }).code !== 'ENOENT') {\n return { ok: false, message: `${path} could not be read, so nothing was written.` };\n }\n }\n\n const result = edit(client, path, current, block, force);\n if (!result.ok) return result;\n\n if (result.text === current) return { ok: true, changed: false, backup: null, text: result.text };\n\n let backup: string | null = null;\n if (current !== null) {\n backup = `${path}.bak`;\n copyFileSync(path, backup);\n }\n\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, result.text);\n\n return { ok: true, changed: true, backup, text: result.text };\n}\n\nfunction differs(path: string): string {\n return (\n `${path} already has a different \"${SERVER_NAME}\" server, so nothing was written.\\n` +\n 'Run again with --force to replace it, or edit the file by hand.'\n );\n}\n\nfunction same(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n\n return keysA.every((key) =>\n same((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),\n );\n}\n\n/* ---------- JSON with comments: VS Code and Gemini CLI ---------- */\n\nfunction editJson(\n client: Exclude<Client, 'codex'>,\n path: string,\n current: string | null,\n block: Record<string, unknown>,\n force: boolean,\n): { ok: true; text: string } | { ok: false; message: string } {\n const text = current ?? '{}';\n\n const errors: ParseError[] = [];\n const parsed = parse(text, errors, {\n allowTrailingComma: true,\n disallowComments: false,\n }) as unknown;\n\n if (errors.length > 0 || typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n return { ok: false, message: `${path} exists and is not valid JSON, so nothing was written.` };\n }\n\n const root = parsed as Record<string, unknown>;\n const key = client === 'vscode' ? 'servers' : 'mcpServers';\n const servers = root[key];\n\n if (\n servers !== undefined &&\n (typeof servers !== 'object' || servers === null || Array.isArray(servers))\n ) {\n return { ok: false, message: `\"${key}\" in ${path} is not an object, so nothing was written.` };\n }\n\n const existing = (servers as Record<string, unknown> | undefined)?.[SERVER_NAME];\n if (existing !== undefined && !same(existing, block) && !force) {\n return { ok: false, message: differs(path) };\n }\n\n const formatting = formattingOf(text);\n let next = text;\n\n if (!same(existing, block)) {\n next = applyEdits(\n next,\n modify(next, [key, SERVER_NAME], block, { formattingOptions: formatting }),\n );\n }\n\n // The prompt a key-mode entry refers to, added once and never duplicated.\n if (client === 'vscode' && JSON.stringify(block).includes('${input:')) {\n const inputs = root.inputs;\n\n if (inputs !== undefined && !Array.isArray(inputs)) {\n return { ok: false, message: `\"inputs\" in ${path} is not a list, so nothing was written.` };\n }\n\n const at = (inputs ?? []).findIndex(\n (input) => (input as { id?: unknown } | null)?.id === VSCODE_INPUT.id,\n );\n\n if (at === -1) {\n next = applyEdits(\n next,\n modify(next, ['inputs', -1], VSCODE_INPUT, {\n formattingOptions: formatting,\n isArrayInsertion: true,\n }),\n );\n } else if (!same(inputs![at], VSCODE_INPUT)) {\n if (!force) return { ok: false, message: differs(path) };\n next = applyEdits(\n next,\n modify(next, ['inputs', at], VSCODE_INPUT, { formattingOptions: formatting }),\n );\n }\n }\n\n // A new file ends in a newline; an existing one keeps its own ending.\n if (current === null) next = `${next.trimEnd()}\\n`;\n\n return { ok: true, text: next };\n}\n\n/** Indent like the file already does, or two spaces. */\nfunction formattingOf(text: string): FormattingOptions {\n const indent = /\\n([ \\t]+)\\S/.exec(text)?.[1];\n\n if (indent?.startsWith('\\t')) return { insertSpaces: false, tabSize: 1, eol: '\\n' };\n return {\n insertSpaces: true,\n tabSize: indent ? indent.length : 2,\n eol: text.includes('\\r\\n') ? '\\r\\n' : '\\n',\n };\n}\n\n/* ---------- TOML: Codex ---------- */\n\n/** `[mcp_servers.pidgeon]`, or a table under it, however it is quoted and spaced. */\nconst OUR_TABLE =\n /^\\s*\\[\\s*mcp_servers\\s*\\.\\s*(?:pidgeon|\"pidgeon\"|'pidgeon')\\s*(?:\\.[^\\]]*)?\\]\\s*(?:#.*)?$/;\n\n/** Any table header, `[x]` or `[[x]]`. */\nconst ANY_TABLE = /^\\s*\\[/;\n\nfunction editToml(\n path: string,\n current: string | null,\n block: Record<string, unknown>,\n force: boolean,\n): { ok: true; text: string } | { ok: false; message: string } {\n const text = current ?? '';\n\n let before: Record<string, unknown>;\n try {\n before = parseToml(text) as Record<string, unknown>;\n } catch {\n return { ok: false, message: `${path} exists and is not valid TOML, so nothing was written.` };\n }\n\n const servers = before.mcp_servers as Record<string, unknown> | undefined;\n const existing = servers?.[SERVER_NAME];\n\n if (existing !== undefined && same(existing, block)) return { ok: true, text };\n if (existing !== undefined && !force) return { ok: false, message: differs(path) };\n\n const eol = text.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const table = [\n `[mcp_servers.${SERVER_NAME}]`,\n ...Object.entries(block).map(([k, v]) => `${k} = ${tomlValue(v)}`),\n ];\n\n let next: string;\n\n if (existing === undefined) {\n const body = text.replace(/\\s*$/, '');\n next = `${body}${body ? `${eol}${eol}` : ''}${table.join(eol)}${eol}`;\n } else {\n const lines = text.split(/\\r?\\n/);\n const start = lines.findIndex((line) => OUR_TABLE.test(line));\n\n // Defined some other way — dotted keys, an inline table. Not ours to rewrite.\n if (start === -1) {\n return {\n ok: false,\n message: `${path} defines \"${SERVER_NAME}\" in a form this cannot edit safely, so nothing was written.`,\n };\n }\n\n let end = start + 1;\n while (end < lines.length && (!ANY_TABLE.test(lines[end]!) || OUR_TABLE.test(lines[end]!)))\n end += 1;\n\n // Leave the blank lines before the next table where they were.\n let keep = end;\n while (keep > start + 1 && lines[keep - 1]!.trim() === '') keep -= 1;\n\n next = [...lines.slice(0, start), ...table, ...lines.slice(keep)].join(eol);\n if (!next.endsWith(eol)) next = `${next}${eol}`;\n }\n\n // The proof: the new file is the old one plus our entry, and nothing else.\n let after: Record<string, unknown>;\n try {\n after = parseToml(next) as Record<string, unknown>;\n } catch {\n return { ok: false, message: `Editing ${path} would have broken it, so nothing was written.` };\n }\n\n const expected = {\n ...before,\n mcp_servers: { ...(servers ?? {}), [SERVER_NAME]: block },\n };\n\n if (!same(after, expected)) {\n return {\n ok: false,\n message: `${path} is laid out in a way this cannot edit safely, so nothing was written.`,\n };\n }\n\n return { ok: true, text: next };\n}\n\nfunction tomlValue(value: unknown): string {\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n return JSON.stringify(String(value));\n}\n\n/** The block, as the client's file would show it, for printing. */\nexport function render(client: Client, block: Record<string, unknown>): string {\n if (client === 'codex') {\n return [\n `[mcp_servers.${SERVER_NAME}]`,\n ...Object.entries(block).map(([k, v]) => `${k} = ${tomlValue(v)}`),\n ].join('\\n');\n }\n\n const withKey = JSON.stringify(block).includes('${input:');\n const shape =\n client === 'vscode'\n ? { ...(withKey ? { inputs: [VSCODE_INPUT] } : {}), servers: { [SERVER_NAME]: block } }\n : { mcpServers: { [SERVER_NAME]: block } };\n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EA,MAAI,CAAC,KAAK,OAAO,QAAQ,GAAG;AAC1B,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,SAAS,GAAG,IAAI;AAAA,IAClB;AAAA,EACF;AAEA,SAAO,EAAE,IAAI,MAAM,MAAM,KAAK;AAChC;AAEA,SAAS,UAAU,OAAwB;AACzC,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,QAAO,OAAO,KAAK;AAChF,SAAO,KAAK,UAAU,OAAO,KAAK,CAAC;AACrC;AAGO,SAAS,OAAO,QAAgB,OAAwC;AAC7E,MAAI,WAAW,SAAS;AACtB,WAAO;AAAA,MACL,gBAAgB,WAAW;AAAA,MAC3B,GAAG,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,UAAU,CAAC,CAAC,EAAE;AAAA,IACnE,EAAE,KAAK,IAAI;AAAA,EACb;AAEA,QAAM,UAAU,KAAK,UAAU,KAAK,EAAE,SAAS,UAAU;AACzD,QAAM,QACJ,WAAW,WACP,EAAE,GAAI,UAAU,EAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,GAAI,SAAS,EAAE,CAAC,WAAW,GAAG,MAAM,EAAE,IACpF,EAAE,YAAY,EAAE,CAAC,WAAW,GAAG,MAAM,EAAE;AAE7C,SAAO,KAAK,UAAU,OAAO,MAAM,CAAC;AACtC;","names":[]}
|
|
@@ -95,176 +95,6 @@ function splitEndpoint(endpoint) {
|
|
|
95
95
|
return [endpoint.slice(0, space), endpoint.slice(space + 1)];
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
// src/init.ts
|
|
99
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
100
|
-
import { resolve } from "path";
|
|
101
|
-
var SERVER_NAME = "pidgeon";
|
|
102
|
-
var CONFIG_FILE = ".mcp.json";
|
|
103
|
-
var DEFAULT_BASE_URL = "https://pidgeon.ai/api/v1";
|
|
104
|
-
function configBlock(baseUrl) {
|
|
105
|
-
const env = { PIDGEON_API_KEY: "${PIDGEON_API_KEY}" };
|
|
106
|
-
if (baseUrl !== DEFAULT_BASE_URL) env.PIDGEON_BASE_URL = baseUrl;
|
|
107
|
-
return { command: "npx", args: ["-y", "@pidgeon-ai/mcp"], env };
|
|
108
|
-
}
|
|
109
|
-
var WHAT_IT_CAN_DO = {
|
|
110
|
-
read: "It can read mail and nothing else \u2014 a model holding it cannot reply, send or change anything.",
|
|
111
|
-
draft: "It can read and manage mail and write drafts, and can never send \u2014 a person reviews each draft and sends it.",
|
|
112
|
-
send: "It can read and send. It cannot create addresses, mint keys or grant access.",
|
|
113
|
-
admin: "It can do everything the API offers, including creating addresses and granting access."
|
|
114
|
-
};
|
|
115
|
-
async function init(options) {
|
|
116
|
-
const { apiKey, baseUrl, cwd, write, force, fetch, out } = options;
|
|
117
|
-
if (!apiKey) {
|
|
118
|
-
out("PIDGEON_API_KEY is not set.");
|
|
119
|
-
out("");
|
|
120
|
-
out("Create one at https://pidgeon.ai/app/developers/keys, then:");
|
|
121
|
-
out(" PIDGEON_API_KEY=pgn_live_\u2026 npx -y @pidgeon-ai/mcp init");
|
|
122
|
-
out("");
|
|
123
|
-
out("Give it the narrowest access the agent needs \u2014 this hands it to a model.");
|
|
124
|
-
return { ok: false, addresses: [], access: null, wrote: null };
|
|
125
|
-
}
|
|
126
|
-
const identity = await describeKey({ apiKey, baseUrl, fetch, out });
|
|
127
|
-
if (identity === null) return { ok: false, addresses: [], access: null, wrote: null };
|
|
128
|
-
const { addresses, access, reachesAll, expiresAt } = identity;
|
|
129
|
-
if (addresses.length === 0) {
|
|
130
|
-
out("That key works, and reaches no address yet.");
|
|
131
|
-
out("");
|
|
132
|
-
out("Grant it one at https://pidgeon.ai/app/developers/keys \u2014 a key\u2019s reach is");
|
|
133
|
-
out("a snapshot, so an address created after the key is not in it.");
|
|
134
|
-
} else {
|
|
135
|
-
const shown = addresses.slice(0, 5);
|
|
136
|
-
const reach = reachesAll ? `That key reaches every address this workspace owns (${addresses.length} today):` : `That key reaches ${addresses.length} address${addresses.length === 1 ? "" : "es"}:`;
|
|
137
|
-
out(reach);
|
|
138
|
-
for (const address of shown) out(` ${address}`);
|
|
139
|
-
if (addresses.length > shown.length) out(` \u2026 and ${addresses.length - shown.length} more`);
|
|
140
|
-
if (reachesAll) {
|
|
141
|
-
out("");
|
|
142
|
-
out("An address created after this key will be in reach too, unlike a key");
|
|
143
|
-
out("granted a fixed list.");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (access) {
|
|
147
|
-
out("");
|
|
148
|
-
out(`Access: ${access}. ${WHAT_IT_CAN_DO[access]}`);
|
|
149
|
-
}
|
|
150
|
-
if (expiresAt) {
|
|
151
|
-
const when = new Date(expiresAt);
|
|
152
|
-
const stale = Number.isNaN(when.getTime());
|
|
153
|
-
out("");
|
|
154
|
-
out(
|
|
155
|
-
stale ? `This key expires: ${expiresAt}.` : `This key stops working on ${when.toUTCString()}.`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
const block = configBlock(baseUrl);
|
|
159
|
-
const path = resolve(cwd, CONFIG_FILE);
|
|
160
|
-
let wrote = null;
|
|
161
|
-
if (write) {
|
|
162
|
-
const result = merge(path, block, force);
|
|
163
|
-
if (!result.ok) {
|
|
164
|
-
out("");
|
|
165
|
-
out(result.message);
|
|
166
|
-
return { ok: false, addresses, access, wrote: null };
|
|
167
|
-
}
|
|
168
|
-
wrote = path;
|
|
169
|
-
}
|
|
170
|
-
out("");
|
|
171
|
-
out(wrote ? `Wrote ${CONFIG_FILE}:` : `Add this to your MCP client\u2019s config:`);
|
|
172
|
-
out("");
|
|
173
|
-
out(JSON.stringify({ mcpServers: { [SERVER_NAME]: block } }, null, 2));
|
|
174
|
-
out("");
|
|
175
|
-
out("The key is read from the environment rather than written into the file,");
|
|
176
|
-
out("so the config can be committed and the credential cannot.");
|
|
177
|
-
return { ok: true, addresses, access, wrote };
|
|
178
|
-
}
|
|
179
|
-
async function describeKey(context) {
|
|
180
|
-
const [addresses, me] = await Promise.all([
|
|
181
|
-
reachableAddresses(context),
|
|
182
|
-
describeCredential(context)
|
|
183
|
-
]);
|
|
184
|
-
if (addresses === null) return null;
|
|
185
|
-
return {
|
|
186
|
-
addresses,
|
|
187
|
-
access: me?.key?.access ?? null,
|
|
188
|
-
reachesAll: me?.key?.reaches_all_addresses ?? false,
|
|
189
|
-
expiresAt: me?.key?.expires_at ?? null
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
async function describeCredential(context) {
|
|
193
|
-
const { apiKey, baseUrl, fetch } = context;
|
|
194
|
-
try {
|
|
195
|
-
const response = await fetch(`${baseUrl}/me`, {
|
|
196
|
-
headers: { authorization: `Bearer ${apiKey}`, accept: "application/json" }
|
|
197
|
-
});
|
|
198
|
-
if (!response.ok) return null;
|
|
199
|
-
const body = await response.json();
|
|
200
|
-
const key = body.data?.key;
|
|
201
|
-
if (!key?.access) return null;
|
|
202
|
-
if (key.access !== "read" && key.access !== "draft" && key.access !== "send" && key.access !== "admin") {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
key: {
|
|
207
|
-
access: key.access,
|
|
208
|
-
reaches_all_addresses: key.reaches_all_addresses ?? false,
|
|
209
|
-
expires_at: key.expires_at ?? null
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
} catch {
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async function reachableAddresses(context) {
|
|
217
|
-
const { apiKey, baseUrl, fetch, out } = context;
|
|
218
|
-
let response;
|
|
219
|
-
try {
|
|
220
|
-
response = await fetch(`${baseUrl}/identities`, {
|
|
221
|
-
headers: { authorization: `Bearer ${apiKey}`, accept: "application/json" }
|
|
222
|
-
});
|
|
223
|
-
} catch (error) {
|
|
224
|
-
out(`Could not reach ${baseUrl}: ${error instanceof Error ? error.message : String(error)}`);
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
if (response.status === 401 || response.status === 403) {
|
|
228
|
-
out("That key was refused. It may be revoked, or from another deployment.");
|
|
229
|
-
out("Keys live at https://pidgeon.ai/app/developers/keys.");
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
if (!response.ok) {
|
|
233
|
-
out(`The API answered ${response.status}. Nothing was written.`);
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
const body = await response.json();
|
|
237
|
-
return (body.data ?? []).map((identity) => identity.email ?? "").filter(Boolean);
|
|
238
|
-
}
|
|
239
|
-
function merge(path, block, force) {
|
|
240
|
-
let existing = {};
|
|
241
|
-
try {
|
|
242
|
-
existing = JSON.parse(readFileSync(path, "utf8"));
|
|
243
|
-
} catch (error) {
|
|
244
|
-
if (error.code !== "ENOENT") {
|
|
245
|
-
return {
|
|
246
|
-
ok: false,
|
|
247
|
-
message: `${path} exists and is not valid JSON, so nothing was written.`
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const servers = existing.mcpServers ?? {};
|
|
252
|
-
const current = servers[SERVER_NAME];
|
|
253
|
-
if (current && !force && JSON.stringify(current) !== JSON.stringify(block)) {
|
|
254
|
-
return {
|
|
255
|
-
ok: false,
|
|
256
|
-
message: `${path} already has a different "${SERVER_NAME}" server, so nothing was written.
|
|
257
|
-
Run again with --force to replace it, or edit the file by hand.`
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
writeFileSync(
|
|
261
|
-
path,
|
|
262
|
-
`${JSON.stringify({ ...existing, mcpServers: { ...servers, [SERVER_NAME]: block } }, null, 2)}
|
|
263
|
-
`
|
|
264
|
-
);
|
|
265
|
-
return { ok: true };
|
|
266
|
-
}
|
|
267
|
-
|
|
268
98
|
// src/tools.ts
|
|
269
99
|
import { z } from "zod";
|
|
270
100
|
var READ = {
|
|
@@ -876,8 +706,8 @@ var TOOLS = [
|
|
|
876
706
|
];
|
|
877
707
|
|
|
878
708
|
// src/index.ts
|
|
879
|
-
var
|
|
880
|
-
var VERSION = "0.
|
|
709
|
+
var DEFAULT_BASE_URL = "https://pidgeon.ai/api/v1";
|
|
710
|
+
var VERSION = "0.17.0";
|
|
881
711
|
function createServer(context) {
|
|
882
712
|
const server = new McpServer({ name: "pidgeon", version: VERSION });
|
|
883
713
|
const calling = {
|
|
@@ -921,8 +751,29 @@ function createServer(context) {
|
|
|
921
751
|
}
|
|
922
752
|
async function main() {
|
|
923
753
|
const apiKey = process.env.PIDGEON_API_KEY;
|
|
924
|
-
const baseUrl = process.env.PIDGEON_BASE_URL ??
|
|
754
|
+
const baseUrl = process.env.PIDGEON_BASE_URL ?? DEFAULT_BASE_URL;
|
|
925
755
|
if (process.argv[2] === "init") {
|
|
756
|
+
const { init } = await import("./init-TDXCNVQ5.js");
|
|
757
|
+
const { CLIENTS } = await import("./clients-N7HG6WUL.js");
|
|
758
|
+
const flag = (name) => {
|
|
759
|
+
const at = process.argv.findIndex((arg2) => arg2 === name || arg2.startsWith(`${name}=`));
|
|
760
|
+
if (at === -1) return void 0;
|
|
761
|
+
const arg = process.argv[at];
|
|
762
|
+
return arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : process.argv[at + 1];
|
|
763
|
+
};
|
|
764
|
+
const client = flag("--client");
|
|
765
|
+
const scope = flag("--scope");
|
|
766
|
+
if (client !== void 0 && !CLIENTS.includes(client)) {
|
|
767
|
+
process.stdout.write(
|
|
768
|
+
`--client takes ${CLIENTS.join(", ")}. Any other client: run init without it and move .mcp.json.
|
|
769
|
+
`
|
|
770
|
+
);
|
|
771
|
+
process.exit(1);
|
|
772
|
+
}
|
|
773
|
+
if (scope !== void 0 && scope !== "user" && scope !== "project") {
|
|
774
|
+
process.stdout.write("--scope takes user or project.\n");
|
|
775
|
+
process.exit(1);
|
|
776
|
+
}
|
|
926
777
|
const result = await init({
|
|
927
778
|
apiKey,
|
|
928
779
|
baseUrl,
|
|
@@ -931,7 +782,10 @@ async function main() {
|
|
|
931
782
|
force: process.argv.includes("--force"),
|
|
932
783
|
fetch: globalThis.fetch,
|
|
933
784
|
out: (line) => process.stdout.write(`${line}
|
|
934
|
-
`)
|
|
785
|
+
`),
|
|
786
|
+
client,
|
|
787
|
+
scope,
|
|
788
|
+
signIn: process.argv.includes("--sign-in")
|
|
935
789
|
});
|
|
936
790
|
process.exit(result.ok ? 0 : 1);
|
|
937
791
|
}
|
|
@@ -951,4 +805,4 @@ export {
|
|
|
951
805
|
createServer,
|
|
952
806
|
main
|
|
953
807
|
};
|
|
954
|
-
//# sourceMappingURL=chunk-
|
|
808
|
+
//# sourceMappingURL=chunk-I37JZ2RW.js.map
|