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

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 (70) hide show
  1. package/dist/ai-sdk.d.mts +2 -2
  2. package/dist/ai-sdk.mjs +1 -1
  3. package/dist/app.d.mts +1 -1
  4. package/dist/app.mjs +1 -1
  5. package/dist/bin.mjs +4 -4
  6. package/dist/cli.d.mts +1 -1
  7. package/dist/cli.mjs +1 -1
  8. package/dist/core.d.mts +3 -3
  9. package/dist/core.mjs +2 -2
  10. package/dist/eve.d.mts +1 -1
  11. package/dist/eve.mjs +1 -1
  12. package/dist/http.d.mts +1 -1
  13. package/dist/http.mjs +1 -1
  14. package/dist/{index-BB5ogMv-.d.mts → index-Be8-UVBC.d.mts} +49 -8
  15. package/dist/{index-DJ--zcWG.d.mts → index-D2CRRUzH.d.mts} +4 -4
  16. package/dist/{index-B_I9n6gN.d.mts → index-Dbc4g9WM.d.mts} +4 -3
  17. package/dist/{index-DCrxWCTv.d.mts → index-DwXlaTXI.d.mts} +3 -3
  18. package/dist/index.d.mts +4 -4
  19. package/dist/index.mjs +3 -3
  20. package/dist/mcp.d.mts +2 -2
  21. package/dist/mcp.mjs +1 -1
  22. package/dist/{mount-BEBJ2Tss.mjs → mount-xvMsjz1B.mjs} +53 -9
  23. package/dist/mount-xvMsjz1B.mjs.map +1 -0
  24. package/dist/runtime-support.d.mts +1 -1
  25. package/dist/runtime-support.mjs +4 -4
  26. package/dist/runtime-support.mjs.map +1 -1
  27. package/dist/server.d.mts +1 -1
  28. package/dist/server.mjs +1 -1
  29. package/dist/{src-D9pLpfeO.mjs → src-BF70JLxI.mjs} +23 -12
  30. package/dist/src-BF70JLxI.mjs.map +1 -0
  31. package/dist/{src-3UaBqI8H.mjs → src-C2MGIlT0.mjs} +17 -18
  32. package/dist/src-C2MGIlT0.mjs.map +1 -0
  33. package/dist/{src-ChDFqZaE.mjs → src-CDxL6w3d.mjs} +3 -3
  34. package/dist/{src-ChDFqZaE.mjs.map → src-CDxL6w3d.mjs.map} +1 -1
  35. package/dist/{src-BjBxOv7x.mjs → src-Db6-XSnU.mjs} +20 -12
  36. package/dist/src-Db6-XSnU.mjs.map +1 -0
  37. package/dist/{src-B53ZbNtC.mjs → src-DdV82An-.mjs} +137 -3
  38. package/dist/src-DdV82An-.mjs.map +1 -0
  39. package/dist/{subscription-McaLyHM2.d.mts → subscription-Bq792Ad2.d.mts} +2 -2
  40. package/docs/CONTEXT.md +8 -3
  41. package/docs/internal/architecture.md +18 -4
  42. package/docs/internal/capability-first-model.md +7 -1
  43. package/docs/internal/implementation-friction.md +68 -7
  44. package/docs/site/capable-orpc-and-trpc.mdx +1 -1
  45. package/docs/site/concepts/architecture.mdx +10 -2
  46. package/docs/site/concepts/capabilities.mdx +6 -6
  47. package/docs/site/concepts/presentations.mdx +161 -0
  48. package/docs/site/hosting/next-js.mdx +1 -1
  49. package/docs/site/introduction.mdx +166 -49
  50. package/docs/site/quickstart.mdx +107 -14
  51. package/docs/site/reference/packages-and-entry-points.mdx +15 -12
  52. package/docs/site/reference/the-cap-cli.mdx +1 -1
  53. package/docs/site/surfaces/cli.mdx +2 -2
  54. package/docs/site/surfaces/http-and-openapi.mdx +1 -1
  55. package/docs/site/surfaces/mcp.mdx +13 -0
  56. package/docs/site/surfaces/react-query.mdx +6 -2
  57. package/docs/site/surfaces/swr.mdx +97 -0
  58. package/docs/site/surfaces.mdx +6 -2
  59. package/package.json +22 -2
  60. package/src/index.test.ts +7 -0
  61. package/src/index.ts +5 -1
  62. package/src/next.ts +1 -0
  63. package/src/package.test.ts +58 -2
  64. package/src/react-query.ts +1 -0
  65. package/src/swr.ts +1 -0
  66. package/dist/mount-BEBJ2Tss.mjs.map +0 -1
  67. package/dist/src-3UaBqI8H.mjs.map +0 -1
  68. package/dist/src-B53ZbNtC.mjs.map +0 -1
  69. package/dist/src-BjBxOv7x.mjs.map +0 -1
  70. package/dist/src-D9pLpfeO.mjs.map +0 -1
@@ -3,6 +3,50 @@
3
3
  This is a live engineering log. Record awkward, unexpectedly heavy,
4
4
  duplicated, or leaky implementation work as it appears.
5
5
 
6
+ ## 2026-08-05 — Markdown negotiation must run before static page matching
7
+
8
+ - **Observed:** The `dom-md` Next.js example returns a flat rewrite list, which
9
+ Next.js 16.2.6 places in `afterFiles`. Those rewrites never see this site's
10
+ statically prerendered MDX routes because filesystem routes win first.
11
+ - **Why it matters:** The Markdown Route Handler worked directly, but
12
+ `Accept: text/markdown` silently returned cached HTML at the public docs URL.
13
+ - **Current choice:** Register the same header-matched rewrite in
14
+ `beforeFiles`, ahead of static route matching. The route's internal request
15
+ explicitly accepts HTML, so it does not negotiate back into itself.
16
+ - **Follow-up:** Recheck whether a flat rewrite becomes safe if Next.js or the
17
+ `dom-md` guide changes its ordering guidance.
18
+
19
+ ## 2026-07-31 — Rich presentation must be requested explicitly
20
+
21
+ - **Observed:** The App runtime previously derived Markdown after every call,
22
+ even when typed callers, AI SDK tools, or CLI `--json` only consumed canonical
23
+ output. Extending that behavior to inline base64 images would waste memory,
24
+ serialization, and network bandwidth.
25
+ - **Why it matters:** Presentation is optional and potentially much larger than
26
+ the semantic result. Eager derivation would make adding a renderer observable
27
+ to callers that never asked for it.
28
+ - **Current choice:** Low-level `call()` and `subscribe()` accept an optional
29
+ `presentation` request flag. CLI, Markdown HTTP, and MCP opt in; typed App
30
+ calls, AI SDK, and JSON output do not. Files remain URL references rather than
31
+ transported binary bodies.
32
+ - **Follow-up:** Add capability negotiation only if a surface needs to request a
33
+ subset of part types often enough to justify the protocol complexity.
34
+
35
+ ## 2026-07-31 — Presentation lowering has a common Markdown baseline
36
+
37
+ - **Observed:** CLI and HTTP both needed the same meaningful Markdown rendering
38
+ of every Presentation part. Treating those as separate surface policies
39
+ duplicated file formatting and caused table caption escaping to drift.
40
+ - **Why it matters:** Presentation already defines Markdown as its portable
41
+ textual baseline. Making each textual surface reinterpret the same parts
42
+ adds policy without adding useful variation.
43
+ - **Current choice:** Core owns one general-purpose Presentation-to-Markdown
44
+ renderer. HTTP returns it directly, CLI adds terminal styling, and MCP uses it
45
+ for textual parts while retaining native image and resource-link blocks.
46
+ - **Follow-up:** Keep native protocol lowering surface-owned; add renderer
47
+ options only after a concrete caller needs a genuinely different Markdown
48
+ representation.
49
+
6
50
  ## 2026-07-29 — Declaration builds repeated TypeScript analysis per package
7
51
 
8
52
  - **Observed:** The root `tsdown` configuration launches thirteen package
@@ -19,13 +63,13 @@ duplicated, or leaky implementation work as it appears.
19
63
  required cross-file inference. The complete build now takes about 0.5–0.7
20
64
  seconds and its declarations are equivalent to the TypeScript-generated
21
65
  output. TypeScript 7 RC handles workspace typechecking separately.
22
- - **Follow-up:** Decide whether scoped surface packages and their
23
- `capable-kit/*` facades should both remain public. Treat that as a package API
24
- decision rather than a build-performance shortcut.
66
+ - **Resolution (2026-08-05):** Scoped `@capable/*` packages are private
67
+ workspace boundaries. `capable-kit` is the only published package and exposes
68
+ user-facing surfaces through subpaths.
25
69
 
26
70
  ## 2026-07-29 — Bundling duplicated nominal App type identities
27
71
 
28
- - **Observed:** The standalone `capable` facade bundles `@capable/app`, while
72
+ - **Observed:** The standalone `capable-kit` facade bundles `@capable/app`, while
29
73
  surface packages such as `@capable/react-query` reference their own external
30
74
  copy. A private `unique symbol` used only to carry Capability type information
31
75
  therefore had two incompatible identities in a consuming application.
@@ -36,9 +80,10 @@ duplicated, or leaky implementation work as it appears.
36
80
  Capability-call phantom metadata structural. React Query accepts the typed
37
81
  callable object it actually projects instead of depending on runtime
38
82
  ownership it never reads.
39
- - **Follow-up:** Add an installed-package consumer fixture so declaration
40
- identity is checked across the bundled facade and separately published
41
- surfaces before release.
83
+ - **Resolution (2026-08-05):** React Query and the other user-facing surfaces
84
+ now ship through bundled `capable-kit/*` subpaths. Keep an installed-package
85
+ consumer fixture so their declarations and optional peers are checked before
86
+ release.
42
87
 
43
88
  ## 2026-07-29 — Manifest discovery cannot be globally eager
44
89
 
@@ -352,6 +397,22 @@ duplicated, or leaky implementation work as it appears.
352
397
  this only if a real App uses one of those names or callable Apps gain
353
398
  synchronous leaf metadata.
354
399
 
400
+ ## 2026-08-05 — SWR fetchers do not receive a cancellation signal
401
+
402
+ - **Observed:** SWR passes the cache key to a unary fetcher, but does not expose
403
+ an `AbortSignal` in that fetcher's contract. Capability subscriptions do have
404
+ an explicit cleanup boundary.
405
+ - **Why it matters:** `@capable/swr` cannot forward hook disposal to an in-flight
406
+ unary Capability call the way `@capable/react-query` can. Pretending to own a
407
+ controller would abort at the wrong time because SWR owns request deduplication
408
+ and revalidation.
409
+ - **Current choice:** Unary `swr()` fetchers call the Capability without a
410
+ signal. `subscription()` creates a controller and aborts it from SWR's
411
+ unsubscribe callback.
412
+ - **Follow-up:** Forward cancellation if SWR adds a fetcher lifecycle signal.
413
+ The projection's `key`, `swr`, `mutation`, and `subscription` member names are
414
+ reserved until App leaves have synchronous metadata.
415
+
355
416
  ## 2026-07-28 — A fresh Next.js build can race SQLite initialization
356
417
 
357
418
  - **Observed:** Next.js page-data collection imports the authenticated Todo
@@ -40,7 +40,7 @@ You do not give up the normal full-stack experience by choosing Capable. A brows
40
40
  ```ts title="query.ts"
41
41
  import { createRemoteApp } from "capable-kit";
42
42
  import { createHttpTransport } from "capable-kit/http";
43
- import { createReactQuery } from "@capable/react-query";
43
+ import { createReactQuery } from "capable-kit/react-query";
44
44
  import type definition from "../capable.app";
45
45
 
46
46
  const app = createRemoteApp<typeof definition>(
@@ -57,8 +57,14 @@ A transport may perform I/O to discover its manifest, but `createRemoteApp()` do
57
57
  ```ts title="transport-and-runtime.ts"
58
58
  interface ApplicationTransport {
59
59
  manifest(): Promise<ApplicationManifest>;
60
- call(args): Promise<{ output: unknown; markdown?: string }>;
61
- subscribe(args): AsyncIterableIterator<{ output: unknown }>;
60
+ call(args: {
61
+ id: string;
62
+ input: unknown;
63
+ presentation?: boolean;
64
+ }): Promise<{
65
+ output: unknown;
66
+ presentation?: readonly PresentationPart[];
67
+ }>;
62
68
  }
63
69
 
64
70
  const app = createRemoteApp(transport);
@@ -68,6 +74,8 @@ const tools = await createAiSdkTools(app);
68
74
 
69
75
  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
76
 
77
+ Presentation is opt-in at this low-level boundary. A typed call does not compute or transport Markdown, images, or files; a surface requests those parts only when it can use them.
78
+
71
79
  ## Open metadata, closed core [#metadata]
72
80
 
73
81
  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.
@@ -163,9 +163,9 @@ export const getTodo = todoCapability({
163
163
 
164
164
  Here the HTTP metadata describes a resource-shaped route, while the CLI metadata says that `todoId` is positional. The handler does not see these presentation details, and other surfaces ignore keys they do not own. See [Surface metadata](/reference/metadata) for every supported key.
165
165
 
166
- ## Add a Markdown rendering [#markdown]
166
+ ## Add a presentation [#presentation]
167
167
 
168
- A capability always returns one canonical structured value. `toMarkdown` optionally turns that same value into an easy-to-read representation for both people and agents.
168
+ A capability always returns one canonical structured value. `toPresentation` can derive an optional human-readable view without changing that contract. Returning a string is the smallest form and is treated as Markdown.
169
169
 
170
170
  ```ts title="capabilities.ts" highlight="1,6-9"
171
171
  import { md } from "capable-kit";
@@ -173,14 +173,14 @@ import { md } from "capable-kit";
173
173
  export const listTodos = todoCapability({
174
174
  id: "todos.list",
175
175
  handler: ({ context }) => context.todos.list(context.userId),
176
- toMarkdown: (todos) =>
176
+ toPresentation: (todos) =>
177
177
  todos.length === 0
178
178
  ? "No todos."
179
179
  : todos.map((todo) => md`- **${todo.title}**`).join("\n"),
180
180
  });
181
181
  ```
182
182
 
183
- The CLI renders this Markdown in the terminal, MCP gives it to agents as tool text, and HTTP returns it when the caller accepts `text/markdown`. Typed calls still receive the original array.
183
+ Only surfaces that need a presentation ask the runtime to produce it. The CLI renders this Markdown in the terminal, MCP gives it to agents as tool text, and HTTP requests it when the caller accepts `text/markdown`. Typed calls and `--json` still receive only the original array. For tables, images, and downloadable files, see [Presentations](/concepts/presentations).
184
184
 
185
185
  ## How execution fits together [#lifecycle]
186
186
 
@@ -215,7 +215,7 @@ A capability can grow into the full declaration below, but only as each concern
215
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).
216
216
 
217
217
  ```ts title="capabilities.ts"
218
- import { defineErrors, md, capability } from "capable-kit";
218
+ import { capability, defineErrors, md } from "capable-kit";
219
219
  import { z } from "zod";
220
220
 
221
221
  const TodoErrors = defineErrors({
@@ -242,7 +242,7 @@ export const getTodo = todoCapability({
242
242
  if (!found) throw TodoErrors.NOT_FOUND();
243
243
  return found;
244
244
  },
245
- toMarkdown: (todo) => md`- **${todo.title}**`,
245
+ toPresentation: (todo) => md`- **${todo.title}**`,
246
246
  });
247
247
  ```
248
248
 
@@ -0,0 +1,161 @@
1
+ ---
2
+ title: "Presentations"
3
+ description: "Derive portable Markdown, tables, images, and files from canonical output."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/concepts/presentations", frontmatter);
9
+
10
+ <DocsPage href="/concepts/presentations" frontmatter={frontmatter}>
11
+
12
+ A capability returns one canonical output. `toPresentation` derives a meaningful representation of that data without turning the representation into the API contract. The same Presentation helps a person understand a result in the CLI and gives an agent a focused, often more token-efficient account of what happened.
13
+
14
+ ## Why present canonical output? [#purpose]
15
+
16
+ Canonical output is designed for programs: it is complete, stable, and structured. That does not mean its raw JSON is the best explanation of a result. It may repeat field names hundreds of times, expose internal bookkeeping, or leave important values without useful labels.
17
+
18
+ A Presentation lets the capability author select what matters, name it clearly, and put it in a useful order. Humans get readable headings, tables, images, and file links. Agents get concise text and structured visual resources instead of having to infer the meaning of an entire JSON object. The canonical output remains available whenever exact machine-readable data is needed.
19
+
20
+ ## Start with Markdown [#markdown]
21
+
22
+ Return a string when Markdown is enough. Existing string renderers stay small and need no wrapper.
23
+
24
+ ```ts title="capabilities.ts"
25
+ import { capability, md } from "capable-kit";
26
+
27
+ export const getWeather = capability({
28
+ id: "weather.get",
29
+ handler: () => ({ city: "Vienna", temperature: 24 }),
30
+ toPresentation: (weather) =>
31
+ md`**${weather.city}:** ${weather.temperature}°C`,
32
+ });
33
+ ```
34
+
35
+ Typed calls still receive `{ city, temperature }`. The string is only produced when a presentation-aware surface asks for it.
36
+
37
+ ## Compose richer output [#parts]
38
+
39
+ `toPresentation` may also return one part or an ordered array of strings and parts. Import the builders from the same root entry point:
40
+
41
+ ```ts title="capabilities.ts"
42
+ import { capability, md, present } from "capable-kit";
43
+
44
+ export const createReport = capability({
45
+ id: "reports.create",
46
+ handler: () => buildReport(),
47
+ toPresentation: (report) => [
48
+ md`## ${report.title}`,
49
+ present.table({
50
+ caption: "Daily totals",
51
+ columns: ["Date", "Requests", "Errors"],
52
+ rows: report.days.map((day) => [
53
+ day.date,
54
+ day.requests,
55
+ day.errors,
56
+ ]),
57
+ }),
58
+ present.image({
59
+ base64: report.chartBase64,
60
+ mimeType: "image/png",
61
+ alt: "Requests and errors over time",
62
+ }),
63
+ present.file({
64
+ url: report.csvUrl,
65
+ name: "daily-totals.csv",
66
+ mimeType: "text/csv",
67
+ size: report.csvSize,
68
+ description: "The underlying report data",
69
+ }),
70
+ ],
71
+ });
72
+ ```
73
+
74
+ The array order is meaningful. A surface can render a heading, then a table, then an image and a file link in that sequence.
75
+
76
+ ## What the CLI shows [#cli]
77
+
78
+ The CLI uses the general Markdown representation and adds terminal styling. The report above reads approximately like this:
79
+
80
+ ```text title="terminal"
81
+ $ cap cli reports create
82
+
83
+ API traffic
84
+
85
+ Daily totals
86
+
87
+ Date Requests Errors
88
+ 2026-07-30 18,420 31
89
+ 2026-07-31 19,105 22
90
+
91
+ [Image: Requests and errors over time]
92
+
93
+ daily-totals.csv — The underlying report data — text/csv, 42.3 kB
94
+ ```
95
+
96
+ Running the same command with `--json` skips `toPresentation` entirely and prints the canonical report object. An MCP client can instead keep the heading and table as text while receiving the chart and file as native content blocks.
97
+
98
+ ## The complete presentation API [#api]
99
+
100
+ ```ts title="types.ts"
101
+ type PresentationValue =
102
+ | string
103
+ | PresentationPart
104
+ | readonly (string | PresentationPart)[];
105
+
106
+ type PresentationPart =
107
+ | {
108
+ type: "markdown";
109
+ markdown: string;
110
+ }
111
+ | {
112
+ type: "table";
113
+ caption?: string;
114
+ columns: readonly string[];
115
+ rows: readonly (readonly (string | number | boolean | null)[])[];
116
+ }
117
+ | {
118
+ type: "image";
119
+ base64: string;
120
+ mimeType: `image/${string}`;
121
+ alt: string;
122
+ }
123
+ | {
124
+ type: "file";
125
+ url: string;
126
+ name: string;
127
+ mimeType?: string;
128
+ size?: number;
129
+ description?: string;
130
+ };
131
+ ```
132
+
133
+ Strings are normalized to Markdown parts. The builders make each part explicit; validation and defensive copying happen only when a surface materializes the presentation:
134
+
135
+ | Builder | Required fields | Purpose |
136
+ | --- | --- | --- |
137
+ | `present.table()` | `columns`, `rows` | Structured scalar data that can become a terminal or Markdown table |
138
+ | `present.image()` | `base64`, `mimeType`, `alt` | An inline image for surfaces that support image content |
139
+ | `present.file()` | `url`, `name` | A reference to a downloadable or otherwise addressable resource |
140
+
141
+ An image is inline because image-capable protocols commonly need its bytes. A file is deliberately a reference: Capable transports its URL and metadata, not the file body. If an image should stay lazy, represent it as a file with an image MIME type instead. Fetching, authentication, expiry, and storage remain the application's responsibility.
142
+
143
+ ## Surface behavior [#surfaces]
144
+
145
+ Each surface chooses whether to request a presentation and how to lower its parts.
146
+
147
+ An empty array means that no presentation is available, so the surface falls back to canonical output. Return an explicit empty Markdown string only when blank presentation output is intentional.
148
+
149
+ | Surface | Behavior |
150
+ | --- | --- |
151
+ | Typed App call | Returns canonical output and does not run `toPresentation` |
152
+ | CLI | Renders the general Markdown representation with terminal styling |
153
+ | CLI `--json` | Prints canonical output and does not run `toPresentation` |
154
+ | HTTP JSON | Returns canonical output and does not run `toPresentation` |
155
+ | HTTP `Accept: text/markdown` | Returns the general Markdown representation |
156
+ | MCP | Sends text, images, and resource links using native MCP content blocks |
157
+ | Other surfaces | May support, partially lower, or ignore presentations |
158
+
159
+ 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
+
161
+ </DocsPage>
@@ -17,7 +17,7 @@ Compose the server once in a shared module. The adapter only maps methods; execu
17
17
 
18
18
  ```ts title="capable/server.ts"
19
19
  // capable/server.ts
20
- import { createNextRouteHandlers } from "@capable/next";
20
+ import { createNextRouteHandlers } from "capable-kit/next";
21
21
  import { protocol, createServer, http } from "capable-kit/server";
22
22
  import definition from "../capable.app";
23
23
 
@@ -1,30 +1,40 @@
1
1
  ---
2
2
  title: "Introduction"
3
- description: "Capable turns one typed capability into a typed client, an HTTP API, a CLI, and agent tools."
3
+ description: "Define typed application capabilities and use them across runtime surfaces."
4
4
  ---
5
5
 
6
6
  import { DocsPage, docMetadata } from "./_components/docs-page";
7
7
  import { Card, Cards } from "./_components/cards";
8
+ import { Tab, Tabs } from "./_components/tabs";
8
9
 
9
10
  export const metadata = docMetadata("/", frontmatter);
10
11
 
11
12
  <DocsPage href="/" frontmatter={frontmatter}>
12
13
 
13
- Most applications end up implementing the same capability several times: once for the product UI, once as a public HTTP route, once as a CLI command, and once as a tool for an agent. Capable gives that capability a single definition — a **capability** — and lets you use it across every surface.
14
+ Capable is a framework for defining the operations an application provides—its capabilities—using types and schemas. Add them to an app, then run or call that app in-process, over HTTP, through a CLI, or with AI tools.
14
15
 
15
- ## Define one capability [#capability]
16
+ ## 1. Define a capability [#capability]
16
17
 
17
- Start with an id, an optional input schema, and a handler. TypeScript infers the handler's output type. Schemas use the Standard Schema interface, so Capable is not tied to the Zod authoring API shown here. A capability has no HTTP method, no command name, and no framework attached.
18
+ Start with an id, input schema, and handler. A capability has no HTTP method, command name, or framework attached.
18
19
 
19
- ```ts title="capable.app.ts"
20
- import { defineApp, capability } from "capable-kit";
20
+ ```ts title="capabilities/create-todo.ts"
21
+ import { capability } from "capable-kit";
21
22
  import { z } from "zod";
22
23
 
23
- const createTodo = capability({
24
+ export const createTodo = capability({
24
25
  id: "todos.create",
25
26
  input: z.object({ title: z.string().min(1) }),
26
27
  handler: ({ input }) => ({ id: "1", title: input.title }),
27
28
  });
29
+ ```
30
+
31
+ ## 2. Put it in an app [#app]
32
+
33
+ An app gives capabilities a path: `todos.create`.
34
+
35
+ ```ts title="capable.app.ts"
36
+ import { defineApp } from "capable-kit";
37
+ import { createTodo } from "./capabilities/create-todo";
28
38
 
29
39
  export default defineApp({
30
40
  name: "Todos",
@@ -35,13 +45,28 @@ export default defineApp({
35
45
  });
36
46
  ```
37
47
 
38
- Add a portable `output` schema, effect metadata, declared errors, middleware, descriptions, or presentation metadata only when the capability needs the behavior they enable.
48
+ Add output schemas, errors, middleware, or surface metadata only when the app needs them.
49
+
50
+ ## 3. Initialize the app [#choose]
51
+
52
+ Choose where the app runs. The in-process option has no network boundary; the other options accept requests from outside the process.
39
53
 
40
- Capabilities are composed into an _app_: an ordinary named object tree. The path `todos.create` is how callers navigate to the capability. The id `todos.create` is its permanent execution identity, which is what remote calls and conflict detection use. Add context, errors, middleware, and `group()` only when a subtree needs them.
54
+ <Tabs id="introduction-hosting" label="Choose a host">
55
+ <Tab label="In-Process">
41
56
 
42
- ## Run it [#run]
57
+ Use the executable app directly in a script, test, server action, or agent. No HTTP server is started.
43
58
 
44
- `cap dev` discovers `capable.app.ts` and serves the derived surfaces.
59
+ ```ts title="app.ts"
60
+ import { createApp } from "capable-kit";
61
+ import definition from "./capable.app";
62
+
63
+ export const app = createApp(definition);
64
+ ```
65
+
66
+ </Tab>
67
+ <Tab label="Capable CLI">
68
+
69
+ The zero-config standalone option. With only `capable.app.ts`, the toolchain mounts Capable, HTTP/OpenAPI, and MCP for you.
45
70
 
46
71
  ```sh title="terminal"
47
72
  $ cap dev
@@ -57,70 +82,162 @@ MCP /mcp
57
82
  ✓ 1 capability ready, watching for changes
58
83
  ```
59
84
 
60
- The same `title` input reaches the capability through a flag or a JSON body — no extra code to write.
85
+ </Tab>
86
+ <Tab label="Next.js">
87
+
88
+ Keep your existing Next.js application, authentication, and deployment. Mount a Capable server in App Router handlers.
89
+
90
+ ```ts title="capable/server.ts"
91
+ import { createNextRouteHandlers } from "capable-kit/next";
92
+ import { mcp } from "capable-kit/mcp";
93
+ import { createServer, http, protocol } from "capable-kit/server";
94
+ import definition from "../capable.app";
95
+
96
+ const server = createServer(definition, {
97
+ mounts: [protocol(), http(), mcp()],
98
+ });
99
+
100
+ export const { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } =
101
+ createNextRouteHandlers(server.fetch);
102
+ ```
103
+
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.
105
+
106
+ </Tab>
107
+ <Tab label="Any Fetch host">
108
+
109
+ Use the server directly in Bun, Hono, H3, or another Fetch-compatible runtime.
110
+
111
+ ```ts title="server.ts"
112
+ import { mcp } from "capable-kit/mcp";
113
+ import { createServer, http, protocol } from "capable-kit/server";
114
+ import definition from "./capable.app";
115
+
116
+ const server = createServer(definition, {
117
+ mounts: [protocol(), http(), mcp()],
118
+ });
119
+
120
+ Bun.serve({ port: 3000, fetch: server.fetch });
121
+ ```
122
+
123
+ </Tab>
124
+ </Tabs>
125
+
126
+ ## 4. Use the app [#consuming]
127
+
128
+ Call the same capability in-process or through an endpoint exposed by the app above.
129
+
130
+ <Tabs id="introduction-consuming" label="Choose a consumer">
131
+ <Tab label="TypeScript">
132
+
133
+ ```ts title="app.ts"
134
+ import { app } from "./app";
135
+
136
+ const todo = await app.todos.create({ title: "Read the docs" });
137
+ ```
138
+
139
+ </Tab>
140
+ <Tab label="Capable CLI">
141
+
142
+ Run the app in this directory. The CLI imports it and calls it in-process.
143
+
144
+ ```sh title="terminal"
145
+ $ cap cli todos create --title "Read the docs"
146
+
147
+ {
148
+ "id": "1",
149
+ "title": "Read the docs"
150
+ }
151
+ ```
152
+
153
+ Point the CLI at an app that is already running or deployed.
61
154
 
62
155
  ```sh title="terminal"
63
- # The capability as a command
64
- cap cli todos create --title "Read the docs"
156
+ $ cap cli --app http://localhost:3000 todos create --title "Read the docs"
157
+ ```
158
+
159
+ </Tab>
160
+ <Tab label="HTTP">
65
161
 
66
- # The same capability as a derived HTTP route
67
- curl -X POST localhost:3000/api/todos/create \
162
+ ```sh title="terminal"
163
+ # Against a host that mounts http():
164
+ $ curl -X POST http://localhost:3000/api/todos/create \
68
165
  -H 'content-type: application/json' \
69
166
  -d '{"title":"Read the docs"}'
70
167
  ```
71
168
 
72
- That one file is also an MCP endpoint at `/mcp`, so an agent can connect and call `todos__create` with the same input schema. Every surface reads the same tree and contracts, so one capability shows up consistently everywhere:
169
+ </Tab>
170
+ <Tab label="MCP">
73
171
 
74
- | Surface | What todos.create becomes |
75
- | --- | --- |
76
- | TypeScript | `await app.todos.create({ title })` |
77
- | HTTP | `POST /api/todos/create` |
78
- | OpenAPI | `/openapi.json` |
79
- | CLI | `todos create --title "..."` |
80
- | MCP | `todos__create` |
81
- | React Query | `query.todos.create.mutationOptions()` |
172
+ Connect any Streamable HTTP MCP client to `http://localhost:3000/mcp`. It discovers `todos__create` with the same input schema.
82
173
 
83
- Nothing is exposed implicitly. A surface exists because you mounted it, and you can narrow the tree per boundary with `selectApp()`.
174
+ ```json title="tools/call params"
175
+ {
176
+ "name": "todos__create",
177
+ "arguments": { "title": "Read the docs" }
178
+ }
179
+ ```
84
180
 
85
- ## Use it programmatically [#programmatic]
181
+ </Tab>
182
+ <Tab label="AI SDK">
86
183
 
87
- No toolchain required. The app is an ordinary typed object — call it from a script, a server action, or a test, and the same validation, middleware, and errors apply.
184
+ ```ts title="agent.ts"
185
+ import { generateText } from "ai";
186
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
187
+ import { app } from "./app";
88
188
 
89
- ```ts title="app.ts"
90
- import { createApp } from "capable-kit";
91
- import definition from "./capable.app";
189
+ await generateText({
190
+ model: "anthropic/claude-sonnet-4.5",
191
+ tools: await createAiSdkTools(app),
192
+ prompt: "Create a todo to read the docs.",
193
+ });
194
+ ```
92
195
 
93
- const app = createApp(definition);
196
+ </Tab>
197
+ <Tab label="Eve">
94
198
 
95
- const todo = await app.todos.create({ title: "Read the docs" });
199
+ ```ts title="agent/tools/todos.ts"
200
+ import { createEveTools } from "capable-kit/eve";
201
+ import { app } from "../../app";
202
+
203
+ export default createEveTools(app);
204
+ // Eve resolves todos__create as a native tool at each step.
96
205
  ```
97
206
 
98
- To get a surface instead of a call, hand the same `app` to `createCli`, `createMcp`, or `createReactQuery`. A surface is just a function that takes an app.
207
+ </Tab>
208
+ <Tab label="React Query">
99
209
 
100
- To call a deployed app instead, swap `createApp` for `createRemoteApp`. Types come from a type-only import of the definition, so there is still no generated client, and every surface works the same over a transport.
210
+ ```tsx title="add-todo.tsx"
211
+ "use client";
101
212
 
102
- ```ts title="remote.ts"
213
+ import { createReactQuery } from "capable-kit/react-query";
214
+ import { useMutation } from "@tanstack/react-query";
103
215
  import { createRemoteApp } from "capable-kit";
104
216
  import { createHttpTransport } from "capable-kit/http";
105
217
  import type definition from "./capable.app";
106
218
 
107
- const app = createRemoteApp<typeof definition>(
108
- createHttpTransport({ url: "https://todos.example.com/_capable/" }),
219
+ const query = createReactQuery(
220
+ createRemoteApp<typeof definition>(
221
+ createHttpTransport({
222
+ url: () => new URL("/_capable/", window.location.origin),
223
+ }),
224
+ ),
109
225
  );
110
226
 
111
- // Identical call, executed on the server.
112
- const todo = await app.todos.create({ title: "Read the docs" });
113
- ```
114
-
115
- ## What Capable is not [#scope]
227
+ // Render this component beneath a QueryClientProvider.
228
+ export function AddTodo() {
229
+ const createTodo = useMutation(query.todos.create.mutationOptions());
116
230
 
117
- - **Not a replacement for your web framework.** Mount Capable in Next.js, Hono, H3, or any Fetch-compatible server — or run it as a standalone service.
118
- - **No generated client required.** Typed calls, commands, and tools are derived from the same capability definitions and schemas.
119
- - **Not tied to one protocol.** HTTP, the Capable transport, MCP, CLI, and in-process tools are projections of the same protocol-neutral capabilities.
231
+ return (
232
+ <button onClick={() => createTodo.mutate({ title: "Read the docs" })}>
233
+ Add todo
234
+ </button>
235
+ );
236
+ }
237
+ ```
120
238
 
121
- > **Early development**
122
- >
123
- > The documented APIs are implemented and tested, but breaking changes are expected.
239
+ </Tab>
240
+ </Tabs>
124
241
 
125
242
  ## Where to go next [#next]
126
243