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.
- package/README.md +21 -3
- package/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +1 -1
- package/dist/app.d.mts +1 -1
- package/dist/app.mjs +1 -1
- package/dist/bin.mjs +17 -16
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +2 -2
- package/dist/eve.d.mts +1 -1
- package/dist/eve.mjs +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-BB5ogMv-.d.mts → index-Be8-UVBC.d.mts} +49 -8
- package/dist/{index-B2ru1zGQ.d.mts → index-D2CRRUzH.d.mts} +6 -6
- package/dist/{index-B_I9n6gN.d.mts → index-Dbc4g9WM.d.mts} +4 -3
- package/dist/{index-AqKbVZ8Z.d.mts → index-DwXlaTXI.d.mts} +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +2 -2
- package/dist/mcp.mjs +1 -1
- package/dist/{mount--YHrgRHJ.mjs → mount-xvMsjz1B.mjs} +65 -27
- package/dist/mount-xvMsjz1B.mjs.map +1 -0
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +6 -6
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +2 -2
- package/dist/{src-DX2xrplP.mjs → src-BF70JLxI.mjs} +24 -13
- package/dist/src-BF70JLxI.mjs.map +1 -0
- package/dist/{src-3UaBqI8H.mjs → src-C2MGIlT0.mjs} +17 -18
- package/dist/src-C2MGIlT0.mjs.map +1 -0
- package/dist/{src-DtSY5fzY.mjs → src-CDxL6w3d.mjs} +7 -7
- package/dist/{src-DtSY5fzY.mjs.map → src-CDxL6w3d.mjs.map} +1 -1
- package/dist/{src-BjBxOv7x.mjs → src-Db6-XSnU.mjs} +20 -12
- package/dist/src-Db6-XSnU.mjs.map +1 -0
- package/dist/{src-B53ZbNtC.mjs → src-DdV82An-.mjs} +137 -3
- package/dist/src-DdV82An-.mjs.map +1 -0
- package/dist/{subscription-McaLyHM2.d.mts → subscription-Bq792Ad2.d.mts} +2 -2
- package/docs/CONTEXT.md +113 -0
- package/docs/README.md +28 -0
- package/docs/internal/README.md +16 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +24 -0
- package/docs/internal/architecture.md +134 -0
- package/docs/internal/capability-first-model.md +160 -0
- package/docs/internal/implementation-friction.md +705 -0
- package/docs/internal/why-capable.md +94 -0
- package/docs/site/capable-orpc-and-trpc.mdx +133 -0
- package/docs/site/concepts/apps.mdx +217 -0
- package/docs/site/concepts/architecture.mdx +83 -0
- package/docs/site/concepts/capabilities.mdx +249 -0
- package/docs/site/concepts/errors.mdx +93 -0
- package/docs/site/concepts/presentations.mdx +161 -0
- package/docs/site/hosting/any-fetch-host.mdx +74 -0
- package/docs/site/hosting/next-js.mdx +77 -0
- package/docs/site/hosting/standalone-server.mdx +94 -0
- package/docs/site/introduction.mdx +259 -0
- package/docs/site/patterns/composition.mdx +142 -0
- package/docs/site/patterns/remote-apps.mdx +117 -0
- package/docs/site/patterns/subscriptions.mdx +87 -0
- package/docs/site/quickstart.mdx +386 -0
- package/docs/site/reference/packages-and-entry-points.mdx +72 -0
- package/docs/site/reference/surface-metadata.mdx +84 -0
- package/docs/site/reference/the-cap-cli.mdx +81 -0
- package/docs/site/surfaces/ai-sdk.mdx +94 -0
- package/docs/site/surfaces/cli.mdx +138 -0
- package/docs/site/surfaces/eve.mdx +121 -0
- package/docs/site/surfaces/http-and-openapi.mdx +111 -0
- package/docs/site/surfaces/mcp.mdx +110 -0
- package/docs/site/surfaces/react-query.mdx +80 -0
- package/docs/site/surfaces/typescript.mdx +123 -0
- package/docs/site/surfaces.mdx +78 -0
- package/docs/site/why-capable.mdx +99 -0
- package/package.json +13 -3
- package/src/index.test.ts +1 -0
- package/src/index.ts +5 -1
- package/src/package.test.ts +102 -0
- package/dist/mount--YHrgRHJ.mjs.map +0 -1
- package/dist/src-3UaBqI8H.mjs.map +0 -1
- package/dist/src-B53ZbNtC.mjs.map +0 -1
- package/dist/src-BjBxOv7x.mjs.map +0 -1
- package/dist/src-DX2xrplP.mjs.map +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
Dependencies point inward. Surfaces and hosts depend on the semantic packages;
|
|
4
|
+
`@capable/core` depends on none of them.
|
|
5
|
+
|
|
6
|
+
```text
|
|
7
|
+
Capability definitions
|
|
8
|
+
│
|
|
9
|
+
▼
|
|
10
|
+
App Definition ──────────────► createServer(definition, { mounts })
|
|
11
|
+
│ ├─ protocol() /_capable/* manifest, call, subscribe
|
|
12
|
+
│ ├─ http() /api/* routes + /openapi.json
|
|
13
|
+
│ └─ mcp() /mcp Streamable HTTP tools
|
|
14
|
+
│ │
|
|
15
|
+
├─ createApp(definition) └─► Next / Nitro / Hono / H3 / Fetch host
|
|
16
|
+
│ └─ context provider only when declared
|
|
17
|
+
└─ createRemoteApp(transport)
|
|
18
|
+
│ lazy manifest discovery
|
|
19
|
+
│
|
|
20
|
+
mergeApps / selectApp
|
|
21
|
+
│
|
|
22
|
+
▼
|
|
23
|
+
App (typed callable object tree)
|
|
24
|
+
│
|
|
25
|
+
┌─────────────┼──────────────┬────────────────────┐
|
|
26
|
+
▼ ▼ ▼ ▼
|
|
27
|
+
direct calls createCli await createMcp await createAiSdkTools
|
|
28
|
+
createEveTools
|
|
29
|
+
createReactQuery
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Package responsibilities
|
|
33
|
+
|
|
34
|
+
| Package | Owns |
|
|
35
|
+
| ------------------- | -------------------------------------------------------------------- |
|
|
36
|
+
| `capable` | Public facade and the user-installed `cap` command |
|
|
37
|
+
| `@capable/core` | Authoring, tree composition, validation, middleware, errors, execution |
|
|
38
|
+
| `@capable/app` | Callable local and remote Apps, merge, selection, manifests |
|
|
39
|
+
| `@capable/fetch` | Capable transport encoding and the HTTP/OpenAPI projection |
|
|
40
|
+
| `@capable/server` | Fetch server composition and protocol mounts |
|
|
41
|
+
| `@capable/cli` | Command derivation, parsing, help, and rendering |
|
|
42
|
+
| `@capable/mcp` | Tool derivation and the Streamable HTTP mount |
|
|
43
|
+
| `@capable/ai-sdk` | Typed AI SDK v7 tool projection |
|
|
44
|
+
| `@capable/eve` | Native in-process Eve tool projection |
|
|
45
|
+
| `@capable/react-query` | Query keys, query options, mutations, live queries |
|
|
46
|
+
| `@capable/next` | Method-export translation for the App Router |
|
|
47
|
+
| `@capable/nitro-host` | Development server, build, and preview for standalone projects |
|
|
48
|
+
| `@capable/toolchain` | Internal command implementation and project discovery |
|
|
49
|
+
|
|
50
|
+
Core follows the two semantic concepts directly: `capability.ts` owns authoring
|
|
51
|
+
and the complete execution lifecycle, `application.ts` owns Groups, App
|
|
52
|
+
Definitions, placement, and uniqueness. Keeping execution beside authoring
|
|
53
|
+
preserves the Capability seam from [ADR-0001](./adr/0001-capability-is-the-semantic-boundary.md).
|
|
54
|
+
|
|
55
|
+
The App package is transport-neutral: `runtime.ts` owns callable local and
|
|
56
|
+
remote Apps, `composition.ts` owns merge and selection, `manifest.ts` owns
|
|
57
|
+
manifest construction and tree invariants, and `index.ts` is only a facade.
|
|
58
|
+
|
|
59
|
+
## Lazy transport discovery
|
|
60
|
+
|
|
61
|
+
The external transport may perform I/O to discover an Application:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
interface ApplicationTransport {
|
|
65
|
+
manifest(): Promise<ApplicationManifest>;
|
|
66
|
+
call({ id, input, signal, presentation }): Promise<{
|
|
67
|
+
output: unknown;
|
|
68
|
+
presentation?: readonly PresentationPart[];
|
|
69
|
+
}>;
|
|
70
|
+
subscribe({ id, input, signal, presentation }): AsyncIterableIterator<{
|
|
71
|
+
output: unknown;
|
|
72
|
+
presentation?: readonly PresentationPart[];
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`createRemoteApp(transport)` returns synchronously without performing I/O.
|
|
78
|
+
The first direct call or manifest-dependent projection resolves, validates, and
|
|
79
|
+
caches the manifest. This keeps browser module evaluation free of network work
|
|
80
|
+
while preserving one discovery request per App.
|
|
81
|
+
|
|
82
|
+
The server decides whether that protocol is exposed remotely. Direct App calls
|
|
83
|
+
never manufacture Requests. Apps keep the runtime behind an internal symbol so
|
|
84
|
+
authored Capability keys cannot collide with `manifest` or `call`.
|
|
85
|
+
|
|
86
|
+
The optional `presentation` request flag prevents expensive representations,
|
|
87
|
+
such as base64 images, from crossing this boundary unless the consuming surface
|
|
88
|
+
will use them. The result remains canonical output plus an optional derived
|
|
89
|
+
view; presentation never replaces the output contract.
|
|
90
|
+
|
|
91
|
+
Its HTTP encoding lives in `@capable/fetch` — `createHttpTransport()` and
|
|
92
|
+
`createProtocolHandler()` — giving request, response, and SSE encoding one home,
|
|
93
|
+
separate from authored HTTP APIs and from transport-neutral App semantics.
|
|
94
|
+
|
|
95
|
+
Subscriptions are encoded at `POST /_capable/subscribe/:id` as SSE. Errors before
|
|
96
|
+
the first replacement are ordinary HTTP errors; a terminal error after streaming
|
|
97
|
+
began uses a typed SSE error frame.
|
|
98
|
+
|
|
99
|
+
## Composition
|
|
100
|
+
|
|
101
|
+
`mergeApps(a, b)` merges root trees rather than building a pipeline. It returns
|
|
102
|
+
synchronously and resolves its inputs together when its manifest is first
|
|
103
|
+
needed. Path and ID conflicts therefore fail at that discovery boundary, before
|
|
104
|
+
the first Capability is dispatched. Namespaces belong in the authored App
|
|
105
|
+
Definition:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const remote = createRemoteApp<typeof serverDefinition>(transport);
|
|
109
|
+
const app = mergeApps(
|
|
110
|
+
remote,
|
|
111
|
+
createApp(localDefinition, { context: createLocalContext }),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
await app.local.login({ token });
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Surface compilation
|
|
118
|
+
|
|
119
|
+
HTTP compilation is independent of the other surfaces. Its default route is the
|
|
120
|
+
Application path, with decorated Group prefixes replacing their corresponding
|
|
121
|
+
segment. `effect: "read"` derives GET; anything else derives POST. `meta.http`
|
|
122
|
+
disables or overrides a route, and `requireExplicitRoutes: true` turns implicit
|
|
123
|
+
routes into a startup error.
|
|
124
|
+
|
|
125
|
+
The CLI reads the Capable manifest, derives commands from the same object tree,
|
|
126
|
+
maps configured top-level scalar fields to positional arguments, and maps the
|
|
127
|
+
rest to flags. It never needs to understand the application's HTTP routes, which
|
|
128
|
+
is why local and remote CLIs are identical.
|
|
129
|
+
|
|
130
|
+
The AI SDK projection awaits the manifest it needs to enumerate JSON
|
|
131
|
+
Schema-backed function tools, then dispatches execution through the App runtime.
|
|
132
|
+
Its mapped return type follows the authored Capability tree retained by the App,
|
|
133
|
+
preserving literal tool names and Capability input/output types for typed local
|
|
134
|
+
and remote Apps.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# The capability-first model
|
|
2
|
+
|
|
3
|
+
Normative rules of the model. Guides and examples live in the docs site; this
|
|
4
|
+
file records what must remain true. Terminology is defined in
|
|
5
|
+
[CONTEXT.md](../CONTEXT.md).
|
|
6
|
+
|
|
7
|
+
## Identity and placement
|
|
8
|
+
|
|
9
|
+
- A Capability ID is canonical execution identity. It is unique within an
|
|
10
|
+
Application and must not change when a Capability moves.
|
|
11
|
+
- The Application path (`todos.delete`) is navigational structure. Surfaces may
|
|
12
|
+
derive routes, commands, and tool names from it.
|
|
13
|
+
- Application and Group collections are named object trees, never arrays, so
|
|
14
|
+
every Capability has one deterministic path.
|
|
15
|
+
- The same Capability object or ID may occur only once in an Application.
|
|
16
|
+
- Groups are anonymous decorated subtrees. They contribute middleware and error
|
|
17
|
+
sets, and expose their metadata ancestry to surface compilers. Core never
|
|
18
|
+
merges surface metadata generically.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const deleteTodo = todo({
|
|
22
|
+
id: "delete-todo",
|
|
23
|
+
effect: "destructive",
|
|
24
|
+
input: z.object({ todoId: z.string() }),
|
|
25
|
+
errors: TodoErrors,
|
|
26
|
+
meta: {
|
|
27
|
+
http: { method: "DELETE", route: "/:todoId" },
|
|
28
|
+
cli: { positional: ["todoId"] },
|
|
29
|
+
},
|
|
30
|
+
handler: async ({ input, context }) => {
|
|
31
|
+
if (!await context.todos.delete(input.todoId)) throw TodoErrors.NOT_FOUND();
|
|
32
|
+
return { deleted: true as const };
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const todos = group({
|
|
37
|
+
middleware: [requireUser],
|
|
38
|
+
errors: AuthErrors,
|
|
39
|
+
meta: { http: { prefix: "/todos" } },
|
|
40
|
+
capabilities: { delete: deleteTodo },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const definition = defineApp({
|
|
44
|
+
capabilities: { todos },
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Core-owned Capability fields are `id`, descriptive metadata, optional `effect`,
|
|
49
|
+
optional object-shaped `input`, optional `output`, errors, middleware, `handler`,
|
|
50
|
+
optional `subscribe`, and optional `toPresentation`. The open `meta` registry is
|
|
51
|
+
typed through module augmentation from surface packages, so core never depends
|
|
52
|
+
on HTTP, CLI, MCP, or Eve.
|
|
53
|
+
|
|
54
|
+
`toPresentation` derives an optional sequence of portable Markdown, table,
|
|
55
|
+
image, and file parts from validated Canonical Output. A surface must explicitly
|
|
56
|
+
request this representation, then lower the parts it understands. Direct typed
|
|
57
|
+
calls and machine-readable JSON do not materialize it. An empty sequence is
|
|
58
|
+
treated as no Presentation, so surfaces use their canonical-output fallback.
|
|
59
|
+
|
|
60
|
+
## Execution
|
|
61
|
+
|
|
62
|
+
Input is parsed once, group middleware wraps capability middleware, the handler
|
|
63
|
+
runs, thrown errors are normalized against the located error sets, and output is
|
|
64
|
+
validated. Every surface enters this same lifecycle.
|
|
65
|
+
|
|
66
|
+
A Capability executes without an Application:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
await executeCapability(deleteTodo, { input, context, signal });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
That boundary applies the Capability's own validation, middleware, and declared
|
|
73
|
+
errors. Group middleware and Group error sets are properties of placement and
|
|
74
|
+
therefore require execution through the tree.
|
|
75
|
+
|
|
76
|
+
## Errors
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const TodoErrors = defineErrors({
|
|
80
|
+
NOT_FOUND: { status: 404, data: z.object({ todoId: z.string() }) },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
throw TodoErrors.NOT_FOUND({ todoId });
|
|
84
|
+
|
|
85
|
+
if (TodoErrors.NOT_FOUND.is(error)) console.error(error.data.todoId);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Declared error data is validated by the executor. Anything outside the located
|
|
89
|
+
Capability's error sets becomes `INTERNAL_SERVER_ERROR`, retaining the original
|
|
90
|
+
value only as a server-side `cause`. A Group and a Capability may not declare
|
|
91
|
+
the same code twice; the conflict fails when the definition is created.
|
|
92
|
+
|
|
93
|
+
## Context and placement
|
|
94
|
+
|
|
95
|
+
`defineApp()` stores no context provider. `createApp()` supplies and erases one
|
|
96
|
+
context; `createRemoteApp()` returns a lazy, transport-backed App. Unrelated
|
|
97
|
+
local contexts are erased before `mergeApps()` and never become one combined
|
|
98
|
+
context:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const remote = createRemoteApp<typeof serverDefinition>(transport);
|
|
102
|
+
const app = mergeApps(
|
|
103
|
+
remote,
|
|
104
|
+
createApp(localDefinition, { context: createLocalContext }),
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Merging validates path, ID, double-mount, and leaf/subtree conflicts when its
|
|
109
|
+
manifest first resolves, then dispatches by Capability ID. It never repositions
|
|
110
|
+
trees or rewrites IDs; namespaces belong in the authored definition.
|
|
111
|
+
|
|
112
|
+
## Replacement subscriptions
|
|
113
|
+
|
|
114
|
+
A `read` Capability may define `subscribe` beside `handler`. Both modes share one
|
|
115
|
+
ID, input, output, error set, middleware, placement, and metadata.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
subscribe: ({ input, context, signal }) =>
|
|
119
|
+
watchQuery({
|
|
120
|
+
snapshot: () => context.prices.get(input.symbol),
|
|
121
|
+
invalidations: () => context.prices.watch(input.symbol, { signal }),
|
|
122
|
+
signal,
|
|
123
|
+
}),
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`watchQuery()` pulls the invalidation source before reading its first snapshot,
|
|
127
|
+
so a concurrent change causes another snapshot instead of being missed.
|
|
128
|
+
Subscription input is parsed once, every replacement is output-validated,
|
|
129
|
+
middleware encloses the complete iterator lifetime, and cancellation aborts the
|
|
130
|
+
subscriber before cleanup.
|
|
131
|
+
|
|
132
|
+
Out of scope, deliberately: patches, generic domain events, buffering, replay,
|
|
133
|
+
resumption, delivery guarantees, and reconnection policy. The Capable transport
|
|
134
|
+
happens to use SSE; that encoding is not part of core semantics. MCP invokes the
|
|
135
|
+
unary snapshot.
|
|
136
|
+
|
|
137
|
+
## Surface direction
|
|
138
|
+
|
|
139
|
+
- Direct calls, CLI, MCP, AI SDK, Eve, and remote clients derive navigation from the
|
|
140
|
+
object tree.
|
|
141
|
+
- HTTP derives `GET` from `effect: "read"` and `POST` otherwise, with the
|
|
142
|
+
Application path as the default route and decorated Group prefixes replacing
|
|
143
|
+
their tree segment. `meta.http` overrides or disables a route, and
|
|
144
|
+
`requireExplicitRoutes` turns implicit routes into a startup error.
|
|
145
|
+
- The Capable transport discovers the tree and calls Capabilities by ID. It is
|
|
146
|
+
separate from an authored or derived HTTP surface.
|
|
147
|
+
- One Fetch server composition mounts the Capable transport, HTTP/OpenAPI, MCP,
|
|
148
|
+
or another protocol, and is shared by Capable-owned Nitro hosting and by embedded
|
|
149
|
+
Next.js or Hono hosting.
|
|
150
|
+
|
|
151
|
+
## Deferred
|
|
152
|
+
|
|
153
|
+
- Generic response and event streaming, separate from replacement subscriptions.
|
|
154
|
+
- `idempotent`, until a retrying transport, Workflow integration, or another
|
|
155
|
+
real consumer proves its contract.
|
|
156
|
+
- Approvals and durable tasks. They wrap an invocation and never enter canonical
|
|
157
|
+
output: a future pre-execution gate may suspend before semantic middleware and
|
|
158
|
+
`handler`, while an execution-boundary coordinator owns grants, task state,
|
|
159
|
+
webhooks, and resumption. The first durable integration should prove that
|
|
160
|
+
boundary vertically with the Workflow SDK and an agent-facing surface.
|