Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

52 lines · 1.9 KBRaw History
1import { dispatch, type Registry } from "./cli.js";
2import { adminCommands, agentGroup, secretGroup, tokenGroup, variableGroup } from "./commands/admin.js";
3import { authCommands, authGroup } from "./commands/auth.js";
4import { issueGroup } from "./commands/issue.js";
5import { migrateGroup } from "./commands/migrate.js";
6import { prGroup } from "./commands/pr.js";
7import { repoGroup } from "./commands/repo.js";
8import { runGroup } from "./commands/run.js";
9import { runnerCommand } from "./commands/runner.js";
10import { workflowGroup } from "./commands/workflow.js";
11import { CliError, processIo, type Io } from "./io.js";
12
13export const registry: Registry = {
14 groups: [authGroup, repoGroup, prGroup, issueGroup, runGroup, workflowGroup, secretGroup, variableGroup, tokenGroup, agentGroup, migrateGroup],
15 commands: [...authCommands, ...adminCommands, runnerCommand],
16};
17
18/** Runs the CLI and returns its exit code (never calls process.exit). */
19export async function main(argv: string[], io: Io = processIo()): Promise<number> {
20 try {
21 return await dispatch(registry, argv, io);
22 } catch (e) {
23 if (e instanceof CliError) {
24 io.stderr.write(`error: ${e.message}\n`);
25 return e.code;
26 }
27 io.stderr.write(`error: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}\n`);
28 return 1;
29 }
30}
31
32const isEntry = (() => {
33 const entry = process.argv[1];
34 if (!entry) return false;
35 return /(?:^|[\\/])(?:diffinery(?:\.mjs)?|main\.[cm]?[jt]s)$/.test(entry);
36})();
37
38if (isEntry) {
39 // EPIPE when piping into `head` and similar should end quietly.
40 process.stdout.on("error", (e: NodeJS.ErrnoException) => {
41 if (e.code === "EPIPE") process.exit(0);
42 });
43 main(process.argv.slice(2)).then(
44 (code) => {
45 process.exitCode = code;
46 },
47 (e: unknown) => {
48 process.stderr.write(`error: ${String(e)}\n`);
49 process.exitCode = 1;
50 },
51 );
52}