capable-kit 0.0.1-alpha.3 → 0.0.1-alpha.4

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 (57) hide show
  1. package/README.md +21 -3
  2. package/dist/bin.mjs +14 -13
  3. package/dist/bin.mjs.map +1 -1
  4. package/dist/http.d.mts +1 -1
  5. package/dist/http.mjs +1 -1
  6. package/dist/{index-AqKbVZ8Z.d.mts → index-DCrxWCTv.d.mts} +2 -2
  7. package/dist/{index-B2ru1zGQ.d.mts → index-DJ--zcWG.d.mts} +4 -4
  8. package/dist/mcp.d.mts +1 -1
  9. package/dist/mcp.mjs +1 -1
  10. package/dist/{mount--YHrgRHJ.mjs → mount-BEBJ2Tss.mjs} +13 -19
  11. package/dist/mount-BEBJ2Tss.mjs.map +1 -0
  12. package/dist/runtime-support.d.mts +1 -1
  13. package/dist/runtime-support.mjs +5 -5
  14. package/dist/runtime-support.mjs.map +1 -1
  15. package/dist/server.d.mts +2 -2
  16. package/dist/server.mjs +2 -2
  17. package/dist/{src-DtSY5fzY.mjs → src-ChDFqZaE.mjs} +6 -6
  18. package/dist/{src-DtSY5fzY.mjs.map → src-ChDFqZaE.mjs.map} +1 -1
  19. package/dist/{src-DX2xrplP.mjs → src-D9pLpfeO.mjs} +2 -2
  20. package/dist/src-D9pLpfeO.mjs.map +1 -0
  21. package/docs/CONTEXT.md +108 -0
  22. package/docs/README.md +28 -0
  23. package/docs/internal/README.md +16 -0
  24. package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +24 -0
  25. package/docs/internal/architecture.md +126 -0
  26. package/docs/internal/capability-first-model.md +154 -0
  27. package/docs/internal/implementation-friction.md +674 -0
  28. package/docs/internal/why-capable.md +94 -0
  29. package/docs/site/capable-orpc-and-trpc.mdx +133 -0
  30. package/docs/site/concepts/apps.mdx +217 -0
  31. package/docs/site/concepts/architecture.mdx +75 -0
  32. package/docs/site/concepts/capabilities.mdx +249 -0
  33. package/docs/site/concepts/errors.mdx +93 -0
  34. package/docs/site/hosting/any-fetch-host.mdx +74 -0
  35. package/docs/site/hosting/next-js.mdx +77 -0
  36. package/docs/site/hosting/standalone-server.mdx +94 -0
  37. package/docs/site/introduction.mdx +142 -0
  38. package/docs/site/patterns/composition.mdx +142 -0
  39. package/docs/site/patterns/remote-apps.mdx +117 -0
  40. package/docs/site/patterns/subscriptions.mdx +87 -0
  41. package/docs/site/quickstart.mdx +293 -0
  42. package/docs/site/reference/packages-and-entry-points.mdx +70 -0
  43. package/docs/site/reference/surface-metadata.mdx +84 -0
  44. package/docs/site/reference/the-cap-cli.mdx +81 -0
  45. package/docs/site/surfaces/ai-sdk.mdx +94 -0
  46. package/docs/site/surfaces/cli.mdx +138 -0
  47. package/docs/site/surfaces/eve.mdx +121 -0
  48. package/docs/site/surfaces/http-and-openapi.mdx +111 -0
  49. package/docs/site/surfaces/mcp.mdx +97 -0
  50. package/docs/site/surfaces/react-query.mdx +80 -0
  51. package/docs/site/surfaces/typescript.mdx +123 -0
  52. package/docs/site/surfaces.mdx +78 -0
  53. package/docs/site/why-capable.mdx +99 -0
  54. package/package.json +13 -3
  55. package/src/package.test.ts +101 -0
  56. package/dist/mount--YHrgRHJ.mjs.map +0 -1
  57. package/dist/src-DX2xrplP.mjs.map +0 -1
@@ -0,0 +1,94 @@
1
+ # Why Capable
2
+
3
+ > Internal memo. The public version of this argument is the "Why Capable" page in
4
+ > the docs site.
5
+
6
+ ## The problem
7
+
8
+ Building a capability for one agent is easy now. Keeping that capability out of
9
+ a single agent is not. "Agent-native" should mean any agent can use it — yours,
10
+ a customer's, a coworker's — and humans still need their own interface:
11
+ dashboards, charts, a place to explore the data directly.
12
+
13
+ Shipping one internal capability today usually means building five things and
14
+ wiring them together:
15
+
16
+ 1. An agent that acts on the data through tools.
17
+ 2. A web app where humans see and explore it.
18
+ 3. An HTTP/OpenAPI surface so other systems can reach it.
19
+ 4. A CLI for the team and for local agents.
20
+ 5. An MCP server so external agents can connect.
21
+
22
+ Those five overlap almost entirely. The same capability is written as a route,
23
+ then as a tool, then as a command, each slightly different. That overlap is
24
+ where drift lives: the CLI grows a flag the API lacks, the agent hits a wall
25
+ because its tool is not the one the web app uses, and a fix in one place stays
26
+ broken in the others. You pay for the overlap when you build it and again every
27
+ time it diverges.
28
+
29
+ ## Why one prompt does not get you there
30
+
31
+ Two assumptions sit under everything else, and they are stated on other pages:
32
+ today's applications have to exist on more than one surface, and agents are now
33
+ participants in the workflow rather than an add-on. A single UI is not a
34
+ finished product.
35
+
36
+ That is also the practical reason this cannot be one-shot. Ask an AI for a todo
37
+ app and you get a good Next.js app with no API in it: a server component reads
38
+ the database, a server action writes to it, the session is a cookie, the input
39
+ shape lives in a form. It is reachable from a browser and nowhere else.
40
+
41
+ So "add a CLI" is not one task. It is: extract an HTTP surface that did not
42
+ exist, add auth for a caller with no cookies, describe the input as a schema,
43
+ write a client, and only then write commands — restating that schema a second
44
+ time. A command framework covers the argument parsing and none of the rest.
45
+ Nothing about it is hard; all of it is redone whenever the capability changes.
46
+
47
+ With one definition, the CLI is a projection rather than a port — commands,
48
+ flags, help text, validation, and errors all come from the same capabilities the
49
+ HTTP surface exposes, and the same file runs locally or against a deployment.
50
+ Going from nothing to a working second surface stops being a project.
51
+
52
+ ## The gap
53
+
54
+ Vercel has Passport (internal auth for users) and Connect (third-party services
55
+ into yours). Both are about other people's data reaching you. The Connect
56
+ direction — collect integrations and expose them to your agents — is right, but
57
+ it has a hole: there is no guidance for adding *your own* capabilities to that
58
+ collection. You can plug in someone else's connector; you cannot extend it with
59
+ your own data without hand-building every surface.
60
+
61
+ The missing piece is an authoring layer that turns one capability into every
62
+ surface. We already know how to host applications, so this is the part worth
63
+ owning: a business's core capabilities — its own data plus its self-grown
64
+ integrations — surfaced everywhere from a single definition.
65
+
66
+ ## What Capable does about it
67
+
68
+ Define each typed capability once and derive HTTP/OpenAPI, typed JavaScript,
69
+ CLI, MCP, native agent tools, and Markdown projections from it.
70
+
71
+ - **The overlap is derived, not re-implemented.** Surface coverage becomes a
72
+ property of the framework rather than a recurring project.
73
+ - **Drift is structurally impossible.** The CLI cannot do something MCP cannot,
74
+ because they are the same Capability running the same validation, middleware,
75
+ and errors.
76
+ - **The core outlives its transports.** `@capable/core` owns authoring and
77
+ execution; HTTP, CLI, MCP, Eve, React Query, and platform hosts are adapters.
78
+
79
+ The premise, stated plainly: the durable asset is the capability layer, not the
80
+ agent wrapped around it. Agents are becoming a commodity on top. The layer every
81
+ agent, CLI, MCP consumer, and human app has to reach is the thing worth making
82
+ cheap to build.
83
+
84
+ ## Why now
85
+
86
+ - Building an agent is solved. Building what the agent uses is not.
87
+ - The identity and connect story exists for other people's data; the story for
88
+ your own is open.
89
+ - Multi-surface is the default expectation, and the second surface is exactly
90
+ where generation stalls.
91
+ - The five-surface overlap grows as MCP and local agent CLIs become table
92
+ stakes.
93
+ - Derivation-first is the only shape that makes drift a non-problem instead of a
94
+ recurring tax.
@@ -0,0 +1,133 @@
1
+ ---
2
+ title: "Capable, oRPC, and tRPC"
3
+ description: "Choose the right abstraction for a typed web app, a public API, or a capability that must work across human and agent surfaces."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../_components/docs-page";
7
+ import { Card, Cards } from "../_components/cards";
8
+
9
+ export const metadata = docMetadata("/comparison", frontmatter);
10
+
11
+ <DocsPage href="/comparison" frontmatter={frontmatter}>
12
+
13
+ Capable, oRPC, and tRPC all let you define typed server capabilities. The difference is not type safety. The difference is what each framework treats as the thing you are building.
14
+
15
+ ## The short answer [#short-answer]
16
+
17
+ <Cards>
18
+ <Card href="https://trpc.io" title="Choose tRPC">
19
+ Your only important boundary is a TypeScript frontend calling a TypeScript
20
+ backend, and you want a mature tool focused on that job.
21
+ </Card>
22
+ <Card href="https://orpc.dev" title="Choose oRPC">
23
+ You are building a typed API and want strong RPC and OpenAPI support,
24
+ contract-first options, and a mature protocol toolset.
25
+ </Card>
26
+ <Card href="/patterns/composition" title="Choose Capable">
27
+ You are building a full-stack TypeScript app and its capabilities must also
28
+ work through APIs, CLIs, agents, or local tools.
29
+ </Card>
30
+ </Cards>
31
+
32
+ > **Full-stack TypeScript is not the dividing line**
33
+ >
34
+ > All three can power a full-stack TypeScript application. Choose based on what else the backend must become: only a web client boundary, a deep API contract, or a capability shared across surfaces.
35
+
36
+ ## Capable is a full-stack TypeScript choice [#full-stack]
37
+
38
+ You do not give up the normal full-stack experience by choosing Capable. A browser gets a typed remote app, and the React Query adapter derives query keys, query functions, and mutations from it.
39
+
40
+ ```ts title="query.ts"
41
+ import { createRemoteApp } from "capable-kit";
42
+ import { createHttpTransport } from "capable-kit/http";
43
+ import { createReactQuery } from "@capable/react-query";
44
+ import type definition from "../capable.app";
45
+
46
+ const app = createRemoteApp<typeof definition>(
47
+ createHttpTransport({ url: "/_capable/" }),
48
+ );
49
+
50
+ export const query = createReactQuery(app);
51
+
52
+ // Fully typed input, output, query key, and query function.
53
+ useQuery(query.todos.list.queryOptions({}));
54
+ ```
55
+
56
+ If that web app later needs a CLI, MCP endpoint, or in-process agent, those surfaces use the same capabilities. You do not have to migrate away from a web-only router first.
57
+
58
+ ## A different center [#different-center]
59
+
60
+ | | tRPC | oRPC | Capable |
61
+ | --- | --- | --- | --- |
62
+ | The main thing | A typed RPC procedure | An API procedure or contract | A portable capability |
63
+ | Designed around | TypeScript client and server | RPC and OpenAPI | Full-stack capabilities across surfaces |
64
+ | Usually produces | A typed client | Typed clients and APIs | Calls, APIs, commands, and tools |
65
+ | Composition | Combine routers | Combine routers or contracts | Merge local and remote apps |
66
+
67
+ tRPC makes a network boundary feel like a function call. oRPC makes a typed API work well as both RPC and OpenAPI. Capable starts one level earlier: it describes a capability, then lets you decide where it runs and which surfaces expose it.
68
+
69
+ ## Why not an oRPC plugin? [#plugin]
70
+
71
+ It should be a plugin if all it does is turn an API router into two more interfaces.
72
+
73
+ ```ts title="a plugin-shaped idea"
74
+ // If this were the whole idea, Capable should be a plugin.
75
+ createCli(router);
76
+ await createMcp(router);
77
+ ```
78
+
79
+ Capable earns a separate abstraction only when an app remains useful before any HTTP or RPC server exists. A Capable app can contain local capabilities, remote capabilities discovered through a manifest, or both. Surfaces are added after that composition.
80
+
81
+ ```ts title="compose first, choose surfaces second"
82
+ import {
83
+ createApp,
84
+ createEveTools,
85
+ createRemoteApp,
86
+ mergeApps,
87
+ } from "capable-kit";
88
+
89
+ const supportApp = createRemoteApp<typeof support>(supportTransport);
90
+ const app = mergeApps(
91
+ supportApp,
92
+ createApp(localDefinition, {
93
+ context: createLocalContext,
94
+ }),
95
+ );
96
+
97
+ await app.support.tickets.list({});
98
+ await app.local.files.search({ query: "invoice" });
99
+
100
+ createCli(app);
101
+ createEveTools(app);
102
+ ```
103
+
104
+ Recreating this inside a plugin would require its own manifest, stable capability identity, local and remote runtime, merge rules, selection, and execution lifecycle. At that point the plugin contains another framework.
105
+
106
+ ## The line Capable has to hold [#invariant]
107
+
108
+ HTTP cannot become the privileged representation. It must remain one projection alongside CLI, MCP, Eve, and direct calls.
109
+
110
+ - **The capability owns meaning.** Input, output, errors, middleware, and the handler do not belong to a transport.
111
+ - **The app owns placement.** It decides whether a capability runs here or through a remote transport.
112
+ - **The adapter owns presentation.** Routes, flags, tool names, and query keys stay controllable without duplicating the handler.
113
+ - **The host owns deployment.** Next.js, Hono, H3, Bun, and the Capable CLI only decide how requests reach the app.
114
+
115
+ If Capable loses those boundaries and becomes a typed HTTP router with extra generators, an oRPC plugin would be the simpler design.
116
+
117
+ ## When another choice is simpler [#tradeoffs]
118
+
119
+ A full-stack TypeScript app is a good fit for Capable. The reason to pick something else is focus or maturity, not that Capable cannot serve the web application.
120
+
121
+ - Pick tRPC when the browser-to-server relationship is the whole problem and extra surface concepts would add no value.
122
+ - Pick oRPC when protocol depth is the main problem: contract-first authoring, rich API features, and a larger integration ecosystem.
123
+ - Pick either established project when its longer production history matters more than Capable's multi-surface model.
124
+
125
+ Pick Capable when you want the full-stack application and expect its capabilities to outgrow that one interface.
126
+
127
+ ## They can work together [#together]
128
+
129
+ Adopting Capable does not require replacing an existing tRPC or oRPC application. Start with the small set of capabilities that need a CLI or agent surface, and let their handlers call the same service layer as the existing API.
130
+
131
+ An oRPC adapter could also become a Capable surface in the future. That would reuse oRPC's protocol ecosystem without making API procedures the foundation of Capable's core.
132
+
133
+ </DocsPage>
@@ -0,0 +1,217 @@
1
+ ---
2
+ title: "Apps"
3
+ description: "Group capabilities into a named tree, then provide context to make it callable."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/concepts/apps", frontmatter);
9
+
10
+ <DocsPage href="/concepts/apps" frontmatter={frontmatter}>
11
+
12
+ An app definition is an immutable object tree whose leaves are capabilities. It describes structure only: no context, no transport, no placement.
13
+
14
+ ## Define the app [#define]
15
+
16
+ An app definition gives a set of capabilities one shared structure. Nest them with plain objects; their keys become stable paths that every consumer can understand.
17
+
18
+ ```ts title="capable.app.ts"
19
+ import { defineApp } from "capable-kit";
20
+
21
+ export default defineApp({
22
+ name: "Todos",
23
+ capabilities: {
24
+ system: { health },
25
+ todos: {
26
+ list: listTodos,
27
+ create: createTodo,
28
+ delete: deleteTodo,
29
+ },
30
+ },
31
+ });
32
+ ```
33
+
34
+ This file is only the definition. It does not choose where the capabilities run or how people and agents reach them.
35
+
36
+ ## Create a callable app [#executable]
37
+
38
+ Pass the definition to `createApp()` to create a local, typed consumer. Its object shape follows the definition, so the tree can be called directly.
39
+
40
+ ```ts title="app.ts"
41
+ import { createApp } from "capable-kit";
42
+ import definition from "./capable.app";
43
+
44
+ export const app = createApp(definition);
45
+
46
+ const todos = await app.todos.list({});
47
+ await app.todos.delete({ todoId: todos[0].id });
48
+ ```
49
+
50
+ These are ordinary in-process function calls. No request or transport is involved.
51
+
52
+ ## Turn the app into a CLI [#cli]
53
+
54
+ A surface consumes the callable app and presents the same capabilities in another form. The CLI turns paths into commands and schemas into arguments and flags.
55
+
56
+ ```ts title="cli.ts"
57
+ #!/usr/bin/env node
58
+ import { createCli } from "capable-kit/cli";
59
+ import { app } from "./app";
60
+
61
+ const cli = createCli(app, { invocationName: "todos" });
62
+
63
+ process.exit(await cli.run(process.argv.slice(2)));
64
+ ```
65
+
66
+ The definition’s `todos.list` path is now the command `todos list`. Validation, middleware, and declared errors still come from the original capabilities.
67
+
68
+ ## Turn the app into AI tools [#ai-tools]
69
+
70
+ The AI SDK adapter consumes the same app. It derives tool names, descriptions, and input schemas without another set of tool definitions.
71
+
72
+ ```ts title="tools.ts"
73
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
74
+ import { app } from "./app";
75
+
76
+ export const tools = await createAiSdkTools(app);
77
+ ```
78
+
79
+ ## Expose the definition over HTTP [#http]
80
+
81
+ A server consumes the definition with runtime options. Its mounts decide which network surfaces to expose; those choices stay out of `capable.app.ts`.
82
+
83
+ ```ts title="server.ts"
84
+ import { protocol, createServer, http } from "capable-kit/server";
85
+ import definition from "./capable.app";
86
+
87
+ export const server = createServer(definition, {
88
+ mounts: [
89
+ protocol({ path: "/_capable" }),
90
+ http({ path: "/api" }),
91
+ ],
92
+ });
93
+ ```
94
+
95
+ Here `http()` creates ordinary HTTP endpoints and `protocol()` exposes the protocol used by remote Capable apps.
96
+
97
+ ## Consume it over HTTP [#remote]
98
+
99
+ In another process, create a remote app instead of a local one. The definition is imported as a type, while the transport points to the `protocol()` mount.
100
+
101
+ ```ts title="remote.ts"
102
+ import { createRemoteApp } from "capable-kit";
103
+ import { createHttpTransport } from "capable-kit/http";
104
+ import type definition from "./capable.app";
105
+
106
+ export const app = createRemoteApp<typeof definition>(
107
+ createHttpTransport({
108
+ url: "https://todos.example.com/_capable/",
109
+ }),
110
+ );
111
+
112
+ const todos = await app.todos.list({});
113
+ ```
114
+
115
+ The call has the same typed shape as the local version, but execution, context, and policy stay on the server. The remote app discovers the manifest on first use and sends calls by capability id. See [Local and remote placement](/patterns/remote-apps#two-instantiations) for the full model, or [Surfaces](/surfaces) for every built-in consumer.
116
+
117
+ ## Path is navigation, id is identity [#identity]
118
+
119
+ Named objects give every capability one deterministic path. A capability object or id may appear only once in the tree. `todos.delete` is how humans and surfaces navigate. It can be renamed when the product changes. The capability id is what actually dispatches a call and what remote clients, manifests, and conflict detection use.
120
+
121
+ | | App path | Capability id |
122
+ | --- | --- | --- |
123
+ | Example | `todos.delete` | `delete-todo` |
124
+ | Set by | Position in the tree | The capability author |
125
+ | Used for | Calls, CLI commands, tool names, default routes | Dispatch, manifests, conflict detection |
126
+ | Safe to change | Yes, it is presentation | No, it is a contract |
127
+
128
+ Ids often mirror the path they started at. They simply are not required to, and moving a capability must not change one.
129
+
130
+ ## Add context only when a capability needs it [#context]
131
+
132
+ Context is opt-in. Declaring a context type on a capability makes the provider required when that definition is placed locally; otherwise, there is no context API to configure.
133
+
134
+ ```ts title="capabilities.ts"
135
+ import { capability } from "capable-kit";
136
+
137
+ export type TodoContext = {
138
+ todos: TodoStore;
139
+ userId: string;
140
+ };
141
+
142
+ const todoCapability = capability.withContext<TodoContext>();
143
+
144
+ export const listTodos = todoCapability({
145
+ id: "todos.list",
146
+ handler: ({ context }) => context.todos.list(context.userId),
147
+ });
148
+ ```
149
+
150
+ ```ts title="capable.app.ts"
151
+ import { defineApp } from "capable-kit";
152
+ import { listTodos } from "./capabilities";
153
+
154
+ export default defineApp({
155
+ capabilities: {
156
+ todos: {
157
+ list: listTodos,
158
+ },
159
+ },
160
+ });
161
+ ```
162
+
163
+ ```ts title="app.ts"
164
+ import { createApp } from "capable-kit";
165
+ import definition from "./capable.app";
166
+
167
+ const app = createApp(definition, {
168
+ context: () => ({ todos: store, userId: currentUser.id }),
169
+ });
170
+ ```
171
+
172
+ The provider runs per call, so it can read a request-scoped session, open a transaction, or return a shared singleton. Because the definition does not store it, the same definition can be instantiated differently in a server, a test, and a script.
173
+
174
+ > **then is reserved**
175
+ >
176
+ > Every level of the tree is a callable proxy. Capable reserves `then` at every path so an app can never be mistaken for a promise by `await`.
177
+
178
+ ## Give one branch a different policy [#decorate]
179
+
180
+ A `group()` is useful when one branch needs shared behaviour that would be wrong for the rest of the app. Here the catalog stays public, while everything under `account` requires an authenticated user. Define the decorated subtree separately so the app remains a simple composition.
181
+
182
+ ```ts title="capable.app.ts"
183
+ import { defineApp, group } from "capable-kit";
184
+
185
+ const account = group({
186
+ middleware: [requireUser],
187
+ errors: AuthErrors,
188
+ capabilities: {
189
+ profile: {
190
+ get: getProfile,
191
+ update: updateProfile,
192
+ },
193
+ orders: {
194
+ list: listOrders,
195
+ cancel: cancelOrder,
196
+ },
197
+ },
198
+ });
199
+
200
+ export default defineApp({
201
+ capabilities: {
202
+ catalog: {
203
+ search: searchProducts,
204
+ get: getProduct,
205
+ },
206
+ account,
207
+ },
208
+ });
209
+ ```
210
+
211
+ Putting `requireUser` at the application boundary would also protect product search. The group expresses the narrower policy once and contributes its authentication errors to only the profile and order capabilities.
212
+
213
+ ## The manifest [#manifest]
214
+
215
+ Every app can describe itself: the tree, ids, titles, effects, JSON Schemas, and declared errors. Surfaces are built from that manifest, which is why a [remote app](/patterns/remote-apps#boundary) can produce the same CLI as a local one. A server exposes it at `/_capable/manifest` when the `protocol()` mount is enabled.
216
+
217
+ </DocsPage>
@@ -0,0 +1,75 @@
1
+ ---
2
+ title: "Architecture"
3
+ description: "How the core, the app runtime, surface adapters, and platform hosts fit together."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/concepts/architecture", frontmatter);
9
+
10
+ <DocsPage href="/concepts/architecture" frontmatter={frontmatter}>
11
+
12
+ Capable is layered so that the part which defines meaning stays free of the parts that move bytes. Dependencies point inward: adapters know about the core, and the core knows nothing about them.
13
+
14
+ ## The layers [#layers]
15
+
16
+ | Layer | Package | Owns |
17
+ | --- | --- | --- |
18
+ | Semantics | `@capable/core` | Capabilities, groups, validation, middleware, errors, execution |
19
+ | Application | `@capable/app` | Callable apps, local and remote runtimes, manifests, merge, selection |
20
+ | Surfaces | `@capable/fetch, cli, mcp, ai-sdk, eve, react-query` | Projections that interpret the manifest and metadata |
21
+ | Hosts | `@capable/server, next, nitro-host` | Translating a platform request into a fetch request |
22
+
23
+ > **Invariant**
24
+ >
25
+ > `@capable/core` depends on no transport, host, HTTP, CLI, MCP, or AI SDK package. If a surface needs something from the core, the core grows an open extension point rather than a dependency.
26
+
27
+ ## How a definition reaches a caller [#flow]
28
+
29
+ ```ts title="flow"
30
+ capability() one typed capability
31
+ |
32
+ defineApp() a named tree of capabilities
33
+ |
34
+ +-- createApp(definition) local placement
35
+ | +-- { context } only when declared
36
+ +-- createRemoteApp(transport) lazy remote placement
37
+ |
38
+ mergeApps() / selectApp() one typed app
39
+ |
40
+ +-- app.todos.list({}) direct call
41
+ +-- createCli(app) commands
42
+ +-- await createMcp(app) agent tools
43
+ +-- await createAiSdkTools(app) AI SDK tools
44
+ +-- createEveTools(app) in-process agent tools
45
+ +-- createReactQuery(app) query keys and options
46
+
47
+ defineApp() -> createServer(definition, { mounts }) -> fetch(request)
48
+ protocol() /_capable/* manifest, call, subscribe
49
+ http() /api/* routes and /openapi.json
50
+ mcp() /mcp Streamable HTTP tools
51
+ ```
52
+
53
+ ## Lazy transport discovery [#transport]
54
+
55
+ A transport may perform I/O to discover its manifest, but `createRemoteApp()` does not perform that work during module evaluation. The first direct call or manifest-dependent projection discovers, validates, and caches it.
56
+
57
+ ```ts title="transport-and-runtime.ts"
58
+ interface ApplicationTransport {
59
+ manifest(): Promise<ApplicationManifest>;
60
+ call(args): Promise<{ output: unknown; markdown?: string }>;
61
+ subscribe(args): AsyncIterableIterator<{ output: unknown }>;
62
+ }
63
+
64
+ const app = createRemoteApp(transport);
65
+ // No I/O yet. Discovery happens on the first call or manifest projection.
66
+ const tools = await createAiSdkTools(app);
67
+ ```
68
+
69
+ Its HTTP encoding lives in `@capable/fetch` as server plumbing, separate from the authored HTTP API. Apps keep this runtime behind an internal symbol so capability names can never collide with `manifest` or `call`.
70
+
71
+ ## Open metadata, closed core [#metadata]
72
+
73
+ Surface metadata is declared by the surface package through module augmentation, which is how `meta.http`, `meta.cli`, `meta.mcp`, and `meta.aiSdk` become type-safe without the core knowing what HTTP, MCP, or the AI SDK is. The core preserves group ancestry and never merges metadata generically; each surface compiler decides what inheritance means for it.
74
+
75
+ </DocsPage>