@zero-gravity/zero-gravity 0.0.0-stage → 0.1.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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/THIRD-PARTY-NOTICES.md +100 -0
- package/dist/adv-context-SLTP32JQ.js +36 -0
- package/dist/advanced-EPLZB6DG.js +164 -0
- package/dist/agents-JYRQHH7R.js +181 -0
- package/dist/chat-AEHVCKXX.js +47 -0
- package/dist/chunk-2OH5KHWO.js +112 -0
- package/dist/chunk-2ZYSAYMJ.js +108 -0
- package/dist/chunk-4BZ4IXTO.js +161 -0
- package/dist/chunk-4ITJY25Z.js +144 -0
- package/dist/chunk-4JBLZQAQ.js +65 -0
- package/dist/chunk-6QLYRU3N.js +28 -0
- package/dist/chunk-7TACFVY2.js +57 -0
- package/dist/chunk-AY36KJTH.js +3023 -0
- package/dist/chunk-BJABQO7S.js +378 -0
- package/dist/chunk-C2GFK4JP.js +387 -0
- package/dist/chunk-CDC2K2KP.js +47 -0
- package/dist/chunk-DKCCXMSE.js +27 -0
- package/dist/chunk-FC3UOHOO.js +194 -0
- package/dist/chunk-FIASMDLX.js +216 -0
- package/dist/chunk-GMVDCQVW.js +88 -0
- package/dist/chunk-JQYZX56A.js +231 -0
- package/dist/chunk-JU5PGDOD.js +138 -0
- package/dist/chunk-JUZP5SXD.js +309 -0
- package/dist/chunk-KGA7VWQG.js +70 -0
- package/dist/chunk-L7VNR5LM.js +407 -0
- package/dist/chunk-LOSXCWHU.js +145 -0
- package/dist/chunk-NVC433AX.js +24 -0
- package/dist/chunk-QH27MDJM.js +248 -0
- package/dist/chunk-QUC5URWQ.js +708 -0
- package/dist/chunk-R2CPYTSP.js +31 -0
- package/dist/chunk-R5KQACGR.js +2833 -0
- package/dist/chunk-R6DONQKN.js +153 -0
- package/dist/chunk-RIX4S3J7.js +4747 -0
- package/dist/chunk-SZKAZ2VN.js +35 -0
- package/dist/chunk-T6DDNE3W.js +1338 -0
- package/dist/chunk-U4URD6TU.js +4605 -0
- package/dist/chunk-U5UIUB6L.js +51 -0
- package/dist/chunk-UMC77TR3.js +79 -0
- package/dist/chunk-UQURXFAE.js +80 -0
- package/dist/chunk-VBG7T7XY.js +1703 -0
- package/dist/chunk-VCCMJIAG.js +326 -0
- package/dist/chunk-VS375NYD.js +91 -0
- package/dist/chunk-WANZOLI5.js +1073 -0
- package/dist/chunk-WUF3TVAE.js +51 -0
- package/dist/chunk-XCWLFZSM.js +149 -0
- package/dist/chunk-YJEUXO5I.js +76 -0
- package/dist/chunk-YR6RCC6Y.js +894 -0
- package/dist/chunk-ZQFAX275.js +35 -0
- package/dist/config-ELG4FQ3K.js +30 -0
- package/dist/config-IEWRCG7R.js +50 -0
- package/dist/doctor-ZZC2D3RW.js +357 -0
- package/dist/ext-context-RIMZMEPB.js +37 -0
- package/dist/index.js +20 -0
- package/dist/init-UB3E47KM.js +22 -0
- package/dist/integrations-HW4VTLN4.js +183 -0
- package/dist/main-RAWWT22W.js +115 -0
- package/dist/mcp-SWD4SO35.js +232 -0
- package/dist/mcp-context-PM5FY665.js +28 -0
- package/dist/memory-QQ54GRCN.js +128 -0
- package/dist/memory-session-R6DGT6CS.js +14 -0
- package/dist/memory-summary-4P26B2ZY.js +18 -0
- package/dist/plugins-VUGTEUNV.js +166 -0
- package/dist/providers-O3WOVP5Q.js +417 -0
- package/dist/report-DDIZ6BLF.js +28 -0
- package/dist/sec-context-VQHW6TOZ.js +15 -0
- package/dist/security-SAYW4LU4.js +95 -0
- package/dist/sessions-CL6CRNQL.js +160 -0
- package/dist/skills-7KDGTTKX.js +126 -0
- package/dist/version-6E6A23B3.js +13 -0
- package/package.json +70 -4
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
entryDetail,
|
|
4
|
+
entryRow,
|
|
5
|
+
statusDetail,
|
|
6
|
+
statusLine,
|
|
7
|
+
toolLine
|
|
8
|
+
} from "./chunk-7TACFVY2.js";
|
|
9
|
+
import {
|
|
10
|
+
lineOrAbort,
|
|
11
|
+
mcpGuard,
|
|
12
|
+
openMcpEnv,
|
|
13
|
+
requireMcpOn
|
|
14
|
+
} from "./chunk-UQURXFAE.js";
|
|
15
|
+
import "./chunk-T6DDNE3W.js";
|
|
16
|
+
import {
|
|
17
|
+
CATEGORIES
|
|
18
|
+
} from "./chunk-2OH5KHWO.js";
|
|
19
|
+
import "./chunk-YJEUXO5I.js";
|
|
20
|
+
import "./chunk-2ZYSAYMJ.js";
|
|
21
|
+
import {
|
|
22
|
+
confirm,
|
|
23
|
+
promptLine
|
|
24
|
+
} from "./chunk-YR6RCC6Y.js";
|
|
25
|
+
import "./chunk-SZKAZ2VN.js";
|
|
26
|
+
import "./chunk-DKCCXMSE.js";
|
|
27
|
+
import "./chunk-U5UIUB6L.js";
|
|
28
|
+
import "./chunk-XCWLFZSM.js";
|
|
29
|
+
import "./chunk-GMVDCQVW.js";
|
|
30
|
+
import "./chunk-JQYZX56A.js";
|
|
31
|
+
import "./chunk-R6DONQKN.js";
|
|
32
|
+
import "./chunk-QH27MDJM.js";
|
|
33
|
+
import "./chunk-ZQFAX275.js";
|
|
34
|
+
import {
|
|
35
|
+
ZgError
|
|
36
|
+
} from "./chunk-FC3UOHOO.js";
|
|
37
|
+
import {
|
|
38
|
+
redactSecrets
|
|
39
|
+
} from "./chunk-WUF3TVAE.js";
|
|
40
|
+
|
|
41
|
+
// src/cli/commands/integrations.ts
|
|
42
|
+
import path from "path";
|
|
43
|
+
var MARK = { pass: "[ok] ", warn: "[warn]", fail: "[fail]", info: "[info]" };
|
|
44
|
+
function registerIntegrations(program, ctx) {
|
|
45
|
+
const say = (t) => ctx.stdout(redactSecrets(t));
|
|
46
|
+
const cmd = program.command("integrations").description("Connect GitHub, Supabase, Firebase and other services through their MCP servers (catalog with verification status)");
|
|
47
|
+
const rows = async (filter = () => true) => {
|
|
48
|
+
const env = await openMcpEnv(ctx);
|
|
49
|
+
const all = env.svc.catalog.all().filter(filter);
|
|
50
|
+
if (all.length === 0) return say("Nothing matches.");
|
|
51
|
+
say(`${"id".padEnd(13)} ${"name".padEnd(12)} ${"category".padEnd(19)} ${"publisher".padEnd(11)} ${"status".padEnd(18)} connection`);
|
|
52
|
+
for (const e of all) say(entryRow(e, env.svc.catalog.connectedAs(env.svc.settings, e.id)));
|
|
53
|
+
say("\nstatus: verified = docs read and usable by zg; restricted = the service may refuse zg; details-unverified / community-only = zg ships no config (see inspect).");
|
|
54
|
+
};
|
|
55
|
+
cmd.action(() => rows());
|
|
56
|
+
cmd.command("list").alias("browse").description("Browse the catalog").action(() => rows());
|
|
57
|
+
cmd.command("search <words...>").description("Search the catalog by name, category or description").option("--category <name>", `one of ${CATEGORIES.join(", ")}`).action(async (words, o) => {
|
|
58
|
+
const env = await openMcpEnv(ctx);
|
|
59
|
+
if (o.category && !CATEGORIES.includes(o.category)) throw new ZgError(`unknown category "${o.category.slice(0, 30)}"`, { hint: `Categories: ${CATEGORIES.join(", ")}` });
|
|
60
|
+
const hits = env.svc.catalog.search(words.join(" "), o.category);
|
|
61
|
+
if (hits.length === 0) return say(`Nothing in the catalog matches "${words.join(" ")}".`);
|
|
62
|
+
for (const e of hits) say(entryRow(e, env.svc.catalog.connectedAs(env.svc.settings, e.id)));
|
|
63
|
+
});
|
|
64
|
+
cmd.command("categories").description("List categories").action(async () => {
|
|
65
|
+
const env = await openMcpEnv(ctx);
|
|
66
|
+
for (const c of env.svc.catalog.categories()) say(`${c.category.padEnd(20)} ${c.count}`);
|
|
67
|
+
});
|
|
68
|
+
cmd.command("inspect <id>").description("Everything known about an entry, including what was NOT verified").action(async (id) => {
|
|
69
|
+
const env = await openMcpEnv(ctx);
|
|
70
|
+
say((await mcpGuard(async () => entryDetail(env.svc.catalog.get(id)))).join("\n"));
|
|
71
|
+
});
|
|
72
|
+
cmd.command("connect <id>").description("Guided connection: shows what it accesses, asks for approval, signs in, connects, discovers tools").option("--name <name>", "name for this connection").option("--project-ref <id>", "(Supabase) limit to one project").option("--this-project", "use this connection only in the current project").option("--read-only", "afterwards deny every tool that is not read-only").option("--yes", "approve without asking (the access summary is still printed)").action(async (id, o) => {
|
|
73
|
+
const env = await openMcpEnv(ctx);
|
|
74
|
+
await requireMcpOn(env);
|
|
75
|
+
const entry = await mcpGuard(async () => env.svc.catalog.get(id));
|
|
76
|
+
let projectRef = o.projectRef;
|
|
77
|
+
if (!projectRef && entry.prompts?.some((p) => p.name === "project_ref")) {
|
|
78
|
+
const typed = await promptLine(ctx, `${entry.prompts[0]?.description ?? "Project reference"} (empty = all projects): `);
|
|
79
|
+
if (typed) projectRef = typed;
|
|
80
|
+
}
|
|
81
|
+
let name = o.name;
|
|
82
|
+
if (!name && o.thisProject && env.projectRoot) name = `${entry.id}-${path.basename(env.projectRoot).toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 20) || "project"}`;
|
|
83
|
+
if (o.thisProject && !env.projectRoot) throw new ZgError("There is no project folder here to bind the connection to.");
|
|
84
|
+
const plan = await mcpGuard(async () => env.svc.catalog.plan(id, { settings: env.svc.settings, ...name ? { name } : {}, ...projectRef ? { projectRef } : {}, ...o.thisProject && env.projectRoot ? { projectPath: env.projectRoot } : {} }));
|
|
85
|
+
say(plan.summary.join("\n"));
|
|
86
|
+
if (plan.server.projectPath) say(`
|
|
87
|
+
This connection works only in: ${plan.server.projectPath}`);
|
|
88
|
+
say(`
|
|
89
|
+
It will be saved as "${plan.name}". Credentials are never stored in zg's settings.`);
|
|
90
|
+
if (!await confirmApprove(ctx, `Approve connecting ${entry.name}?`, o.yes === true)) return say("Cancelled. Nothing was added or connected.");
|
|
91
|
+
try {
|
|
92
|
+
const ac = new AbortController();
|
|
93
|
+
const st = await mcpGuard(
|
|
94
|
+
() => env.svc.connectPlan(plan, {
|
|
95
|
+
signal: ac.signal,
|
|
96
|
+
onUrl: (u) => say(`
|
|
97
|
+
Sign in: open this address in a browser (copy it if needed):
|
|
98
|
+
${u}
|
|
99
|
+
|
|
100
|
+
If the browser is on ANOTHER device, paste the address it ends on here. Waiting (up to 5 minutes)...`),
|
|
101
|
+
manualInput: (sig) => lineOrAbort(ctx, "Pasted address (or wait for the browser): ", sig)
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
say(`
|
|
105
|
+
Connected (initialized and tools discovered).`);
|
|
106
|
+
for (const l of statusDetail(st)) say(l);
|
|
107
|
+
const tools = env.svc.manager.tools({ includeDenied: true }).filter((t) => t.server === plan.name);
|
|
108
|
+
say("\nTools offered:");
|
|
109
|
+
for (const t of tools) say(` ${toolLine(t, "ask")}`);
|
|
110
|
+
for (const s of env.svc.manager.skipped(plan.name)) say(` skipped ${s.name}: ${s.reason}`);
|
|
111
|
+
const writes = tools.filter((t) => t.sensitivity !== "read");
|
|
112
|
+
if (writes.length > 0 && (o.readOnly || await confirm0(ctx, `Disable the ${writes.length} tool(s) that may change things (keep read-only tools)?`))) {
|
|
113
|
+
for (const t of writes) await env.svc.setPolicy(plan.name, t.name, "deny");
|
|
114
|
+
say(`Denied ${writes.length} tool(s). Re-enable one with: zg mcp policy ${plan.name} <tool> ask`);
|
|
115
|
+
}
|
|
116
|
+
say(`
|
|
117
|
+
Every remaining tool call still shows a preview and asks first. Use it in chat: zg, then /mcp connect ${plan.name}`);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
say(`"${plan.name}" was added to your settings but is NOT connected.`);
|
|
120
|
+
say(`Remove it with: zg integrations remove ${plan.name} Retry: zg mcp connect ${plan.name}`);
|
|
121
|
+
throw err;
|
|
122
|
+
} finally {
|
|
123
|
+
await env.svc.manager.shutdown();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
const connected = async () => {
|
|
127
|
+
const env = await openMcpEnv(ctx);
|
|
128
|
+
const sts = env.svc.manager.statuses().filter((s) => s.integration);
|
|
129
|
+
if (sts.length === 0) return say("No integration is configured. Browse: zg integrations list");
|
|
130
|
+
for (const s of sts) say(statusLine(s));
|
|
131
|
+
say("\nConnections last only while a chat or command is running.");
|
|
132
|
+
};
|
|
133
|
+
cmd.command("connected").description("Integrations you have set up").action(connected);
|
|
134
|
+
cmd.command("status").description("Same as connected").action(connected);
|
|
135
|
+
cmd.command("disconnect <name>").description("Delete the stored sign-in for an integration").option("--yes", "do not ask").action(async (name, o) => {
|
|
136
|
+
const env = await openMcpEnv(ctx);
|
|
137
|
+
if (!await confirm(ctx, `Delete the stored sign-in for "${name}"?`, o.yes === true)) return say("Cancelled.");
|
|
138
|
+
const had = await mcpGuard(() => env.svc.signOut(name));
|
|
139
|
+
say(had ? "Stored sign-in deleted." : "There was no stored sign-in.");
|
|
140
|
+
});
|
|
141
|
+
cmd.command("remove <name>").description("Remove an integration's connection and its stored sign-in").option("--yes", "do not ask").action(async (name, o) => {
|
|
142
|
+
const env = await openMcpEnv(ctx);
|
|
143
|
+
if (!await confirm(ctx, `Remove "${name}" and its stored sign-in?`, o.yes === true)) return say("Cancelled. Nothing was removed.");
|
|
144
|
+
const r = await mcpGuard(() => env.svc.remove(name));
|
|
145
|
+
say(`Removed "${name}".${r.hadCredentials ? " Its sign-in on this computer was deleted; revoke access at the service as well to end it fully." : ""}`);
|
|
146
|
+
});
|
|
147
|
+
cmd.command("refresh <name>").description("Reconnect an integration and re-read its tool list").action(async (name) => {
|
|
148
|
+
const env = await openMcpEnv(ctx);
|
|
149
|
+
await requireMcpOn(env);
|
|
150
|
+
try {
|
|
151
|
+
const st = await mcpGuard(async () => {
|
|
152
|
+
await env.svc.manager.connect(name);
|
|
153
|
+
return env.svc.manager.refresh(name);
|
|
154
|
+
});
|
|
155
|
+
for (const l of statusDetail(st)) say(l);
|
|
156
|
+
} finally {
|
|
157
|
+
await env.svc.manager.shutdown();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
cmd.command("doctor").description("Check the catalog itself and the integrations you set up (no network, no credentials shown)").option("--json", "machine-readable output").action(async (o) => {
|
|
161
|
+
const env = await openMcpEnv(ctx);
|
|
162
|
+
const mine = Object.entries(env.svc.settings.servers).filter(([, s]) => s.integration).map(([n]) => n);
|
|
163
|
+
const checks = [...env.svc.catalogDoctor()];
|
|
164
|
+
for (const n of mine) checks.push(...await env.svc.doctor({ server: n }));
|
|
165
|
+
if (o.json) return say(JSON.stringify(checks, null, 2));
|
|
166
|
+
for (const c of checks) say(`${MARK[c.status]} ${c.label.padEnd(18)} ${c.detail}${c.hint ? `
|
|
167
|
+
hint: ${c.hint}` : ""}`);
|
|
168
|
+
if (checks.some((c) => c.status === "fail")) process.exitCode = 1;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async function confirmApprove(ctx, q, yes) {
|
|
172
|
+
if (yes) return true;
|
|
173
|
+
const a = await promptLine(ctx, `${q} [y/N] `);
|
|
174
|
+
if (a === null) throw new ZgError("This needs your approval, but there is no terminal to ask in.", { hint: "Re-run with --yes after reading the access summary above." });
|
|
175
|
+
return a.toLowerCase() === "y" || a.toLowerCase() === "yes";
|
|
176
|
+
}
|
|
177
|
+
async function confirm0(ctx, q) {
|
|
178
|
+
const a = await promptLine(ctx, `${q} [y/N] `);
|
|
179
|
+
return a !== null && (a.toLowerCase() === "y" || a.toLowerCase() === "yes");
|
|
180
|
+
}
|
|
181
|
+
export {
|
|
182
|
+
registerIntegrations
|
|
183
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ConfigManager
|
|
4
|
+
} from "./chunk-UMC77TR3.js";
|
|
5
|
+
import {
|
|
6
|
+
detectHost
|
|
7
|
+
} from "./chunk-JU5PGDOD.js";
|
|
8
|
+
import {
|
|
9
|
+
getConfigDir
|
|
10
|
+
} from "./chunk-SZKAZ2VN.js";
|
|
11
|
+
import "./chunk-U5UIUB6L.js";
|
|
12
|
+
import {
|
|
13
|
+
BIN_NAME,
|
|
14
|
+
VERSION
|
|
15
|
+
} from "./chunk-GMVDCQVW.js";
|
|
16
|
+
import "./chunk-QH27MDJM.js";
|
|
17
|
+
import {
|
|
18
|
+
formatError
|
|
19
|
+
} from "./chunk-FC3UOHOO.js";
|
|
20
|
+
import "./chunk-WUF3TVAE.js";
|
|
21
|
+
|
|
22
|
+
// src/cli/main.ts
|
|
23
|
+
import { CommanderError } from "commander";
|
|
24
|
+
|
|
25
|
+
// src/cli/command-table.ts
|
|
26
|
+
var COMMAND_MODULES = [
|
|
27
|
+
{ names: ["doctor", "diagnostics", "version", "status"], load: async () => (await import("./doctor-ZZC2D3RW.js")).registerDoctor },
|
|
28
|
+
{ names: ["init"], load: async () => (await import("./init-UB3E47KM.js")).registerInit },
|
|
29
|
+
{ names: ["config"], load: async () => (await import("./config-IEWRCG7R.js")).registerConfig },
|
|
30
|
+
{ names: ["chat"], load: async () => (await import("./chat-AEHVCKXX.js")).registerChat },
|
|
31
|
+
{ names: ["providers", "provider", "models", "auth"], load: async () => (await import("./providers-O3WOVP5Q.js")).registerProviders },
|
|
32
|
+
{ names: ["memory"], load: async () => (await import("./memory-QQ54GRCN.js")).registerMemory },
|
|
33
|
+
{ names: ["sessions"], load: async () => (await import("./sessions-CL6CRNQL.js")).registerSessions },
|
|
34
|
+
{ names: ["mcp"], load: async () => (await import("./mcp-SWD4SO35.js")).registerMcp },
|
|
35
|
+
{ names: ["integrations"], load: async () => (await import("./integrations-HW4VTLN4.js")).registerIntegrations },
|
|
36
|
+
{ names: ["skills"], load: async () => (await import("./skills-7KDGTTKX.js")).registerSkills },
|
|
37
|
+
{ names: ["plugins"], load: async () => (await import("./plugins-VUGTEUNV.js")).registerPlugins },
|
|
38
|
+
{ names: ["agents"], load: async () => (await import("./agents-JYRQHH7R.js")).registerAgents },
|
|
39
|
+
{ names: ["analyze", "search", "index", "explain", "debug", "review", "refactor", "test", "docs", "lsp"], load: async () => (await import("./advanced-EPLZB6DG.js")).registerAdvanced },
|
|
40
|
+
{ names: ["security"], load: async () => (await import("./security-SAYW4LU4.js")).registerSecurity }
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
// src/cli/context.ts
|
|
44
|
+
import os from "os";
|
|
45
|
+
function createContext(overrides = {}) {
|
|
46
|
+
const platform = overrides.platform ?? detectHost();
|
|
47
|
+
const configDir = overrides.configDir ?? getConfigDir({ os: platform.os, env: process.env, homedir: os.homedir() });
|
|
48
|
+
return {
|
|
49
|
+
platform,
|
|
50
|
+
configDir,
|
|
51
|
+
manager: overrides.manager ?? new ConfigManager(configDir),
|
|
52
|
+
stdout: overrides.stdout ?? ((t) => process.stdout.write(`${t}
|
|
53
|
+
`)),
|
|
54
|
+
stderr: overrides.stderr ?? ((t) => process.stderr.write(`${t}
|
|
55
|
+
`)),
|
|
56
|
+
io: overrides.io ?? { input: process.stdin, output: process.stdout },
|
|
57
|
+
env: overrides.env ?? process.env,
|
|
58
|
+
fetch: overrides.fetch ?? ((input, init) => fetch(input, init))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/cli/program-base.ts
|
|
63
|
+
import { Command } from "commander";
|
|
64
|
+
function createBaseProgram(ctx = createContext()) {
|
|
65
|
+
const program = new Command();
|
|
66
|
+
program.name(BIN_NAME).description("ZERO GRAVITY: an independent AI coding terminal. Run `zg` to start chatting.").version(VERSION, "-v, --version", "print the version").option("--debug", "print stack traces for unexpected errors").allowExcessArguments(true).showHelpAfterError("(run `zg --help` for usage)").configureOutput({
|
|
67
|
+
writeOut: (s) => process.stdout.write(s),
|
|
68
|
+
writeErr: (s) => process.stderr.write(s)
|
|
69
|
+
}).exitOverride();
|
|
70
|
+
program.action(async () => {
|
|
71
|
+
const [unknown] = program.args;
|
|
72
|
+
if (unknown !== void 0) program.error(`unknown command '${unknown}'`);
|
|
73
|
+
const { launchChat } = await import("./chat-AEHVCKXX.js");
|
|
74
|
+
await launchChat(ctx);
|
|
75
|
+
});
|
|
76
|
+
return program;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/cli/lazy-program.ts
|
|
80
|
+
function requestedCommand(argv) {
|
|
81
|
+
for (const a of argv.slice(2)) {
|
|
82
|
+
if (a === "--debug") continue;
|
|
83
|
+
if (a.startsWith("-")) return null;
|
|
84
|
+
return a;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
async function buildProgramLazy(argv, ctx = createContext()) {
|
|
89
|
+
const program = createBaseProgram(ctx);
|
|
90
|
+
const wanted = requestedCommand(argv);
|
|
91
|
+
const one = wanted === null ? null : COMMAND_MODULES.find((m) => m.names.includes(wanted));
|
|
92
|
+
const mods = one ? [one] : COMMAND_MODULES;
|
|
93
|
+
for (const m of mods) (await m.load())(program, ctx);
|
|
94
|
+
return program;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/cli/main.ts
|
|
98
|
+
async function run(argv) {
|
|
99
|
+
const debug = argv.includes("--debug");
|
|
100
|
+
try {
|
|
101
|
+
await (await buildProgramLazy(argv)).parseAsync(argv);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
if (err instanceof CommanderError) {
|
|
104
|
+
process.exitCode = err.exitCode;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const { text, exitCode } = formatError(err, debug);
|
|
108
|
+
process.stderr.write(`${text}
|
|
109
|
+
`);
|
|
110
|
+
process.exitCode = exitCode;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
run
|
|
115
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
promptLine as promptLine2,
|
|
4
|
+
resourceLine,
|
|
5
|
+
statusDetail,
|
|
6
|
+
statusLine,
|
|
7
|
+
toolLine
|
|
8
|
+
} from "./chunk-7TACFVY2.js";
|
|
9
|
+
import {
|
|
10
|
+
setConfigValue
|
|
11
|
+
} from "./chunk-BJABQO7S.js";
|
|
12
|
+
import {
|
|
13
|
+
lineOrAbort,
|
|
14
|
+
mcpGuard,
|
|
15
|
+
openMcpEnv,
|
|
16
|
+
requireMcpOn
|
|
17
|
+
} from "./chunk-UQURXFAE.js";
|
|
18
|
+
import "./chunk-T6DDNE3W.js";
|
|
19
|
+
import "./chunk-2OH5KHWO.js";
|
|
20
|
+
import "./chunk-YJEUXO5I.js";
|
|
21
|
+
import "./chunk-KGA7VWQG.js";
|
|
22
|
+
import "./chunk-2ZYSAYMJ.js";
|
|
23
|
+
import {
|
|
24
|
+
confirm,
|
|
25
|
+
promptLine
|
|
26
|
+
} from "./chunk-YR6RCC6Y.js";
|
|
27
|
+
import "./chunk-SZKAZ2VN.js";
|
|
28
|
+
import "./chunk-DKCCXMSE.js";
|
|
29
|
+
import "./chunk-U5UIUB6L.js";
|
|
30
|
+
import "./chunk-XCWLFZSM.js";
|
|
31
|
+
import "./chunk-GMVDCQVW.js";
|
|
32
|
+
import "./chunk-JQYZX56A.js";
|
|
33
|
+
import {
|
|
34
|
+
describeMcpError,
|
|
35
|
+
describeServerLines,
|
|
36
|
+
toMcpError
|
|
37
|
+
} from "./chunk-R6DONQKN.js";
|
|
38
|
+
import "./chunk-QH27MDJM.js";
|
|
39
|
+
import "./chunk-ZQFAX275.js";
|
|
40
|
+
import {
|
|
41
|
+
ZgError
|
|
42
|
+
} from "./chunk-FC3UOHOO.js";
|
|
43
|
+
import {
|
|
44
|
+
redactSecrets
|
|
45
|
+
} from "./chunk-WUF3TVAE.js";
|
|
46
|
+
|
|
47
|
+
// src/mcp/discovery.ts
|
|
48
|
+
async function discover(m, server, signal) {
|
|
49
|
+
const st = m.status(server);
|
|
50
|
+
const out = { server, connected: st.state === "connected", tools: m.tools({ includeDenied: true }).filter((t) => t.server === server).map((t) => ({ id: t.id, sensitivity: t.sensitivity })), skipped: m.skipped(server), resources: null, prompts: null, instructions: false, error: st.lastError };
|
|
51
|
+
if (!out.connected) return out;
|
|
52
|
+
try {
|
|
53
|
+
if (st.capabilities.resources) out.resources = (await m.listResources(server, signal)).length;
|
|
54
|
+
if (st.capabilities.prompts) out.prompts = (await m.listPrompts(server, signal)).length;
|
|
55
|
+
} catch (err) {
|
|
56
|
+
out.error = describeMcpError(toMcpError(err));
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/cli/commands/mcp.ts
|
|
62
|
+
var collect = (v, prev = []) => [...prev, v];
|
|
63
|
+
function parseEnvPairs(pairs = []) {
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const p of pairs) {
|
|
66
|
+
const i = p.indexOf("=");
|
|
67
|
+
const child = i === -1 ? p : p.slice(0, i);
|
|
68
|
+
const host = i === -1 ? p : p.slice(i + 1);
|
|
69
|
+
if (i !== -1 && host === "") throw new ZgError(`--env ${p}: name the variable in YOUR environment after '='.`, { hint: "Example: --env GITHUB_TOKEN=MY_GITHUB_TOKEN (zg stores only the names, never values)" });
|
|
70
|
+
out[child] = host;
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
var MARK = { pass: "[ok] ", warn: "[warn]", fail: "[fail]", info: "[info]" };
|
|
75
|
+
function registerMcp(program, ctx) {
|
|
76
|
+
const say = (t) => ctx.stdout(redactSecrets(t));
|
|
77
|
+
const cmd = program.command("mcp").description("MCP servers: tools, resources and prompts from other programs and services (off until you enable it)");
|
|
78
|
+
async function withConnection(name, fn) {
|
|
79
|
+
const env = await openMcpEnv(ctx);
|
|
80
|
+
await requireMcpOn(env);
|
|
81
|
+
try {
|
|
82
|
+
await mcpGuard(() => env.svc.manager.connect(name));
|
|
83
|
+
return await mcpGuard(() => fn(env));
|
|
84
|
+
} finally {
|
|
85
|
+
await env.svc.manager.shutdown();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const list = async (name) => {
|
|
89
|
+
const env = await openMcpEnv(ctx);
|
|
90
|
+
say(`MCP: ${env.svc.settings.enabled ? "ON" : "off (turn on: zg config set mcp.enabled true)"}`);
|
|
91
|
+
const names = Object.keys(env.svc.settings.servers).sort();
|
|
92
|
+
if (name) return say(["", ...describeServerLines(name, await mcpGuard(async () => (await import("./config-ELG4FQ3K.js")).getServer(env.svc.settings, name))), ` state: ${env.svc.manager.status(name).state} (a connection lasts only while a zg command or chat is running)`].join("\n"));
|
|
93
|
+
if (names.length === 0) return say("No servers yet. Add one: zg mcp add <name> or browse: zg integrations list");
|
|
94
|
+
for (const n of names) say(statusLine(env.svc.manager.status(n)));
|
|
95
|
+
say("\nConnections last only while a chat or command is running. In chat: /mcp connect <server>");
|
|
96
|
+
};
|
|
97
|
+
cmd.action(() => list());
|
|
98
|
+
cmd.command("list [server]").alias("status").description("Show configured servers (or one in detail)").action(list);
|
|
99
|
+
cmd.command("add <name>").description("Add a server. Give options, or you are asked. Credentials are never stored: only environment variable NAMES.").option("--transport <stdio|http>", "how to reach it").option("--command <program>", "stdio: the program (no spaces; arguments go in --arg)").option("--arg <value>", "stdio: one argument (repeat for several)", collect).option("--url <https-url>", "http: the Streamable HTTP endpoint").option("--env <CHILD=HOSTVAR>", "pass the variable HOSTVAR from your environment to the server as CHILD (repeatable)", collect).option("--auth <none|env|oauth>", "http: how it authenticates").option("--credential-env <NAME>", "with --auth env: the NAME of the variable holding the bearer token").option("--this-project", "only usable from the current project").option("--disabled", "add it switched off").action(async (name, o) => {
|
|
100
|
+
const env = await openMcpEnv(ctx);
|
|
101
|
+
let transport = o.transport;
|
|
102
|
+
if (!transport) {
|
|
103
|
+
const t = await promptLine(ctx, "Transport (stdio = local program, http = remote URL): ");
|
|
104
|
+
if (t === null) throw new ZgError("No transport given and there is no terminal to ask in.", { hint: "Use --transport stdio|http with --command or --url." });
|
|
105
|
+
transport = t;
|
|
106
|
+
}
|
|
107
|
+
if (transport !== "stdio" && transport !== "http") throw new ZgError(`transport must be stdio or http, not "${transport.slice(0, 20)}"`);
|
|
108
|
+
const server = { transport, enabled: o.disabled !== true, env: parseEnvPairs(o.env) };
|
|
109
|
+
if (transport === "stdio") {
|
|
110
|
+
const command = o.command ?? await promptLine(ctx, "Program to run (for example npx): ");
|
|
111
|
+
if (!command) throw new ZgError("A stdio server needs --command.");
|
|
112
|
+
server["command"] = command;
|
|
113
|
+
server["args"] = o.arg ?? [];
|
|
114
|
+
} else {
|
|
115
|
+
const url = o.url ?? await promptLine(ctx, "Server URL (https://...): ");
|
|
116
|
+
if (!url) throw new ZgError("An http server needs --url.");
|
|
117
|
+
server["url"] = url;
|
|
118
|
+
server["authMethod"] = o.auth ?? "none";
|
|
119
|
+
if (o.credentialEnv) server["credentialEnv"] = o.credentialEnv;
|
|
120
|
+
}
|
|
121
|
+
if (o.thisProject) {
|
|
122
|
+
if (!env.projectRoot) throw new ZgError("There is no project folder here to bind the server to.");
|
|
123
|
+
server["projectPath"] = env.projectRoot;
|
|
124
|
+
}
|
|
125
|
+
await mcpGuard(() => env.svc.add(name, server));
|
|
126
|
+
say(`Added "${name}". Nothing was started or connected yet.`);
|
|
127
|
+
if (!env.svc.settings.enabled) say("MCP itself is off. Turn it on: zg config set mcp.enabled true");
|
|
128
|
+
say(env.svc.manager.status(name).authMethod === "oauth" ? `Next: zg mcp connect ${name} (signs you in)` : `Next: zg mcp inspect ${name} (connects once and shows what it offers)`);
|
|
129
|
+
});
|
|
130
|
+
cmd.command("remove <name>").description("Remove a server and any credentials zg stored for it (asks first)").option("--yes", "do not ask").action(async (name, o) => {
|
|
131
|
+
const env = await openMcpEnv(ctx);
|
|
132
|
+
await mcpGuard(async () => (await import("./config-ELG4FQ3K.js")).getServer(env.svc.settings, name));
|
|
133
|
+
if (!await confirm(ctx, `Remove server "${name}" and its stored sign-in?`, o.yes === true)) return say("Cancelled. Nothing was removed.");
|
|
134
|
+
const r = await mcpGuard(() => env.svc.remove(name));
|
|
135
|
+
say(`Removed "${name}".${r.hadCredentials ? " Its stored sign-in on this computer was deleted. To revoke access at the service itself, use that service's settings." : ""}`);
|
|
136
|
+
});
|
|
137
|
+
const toggle = (on) => async (server) => {
|
|
138
|
+
const env = await openMcpEnv(ctx);
|
|
139
|
+
if (!server) {
|
|
140
|
+
const { config } = await ctx.manager.load();
|
|
141
|
+
await ctx.manager.save(setConfigValue(config, "mcp.enabled", String(on)));
|
|
142
|
+
return say(on ? "MCP is ON. Servers still connect only when you ask (zg mcp inspect / chat /mcp connect), and every tool call asks first." : "MCP is off. Configured servers stay on disk.");
|
|
143
|
+
}
|
|
144
|
+
await mcpGuard(() => env.svc.setServerEnabled(server, on));
|
|
145
|
+
say(`Server "${server}" is ${on ? "enabled" : "disabled"}.`);
|
|
146
|
+
};
|
|
147
|
+
cmd.command("enable [server]").description("Turn MCP on, or enable one server").action(toggle(true));
|
|
148
|
+
cmd.command("disable [server]").description("Turn MCP off, or disable one server").action(toggle(false));
|
|
149
|
+
cmd.command("inspect <server>").description("Connect once and show what the server offers (then stop it)").action(async (name) => {
|
|
150
|
+
await withConnection(name, async ({ svc }) => {
|
|
151
|
+
const d = await discover(svc.manager, name);
|
|
152
|
+
for (const l of statusDetail(svc.manager.status(name))) say(l);
|
|
153
|
+
say(`Tools: ${d.tools.length} Resources: ${d.resources ?? "not offered"} Prompts: ${d.prompts ?? "not offered"}`);
|
|
154
|
+
for (const s of d.skipped) say(` skipped tool ${s.name}: ${s.reason}`);
|
|
155
|
+
say("Stopped again (a connection lasts only while a command or chat runs).");
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
cmd.command("connect <server>").description("Sign in (OAuth servers) and verify the connection works, then stop it").action(async (name) => {
|
|
159
|
+
const env = await openMcpEnv(ctx);
|
|
160
|
+
await requireMcpOn(env);
|
|
161
|
+
const s = await mcpGuard(async () => (await import("./config-ELG4FQ3K.js")).getServer(env.svc.settings, name));
|
|
162
|
+
try {
|
|
163
|
+
if (s.authMethod === "oauth") {
|
|
164
|
+
const ac = new AbortController();
|
|
165
|
+
say("Sign-in needs a browser. zg shows a link; it never opens one itself.");
|
|
166
|
+
await mcpGuard(() => env.svc.signIn(name, { onUrl: (u) => say(`
|
|
167
|
+
Open this address in a browser (copy it if needed):
|
|
168
|
+
${u}
|
|
169
|
+
|
|
170
|
+
If the browser is on ANOTHER device, after approving copy the address it ends on and paste it here.
|
|
171
|
+
Waiting (up to 5 minutes)...`), manualInput: (sig) => lineOrAbort(ctx, "Pasted address (or wait for the browser): ", sig), signal: ac.signal }));
|
|
172
|
+
say("Signed in. Credentials are stored on this computer only, in an owner-only file.");
|
|
173
|
+
}
|
|
174
|
+
const st = await mcpGuard(() => env.svc.manager.connect(name));
|
|
175
|
+
for (const l of statusDetail(st)) say(l);
|
|
176
|
+
say("Verified. (A connection lasts only while a command or chat runs; in chat use /mcp connect.)");
|
|
177
|
+
} finally {
|
|
178
|
+
await env.svc.manager.shutdown();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
cmd.command("disconnect <server>").description("Delete the stored sign-in for a server (connections do not persist between commands)").option("--yes", "do not ask").action(async (name, o) => {
|
|
182
|
+
const env = await openMcpEnv(ctx);
|
|
183
|
+
if (!await confirm(ctx, `Delete the stored sign-in for "${name}"?`, o.yes === true)) return say("Cancelled.");
|
|
184
|
+
const had = await mcpGuard(() => env.svc.signOut(name));
|
|
185
|
+
say(had ? `Stored sign-in for "${name}" deleted. Revoke access at the service too if you want it fully ended.` : `There was no stored sign-in for "${name}".`);
|
|
186
|
+
});
|
|
187
|
+
cmd.command("tools <server>").description("List the tools a server offers, with zg's risk label and your decision").action(async (name) => {
|
|
188
|
+
await withConnection(name, async ({ svc }) => {
|
|
189
|
+
for (const t of svc.manager.tools({ includeDenied: true })) say(toolLine(t, svc.settings.servers[name]?.toolPolicy[t.name] ?? "ask"));
|
|
190
|
+
say("\nColumns: id, risk (zg decides from the tool name; a server's own hints cannot lower it), your decision. Change: zg mcp policy " + name + " <tool> allow|ask|deny|reset");
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
cmd.command("policy <server> <tool> <decision>").description("allow (read-only tools skip the question), ask (default), deny (hidden and blocked), reset").action(async (server, tool, decision) => {
|
|
194
|
+
const env = await openMcpEnv(ctx);
|
|
195
|
+
if (!["allow", "ask", "deny", "reset"].includes(decision)) throw new ZgError("decision must be allow, ask, deny or reset");
|
|
196
|
+
await mcpGuard(() => env.svc.setPolicy(server, tool, decision === "reset" ? null : decision));
|
|
197
|
+
say(`${server}.${tool}: ${decision}.${decision === "allow" ? " (Only tools zg classifies as read-only can skip the question; others still ask.)" : ""}`);
|
|
198
|
+
});
|
|
199
|
+
cmd.command("resources <server>").description("List a server's resources, or show one with --read <uri> (shown only, never saved or sent to the AI)").option("--read <uri>", "show one resource").action(async (name, o) => {
|
|
200
|
+
await withConnection(name, async ({ svc }) => {
|
|
201
|
+
if (o.read) {
|
|
202
|
+
for (const it of await svc.resources.read(name, o.read)) say(it.kind === "binary" ? `[binary ${it.mimeType ?? "data"}, ${it.bytes} bytes: not shown and not saved]` : `${it.uri}${it.truncated ? " (cut to the size limit)" : ""}
|
|
203
|
+
${it.text}`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const r = await svc.resources.list(name);
|
|
207
|
+
say(r.length ? r.map(resourceLine).join("\n") : "(none)");
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
cmd.command("prompts <server>").description("List a server's prompt templates, or show one with --show <name>").option("--show <name>", "show one prompt's arguments").action(async (name, o) => {
|
|
211
|
+
await withConnection(name, async ({ svc }) => {
|
|
212
|
+
if (o.show) {
|
|
213
|
+
const p = await svc.prompts.show(name, o.show);
|
|
214
|
+
return say([promptLine2(p), ...p.arguments.map((a) => ` ${a.required ? "required" : "optional"} ${a.name}: ${a.description}`)].join("\n"));
|
|
215
|
+
}
|
|
216
|
+
const l = await svc.prompts.list(name);
|
|
217
|
+
say(l.length ? l.map(promptLine2).join("\n") : "(none)");
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
cmd.command("doctor [server]").description("Check MCP configuration, programs, variable NAMES and sign-in state (no credentials shown)").option("--json", "machine-readable output").action(async (server, o) => {
|
|
221
|
+
const env = await openMcpEnv(ctx);
|
|
222
|
+
const checks = await env.svc.doctor(server ? { server } : {});
|
|
223
|
+
if (o.json) return say(JSON.stringify(checks, null, 2));
|
|
224
|
+
for (const c of checks) say(`${MARK[c.status]} ${c.label.padEnd(18)} ${c.detail}${c.hint ? `
|
|
225
|
+
hint: ${c.hint}` : ""}`);
|
|
226
|
+
if (checks.some((c) => c.status === "fail")) process.exitCode = 1;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
export {
|
|
230
|
+
parseEnvPairs,
|
|
231
|
+
registerMcp
|
|
232
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
lineOrAbort,
|
|
4
|
+
mcpGuard,
|
|
5
|
+
openMcpEnv,
|
|
6
|
+
requireMcpOn
|
|
7
|
+
} from "./chunk-UQURXFAE.js";
|
|
8
|
+
import "./chunk-T6DDNE3W.js";
|
|
9
|
+
import "./chunk-2OH5KHWO.js";
|
|
10
|
+
import "./chunk-2ZYSAYMJ.js";
|
|
11
|
+
import "./chunk-YR6RCC6Y.js";
|
|
12
|
+
import "./chunk-SZKAZ2VN.js";
|
|
13
|
+
import "./chunk-DKCCXMSE.js";
|
|
14
|
+
import "./chunk-U5UIUB6L.js";
|
|
15
|
+
import "./chunk-XCWLFZSM.js";
|
|
16
|
+
import "./chunk-GMVDCQVW.js";
|
|
17
|
+
import "./chunk-JQYZX56A.js";
|
|
18
|
+
import "./chunk-R6DONQKN.js";
|
|
19
|
+
import "./chunk-QH27MDJM.js";
|
|
20
|
+
import "./chunk-ZQFAX275.js";
|
|
21
|
+
import "./chunk-FC3UOHOO.js";
|
|
22
|
+
import "./chunk-WUF3TVAE.js";
|
|
23
|
+
export {
|
|
24
|
+
lineOrAbort,
|
|
25
|
+
mcpGuard,
|
|
26
|
+
openMcpEnv,
|
|
27
|
+
requireMcpOn
|
|
28
|
+
};
|