capable-kit 0.0.1-alpha.7 → 0.1.0-alpha.10

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 (104) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/README.md +6 -0
  3. package/dist/ai-sdk.d.mts +3 -3
  4. package/dist/ai-sdk.mjs +9 -7
  5. package/dist/ai-sdk.mjs.map +1 -1
  6. package/dist/app.d.mts +2 -2
  7. package/dist/app.mjs +2 -2
  8. package/dist/bin.mjs +12 -9
  9. package/dist/bin.mjs.map +1 -1
  10. package/dist/cli.d.mts +9 -1
  11. package/dist/cli.mjs +1 -1
  12. package/dist/core.d.mts +3 -3
  13. package/dist/core.mjs +1 -1
  14. package/dist/eve.d.mts +82 -5
  15. package/dist/eve.mjs +364 -23
  16. package/dist/eve.mjs.map +1 -1
  17. package/dist/http.d.mts +2 -2
  18. package/dist/http.mjs +2 -2
  19. package/dist/{index-Dbc4g9WM.d.mts → index-1A44jLuE.d.mts} +54 -16
  20. package/dist/{index-DwXlaTXI.d.mts → index-CHuCLJIs.d.mts} +20 -4
  21. package/dist/{index-D2CRRUzH.d.mts → index-D-NV4PiU.d.mts} +6 -5
  22. package/dist/{index-Be8-UVBC.d.mts → index-WiBWfyTn.d.mts} +66 -27
  23. package/dist/index.d.mts +4 -4
  24. package/dist/index.mjs +3 -3
  25. package/dist/mcp.d.mts +40 -5
  26. package/dist/mcp.mjs +1 -1
  27. package/dist/mount-BmLHp349.mjs +235 -0
  28. package/dist/mount-BmLHp349.mjs.map +1 -0
  29. package/dist/react-query.d.mts +2 -2
  30. package/dist/react-query.mjs +1 -1
  31. package/dist/react-query.mjs.map +1 -1
  32. package/dist/runtime-support.d.mts +1 -1
  33. package/dist/runtime-support.mjs +8 -8
  34. package/dist/runtime-support.mjs.map +1 -1
  35. package/dist/server.d.mts +1 -1
  36. package/dist/server.mjs +1 -1
  37. package/dist/{src-Db6-XSnU.mjs → src-3LE9S4QE.mjs} +67 -38
  38. package/dist/src-3LE9S4QE.mjs.map +1 -0
  39. package/dist/{src-DdV82An-.mjs → src-B2WeUwUT.mjs} +69 -34
  40. package/dist/src-B2WeUwUT.mjs.map +1 -0
  41. package/dist/{src-CDxL6w3d.mjs → src-C5jGDnuu.mjs} +9 -6
  42. package/dist/src-C5jGDnuu.mjs.map +1 -0
  43. package/dist/src-DePlcG_t.mjs +787 -0
  44. package/dist/src-DePlcG_t.mjs.map +1 -0
  45. package/dist/{src-BF70JLxI.mjs → src-_6OmFRYa.mjs} +185 -38
  46. package/dist/src-_6OmFRYa.mjs.map +1 -0
  47. package/dist/{subscription-Bq792Ad2.d.mts → subscription-DPdwovhw.d.mts} +2 -2
  48. package/dist/swr.d.mts +2 -2
  49. package/dist/swr.mjs +1 -1
  50. package/dist/swr.mjs.map +1 -1
  51. package/docs/CONTEXT.md +42 -21
  52. package/docs/README.md +3 -0
  53. package/docs/internal/README.md +3 -0
  54. package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +1 -1
  55. package/docs/internal/adr/0002-version-the-capable-value-codec.md +24 -0
  56. package/docs/internal/adr/0003-capability-reference-customization.md +68 -0
  57. package/docs/internal/architecture.md +64 -19
  58. package/docs/internal/capability-first-model.md +127 -18
  59. package/docs/internal/eve-recovery-validation.md +86 -0
  60. package/docs/internal/feedback/v-ray/README.md +258 -0
  61. package/docs/internal/feedback/v-ray/inference.mjs +43 -0
  62. package/docs/internal/feedback/v-ray/reproduce.mjs +36 -0
  63. package/docs/internal/implementation-friction.md +481 -1
  64. package/docs/internal/releases.md +79 -0
  65. package/docs/site/capable-orpc-and-trpc.mdx +5 -5
  66. package/docs/site/concepts/apps.mdx +17 -8
  67. package/docs/site/concepts/architecture.mdx +10 -2
  68. package/docs/site/concepts/capabilities.mdx +41 -4
  69. package/docs/site/concepts/errors.mdx +11 -1
  70. package/docs/site/concepts/presentations.mdx +20 -0
  71. package/docs/site/hosting/any-fetch-host.mdx +2 -2
  72. package/docs/site/hosting/next-js.mdx +38 -4
  73. package/docs/site/hosting/standalone-server.mdx +2 -2
  74. package/docs/site/introduction.mdx +9 -6
  75. package/docs/site/patterns/composition.mdx +159 -11
  76. package/docs/site/patterns/remote-apps.mdx +68 -10
  77. package/docs/site/patterns/subscriptions.mdx +79 -32
  78. package/docs/site/quickstart.mdx +19 -14
  79. package/docs/site/reference/packages-and-entry-points.mdx +52 -5
  80. package/docs/site/reference/surface-metadata.mdx +7 -2
  81. package/docs/site/reference/the-cap-cli.mdx +2 -2
  82. package/docs/site/surfaces/ai-sdk.mdx +3 -3
  83. package/docs/site/surfaces/cli.mdx +47 -3
  84. package/docs/site/surfaces/eve.mdx +67 -20
  85. package/docs/site/surfaces/mcp.mdx +73 -5
  86. package/docs/site/surfaces/react-query.mdx +3 -3
  87. package/docs/site/surfaces/swr.mdx +3 -3
  88. package/docs/site/surfaces/typescript.mdx +8 -8
  89. package/docs/site/surfaces.mdx +1 -1
  90. package/package-docs.mjs +3 -0
  91. package/package.json +11 -11
  92. package/src/bin.ts +0 -0
  93. package/src/index.test.ts +2 -1
  94. package/src/index.ts +6 -1
  95. package/src/mcp.ts +4 -0
  96. package/src/package.test.ts +9 -0
  97. package/dist/mount-xvMsjz1B.mjs +0 -178
  98. package/dist/mount-xvMsjz1B.mjs.map +0 -1
  99. package/dist/src-BF70JLxI.mjs.map +0 -1
  100. package/dist/src-C2MGIlT0.mjs +0 -464
  101. package/dist/src-C2MGIlT0.mjs.map +0 -1
  102. package/dist/src-CDxL6w3d.mjs.map +0 -1
  103. package/dist/src-Db6-XSnU.mjs.map +0 -1
  104. package/dist/src-DdV82An-.mjs.map +0 -1
@@ -18,7 +18,7 @@ An app definition gives a set of capabilities one shared structure. Nest them wi
18
18
  ```ts title="capable.app.ts"
19
19
  import { defineApp } from "capable-kit";
20
20
 
21
- export default defineApp({
21
+ const definition = defineApp({
22
22
  name: "Todos",
23
23
  capabilities: {
24
24
  system: { health },
@@ -29,6 +29,9 @@ export default defineApp({
29
29
  },
30
30
  },
31
31
  });
32
+
33
+ export type AppDefinition = typeof definition;
34
+ export default definition;
32
35
  ```
33
36
 
34
37
  This file is only the definition. It does not choose where the capabilities run or how people and agents reach them.
@@ -86,7 +89,7 @@ import definition from "./capable.app";
86
89
 
87
90
  export const server = createServer(definition, {
88
91
  mounts: [
89
- protocol({ path: "/_capable" }),
92
+ protocol(),
90
93
  http({ path: "/api" }),
91
94
  ],
92
95
  });
@@ -96,16 +99,16 @@ Here `http()` creates ordinary HTTP endpoints and `protocol()` exposes the proto
96
99
 
97
100
  ## Consume it over HTTP [#remote]
98
101
 
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.
102
+ In another process, create a remote app instead of a local one. Import its named definition type while the transport points to the `protocol()` mount.
100
103
 
101
104
  ```ts title="remote.ts"
102
105
  import { createRemoteApp } from "capable-kit";
103
106
  import { createHttpTransport } from "capable-kit/http";
104
- import type definition from "./capable.app";
107
+ import type { AppDefinition } from "./capable.app";
105
108
 
106
- export const app = createRemoteApp<typeof definition>(
109
+ export const app = createRemoteApp<AppDefinition>(
107
110
  createHttpTransport({
108
- url: "https://todos.example.com/_capable/",
111
+ url: "https://todos.example.com/~capable/",
109
112
  }),
110
113
  );
111
114
 
@@ -173,10 +176,16 @@ The provider runs per call, so it can read a request-scoped session, open a tran
173
176
 
174
177
  > **then is reserved**
175
178
  >
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`.
179
+ > Every traversable level of the tree is a lazy proxy. Capability leaves are callable unless they are subscription-only. Capable reserves `then` at every path so an app can never be mistaken for a promise by `await`.
177
180
 
178
181
  ## Give one branch a different policy [#decorate]
179
182
 
183
+ Use `defineApp({ capabilities, middleware: [authorizeCapability], errors: AccessErrors })`
184
+ for policy shared by the whole app. App middleware runs before group and capability
185
+ middleware for both local and remote invocations executed by that definition.
186
+ See [Capability middleware](/concepts/capabilities#middleware) for the identity
187
+ arguments and a complete example.
188
+
180
189
  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
190
 
182
191
  ```ts title="capable.app.ts"
@@ -212,6 +221,6 @@ Putting `requireUser` at the application boundary would also protect product sea
212
221
 
213
222
  ## The manifest [#manifest]
214
223
 
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.
224
+ 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
225
 
217
226
  </DocsPage>
@@ -35,7 +35,7 @@ defineApp() a named tree of capabilities
35
35
  | +-- { context } only when declared
36
36
  +-- createRemoteApp(transport) lazy remote placement
37
37
  |
38
- mergeApps() / selectApp() one typed app
38
+ composeApps() / selectApp() one typed app
39
39
  |
40
40
  +-- app.todos.list({}) direct call
41
41
  +-- createCli(app) commands
@@ -45,7 +45,7 @@ mergeApps() / selectApp() one typed app
45
45
  +-- createReactQuery(app) query keys and options
46
46
 
47
47
  defineApp() -> createServer(definition, { mounts }) -> fetch(request)
48
- protocol() /_capable/* manifest, call, subscribe
48
+ protocol() /~capable/* manifest, call, subscribe
49
49
  http() /api/* routes and /openapi.json
50
50
  mcp() /mcp Streamable HTTP tools
51
51
  ```
@@ -65,6 +65,14 @@ interface ApplicationTransport {
65
65
  output: unknown;
66
66
  presentation?: readonly PresentationPart[];
67
67
  }>;
68
+ subscribe(args: {
69
+ id: string;
70
+ input: unknown;
71
+ signal?: AbortSignal;
72
+ }): Promise<AsyncIterableIterator<{
73
+ output: unknown;
74
+ presentation?: readonly PresentationPart[];
75
+ }>>;
68
76
  }
69
77
 
70
78
  const app = createRemoteApp(transport);
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: "Capabilities"
3
- description: "A capability is one typed capability: input, output, errors, middleware, and a handler."
3
+ description: "Define input, output, errors, middleware, and a handler or subscriber."
4
4
  ---
5
5
 
6
6
  import { DocsPage, docMetadata } from "../../_components/docs-page";
@@ -145,6 +145,43 @@ export const listTodos = todoCapability({
145
145
 
146
146
  Put middleware on a `group()` when several capabilities in one branch share the policy and the rest of the app does not.
147
147
 
148
+ Put middleware on `defineApp()` to apply it to every capability in that app.
149
+ All three scopes receive a readonly `capability` descriptor containing the
150
+ authored `id` and optional `effect`, plus `mode: "call" | "subscribe"`.
151
+ The ID stays the same when a capability moves to another application path.
152
+ An omitted effect remains `undefined`.
153
+
154
+ ```ts title="capable.app.ts"
155
+ const AccessErrors = defineErrors({
156
+ FORBIDDEN: { status: 403, message: "Access denied" },
157
+ });
158
+
159
+ const definition = defineApp({
160
+ capabilities: { todos },
161
+ errors: AccessErrors,
162
+ middleware: [async ({ capability, mode, context, next }) => {
163
+ if (!await canCall(context.user, capability.id)) {
164
+ throw AccessErrors.FORBIDDEN();
165
+ }
166
+ console.info({ capabilityId: capability.id, mode });
167
+ return next();
168
+ }],
169
+ });
170
+ ```
171
+
172
+ App middleware uses the Context required by the app's capabilities. It does
173
+ not add or narrow Context fields. Declare capabilities separately, then
174
+ compose them into the app so TypeScript can infer that Context before typing
175
+ the middleware. Input is parsed before middleware runs; at app and group
176
+ scope it is typed as `unknown`, because each capability can have a different
177
+ input schema. Middleware receives identity, not the handler or internal
178
+ capability definition.
179
+
180
+ The order is app middleware, outer-to-inner group middleware, capability
181
+ middleware, then the handler. Return values unwind in reverse order.
182
+ Subscriptions use the same chain for the complete subscription lifetime.
183
+ Middleware does not see input-validation failures or Context-provider failures.
184
+
148
185
  ## Describe each surface with metadata [#metadata]
149
186
 
150
187
  App paths give every surface enough information to derive routes, commands, and tool names. Add `meta` when a surface needs details that the capability itself cannot express.
@@ -187,7 +224,7 @@ Only surfaces that need a presentation ask the runtime to produce it. The CLI re
187
224
  Once these pieces are present, every caller enters the same lifecycle. A surface only translates its own transport into an input object.
188
225
 
189
226
  1. **Parse input.** The input schema runs once.
190
- 2. **Run middleware.** Group middleware runs outermost, then capability middleware, in declaration order.
227
+ 2. **Run middleware.** App middleware runs outermost, followed by outer-to-inner group middleware and capability middleware, in declaration order.
191
228
  3. **Run the handler.** It receives `{ input, context, signal }`.
192
229
  4. **Normalize errors.** Declared errors keep their contract; unexpected failures become `INTERNAL_SERVER_ERROR`.
193
230
  5. **Validate output.** The optional output schema runs before the canonical result is returned.
@@ -206,13 +243,13 @@ const todo = await executeCapability(getTodo, {
206
243
  });
207
244
  ```
208
245
 
209
- Direct execution applies the capability's own validation, middleware, and declared errors. Middleware and errors contributed by a group only exist when the capability is executed through the app tree that contains it.
246
+ Direct execution applies the capability's own validation, middleware, and declared errors. Middleware and errors contributed by an app or group only exist when the capability is executed through the app tree that contains it. A handler that requires a user must check that requirement itself if it can also be executed directly; a check in group middleware does not narrow the handler's Context type.
210
247
 
211
248
  ## Put it all together [#complete]
212
249
 
213
250
  A capability can grow into the full declaration below, but only as each concern becomes real. The handler remains the centre; every other field either strengthens its contract, shares semantic policy, or helps a surface present it.
214
251
 
215
- Subscriptions are the remaining optional execution mode. A read capability can add `subscribe` beside its handler when it needs to emit replacement snapshots; see [Subscriptions](/patterns/subscriptions).
252
+ A read capability can add `subscribe` beside its handler to emit replacement snapshots, or define only `subscribe` to emit individual events such as logs. Event-only capabilities have no unary handler. See [Subscriptions](/patterns/subscriptions).
216
253
 
217
254
  ```ts title="capabilities.ts"
218
255
  import { capability, defineErrors, md } from "capable-kit";
@@ -88,6 +88,16 @@ const todos = group({
88
88
  });
89
89
  ```
90
90
 
91
- A group and a capability may not declare the same error code twice. The conflict is reported when the app definition is created, not at call time.
91
+ An app can contribute errors to every capability, including failures from app-wide middleware:
92
+
93
+ ```ts title="capable.app.ts"
94
+ const definition = defineApp({
95
+ capabilities: { todos },
96
+ errors: AccessErrors,
97
+ middleware: [authorizeCapability],
98
+ });
99
+ ```
100
+
101
+ An app, its nested groups, and a capability may not redeclare an inherited error code. The conflict is reported when the app definition is created, not at call time. Inherited errors appear on each affected capability in the manifest and OpenAPI. Standalone `executeCapability()` calls only use errors declared on that capability.
92
102
 
93
103
  </DocsPage>
@@ -34,6 +34,22 @@ export const getWeather = capability({
34
34
 
35
35
  Typed calls still receive `{ city, temperature }`. The string is only produced when a presentation-aware surface asks for it.
36
36
 
37
+ A typed named renderer can appear before or after `handler`:
38
+
39
+ ```ts
40
+ const presentWeather = (weather: { city: string; temperature: number }) =>
41
+ `${weather.city}: ${weather.temperature}°C`;
42
+
43
+ capability({
44
+ id: "weather.get",
45
+ toPresentation: presentWeather,
46
+ handler: () => ({ city: "Vienna", temperature: 24 }),
47
+ });
48
+ ```
49
+
50
+ When using an inline renderer with an inferred parameter, keep it after
51
+ `handler` so TypeScript can infer the result first.
52
+
37
53
  ## Compose richer output [#parts]
38
54
 
39
55
  `toPresentation` may also return one part or an ordered array of strings and parts. Import the builders from the same root entry point:
@@ -158,4 +174,8 @@ An empty array means that no presentation is available, so the surface falls bac
158
174
 
159
175
  This is a portable presentation model, not an MCP authoring API and not a UI component framework. It has no JSX, layout system, callbacks, or protocol-specific fields. New part types should be added only when several surfaces can give them a useful meaning.
160
176
 
177
+ ## Subscription presentations [#subscriptions]
178
+
179
+ `toPresentation` describes each validated subscription value using the same API as unary results. Event-only subscriptions append presentations in the CLI; replacement subscriptions redraw the current snapshot in terminals. Typed `subscribe()` consumers and CLI `--json` output use canonical values without generating presentations. An empty presentation selects canonical-output fallback, not suppression. See [Subscriptions](/patterns/subscriptions).
180
+
161
181
  </DocsPage>
@@ -43,7 +43,7 @@ app.get("/", (c) => c.html(renderProduct()));
43
43
 
44
44
  app.all("/api", (c) => server.fetch(c.req.raw));
45
45
  app.all("/api/*", (c) => server.fetch(c.req.raw));
46
- app.all("/_capable/*", (c) => server.fetch(c.req.raw));
46
+ app.all("/~capable/*", (c) => server.fetch(c.req.raw));
47
47
  app.all("/openapi.json", (c) => server.fetch(c.req.raw));
48
48
  app.all("/mcp", (c) => server.fetch(c.req.raw));
49
49
 
@@ -61,7 +61,7 @@ import server from "./capable.server";
61
61
  const app = new H3()
62
62
  .get("/", () => "Existing H3 application")
63
63
  .all("/api/**", (event) => server.fetch(event.req))
64
- .all("/_capable/**", (event) => server.fetch(event.req))
64
+ .all("/~capable/**", (event) => server.fetch(event.req))
65
65
  .all("/openapi.json", (event) => server.fetch(event.req));
66
66
 
67
67
  serve(app, { port: 3000 });
@@ -38,24 +38,58 @@ Route folders decide what is reachable. Export only the methods a path should an
38
38
  // app/api/[[...path]]/route.ts
39
39
  export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
40
40
 
41
- // app/%5Fcapable/[[...path]]/route.ts
42
- // %5F keeps Next from treating _capable as a private folder.
41
+ // app/~capable/[[...path]]/route.ts
43
42
  export { GET, POST } from "@/capable/server";
44
43
 
45
44
  // app/openapi.json/route.ts
46
45
  export { GET } from "@/capable/server";
46
+
47
+ // app/mcp/route.ts
48
+ export { DELETE, GET, OPTIONS, POST } from "@/capable/server";
47
49
  ```
48
50
 
49
51
  | Route | Serves |
50
52
  | --- | --- |
51
53
  | `/api/*` | Derived or authored HTTP routes |
52
- | `/_capable/*` | Capable transport for remote apps, the CLI, and React Query |
54
+ | `/~capable/*` | Capable transport for remote apps, the CLI, and React Query |
53
55
  | `/openapi.json` | Generated OpenAPI document |
54
56
  | `/mcp` | MCP, when the mcp() mount is included |
55
57
 
58
+ ## Keep server implementations out of client bundles [#client-boundary]
59
+
60
+ A browser caller needs the definition's type, not its runtime implementation.
61
+ Export a named type derived from the definition so the contract stays tied to
62
+ the source of truth:
63
+
64
+ ```ts title="capable.app.ts"
65
+ export type AppDefinition = typeof definition;
66
+ ```
67
+
68
+ Import only that named type in client code. Handlers, database clients, and
69
+ environment variables are erased from the client bundle.
70
+
71
+ ```tsx title="app/todos.tsx"
72
+ "use client";
73
+
74
+ import { createRemoteApp } from "capable-kit";
75
+ import { createHttpTransport } from "capable-kit/http";
76
+ import type { AppDefinition } from "@/capable.app";
77
+
78
+ const app = createRemoteApp<AppDefinition>(
79
+ createHttpTransport({
80
+ url: "/~capable/",
81
+ }),
82
+ );
83
+ ```
84
+
85
+ If both client and server code need a runtime value such as a status list,
86
+ place it in a dependency-free shared module. Do not import that value from a
87
+ capability module that also imports a database or reads server environment
88
+ variables.
89
+
56
90
  ## Server components and actions [#server-components]
57
91
 
58
- Inside the same deployment, do not go through HTTP. Create a local app and call it directly from a server component or a server action; the browser can still reach the same capabilities through `/_capable/*`.
92
+ Inside the same deployment, do not go through HTTP. Create a local app and call it directly from a server component or a server action; the browser can still reach the same capabilities through `/~capable/*`.
59
93
 
60
94
  ```ts title="app/todo-actions.ts"
61
95
  // app/todo-actions.ts
@@ -34,7 +34,7 @@ $ cap dev
34
34
  ◆ Todos 1.0.0
35
35
 
36
36
  Local http://localhost:3000
37
- Capable /_capable
37
+ Capable /~capable
38
38
  HTTP /api
39
39
  OpenAPI /openapi.json
40
40
  MCP /mcp
@@ -73,7 +73,7 @@ export default createServer(definition, {
73
73
  db,
74
74
  }),
75
75
  mounts: [
76
- protocol({ path: "/_capable" }),
76
+ protocol(),
77
77
  http({ path: "/api", requireExplicitRoutes: true }),
78
78
  mcp({ path: "/mcp" }),
79
79
  ],
@@ -36,13 +36,16 @@ An app gives capabilities a path: `todos.create`.
36
36
  import { defineApp } from "capable-kit";
37
37
  import { createTodo } from "./capabilities/create-todo";
38
38
 
39
- export default defineApp({
39
+ const definition = defineApp({
40
40
  name: "Todos",
41
41
  version: "1.0.0",
42
42
  capabilities: {
43
43
  todos: { create: createTodo },
44
44
  },
45
45
  });
46
+
47
+ export type AppDefinition = typeof definition;
48
+ export default definition;
46
49
  ```
47
50
 
48
51
  Add output schemas, errors, middleware, or surface metadata only when the app needs them.
@@ -74,7 +77,7 @@ $ cap dev
74
77
  ◆ Todos 1.0.0
75
78
 
76
79
  Local http://localhost:3000
77
- Capable /_capable
80
+ Capable /~capable
78
81
  HTTP /api
79
82
  OpenAPI /openapi.json
80
83
  MCP /mcp
@@ -101,7 +104,7 @@ export const { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } =
101
104
  createNextRouteHandlers(server.fetch);
102
105
  ```
103
106
 
104
- Re-export those handlers at the `/api`, `/_capable`, `/openapi.json`, and `/mcp` URLs. The [Next.js guide](/hosting/next) shows the complete route layout.
107
+ Re-export those handlers at the `/api`, `/~capable`, `/openapi.json`, and `/mcp` URLs. The [Next.js guide](/hosting/next) shows the complete route layout.
105
108
 
106
109
  </Tab>
107
110
  <Tab label="Any Fetch host">
@@ -214,12 +217,12 @@ import { createReactQuery } from "capable-kit/react-query";
214
217
  import { useMutation } from "@tanstack/react-query";
215
218
  import { createRemoteApp } from "capable-kit";
216
219
  import { createHttpTransport } from "capable-kit/http";
217
- import type definition from "./capable.app";
220
+ import type { AppDefinition } from "./capable.app";
218
221
 
219
222
  const query = createReactQuery(
220
- createRemoteApp<typeof definition>(
223
+ createRemoteApp<AppDefinition>(
221
224
  createHttpTransport({
222
- url: () => new URL("/_capable/", window.location.origin),
225
+ url: "/~capable/",
223
226
  }),
224
227
  ),
225
228
  );
@@ -18,12 +18,12 @@ The product API, on a server. `createRemoteApp()` takes the server definition as
18
18
  ```ts title="remote.ts"
19
19
  import { createRemoteApp } from "capable-kit";
20
20
  import { createHttpTransport } from "capable-kit/http";
21
- import type definition from "../server/capable.app";
21
+ import type { AppDefinition } from "../server/capable.app";
22
22
 
23
23
  // The product API, running on a server. Typed from the server
24
24
  // definition, no client generated. Talks to the Capable transport.
25
- export const remote = createRemoteApp<typeof definition>(
26
- createHttpTransport({ url: "https://todos.example.com/_capable/" }),
25
+ export const remote = createRemoteApp<AppDefinition>(
26
+ createHttpTransport({ url: "https://todos.example.com/~capable/" }),
27
27
  );
28
28
  ```
29
29
 
@@ -80,21 +80,26 @@ export const local = createApp(localDefinition, {
80
80
  });
81
81
  ```
82
82
 
83
- Both definitions compose named capabilities under the same `todos` path. When the apps are merged, those branches combine — `todos list` and `todos create` from the server, `todos import` from here.
83
+ Both definitions contribute named capabilities under the same `todos` path.
84
+ When the Apps are composed, those branches combine: `todos list` and
85
+ `todos create` run on the server, while `todos import` runs here.
84
86
 
85
- ## Merge them into one CLI [#merge]
87
+ ## Compose them into one CLI [#compose]
86
88
 
87
- `mergeApps()` combines the two apps into one. Calls dispatch by capability id to whichever app owns them. No proxy server, no logic moved — the import runs in this process, the creates run on the server.
89
+ `composeApps()` combines the two apps into one. App arguments contribute their
90
+ trees at the root, so the two `todos` branches become one. Calls dispatch by
91
+ capability id to whichever app owns them. No proxy server, no logic moved — the
92
+ import runs in this process, the creates run on the server.
88
93
 
89
94
  ```ts title="cli.ts"
90
- import { mergeApps } from "capable-kit";
95
+ import { composeApps } from "capable-kit";
91
96
  import { createCli } from "capable-kit/cli";
92
97
  import { remote } from "./remote";
93
98
  import { local } from "./local";
94
99
 
95
100
  // One command tree. Calls dispatch by capability id to whichever
96
101
  // app owns them — the server for list and create, this process for import.
97
- const app = mergeApps(remote, local);
102
+ const app = composeApps(remote, local);
98
103
 
99
104
  process.exit(
100
105
  await createCli(app, { invocationName: "mycli" }).run(process.argv.slice(2)),
@@ -118,15 +123,154 @@ mycli todos import ./todos.txt
118
123
  # { "imported": 2 }
119
124
  ```
120
125
 
121
- Path collisions, duplicate ids, and leaf/subtree conflicts fail when the merged manifest first resolves, not at call time. Namespaces belong in the app definitions, so the final command tree stays visible in source.
126
+ Path collisions, duplicate ids, and leaf/subtree conflicts fail when the
127
+ composed manifest first resolves, not at call time.
128
+
129
+ Object keys place an App or one of its executable subtrees beneath a
130
+ navigational branch. This is useful for external Apps that should keep a
131
+ visible namespace or contribute one existing group:
132
+
133
+ ```ts title="integrations.ts"
134
+ const app = composeApps(local, {
135
+ deepwiki,
136
+ tools: remote.admin,
137
+ integrations: {
138
+ linear,
139
+ github,
140
+ },
141
+ });
142
+
143
+ await app.deepwiki.search({ query: "routing" });
144
+ await app.integrations.linear.issue({ id: "CAP-1" });
145
+ ```
146
+
147
+ The object shape is the resulting callable tree. Namespacing changes application
148
+ paths, not Capability IDs or where execution happens. A direct call beneath one
149
+ namespace discovers only that branch; complete-manifest surfaces such as CLI
150
+ still discover and validate the entire composition.
151
+
152
+ The same App may deliberately appear at more than one path:
153
+
154
+ ```ts title="aliases.ts"
155
+ const app = composeApps({
156
+ internal: todos,
157
+ public: todos,
158
+ });
159
+ ```
160
+
161
+ Those paths are aliases backed by one terminal execution owner. Repeating the
162
+ same operation through a nested composition or another Remote App over the same
163
+ transport remains an alias. Independently bound local Apps and distinct
164
+ transports may not claim the same Capability ID, even when their manifests
165
+ happen to look identical.
122
166
 
123
167
  > **Placement stays explicit**
124
168
  >
125
- > Merging makes calling uniform, not location-transparent. Each capability still executes where it was created — behind the server's context and policy, or in this process. The CLI does not hide which is which; the source code does.
169
+ > Composition makes calling uniform, not location-transparent. Each capability
170
+ > still executes where it was created — behind the server's context and policy,
171
+ > or in this process. The CLI does not hide which is which; the source code does.
172
+
173
+ ## Curate individual capabilities [#references]
174
+
175
+ Use individual references when the local tree should choose exactly which
176
+ capabilities to expose and where they appear. Both local and remote references
177
+ retain their original execution binding:
178
+
179
+ ```ts title="radar-cli.ts"
180
+ import { composeApps, customize } from "capable-kit";
181
+ import { createCli } from "capable-kit/cli";
182
+
183
+ // desktop is a createRemoteApp<DesktopApp>(transport).
184
+ // local is a createApp(localDefinition), with its context already supplied.
185
+ const cliApp = composeApps({
186
+ stop: customize(desktop.plugins.stop, {
187
+ description: "Stop a running desktop instance.",
188
+ meta: { cli: { positional: ["instanceId"] } },
189
+ }),
190
+ debug: {
191
+ status: desktop.plugins.status,
192
+ continue: desktop.plugins.continue,
193
+ screenshot: local.screenshot,
194
+ },
195
+ });
196
+
197
+ await createCli(cliApp, { invocationName: "radar" }).run(process.argv.slice(2));
198
+ await cliApp.debug.status({ instanceId: "one" });
199
+ ```
200
+
201
+ References preserve input/output types, IDs, errors, cancellation, subscriptions,
202
+ and the backend's app/group middleware. Construction performs no discovery.
203
+ The local tree determines paths and CLI/MCP names. Authored `cli.name`,
204
+ `cli.command`, and `mcp.name` do not override an individually placed reference;
205
+ use `customize()` to set a name or command explicitly in the curated tree.
206
+ Other source metadata, such as positional arguments, remains available unless
207
+ its namespace is replaced. Source group display metadata is not copied when
208
+ moving a leaf. Place a whole App or executable Group subtree to retain its
209
+ existing internal navigation and presentation:
210
+
211
+ ```ts
212
+ const app = composeApps({
213
+ debug: desktop.plugins,
214
+ });
215
+ ```
216
+
217
+ The destination key names the placed Group, so this example creates `debug` even
218
+ if `plugins` has an authored CLI name. Its title, description, and navigation
219
+ inside the subtree remain authored. An absolute `meta.cli.command` on a child may
220
+ therefore place that command outside `debug`. Use individual references when
221
+ every CLI/MCP name should follow the destination tree.
222
+
223
+ `customize(reference, options)` accepts `title`, `description`, and `meta`.
224
+ CLI and MCP metadata are supported initially. Import the relevant surface entry
225
+ point to load its metadata types. It returns an immutable **composition entry**,
226
+ not a callable; invoke or subscribe through the resulting App. Bind local
227
+ capability definitions with `createApp()` first. Remote references do not belong
228
+ inside `defineApp()`.
229
+
230
+ Each supplied metadata namespace replaces that namespace, retaining other
231
+ namespaces. For example, overriding `meta.cli` does not replace `meta.mcp`.
232
+ Customizing an already customized entry, or a reference from a composed App,
233
+ applies outer overrides last. Title and description can be set to an empty
234
+ string to suppress authored text. Execution fields and output renderers cannot
235
+ be overridden.
236
+
237
+ The same source capability can appear at several paths with different display
238
+ settings. Repeating an identical placement is deduplicated; conflicting settings
239
+ at the same path fail. A manifest stores overrides separately from the source
240
+ contract, so nested composition, `selectApp()`, and remote discovery preserve
241
+ them. Policy callbacks still receive the original metadata. CLI, MCP, AI SDK,
242
+ and Eve honor customized descriptions; HTTP/OpenAPI continue to use authored
243
+ definitions. Older clients may ignore overrides or reject customized aliases;
244
+ use the updated client when re-exporting these Apps.
245
+
246
+ Composition cannot add middleware, errors, Context requirements, or another
247
+ execution lifecycle around a reference. Local workflow capabilities remain
248
+ normal capabilities: read stdin, save files, or orchestrate remote calls inside
249
+ their handlers. A local wrapper is a new operation with its own ID and input
250
+ schema, so forwarding a call inside a handler does not automatically forward its
251
+ remote error declarations or subscriptions.
252
+
253
+ ## Offline help [#offline-help]
254
+
255
+ Help requires runtime schemas; the TypeScript generic alone cannot supply them.
256
+ Bundle the manifest with the CLI and return it from the transport:
257
+
258
+ ```ts
259
+ const desktop = createRemoteApp<DesktopApp>({
260
+ manifest: async () => bundledManifest,
261
+ call: request => transport.call(request),
262
+ subscribe: request => transport.subscribe(request),
263
+ });
264
+ ```
265
+
266
+ Help then works without the backend. Execution still needs it. Keep the bundled
267
+ manifest aligned with the backend contract and the client types. A curated leaf
268
+ still resolves against its source App's manifest; it does not introduce a
269
+ per-capability discovery protocol.
126
270
 
127
271
  ## Narrow what a surface sees [#select]
128
272
 
129
- The same merged tree can feed more than one surface. Before handing it to an agent, narrow it with `selectApp()`. An omitted `include` means everything; `exclude` wins.
273
+ The same composed tree can feed more than one surface. Before handing it to an agent, narrow it with `selectApp()`. An omitted `include` means everything; `exclude` wins.
130
274
 
131
275
  ```ts title="agent-surface.ts"
132
276
  import { selectApp } from "capable-kit";
@@ -139,4 +283,8 @@ const agentApp = selectApp(app, {
139
283
  await createMcp(agentApp);
140
284
  ```
141
285
 
286
+ Every `include` and `exclude` path must exist in the resolved App manifest.
287
+ Unknown paths fail manifest resolution, which keeps stale policy from silently
288
+ changing the exposed surface.
289
+
142
290
  </DocsPage>