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,14 +18,14 @@ A capability describes what something does. It says nothing about where it runs.
18
18
  ```ts title="apps.ts"
19
19
  import { createApp, createRemoteApp } from "capable-kit";
20
20
  import { createHttpTransport } from "capable-kit/http";
21
- import type definition from "./capable.app";
21
+ import definition, { type AppDefinition } from "./capable.app";
22
22
 
23
23
  // Runs here, in this process.
24
24
  const local = createApp(definition);
25
25
 
26
26
  // Runs there, behind someone else's context and policy.
27
- const remote = createRemoteApp<typeof definition>(
28
- createHttpTransport({ url: "https://todos.example.com/_capable/" }),
27
+ const remote = createRemoteApp<AppDefinition>(
28
+ createHttpTransport({ url: "https://todos.example.com/~capable/" }),
29
29
  );
30
30
 
31
31
  // The calling code cannot tell them apart.
@@ -43,7 +43,7 @@ export async function openTodos(app: typeof local | typeof remote) {
43
43
 
44
44
  > **No code generation**
45
45
  >
46
- > The consumer imports `type definition`only. Types are erased at build time, so no server code, no dependency, and no generated client ends up in the caller. Ship the definition's types in a package and any consumer can be typed against it.
46
+ > Export a named type derived from the definition, then import that type in remote consumers. The type is erased at build time, so no server code or generated client ends up in the caller. Ship the definition's types in a package and any consumer can be typed against it.
47
47
 
48
48
  ## What crosses the boundary [#boundary]
49
49
 
@@ -57,16 +57,25 @@ import definition from "./capable.app";
57
57
 
58
58
  export default createServer(definition, {
59
59
  context: ({ request }) => contextFromRequest(request),
60
- mounts: [protocol({ path: "/_capable" })],
60
+ mounts: [protocol()],
61
61
  });
62
62
  ```
63
63
 
64
64
  Because surfaces are built from the manifest, a remote app can produce the same [CLI](/surfaces/cli), [MCP tools](/surfaces/mcp), or [React Query](/surfaces/react-query) bindings as a local one. The projection never learns where execution happens.
65
65
 
66
+ The built-in transport preserves runtime values such as `Date` across inputs,
67
+ outputs, declared errors, and subscriptions. This rich encoding belongs only to
68
+ the private Capable protocol; authored HTTP routes and OpenAPI remain ordinary
69
+ JSON.
70
+
66
71
  ## Transports [#transports]
67
72
 
68
73
  HTTP is the transport that ships, but it is not privileged. `ApplicationTransport` is an interface with `manifest()`, `call()`, and `subscribe()`, so "remote" can mean a worker, a child process, a message queue, a browser extension port, or a stub in a test.
69
74
 
75
+ `subscribe()` resolves after the remote stream is opened, then returns its async
76
+ iterator. This keeps request and authorization failures separate from errors
77
+ emitted after streaming begins.
78
+
70
79
  ```ts title="worker-transport.ts"
71
80
  import type { ApplicationTransport } from "capable-kit/app";
72
81
 
@@ -75,33 +84,82 @@ export function createWorkerTransport(worker: Worker): ApplicationTransport {
75
84
  return {
76
85
  manifest: (options) => send(worker, { kind: "manifest" }, options),
77
86
  call: (call) => send(worker, { kind: "call", call }),
78
- subscribe: (call) => stream(worker, call),
87
+ subscribe: async (call) => stream(worker, call),
79
88
  };
80
89
  }
81
90
  ```
82
91
 
83
92
  ```ts title="main.ts"
84
93
  import { createRemoteApp } from "capable-kit";
85
- import type definition from "./capable.app";
94
+ import type { AppDefinition } from "./capable.app";
86
95
 
87
- const app = createRemoteApp<typeof definition>(
96
+ const app = createRemoteApp<AppDefinition>(
88
97
  createWorkerTransport(new Worker("./worker.js")),
89
98
  );
90
99
 
91
100
  await app.image.resize({ url, width: 512 }); // runs off the main thread
92
101
  ```
93
102
 
103
+ ### Custom value codecs [#custom-codecs]
104
+
105
+ You can replace the protocol's value encoding while keeping Capable's HTTP and
106
+ SSE framing. Give the codec a stable ID and configure the same codec semantics
107
+ on both peers. A missing or different ID is rejected explicitly.
108
+
109
+ ```ts title="codec.ts"
110
+ import { defineProtocolCodec } from "capable-kit/http";
111
+
112
+ export const codec = defineProtocolCodec({
113
+ id: "acme.protocol-values.v1",
114
+ encode: (value) => acmeValues.encode(value),
115
+ decode: (value) => acmeValues.decode(value),
116
+ });
117
+ ```
118
+
119
+ ```ts title="capable.server.ts"
120
+ import { createServer, protocol } from "capable-kit/server";
121
+ import definition from "./capable.app";
122
+ import { codec } from "./codec";
123
+
124
+ export default createServer(definition, {
125
+ mounts: [protocol({ codec })],
126
+ });
127
+ ```
128
+
129
+ ```ts title="client.ts"
130
+ import { createHttpTransport } from "capable-kit/http";
131
+ import { codec } from "./codec";
132
+
133
+ const transport = createHttpTransport({
134
+ url: "https://todos.example.com/~capable/",
135
+ codec,
136
+ });
137
+ ```
138
+
94
139
  ## Credentials and base URLs [#credentials]
95
140
 
96
141
  The transport owns everything about reaching the server, so capabilities never see tokens or hostnames. Both `url` and `headers` accept a function, which is resolved per request — enough for token refresh, environment switching, or per-tenant routing.
97
142
 
98
143
  ```ts title="transport.ts"
99
144
  createHttpTransport({
100
- url: () => `${process.env.API_URL}/_capable/`,
145
+ url: () => `${process.env.API_URL}/~capable/`,
101
146
  headers: async () => ({ authorization: `Bearer ${await accessToken()}` }),
102
147
  });
103
148
  ```
104
149
 
150
+ In a browser, a relative transport URL resolves against `window.location.origin`
151
+ when the request is made:
152
+
153
+ ```ts title="browser-transport.ts"
154
+ createHttpTransport({
155
+ url: "/~capable/",
156
+ });
157
+ ```
158
+
159
+ The same API also runs in servers, workers, CLIs, and tests, where no browser
160
+ origin exists. Those environments must pass an absolute URL or return one from
161
+ the `url` function.
162
+
105
163
  ## Choosing where a capability runs [#honesty]
106
164
 
107
165
  Calling is uniform; placement is still a decision you make in source. A remote call is a network call, with the latency and failure modes that implies, and it runs under the server's context and policy rather than yours. Capable does not pretend otherwise — it only removes the boilerplate between the two.
@@ -112,6 +170,6 @@ Calling is uniform; placement is still a decision you make in source. A remote c
112
170
  | It needs to work offline or without a server | It enforces authorization the client must not be trusted with |
113
171
  | Latency per call matters more than trust | The implementation must not ship to the caller |
114
172
 
115
- When one process needs both, merge them: [composition](/patterns/composition) combines a remote app and a local app into a single tree that dispatches each call to whichever app owns it.
173
+ When one process needs both, compose them: [composition](/patterns/composition) combines a remote app and a local app into a single tree that dispatches each call to whichever app owns it.
116
174
 
117
175
  </DocsPage>
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: "Subscriptions"
3
- description: "Give a read capability a second execution mode that emits complete replacements."
3
+ description: "Follow replacement snapshots or individual events with typed read capabilities."
4
4
  ---
5
5
 
6
6
  import { DocsPage, docMetadata } from "../../_components/docs-page";
@@ -9,11 +9,48 @@ export const metadata = docMetadata("/patterns/subscriptions", frontmatter);
9
9
 
10
10
  <DocsPage href="/patterns/subscriptions" frontmatter={frontmatter}>
11
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.
12
+ A `read` capability can subscribe to changing state or individual events. The operations you define determine its meaning:
13
13
 
14
- ## Add a subscriber [#define]
14
+ | Definition | Meaning |
15
+ | --- | --- |
16
+ | `handler` | One result |
17
+ | `handler` + `subscribe` | One result and a subscription yielding complete replacement snapshots |
18
+ | `subscribe` | Individual events, with no unary operation |
15
19
 
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.
20
+ ## Follow logs and events [#events]
21
+
22
+ Omit `handler` when each value is another event. No dummy unary result or initial event is required, and a stream may complete without yielding anything.
23
+
24
+ ```ts title="capabilities.ts"
25
+ import { capability } from "capable-kit";
26
+ import { z } from "zod";
27
+
28
+ const runCapability = capability.withContext<RunContext>();
29
+
30
+ export const logs = runCapability({
31
+ id: "runs.logs",
32
+ effect: "read",
33
+ input: z.object({ runId: z.string() }),
34
+ output: z.object({
35
+ at: z.date(),
36
+ level: z.enum(["info", "warn", "error"]),
37
+ message: z.string(),
38
+ }),
39
+ subscribe: ({ input, context, signal }) =>
40
+ context.runs.followLogs(input.runId, { signal }),
41
+ toPresentation: entry => `**${entry.level}** ${entry.message}`,
42
+ });
43
+ ```
44
+
45
+ Without an `output` schema, the event type is inferred from the subscriber's yielded values. With a schema, each yielded value is parsed before delivery; schema transforms also apply before `toPresentation` runs.
46
+
47
+ An event stream can emit a discriminated union, such as `started`, `progress`, and `completed` events from an existing job. For a progress bar that must immediately reflect current state when opened, use replacement snapshots instead.
48
+
49
+ ## Follow replacement state [#define]
50
+
51
+ Keep `handler` alongside `subscribe` when each update describes the entire current value. Both operations share one ID, input, output, errors, middleware, and presentation.
52
+
53
+ `watchQuery()` reads a snapshot, then re-reads 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
54
 
18
55
  ```ts title="capabilities.ts"
19
56
  import { capability, watchQuery } from "capable-kit";
@@ -35,53 +72,63 @@ export const listTodos = todoCapability({
35
72
  });
36
73
  ```
37
74
 
38
- An async generator works too when there is nothing to watch:
75
+ The subscriber supplies its own initial snapshot. Subscribing does not invoke the unary handler first. A replacement stream that completes without yielding a snapshot is an error.
39
76
 
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
- ```
77
+ Adding a handler to an event-only capability changes its contract to replacement state. Define separate capabilities when you need a snapshot and unrelated events.
48
78
 
49
- ## Consume it [#consume]
79
+ ## Consume a subscription [#consume]
50
80
 
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.
81
+ `subscribe()` takes a capability reference from an app, keeping app navigation free of extra method names. It works against local, remote, composed, and selected apps.
52
82
 
53
83
  ```ts title="watch.ts"
54
84
  import { subscribe } from "capable-kit";
55
85
 
56
- const updates = subscribe(app.todos.list, {}, { signal });
86
+ for await (const entry of subscribe(app.runs.logs, { runId }, { signal })) {
87
+ appendLog(entry); // another individual event
88
+ }
57
89
 
58
- for await (const todos of updates) {
59
- render(todos); // a complete, validated list every time
90
+ for await (const todos of subscribe(app.todos.list, {}, { signal })) {
91
+ render(todos); // a complete replacement list
60
92
  }
61
93
  ```
62
94
 
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.
95
+ Event references have no unary call signature: `app.runs.logs({ runId })` is a type error, and untyped unary calls fail with `METHOD_NOT_ALLOWED`. `app.todos.list()` remains callable.
64
96
 
65
- ## Over the wire [#transport]
97
+ Input is parsed once. Every emitted item is validated against the output schema, middleware encloses the iterator lifetime, and cancellation aborts the subscriber's signal before cleanup. Sources must observe that signal to release pending work.
66
98
 
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.
99
+ ## Present each value [#presentation]
100
+
101
+ `toPresentation` describes one validated value. Typed `subscribe()` consumers receive canonical values without materializing presentation. A presentation-aware surface can request canonical values plus their derived presentations.
102
+
103
+ The CLI appends each event's presentation. For replacement subscriptions, it redraws the current snapshot in a terminal and separates snapshots in piped output. An empty presentation falls back to canonical output; it does not hide an event.
68
104
 
69
105
  ```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
106
+ # Events stream automatically; no --watch is needed.
107
+ radar runs logs --run-id run_123
108
+
109
+ # Each canonical event becomes one JSON line; presentation is not generated.
110
+ radar runs logs --run-id run_123 --json
111
+
112
+ # Replacement snapshots still use --watch.
113
+ radar todos list --watch
75
114
  ```
76
115
 
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.
116
+ ## Over the wire [#transport]
117
+
118
+ The Capable transport encodes subscriptions as server-sent events at `POST /~capable/subscribe/:id`, using its rich-value codec for events, replacements, and errors.
119
+
120
+ Replacement streams preserve ordinary HTTP errors before the first snapshot; subsequent failures arrive as typed SSE error frames. Event streams establish without waiting for an event. Before committing the response, Capable parses input, resolves context, enters middleware, invokes the subscriber, and verifies its AsyncIterable result. Failures in that preparation retain their HTTP status. An initial SSE comment then flushes the response without creating a canonical event.
121
+
122
+ An async-generator body starts only when its iterator is pulled. Failures, authorization, or listener setup inside that body therefore happen after establishment; failures arrive as typed SSE error frames. Put request rejection in middleware when it must determine the HTTP status. Listener readiness requires an application-level handshake if it must be known before returning the response.
123
+
124
+ Manifest protocol `capable.capabilities.v4` identifies each capability with `execution: "unary"`, `"live"`, or `"events"`. Upgrade clients and servers together and regenerate bundled manifests when migrating from v3. The value codec remains `capable.rich-json.v1`.
125
+
126
+ ## Other surfaces and scope [#scope]
78
127
 
79
- ## What this is not [#scope]
128
+ [React Query](/surfaces/react-query) and [SWR](/surfaces/swr) expose replacement subscriptions as state updates. Event-only capabilities are excluded from those typed projections and from automatic unary HTTP/OpenAPI, MCP, AI SDK, and Eve tools. Explicit unsupported HTTP or tool metadata is rejected; use `false` to disable that surface. Unary tools can still call a replacement capability's handler.
80
129
 
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.
130
+ Subscriptions observe work and require `effect: "read"`. A command that starts work and streams results from that same invocation is outside this API.
84
131
 
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.
132
+ Buffering, replay, resumption, delivery guarantees, and reconnection policy remain application responsibilities. Starting a job and then subscribing can miss early events unless the backing service retains them. A pull-based iterator alone does not guarantee lossless capture of a push-based event source.
86
133
 
87
134
  </DocsPage>
@@ -44,13 +44,16 @@ Capable works two ways: as its own service, or embedded in an app you already ha
44
44
  handler: ({ input }) => ({ id: "1", title: input.title }),
45
45
  });
46
46
 
47
- export default defineApp({
47
+ const definition = defineApp({
48
48
  name: "Todos",
49
49
  version: "1.0.0",
50
50
  capabilities: {
51
51
  todos: { list: listTodos, create: createTodo },
52
52
  },
53
53
  });
54
+
55
+ export type AppDefinition = typeof definition;
56
+ export default definition;
54
57
  ```
55
58
 
56
59
  > 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.
@@ -65,7 +68,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
65
68
  ◆ Todos 1.0.0
66
69
 
67
70
  Local http://localhost:3000
68
- Capable /_capable
71
+ Capable /~capable
69
72
  HTTP /api
70
73
  OpenAPI /openapi.json
71
74
  MCP /mcp
@@ -167,18 +170,17 @@ Capable works two ways: as its own service, or embedded in an app you already ha
167
170
 
168
171
  7. ### Call it from another process
169
172
 
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.
173
+ Swap `createApp()` for `createRemoteApp()` and the calls are identical—only placement changed. The manifest is discovered lazily on first use, and types come from the named definition type.
171
174
 
172
175
  ```ts title="remote.ts"
173
176
  import { createRemoteApp } from "capable-kit";
174
177
  import { createHttpTransport } from "capable-kit/http";
175
- import type definition from "./capable.app";
178
+ import type { AppDefinition } from "./capable.app";
176
179
 
177
180
  // 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>(
181
+ const app = createRemoteApp<AppDefinition>(
180
182
  createHttpTransport({
181
- url: process.env.CAPABLE_URL ?? "http://localhost:3000/_capable/",
183
+ url: process.env.CAPABLE_URL ?? "http://localhost:3000/~capable/",
182
184
  headers: () => ({ authorization: `Bearer ${process.env.TOKEN}` }),
183
185
  }),
184
186
  );
@@ -203,7 +205,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
203
205
 
204
206
  > **Remote apps are apps**
205
207
  >
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).
208
+ > A remote app can be combined with a local one using `composeApps()`, so one command tree can mix capabilities that run on the server with capabilities that must run here. See [Composition](/patterns/composition).
207
209
 
208
210
  8. ### Build for production
209
211
 
@@ -254,12 +256,15 @@ Capable works two ways: as its own service, or embedded in an app you already ha
254
256
  handler: ({ input }) => ({ id: "1", title: input.title }),
255
257
  });
256
258
 
257
- export default defineApp({
259
+ const definition = defineApp({
258
260
  name: "Todos",
259
261
  capabilities: {
260
262
  todos: { list: listTodos, create: createTodo },
261
263
  },
262
264
  });
265
+
266
+ export type AppDefinition = typeof definition;
267
+ export default definition;
263
268
  ```
264
269
 
265
270
  > Output types are inferred from handlers. Portable output schemas, effects, descriptions, errors, middleware, and surface metadata are opt-in.
@@ -308,7 +313,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
308
313
  // app/api/[[...path]]/route.ts
309
314
  export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
310
315
 
311
- // app/%5Fcapable/[[...path]]/route.ts — %5F keeps _capable out of Next's private folders
316
+ // app/~capable/[[...path]]/route.ts
312
317
  export { GET, POST } from "@/capable/server";
313
318
  ```
314
319
 
@@ -347,16 +352,16 @@ Capable works two ways: as its own service, or embedded in an app you already ha
347
352
 
348
353
  6. ### Call from React Query
349
354
 
350
- `capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/_capable`.
355
+ `capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/~capable`.
351
356
 
352
357
  ```ts title="app/query.ts"
353
358
  import { createRemoteApp } from "capable-kit";
354
359
  import { createHttpTransport } from "capable-kit/http";
355
360
  import { createReactQuery } from "capable-kit/react-query";
356
- import type definition from "../capable/app";
361
+ import type { AppDefinition } from "../capable/app";
357
362
 
358
- const app = createRemoteApp<typeof definition>(
359
- createHttpTransport({ url: "/_capable/" }),
363
+ const app = createRemoteApp<AppDefinition>(
364
+ createHttpTransport({ url: "/~capable/" }),
360
365
  );
361
366
 
362
367
  export const query = createReactQuery(app);
@@ -11,6 +11,14 @@ export const metadata = docMetadata("/reference/packages", frontmatter);
11
11
 
12
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
13
 
14
+ ## Changes and upgrades [#changes]
15
+
16
+ Read the [versioned changelog](https://github.com/vercel-labs/capable/blob/main/packages/capable/CHANGELOG.md)
17
+ for features, fixes, and breaking changes. It also ships at
18
+ `node_modules/capable-kit/CHANGELOG.md`. When upgrading, read the target version’s
19
+ changelog and apply entries after your installed version through your target
20
+ version, oldest first. Repository main may be ahead of your installed version.
21
+
14
22
  ## The root entry point [#root]
15
23
 
16
24
  `capable-kit` is deliberately limited to authoring and composing apps. Everything you need to define capabilities lives here.
@@ -26,7 +34,8 @@ import {
26
34
  watchQuery, // snapshot + invalidation subscriber
27
35
  createApp, // definition + context -> callable app
28
36
  createRemoteApp, // transport + definition type -> callable app
29
- mergeApps, // combine apps
37
+ composeApps, // place apps, subtrees, and individual references
38
+ customize, // customize a reference for presentation
30
39
  selectApp, // narrow an app
31
40
  subscribe, // iterate replacements
32
41
  executeCapability, // run one capability without an app
@@ -39,7 +48,7 @@ import {
39
48
  | --- | --- |
40
49
  | `capable-kit` | Capability authoring, app definitions, executable and remote apps, composition, and the capable command |
41
50
  | `capable-kit/server` | `createServer()` plus the `protocol()` and `http()` mounts |
42
- | `capable-kit/http` | Capable transport client and server encoding: `createHttpTransport()`, `createHttpHandler()` |
51
+ | `capable-kit/http` | Capable transport and HTTP projection: `createHttpTransport()`, `createHttpHandler()`, `defineProtocolCodec()` |
43
52
  | `capable-kit/cli` | `createCli()` |
44
53
  | `capable-kit/mcp` | `createMcp()` and the `mcp()` server mount |
45
54
  | `capable-kit/eve` | `createEveTools()` |
@@ -60,14 +69,52 @@ import {
60
69
  | --- | --- | --- |
61
70
  | `capability()` | `capability(config)` | `capability<Context>()` or `capability.withContext<Context>()` binds a context type |
62
71
  | `present` | `present.table(), .image(), .file()` | Portable presentation parts for `toPresentation` |
63
- | `defineApp()` | `defineApp({ name, version, capabilities })` | Immutable definition, no context |
72
+ | `defineApp()` | `defineApp({ name, version, capabilities, middleware, errors })` | Immutable definition, no context |
64
73
  | `group()` | `group({ middleware, errors, meta, capabilities })` | Anonymous decorated subtree |
65
74
  | `createApp()` | `createApp(definition)` | Callable tree; context options exist only when declared |
66
- | `createRemoteApp()` | `createRemoteApp<typeof definition>(transport)` | Lazy, transport-backed remote placement |
67
- | `mergeApps()` | `mergeApps(a, b, ...)` | Root-tree merge, dispatch by id |
75
+ | `createRemoteApp()` | `createRemoteApp<AppDefinition>(transport)` | Lazy, transport-backed remote placement |
76
+ | `composeApps()` | `composeApps(a, { tools: b.plugins })` | Place whole Apps, executable subtrees, or individual references; dispatch by ID |
77
+ | `customize()` | `customize(app.status, { description, meta: { cli: { positional: ["id"] } } })` | Immutable title, description, and CLI/MCP overrides for a composition entry |
68
78
  | `selectApp()` | `selectApp(app, { include, exclude })` | Exclude wins over include |
69
79
  | `subscribe()` | `subscribe(app.todos.list, input, { signal })` | Async iterator of replacements |
70
80
  | `executeCapability()` | `executeCapability(capability, { input, context, signal })` | No app tree, no group behaviour |
71
81
  | `createServer()` | `createServer(definition, { context, mounts, middleware })` | Returns `{ fetch }` |
72
82
 
83
+ ## Custom surface display [#custom-display]
84
+
85
+ Custom surfaces can read placement settings without replacing the source
86
+ contract used for execution or policy:
87
+
88
+ ```ts
89
+ import {
90
+ flattenManifestCapabilities, getAppRuntime, getCapabilityDisplay,
91
+ } from "capable-kit/app";
92
+
93
+ const manifest = await getAppRuntime(app).manifest();
94
+ const help = flattenManifestCapabilities(manifest.capabilities).map(capability => ({
95
+ id: capability.id,
96
+ path: capability.path,
97
+ ...getCapabilityDisplay(capability),
98
+ }));
99
+ ```
100
+
101
+ `getCapabilityDisplay()` returns the effective title, description, and metadata.
102
+ To opt a custom surface into `customize()` metadata, augment the global
103
+ `CapableCustomizationMeta` interface in the surface's types and explicitly read
104
+ that namespace when compiling its display. This registry is separate from the
105
+ open metadata on authored capabilities.
106
+
107
+ ```ts
108
+ // In a custom surface module:
109
+ declare global {
110
+ interface CapableCustomizationMeta {
111
+ readonly inspector?: { readonly label?: string };
112
+ }
113
+ }
114
+
115
+ const reference = customize(app.status, {
116
+ meta: { inspector: { label: "Instance status" } },
117
+ });
118
+ ```
119
+
73
120
  </DocsPage>
@@ -21,7 +21,12 @@ const deleteTodo = todo({
21
21
  meta: {
22
22
  http: { method: "DELETE", route: "/:todoId", status: 200 },
23
23
  cli: { positional: ["todoId"] },
24
- mcp: { name: "todos_delete" },
24
+ mcp: {
25
+ name: "todos_delete",
26
+ idempotentHint: true,
27
+ openWorldHint: false,
28
+ icons: [{ src: "https://example.com/delete.svg" }],
29
+ },
25
30
  aiSdk: { name: "todos_delete", strict: true },
26
31
  eve: false,
27
32
  },
@@ -43,7 +48,7 @@ const todos = group({
43
48
  | --- | --- | --- |
44
49
  | `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
50
  | `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 `__`. |
51
+ | `mcp` | `false \| { name, icons, idempotentHint, openWorldHint }` | Renames, decorates, or hides the MCP tool. Default name is the app path joined with `__`; the canonical Capability ID remains available in tool `_meta`. |
47
52
  | `eve` | `false \| { name }` | Same, for native in-process Eve tools. |
48
53
  | `aiSdk` | `false \| { name, strict }` | Renames, constrains, or hides an AI SDK tool. |
49
54
 
@@ -31,7 +31,7 @@ pnpm dev
31
31
  | Command | Description |
32
32
  | --- | --- |
33
33
  | `init` | Creates capable.app.ts and a runnable package.json in the current directory or a supplied directory. Existing fields and Capable App entries are never overwritten. |
34
- | `dev` | Starts a watching development server. Without a capable.server.ts it serves /\_capable, /api, /openapi.json, and /mcp, plus a read-only capability index at /. With one, it wraps the authored server and adds only the index. |
34
+ | `dev` | Starts a watching development server. Without a capable.server.ts it serves /~capable, /api, /openapi.json, and /mcp, plus a read-only capability index at /. With one, it wraps the authored server and adds only the index. |
35
35
  | `build` | Builds the project into `.output`. Presets are Nitro deployment presets, for example `node-server` or `vercel`. |
36
36
  | `preview` | Runs a previously built `node-server` output. Other presets do not produce a locally runnable command. |
37
37
  | `cli` | Runs the app's derived command tree without writing a CLI entry point. |
@@ -65,7 +65,7 @@ cap cli --app ./ todos list
65
65
  cap cli --app https://todos.example.com todos list
66
66
  ```
67
67
 
68
- A local project runs in-process, so no development server is needed. A URL is treated as the root of a Capable server and reached through `/_capable/`. Both produce the same commands and help, because both read the same manifest.
68
+ A local project runs in-process, so no development server is needed. A URL is treated as the root of a Capable server and reached through `/~capable/`. Both produce the same commands and help, because both read the same manifest.
69
69
 
70
70
  | Option | Applies to | Meaning |
71
71
  | --- | --- | --- |
@@ -74,10 +74,10 @@ Conversion reads the App manifest rather than the original live schema objects,
74
74
  import { createRemoteApp } from "capable-kit";
75
75
  import { createAiSdkTools } from "capable-kit/ai-sdk";
76
76
  import { createHttpTransport } from "capable-kit/http";
77
- import type definition from "./capable.app";
77
+ import type { AppDefinition } from "./capable.app";
78
78
 
79
- const app = createRemoteApp<typeof definition>(
80
- createHttpTransport({ url: "https://todos.example.com/_capable/" }),
79
+ const app = createRemoteApp<AppDefinition>(
80
+ createHttpTransport({ url: "https://todos.example.com/~capable/" }),
81
81
  );
82
82
 
83
83
  export const tools = await createAiSdkTools(app);
@@ -52,6 +52,39 @@ todo --help
52
52
 
53
53
  `run()` resolves to an exit code: `0` on success, `1` for a failed capability, and `2` for a usage error.
54
54
 
55
+ For a single-operation CLI, map the Capability to an empty command path:
56
+
57
+ ```ts
58
+ capability({
59
+ id: "analysis.url",
60
+ input: z.object({ url: z.string() }),
61
+ meta: { cli: { command: [], positional: ["url"] } },
62
+ handler: ({ input }) => analyzeURL(input.url),
63
+ });
64
+ // pnpm cli vercel.com
65
+ ```
66
+
67
+ Bare invocation and `--help` keep the app name and command listing, with the root
68
+ Capability's arguments and options underneath. `--json`
69
+ or `--watch` selects execution even without positional arguments, applying schema
70
+ defaults or reporting missing required input. Only one Capability may map to the
71
+ root; longer subcommands still take precedence.
72
+
73
+ Pass markdansi's `RenderOptions` directly through `markdown` to customize terminal
74
+ presentations:
75
+
76
+ ```ts
77
+ createCli(app, {
78
+ invocationName: "pnpm cli",
79
+ markdown: { codeBox: false, tableBorder: "none", tableDense: true },
80
+ });
81
+ ```
82
+
83
+ These options are forwarded unchanged for ordinary and watched presentations in
84
+ a TTY. `markdown.color` and `markdown.width`, when supplied, override the CLI's
85
+ color and columns defaults for presentation rendering. Redirected output remains
86
+ Markdown, and `--json` returns canonical output.
87
+
55
88
  ## How commands are derived [#mapping]
56
89
 
57
90
  | Authored | Becomes |
@@ -107,11 +140,11 @@ A remote app produces an identical command tree, because help and arguments are
107
140
  import { createRemoteApp } from "capable-kit";
108
141
  import { createCli } from "capable-kit/cli";
109
142
  import { createHttpTransport } from "capable-kit/http";
110
- import type definition from "./capable.app";
143
+ import type { AppDefinition } from "./capable.app";
111
144
 
112
- const remote = createRemoteApp<typeof definition>(
145
+ const remote = createRemoteApp<AppDefinition>(
113
146
  createHttpTransport({
114
- url: process.env.CAPABLE_URL ?? "http://localhost:3000/_capable/",
147
+ url: process.env.CAPABLE_URL ?? "http://localhost:3000/~capable/",
115
148
  headers: () => ({ authorization: `Bearer ${readToken()}` }),
116
149
  }),
117
150
  );
@@ -135,4 +168,15 @@ cap cli --app ./ todos list
135
168
  cap cli --app https://todos.example.com todos list
136
169
  ```
137
170
 
171
+ ## Stream events and live state [#subscriptions]
172
+
173
+ A capability with only `subscribe` streams individual events by default. Readable output appends each event's presentation, with canonical output as the fallback. `--json` emits one canonical event per line without generating presentations.
174
+
175
+ ```sh title="terminal"
176
+ radar runs logs --run-id run_123
177
+ radar runs logs --run-id run_123 --json
178
+ ```
179
+
180
+ Capabilities with both `handler` and `subscribe` keep their unary command and use `--watch` for replacement snapshots. See [Subscriptions](/patterns/subscriptions).
181
+
138
182
  </DocsPage>