proteum 2.2.9 → 2.4.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.
Files changed (59) hide show
  1. package/AGENTS.md +10 -4
  2. package/README.md +58 -15
  3. package/agents/project/AGENTS.md +53 -10
  4. package/agents/project/DOCUMENTATION.md +1326 -0
  5. package/agents/project/app-root/AGENTS.md +2 -2
  6. package/agents/project/diagnostics.md +12 -7
  7. package/agents/project/optimizations.md +1 -0
  8. package/agents/project/root/AGENTS.md +24 -9
  9. package/agents/project/tests/AGENTS.md +7 -0
  10. package/agents/project/tests/e2e/AGENTS.md +13 -0
  11. package/agents/project/tests/e2e/REAL_WORLD_JOURNEY_TESTS.md +192 -0
  12. package/cli/commands/connect.ts +40 -4
  13. package/cli/commands/dev.ts +148 -25
  14. package/cli/commands/diagnose.ts +138 -5
  15. package/cli/commands/doctor.ts +24 -4
  16. package/cli/commands/explain.ts +134 -6
  17. package/cli/commands/mcp.ts +133 -0
  18. package/cli/commands/orient.ts +93 -3
  19. package/cli/commands/perf.ts +118 -13
  20. package/cli/commands/runtime.ts +234 -0
  21. package/cli/commands/trace.ts +116 -21
  22. package/cli/mcp/router.ts +1010 -0
  23. package/cli/presentation/commands.ts +93 -26
  24. package/cli/presentation/devSession.ts +2 -0
  25. package/cli/presentation/help.ts +1 -1
  26. package/cli/runtime/commands.ts +215 -24
  27. package/cli/runtime/devSessions.ts +328 -2
  28. package/cli/runtime/mcpDaemon.ts +288 -0
  29. package/cli/runtime/ports.ts +151 -0
  30. package/cli/utils/agentOutput.ts +46 -0
  31. package/cli/utils/agents.ts +194 -51
  32. package/cli/utils/appRoots.ts +232 -0
  33. package/common/dev/diagnostics.ts +1 -1
  34. package/common/dev/inspection.ts +22 -7
  35. package/common/dev/mcpPayloads.ts +1150 -0
  36. package/common/dev/mcpServer.ts +287 -0
  37. package/docs/agent-routing.md +137 -0
  38. package/docs/dev-commands.md +2 -0
  39. package/docs/dev-sessions.md +4 -1
  40. package/docs/diagnostics.md +70 -24
  41. package/docs/mcp.md +206 -0
  42. package/docs/migrate-from-2.1.3.md +14 -6
  43. package/docs/request-tracing.md +12 -6
  44. package/package.json +11 -3
  45. package/server/app/devMcp.ts +204 -0
  46. package/server/services/router/http/cache.ts +116 -0
  47. package/server/services/router/http/index.ts +94 -35
  48. package/server/services/router/index.ts +8 -11
  49. package/server/services/router/request/ip.test.cjs +0 -1
  50. package/tests/agents-utils.test.cjs +92 -14
  51. package/tests/cli-mcp-command.test.cjs +262 -0
  52. package/tests/codex-mcp-usage.test.cjs +307 -0
  53. package/tests/dev-sessions.test.cjs +113 -0
  54. package/tests/dev-transpile-watch.test.cjs +117 -9
  55. package/tests/eslint-rules.test.cjs +0 -1
  56. package/tests/inspection.test.cjs +66 -0
  57. package/tests/mcp.test.cjs +873 -0
  58. package/tests/router-cache-config.test.cjs +73 -0
  59. package/vitest.config.mjs +9 -0
@@ -0,0 +1,287 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { CallToolResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import { z } from 'zod/v4';
4
+
5
+ import { stringifyMcpPayload, type TProteumMcpPayload } from './mcpPayloads';
6
+
7
+ export type TProteumMcpDetail = 'compact' | 'full';
8
+
9
+ export type TProteumMcpProvider = {
10
+ diagnose: (input: {
11
+ logsLevel?: 'silly' | 'log' | 'info' | 'warn' | 'error';
12
+ logsLimit?: number;
13
+ path?: string;
14
+ query?: string;
15
+ requestId?: string;
16
+ }) => Promise<TProteumMcpPayload>;
17
+ doctor: (input: { contracts?: boolean }) => Promise<TProteumMcpPayload>;
18
+ explainSummary: (input: { query?: string }) => Promise<TProteumMcpPayload>;
19
+ instructionsResolve: (input: { query?: string }) => Promise<TProteumMcpPayload>;
20
+ logsTail: (input: { level?: 'silly' | 'log' | 'info' | 'warn' | 'error'; limit?: number }) => Promise<TProteumMcpPayload>;
21
+ orient: (input: { query: string }) => Promise<TProteumMcpPayload>;
22
+ perfRequest: (input: { query: string }) => Promise<TProteumMcpPayload>;
23
+ perfTop: (input: { groupBy?: 'path' | 'route' | 'controller'; limit?: number; since?: string }) => Promise<TProteumMcpPayload>;
24
+ readResource: (uri: string) => Promise<TProteumMcpPayload>;
25
+ routeCandidates: (input: { limit?: number; query: string }) => Promise<TProteumMcpPayload>;
26
+ runtimeStatus: (input: Record<string, never>) => Promise<TProteumMcpPayload>;
27
+ traceLatest: (input: { detail?: TProteumMcpDetail; limit?: number; offset?: number }) => Promise<TProteumMcpPayload>;
28
+ traceShow: (input: { detail?: TProteumMcpDetail; limit?: number; offset?: number; requestId: string }) => Promise<TProteumMcpPayload>;
29
+ workflowStart: (input: { file?: string; query?: string; route?: string; task?: string }) => Promise<TProteumMcpPayload>;
30
+ };
31
+
32
+ type TCreateProteumMcpServerArgs = {
33
+ provider: TProteumMcpProvider;
34
+ version: string;
35
+ };
36
+
37
+ const jsonToolResult = (payload: object): CallToolResult => ({
38
+ content: [
39
+ {
40
+ type: 'text',
41
+ text: stringifyMcpPayload(payload),
42
+ },
43
+ ],
44
+ });
45
+
46
+ const jsonResourceResult = (uri: string, payload: object): ReadResourceResult => ({
47
+ contents: [
48
+ {
49
+ mimeType: 'application/json',
50
+ text: stringifyMcpPayload(payload),
51
+ uri,
52
+ },
53
+ ],
54
+ });
55
+
56
+ const readOnlyAnnotations = {
57
+ destructiveHint: false,
58
+ idempotentHint: true,
59
+ openWorldHint: false,
60
+ readOnlyHint: true,
61
+ };
62
+
63
+ const detailSchema = z.enum(['compact', 'full']).optional();
64
+ const logsLevelSchema = z.enum(['silly', 'log', 'info', 'warn', 'error']).optional();
65
+ const positiveLimitSchema = z.number().int().min(1).max(100).optional();
66
+ const offsetSchema = z.number().int().min(0).max(10_000).optional();
67
+
68
+ export const createProteumMcpServer = ({ provider, version }: TCreateProteumMcpServerArgs) => {
69
+ const server = new McpServer(
70
+ {
71
+ name: 'proteum',
72
+ version,
73
+ },
74
+ {
75
+ capabilities: {
76
+ logging: {},
77
+ },
78
+ },
79
+ );
80
+
81
+ server.registerTool(
82
+ 'workflow_start',
83
+ {
84
+ annotations: readOnlyAnnotations,
85
+ description:
86
+ 'Bootstrap an agent workflow with compact runtime, instruction, owner, doctor, and next-action data in one read.',
87
+ inputSchema: {
88
+ file: z.string().optional().describe('Optional source file or generated artifact path in scope.'),
89
+ query: z.string().optional().describe('Optional task, route, controller, file, or owner query.'),
90
+ route: z.string().optional().describe('Optional route path in scope.'),
91
+ task: z.string().optional().describe('Optional short natural-language task description.'),
92
+ },
93
+ title: 'Proteum Workflow Start',
94
+ },
95
+ async ({ file, query, route, task }) => jsonToolResult(await provider.workflowStart({ file, query, route, task })),
96
+ );
97
+
98
+ server.registerTool(
99
+ 'runtime_status',
100
+ {
101
+ annotations: readOnlyAnnotations,
102
+ description: 'Return the compact Proteum app manifest, selected dev runtime, tracked sessions, and health.',
103
+ inputSchema: {},
104
+ title: 'Proteum Runtime Status',
105
+ },
106
+ async () => jsonToolResult(await provider.runtimeStatus({})),
107
+ );
108
+
109
+ server.registerTool(
110
+ 'orient',
111
+ {
112
+ annotations: readOnlyAnnotations,
113
+ description: 'Resolve owners, instruction files, connected boundaries, and next diagnostic actions for a query.',
114
+ inputSchema: {
115
+ query: z.string().min(1).describe('Route, controller, file path, connected namespace, or task query.'),
116
+ },
117
+ title: 'Proteum Orient',
118
+ },
119
+ async ({ query }) => jsonToolResult(await provider.orient({ query })),
120
+ );
121
+
122
+ server.registerTool(
123
+ 'instructions_resolve',
124
+ {
125
+ annotations: readOnlyAnnotations,
126
+ description: 'Return the routed Proteum instruction files an agent should read for the current query.',
127
+ inputSchema: {
128
+ query: z.string().optional().describe('Optional task, route, file path, or area query.'),
129
+ },
130
+ title: 'Proteum Instruction Routing',
131
+ },
132
+ async ({ query }) => jsonToolResult(await provider.instructionsResolve({ query })),
133
+ );
134
+
135
+ server.registerTool(
136
+ 'explain_summary',
137
+ {
138
+ annotations: readOnlyAnnotations,
139
+ description: 'Return a compact manifest summary or owner ranking without dumping the full generated manifest.',
140
+ inputSchema: {
141
+ query: z.string().optional().describe('Optional owner query. Omit for the manifest summary.'),
142
+ },
143
+ title: 'Proteum Explain Summary',
144
+ },
145
+ async ({ query }) => jsonToolResult(await provider.explainSummary({ query })),
146
+ );
147
+
148
+ server.registerTool(
149
+ 'route_candidates',
150
+ {
151
+ annotations: readOnlyAnnotations,
152
+ description: 'Return compact route candidates for a query without dumping raw route arrays.',
153
+ inputSchema: {
154
+ limit: z.number().int().min(1).max(50).optional(),
155
+ query: z.string().min(1).describe('Route path or route-like search query.'),
156
+ },
157
+ title: 'Proteum Route Candidates',
158
+ },
159
+ async ({ limit, query }) => jsonToolResult(await provider.routeCandidates({ limit, query })),
160
+ );
161
+
162
+ server.registerTool(
163
+ 'doctor',
164
+ {
165
+ annotations: readOnlyAnnotations,
166
+ description: 'Return compact manifest diagnostics, optionally including generated-contract diagnostics.',
167
+ inputSchema: {
168
+ contracts: z.boolean().optional().describe('Include generated contract diagnostics.'),
169
+ },
170
+ title: 'Proteum Doctor',
171
+ },
172
+ async ({ contracts }) => jsonToolResult(await provider.doctor({ contracts })),
173
+ );
174
+
175
+ server.registerTool(
176
+ 'diagnose',
177
+ {
178
+ annotations: readOnlyAnnotations,
179
+ description: 'Read the dev runtime composite diagnosis for an existing trace, route, request id, or query.',
180
+ inputSchema: {
181
+ logsLevel: logsLevelSchema,
182
+ logsLimit: z.number().int().min(0).max(100).optional(),
183
+ path: z.string().optional(),
184
+ query: z.string().optional(),
185
+ requestId: z.string().optional(),
186
+ },
187
+ title: 'Proteum Diagnose',
188
+ },
189
+ async ({ logsLevel, logsLimit, path, query, requestId }) =>
190
+ jsonToolResult(await provider.diagnose({ logsLevel, logsLimit, path, query, requestId })),
191
+ );
192
+
193
+ server.registerTool(
194
+ 'trace_latest',
195
+ {
196
+ annotations: readOnlyAnnotations,
197
+ description: 'Return a compact summary of the latest request trace, with optional paginated full detail.',
198
+ inputSchema: {
199
+ detail: detailSchema,
200
+ limit: positiveLimitSchema,
201
+ offset: offsetSchema,
202
+ },
203
+ title: 'Proteum Latest Trace',
204
+ },
205
+ async ({ detail, limit, offset }) => jsonToolResult(await provider.traceLatest({ detail, limit, offset })),
206
+ );
207
+
208
+ server.registerTool(
209
+ 'trace_show',
210
+ {
211
+ annotations: readOnlyAnnotations,
212
+ description: 'Return a compact or paginated full summary of a specific request trace.',
213
+ inputSchema: {
214
+ detail: detailSchema,
215
+ limit: positiveLimitSchema,
216
+ offset: offsetSchema,
217
+ requestId: z.string().min(1),
218
+ },
219
+ title: 'Proteum Trace Show',
220
+ },
221
+ async ({ detail, limit, offset, requestId }) =>
222
+ jsonToolResult(await provider.traceShow({ detail, limit, offset, requestId })),
223
+ );
224
+
225
+ server.registerTool(
226
+ 'perf_top',
227
+ {
228
+ annotations: readOnlyAnnotations,
229
+ description: 'Return compact trace-derived performance rollups for hot routes, paths, or controllers.',
230
+ inputSchema: {
231
+ groupBy: z.enum(['path', 'route', 'controller']).optional(),
232
+ limit: z.number().int().min(1).max(50).optional(),
233
+ since: z.string().optional(),
234
+ },
235
+ title: 'Proteum Perf Top',
236
+ },
237
+ async ({ groupBy, limit, since }) => jsonToolResult(await provider.perfTop({ groupBy, limit, since })),
238
+ );
239
+
240
+ server.registerTool(
241
+ 'perf_request',
242
+ {
243
+ annotations: readOnlyAnnotations,
244
+ description: 'Return a compact waterfall and attribution summary for one traced request id or path.',
245
+ inputSchema: {
246
+ query: z.string().min(1).describe('Request id or path.'),
247
+ },
248
+ title: 'Proteum Perf Request',
249
+ },
250
+ async ({ query }) => jsonToolResult(await provider.perfRequest({ query })),
251
+ );
252
+
253
+ server.registerTool(
254
+ 'logs_tail',
255
+ {
256
+ annotations: readOnlyAnnotations,
257
+ description: 'Return capped recent Proteum dev server logs.',
258
+ inputSchema: {
259
+ level: logsLevelSchema,
260
+ limit: z.number().int().min(0).max(100).optional(),
261
+ },
262
+ title: 'Proteum Logs Tail',
263
+ },
264
+ async ({ level, limit }) => jsonToolResult(await provider.logsTail({ level, limit })),
265
+ );
266
+
267
+ for (const [name, uri, description] of [
268
+ ['runtime-status', 'proteum://runtime/status', 'Current compact runtime status.'],
269
+ ['instructions-router', 'proteum://instructions/router', 'Current instruction routing contract.'],
270
+ ['manifest-summary', 'proteum://manifest/summary', 'Compact generated manifest summary.'],
271
+ ['trace-latest-summary', 'proteum://trace/latest/summary', 'Latest request trace summary.'],
272
+ ['perf-top', 'proteum://perf/top', 'Current compact perf top rollup.'],
273
+ ] as const) {
274
+ server.registerResource(
275
+ name,
276
+ uri,
277
+ {
278
+ description,
279
+ mimeType: 'application/json',
280
+ title: description,
281
+ },
282
+ async (resourceUri) => jsonResourceResult(resourceUri.href, await provider.readResource(uri)),
283
+ );
284
+ }
285
+
286
+ return server;
287
+ };
@@ -0,0 +1,137 @@
1
+ # Agent Routing And Token Efficiency
2
+
3
+ Proteum routing and diagnostics CLI commands are agent-facing by default. The interactive `proteum dev` and user-facing `proteum build` surfaces keep their human presentation.
4
+
5
+ The optimized stack is:
6
+
7
+ - routed agent instructions for stable policy
8
+ - compact CLI for reproducible command-line checks
9
+ - MCP for repeated reads of the same project/runtime state, routed by `projectId`
10
+
11
+ The routing strategy is:
12
+
13
+ 1. Use instructions for hard safety rules and routing only.
14
+ 2. Use MCP first when available for read-only runtime status, instruction routing, owner lookup, diagnosis, traces, perf, and logs.
15
+ 3. Start machine MCP sessions with `workflow_start { cwd, task, route?, file? }` when possible; use `project_resolve { cwd }` when the bootstrap is ambiguous, no `projectId` is known, or the app is offline.
16
+ 4. Pass the returned live stable `projectId` to every follow-up app-bound MCP call.
17
+ 5. Use MCP `orient { projectId, query }`, `instructions_resolve { projectId, query }`, `route_candidates { projectId, query }`, and `explain_summary { projectId, query }` only when `workflow_start` did not return enough owner or instruction detail.
18
+ 6. Use compact CLI output for reproducible terminal validation, CI-like checks, fallback repair, and final evidence.
19
+ 7. Use `--full`, `--manifest`, `--events`, or MCP paginated `detail: "full"` only after compact output identifies the missing detail.
20
+
21
+ ## Problem Resolved
22
+
23
+ Past agent workflows spent too much context on repeated instruction payloads, full manifest dumps, raw trace JSON, and broad source searches.
24
+
25
+ The measured Product diagnostic loop produced roughly tens of thousands of output tokens because agents combined:
26
+
27
+ - `dev list`
28
+ - `orient`
29
+ - full `diagnose`
30
+ - raw `trace latest`
31
+ - `perf request`
32
+ - `verify request`
33
+ - sometimes full manifest or explain section output
34
+
35
+ Managed project instructions also embedded the same Proteum corpus into multiple generated files, so reading a handful of local docs could repeat the same contract many times.
36
+
37
+ ## CLI Contract
38
+
39
+ Default CLI output for agent commands is compact `proteum-agent-v1` JSON:
40
+
41
+ ```json
42
+ {
43
+ "ok": true,
44
+ "format": "proteum-agent-v1",
45
+ "summary": "...",
46
+ "data": {},
47
+ "nextActions": [],
48
+ "omitted": [],
49
+ "fullDetailCommand": "..."
50
+ }
51
+ ```
52
+
53
+ Use compact CLI commands when MCP is unavailable, when a command must be reproducible in a shell, or when final terminal evidence is required:
54
+
55
+ ```bash
56
+ proteum orient <route|file|controller|error>
57
+ proteum runtime status
58
+ proteum diagnose <target>
59
+ proteum perf request <requestId|path>
60
+ proteum trace latest
61
+ ```
62
+
63
+ Use MCP for repeated reads when a client is available:
64
+
65
+ ```text
66
+ proteum mcp
67
+ ```
68
+
69
+ The machine router discovers live `proteum dev` sessions and offline Proteum app roots under a cwd. `proteum dev` ensures one managed machine MCP daemon is running; terminal `proteum mcp` starts or reuses that daemon, while MCP clients can use stdio. Agents should call MCP `workflow_start` with `cwd` or a known `projectId`, use `project_resolve { cwd }` when routing is ambiguous or offline, and pass the returned live `projectId` to every follow-up app-bound MCP tool. Offline candidates include port-inspected next actions, so agents should follow those instead of guessing the manifest default port. The router forwards to the selected dev-hosted `/__proteum/mcp` endpoint and strips routing fields before the app sees the call.
70
+
71
+ If machine MCP routing returns offline candidates, choose the intended app root and follow that candidate's next action from the app root, not from the monorepo wrapper. If machine MCP routing fails, run `proteum mcp status` and `proteum runtime status` from the intended app root; if no live session exists, use the exact Start Dev next action from runtime status so occupied router/HMR ports are avoided. If the same app already responds on the configured port without live tracking, use or repair that runtime instead of starting another server. Do not `curl` normal page routes to identify which app owns a port; use runtime status or Proteum dev-only endpoints. If a live session exists but runtime/MCP is unreachable, stop the listed session file first, then start dev again. Do not run diagnose, trace, or perf reads while runtime health is unreachable. Do not start a second dev server in the same worktree, and do not start a second managed MCP daemon. Then retry MCP `workflow_start`.
72
+
73
+ Prefer CLI over MCP when the result must be reproducible as a shell command, part of verification, or copied into CI/debug instructions.
74
+
75
+ MCP output is compact `proteum-mcp-v1` JSON. It is intentionally single-line JSON, capped, and paginated for full trace detail. Do not expand MCP output just to make it look nicer for humans.
76
+
77
+ Use full-detail escape hatches only when needed:
78
+
79
+ ```bash
80
+ proteum explain --manifest
81
+ proteum explain --routes --controllers --full
82
+ proteum orient <query> --full
83
+ proteum diagnose <target> --full
84
+ proteum trace show <requestId> --events
85
+ proteum perf request <requestId> --full
86
+ ```
87
+
88
+ ## Instruction Contract
89
+
90
+ Managed `AGENTS.md` files now carry a compact router instead of the full instruction corpus.
91
+
92
+ The router standard is trigger -> canonical instruction file, not trigger -> copied summary. Keep the compact root focused on hard safety rules, routing triggers, and source-map references. When a trigger needs a lifecycle or area contract, route agents to the full file that owns the rule.
93
+
94
+ Standard triggered reads:
95
+
96
+ - Git lifecycle (`commit`, `and commit`, `stage`, `push`, `PR`, pull request): root contract fallback.
97
+ - Before finishing production code changes: root contract fallback, `CODING_STYLE.md`, and touched area `AGENTS.md`.
98
+ - Runtime-visible, request-time, router, SSR, browser, or controller behavior: root contract fallback plus `diagnostics.md`.
99
+ - Non-trivial feature, product, business-rule, UX, copy, or docs changes: `DOCUMENTATION.md`.
100
+ - Implementation edits: `CODING_STYLE.md` plus the matching area file from the routing table.
101
+
102
+ `workflow_start`, `orient`, `route_candidates`, and MCP `instructions_resolve` should promote obvious triggered files into selected instruction previews; ambiguous conditional reads can remain in `readWhen`.
103
+
104
+ Area files carry only their own source content:
105
+
106
+ - `DOCUMENTATION.md`: documentation-driven coding, `/docs` source-of-truth routing, and docs update expectations
107
+ - `diagnostics.md`: raw errors, failing routes, traces, perf, reproduction
108
+ - `optimizations.md`: package, runtime, build, and optimization decisions
109
+ - `CODING_STYLE.md`: implementation style before editing
110
+ - `client/AGENTS.md`: client code
111
+ - `client/pages/AGENTS.md`: page route/data/render rules
112
+ - `server/services/AGENTS.md`: services
113
+ - `server/routes/AGENTS.md`: manual routes
114
+ - `tests/e2e/AGENTS.md`: E2E workflow
115
+ - `tests/e2e/REAL_WORLD_JOURNEY_TESTS.md`: journey-test design
116
+
117
+ Agents should not read broad folders or every managed instruction file. They should use selected MCP previews for read-only discovery and diagnostics, then read full files only before edits or git writes, when returned `fullRead`/`fullReadPolicy` requires it, or when the preview is insufficient.
118
+
119
+ MCP `workflow_start` exposes the first routing decision in compact JSON. MCP `instructions_resolve { projectId, query }` is the lowest-token way to refresh instruction selection without rereading full docs.
120
+
121
+ ## Benchmark Result
122
+
123
+ The latest Product `/domains` benchmark used routed instructions plus the compact CLI/MCP stack. Token estimates are `ceil(UTF-8 bytes / 4)` and measure output size only.
124
+
125
+ | Workflow | Approx output tokens | Elapsed |
126
+ | --- | ---: | ---: |
127
+ | Compact CLI single loop | 6,286 | 4,809 ms |
128
+ | Dev-hosted HTTP MCP single loop | 5,211 | 232 ms |
129
+ | Compact CLI repeated reads x3 | 11,660 | 9,572 ms |
130
+ | Dev-hosted HTTP MCP repeated reads x3 | 10,537 | 214 ms |
131
+
132
+ The result confirms the intended routing:
133
+
134
+ - use CLI for reproducible verification and final command evidence
135
+ - use `workflow_start` to collapse project resolution, runtime status, instruction previews, owner summary, and first next actions into one read
136
+ - use machine MCP with `projectId` for repeated runtime reads against an already running app
137
+ - use `instructions_resolve` to refresh routing instead of rereading full instruction files
@@ -79,6 +79,8 @@ The profiler also exposes the shared diagnostics surfaces for humans:
79
79
 
80
80
  For the shared diagnostics contract, trace-derived perf contract, and the corresponding dev HTTP endpoints, see [diagnostics.md](diagnostics.md) and [request-tracing.md](request-tracing.md).
81
81
 
82
+ Command execution stays in the CLI, profiler, and dev command HTTP endpoints. The Proteum MCP surfaces are read-only; use MCP with the selected `projectId` for repeated diagnostics, trace, perf, status, and log reads, not for running commands.
83
+
82
84
  ### HTTP Endpoints
83
85
 
84
86
  The CLI remote mode and the profiler use the same dev-only endpoints:
@@ -78,13 +78,14 @@ curl -H "$(jq -r '.curlCookieHeader' session.json)" http://localhost:3101/api/Au
78
78
  - Prefer `proteum session` over UI login automation when the goal is to test or debug protected application behavior.
79
79
  - Prefer `proteum verify browser` for focused browser-visible verification, and `proteum e2e --port <port>` for targeted or full Playwright suites. When lower-level control is required, use direct Playwright with a disposable profile.
80
80
  - Use UI login automation only when the auth UX itself is the feature under test.
81
- - Pair it with `proteum diagnose` for a fast protected-route summary, `proteum perf request` for a one-request timing breakdown, then use `proteum trace` when you need lower-level request events.
81
+ - Pair it with `proteum diagnose` for a fast protected-route summary, `proteum perf request` for a one-request timing breakdown, or MCP `diagnose`/`perf_request` with the selected `projectId` for repeated reads against the same running app. Use `proteum trace show <requestId> --events` only when you need lower-level request events.
82
82
  - Only the final verifier agent should usually run browser flows. Earlier agents should stay on `orient`, `verify owner`, `verify request`, and request-level diagnostics unless browser execution is required.
83
83
 
84
84
  Typical flow:
85
85
 
86
86
  ```bash
87
87
  proteum orient /dashboard
88
+ proteum runtime status
88
89
  proteum session admin@example.com --role ADMIN --port 3101 --json > session.json
89
90
  proteum e2e --port 3101 --session-email admin@example.com --session-role ADMIN tests/e2e/features/dashboard.spec.ts
90
91
  proteum diagnose /dashboard --hit /dashboard --port 3101
@@ -92,6 +93,8 @@ proteum perf request /dashboard --port 3101
92
93
  proteum trace latest --port 3101
93
94
  ```
94
95
 
96
+ Use the exact next action from `proteum runtime status` before starting a long-lived dev server. It inspects configured router/HMR ports without fetching normal page bodies, and it tells agents to use or repair an untracked same-app runtime instead of starting a second server.
97
+
95
98
  When `proteum verify browser <path>` is available in the target app, it uses the same fresh per-run browser workspace model under `var/proteum/browser/<run-id>` and should be preferred over ad hoc shared Playwright profile reuse.
96
99
 
97
100
  ## Dev HTTP Endpoint
@@ -11,21 +11,26 @@ These are not separate models for different tools. `orient`, `explain`, and `doc
11
11
 
12
12
  Performance inspection is a sibling surface, not a separate instrumentation stack: `proteum perf` and the profiler `Perf` tab aggregate the same dev-only request traces that back `proteum trace`.
13
13
 
14
+ The diagnostics and routing CLI surfaces are optimized for agents by default. They return compact decision-ready output first and expose large raw detail only through explicit flags such as `--full`, `--manifest`, or `--events`.
15
+
16
+ For repeated agent reads, Proteum also exposes the same compact diagnostic contract through `proteum mcp`, a machine-scope router that forwards `projectId`-scoped calls to the matching dev-hosted `/__proteum/mcp` endpoint. See [mcp.md](mcp.md).
17
+
14
18
  ## Shared Contract
15
19
 
16
20
  The canonical snapshot lives in `./.proteum/manifest.json`.
17
21
 
18
- Proteum uses that same manifest in seven places:
22
+ Proteum uses that same manifest in these places:
19
23
 
20
24
  - `proteum orient` for owner lookup, guidance resolution, connected-boundary summary, and next-step suggestions
21
- - `proteum explain` for human-readable and `--json` output
25
+ - `proteum explain` for compact manifest summaries and selected-section counts
22
26
  - `proteum doctor` for human-readable and `--json` output
23
27
  - `proteum explain owner <query>` for ownership lookup over the manifest index
24
28
  - `proteum doctor --contracts` for generated-artifact and manifest-owned source validation on disk
25
29
  - the dev-only `__proteum/explain*` and `__proteum/doctor*` HTTP endpoints
30
+ - the dev-only `/__proteum/mcp` endpoint
26
31
  - the `Explain`, `Doctor`, and `Diagnose` tabs in the bottom profiler during `proteum dev`
27
32
 
28
- This means the CLI, the dev HTTP endpoints, and the profiler all describe the same framework-owned snapshot before any live trace or log overlays are added.
33
+ This means the CLI, MCP, the dev HTTP endpoints, and the profiler all describe the same framework-owned snapshot before any live trace or log overlays are added.
29
34
 
30
35
  If a command such as `proteum explain`, `proteum doctor`, `proteum diagnose`, or `proteum refresh` regenerates `.proteum/manifest.json`, the next CLI call, HTTP call, or profiler refresh will reflect that same updated snapshot.
31
36
 
@@ -39,11 +44,12 @@ proteum orient /api/Auth/CurrentUser
39
44
  proteum explain
40
45
  proteum explain owner /api/Auth/CurrentUser
41
46
  proteum explain --routes --controllers --commands
42
- proteum explain --all --json
47
+ proteum explain --routes --controllers --commands --full
48
+ proteum explain --manifest
43
49
 
44
50
  proteum doctor
45
51
  proteum doctor --contracts
46
- proteum doctor --json
52
+ proteum doctor --full
47
53
  proteum doctor --strict
48
54
 
49
55
  proteum diagnose /
@@ -59,45 +65,76 @@ proteum perf top --since today
59
65
  proteum perf request /dashboard --port 3101
60
66
  proteum perf compare --baseline yesterday --target today --group-by route
61
67
  proteum perf memory --since 1h --group-by controller
68
+
69
+ proteum runtime status
70
+ ```
71
+
72
+ Default compact command output follows this shape:
73
+
74
+ ```json
75
+ {
76
+ "ok": true,
77
+ "format": "proteum-agent-v1",
78
+ "summary": "...",
79
+ "data": {},
80
+ "nextActions": [],
81
+ "omitted": [],
82
+ "fullDetailCommand": "..."
83
+ }
62
84
  ```
63
85
 
64
- `proteum orient --json` emits:
86
+ `proteum orient` emits compact agent JSON with:
65
87
 
66
88
  - `query`
67
- - `normalizedQuery`
68
89
  - `app`
69
- - `guidance`
70
90
  - `owner`
91
+ - `instructions.mustRead`
92
+ - `instructions.readWhen`
71
93
  - `connected`
72
- - `nextSteps`
94
+ - `nextActions`
73
95
  - `warnings`
74
96
 
75
- `proteum explain --json` emits the selected manifest sections as machine-readable JSON.
97
+ `proteum orient --full` emits the full orientation payload.
98
+
99
+ `proteum explain` emits a compact manifest summary. Explicit section flags such as `--routes --controllers` now summarize those sections by default to avoid route/controller dumps in agent context. Add `--full` to emit selected raw section arrays, or use `proteum explain --manifest` for the full generated manifest.
76
100
 
77
- `proteum explain owner <query> --json` keeps the existing owner ranking shape and adds:
101
+ `proteum explain owner <query>` emits compact owner ranking. `proteum explain owner <query> --full` keeps the existing full owner ranking shape and adds:
78
102
 
79
103
  - `scopeLabel`
80
104
  - `originHint`
81
105
 
82
- `proteum doctor --json` emits:
106
+ `proteum doctor` emits compact diagnostics. `proteum doctor --full` emits:
83
107
 
84
108
  - `summary.errors`
85
109
  - `summary.warnings`
86
110
  - `summary.strictFailed`
87
111
  - `diagnostics`
88
112
 
89
- `proteum diagnose` emits a composite response with:
113
+ `proteum runtime status` emits the current app manifest summary, tracked dev sessions, selected live session, MCP URL, health status, configured router/HMR port inspection, and a suggested next command. Use it before starting another dev server, and use its Start Dev command instead of probing page bodies when the default port is occupied. If it reports that the same app already responds on the configured port without a live tracked session, use or repair that runtime instead of starting a second server.
114
+
115
+ During `proteum dev`, `/__proteum/mcp` exposes compact `workflow_start`, `runtime_status`, `orient`, `instructions_resolve`, `route_candidates`, `explain_summary`, `doctor`, `diagnose`, `trace_*`, `perf_*`, and `logs_tail` tools without spawning CLI commands for each repeated read. `proteum dev` also ensures one managed machine `proteum mcp` daemon is running. Through the machine router, call `workflow_start` with `cwd` or a known `projectId`; if routing is ambiguous or returns offline app candidates, use `project_resolve { cwd }`, follow the selected app root's port-inspected next action when needed, then pass the selected live `projectId` to follow-up app-bound tools.
116
+
117
+ MCP tool/resource output follows compact single-line `proteum-mcp-v1` JSON:
118
+
119
+ ```json
120
+ {"ok":true,"format":"proteum-mcp-v1","summary":"...","data":{},"nextActions":[],"omitted":[]}
121
+ ```
122
+
123
+ Use MCP for repeated reads of the same app/runtime state. Keep CLI commands for reproducible validation, final evidence, and CI-like command output.
124
+
125
+ `proteum diagnose` emits a compact composite response with:
90
126
 
91
127
  - `owner`
92
- - `orientation`
128
+ - `instructions`
93
129
  - `chain`
94
130
  - `doctor`
95
131
  - `contracts`
96
132
  - `request`
97
- - `attribution`
98
133
  - `suspects`
99
134
  - `serverLogs`
100
135
 
136
+ `proteum diagnose --full` emits the full lower-level composite response, including raw request trace payloads.
137
+
101
138
  `proteum verify owner|request|browser --json` emits:
102
139
 
103
140
  - `action`
@@ -115,6 +152,8 @@ proteum perf memory --since 1h --group-by controller
115
152
  - `compare`: grouped baseline vs target deltas
116
153
  - `memory`: grouped heap and RSS drift summaries
117
154
 
155
+ `proteum trace latest` and `proteum trace show <requestId>` emit compact trace summaries by default. Use `--events` or `--full` to print the raw event stream, payload summaries, and SQL text.
156
+
118
157
  Focused verification defaults to the smallest trustworthy surface first:
119
158
 
120
159
  - `verify owner`: orient the target, then choose request, command, or local owner-scoped diagnostics
@@ -137,6 +176,7 @@ In `profile: dev`, the running app exposes:
137
176
  - `GET /__proteum/perf/compare`
138
177
  - `GET /__proteum/perf/memory`
139
178
  - `GET /__proteum/perf/request`
179
+ - `POST|GET|DELETE /__proteum/mcp`
140
180
 
141
181
  `/__proteum/explain` supports optional section selection:
142
182
 
@@ -169,6 +209,8 @@ GET /__proteum/diagnose?query=/api/Auth/CurrentUser&logsLevel=warn&logsLimit=40
169
209
 
170
210
  These endpoints are intended for local tooling and are not available in production.
171
211
 
212
+ `/__proteum/mcp` is the dev-hosted MCP transport. It exposes the read-only tool/resource contract backed directly by the running app's diagnostics, trace, perf, and log stores. The `proteum dev` session UI and ready banner print this URL when the server is ready. The machine `proteum mcp` router discovers these live endpoints and routes app-bound calls by `projectId`.
213
+
172
214
  ## Profiler
173
215
 
174
216
  During `proteum dev`, the bottom profiler is the human-facing UI over the same dev diagnostics surfaces.
@@ -207,12 +249,16 @@ Treat these as framework contract failures first. The fix usually belongs at the
207
249
 
208
250
  For AI coding agents or automation:
209
251
 
210
- 1. Start with `proteum orient <query>` when the target might be generated, connected, framework-owned, or multi-repo.
211
- 2. Read `./.proteum/manifest.json` or run `proteum explain --json` only after you know which surface matters.
212
- 3. Run `proteum doctor --json` and `proteum doctor --contracts --json` to inspect framework and generated-artifact diagnostics.
213
- 4. Use `proteum verify owner <query>` or `proteum diagnose <path> --port <port>` for the smallest trustworthy runtime surface before broad checks.
214
- 5. Use `proteum verify browser` for browser-visible verification, or `proteum e2e --port <port>` for targeted/full Playwright suites. Only drop to direct Playwright when the Proteum wrapper cannot express the needed control. Keep auth sourced from Proteum session helpers, and reserve browser flows for the final verifier agent unless they are the only trustworthy surface.
215
- 6. For performance, CPU, SQL, render, cache, or connected-boundary questions, use `proteum perf request <requestId|path>` against the same running dev server.
216
- 7. Use `proteum trace ...` when you need lower-level event detail than `diagnose` or `perf` provides.
217
- 8. Run global checks second, not first. Unrelated diagnostics should remain visible but non-blocking during focused verification unless strict global mode is required.
218
- 9. Open the profiler only when a human-readable view helps; it should agree with the CLI after refresh.
252
+ 1. When MCP is available, call `workflow_start` with `cwd` or a known `projectId`; if routing is ambiguous or returns offline app candidates, call `project_resolve { cwd }`, select the intended app root, start dev from that app root when needed, then retry with the selected stable live `projectId`.
253
+ 2. Use the returned `projectId` for MCP `runtime_status`, `orient`, `instructions_resolve`, `route_candidates`, `explain_summary`, `doctor`, `diagnose`, `trace_show`, `perf_request`, and `logs_tail` read-only runtime, owner, route, instruction, trace, perf, and log reads.
254
+ 3. Do not run CLI equivalents after a successful MCP result for the same read, and do not run broad source searches for ownership MCP already returned. Use CLI for fallback, `dev`, `build`, `check`, `verify`, migrations, E2E, and final terminal evidence.
255
+ 4. Use selected instruction previews for read-only discovery and diagnostics; read full files only before edits or git writes, when returned `fullRead`/`fullReadPolicy` requires it, or when the preview is insufficient.
256
+ 5. Use `proteum orient <query>` only when MCP is unavailable or terminal evidence is required.
257
+ 6. If machine MCP routing fails, run `proteum mcp status` and `proteum runtime status` from the intended app root. If you are in a monorepo wrapper, use the returned app candidates and exact next action. If no live session exists, use the exact Start Dev next action returned by runtime status so occupied router/HMR ports are avoided. Do not `curl` normal page routes to identify a port owner. If a live session exists but runtime/MCP is unreachable, stop the listed session file first, then start dev again.
258
+ 7. Use MCP `diagnose { projectId, path }` for the smallest trustworthy runtime surface before broad checks only after runtime health is reachable; use `proteum diagnose <path> --port <port>` as fallback or terminal evidence.
259
+ 8. Use MCP `perf_request { projectId, query }` for performance, CPU, SQL, render, cache, or connected-boundary questions; use `proteum perf request <requestId|path>` as fallback or terminal evidence.
260
+ 9. Use `proteum trace show <requestId> --events` only when compact diagnose, perf, trace, or MCP output says lower-level event detail is needed.
261
+ 10. Use `proteum explain --manifest` or read `./.proteum/manifest.json` only when compact `workflow_start`/`orient`/`explain`/MCP summary cannot answer the specific manifest question.
262
+ 11. Use `proteum verify browser` for browser-visible verification, or `proteum e2e --port <port>` for targeted/full Playwright suites. Keep auth sourced from Proteum session helpers.
263
+ 12. Run global checks second, not first. Unrelated diagnostics should remain visible but non-blocking during focused verification unless strict global mode is required.
264
+ 13. Open the profiler only when a human-readable view helps; it should agree with the CLI and MCP after refresh.