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.
- package/CHANGELOG.md +214 -0
- package/README.md +6 -0
- package/dist/ai-sdk.d.mts +3 -3
- package/dist/ai-sdk.mjs +9 -7
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +2 -2
- package/dist/bin.mjs +12 -9
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +9 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +1 -1
- package/dist/eve.d.mts +82 -5
- package/dist/eve.mjs +364 -23
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +2 -2
- package/dist/http.mjs +2 -2
- package/dist/{index-Dbc4g9WM.d.mts → index-1A44jLuE.d.mts} +54 -16
- package/dist/{index-DwXlaTXI.d.mts → index-CHuCLJIs.d.mts} +20 -4
- package/dist/{index-D2CRRUzH.d.mts → index-D-NV4PiU.d.mts} +6 -5
- package/dist/{index-Be8-UVBC.d.mts → index-WiBWfyTn.d.mts} +66 -27
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +40 -5
- package/dist/mcp.mjs +1 -1
- package/dist/mount-BmLHp349.mjs +235 -0
- package/dist/mount-BmLHp349.mjs.map +1 -0
- package/dist/react-query.d.mts +2 -2
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +8 -8
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-Db6-XSnU.mjs → src-3LE9S4QE.mjs} +67 -38
- package/dist/src-3LE9S4QE.mjs.map +1 -0
- package/dist/{src-DdV82An-.mjs → src-B2WeUwUT.mjs} +69 -34
- package/dist/src-B2WeUwUT.mjs.map +1 -0
- package/dist/{src-CDxL6w3d.mjs → src-C5jGDnuu.mjs} +9 -6
- package/dist/src-C5jGDnuu.mjs.map +1 -0
- package/dist/src-DePlcG_t.mjs +787 -0
- package/dist/src-DePlcG_t.mjs.map +1 -0
- package/dist/{src-BF70JLxI.mjs → src-_6OmFRYa.mjs} +185 -38
- package/dist/src-_6OmFRYa.mjs.map +1 -0
- package/dist/{subscription-Bq792Ad2.d.mts → subscription-DPdwovhw.d.mts} +2 -2
- package/dist/swr.d.mts +2 -2
- package/dist/swr.mjs +1 -1
- package/dist/swr.mjs.map +1 -1
- package/docs/CONTEXT.md +42 -21
- package/docs/README.md +3 -0
- package/docs/internal/README.md +3 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +1 -1
- package/docs/internal/adr/0002-version-the-capable-value-codec.md +24 -0
- package/docs/internal/adr/0003-capability-reference-customization.md +68 -0
- package/docs/internal/architecture.md +64 -19
- package/docs/internal/capability-first-model.md +127 -18
- package/docs/internal/eve-recovery-validation.md +86 -0
- package/docs/internal/feedback/v-ray/README.md +258 -0
- package/docs/internal/feedback/v-ray/inference.mjs +43 -0
- package/docs/internal/feedback/v-ray/reproduce.mjs +36 -0
- package/docs/internal/implementation-friction.md +481 -1
- package/docs/internal/releases.md +79 -0
- package/docs/site/capable-orpc-and-trpc.mdx +5 -5
- package/docs/site/concepts/apps.mdx +17 -8
- package/docs/site/concepts/architecture.mdx +10 -2
- package/docs/site/concepts/capabilities.mdx +41 -4
- package/docs/site/concepts/errors.mdx +11 -1
- package/docs/site/concepts/presentations.mdx +20 -0
- package/docs/site/hosting/any-fetch-host.mdx +2 -2
- package/docs/site/hosting/next-js.mdx +38 -4
- package/docs/site/hosting/standalone-server.mdx +2 -2
- package/docs/site/introduction.mdx +9 -6
- package/docs/site/patterns/composition.mdx +159 -11
- package/docs/site/patterns/remote-apps.mdx +68 -10
- package/docs/site/patterns/subscriptions.mdx +79 -32
- package/docs/site/quickstart.mdx +19 -14
- package/docs/site/reference/packages-and-entry-points.mdx +52 -5
- package/docs/site/reference/surface-metadata.mdx +7 -2
- package/docs/site/reference/the-cap-cli.mdx +2 -2
- package/docs/site/surfaces/ai-sdk.mdx +3 -3
- package/docs/site/surfaces/cli.mdx +47 -3
- package/docs/site/surfaces/eve.mdx +67 -20
- package/docs/site/surfaces/mcp.mdx +73 -5
- package/docs/site/surfaces/react-query.mdx +3 -3
- package/docs/site/surfaces/swr.mdx +3 -3
- package/docs/site/surfaces/typescript.mdx +8 -8
- package/docs/site/surfaces.mdx +1 -1
- package/package-docs.mjs +3 -0
- package/package.json +11 -11
- package/src/bin.ts +0 -0
- package/src/index.test.ts +2 -1
- package/src/index.ts +6 -1
- package/src/mcp.ts +4 -0
- package/src/package.test.ts +9 -0
- package/dist/mount-xvMsjz1B.mjs +0 -178
- package/dist/mount-xvMsjz1B.mjs.map +0 -1
- package/dist/src-BF70JLxI.mjs.map +0 -1
- package/dist/src-C2MGIlT0.mjs +0 -464
- package/dist/src-C2MGIlT0.mjs.map +0 -1
- package/dist/src-CDxL6w3d.mjs.map +0 -1
- package/dist/src-Db6-XSnU.mjs.map +0 -1
- package/dist/src-DdV82An-.mjs.map +0 -1
|
@@ -46,8 +46,9 @@ const definition = defineApp({
|
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
Core-owned Capability fields are `id`, descriptive metadata, optional `effect`,
|
|
49
|
-
optional object-shaped `input`, optional `output`, errors, middleware, `handler`,
|
|
50
|
-
|
|
49
|
+
optional object-shaped `input`, optional `output`, errors, middleware, `handler` and/or `subscribe`, and optional `toPresentation`.
|
|
50
|
+
At least one operation is required. Definitions derive `execution` as `unary`,
|
|
51
|
+
`live`, or `events`; authors do not configure this field. The open `meta` registry is
|
|
51
52
|
typed through module augmentation from surface packages, so core never depends
|
|
52
53
|
on HTTP, CLI, MCP, or Eve.
|
|
53
54
|
|
|
@@ -59,10 +60,29 @@ treated as no Presentation, so surfaces use their canonical-output fallback.
|
|
|
59
60
|
|
|
60
61
|
## Execution
|
|
61
62
|
|
|
62
|
-
Input is parsed once,
|
|
63
|
+
Input is parsed once, app middleware wraps outer-to-inner group middleware and
|
|
64
|
+
capability middleware, the handler
|
|
63
65
|
runs, thrown errors are normalized against the located error sets, and output is
|
|
64
66
|
validated. Every surface enters this same lifecycle.
|
|
65
67
|
|
|
68
|
+
App Definitions accept `middleware` and `errors` using the same inheritance
|
|
69
|
+
rules as Groups. Middleware at every scope receives a readonly `capability`
|
|
70
|
+
descriptor (`id`, `effect`) and execution `mode` (`call` or `subscribe`).
|
|
71
|
+
The descriptor does not expose executable definitions or application paths.
|
|
72
|
+
Middleware consumes the existing Context contract; it cannot refine downstream
|
|
73
|
+
Context types or introduce Context requirements on the App Definition.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const definition = defineApp({
|
|
77
|
+
capabilities: { todos },
|
|
78
|
+
errors: AccessErrors,
|
|
79
|
+
middleware: [({ capability, context, next }) => {
|
|
80
|
+
if (!canCall(context.user, capability.id)) throw AccessErrors.FORBIDDEN();
|
|
81
|
+
return next();
|
|
82
|
+
}],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
66
86
|
A Capability executes without an Application:
|
|
67
87
|
|
|
68
88
|
```ts
|
|
@@ -70,7 +90,7 @@ await executeCapability(deleteTodo, { input, context, signal });
|
|
|
70
90
|
```
|
|
71
91
|
|
|
72
92
|
That boundary applies the Capability's own validation, middleware, and declared
|
|
73
|
-
errors. Group middleware and
|
|
93
|
+
errors. App and Group middleware and error sets are properties of placement and
|
|
74
94
|
therefore require execution through the tree.
|
|
75
95
|
|
|
76
96
|
## Errors
|
|
@@ -88,31 +108,80 @@ if (TodoErrors.NOT_FOUND.is(error)) console.error(error.data.todoId);
|
|
|
88
108
|
Declared error data is validated by the executor. Anything outside the located
|
|
89
109
|
Capability's error sets becomes `INTERNAL_SERVER_ERROR`, retaining the original
|
|
90
110
|
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.
|
|
111
|
+
the same code twice; the conflict fails when the definition is created. The same
|
|
112
|
+
rule applies to App errors inherited by Groups and Capabilities.
|
|
92
113
|
|
|
93
114
|
## Context and placement
|
|
94
115
|
|
|
95
116
|
`defineApp()` stores no context provider. `createApp()` supplies and erases one
|
|
96
117
|
context; `createRemoteApp()` returns a lazy, transport-backed App. Unrelated
|
|
97
|
-
local contexts are erased before `
|
|
118
|
+
local contexts are erased before `composeApps()` and never become one combined
|
|
98
119
|
context:
|
|
99
120
|
|
|
100
121
|
```ts
|
|
101
|
-
const remote = createRemoteApp<
|
|
102
|
-
const app =
|
|
122
|
+
const remote = createRemoteApp<AppDefinition>(transport);
|
|
123
|
+
const app = composeApps(
|
|
103
124
|
remote,
|
|
104
125
|
createApp(localDefinition, { context: createLocalContext }),
|
|
105
126
|
);
|
|
106
127
|
```
|
|
107
128
|
|
|
108
|
-
|
|
109
|
-
manifest first resolves, then dispatches by Capability ID.
|
|
110
|
-
|
|
129
|
+
Composition validates path, ID ownership, and leaf/subtree conflicts when its
|
|
130
|
+
complete manifest first resolves, then dispatches by Capability ID. App
|
|
131
|
+
arguments contribute at the root; object keys reposition Apps, executable
|
|
132
|
+
subtrees, or individual references beneath navigational namespaces without
|
|
133
|
+
rewriting IDs. References that reach the same terminal transport create
|
|
134
|
+
aliases; distinct execution owners cannot claim the same ID. Direct calls
|
|
135
|
+
beneath a namespace resolve only the placements that can contribute to that
|
|
136
|
+
path.
|
|
137
|
+
|
|
138
|
+
Individual bound references may also be leaves of `composeApps()`:
|
|
111
139
|
|
|
112
|
-
|
|
140
|
+
```ts
|
|
141
|
+
const app = composeApps({
|
|
142
|
+
status: customize(remote.plugins.status, {
|
|
143
|
+
description: "Inspect this desktop instance.",
|
|
144
|
+
meta: { cli: { positional: ["instanceId"] } },
|
|
145
|
+
}),
|
|
146
|
+
screenshot: local.screenshot,
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
An executable Group proxy places its complete subtree. The destination key
|
|
151
|
+
names the placed Group; its title, description, internal paths, and nested Group
|
|
152
|
+
metadata remain authored:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const app = composeApps({
|
|
156
|
+
debug: remote.plugins,
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Navigation inside the subtree remains authored. For example, an absolute CLI
|
|
161
|
+
command on a child may intentionally appear outside the destination Group;
|
|
162
|
+
place individual leaves when destination paths should determine every surface
|
|
163
|
+
name.
|
|
164
|
+
|
|
165
|
+
A reference keeps source execution and adopts the destination path. Source
|
|
166
|
+
Group presentation ancestry is not copied; source middleware and errors still
|
|
167
|
+
execute. `customize()` returns an immutable composition entry and only accepts
|
|
168
|
+
title, description, and opted-in surface metadata. Overrides are stored in the
|
|
169
|
+
manifest separately from the source contract, survive serialization, and are
|
|
170
|
+
excluded from alias identity comparison. Original metadata remains part of the
|
|
171
|
+
contract. Outer overrides replace each supplied metadata namespace. See
|
|
172
|
+
[the decision](adr/0003-capability-reference-customization.md).
|
|
173
|
+
|
|
174
|
+
Composition adds no semantic behavior. It cannot add middleware, errors,
|
|
175
|
+
Context requirements, or another execution lifecycle around a reference. A
|
|
176
|
+
local wrapper around a remote invocation is a new Capability with its own ID
|
|
177
|
+
and input schema; its handler calls the remote reference explicitly.
|
|
178
|
+
|
|
179
|
+
## Subscriptions
|
|
113
180
|
|
|
114
181
|
A `read` Capability may define `subscribe` beside `handler`. Both modes share one
|
|
115
182
|
ID, input, output, error set, middleware, placement, and metadata.
|
|
183
|
+
The subscriber emits its own initial snapshot; subscribing never invokes the
|
|
184
|
+
unary handler.
|
|
116
185
|
|
|
117
186
|
```ts
|
|
118
187
|
subscribe: ({ input, context, signal }) =>
|
|
@@ -125,14 +194,54 @@ subscribe: ({ input, context, signal }) =>
|
|
|
125
194
|
|
|
126
195
|
`watchQuery()` pulls the invalidation source before reading its first snapshot,
|
|
127
196
|
so a concurrent change causes another snapshot instead of being missed.
|
|
128
|
-
Subscription input is parsed once, every
|
|
197
|
+
Subscription input is parsed once, every emitted value is output-validated,
|
|
129
198
|
middleware encloses the complete iterator lifetime, and cancellation aborts the
|
|
130
199
|
subscriber before cleanup.
|
|
131
200
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
201
|
+
A `read` Capability with only `subscribe` is an event stream:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
const logs = capability({
|
|
205
|
+
id: "runs.logs",
|
|
206
|
+
effect: "read",
|
|
207
|
+
async *subscribe({ signal }) {
|
|
208
|
+
yield* followLogs({ signal });
|
|
209
|
+
},
|
|
210
|
+
toPresentation: entry => entry.message,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
for await (const entry of subscribe(app.runs.logs, {}, { signal })) {
|
|
214
|
+
appendLog(entry);
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
An event stream needs no initial value and may complete without yielding.
|
|
219
|
+
Its App reference has no unary call signature; untyped unary calls fail with
|
|
220
|
+
`METHOD_NOT_ALLOWED`. Without an output schema, infer the yielded type. With a
|
|
221
|
+
schema, yield schema inputs and deliver parsed schema outputs to consumers and
|
|
222
|
+
presentations. Adding a handler changes the contract into replacement snapshots;
|
|
223
|
+
a snapshot and unrelated events belong in separate Capabilities.
|
|
224
|
+
|
|
225
|
+
`toPresentation` is optional and operates on each validated value. Typed consumers
|
|
226
|
+
and JSON CLI output do not request it. The CLI appends event presentations but
|
|
227
|
+
replaces live snapshots. An empty presentation selects canonical-output fallback,
|
|
228
|
+
not suppression. Event commands stream by default; live commands use `--watch`.
|
|
229
|
+
|
|
230
|
+
Event-only Capabilities are excluded from React Query/SWR state projections and
|
|
231
|
+
implicit unary HTTP/OpenAPI, MCP, AI SDK, and Eve projections. Explicit unsupported
|
|
232
|
+
HTTP/tool metadata is rejected when that projection is created; use `false` to
|
|
233
|
+
disable it.
|
|
234
|
+
|
|
235
|
+
Out of scope: patches, buffering, replay, resumption, delivery guarantees,
|
|
236
|
+
reconnection policy, and commands that start work and stream results. The Capable
|
|
237
|
+
transport uses SSE; that encoding is not part of core semantics. A quiet event
|
|
238
|
+
response establishes after input parsing, context resolution, middleware entry,
|
|
239
|
+
and subscriber invocation, without waiting for a domain event. Failures during
|
|
240
|
+
that preparation remain ordinary HTTP errors. Failures inside an async-generator
|
|
241
|
+
body use typed stream errors because the body starts on the first pull.
|
|
242
|
+
Establishment does not promise that a source listener or authorization inside a
|
|
243
|
+
generator body has completed; put request rejection in middleware when it must
|
|
244
|
+
affect the HTTP status.
|
|
136
245
|
|
|
137
246
|
## Surface direction
|
|
138
247
|
|
|
@@ -150,7 +259,7 @@ unary snapshot.
|
|
|
150
259
|
|
|
151
260
|
## Deferred
|
|
152
261
|
|
|
153
|
-
-
|
|
262
|
+
- Streaming commands that start work and yield results from that invocation.
|
|
154
263
|
- `idempotent`, until a retrying transport, Workflow integration, or another
|
|
155
264
|
real consumer proves its contract.
|
|
156
265
|
- Approvals and durable tasks. They wrap an invocation and never enter canonical
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Capable reproduction for Eve PR #2981
|
|
2
|
+
|
|
3
|
+
The integration uses `defineDurableCallback` from the PR at
|
|
4
|
+
`8e6964036657082ce1405864cf3313ad11fc8d60`, backported onto Eve 0.52.3 with the
|
|
5
|
+
checked-in pnpm patch. No Eve lifecycle code is changed.
|
|
6
|
+
|
|
7
|
+
User API:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
export default createEveTools(({ session }) =>
|
|
11
|
+
appForUser(session.auth.current!.principalId), {
|
|
12
|
+
approval: capability =>
|
|
13
|
+
capability.effect === "destructive" ? approvalPolicy : undefined,
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Internally, the adapter uses `session.started` for recoverable discovery and
|
|
18
|
+
persists `{ id: capability.id }` in its generated execution callback. On recovery,
|
|
19
|
+
Eve reruns the resolver to register the current implementation. The App provider
|
|
20
|
+
is invoked again with the live execution session before the handler runs.
|
|
21
|
+
The app's code is reconstructable; its data resides outside the function process.
|
|
22
|
+
|
|
23
|
+
A regression surfaced during testing: an unauthorized approval attempt triggered
|
|
24
|
+
recovery with that responder as the current user. Holding onto the App from that
|
|
25
|
+
resolver caused later, legitimately approved execution to use the wrong user's
|
|
26
|
+
context. Recreating the execution App from `ToolContext.session` fixed it.
|
|
27
|
+
|
|
28
|
+
## Local test
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pnpm install --frozen-lockfile
|
|
32
|
+
pnpm run build
|
|
33
|
+
pnpm --dir examples/eve run test:recovery
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Requires an AI Gateway credential. The test:
|
|
37
|
+
|
|
38
|
+
1. Creates a persistent todo and starts an agent deletion through the CLI.
|
|
39
|
+
2. Waits for an actual tool-approval request and a durable waiting event.
|
|
40
|
+
3. Stops Eve and verifies its health endpoint is unreachable.
|
|
41
|
+
4. Starts a fresh server with the same workflow and todo storage.
|
|
42
|
+
5. Submits an approval as another authenticated user and checks rejection.
|
|
43
|
+
6. Approves as the initiator and checks the original call's successful result.
|
|
44
|
+
7. Verifies the deletion receipt names the initiating user and the new instance.
|
|
45
|
+
8. Reads the completed result through a fresh CLI process.
|
|
46
|
+
|
|
47
|
+
## Vercel test
|
|
48
|
+
|
|
49
|
+
`examples/eve/vercel-recovery.e2e.ts` separates `prepare` and `resume` so a new
|
|
50
|
+
preview can be deployed while the call is paused. The driver uses the same
|
|
51
|
+
private Blob store as the deployed app. It checks the same request/call identity,
|
|
52
|
+
rejected responder, successful original-user execution, and persistent deletion.
|
|
53
|
+
It fails if the approval and execution instance markers are identical.
|
|
54
|
+
|
|
55
|
+
The test project is `timo-lins-projects/capable-eve-recovery`. Its routes require
|
|
56
|
+
new demo bearer credentials, and its Blob store is private. See the demo README
|
|
57
|
+
for environment variables and commands. Gateway credentials remain in sensitive
|
|
58
|
+
Preview environment variables; no credentials belong in a reproduction or PR.
|
|
59
|
+
|
|
60
|
+
No issue or PR comment has been posted by this task.
|
|
61
|
+
|
|
62
|
+
## Recorded result — September 9, 2026
|
|
63
|
+
|
|
64
|
+
Both the local stop/start test and the deployed two-phase test passed. The normal
|
|
65
|
+
CLI E2E also passed, alongside 126 unit tests, 5 auth integration tests,
|
|
66
|
+
typechecking, and the package build.
|
|
67
|
+
|
|
68
|
+
Deployed run: `wrun_41M22YGA1Q0GGVQMMJRQF13QQV`.
|
|
69
|
+
|
|
70
|
+
- Prepared on this immutable preview:
|
|
71
|
+
https://capable-eve-recovery-pilxxx6pq-timo-lins-projects.vercel.app
|
|
72
|
+
- Resumed through a newly deployed preview:
|
|
73
|
+
https://capable-eve-recovery-1qtw73tiv-timo-lins-projects.vercel.app
|
|
74
|
+
- Approval runtime marker: `16cfe5b5-ee66-4914-807b-7f15549f292b`.
|
|
75
|
+
- Execution runtime marker: `9f0c5a38-a12d-46e2-a1de-47bed69dd513`.
|
|
76
|
+
- Execution principal: `demo-user`.
|
|
77
|
+
- A fresh combined-CLI process subsequently read `status: "completed"` from
|
|
78
|
+
the deployed run and returned the deletion confirmation.
|
|
79
|
+
- The other authenticated principal's approval was rejected before execution.
|
|
80
|
+
- The successful result kept the original pending request's tool-call ID.
|
|
81
|
+
- The private Blob record contained the deletion, and the normal todo list no
|
|
82
|
+
longer contained that item.
|
|
83
|
+
|
|
84
|
+
These markers identify initialized demo runtime instances. The separate local
|
|
85
|
+
test additionally verifies that the original server process was actually stopped.
|
|
86
|
+
This is a focused approval-recovery test, not load or exhaustive replay testing.
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# v-ray migration feedback review
|
|
2
|
+
|
|
3
|
+
Reviewed 2026-09-09 at Capable commit `88de060ddfec42c2c33b83a8fab25ccb8f9a6a04`.
|
|
4
|
+
The investigation below records the baseline at that commit.
|
|
5
|
+
|
|
6
|
+
## Implemented follow-up
|
|
7
|
+
|
|
8
|
+
The current worktree now forwards markdansi's complete `RenderOptions` through
|
|
9
|
+
`createCli(app, { markdown: { codeBox: false } })`, including watch rendering.
|
|
10
|
+
Root empty/help-only invocations retain the app banner and command listing with
|
|
11
|
+
Capability arguments and options underneath; root `--json`
|
|
12
|
+
and `--watch` select execution, duplicate roots produce a usage error, and error
|
|
13
|
+
hints no longer contain a doubled space.
|
|
14
|
+
|
|
15
|
+
Inferred-output Capability overloads infer the handler return type directly,
|
|
16
|
+
then apply `Awaited` to derive canonical output, preserving mixed synchronous and
|
|
17
|
+
asynchronous return branches. Named
|
|
18
|
+
renderers pass in either property position on TS 5.8.3 and 7.0.1 RC, preserving
|
|
19
|
+
extra handler output fields and rejecting incompatible renderers. Untyped inline
|
|
20
|
+
renderers before `handler` still receive `unknown`; place inline renderers after
|
|
21
|
+
the handler. Explicit output schemas continue to work. The diagnostic script
|
|
22
|
+
therefore now reports success for both named cases against the current build;
|
|
23
|
+
the installed alpha.8 baseline remains unchanged.
|
|
24
|
+
|
|
25
|
+
Dependency restructuring, paragraph spacing, and end-of-options delimiter
|
|
26
|
+
handling remain follow-up work. No v-ray files or published packages changed.
|
|
27
|
+
|
|
28
|
+
## Assessment and evidence
|
|
29
|
+
|
|
30
|
+
The migration demonstrates the intended boundary: one analysis Capability feeds
|
|
31
|
+
a local Next.js Server Component, the legacy HTTP adapter, the `/~capable/`
|
|
32
|
+
protocol, and local/remote CLI. The existing analyzer remains application code.
|
|
33
|
+
Presentation derives from the same result without changing canonical JSON.
|
|
34
|
+
|
|
35
|
+
The integration was inspected read-only in `/Volumes/Development/v-ray`:
|
|
36
|
+
`capable.app.ts`, `capable/presentation.ts`, `scripts/cli.ts`,
|
|
37
|
+
`test/capable.test.ts`, `README.md`, and `app/api/v2/providers/route.ts`.
|
|
38
|
+
Its package is the installed `capable-kit@0.0.1-alpha.8`, not a workspace link.
|
|
39
|
+
The worktree declares the same version; more importantly, the installed source
|
|
40
|
+
maps contain byte-identical copies of current `core/src/capability.ts`,
|
|
41
|
+
`core/src/presentation.ts`, `cli/src/index.ts`, and `cli/src/presentation.ts`.
|
|
42
|
+
Runtime reproductions produced identical output for the installed and locally
|
|
43
|
+
built packages. None of the four reported issues is already fixed here.
|
|
44
|
+
|
|
45
|
+
Reported Next.js production build, migration tests, typecheck, and fixture
|
|
46
|
+
end-to-end success are migration evidence supplied by the integration owner;
|
|
47
|
+
they were not rerun in v-ray during this review. Production deployment remains
|
|
48
|
+
unvalidated. The following findings use focused, deterministic local fixtures.
|
|
49
|
+
|
|
50
|
+
## 1. P1: Route root help through the root Capability
|
|
51
|
+
|
|
52
|
+
Existing API already expresses the desired invocation; no new `root` flag is needed:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
capability({
|
|
56
|
+
id: 'analysis.url',
|
|
57
|
+
input: z.object({ url: z.string() }),
|
|
58
|
+
meta: { cli: { command: [], positional: ['url'] } },
|
|
59
|
+
handler: ({ input }) => analyzeURL(input.url),
|
|
60
|
+
});
|
|
61
|
+
await createCli(app, { invocationName: 'pnpm cli' }).run(process.argv.slice(2));
|
|
62
|
+
// pnpm cli vercel.com
|
|
63
|
+
// pnpm cli --help → proposed: detailed <url> help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`packages/cli/src/index.ts` removes global flags and returns root/group help
|
|
67
|
+
when no tokens remain, before matching commands. Reproduced behavior:
|
|
68
|
+
|
|
69
|
+
| Arguments | Current result |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `vercel.com` | Executes the root Capability successfully |
|
|
72
|
+
| empty, `--help`, or `-h` | Generic `<command>` help; omits detailed arguments |
|
|
73
|
+
| `--help --` | Detailed root `<url>` help, exit 0 |
|
|
74
|
+
| `--json` alone | Generic help on stdout, exit 0, even with a defaulted URL |
|
|
75
|
+
| `--wat` or excess positional arguments | Useful specific error, exit 2; help hint contains `pnpm cli --help` with two spaces |
|
|
76
|
+
| `-- vercel.com` | `Unknown option --`, exit 2 |
|
|
77
|
+
|
|
78
|
+
The workaround works because help returns before input parsing. `--` is not
|
|
79
|
+
currently a functioning end-of-options delimiter. Global flags are also removed
|
|
80
|
+
regardless of delimiter position. Do not document the workaround as delimiter support.
|
|
81
|
+
|
|
82
|
+
Small first patch: resolve a unique empty command before the empty-argv help
|
|
83
|
+
branch and render its command help for empty/help-only invocation. Keep existing
|
|
84
|
+
group behavior when no root Capability exists. Build command names with a token
|
|
85
|
+
join to remove the doubled space. Add tests for required/defaulted/no-input roots,
|
|
86
|
+
local/remote Apps, mixed root/subcommands, and duplicate root mappings. Reject
|
|
87
|
+
ambiguous roots instead of silently choosing by catalog order; preserve longer
|
|
88
|
+
subcommand precedence.
|
|
89
|
+
|
|
90
|
+
Separate follow-up: decide and document no-argument execution. A conservative
|
|
91
|
+
first patch retains bare invocation as help; explicit `--json` should select
|
|
92
|
+
execution (including schema defaults), or emit a missing-input error when
|
|
93
|
+
required input is absent. It should never return human help as successful JSON.
|
|
94
|
+
Test `--watch` with the same dispatch policy. Implement normal `--` handling in
|
|
95
|
+
the argument parser as a separate bounded fix, including global-flag handling
|
|
96
|
+
after the delimiter. These are dispatch/parser corrections, not a new CLI DSL.
|
|
97
|
+
|
|
98
|
+
## 2. P1: Make output inference independent of renderer form/order
|
|
99
|
+
|
|
100
|
+
The reproduction uses an input schema, an async handler with inferred
|
|
101
|
+
`{ url: string; status: number }` output, and a named presentation function.
|
|
102
|
+
It also assigns the typed App call result to that output type.
|
|
103
|
+
|
|
104
|
+
| Form | TS 5.8.3 | TS 7.0.1 RC |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| Named renderer before handler | TS2769, renderer expects `unknown` | Same |
|
|
107
|
+
| Named renderer after handler | TS2769 | Same |
|
|
108
|
+
| Inline renderer before handler | TS2345; App output is `unknown` (TS2322) | Same |
|
|
109
|
+
| Inline renderer after handler | Pass | Pass |
|
|
110
|
+
| Explicit output schema, named renderer before handler | Pass | Pass |
|
|
111
|
+
|
|
112
|
+
Results match for installed alpha.8 declarations and freshly built declarations.
|
|
113
|
+
Both runs use workspace Zod 4.4.3 to isolate compiler/package variables; this is
|
|
114
|
+
a minimized reproduction, not a compile of the full FetchResult type with v-ray's
|
|
115
|
+
Zod 4.5.4. The exact reported diagnostic does not require that full type.
|
|
116
|
+
|
|
117
|
+
Working current example:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
capability({
|
|
121
|
+
id: 'analysis.url',
|
|
122
|
+
input: z.object({ url: z.string() }),
|
|
123
|
+
handler: ({ input }) => analyzeURL(input.url),
|
|
124
|
+
toPresentation: result => presentAnalysis(result),
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Target: allow `toPresentation: presentAnalysis` in either property position,
|
|
129
|
+
preserving output inference and rejecting a renderer for an incompatible result.
|
|
130
|
+
Investigate the inferred-output overload's coupling of `THandler` and
|
|
131
|
+
`Awaited<ReturnType<THandler>>`; prototype inference isolation (`NoInfer`) or a
|
|
132
|
+
direct output type parameter before selecting a fix. Neither approach has been
|
|
133
|
+
validated here. Do not solve this with `any`, consumer casts, or a mandatory
|
|
134
|
+
output schema. An explicit schema is a useful contract decision, but adds runtime
|
|
135
|
+
validation and must not be demanded just to make renderer inference work.
|
|
136
|
+
Add compile fixtures for both supported compilers, property orders, named/inline
|
|
137
|
+
renderers, async output, incompatible renderers, and output transforms.
|
|
138
|
+
|
|
139
|
+
## 3. P2: Expose the small renderer controls already available
|
|
140
|
+
|
|
141
|
+
Capable lowers all presentation parts to Markdown, then calls markdansi 0.3.2
|
|
142
|
+
with only `color` and `width` in a TTY. Redirected output is raw Markdown.
|
|
143
|
+
The runtime fixture confirms:
|
|
144
|
+
|
|
145
|
+
- Two Markdown paragraphs become adjacent terminal lines, without a blank line.
|
|
146
|
+
- Fenced code and tables receive boxes by default.
|
|
147
|
+
- markdansi's `codeBox: false` preserves aligned fenced rows without a box.
|
|
148
|
+
- `tableBorder: 'none', tableDense: true` removes the outside box, but retains
|
|
149
|
+
column `|` separators. This is not a complete key/value detail-row layout.
|
|
150
|
+
- Those controls do not fix ordinary paragraph spacing. Its documented
|
|
151
|
+
`spacing` option belongs to streaming, not the whole-document `render()` used here.
|
|
152
|
+
|
|
153
|
+
Start with a small CLI-owned option, not new core parts or a renderer callback.
|
|
154
|
+
Illustrative proposed API (not available today):
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
createCli(app, {
|
|
158
|
+
invocationName: 'pnpm cli',
|
|
159
|
+
markdown: { codeBox: false, tableBorder: 'none', tableDense: true },
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This permits ordinary fenced text for response headers and duration bars;
|
|
164
|
+
the consumer no longer needs dynamic inline-code delimiters solely to avoid
|
|
165
|
+
terminal boxes. Keep escaping untrusted remote values. Verify narrow terminals,
|
|
166
|
+
long headers, wide Unicode labels, and non-TTY Markdown before changing defaults.
|
|
167
|
+
|
|
168
|
+
Handle paragraph spacing as a focused renderer issue with before/after fixtures;
|
|
169
|
+
do not regex-rewrite arbitrary Markdown. Only if spacing remains unsolved should
|
|
170
|
+
a narrowly scoped detail-row helper be considered, with a portable Markdown
|
|
171
|
+
lowering. Any new core part would also need normalization, HTTP and MCP support,
|
|
172
|
+
which is disproportionate to the first fix. Framework joins (`+`), provider-role
|
|
173
|
+
arrows, duration units, and proportional bar calculations remain v-ray policy.
|
|
174
|
+
The current headings are normal structure; inline-code alignment and the
|
|
175
|
+
` ` footer spacer are the specific workarounds to remove.
|
|
176
|
+
|
|
177
|
+
## 4. P2: Separate installed host dependencies from embedded usage
|
|
178
|
+
|
|
179
|
+
Both package manifests require Nitro `3.0.260610-beta`. The v-ray lockfile
|
|
180
|
+
resolves it with Vite 6.1.0 although its optional peer wants `^7 || ^8`.
|
|
181
|
+
Nitro's unstorage 2.0.0-alpha.7 dependency wants the optional peer
|
|
182
|
+
`@vercel/functions: ^2.2.12 || ^3.0.0`; v-ray resolves 2.2.4. These ranges
|
|
183
|
+
explain the reported warnings. No fresh v-ray install was run during this review.
|
|
184
|
+
|
|
185
|
+
Inspection of emitted module imports in both packages shows that the root,
|
|
186
|
+
`/core`, `/cli`, and `/next` entries do not reach Nitro. `/cli` imports markdansi.
|
|
187
|
+
The `cap` executable statically imports `nitro/builder`, including when invoking
|
|
188
|
+
toolchain CLI functionality. Nitro is external to Capable's emitted bundle but
|
|
189
|
+
installed transitively. Thus installed footprint is real; this evidence does
|
|
190
|
+
not show Nitro in v-ray's Next.js runtime bundle. No Next.js bundle size, cold
|
|
191
|
+
start, or deployment performance measurement was made.
|
|
192
|
+
|
|
193
|
+
Smallest packaging candidate: make Nitro an optional peer and load host code
|
|
194
|
+
lazily only for host commands. `optionalDependencies` alone still installs it
|
|
195
|
+
normally, and lazy imports alone do not reduce installation footprint. A
|
|
196
|
+
separate published host package is a larger alternative; current scoped packages
|
|
197
|
+
are private implementation boundaries and should not be advertised as installable.
|
|
198
|
+
|
|
199
|
+
Proposed install flow (not the current package contract):
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
pnpm add capable-kit # embedded App, Next.js, createCli
|
|
203
|
+
pnpm add -D nitro@3.0.260610-beta # only when using cap dev/build host
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Retain current `createCli(app)` and Next mounting APIs. If choosing this option,
|
|
207
|
+
update generated standalone starters to include Nitro, give missing-host errors
|
|
208
|
+
an exact install command, and test packed installs with and without Nitro. Include
|
|
209
|
+
`cap --help`, local/remote `cap cli`, and `cap dev/build`: the executable must
|
|
210
|
+
remain usable without loading an absent host for unrelated commands. Consider
|
|
211
|
+
MCP's required SDK separately if install measurements justify doing so; do not
|
|
212
|
+
expand the initial packaging change to every surface.
|
|
213
|
+
|
|
214
|
+
## Preserve the migration boundary
|
|
215
|
+
|
|
216
|
+
The legacy adapter owns truthy-flag coercion, deprecated
|
|
217
|
+
`force_browserbase_bypass`, URL normalization, plain-text 400 responses, GET 405,
|
|
218
|
+
and HTTP-200 analysis failures. Its positive fractional body limit floors to zero:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const bodyMaxChars = typeof body_max_chars === 'number' && body_max_chars > 0
|
|
222
|
+
? Math.floor(body_max_chars) : undefined;
|
|
223
|
+
const result = await app.analysis.url({ url: normalizedURL.href, body_max_chars: bodyMaxChars });
|
|
224
|
+
return new Response(JSON.stringify(result));
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
That is why the Capability accepts a **nonnegative** integer. A stricter positive
|
|
228
|
+
schema would break compatibility. Returned error data remains canonical output;
|
|
229
|
+
thrown undeclared errors are normalized by Capable. Do not quietly convert one
|
|
230
|
+
into the other. Explicit output/error schemas are future v-ray work requiring
|
|
231
|
+
intentional compatibility decisions. Existing input schema direction/default
|
|
232
|
+
support already works here; the older default-requiredness friction entry should
|
|
233
|
+
not be mistaken for a present bug (defaulted URL help correctly shows optional).
|
|
234
|
+
|
|
235
|
+
MCP, `analyzeResponse()`, and sharing should follow concrete consumer demand.
|
|
236
|
+
The migration gives no reason to replace Next.js, introduce subscriptions, or
|
|
237
|
+
turn analyzer helpers into Capabilities.
|
|
238
|
+
|
|
239
|
+
## Reproduction and validation
|
|
240
|
+
|
|
241
|
+
```sh
|
|
242
|
+
pnpm install --frozen-lockfile
|
|
243
|
+
pnpm build
|
|
244
|
+
node docs/feedback/v-ray/reproduce.mjs
|
|
245
|
+
node docs/feedback/v-ray/reproduce.mjs /Volumes/Development/v-ray/node_modules/capable-kit
|
|
246
|
+
node docs/feedback/v-ray/inference.mjs
|
|
247
|
+
node docs/feedback/v-ray/inference.mjs /Volumes/Development/v-ray/node_modules/typescript/bin/tsc
|
|
248
|
+
node docs/feedback/v-ray/inference.mjs /Volumes/Development/v-ray/node_modules/typescript/bin/tsc /Volumes/Development/v-ray/node_modules/capable-kit
|
|
249
|
+
node docs/feedback/v-ray/inference.mjs node_modules/typescript/bin/tsc /Volumes/Development/v-ray/node_modules/capable-kit
|
|
250
|
+
pnpm exec vitest run packages/cli/src/cli.test.ts packages/core/src/presentation.test.ts
|
|
251
|
+
pnpm typecheck
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Build and typecheck passed; 12 existing focused tests passed. The reproduction
|
|
255
|
+
scripts print observations and compiler diagnostics, including expected current
|
|
256
|
+
failures; they are diagnostic tools, not passing regression assertions. The
|
|
257
|
+
inference script removes only its own temporary fixture directory. No v-ray
|
|
258
|
+
files were edited, no framework implementation changed, and nothing was published.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Current compiler by default; pass an absolute tsc.js path for another compiler.
|
|
2
|
+
// Optional second argument selects an installed capable-kit package directory.
|
|
3
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { resolve, join } from 'node:path';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
const compiler = process.argv[2] ?? resolve('node_modules/typescript/bin/tsc');
|
|
8
|
+
const packageDirectory = process.argv[3] ?? resolve('packages/capable');
|
|
9
|
+
const temporary = mkdtempSync(resolve('.vray-inference-'));
|
|
10
|
+
try {
|
|
11
|
+
for (const form of ['named-before', 'named-after', 'inline-before', 'inline-after', 'explicit-output']) {
|
|
12
|
+
const handler = 'handler: ({ input }) => Promise.resolve({ url: input.url, status: 200 }),';
|
|
13
|
+
const renderer = form.startsWith('inline') ? 'toPresentation: result => presentAnalysis(result),' : 'toPresentation: presentAnalysis,';
|
|
14
|
+
const source = `
|
|
15
|
+
import { capability, createApp, defineApp, type PresentationValue } from 'capable-kit';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
type FetchResult = { url: string; status: number };
|
|
18
|
+
function presentAnalysis(result: FetchResult): PresentationValue { return result.url; }
|
|
19
|
+
const analysis = capability({
|
|
20
|
+
id: 'analysis.url',
|
|
21
|
+
input: z.object({ url: z.string() }),
|
|
22
|
+
${form === 'explicit-output' ? 'output: z.object({ url: z.string(), status: z.number() }),' : ''}
|
|
23
|
+
${form.endsWith('after') ? handler + renderer : renderer + handler}
|
|
24
|
+
});
|
|
25
|
+
const app = createApp(defineApp({ name: 'v-ray', capabilities: { analysis } }));
|
|
26
|
+
const result: FetchResult = await app.analysis({ url: 'vercel.com' });
|
|
27
|
+
const status: number = result.status;
|
|
28
|
+
`;
|
|
29
|
+
writeFileSync(join(temporary, 'case.ts'), source);
|
|
30
|
+
writeFileSync(join(temporary, 'tsconfig.json'), JSON.stringify({
|
|
31
|
+
compilerOptions: {
|
|
32
|
+
target: 'ES2022', module: 'Preserve', moduleResolution: 'Bundler',
|
|
33
|
+
strict: true, skipLibCheck: true, noEmit: true,
|
|
34
|
+
paths: { 'capable-kit': [resolve(packageDirectory, 'dist/index.d.mts')] },
|
|
35
|
+
}, files: ['./case.ts'],
|
|
36
|
+
}));
|
|
37
|
+
const result = spawnSync(process.execPath, [compiler, '-p', join(temporary, 'tsconfig.json')], { encoding: 'utf8' });
|
|
38
|
+
console.log(JSON.stringify({ form, exit: result.status, diagnostics: result.stdout + result.stderr }));
|
|
39
|
+
if (result.error) throw result.error;
|
|
40
|
+
}
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Run after pnpm build. Optional argument: absolute capable-kit package directory.
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { realpathSync } from 'node:fs';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
const directory = process.argv[2] ?? resolve('packages/capable');
|
|
9
|
+
const entry = pathToFileURL(realpathSync(resolve(directory, 'dist/index.mjs')));
|
|
10
|
+
const { capability, defineApp, createApp } = await import(entry.href);
|
|
11
|
+
const { createCli } = await import(new URL('./cli.mjs', entry).href);
|
|
12
|
+
const { render } = await import(createRequire(entry).resolve('markdansi'));
|
|
13
|
+
|
|
14
|
+
for (const required of [true, false]) {
|
|
15
|
+
const app = createApp(defineApp({
|
|
16
|
+
name: 'v-ray',
|
|
17
|
+
capabilities: { analysis: { url: capability({
|
|
18
|
+
id: 'analysis.url',
|
|
19
|
+
description: 'Inspect a URL.',
|
|
20
|
+
input: z.object({ url: required ? z.string() : z.string().default('example.com') }),
|
|
21
|
+
meta: { cli: { command: [], positional: ['url'] } },
|
|
22
|
+
handler: ({ input }) => input,
|
|
23
|
+
}) } },
|
|
24
|
+
}));
|
|
25
|
+
for (const argv of [[], ['--help'], ['-h'], ['--help', '--'], ['vercel.com'], ['--json'], ['--wat'], ['one', 'two'], ['--', 'vercel.com']]) {
|
|
26
|
+
const stdout = [], stderr = [];
|
|
27
|
+
const exit = await createCli(app, { invocationName: 'pnpm cli', isTTY: false, color: false })
|
|
28
|
+
.run(argv, { io: { stdout: text => stdout.push(text), stderr: text => stderr.push(text) } });
|
|
29
|
+
console.log(JSON.stringify({ required, argv, exit, stdout, stderr }));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const markdown of ['First paragraph\n\nSecond paragraph', '### Headers\n\n```\nserver Vercel\ncache HIT\n```\n\nFooter', '| Header | Value |\n| --- | --- |\n| server | Vercel |']) {
|
|
33
|
+
for (const settings of [{}, { codeBox: false, tableBorder: 'none', tableDense: true }]) {
|
|
34
|
+
console.log(JSON.stringify({ markdown, settings, rendered: render(markdown, { color: false, width: 80, ...settings }) }));
|
|
35
|
+
}
|
|
36
|
+
}
|