@moxxy/cli 0.0.1

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.
@@ -0,0 +1,440 @@
1
+ // src/cli.ts
2
+ import { Command } from "commander";
3
+
4
+ // src/config/config-manager.ts
5
+ import { readFile, writeFile, mkdir } from "fs/promises";
6
+ import { existsSync } from "fs";
7
+ import { join } from "path";
8
+ import { homedir } from "os";
9
+ import { moxxyConfigSchema } from "@moxxy/types";
10
+
11
+ // src/config/config-defaults.ts
12
+ var DEFAULT_CONFIG = {
13
+ version: 1,
14
+ webhook: { port: 3456, host: "0.0.0.0", path: "/webhook/github" },
15
+ repos: []
16
+ };
17
+ var CONFIG_DIR = ".moxxy";
18
+ var CONFIG_FILE = "config.json";
19
+
20
+ // src/config/config-manager.ts
21
+ var ConfigManager = class {
22
+ configPath;
23
+ config = null;
24
+ constructor(configDir) {
25
+ const base = configDir || join(homedir(), CONFIG_DIR);
26
+ this.configPath = join(base, CONFIG_FILE);
27
+ }
28
+ async load() {
29
+ if (!existsSync(this.configPath)) {
30
+ throw new Error(`Config not found at ${this.configPath}. Run 'moxxy config init' first.`);
31
+ }
32
+ const raw = await readFile(this.configPath, "utf-8");
33
+ const parsed = JSON.parse(raw);
34
+ this.config = moxxyConfigSchema.parse(parsed);
35
+ return this.config;
36
+ }
37
+ async save(config) {
38
+ const dir = join(this.configPath, "..");
39
+ if (!existsSync(dir)) {
40
+ await mkdir(dir, { recursive: true });
41
+ }
42
+ this.config = moxxyConfigSchema.parse(config);
43
+ await writeFile(this.configPath, JSON.stringify(this.config, null, 2) + "\n");
44
+ }
45
+ async init(config) {
46
+ const merged = { ...DEFAULT_CONFIG, ...config };
47
+ await this.save(merged);
48
+ return merged;
49
+ }
50
+ getConfig() {
51
+ if (!this.config) throw new Error("Config not loaded. Call load() first.");
52
+ return this.config;
53
+ }
54
+ async addRepo(repo) {
55
+ const config = this.getConfig();
56
+ const exists = config.repos.find((r) => r.owner === repo.owner && r.repo === repo.repo);
57
+ if (exists) throw new Error(`Repo ${repo.owner}/${repo.repo} already configured.`);
58
+ config.repos.push(repo);
59
+ await this.save(config);
60
+ }
61
+ async removeRepo(owner, repo) {
62
+ const config = this.getConfig();
63
+ config.repos = config.repos.filter((r) => !(r.owner === owner && r.repo === repo));
64
+ await this.save(config);
65
+ }
66
+ async set(key, value) {
67
+ const config = this.getConfig();
68
+ const keys = key.split(".");
69
+ let obj = config;
70
+ for (let i = 0; i < keys.length - 1; i++) {
71
+ obj = obj[keys[i]] ??= {};
72
+ }
73
+ obj[keys[keys.length - 1]] = value;
74
+ await this.save(config);
75
+ }
76
+ get(key) {
77
+ const config = this.getConfig();
78
+ const keys = key.split(".");
79
+ let obj = config;
80
+ for (const k of keys) {
81
+ obj = obj?.[k];
82
+ }
83
+ return obj;
84
+ }
85
+ get path() {
86
+ return this.configPath;
87
+ }
88
+ };
89
+
90
+ // src/utils/logger.ts
91
+ import chalk from "chalk";
92
+ import ora from "ora";
93
+ function info(message) {
94
+ console.log(`${chalk.cyan("i")} ${message}`);
95
+ }
96
+ function success(message) {
97
+ console.log(`${chalk.green("\u2714")} ${message}`);
98
+ }
99
+ function error(message) {
100
+ console.error(`${chalk.red("\u2716")} ${message}`);
101
+ }
102
+ function spinner(text) {
103
+ return ora({ text, color: "cyan" }).start();
104
+ }
105
+ function printBanner() {
106
+ console.log();
107
+ console.log(chalk.bold.cyan(" Moxxy"));
108
+ console.log(chalk.dim(" Agent orchestration platform"));
109
+ console.log();
110
+ }
111
+ function section(title) {
112
+ console.log();
113
+ console.log(chalk.bold(title));
114
+ console.log(chalk.dim("\u2500".repeat(title.length)));
115
+ }
116
+ function keyValue(key, value) {
117
+ console.log(` ${chalk.dim(key + ":")} ${value}`);
118
+ }
119
+ function listItem(text) {
120
+ console.log(` ${chalk.dim("\u2022")} ${text}`);
121
+ }
122
+
123
+ // src/commands/start.ts
124
+ var SDK_NAMES = {
125
+ molt: "Molt Gateway",
126
+ claude: "Claude CLI"
127
+ };
128
+ async function createSDK(config) {
129
+ const provider = config.sdk || "molt";
130
+ const sdkName = SDK_NAMES[provider] || provider;
131
+ if (provider === "claude") {
132
+ const { ClaudeSDK } = await import("@moxxy/claude");
133
+ const claudeConfig = config.claude || {};
134
+ const sdk2 = await ClaudeSDK.create({
135
+ cliPath: claudeConfig.cliPath,
136
+ model: claudeConfig.model,
137
+ timeout: claudeConfig.timeout,
138
+ permissionMode: claudeConfig.permissionMode
139
+ });
140
+ return { sdk: sdk2, sdkName };
141
+ }
142
+ const { MoltSDK } = await import("@moxxy/molt");
143
+ const sdk = await MoltSDK.create({
144
+ gatewayUrl: config.gateway.url,
145
+ authToken: config.gateway.authToken,
146
+ deviceId: config.gateway.deviceId,
147
+ devicePrivateKey: config.gateway.devicePrivateKey
148
+ });
149
+ return { sdk, sdkName };
150
+ }
151
+ function registerStartCommand(program) {
152
+ program.command("start").description("Start Moxxy orchestration").action(async () => {
153
+ const configManager = new ConfigManager();
154
+ try {
155
+ const config = await configManager.load();
156
+ printBanner();
157
+ const { MoltAgentSupervisor } = await import("@moxxy/agents");
158
+ const { IntegrationManager } = await import("@moxxy/integration-base");
159
+ const { GitHubIntegration } = await import("@moxxy/integration-github");
160
+ const provider = config.sdk || "molt";
161
+ const sdkName = SDK_NAMES[provider] || provider;
162
+ const connectSpinner = spinner(`Connecting to ${sdkName}`);
163
+ try {
164
+ const { sdk } = await createSDK(config);
165
+ connectSpinner.succeed(`Connected to ${sdkName}`);
166
+ const supervisorSpinner = spinner("Initializing agent supervisor");
167
+ const supervisor = new MoltAgentSupervisor(sdk);
168
+ const agentId = config.agent?.moltAgentId;
169
+ if (agentId) {
170
+ await supervisor.assignAgent(agentId, "developer");
171
+ supervisorSpinner.succeed(`Agent ${chalk.bold(agentId)} assigned`);
172
+ } else {
173
+ supervisorSpinner.succeed("Supervisor ready (no agent configured)");
174
+ }
175
+ const integrationManager = new IntegrationManager();
176
+ const github = new GitHubIntegration();
177
+ integrationManager.register(github);
178
+ integrationManager.on("*", (event) => {
179
+ info(
180
+ `${chalk.dim(`[${event.integration}]`)} ${event.type}: ${JSON.stringify(event.data).slice(0, 200)}`
181
+ );
182
+ });
183
+ const webhookConfig = config.webhook || {
184
+ port: 3456,
185
+ host: "0.0.0.0",
186
+ path: "/webhook/github"
187
+ };
188
+ const webhookSpinner = spinner("Starting webhook server");
189
+ await github.connect({
190
+ github: config.github,
191
+ webhook: webhookConfig,
192
+ sdk,
193
+ supervisor,
194
+ moltAgentId: agentId || ""
195
+ });
196
+ webhookSpinner.succeed(
197
+ `Webhook server listening on ${chalk.cyan(`${webhookConfig.host}:${webhookConfig.port}${webhookConfig.path}`)}`
198
+ );
199
+ if (config.repos.length > 0) {
200
+ const watchSpinner = spinner(
201
+ `Watching ${config.repos.length} repositories`
202
+ );
203
+ const targets = config.repos.map((r) => `${r.owner}/${r.repo}`);
204
+ await github.watch(targets);
205
+ watchSpinner.succeed(
206
+ `Watching ${chalk.bold(String(targets.length))} repositories: ${targets.join(", ")}`
207
+ );
208
+ }
209
+ console.log();
210
+ success(chalk.bold("Moxxy is running.") + " Press Ctrl+C to stop.");
211
+ const shutdown = async () => {
212
+ console.log();
213
+ info("Shutting down...");
214
+ await integrationManager.stopAll();
215
+ sdk.disconnect();
216
+ success("Shutdown complete.");
217
+ process.exit(0);
218
+ };
219
+ process.on("SIGINT", shutdown);
220
+ process.on("SIGTERM", shutdown);
221
+ await new Promise(() => {
222
+ });
223
+ } catch (innerErr) {
224
+ connectSpinner.fail(
225
+ `Failed to start: ${innerErr instanceof Error ? innerErr.message : innerErr}`
226
+ );
227
+ process.exitCode = 1;
228
+ }
229
+ } catch (err) {
230
+ error(`Failed to start: ${err instanceof Error ? err.message : err}`);
231
+ process.exitCode = 1;
232
+ }
233
+ });
234
+ }
235
+
236
+ // src/commands/repo.ts
237
+ function registerRepoCommand(program) {
238
+ const repo = program.command("repo").description("Manage watched repositories");
239
+ repo.command("add").description("Add a repository to watch").argument("<repo>", "Repository in owner/repo format").option("--branch <branch>", "Default branch", "main").option("--events <events>", "Comma-separated events to watch", "issues.opened,issues.labeled").action(async (repoStr, options) => {
240
+ const [owner, name] = repoStr.split("/");
241
+ if (!owner || !name) {
242
+ error("Repository must be in owner/repo format");
243
+ process.exitCode = 1;
244
+ return;
245
+ }
246
+ const manager = new ConfigManager();
247
+ try {
248
+ await manager.load();
249
+ await manager.addRepo({
250
+ owner,
251
+ repo: name,
252
+ defaultBranch: options.branch,
253
+ enabledEvents: options.events.split(",")
254
+ });
255
+ success(`Added ${chalk.bold(`${owner}/${name}`)}`);
256
+ } catch (err) {
257
+ error(`Failed: ${err instanceof Error ? err.message : err}`);
258
+ process.exitCode = 1;
259
+ }
260
+ });
261
+ repo.command("list").description("List watched repositories").action(async () => {
262
+ const manager = new ConfigManager();
263
+ try {
264
+ await manager.load();
265
+ const config = manager.getConfig();
266
+ if (config.repos.length === 0) {
267
+ info("No repositories configured.");
268
+ return;
269
+ }
270
+ section(`Repositories (${config.repos.length})`);
271
+ for (const r of config.repos) {
272
+ listItem(
273
+ `${chalk.bold(`${r.owner}/${r.repo}`)} ${chalk.dim(`branch: ${r.defaultBranch}`)} ${chalk.dim(`events: ${r.enabledEvents.join(", ")}`)}`
274
+ );
275
+ }
276
+ console.log();
277
+ } catch (err) {
278
+ error(`Failed: ${err instanceof Error ? err.message : err}`);
279
+ process.exitCode = 1;
280
+ }
281
+ });
282
+ repo.command("remove").description("Remove a watched repository").argument("<repo>", "Repository in owner/repo format").action(async (repoStr) => {
283
+ const [owner, name] = repoStr.split("/");
284
+ if (!owner || !name) {
285
+ error("Repository must be in owner/repo format");
286
+ process.exitCode = 1;
287
+ return;
288
+ }
289
+ const manager = new ConfigManager();
290
+ try {
291
+ await manager.load();
292
+ await manager.removeRepo(owner, name);
293
+ success(`Removed ${chalk.bold(`${owner}/${name}`)}`);
294
+ } catch (err) {
295
+ error(`Failed: ${err instanceof Error ? err.message : err}`);
296
+ process.exitCode = 1;
297
+ }
298
+ });
299
+ }
300
+
301
+ // src/commands/config.ts
302
+ function registerConfigCommand(program) {
303
+ const config = program.command("config").description("Manage Moxxy configuration");
304
+ config.command("init").description("Initialize Moxxy configuration").requiredOption("--gateway-url <url>", "Gateway URL (for molt SDK)").requiredOption("--github-token <token>", "GitHub personal access token").option("--sdk <provider>", "SDK provider (molt or claude)", "molt").option("--webhook-secret <secret>", "GitHub webhook secret").option("--webhook-port <port>", "Webhook server port", "3456").option("--agent-id <id>", "Agent ID").option("--claude-model <model>", "Claude model (for claude SDK)", "claude-sonnet-4-5").option("--claude-cli-path <path>", "Claude CLI path (for claude SDK)", "claude").action(async (options) => {
305
+ const manager = new ConfigManager();
306
+ try {
307
+ await manager.init({
308
+ version: 1,
309
+ sdk: options.sdk,
310
+ gateway: { url: options.gatewayUrl },
311
+ github: { token: options.githubToken, webhookSecret: options.webhookSecret },
312
+ webhook: {
313
+ port: parseInt(options.webhookPort, 10),
314
+ host: "0.0.0.0",
315
+ path: "/webhook/github"
316
+ },
317
+ repos: [],
318
+ agent: options.agentId ? { moltAgentId: options.agentId } : void 0,
319
+ claude: options.sdk === "claude" ? { cliPath: options.claudeCliPath, model: options.claudeModel } : void 0
320
+ });
321
+ success(`Config created at ${chalk.dim(manager.path)}`);
322
+ } catch (err) {
323
+ error(`Failed to init config: ${err instanceof Error ? err.message : err}`);
324
+ process.exitCode = 1;
325
+ }
326
+ });
327
+ config.command("set").description("Set a config value").argument("<key>", "Config key (dot notation)").argument("<value>", "Config value").action(async (key, value) => {
328
+ const manager = new ConfigManager();
329
+ try {
330
+ await manager.load();
331
+ let parsed = value;
332
+ try {
333
+ parsed = JSON.parse(value);
334
+ } catch {
335
+ }
336
+ await manager.set(key, parsed);
337
+ success(`Set ${chalk.bold(key)}`);
338
+ } catch (err) {
339
+ error(`Failed: ${err instanceof Error ? err.message : err}`);
340
+ process.exitCode = 1;
341
+ }
342
+ });
343
+ config.command("get").description("Get a config value").argument("<key>", "Config key (dot notation)").action(async (key) => {
344
+ const manager = new ConfigManager();
345
+ try {
346
+ await manager.load();
347
+ const value = manager.get(key);
348
+ console.log(chalk.cyan(JSON.stringify(value, null, 2)));
349
+ } catch (err) {
350
+ error(`Failed: ${err instanceof Error ? err.message : err}`);
351
+ process.exitCode = 1;
352
+ }
353
+ });
354
+ }
355
+
356
+ // src/commands/status.ts
357
+ function registerStatusCommand(program) {
358
+ program.command("status").description("Show Moxxy configuration status").action(async () => {
359
+ const configManager = new ConfigManager();
360
+ try {
361
+ const config = await configManager.load();
362
+ printBanner();
363
+ const provider = config.sdk || "molt";
364
+ section("SDK");
365
+ keyValue("Provider", chalk.bold(provider));
366
+ if (provider === "molt") {
367
+ section("Gateway");
368
+ keyValue("URL", chalk.cyan(config.gateway.url));
369
+ keyValue(
370
+ "Auth",
371
+ config.gateway.authToken ? chalk.green("configured") : chalk.dim("not set")
372
+ );
373
+ keyValue(
374
+ "Device",
375
+ config.gateway.deviceId || chalk.dim("not set")
376
+ );
377
+ }
378
+ if (provider === "claude" && config.claude) {
379
+ section("Claude");
380
+ keyValue("CLI Path", chalk.cyan(config.claude.cliPath || "claude"));
381
+ keyValue("Model", chalk.cyan(config.claude.model || "claude-sonnet-4-5"));
382
+ }
383
+ section("GitHub");
384
+ keyValue(
385
+ "Token",
386
+ config.github.token ? chalk.yellow("***" + config.github.token.slice(-4)) : chalk.dim("not set")
387
+ );
388
+ keyValue(
389
+ "Webhook Secret",
390
+ config.github.webhookSecret ? chalk.green("configured") : chalk.dim("not set")
391
+ );
392
+ if (config.webhook) {
393
+ section("Webhook Server");
394
+ keyValue("Port", chalk.cyan(String(config.webhook.port)));
395
+ keyValue("Path", chalk.cyan(config.webhook.path));
396
+ }
397
+ section(`Repositories (${config.repos.length})`);
398
+ if (config.repos.length === 0) {
399
+ keyValue("", chalk.dim("None configured"));
400
+ } else {
401
+ for (const r of config.repos) {
402
+ listItem(
403
+ `${chalk.bold(`${r.owner}/${r.repo}`)} ${chalk.dim(`(${r.defaultBranch})`)}`
404
+ );
405
+ }
406
+ }
407
+ if (config.agent) {
408
+ section("Agent");
409
+ keyValue(
410
+ "Agent ID",
411
+ config.agent.moltAgentId || chalk.dim("not set")
412
+ );
413
+ keyValue(
414
+ "Max Concurrent",
415
+ String(config.agent.maxConcurrentTasks || 1)
416
+ );
417
+ }
418
+ console.log();
419
+ } catch (err) {
420
+ error(`${err instanceof Error ? err.message : err}`);
421
+ process.exitCode = 1;
422
+ }
423
+ });
424
+ }
425
+
426
+ // src/cli.ts
427
+ function createProgram() {
428
+ const program = new Command();
429
+ program.name("moxxy").description("Moxxy - Agent orchestration platform").version("1.0.0");
430
+ registerStartCommand(program);
431
+ registerRepoCommand(program);
432
+ registerConfigCommand(program);
433
+ registerStatusCommand(program);
434
+ return program;
435
+ }
436
+
437
+ export {
438
+ ConfigManager,
439
+ createProgram
440
+ };