@intelligo-dev/cli 1.0.0-beta.1 → 1.0.0-beta.14

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.
Files changed (223) hide show
  1. package/NOTICE +6 -0
  2. package/README.md +102 -0
  3. package/dist/bin.js +122 -37
  4. package/dist/bin.js.map +1 -1
  5. package/dist/commands/add.d.ts +26 -1
  6. package/dist/commands/add.d.ts.map +1 -1
  7. package/dist/commands/add.js +70 -4
  8. package/dist/commands/add.js.map +1 -1
  9. package/dist/commands/create-flow.d.ts +37 -0
  10. package/dist/commands/create-flow.d.ts.map +1 -0
  11. package/dist/commands/create-flow.js +212 -0
  12. package/dist/commands/create-flow.js.map +1 -0
  13. package/dist/commands/create.d.ts +27 -6
  14. package/dist/commands/create.d.ts.map +1 -1
  15. package/dist/commands/create.js +53 -13
  16. package/dist/commands/create.js.map +1 -1
  17. package/dist/commands/doctor.d.ts +14 -3
  18. package/dist/commands/doctor.d.ts.map +1 -1
  19. package/dist/commands/doctor.js +295 -37
  20. package/dist/commands/doctor.js.map +1 -1
  21. package/dist/commands/migrate-check.d.ts +73 -1
  22. package/dist/commands/migrate-check.d.ts.map +1 -1
  23. package/dist/commands/migrate-check.js +130 -5
  24. package/dist/commands/migrate-check.js.map +1 -1
  25. package/dist/commands/migrate.d.ts +97 -0
  26. package/dist/commands/migrate.d.ts.map +1 -0
  27. package/dist/commands/migrate.js +141 -0
  28. package/dist/commands/migrate.js.map +1 -0
  29. package/dist/commands/sync-messages.d.ts +37 -0
  30. package/dist/commands/sync-messages.d.ts.map +1 -0
  31. package/dist/commands/sync-messages.js +88 -0
  32. package/dist/commands/sync-messages.js.map +1 -0
  33. package/dist/commands/sync-scaffold.d.ts +36 -0
  34. package/dist/commands/sync-scaffold.d.ts.map +1 -0
  35. package/dist/commands/sync-scaffold.js +53 -0
  36. package/dist/commands/sync-scaffold.js.map +1 -0
  37. package/dist/commands/sync.d.ts +103 -0
  38. package/dist/commands/sync.d.ts.map +1 -0
  39. package/dist/commands/sync.js +361 -0
  40. package/dist/commands/sync.js.map +1 -0
  41. package/dist/commands/upgrade-check.d.ts +5 -5
  42. package/dist/commands/upgrade-check.d.ts.map +1 -1
  43. package/dist/commands/upgrade-check.js +22 -6
  44. package/dist/commands/upgrade-check.js.map +1 -1
  45. package/dist/env-files.d.ts +12 -0
  46. package/dist/env-files.d.ts.map +1 -0
  47. package/dist/env-files.js +29 -0
  48. package/dist/env-files.js.map +1 -0
  49. package/dist/index.d.ts +9 -0
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +9 -0
  52. package/dist/index.js.map +1 -1
  53. package/dist/manifest.d.ts +36 -15
  54. package/dist/manifest.d.ts.map +1 -1
  55. package/dist/manifest.js +32 -16
  56. package/dist/manifest.js.map +1 -1
  57. package/dist/migrations.d.ts +3 -6
  58. package/dist/migrations.d.ts.map +1 -1
  59. package/dist/migrations.js +3 -6
  60. package/dist/migrations.js.map +1 -1
  61. package/dist/model-catalogue.d.ts +14 -0
  62. package/dist/model-catalogue.d.ts.map +1 -0
  63. package/dist/model-catalogue.js +34 -0
  64. package/dist/model-catalogue.js.map +1 -0
  65. package/dist/module-exports.d.ts +63 -0
  66. package/dist/module-exports.d.ts.map +1 -0
  67. package/dist/module-exports.js +231 -0
  68. package/dist/module-exports.js.map +1 -0
  69. package/dist/registry-bundle.d.ts +43 -0
  70. package/dist/registry-bundle.d.ts.map +1 -0
  71. package/dist/registry-bundle.js +74 -0
  72. package/dist/registry-bundle.js.map +1 -0
  73. package/dist/registry-items.d.ts +84 -0
  74. package/dist/registry-items.d.ts.map +1 -0
  75. package/dist/registry-items.js +187 -0
  76. package/dist/registry-items.js.map +1 -0
  77. package/package.json +36 -10
  78. package/src/bin.ts +316 -0
  79. package/src/commands/add.ts +255 -0
  80. package/src/commands/create-flow.ts +284 -0
  81. package/src/commands/create.ts +149 -0
  82. package/src/commands/doctor.ts +487 -0
  83. package/src/commands/migrate-check.ts +298 -0
  84. package/src/commands/migrate.ts +228 -0
  85. package/src/commands/sync-messages.ts +114 -0
  86. package/src/commands/sync-scaffold.ts +83 -0
  87. package/src/commands/sync.ts +534 -0
  88. package/src/commands/upgrade-check.ts +160 -0
  89. package/src/env-files.ts +31 -0
  90. package/src/index.ts +39 -0
  91. package/src/manifest.ts +147 -0
  92. package/src/migrations-dir.ts +25 -0
  93. package/src/migrations.ts +133 -0
  94. package/src/model-catalogue.ts +35 -0
  95. package/src/module-exports.ts +266 -0
  96. package/src/registry-bundle.ts +103 -0
  97. package/src/registry-items.ts +237 -0
  98. package/templates/admin-page/admin-page.tsx.tpl +2 -3
  99. package/templates/app-scaffold/assistant-route.ts.tpl +2 -2
  100. package/templates/app-scaffold/auth-route.ts.tpl +10 -0
  101. package/templates/app-scaffold/components.json.tpl +6 -2
  102. package/templates/app-scaffold/db-schema.ts.tpl +29 -0
  103. package/templates/app-scaffold/drizzle-journal.json.tpl +5 -0
  104. package/templates/app-scaffold/drizzle.config.ts.tpl +45 -0
  105. package/templates/app-scaffold/env.example.tpl +65 -1
  106. package/templates/app-scaffold/globals.css.tpl +172 -281
  107. package/templates/app-scaffold/i18n-request.ts.tpl +25 -0
  108. package/templates/app-scaffold/instrumentation.ts.tpl +21 -0
  109. package/templates/app-scaffold/intelligo.ts.tpl +95 -41
  110. package/templates/app-scaffold/layout.tsx.tpl +18 -1
  111. package/templates/app-scaffold/lib-utils.ts.tpl +1 -6
  112. package/templates/app-scaffold/next.config.mjs.tpl +2 -0
  113. package/templates/app-scaffold/package.json.tpl +31 -17
  114. package/templates/app-scaffold/page.tsx.tpl +16 -0
  115. package/templates/app-scaffold/plans.ts.tpl +32 -13
  116. package/templates/app-scaffold/{middleware.ts.tpl → proxy.ts.tpl} +6 -0
  117. package/templates/app-scaffold/sonner.tsx.tpl +42 -20
  118. package/templates/app-scaffold/stripe-webhook-route.ts.tpl +24 -0
  119. package/templates/app-scaffold/theme-provider.tsx.tpl +6 -4
  120. package/templates/app-scaffold/tsconfig.json.tpl +20 -4
  121. package/templates/app-scaffold/use-mobile.ts.tpl +19 -0
  122. package/templates/app-scaffold/workspace-bootstrap.ts.tpl +30 -0
  123. package/templates/maintenance/maintenance-route.ts.tpl +119 -0
  124. package/templates/manifest.json +75 -17
  125. package/templates/registry/ai-agent-activity.json +23 -0
  126. package/templates/registry/ai-agent-progress.json +21 -0
  127. package/templates/registry/ai-approval-card.json +27 -0
  128. package/templates/registry/ai-artifact.json +22 -0
  129. package/templates/registry/ai-branch.json +21 -0
  130. package/templates/registry/ai-citations.json +24 -0
  131. package/templates/registry/ai-code-block.json +23 -0
  132. package/templates/registry/ai-composer-menu.json +19 -0
  133. package/templates/registry/ai-file-diff.json +25 -0
  134. package/templates/registry/ai-image-generation.json +23 -0
  135. package/templates/registry/ai-markdown.json +23 -0
  136. package/templates/registry/ai-message-bubble.json +23 -0
  137. package/templates/registry/ai-message-scroller.json +22 -0
  138. package/templates/registry/ai-message.json +21 -0
  139. package/templates/registry/ai-motion.json +19 -0
  140. package/templates/registry/ai-prompt-input.json +28 -0
  141. package/templates/registry/ai-reasoning-text.json +22 -0
  142. package/templates/registry/ai-reasoning.json +22 -0
  143. package/templates/registry/ai-shimmer-text.json +19 -0
  144. package/templates/registry/ai-sidebar.json +25 -0
  145. package/templates/registry/ai-speech-input.json +21 -0
  146. package/templates/registry/ai-streaming-response.json +24 -0
  147. package/templates/registry/ai-suggestion.json +19 -0
  148. package/templates/registry/ai-todo-list.json +22 -0
  149. package/templates/registry/ai-tool-approval.json +26 -0
  150. package/templates/registry/ai-tool-result.json +25 -0
  151. package/templates/registry/alert-dialog.json +23 -0
  152. package/templates/registry/animated-list.json +21 -0
  153. package/templates/registry/app-shell.json +93 -0
  154. package/templates/registry/artifacts.json +82 -0
  155. package/templates/registry/attachment.json +22 -0
  156. package/templates/registry/auth-email-verification.json +39 -0
  157. package/templates/registry/auth-login.json +72 -0
  158. package/templates/registry/auth-password-reset.json +53 -0
  159. package/templates/registry/auth-signup.json +41 -0
  160. package/templates/registry/billing-settings.json +60 -0
  161. package/templates/registry/button.json +22 -0
  162. package/templates/registry/chat-eve.json +19 -0
  163. package/templates/registry/chat-panel.json +30 -0
  164. package/templates/registry/chat-share.json +42 -0
  165. package/templates/registry/chat-widget.json +34 -0
  166. package/templates/registry/chat.json +326 -0
  167. package/templates/registry/checkbox.json +22 -0
  168. package/templates/registry/checkout.json +40 -0
  169. package/templates/registry/collapsible.json +19 -0
  170. package/templates/registry/command.json +23 -0
  171. package/templates/registry/copy-button.json +21 -0
  172. package/templates/registry/dashboard.json +69 -0
  173. package/templates/registry/dialog.json +24 -0
  174. package/templates/registry/document-viewer.json +22 -0
  175. package/templates/registry/dropdown-menu.json +23 -0
  176. package/templates/registry/expandable-tabs.json +22 -0
  177. package/templates/registry/feature-gating.json +73 -0
  178. package/templates/registry/file-upload.json +24 -0
  179. package/templates/registry/hold-action-button.json +22 -0
  180. package/templates/registry/input-group.json +23 -0
  181. package/templates/registry/input.json +19 -0
  182. package/templates/registry/intelligo.json +187 -0
  183. package/templates/registry/invitation-accept.json +64 -0
  184. package/templates/registry/language-switcher.json +29 -0
  185. package/templates/registry/morphing-modal.json +24 -0
  186. package/templates/registry/notification-stack.json +24 -0
  187. package/templates/registry/notifications.json +87 -0
  188. package/templates/registry/onboarding.json +83 -0
  189. package/templates/registry/otp-input.json +22 -0
  190. package/templates/registry/page-header.json +15 -0
  191. package/templates/registry/payment-poll.json +52 -0
  192. package/templates/registry/popover-morph.json +22 -0
  193. package/templates/registry/popover.json +22 -0
  194. package/templates/registry/pricing.json +111 -0
  195. package/templates/registry/privacy-settings.json +65 -0
  196. package/templates/registry/profile-settings.json +68 -0
  197. package/templates/registry/progress.json +19 -0
  198. package/templates/registry/radio-group.json +22 -0
  199. package/templates/registry/registry.json +2945 -0
  200. package/templates/registry/route-error.json +65 -0
  201. package/templates/registry/select-morph.json +23 -0
  202. package/templates/registry/select.json +23 -0
  203. package/templates/registry/settings-shell.json +47 -0
  204. package/templates/registry/sheet.json +24 -0
  205. package/templates/registry/sidebar.json +28 -0
  206. package/templates/registry/smoke.json +34 -0
  207. package/templates/registry/spinner.json +16 -0
  208. package/templates/registry/stat-card.json +18 -0
  209. package/templates/registry/status-badge.json +18 -0
  210. package/templates/registry/switch.json +20 -0
  211. package/templates/registry/tabs.json +23 -0
  212. package/templates/registry/team-settings.json +97 -0
  213. package/templates/registry/textarea.json +16 -0
  214. package/templates/registry/tooltip.json +22 -0
  215. package/templates/registry/trial-banner.json +43 -0
  216. package/templates/registry/usage.json +84 -0
  217. package/templates/registry/workspace-settings.json +71 -0
  218. package/templates/registry-items.json +116 -0
  219. package/templates/registry-requires.json +180 -0
  220. package/templates/usage-page/usage-page.tsx.tpl +23 -8
  221. package/templates/vitest/server-only.ts.tpl +7 -0
  222. package/templates/vitest/vitest.config.ts.tpl +37 -0
  223. package/templates/billing-page/billing-page.tsx.tpl +0 -72
@@ -0,0 +1,266 @@
1
+ /**
2
+ * What a TypeScript module exports, read from its text — enough for
3
+ * `doctor` to confirm an app provides the names an installed item
4
+ * imports, without compiling or running the app.
5
+ *
6
+ * It understands declarations (`export const|function|class|type|
7
+ * interface|enum …`), export lists with aliases (`export { a as b }`),
8
+ * re-exports (`export { x } from "…"`, `export * from "…"`) and the
9
+ * imports a bare export list re-exports. Modules are resolved the way
10
+ * the app would: relative paths, the `@/` alias, and packages through
11
+ * node resolution from the app's root (a workspace package included).
12
+ */
13
+
14
+ import { existsSync, readFileSync, statSync } from "node:fs";
15
+ import { createRequire } from "node:module";
16
+ import path from "node:path";
17
+
18
+ /**
19
+ * Block and line comments removed, so a check cannot be satisfied — or
20
+ * defeated — by prose.
21
+ */
22
+ export function stripComments(text: string): string {
23
+ return text
24
+ .replace(/\/\*[\s\S]*?\*\//g, "")
25
+ .replace(/(^|[^:])\/\/.*$/gm, "$1");
26
+ }
27
+
28
+ export function escapeRegExp(text: string): string {
29
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
30
+ }
31
+
32
+ export type ModuleShape = {
33
+ /** Names exported by this module itself, or re-exported by name. */
34
+ names: Set<string>;
35
+ /** Exported name → the module it is re-exported from, when it is. */
36
+ reexports: Map<string, string>;
37
+ /** `export * from "…"` specifiers. */
38
+ stars: string[];
39
+ /** Local name → the module it was imported from. */
40
+ imports: Map<string, string>;
41
+ };
42
+
43
+ const DECLARATION =
44
+ /\bexport\s+(?:declare\s+)?(?:default\s+)?(?:abstract\s+)?(?:async\s+)?(?:const|let|var|function\s*\*?|class|type|interface|enum)\s+([A-Za-z_$][\w$]*)/g;
45
+ const EXPORT_LIST =
46
+ /\bexport\s+(?:type\s+)?\{([^}]*)\}(?:\s*from\s*["']([^"']+)["'])?/g;
47
+ const EXPORT_STAR =
48
+ /\bexport\s+(?:type\s+)?\*\s*(?:as\s+([A-Za-z_$][\w$]*)\s+)?from\s*["']([^"']+)["']/g;
49
+ const IMPORT =
50
+ /\bimport\s+(?:type\s+)?([\w$]+\s*,?\s*)?(?:\{([^}]*)\}|\*\s*as\s+([\w$]+))?\s*from\s*["']([^"']+)["']/g;
51
+
52
+ /** `a`, `type a`, `a as b` → [local, exported]. */
53
+ function specifiers(list: string): Array<[string, string]> {
54
+ return list
55
+ .split(",")
56
+ .map((s) => s.trim().replace(/^type\s+/, ""))
57
+ .filter(Boolean)
58
+ .map((s) => {
59
+ const [local, exported] = s.split(/\s+as\s+/).map((x) => x.trim());
60
+ return [local!, exported ?? local!];
61
+ });
62
+ }
63
+
64
+ /** The shape of a module's text; comments are stripped first. */
65
+ export function moduleShape(source: string): ModuleShape {
66
+ const text = stripComments(source);
67
+ const shape: ModuleShape = {
68
+ names: new Set(),
69
+ reexports: new Map(),
70
+ stars: [],
71
+ imports: new Map(),
72
+ };
73
+ for (const m of text.matchAll(IMPORT)) {
74
+ const from = m[4]!;
75
+ const defaultName = m[1]?.replace(/[\s,]/g, "");
76
+ if (defaultName) shape.imports.set(defaultName, from);
77
+ if (m[3]) shape.imports.set(m[3], from);
78
+ for (const [, local] of specifiers(m[2] ?? "")) {
79
+ shape.imports.set(local, from);
80
+ }
81
+ }
82
+ for (const m of text.matchAll(DECLARATION)) shape.names.add(m[1]!);
83
+ for (const m of text.matchAll(EXPORT_LIST)) {
84
+ for (const [local, exported] of specifiers(m[1]!)) {
85
+ shape.names.add(exported);
86
+ const from = m[2] ?? shape.imports.get(local);
87
+ if (from) shape.reexports.set(exported, from);
88
+ }
89
+ }
90
+ for (const m of text.matchAll(EXPORT_STAR)) {
91
+ if (m[1]) shape.names.add(m[1]);
92
+ else shape.stars.push(m[2]!);
93
+ }
94
+ return shape;
95
+ }
96
+
97
+ const EXTENSIONS = [".ts", ".tsx", ".mts", ".d.ts", ".js", ".mjs", ".jsx"];
98
+
99
+ function resolveFile(base: string): string | null {
100
+ const isFile = (p: string) => existsSync(p) && statSync(p).isFile();
101
+ if (isFile(base)) return base;
102
+ // TypeScript sources import siblings with the `.js` they compile to.
103
+ const stem = base.replace(/\.(?:m?js|jsx)$/, "");
104
+ for (const ext of EXTENSIONS) if (isFile(stem + ext)) return stem + ext;
105
+ for (const ext of EXTENSIONS) {
106
+ const index = path.join(base, `index${ext}`);
107
+ if (isFile(index)) return index;
108
+ }
109
+ return null;
110
+ }
111
+
112
+ /** The first file path an `exports` condition object leads to. */
113
+ function pickCondition(entry: unknown): string | null {
114
+ if (typeof entry === "string") return entry;
115
+ if (!entry || typeof entry !== "object") return null;
116
+ const record = entry as Record<string, unknown>;
117
+ for (const key of ["import", "default", "node", "require", "types"]) {
118
+ const hit = key in record ? pickCondition(record[key]) : null;
119
+ if (hit) return hit;
120
+ }
121
+ return null;
122
+ }
123
+
124
+ /** A package's module file from its package.json `exports`, `module` or `main`. */
125
+ function packageFile(specifier: string, appRoot: string): string | null {
126
+ const parts = specifier.split("/");
127
+ const name = specifier.startsWith("@")
128
+ ? parts.slice(0, 2).join("/")
129
+ : parts[0]!;
130
+ const subpath = `.${specifier.slice(name.length)}`;
131
+ let dir = path.resolve(appRoot);
132
+ for (;;) {
133
+ const manifestFile = path.join(dir, "node_modules", name, "package.json");
134
+ if (existsSync(manifestFile)) {
135
+ const pkgDir = path.dirname(manifestFile);
136
+ const manifest = JSON.parse(readFileSync(manifestFile, "utf8")) as {
137
+ exports?: unknown;
138
+ module?: string;
139
+ main?: string;
140
+ };
141
+ const exp = manifest.exports;
142
+ let target: string | null = null;
143
+ if (typeof exp === "string") target = subpath === "." ? exp : null;
144
+ else if (exp && typeof exp === "object") {
145
+ const map = exp as Record<string, unknown>;
146
+ const keyed = Object.keys(map).some((k) => k.startsWith("."));
147
+ target = pickCondition(
148
+ keyed ? map[subpath] : subpath === "." ? map : null
149
+ );
150
+ }
151
+ if (!target && subpath === ".")
152
+ target = manifest.module ?? manifest.main ?? "index";
153
+ if (!target && subpath !== ".") target = subpath;
154
+ return target ? resolveFile(path.join(pkgDir, target)) : null;
155
+ }
156
+ const parent = path.dirname(dir);
157
+ if (parent === dir) return null;
158
+ dir = parent;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * The file a module specifier leads to from `fromFile`, or null when it
164
+ * cannot be found: relative, the `@/` alias, then node resolution from
165
+ * the app's root.
166
+ */
167
+ export function resolveModule(
168
+ specifier: string,
169
+ fromFile: string,
170
+ appRoot: string
171
+ ): string | null {
172
+ if (specifier.startsWith(".")) {
173
+ return resolveFile(path.resolve(path.dirname(fromFile), specifier));
174
+ }
175
+ if (specifier.startsWith("@/")) {
176
+ return resolveFile(path.join(appRoot, specifier.slice(2)));
177
+ }
178
+ const fromPackage = packageFile(specifier, appRoot);
179
+ if (fromPackage) return fromPackage;
180
+ try {
181
+ const resolved = createRequire(path.join(appRoot, "package.json")).resolve(
182
+ specifier
183
+ );
184
+ return existsSync(resolved) ? resolved : null;
185
+ } catch {
186
+ return null;
187
+ }
188
+ }
189
+
190
+ export type ExportCheck = {
191
+ /** Names the module provably does not export. */
192
+ missing: string[];
193
+ /**
194
+ * `export * from` specifiers that could not be read: the names not
195
+ * found elsewhere are assumed to come from them.
196
+ */
197
+ unresolved: string[];
198
+ };
199
+
200
+ /**
201
+ * Which of `names` the module at `file` does not export, following
202
+ * `export * from` into the modules it can resolve.
203
+ */
204
+ export function checkExports(
205
+ file: string,
206
+ names: readonly string[],
207
+ appRoot: string,
208
+ seen: Set<string> = new Set()
209
+ ): ExportCheck {
210
+ seen.add(file);
211
+ const shape = moduleShape(readFileSync(file, "utf8"));
212
+ let missing = names.filter((n) => !shape.names.has(n));
213
+ const unresolved: string[] = [];
214
+ for (const star of shape.stars) {
215
+ if (missing.length === 0) break;
216
+ const target = resolveModule(star, file, appRoot);
217
+ if (!target) {
218
+ unresolved.push(star);
219
+ continue;
220
+ }
221
+ if (seen.has(target)) continue;
222
+ const inner = checkExports(target, missing, appRoot, seen);
223
+ missing = inner.missing;
224
+ unresolved.push(...inner.unresolved);
225
+ }
226
+ return unresolved.length > 0
227
+ ? { missing: [], unresolved }
228
+ : { missing, unresolved };
229
+ }
230
+
231
+ /**
232
+ * The text of a module and of every module it re-exports from —
233
+ * `export … from`, `export * from`, and imports a bare export list
234
+ * passes on — comments stripped. What a `lib/plans.ts` that re-exports
235
+ * a workspace package's catalogue actually defines.
236
+ */
237
+ export function reexportedSource(
238
+ file: string,
239
+ appRoot: string,
240
+ depth = 3
241
+ ): { text: string; unresolved: string[] } {
242
+ const seen = new Set<string>();
243
+ const unresolved: string[] = [];
244
+ const texts: string[] = [];
245
+ const visit = (current: string, left: number) => {
246
+ if (seen.has(current)) return;
247
+ seen.add(current);
248
+ const source = readFileSync(current, "utf8");
249
+ texts.push(stripComments(source));
250
+ if (left === 0) return;
251
+ const shape = moduleShape(source);
252
+ for (const spec of new Set([...shape.reexports.values(), ...shape.stars])) {
253
+ const target = resolveModule(spec, current, appRoot);
254
+ if (target) visit(target, left - 1);
255
+ else unresolved.push(spec);
256
+ }
257
+ };
258
+ visit(file, depth);
259
+ return { text: texts.join("\n"), unresolved };
260
+ }
261
+
262
+ /** An object key `key:` or `"key":`, not a longer identifier ending in it. */
263
+ export function hasObjectKey(text: string, key: string): boolean {
264
+ const k = escapeRegExp(key);
265
+ return new RegExp(`(?:(?<![\\w$-])${k}|["'\`]${k}["'\`])\\s*:`).test(text);
266
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The page registry as this CLI ships it.
3
+ *
4
+ * The build copies packages/registry/public/r — the same shadcn-schema
5
+ * JSON intelligo.dev/r serves — into templates/registry, so the items a
6
+ * CLI installs are the ones built with the packages of its own version:
7
+ * `@intelligo-dev/cli@X` syncs the pages of framework X, never whatever
8
+ * the site deployed last. In the framework repository, before a build,
9
+ * the freshly built registry stands in for the bundle.
10
+ */
11
+
12
+ import { existsSync, readFileSync } from "node:fs";
13
+ import path from "node:path";
14
+
15
+ export type RegistryFile = {
16
+ path: string;
17
+ type: string;
18
+ target?: string;
19
+ content?: string;
20
+ };
21
+
22
+ export type RegistryItemJson = {
23
+ name: string;
24
+ type: string;
25
+ files?: RegistryFile[];
26
+ registryDependencies?: string[];
27
+ };
28
+
29
+ /** How items name each other; resolved against this registry. */
30
+ export const NAMESPACE = "@intelligo/";
31
+
32
+ export function resolveRegistryDir(templatesDir: string): string | null {
33
+ const candidates = [
34
+ path.join(templatesDir, "registry"),
35
+ // packages/cli/templates → packages/registry/public/r
36
+ path.resolve(templatesDir, "..", "..", "registry", "public", "r"),
37
+ ];
38
+ return (
39
+ candidates.find((dir) => existsSync(path.join(dir, "intelligo.json"))) ??
40
+ null
41
+ );
42
+ }
43
+
44
+ export function hasRegistryItem(dir: string, name: string): boolean {
45
+ return (
46
+ /^[a-z0-9-]+$/.test(name) && existsSync(path.join(dir, `${name}.json`))
47
+ );
48
+ }
49
+
50
+ export function readRegistryItem(dir: string, name: string): RegistryItemJson {
51
+ if (!hasRegistryItem(dir, name)) {
52
+ throw new Error(`Unknown registry item "${name}".`);
53
+ }
54
+ return JSON.parse(
55
+ readFileSync(path.join(dir, `${name}.json`), "utf8")
56
+ ) as RegistryItemJson;
57
+ }
58
+
59
+ /** Where shadcn writes a file of an item. */
60
+ export function installedPath(
61
+ item: Pick<RegistryItemJson, "type">,
62
+ file: RegistryFile
63
+ ): string | null {
64
+ if (file.target) return file.target;
65
+ if (item.type === "registry:ui") {
66
+ return `components/ui/${path.basename(file.path)}`;
67
+ }
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * A file as `shadcn add` writes it: the CLI drops the comment block that
73
+ * opens a file, so that header is not part of any comparison.
74
+ */
75
+ export function asInstalled(source: string): string {
76
+ return source.replace(/^(?:\s*(?:\/\*[\s\S]*?\*\/|\/\/[^\n]*))*\s*/, "");
77
+ }
78
+
79
+ /**
80
+ * The named items and every Intelligo item they pull in through
81
+ * `@intelligo/<name>`, transitively, dependencies first — the set of
82
+ * files one `shadcn add` of each name writes. Dependencies outside the
83
+ * namespace (shadcn's own `utils`, `skeleton`…) are not this registry's
84
+ * to check.
85
+ */
86
+ export function registryClosure(
87
+ dir: string,
88
+ names: readonly string[]
89
+ ): string[] {
90
+ const order: string[] = [];
91
+ const seen = new Set<string>();
92
+ const visit = (name: string) => {
93
+ if (seen.has(name)) return;
94
+ seen.add(name);
95
+ const item = readRegistryItem(dir, name);
96
+ for (const dep of item.registryDependencies ?? []) {
97
+ if (dep.startsWith(NAMESPACE)) visit(dep.slice(NAMESPACE.length));
98
+ }
99
+ order.push(name);
100
+ };
101
+ for (const name of names) visit(name);
102
+ return order;
103
+ }
@@ -0,0 +1,237 @@
1
+ /**
2
+ * The registry's pages as `intelligo create` offers them: what each one
3
+ * is, what else it needs installed first, and the commands that install
4
+ * a selection into a fresh app.
5
+ *
6
+ * Installing goes through `intelligo sync` (commands/sync.ts): one
7
+ * `shadcn add` per item from the registry bundled with this CLI, in the
8
+ * order requires.json `items` implies — an item that imports a
9
+ * sibling's files lands after it.
10
+ */
11
+
12
+ import { existsSync, readFileSync } from "node:fs";
13
+ import path from "node:path";
14
+
15
+ import type { RegistryRequires } from "./commands/doctor.js";
16
+
17
+ export type RegistryItem = { title: string; description: string };
18
+ export type RegistryCatalogue = {
19
+ items: Record<string, RegistryItem>;
20
+ requires: RegistryRequires;
21
+ };
22
+
23
+ /** Both files are build-time copies from packages/registry (see scripts/). */
24
+ export function readRegistryCatalogue(templatesDir: string): RegistryCatalogue {
25
+ const read = (file: string) =>
26
+ JSON.parse(readFileSync(path.join(templatesDir, file), "utf8"));
27
+ return {
28
+ items: (
29
+ read("registry-items.json") as { items: Record<string, RegistryItem> }
30
+ ).items,
31
+ requires: read("registry-requires.json") as RegistryRequires,
32
+ };
33
+ }
34
+
35
+ /** The description's opening clause — short enough for one picker line. */
36
+ export function shortDescription(description: string, max = 64): string {
37
+ const head = description.split(/[:.]\s|\s—\s/)[0]!.trim();
38
+ return head.length <= max ? head : `${head.slice(0, max - 1).trimEnd()}…`;
39
+ }
40
+
41
+ /**
42
+ * The selection plus everything it depends on, dependencies first.
43
+ * Unknown names throw rather than being dropped: a typo in `--items`
44
+ * should not quietly install less than was asked for.
45
+ */
46
+ export function withDependencies(
47
+ selected: readonly string[],
48
+ requires: RegistryRequires
49
+ ): string[] {
50
+ const order: string[] = [];
51
+ const seen = new Set<string>();
52
+ const visit = (name: string) => {
53
+ if (seen.has(name)) return;
54
+ const entry = requires.items[name];
55
+ if (!entry) {
56
+ throw new Error(
57
+ `Unknown registry item "${name}". Available: ${Object.keys(requires.items).join(", ")}`
58
+ );
59
+ }
60
+ seen.add(name);
61
+ for (const dependency of entry.items ?? []) visit(dependency);
62
+ order.push(name);
63
+ };
64
+ for (const name of selected) visit(name);
65
+ return order;
66
+ }
67
+
68
+ export type PackageManager = "pnpm" | "npm" | "yarn" | "bun";
69
+
70
+ /**
71
+ * Whichever manager ran the CLI (`pnpm dlx`, `npx`, `bunx`… all set
72
+ * npm_config_user_agent), else pnpm — the one the scaffold documents.
73
+ */
74
+ export function detectPackageManager(
75
+ userAgent: string | undefined = process.env.npm_config_user_agent
76
+ ): PackageManager {
77
+ const name = userAgent?.split("/")[0];
78
+ return name === "npm" || name === "yarn" || name === "bun" ? name : "pnpm";
79
+ }
80
+
81
+ export type Command = {
82
+ command: string;
83
+ args: string[];
84
+ /** Where it runs, when not the app itself (a parent workspace's root). */
85
+ cwd?: string;
86
+ };
87
+
88
+ /**
89
+ * The command as a reader pastes it from `from` (the app's directory):
90
+ * a command that runs elsewhere is wrapped in a `cd`.
91
+ */
92
+ export function formatCommand(c: Command, from?: string): string {
93
+ const line = [c.command, ...c.args].join(" ");
94
+ if (!c.cwd || !from || path.resolve(c.cwd) === path.resolve(from)) {
95
+ return line;
96
+ }
97
+ return `(cd ${path.relative(from, c.cwd) || "."} && ${line})`;
98
+ }
99
+
100
+ const EXEC: Record<PackageManager, string[]> = {
101
+ pnpm: ["pnpm", "exec"],
102
+ npm: ["npx"],
103
+ yarn: ["yarn"],
104
+ bun: ["bunx"],
105
+ };
106
+
107
+ /** Whether the app has its own shadcn binary, i.e. dependencies are installed. */
108
+ export function hasLocalShadcn(appRoot: string): boolean {
109
+ return existsSync(path.join(appRoot, "node_modules", ".bin", "shadcn"));
110
+ }
111
+
112
+ /** The `packages:` globs of a pnpm-workspace.yaml (`!` exclusions kept). */
113
+ export function workspaceGlobs(yaml: string): string[] {
114
+ const globs: string[] = [];
115
+ let inPackages = false;
116
+ for (const raw of yaml.split(/\r?\n/)) {
117
+ const line = raw.replace(/\s+#.*$/, "");
118
+ const key = /^packages\s*:\s*(.*)$/.exec(line);
119
+ if (key) {
120
+ const flow = /^\[(.*)\]$/.exec(key[1]!.trim());
121
+ if (flow) {
122
+ for (const g of flow[1]!.split(",")) {
123
+ const glob = g.trim().replace(/^["']|["']$/g, "");
124
+ if (glob) globs.push(glob);
125
+ }
126
+ } else inPackages = true;
127
+ continue;
128
+ }
129
+ if (!inPackages) continue;
130
+ const entry = /^\s+-\s*(.+?)\s*$/.exec(line);
131
+ if (entry) globs.push(entry[1]!.replace(/^["']|["']$/g, ""));
132
+ else if (/^\S/.test(line)) inPackages = false;
133
+ }
134
+ return globs;
135
+ }
136
+
137
+ function globToRegExp(glob: string): RegExp {
138
+ const pattern = glob
139
+ .replace(/^\.\//, "")
140
+ .replace(/\/+$/, "")
141
+ .split(/(\*\*|\*|\?)/)
142
+ .map((part) =>
143
+ part === "**"
144
+ ? ".*"
145
+ : part === "*"
146
+ ? "[^/]*"
147
+ : part === "?"
148
+ ? "[^/]"
149
+ : part.replace(/[.+^${}()|[\]\\]/g, "\\$&")
150
+ )
151
+ .join("");
152
+ return new RegExp(`^${pattern}$`);
153
+ }
154
+
155
+ /**
156
+ * The root of the pnpm workspace that has `appRoot` as a member, if
157
+ * any: the nearest pnpm-workspace.yaml above the app, when one of its
158
+ * `packages` globs matches the app's path and no `!` glob excludes it.
159
+ * Installing from there updates the workspace's one lockfile instead of
160
+ * starting a nested one in the app.
161
+ */
162
+ export function findWorkspaceRoot(appRoot: string): string | null {
163
+ const app = path.resolve(appRoot);
164
+ let dir = path.dirname(app);
165
+ for (;;) {
166
+ const file = path.join(dir, "pnpm-workspace.yaml");
167
+ if (existsSync(file)) {
168
+ const rel = path.relative(dir, app).split(path.sep).join("/");
169
+ const globs = workspaceGlobs(readFileSync(file, "utf8"));
170
+ const included = globs
171
+ .filter((g) => !g.startsWith("!"))
172
+ .some((g) => globToRegExp(g).test(rel));
173
+ const excluded = globs
174
+ .filter((g) => g.startsWith("!"))
175
+ .some((g) => globToRegExp(g.slice(1)).test(rel));
176
+ return included && !excluded ? dir : null;
177
+ }
178
+ const parent = path.dirname(dir);
179
+ if (parent === dir) return null;
180
+ dir = parent;
181
+ }
182
+ }
183
+
184
+ /** The design-system base, installed before any page. */
185
+ const BASE = "intelligo";
186
+
187
+ export type InstallPlan = {
188
+ /**
189
+ * The dependency install, when shadcn is not there yet (the scaffold
190
+ * declares it) — run from the parent workspace's root when the app is
191
+ * a member of one.
192
+ */
193
+ install: Command | null;
194
+ /** The items `intelligo sync` installs: the base first, then the pages in dependency order. */
195
+ items: string[];
196
+ /** The same sync as a command, for a reader to run by hand. */
197
+ sync: Command;
198
+ };
199
+
200
+ /**
201
+ * How `items` get into the app at `appRoot`: the dependencies first
202
+ * when shadcn is missing, then `intelligo sync` of the base and every
203
+ * item — one `shadcn add` per item in dependency order, from the
204
+ * registry bundled with this CLI, with `--force` because a fresh
205
+ * scaffold's files (globals.css, the theme provider) are the registry's
206
+ * to replace. Null when nothing was picked.
207
+ */
208
+ export function installPlan(
209
+ items: readonly string[],
210
+ options: {
211
+ appRoot: string;
212
+ packageManager: PackageManager;
213
+ workspaceRoot?: string | null;
214
+ }
215
+ ): InstallPlan | null {
216
+ if (items.length === 0) return null;
217
+ const packageManager = options.workspaceRoot
218
+ ? "pnpm"
219
+ : options.packageManager;
220
+ const [command, ...exec] = EXEC[packageManager];
221
+ const synced = [BASE, ...items.filter((n) => n !== BASE)];
222
+ return {
223
+ install: hasLocalShadcn(options.appRoot)
224
+ ? null
225
+ : {
226
+ command: packageManager,
227
+ args: ["install"],
228
+ cwd: options.workspaceRoot ?? options.appRoot,
229
+ },
230
+ items: synced,
231
+ sync: {
232
+ command: command!,
233
+ args: [...exec, "intelligo", "sync", ...synced, "--force"],
234
+ cwd: options.appRoot,
235
+ },
236
+ };
237
+ }
@@ -1,11 +1,10 @@
1
1
  /**
2
- * The Intelligo operational console, mounted in your app.
2
+ * The operational console, mounted in your app.
3
3
  *
4
4
  * The screen itself ships from @intelligo-dev/admin so every deployment
5
5
  * shows the same operational truth — a fork could quietly stop showing
6
6
  * you unsettled executions. What is generated here is only the mount:
7
- * the route, the authorization call, and your own page chrome
8
- * (ADR-0002).
7
+ * the route, the authorization call, and your own page chrome.
9
8
  *
10
9
  * Access is gated on PLATFORM_ADMIN_EMAILS, not on a workspace role.
11
10
  * Workspace `owner` is per-tenant and every signup has one.
@@ -5,7 +5,7 @@
5
5
  * it runs inside an execution — entitlement decided, worst-case cost
6
6
  * held, usage settled, audit emitted. Swap `callModel` for a Mastra
7
7
  * agent, an AI SDK call, or anything else and nothing around it
8
- * changes (ADR-0003).
8
+ * changes.
9
9
  */
10
10
 
11
11
  import { requireWorkspace } from "@intelligo-dev/auth";
@@ -15,7 +15,7 @@ import { CAPABILITIES, composeIntelligo, executions } from "@/lib/intelligo";
15
15
  export const maxDuration = 60;
16
16
 
17
17
  async function callModel(prompt: string) {
18
- // Replace this with your framework's call.
18
+ // Your AI framework's call goes here.
19
19
  const inputTokens = Math.max(1, Math.ceil(prompt.length / 4));
20
20
  return {
21
21
  text: `Echo: ${prompt}`,
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Better-Auth's HTTP mount.
3
+ *
4
+ * Every call the auth client makes is a request to `/api/auth/*` on
5
+ * this app's own origin; without this file every sign-in POST answers
6
+ * 404. The handlers come from `@intelligo-dev/next`, so the app never
7
+ * depends on `better-auth` directly.
8
+ */
9
+
10
+ export { GET, POST } from "@intelligo-dev/next/auth";
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://ui.shadcn.com/schema.json",
3
- "style": "new-york",
3
+ "style": "base-nova",
4
4
  "rsc": true,
5
5
  "tsx": true,
6
6
  "tailwind": {
@@ -19,5 +19,9 @@
19
19
  "lib": "@/lib",
20
20
  "hooks": "@/hooks"
21
21
  },
22
- "registries": {}
22
+ "registries": {
23
+ "@intelligo": "https://intelligo.dev/r/{name}.json"
24
+ },
25
+ "menuColor": "default",
26
+ "menuAccent": "subtle"
23
27
  }