@zerotal/arch 1.7.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 (160) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +67 -0
  4. package/api-surface.md +283 -0
  5. package/docs/about.md +676 -0
  6. package/docs/admin/actions.md +183 -0
  7. package/docs/admin/auth.md +89 -0
  8. package/docs/admin/dashboard.md +155 -0
  9. package/docs/admin/extending-ui.md +229 -0
  10. package/docs/admin/extending.md +205 -0
  11. package/docs/admin/forms.md +155 -0
  12. package/docs/admin/index.md +144 -0
  13. package/docs/admin/operations.md +224 -0
  14. package/docs/admin/references.md +174 -0
  15. package/docs/admin/resources.md +132 -0
  16. package/docs/admin/structure.md +158 -0
  17. package/docs/admin/tables.md +185 -0
  18. package/docs/admin/testing.md +138 -0
  19. package/docs/ai.md +373 -0
  20. package/docs/application.md +435 -0
  21. package/docs/arch.md +263 -0
  22. package/docs/assets.md +755 -0
  23. package/docs/audit.md +367 -0
  24. package/docs/authentication.md +1000 -0
  25. package/docs/authorization.md +529 -0
  26. package/docs/broadcasting/channels.md +170 -0
  27. package/docs/broadcasting/client.md +108 -0
  28. package/docs/broadcasting/events.md +190 -0
  29. package/docs/broadcasting/index.md +163 -0
  30. package/docs/broadcasting/references.md +84 -0
  31. package/docs/broadcasting/testing.md +132 -0
  32. package/docs/cache.md +387 -0
  33. package/docs/carbon.md +830 -0
  34. package/docs/changelog.md +465 -0
  35. package/docs/client/auth.md +113 -0
  36. package/docs/client/errors.md +139 -0
  37. package/docs/client/files.md +118 -0
  38. package/docs/client/index.md +128 -0
  39. package/docs/client/references.md +58 -0
  40. package/docs/client/requests.md +131 -0
  41. package/docs/client/resilience.md +141 -0
  42. package/docs/client/testing.md +146 -0
  43. package/docs/commands.md +450 -0
  44. package/docs/components.md +2427 -0
  45. package/docs/config-system.md +258 -0
  46. package/docs/container.md +596 -0
  47. package/docs/context.md +579 -0
  48. package/docs/contributing.md +164 -0
  49. package/docs/controllers.md +354 -0
  50. package/docs/conventions.md +466 -0
  51. package/docs/cookies.md +101 -0
  52. package/docs/csrf.md +206 -0
  53. package/docs/database.md +476 -0
  54. package/docs/deployment.md +434 -0
  55. package/docs/devtools.md +1013 -0
  56. package/docs/email-verification.md +320 -0
  57. package/docs/encryption.md +380 -0
  58. package/docs/errors.md +317 -0
  59. package/docs/events.md +420 -0
  60. package/docs/flow/components.md +846 -0
  61. package/docs/flow/decorators.md +458 -0
  62. package/docs/flow/events.md +420 -0
  63. package/docs/flow/forms.md +551 -0
  64. package/docs/flow/index.md +568 -0
  65. package/docs/flow/layouts.md +793 -0
  66. package/docs/flow/lifecycle.md +336 -0
  67. package/docs/flow/pagination.md +402 -0
  68. package/docs/flow/performance.md +262 -0
  69. package/docs/flow/references.md +317 -0
  70. package/docs/flow/routing.md +550 -0
  71. package/docs/flow/testing.md +447 -0
  72. package/docs/getting-started.md +286 -0
  73. package/docs/health.md +269 -0
  74. package/docs/helpers.md +423 -0
  75. package/docs/i18n.md +414 -0
  76. package/docs/index.md +65 -0
  77. package/docs/inertia/build.md +95 -0
  78. package/docs/inertia/devtools.md +197 -0
  79. package/docs/inertia/index.md +267 -0
  80. package/docs/inertia/middleware.md +81 -0
  81. package/docs/inertia/props.md +507 -0
  82. package/docs/inertia/references.md +144 -0
  83. package/docs/inertia/rendering.md +189 -0
  84. package/docs/inertia/ssr.md +102 -0
  85. package/docs/inspirations.md +257 -0
  86. package/docs/lifecycle.md +331 -0
  87. package/docs/lock.md +454 -0
  88. package/docs/logger.md +517 -0
  89. package/docs/media.md +582 -0
  90. package/docs/middleware.md +509 -0
  91. package/docs/migrations.md +529 -0
  92. package/docs/monitor.md +377 -0
  93. package/docs/notifications.md +848 -0
  94. package/docs/orm/casts.md +365 -0
  95. package/docs/orm/factories.md +231 -0
  96. package/docs/orm/index.md +663 -0
  97. package/docs/orm/lifecycle.md +421 -0
  98. package/docs/orm/queries.md +692 -0
  99. package/docs/orm/relationships.md +440 -0
  100. package/docs/orm/serialization.md +251 -0
  101. package/docs/package-development.md +536 -0
  102. package/docs/pagination.md +340 -0
  103. package/docs/password-reset.md +335 -0
  104. package/docs/providers.md +447 -0
  105. package/docs/query-builder.md +465 -0
  106. package/docs/queue.md +549 -0
  107. package/docs/rate-limiting.md +253 -0
  108. package/docs/responses.md +336 -0
  109. package/docs/roles-and-2fa.md +418 -0
  110. package/docs/routing.md +1008 -0
  111. package/docs/scaffolding.md +335 -0
  112. package/docs/scheduler.md +533 -0
  113. package/docs/seeding.md +229 -0
  114. package/docs/session.md +451 -0
  115. package/docs/social.md +524 -0
  116. package/docs/storage.md +622 -0
  117. package/docs/structure.md +230 -0
  118. package/docs/support-policy.md +114 -0
  119. package/docs/telemetry.md +505 -0
  120. package/docs/tenancy.md +608 -0
  121. package/docs/testing/browser.md +153 -0
  122. package/docs/testing/console.md +130 -0
  123. package/docs/testing/database.md +238 -0
  124. package/docs/testing/flow-browser.md +216 -0
  125. package/docs/testing/http.md +441 -0
  126. package/docs/testing/index.md +240 -0
  127. package/docs/testing/mocking.md +410 -0
  128. package/docs/upgrade.md +192 -0
  129. package/docs/validator.md +549 -0
  130. package/docs/view.md +453 -0
  131. package/package.json +60 -0
  132. package/src/bin/mcp.ts +73 -0
  133. package/src/config.ts +63 -0
  134. package/src/errors.ts +27 -0
  135. package/src/index.ts +56 -0
  136. package/src/install/ArchInstallCommand.ts +189 -0
  137. package/src/install/detect.ts +98 -0
  138. package/src/install/guidelines.ts +290 -0
  139. package/src/install/markers.ts +77 -0
  140. package/src/install/mcpConfig.ts +81 -0
  141. package/src/mcp/index.ts +27 -0
  142. package/src/mcp/jsonrpc.ts +133 -0
  143. package/src/mcp/server.ts +307 -0
  144. package/src/mcp/stdio.ts +111 -0
  145. package/src/mcp/types.ts +146 -0
  146. package/src/probe/ArchProbeCommand.ts +48 -0
  147. package/src/probe/sentinel.ts +13 -0
  148. package/src/probe/topics.ts +291 -0
  149. package/src/provider/ArchProvider.ts +101 -0
  150. package/src/tools/_probe.ts +164 -0
  151. package/src/tools/apiSurface.ts +241 -0
  152. package/src/tools/appInfo.ts +88 -0
  153. package/src/tools/baselines.ts +210 -0
  154. package/src/tools/context.ts +37 -0
  155. package/src/tools/doctor.ts +93 -0
  156. package/src/tools/index.ts +50 -0
  157. package/src/tools/logs.ts +265 -0
  158. package/src/tools/routes.ts +133 -0
  159. package/src/tools/schema.ts +119 -0
  160. package/src/tools/searchDocs.ts +345 -0
package/docs/arch.md ADDED
@@ -0,0 +1,263 @@
1
+ ---
2
+ title: Agent Surface
3
+ description: Give coding agents the framework's machine-readable truth — exact signatures, live routes and schema, version-matched docs, and a health check they can act on.
4
+ ---
5
+
6
+ # Agent Surface
7
+
8
+ `@zerotal/arch` is an MCP server that hands a coding agent what the framework already
9
+ knows about your app: the exact signature of every export, the routes it actually
10
+ registered, what the models declare, the documentation for the version you installed,
11
+ and a health check whose findings come with the fix attached.
12
+
13
+ The premise is that none of this needs to be inferred. Zerotal produces it mechanically
14
+ already — `api-surface.md` is regenerated and diffed by CI on every change, `zt doctor`
15
+ returns structured findings, the router knows its routes and the ORM knows its columns.
16
+ This package exposes it over the protocol agents speak.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ # in your project root
22
+ bun add -d @zerotal/arch
23
+ ```
24
+
25
+ Register the provider in `bootstrap/providers.ts`:
26
+
27
+ ```typescript
28
+ // bootstrap/providers.ts
29
+ import { ArchProvider } from "@zerotal/arch";
30
+
31
+ export default [DatabaseProvider, ArchProvider];
32
+ ```
33
+
34
+ Then wire it into whichever agents you use:
35
+
36
+ ```bash
37
+ # in your project root
38
+ bun zt arch:install
39
+ ```
40
+
41
+ That writes three things and restarts nothing:
42
+
43
+ | File | What it is |
44
+ | ----------- | ------------------------------------------------------------------------------------------------------------------ |
45
+ | `.mcp.json` | Registers the server so an agent can call its tools. A `.cursor/` or `.vscode/` directory gets its own config too. |
46
+ | `AGENTS.md` | The instructions, composed from the packages you actually installed. |
47
+ | `CLAUDE.md` | A one-line shim importing `AGENTS.md`. |
48
+
49
+ Restart your agent afterwards so it picks up the new server.
50
+
51
+ > **Note** — `ArchProvider` declares `environments: ["console"]`. It adds three commands
52
+ > and contributes nothing to a request, so a web process never loads it.
53
+
54
+ ## The tools
55
+
56
+ | Tool | Answers |
57
+ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
58
+ | `app_info` | Bun version, boot mode, registered providers, and the version and [maturity](/docs/support-policy#maturity-levels) of every installed `@zerotal` package. |
59
+ | `api_surface` | Every export of a package with its full TypeScript signature, class members included. Takes an optional `symbol` filter. |
60
+ | `search_docs` | These pages, for the version installed here. Returns the matching section, not the whole page. |
61
+ | `routes` | The registered routes with their names, controllers and middleware — including ones a provider added programmatically. |
62
+ | `schema` | What the models declare: tables, primary keys, timestamps, soft deletes, and every column with its flags. |
63
+ | `logs` / `last_error` | The app's own trail from `storage/logs`, already structured. `level` acts as a floor, so `warn` includes errors. |
64
+ | `baselines` | The quality ratchets this project records and the command that checks each. |
65
+ | `doctor` | Every health check, with the fix beside each finding. |
66
+
67
+ Every tool is read-only, and every one publishes an `outputSchema` and returns
68
+ `structuredContent` alongside its text.
69
+
70
+ ### The two that carry the most
71
+
72
+ **`api_surface`** is the reason the rest is worth building. Where a documentation search
73
+ can tell an agent that a fluent builder exists, this hands over the call it has to write
74
+ for `tsc` to accept it:
75
+
76
+ ```text
77
+ class Collection = {
78
+ new <T>(items?: T[]): Collection<T>
79
+ static make<T>(items: T[]): Collection<T>
80
+ filter(predicate: (item: T, index: number) => boolean): Collection<T>
81
+
82
+ }
83
+ ```
84
+
85
+ It reads the snapshot from `node_modules`, so the answer describes the version this app
86
+ runs rather than whatever is current.
87
+
88
+ **`doctor`** is the one to end a task with. Every finding carries a `fix`, which is what
89
+ makes "the app is healthy" a claim an agent can verify rather than assert.
90
+
91
+ ## Commands
92
+
93
+ | Command | What it does |
94
+ | --------------------------- | ------------------------------------------------------------------ |
95
+ | `bun zt arch:install` | Write the MCP config and the instruction files. |
96
+ | `bun zt arch:update` | The same command — re-running it _is_ the update. |
97
+ | `bun zt arch:probe <topic>` | Print one JSON report: `doctor`, `routes`, `schema` or `app-info`. |
98
+
99
+ Both writers take `--dry`, which prints what would change and writes nothing.
100
+
101
+ ### Re-running is safe
102
+
103
+ Generated content lives between markers:
104
+
105
+ ```markdown
106
+ <!-- zerotal:arch:start -->
107
+
108
+ …generated…
109
+ <!-- zerotal:arch:end -->
110
+ ```
111
+
112
+ `arch:update` replaces what is between them and nothing else, so anything you write
113
+ above, below, or after the block survives every framework upgrade. The MCP config is
114
+ merged the same way — other servers in the file are left exactly as they were.
115
+
116
+ A file whose markers are damaged, or a `.mcp.json` that is not valid JSON, is reported
117
+ and left completely alone. Guessing where a half-marked block was meant to end is how a
118
+ tool eats a paragraph nobody kept a copy of.
119
+
120
+ ## How it runs
121
+
122
+ The server is a bin, not a `zt` command, and it never boots your application:
123
+
124
+ ```json
125
+ // .mcp.json
126
+ {
127
+ "mcpServers": {
128
+ "zerotal": {
129
+ "command": "bun",
130
+ "args": ["node_modules/@zerotal/arch/src/bin/mcp.ts"]
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ Two reasons, and both matter.
137
+
138
+ **The protocol forbids noise.** MCP's stdio transport says a server must write nothing to
139
+ stdout that is not a protocol message, and a stray line does not degrade the session — it
140
+ desynchronises the client's parser and corrupts every message after it. A booted app
141
+ prints: banners, provider notices, warnings. A process that never boots one cannot.
142
+
143
+ **Answers have to be current.** The caller is an agent editing the code between calls. A
144
+ long-lived server holding a booted app would answer `routes` from the state it started
145
+ with. So the tools that need an app spawn one per call — `bun zt.ts arch:probe <topic>` —
146
+ and pay about a second for an answer that is true right now. There is no cache anywhere
147
+ in that path, deliberately.
148
+
149
+ The tools that read files rather than the app — `api_surface`, `search_docs`,
150
+ `baselines`, `logs` — need no app at all and work in a project that will not boot, which
151
+ is exactly when an agent needs them most.
152
+
153
+ ## Protocol support
154
+
155
+ The server speaks both eras of MCP and picks per request:
156
+
157
+ - **Modern** (`2026-07-28`) — stateless, with the protocol version in each request's
158
+ `_meta`. `server/discover` is implemented, which is also the probe a dual-era client
159
+ uses on stdio to decide it need not fall back.
160
+ - **Legacy** (`2025-11-25` and earlier) — the `initialize` handshake, which is still what
161
+ most shipping clients open with.
162
+
163
+ A client that opens with `initialize` gets legacy semantics; one that tags its requests
164
+ gets modern ones, including `resultType`, `ttlMs` and `cacheScope` on list results.
165
+
166
+ ## Configuration
167
+
168
+ Only the install side is configurable — the server reads no config, because it boots no
169
+ app to read one from.
170
+
171
+ ```typescript
172
+ // config/arch.ts
173
+ import { ArchConfig } from "@zerotal/arch";
174
+
175
+ export default ArchConfig({ claudeFile: false });
176
+ ```
177
+
178
+ | Field | Required | Default | Description |
179
+ | --------------- | -------- | ------------- | --------------------------------------------------- |
180
+ | `agentsFile` | no | `true` | Write `AGENTS.md`, the cross-tool instruction file. |
181
+ | `claudeFile` | no | `true` | Write a `CLAUDE.md` importing it. |
182
+ | `mcpConfig` | no | `true` | Write the MCP client configuration. |
183
+ | `mcpConfigPath` | no | `".mcp.json"` | Where that configuration goes. |
184
+ | `serverName` | no | `"zerotal"` | The key the server is registered under. |
185
+
186
+ ## Building on it
187
+
188
+ The transport is exported separately from the tools, on the `@zerotal/arch/mcp` subpath.
189
+ A tool is a plain object with a schema and a `run`, so you can serve your own alongside
190
+ these — or serve these over a transport of your own.
191
+
192
+ ```typescript
193
+ import { McpServer, serveStdio } from "@zerotal/arch/mcp";
194
+ import { archTools, vendoredDocsDir, spawnProbe } from "@zerotal/arch";
195
+
196
+ const tools = archTools({
197
+ root: process.cwd(),
198
+ docsDir: vendoredDocsDir(),
199
+ probe: spawnProbe(),
200
+ });
201
+
202
+ await serveStdio({
203
+ server: new McpServer({
204
+ identity: { name: "my-app", title: "My App", version: "1.0.0" },
205
+ tools: [...tools, myOwnTool],
206
+ }),
207
+ });
208
+ ```
209
+
210
+ `ArchTool`, `ToolOutcome` and `ToolContext` are the three types you need; `ProbeRunner`
211
+ is the seam that lets a tool's tests answer from a fixture instead of booting anything.
212
+
213
+ ## References
214
+
215
+ | Member | Signature | Description |
216
+ | ----------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------- |
217
+ | `ArchProvider` | `class ArchProvider extends ServiceProvider` | Registers `arch:install`, `arch:update` and `arch:probe`, and one doctor check. |
218
+ | `ArchConfig` | `ArchConfig(options?: Partial<ArchConfigShape>): ArchConfigShape` | Config factory for the install side. |
219
+ | `ArchConfigShape` | `interface ArchConfigShape` | What `arch:install` writes, and under what name. |
220
+ | `ArchError` | `class ArchError extends ZerotalError` | Base for this package's errors. |
221
+ | `NoProjectRootError` | `class NoProjectRootError extends ArchError` | Thrown when `arch:install` runs outside a project. |
222
+ | `archTools` | `archTools(ctx: ToolContext): ArchTool[]` | Every tool, in listing order. |
223
+ | `ToolContext` | `interface ToolContext` | The project root, the docs corpus, and a `ProbeRunner`. |
224
+ | `vendoredDocsDir` | `vendoredDocsDir(): string` | Path to the documentation shipped inside this package. |
225
+ | `spawnProbe` | `spawnProbe(options?: SpawnProbeOptions): ProbeRunner` | The runner that spawns `zt arch:probe`. |
226
+ | `findApp` | `findApp(start: string): Promise<{ root, entry } \| undefined>` | The nearest enclosing Zerotal app. |
227
+ | `ProbeRunner` | `interface ProbeRunner` | The seam a tool reaches a booted app through. |
228
+ | `ProbeResult` | `type ProbeResult` | A probe's answer, or the reason there is none. |
229
+ | `SpawnProbeOptions` | `interface SpawnProbeOptions` | `cwd` and `timeoutMs` for the runner. |
230
+ | `probe` | `probe(topic: ProbeTopic, app: Application): Promise<unknown>` | Run one topic against a booted app. |
231
+ | `PROBE_TOPICS` | `readonly ProbeTopic[]` | The topics `arch:probe` accepts. |
232
+ | `ProbeTopic` | `type ProbeTopic` | `"doctor" \| "routes" \| "schema" \| "app-info"`. |
233
+ | `isProbeTopic` | `isProbeTopic(value: string): value is ProbeTopic` | Narrow a string to a topic. |
234
+ | `DoctorReport` / `DoctorFinding` | `interface` | What the `doctor` tool returns. |
235
+ | `RouteReport` / `RouteEntry` | `interface` | What the `routes` tool returns. |
236
+ | `SchemaReport` / `SchemaModel` / `SchemaColumn` | `interface` | What the `schema` tool returns. |
237
+ | `AppInfo` / `InstalledPackage` | `interface` | What the `app_info` tool returns. |
238
+ | `detectAgents` | `detectAgents(root: string): Promise<Detected>` | Which agents a project is set up for. |
239
+ | `Detected` / `McpTarget` | `interface` | The detection result and one client's config location. |
240
+ | `applyMcpConfig` | `applyMcpConfig(existing, name, target): ConfigOutcome` | Merge this server into an MCP config. |
241
+ | `ConfigOutcome` | `type ConfigOutcome` | Created, updated, unchanged, or a conflict. |
242
+ | `serverEntry` | `serverEntry(): Record<string, unknown>` | The command and args a client is given. |
243
+ | `SERVER_ENTRY_PATH` | `const SERVER_ENTRY_PATH: string` | Where the server lives in `node_modules`. |
244
+ | `applyBlock` | `applyBlock(existing, content, preamble?): BlockOutcome` | Replace a managed block, preserving everything else. |
245
+ | `BlockOutcome` | `type BlockOutcome` | The result of a block write. |
246
+ | `fence` | `fence(content: string): string` | Wrap content in its markers. |
247
+ | `BLOCK_START` / `BLOCK_END` | `const` | The markers themselves. |
248
+ | `buildGuidelines` | `buildGuidelines(options: GuidelineOptions): string` | The generated `AGENTS.md` body. |
249
+ | `GuidelineOptions` | `interface GuidelineOptions` | Installed packages and the server name. |
250
+ | `agentsPreamble` | `agentsPreamble(): string` | The prose written above the block on creation. |
251
+ | `claudeShim` | `claudeShim(): string` | The `CLAUDE.md` that imports `AGENTS.md`. |
252
+
253
+ The transport is on the `@zerotal/arch/mcp` subpath: `McpServer`, `McpServerOptions`,
254
+ `serveStdio`, `StdioOptions`, `decodeFrame`, `encodeFrame`, `DecodedFrame`, `success`,
255
+ `failure`, `ArchTool`, `ToolOutcome`, `JsonSchema`, `ServerIdentity`, `Era`,
256
+ `JsonRpcRequest`, `JsonRpcResponse`, `JsonRpcSuccess`, `JsonRpcFailure`, `JsonRpcId`,
257
+ `RpcError`, `Meta`, `MODERN_VERSION`, `LEGACY_VERSIONS` and `SUPPORTED_VERSIONS`.
258
+
259
+ ## Next steps
260
+
261
+ - [Commands](/docs/commands) — the full `bun zt` vocabulary an agent is told about.
262
+ - [Package Development](/docs/package-development) — contributing doctor checks of your own.
263
+ - [Support policy](/docs/support-policy#maturity-levels) — what `beta` promises.