@montytools/cli 0.1.5 → 0.1.6

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/bin/monty.mjs CHANGED
@@ -362,7 +362,50 @@ async function create() {
362
362
 
363
363
  installSkills({ appDir: target });
364
364
  console.log(`created: ${target}`);
365
- console.log(`next: cd ${target} && pnpm install && monty dev`);
365
+ console.log(`next: cd ${target} && monty install && monty dev`);
366
+ }
367
+
368
+
369
+ // ── monty install / build / typecheck ───────────────────────────────────────
370
+ // The full app lifecycle goes through the CLI — agents never invoke pnpm,
371
+ // vite, or tsc directly. Same underlying tools, agent-shaped output, and the
372
+ // build-before-typecheck ordering handled for you.
373
+ function installDeps() {
374
+ const appDir = requireAppDir("install");
375
+ const pm = spawnSync("pnpm", ["--version"], { stdio: "ignore" }).status === 0 ? "pnpm" : "npm";
376
+ run(appDir, "install", [pm, "install"],
377
+ "Dependency install failed. Read the package manager error above; usually network or a bad package.json edit.");
378
+ }
379
+
380
+ function buildApp() {
381
+ const appDir = requireAppDir("build");
382
+ run(appDir, "build", ["npx", "vite", "build"],
383
+ "The production build failed. Read the vite error above; it names the file to fix.");
384
+ }
385
+
386
+ function typecheckApp() {
387
+ const appDir = requireAppDir("typecheck");
388
+ // routeTree.gen.ts is generated by the build — without it tsc fails on a
389
+ // fresh checkout, so build first when it's missing.
390
+ if (!existsSync(join(appDir, "src", "routeTree.gen.ts"))) {
391
+ run(appDir, "build", ["npx", "vite", "build"],
392
+ "The production build failed. Read the vite error above; it names the file to fix.");
393
+ }
394
+ run(appDir, "typecheck", ["npx", "tsc", "--noEmit"],
395
+ "TypeScript errors above. Fix them in the listed files.");
396
+ }
397
+
398
+
399
+ async function freePort(start) {
400
+ for (let p = start; p < start + 50; p++) {
401
+ const ok = await new Promise((resolve) => {
402
+ const probe = createServer();
403
+ probe.once("error", () => resolve(false));
404
+ probe.listen(p, "127.0.0.1", () => probe.close(() => resolve(true)));
405
+ });
406
+ if (ok) return p;
407
+ }
408
+ fail("NO_FREE_PORT", `No free port between ${start} and ${start + 49}. Pass --port <n>.`);
366
409
  }
367
410
 
368
411
  // ── monty dev ──────────────────────────────────────────────────────────────
@@ -373,7 +416,10 @@ async function dev() {
373
416
  }
374
417
  const meta = await compileConfig(appDir);
375
418
  const host = loadConfig()?.host ?? DEFAULT_HOST;
376
- const port = Number(flag("port") ?? 5173);
419
+ // Auto-pick a free port (agents run several apps side by side); an
420
+ // explicit --port is honored strictly.
421
+ const requested = flag("port");
422
+ const port = requested ? Number(requested) : await freePort(5173);
377
423
 
378
424
  console.log(`dev: starting vite on :${port} (app "${meta.slug}")`);
379
425
  const child = spawn("npx", ["vite", "dev", "--port", String(port), "--strictPort"], {
@@ -400,9 +446,9 @@ async function dev() {
400
446
  // implementation. Only catalog registries and core shadcn resolve.
401
447
 
402
448
  function requireAppDir(cmd) {
403
- const appDir = process.cwd();
404
- if (!existsSync(join(appDir, "monty.config.ts"))) {
405
- fail("NOT_A_MONTY_APP", `No monty.config.ts here. Run \`monty ${cmd}\` from your app's root directory.`);
449
+ const appDir = findAppRoot(process.cwd());
450
+ if (!appDir) {
451
+ fail("NOT_A_MONTY_APP", `Not inside a Monty app. \`monty apps\` lists local apps; cd "$(monty select <slug>)" jumps to one — then run \`monty ${cmd}\`.`);
406
452
  }
407
453
  return appDir;
408
454
  }
@@ -642,20 +688,32 @@ switch (command) {
642
688
  installSkills({ appDir: findAppRoot(process.cwd()), silent: false });
643
689
  console.log("skills: up to date");
644
690
  break;
691
+ case "install":
692
+ installDeps();
693
+ break;
694
+ case "build":
695
+ buildApp();
696
+ break;
697
+ case "typecheck":
698
+ typecheckApp();
699
+ break;
645
700
  case "deploy":
646
701
  await deploy();
647
702
  break;
648
703
  default:
649
- console.log("usage: monty <login|create|current|select|apps|dev|add|components|docs|deploy|skills>");
704
+ console.log("usage: monty <login|create|current|select|apps|install|dev|build|typecheck|add|components|docs|deploy|skills>");
650
705
  console.log(" login [--host <url>] [--key <mk_...>] sign in (opens your browser to authorize)");
651
706
  console.log(" create <slug> [--name N] [--icon I] [--build ID] stamp a new app into ~/Monty/<slug>");
652
- console.log(" dev [--port 5173] run the app locally (sandboxed data)");
707
+ console.log(" dev [--port N] run locally, auto-picks a free port (sandboxed data)");
653
708
  console.log(" add <name...> install curated UI components (see `monty components`)");
654
709
  console.log(" components [query] list the curated component catalog");
655
710
  console.log(" docs <name> view a component's source before installing");
656
711
  console.log(" current which app folder am I in?");
657
712
  console.log(" select <slug> print an app's folder — cd \"$(monty select x)\"");
658
713
  console.log(" apps list local apps in ~/Monty");
714
+ console.log(" install install app dependencies");
715
+ console.log(" build production build (vite, via monty)");
716
+ console.log(" typecheck typecheck (builds first if needed)");
659
717
  console.log(" deploy build + upload this app");
660
718
  console.log(" skills install/refresh the agent build skill");
661
719
  process.exit(command ? 1 : 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@montytools/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "monty": "./bin/monty.mjs"
@@ -19,21 +19,25 @@ the territory.
19
19
  2. **The loop:** `monty create <slug> --name "Name" --icon <lucide-icon>` →
20
20
  (if the prompt includes a `build id`, pass it: `--build <id>` — the
21
21
  workspace's New app screen tracks your progress live) →
22
- edit `monty.config.ts` (zod tables) + `src/routes/` → verify with
22
+ `monty install` → edit `monty.config.ts` (zod tables) + `src/routes/` → verify with
23
23
  `monty dev` (localhost:5173, already authenticated, sandboxed data) →
24
24
  `monty deploy`. You are done when deploy prints the URL.
25
- 3. **One import surface:** `@montytools/sdk` (`defineApp`, zod) and
25
+ 3. **Everything through the CLI.** `monty install`, `monty build`,
26
+ `monty typecheck`, `monty dev`, `monty deploy` — never run vite, tsc,
27
+ pnpm, or npm scripts directly. `monty dev` auto-picks a free port and
28
+ prints it; `monty typecheck` builds first when needed.
29
+ 4. **One import surface:** `@montytools/sdk` (`defineApp`, zod) and
26
30
  `@montytools/sdk/react` (hooks: `useList`, `useInsert`, …). Never import
27
31
  Clerk or Convex directly; never fetch external APIs from app code — the
28
32
  platform CSP blocks them.
29
- 4. **Schema is zod in `monty.config.ts`.** Field names `_*`, `updatedAt`,
33
+ 5. **Schema is zod in `monty.config.ts`.** Field names `_*`, `updatedAt`,
30
34
  `createdBy` are reserved. Push happens automatically on dev/deploy.
31
- 5. **UI is stock shadcn** (preset already wired). Add curated components with
35
+ 6. **UI is stock shadcn** (preset already wired). Add curated components with
32
36
  `monty add <name>`; browse with `monty components` / `monty docs <name>`.
33
- 6. **Errors are instructions.** Every failure prints
37
+ 7. **Errors are instructions.** Every failure prints
34
38
  `[MontyError CODE] Fix: …` — do exactly what the Fix says; don't guess.
35
39
  Typecheck failures block deploy by design.
36
- 7. **Verify before deploy.** `monty dev` writes to a `#dev` sandbox — live
40
+ 8. **Verify before deploy.** `monty dev` writes to a `#dev` sandbox — live
37
41
  team records are never touched, so exercise the app for real.
38
42
 
39
43
  ## CLI reference
@@ -43,7 +47,8 @@ the territory.
43
47
  | `monty login` | browser sign-in (loopback authorize), once per machine |
44
48
  | `monty create <slug>` | stamp a new app into `~/Monty/<slug>` |
45
49
  | `monty current` / `select` / `apps` | where am I / jump to app / list local |
46
- | `monty dev` | run locally on :5173, sandboxed data, auto-auth |
50
+ | `monty install` / `build` / `typecheck` | full lifecycle via the CLI no raw pnpm/vite/tsc |
51
+ | `monty dev` | run locally (auto-picks a free port), sandboxed data, auto-auth |
47
52
  | `monty add <name…>` | install curated shadcn components |
48
53
  | `monty deploy` | build + typecheck + upload; app appears in the workspace |
49
54
  | `monty skills` | (re)install this skill for your agent |
@@ -102,14 +102,18 @@ Every platform error is one line shaped like:
102
102
 
103
103
  ## Dev loop
104
104
 
105
+ Everything goes through the `monty` CLI — never run vite, tsc, pnpm, or npm
106
+ scripts directly:
107
+
105
108
  ```
106
- pnpm dev # Vite + HMR on :5173; sign in with your workspace account
109
+ monty install # dependencies
110
+ monty dev # Vite + HMR, auto-picks a free port and prints it
107
111
  ```
108
112
 
109
- Headless? Verify with `pnpm exec vite build` then `pnpm exec tsc --noEmit` in
110
- that order: the first build generates `src/routeTree.gen.ts`, without which
111
- typecheck fails on a fresh app. `monty deploy` runs both itself (it never
112
- uploads code that doesn't compile), so deploy is self-verifying.
113
+ Headless? Verify with `monty build` then `monty typecheck` (typecheck builds
114
+ first when needed — the build generates `src/routeTree.gen.ts`). `monty
115
+ deploy` runs both itself (it never uploads code that doesn't compile), so
116
+ deploy is self-verifying.
113
117
 
114
118
  **Driving your app in a browser (agents):** while `monty dev` runs, opening
115
119
  `http://localhost:5173` is ALREADY AUTHENTICATED — no sign-in screen (the dev