create-macostack 0.6.1 → 0.6.3

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/README.md CHANGED
@@ -14,6 +14,8 @@ An interactive wizard walks you through the rest:
14
14
 
15
15
  The CLI then downloads each template without its git history, installs dependencies, runs each template's own setup (app name, fresh secrets, module wiring), and leaves every part as its own independent git repository, ready to push.
16
16
 
17
+ Finally it scaffolds the **docs system**: `AGENTS.md` (the agent orchestrator), a `docs/` folder (product, architecture, API contract, testing strategy, current plan, ADRs, and per-feature SPEC → DESIGN → TASKS templates), and matching slash commands (`/spec`, `/design`, `/tasks`, `/implement`, `/review`) for **both Claude Code and OpenCode**. The workspace root becomes its own git repo that versions the docs — `client/` and `server/` stay independent.
18
+
17
19
  ## Requirements
18
20
 
19
21
  - [Bun](https://bun.sh) 1.x
@@ -38,21 +40,26 @@ Result:
38
40
 
39
41
  ```txt
40
42
  my-app/
41
- ├── server/ # Bun + Hono + Postgres API its own git repo
42
- └── client/ # TanStack web app its own git repo
43
+ ├── AGENTS.md # how AI agents work here (Claude Code & OpenCode)
44
+ ├── CLAUDE.md # Claude Code adapter AGENTS.md
45
+ ├── docs/ # product, architecture, contracts, features (SPEC/DESIGN/TASKS)
46
+ ├── server/ # Bun + Hono + Postgres API — its own git repo
47
+ └── client/ # TanStack web app — its own git repo
43
48
  ```
44
49
 
45
- The root folder is intentionally **not** a git repository: server and client are designed to live and deploy as separate repos.
50
+ The root is the **workspace repo**: it versions `docs/` and the orchestration files, while `server/` and `client/` are ignored each lives and deploys as its own separate repo.
46
51
 
47
52
  ### Managing an existing app
48
53
 
49
- Run the CLI again inside an app it created to add the missing part or toggle feature modules on and off — it detects the existing setup and switches to manage mode:
54
+ Run the CLI again inside an app it created — it detects the existing setup and switches to manage mode:
50
55
 
51
56
  ```bash
52
57
  cd my-app
53
58
  bun create macostack .
54
59
  ```
55
60
 
61
+ From there you can **start a new feature** (scaffolds `docs/features/<name>/` with SPEC, DESIGN and TASKS — then run `/spec <name>` in your agent), **update the docs system** (syncs AGENTS.md, slash commands, cheat sheet and feature templates from the template repo — your project's own docs are never touched), **add the docs system** to an app created before it existed, add a missing part, or toggle feature modules on and off.
62
+
56
63
  ### Flags
57
64
 
58
65
  | Flag | Description |
@@ -63,8 +70,10 @@ bun create macostack .
63
70
  | `--ref <ref>` | Branch or tag to download (default: `main`) |
64
71
  | `--server-repo <name>` | Server template repo (default: `macostack-server`) |
65
72
  | `--client-repo <name>` | Client template repo (default: `macostack-client`) |
73
+ | `--docs-repo <name>` | Docs system repo (default: `macostack-docs`) |
66
74
  | `--skip-install` | Skip `bun install` |
67
75
  | `--skip-setup` | Skip each template's setup wizard |
76
+ | `--skip-docs` | Skip the docs system (AGENTS.md + docs/) |
68
77
  | `--help` | Print usage |
69
78
 
70
79
  ### Environment variables
@@ -75,6 +84,7 @@ bun create macostack .
75
84
  | `MACOSTACK_GITHUB_OWNER` | Default template owner |
76
85
  | `MACOSTACK_SERVER_REPO` | Default server template repo |
77
86
  | `MACOSTACK_CLIENT_REPO` | Default client template repo |
87
+ | `MACOSTACK_DOCS_REPO` | Default docs system repo |
78
88
  | `MACOSTACK_REF` | Default branch or tag |
79
89
 
80
90
  ## Bring your own templates
@@ -15,10 +15,13 @@ import {
15
15
  mkdirSync,
16
16
  mkdtempSync,
17
17
  readdirSync,
18
+ readFileSync,
18
19
  rmSync,
20
+ statSync,
21
+ writeFileSync,
19
22
  } from "node:fs";
20
23
  import { tmpdir } from "node:os";
21
- import { basename, join, resolve } from "node:path";
24
+ import { basename, dirname, join, resolve } from "node:path";
22
25
  import { parseArgs } from "node:util";
23
26
 
24
27
  // create-macostack — start a new app from the macostack templates.
@@ -80,6 +83,11 @@ const PARTS: Part[] = [
80
83
  },
81
84
  ];
82
85
 
86
+ // The docs system: AGENTS.md + docs/ + slash commands for Claude Code and
87
+ // OpenCode. Lands at the WORKSPACE ROOT (not inside a part) and becomes its own
88
+ // git repo — its .gitignore excludes client/ and server/.
89
+ const DOCS_REPO = Bun.env.MACOSTACK_DOCS_REPO ?? "macostack-docs";
90
+
83
91
  //////////////////////////////////////////////////////////////////
84
92
  // FLAGS
85
93
  //////////////////////////////////////////////////////////////////
@@ -96,8 +104,10 @@ const parsed = parseArgs({
96
104
  ref: { type: "string" },
97
105
  "server-repo": { type: "string" },
98
106
  "client-repo": { type: "string" },
107
+ "docs-repo": { type: "string" },
99
108
  "skip-install": { type: "boolean", default: false },
100
109
  "skip-setup": { type: "boolean", default: false },
110
+ "skip-docs": { type: "boolean", default: false },
101
111
  },
102
112
  });
103
113
  const flags = parsed.values;
@@ -116,8 +126,10 @@ Flags:
116
126
  --ref <ref> branch or tag to pull (default: ${DEFAULT_REF})
117
127
  --server-repo <name> server template repo
118
128
  --client-repo <name> client template repo
129
+ --docs-repo <name> docs system repo (default: ${DOCS_REPO})
119
130
  --skip-install don't run bun install
120
131
  --skip-setup don't run each template's setup wizard
132
+ --skip-docs don't scaffold the docs system (AGENTS.md + docs/)
121
133
 
122
134
  Auth (templates are private):
123
135
  export GITHUB_TOKEN=github_pat_… or gh auth login
@@ -155,6 +167,179 @@ const isEmptyDir = (dir: string) =>
155
167
  !existsSync(dir) ||
156
168
  readdirSync(dir).filter((e) => e !== ".DS_Store").length === 0;
157
169
 
170
+ const ghFetch = (token: string, path: string) =>
171
+ fetch(`https://api.github.com${path}`, {
172
+ headers: {
173
+ Accept: "application/vnd.github+json",
174
+ Authorization: `Bearer ${token}`,
175
+ "User-Agent": "create-macostack",
176
+ "X-GitHub-Api-Version": "2022-11-28",
177
+ },
178
+ });
179
+
180
+ // Download a repo tarball (no git history) and unpack it into dest.
181
+ // Returns an error message, or null on success.
182
+ const downloadInto = async (
183
+ token: string,
184
+ ownerName: string,
185
+ repo: string,
186
+ refName: string,
187
+ dest: string,
188
+ ): Promise<string | null> => {
189
+ const tmp = mkdtempSync(join(tmpdir(), "create-macostack-"));
190
+ try {
191
+ const res = await ghFetch(token, `/repos/${ownerName}/${repo}/tarball/${refName}`);
192
+ if (!res.ok) return `GitHub refused the download (HTTP ${res.status})`;
193
+ const archive = join(tmp, "template.tar.gz");
194
+ await Bun.write(archive, await res.arrayBuffer());
195
+ mkdirSync(dest, { recursive: true });
196
+ const tar = Bun.spawnSync(
197
+ ["tar", "-xzf", archive, "-C", dest, "--strip-components=1"],
198
+ { stdout: "pipe", stderr: "pipe" },
199
+ );
200
+ if (tar.exitCode !== 0) return `couldn't unpack: ${tar.stderr.toString().slice(0, 200)}`;
201
+ return null;
202
+ } finally {
203
+ rmSync(tmp, { recursive: true, force: true });
204
+ }
205
+ };
206
+
207
+ // Bring the docs system into the workspace root: AGENTS.md, docs/, and the
208
+ // /spec /design /tasks /implement /review commands for BOTH agents. Stamps the
209
+ // placeholders and turns the root into its own git repo (its .gitignore
210
+ // excludes client/ and server/ — each part stays an independent repo).
211
+ const scaffoldDocs = async (
212
+ token: string,
213
+ root: string,
214
+ name: string,
215
+ modules: string[] | null,
216
+ ): Promise<boolean> => {
217
+ const docsOwner = flags.owner ?? DEFAULT_OWNER;
218
+ const docsRef = flags.ref ?? DEFAULT_REF;
219
+ const docsRepo = flags["docs-repo"] ?? DOCS_REPO;
220
+ const s = spinner();
221
+ s.start(`Docs — downloading ${docsOwner}/${docsRepo}@${docsRef}`);
222
+ const err = await downloadInto(token, docsOwner, docsRepo, docsRef, root);
223
+ if (err) {
224
+ s.stop("Docs — download failed");
225
+ note(
226
+ `The app itself is fine — only the docs system is missing (${err}).\n` +
227
+ " Add it later by running me again in this folder.",
228
+ "Heads up",
229
+ );
230
+ return false;
231
+ }
232
+
233
+ const stamp = (rel: string, replacements: Record<string, string>) => {
234
+ const p = resolve(root, rel);
235
+ if (!existsSync(p)) return;
236
+ let txt = readFileSync(p, "utf8");
237
+ for (const [k, v] of Object.entries(replacements)) txt = txt.replaceAll(k, v);
238
+ writeFileSync(p, txt);
239
+ };
240
+ const modulesText =
241
+ modules && modules.length > 0
242
+ ? modules.map((m) => `- ${m}`).join("\n")
243
+ : "Configuración por defecto del template.";
244
+ stamp("README.md", { "{{APP_NAME}}": name });
245
+ stamp("docs/PRODUCT.md", { "{{APP_NAME}}": name });
246
+ stamp("docs/ARCHITECTURE.md", { "{{MODULES}}": modulesText });
247
+
248
+ // The workspace root becomes its own repo: docs + orchestration, versioned.
249
+ if (!existsSync(resolve(root, ".git"))) {
250
+ Bun.spawnSync(["git", "init", "-b", "main"], { cwd: root, stdout: "pipe", stderr: "pipe" });
251
+ Bun.spawnSync(["git", "add", "-A"], { cwd: root, stdout: "pipe", stderr: "pipe" });
252
+ Bun.spawnSync(["git", "commit", "-m", "init: docs workspace"], { cwd: root, stdout: "pipe", stderr: "pipe" });
253
+ }
254
+ s.stop("Docs — AGENTS.md + docs/ + slash commands ready (Claude Code & OpenCode)");
255
+ return true;
256
+ };
257
+
258
+ // The docs-system files that a sync may replace. STRICT whitelist: process and
259
+ // templates only — never the project's own content (PRODUCT, CURRENT_PLAN,
260
+ // DECISIONS, ARCHITECTURE, real features), which lives outside these paths.
261
+ const DOCS_SYNC_PATHS = [
262
+ "AGENTS.md",
263
+ "CLAUDE.md",
264
+ "docs/CHEATSHEET.md",
265
+ "docs/features/_template",
266
+ ".claude/commands",
267
+ ".opencode/commands",
268
+ ];
269
+
270
+ // Bring an existing project's docs SYSTEM up to date with the template repo.
271
+ // Downloads the repo to a temp dir and copies only DOCS_SYNC_PATHS over the
272
+ // local files, reporting exactly what changed. Nothing is committed — the
273
+ // workspace repo shows the diff for review.
274
+ const updateDocs = async (token: string, root: string): Promise<void> => {
275
+ const docsOwner = flags.owner ?? DEFAULT_OWNER;
276
+ const docsRef = flags.ref ?? DEFAULT_REF;
277
+ const docsRepo = flags["docs-repo"] ?? DOCS_REPO;
278
+ const s = spinner();
279
+ s.start(`Docs — fetching ${docsOwner}/${docsRepo}@${docsRef}`);
280
+ const tmp = mkdtempSync(join(tmpdir(), "macostack-docs-sync-"));
281
+ try {
282
+ const err = await downloadInto(token, docsOwner, docsRepo, docsRef, tmp);
283
+ if (err) {
284
+ s.stop("Docs — download failed");
285
+ bail(err);
286
+ }
287
+ const changed: string[] = [];
288
+ const syncFile = (rel: string) => {
289
+ const src = join(tmp, rel);
290
+ const next = readFileSync(src, "utf8");
291
+ const dst = resolve(root, rel);
292
+ if (existsSync(dst) && readFileSync(dst, "utf8") === next) return;
293
+ mkdirSync(dirname(dst), { recursive: true });
294
+ writeFileSync(dst, next);
295
+ changed.push(rel);
296
+ };
297
+ const syncDir = (rel: string) => {
298
+ for (const e of readdirSync(join(tmp, rel), { withFileTypes: true })) {
299
+ const childRel = `${rel}/${e.name}`;
300
+ if (e.isDirectory()) syncDir(childRel);
301
+ else syncFile(childRel);
302
+ }
303
+ };
304
+ for (const p of DOCS_SYNC_PATHS) {
305
+ const src = join(tmp, p);
306
+ if (!existsSync(src)) continue;
307
+ if (statSync(src).isDirectory()) syncDir(p);
308
+ else syncFile(p);
309
+ }
310
+ s.stop(
311
+ changed.length === 0
312
+ ? "Docs — already up to date"
313
+ : `Docs — updated ${changed.length} file${changed.length === 1 ? "" : "s"}`,
314
+ );
315
+ if (changed.length > 0) {
316
+ note(
317
+ changed.map((f) => `• ${f}`).join("\n") +
318
+ "\n\nYour project's own docs (PRODUCT, CURRENT_PLAN, features…) were not touched.\nReview with git diff, then commit when happy.",
319
+ "Docs system updated",
320
+ );
321
+ }
322
+ } finally {
323
+ rmSync(tmp, { recursive: true, force: true });
324
+ }
325
+ };
326
+
327
+ // Scaffold docs/features/<name>/ from the _template folder (SPEC → DESIGN →
328
+ // TASKS). Returns an error message, or null on success.
329
+ const scaffoldFeature = (root: string, feature: string): string | null => {
330
+ const templateDir = resolve(root, "docs", "features", "_template");
331
+ const dest = resolve(root, "docs", "features", feature);
332
+ if (!existsSync(templateDir))
333
+ return "docs/features/_template is missing — add the docs system first.";
334
+ if (existsSync(dest)) return `docs/features/${feature} already exists.`;
335
+ mkdirSync(dest, { recursive: true });
336
+ for (const f of readdirSync(templateDir)) {
337
+ const txt = readFileSync(join(templateDir, f), "utf8").replaceAll("<nombre>", feature);
338
+ writeFileSync(join(dest, f), txt);
339
+ }
340
+ return null;
341
+ };
342
+
158
343
  //////////////////////////////////////////////////////////////////
159
344
  // WIZARD
160
345
  //////////////////////////////////////////////////////////////////
@@ -271,10 +456,19 @@ if (present.length > 0) {
271
456
  bail(`${displayRoot} already has macostack in it — run me without --yes to manage it.`);
272
457
  }
273
458
  const missing = PARTS.filter((p) => !present.includes(p));
274
- const stateLine = PARTS.map((p) => `${p.label}: ${present.includes(p) ? "✓ installed" : "— not yet"}`).join(" ");
459
+ const hasDocs = existsSync(resolve(targetRoot, "AGENTS.md"));
460
+ const stateLine =
461
+ PARTS.map((p) => `${p.label}: ${present.includes(p) ? "✓ installed" : "— not yet"}`).join(" ") +
462
+ ` Docs: ${hasDocs ? "✓ installed" : "— not yet"}`;
275
463
  note(stateLine, "You already have macostack here");
276
464
 
277
465
  const actions = [
466
+ ...(hasDocs
467
+ ? [
468
+ { value: "feature", label: "Start a new feature", hint: "SPEC → DESIGN → TASKS in docs/features/" },
469
+ { value: "docs-update", label: "Update the docs system", hint: "sync AGENTS.md, commands and templates — your content stays" },
470
+ ]
471
+ : [{ value: "docs", label: "Add the docs system", hint: "AGENTS.md + docs/ + /spec /design /tasks commands" }]),
278
472
  ...missing.map((p) => ({ value: `add:${p.id}`, label: `Add the ${p.label.toLowerCase()}`, hint: p.hint })),
279
473
  ...present.map((p) => ({ value: `adjust:${p.id}`, label: `Adjust ${p.label.toLowerCase()} modules`, hint: "turn things on or off" })),
280
474
  { value: "exit", label: "Nothing — just looking", hint: "leaves everything untouched" },
@@ -287,6 +481,58 @@ if (present.length > 0) {
287
481
  outro("All good — nothing was touched. 👋");
288
482
  process.exit(0);
289
483
  }
484
+ if (action === "feature") {
485
+ const feature = answered(
486
+ await text({
487
+ message: "Feature name?",
488
+ placeholder: "your-feature-name",
489
+ validate: (v) =>
490
+ validName(v ?? "") ? undefined : "lowercase letters, digits and dashes — e.g. dark-mode",
491
+ }),
492
+ );
493
+ const err = scaffoldFeature(targetRoot, feature);
494
+ if (err) bail(err);
495
+ note(
496
+ `docs/features/${feature}/ created (SPEC, DESIGN, TASKS).\nNext: open your agent here and run /spec ${feature}`,
497
+ "Feature",
498
+ );
499
+ outro(`${appName} — ready to spec ✨`);
500
+ process.exit(0);
501
+ }
502
+ if (action === "docs-update") {
503
+ const syncToken = githubToken();
504
+ if (!syncToken) {
505
+ bail(
506
+ "I need GitHub access to fetch the docs system (the repo is private).\n" +
507
+ " Easiest: gh auth login\n" +
508
+ " Or: export GITHUB_TOKEN=github_pat_… (Contents: Read-only)",
509
+ );
510
+ throw ""; // unreachable
511
+ }
512
+ await updateDocs(syncToken, targetRoot);
513
+ outro(`${appName} is up to date ✨`);
514
+ process.exit(0);
515
+ }
516
+ if (action === "docs") {
517
+ const docsToken = githubToken();
518
+ if (!docsToken) {
519
+ bail(
520
+ "I need GitHub access to download the docs system (the repo is private).\n" +
521
+ " Easiest: gh auth login\n" +
522
+ " Or: export GITHUB_TOKEN=github_pat_… (Contents: Read-only)",
523
+ );
524
+ throw ""; // unreachable
525
+ }
526
+ const ok = await scaffoldDocs(docsToken, targetRoot, appName, null);
527
+ if (ok) {
528
+ note(
529
+ `Open Claude Code or OpenCode in ${displayRoot}/ — it reads AGENTS.md.\nFirst: fill docs/PRODUCT.md, then /spec your-first-feature`,
530
+ "Next",
531
+ );
532
+ }
533
+ outro(`${appName} is up to date ✨`);
534
+ process.exit(0);
535
+ }
290
536
  const [verb, partId] = (action as string).split(":");
291
537
  const part = PARTS.find((p) => p.id === partId)!;
292
538
  if (verb === "adjust") {
@@ -340,15 +586,7 @@ for (const p of selected) {
340
586
 
341
587
  // Preflight every selected template so a typo'd repo or missing access fails
342
588
  // BEFORE any folders exist.
343
- const gh = (path: string) =>
344
- fetch(`https://api.github.com${path}`, {
345
- headers: {
346
- Accept: "application/vnd.github+json",
347
- Authorization: `Bearer ${token}`,
348
- "User-Agent": "create-macostack",
349
- "X-GitHub-Api-Version": "2022-11-28",
350
- },
351
- });
589
+ const gh = (path: string) => ghFetch(token, path);
352
590
  for (const p of selected) {
353
591
  const res = await gh(`/repos/${owner}/${p.repo}`);
354
592
  if (!res.ok) {
@@ -371,26 +609,10 @@ for (const p of selected) {
371
609
  const dest = resolve(targetRoot, p.folder);
372
610
  const s = spinner();
373
611
  s.start(`${p.label} — downloading ${owner}/${p.repo}@${ref}`);
374
- const tmp = mkdtempSync(join(tmpdir(), "create-macostack-"));
375
- try {
376
- const res = await gh(`/repos/${owner}/${p.repo}/tarball/${ref}`);
377
- if (!res.ok) {
378
- s.stop(`${p.label} — download failed`);
379
- bail(`GitHub refused the download (HTTP ${res.status}). Try again, or check --ref ${ref}.`);
380
- }
381
- const archive = join(tmp, "template.tar.gz");
382
- await Bun.write(archive, await res.arrayBuffer());
383
- mkdirSync(dest, { recursive: true });
384
- const tar = Bun.spawnSync(
385
- ["tar", "-xzf", archive, "-C", dest, "--strip-components=1"],
386
- { stdout: "pipe", stderr: "pipe" },
387
- );
388
- if (tar.exitCode !== 0) {
389
- s.stop(`${p.label} — extract failed`);
390
- bail(`Couldn't unpack the template: ${tar.stderr.toString().slice(0, 200)}`);
391
- }
392
- } finally {
393
- rmSync(tmp, { recursive: true, force: true });
612
+ const err = await downloadInto(token, owner, p.repo, ref, dest);
613
+ if (err) {
614
+ s.stop(`${p.label} — download failed`);
615
+ bail(`${err}. Try again, or check --ref ${ref}.`);
394
616
  }
395
617
  s.stop(`${p.label} — downloaded into ${displayRoot}/${p.folder}`);
396
618
 
@@ -568,6 +790,14 @@ for (const s of setups) {
568
790
  ready.push(p);
569
791
  }
570
792
 
793
+ // Phase 4 — the docs system: AGENTS.md + docs/ + slash commands for Claude
794
+ // Code and OpenCode, stamped with this app's choices. The root becomes the
795
+ // workspace repo (docs + orchestration; client/ and server/ stay independent).
796
+ let docsReady = existsSync(resolve(targetRoot, "AGENTS.md"));
797
+ if (!flags["skip-docs"] && !docsReady) {
798
+ docsReady = await scaffoldDocs(token, targetRoot, appName, chosenModules);
799
+ }
800
+
571
801
  //////////////////////////////////////////////////////////////////
572
802
  // DONE
573
803
  //////////////////////////////////////////////////////////////////
@@ -583,6 +813,11 @@ if (server) {
583
813
  if (client) {
584
814
  steps.push(`Start the web app:\n cd ${displayRoot}/client\n bun dev`);
585
815
  }
816
+ if (docsReady) {
817
+ steps.push(
818
+ `Define the product:\n open Claude Code or OpenCode in ${displayRoot}/ — they read AGENTS.md\n first session: fill docs/PRODUCT.md, then /spec <your-first-feature>`,
819
+ );
820
+ }
586
821
  steps.push(
587
822
  `When you're ready to publish (each part is its own repo):\n` +
588
823
  ready
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-macostack",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Scaffold a production-ready full-stack app from the macostack templates: Bun + Hono + Postgres backend and TanStack web app, each as its own git repo.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,6 +38,6 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3.14",
41
- "typescript": "^6.0.3"
41
+ "typescript": "^7.0.2"
42
42
  }
43
43
  }