@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,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ZgError
|
|
4
|
+
} from "./chunk-FC3UOHOO.js";
|
|
5
|
+
|
|
6
|
+
// src/utils/fs.ts
|
|
7
|
+
import { lstat, mkdir, readFile, rename, rm, stat, writeFile } from "fs/promises";
|
|
8
|
+
import path from "path";
|
|
9
|
+
var MAX_READ_BYTES = 1024 * 1024;
|
|
10
|
+
async function ensureDir(dir) {
|
|
11
|
+
await mkdir(dir, { recursive: true, mode: 448 });
|
|
12
|
+
}
|
|
13
|
+
async function readTextFileIfExists(file) {
|
|
14
|
+
let info;
|
|
15
|
+
try {
|
|
16
|
+
info = await stat(file);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
if (err.code === "ENOENT") return null;
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
if (!info.isFile()) throw new ZgError(`${file} exists but is not a regular file`);
|
|
22
|
+
if (info.size > MAX_READ_BYTES) {
|
|
23
|
+
throw new ZgError(`${file} is unexpectedly large (${info.size} bytes); refusing to read it`);
|
|
24
|
+
}
|
|
25
|
+
return readFile(file, "utf8");
|
|
26
|
+
}
|
|
27
|
+
async function atomicWriteFile(file, data) {
|
|
28
|
+
try {
|
|
29
|
+
const existing = await lstat(file);
|
|
30
|
+
if (existing.isSymbolicLink()) {
|
|
31
|
+
throw new ZgError(`${file} is a symbolic link; refusing to overwrite it`);
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (err.code !== "ENOENT") throw err;
|
|
35
|
+
}
|
|
36
|
+
await ensureDir(path.dirname(file));
|
|
37
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
38
|
+
try {
|
|
39
|
+
await writeFile(tmp, data, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
40
|
+
await rename(tmp, file);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
await rm(tmp, { force: true });
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
ensureDir,
|
|
49
|
+
readTextFileIfExists,
|
|
50
|
+
atomicWriteFile
|
|
51
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CONFIG_FILE_NAME
|
|
4
|
+
} from "./chunk-SZKAZ2VN.js";
|
|
5
|
+
import {
|
|
6
|
+
atomicWriteFile,
|
|
7
|
+
ensureDir,
|
|
8
|
+
readTextFileIfExists
|
|
9
|
+
} from "./chunk-U5UIUB6L.js";
|
|
10
|
+
import {
|
|
11
|
+
ConfigSchema,
|
|
12
|
+
defaultConfig,
|
|
13
|
+
migrateConfig
|
|
14
|
+
} from "./chunk-QH27MDJM.js";
|
|
15
|
+
import {
|
|
16
|
+
ZgError
|
|
17
|
+
} from "./chunk-FC3UOHOO.js";
|
|
18
|
+
import {
|
|
19
|
+
redactSecrets
|
|
20
|
+
} from "./chunk-WUF3TVAE.js";
|
|
21
|
+
|
|
22
|
+
// src/config/manager.ts
|
|
23
|
+
import path from "path";
|
|
24
|
+
var ConfigManager = class {
|
|
25
|
+
dir;
|
|
26
|
+
file;
|
|
27
|
+
/** `dir` must already be resolved (see platform/paths.ts). */
|
|
28
|
+
constructor(dir) {
|
|
29
|
+
this.dir = dir;
|
|
30
|
+
this.file = path.join(dir, CONFIG_FILE_NAME);
|
|
31
|
+
}
|
|
32
|
+
async load() {
|
|
33
|
+
const text = await readTextFileIfExists(this.file);
|
|
34
|
+
if (text === null) return { config: defaultConfig(), exists: false, file: this.file };
|
|
35
|
+
let json;
|
|
36
|
+
try {
|
|
37
|
+
json = JSON.parse(text);
|
|
38
|
+
} catch {
|
|
39
|
+
throw new ZgError(`config file is not valid JSON: ${this.file}`, {
|
|
40
|
+
hint: "fix it by hand, or run `zg init --force` to reset it to defaults."
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const migrated = migrateConfig(json);
|
|
44
|
+
const result = ConfigSchema.safeParse(migrated.value);
|
|
45
|
+
if (!result.success) {
|
|
46
|
+
const detail = result.error.issues.map((i) => `${i.path.join(".") || "root"}: ${i.message}`).join("; ");
|
|
47
|
+
throw new ZgError(`config file failed validation: ${redactSecrets(detail)}`, {
|
|
48
|
+
hint: `edit ${this.file}, or run \`zg init --force\` to reset it.`
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
config: result.data,
|
|
53
|
+
exists: true,
|
|
54
|
+
file: this.file,
|
|
55
|
+
...migrated.migratedFrom !== null ? { migratedFrom: migrated.migratedFrom } : {}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async save(config) {
|
|
59
|
+
const valid = ConfigSchema.parse(config);
|
|
60
|
+
await ensureDir(this.dir);
|
|
61
|
+
await atomicWriteFile(this.file, `${JSON.stringify(valid, null, 2)}
|
|
62
|
+
`);
|
|
63
|
+
}
|
|
64
|
+
/** Create the config file with defaults. Returns false if it already existed and force is off. */
|
|
65
|
+
async init(force = false) {
|
|
66
|
+
const { exists } = force ? { exists: false } : await this.loadForInit();
|
|
67
|
+
if (exists) return false;
|
|
68
|
+
await this.save(defaultConfig());
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
async loadForInit() {
|
|
72
|
+
const text = await readTextFileIfExists(this.file);
|
|
73
|
+
return { exists: text !== null };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
ConfigManager
|
|
79
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
McpService
|
|
4
|
+
} from "./chunk-T6DDNE3W.js";
|
|
5
|
+
import {
|
|
6
|
+
currentProjectRoot
|
|
7
|
+
} from "./chunk-YR6RCC6Y.js";
|
|
8
|
+
import {
|
|
9
|
+
isInteractive
|
|
10
|
+
} from "./chunk-DKCCXMSE.js";
|
|
11
|
+
import {
|
|
12
|
+
McpError
|
|
13
|
+
} from "./chunk-R6DONQKN.js";
|
|
14
|
+
import {
|
|
15
|
+
defaultConfig
|
|
16
|
+
} from "./chunk-QH27MDJM.js";
|
|
17
|
+
import {
|
|
18
|
+
ZgError
|
|
19
|
+
} from "./chunk-FC3UOHOO.js";
|
|
20
|
+
|
|
21
|
+
// src/cli/mcp-context.ts
|
|
22
|
+
import os from "os";
|
|
23
|
+
import readline from "readline";
|
|
24
|
+
async function openMcpEnv(ctx, cwd = process.cwd()) {
|
|
25
|
+
let config = defaultConfig();
|
|
26
|
+
try {
|
|
27
|
+
config = (await ctx.manager.load()).config;
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
let current = config.mcp;
|
|
31
|
+
const projectRoot = await currentProjectRoot(config, cwd, os.homedir());
|
|
32
|
+
const svc = new McpService({
|
|
33
|
+
settings: () => current,
|
|
34
|
+
update: async (next) => {
|
|
35
|
+
const { config: fresh } = await ctx.manager.load();
|
|
36
|
+
await ctx.manager.save({ ...fresh, mcp: next });
|
|
37
|
+
current = next;
|
|
38
|
+
},
|
|
39
|
+
configDir: ctx.configDir,
|
|
40
|
+
env: ctx.env,
|
|
41
|
+
windows: ctx.platform.os === "windows",
|
|
42
|
+
termux: ctx.platform.isTermux,
|
|
43
|
+
projectRoot: () => projectRoot
|
|
44
|
+
});
|
|
45
|
+
return { svc, config, projectRoot };
|
|
46
|
+
}
|
|
47
|
+
async function mcpGuard(fn) {
|
|
48
|
+
try {
|
|
49
|
+
return await fn();
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err instanceof McpError) throw new ZgError(err.message, err.hint ? { hint: err.hint } : {});
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function lineOrAbort(ctx, question, signal) {
|
|
56
|
+
if (!isInteractive(ctx.io)) return Promise.resolve(null);
|
|
57
|
+
return new Promise((resolve) => {
|
|
58
|
+
const rl = readline.createInterface({ input: ctx.io.input, output: ctx.io.output, terminal: false });
|
|
59
|
+
const done = (v) => {
|
|
60
|
+
signal?.removeEventListener("abort", onAbort);
|
|
61
|
+
rl.close();
|
|
62
|
+
resolve(v);
|
|
63
|
+
};
|
|
64
|
+
const onAbort = () => done(null);
|
|
65
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
66
|
+
ctx.io.output.write(question);
|
|
67
|
+
rl.once("line", (l) => done(l.trim()));
|
|
68
|
+
rl.once("close", () => done(null));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async function requireMcpOn(env) {
|
|
72
|
+
if (!env.svc.settings.enabled) throw new ZgError("MCP is turned off.", { hint: "Turn it on with: zg config set mcp.enabled true" });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
openMcpEnv,
|
|
77
|
+
mcpGuard,
|
|
78
|
+
lineOrAbort,
|
|
79
|
+
requireMcpOn
|
|
80
|
+
};
|