@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.
Files changed (73) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +50 -2
  4. package/THIRD-PARTY-NOTICES.md +100 -0
  5. package/dist/adv-context-SLTP32JQ.js +36 -0
  6. package/dist/advanced-EPLZB6DG.js +164 -0
  7. package/dist/agents-JYRQHH7R.js +181 -0
  8. package/dist/chat-AEHVCKXX.js +47 -0
  9. package/dist/chunk-2OH5KHWO.js +112 -0
  10. package/dist/chunk-2ZYSAYMJ.js +108 -0
  11. package/dist/chunk-4BZ4IXTO.js +161 -0
  12. package/dist/chunk-4ITJY25Z.js +144 -0
  13. package/dist/chunk-4JBLZQAQ.js +65 -0
  14. package/dist/chunk-6QLYRU3N.js +28 -0
  15. package/dist/chunk-7TACFVY2.js +57 -0
  16. package/dist/chunk-AY36KJTH.js +3023 -0
  17. package/dist/chunk-BJABQO7S.js +378 -0
  18. package/dist/chunk-C2GFK4JP.js +387 -0
  19. package/dist/chunk-CDC2K2KP.js +47 -0
  20. package/dist/chunk-DKCCXMSE.js +27 -0
  21. package/dist/chunk-FC3UOHOO.js +194 -0
  22. package/dist/chunk-FIASMDLX.js +216 -0
  23. package/dist/chunk-GMVDCQVW.js +88 -0
  24. package/dist/chunk-JQYZX56A.js +231 -0
  25. package/dist/chunk-JU5PGDOD.js +138 -0
  26. package/dist/chunk-JUZP5SXD.js +309 -0
  27. package/dist/chunk-KGA7VWQG.js +70 -0
  28. package/dist/chunk-L7VNR5LM.js +407 -0
  29. package/dist/chunk-LOSXCWHU.js +145 -0
  30. package/dist/chunk-NVC433AX.js +24 -0
  31. package/dist/chunk-QH27MDJM.js +248 -0
  32. package/dist/chunk-QUC5URWQ.js +708 -0
  33. package/dist/chunk-R2CPYTSP.js +31 -0
  34. package/dist/chunk-R5KQACGR.js +2833 -0
  35. package/dist/chunk-R6DONQKN.js +153 -0
  36. package/dist/chunk-RIX4S3J7.js +4747 -0
  37. package/dist/chunk-SZKAZ2VN.js +35 -0
  38. package/dist/chunk-T6DDNE3W.js +1338 -0
  39. package/dist/chunk-U4URD6TU.js +4605 -0
  40. package/dist/chunk-U5UIUB6L.js +51 -0
  41. package/dist/chunk-UMC77TR3.js +79 -0
  42. package/dist/chunk-UQURXFAE.js +80 -0
  43. package/dist/chunk-VBG7T7XY.js +1703 -0
  44. package/dist/chunk-VCCMJIAG.js +326 -0
  45. package/dist/chunk-VS375NYD.js +91 -0
  46. package/dist/chunk-WANZOLI5.js +1073 -0
  47. package/dist/chunk-WUF3TVAE.js +51 -0
  48. package/dist/chunk-XCWLFZSM.js +149 -0
  49. package/dist/chunk-YJEUXO5I.js +76 -0
  50. package/dist/chunk-YR6RCC6Y.js +894 -0
  51. package/dist/chunk-ZQFAX275.js +35 -0
  52. package/dist/config-ELG4FQ3K.js +30 -0
  53. package/dist/config-IEWRCG7R.js +50 -0
  54. package/dist/doctor-ZZC2D3RW.js +357 -0
  55. package/dist/ext-context-RIMZMEPB.js +37 -0
  56. package/dist/index.js +20 -0
  57. package/dist/init-UB3E47KM.js +22 -0
  58. package/dist/integrations-HW4VTLN4.js +183 -0
  59. package/dist/main-RAWWT22W.js +115 -0
  60. package/dist/mcp-SWD4SO35.js +232 -0
  61. package/dist/mcp-context-PM5FY665.js +28 -0
  62. package/dist/memory-QQ54GRCN.js +128 -0
  63. package/dist/memory-session-R6DGT6CS.js +14 -0
  64. package/dist/memory-summary-4P26B2ZY.js +18 -0
  65. package/dist/plugins-VUGTEUNV.js +166 -0
  66. package/dist/providers-O3WOVP5Q.js +417 -0
  67. package/dist/report-DDIZ6BLF.js +28 -0
  68. package/dist/sec-context-VQHW6TOZ.js +15 -0
  69. package/dist/security-SAYW4LU4.js +95 -0
  70. package/dist/sessions-CL6CRNQL.js +160 -0
  71. package/dist/skills-7KDGTTKX.js +126 -0
  72. package/dist/version-6E6A23B3.js +13 -0
  73. package/package.json +70 -4
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/filesystem/sensitive-files.ts
4
+ var SENSITIVE_DIRS = /* @__PURE__ */ new Set([".ssh", ".gnupg", ".aws", ".azure", ".kube", ".docker", ".config/gcloud"]);
5
+ var PROTECTED_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
6
+ var EXACT = /* @__PURE__ */ new Set([".npmrc", ".yarnrc.yml", ".netrc", "_netrc", ".pypirc", ".git-credentials", ".htpasswd", ".dockercfg", "terraform.tfstate", "terraform.tfstate.backup", ".pgpass", ".my.cnf", "kubeconfig"]);
7
+ var EXTENSIONS = [".pem", ".key", ".p12", ".pfx", ".keystore", ".jks", ".ppk", ".asc", ".gpg", ".tfvars", ".kdbx"];
8
+ var ENV_SAFE_SUFFIX = /* @__PURE__ */ new Set(["example", "sample", "template", "dist", "defaults"]);
9
+ function sensitiveReason(rel) {
10
+ const parts = rel.toLowerCase().split("/").filter(Boolean);
11
+ const dirs = parts.slice(0, -1);
12
+ const name = parts[parts.length - 1] ?? "";
13
+ for (const d of dirs) if (SENSITIVE_DIRS.has(d)) return `inside the protected directory ${d}`;
14
+ if (SENSITIVE_DIRS.has(name)) return `the protected directory ${name}`;
15
+ if (name === ".env" || name.startsWith(".env.")) {
16
+ const suffix = name.slice(5);
17
+ return ENV_SAFE_SUFFIX.has(suffix) ? null : "an environment file (may hold secrets)";
18
+ }
19
+ if (name.endsWith(".env") && name !== ".env") return "an environment file (may hold secrets)";
20
+ if (EXACT.has(name)) return "a credentials or secret configuration file";
21
+ if (EXTENSIONS.some((e) => name.endsWith(e))) return "a key, certificate or secret store";
22
+ if (/^id_(rsa|dsa|ecdsa|ed25519)(\.|$|-)/.test(name)) return "a private key";
23
+ if (/^(\.?credentials|\.?secrets?)([._-]|$)/.test(name)) return "a credentials or secrets file";
24
+ if (/^service[-_]?account.*\.json$/.test(name)) return "a service-account key";
25
+ return null;
26
+ }
27
+ function protectedDirReason(rel) {
28
+ for (const part of rel.toLowerCase().split("/")) if (PROTECTED_DIRS.has(part)) return `inside ${part}, which zg never modifies`;
29
+ return null;
30
+ }
31
+
32
+ export {
33
+ sensitiveReason,
34
+ protectedDirReason
35
+ };
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ addServer,
4
+ describeServerLines,
5
+ describeTarget,
6
+ getServer,
7
+ removeServer,
8
+ safeUrl,
9
+ setToolPolicy,
10
+ updateServer,
11
+ validateServer,
12
+ validateServerName,
13
+ validateServerUrl
14
+ } from "./chunk-R6DONQKN.js";
15
+ import "./chunk-QH27MDJM.js";
16
+ import "./chunk-FC3UOHOO.js";
17
+ import "./chunk-WUF3TVAE.js";
18
+ export {
19
+ addServer,
20
+ describeServerLines,
21
+ describeTarget,
22
+ getServer,
23
+ removeServer,
24
+ safeUrl,
25
+ setToolPolicy,
26
+ updateServer,
27
+ validateServer,
28
+ validateServerName,
29
+ validateServerUrl
30
+ };
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ SETTABLE_KEYS,
4
+ getConfigValue,
5
+ setConfigValue
6
+ } from "./chunk-BJABQO7S.js";
7
+ import "./chunk-KGA7VWQG.js";
8
+ import {
9
+ defaultConfig
10
+ } from "./chunk-QH27MDJM.js";
11
+ import {
12
+ ZgError
13
+ } from "./chunk-FC3UOHOO.js";
14
+ import "./chunk-WUF3TVAE.js";
15
+
16
+ // src/cli/commands/config.ts
17
+ function registerConfig(program, ctx) {
18
+ const cmd = program.command("config").description("View or change configuration (no API keys are ever stored)");
19
+ const show = async () => {
20
+ const { config, exists, file } = await ctx.manager.load();
21
+ ctx.stdout(JSON.stringify(config, null, 2));
22
+ ctx.stdout(exists ? `# ${file}` : `# ${file} (not created yet; showing defaults. Run \`zg init\`.)`);
23
+ };
24
+ cmd.action(show);
25
+ cmd.command("show").description("Print the current configuration").action(show);
26
+ cmd.command("path").description("Print the configuration file path").action(() => ctx.stdout(ctx.manager.file));
27
+ cmd.command("keys").description("List settable keys").action(() => ctx.stdout(SETTABLE_KEYS.join("\n")));
28
+ cmd.command("get <key>").description("Print one setting").action(async (key) => {
29
+ const { config } = await ctx.manager.load();
30
+ ctx.stdout(JSON.stringify(getConfigValue(config, key)));
31
+ });
32
+ cmd.command("set <key> <value>").description("Change one setting").action(async (key, value) => {
33
+ const { config } = await ctx.manager.load();
34
+ const next = setConfigValue(config, key, value);
35
+ await ctx.manager.save(next);
36
+ ctx.stdout(`Set ${key} = ${JSON.stringify(getConfigValue(next, key))}`);
37
+ });
38
+ cmd.command("reset").description("Reset configuration to defaults").option("--yes", "confirm the reset").action(async (opts) => {
39
+ if (!opts.yes) {
40
+ throw new ZgError("this overwrites your configuration with defaults", {
41
+ hint: "re-run with --yes to confirm."
42
+ });
43
+ }
44
+ await ctx.manager.save(defaultConfig());
45
+ ctx.stdout(`Reset ${ctx.manager.file} to defaults`);
46
+ });
47
+ }
48
+ export {
49
+ registerConfig
50
+ };
@@ -0,0 +1,357 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ ConfigManager
4
+ } from "./chunk-UMC77TR3.js";
5
+ import {
6
+ describePlatform
7
+ } from "./chunk-JU5PGDOD.js";
8
+ import {
9
+ createStyle
10
+ } from "./chunk-NVC433AX.js";
11
+ import {
12
+ describeProviderStatus,
13
+ getProvider
14
+ } from "./chunk-WANZOLI5.js";
15
+ import "./chunk-4ITJY25Z.js";
16
+ import "./chunk-KGA7VWQG.js";
17
+ import "./chunk-SZKAZ2VN.js";
18
+ import "./chunk-U5UIUB6L.js";
19
+ import {
20
+ MIN_NODE_MAJOR,
21
+ VERSION
22
+ } from "./chunk-GMVDCQVW.js";
23
+ import "./chunk-QH27MDJM.js";
24
+ import {
25
+ ZgError
26
+ } from "./chunk-FC3UOHOO.js";
27
+ import {
28
+ redactSecrets
29
+ } from "./chunk-WUF3TVAE.js";
30
+
31
+ // src/cli/commands/doctor.ts
32
+ import os2 from "os";
33
+
34
+ // src/core/diagnostics.ts
35
+ import { access, constants, stat } from "fs/promises";
36
+ import path from "path";
37
+ async function nearestExisting(target) {
38
+ let current = target;
39
+ for (let i = 0; i < 64; i++) {
40
+ try {
41
+ await stat(current);
42
+ return current;
43
+ } catch {
44
+ const parent = path.dirname(current);
45
+ if (parent === current) return null;
46
+ current = parent;
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ async function checkConfigDir(configDir) {
52
+ const label = "Config directory";
53
+ const existing = await nearestExisting(configDir);
54
+ if (!existing) {
55
+ return { id: "config-dir", label, status: "fail", detail: `${configDir} (no existing parent found)` };
56
+ }
57
+ try {
58
+ await access(existing, constants.W_OK);
59
+ } catch {
60
+ return {
61
+ id: "config-dir",
62
+ label,
63
+ status: "fail",
64
+ detail: `${configDir} (${existing} is not writable)`,
65
+ hint: "set ZG_CONFIG_DIR to a writable absolute path."
66
+ };
67
+ }
68
+ const created = existing === configDir;
69
+ return {
70
+ id: "config-dir",
71
+ label,
72
+ status: "pass",
73
+ detail: created ? configDir : `${configDir} (will be created by \`zg init\`)`
74
+ };
75
+ }
76
+ async function checkConfigFile(manager) {
77
+ const label = "Config file";
78
+ try {
79
+ const { exists, file } = await manager.load();
80
+ return exists ? { id: "config-file", label, status: "pass", detail: `${file} (valid)` } : {
81
+ id: "config-file",
82
+ label,
83
+ status: "info",
84
+ detail: "not created yet; defaults in use",
85
+ hint: "run `zg init` to create it."
86
+ };
87
+ } catch (err) {
88
+ const message = err instanceof ZgError ? err.message : "could not read config file";
89
+ return {
90
+ id: "config-file",
91
+ label,
92
+ status: "fail",
93
+ detail: message,
94
+ ...err instanceof ZgError && err.hint ? { hint: err.hint } : {}
95
+ };
96
+ }
97
+ }
98
+ async function runDiagnostics(platform, configDir) {
99
+ const checks = [];
100
+ checks.push({
101
+ id: "node",
102
+ label: "Node.js",
103
+ status: platform.node.supported ? "pass" : "fail",
104
+ detail: platform.node.supported ? `${platform.node.version} (requires >= ${MIN_NODE_MAJOR})` : `${platform.node.version} is too old; zg requires Node.js ${MIN_NODE_MAJOR} or newer`,
105
+ ...platform.node.supported ? {} : { hint: "install a current Node.js LTS release." }
106
+ });
107
+ const osKnown = platform.os !== "other";
108
+ checks.push({
109
+ id: "os",
110
+ label: "Operating system",
111
+ status: osKnown ? "pass" : "warn",
112
+ detail: `${describePlatform(platform)} (${platform.rawPlatform}, kernel ${platform.kernelRelease})`,
113
+ ...osKnown ? {} : { hint: "this platform is outside the designed support list." }
114
+ });
115
+ if (platform.isAndroid) {
116
+ checks.push({
117
+ id: "android",
118
+ label: "Android / Termux",
119
+ status: "info",
120
+ detail: platform.isTermux ? "Termux detected" : "Android detected (not Termux)"
121
+ });
122
+ }
123
+ const archKnown = platform.arch !== "other";
124
+ checks.push({
125
+ id: "arch",
126
+ label: "CPU architecture",
127
+ status: archKnown ? "pass" : "warn",
128
+ detail: platform.rawArch,
129
+ ...archKnown ? {} : { hint: "only x64 and arm64 are in the design scope." }
130
+ });
131
+ const t = platform.terminal;
132
+ const size = t.columns && t.rows ? `${t.columns}x${t.rows}` : "size unknown";
133
+ checks.push({
134
+ id: "terminal",
135
+ label: "Terminal",
136
+ status: "info",
137
+ detail: `${t.isTTY ? "interactive" : "not a TTY"}, colour level ${t.colorLevel}, unicode ${t.unicode ? "yes" : "no"}, ${size}${platform.shell ? `, shell ${platform.shell}` : ""}`
138
+ });
139
+ checks.push(await checkConfigDir(configDir));
140
+ checks.push(await checkConfigFile(new ConfigManager(configDir)));
141
+ return { ok: !checks.some((c) => c.status === "fail"), checks, platform, configDir };
142
+ }
143
+
144
+ // src/cli/sys-checks.ts
145
+ import { execFile } from "child_process";
146
+ import os from "os";
147
+ function probe(file, args, o) {
148
+ const useCmd = o.windows && (file === "npm" || file === "npx");
149
+ const [bin, argv] = useCmd ? ["cmd.exe", ["/d", "/s", "/c", `${file} ${args.join(" ")}`]] : [file, [...args]];
150
+ return new Promise((resolve) => {
151
+ try {
152
+ execFile(bin, argv, { timeout: o.timeoutMs ?? 4e3, windowsHide: true, env: { ...o.env }, maxBuffer: 64 * 1024 }, (err, stdout) => {
153
+ if (err) resolve({ ok: false, text: err.code === "ENOENT" ? "not found" : "did not run" });
154
+ else resolve({ ok: true, text: stdout.toString().split(/\r?\n/)[0]?.trim() ?? "" });
155
+ });
156
+ } catch {
157
+ resolve({ ok: false, text: "did not run" });
158
+ }
159
+ });
160
+ }
161
+ async function systemChecks(ctx) {
162
+ const win = ctx.platform.os === "windows";
163
+ const [git, npm] = await Promise.all([probe("git", ["--version"], { windows: win, env: ctx.env }), probe("npm", ["--version"], { windows: win, env: ctx.env })]);
164
+ const checks = [
165
+ { id: "zg-version", label: "ZERO GRAVITY", status: "info", detail: `version ${VERSION} (pre-release, not published to npm)` },
166
+ git.ok ? { id: "git", label: "Git", status: "pass", detail: git.text } : { id: "git", label: "Git", status: "warn", detail: `${git.text}; Git features are unavailable`, hint: ctx.platform.isTermux ? "install it with: pkg install git" : "install Git from https://git-scm.com/downloads" },
167
+ npm.ok ? { id: "npm", label: "npm", status: "pass", detail: `${npm.text}` } : { id: "npm", label: "npm", status: "info", detail: `${npm.text} (only needed to install or update zg)` }
168
+ ];
169
+ const problems = [];
170
+ const home = ctx.env["HOME"] ?? ctx.env["USERPROFILE"];
171
+ if (!home) problems.push("no HOME / USERPROFILE is set (the default config folder cannot be found; set ZG_CONFIG_DIR)");
172
+ const cfg = ctx.env["ZG_CONFIG_DIR"];
173
+ if (cfg && !/^([a-z]:[\\/]|[\\/])/i.test(cfg)) problems.push("ZG_CONFIG_DIR is not an absolute path");
174
+ if (ctx.env["TERM"] === "dumb") problems.push("TERM=dumb: colours and the interactive layout are reduced");
175
+ if (!ctx.platform.terminal.isTTY) problems.push("not an interactive terminal: the chat needs one (piping works for other commands)");
176
+ if (ctx.platform.isTermux && !ctx.env["PREFIX"]) problems.push("Termux detected but PREFIX is not set (unusual environment)");
177
+ if (os.freemem() < 100 * 1024 * 1024) problems.push("less than 100 MB of free memory");
178
+ checks.push(problems.length ? { id: "environment", label: "Environment", status: "warn", detail: problems.join("; "), hint: "fix the items listed, then re-run `zg doctor`" } : { id: "environment", label: "Environment", status: "pass", detail: "no common problems detected" });
179
+ return checks;
180
+ }
181
+
182
+ // src/cli/commands/doctor.ts
183
+ var SYMBOLS = {
184
+ pass: { unicode: "\u2714", ascii: "[ok]" },
185
+ warn: { unicode: "!", ascii: "[warn]" },
186
+ fail: { unicode: "\u2716", ascii: "[fail]" },
187
+ info: { unicode: "\u2022", ascii: "[info]" }
188
+ };
189
+ async function collectReport(ctx) {
190
+ const report = await runDiagnostics(ctx.platform, ctx.configDir);
191
+ report.checks.unshift(...await systemChecks(ctx));
192
+ report.checks.push(await providerCheck(ctx));
193
+ report.checks.push(...await mcpChecks(ctx));
194
+ report.checks.push(...await extensionChecks(ctx));
195
+ report.checks.push(...await advancedChecks(ctx));
196
+ report.checks.push(...await securityChecks(ctx));
197
+ report.ok = !report.checks.some((c) => c.status === "fail");
198
+ return report;
199
+ }
200
+ function printReport(ctx, report, title) {
201
+ const style = createStyle(ctx.platform.terminal);
202
+ const paint = { pass: style.ok, warn: style.warn, fail: style.fail, info: style.dim };
203
+ ctx.stdout("");
204
+ ctx.stdout(style.bold(` ${title}`));
205
+ ctx.stdout("");
206
+ for (const check of report.checks) {
207
+ const sym = SYMBOLS[check.status];
208
+ const mark = paint[check.status]((style.unicode ? sym.unicode : sym.ascii).padEnd(6));
209
+ ctx.stdout(` ${mark} ${style.bold(check.label.padEnd(18))} ${check.detail}`);
210
+ if (check.hint) ctx.stdout(` ${style.dim(`hint: ${check.hint}`)}`);
211
+ }
212
+ ctx.stdout("");
213
+ ctx.stdout(
214
+ report.ok ? ` ${style.ok("No problems found.")} ${style.dim("This reports what was detected on this machine; it does not certify compatibility.")}` : ` ${style.fail("Problems found.")} See the items marked as failed above.`
215
+ );
216
+ ctx.stdout("");
217
+ }
218
+ function systemInfo(ctx) {
219
+ const p = ctx.platform;
220
+ const watched = ["ZG_CONFIG_DIR", "TERM", "NO_COLOR", "FORCE_COLOR", "SHELL", "PREFIX", "HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY", "GEMINI_API_KEY", "GOOGLE_API_KEY", "OLLAMA_API_KEY"];
221
+ return {
222
+ version: VERSION,
223
+ node: process.versions.node,
224
+ v8: process.versions.v8,
225
+ os: p.os,
226
+ platform: p.rawPlatform,
227
+ arch: p.rawArch,
228
+ kernel: p.kernelRelease,
229
+ distro: p.distro?.name ?? null,
230
+ termux: p.isTermux,
231
+ android: p.isAndroid,
232
+ shell: p.shell,
233
+ terminal: { tty: p.terminal.isTTY, colorLevel: p.terminal.colorLevel, unicode: p.terminal.unicode, columns: p.terminal.columns, rows: p.terminal.rows },
234
+ cpus: os2.cpus().length,
235
+ totalMemoryMB: Math.round(os2.totalmem() / 1048576),
236
+ freeMemoryMB: Math.round(os2.freemem() / 1048576),
237
+ processRssMB: Math.round(process.memoryUsage().rss / 1048576),
238
+ configDir: ctx.configDir,
239
+ environment: Object.fromEntries(watched.map((k) => [k, ctx.env[k] ? "set" : "not set"]))
240
+ };
241
+ }
242
+ function registerDoctor(program, ctx) {
243
+ program.command("doctor").description("Check this system and your configuration").option("--json", "print machine-readable JSON").action(async (opts) => {
244
+ const report = await collectReport(ctx);
245
+ if (opts.json) ctx.stdout(redactSecrets(JSON.stringify(report, null, 2)));
246
+ else printReport(ctx, report, "zg doctor");
247
+ if (!report.ok) process.exitCode = 1;
248
+ });
249
+ program.command("diagnostics").description("Everything `zg doctor` checks, plus system facts, for bug reports (no secret values)").option("--json", "print machine-readable JSON").action(async (opts) => {
250
+ const started = performance.now();
251
+ const report = await collectReport(ctx);
252
+ const full = { ...report, system: systemInfo(ctx), checkedInMs: Math.round(performance.now() - started) };
253
+ if (opts.json) ctx.stdout(redactSecrets(JSON.stringify(full, null, 2)));
254
+ else {
255
+ printReport(ctx, report, "zg diagnostics");
256
+ for (const [k, v] of Object.entries(full.system)) ctx.stdout(` ${k.padEnd(16)} ${typeof v === "object" && v !== null ? JSON.stringify(v) : String(v)}`);
257
+ ctx.stdout("");
258
+ }
259
+ if (!report.ok) process.exitCode = 1;
260
+ });
261
+ program.command("version").description("Print the version and the runtime it runs on").option("--json", "print machine-readable JSON").action((opts) => {
262
+ const p = ctx.platform;
263
+ const info = { version: VERSION, node: process.versions.node, os: p.os, arch: p.rawArch, termux: p.isTermux };
264
+ if (opts.json) ctx.stdout(JSON.stringify(info, null, 2));
265
+ else ctx.stdout(`zg ${VERSION} (Node.js ${info.node}, ${describePlatform(p)} ${p.rawArch}${p.isTermux ? ", Termux" : ""})`);
266
+ });
267
+ program.command("status").description("A short summary: configuration, provider, security mode and project").option("--json", "print machine-readable JSON").action(async (opts) => {
268
+ const { config, exists, file } = await ctx.manager.load();
269
+ let provider = "none selected";
270
+ if (config.defaultProvider) {
271
+ const d = getProvider(config.defaultProvider);
272
+ provider = d ? `${d.displayName}: ${describeProviderStatus(d, config, ctx.env).detail}` : `unknown provider "${config.defaultProvider.slice(0, 40)}"`;
273
+ }
274
+ const { openSecEnv } = await import("./sec-context-VQHW6TOZ.js");
275
+ const sec = await openSecEnv(ctx);
276
+ const eff = sec.report.engine.levels();
277
+ const st = { version: VERSION, configFile: exists ? file : "(not created; defaults in use)", provider, model: config.defaultModel ?? "(provider default)", securityMode: eff.mode, project: sec.report.projectRoot ?? "(none)", approvalMode: config.approvalMode, mcp: config.mcp.enabled ? "on" : "off", extensions: { skills: config.extensions.skills.enabled, plugins: config.extensions.plugins.enabled, agents: config.extensions.agents.enabled } };
278
+ if (opts.json) ctx.stdout(redactSecrets(JSON.stringify(st, null, 2)));
279
+ else for (const [k, v] of Object.entries(st)) ctx.stdout(`${k.padEnd(14)} ${typeof v === "object" ? JSON.stringify(v) : String(v)}`);
280
+ });
281
+ }
282
+ async function mcpChecks(ctx) {
283
+ try {
284
+ const { openMcpEnv } = await import("./mcp-context-PM5FY665.js");
285
+ const env = await openMcpEnv(ctx);
286
+ const cat = env.svc.catalogDoctor()[0];
287
+ const servers = env.svc.settings.enabled ? await env.svc.doctor() : [];
288
+ return env.svc.settings.enabled ? [...servers, ...cat ? [cat] : []] : [{ id: "mcp", label: "MCP", status: "info", detail: "off", hint: "turn on with: zg config set mcp.enabled true" }];
289
+ } catch {
290
+ return [{ id: "mcp", label: "MCP", status: "info", detail: "unknown (config file could not be read)" }];
291
+ }
292
+ }
293
+ async function advancedChecks(ctx) {
294
+ try {
295
+ const { openAdvanced } = await import("./adv-context-SLTP32JQ.js");
296
+ const env = await openAdvanced(ctx);
297
+ const a = env.config.advanced;
298
+ const st = await env.svc.intel.indexer.status();
299
+ const checks = [{ id: "index", label: "Code index", status: "info", detail: `${a.indexing.enabled ? "on" : "off"}; ${st.exists ? `${st.files} files, ${st.persisted ? "saved" : "in memory"}${st.stale ? `, ${st.stale} changed since` : ""}` : "none yet"}`, ...a.indexing.enabled ? {} : { hint: "optional: zg config set advanced.indexing.enabled true" } }];
300
+ const langs = (await env.svc.intel.facts()).languages.map((l) => l.id);
301
+ const rows = await env.svc.lsp.status(langs);
302
+ const found = rows.filter((r) => r.available).length;
303
+ checks.push({ id: "lsp", label: "Language servers", status: "info", detail: `${a.lsp.enabled ? "on" : "off"}; ${found} of ${rows.length} project language(s) have a server installed`, hint: "see `zg lsp status`" });
304
+ return checks;
305
+ } catch {
306
+ return [{ id: "index", label: "Code index", status: "info", detail: "not checked (run inside a project folder)" }];
307
+ }
308
+ }
309
+ async function extensionChecks(ctx) {
310
+ try {
311
+ const { openExtEnv } = await import("./ext-context-RIMZMEPB.js");
312
+ const env = await openExtEnv(ctx);
313
+ const x = env.config.extensions;
314
+ const checks = [];
315
+ const skills = await env.svc.skills.list();
316
+ const bad = (await env.svc.skills.broken()).length + skills.filter((s) => s.problems.length > 0 && s.enabled).length;
317
+ checks.push({ id: "skills", label: "Skills", status: bad ? "warn" : "pass", detail: `${x.skills.enabled ? "on" : "off"}, ${skills.length} found${bad ? `, ${bad} unusable` : ""}`, ...bad ? { hint: "run `zg skills list`" } : {} });
318
+ const pl = await env.svc.plugins.doctor();
319
+ const installed = (await env.svc.plugins.list()).length;
320
+ checks.push({ id: "plugins", label: "Plugins", status: pl.ok ? "pass" : installed === 0 ? "info" : "warn", detail: `${x.plugins.enabled ? "on" : "off"}, ${installed} installed; ${pl.lines[0] ?? ""}`, ...pl.ok ? {} : { hint: "run `zg plugins doctor`" } });
321
+ const ag = await env.svc.agents.doctor();
322
+ checks.push({ id: "agents", label: "Agents", status: ag.ok ? "pass" : "warn", detail: `${x.agents.enabled ? "on" : "off"}; ${ag.lines[0] ?? ""}`, ...ag.ok ? {} : { hint: "run `zg agents doctor`" } });
323
+ return checks;
324
+ } catch {
325
+ return [{ id: "extensions", label: "Extensions", status: "info", detail: "unknown (could not be read)" }];
326
+ }
327
+ }
328
+ async function providerCheck(ctx) {
329
+ const label = "AI provider";
330
+ try {
331
+ const { config } = await ctx.manager.load();
332
+ if (config.defaultProvider === null) {
333
+ return { id: "provider", label, status: "info", detail: "none selected", hint: "run `zg provider` to choose one." };
334
+ }
335
+ const desc = getProvider(config.defaultProvider);
336
+ if (!desc) return { id: "provider", label, status: "warn", detail: `unknown provider "${config.defaultProvider.slice(0, 40)}"`, hint: "run `zg providers` for valid ids." };
337
+ const status = describeProviderStatus(desc, config, ctx.env);
338
+ return status.readiness === "ready" ? { id: "provider", label, status: "pass", detail: `${desc.displayName}: ${status.detail}` } : { id: "provider", label, status: "warn", detail: `${desc.displayName}: ${status.detail}`, hint: "run `zg auth status` or `zg provider status`." };
339
+ } catch {
340
+ return { id: "provider", label, status: "info", detail: "unknown (config file could not be read)" };
341
+ }
342
+ }
343
+ async function securityChecks(ctx) {
344
+ try {
345
+ const { openSecEnv } = await import("./sec-context-VQHW6TOZ.js");
346
+ const { doctorChecks } = await import("./report-DDIZ6BLF.js");
347
+ const env = await openSecEnv(ctx);
348
+ return (await doctorChecks(env.report)).map((c) => ({ id: c.id, label: c.label, status: c.status === "ok" ? "pass" : c.status, detail: c.detail, ...c.hint ? { hint: c.hint } : {} }));
349
+ } catch {
350
+ return [{ id: "sec-unavailable", label: "Security", status: "warn", detail: "the security status could not be read" }];
351
+ }
352
+ }
353
+ export {
354
+ collectReport,
355
+ registerDoctor,
356
+ systemInfo
357
+ };
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ backendFactory,
4
+ extGuard,
5
+ openExtEnv,
6
+ requireOn
7
+ } from "./chunk-RIX4S3J7.js";
8
+ import {
9
+ describeExtensionError
10
+ } from "./chunk-LOSXCWHU.js";
11
+ import "./chunk-WANZOLI5.js";
12
+ import "./chunk-JUZP5SXD.js";
13
+ import "./chunk-4ITJY25Z.js";
14
+ import "./chunk-CDC2K2KP.js";
15
+ import "./chunk-YJEUXO5I.js";
16
+ import "./chunk-KGA7VWQG.js";
17
+ import "./chunk-2ZYSAYMJ.js";
18
+ import "./chunk-YR6RCC6Y.js";
19
+ import "./chunk-SZKAZ2VN.js";
20
+ import "./chunk-DKCCXMSE.js";
21
+ import "./chunk-U5UIUB6L.js";
22
+ import "./chunk-XCWLFZSM.js";
23
+ import "./chunk-GMVDCQVW.js";
24
+ import "./chunk-JQYZX56A.js";
25
+ import "./chunk-R6DONQKN.js";
26
+ import "./chunk-QH27MDJM.js";
27
+ import "./chunk-R2CPYTSP.js";
28
+ import "./chunk-ZQFAX275.js";
29
+ import "./chunk-FC3UOHOO.js";
30
+ import "./chunk-WUF3TVAE.js";
31
+ export {
32
+ backendFactory,
33
+ describeExtensionError,
34
+ extGuard,
35
+ openExtEnv,
36
+ requireOn
37
+ };
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli/index.ts
4
+ var major = Number.parseInt(process.versions.node.split(".")[0] ?? "0", 10);
5
+ if (major < 22) {
6
+ process.stderr.write(
7
+ `zg requires Node.js 22 or newer (found ${process.versions.node}).
8
+ Install a current Node.js LTS release and try again.
9
+ `
10
+ );
11
+ process.exit(1);
12
+ }
13
+ if (process.argv.length === 3 && (process.argv[2] === "-v" || process.argv[2] === "--version")) {
14
+ const { VERSION } = await import("./version-6E6A23B3.js");
15
+ process.stdout.write(`${VERSION}
16
+ `);
17
+ process.exit(0);
18
+ }
19
+ var { run } = await import("./main-RAWWT22W.js");
20
+ await run(process.argv);
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createStyle
4
+ } from "./chunk-NVC433AX.js";
5
+
6
+ // src/cli/commands/init.ts
7
+ function registerInit(program, ctx) {
8
+ program.command("init").description("Create the default configuration file").option("--force", "overwrite an existing configuration with defaults").action(async (opts) => {
9
+ const style = createStyle(ctx.platform.terminal);
10
+ const created = await ctx.manager.init(Boolean(opts.force));
11
+ if (created) {
12
+ ctx.stdout(`${style.ok("Created")} ${ctx.manager.file}`);
13
+ ctx.stdout(style.dim("Next: `zg doctor` to check your setup, `zg config` to view settings."));
14
+ } else {
15
+ ctx.stdout(`Already initialised: ${ctx.manager.file}`);
16
+ ctx.stdout(style.dim("Use `zg init --force` to reset it to defaults."));
17
+ }
18
+ });
19
+ }
20
+ export {
21
+ registerInit
22
+ };