create-cofounder 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 (3) hide show
  1. package/README.md +10 -0
  2. package/index.js +154 -0
  3. package/package.json +16 -0
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # create-cofounder
2
+
3
+ Initializer for Cofounder Crew project config.
4
+
5
+ ```bash
6
+ npm create cofounder@latest
7
+ npm create cofounder@latest -- --template worktree --setup-codex --yes
8
+ ```
9
+
10
+ This creates a `.cofounder/` skeleton in the current project and can optionally install the Codex MCP entry.
package/index.js ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { createInterface } from "node:readline/promises";
4
+ import { stdin as input, stdout as output } from "node:process";
5
+
6
+ const PACKAGE_NAME = "cofounder-crew";
7
+ const TEMPLATES = ["default", "worktree"];
8
+
9
+ async function main(argv = process.argv.slice(2)) {
10
+ const options = parseArgs(argv);
11
+ const interactive = process.stdin.isTTY && process.stdout.isTTY && !options.yes;
12
+ const answers = interactive ? await askQuestions(options) : options;
13
+ const template = answers.template ?? "default";
14
+
15
+ await runCofounder(["init", "--template", template], { inherit: true });
16
+
17
+ if (answers.setupCodex) {
18
+ await runCofounder(["setup", "codex", "--install"], { inherit: true });
19
+ } else {
20
+ console.log("");
21
+ console.log("Next:");
22
+ console.log(" cofounder setup codex --install");
23
+ console.log(" cofounder team");
24
+ console.log(' cofounder delegate backend "inspect this repo and summarize the API boundaries"');
25
+ }
26
+ }
27
+
28
+ function parseArgs(args) {
29
+ const options = {
30
+ yes: false,
31
+ setupCodex: false,
32
+ template: undefined
33
+ };
34
+
35
+ for (let index = 0; index < args.length; index += 1) {
36
+ const arg = args[index];
37
+ if (arg === "--yes" || arg === "-y") {
38
+ options.yes = true;
39
+ continue;
40
+ }
41
+ if (arg === "--setup-codex") {
42
+ options.setupCodex = true;
43
+ continue;
44
+ }
45
+ if (arg === "--no-setup-codex") {
46
+ options.setupCodex = false;
47
+ continue;
48
+ }
49
+ if (arg === "--template") {
50
+ options.template = requireValue(args[index + 1], "--template");
51
+ index += 1;
52
+ continue;
53
+ }
54
+ if (arg === "--help" || arg === "-h") {
55
+ printHelp();
56
+ process.exit(0);
57
+ }
58
+ throw new Error(`Unknown option: ${arg}`);
59
+ }
60
+
61
+ validateTemplate(options.template);
62
+ return options;
63
+ }
64
+
65
+ async function askQuestions(options) {
66
+ const reader = createInterface({ input, output });
67
+ try {
68
+ const templateAnswer = options.template ?? ((await reader.question(`Template (${TEMPLATES.join("/")}) [default]: `)).trim() || "default");
69
+ validateTemplate(templateAnswer);
70
+ const setupDefault = options.setupCodex ? "Y/n" : "y/N";
71
+ const setupAnswer = (await reader.question(`Install Codex MCP now? (${setupDefault}): `)).trim().toLowerCase();
72
+ return {
73
+ template: templateAnswer,
74
+ setupCodex: setupAnswer ? ["y", "yes"].includes(setupAnswer) : options.setupCodex
75
+ };
76
+ } finally {
77
+ reader.close();
78
+ }
79
+ }
80
+
81
+ async function runCofounder(args, options = {}) {
82
+ const command = resolveCofounderCommand(args);
83
+ await new Promise((resolve, reject) => {
84
+ const child = spawn(command.bin, command.args, {
85
+ cwd: process.cwd(),
86
+ env: process.env,
87
+ stdio: options.inherit ? "inherit" : "pipe"
88
+ });
89
+ const stderr = [];
90
+ child.stderr?.on("data", (chunk) => stderr.push(chunk));
91
+ child.on("error", reject);
92
+ child.on("close", (code) => {
93
+ if (code === 0) {
94
+ resolve();
95
+ return;
96
+ }
97
+ const output = Buffer.concat(stderr).toString("utf8").trim();
98
+ reject(new Error(output || `${command.bin} exited with code ${code ?? "unknown"}`));
99
+ });
100
+ });
101
+ }
102
+
103
+ function resolveCofounderCommand(args) {
104
+ if (process.env.COFOUNDER_CLI) {
105
+ return {
106
+ bin: process.execPath,
107
+ args: [process.env.COFOUNDER_CLI, ...args]
108
+ };
109
+ }
110
+
111
+ return {
112
+ bin: "npx",
113
+ args: ["-y", PACKAGE_NAME, ...args]
114
+ };
115
+ }
116
+
117
+ function validateTemplate(template) {
118
+ if (!template) {
119
+ return;
120
+ }
121
+ if (!TEMPLATES.includes(template)) {
122
+ throw new Error(`Unknown template "${template}". Available templates: ${TEMPLATES.join(", ")}`);
123
+ }
124
+ }
125
+
126
+ function requireValue(value, name) {
127
+ if (!value) {
128
+ throw new Error(`Missing ${name} value`);
129
+ }
130
+ return value;
131
+ }
132
+
133
+ function printHelp() {
134
+ console.log(`Usage:
135
+ npm create cofounder@latest
136
+ npm create cofounder@latest -- --template worktree
137
+ npm create cofounder@latest -- --template worktree --setup-codex --yes
138
+
139
+ Options:
140
+ --template <default|worktree>
141
+ --setup-codex
142
+ --no-setup-codex
143
+ --yes, -y
144
+
145
+ Local development:
146
+ COFOUNDER_CLI=/path/to/dist/src/cli.js node packages/create-cofounder/index.js --yes
147
+ `);
148
+ }
149
+
150
+ main().catch((error) => {
151
+ const message = error instanceof Error ? error.message : String(error);
152
+ console.error(`error: ${message}`);
153
+ process.exitCode = 1;
154
+ });
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "create-cofounder",
3
+ "version": "0.1.0",
4
+ "description": "Initializer for Cofounder Crew projects",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-cofounder": "index.js"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=22"
15
+ }
16
+ }