proteum 2.4.4 → 2.5.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 (73) hide show
  1. package/README.md +60 -55
  2. package/agents/project/AGENTS.md +112 -31
  3. package/agents/project/CODING_STYLE.md +2 -2
  4. package/agents/project/app-root/AGENTS.md +1 -3
  5. package/agents/project/client/AGENTS.md +1 -1
  6. package/agents/project/client/pages/AGENTS.md +21 -9
  7. package/agents/project/diagnostics.md +2 -2
  8. package/agents/project/optimizations.md +1 -1
  9. package/agents/project/root/AGENTS.md +105 -22
  10. package/agents/project/server/routes/AGENTS.md +30 -1
  11. package/agents/project/tests/AGENTS.md +1 -1
  12. package/cli/commands/doctor.ts +54 -3
  13. package/cli/commands/runtime.ts +6 -0
  14. package/cli/commands/worktree.ts +116 -0
  15. package/cli/compiler/artifacts/controllers.ts +16 -15
  16. package/cli/compiler/artifacts/discovery.ts +129 -17
  17. package/cli/compiler/artifacts/routing.ts +0 -5
  18. package/cli/compiler/artifacts/services.ts +253 -76
  19. package/cli/compiler/common/controllers.ts +159 -57
  20. package/cli/compiler/common/generatedRouteModules.ts +457 -363
  21. package/cli/mcp/router.ts +47 -3
  22. package/cli/presentation/commands.ts +25 -15
  23. package/cli/runtime/commands.ts +39 -12
  24. package/cli/runtime/worktreeBootstrap.ts +608 -0
  25. package/cli/scaffold/index.ts +28 -18
  26. package/cli/scaffold/templates.ts +44 -33
  27. package/cli/utils/agents.ts +14 -1
  28. package/client/services/router/index.tsx +23 -3
  29. package/client/services/router/request/api.ts +14 -4
  30. package/common/dev/contractsDoctor.ts +1 -1
  31. package/common/dev/mcpPayloads.ts +8 -1
  32. package/common/env/proteumEnv.ts +14 -2
  33. package/common/router/contracts.ts +1 -1
  34. package/common/router/definitions.ts +177 -0
  35. package/common/router/index.ts +23 -12
  36. package/common/router/pageData.ts +5 -5
  37. package/common/router/register.ts +2 -2
  38. package/common/router/request/api.ts +12 -2
  39. package/docs/agent-routing.md +5 -2
  40. package/docs/diagnostics.md +2 -0
  41. package/docs/mcp.md +6 -3
  42. package/eslint.js +36 -1
  43. package/package.json +1 -1
  44. package/server/app/commands.ts +5 -1
  45. package/server/app/container/console/index.ts +1 -1
  46. package/server/app/controller/index.ts +98 -40
  47. package/server/app/index.ts +92 -1
  48. package/server/app/service/index.ts +5 -1
  49. package/server/index.ts +6 -2
  50. package/server/services/router/index.ts +47 -38
  51. package/server/services/router/response/index.ts +2 -2
  52. package/tests/agents-utils.test.cjs +14 -1
  53. package/tests/cli-mcp-command.test.cjs +84 -0
  54. package/tests/definition-contracts.test.cjs +453 -0
  55. package/tests/dev-transpile-watch.test.cjs +37 -28
  56. package/tests/eslint-rules.test.cjs +39 -1
  57. package/tests/mcp.test.cjs +90 -0
  58. package/tests/worktree-bootstrap.test.cjs +206 -0
  59. package/types/aliases.d.ts +0 -5
  60. package/types/controller-input.test.ts +23 -17
  61. package/types/controller-request-context.test.ts +10 -11
  62. package/cli/commands/migrate.ts +0 -51
  63. package/cli/migrate/pageContract.ts +0 -516
  64. package/docs/migrate-from-2.1.3.md +0 -396
  65. package/scripts/cleanup-generated-controllers.ts +0 -62
  66. package/scripts/fix-reference-app-typing.ts +0 -490
  67. package/scripts/format-router-registrations.ts +0 -119
  68. package/scripts/migrate-explicit-controllers-and-request.ts +0 -423
  69. package/scripts/refactor-client-app-imports.ts +0 -244
  70. package/scripts/refactor-client-pages.ts +0 -587
  71. package/scripts/refactor-server-controllers.ts +0 -471
  72. package/scripts/refactor-server-runtime-aliases.ts +0 -360
  73. package/scripts/restore-client-app-import-files.ts +0 -41
@@ -1,396 +0,0 @@
1
- # Migrating from Proteum 2.1.3
2
-
3
- This guide covers the breaking changes between `proteum@2.1.3` and the current framework code in this repository.
4
-
5
- The important conclusion is that the breaking surface is mostly at the app root and tooling contract level, not in day-to-day page, controller, or service authoring. In the repo diff from `2.1.3` to the current `2.1.9` line, I did not find a mandatory rewrite of `Router.page(...)`, controller methods, or normal service method bodies. The required migration is mainly about config files, env, service metadata discovery, and connected-app setup.
6
-
7
- ## Breaking Changes Summary
8
-
9
- ### 1. `identity.yaml` is no longer supported
10
-
11
- `2.1.3` expected a YAML file at the app root:
12
-
13
- - `identity.yaml`
14
-
15
- Current Proteum requires a typed TypeScript config:
16
-
17
- - `identity.config.ts`
18
-
19
- The file must default-export `Application.identity(...)` from `proteum/config`.
20
-
21
- ### 2. `proteum.config.ts` is now required
22
-
23
- `2.1.3` had no app-level setup file for compiler or connected-project config.
24
-
25
- Current Proteum requires:
26
-
27
- - `proteum.config.ts`
28
-
29
- The file must default-export `Application.setup(...)` from `proteum/config`.
30
-
31
- This is where app-level framework config now lives, especially:
32
-
33
- - `transpile`
34
- - `connect`
35
-
36
- ### 3. `URL_INTERNAL` is now a required env var
37
-
38
- `2.1.3` required:
39
-
40
- - `ENV_NAME`
41
- - `ENV_PROFILE`
42
- - `PORT`
43
- - `URL`
44
-
45
- Current Proteum also requires:
46
-
47
- - `URL_INTERNAL`
48
-
49
- The router and SSR runtime now treat the internal base URL as a first-class contract instead of reusing `URL` implicitly.
50
-
51
- ### 4. `server/services/**/service.json` is no longer part of the contract
52
-
53
- In `2.1.3`, Proteum still read service metadata from `server/services/**/service.json`.
54
-
55
- Current Proteum reads the service graph from:
56
-
57
- - `server/index.ts`
58
- - typed config exports under `server/config/*.ts`
59
-
60
- If you still have `service.json` files from a `2.1.3` app, they are obsolete and should be removed.
61
-
62
- If you used `priority` there, move that value into the typed service config export with `Services.config(...)`.
63
-
64
- ### 5. Connected apps must be declared explicitly
65
-
66
- Current Proteum adds an explicit connected-project contract in `proteum.config.ts`.
67
-
68
- If your app consumes controllers from another Proteum app, you now need:
69
-
70
- - `connect.<Namespace>.source`
71
- - `connect.<Namespace>.urlInternal`
72
-
73
- There is no namespace-based inference. The producer app must also already be on the new contract because Proteum now expects the producer app root to contain:
74
-
75
- - `identity.config.ts`
76
- - `proteum.config.ts`
77
- - generated connected contract files
78
-
79
- ### 6. `proteum dev` is stricter when connected apps are configured
80
-
81
- If `connect` is configured, current `proteum dev` verifies the producer app health endpoint before it declares the server ready.
82
-
83
- That means broken or stale connected-app config is now a startup failure, not just a latent runtime problem.
84
-
85
- ### 7. Human-facing CLI output changed
86
-
87
- Current Proteum prints a welcome banner only for the bare `proteum build` and bare `proteum dev` commands, and `proteum dev` now has tracked session files plus `list` and `stop` subcommands.
88
-
89
- This is not an app-code migration, but it can break scripts that parse mixed stdout/stderr loosely. Prefer `--json` for automation.
90
-
91
- ## Migration Checklist
92
-
93
- ### 1. Upgrade the package
94
-
95
- Update the app dependency to the current Proteum version, then reinstall.
96
-
97
- ### 2. Replace `identity.yaml` with `identity.config.ts`
98
-
99
- Create a new root file:
100
-
101
- ```ts
102
- import { Application } from 'proteum/config';
103
-
104
- export default Application.identity({
105
- name: 'My App',
106
- identifier: 'MyApp',
107
- description: 'My Proteum app',
108
- author: {
109
- name: 'My Team',
110
- url: 'https://example.com',
111
- email: 'team@example.com',
112
- },
113
- social: {},
114
- language: 'en',
115
- locale: 'en-US',
116
- maincolor: 'white',
117
- iconsPack: 'light',
118
- web: {
119
- title: 'My App',
120
- titleSuffix: 'My App',
121
- fullTitle: 'My App',
122
- description: 'My Proteum app',
123
- version: '0.0.1',
124
- },
125
- });
126
- ```
127
-
128
- Mapping from the old YAML shape is mostly direct:
129
-
130
- - `name` stays `name`
131
- - `identifier` stays `identifier`
132
- - `description` stays `description`
133
- - `author.*` stays `author.*`
134
- - `language`, `locale`, `maincolor`, `iconsPack` keep the same meaning
135
- - `web.*` keeps the same meaning
136
-
137
- Then remove the old file:
138
-
139
- - `identity.yaml`
140
-
141
- ### 3. Add `proteum.config.ts`
142
-
143
- Create a new root file:
144
-
145
- ```ts
146
- import { Application } from 'proteum/config';
147
-
148
- export default Application.setup({
149
- transpile: [],
150
- connect: {},
151
- });
152
- ```
153
-
154
- If your app does not consume another Proteum app and does not need package transpilation, this empty config is enough.
155
-
156
- If your app compiles workspace or source-distributed packages through Proteum, put them in `transpile`.
157
-
158
- Example:
159
-
160
- ```ts
161
- import { Application } from 'proteum/config';
162
-
163
- export default Application.setup({
164
- transpile: ['@acme/components'],
165
- connect: {},
166
- });
167
- ```
168
-
169
- ### 4. Add `URL_INTERNAL` to `.env`
170
-
171
- At minimum, a migrated app now needs:
172
-
173
- ```dotenv
174
- ENV_NAME=local
175
- ENV_PROFILE=dev
176
- PORT=3010
177
- URL=http://localhost:3010
178
- URL_INTERNAL=http://localhost:3010
179
- ```
180
-
181
- For many local apps, `URL_INTERNAL` can initially match `URL`.
182
-
183
- Use a different internal URL only when the app is reached differently from server-side code than from a browser.
184
-
185
- ### 5. Remove `service.json` and move metadata into typed config
186
-
187
- Delete any legacy files such as:
188
-
189
- - `server/services/Foo/service.json`
190
-
191
- Current Proteum derives the root service graph from `server/index.ts`, so the real source of truth is now the code that instantiates root services there.
192
-
193
- If the old `service.json` carried priority metadata, move it into the typed config export.
194
-
195
- Old pattern:
196
-
197
- ```json
198
- {
199
- "priority": 5
200
- }
201
- ```
202
-
203
- New pattern:
204
-
205
- ```ts
206
- import { Services } from '@server/app';
207
- import MetricsRouter from '@/server/services/utils/Metrics/router';
208
-
209
- export const routerMetricsConfig = Services.config(MetricsRouter, {
210
- priority: 5,
211
- });
212
- ```
213
-
214
- Then make sure `server/index.ts` instantiates the service explicitly:
215
-
216
- ```ts
217
- public Router = new Router(this, {
218
- ...userConfig.routerBaseConfig,
219
- plugins: {
220
- metrics: new MetricsRouter(userConfig.routerMetricsConfig, this),
221
- },
222
- }, this);
223
- ```
224
-
225
- ### 6. Keep `server/index.ts` explicit
226
-
227
- Current Proteum expects the installed root services and router plugins to be visible directly in `server/index.ts`.
228
-
229
- The migration target is:
230
-
231
- - root services are instantiated as class properties on the `Application` subclass
232
- - router plugins are instantiated inside the `Router` config
233
- - typed config values come from `server/config/*.ts`
234
-
235
- If your `2.1.3` app relied on legacy discovery metadata, replace that with explicit code.
236
-
237
- ## Connected-App Migration
238
-
239
- This section applies only if one Proteum app consumes controllers from another Proteum app.
240
-
241
- ### 1. Upgrade the producer app too
242
-
243
- A current consumer app expects a producer app root that already has:
244
-
245
- - `identity.config.ts`
246
- - `proteum.config.ts`
247
-
248
- So a `file:` connected source pointing at an untouched `2.1.3` producer will fail.
249
-
250
- ### 2. Declare `connect` explicitly in `proteum.config.ts`
251
-
252
- Example:
253
-
254
- ```ts
255
- import { Application } from 'proteum/config';
256
-
257
- export default Application.setup({
258
- connect: {
259
- Product: {
260
- source: process.env.PRODUCT_CONNECTED_SOURCE,
261
- urlInternal: process.env.PRODUCT_URL_INTERNAL,
262
- },
263
- },
264
- });
265
- ```
266
-
267
- ### 3. Add the new env vars used by that config
268
-
269
- Example:
270
-
271
- ```dotenv
272
- PRODUCT_CONNECTED_SOURCE=file:../product
273
- PRODUCT_URL_INTERNAL=http://localhost:3020
274
- ```
275
-
276
- Supported source styles in the current contract are:
277
-
278
- - `file:../relative-producer-app`
279
- - `github:owner/repo?ref=<ref>&path=proteum.connected.json`
280
-
281
- ### 4. Expect stricter startup behavior
282
-
283
- When `connect` is configured, `proteum dev` now checks the producer health endpoint before it reports ready.
284
-
285
- If startup fails, validate in this order:
286
-
287
- 1. The producer app has already been migrated.
288
- 2. `connect.<Namespace>.source` points at the right producer app root.
289
- 3. `connect.<Namespace>.urlInternal` points at the producer dev server.
290
- 4. The producer app is running.
291
- 5. `npx proteum connect --strict` passes in the consumer app.
292
-
293
- ## Monorepo and Workspace Notes
294
-
295
- Current Proteum is better at resolving hoisted and workspace installs than `2.1.3`, but old app tsconfig files often still hardcode shallow `node_modules` paths.
296
-
297
- If your app lives inside a monorepo and TypeScript path resolution starts failing after the upgrade, align `client/tsconfig.json` and `server/tsconfig.json` with the current scaffold shape:
298
-
299
- - include `../identity.config.ts` and `../proteum.config.ts` in the server tsconfig
300
- - make sure the `extends` path points to the real visible `proteum/tsconfig.common.json`
301
- - make sure the `@client/*`, `@common/*`, and `@server/*` aliases point to the real visible Proteum install
302
- - make sure Preact compat aliases include `react-dom/client` when your app imports it
303
-
304
- This is usually only needed for workspace or hoisted installs. Standalone apps with a local `node_modules/proteum` often keep working after the config-file migration alone.
305
-
306
- ## CLI and Workflow Changes
307
-
308
- These are worth updating even though they are not core app-code migrations.
309
-
310
- ### Use compact CLI output for automation
311
-
312
- Only bare `proteum build` and bare `proteum dev` runs print a banner. Other CLI diagnostics are optimized for agents and return compact machine-readable output by default. For scripts, CI helpers, or editor tooling, prefer:
313
-
314
- - `npx proteum orient <query>`
315
- - `npx proteum runtime status`
316
- - `npx proteum explain`
317
- - `npx proteum doctor`
318
- - `npx proteum connect`
319
- - `npx proteum mcp` as the managed machine-scope MCP router; `proteum dev` ensures one daemon is running, agents call `workflow_start` first, use offline candidates to choose the correct app root when needed, then pass the returned live `projectId` to repeated reads against a live dev app
320
-
321
- CLI output uses compact `proteum-agent-v1` JSON for reproducible command evidence. MCP output uses compact `proteum-mcp-v1` JSON for repeated runtime reads. Use `npx proteum explain --manifest`, `npx proteum diagnose <target> --full`, or `npx proteum trace show <requestId> --events` only when the compact output is insufficient.
322
-
323
- ### Use tracked dev sessions
324
-
325
- Current `proteum dev` supports tracked session management:
326
-
327
- - `npx proteum dev --session-file var/run/proteum/dev/app.json --replace-existing`
328
- - `npx proteum dev list --json`
329
- - `npx proteum dev stop --session-file var/run/proteum/dev/app.json`
330
-
331
- `proteum dev` fails fast when another live tracked session already exists for the same app root. If runtime/MCP is unreachable, stop the listed session file first, then start dev again instead of launching a second server in the same worktree.
332
-
333
- ### New diagnostics are available
334
-
335
- These are new capabilities, not migration requirements, but they are the fastest way to validate the upgrade:
336
-
337
- - `npx proteum connect --strict`
338
- - `npx proteum explain --connected --controllers`
339
- - `npx proteum runtime status`
340
- - `npx proteum mcp status` plus MCP `workflow_start`, `project_resolve`, or `projects_list`
341
- - `npx proteum diagnose / --port <port>`
342
- - `npx proteum perf top --port <port>`
343
- - `npx proteum trace latest --port <port>`
344
-
345
- ## Recommended Migration Order
346
-
347
- 1. Upgrade the package.
348
- 2. Convert `identity.yaml` to `identity.config.ts`.
349
- 3. Add `proteum.config.ts`.
350
- 4. Add `URL_INTERNAL`.
351
- 5. Delete all legacy `service.json` files.
352
- 6. Move any legacy service metadata, especially `priority`, into `Services.config(...)`.
353
- 7. Confirm `server/index.ts` explicitly instantiates every root service and router plugin.
354
- 8. If the app is connected to another app, migrate the producer app and then add explicit `connect` config.
355
- 9. If the app is inside a workspace, align tsconfig paths with the actual Proteum install location.
356
- 10. Run `npx proteum refresh`, then validate with the commands below.
357
-
358
- ## Validation After Migration
359
-
360
- Run these from the migrated app:
361
-
362
- ```bash
363
- npx proteum refresh
364
- npx proteum explain --env
365
- npx proteum doctor --contracts --strict
366
- npx proteum check
367
- ```
368
-
369
- If the app uses connected projects, also run:
370
-
371
- ```bash
372
- npx proteum connect --strict
373
- npx proteum explain --connected --controllers
374
- ```
375
-
376
- Then boot the app and verify the live runtime:
377
-
378
- ```bash
379
- npx proteum dev --port 3010
380
- npx proteum runtime status
381
- npx proteum diagnose / --port 3010
382
- npx proteum trace latest --port 3010
383
- ```
384
-
385
- ## Short Version
386
-
387
- If you want the shortest possible migration plan:
388
-
389
- 1. Replace `identity.yaml` with `identity.config.ts`.
390
- 2. Add `proteum.config.ts`.
391
- 3. Add `URL_INTERNAL`.
392
- 4. Delete `server/services/**/service.json`.
393
- 5. Move any service `priority` into `Services.config(...)`.
394
- 6. If you connect apps together, declare `connect.<Namespace>.source` and `connect.<Namespace>.urlInternal` explicitly.
395
-
396
- That is the minimum needed to move a real `2.1.3` app onto the current Proteum contract.
@@ -1,62 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- const findControllerFiles = (dir: string): string[] => {
5
- if (!fs.existsSync(dir)) return [];
6
-
7
- const files: string[] = [];
8
-
9
- for (const dirent of fs.readdirSync(dir, { withFileTypes: true })) {
10
- const filepath = path.join(dir, dirent.name);
11
-
12
- if (dirent.isDirectory()) {
13
- files.push(...findControllerFiles(filepath));
14
- continue;
15
- }
16
-
17
- if (dirent.isFile() && /\.(tsx?|jsx?)$/.test(dirent.name) && !dirent.name.endsWith('.d.ts')) files.push(filepath);
18
- }
19
-
20
- return files;
21
- };
22
-
23
- const repoRoots = process.argv.slice(2);
24
- if (!repoRoots.length)
25
- throw new Error('Usage: ts-node scripts/cleanup-generated-controllers.ts <repo-root> [repo-root...]');
26
-
27
- for (const repoRoot of repoRoots) {
28
- const controllerFiles = findControllerFiles(path.join(repoRoot, 'server', 'controllers'));
29
- let updated = 0;
30
-
31
- for (const controllerFile of controllerFiles) {
32
- let content = fs.readFileSync(controllerFile, 'utf8');
33
- let changed = false;
34
-
35
- if (
36
- content.includes('this.input(schema.') &&
37
- content.includes("import Controller from '@server/app/controller';")
38
- ) {
39
- content = content.replace(
40
- "import Controller from '@server/app/controller';",
41
- "import Controller, { schema } from '@server/app/controller';",
42
- );
43
- changed = true;
44
- }
45
-
46
- if (content.includes('export default class indexController extends Controller')) {
47
- const parentName = path.basename(path.dirname(controllerFile)).replace(/[^A-Za-z0-9_$]/g, '');
48
- content = content.replace(
49
- 'export default class indexController extends Controller',
50
- `export default class ${parentName || 'Generated'}Controller extends Controller`,
51
- );
52
- changed = true;
53
- }
54
-
55
- if (!changed) continue;
56
-
57
- fs.writeFileSync(controllerFile, content);
58
- updated++;
59
- }
60
-
61
- console.log(`[cleanup-generated-controllers] ${repoRoot}: updated ${updated} controller files`);
62
- }