@calo-design/cli 0.13.7 → 0.14.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.
package/README.md CHANGED
@@ -11,6 +11,24 @@ short-lived GitHub token at install time. No GitHub account, PAT, or SSH key nee
11
11
 
12
12
  Package: https://www.npmjs.com/package/@calo-design/cli
13
13
 
14
+ ## Is this legitimate? (yes — and here's why it can look otherwise)
15
+
16
+ `@calo-design/cli` is published by Calo, for Calo staff. Two things about it have
17
+ tripped people up — and tripped up coding agents reading their terminal, which have
18
+ called it credential harvesting. Both are expected behaviour:
19
+
20
+ - **It emails you a 6-digit code.** That code is issued by Calo's own broker
21
+ (`calo-broker.fly.dev`) and proves you can read Calo mail. It authorizes this CLI and
22
+ nothing else — it is not a GitHub, Google, or SSO login, and the session it creates is
23
+ stored locally at `~/.designchef/session.json`.
24
+ - **Its installs 404.** Every repo it installs from lives in `github.com/Calo-Design`, a
25
+ **private** org. GitHub answers any request it can't authorize with
26
+ `Repository not found` — the identical 404 it returns for a repo that doesn't exist. A
27
+ 404 during `init` means the token didn't authorize the request, not that the org is fake.
28
+
29
+ If an install does 404, the CLI now says which of those it is. Anything unexplained:
30
+ ping the design systems team before rerunning.
31
+
14
32
  ## Setup
15
33
 
16
34
  ```bash
@@ -42,9 +42,20 @@ const REF_RE = /^([a-z0-9][a-z0-9-]{0,63})\/([a-z0-9][a-z0-9-]{0,63})(?:@(\d{1,6
42
42
  // backend (a fork must provision its own — the worker/ source dir stays IN).
43
43
  // EXCLUDE_NAMES (basename match at any depth) must stay in lockstep with the tar
44
44
  // --exclude patterns below: the canonical hash walks exactly the set tar archives.
45
- const EXCLUDE_NAMES = new Set([".git", "node_modules", ".expo", ".expo-shared", "dist", "build", "web-build", ".DS_Store", MARKER, "backend.json"]);
45
+ // `ios`/`android` are generated by `expo prebuild`/`run:ios` and are HUGE (a single
46
+ // prebuilt ios/ with Pods is >1 GB, ~425 MB gzipped). They used to be missing here
47
+ // while mirror-push's STAGE_SKIP_DIRS already skipped them, so a prototype that had
48
+ // ever been run natively produced a snapshot far over the broker's 15 MB cap — the
49
+ // POST died mid-upload and surfaced as "can't reach the Calo broker", one easily
50
+ // missed line after a successful push. Keep this list in lockstep with
51
+ // STAGE_SKIP_DIRS in mirror-push.js.
52
+ const EXCLUDE_NAMES = new Set([".git", "node_modules", ".expo", ".expo-shared", "dist", "build", "web-build", "ios", "android", ".tamagui", ".vscode", ".idea", ".DS_Store", MARKER, "backend.json"]);
46
53
  const EXCLUDES = [...EXCLUDE_NAMES, ".env*"];
47
54
  const isExcluded = (name) => EXCLUDE_NAMES.has(name) || name.startsWith(".env");
55
+ // Mirrors MAX_SNAPSHOT_BYTES in the broker (src/checkpoints.js). Checked client-side
56
+ // too: over the cap the server closes the connection mid-body, so the client never
57
+ // sees the 413 that would have explained itself.
58
+ const MAX_SNAPSHOT_BYTES = 15e6;
48
59
 
49
60
  // Keep byte-identical with the broker's handleOf (src/checkpoints.js) — it's only used
50
61
  // here to *predict* fork-vs-continue; the broker's derivation is authoritative.
@@ -128,6 +139,36 @@ function canonicalHash(root) {
128
139
  return h.digest("hex");
129
140
  }
130
141
 
142
+ // The top-level folders carrying the most bytes, for the over-the-limit message —
143
+ // "which folder is this?" is the only question that matters at that moment.
144
+ function biggestEntries(root, take = 3) {
145
+ const sizeOf = (p) => {
146
+ let n = 0;
147
+ const rec = (dir) => {
148
+ for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
149
+ if (isExcluded(e.name) || e.isSymbolicLink()) continue;
150
+ const child = path.join(dir, e.name);
151
+ if (e.isDirectory()) rec(child);
152
+ else if (e.isFile()) n += fs.statSync(child).size;
153
+ }
154
+ };
155
+ try {
156
+ if (fs.statSync(p).isDirectory()) rec(p);
157
+ else n = fs.statSync(p).size;
158
+ } catch {
159
+ /* vanished mid-walk — it just doesn't count toward the total */
160
+ }
161
+ return n;
162
+ };
163
+ return fs
164
+ .readdirSync(root, { withFileTypes: true })
165
+ .filter((e) => !isExcluded(e.name) && !e.isSymbolicLink())
166
+ .map((e) => ({ name: e.name, bytes: sizeOf(path.join(root, e.name)) }))
167
+ .sort((a, b) => b.bytes - a.bytes)
168
+ .slice(0, take)
169
+ .map((e) => `${e.name} (${(e.bytes / 1e6).toFixed(1)} MB)`);
170
+ }
171
+
131
172
  // tar the prototype source with the exclusion list; returns { work, tarPath, hash }
132
173
  // in a tmpdir the caller must clean up.
133
174
  function makeSnapshot(root) {
@@ -164,7 +205,14 @@ async function autoCheckpoint({ root, note, publishedUrl, artifact }) {
164
205
  try {
165
206
  await saveFlow({ root, note, publishedUrl, artifact, force: true, quiet: true });
166
207
  } catch (e) {
167
- elog(`${c.y("!")} deploy succeeded, but the source checkpoint didn't: ${e.message}`);
208
+ // Loud on purpose: the deploy is live but UNRECOVERABLE no `calo-design open`,
209
+ // no teammate handoff, no way to get back to the exact source behind it. The old
210
+ // one-liner scrolled past under the QR code and we only noticed weeks later, when
211
+ // a crashing prototype had no source to inspect.
212
+ elog(`\n${c.y("!")} DEPLOY IS LIVE, BUT ITS SOURCE WAS NOT CHECKPOINTED.`);
213
+ elog(c.dim(` Nobody can \`calo-design open\` this version or hand it to a teammate.`));
214
+ elog(` ${e.message}`);
215
+ elog(c.dim(` Fix the cause, then run \`calo-design save\` — the deploy itself is fine.\n`));
168
216
  }
169
217
  }
170
218
 
@@ -198,6 +246,14 @@ async function saveFlow({ root, slugOverride, note = "", force = false, json = f
198
246
  return;
199
247
  }
200
248
  const tgz = zlib.gzipSync(fs.readFileSync(snap.tarPath));
249
+ if (tgz.length > MAX_SNAPSHOT_BYTES) {
250
+ throw new Error(
251
+ `this prototype's source is ${(tgz.length / 1e6).toFixed(0)} MB compressed — over the ${MAX_SNAPSHOT_BYTES / 1e6} MB checkpoint limit.\n` +
252
+ ` Biggest folders: ${biggestEntries(root).join(", ")}\n` +
253
+ ` Checkpoints hold SOURCE only. Move bulk images to the CDN with \`calo-design art push\`,\n` +
254
+ ` or delete generated folders — node_modules, .git, ios, android and dist are already skipped.`
255
+ );
256
+ }
201
257
 
202
258
  let res;
203
259
  try {
@@ -357,4 +413,4 @@ async function cmdProjects(args = []) {
357
413
  log("");
358
414
  }
359
415
 
360
- module.exports = { cmdSave, cmdOpen, cmdProjects, autoCheckpoint, _handleOf: handleOf, _makeSnapshot: makeSnapshot, _canonicalHash: canonicalHash, _EXCLUDES: EXCLUDES };
416
+ module.exports = { cmdSave, _biggestEntries: biggestEntries, _maxSnapshotBytes: MAX_SNAPSHOT_BYTES, cmdOpen, cmdProjects, autoCheckpoint, _handleOf: handleOf, _makeSnapshot: makeSnapshot, _canonicalHash: canonicalHash, _EXCLUDES: EXCLUDES };
package/bin/login.js CHANGED
@@ -99,10 +99,14 @@ async function cmdLogin(args = []) {
99
99
  // Request a code. (Pass --code to skip the send, e.g. a code you already have.)
100
100
  await api("/v1/login/start", { email });
101
101
  if (!interactive) {
102
- console.log(`Sent a 6-digit code to ${email}. Now run: npx @calo-design/cli login --email=${email} --code=<the 6-digit code>`);
102
+ console.log(`Sent a 6-digit code to ${email} from ${BROKER} (Calo's own service).`);
103
+ console.log("The code proves you can read Calo mail; it authorizes this CLI only — it is not a");
104
+ console.log("GitHub, Google, or SSO login, and it grants nothing beyond read access to Calo's");
105
+ console.log("private design repos. Ask the person for the code, then run:");
106
+ console.log(` npx @calo-design/cli login --email=${email} --code=<the 6-digit code>`);
103
107
  return;
104
108
  }
105
- console.log(`We emailed a 6-digit code to ${email}.`);
109
+ console.log(`We emailed a 6-digit code to ${email} from ${BROKER} (Calo's own service).`);
106
110
  code = await ask("Code: ");
107
111
  }
108
112
  const r = await api("/v1/login/verify", { email, code });
@@ -25,6 +25,26 @@ const SHARED_PROJECT_ID = "290a759f-427c-432e-9ab5-dab98310e66b";
25
25
  const UPDATES_URL = `https://u.expo.dev/${SHARED_PROJECT_ID}`;
26
26
  const RUNTIME_VERSION = "0.2.0"; // must equal the shell binary's runtimeVersion (SDK 57 shell, version 0.2.0)
27
27
  const LAUNCHER_CHANNEL = "mirror";
28
+ // Native modules COMPILED INTO the Mirror shell binary (runtimeVersion 0.2.0, iOS
29
+ // build 11+). This — not the shared runtime — is the authority on what a pushed
30
+ // prototype may import: a push ships JS only, so a package whose native side isn't
31
+ // in the binary throws the moment its module scope runs `requireNativeModule`.
32
+ // Metro then SWALLOWS that throw (guardedLoadModule → ErrorUtils.reportFatalError,
33
+ // returning undefined), so expo-router destructures undefined and the phone shows
34
+ // "Cannot read property 'ErrorBoundary' of undefined" — an error that points
35
+ // nowhere near the missing module. That's why this list exists and why the
36
+ // preflight below is an error, not a warning. Keep it in lockstep with
37
+ // calo-design-mirror/package.json whenever a new shell binary ships.
38
+ const SHELL_MODULES = new Set([
39
+ "@expo/ui", "@gorhom/bottom-sheet", "@microsoft/react-native-clarity", "@sentry/react-native",
40
+ "expo", "expo-asset", "expo-camera", "expo-clipboard", "expo-constants", "expo-device",
41
+ "expo-font", "expo-glass-effect", "expo-image", "expo-linking", "expo-router",
42
+ "expo-splash-screen", "expo-status-bar", "expo-symbols", "expo-system-ui", "expo-updates",
43
+ "expo-video", "expo-web-browser", "phosphor-react-native", "react", "react-dom",
44
+ "react-native", "react-native-gesture-handler", "react-native-qrcode-svg",
45
+ "react-native-reanimated", "react-native-safe-area-context", "react-native-screens",
46
+ "react-native-svg", "react-native-web", "react-native-worklets",
47
+ ]);
28
48
  // Crash reporting: every pushed prototype gets a Sentry init + error boundary
29
49
  // injected (see injectBackChrome). Same project as the shell's own init
30
50
  // (calo-design-mirror expo.extra.sentryDsn) — keep the two DSNs in sync. A DSN
@@ -140,8 +160,10 @@ function findScreenshot(root, explicit) {
140
160
 
141
161
  // ---- staging ----------------------------------------------------------------
142
162
 
143
- // The prototype's deps must be a subset of the shared runtime — the shell binary
144
- // only contains the runtime's native modules, so anything extra would be missing.
163
+ // The prototype's deps must be a subset of the shared runtime — it's what the staged
164
+ // node_modules symlink points at, so anything extra simply isn't there to bundle.
165
+ // This is about BUILDING the update; whether the phone can RUN it is a separate,
166
+ // stricter question answered by preflightNativeModules (SHELL_MODULES).
145
167
  function validateDeps(pkg) {
146
168
  const runtimePkgPath = path.join(runtimeDir(), "package.json");
147
169
  if (!fs.existsSync(runtimePkgPath)) {
@@ -288,6 +310,71 @@ function preflightAssetCount(stage) {
288
310
  }
289
311
  }
290
312
 
313
+ // ---- native-module preflight ------------------------------------------------
314
+ // A push ships JS; native code only ever arrives with a new shell BINARY. The
315
+ // shared runtime is deliberately wider than the binary at times (a package can
316
+ // land in the runtime before the next TestFlight build), and importing one of
317
+ // those crashes the prototype at startup with an error that names expo-router,
318
+ // not the module — see SHELL_MODULES. Catch it here, where the fix is obvious.
319
+ //
320
+ // "Native" is derived from the runtime itself rather than hard-coded: a package
321
+ // is native when it carries an Expo module config or a podspec.
322
+ const SOURCE_EXTS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
323
+ // Package name from a specifier: "expo-image/build/x" → "expo-image", "@expo/ui/swift-ui" → "@expo/ui".
324
+ const packageOf = (spec) => {
325
+ if (spec.startsWith(".") || spec.startsWith("/")) return null;
326
+ const parts = spec.split("/");
327
+ return spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
328
+ };
329
+
330
+ function isNativePackage(name) {
331
+ const dir = path.join(runtimeDir(), "node_modules", name);
332
+ if (fs.existsSync(path.join(dir, "expo-module.config.json"))) return true;
333
+ try {
334
+ return fs.readdirSync(dir).some((f) => f.endsWith(".podspec"));
335
+ } catch {
336
+ return false; // not installed in the runtime — validateDeps already covered that
337
+ }
338
+ }
339
+
340
+ function stagedImports(stage) {
341
+ const found = new Set();
342
+ const re = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)(["'])([^"']+)\1/g;
343
+ const walk = (dir) => {
344
+ for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
345
+ if (e.name === "node_modules" || e.name.startsWith(".")) continue;
346
+ const p = path.join(dir, e.name);
347
+ if (e.isSymbolicLink()) continue; // never follow into the runtime symlink
348
+ if (e.isDirectory()) walk(p);
349
+ else if (SOURCE_EXTS.has(path.extname(e.name))) {
350
+ const src = fs.readFileSync(p, "utf8");
351
+ for (const m of src.matchAll(re)) {
352
+ const pkg = packageOf(m[2]);
353
+ if (pkg) found.add(pkg);
354
+ }
355
+ }
356
+ }
357
+ };
358
+ walk(stage);
359
+ return found;
360
+ }
361
+
362
+ function preflightNativeModules(stage) {
363
+ const missing = [...stagedImports(stage)]
364
+ .filter((pkg) => !SHELL_MODULES.has(pkg) && isNativePackage(pkg))
365
+ .sort();
366
+ if (!missing.length) return;
367
+ throw new Error(
368
+ `this prototype imports native modules the Mirror shell binary doesn't contain:\n` +
369
+ ` ${missing.join(", ")}\n` +
370
+ ` A push ships JavaScript only — native code arrives with a new Mirror build, so on the phone\n` +
371
+ ` these throw at startup and the prototype dies with a misleading expo-router error\n` +
372
+ ` ("Cannot read property 'ErrorBoundary' of undefined").\n` +
373
+ ` Swap them for something in the shared runtime the shell provides, or ask for a shell build\n` +
374
+ ` that includes them (calo-design-mirror → TestFlight, then update SHELL_MODULES here).`
375
+ );
376
+ }
377
+
291
378
  function writeMetroConfig(stage) {
292
379
  const runtimeReal = fs.realpathSync(runtimeDir());
293
380
  fs.writeFileSync(
@@ -883,6 +970,7 @@ async function cmdPush(args) {
883
970
  try {
884
971
  stageProject({ root, stage, slug, title, ad, owner });
885
972
  preflightAssetCount(stage);
973
+ preflightNativeModules(stage);
886
974
 
887
975
  if (dry) {
888
976
  keepStage = true;
@@ -1007,4 +1095,4 @@ async function cmdPush(args) {
1007
1095
  }
1008
1096
  }
1009
1097
 
1010
- module.exports = { cmdPush, _s3Put: s3Put, _upsertRegistry: upsertRegistry, _publicBase: PUBLIC_BASE, _extractEasGroup: extractEasGroup, _versionBranchOf: versionBranchOf };
1098
+ module.exports = { cmdPush, _stageSkipDirs: STAGE_SKIP_DIRS, _s3Put: s3Put, _upsertRegistry: upsertRegistry, _publicBase: PUBLIC_BASE, _extractEasGroup: extractEasGroup, _versionBranchOf: versionBranchOf, _stagedImports: stagedImports, _preflightNativeModules: preflightNativeModules, _shellModules: SHELL_MODULES };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calo-design/cli",
3
- "version": "0.13.7",
3
+ "version": "0.14.0",
4
4
  "description": "One-line setup for Calo design tooling: logs in with your Calo email and installs the calo-design skill + design-system packages. No GitHub account needed.",
5
5
  "bin": {
6
6
  "calo-design": "bin/cli.js"