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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +21 -3
  2. package/dist/ai-sdk.d.mts +2 -2
  3. package/dist/ai-sdk.mjs +1 -1
  4. package/dist/app.d.mts +1 -1
  5. package/dist/app.mjs +1 -1
  6. package/dist/bin.mjs +17 -16
  7. package/dist/bin.mjs.map +1 -1
  8. package/dist/cli.d.mts +1 -1
  9. package/dist/cli.mjs +1 -1
  10. package/dist/core.d.mts +3 -3
  11. package/dist/core.mjs +2 -2
  12. package/dist/eve.d.mts +1 -1
  13. package/dist/eve.mjs +1 -1
  14. package/dist/http.d.mts +1 -1
  15. package/dist/http.mjs +1 -1
  16. package/dist/{index-BB5ogMv-.d.mts → index-Be8-UVBC.d.mts} +49 -8
  17. package/dist/{index-B2ru1zGQ.d.mts → index-D2CRRUzH.d.mts} +6 -6
  18. package/dist/{index-B_I9n6gN.d.mts → index-Dbc4g9WM.d.mts} +4 -3
  19. package/dist/{index-AqKbVZ8Z.d.mts → index-DwXlaTXI.d.mts} +4 -4
  20. package/dist/index.d.mts +4 -4
  21. package/dist/index.mjs +3 -3
  22. package/dist/mcp.d.mts +2 -2
  23. package/dist/mcp.mjs +1 -1
  24. package/dist/{mount--YHrgRHJ.mjs → mount-xvMsjz1B.mjs} +65 -27
  25. package/dist/mount-xvMsjz1B.mjs.map +1 -0
  26. package/dist/runtime-support.d.mts +1 -1
  27. package/dist/runtime-support.mjs +6 -6
  28. package/dist/runtime-support.mjs.map +1 -1
  29. package/dist/server.d.mts +2 -2
  30. package/dist/server.mjs +2 -2
  31. package/dist/{src-DX2xrplP.mjs → src-BF70JLxI.mjs} +24 -13
  32. package/dist/src-BF70JLxI.mjs.map +1 -0
  33. package/dist/{src-3UaBqI8H.mjs → src-C2MGIlT0.mjs} +17 -18
  34. package/dist/src-C2MGIlT0.mjs.map +1 -0
  35. package/dist/{src-DtSY5fzY.mjs → src-CDxL6w3d.mjs} +7 -7
  36. package/dist/{src-DtSY5fzY.mjs.map → src-CDxL6w3d.mjs.map} +1 -1
  37. package/dist/{src-BjBxOv7x.mjs → src-Db6-XSnU.mjs} +20 -12
  38. package/dist/src-Db6-XSnU.mjs.map +1 -0
  39. package/dist/{src-B53ZbNtC.mjs → src-DdV82An-.mjs} +137 -3
  40. package/dist/src-DdV82An-.mjs.map +1 -0
  41. package/dist/{subscription-McaLyHM2.d.mts → subscription-Bq792Ad2.d.mts} +2 -2
  42. package/docs/CONTEXT.md +113 -0
  43. package/docs/README.md +28 -0
  44. package/docs/internal/README.md +16 -0
  45. package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +24 -0
  46. package/docs/internal/architecture.md +134 -0
  47. package/docs/internal/capability-first-model.md +160 -0
  48. package/docs/internal/implementation-friction.md +705 -0
  49. package/docs/internal/why-capable.md +94 -0
  50. package/docs/site/capable-orpc-and-trpc.mdx +133 -0
  51. package/docs/site/concepts/apps.mdx +217 -0
  52. package/docs/site/concepts/architecture.mdx +83 -0
  53. package/docs/site/concepts/capabilities.mdx +249 -0
  54. package/docs/site/concepts/errors.mdx +93 -0
  55. package/docs/site/concepts/presentations.mdx +161 -0
  56. package/docs/site/hosting/any-fetch-host.mdx +74 -0
  57. package/docs/site/hosting/next-js.mdx +77 -0
  58. package/docs/site/hosting/standalone-server.mdx +94 -0
  59. package/docs/site/introduction.mdx +259 -0
  60. package/docs/site/patterns/composition.mdx +142 -0
  61. package/docs/site/patterns/remote-apps.mdx +117 -0
  62. package/docs/site/patterns/subscriptions.mdx +87 -0
  63. package/docs/site/quickstart.mdx +386 -0
  64. package/docs/site/reference/packages-and-entry-points.mdx +72 -0
  65. package/docs/site/reference/surface-metadata.mdx +84 -0
  66. package/docs/site/reference/the-cap-cli.mdx +81 -0
  67. package/docs/site/surfaces/ai-sdk.mdx +94 -0
  68. package/docs/site/surfaces/cli.mdx +138 -0
  69. package/docs/site/surfaces/eve.mdx +121 -0
  70. package/docs/site/surfaces/http-and-openapi.mdx +111 -0
  71. package/docs/site/surfaces/mcp.mdx +110 -0
  72. package/docs/site/surfaces/react-query.mdx +80 -0
  73. package/docs/site/surfaces/typescript.mdx +123 -0
  74. package/docs/site/surfaces.mdx +78 -0
  75. package/docs/site/why-capable.mdx +99 -0
  76. package/package.json +13 -3
  77. package/src/index.test.ts +1 -0
  78. package/src/index.ts +5 -1
  79. package/src/package.test.ts +102 -0
  80. package/dist/mount--YHrgRHJ.mjs.map +0 -1
  81. package/dist/src-3UaBqI8H.mjs.map +0 -1
  82. package/dist/src-B53ZbNtC.mjs.map +0 -1
  83. package/dist/src-BjBxOv7x.mjs.map +0 -1
  84. package/dist/src-DX2xrplP.mjs.map +0 -1
@@ -0,0 +1,87 @@
1
+ ---
2
+ title: "Subscriptions"
3
+ description: "Give a read capability a second execution mode that emits complete replacements."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/patterns/subscriptions", frontmatter);
9
+
10
+ <DocsPage href="/patterns/subscriptions" frontmatter={frontmatter}>
11
+
12
+ A `read` capability can define `subscribe` beside its `handler`. Both modes share one id, input, output, error set, middleware, placement, and metadata — so a subscription is not a second capability, it is a second way to execute the same one.
13
+
14
+ ## Add a subscriber [#define]
15
+
16
+ `watchQuery()` is the common shape: read a snapshot, then re-read it whenever an invalidation source signals a change. It pulls the invalidation iterator before reading the first snapshot, so a change that races with the read produces another snapshot instead of being lost.
17
+
18
+ ```ts title="capabilities.ts"
19
+ import { capability, watchQuery } from "capable-kit";
20
+ import { z } from "zod";
21
+
22
+ const todoCapability = capability.withContext<TodoContext>();
23
+
24
+ export const listTodos = todoCapability({
25
+ id: "todos.list",
26
+ effect: "read",
27
+ output: z.array(Todo),
28
+ handler: ({ context }) => context.todos.list(),
29
+ subscribe: ({ context, signal }) =>
30
+ watchQuery({
31
+ snapshot: () => context.todos.list(),
32
+ invalidations: () => context.todos.changes({ signal }),
33
+ signal,
34
+ }),
35
+ });
36
+ ```
37
+
38
+ An async generator works too when there is nothing to watch:
39
+
40
+ ```ts title="capabilities.ts"
41
+ subscribe: async function* ({ signal }) {
42
+ while (!signal.aborted) {
43
+ yield { now: new Date().toISOString() };
44
+ await wait(1000, signal);
45
+ }
46
+ },
47
+ ```
48
+
49
+ ## Consume it [#consume]
50
+
51
+ `subscribe()` takes a capability call from an app, which keeps app navigation free of extra method names. It works the same against local, remote, merged, and selected apps.
52
+
53
+ ```ts title="watch.ts"
54
+ import { subscribe } from "capable-kit";
55
+
56
+ const updates = subscribe(app.todos.list, {}, { signal });
57
+
58
+ for await (const todos of updates) {
59
+ render(todos); // a complete, validated list every time
60
+ }
61
+ ```
62
+
63
+ Input is parsed once. Every emitted item is validated against the output schema, middleware encloses the whole iterator lifetime, and cancelling the signal aborts the subscriber before cleanup runs.
64
+
65
+ ## Over the wire [#transport]
66
+
67
+ The Capable transport encodes subscriptions as server-sent events at `POST /_capable/subscribe/:id`. Errors raised before the first replacement are ordinary HTTP errors; a terminal error after streaming began arrives as a typed SSE error frame.
68
+
69
+ ```sh title="terminal"
70
+ curl -N -X POST \
71
+ -H 'accept: text/event-stream' \
72
+ -H 'content-type: application/json' \
73
+ --data '{"input":{}}' \
74
+ http://localhost:3000/_capable/subscribe/todos.list
75
+ ```
76
+
77
+ The CLI exposes the same mode with `--watch`, and [React Query](/surfaces/react-query) exposes it as `liveQueryOptions()`. MCP always calls the unary snapshot.
78
+
79
+ ## What this is not [#scope]
80
+
81
+ > **Deliberately out of scope**
82
+ >
83
+ > Replacement subscriptions are not an event system. There are no patches, no domain events, no buffering, no replay, no resumption, no delivery guarantees, and no reconnection policy. Every item is a complete replacement of the canonical output.
84
+
85
+ That constraint is what keeps one capability honest across surfaces: a consumer that can render the unary result can render every update without additional state.
86
+
87
+ </DocsPage>
@@ -0,0 +1,386 @@
1
+ ---
2
+ title: "Quickstart"
3
+ description: "Install Capable, write one capability, run it locally, and deploy it."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../_components/docs-page";
7
+ import { Tab, Tabs } from "../_components/tabs";
8
+
9
+ export const metadata = docMetadata("/quickstart", frontmatter);
10
+
11
+ <DocsPage href="/quickstart" frontmatter={frontmatter}>
12
+
13
+ Capable works two ways: as its own service, or embedded in an app you already have. Both start from the same capability. Pick the path that matches your project.
14
+
15
+ <Tabs id="quickstart-path" label="Choose a setup path">
16
+ <Tab label="Standalone service">
17
+
18
+ 1. ### Install Capable
19
+
20
+ The `capable` package includes the runtime and the `capable` command for development, builds, and derived CLI access. Zod is the schema authoring library in this example; Capable consumes its Standard Schema and Standard JSON Schema interfaces.
21
+
22
+ ```sh title="terminal"
23
+ pnpm add capable-kit zod
24
+ ```
25
+
26
+ 2. ### Create capable.app.ts
27
+
28
+ The toolchain discovers `capable.app.ts` in the project root. Export an app definition as the default export.
29
+
30
+ ```ts title="capable.app.ts"
31
+ import { defineApp, capability } from "capable-kit";
32
+ import { z } from "zod";
33
+
34
+ const listTodos = capability({
35
+ id: "todos.list",
36
+ // Opt in to GET and read-only tool hints.
37
+ effect: "read",
38
+ handler: () => [{ id: "1", title: "Read the docs" }],
39
+ });
40
+
41
+ const createTodo = capability({
42
+ id: "todos.create",
43
+ input: z.object({ title: z.string().min(1) }),
44
+ handler: ({ input }) => ({ id: "1", title: input.title }),
45
+ });
46
+
47
+ export default defineApp({
48
+ name: "Todos",
49
+ version: "1.0.0",
50
+ capabilities: {
51
+ todos: { list: listTodos, create: createTodo },
52
+ },
53
+ });
54
+ ```
55
+
56
+ > This starts with the minimum useful contract. The list Capability declares `effect: "read"` only because HTTP and tool projections need its read-only intent. Add an `output` schema when you need runtime output validation or a portable output contract.
57
+
58
+ 3. ### Start the dev server
59
+
60
+ `cap dev` watches the dependency graph, validates the manifest, and serves every derived surface. The root is a development-only index of the capabilities.
61
+
62
+ ```sh title="terminal"
63
+ $ cap dev
64
+
65
+ ◆ Todos 1.0.0
66
+
67
+ Local http://localhost:3000
68
+ Capable /_capable
69
+ HTTP /api
70
+ OpenAPI /openapi.json
71
+ MCP /mcp
72
+
73
+ ✓ 2 capabilities ready, watching for changes
74
+ ```
75
+
76
+ 4. ### Call the capabilities
77
+
78
+ The CLI reads the same tree, so `todos.create` becomes `todos create`. The HTTP routes default to the app path, and `effect: "read"` makes `todos.list` a `GET`. Everything else is a `POST`.
79
+
80
+ ```sh title="terminal"
81
+ # The capabilities as commands
82
+ cap cli todos create "Read the quickstart"
83
+ cap cli todos list
84
+
85
+ # The same capabilities as derived HTTP routes
86
+ curl http://localhost:3000/api/todos/list
87
+ curl -X POST http://localhost:3000/api/todos/create \
88
+ -H 'content-type: application/json' \
89
+ -d '{"title":"Read the quickstart"}'
90
+ ```
91
+
92
+ 5. ### Call it in-process
93
+
94
+ The app is an ordinary typed object. `createApp()` executes capabilities in this process — useful from a script, a job, or a test — with the same validation, middleware, and errors the HTTP routes get.
95
+
96
+ ```ts title="script.ts"
97
+ import { createApp } from "capable-kit";
98
+ import definition from "./capable.app";
99
+
100
+ // In-process execution: no server, no network.
101
+ const app = createApp(definition);
102
+
103
+ const todo = await app.todos.create({ title: "Read the quickstart" });
104
+ const todos = await app.todos.list({});
105
+ ```
106
+
107
+ 6. ### Hand the same app to a surface
108
+
109
+ A surface is just a function that takes an app. Nothing about the capability changes — `createAiSdkTools()` reads the same tree, the same schemas, and the same `effect` metadata that HTTP and the CLI read, and returns an AI SDK v7 tool set.
110
+
111
+ ```ts title="agent.ts"
112
+ import { generateText, stepCountIs } from "ai";
113
+ import { createApp } from "capable-kit";
114
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
115
+ import definition from "./capable.app";
116
+
117
+ export const app = createApp(definition);
118
+
119
+ // todos.list -> tool "todos__list", todos.create -> tool "todos__create".
120
+ // Input schemas, output schemas, and execution come from the capabilities.
121
+ const tools = await createAiSdkTools(app);
122
+
123
+ const result = await generateText({
124
+ model: "anthropic/claude-sonnet-4.5",
125
+ tools,
126
+ stopWhen: stepCountIs(5),
127
+ prompt: "Add a todo to read the Capable quickstart, then list the todos.",
128
+ });
129
+ ```
130
+
131
+ The model's tool call goes through the same runtime as `app.todos.create(...)`: input validation, middleware, declared errors, output validation. There is no second definition of the capability, and no hand-written tool wrapper to keep in sync.
132
+
133
+ Swapping the surface swaps the projection, not the app. The same `app` value drives an agent running in your process, a terminal command tree, or a React data layer:
134
+
135
+ ```ts title="surfaces.ts"
136
+ import { createCli } from "capable-kit/cli";
137
+ import { createEveTools } from "capable-kit/eve";
138
+ import { createMcp } from "capable-kit/mcp";
139
+ import { always } from "eve/tools/approval";
140
+ import { app } from "./agent";
141
+
142
+ // Durable in-process agent tools, with approvals derived from effect.
143
+ export const eveTools = createEveTools(app, {
144
+ approval: (capability) =>
145
+ capability.effect === "destructive" ? always() : undefined,
146
+ });
147
+
148
+ // The same app as a command tree, or as MCP tools for an external agent.
149
+ await createCli(app).run(process.argv.slice(2));
150
+ const mcpTools = await createMcp(app);
151
+ ```
152
+
153
+ A surface should often see less than the whole app. `selectApp()` narrows the tree before projection, so an agent can be given reads without ever seeing the destructive capabilities.
154
+
155
+ ```ts title="agent-tools.ts"
156
+ import { selectApp } from "capable-kit";
157
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
158
+ import { app } from "./agent";
159
+
160
+ // The model gets todos__list only. todos__create is not projected at all.
161
+ const readOnly = selectApp(app, { include: { todos: { list: true } } });
162
+
163
+ export const tools = await createAiSdkTools(readOnly);
164
+ ```
165
+
166
+ Per-capability metadata renames or hides a capability on one surface without touching the others — `meta.aiSdk.name` sets the tool name, and `meta.aiSdk: false` keeps a capability out of the tool set entirely. See [AI SDK](/surfaces/ai-sdk), [Eve](/surfaces/eve), and the [metadata reference](/reference/metadata).
167
+
168
+ 7. ### Call it from another process
169
+
170
+ Swap `createApp()` for `createRemoteApp()` and the calls are identical—only placement changed. The manifest is discovered lazily on first use, and types come from a type-only import of the definition.
171
+
172
+ ```ts title="remote.ts"
173
+ import { createRemoteApp } from "capable-kit";
174
+ import { createHttpTransport } from "capable-kit/http";
175
+ import type definition from "./capable.app";
176
+
177
+ // Same tree, same types, same errors — executed on the server.
178
+ // "typeof definition" is a type-only import, so no client is generated.
179
+ const app = createRemoteApp<typeof definition>(
180
+ createHttpTransport({
181
+ url: process.env.CAPABLE_URL ?? "http://localhost:3000/_capable/",
182
+ headers: () => ({ authorization: `Bearer ${process.env.TOKEN}` }),
183
+ }),
184
+ );
185
+
186
+ const todo = await app.todos.create({ title: "Read the quickstart" });
187
+ const todos = await app.todos.list({});
188
+ ```
189
+
190
+ Every surface from the previous step still applies, because they take an app rather than a server. Point them at the remote app and they run against the deployed service instead of this process.
191
+
192
+ ```ts title="cli.ts"
193
+ import { createCli } from "capable-kit/cli";
194
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
195
+ import { app } from "./remote";
196
+
197
+ // Same projection code as the local app — only placement changed.
198
+ process.exit(await createCli(app).run(process.argv.slice(2)));
199
+
200
+ // ...or give a model tools backed by the deployed service.
201
+ const tools = await createAiSdkTools(app);
202
+ ```
203
+
204
+ > **Remote apps are apps**
205
+ >
206
+ > A remote app can be merged with a local one using `mergeApps()`, so one command tree can mix capabilities that run on the server with capabilities that must run here. See [Composition](/patterns/composition).
207
+
208
+ 8. ### Build for production
209
+
210
+ `cap build` emits a standalone server. A preset changes the output target without touching the app definition.
211
+
212
+ ```sh title="terminal"
213
+ # Build a standalone Node server
214
+ cap build
215
+
216
+ # ...or Vercel Build Output
217
+ cap build --preset vercel
218
+ vercel deploy --prebuilt
219
+ ```
220
+
221
+ Run `cap preview` to serve a `node-server` build locally before shipping it.
222
+
223
+
224
+ </Tab>
225
+ <Tab label="In your Next.js app">
226
+
227
+ 1. ### Install Capable
228
+
229
+ Add Capable to your existing Next.js app. No toolchain needed — you keep your own dev server and deployment. Zod is only the Standard Schema provider used by this example.
230
+
231
+ ```sh title="terminal"
232
+ # inside your existing Next.js app
233
+ pnpm add capable-kit zod @capable/next
234
+ ```
235
+
236
+ 2. ### Define capabilities
237
+
238
+ Capabilities live in an ordinary module. The names and paths here become the typed tree you call.
239
+
240
+ ```ts title="capable/app.ts"
241
+ import { defineApp, capability } from "capable-kit";
242
+ import { z } from "zod";
243
+
244
+ const listTodos = capability({
245
+ id: "todos.list",
246
+ // Opt in to GET and read-only tool hints.
247
+ effect: "read",
248
+ handler: () => [{ id: "1", title: "Read the docs" }],
249
+ });
250
+
251
+ const createTodo = capability({
252
+ id: "todos.create",
253
+ input: z.object({ title: z.string().min(1) }),
254
+ handler: ({ input }) => ({ id: "1", title: input.title }),
255
+ });
256
+
257
+ export default defineApp({
258
+ name: "Todos",
259
+ capabilities: {
260
+ todos: { list: listTodos, create: createTodo },
261
+ },
262
+ });
263
+ ```
264
+
265
+ > Output types are inferred from handlers. Portable output schemas, effects, descriptions, errors, middleware, and surface metadata are opt-in.
266
+
267
+ 3. ### Call from a server component
268
+
269
+ This is the tRPC moment. `createApp()` gives you a typed callable object — call it from a server component or a server action. No network, no generated client, and the same validation and errors apply.
270
+
271
+ ```tsx title="app/todos/page.tsx"
272
+ import { createApp } from "capable-kit";
273
+ import definition from "../capable/app";
274
+
275
+ // A typed call in a server component or server action.
276
+ // No network, no client generated — same validation and errors.
277
+ const app = createApp(definition);
278
+
279
+ export default async function TodoList() {
280
+ const todos = await app.todos.list({});
281
+ return (
282
+ <ul>
283
+ {todos.map((t) => <li key={t.id}>{t.title}</li>)}
284
+ </ul>
285
+ );
286
+ }
287
+ ```
288
+
289
+ 4. ### Expose it to the browser
290
+
291
+ To call the same capabilities from the client, mount one fetch server and re-export its handlers into two catch-all route files.
292
+
293
+ ```ts title="capable/server.ts"
294
+ // capable/server.ts
295
+ import { createNextRouteHandlers } from "@capable/next";
296
+ import { protocol, createServer, http } from "capable-kit/server";
297
+ import definition from "./app";
298
+
299
+ const server = createServer(definition, {
300
+ mounts: [protocol(), http()],
301
+ });
302
+
303
+ export const { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } =
304
+ createNextRouteHandlers(server.fetch);
305
+ ```
306
+
307
+ ```ts title="App Router"
308
+ // app/api/[[...path]]/route.ts
309
+ export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
310
+
311
+ // app/%5Fcapable/[[...path]]/route.ts — %5F keeps _capable out of Next's private folders
312
+ export { GET, POST } from "@/capable/server";
313
+ ```
314
+
315
+ 5. ### Turn the same capabilities into agent tools
316
+
317
+ The capabilities you already call from a server component are also a tool set. In a chat route, project the app with `createAiSdkTools()` and pass it to `streamText()` — the model calls the same handlers your UI does.
318
+
319
+ ```ts title="app/api/chat/route.ts"
320
+ import { convertToModelMessages, streamText, type UIMessage } from "ai";
321
+ import { createApp, selectApp } from "capable-kit";
322
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
323
+ import definition from "../../../capable/app";
324
+
325
+ const app = createApp(definition);
326
+
327
+ // The agent sees a narrowed tree: reads and creates, nothing destructive.
328
+ const agentApp = selectApp(app, {
329
+ include: { todos: { list: true, create: true } },
330
+ });
331
+ const tools = await createAiSdkTools(agentApp);
332
+
333
+ export async function POST(request: Request) {
334
+ const { messages }: { messages: UIMessage[] } = await request.json();
335
+
336
+ const result = streamText({
337
+ model: "anthropic/claude-sonnet-4.5",
338
+ messages: convertToModelMessages(messages),
339
+ tools,
340
+ });
341
+
342
+ return result.toUIMessageStreamResponse();
343
+ }
344
+ ```
345
+
346
+ Nothing was added to the capability to make this work. `todos.create` became the tool `todos__create` because a surface projected it, with the same input schema, middleware, and errors the server component gets.
347
+
348
+ 6. ### Call from React Query
349
+
350
+ `@capable/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/_capable`.
351
+
352
+ ```ts title="app/query.ts"
353
+ import { createRemoteApp } from "capable-kit";
354
+ import { createHttpTransport } from "capable-kit/http";
355
+ import { createReactQuery } from "@capable/react-query";
356
+ import type definition from "../capable/app";
357
+
358
+ const app = createRemoteApp<typeof definition>(
359
+ createHttpTransport({ url: "/_capable/" }),
360
+ );
361
+
362
+ export const query = createReactQuery(app);
363
+ ```
364
+
365
+ ```tsx title="app/todos/todos.tsx"
366
+ import { useQuery } from "@tanstack/react-query";
367
+ import { query } from "./query";
368
+
369
+ export function TodoList() {
370
+ const { data } = useQuery(query.todos.list.queryOptions({}));
371
+ return (
372
+ <ul>
373
+ {data?.map((t) => <li key={t.id}>{t.title}</li>)}
374
+ </ul>
375
+ );
376
+ }
377
+ ```
378
+
379
+ </Tab>
380
+ </Tabs>
381
+
382
+ > **Both paths are the same Capable**
383
+ >
384
+ > The capability you wrote is identical in either tab. The difference is only where it runs and who calls it. Standalone gives you HTTP, CLI, and MCP from one file; embedded gives you typed calls inside an app you already deploy. Local and remote callers use the same tree — the only difference is `createApp()` versus `createRemoteApp()`. You can move between them without rewriting capabilities.
385
+
386
+ </DocsPage>
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: "Packages and entry points"
3
+ description: "What each import path contains and when to reach for it."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/reference/packages", frontmatter);
9
+
10
+ <DocsPage href="/reference/packages" frontmatter={frontmatter}>
11
+
12
+ Entry points are explicit so that a server mount, a UI projection, or an agent integration never gets pulled into an application that does not use it.
13
+
14
+ ## The root entry point [#root]
15
+
16
+ `capable` is deliberately limited to authoring and composing apps. Everything you need to define capabilities lives here.
17
+
18
+ ```ts title="import"
19
+ import {
20
+ defineApp, // compose a definition
21
+ defineErrors, // declare an error set
22
+ group, // decorated subtree
23
+ capability, // author a capability
24
+ md, // markdown template tag
25
+ present, // table, image, and file builders
26
+ watchQuery, // snapshot + invalidation subscriber
27
+ createApp, // definition + context -> callable app
28
+ createRemoteApp, // transport + definition type -> callable app
29
+ mergeApps, // combine apps
30
+ selectApp, // narrow an app
31
+ subscribe, // iterate replacements
32
+ executeCapability, // run one capability without an app
33
+ } from "capable-kit";
34
+ ```
35
+
36
+ ## All entry points [#entry-points]
37
+
38
+ | Import | Contains |
39
+ | --- | --- |
40
+ | `capable` | Capability authoring, app definitions, executable and remote apps, composition, and the capable command |
41
+ | `capable/server` | `createServer()` plus the `protocol()` and `http()` mounts |
42
+ | `capable/http` | Capable transport client and server encoding: `createHttpTransport()`, `createHttpHandler()` |
43
+ | `capable/cli` | `createCli()` |
44
+ | `capable/mcp` | `createMcp()` and the `mcp()` server mount |
45
+ | `capable/eve` | `createEveTools()` |
46
+ | `capable/ai-sdk` | `createAiSdkTools()` |
47
+ | `capable/app` | App runtime internals: manifests, transport types, selection |
48
+ | `capable/core` | Execution and schema primitives for building your own surface |
49
+ | `@capable/react-query` | `createReactQuery()` |
50
+ | `@capable/next` | `createNextRouteHandlers()` |
51
+
52
+ > **Dependency direction**
53
+ >
54
+ > `@capable/core` depends on no transport, host, CLI, MCP, or HTTP package. Surface packages depend inward on the core, never the other way around.
55
+
56
+ ## Function summary [#functions]
57
+
58
+ | Function | Signature | Notes |
59
+ | --- | --- | --- |
60
+ | `capability()` | `capability(config)` | `capability<Context>()` or `capability.withContext<Context>()` binds a context type |
61
+ | `present` | `present.table(), .image(), .file()` | Portable presentation parts for `toPresentation` |
62
+ | `defineApp()` | `defineApp({ name, version, capabilities })` | Immutable definition, no context |
63
+ | `group()` | `group({ middleware, errors, meta, capabilities })` | Anonymous decorated subtree |
64
+ | `createApp()` | `createApp(definition)` | Callable tree; context options exist only when declared |
65
+ | `createRemoteApp()` | `createRemoteApp<typeof definition>(transport)` | Lazy, transport-backed remote placement |
66
+ | `mergeApps()` | `mergeApps(a, b, ...)` | Root-tree merge, dispatch by id |
67
+ | `selectApp()` | `selectApp(app, { include, exclude })` | Exclude wins over include |
68
+ | `subscribe()` | `subscribe(app.todos.list, input, { signal })` | Async iterator of replacements |
69
+ | `executeCapability()` | `executeCapability(capability, { input, context, signal })` | No app tree, no group behaviour |
70
+ | `createServer()` | `createServer(definition, { context, mounts, middleware })` | Returns `{ fetch }` |
71
+
72
+ </DocsPage>
@@ -0,0 +1,84 @@
1
+ ---
2
+ title: "Surface metadata"
3
+ description: "Every meta field the built-in surfaces read, and what it changes."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/reference/metadata", frontmatter);
9
+
10
+ <DocsPage href="/reference/metadata" frontmatter={frontmatter}>
11
+
12
+ `meta` is an open record. Each surface package declares its own key through module augmentation, which is how the fields below are type-checked without the core knowing anything about HTTP, terminals, or agents.
13
+
14
+ ## In context [#example]
15
+
16
+ ```ts title="capabilities.ts"
17
+ const deleteTodo = todo({
18
+ id: "todos.delete",
19
+ effect: "destructive",
20
+ input: z.object({ todoId: z.string() }),
21
+ meta: {
22
+ http: { method: "DELETE", route: "/:todoId", status: 200 },
23
+ cli: { positional: ["todoId"] },
24
+ mcp: { name: "todos_delete" },
25
+ aiSdk: { name: "todos_delete", strict: true },
26
+ eve: false,
27
+ },
28
+ handler: ({ input, context }) => context.todos.delete(input.todoId),
29
+ });
30
+
31
+ const todos = group({
32
+ meta: {
33
+ http: { prefix: "/todos" },
34
+ cli: { name: "todo" },
35
+ },
36
+ capabilities: { delete: deleteTodo },
37
+ });
38
+ ```
39
+
40
+ ## Capability metadata [#capability]
41
+
42
+ | Field | Type | Effect |
43
+ | --- | --- | --- |
44
+ | `http` | `false \| { method, route, status }` | Overrides the derived route. `false` removes the capability from HTTP. `route` may contain `:params` that must exist in the input schema. |
45
+ | `cli` | `false \| { name, command, positional }` | `positional` promotes input fields to arguments, `name` renames the command, `command` replaces the whole path. |
46
+ | `mcp` | `false \| { name }` | Renames the tool. Default is the app path joined with `__`. |
47
+ | `eve` | `false \| { name }` | Same, for native in-process Eve tools. |
48
+ | `aiSdk` | `false \| { name, strict }` | Renames, constrains, or hides an AI SDK tool. |
49
+
50
+ ## Group metadata [#group]
51
+
52
+ | Field | Type | Effect |
53
+ | --- | --- | --- |
54
+ | `http.prefix` | `string` | Replaces this group's segment in derived routes and prefixes authored ones. |
55
+ | `cli.name` | `string` | Renames the command group. |
56
+
57
+ > **No generic merging**
58
+ >
59
+ > The core preserves the full group ancestry and never merges metadata itself. Each surface compiler decides what inheritance means, which is why `http.prefix` composes but `mcp.name` does not exist on groups at all.
60
+
61
+ ## Effect is not metadata [#effect]
62
+
63
+ `effect` is a core field, because intent is part of the capability rather than of one presentation. Surfaces read it:
64
+
65
+ | Effect | HTTP | MCP | AI SDK | Eve |
66
+ | --- | --- | --- | --- | --- |
67
+ | `read` | `GET` | `readOnlyHint` | `toolMetadata.capable.effect` | Usually no approval |
68
+ | `write` | `POST` | — | `toolMetadata.capable.effect` | Policy of your choice |
69
+ | `destructive` | `POST` | `destructiveHint` | `toolMetadata.capable.effect` | Often `always()` |
70
+ | omitted | `POST` | — | Omitted | Treated as unknown intent |
71
+
72
+ ## Your own metadata [#custom]
73
+
74
+ A surface you write can claim its own key the same way the built-in ones do. Unknown keys are preserved and passed through, so nothing in the core has to change.
75
+
76
+ ```ts title="dashboard-surface.ts"
77
+ declare module "@capable/core" {
78
+ interface CapabilityMetaRegistry {
79
+ readonly dashboard?: { readonly icon: string };
80
+ }
81
+ }
82
+ ```
83
+
84
+ </DocsPage>