@agentuity/migrate 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -0
- package/bin/migrate.ts +60 -0
- package/dist/detect.d.ts +56 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +561 -0
- package/dist/detect.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate.d.ts +29 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +315 -0
- package/dist/migrate.js.map +1 -0
- package/dist/report.d.ts +22 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +159 -0
- package/dist/report.js.map +1 -0
- package/dist/transforms/app-ts.d.ts +29 -0
- package/dist/transforms/app-ts.d.ts.map +1 -0
- package/dist/transforms/app-ts.js +114 -0
- package/dist/transforms/app-ts.js.map +1 -0
- package/dist/transforms/barrels.d.ts +12 -0
- package/dist/transforms/barrels.d.ts.map +1 -0
- package/dist/transforms/barrels.js +103 -0
- package/dist/transforms/barrels.js.map +1 -0
- package/dist/transforms/generated.d.ts +7 -0
- package/dist/transforms/generated.d.ts.map +1 -0
- package/dist/transforms/generated.js +10 -0
- package/dist/transforms/generated.js.map +1 -0
- package/dist/transforms/routes.d.ts +49 -0
- package/dist/transforms/routes.d.ts.map +1 -0
- package/dist/transforms/routes.js +208 -0
- package/dist/transforms/routes.js.map +1 -0
- package/package.json +45 -0
- package/src/detect.ts +694 -0
- package/src/index.ts +9 -0
- package/src/migrate.ts +379 -0
- package/src/report.ts +195 -0
- package/src/transforms/app-ts.ts +144 -0
- package/src/transforms/barrels.ts +138 -0
- package/src/transforms/generated.ts +11 -0
- package/src/transforms/routes.ts +273 -0
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# @agentuity/migrate
|
|
2
|
+
|
|
3
|
+
CLI tool to migrate Agentuity SDK projects from v1 to v2.
|
|
4
|
+
|
|
5
|
+
## What's Changed in v2
|
|
6
|
+
|
|
7
|
+
v2 introduces six fundamental architectural changes:
|
|
8
|
+
|
|
9
|
+
### 1. Agents are Declarative
|
|
10
|
+
|
|
11
|
+
**v1**: Agents were auto-discovered from `src/agent/*/agent.ts` files at runtime.
|
|
12
|
+
|
|
13
|
+
**v2**: Agents must be explicitly imported and passed to `createApp()`:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createApp } from '@agentuity/runtime';
|
|
17
|
+
import * as agents from './agent'; // Barrel export
|
|
18
|
+
|
|
19
|
+
export default createApp({
|
|
20
|
+
agents, // Explicit declaration
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. No More setup/shutdown Hooks
|
|
25
|
+
|
|
26
|
+
**v1**: Lifecycle hooks in `createApp()`:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
createApp({
|
|
30
|
+
setup: async (ctx) => { /* initialize */ },
|
|
31
|
+
shutdown: async (ctx) => { /* cleanup */ }
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**v2**: Use standard patterns:
|
|
36
|
+
- **Initialization**: Module-level code (runs when file loads)
|
|
37
|
+
- **Cleanup**: Hono middleware or Bun's `process.on('beforeExit', ...)`
|
|
38
|
+
|
|
39
|
+
### 3. Router is Required
|
|
40
|
+
|
|
41
|
+
**v1**: File-based auto-discovery — routes in `src/api/*.ts` were automatically mounted.
|
|
42
|
+
|
|
43
|
+
**v2**: You must explicitly provide a router to `createApp()`:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import router from './api'; // Your Hono router
|
|
47
|
+
|
|
48
|
+
export default createApp({
|
|
49
|
+
router, // Required — no more auto-discovery
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The old file-based approach no longer works. Routes must be composed into a barrel (`src/api/index.ts`) and exported as a Hono instance.
|
|
54
|
+
|
|
55
|
+
### 4. Use Hono Directly (No createRouter)
|
|
56
|
+
|
|
57
|
+
**v1**: `createRouter()` was a wrapper around Hono:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { createRouter } from '@agentuity/runtime';
|
|
61
|
+
|
|
62
|
+
const router = createRouter();
|
|
63
|
+
router.get('/hello', async (c) => c.json({ msg: 'hi' }));
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**v2**: Use Hono directly with chained methods:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { Hono } from 'hono';
|
|
70
|
+
import type { Env } from '@agentuity/runtime';
|
|
71
|
+
|
|
72
|
+
const router = new Hono<Env>()
|
|
73
|
+
.get('/hello', async (c) => c.json({ msg: 'hi' }));
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 5. React Helpers Removed
|
|
77
|
+
|
|
78
|
+
**v1**: `@agentuity/react` exported `createClient`, `useAPI`, `RPCRouteRegistry` for API calls.
|
|
79
|
+
|
|
80
|
+
**v2**: These are removed. Use your preferred data fetching library:
|
|
81
|
+
- **Hono client directly**: `hc<AppRouter>()` from `hono/client`
|
|
82
|
+
- **TanStack Query**: Combine with Hono client for caching, background updates
|
|
83
|
+
- **SWR**: Stale-while-revalidate pattern
|
|
84
|
+
- **RTK Query**: If already using Redux Toolkit
|
|
85
|
+
|
|
86
|
+
Example with TanStack Query:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { useQuery } from '@tanstack/react-query';
|
|
90
|
+
import { hc } from 'hono/client';
|
|
91
|
+
import type { AppRouter } from '../api';
|
|
92
|
+
|
|
93
|
+
const client = hc<AppRouter>('/api');
|
|
94
|
+
|
|
95
|
+
function useHello() {
|
|
96
|
+
return useQuery({
|
|
97
|
+
queryKey: ['hello'],
|
|
98
|
+
queryFn: async () => {
|
|
99
|
+
const res = await client.hello.$get();
|
|
100
|
+
return res.json();
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 6. Standard vite.config.ts
|
|
107
|
+
|
|
108
|
+
**v1**: Vite config lived inside `agentuity.config.ts` along with workbench settings.
|
|
109
|
+
|
|
110
|
+
**v2**: Use standard `vite.config.ts` for build config; runtime settings go in `createApp()`:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// vite.config.ts
|
|
114
|
+
import { defineConfig } from 'vite';
|
|
115
|
+
import react from '@vitejs/plugin-react';
|
|
116
|
+
|
|
117
|
+
export default defineConfig({
|
|
118
|
+
plugins: [react()], // Add your frontend framework's plugin
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// app.ts
|
|
124
|
+
import { createApp } from '@agentuity/runtime';
|
|
125
|
+
|
|
126
|
+
export default createApp({
|
|
127
|
+
analytics: true,
|
|
128
|
+
workbench: true,
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
> **Note**: v2 doesn't include a default Vite plugin. You must add the plugin for your frontend framework (React, Vue, Svelte, Solid, etc.).
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Usage
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npx @agentuity/migrate [project-dir] [options]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Run in your project root (or pass a path). The tool checks that your **git worktree is clean** before touching anything, so you can always `git diff` to review changes or `git checkout .` to roll back.
|
|
143
|
+
|
|
144
|
+
## Options
|
|
145
|
+
|
|
146
|
+
| Flag | Description |
|
|
147
|
+
|---|---|
|
|
148
|
+
| `--yes`, `-y` | Skip interactive confirmation |
|
|
149
|
+
| `--dry-run` | Print the migration report without modifying files |
|
|
150
|
+
| `--help`, `-h` | Show help |
|
|
151
|
+
|
|
152
|
+
## What it migrates
|
|
153
|
+
|
|
154
|
+
### Auto-fixable (fully automated)
|
|
155
|
+
|
|
156
|
+
| Finding | Action |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `src/generated/` directory | Deleted |
|
|
159
|
+
| `bootstrapRuntimeEnv()` call in `app.ts` | Removed (createApp handles it) |
|
|
160
|
+
| v1 `createRouter()` + mutating `.get()/.post()` route files | Rewritten to `new Hono<Env>()` chained style |
|
|
161
|
+
| Missing `src/api/index.ts` barrel | Generated from discovered route files |
|
|
162
|
+
| Missing `src/agent/index.ts` barrel | Generated from discovered agent files |
|
|
163
|
+
|
|
164
|
+
### Guided (applied with your review)
|
|
165
|
+
|
|
166
|
+
| Finding | What happens |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `setup` in `createApp()` | Migration comment added — move init to module level |
|
|
169
|
+
| `shutdown` in `createApp()` | Guidance to use Hono's lifecycle hooks instead |
|
|
170
|
+
| No `router`/`agents` in `createApp()` | Guidance shown — wire up the generated barrels |
|
|
171
|
+
| `agentuity.config.ts` has Vite keys | Guidance to create `vite.config.ts` with plugins/define/render/bundle |
|
|
172
|
+
| `agentuity.config.ts` has analytics/workbench | Remove — keep only in `createApp()` |
|
|
173
|
+
| `agentuity.config.ts` empty | Can be deleted |
|
|
174
|
+
|
|
175
|
+
### Manual (instructions only, no auto-transform)
|
|
176
|
+
|
|
177
|
+
| Finding | Guidance |
|
|
178
|
+
|---|---|
|
|
179
|
+
| Frontend files using `createClient`, `useAPI`, `useAgentuity`, `RPCRouteRegistry` etc. | Replace with `hc<AppRouter>()` from `hono/client` or your preferred data fetching library |
|
|
180
|
+
|
|
181
|
+
## V1 → V2 changes summary
|
|
182
|
+
|
|
183
|
+
**Configuration (consolidated)**
|
|
184
|
+
- v1: Config split between `app.ts` and `agentuity.config.ts`
|
|
185
|
+
- v2: **All runtime config in `createApp()`** — analytics, workbench, cors, compression, etc.
|
|
186
|
+
- v2: **Vite config in `vite.config.ts`** — plugins, define, render, bundle
|
|
187
|
+
- v2: `agentuity.config.ts` is **deprecated** — delete it
|
|
188
|
+
|
|
189
|
+
**`app.ts` entrypoint**
|
|
190
|
+
- v1: thin shell; CLI generated a 500-line `src/generated/app.ts`
|
|
191
|
+
- v2: `app.ts` is the real entrypoint; `createApp()` handles all lifecycle
|
|
192
|
+
|
|
193
|
+
**Routing**
|
|
194
|
+
- v1: file-based auto-discovery + `createRouter()` mutating style
|
|
195
|
+
- v2: explicit `src/api/index.ts` barrel + `new Hono<Env>()` chained style
|
|
196
|
+
|
|
197
|
+
**Type-safe API client**
|
|
198
|
+
- v1: `createClient<RPCRouteRegistry>()` from `@agentuity/react`
|
|
199
|
+
- v2: `hc<AppRouter>()` from `hono/client` — Hono's native RPC inference
|
|
200
|
+
|
|
201
|
+
**Setup/shutdown lifecycle**
|
|
202
|
+
- v1: `createApp({ setup, shutdown })` with generic state via `ctx.app`
|
|
203
|
+
- v2: Use Hono's standard patterns — module-level initialization and Hono lifecycle hooks
|
package/bin/migrate.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @agentuity/migrate CLI entry point
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* npx @agentuity/migrate [project-dir] [options]
|
|
8
|
+
*
|
|
9
|
+
* Options:
|
|
10
|
+
* --yes, -y Skip interactive confirmation prompts
|
|
11
|
+
* --dry-run Print migration report without modifying any files
|
|
12
|
+
* --help, -h Show this help message
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
|
|
17
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
18
|
+
console.log(`
|
|
19
|
+
${'\x1b[1m'}@agentuity/migrate${'\x1b[0m'} — Migrate an Agentuity SDK v1 project to v2
|
|
20
|
+
|
|
21
|
+
${'\x1b[2m'}Usage:${'\x1b[0m'}
|
|
22
|
+
npx @agentuity/migrate [project-dir] [options]
|
|
23
|
+
|
|
24
|
+
${'\x1b[2m'}Arguments:${'\x1b[0m'}
|
|
25
|
+
project-dir Path to the project to migrate (default: current directory)
|
|
26
|
+
|
|
27
|
+
${'\x1b[2m'}Options:${'\x1b[0m'}
|
|
28
|
+
--yes, -y Skip interactive confirmation prompts
|
|
29
|
+
--dry-run Print the migration report without modifying any files
|
|
30
|
+
--help, -h Show this help message
|
|
31
|
+
|
|
32
|
+
${'\x1b[2m'}What it does:${'\x1b[0m'}
|
|
33
|
+
• Detects v1 patterns (generated dir, old createApp config, mutable routes…)
|
|
34
|
+
• Prints a categorised report: auto-fixable, guided, and manual changes
|
|
35
|
+
• Asks for confirmation, then applies mechanical codemods
|
|
36
|
+
• Rewrites route files to chained new Hono<Env>() style
|
|
37
|
+
• Generates src/api/index.ts and src/agent/index.ts barrel files
|
|
38
|
+
• Removes src/generated/ directory
|
|
39
|
+
• Guides you to delete agentuity.config.ts (config now in createApp/vite.config)
|
|
40
|
+
• Runs tsc --noEmit to verify no type errors were introduced
|
|
41
|
+
|
|
42
|
+
${'\x1b[2m'}Safety:${'\x1b[0m'}
|
|
43
|
+
The tool checks that your git worktree is clean before making any changes,
|
|
44
|
+
so you can always review the diff or roll back with git checkout .
|
|
45
|
+
`);
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Parse flags
|
|
50
|
+
const yes = args.includes('--yes') || args.includes('-y');
|
|
51
|
+
const dryRun = args.includes('--dry-run');
|
|
52
|
+
|
|
53
|
+
// First non-flag argument is the project dir
|
|
54
|
+
const projectDir = args.find((a) => !a.startsWith('-')) ?? process.cwd();
|
|
55
|
+
|
|
56
|
+
const { migrate } = await import('../src/migrate');
|
|
57
|
+
|
|
58
|
+
const result = await migrate({ projectDir, yes, dryRun });
|
|
59
|
+
|
|
60
|
+
process.exit(result.ok ? 0 : 1);
|
package/dist/detect.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V1 pattern detection.
|
|
3
|
+
*
|
|
4
|
+
* Analyses a project directory and returns a structured report of every v1
|
|
5
|
+
* artefact that needs to be migrated to v2. No files are modified here.
|
|
6
|
+
*/
|
|
7
|
+
/** Severity of a finding — drives the interactive prompt */
|
|
8
|
+
export type Severity = 'auto' | 'guided' | 'manual';
|
|
9
|
+
export interface Finding {
|
|
10
|
+
/** Short identifier used to reference this finding in transforms */
|
|
11
|
+
id: string;
|
|
12
|
+
severity: Severity;
|
|
13
|
+
/** Human-readable summary */
|
|
14
|
+
message: string;
|
|
15
|
+
/** File relative to project root, or undefined for project-level findings */
|
|
16
|
+
file?: string;
|
|
17
|
+
/** Extra detail or migration hint shown in the report */
|
|
18
|
+
hint?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DetectionResult {
|
|
21
|
+
projectDir: string;
|
|
22
|
+
/** All findings, ordered by severity (auto → guided → manual) */
|
|
23
|
+
findings: Finding[];
|
|
24
|
+
/** Absolute path to app.ts, if found */
|
|
25
|
+
appTsPath?: string;
|
|
26
|
+
/** Absolute path to src/generated dir, if it exists */
|
|
27
|
+
generatedDir?: string;
|
|
28
|
+
/** Absolute paths of route files detected as v1-style (mutating createRouter) */
|
|
29
|
+
v1RouteFiles: string[];
|
|
30
|
+
/** Absolute paths of route files already in v2-style (chained Hono) */
|
|
31
|
+
v2RouteFiles: string[];
|
|
32
|
+
/** Whether src/agent/index.ts barrel exists */
|
|
33
|
+
hasAgentBarrel: boolean;
|
|
34
|
+
/** Whether src/api/index.ts barrel exists */
|
|
35
|
+
hasApiBarrel: boolean;
|
|
36
|
+
/** Whether agentuity.config.ts exists */
|
|
37
|
+
hasAgentuityConfig: boolean;
|
|
38
|
+
/** Whether app.ts passes analytics/workbench inside createApp() */
|
|
39
|
+
analyticsInCreateApp: boolean;
|
|
40
|
+
workbenchInCreateApp: boolean;
|
|
41
|
+
/** Whether app.ts passes setup/shutdown inside createApp() */
|
|
42
|
+
setupInCreateApp: boolean;
|
|
43
|
+
shutdownInCreateApp: boolean;
|
|
44
|
+
/** Whether app.ts calls bootstrapRuntimeEnv() */
|
|
45
|
+
bootstrapCallInAppTs: boolean;
|
|
46
|
+
/** Whether frontend code uses removed APIs */
|
|
47
|
+
frontendRemovedApis: FrontendFinding[];
|
|
48
|
+
}
|
|
49
|
+
export interface FrontendFinding {
|
|
50
|
+
file: string;
|
|
51
|
+
apis: string[];
|
|
52
|
+
/** APIs that are deprecated (still work but should migrate away) */
|
|
53
|
+
deprecatedApis?: string[];
|
|
54
|
+
}
|
|
55
|
+
export declare function detect(projectDir: string): Promise<DetectionResult>;
|
|
56
|
+
//# sourceMappingURL=detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,4DAA4D;AAC5D,MAAM,MAAM,QAAQ,GACjB,MAAM,GACN,QAAQ,GACR,QAAQ,CAAC;AAEZ,MAAM,WAAW,OAAO;IACvB,oEAAoE;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uEAAuE;IACvE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,+CAA+C;IAC/C,cAAc,EAAE,OAAO,CAAC;IACxB,6CAA6C;IAC7C,YAAY,EAAE,OAAO,CAAC;IACtB,yCAAyC;IACzC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,mEAAmE;IACnE,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,8DAA8D;IAC9D,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,iDAAiD;IACjD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,8CAA8C;IAC9C,mBAAmB,EAAE,eAAe,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AA4PD,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAqXzE"}
|