@alori/cli 0.1.0 → 0.1.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
@@ -4,14 +4,18 @@ Build your Alori app with your own Claude Code.
4
4
 
5
5
  ```bash
6
6
  npm install -g @alori/cli # once
7
- alori login # connect this computer to your Alori account
8
- alori pull my-app # download your app's code
9
- cd my-app && pnpm install
10
- claude # change it with Claude Code
7
+ alori dev # signs you in, downloads your app, installs it and opens it on this computer
8
+ claude # in the app's folder: change it with Claude Code, and watch it change
11
9
  alori push -m "New pricing page"
12
10
  ```
13
11
 
14
12
  Alori builds each push, shows it in your workspace preview and saves it as a version. Publish it from Alori when it
15
13
  looks right. How it works: `docs/CLAUDE_CODE.md` in Alori's repository.
16
14
 
17
- No dependencies; Node 20 or newer, and `tar`.
15
+ `alori dev` runs the app from your files against its real backend and data: screens and text change as you save,
16
+ backend changes (`convex/`) reach it with `alori push`.
17
+
18
+ The folder is a git repository: each pull is a commit by Alori, so it opens in GitHub Desktop and can go to your own
19
+ GitHub. A push to GitHub deploys nothing; only `alori push` does.
20
+
21
+ No dependencies; Node 20 or newer, and `tar`. pnpm is used when installed, through npx otherwise.
package/bin/alori.mjs CHANGED
@@ -5,11 +5,12 @@
5
5
  */
6
6
  import { resolve } from "node:path";
7
7
  import { apiBase, call, forget, login, SignedOut } from "../lib/auth.mjs";
8
- import { pull, push, status } from "../lib/sync.mjs";
8
+ import { dev, pull, push, status } from "../lib/sync.mjs";
9
9
 
10
10
  const help = `alori: build your Alori app with Claude Code
11
11
 
12
12
  alori login Connect this computer to your Alori account
13
+ alori dev [folder] Download your app, install it and run it on this computer (opens your browser)
13
14
  alori pull [folder] Download your app's code (or bring the latest into a pulled folder)
14
15
  alori status What changed since the last pull or push
15
16
  alori push -m "message" Send your changes: Alori builds them and saves a new version
@@ -23,6 +24,17 @@ function messageOf(args) {
23
24
  return index >= 0 ? args[index + 1] : undefined;
24
25
  }
25
26
 
27
+ /** Runs a command that needs a sign-in, signing in first when this computer isn't connected yet. */
28
+ async function signedIn(run) {
29
+ try {
30
+ await run();
31
+ } catch (error) {
32
+ if (!(error instanceof SignedOut)) throw error;
33
+ await login();
34
+ await run();
35
+ }
36
+ }
37
+
26
38
  async function main() {
27
39
  const [command, ...args] = process.argv.slice(2);
28
40
  switch (command) {
@@ -33,7 +45,7 @@ async function main() {
33
45
  console.log(me.body?.error === "cantBuild" ? "Connected, but your role doesn't build this app." : "Connected.");
34
46
  return;
35
47
  }
36
- console.log(`Connected to ${me.body.app} as ${me.body.email ?? "you"}. Next: alori pull <folder>`);
48
+ console.log(`Connected to ${me.body.app} as ${me.body.email ?? "you"}. Next: alori dev`);
37
49
  return;
38
50
  }
39
51
  case "logout":
@@ -46,8 +58,11 @@ async function main() {
46
58
  console.log(`${me.body.app} (version ${me.body.version ?? "none"}), signed in as ${me.body.email ?? "you"}.`);
47
59
  return;
48
60
  }
61
+ case "dev":
62
+ await signedIn(() => dev(args.find((arg) => !arg.startsWith("-"))));
63
+ return;
49
64
  case "pull":
50
- await pull(resolve(args.find((arg) => !arg.startsWith("-")) ?? "."));
65
+ await signedIn(() => pull(args.find((arg) => !arg.startsWith("-"))));
51
66
  return;
52
67
  case "status":
53
68
  status(resolve("."));
package/lib/auth.mjs CHANGED
@@ -54,7 +54,7 @@ export function forget() {
54
54
 
55
55
  const base64Url = (buffer) => buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
56
56
 
57
- function openBrowser(url) {
57
+ export function openBrowser(url) {
58
58
  const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
59
59
  const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
60
60
  try {
package/lib/dev.mjs ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * `alori dev`: the app running on this computer from the folder's files, against the app's own backend (its one
3
+ * Convex deployment, with real data). Screens and text change as files are saved; `convex/` changes reach the
4
+ * backend only with `alori push`.
5
+ */
6
+ import { spawn, spawnSync } from "node:child_process";
7
+ import { existsSync } from "node:fs";
8
+ import { createServer } from "node:net";
9
+ import { join } from "node:path";
10
+ import { openBrowser } from "./auth.mjs";
11
+
12
+ function fail(message) {
13
+ const error = new Error(message);
14
+ error.plain = true;
15
+ throw error;
16
+ }
17
+
18
+ const hasCommand = (name) => spawnSync(process.platform === "win32" ? "where" : "which", [name], { stdio: "ignore" }).status === 0;
19
+
20
+ /** Installs the app's packages with pnpm (the app's lockfile is pnpm's), through npx when pnpm isn't installed. */
21
+ export function install(dir) {
22
+ console.log("Installing packages (a minute the first time)...");
23
+ const [command, args] = hasCommand("pnpm") ? ["pnpm", ["install"]] : ["npx", ["--yes", "pnpm@11", "install"]];
24
+ const result = spawnSync(command, args, { cwd: dir, stdio: "inherit", shell: process.platform === "win32" });
25
+ if (result.status !== 0) fail("Installing packages failed. Fix what it says above, then run alori dev again.");
26
+ }
27
+
28
+ export const installed = (dir) => existsSync(join(dir, "node_modules", ".bin", "vite"));
29
+
30
+ /** The first free port from `from` on. */
31
+ function freePort(from) {
32
+ return new Promise((resolve) => {
33
+ const server = createServer();
34
+ server.once("error", () => resolve(freePort(from + 1)));
35
+ server.listen(from, "127.0.0.1", () => server.close(() => resolve(from)));
36
+ });
37
+ }
38
+
39
+ /** Runs the site until Ctrl-C, and opens it in the browser once it answers. */
40
+ export async function runLocally(dir, app, convexUrl) {
41
+ if (!convexUrl) fail("Alori didn't say where this app's backend is. Run alori pull, then try again.");
42
+ if (!installed(dir)) install(dir);
43
+ const port = await freePort(5300);
44
+ const url = `http://localhost:${port}`;
45
+ console.log(`\n${app} is starting at ${url} (Ctrl-C stops it).`);
46
+ console.log("Saved changes show at once. Send them to Alori with: alori push -m \"what changed\"\n");
47
+ const vite = join(dir, "node_modules", ".bin", process.platform === "win32" ? "vite.cmd" : "vite");
48
+ const child = spawn(vite, ["dev", "--port", String(port), "--strictPort"], {
49
+ cwd: dir,
50
+ stdio: "inherit",
51
+ shell: process.platform === "win32",
52
+ env: { ...process.env, VITE_CONVEX_URL: convexUrl },
53
+ });
54
+ let opened = false;
55
+ const opener = setInterval(async () => {
56
+ if (opened) return;
57
+ try {
58
+ await fetch(url, { signal: AbortSignal.timeout(1500) });
59
+ opened = true;
60
+ clearInterval(opener);
61
+ if (process.env.ALORI_NO_BROWSER !== "1") openBrowser(url);
62
+ } catch {
63
+ // Not answering yet.
64
+ }
65
+ }, 1000);
66
+ const stop = () => child.kill("SIGINT");
67
+ process.on("SIGINT", stop);
68
+ process.on("SIGTERM", stop);
69
+ await new Promise((resolve) => child.on("exit", resolve));
70
+ clearInterval(opener);
71
+ }
package/lib/git.mjs ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Git in the pulled folder, so GitHub Desktop, GitHub and Claude Code work with it. Each pull is a commit by Alori
3
+ * ("Pulled version 12"), apart from the person's own commits. Git stays on this computer: Alori never pushes to a
4
+ * remote, and a push to GitHub deploys nothing (only `alori push` does). A folder inside another repository is left
5
+ * alone: that repository is the person's to manage.
6
+ */
7
+ import { execFileSync } from "node:child_process";
8
+ import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
9
+ import { join } from "node:path";
10
+
11
+ /** Pull commits are Alori's, which also works on a computer where git has no name or email set. */
12
+ const asAlori = {
13
+ ...process.env,
14
+ GIT_AUTHOR_NAME: "Alori",
15
+ GIT_AUTHOR_EMAIL: "noreply@alori.dev",
16
+ GIT_COMMITTER_NAME: "Alori",
17
+ GIT_COMMITTER_EMAIL: "noreply@alori.dev",
18
+ };
19
+
20
+ function git(dir, args) {
21
+ return execFileSync("git", ["-C", dir, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], env: asAlori });
22
+ }
23
+
24
+ function hasGit() {
25
+ try {
26
+ execFileSync("git", ["--version"], { stdio: "ignore" });
27
+ return true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ /** "own": `dir` is the root of its own repository; "none": no repository; "parent": inside someone else's. */
34
+ function repoOf(dir) {
35
+ try {
36
+ const top = git(dir, ["rev-parse", "--show-toplevel"]).trim();
37
+ return realpathSync(top) === realpathSync(dir) ? "own" : "parent";
38
+ } catch {
39
+ return "none";
40
+ }
41
+ }
42
+
43
+ /** Lines every pulled folder's .gitignore needs: the template's own file comes fresh with each pull and lacks them. */
44
+ export function ensureIgnored(dir, lines) {
45
+ const file = join(dir, ".gitignore");
46
+ const current = existsSync(file) ? readFileSync(file, "utf8") : "";
47
+ const have = new Set(current.split("\n").map((line) => line.trim()));
48
+ const missing = lines.filter((line) => !have.has(line));
49
+ if (missing.length === 0) return;
50
+ writeFileSync(file, `${current}${current === "" || current.endsWith("\n") ? "" : "\n"}${missing.join("\n")}\n`);
51
+ }
52
+
53
+ /**
54
+ * Before a pull lays Alori's files down: whether the person has changes not committed yet. A pull commits only into a
55
+ * clean folder, so their work never lands inside Alori's commit.
56
+ */
57
+ export function hadChanges(dir) {
58
+ if (repoOf(dir) !== "own") return false;
59
+ try {
60
+ return git(dir, ["status", "--porcelain"]).trim() !== "";
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ /** After a pull: starts the repository when there is none, and commits what the pull brought. */
67
+ export function commitPull(dir, version, { hadChanges }) {
68
+ if (!hasGit()) return;
69
+ const repo = repoOf(dir);
70
+ if (repo === "parent") return;
71
+ try {
72
+ if (repo === "none") {
73
+ git(dir, ["init", "-b", "main"]);
74
+ git(dir, ["add", "-A"]);
75
+ git(dir, ["commit", "-q", "-m", `Pulled version ${version} from Alori`]);
76
+ console.log("Started git in this folder: open it in GitHub Desktop, or add your own GitHub remote.");
77
+ return;
78
+ }
79
+ if (hadChanges) {
80
+ console.log("Your folder had changes not committed, so this pull isn't a commit of its own. Commit when ready.");
81
+ return;
82
+ }
83
+ git(dir, ["add", "-A"]);
84
+ if (git(dir, ["status", "--porcelain"]).trim() === "") return;
85
+ git(dir, ["commit", "-q", "-m", `Pulled version ${version} from Alori`]);
86
+ } catch (error) {
87
+ console.log(`Git couldn't commit this pull (${String(error.stderr ?? error.message).trim().split("\n")[0]}). Your files are pulled.`);
88
+ }
89
+ }
package/lib/guide.mjs CHANGED
@@ -16,10 +16,22 @@ with \`alori push\`. Alori builds them, deploys them, and shows them in the work
16
16
  even before Publish. Never drop a table or a field that holds data.
17
17
  - \`convex/_generated/\` and \`src/routeTree.gen.ts\` are generated: never edit them.
18
18
 
19
+ ## Git and GitHub
20
+
21
+ This folder is a git repository, and each \`alori pull\` is a commit by Alori ("Pulled version 12 from Alori"), so
22
+ \`git log\` shows Alori's changes apart from yours. Commit your own work as usual, and push it to your own GitHub if you
23
+ like. **GitHub is only a copy:** a push to GitHub deploys nothing. Only \`alori push\` sends changes to the app.
24
+
25
+ ## Seeing changes
26
+
27
+ \`alori dev\` runs the app at http://localhost:5300 (or the next free port) from this folder's files, against the app's
28
+ real backend and data. Screens, text and styles change as files are saved. A change under \`convex/\` reaches the backend
29
+ only with \`alori push\`. Keep \`alori dev\` running and check each change there before pushing.
30
+
19
31
  ## Commands
20
32
 
21
33
  \`\`\`bash
22
- pnpm install # once, after a pull
34
+ alori dev # runs the app on this computer and opens it; saved changes show at once
23
35
  pnpm typecheck # before each push
24
36
  pnpm lint
25
37
  alori status # what changed since the last pull or push
package/lib/sync.mjs CHANGED
@@ -6,9 +6,11 @@
6
6
  import { execFileSync } from "node:child_process";
7
7
  import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
8
8
  import { tmpdir } from "node:os";
9
- import { dirname, join } from "node:path";
9
+ import { basename, dirname, join, resolve } from "node:path";
10
10
  import { apiBase, call } from "./auth.mjs";
11
11
  import { changesOf, codeHashes, isAppCode, readState, stateDir, walk, writeState } from "./folder.mjs";
12
+ import { install, installed, runLocally } from "./dev.mjs";
13
+ import { commitPull, ensureIgnored, hadChanges } from "./git.mjs";
12
14
  import { claudeGuide } from "./guide.mjs";
13
15
 
14
16
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -70,13 +72,15 @@ function copyInto(from, to, path) {
70
72
  copyFileSync(join(from, path), join(to, path));
71
73
  }
72
74
 
73
- const ignoreFile = `node_modules/
74
- ${stateDir}/
75
- dist/
76
- .output/
77
- .tanstack/
78
- .env*
79
- *.alori-theirs
75
+ /** Kept out of git: installed packages, builds, secrets, the pull snapshot and Alori's copies of overlapping files. */
76
+ const ignoreLines = ["node_modules/", `${stateDir}/`, "dist/", ".output/", ".tanstack/", ".vercel/", ".env*", "*.alori-theirs"];
77
+
78
+ /** pnpm 11 stops `pnpm install` until each package's build script is allowed or refused. */
79
+ const workspaceFile = `allowBuilds:
80
+ esbuild: true
81
+ onnxruntime-node: true
82
+ protobufjs: true
83
+ sharp: true
80
84
  `;
81
85
 
82
86
  /** A first pull into an empty folder. */
@@ -86,10 +90,12 @@ async function pullFresh(dir, me) {
86
90
  for (const path of walk(folder).filter((path) => !templateNotes.has(path))) copyInto(folder, dir, path);
87
91
  rmSync(temp, { recursive: true, force: true });
88
92
  writeFileSync(join(dir, "CLAUDE.md"), claudeGuide(me.app));
89
- if (!existsSync(join(dir, ".gitignore"))) writeFileSync(join(dir, ".gitignore"), ignoreFile);
93
+ ensureIgnored(dir, ignoreLines);
94
+ if (!existsSync(join(dir, "pnpm-workspace.yaml"))) writeFileSync(join(dir, "pnpm-workspace.yaml"), workspaceFile);
90
95
  writeState(dir, { api: apiBase(), appId: me.appId, app: me.app, version, hashes: codeHashes(dir) });
91
96
  console.log(`Pulled ${me.app}, version ${version}, into ${dir}`);
92
- console.log("Next: pnpm install, then change it with Claude Code, then: alori push -m \"what changed\"");
97
+ commitPull(dir, version, { hadChanges: false });
98
+ install(dir);
93
99
  }
94
100
 
95
101
  /**
@@ -98,6 +104,7 @@ async function pullFresh(dir, me) {
98
104
  */
99
105
  async function pullOver(dir, state, me) {
100
106
  const { folder, temp, version } = await download();
107
+ const uncommitted = hadChanges(dir);
101
108
  const remote = codeHashes(folder);
102
109
  const local = codeHashes(dir);
103
110
  const overlaps = [];
@@ -120,10 +127,15 @@ async function pullOver(dir, state, me) {
120
127
  }
121
128
  }
122
129
  // Alori's template files (package.json, vite.config.ts, public/…) always come fresh.
130
+ const lockfile = (root) => (existsSync(join(root, "pnpm-lock.yaml")) ? readFileSync(join(root, "pnpm-lock.yaml"), "utf8") : "");
131
+ const packagesChanged = lockfile(folder) !== lockfile(dir);
123
132
  for (const path of walk(folder).filter((path) => !isAppCode(path) && !templateNotes.has(path))) copyInto(folder, dir, path);
124
133
  rmSync(temp, { recursive: true, force: true });
134
+ ensureIgnored(dir, ignoreLines);
125
135
  writeState(dir, { api: apiBase(), appId: me.appId, app: me.app, version, hashes: remote });
126
136
  console.log(`Pulled ${me.app}, version ${version}.`);
137
+ commitPull(dir, version, { hadChanges: uncommitted });
138
+ if (packagesChanged || !installed(dir)) install(dir);
127
139
  if (overlaps.length > 0) {
128
140
  console.log("\nThese files changed both here and in Alori. Yours are kept; Alori's are beside them as .alori-theirs:");
129
141
  for (const path of overlaps) console.log(` ${path}`);
@@ -141,8 +153,25 @@ function checkSameApp(state, me) {
141
153
  if (state.appId && state.appId !== me.appId) fail(`This folder holds ${state.app}, but you're signed in to ${me.app}. Run alori login with the right account.`);
142
154
  }
143
155
 
144
- export async function pull(dir) {
156
+ /** A folder name from the app's name: "Pro-Quai Inc" → pro-quai-inc. */
157
+ const folderNameOf = (app) =>
158
+ app
159
+ .normalize("NFD")
160
+ .replace(/[\u0300-\u036f]/g, "")
161
+ .toLowerCase()
162
+ .replace(/[^a-z0-9]+/g, "-")
163
+ .replace(/^-+|-+$/g, "") || "alori-app";
164
+
165
+ /** Where a command works: the folder named, else this one when it was pulled, else a new folder named after the app. */
166
+ function folderFor(named, me) {
167
+ if (named) return resolve(named);
168
+ if (readState(resolve("."))) return resolve(".");
169
+ return resolve(folderNameOf(me.app));
170
+ }
171
+
172
+ export async function pull(named) {
145
173
  const me = await whoAmI();
174
+ const dir = folderFor(named, me);
146
175
  const state = readState(dir);
147
176
  if (state) {
148
177
  checkSameApp(state, me);
@@ -151,6 +180,21 @@ export async function pull(dir) {
151
180
  }
152
181
  if (existsSync(dir) && readdirSync(dir).some((name) => name !== ".DS_Store")) fail(`${dir} isn't empty. Pull into a new folder: alori pull <folder>`);
153
182
  await pullFresh(dir, me);
183
+ const move = dir === resolve(".") ? "" : `cd ${basename(dir)} && `;
184
+ console.log(`\nReady. Run it on this computer: ${move}alori dev`);
185
+ }
186
+
187
+ /** `alori dev`: pulls the app first when there is no pulled folder, installs what's missing, and runs it here. */
188
+ export async function dev(named) {
189
+ const me = await whoAmI();
190
+ const dir = folderFor(named, me);
191
+ const state = readState(dir);
192
+ if (state) checkSameApp(state, me);
193
+ else {
194
+ if (existsSync(dir) && readdirSync(dir).some((name) => name !== ".DS_Store")) fail(`${dir} isn't empty and wasn't pulled from Alori. Run alori dev <new folder>.`);
195
+ await pullFresh(dir, me);
196
+ }
197
+ await runLocally(dir, me.app, me.convexUrl);
154
198
  }
155
199
 
156
200
  export function status(dir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alori/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Build your Alori app with your own Claude Code: pull its code, change it, push it back.",
5
5
  "type": "module",
6
6
  "bin": {