@agentuity/cli 1.0.47 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/cmd/build/app-router-detector.d.ts +2 -5
  2. package/dist/cmd/build/app-router-detector.d.ts.map +1 -1
  3. package/dist/cmd/build/app-router-detector.js +130 -154
  4. package/dist/cmd/build/app-router-detector.js.map +1 -1
  5. package/dist/cmd/build/ids.d.ts +11 -0
  6. package/dist/cmd/build/ids.d.ts.map +1 -0
  7. package/dist/cmd/build/ids.js +18 -0
  8. package/dist/cmd/build/ids.js.map +1 -0
  9. package/dist/cmd/build/vite/agent-discovery.d.ts +8 -4
  10. package/dist/cmd/build/vite/agent-discovery.d.ts.map +1 -1
  11. package/dist/cmd/build/vite/agent-discovery.js +166 -487
  12. package/dist/cmd/build/vite/agent-discovery.js.map +1 -1
  13. package/dist/cmd/build/vite/bun-dev-server.d.ts +10 -16
  14. package/dist/cmd/build/vite/bun-dev-server.d.ts.map +1 -1
  15. package/dist/cmd/build/vite/bun-dev-server.js +67 -134
  16. package/dist/cmd/build/vite/bun-dev-server.js.map +1 -1
  17. package/dist/cmd/build/vite/docs-generator.d.ts.map +1 -1
  18. package/dist/cmd/build/vite/docs-generator.js +0 -2
  19. package/dist/cmd/build/vite/docs-generator.js.map +1 -1
  20. package/dist/cmd/build/vite/index.d.ts.map +1 -1
  21. package/dist/cmd/build/vite/index.js +0 -36
  22. package/dist/cmd/build/vite/index.js.map +1 -1
  23. package/dist/cmd/build/vite/lifecycle-generator.d.ts +10 -2
  24. package/dist/cmd/build/vite/lifecycle-generator.d.ts.map +1 -1
  25. package/dist/cmd/build/vite/lifecycle-generator.js +302 -23
  26. package/dist/cmd/build/vite/lifecycle-generator.js.map +1 -1
  27. package/dist/cmd/build/vite/route-discovery.d.ts +11 -38
  28. package/dist/cmd/build/vite/route-discovery.d.ts.map +1 -1
  29. package/dist/cmd/build/vite/route-discovery.js +97 -177
  30. package/dist/cmd/build/vite/route-discovery.js.map +1 -1
  31. package/dist/cmd/build/vite/server-bundler.js +1 -1
  32. package/dist/cmd/build/vite/server-bundler.js.map +1 -1
  33. package/dist/cmd/build/vite/static-renderer.d.ts.map +1 -1
  34. package/dist/cmd/build/vite/static-renderer.js +1 -9
  35. package/dist/cmd/build/vite/static-renderer.js.map +1 -1
  36. package/dist/cmd/build/vite/vite-asset-server-config.d.ts +6 -3
  37. package/dist/cmd/build/vite/vite-asset-server-config.d.ts.map +1 -1
  38. package/dist/cmd/build/vite/vite-asset-server-config.js +171 -18
  39. package/dist/cmd/build/vite/vite-asset-server-config.js.map +1 -1
  40. package/dist/cmd/build/vite/vite-asset-server.d.ts +8 -3
  41. package/dist/cmd/build/vite/vite-asset-server.d.ts.map +1 -1
  42. package/dist/cmd/build/vite/vite-asset-server.js +14 -13
  43. package/dist/cmd/build/vite/vite-asset-server.js.map +1 -1
  44. package/dist/cmd/build/vite/vite-builder.d.ts.map +1 -1
  45. package/dist/cmd/build/vite/vite-builder.js +6 -34
  46. package/dist/cmd/build/vite/vite-builder.js.map +1 -1
  47. package/dist/cmd/build/vite/ws-proxy.d.ts +53 -0
  48. package/dist/cmd/build/vite/ws-proxy.d.ts.map +1 -0
  49. package/dist/cmd/build/vite/ws-proxy.js +95 -0
  50. package/dist/cmd/build/vite/ws-proxy.js.map +1 -0
  51. package/dist/cmd/build/vite-bundler.d.ts.map +1 -1
  52. package/dist/cmd/build/vite-bundler.js +0 -3
  53. package/dist/cmd/build/vite-bundler.js.map +1 -1
  54. package/dist/cmd/dev/file-watcher.d.ts.map +1 -1
  55. package/dist/cmd/dev/file-watcher.js +2 -8
  56. package/dist/cmd/dev/file-watcher.js.map +1 -1
  57. package/dist/cmd/dev/index.d.ts.map +1 -1
  58. package/dist/cmd/dev/index.js +369 -720
  59. package/dist/cmd/dev/index.js.map +1 -1
  60. package/package.json +6 -8
  61. package/src/cmd/ai/prompt/agent.md +0 -1
  62. package/src/cmd/ai/prompt/api.md +0 -7
  63. package/src/cmd/ai/prompt/web.md +51 -213
  64. package/src/cmd/build/app-router-detector.ts +152 -182
  65. package/src/cmd/build/ids.ts +19 -0
  66. package/src/cmd/build/vite/agent-discovery.ts +208 -679
  67. package/src/cmd/build/vite/bun-dev-server.ts +78 -154
  68. package/src/cmd/build/vite/docs-generator.ts +0 -2
  69. package/src/cmd/build/vite/index.ts +1 -42
  70. package/src/cmd/build/vite/lifecycle-generator.ts +345 -21
  71. package/src/cmd/build/vite/route-discovery.ts +116 -274
  72. package/src/cmd/build/vite/server-bundler.ts +1 -1
  73. package/src/cmd/build/vite/static-renderer.ts +1 -11
  74. package/src/cmd/build/vite/vite-asset-server-config.ts +196 -20
  75. package/src/cmd/build/vite/vite-asset-server.ts +25 -15
  76. package/src/cmd/build/vite/vite-builder.ts +6 -51
  77. package/src/cmd/build/vite/ws-proxy.ts +126 -0
  78. package/src/cmd/build/vite-bundler.ts +0 -4
  79. package/src/cmd/dev/file-watcher.ts +2 -9
  80. package/src/cmd/dev/index.ts +409 -832
  81. package/dist/cmd/build/ast.d.ts +0 -78
  82. package/dist/cmd/build/ast.d.ts.map +0 -1
  83. package/dist/cmd/build/ast.js +0 -2703
  84. package/dist/cmd/build/ast.js.map +0 -1
  85. package/dist/cmd/build/entry-generator.d.ts +0 -25
  86. package/dist/cmd/build/entry-generator.d.ts.map +0 -1
  87. package/dist/cmd/build/entry-generator.js +0 -695
  88. package/dist/cmd/build/entry-generator.js.map +0 -1
  89. package/dist/cmd/build/vite/api-mount-path.d.ts +0 -61
  90. package/dist/cmd/build/vite/api-mount-path.d.ts.map +0 -1
  91. package/dist/cmd/build/vite/api-mount-path.js +0 -83
  92. package/dist/cmd/build/vite/api-mount-path.js.map +0 -1
  93. package/dist/cmd/build/vite/registry-generator.d.ts +0 -19
  94. package/dist/cmd/build/vite/registry-generator.d.ts.map +0 -1
  95. package/dist/cmd/build/vite/registry-generator.js +0 -1108
  96. package/dist/cmd/build/vite/registry-generator.js.map +0 -1
  97. package/dist/cmd/build/webanalytics-generator.d.ts +0 -16
  98. package/dist/cmd/build/webanalytics-generator.d.ts.map +0 -1
  99. package/dist/cmd/build/webanalytics-generator.js +0 -178
  100. package/dist/cmd/build/webanalytics-generator.js.map +0 -1
  101. package/dist/cmd/build/workbench.d.ts +0 -7
  102. package/dist/cmd/build/workbench.d.ts.map +0 -1
  103. package/dist/cmd/build/workbench.js +0 -55
  104. package/dist/cmd/build/workbench.js.map +0 -1
  105. package/dist/utils/route-migration.d.ts +0 -62
  106. package/dist/utils/route-migration.d.ts.map +0 -1
  107. package/dist/utils/route-migration.js +0 -630
  108. package/dist/utils/route-migration.js.map +0 -1
  109. package/src/cmd/build/ast.ts +0 -3529
  110. package/src/cmd/build/entry-generator.ts +0 -760
  111. package/src/cmd/build/vite/api-mount-path.ts +0 -87
  112. package/src/cmd/build/vite/registry-generator.ts +0 -1267
  113. package/src/cmd/build/webanalytics-generator.ts +0 -197
  114. package/src/cmd/build/workbench.ts +0 -58
  115. package/src/utils/route-migration.ts +0 -757
@@ -1,15 +1,331 @@
1
1
  /**
2
2
  * Lifecycle Types Generator
3
3
  *
4
- * Generates src/generated/lifecycle.d.ts by analyzing app.ts for setup() function
4
+ * Generates src/generated/state.ts and src/generated/router.ts by analyzing
5
+ * app.ts for a setup() function.
6
+ *
7
+ * Uses TypeScript's type checker to extract the real return type of setup —
8
+ * no AST literal guessing needed.
5
9
  */
6
10
 
7
- import { join } from 'node:path';
8
- import { generateLifecycleTypes as generateLifecycleTypesFromAST } from '../ast';
11
+ import ts from 'typescript';
12
+ import { join, relative, dirname } from 'node:path';
13
+ import { mkdirSync } from 'node:fs';
14
+ import { StructuredError } from '@agentuity/core';
9
15
  import type { Logger } from '../../../types';
16
+ import { toForwardSlash } from '../../../utils/normalize-path';
17
+
18
+ const RuntimePackageNotFound = StructuredError('RuntimePackageNotFound');
19
+
20
+ /**
21
+ * Use the TypeScript type checker to extract the return type of the setup
22
+ * function passed to createApp(). Works with inline setup, exported setup,
23
+ * variable references, async functions — anything TS can resolve.
24
+ */
25
+ function extractSetupReturnType(appFilePath: string, logger: Logger): string | null {
26
+ const compilerOptions: ts.CompilerOptions = {
27
+ target: ts.ScriptTarget.ESNext,
28
+ module: ts.ModuleKind.ESNext,
29
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
30
+ strict: true,
31
+ skipLibCheck: true,
32
+ noEmit: true,
33
+ allowJs: true,
34
+ esModuleInterop: true,
35
+ };
36
+
37
+ const program = ts.createProgram([appFilePath], compilerOptions);
38
+ const checker = program.getTypeChecker();
39
+ const sourceFile = program.getSourceFile(appFilePath);
40
+
41
+ if (!sourceFile) {
42
+ logger.debug('[lifecycle] Could not load source file');
43
+ return null;
44
+ }
45
+
46
+ let setupType: ts.Type | null = null;
47
+
48
+ function unwrapPromise(type: ts.Type): ts.Type {
49
+ // Check for Promise by looking at typeArguments on TypeReference
50
+ const typeRef = type as ts.TypeReference;
51
+ if (typeRef.typeArguments && typeRef.typeArguments.length > 0) {
52
+ const symbol = type.getSymbol() ?? type.aliasSymbol;
53
+ if (symbol?.name === 'Promise') {
54
+ return typeRef.typeArguments[0]!;
55
+ }
56
+ }
57
+ return type;
58
+ }
59
+
60
+ function extractFromProperty(prop: ts.ObjectLiteralElementLike): void {
61
+ if (setupType) return;
62
+
63
+ // Handle: setup: () => { ... } or setup: myFunc
64
+ if (
65
+ ts.isPropertyAssignment(prop) &&
66
+ ts.isIdentifier(prop.name) &&
67
+ prop.name.text === 'setup'
68
+ ) {
69
+ const type = checker.getTypeAtLocation(prop.initializer);
70
+ const callSigs = type.getCallSignatures();
71
+ if (callSigs.length > 0) {
72
+ setupType = unwrapPromise(checker.getReturnTypeOfSignature(callSigs[0]!));
73
+ }
74
+ return;
75
+ }
76
+
77
+ // Handle shorthand: createApp({ setup })
78
+ if (ts.isShorthandPropertyAssignment(prop) && prop.name.text === 'setup') {
79
+ const type = checker.getTypeAtLocation(prop.name);
80
+ const callSigs = type.getCallSignatures();
81
+ if (callSigs.length > 0) {
82
+ setupType = unwrapPromise(checker.getReturnTypeOfSignature(callSigs[0]!));
83
+ }
84
+ }
85
+ }
86
+
87
+ function visit(node: ts.Node): void {
88
+ if (setupType) return;
89
+
90
+ // Find createApp(...) call — with or without await
91
+ let callExpr: ts.CallExpression | undefined;
92
+
93
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
94
+ if (node.expression.text === 'createApp') callExpr = node;
95
+ } else if (ts.isAwaitExpression(node) && ts.isCallExpression(node.expression)) {
96
+ const call = node.expression;
97
+ if (ts.isIdentifier(call.expression) && call.expression.text === 'createApp') {
98
+ callExpr = call;
99
+ }
100
+ }
101
+
102
+ if (callExpr && callExpr.arguments.length > 0) {
103
+ const configArg = callExpr.arguments[0];
104
+ if (configArg && ts.isObjectLiteralExpression(configArg)) {
105
+ for (const prop of configArg.properties) {
106
+ extractFromProperty(prop);
107
+ if (setupType) return;
108
+ }
109
+ }
110
+ }
111
+
112
+ ts.forEachChild(node, visit);
113
+ }
114
+
115
+ visit(sourceFile);
116
+
117
+ // Fallback: look for an exported function named `setup` in the file
118
+ // (user may define `export function setup()` without passing it to createApp)
119
+ if (!setupType) {
120
+ for (const stmt of sourceFile.statements) {
121
+ if (
122
+ ts.isFunctionDeclaration(stmt) &&
123
+ stmt.name?.text === 'setup' &&
124
+ stmt.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)
125
+ ) {
126
+ const type = checker.getTypeAtLocation(stmt);
127
+ const callSigs = type.getCallSignatures();
128
+ if (callSigs.length > 0) {
129
+ setupType = unwrapPromise(checker.getReturnTypeOfSignature(callSigs[0]!));
130
+ }
131
+ break;
132
+ }
133
+
134
+ // Handle: export const setup = () => { ... }
135
+ if (
136
+ ts.isVariableStatement(stmt) &&
137
+ stmt.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)
138
+ ) {
139
+ for (const decl of stmt.declarationList.declarations) {
140
+ if (ts.isIdentifier(decl.name) && decl.name.text === 'setup' && decl.initializer) {
141
+ const type = checker.getTypeAtLocation(decl.initializer);
142
+ const callSigs = type.getCallSignatures();
143
+ if (callSigs.length > 0) {
144
+ setupType = unwrapPromise(checker.getReturnTypeOfSignature(callSigs[0]!));
145
+ }
146
+ break;
147
+ }
148
+ }
149
+ if (setupType) break;
150
+ }
151
+ }
152
+ }
153
+
154
+ if (!setupType) {
155
+ return null;
156
+ }
157
+
158
+ // Print the type as a string — TS gives us the real resolved type
159
+ const typeString = checker.typeToString(
160
+ setupType,
161
+ undefined,
162
+ ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.MultilineObjectLiterals
163
+ );
164
+
165
+ return typeString;
166
+ }
167
+
168
+ /**
169
+ * Find the @agentuity/runtime package by walking up the directory tree.
170
+ */
171
+ async function findRuntimePackage(rootDir: string, logger: Logger): Promise<string> {
172
+ let currentDir = rootDir;
173
+ const searchedPaths: string[] = [];
174
+
175
+ while (currentDir && currentDir !== '/' && currentDir !== '.') {
176
+ const candidatePath = join(currentDir, 'node_modules', '@agentuity', 'runtime');
177
+ searchedPaths.push(candidatePath);
178
+ if (await Bun.file(join(candidatePath, 'package.json')).exists()) {
179
+ logger.debug(`Found runtime package at: ${candidatePath}`);
180
+ return candidatePath;
181
+ }
182
+
183
+ const packagesPath = join(currentDir, 'packages', 'runtime');
184
+ searchedPaths.push(packagesPath);
185
+ if (await Bun.file(join(packagesPath, 'package.json')).exists()) {
186
+ logger.debug(`Found runtime package (source) at: ${packagesPath}`);
187
+ return packagesPath;
188
+ }
189
+
190
+ const parent = dirname(currentDir);
191
+ if (parent === currentDir) break;
192
+ currentDir = parent;
193
+ }
194
+
195
+ throw new RuntimePackageNotFound({
196
+ message:
197
+ `@agentuity/runtime package not found.\n` +
198
+ `Searched paths:\n${searchedPaths.map((p) => ` - ${p}`).join('\n')}\n` +
199
+ `Make sure dependencies are installed by running 'bun install' or 'npm install'`,
200
+ });
201
+ }
202
+
203
+ function generateStateContent(appStateType: string): string {
204
+ return `// @generated
205
+ // AUTO-GENERATED from app.ts setup() return type
206
+ // This file is auto-generated by the build tool - do not edit manually
10
207
 
11
208
  /**
12
- * Setup lifecycle types by analyzing app.ts for setup() function
209
+ * Application state type inferred from your createApp setup function.
210
+ * This type is automatically generated and available throughout your app via ctx.app.
211
+ *
212
+ * @example
213
+ * \`\`\`typescript
214
+ * // In your agents:
215
+ * const agent = createAgent({
216
+ * handler: async (ctx, input) => {
217
+ * // ctx.app is strongly typed as GeneratedAppState
218
+ * const value = ctx.app; // All properties from your setup return value
219
+ * return 'result';
220
+ * }
221
+ * });
222
+ * \`\`\`
223
+ */
224
+ export type GeneratedAppState = ${appStateType};
225
+
226
+ // Augment the @agentuity/runtime module with AppState
227
+ declare module '@agentuity/runtime' {
228
+ interface AppState extends GeneratedAppState {}
229
+ }
230
+
231
+ // FOUND AN ERROR IN THIS FILE?
232
+ // Please file an issue at https://github.com/agentuity/sdk/issues
233
+ // or if you know the fix please submit a PR!
234
+ `;
235
+ }
236
+
237
+ function generateRouterWrapper(runtimeImportPath: string): string {
238
+ return `// @generated
239
+ // AUTO-GENERATED runtime wrapper
240
+ // This file is auto-generated by the build tool - do not edit manually
241
+
242
+ // Import augmentations file (NOT type-only) to trigger module augmentation
243
+ import type { GeneratedAppState } from './state';
244
+ import './state';
245
+
246
+ // Import from actual package location
247
+ import { createRouter as baseCreateRouter, type Env } from '${runtimeImportPath}/src/index';
248
+ import type { Hono } from 'hono';
249
+
250
+ // Type aliases to avoid repeating the generic parameter
251
+ type AppEnv = Env<GeneratedAppState>;
252
+ type AppRouter = Hono<AppEnv>;
253
+
254
+ /**
255
+ * Creates a Hono router with extended methods for Agentuity-specific routing patterns.
256
+ *
257
+ * @returns Extended Hono router with custom methods and app state typing
258
+ *
259
+ * @example
260
+ * \`\`\`typescript
261
+ * const router = createRouter();
262
+ * router.get('/hello', (c) => c.text('Hello!'));
263
+ * router.get('/db', (c) => {
264
+ * const db = c.var.app; // Your app state from createApp setup
265
+ * return c.json({ connected: true });
266
+ * });
267
+ * \`\`\`
268
+ */
269
+ export function createRouter(): AppRouter {
270
+ return baseCreateRouter() as unknown as AppRouter;
271
+ }
272
+
273
+ // Re-export everything else
274
+ export * from '${runtimeImportPath}/src/index';
275
+
276
+ // FOUND AN ERROR IN THIS FILE?
277
+ // Please file an issue at https://github.com/agentuity/sdk/issues
278
+ // or if you know the fix please submit a PR!
279
+ `;
280
+ }
281
+
282
+ async function updateTsconfigPathMapping(
283
+ rootDir: string,
284
+ shouldAdd: boolean,
285
+ logger: Logger
286
+ ): Promise<void> {
287
+ const tsconfigPath = join(rootDir, 'tsconfig.json');
288
+ if (!(await Bun.file(tsconfigPath).exists())) {
289
+ logger.debug('No tsconfig.json found, skipping path mapping update');
290
+ return;
291
+ }
292
+
293
+ try {
294
+ const tsconfigContent = await Bun.file(tsconfigPath).text();
295
+ const { parseJSONC } = await import('../../../utils/jsonc');
296
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
297
+ const tsconfig = parseJSONC(tsconfigContent) as any;
298
+ const before = JSON.stringify(tsconfig);
299
+
300
+ if (!tsconfig.compilerOptions) tsconfig.compilerOptions = {};
301
+ if (!tsconfig.compilerOptions.paths) tsconfig.compilerOptions.paths = {};
302
+
303
+ if (shouldAdd) {
304
+ tsconfig.compilerOptions.paths['@agentuity/runtime'] = ['./src/generated/router.ts'];
305
+ logger.debug('Added @agentuity/runtime path mapping to tsconfig.json');
306
+ } else {
307
+ if (tsconfig.compilerOptions.paths['@agentuity/runtime']) {
308
+ delete tsconfig.compilerOptions.paths['@agentuity/runtime'];
309
+ logger.debug('Removed @agentuity/runtime path mapping from tsconfig.json');
310
+ }
311
+ if (Object.keys(tsconfig.compilerOptions.paths).length === 0) {
312
+ delete tsconfig.compilerOptions.paths;
313
+ }
314
+ }
315
+
316
+ if (JSON.stringify(tsconfig) === before) return;
317
+ await Bun.write(tsconfigPath, JSON.stringify(tsconfig, null, '\t') + '\n');
318
+ } catch (error) {
319
+ logger.warn('Failed to update tsconfig.json:', error);
320
+ }
321
+ }
322
+
323
+ /**
324
+ * Setup lifecycle types by analyzing app.ts for setup() function.
325
+ *
326
+ * Uses TypeScript's type checker to extract the real return type — handles
327
+ * inline setup, exported setup, variable references, async functions, and
328
+ * any other pattern TS can resolve.
13
329
  */
14
330
  export async function generateLifecycleTypes(
15
331
  rootDir: string,
@@ -17,11 +333,8 @@ export async function generateLifecycleTypes(
17
333
  logger: Logger
18
334
  ): Promise<boolean> {
19
335
  logger.debug('[lifecycle] Starting lifecycle type generation...');
20
- logger.debug(`[lifecycle] rootDir: ${rootDir}`);
21
- logger.debug(`[lifecycle] srcDir: ${srcDir}`);
22
336
 
23
337
  const outDir = join(srcDir, 'generated');
24
- logger.debug(`[lifecycle] outDir: ${outDir}`);
25
338
 
26
339
  // Look for app.ts in both root and src directories
27
340
  const rootAppFile = join(rootDir, 'app.ts');
@@ -30,28 +343,39 @@ export async function generateLifecycleTypes(
30
343
  let appFile = '';
31
344
  if (await Bun.file(rootAppFile).exists()) {
32
345
  appFile = rootAppFile;
33
- logger.debug(`[lifecycle] Found app.ts at root: ${rootAppFile}`);
34
346
  } else if (await Bun.file(srcAppFile).exists()) {
35
347
  appFile = srcAppFile;
36
- logger.debug(`[lifecycle] Found app.ts in src: ${srcAppFile}`);
37
348
  }
38
349
 
39
350
  if (!appFile || !(await Bun.file(appFile).exists())) {
40
- logger.debug('[lifecycle] No app.ts found for lifecycle types generation');
351
+ logger.debug('[lifecycle] No app.ts found');
41
352
  return false;
42
353
  }
43
354
 
44
- try {
45
- logger.debug(`[lifecycle] Calling generateLifecycleTypesFromAST...`);
46
- const result = await generateLifecycleTypesFromAST(rootDir, outDir, appFile);
47
- if (result) {
48
- logger.debug(`[lifecycle] Lifecycle types generated successfully in ${outDir}`);
49
- } else {
50
- logger.debug('[lifecycle] generateLifecycleTypesFromAST returned false (no setup found)');
51
- }
52
- return result;
53
- } catch (error) {
54
- logger.error('[lifecycle] Failed to generate lifecycle types:', error);
355
+ // Use TypeScript type checker to extract the setup return type
356
+ const appStateType = extractSetupReturnType(appFile, logger);
357
+
358
+ if (!appStateType) {
359
+ logger.debug('[lifecycle] No setup() function found in createApp');
360
+ await updateTsconfigPathMapping(rootDir, false, logger);
55
361
  return false;
56
362
  }
363
+
364
+ logger.debug(`[lifecycle] Extracted setup return type: ${appStateType}`);
365
+
366
+ // Generate files
367
+ mkdirSync(outDir, { recursive: true });
368
+
369
+ const runtimePkgPath = await findRuntimePackage(rootDir, logger);
370
+ const runtimeImportPath = toForwardSlash(relative(outDir, runtimePkgPath));
371
+
372
+ await Bun.write(join(outDir, 'state.ts'), generateStateContent(appStateType));
373
+ logger.debug(`Generated lifecycle types: ${join(outDir, 'state.ts')}`);
374
+
375
+ await Bun.write(join(outDir, 'router.ts'), generateRouterWrapper(runtimeImportPath));
376
+ logger.debug(`Generated lifecycle wrapper: ${join(outDir, 'router.ts')}`);
377
+
378
+ await updateTsconfigPathMapping(rootDir, true, logger);
379
+
380
+ return true;
57
381
  }