clivly 0.10.7 → 0.10.9

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
@@ -530,7 +530,11 @@ subpaths:
530
530
 
531
531
  ```ts
532
532
  import { createClivlySDK, defineClivlyConfig } from "clivly/sdk";
533
- import { fromDrizzle, discoverFromDrizzle } from "clivly/drizzle";
533
+ import {
534
+ fromDrizzle,
535
+ fromDrizzleProjection,
536
+ discoverFromDrizzle,
537
+ } from "clivly/drizzle";
534
538
  import { clivlyVite } from "clivly/vite";
535
539
  import { createClerkAuthAdapter } from "clivly/auth/clerk";
536
540
  import { createWorkOSAuthAdapter } from "clivly/auth/workos";
@@ -542,6 +546,32 @@ import { createBetterAuthAdapter } from "clivly/auth/better-auth";
542
546
  > importing it from app code drags the whole CLI into your bundle and throws at
543
547
  > import time on Workers and other edge runtimes.
544
548
 
549
+ ### Projection entities need `fromDrizzleProjection`
550
+
551
+ An entity with a `projection` spans several tables. `fromDrizzle` emits a
552
+ single-table select, so pairing it with a projection pushes bare base-table rows
553
+ and every joined field mirrors empty. Use the projection builder instead:
554
+
555
+ ```ts
556
+ source: {
557
+ custom: [
558
+ fromDrizzleProjection(db, clientAccountsProjection, {
559
+ entity: "client_accounts",
560
+ objectType: "client-accounts",
561
+ cursorField: "base.updated_at",
562
+ }),
563
+ ],
564
+ },
565
+ ```
566
+
567
+ The builder also labels the push with the projection's `baseTable`, which is
568
+ what the mapping is filed under. A hand-built source (`fromDrizzle` with an
569
+ overridden `fetchPage`) is still supported — the SDK derives the same label from
570
+ your config — but the builder performs the joins for you.
571
+
572
+ > Authoring a derived object in the dashboard? Its **Connect** panel generates
573
+ > this snippet for you, projection literal included.
574
+
545
575
  Provider and framework integrations use **optional peer dependencies**. Install
546
576
  only what your app actually uses:
547
577
 
package/drizzle.cjs CHANGED
@@ -60,6 +60,7 @@ function fromDrizzleProjection(db, projection, opts) {
60
60
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
61
61
  return {
62
62
  entity: opts.entity,
63
+ pushSource: projection.baseTable,
63
64
  cursorField: cursorToken,
64
65
  idField: "id",
65
66
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
@@ -89,6 +90,7 @@ function fromDrizzleProjectionByIdentity(client, projection, identityExpr, fromC
89
90
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
90
91
  return {
91
92
  entity: opts.entity,
93
+ pushSource: projection.baseTable,
92
94
  cursorField: "id",
93
95
  idField: "id",
94
96
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
package/drizzle.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-w8oMBWf8.cjs";
2
2
  import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-SD8WCvYj.cjs";
3
- import { t as NamespaceIntrospector, v as SyncSource } from "./namespace-probe-lj_0bJrc.cjs";
3
+ import { t as NamespaceIntrospector, v as SyncSource } from "./namespace-probe-C3xMOqWE.cjs";
4
4
  import { Table } from "drizzle-orm";
5
5
  //#region ../sdk/src/drizzle-projection.d.ts
6
6
  /**
package/drizzle.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-w8oMBWf8.mjs";
2
2
  import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-axugRJ0u.mjs";
3
- import { t as NamespaceIntrospector, v as SyncSource } from "./namespace-probe-ouHKZas2.mjs";
3
+ import { t as NamespaceIntrospector, v as SyncSource } from "./namespace-probe-BmxtnOfc.mjs";
4
4
  import { Table } from "drizzle-orm";
5
5
  //#region ../sdk/src/drizzle-projection.d.ts
6
6
  /**
package/drizzle.mjs CHANGED
@@ -59,6 +59,7 @@ function fromDrizzleProjection(db, projection, opts) {
59
59
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
60
60
  return {
61
61
  entity: opts.entity,
62
+ pushSource: projection.baseTable,
62
63
  cursorField: cursorToken,
63
64
  idField: "id",
64
65
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
@@ -88,6 +89,7 @@ function fromDrizzleProjectionByIdentity(client, projection, identityExpr, fromC
88
89
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
89
90
  return {
90
91
  entity: opts.entity,
92
+ pushSource: projection.baseTable,
91
93
  cursorField: "id",
92
94
  idField: "id",
93
95
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
package/index.cjs CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_entity_config = require("./entity-config-C2MfIDL2.cjs");
4
4
  require("./mapping-score-CaB3F4Uu.cjs");
5
5
  const require_internal_entity_heuristics = require("./internal-entity-heuristics.cjs");
6
- const require_sdk = require("./sdk-DbvqXNSh.cjs");
6
+ const require_sdk = require("./sdk-BIYu0N3V.cjs");
7
7
  let node_child_process = require("node:child_process");
8
8
  let node_fs = require("node:fs");
9
9
  let node_module = require("node:module");
@@ -293,6 +293,124 @@ function addCommand(pm, packages) {
293
293
  };
294
294
  }
295
295
  //#endregion
296
+ //#region src/detect-workspace.ts
297
+ const SELECTABLE_FRAMEWORKS = [
298
+ "nextjs",
299
+ "tanstack-start",
300
+ "sveltekit",
301
+ "remix",
302
+ "nuxt"
303
+ ];
304
+ /**
305
+ * Validate a `--framework` value.
306
+ *
307
+ * Rejecting a typo matters more than accepting one leniently: an unrecognised
308
+ * value silently falling back to detection would scaffold route files in the
309
+ * wrong shape, and a route in the wrong shape is not a build error — the
310
+ * generator simply skips it and the endpoint 404s at runtime.
311
+ */
312
+ function parseFrameworkFlag(value) {
313
+ if (value === void 0) return;
314
+ if (SELECTABLE_FRAMEWORKS.includes(value)) return value;
315
+ throw new Error(`"${value}" is not a supported framework. Accepted: ${SELECTABLE_FRAMEWORKS.join(", ")}.`);
316
+ }
317
+ /**
318
+ * A caution for when the framework came from a sibling package, or null.
319
+ *
320
+ * Borrowing the ORM or auth is unambiguous — one database and one auth instance
321
+ * serve the whole workspace. Borrowing the *framework* is not: route files are
322
+ * generated in that framework's shape and written into the directory `init` ran
323
+ * in, so if the framework lives next door the routes probably belong next door
324
+ * too. Writing TanStack `src/routes/` files into a Hono app is not a build
325
+ * error — the route generator simply never sees them and the endpoints 404.
326
+ */
327
+ function borrowedFrameworkWarning(framework, source) {
328
+ if (!source) return null;
329
+ return ` ⚠️ ${FRAMEWORK_LABELS[framework]} was detected in "${source}", not here.\n Route files are generated in that framework's shape. If this app
330
+ does not serve them, run init inside "${source}" instead, or pass\n --framework to say what this app actually is.
331
+ `;
332
+ }
333
+ /**
334
+ * Extra guidance for a detection failure inside a workspace, or "" outside one.
335
+ *
336
+ * Detection has already scanned every sibling by the time either failure fires,
337
+ * so the marker really is absent everywhere — which is worth saying, because
338
+ * the bare message sends a developer looking for a dependency that was never
339
+ * missing. Returning "" for the single-package case keeps the caller
340
+ * branch-free.
341
+ */
342
+ function workspaceHint(kind, packageCount) {
343
+ if (packageCount === 0) return "";
344
+ const scanned = `\nScanned ${packageCount} workspace package(s) and found no ${kind === "orm" ? "ORM" : "framework"} marker`;
345
+ return kind === "orm" ? `${scanned}.\nIf your schema is Drizzle, point at it and init will take your word:\n\n clivly init --schema <path-or-package>\n` : `${scanned}\nin any of them. If this app is served by one of the frameworks above,\nname it outright:\n\n clivly init --framework tanstack-start\n`;
346
+ }
347
+ /**
348
+ * Resolve one signal, preferring the app's own dependencies.
349
+ *
350
+ * The app's package.json is authoritative: a sibling on a different framework
351
+ * must never redefine what this app is. Only when the app itself is silent do
352
+ * we look outward, and then the first package by name wins.
353
+ *
354
+ * Sorting here rather than trusting the caller matters: the real package list
355
+ * comes from glob expansion, whose order is not guaranteed, so an unsorted scan
356
+ * would let the same repo detect differently between runs and report a
357
+ * different package as the source.
358
+ */
359
+ function resolveSignal(appDeps, packages, detect, unknown) {
360
+ const own = detect(appDeps);
361
+ if (own !== unknown) return {
362
+ source: null,
363
+ value: own
364
+ };
365
+ const ordered = [...packages].sort((a, b) => a.name.localeCompare(b.name));
366
+ for (const pkg of ordered) {
367
+ const found = detect(pkg.deps);
368
+ if (found !== unknown) return {
369
+ source: pkg.name,
370
+ value: found
371
+ };
372
+ }
373
+ return {
374
+ source: null,
375
+ value: unknown
376
+ };
377
+ }
378
+ /**
379
+ * Detect framework, ORM and auth across a whole workspace.
380
+ *
381
+ * A monorepo routinely splits these across packages — framework in the frontend
382
+ * app, ORM in a `db` package, auth in an `auth` package — so reading only the
383
+ * directory `init` was run from finds at most one of the three and fails
384
+ * whichever way the developer turns. Widening the search to sibling packages is
385
+ * what makes those layouts installable.
386
+ *
387
+ * Detection is deliberately a union rather than a per-package view: `init`
388
+ * generates one config for one app, and that app reaches its database and auth
389
+ * through workspace dependencies whether or not they are named in its own
390
+ * manifest.
391
+ *
392
+ * `packages` may include the app itself; that is harmless, since the app's own
393
+ * deps are consulted first anyway. Pass `[]` outside a workspace, which reduces
394
+ * this to a plain single-package read.
395
+ */
396
+ function detectAcrossWorkspace(appDeps, packages) {
397
+ const framework = resolveSignal(appDeps, packages, detectFramework, "unknown");
398
+ const orm = resolveSignal(appDeps, packages, detectOrm, "unknown");
399
+ const auth = resolveSignal(appDeps, packages, detectAuth, "unknown");
400
+ const sources = {
401
+ auth: auth.source,
402
+ framework: framework.source,
403
+ orm: orm.source
404
+ };
405
+ return {
406
+ auth: auth.value,
407
+ borrowed: Object.values(sources).some((source) => source !== null),
408
+ framework: framework.value,
409
+ orm: orm.value,
410
+ sources
411
+ };
412
+ }
413
+ //#endregion
296
414
  //#region src/tick-route.ts
297
415
  /**
298
416
  * The tick route's public URL path, and the template `clivly login` writes for
@@ -1258,10 +1376,12 @@ Usage:
1258
1376
  clivly init [--force] [--dry-run] [--diff] [--yes] [--no-login] [--no-browser]
1259
1377
  [--schema <path|package>] [--db-import <specifier>]
1260
1378
  [--auth-import <specifier>] [--contact-table <table>]
1261
- [--company-table <table>]
1379
+ [--company-table <table>] [--framework <name>]
1262
1380
 
1263
1381
  Scaffolds clivly.config.ts, the Clivly route files, and .env placeholders.
1264
1382
  Detects your framework, ORM, auth adapter and app layout from the project.
1383
+ In a workspace the whole package graph is scanned, so a monorepo that keeps
1384
+ its framework, ORM and auth in separate packages is detected from any app.
1265
1385
 
1266
1386
  Options:
1267
1387
  --dry-run Show what would be written; write nothing
@@ -1269,7 +1389,8 @@ Options:
1269
1389
  --force Overwrite files Clivly owns
1270
1390
  --yes Skip prompts
1271
1391
  --no-login Skip browser pairing
1272
- --schema <p> Path or package holding your ORM schema
1392
+ --framework <n> nextjs | tanstack-start | sveltekit | remix | nuxt
1393
+ --schema <p> Path or package holding your ORM schema (implies Drizzle)
1273
1394
  --db-import <s> Module specifier exporting your database instance
1274
1395
  --auth-import <s> Module specifier exporting your auth instance
1275
1396
  --contact-table <t> Table to map as contacts
@@ -1701,13 +1822,52 @@ function toScoredTable(table) {
1701
1822
  function columnNames(table) {
1702
1823
  return table.columns.map((column) => column.dbName);
1703
1824
  }
1704
- function rankCandidates$1(tables, concept) {
1825
+ /**
1826
+ * Company candidates the vocabulary cannot name, promoted on foreign-key
1827
+ * evidence.
1828
+ *
1829
+ * The company vocabulary is seven generic business words (companies,
1830
+ * organizations, teams, accounts…). A domain word for the same idea —
1831
+ * `campuses`, `branches`, `sites`, `practices`, `chapters` — matches none of
1832
+ * them, so such a table was never a candidate at all and no amount of ranking
1833
+ * could reach it. On `vue-academy` that left Better Auth's `organization` as
1834
+ * the only company candidate, and init duly scaffolded the auth table while
1835
+ * `campuses`, which every student row references, was invisible.
1836
+ *
1837
+ * Guessing more words does not fix this; the next unlisted word fails
1838
+ * identically. The schema already states the answer: when the CONTACT table
1839
+ * holds a real foreign key to some table, that target is what a contact
1840
+ * belongs to. `references` is reflected metadata, so this is a fact rather
1841
+ * than a name guess.
1842
+ *
1843
+ * Two guards keep it honest. The target must pass `hasDefiningColumn`, the
1844
+ * same "can this table BE a company" test every other candidate passes — a
1845
+ * join table with no `name` is not promoted. And framework tables are skipped,
1846
+ * because `contacts.organization_id → organization` is exactly the auth
1847
+ * plumbing this is meant to see past.
1848
+ */
1849
+ function fkPromotedCompanies(tables, contact) {
1850
+ if (!contact) return [];
1851
+ const targets = /* @__PURE__ */ new Set();
1852
+ for (const column of contact.columns) {
1853
+ const table = column.references?.table;
1854
+ if (table && !require_internal_entity_heuristics.isFrameworkTable(table)) targets.add(table.toLowerCase());
1855
+ }
1856
+ return tables.filter((t) => targets.has(t.tableName.toLowerCase()) && t.tableName !== contact.tableName && require_internal_entity_heuristics.hasDefiningColumn("company", columnNames(t)));
1857
+ }
1858
+ function rankCandidates$1(tables, concept, contact = null) {
1859
+ const promoted = concept === "company" ? fkPromotedCompanies(tables, contact) : [];
1860
+ const promotedNames = new Set(promoted.map((t) => t.tableName));
1705
1861
  return tables.map((t) => ({
1706
1862
  t,
1707
- m: require_internal_entity_heuristics.matchesConcept(t.tableName, concept)
1863
+ m: require_internal_entity_heuristics.matchesConcept(t.tableName, concept) ?? (promotedNames.has(t.tableName) ? { exact: false } : null)
1708
1864
  })).filter((c) => Boolean(c.m)).sort((a, b) => {
1709
1865
  const usable = Number(require_internal_entity_heuristics.hasDefiningColumn(concept, columnNames(b.t))) - Number(require_internal_entity_heuristics.hasDefiningColumn(concept, columnNames(a.t)));
1710
1866
  if (usable !== 0) return usable;
1867
+ const aPromoted = promotedNames.has(a.t.tableName);
1868
+ if (aPromoted !== promotedNames.has(b.t.tableName)) {
1869
+ if (require_internal_entity_heuristics.isFrameworkTable((aPromoted ? b.t : a.t).tableName)) return aPromoted ? -1 : 1;
1870
+ }
1711
1871
  const exact = Number(b.m.exact) - Number(a.m.exact);
1712
1872
  if (exact !== 0) return exact;
1713
1873
  return Number(require_internal_entity_heuristics.isFrameworkTable(a.t.tableName)) - Number(require_internal_entity_heuristics.isFrameworkTable(b.t.tableName));
@@ -1715,7 +1875,7 @@ function rankCandidates$1(tables, concept) {
1715
1875
  }
1716
1876
  function selectEntities(tables) {
1717
1877
  const contactCands = rankCandidates$1(tables, "contact");
1718
- const companyCands = rankCandidates$1(tables, "company");
1878
+ const companyCands = rankCandidates$1(tables, "company", contactCands[0] ?? null);
1719
1879
  const contactNames = new Set(contactCands.map((t) => t.tableName));
1720
1880
  const companyNames = new Set(companyCands.map((t) => t.tableName));
1721
1881
  const contactExclusive = contactCands.filter((t) => !companyNames.has(t.tableName));
@@ -1953,14 +2113,19 @@ export async function register() {
1953
2113
  return;
1954
2114
  }
1955
2115
  try {
1956
- // Built at runtime so the bundler cannot statically trace it. Next
1957
- // compiles this file for BOTH runtimes, and the guard above only runs on
1958
- // the edge — it does not stop the edge BUILD from following a literal
1959
- // import into your config, and from there into your database driver. A
1960
- // node-postgres app fails that pass on \`require('path')\` and every route
1961
- // 500s before Clivly is ever reached.
1962
- const specifier = "${importPath}";
1963
- const { default: clivly } = await import(/* webpackIgnore: true */ specifier);
2116
+ // A plain import, deliberately. Next compiles this file for BOTH runtimes
2117
+ // and follows this into your config and on into your database driver, so a
2118
+ // Node-only driver breaks the EDGE build — the guard above is a runtime
2119
+ // check and cannot prevent that. The fix belongs in next.config, where
2120
+ // \`clivly init\` writes an edge-only \`config.externals\` entry; nothing here
2121
+ // ever executes on the edge, so the driver only has to resolve.
2122
+ //
2123
+ // Do NOT make this untraceable (a variable specifier, webpackIgnore).
2124
+ // That silences the build error and breaks the app in a worse way:
2125
+ // clivly.config is TypeScript, so an unbundled import cannot load it, and
2126
+ // the catch below turns that into a warning — the app boots, serves
2127
+ // traffic, and never checks in.
2128
+ const { default: clivly } = await import("${importPath}");
1964
2129
  await clivly.start();
1965
2130
  } catch (error) {
1966
2131
  console.warn("[clivly] could not check in:", error);
@@ -2013,6 +2178,46 @@ function nextNeedsInstrumentationFlag(versionRange) {
2013
2178
  }
2014
2179
  const NEXT_INSTRUMENTATION_FLAG_STEP = `Your Next.js version reads instrumentation.ts only when it is switched on. Add this to next.config, or Clivly will never be told your app started:
2015
2180
  experimental: { instrumentationHook: true }`;
2181
+ const NODE_ONLY_DRIVERS = /* @__PURE__ */ new Set([
2182
+ "pg",
2183
+ "mysql",
2184
+ "mysql2",
2185
+ "better-sqlite3",
2186
+ "sqlite3",
2187
+ "tedious",
2188
+ "oracledb",
2189
+ "ioredis"
2190
+ ]);
2191
+ /**
2192
+ * The Node-only database drivers a config's dependency list contains.
2193
+ *
2194
+ * Next compiles instrumentation.ts for the edge runtime whether or not the app
2195
+ * uses it, and follows the boot hook's config import into the driver. `pg`
2196
+ * pulls in `pgpass` → `split2` → `stream`, none of which resolve there, so the
2197
+ * build fails and every route 500s — before any Clivly code runs.
2198
+ *
2199
+ * `serverExternalPackages` does NOT fix this. It applies to the Node server
2200
+ * bundle only; the edge pass ignores it entirely, which is why adding package
2201
+ * after package to it never terminates. An edge-only `config.externals` is what
2202
+ * works, and it is safe precisely because nothing in that bundle ever executes
2203
+ * — the boot hook returns early unless NEXT_RUNTIME is "nodejs".
2204
+ */
2205
+ function nodeOnlyDrivers(dependencies) {
2206
+ if (!dependencies) return [];
2207
+ return Object.keys(dependencies).filter((name) => NODE_ONLY_DRIVERS.has(name)).sort();
2208
+ }
2209
+ /** The next.config step an app needs when its config reaches a Node driver. */
2210
+ function nextEdgeExternalsStep(drivers) {
2211
+ const list = drivers.map((d) => `"${d}"`).join(", ");
2212
+ return `Your database driver (${drivers.join(", ")}) cannot be bundled for Next's edge runtime, which compiles instrumentation.ts whether or not you use it. Without this, every route fails to build. Add to next.config:
2213
+ webpack: (config, { nextRuntime }) => {
2214
+ if (nextRuntime === "edge") {
2215
+ config.externals = [...(config.externals ?? []), ${list}];
2216
+ }
2217
+ return config;
2218
+ }
2219
+ Nothing runs on the edge — the boot hook exits early there — so the driver only has to resolve.`;
2220
+ }
2016
2221
  const REMIX_BOOT_STEP = `Start Clivly when your app boots. Add this near the top of app/entry.server.tsx:
2017
2222
  import clivly from "./clivly.config";
2018
2223
  clivly.start().catch((error) => console.warn("[clivly] could not check in:", error));`;
@@ -2563,21 +2768,32 @@ function planEnv(args) {
2563
2768
  action: envAction(addedKeys.length, existing.length)
2564
2769
  };
2565
2770
  }
2566
- function declaredNextVersion(args) {
2771
+ function hostManifest(args) {
2567
2772
  const raw = args.readFile((0, node_path.join)(args.cwd, "package.json"));
2568
- if (!raw) return;
2569
- let pkg = {};
2773
+ if (!raw) return {};
2570
2774
  try {
2571
- pkg = JSON.parse(raw);
2775
+ return JSON.parse(raw);
2572
2776
  } catch {
2573
- pkg = {};
2777
+ return {};
2574
2778
  }
2779
+ }
2780
+ function declaredNextVersion(args) {
2781
+ const pkg = hostManifest(args);
2575
2782
  return pkg.dependencies?.next ?? pkg.devDependencies?.next;
2576
2783
  }
2784
+ function declaredDependencies(args) {
2785
+ return hostManifest(args).dependencies;
2786
+ }
2787
+ /** The edge-externals step, or null when no Node-only driver is declared. */
2788
+ function edgeExternalsStepFor(dependencies) {
2789
+ const drivers = nodeOnlyDrivers(dependencies);
2790
+ return drivers.length > 0 ? nextEdgeExternalsStep(drivers) : null;
2791
+ }
2577
2792
  function planBootPatch(args) {
2578
2793
  if (bootHookPath(args.framework, args.layout) !== null) return {
2579
2794
  file: null,
2580
- manual: args.framework === "nextjs" && nextNeedsInstrumentationFlag(declaredNextVersion(args)) ? NEXT_INSTRUMENTATION_FLAG_STEP : null
2795
+ manual: args.framework === "nextjs" && nextNeedsInstrumentationFlag(declaredNextVersion(args)) ? NEXT_INSTRUMENTATION_FLAG_STEP : null,
2796
+ extra: args.framework === "nextjs" ? edgeExternalsStepFor(declaredDependencies(args)) : null
2581
2797
  };
2582
2798
  if (args.framework === "remix") return {
2583
2799
  file: null,
@@ -2623,7 +2839,7 @@ function planMutations(args) {
2623
2839
  return {
2624
2840
  files,
2625
2841
  env: planEnv(args),
2626
- manualSteps: boot.manual ? [boot.manual] : []
2842
+ manualSteps: [boot.manual, boot.extra ?? null].filter((step) => step !== null)
2627
2843
  };
2628
2844
  }
2629
2845
  function planWidgetMutations(args) {
@@ -3906,6 +4122,18 @@ function resolveInitDeps(options) {
3906
4122
  authWiring: renderAuthWiring("unknown")
3907
4123
  };
3908
4124
  }
4125
+ /**
4126
+ * The three detection lines, annotating any signal borrowed from a sibling.
4127
+ *
4128
+ * Naming the source package is what makes a workspace detection auditable:
4129
+ * without it the banner claims an ORM the developer cannot find in the
4130
+ * directory they are standing in.
4131
+ */
4132
+ function renderDetectionLines(detection) {
4133
+ const from = (source) => source ? ` (from ${source})` : "";
4134
+ const frameworkNote = detection.frameworkForced ? " (--framework)" : from(detection.sources.framework);
4135
+ return ` Framework: ${FRAMEWORK_LABELS[detection.framework]}${frameworkNote}\n ORM: ${detection.orm}${from(detection.sources.orm)}\n Auth: ${detection.auth}${from(detection.sources.auth)}${detection.authWired ? " (wired)" : ""}\n`;
4136
+ }
3909
4137
  async function acquireSchema(options, deps) {
3910
4138
  const { out } = deps;
3911
4139
  const appDeps = deps.readDepsFn(options.cwd);
@@ -3913,26 +4141,39 @@ async function acquireSchema(options, deps) {
3913
4141
  out(`No package.json found in ${options.cwd}. Run \`clivly init\` from inside an existing app — cd into your project first.\n`);
3914
4142
  return { code: 1 };
3915
4143
  }
3916
- const framework = detectFramework(appDeps);
3917
- const orm = detectOrm(appDeps);
3918
- const auth = detectAuth(appDeps);
4144
+ const workspacePackages = (deps.graphFor(options.cwd)?.packages ?? []).map((pkg) => ({
4145
+ deps: deps.readDepsFn(pkg.dir),
4146
+ name: pkg.name
4147
+ }));
4148
+ const detected = detectAcrossWorkspace(appDeps, workspacePackages);
4149
+ const framework = options.frameworkFlag ?? detected.framework;
4150
+ const { auth, orm, sources } = detected;
3919
4151
  deps.framework = framework;
3920
4152
  const layout = deps.resolveAppLayout(options.cwd, deps.fileExists);
3921
4153
  deps.layout = layout;
3922
4154
  out("\nClivly init\n");
3923
4155
  deps.authWiring = renderAuthWiring(auth, auth === "better-auth" ? authInstanceFromFlag(options.authImportFlag) ?? await deps.probeAuth(options.cwd) : null);
3924
- out(` Framework: ${FRAMEWORK_LABELS[framework]}\n`);
3925
- out(` ORM: ${orm}\n`);
3926
- out(` Auth: ${auth}${deps.authWiring.complete ? " (wired)" : ""}\n`);
4156
+ out(renderDetectionLines({
4157
+ auth,
4158
+ authWired: deps.authWiring.complete,
4159
+ framework,
4160
+ frameworkForced: options.frameworkFlag !== void 0,
4161
+ orm,
4162
+ sources
4163
+ }));
3927
4164
  if (framework === "nextjs") out(` Layout: ${layout}\n`);
4165
+ const frameworkCaution = options.frameworkFlag ? null : borrowedFrameworkWarning(framework, sources.framework);
4166
+ if (frameworkCaution) out(`\n${frameworkCaution}`);
3928
4167
  if (auth === "better-auth" && !deps.authWiring.complete) out("\n ⚠️ Could not locate your better-auth instance.\n The verify route will import a placeholder path that does not\n resolve. Point it at the real module with:\n\n clivly init --force --auth-import <specifier>\n\n Accepts an alias ($lib/server/auth, @/lib/auth), a package name,\n or a project-relative path (src/lib/server/auth).\n");
3929
4168
  out("\n");
3930
- if (orm !== "drizzle") {
4169
+ if (orm !== "drizzle" && !options.schemaFlag) {
3931
4170
  out(`clivly init currently generates config for Drizzle only. Detected ORM: ${orm}\n`);
4171
+ out(workspaceHint("orm", workspacePackages.length));
3932
4172
  return { code: 1 };
3933
4173
  }
3934
4174
  if (framework === "unknown") {
3935
4175
  out("clivly init doesn't recognise your framework yet (looked for Next.js, TanStack Start, SvelteKit, Remix, Nuxt). Route file generation needs one of these.\n");
4176
+ out(workspaceHint("framework", workspacePackages.length));
3936
4177
  if ("vue" in appDeps) out("\nUsing Vue? Clivly supports Vue through Nuxt. A Vite SPA has no server\nto mount the sync route on, so the route files need Nuxt's server\ndirectory (or any of the frameworks above).\n");
3937
4178
  return { code: 1 };
3938
4179
  }
@@ -4030,6 +4271,10 @@ function previewMutations(deps, mutations, options) {
4030
4271
  out(` ${mutations.env.action.padEnd(9)} .env\n`);
4031
4272
  for (const key of mutations.env.addedKeys) out(` + ${key}=\n`);
4032
4273
  }
4274
+ if (mutations.manualSteps.length > 0) {
4275
+ out("\nYou will also need to:\n");
4276
+ for (const step of mutations.manualSteps) out(`\n ! ${step}\n`);
4277
+ }
4033
4278
  out(options.diff ? "\nRe-run without --diff to apply; --force to overwrite the files marked conflict.\n" : "\nRe-run without --dry-run to apply.\n");
4034
4279
  }
4035
4280
  function printNextSteps(out, authComplete, loginRan, envFile, needsViteDotenv = false) {
@@ -4356,6 +4601,13 @@ function defaultLoginDeps() {
4356
4601
  };
4357
4602
  }
4358
4603
  function runInitFromArgv(argv, cwd) {
4604
+ let frameworkFlag;
4605
+ try {
4606
+ frameworkFlag = parseFrameworkFlag(flagValue(argv, "--framework"));
4607
+ } catch (error) {
4608
+ process.stdout.write(`${error.message}\n`);
4609
+ return Promise.resolve(1);
4610
+ }
4359
4611
  return runInit({
4360
4612
  cwd,
4361
4613
  force: argv.includes("--force"),
@@ -4365,6 +4617,7 @@ function runInitFromArgv(argv, cwd) {
4365
4617
  noLogin: argv.includes("--no-login"),
4366
4618
  openBrowser: !argv.includes("--no-browser"),
4367
4619
  schemaFlag: flagValue(argv, "--schema"),
4620
+ frameworkFlag,
4368
4621
  dbImportFlag: flagValue(argv, "--db-import"),
4369
4622
  authImportFlag: flagValue(argv, "--auth-import"),
4370
4623
  contactTableFlag: flagValue(argv, "--contact-table"),
package/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  //#region src/detect.d.ts
2
+ type Framework = "nextjs" | "tanstack-start" | "sveltekit" | "remix" | "nuxt" | "unknown";
2
3
  type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
3
4
  //#endregion
4
5
  //#region src/app-layout.d.ts
@@ -84,6 +85,7 @@ interface RunInitOptions {
84
85
  dryRun?: boolean;
85
86
  fileExists?: (path: string) => boolean;
86
87
  force: boolean;
88
+ frameworkFlag?: Framework;
87
89
  installPackages?: (options: {
88
90
  cwd: string;
89
91
  packages: string[];
package/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  //#region src/detect.d.ts
2
+ type Framework = "nextjs" | "tanstack-start" | "sveltekit" | "remix" | "nuxt" | "unknown";
2
3
  type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
3
4
  //#endregion
4
5
  //#region src/app-layout.d.ts
@@ -84,6 +85,7 @@ interface RunInitOptions {
84
85
  dryRun?: boolean;
85
86
  fileExists?: (path: string) => boolean;
86
87
  force: boolean;
88
+ frameworkFlag?: Framework;
87
89
  installPackages?: (options: {
88
90
  cwd: string;
89
91
  packages: string[];