proteum 2.1.9-2 → 2.1.9-5

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 (42) hide show
  1. package/.codex/environments/environment.toml +11 -0
  2. package/AGENTS.md +15 -6
  3. package/README.md +3 -1
  4. package/agents/project/AGENTS.md +139 -106
  5. package/agents/project/diagnostics.md +16 -9
  6. package/agents/project/server/services/AGENTS.md +2 -0
  7. package/agents/project/tests/AGENTS.md +1 -1
  8. package/cli/commands/diagnose.ts +33 -1
  9. package/cli/commands/explain.ts +1 -1
  10. package/cli/commands/orient.ts +169 -0
  11. package/cli/commands/perf.ts +8 -1
  12. package/cli/commands/verify.ts +1003 -49
  13. package/cli/compiler/artifacts/services.ts +12 -3
  14. package/cli/compiler/common/proteumManifest.ts +1 -0
  15. package/cli/context.ts +6 -1
  16. package/cli/index.ts +7 -8
  17. package/cli/presentation/commands.ts +50 -9
  18. package/cli/presentation/help.ts +1 -1
  19. package/cli/runtime/commands.ts +49 -1
  20. package/client/dev/profiler/index.tsx +2 -0
  21. package/client/router.ts +10 -2
  22. package/common/dev/connect.ts +20 -4
  23. package/common/dev/console.ts +6 -0
  24. package/common/dev/contractsDoctor.ts +354 -0
  25. package/common/dev/diagnostics.ts +6 -3
  26. package/common/dev/inspection.ts +829 -37
  27. package/common/dev/performance.ts +19 -5
  28. package/common/dev/profiler.ts +1 -0
  29. package/common/dev/proteumManifest.ts +1 -0
  30. package/common/dev/requestTrace.ts +12 -0
  31. package/docs/dev-sessions.md +8 -4
  32. package/docs/diagnostics.md +77 -11
  33. package/docs/migrate-from-2.1.3.md +388 -0
  34. package/docs/request-tracing.md +25 -6
  35. package/package.json +1 -1
  36. package/server/app/container/console/index.ts +11 -1
  37. package/server/app/container/trace/index.ts +117 -0
  38. package/server/app/devDiagnostics.ts +1 -1
  39. package/server/app/index.ts +5 -1
  40. package/server/services/router/index.ts +16 -0
  41. package/server/services/router/request/api.ts +7 -1
  42. package/server/services/router/response/index.ts +8 -1
@@ -0,0 +1,11 @@
1
+ # THIS IS AUTOGENERATED. DO NOT EDIT MANUALLY
2
+ version = 1
3
+ name = "core"
4
+
5
+ [setup]
6
+ script = ""
7
+
8
+ [[actions]]
9
+ name = "Run"
10
+ icon = "run"
11
+ command = "npm login && npm publish"
package/AGENTS.md CHANGED
@@ -19,22 +19,29 @@ After those optimization concerns, preserve explicit, typed, machine-readable co
19
19
  - Keep `server/index.ts` as the canonical type root for services, router context, request context, and models.
20
20
  - Keep generated code deterministic, auditable, and easy to map back to source.
21
21
  - Prefer typed traces, perf rollups, and manifest-backed diagnostics over ad hoc logging.
22
+ - For Prisma-backed apps, declare database structure changes in the app's `schema.prisma` only. Never create or edit migration files manually, and never run schema-mutating SQL such as `ALTER TABLE`, `CREATE TABLE`, or `DROP TABLE`.
22
23
  - Follow `agents/project/optimizations.md` when choosing packages, helpers, runtimes, plugins, or build infrastructure.
23
24
  - Delete obsolete compatibility layers, helper indirection, and unused packages when safe.
24
25
 
25
26
  ## Workflow
26
27
 
27
28
  - If the user pastes raw errors without asking for a fix, do not implement changes. List likely causes and, for each one, give probability, why, and how to fix it.
29
+ - If you changed any app `schema.prisma`, do not start testing or validation yet. Ask the user to run the following command in the affected worktree directory, replacing the placeholders, and wait for the user to reply exactly `continue` before resuming validation or tests:
30
+ ```
31
+ cd <worktree path>
32
+ npx prisma migrate dev --config ./prisma.config.ts --name <migration name>
33
+ ```
28
34
  - After implementing a framework feature or change, do not stop at code edits. Boot both reference apps, exercise the affected flow with Playwright or the smallest real Proteum surface, run the relevant `proteum` diagnostics or perf commands, and confirm there is no meaningful regression in runtime behavior, performance, load size, SEO output, or coding-style expectations before finishing.
29
35
  - When starting a long-lived reference app dev server for framework work, prefer `npx proteum dev --session-file <path> --replace-existing --port <port>` so the session can be listed and stopped deterministically later.
30
36
  - Before retrying a boot on the same app, changing ports, or finishing the task, stop every framework-started dev session with `npx proteum dev stop --session-file <path>` or `npx proteum dev stop --all --stale`.
31
37
  - If the task changed the dev workflow itself, verify the final cleanup path with `npx proteum dev list --json` before finishing.
32
- - When you have finished your work, summarize in one top-level short (up to 100 characters) sentence the changes you made since the beginning of the conversation. Strictly use the Conventional Commits specification:
33
- ```
34
- Commit message: <type>[optional scope]: <description>
38
+ - When you have finished your work, summarize in one top-level short (up to 100 characters) sentence ALL the changes you made since the beginning of the WHOLE conversation. Strictly use the Conventional Commits specification:
39
+ ```
40
+ Commit message: <type>[optional scope]: <description>
35
41
 
36
- [optional body]
37
- ```
42
+ [optional body]
43
+ ```
44
+ If the user replies exactly `commit`, use that Conventional Commit message, stage the task-related changed files with `git add` while avoiding unrelated user changes or incidental untracked files, then create the commit by running `git commit`.
38
45
 
39
46
  ## Core Changes
40
47
 
@@ -45,7 +52,7 @@ Commit message: <type>[optional scope]: <description>
45
52
  - `/Users/gaetan/Desktop/Projets/unique.domains/platform/apps/website`
46
53
  - Inspect how both apps currently use the touched feature, runtime, API, compiler behavior, or generated output before proposing or implementing changes.
47
54
  - Keep the developer-facing contract synchronized when framework work changes CLI commands, profiler capabilities, or the `proteum dev` banner. Update the live surfaces together in the same pass: CLI command/help definitions, profiler panels and dev-only endpoints, banner text/examples, and the most relevant agent docs that describe them, especially `AGENTS.md`, `agents/project/AGENTS.md`, `agents/project/diagnostics.md`, and any narrower `agents/project/**/AGENTS.md` file that mentions the changed workflow.
48
- - Current CLI banner contract: every human-facing Proteum CLI run prints the welcome banner and includes the active Proteum installation method, while only `proteum dev` clears the interactive terminal before rendering, exposes `CTRL+R` reload plus `CTRL+C` shutdown hotkeys in its session UI, and reports connected app names plus successful connected `/ping` checks in the ready banner.
55
+ - Current CLI banner contract: only the bare `proteum build` and bare `proteum dev` commands print the welcome banner and include the active Proteum installation method. Any extra argument or option skips the banner. Only `proteum dev` clears the interactive terminal before rendering, exposes `CTRL+R` reload plus `CTRL+C` shutdown hotkeys in its session UI, and reports connected app names plus successful connected `/ping` checks in the ready banner.
49
56
  - Keep core changes aligned with the explicit controller/page architecture in `agents/project/AGENTS.md`.
50
57
  - Prefer removing framework magic when the same result can be expressed with explicit contracts, generated code, or typed context.
51
58
  - Apply the pruning rules from `agents/project/optimizations.md`, especially for webpack plugins, Babel plugins, aliases, helpers, runtime services, and npm packages that are not meaningfully used by both apps.
@@ -69,8 +76,10 @@ Do not stop at static analysis for routing, controllers, generated code, SSR, cl
69
76
  - When the issue is latency, CPU, SQL cost, render cost, or memory drift, inspect `proteum perf top`, `proteum perf request`, `proteum perf compare`, or `proteum perf memory` against the running dev server before adding custom instrumentation.
70
77
  - When a framework change can affect shipped client code size, run `proteum build --prod --analyze` for static bundle artifacts or `proteum build --prod --analyze --analyze-serve --analyze-port auto` when you need a local analyzer URL.
71
78
  - For protected browser or API flows in dev, prefer `npx proteum session <email> --role <role>` to mint a dev auth cookie instead of automating the login UI. Use the login UI only when login itself is the feature under test.
79
+ - When a task needs browser execution instead of the higher-level verifier, prefer `npx proteum verify browser <path>` or direct Playwright with a disposable profile. Keep auth sourced from `npx proteum session`, not UI login or shared browser state.
72
80
  - For request-time behavior, arm traces with `proteum trace arm --capture deep`, reproduce once, then inspect `proteum trace latest` or `proteum trace show <requestId>`.
73
81
  - When the framework-facing workflow itself changed, verify the CLI surface too with `proteum verify framework-change --crosspath-port <port> --product-port <port> --website-port <port>`.
82
+ - Only the final verifier agent should usually run browser flows. Other agents should stay on `orient`, `verify owner`, `verify request`, and command-level checks unless browser execution is the only trustworthy surface.
74
83
  - Open the real pages with Playwright.
75
84
  - Inspect browser console errors and warnings.
76
85
  - Inspect server startup and runtime errors.
package/README.md CHANGED
@@ -4,6 +4,8 @@ Proteum is an LLM-first SSR / SEO / TypeScript framework for full-stack web appl
4
4
 
5
5
  It is built for teams that want explicit server contracts, server-first rendering, deterministic generated artifacts, and a codebase that an AI agent can inspect without reverse-engineering hidden runtime magic.
6
6
 
7
+ Migration guide for older apps: [docs/migrate-from-2.1.3.md](docs/migrate-from-2.1.3.md)
8
+
7
9
  ## Why Proteum
8
10
 
9
11
  Most full-stack frameworks optimize first for human convenience.
@@ -347,7 +349,7 @@ proteum build --prod --analyze
347
349
  proteum build --prod --analyze --analyze-serve --analyze-port auto
348
350
  ```
349
351
 
350
- Every human-facing Proteum CLI run prints the welcome banner and includes the active Proteum installation method. `proteum dev` is the only command that clears the interactive terminal before rendering its live session UI, exposes `CTRL+R` reload plus `CTRL+C` shutdown hotkeys, and prints connected app names plus successful connected `/ping` checks in the server-ready banner.
352
+ Only the bare `proteum build` and bare `proteum dev` commands print the welcome banner and include the active Proteum installation method. Any extra argument or option skips the banner. `proteum dev` is the only command that clears the interactive terminal before rendering its live session UI, exposes `CTRL+R` reload plus `CTRL+C` shutdown hotkeys, and prints connected app names plus successful connected `/ping` checks in the server-ready banner.
351
353
 
352
354
  Useful inspection commands:
353
355
 
@@ -9,37 +9,52 @@ Optimization source of truth: project-root `optimizations.md`.
9
9
  Diagnostics source of truth: project-root `diagnostics.md`.
10
10
  Coding style source of truth: project-root `CODING_STYLE.md`.
11
11
 
12
- ## Workflow
12
+ ## Fast Triggers
13
13
 
14
- - At the beginning of every task, acknowledge the applicable optimization, diagnostics, and coding-style sources before analyzing or editing code: project-root `optimizations.md`, project-root `diagnostics.md`, project-root `CODING_STYLE.md`, and any narrower area `AGENTS.md`.
15
14
  - If the user pastes raw errors without asking for a fix, do not implement changes. List likely causes and, for each one, give probability, why, and how to fix it.
16
- - Follow project-root `diagnostics.md` for diagnosis, runtime reproduction, temporary instrumentation, error-solving workflow, and verification method selection.
17
- - For new app or artifact boilerplate, prefer `npx proteum init ...` and `npx proteum create ...` before creating files by hand. Use `--dry-run --json` when an agent needs a machine-readable plan before writing files.
15
+ - If the task is ambiguous, generated, connected, or multi-repo, start with `npx proteum orient <query>` before reading large parts of the codebase.
16
+ - If the user reports an issue, or the agent encounters one during exploration, implementation, verification, or runtime reproduction, load and follow project-root `diagnostics.md`.
17
+ - If the task touches client-side files, especially `client/**` and page files, load and apply project-root `optimizations.md` only after implementation for post-implementation checking and optimization. Skip it at task start and skip it for server-only, test-only, doc-only, and non-client refactor tasks unless the user explicitly asks for optimization work.
18
+ - If the task changes UX, copy, onboarding, pricing, product semantics, or commercial positioning, read the relevant files under `./docs/` first, especially `docs/PERSONAS.md`, `docs/PRODUCT.md`, and `docs/MARKETING.md` when they exist. If a dev server is already running, print the dev server URL.
19
+ - If the task needs new app or artifact boilerplate, prefer `npx proteum init ...` and `npx proteum create ...` before creating files by hand. Use `--dry-run --json` when an agent needs a machine-readable plan before writing files.
20
+ - If you changed `schema.prisma`, do not start testing or validation yet. Ask the user to run the following command in the affected worktree directory, replacing the placeholders, and wait for the user to reply exactly `continue` before resuming validation or tests:
21
+ ```
22
+ cd <worktree path>
23
+ npx prisma migrate dev --config ./prisma.config.ts --name <migration name>
24
+ ```
25
+ - If you encounter `runtime/provider-hook-outside-provider`, `runtime/client-only-hook-in-ssr`, `runtime/router-context-outside-router`, or `runtime/connected-boundary-mismatch`, treat it as a framework contract failure first. Fix the provider, SSR/client, router, or connected boundary before assuming a local leaf-component bug.
26
+ - If the change is runtime-visible, request-time, router, SSR, browser-visible, or controller-behavior, use running-app verification.
27
+ - If the change is docs-only, wording-only, type-only, test-only, generated-output cleanup, or a clearly local non-runtime refactor, use static verification only unless the user explicitly asks for runtime verification or the agent finds a real issue.
28
+ - If the user replies exactly `commit`, generate one top-level short (up to 100 characters) sentence covering all changes made since the last `commit` and, if there has been no prior `commit`, since the beginning of the whole conversation, strictly using the Conventional Commits specification:
29
+ ```
30
+ <type>[optional scope]: <description>
31
+
32
+ [optional body]
33
+ ```
34
+ Then use that generated message, stage the task-related changed files with `git add` while avoiding unrelated user changes or incidental untracked files, and create the commit by running `git commit`. Do not stop at only suggesting the message.
35
+
36
+ ## Task Lifecycle
37
+
38
+ ### Before Editing
39
+
40
+ - Before changing any file, load project-root `CODING_STYLE.md` and any narrower area `AGENTS.md` that applies to the touched files. Do not spend response space explicitly acknowledging those reads unless the user asks.
41
+
42
+ ### During Implementation
43
+
18
44
  - After running `npx proteum create ...`, adapt the generated code to the real feature instead of leaving placeholder logic in place.
19
45
  - When starting a long-lived dev server for an agent task, prefer `npx proteum dev --session-file <path> --replace-existing --port <port>` so the session can be listed and stopped deterministically later.
20
46
  - Do not start a second `proteum dev` server for the same app and port until the earlier tracked session has been stopped or replaced.
21
- - When framework work changes Proteum CLI commands, profiler panels/features, or the `proteum dev` banners, keep this file, project-root `diagnostics.md`, and any narrower area `AGENTS.md` that mentions the same workflow aligned with the live framework behavior in the same pass.
22
- - Current CLI banner contract: every human-facing Proteum CLI run prints the welcome banner and includes the active Proteum installation method, while only `proteum dev` clears the interactive terminal before rendering, exposes `CTRL+R` reload plus `CTRL+C` shutdown hotkeys in its session UI, and reports connected app names plus successful connected `/ping` checks in the ready banner.
23
- - Before finishing, double-check the touched files and generated output against the applicable optimization, diagnostics, and coding-style sources: project-root `optimizations.md`, project-root `diagnostics.md`, project-root `CODING_STYLE.md`, and any narrower area `AGENTS.md`.
24
- - After implementing any feature or behavior change, always verify it on a running app before finishing: start the server, exercise the affected flow with Playwright or the smallest real runtime or `npx proteum` surface, run the relevant diagnostics or perf commands, and confirm there is no meaningful regression in behavior, performance, bundle/load size, SEO output, or coding style.
25
- - Before finishing a task, stop every `proteum dev` session started during the task and confirm cleanup with `npx proteum dev list --json` or an explicit `npx proteum dev stop --session-file <path>`.
26
- - When you have finished your work, summarize in one top-level short (up to 100 characters) sentence the changes you made since the beginning of the conversation. Strictly use the Conventional Commits specification:
27
- ```
28
- Commit message: <type>[optional scope]: <description>
29
-
30
- [optional body]
31
- ```
47
+ - For raw browser automation, use `npx proteum verify browser` when it matches the task, or direct Playwright with a disposable profile when lower-level control is required. Bootstrap protected browser state through `npx proteum session`.
48
+ - Current CLI banner contract: only the bare `proteum build` and bare `proteum dev` commands print the welcome banner and include the active Proteum installation method. Any extra argument or option skips the banner. Only `proteum dev` clears the interactive terminal before rendering, exposes `CTRL+R` reload plus `CTRL+C` shutdown hotkeys in its session UI, and reports connected app names plus successful connected `/ping` checks in the ready banner.
32
49
 
33
- ## Project Shape
34
-
35
- This is a TypeScript, Node.js, Preact, Proteum monolith:
50
+ ### Before Finishing
36
51
 
37
- - `/client`: assets, catalogs, components, hooks, pages
38
- - `/common`: shared functions, constants, types, and catalogs
39
- - `/server`: catalogs, config, services, routes, lib
40
- - `/tests`
52
+ - Before finishing, re-check touched files against project-root `CODING_STYLE.md` and any narrower area `AGENTS.md` that applied to the edit. Re-check against project-root `optimizations.md` only for touched client-side files. Re-check against project-root `diagnostics.md` only if the task involved an issue, diagnosis, runtime reproduction, or verification failure.
53
+ - Do not default to project-wide typecheck, `npx proteum check`, or Playwright after every change. Run them only when the user asks for them, when the changed surface specifically requires them, or when a real issue discovered during verification justifies escalation.
54
+ - Before finishing a task, stop every `proteum dev` session started during the task and confirm cleanup with `npx proteum dev list --json` or an explicit `npx proteum dev stop --session-file <path>`.
55
+ - When you have finished your work, ask the user whether they want a commit message.
41
56
 
42
- ## Non-Negotiable Rules
57
+ ## Core Contracts
43
58
 
44
59
  - Client pages live in `client/pages/**` and register routes with top-level `Router.page(...)` or `Router.error(...)`.
45
60
  - Page URLs come from the explicit `Router.page('/path', ...)` call, not from the file path.
@@ -48,11 +63,12 @@ This is a TypeScript, Node.js, Preact, Proteum monolith:
48
63
  - Manual HTTP endpoints live only in `server/routes/**`.
49
64
  - Controllers call `this.input(schema)` inside the method body, at most once per method.
50
65
  - Request-scoped state lives only on `this.request` and manual-route/router context objects.
51
- - Follow project-root `optimizations.md` for bundle size, performance, SEO, and SSR page-size rules.
52
66
  - Keep one class or one React/Preact component per file.
53
67
  - Prefer a deep tree grouped by business concern instead of long file names.
54
68
  - Use the default `*.ts` or `*.tsx` file unless an `*.ssr.ts` or `*.ssr.tsx` variant is truly required.
55
69
  - Never edit generated files under `.proteum`.
70
+ - When a task changes database structure, edit the app's `schema.prisma` only.
71
+ - Never create or edit migration files manually.
56
72
  - Use `@generated/client/*`, `@generated/common/*`, and `@generated/server/*` for generated surfaces.
57
73
  - Client context is typically imported from `@/client/context`.
58
74
  - Normal service methods do not read request state directly.
@@ -61,63 +77,7 @@ This is a TypeScript, Node.js, Preact, Proteum monolith:
61
77
  - Do not use `@app` on the client.
62
78
  - Prefer type inference rooted in the explicit application graph in `server/index.ts`.
63
79
 
64
- ## Source Of Truth
65
-
66
- Proteum reads:
67
-
68
- - `package.json`
69
- - `identity.config.ts` for app identity via `Application.identity({ ... })`
70
- - `proteum.config.ts` for compiler setup via `Application.setup({ transpile, connect })`
71
- - `process.env` via `PORT`, `ENV_*`, `URL`, `URL_INTERNAL`, any app-chosen connected-project values referenced by `proteum.config.ts`, and `TRACE_*`
72
- - `server/config/*.ts`
73
- - `server/index.ts`
74
- - `commands/**/*.ts`
75
- - `server/controllers/**/*.ts`
76
- - `server/routes/**/*.ts`
77
- - `client/pages/**/*.ts(x)`
78
- - `client/pages/**/_layout/index.tsx`
79
- - `public/**`
80
-
81
- Proteum owns:
82
-
83
- - `.proteum/manifest.json`
84
- - `.proteum/client/*`
85
- - `.proteum/common/*`
86
- - `.proteum/server/*`
87
-
88
- Project code should consume:
89
-
90
- - `@generated/client/*`
91
- - `@generated/common/*`
92
- - `@generated/server/*`
93
- - `@/client/context` as the generated client context entrypoint
94
-
95
- Prefer structured CLI surfaces over re-deriving framework facts from source:
96
-
97
- - `npx proteum connect --json`
98
- - `npx proteum connect --controllers --strict`
99
- - `npx proteum explain --json`
100
- - `npx proteum explain --connected --controllers`
101
- - `npx proteum explain owner <query>`
102
- - `npx proteum doctor --json`
103
- - `npx proteum doctor --contracts --json`
104
- - `npx proteum diagnose <path> --port <port>`
105
- - `npx proteum perf ...`
106
- - `npx proteum trace ...`
107
- - `npx proteum command ...`
108
- - `npx proteum session ...`
109
- - `npx proteum create ... --dry-run --json`
110
- - `npx proteum dev list --json`
111
- - `npx proteum dev stop --session-file <path>`
112
-
113
- Prefer scaffold commands before hand-writing boilerplate:
114
-
115
- - Use `npx proteum init <directory> --name <name>` for new apps.
116
- - Use `npx proteum init ... --dry-run --json` when an agent needs a machine-readable app plan before writing files.
117
- - Use `npx proteum create page|controller|command|route|service <target>` for new app artifacts before creating the files manually.
118
- - Use `npx proteum create ... --dry-run --json` when an agent needs a machine-readable artifact plan before writing files.
119
-
120
- ## File Contracts
80
+ ## Surface Contracts
121
81
 
122
82
  ### App Bootstrap And Services
123
83
 
@@ -193,15 +153,31 @@ Prefer scaffold commands before hand-writing boilerplate:
193
153
  - `@app`: server-side application services for manual routes only
194
154
  - `@generated/*`: generated app surfaces
195
155
 
196
- ## Dependency Selection
156
+ ## Verification Matrix
157
+
158
+ Verify at the correct layer:
159
+
160
+ - Default: use the cheapest trustworthy verification for the changed surface first, then escalate only if the changed surface justifies it.
161
+ - Route additions: boot the app and hit the real URL.
162
+ - Controller changes: exercise the generated client call or generated `/api/...` endpoint.
163
+ - SSR changes: load the real page and inspect rendered HTML plus browser console.
164
+ - Router or plugin changes: verify request context, auth, redirects, metrics, and validation on a running app.
165
+ - Generated, connected, or ownership-ambiguous changes: start with `npx proteum orient <query>` and prefer `npx proteum verify owner <query>` before broad global checks.
166
+ - Browser-visible issues: prefer `npx proteum verify browser <path>` or the narrowest targeted Playwright pass only after request-level verification is insufficient.
167
+ - Raw browser execution beyond `npx proteum verify browser`: use direct Playwright with a disposable profile, and keep that step for the final verifier agent unless a narrower surface cannot reproduce the issue.
168
+ - For trace-first reproduction, session-based auth setup, temporary logs, and post-fix surface checks, follow project-root `diagnostics.md`.
169
+
170
+ ## Implementation Rules
171
+
172
+ ### Dependency Selection
197
173
 
198
174
  - Before implementing a feature or change, first check whether the repo already includes a suitable dependency.
199
175
  - If not, search npm before building a new utility, abstraction, component primitive, parser, formatter, or integration from scratch.
200
176
  - Prefer the most popular, flexible, maintained packages that fit the project constraints.
201
- - Follow project-root `optimizations.md` when deciding whether custom infrastructure is justified over an existing package.
177
+ - When the task explicitly involves client-side optimization work, use project-root `optimizations.md` to decide whether custom infrastructure is justified over an existing package.
202
178
  - When you choose custom over a package, explain the reason briefly.
203
179
 
204
- ## Catalogs And Typing
180
+ ### Catalogs And Typing
205
181
 
206
182
  - Keep one canonical catalog or registry file and import it everywhere else.
207
183
  - Client-only catalogs live in `/client/catalogs/**`, server-only catalogs in `/server/catalogs/**`, and shared catalogs in `/common/catalogs/**`.
@@ -211,7 +187,7 @@ Prefer scaffold commands before hand-writing boilerplate:
211
187
  - Fix typing issues only on code you wrote.
212
188
  - Never cast with `as any` or `as unknown`; fix the contract or add an explicit typed adapter.
213
189
 
214
- ## Design Rules
190
+ ### Design Rules
215
191
 
216
192
  - Prefer explicit `server/index.ts` bootstrap over hidden registration.
217
193
  - Prefer controller-backed app APIs over ad hoc manual `/api/...` routes.
@@ -219,25 +195,93 @@ Prefer scaffold commands before hand-writing boilerplate:
219
195
  - Keep one canonical source of truth for catalogs, registries, and shared types.
220
196
  - Reuse shared Shadcn-based UI primitives when the project already provides them.
221
197
 
222
- ## Discouraged Patterns
198
+ ### Discouraged Patterns
223
199
 
224
200
  - request-scoped state inside normal service methods
225
201
  - hiding route registration behind abstractions that remove the top-level `Router.page(...)` call
226
202
  - editing `.proteum` directly
227
203
 
228
- ## Verification
204
+ ## Hard Stops
229
205
 
230
- Verify at the correct layer:
206
+ - Never run schema-mutating SQL such as `ALTER TABLE`, `CREATE TABLE`, `DROP TABLE`, or `CREATE INDEX` to change database structure.
207
+ - Do not run `prisma *` yourself. If a schema change requires migration, ask the user to run `npx prisma migrate dev --config ./prisma.config.ts --name <migration name>` and wait for `continue`.
208
+ - Do not run `git restore` or `git reset`.
209
+ - Do not run write-mode git commands by default. The built-in exception is an exact `commit` reply, which allows only task-scoped `git add` and `git commit`. Any other write-mode git action requires an explicit user request.
231
210
 
232
- - route additions: boot the app and hit the real URL
233
- - controller changes: exercise the generated client call or generated `/api/...` endpoint
234
- - SSR changes: load the real page and inspect rendered HTML plus browser console
235
- - router or plugin changes: verify request context, auth, redirects, metrics, and validation on a running app
236
- - For trace-first reproduction, session-based auth setup, temporary logs, and post-fix surface checks, follow project-root `diagnostics.md`.
211
+ ## Appendix
212
+
213
+ ### Project Shape
214
+
215
+ This is a TypeScript, Node.js, Preact, Proteum monolith:
216
+
217
+ - `/client`: assets, catalogs, components, hooks, pages
218
+ - `/common`: shared functions, constants, types, and catalogs
219
+ - `/server`: catalogs, config, services, routes, lib
220
+ - `/tests`
221
+
222
+ ### Source Of Truth
223
+
224
+ Proteum reads:
225
+
226
+ - `package.json`
227
+ - `identity.config.ts` for app identity via `Application.identity({ ... })`
228
+ - `proteum.config.ts` for compiler setup via `Application.setup({ transpile, connect })`
229
+ - `process.env` via `PORT`, `ENV_*`, `URL`, `URL_INTERNAL`, any app-chosen connected-project values referenced by `proteum.config.ts`, and `TRACE_*`
230
+ - `server/config/*.ts`
231
+ - `server/index.ts`
232
+ - `commands/**/*.ts`
233
+ - `server/controllers/**/*.ts`
234
+ - `server/routes/**/*.ts`
235
+ - `client/pages/**/*.ts(x)`
236
+ - `client/pages/**/_layout/index.tsx`
237
+ - `public/**`
238
+
239
+ Proteum owns:
240
+
241
+ - `.proteum/manifest.json`
242
+ - `.proteum/client/*`
243
+ - `.proteum/common/*`
244
+ - `.proteum/server/*`
237
245
 
238
- Useful commands: `npx proteum init <dir> --name <name>`, `npx proteum create <kind> <target>`, `proteum dev`, `proteum dev list --json`, `proteum dev stop --session-file <path>`, `npx proteum refresh`, `npx proteum typecheck`, `npx proteum lint`, `npx proteum check`, `npx proteum build prod`, `npx proteum build --prod --analyze`, `npx proteum build --prod --analyze --analyze-serve --analyze-port auto`, `npx proteum perf top`, `npx proteum perf request <requestId|path>`, `npx proteum perf compare --baseline yesterday --target today`, `npx proteum command <path>`, `npx proteum session <email> --role <role>`.
246
+ Project code should consume:
239
247
 
240
- ## High-Impact Files
248
+ - `@generated/client/*`
249
+ - `@generated/common/*`
250
+ - `@generated/server/*`
251
+ - `@/client/context` as the generated client context entrypoint
252
+
253
+ ### Useful Commands
254
+
255
+ Prefer structured CLI surfaces over re-deriving framework facts from source:
256
+
257
+ - `npx proteum connect --json`
258
+ - `npx proteum connect --controllers --strict`
259
+ - `npx proteum orient <query>`
260
+ - `npx proteum explain --json`
261
+ - `npx proteum explain --connected --controllers`
262
+ - `npx proteum explain owner <query>`
263
+ - `npx proteum doctor --json`
264
+ - `npx proteum doctor --contracts --json`
265
+ - `npx proteum diagnose <path> --port <port>`
266
+ - `npx proteum verify owner <query>`
267
+ - `npx proteum verify request <path>`
268
+ - `npx proteum verify browser <path>`
269
+ - `npx proteum perf ...`
270
+ - `npx proteum trace ...`
271
+ - `npx proteum command ...`
272
+ - `npx proteum session ...`
273
+ - `npx proteum create ... --dry-run --json`
274
+ - `npx proteum dev list --json`
275
+ - `npx proteum dev stop --session-file <path>`
276
+
277
+ Prefer scaffold commands before hand-writing boilerplate:
278
+
279
+ - `npx proteum init <directory> --name <name>`
280
+ - `npx proteum init ... --dry-run --json`
281
+ - `npx proteum create page|controller|command|route|service <target>`
282
+ - `npx proteum create ... --dry-run --json`
283
+
284
+ ### High-Impact Files
241
285
 
242
286
  Edit these only when required, and keep changes minimal and explicit:
243
287
 
@@ -245,14 +289,3 @@ Edit these only when required, and keep changes minimal and explicit:
245
289
  - `PORT`, `ENV_*`, `URL`, and `TRACE_*` env setup
246
290
  - Prisma-generated files
247
291
  - symbolic links
248
-
249
- ## Commands Not To Run
250
-
251
- - `git restore`
252
- - `git reset`
253
- - `prisma *`
254
- - any write-mode git command
255
-
256
- ## Product And UX Docs
257
-
258
- If the task changes UX, copy, onboarding, pricing, product semantics, or commercial positioning, read the relevant files under `./docs/` first, especially `docs/PERSONAS.md`, `docs/PRODUCT.md`, and `docs/MARKETING.md` when they exist.
@@ -4,7 +4,7 @@ This file is the canonical source of truth for diagnostics, temporary instrument
4
4
 
5
5
  ## Initial Triage
6
6
 
7
- - Start with machine-readable app state before reading large parts of the codebase: `./.proteum/manifest.json`, `npx proteum connect --json`, `npx proteum explain --json`, `npx proteum doctor --json`, and `npx proteum doctor --contracts --json` when generated artifacts or manifest-owned files may be stale.
7
+ - Start with machine-readable app state before reading large parts of the codebase: `npx proteum orient <query>`, `./.proteum/manifest.json`, `npx proteum connect --json`, `npx proteum explain --json`, `npx proteum doctor --json`, and `npx proteum doctor --contracts --json` when generated artifacts or manifest-owned files may be stale.
8
8
  - When one app depends on another app's generated controllers, inspect `npx proteum connect --controllers`, `npx proteum explain --connected --controllers`, the producer `proteum.connected.json`, the consumer `proteum.config.ts` connected `source` value, and the producer `./.proteum/proteum.connected.d.ts` before assuming the contract is local.
9
9
  - Use `rg -n` first to narrow the exact code path, then read only the relevant files.
10
10
  - Inspect `./server/index.ts`, `./server/config/*.ts`, and the touched files under `./commands`, `./server/controllers`, `./server/services`, `./server/routes`, `./client/pages`, and `./tests`.
@@ -13,22 +13,25 @@ This file is the canonical source of truth for diagnostics, temporary instrument
13
13
  ## Runtime Diagnostics
14
14
 
15
15
  - For long-lived dev reproductions, start the app with `npx proteum dev --session-file <path> --replace-existing --port <port>` so the session can be listed and stopped deterministically after the repro.
16
- - Human-facing Proteum CLI runs now print the welcome banner and include the active Proteum installation method, but only `npx proteum dev` clears the interactive terminal before rendering and reports connected app names plus successful connected `/ping` checks in the ready banner; keep that in mind when capturing or comparing command logs during diagnosis.
16
+ - Only the bare `npx proteum build` and bare `npx proteum dev` commands print the welcome banner and active Proteum installation method. Any extra argument or option skips the banner. Only `npx proteum dev` clears the interactive terminal before rendering and reports connected app names plus successful connected `/ping` checks in the ready banner; keep that in mind when capturing or comparing command logs during diagnosis.
17
+ - For ownership or repo discovery questions, start with `npx proteum orient <query>` instead of jumping straight into source searches.
17
18
  - For request-time issues in dev, start with `npx proteum diagnose <path> --port <port>` when you have a concrete failing route, page, controller path, or request target. It combines owner lookup, manifest diagnostics, contract diagnostics, matching trace data, and buffered server logs in one pass.
19
+ - Prefer focused verification before global checks: `npx proteum verify owner <query>`, `npx proteum verify request <path>`, and only then `npx proteum verify browser <path>` or targeted Playwright when the bug is browser-visible.
18
20
  - For connected-project failures, confirm the consumer app resolves the expected `connect.<Namespace>.source` and `connect.<Namespace>.urlInternal` values, the producer app exposes `GET /api/__proteum/connected/ping`, and the imported controller entries show `scope=connected` in `proteum explain`.
19
21
  - Use `npx proteum explain owner <query>` when you need a fast ownership graph for a route, controller path, source file, or generated artifact before reading code.
20
- - For performance issues or regressions in dev, use `npx proteum perf top --since <window>` to rank hot paths, `npx proteum perf request <requestId|path>` for one request waterfall, `npx proteum perf compare --baseline <window> --target <window>` for regressions, and `npx proteum perf memory --since <window>` for heap or RSS drift.
22
+ - For performance issues or regressions in dev, use `npx proteum perf top --since <window>` to rank hot paths, `npx proteum perf request <requestId|path>` for one request waterfall plus chain attribution and SQL fingerprints, `npx proteum perf compare --baseline <window> --target <window>` for regressions, and `npx proteum perf memory --since <window>` for heap or RSS drift.
21
23
  - For bundle-size inspection, use `npx proteum build --prod --analyze` to emit `bin/bundle-analysis/client.html` and `client-stats.json`, or add `--analyze-serve --analyze-port auto` when you want a local analyzer URL instead of a static HTML file.
22
24
  - For request-time issues in dev, inspect traces before adding logs when the diagnose surface is still too coarse.
23
25
  - If a server is already running on the default port from `PORT` or `./.proteum/manifest.json`, inspect existing traces before reproducing the issue.
24
26
  - If existing traces are insufficient, arm `npx proteum trace arm --capture deep`, reproduce once, then inspect the new request with `npx proteum trace latest` or `npx proteum trace show <requestId>`.
25
27
  - Inspect browser console errors and warnings for frontend, SSR, hydration, and controller-call issues.
26
28
  - Inspect server startup and runtime errors.
27
- - For protected browser or API flows in dev, prefer `npx proteum session <email> --role <role>` over driving the login UI. Use the login UI only when auth UX itself is under test.
29
+ - For protected browser or API flows in dev, prefer `npx proteum session <email> --role <role>` over driving the login UI. Feed that auth into `npx proteum verify browser ...` or direct Playwright. Use the login UI only when auth UX itself is under test.
28
30
 
29
31
  ## Temporary Instrumentation
30
32
 
31
33
  - When manifest inspection, trace data, browser console output, and server errors are still insufficient, add temporary targeted logs in the code to confirm control flow, payload shape, query shape, or branch selection.
34
+ - If SQL is needed during diagnosis, keep it read-only. Never use SQL to change database structure or execute schema-mutating DDL.
32
35
  - Keep temporary logs narrow, contextual, and easy to remove. Do not leave broad debug noise in shared execution paths.
33
36
  - Re-run only the smallest relevant repro, request, or test after adding temporary instrumentation.
34
37
  - Temporary logs added in the code for diagnosis must be cleaned at the end of tests or the repro cycle and must never be committed.
@@ -36,6 +39,7 @@ This file is the canonical source of truth for diagnostics, temporary instrument
36
39
  ## Error Solving
37
40
 
38
41
  - Fix the contract boundary, not only the downstream symptom.
42
+ - Treat provider, SSR/client-only hook, router-context, and connected-boundary failures as contract mistakes first. The likely fix is where the boundary was crossed incorrectly, not only where the throw surfaced.
39
43
  - Prefer explicit typed schemas, adapters, query `select`s, and narrow response shapes over casts, broad payloads, or hidden fallbacks.
40
44
  - Keep patches narrow, then verify immediately at the failing layer before broadening the test surface.
41
45
  - Review the resulting diff to confirm the fix removed the cause instead of masking it.
@@ -43,13 +47,16 @@ This file is the canonical source of truth for diagnostics, temporary instrument
43
47
  ## Verification And Testing
44
48
 
45
49
  - Use the cheapest trustworthy verification that matches the failing layer.
46
- - After implementing a feature or behavior change, always verify it on a running app instead of stopping at static analysis or code review.
47
- - For compile-time or type-safety issues, start with the relevant typecheck or build command.
50
+ - After implementing a change, verify only at the smallest trustworthy layer required by the changed surface. Do not default to a running app, project-wide typecheck, `npx proteum check`, or Playwright when a narrower static or request-level verification is enough.
51
+ - For compile-time or type-safety issues, start with the relevant targeted typecheck or build command. Do not run them by default for unrelated runtime, copy, docs, or local refactor changes.
48
52
  - For request/runtime issues, verify through the real page, route, generated controller call, or command on a running app.
49
- - Start the smallest trustworthy runtime surface first: boot the server, run the relevant real URL, generated controller call, command, or `npx proteum diagnose <path> --port <port>`, then add targeted Playwright coverage when the change is browser-visible.
50
- - For browser regressions, prefer targeted Playwright coverage and inspect failure artifacts such as screenshots, videos, `error-context.md`, and Playwright traces.
53
+ - Start the smallest trustworthy runtime surface first: `npx proteum orient <query>`, then the relevant real URL, generated controller call, command, or `npx proteum diagnose <path> --port <port>`. Add targeted Playwright coverage only when request-level verification is insufficient or the change is browser-visible.
54
+ - Proteum does not provide a dedicated raw browser-runtime CLI. When `npx proteum verify browser` is insufficient, use direct Playwright with a disposable profile. Do not launch raw browser automation against a shared persistent profile.
55
+ - Focused verification should treat unrelated global diagnostics as visible but non-blocking by default. Use `--strict-global` only when the task explicitly requires broad clean-room validation.
56
+ - For browser regressions, prefer a real browser repro first and add targeted Playwright coverage only when the user asks for automated coverage, when a stable regression path needs automation, or when manual/browser verification is insufficient.
57
+ - Only the final verifier agent should usually run browser flows. Earlier agents should stay on `orient`, `verify owner`, `verify request`, `diagnose`, and command-level checks unless browser execution is the only trustworthy reproducer.
51
58
  - Treat server startup failures, runtime errors, browser console errors or warnings, and Playwright failures as blocking unless they are clearly unrelated to the change.
52
- - When the touched surface can affect coding-style enforcement, run the smallest relevant project check such as `npx proteum lint` or `npx proteum check` before finishing.
59
+ - When the touched surface can affect coding-style enforcement, run the smallest relevant static check. Do not default to `npx proteum check`; prefer a narrower lint or type check only when the changed surface or an observed issue calls for it.
53
60
  - If the task started any long-lived `proteum dev` server, stop it explicitly with `npx proteum dev stop --session-file <path>` or `npx proteum dev stop --all --stale`, then confirm the remaining tracked sessions with `npx proteum dev list --json`.
54
61
  - Add `data-testid` when stable selectors are missing instead of relying on brittle text or DOM-shape selectors.
55
62
  - If an isolated test misses prerequisite state, run the smallest broader scope that reproduces the real setup.
@@ -29,6 +29,8 @@ Diagnostics source of truth: project-root `diagnostics.md`.
29
29
  - Use runtime models through `this.models` or the app model accessors.
30
30
  - Use Prisma typings through `@models/types` only.
31
31
  - In database queries, prefer explicit `select` or narrow `include`.
32
+ - For database structure changes, edit the app's `schema.prisma` only. Never create or edit migration files manually.
33
+ - Never use raw SQL DDL or other schema-mutating SQL to change database structure.
32
34
  - Prefer inferred return types such as `Awaited<ReturnType<MyService['methodName']>>` over manual DTO duplication.
33
35
 
34
36
  ## Errors
@@ -10,7 +10,7 @@ Diagnostics source of truth: project-root `diagnostics.md`.
10
10
  - Understand the real user flow and the main feature branches before writing tests.
11
11
  - Test the current controller/page runtime model, not legacy `@Route` or `api.fetch(...)` behavior.
12
12
  - Verify routing, controllers, SSR, and router plugins against a running app when behavior depends on real request handling.
13
- - After implementing a browser-visible feature or change, run targeted Playwright coverage or a real browser repro against a running app before finishing; this verification is required, not optional cleanup.
13
+ - After implementing a browser-visible feature or change, prefer a real browser repro against a running app first. Add targeted Playwright coverage only when the user asks for automated coverage, when a stable regression path needs automation, or when manual/browser verification is insufficient.
14
14
  - Exercise real URLs, generated controller calls, or real browser flows instead of re-deriving framework internals in tests.
15
15
  - Locate elements with `data-testid`.
16
16
  - Add `data-testid` where needed instead of relying on brittle selectors.
@@ -163,7 +163,35 @@ const renderOwners = (matches: TExplainOwnerMatch[]) =>
163
163
  ? ['Owner matches', '- none'].join('\n')
164
164
  : [
165
165
  'Owner matches',
166
- ...matches.map((match) => `- [${match.kind}] ${match.label} score=${match.score} source=${formatSource(match)}`),
166
+ ...matches.map(
167
+ (match) =>
168
+ `- [${match.kind}] ${match.label} score=${match.score} scope=${match.scopeLabel} origin=${match.originHint} source=${formatSource(match)}`,
169
+ ),
170
+ ].join('\n');
171
+
172
+ const renderChain = (response: TDiagnoseResponse) =>
173
+ !response.chain || response.chain.length === 0
174
+ ? ['Chain', '- none'].join('\n')
175
+ : [
176
+ 'Chain',
177
+ ...response.chain.map(
178
+ (item) =>
179
+ `- [${item.kind}] ${item.label}${item.source?.filepath ? ` source=${item.source.filepath}${item.source.line ? `:${item.source.line}` : ''}${item.source.column ? `:${item.source.column}` : ''}` : ''}${item.details.length > 0 ? ` details=${item.details.join(', ')}` : ''}`,
180
+ ),
181
+ ].join('\n');
182
+
183
+ const renderOrientation = (response: TDiagnoseResponse) =>
184
+ !response.orientation
185
+ ? ['Orientation', '- none'].join('\n')
186
+ : [
187
+ 'Orientation',
188
+ `- agents=${response.orientation.guidance.agents}`,
189
+ `- diagnostics=${response.orientation.guidance.diagnostics}`,
190
+ `- optimizations=${response.orientation.guidance.optimizations}`,
191
+ `- codingStyle=${response.orientation.guidance.codingStyle}`,
192
+ `- areaAgents=${response.orientation.guidance.areaAgents.join(', ') || 'none'}`,
193
+ `- connected imports=${response.orientation.connected.imports.length} producers=${response.orientation.connected.producers.length}`,
194
+ ...response.orientation.nextSteps.map((step) => `- next=${step.command} (${step.reason})`),
167
195
  ].join('\n');
168
196
 
169
197
  const renderSuspects = (response: TDiagnoseResponse) =>
@@ -188,6 +216,10 @@ const renderHuman = (manifest: ReturnType<typeof readProteumManifest>, response:
188
216
  '',
189
217
  renderOwners(response.owner.matches.slice(0, 6)),
190
218
  '',
219
+ renderChain(response),
220
+ '',
221
+ renderOrientation(response),
222
+ '',
191
223
  renderDoctorResponseHuman({
192
224
  emptyMessage: 'No manifest diagnostics were found.',
193
225
  manifest,
@@ -55,7 +55,7 @@ export const run = async (): Promise<void> => {
55
55
  ? ['- No matching manifest owners were found.']
56
56
  : response.matches.map(
57
57
  (match) =>
58
- `- [${match.kind}] ${match.label} score=${match.score} source=${match.source.filepath}${match.source.line ? `:${match.source.line}` : ''}${match.source.column ? `:${match.source.column}` : ''}`,
58
+ `- [${match.kind}] ${match.label} score=${match.score} scope=${match.scopeLabel} origin=${match.originHint} source=${match.source.filepath}${match.source.line ? `:${match.source.line}` : ''}${match.source.column ? `:${match.source.column}` : ''}`,
59
59
  )),
60
60
  ].join('\n'),
61
61
  );