@intelligo-dev/cli 1.0.0-beta.13 → 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 (171) hide show
  1. package/README.md +41 -2
  2. package/dist/bin.js +37 -0
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/add.d.ts +4 -0
  5. package/dist/commands/add.d.ts.map +1 -1
  6. package/dist/commands/add.js +9 -0
  7. package/dist/commands/add.js.map +1 -1
  8. package/dist/commands/create-flow.d.ts +4 -1
  9. package/dist/commands/create-flow.d.ts.map +1 -1
  10. package/dist/commands/create-flow.js +63 -31
  11. package/dist/commands/create-flow.js.map +1 -1
  12. package/dist/commands/create.d.ts +8 -4
  13. package/dist/commands/create.d.ts.map +1 -1
  14. package/dist/commands/create.js +15 -7
  15. package/dist/commands/create.js.map +1 -1
  16. package/dist/commands/doctor.d.ts.map +1 -1
  17. package/dist/commands/doctor.js +21 -19
  18. package/dist/commands/doctor.js.map +1 -1
  19. package/dist/commands/migrate-check.d.ts +20 -1
  20. package/dist/commands/migrate-check.d.ts.map +1 -1
  21. package/dist/commands/migrate-check.js +35 -6
  22. package/dist/commands/migrate-check.js.map +1 -1
  23. package/dist/commands/migrate.d.ts.map +1 -1
  24. package/dist/commands/migrate.js +2 -8
  25. package/dist/commands/migrate.js.map +1 -1
  26. package/dist/commands/sync-messages.d.ts +37 -0
  27. package/dist/commands/sync-messages.d.ts.map +1 -0
  28. package/dist/commands/sync-messages.js +88 -0
  29. package/dist/commands/sync-messages.js.map +1 -0
  30. package/dist/commands/sync-scaffold.d.ts +36 -0
  31. package/dist/commands/sync-scaffold.d.ts.map +1 -0
  32. package/dist/commands/sync-scaffold.js +53 -0
  33. package/dist/commands/sync-scaffold.js.map +1 -0
  34. package/dist/commands/sync.d.ts +103 -0
  35. package/dist/commands/sync.d.ts.map +1 -0
  36. package/dist/commands/sync.js +361 -0
  37. package/dist/commands/sync.js.map +1 -0
  38. package/dist/commands/upgrade-check.d.ts.map +1 -1
  39. package/dist/commands/upgrade-check.js +4 -1
  40. package/dist/commands/upgrade-check.js.map +1 -1
  41. package/dist/manifest.d.ts +27 -0
  42. package/dist/manifest.d.ts.map +1 -1
  43. package/dist/manifest.js +30 -3
  44. package/dist/manifest.js.map +1 -1
  45. package/dist/module-exports.d.ts +63 -0
  46. package/dist/module-exports.d.ts.map +1 -0
  47. package/dist/module-exports.js +231 -0
  48. package/dist/module-exports.js.map +1 -0
  49. package/dist/registry-bundle.d.ts +43 -0
  50. package/dist/registry-bundle.d.ts.map +1 -0
  51. package/dist/registry-bundle.js +74 -0
  52. package/dist/registry-bundle.js.map +1 -0
  53. package/dist/registry-items.d.ts +41 -13
  54. package/dist/registry-items.d.ts.map +1 -1
  55. package/dist/registry-items.js +117 -33
  56. package/dist/registry-items.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/bin.ts +52 -0
  59. package/src/commands/add.ts +11 -0
  60. package/src/commands/create-flow.ts +82 -26
  61. package/src/commands/create.ts +17 -7
  62. package/src/commands/doctor.ts +27 -27
  63. package/src/commands/migrate-check.ts +51 -10
  64. package/src/commands/migrate.ts +2 -8
  65. package/src/commands/sync-messages.ts +114 -0
  66. package/src/commands/sync-scaffold.ts +83 -0
  67. package/src/commands/sync.ts +534 -0
  68. package/src/commands/upgrade-check.ts +4 -1
  69. package/src/manifest.ts +57 -3
  70. package/src/module-exports.ts +266 -0
  71. package/src/registry-bundle.ts +103 -0
  72. package/src/registry-items.ts +141 -36
  73. package/templates/app-scaffold/intelligo.ts.tpl +6 -47
  74. package/templates/manifest.json +19 -0
  75. package/templates/registry/ai-agent-activity.json +23 -0
  76. package/templates/registry/ai-agent-progress.json +21 -0
  77. package/templates/registry/ai-approval-card.json +27 -0
  78. package/templates/registry/ai-artifact.json +22 -0
  79. package/templates/registry/ai-branch.json +21 -0
  80. package/templates/registry/ai-citations.json +24 -0
  81. package/templates/registry/ai-code-block.json +23 -0
  82. package/templates/registry/ai-composer-menu.json +19 -0
  83. package/templates/registry/ai-file-diff.json +25 -0
  84. package/templates/registry/ai-image-generation.json +23 -0
  85. package/templates/registry/ai-markdown.json +23 -0
  86. package/templates/registry/ai-message-bubble.json +23 -0
  87. package/templates/registry/ai-message-scroller.json +22 -0
  88. package/templates/registry/ai-message.json +21 -0
  89. package/templates/registry/ai-motion.json +19 -0
  90. package/templates/registry/ai-prompt-input.json +28 -0
  91. package/templates/registry/ai-reasoning-text.json +22 -0
  92. package/templates/registry/ai-reasoning.json +22 -0
  93. package/templates/registry/ai-shimmer-text.json +19 -0
  94. package/templates/registry/ai-sidebar.json +25 -0
  95. package/templates/registry/ai-speech-input.json +21 -0
  96. package/templates/registry/ai-streaming-response.json +24 -0
  97. package/templates/registry/ai-suggestion.json +19 -0
  98. package/templates/registry/ai-todo-list.json +22 -0
  99. package/templates/registry/ai-tool-approval.json +26 -0
  100. package/templates/registry/ai-tool-result.json +25 -0
  101. package/templates/registry/alert-dialog.json +23 -0
  102. package/templates/registry/animated-list.json +21 -0
  103. package/templates/registry/app-shell.json +93 -0
  104. package/templates/registry/artifacts.json +82 -0
  105. package/templates/registry/attachment.json +22 -0
  106. package/templates/registry/auth-email-verification.json +39 -0
  107. package/templates/registry/auth-login.json +72 -0
  108. package/templates/registry/auth-password-reset.json +53 -0
  109. package/templates/registry/auth-signup.json +41 -0
  110. package/templates/registry/billing-settings.json +60 -0
  111. package/templates/registry/button.json +22 -0
  112. package/templates/registry/chat-eve.json +19 -0
  113. package/templates/registry/chat-panel.json +30 -0
  114. package/templates/registry/chat-share.json +42 -0
  115. package/templates/registry/chat-widget.json +34 -0
  116. package/templates/registry/chat.json +326 -0
  117. package/templates/registry/checkbox.json +22 -0
  118. package/templates/registry/checkout.json +40 -0
  119. package/templates/registry/collapsible.json +19 -0
  120. package/templates/registry/command.json +23 -0
  121. package/templates/registry/copy-button.json +21 -0
  122. package/templates/registry/dashboard.json +69 -0
  123. package/templates/registry/dialog.json +24 -0
  124. package/templates/registry/document-viewer.json +22 -0
  125. package/templates/registry/dropdown-menu.json +23 -0
  126. package/templates/registry/expandable-tabs.json +22 -0
  127. package/templates/registry/feature-gating.json +73 -0
  128. package/templates/registry/file-upload.json +24 -0
  129. package/templates/registry/hold-action-button.json +22 -0
  130. package/templates/registry/input-group.json +23 -0
  131. package/templates/registry/input.json +19 -0
  132. package/templates/registry/intelligo.json +187 -0
  133. package/templates/registry/invitation-accept.json +64 -0
  134. package/templates/registry/language-switcher.json +29 -0
  135. package/templates/registry/morphing-modal.json +24 -0
  136. package/templates/registry/notification-stack.json +24 -0
  137. package/templates/registry/notifications.json +87 -0
  138. package/templates/registry/onboarding.json +83 -0
  139. package/templates/registry/otp-input.json +22 -0
  140. package/templates/registry/page-header.json +15 -0
  141. package/templates/registry/payment-poll.json +52 -0
  142. package/templates/registry/popover-morph.json +22 -0
  143. package/templates/registry/popover.json +22 -0
  144. package/templates/registry/pricing.json +111 -0
  145. package/templates/registry/privacy-settings.json +65 -0
  146. package/templates/registry/profile-settings.json +68 -0
  147. package/templates/registry/progress.json +19 -0
  148. package/templates/registry/radio-group.json +22 -0
  149. package/templates/registry/registry.json +2945 -0
  150. package/templates/registry/route-error.json +65 -0
  151. package/templates/registry/select-morph.json +23 -0
  152. package/templates/registry/select.json +23 -0
  153. package/templates/registry/settings-shell.json +47 -0
  154. package/templates/registry/sheet.json +24 -0
  155. package/templates/registry/sidebar.json +28 -0
  156. package/templates/registry/smoke.json +34 -0
  157. package/templates/registry/spinner.json +16 -0
  158. package/templates/registry/stat-card.json +18 -0
  159. package/templates/registry/status-badge.json +18 -0
  160. package/templates/registry/switch.json +20 -0
  161. package/templates/registry/tabs.json +23 -0
  162. package/templates/registry/team-settings.json +97 -0
  163. package/templates/registry/textarea.json +16 -0
  164. package/templates/registry/tooltip.json +22 -0
  165. package/templates/registry/trial-banner.json +43 -0
  166. package/templates/registry/usage.json +84 -0
  167. package/templates/registry/workspace-settings.json +71 -0
  168. package/templates/registry-items.json +1 -1
  169. package/templates/registry-requires.json +26 -2
  170. package/templates/vitest/server-only.ts.tpl +7 -0
  171. package/templates/vitest/vitest.config.ts.tpl +37 -0
@@ -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
+ }
@@ -3,11 +3,10 @@
3
3
  * is, what else it needs installed first, and the commands that install
4
4
  * a selection into a fresh app.
5
5
  *
6
- * Installing is the shadcn CLI's job, not this package's — the items
7
- * are shadcn-schema JSON served at intelligo.dev/r, and the scaffold's
8
- * components.json already names that registry as `@intelligo`. What the
9
- * CLI adds is the order: an item that imports a sibling's files
10
- * (requires.json `items`) has to land after it.
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.
11
10
  */
12
11
 
13
12
  import { existsSync, readFileSync } from "node:fs";
@@ -79,10 +78,23 @@ export function detectPackageManager(
79
78
  return name === "npm" || name === "yarn" || name === "bun" ? name : "pnpm";
80
79
  }
81
80
 
82
- export type Command = { command: string; args: string[] };
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
+ };
83
87
 
84
- export function formatCommand(c: Command): string {
85
- return [c.command, ...c.args].join(" ");
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})`;
86
98
  }
87
99
 
88
100
  const EXEC: Record<PackageManager, string[]> = {
@@ -97,36 +109,129 @@ export function hasLocalShadcn(appRoot: string): boolean {
97
109
  return existsSync(path.join(appRoot, "node_modules", ".bin", "shadcn"));
98
110
  }
99
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
+
100
200
  /**
101
- * The commands that put `items` into the app at `appRoot`: install the
102
- * dependencies when shadcn is not there yet (the scaffold declares it),
103
- * then the design-system base, then the items in dependency order.
104
- * `--overwrite` because the base replaces the scaffold's globals.css,
105
- * and items that share a file agree on it — the same flags the
106
- * reference app is regenerated with.
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.
107
207
  */
108
208
  export function installPlan(
109
209
  items: readonly string[],
110
- options: { appRoot: string; packageManager: PackageManager }
111
- ): Command[] {
112
- if (items.length === 0) return [];
113
- const [command, ...exec] = EXEC[options.packageManager];
114
- const add = (names: string[]): Command => ({
115
- command: command!,
116
- args: [
117
- ...exec,
118
- "shadcn",
119
- "add",
120
- ...names.map((n) => `@intelligo/${n}`),
121
- "--yes",
122
- "--overwrite",
123
- ],
124
- });
125
- return [
126
- ...(hasLocalShadcn(options.appRoot)
127
- ? []
128
- : [{ command: options.packageManager, args: ["install"] }]),
129
- add(["intelligo"]),
130
- add([...items]),
131
- ];
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
+ };
132
237
  }
@@ -14,12 +14,9 @@ import "server-only";
14
14
  */
15
15
 
16
16
  import {
17
+ createBillingExecutions,
17
18
  ensureBillingSettingsRow,
18
19
  ensurePlanRows,
19
- reserveQuota,
20
- recordTokenUsage,
21
- releaseReservation,
22
- findSettlementByRequestId,
23
20
  } from "@intelligo-dev/billing";
24
21
  import { DEFAULT_MARGIN_BP } from "@intelligo-dev/executions/pricing";
25
22
  import {
@@ -33,7 +30,6 @@ import { assertEnv } from "@intelligo-dev/core/env";
33
30
  import { setRequestContextSource } from "@intelligo-dev/core/request-context";
34
31
  import {
35
32
  DEFAULT_MODELS,
36
- createExecutions,
37
33
  registerModels,
38
34
  } from "@intelligo-dev/executions";
39
35
  import { nextRequestContext } from "@intelligo-dev/next";
@@ -135,45 +131,8 @@ function bind(): void {
135
131
  registerModels(DEFAULT_MODELS);
136
132
  }
137
133
 
138
- export const executions = createExecutions({
139
- async checkEntitlement({ workspaceId, requestId, model }) {
140
- // Passing requestId makes admission atomic: the worst-case cost is
141
- // reserved in the same transaction that reads the balance, so
142
- // concurrent requests cannot all pass.
143
- const quota = await reserveQuota(workspaceId, { modelId: model, requestId });
144
- return {
145
- allowed: quota.allowed,
146
- code: quota.code,
147
- reason: quota.reason,
148
- // The hold, as an amount with its currency.
149
- estimated: quota.estimated,
150
- usingTrialCredits: quota.usingTrialCredits,
151
- };
152
- },
153
-
154
- async settleUsage(s) {
155
- // Returns what was charged and which pool funded it; the lifecycle
156
- // records the amount and its currency on the execution row.
157
- return recordTokenUsage({
158
- workspaceId: s.workspaceId,
159
- userId: s.userId ?? "",
160
- model: s.model ?? "unknown",
161
- agent: s.capability,
162
- inputTokens: s.inputTokens,
163
- outputTokens: s.outputTokens,
164
- totalTokens: s.totalTokens,
165
- usingTrialCredits: s.usingTrialCredits,
166
- requestId: s.requestId,
167
- metadata: s.metadata,
168
- });
169
- },
170
-
171
- async releaseHold({ requestId }) {
172
- await releaseReservation(requestId);
173
- },
174
-
175
- // Lets executions.reconcile() tell a settling row whose charge
176
- // committed from one whose charge never happened.
177
- findSettlement: ({ workspaceId, requestId }) =>
178
- findSettlementByRequestId(workspaceId, requestId),
179
- });
134
+ // The execution boundary, bound to the billing engine: admission
135
+ // reserves the worst-case cost atomically, settlement records usage and
136
+ // deducts credits, reconcile() can tell a committed charge from none.
137
+ // Pass a port to replace one.
138
+ export const executions = createBillingExecutions();
@@ -151,5 +151,24 @@
151
151
  "target": "app/api/cron/maintenance/route.ts"
152
152
  }
153
153
  ]
154
+ },
155
+ "vitest": {
156
+ "templateVersion": "1.0.0",
157
+ "description": "A Vitest setup for the app's own tests: the `@` alias, a `server-only` stub, and the `@intelligo-dev/*` packages inlined so the stub reaches them",
158
+ "files": [
159
+ {
160
+ "template": "vitest/vitest.config.ts.tpl",
161
+ "target": "vitest.config.ts"
162
+ },
163
+ {
164
+ "template": "vitest/server-only.ts.tpl",
165
+ "target": "tests/stubs/server-only.ts"
166
+ }
167
+ ],
168
+ "nextSteps": [
169
+ "Install the runner: pnpm add -D vitest",
170
+ "Add a script to package.json: \"test\": \"vitest run\"",
171
+ "Write tests beside the code as *.test.ts; mock @ai-sdk/* providers so CI makes no model calls"
172
+ ]
154
173
  }
155
174
  }